status_t DataTranslationsWindow::_ShowConfigView(int32 id) { // Shows the config panel for the translator with the given id if (id < 0) return B_BAD_VALUE; BTranslatorRoster* roster = BTranslatorRoster::Default(); if (fConfigView) { fRightBox->RemoveChild(fConfigView); delete fConfigView; fConfigView = NULL; } BMessage emptyMsg; BRect rect(0, 0, 200, 233); status_t ret = roster->MakeConfigurationView(id, &emptyMsg, &fConfigView, &rect); if (ret != B_OK) return ret; fConfigView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); // force config views to all have the same color fRightBox->AddChild(fConfigView); return B_OK; }
status_t DataTranslationsWindow::_ShowConfigView(int32 id) { // Shows the config panel for the translator with the given id if (id < 0) return B_BAD_VALUE; BTranslatorRoster *roster = BTranslatorRoster::Default(); // fConfigView is NULL the first time this function // is called, prevent a segment fault if (fConfigView) fRightBox->RemoveChild(fConfigView); BMessage emptyMsg; BRect rect(0, 0, 200, 233); status_t ret = roster->MakeConfigurationView(id, &emptyMsg, &fConfigView, &rect); if (ret != B_OK) { fRightBox->RemoveChild(fConfigView); return ret; } BRect configRect(fRightBox->Bounds()); configRect.InsetBy(3, 3); configRect.bottom -= 45; float width = 0, height = 0; if ((fConfigView->Flags() & B_SUPPORTS_LAYOUT) != 0) { BSize configSize = fConfigView->ExplicitPreferredSize(); width = configSize.Width(); height = configSize.Height(); } else { fConfigView->GetPreferredSize(&width, &height); } float widen = max_c(0, width - configRect.Width()); float heighten = max_c(0, height - configRect.Height()); if (widen > 0 || heighten > 0) { ResizeBy(widen, heighten); configRect.right += widen; configRect.bottom += heighten; } fConfigView->MoveTo(configRect.left, configRect.top); fConfigView->ResizeTo(configRect.Width(), configRect.Height()); fConfigView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); // force config views to all have the same color fRightBox->AddChild(fConfigView); return B_OK; }
status_t DataTranslationsWindow::_ShowConfigView(int32 id) { // Shows the config panel for the translator with the given id if (id < 0) return B_BAD_VALUE; BTranslatorRoster* roster = BTranslatorRoster::Default(); if (fConfigView != NULL) { fRightBox->RemoveChild(fConfigView); delete fConfigView; fConfigView = NULL; fInfoText = NULL; if (fRelease != NULL) { fRelease->Release(); fRelease = NULL; } } BMessage emptyMessage; BRect rect(0.0f, 0.0f, 200.0f, 233.0f); status_t result = roster->MakeConfigurationView(id, &emptyMessage, &fConfigView, &rect); if (result != B_OK) return result; fConfigView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR); // force config views to all have the same color fRightBox->AddChild(fConfigView); // for default 12pt font size: 597 ≈ (0.85 * 12 * 49) fConfigView->SetExplicitMinSize( BSize(ceilf(be_control_look->DefaultItemSpacing() * 49) - fTranslatorListView->Frame().Width(), B_SIZE_UNSET)); // Make sure the translator's image doesn't get unloaded while we are still // showing a config view whose code is in the image fRelease = roster->AcquireTranslator(id); return B_OK; }
void ScreenshotWindow::_ShowSettings(bool activate) { if (!fSettingsWindow && !activate) return; // Find a translator translator_id translator = 0; BTranslatorRoster *roster = BTranslatorRoster::Default(); translator_id* translators = NULL; int32 numTranslators = 0; if (roster->GetAllTranslators(&translators, &numTranslators) != B_OK) return; bool foundTranslator = false; for (int32 x = 0; x < numTranslators; x++) { const translation_format* formats = NULL; int32 numFormats; if (roster->GetOutputFormats(translators[x], &formats, &numFormats) == B_OK) { for (int32 i = 0; i < numFormats; ++i) { if (formats[i].type == static_cast<uint32>(fImageFileType)) { translator = translators[x]; foundTranslator = true; break; } } } if (foundTranslator) break; } delete [] translators; if (!foundTranslator) return; // Create a window with a configuration view BView *view; BRect rect(0, 0, 239, 239); status_t err = roster->MakeConfigurationView(translator, NULL, &view, &rect); if (err < B_OK || view == NULL) { BAlert *alert = new BAlert(NULL, strerror(err), "OK"); alert->Go(); } else { if (fSettingsWindow) { fSettingsWindow->RemoveChild(fSettingsWindow->ChildAt(0)); float width, height; view->GetPreferredSize(&width, &height); fSettingsWindow->ResizeTo(width, height); fSettingsWindow->AddChild(view); if (activate) fSettingsWindow->Activate(); } else { fSettingsWindow = new BWindow(rect, B_TRANSLATE("Translator Settings"), B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_NOT_ZOOMABLE | B_NOT_RESIZABLE); fSettingsWindow->AddFilter(new QuitMessageFilter(this)); fSettingsWindow->AddChild(view); fSettingsWindow->CenterOnScreen(); fSettingsWindow->Show(); } } }
// Private function to add the config view of the currently // selected output format to our window void OutputFormatView::AddConfigView() { the_window->Lock(); // Remove the window size limits, // so we are free to do whatever we like the_window->SetSizeLimits(0.0, 32767.0, 0.0, 32767.0); // The current views must stay put while we resize // the window to make room for the config view MakeFollowBottom(false); // Remove the old config view if there is one if (config_view) { RemoveChild(config_view); delete config_view; config_view = 0; } BRect config_rect; if (the_roster->MakeConfigurationView( output_list[index].translator, 0, &config_view, &config_rect) == B_NO_ERROR && config_view != 0) { // Create a caption for the config view // if there wasn't one already if (!config_caption) { config_caption = new CaptionView( BRect(8.0, info_view->Frame().bottom + 1.0, Bounds().right - 8.0, 0.0), "config caption", StringsRsrc[STR_TRANSLATOR_SETTINGS]); config_caption->SetResizingMode(B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); AddChild(config_caption); } // Move the config view to just below the config caption config_view->MoveBy( 16.0 - config_view->Frame().left, config_caption->Frame().bottom + 1.0 - config_view->Frame().top); // Colour it gray config_view->SetViewColor(222, 222, 222); config_view->SetLowColor(222, 222, 222); // First resize the window so that the config view will fit, // otherwise the config view may want to change with us float width_diff = config_view->Frame().right + 16.0 - Bounds().Width(); the_window->ResizeTo( Bounds().Width() + (width_diff > 0.0 ? width_diff : 0.0), config_view->Frame().bottom + 8.0); // Add it to the main view AddChild(config_view); // Make the config_view and its children follow the bottom of the window RecursiveSetMode(config_view); } else { // This translator doesn't have a config view if (config_caption) { RemoveChild(config_caption); delete config_caption; config_caption = 0; } the_window->ResizeTo(Bounds().right, info_view->Frame().bottom + 8.0); } // Make all views follow the bottom of the window again MakeFollowBottom(); // Set the window's minimum size float min_width = (config_view ? config_view->Frame().right : 200.0); if (min_width < 200.0) min_width = 200.0; the_window->SetSizeLimits( min_width, 32767.0, Bounds().Height() - scroll_view->Bounds().Height() + 50.0, 32767.0); the_window->Unlock(); }