bool FilePicker(const TCHAR *caption, FileDataField &df, const TCHAR *help_text) { ComboList combo_list = df.CreateComboList(nullptr); if (combo_list.size() == 0) return false; const TCHAR *extra_caption = nullptr; #ifdef HAVE_DOWNLOAD_MANAGER if (df.GetFileType() != FileType::UNKNOWN && Net::DownloadManager::IsAvailable()) extra_caption = _("Download"); #endif int i = ComboPicker(caption, combo_list, help_text, false, extra_caption); #ifdef HAVE_DOWNLOAD_MANAGER if (i == -2) { const auto path = DownloadFilePicker(df.GetFileType()); if (path.IsNull()) return false; df.ForceModify(path); return true; } #endif if (i < 0) return false; const ComboList::Item &item = combo_list[i]; df.SetFromCombo(item.int_value, item.string_value.c_str()); return true; }
static const TCHAR * SelectLuaFile(TCHAR *buffer, const TCHAR *path) { if (StringIsEmpty(path)) { /* no parameter: let user select a *.lua file */ LuaFileVisitor visitor; Directory::VisitSpecificFiles(LocalPath(buffer, _T("lua")), _T("*.lua"), visitor, true); if (visitor.combo_list.empty()) { ShowMessageBox(_("Not found"), _T("RunLuaFile"), MB_OK|MB_ICONINFORMATION); return nullptr; } int i = ComboPicker(_("Select a file"), visitor.combo_list); if (i < 0) return nullptr; UnsafeCopyString(buffer, visitor.combo_list[i].string_value); return buffer; } else if (StringEndsWith(path, _T(".lua"))) { /* *.lua file specified: run this file */ return IsAbsolutePath(path) ? path : LocalPath(buffer, _T("lua"), path); } else { ShowMessageBox(_T("RunLuaFile expects *.lua parameter"), _T("RunLuaFile"), MB_OK|MB_ICONINFORMATION); return nullptr; } }
static bool EditPortCallback(const TCHAR *caption, DataField &_df, const TCHAR *help_text) { DataFieldEnum &df = (DataFieldEnum &)_df; ComboList combo_list = df.CreateComboList(nullptr); #ifdef ANDROID static constexpr int SCAN_BLUETOOTH_LE = -1; if (BluetoothHelper::HasLe(Java::GetEnv())) combo_list.Append(SCAN_BLUETOOTH_LE, _("Bluetooth LE")); #endif int i = ComboPicker(caption, combo_list, help_text); if (i < 0) return false; const ComboList::Item &item = combo_list[i]; #ifdef ANDROID if (item.int_value == SCAN_BLUETOOTH_LE) { char address[32]; if (!ScanBluetoothLeDialog(address, sizeof(address))) return false; SetPort(df, DeviceConfig::PortType::RFCOMM, address); return true; } #endif df.SetFromCombo(item.int_value, item.string_value); return true; }
static int ComboPicker(const WndProperty &control, const ComboList &combo_list, bool EnableItemHelp) { return ComboPicker(control.GetCaption(), combo_list, control.HasHelp() ? OnHelpClicked : nullptr, EnableItemHelp); }
void InfoBoxManager::ShowInfoBoxPicker(const int id) { int i; if (id < 0) i = GetFocused(); else i = id; if (i < 0) return; InfoBoxSettings &settings = CommonInterface::SetUISettings().info_boxes; const unsigned panel_index = CommonInterface::GetUIState().panel_index; InfoBoxSettings::Panel &panel = settings.panels[panel_index]; const InfoBoxFactory::Type old_type = panel.contents[i]; ComboList list; for (unsigned j = InfoBoxFactory::MIN_TYPE_VAL; j < InfoBoxFactory::NUM_TYPES; j++) { const TCHAR *desc = InfoBoxFactory::GetDescription((InfoBoxFactory::Type)j); list.Append(j, gettext(InfoBoxFactory::GetName((InfoBoxFactory::Type)j)), gettext(InfoBoxFactory::GetName((InfoBoxFactory::Type)j)), desc != NULL ? gettext(desc) : NULL); } list.Sort(); list.current_index = list.LookUp(old_type); /* let the user select */ StaticString<20> caption; caption.Format(_T("%s: %d"), _("InfoBox"), i + 1); int result = ComboPicker(caption, list, nullptr, true); if (result < 0) return; /* was there a modification? */ InfoBoxFactory::Type new_type = (InfoBoxFactory::Type)list[result].int_value; if (new_type == old_type) return; /* yes: apply and save it */ panel.contents[i] = new_type; DisplayInfoBox(); Profile::Save(panel, panel_index); }
void InfoBoxManager::SetupFocused() { int i = GetFocused(); if (i < 0) return; const enum mode mode = GetCurrentMode(); int old_type = GetType(i, mode); /* create a fake WndProperty for dlgComboPicker() */ /* XXX reimplement properly */ DataFieldEnum *dfe = new DataFieldEnum(old_type, NULL); for (unsigned i = 0; i < InfoBoxFactory::NUM_TYPES; i++) dfe->addEnumText(gettext(GetTypeDescription(i))); dfe->Sort(0); dfe->Set(old_type); ComboList *list = dfe->CreateComboList(); delete dfe; /* let the user select */ info_box_combo_list = list; int result = ComboPicker(XCSoarInterface::main_window, _("InfoBox"), *list, OnInfoBoxHelp); if (result < 0) { delete list; return; } /* was there a modification? */ int new_type = (*list)[result].DataFieldIndex; delete list; if (new_type == old_type) return; /* yes: apply and save it */ SetType(i, new_type, mode); DisplayInfoBox(); Profile::SetInfoBoxes(i, GetTypes(i)); }
bool EditDataFieldDialog(const TCHAR *caption, DataField &df, const TCHAR *help_text) { if (df.GetType() == DataField::Type::FILE) { return FilePicker(caption, (FileDataField &)df, help_text); } else if (df.SupportsCombolist()) { return ComboPicker(caption, df, help_text); } else if (df.GetType() == DataField::Type::ROUGH_TIME) { RoughTimeDataField &tdf = (RoughTimeDataField &)df; RoughTime value = tdf.GetValue(); if (!TimeEntryDialog(caption, value, tdf.GetTimeZone(), true)) return false; tdf.ModifyValue(value); return true; } else if (df.GetType() == DataField::Type::GEOPOINT) { GeoPointDataField &gdf = (GeoPointDataField &)df; GeoPoint value = gdf.GetValue(); if (!GeoPointEntryDialog(caption, value, gdf.GetFormat(), false)) return false; gdf.ModifyValue(value); return true; } else { const TCHAR *value = df.GetAsString(); if (value == NULL) return false; StaticString<EDITSTRINGSIZE> buffer(value); PrefixDataField::AllowedCharactersFunction acf; if (df.GetType() == DataField::Type::PREFIX) acf = ((PrefixDataField &)df).GetAllowedCharactersFunction(); if (!TextEntryDialog(buffer, caption, acf)) return false; df.SetAsString(buffer); return true; } }
static void ImportClicked(gcc_unused WndButton &button) { ComboList list; PolarFileVisitor fv(list); // Fill list VisitDataFiles(_T("*.plr"), fv); list.Sort(); // let the user select int result = ComboPicker(UIGlobals::GetMainWindow(), _("Load Polar From File"), list, NULL); if (result < 0) return; assert((unsigned)result < list.size()); PolarInfo polar; const TCHAR* path = list[result].StringValue; PolarGlue::LoadFromFile(polar, path); plane.reference_mass = polar.reference_mass; plane.dry_mass = polar.reference_mass; plane.max_ballast = polar.max_ballast; if (positive(polar.wing_area)) plane.wing_area = polar.wing_area; if (positive(polar.v_no)) plane.max_speed = polar.v_no; plane.v1 = polar.v1; plane.v2 = polar.v2; plane.v3 = polar.v3; plane.w1 = polar.w1; plane.w2 = polar.w2; plane.w3 = polar.w3; plane.polar_name = list[result].StringValueFormatted; Update(); }
static void ListClicked(gcc_unused WndButton &button) { ComboList list; unsigned len = PolarStore::Count(); for (unsigned i = 0; i < len; i++) list.Append(i, PolarStore::GetItem(i).name); list.Sort(); // let the user select int result = ComboPicker(UIGlobals::GetMainWindow(), _("Load Polar"), list, NULL); if (result < 0) return; assert((unsigned)result < len); const PolarStore::Item &item = PolarStore::GetItem(list[result].DataFieldIndex); plane.reference_mass = fixed(item.reference_mass); plane.dry_mass = fixed(item.reference_mass); plane.max_ballast = fixed(item.max_ballast); if (item.wing_area > 0.0) plane.wing_area = fixed(item.wing_area); if (item.v_no > 0.0) plane.max_speed = fixed(item.v_no); plane.v1 = Units::ToSysUnit(fixed(item.v1), Unit::KILOMETER_PER_HOUR); plane.v2 = Units::ToSysUnit(fixed(item.v2), Unit::KILOMETER_PER_HOUR); plane.v3 = Units::ToSysUnit(fixed(item.v3), Unit::KILOMETER_PER_HOUR); plane.w1 = fixed(item.w1); plane.w2 = fixed(item.w2); plane.w3 = fixed(item.w3); plane.polar_name = list[result].StringValue; if (item.contest_handicap > 0) plane.handicap = item.contest_handicap; Update(); }
void InfoBoxManager::SetupFocused(const int id) { int i; if (id < 0) i = GetFocused(); else i = id; if (i < 0) return; const unsigned panel = GetCurrentPanel(); int old_type = GetType(i, panel); ComboList list; for (unsigned i = 0; i < InfoBoxFactory::NUM_TYPES; i++) list.Append(i, gettext(InfoBoxFactory::GetName(i))); list.Sort(); list.ComboPopupItemSavedIndex = list.LookUp(old_type); /* let the user select */ TCHAR caption[20]; _stprintf(caption, _T("%s: %d"), _("InfoBox"), i + 1); info_box_combo_list = &list; int result = ComboPicker(XCSoarInterface::main_window, caption, list, OnInfoBoxHelp); if (result < 0) return; /* was there a modification? */ int new_type = list[result].DataFieldIndex; if (new_type == old_type) return; /* yes: apply and save it */ SetType(i, new_type, panel); DisplayInfoBox(); Profile::SetInfoBoxManagerConfig(infoBoxManagerConfig); }
bool FilePicker(const TCHAR *caption, const TCHAR *patterns, TCHAR *buffer) { assert(patterns != NULL); DataFieldFileReader df; df.ScanMultiplePatterns(patterns); const ComboList combo_list = df.CreateComboList(nullptr); if (combo_list.size() == 0) return false; int i = ComboPicker(caption, combo_list, nullptr); if (i < 0) return false; const ComboList::Item &item = combo_list[i]; df.SetFromCombo(item.DataFieldIndex, item.StringValue); _tcscpy(buffer, df.GetAsString()); return true; }
void PolarConfigPanel::LoadInternal() { ComboList list; unsigned len = PolarStore::Count(); for (unsigned i = 0; i < len; i++) list.Append(i, PolarStore::GetItem(i).name); list.Sort(); /* let the user select */ int result = ComboPicker(UIGlobals::GetMainWindow(), _("Load Polar"), list, NULL); if (result >= 0) { const PolarStore::Item &item = PolarStore::GetItem(list[result].DataFieldIndex); UpdatePolarPoints(Units::ToSysUnit(fixed(item.v1), unKiloMeterPerHour), Units::ToSysUnit(fixed(item.v2), unKiloMeterPerHour), Units::ToSysUnit(fixed(item.v3), unKiloMeterPerHour), fixed(item.w1), fixed(item.w2), fixed(item.w3)); LoadFormProperty(form, _T("prpPolarReferenceMass"), fixed(item.reference_mass)); LoadFormProperty(form, _T("prpPolarDryMass"), fixed(item.reference_mass)); LoadFormProperty(form, _T("prpPolarMaxBallast"), fixed(item.max_ballast)); if (item.wing_area > 0.0) LoadFormProperty(form, _T("prpPolarWingArea"), fixed(item.wing_area)); if (item.v_no > 0.0) LoadFormProperty(form, _T("prpMaxManoeuveringSpeed"), ugHorizontalSpeed, fixed(item.v_no)); if (item.contest_handicap > 0) LoadFormProperty(form, _T("prpHandicap"), item.contest_handicap); CommonInterface::SetComputerSettings().plane.polar_name = item.name; UpdatePolarTitle(); UpdatePolarInvalidLabel(); } }
void PolarConfigPanel::LoadFromFile() { ComboList list; PolarFileVisitor fv(list); // Fill list VisitDataFiles(_T("*.plr"), fv); // Sort list list.Sort(); // Show selection dialog int result = ComboPicker(UIGlobals::GetMainWindow(), _("Load Polar From File"), list, NULL); if (result >= 0) { const TCHAR* path = list[result].StringValue; PolarInfo polar; PolarGlue::LoadFromFile(polar, path); UpdatePolarPoints(polar.v1, polar.v2, polar.v3, polar.w1, polar.w2, polar.w3); LoadFormProperty(form, _T("prpPolarReferenceMass"), polar.reference_mass); LoadFormProperty(form, _T("prpPolarDryMass"), polar.reference_mass); LoadFormProperty(form, _T("prpPolarMaxBallast"), polar.max_ballast); if (positive(polar.wing_area)) LoadFormProperty(form, _T("prpPolarWingArea"), polar.wing_area); if (positive(polar.v_no)) LoadFormProperty(form, _T("prpMaxManoeuveringSpeed"), ugHorizontalSpeed, polar.v_no); CommonInterface::SetComputerSettings().plane.polar_name = list[result].StringValueFormatted; UpdatePolarTitle(); UpdatePolarInvalidLabel(); } }
inline void PlanePolarWidget::ImportClicked() { ComboList list; PolarFileVisitor fv(list); // Fill list VisitDataFiles(_T("*.plr"), fv); list.Sort(); // let the user select int result = ComboPicker(_("Load Polar From File"), list, NULL); if (result < 0) return; assert((unsigned)result < list.size()); PolarInfo polar; const TCHAR* path = list[result].StringValue; PolarGlue::LoadFromFile(polar, path); plane.reference_mass = polar.reference_mass; plane.dry_mass = polar.reference_mass; plane.max_ballast = polar.max_ballast; if (positive(polar.wing_area)) plane.wing_area = polar.wing_area; if (positive(polar.v_no)) plane.max_speed = polar.v_no; plane.polar_shape = polar.shape; plane.polar_name = list[result].StringValueFormatted; Update(); }
inline void PlanePolarWidget::ListClicked() { ComboList list; unsigned len = PolarStore::Count(); for (unsigned i = 0; i < len; i++) list.Append(i, PolarStore::GetItem(i).name); list.Sort(); // let the user select int result = ComboPicker(_("Load Polar"), list, NULL); if (result < 0) return; assert((unsigned)result < len); const PolarStore::Item &item = PolarStore::GetItem(list[result].DataFieldIndex); plane.reference_mass = fixed(item.reference_mass); plane.dry_mass = fixed(item.reference_mass); plane.max_ballast = fixed(item.max_ballast); if (item.wing_area > 0.0) plane.wing_area = fixed(item.wing_area); if (item.v_no > 0.0) plane.max_speed = fixed(item.v_no); plane.polar_shape = item.ToPolarShape(); plane.polar_name = list[result].StringValue; if (item.contest_handicap > 0) plane.handicap = item.contest_handicap; Update(); }
static const RecordedFlightInfo * ShowFlightList(const RecordedFlightList &flight_list) { // Prepare list of the flights for displaying ComboList combo; for (unsigned i = 0; i < flight_list.size(); ++i) { const RecordedFlightInfo &flight = flight_list[i]; TCHAR buffer[64]; _sntprintf(buffer, 64, _T("%04u/%02u/%02u %02u:%02u-%02u:%02u"), flight.date.year, flight.date.month, flight.date.day, flight.start_time.hour, flight.start_time.minute, flight.end_time.hour, flight.end_time.minute); combo.Append(i, buffer); } // Show list of the flights int i = ComboPicker(UIGlobals::GetMainWindow(), _T("Choose a flight"), combo, NULL, false); return (i < 0) ? NULL : &flight_list[i]; }
static const RecordedFlightInfo * ShowFlightList(const RecordedFlightList &flight_list) { // Prepare list of the flights for displaying ComboList combo; for (unsigned i = 0; i < flight_list.size(); ++i) { const RecordedFlightInfo &flight = flight_list[i]; StaticString<64> buffer; buffer.UnsafeFormat(_T("%04u/%02u/%02u %02u:%02u-%02u:%02u"), flight.date.year, flight.date.month, flight.date.day, flight.start_time.hour, flight.start_time.minute, flight.end_time.hour, flight.end_time.minute); combo.Append(i, buffer); } // Show list of the flights int i = ComboPicker(_T("Choose a flight"), combo, NULL, false); return (i < 0) ? NULL : &flight_list[i]; }
void PolarConfigPanel::LoadInternal() { ComboList list; unsigned len = PolarStore::Count(); for (unsigned i = 0; i < len; i++) list.Append(i, PolarStore::GetItem(i).name); list.Sort(); /* let the user select */ int result = ComboPicker(_("Load Polar"), list, NULL); if (result >= 0) { const PolarStore::Item &item = PolarStore::GetItem(list[result].DataFieldIndex); LoadPolarShape(form, item.ToPolarShape()); LoadFormProperty(form, _T("prpPolarReferenceMass"), fixed(item.reference_mass)); LoadFormProperty(form, _T("prpPolarDryMass"), fixed(item.reference_mass)); LoadFormProperty(form, _T("prpPolarMaxBallast"), fixed(item.max_ballast)); if (item.wing_area > 0.0) LoadFormProperty(form, _T("prpPolarWingArea"), fixed(item.wing_area)); if (item.v_no > 0.0) LoadFormProperty(form, _T("prpMaxManoeuveringSpeed"), UnitGroup::HORIZONTAL_SPEED, fixed(item.v_no)); if (item.contest_handicap > 0) LoadFormProperty(form, _T("prpHandicap"), item.contest_handicap); CommonInterface::SetComputerSettings().plane.polar_name = item.name; UpdatePolarTitle(); UpdatePolarInvalidLabel(); } }
int dlgComboPicker(SingleWindow &parent, WndProperty *theProperty) { static bool bInComboPicker = false; bool bInitialPage = true; // used to exit loop (optionally reruns combo with // lower/higher index of items for int/float bool bOpenCombo = true; // prevents multiple instances if (bInComboPicker) return 0; bInComboPicker = true; TCHAR sSavedInitialValue[100]; int iSavedInitialDataIndex = -1; while (bOpenCombo) { assert(theProperty != NULL); wComboPopupWndProperty = theProperty; ComboPopupDataField = wComboPopupWndProperty->GetDataField(); assert(ComboPopupDataField != NULL); ComboListPopup = ComboPopupDataField->CreateComboList(); if (bInitialPage) { // save values for "Cancel" from first page only bInitialPage = false; iSavedInitialDataIndex = (*ComboListPopup)[ComboListPopup->ComboPopupItemSavedIndex] .DataFieldIndex; ComboPopupDataField->CopyString(sSavedInitialValue, false); } int idx = ComboPicker(parent, *theProperty, *ComboListPopup, ComboPopupDataField->GetItemHelpEnabled()); bOpenCombo = false; //tell combo to exit loop after close if (idx >= 0 && (unsigned)idx < ComboListPopup->size()) { const ComboList::Item *item = &(*ComboListPopup)[idx]; // OK/Select if (item->DataFieldIndex == ComboList::Item::NEXT_PAGE) { // we're last in list and the want more past end of list so select last real list item and reopen ComboPopupDataField->SetDetachGUI(true); // we'll reopen, so don't call xcsoar data changed routine yet item = &(*ComboListPopup)[idx - 1]; bOpenCombo = true; // reopen combo with new selected index at center } else if (item->DataFieldIndex == ComboList::Item::PREVIOUS_PAGE) { // same as above but lower items needed ComboPopupDataField->SetDetachGUI(true); item = &(*ComboListPopup)[idx + 1]; bOpenCombo = true; } ComboPopupDataField->SetFromCombo(item->DataFieldIndex, item->StringValue); } else { // Cancel // if we've detached the GUI during the load, then there is nothing to do here assert(iSavedInitialDataIndex >= 0); if (iSavedInitialDataIndex >= 0) // use statics here - saved from first page if multiple were used ComboPopupDataField->SetFromCombo(iSavedInitialDataIndex, sSavedInitialValue); } delete ComboListPopup; wComboPopupWndProperty->RefreshDisplay(); } // loop reopen combo if <<More>> or <<Less>> picked bInComboPicker = false; return 1; }
static int ComboPicker(SingleWindow &parent, const WndProperty &control, const ComboList &combo_list, bool EnableItemHelp) { return ComboPicker(parent, control.GetCaption(), combo_list, OnHelpClicked, EnableItemHelp); }