int32_t PListViewSelect(void *pobject, void *in, void *out, void *extraData) { if (!pobject || !in || !out) return B_ERROR; PView *parent = static_cast<PView*>(pobject); if (!parent) return B_BAD_TYPE; BListView *backend = (BListView*)parent->GetView(); PArgs *inArgs = static_cast<PArgs*>(in); int32 index; if (inArgs->FindInt32("index", &index) != B_OK) return B_ERROR; bool extend; if (inArgs->FindBool("extend", &extend) != B_OK) return B_ERROR; if (backend->Window()) backend->Window()->Lock(); backend->Select(index, extend); if (backend->Window()) backend->Window()->Unlock(); return B_OK; }
// Stuff we can only do when the main view is attached to a window void OutputFormatView::AttachedToWindow() { // Get the window and lock it the_window = Window(); the_window->Lock(); // Set some size limits on the window the_window->SetSizeLimits( 200.0, 32767.0, Bounds().Height() - scroll_view->Bounds().Height() + 50.0, 32767.0); // Set the target for messages sent to this view list_view->SetTarget(this); the_button->SetTarget(this); // Make the list view the keyboard focus list_view->MakeFocus(); // Select the first item in the list, // and make its config view show up if (list_view->CountItems() > 0) list_view->Select(0); else the_button->SetEnabled(false); // Unlock the window the_window->Unlock(); // Call the base class BView::AttachedToWindow(); }
void GuideWindow::deleteGuide(BMessage *msg) { BStringItem *item = modifyGuide(msg); BListView *view = getCurrentListView(); view->RemoveItem(item); view->Select(0); view->ScrollToSelection(); }
/** * @brief Makes specified item selected. * @param[in] index item index. if this is -1, no item is selected. */ void BeListViewAdapter::SetSelectedItem(SInt32 index) { BListView* listView = getListView(); int32 current = listView->CurrentSelection(0); if (current != index) { listView->DeselectAll(); listView->Select(index); } }
void ModulesView::PopulateScreenSaverList() { // Blackness is a built-in screen saver ScreenSaverItem* defaultItem = new ScreenSaverItem(B_TRANSLATE("Blackness"), ""); fScreenSaversListView->AddItem(defaultItem); // Iterate over add-on directories, and add their files to the list view directory_which which[] = { B_USER_NONPACKAGED_ADDONS_DIRECTORY, B_USER_ADDONS_DIRECTORY, B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY, B_SYSTEM_ADDONS_DIRECTORY, }; ScreenSaverItem* selectedItem = NULL; for (uint32 i = 0; i < sizeof(which) / sizeof(which[0]); i++) { BPath basePath; if (find_directory(which[i], &basePath) != B_OK) continue; else if (basePath.Append("Screen Savers", true) != B_OK) continue; BDirectory dir(basePath.Path()); BEntry entry; while (dir.GetNextEntry(&entry, true) == B_OK) { char name[B_FILE_NAME_LENGTH]; if (entry.GetName(name) != B_OK) continue; BPath path(basePath); if (path.Append(name) != B_OK) continue; ScreenSaverItem* item = new ScreenSaverItem(name, path.Path()); fScreenSaversListView->AddItem(item); if (selectedItem != NULL) continue; if (strcmp(fSettings.ModuleName(), item->Text()) == 0) selectedItem = item; } } fScreenSaversListView->SortItems(_CompareScreenSaverItems); if (selectedItem == NULL) selectedItem = defaultItem; fScreenSaversListView->Select(fScreenSaversListView->IndexOf(selectedItem)); fScreenSaversListView->ScrollToSelection(); }
void ModulesView::PopulateScreenSaverList() { fScreenSaversListView->DeselectAll(); while (ScreenSaverItem* item = (ScreenSaverItem*)fScreenSaversListView->RemoveItem((int32)0)) { delete item; } // Blackness is a built-in screen saver fScreenSaversListView->AddItem( new ScreenSaverItem(B_TRANSLATE("Blackness"), "")); // Iterate over add-on directories, and add their files to the list view directory_which which[] = { B_USER_ADDONS_DIRECTORY, B_COMMON_ADDONS_DIRECTORY, B_SYSTEM_ADDONS_DIRECTORY, }; ScreenSaverItem* selectItem = NULL; for (uint32 i = 0; i < sizeof(which) / sizeof(which[0]); i++) { BPath basePath; find_directory(which[i], &basePath); basePath.Append("Screen Savers", true); BDirectory dir(basePath.Path()); BEntry entry; while (dir.GetNextEntry(&entry, true) == B_OK) { char name[B_FILE_NAME_LENGTH]; if (entry.GetName(name) != B_OK) continue; BPath path = basePath; path.Append(name); ScreenSaverItem* item = new ScreenSaverItem(name, path.Path()); fScreenSaversListView->AddItem(item); if (strcmp(fSettings.ModuleName(), item->Text()) != 0 || (strcmp(fSettings.ModuleName(), "") != 0 && strcmp(item->Text(), B_TRANSLATE("Blackness")) != 0)) { selectItem = item; } } } fScreenSaversListView->SortItems(_CompareScreenSaverItems); fScreenSaversListView->Select(fScreenSaversListView->IndexOf(selectItem)); fScreenSaversListView->ScrollToSelection(); }
LocaleWindow::LocaleWindow() : BWindow(BRect(0, 0, 0, 0), "Locale", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS) { BCountry* defaultCountry; be_locale_roster->GetDefaultCountry(&defaultCountry); SetLayout(new BGroupLayout(B_HORIZONTAL)); float spacing = be_control_look->DefaultItemSpacing(); BTabView* tabView = new BTabView("tabview"); BGroupView* languageTab = new BGroupView(B_TRANSLATE("Language"), B_HORIZONTAL, spacing); // first list: available languages fLanguageListView = new LanguageListView("available", B_MULTIPLE_SELECTION_LIST); BScrollView* scrollView = new BScrollView("scroller", fLanguageListView, B_WILL_DRAW | B_FRAME_EVENTS, false, true); fLanguageListView->SetInvocationMessage(new BMessage(kMsgLanguageInvoked)); fLanguageListView->SetDragMessage(new BMessage(kMsgLanguageDragged)); // Fill the language list from the LocaleRoster data BMessage installedLanguages; if (be_locale_roster->GetInstalledLanguages(&installedLanguages) == B_OK) { BString currentID; LanguageListItem* lastAddedCountryItem = NULL; for (int i = 0; installedLanguages.FindString("langs", i, ¤tID) == B_OK; i++) { // Now get an human-readable, localized name for each language BLanguage* currentLanguage; be_locale_roster->GetLanguage(currentID.String(), ¤tLanguage); BString name; currentLanguage->GetName(name); // TODO: as long as the app_server doesn't support font overlays, // use the translated name if problematic characters are used... const char* string = name.String(); while (uint32 code = BUnicodeChar::FromUTF8(&string)) { if (code > 1424) { currentLanguage->GetTranslatedName(name); break; } } LanguageListItem* item = new LanguageListItem(name, currentID.String(), currentLanguage->Code()); if (currentLanguage->IsCountrySpecific() && lastAddedCountryItem != NULL && lastAddedCountryItem->Code() == item->Code()) { fLanguageListView->AddUnder(item, lastAddedCountryItem); } else { // This is a language variant, add it at top-level fLanguageListView->AddItem(item); if (!currentLanguage->IsCountrySpecific()) { item->SetExpanded(false); lastAddedCountryItem = item; } } delete currentLanguage; } fLanguageListView->FullListSortItems(compare_typed_list_items); } else { BAlert* alert = new BAlert("Error", B_TRANSLATE("Unable to find the available languages! You can't " "use this preflet!"), B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_STOP_ALERT); alert->Go(); } // Second list: active languages fPreferredListView = new LanguageListView("preferred", B_MULTIPLE_SELECTION_LIST); BScrollView* scrollViewEnabled = new BScrollView("scroller", fPreferredListView, B_WILL_DRAW | B_FRAME_EVENTS, false, true); fPreferredListView->SetInvocationMessage( new BMessage(kMsgPreferredLanguageInvoked)); fPreferredListView->SetDeleteMessage( new BMessage(kMsgPreferredLanguageDeleted)); fPreferredListView->SetDragMessage( new BMessage(kMsgPreferredLanguageDragged)); BLayoutBuilder::Group<>(languageTab) .AddGroup(B_VERTICAL, spacing) .Add(new BStringView("", B_TRANSLATE("Available languages"))) .Add(scrollView) .End() .AddGroup(B_VERTICAL, spacing) .Add(new BStringView("", B_TRANSLATE("Preferred languages"))) .Add(scrollViewEnabled) .End() .SetInsets(spacing, spacing, spacing, spacing); BView* countryTab = new BView(B_TRANSLATE("Country"), B_WILL_DRAW); countryTab->SetLayout(new BGroupLayout(B_VERTICAL, 0)); BListView* listView = new BListView("country", B_SINGLE_SELECTION_LIST); scrollView = new BScrollView("scroller", listView, B_WILL_DRAW | B_FRAME_EVENTS, false, true); listView->SetSelectionMessage(new BMessage(kMsgCountrySelection)); // get all available countries from ICU // Use DateFormat::getAvailableLocale so we get only the one we can // use. Maybe check the NumberFormat one and see if there is more. int32_t localeCount; const Locale* currentLocale = Locale::getAvailableLocales(localeCount); for (int index = 0; index < localeCount; index++) { UnicodeString countryFullName; BString string; BStringByteSink sink(&string); currentLocale[index].getDisplayName(countryFullName); countryFullName.toUTF8(sink); LanguageListItem* item = new LanguageListItem(string, currentLocale[index].getName(), NULL); listView->AddItem(item); if (!strcmp(currentLocale[index].getName(), defaultCountry->Code())) listView->Select(listView->CountItems() - 1); } // TODO: find a real solution intead of this hack listView->SetExplicitMinSize( BSize(25 * be_plain_font->Size(), B_SIZE_UNSET)); fFormatView = new FormatView(defaultCountry); countryTab->AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL, spacing) .AddGroup(B_VERTICAL, 3) .Add(scrollView) .End() .Add(fFormatView) .SetInsets(spacing, spacing, spacing, spacing)); listView->ScrollToSelection(); tabView->AddTab(languageTab); tabView->AddTab(countryTab); BButton* button = new BButton(B_TRANSLATE("Defaults"), new BMessage(kMsgDefaults)); fRevertButton = new BButton(B_TRANSLATE("Revert"), new BMessage(kMsgRevert)); fRevertButton->SetEnabled(false); BLayoutBuilder::Group<>(this, B_VERTICAL, spacing) .Add(tabView) .AddGroup(B_HORIZONTAL, spacing) .Add(button) .Add(fRevertButton) .AddGlue() .End() .SetInsets(spacing, spacing, spacing, spacing) .End(); _UpdatePreferredFromLocaleRoster(); SettingsReverted(); CenterOnScreen(); }
// Handle messages to the main view void OutputFormatView::MessageReceived(BMessage *msg) { int32 item_index; const char *info_lines[3]; switch (msg->what) { case ITEM_SELECTED: if (msg->FindInt32("index", &item_index) == B_OK && item_index >= 0 && item_index < list_view->CountItems()) { // Store the currently selected item // in the class member 'index' index = item_index; // Update the info view and config view int32 outVersion; the_roster->GetTranslatorInfo( output_list[item_index].translator, &name_line, &info_line, &outVersion); int32 ver = outVersion / 100; int32 rev1 = (outVersion % 100) / 10; int32 rev2 = outVersion % 10; sprintf(version_line, "Version %ld.%ld.%ld", ver, rev1, rev2); info_lines[0] = name_line; info_lines[1] = info_line; info_lines[2] = version_line; info_view->SetInfoLines(info_lines); AddConfigView(); } else { // Reselect the original item if (index >= 0) list_view->Select(index); } break; case INVOKE_LIST: { // The main button was pressed // Find out which item is selected, and invoke it int32 item_count = list_view->CountItems(); for (int32 i = 0; i < item_count; ++i) { if (list_view->IsItemSelected(i)) { list_view->Invoke(); break; } } break; } case SEND_MESSAGE: // An output format has been selected if (!message_sent && msg->FindInt32("index", &item_index) == B_OK && item_index >= 0 && item_index < list_view->CountItems()) { // Get the message from the invoker BMessage *the_message=selected_invoker->Message(); // Add some info about the selected output format to it the_message->AddInt32("translator", output_list[item_index].translator); the_message->AddInt32("type", output_list[item_index].type); // Send the message selected_invoker->Invoke(the_message); message_sent = true; the_window->PostMessage(MESSAGE_SENT); } break; default: BView::MessageReceived(msg); break; } }