TestWindow::TestWindow(BApplication* myApp) : BWindow(BRect(20,20,100,100), "Code Profile", B_TITLED_WINDOW, 0) { BRect frm = Bounds(); BView* myview = new BView(BRect(),"testView",0,0); BOutlineListView* olist = new BOutlineListView(BRect(),"MyList", B_SINGLE_SELECTION_LIST,B_FOLLOW_NONE); if( myview && olist ) { myview->AddChild(olist); BView* vw = olist; vw->SetViewColor(0xc0,0xc0,0xc0); vw->Invalidate(); vw->SetLowColor(0xc0,0xc0,0xc0); vw->Invalidate(); vw->SetHighColor(0x00,0x00,0x00); vw->Invalidate(); vw->SetFont(be_bold_font); this->AddChild(myview); BRect frm = vw->Frame(); vw->ResizeTo(1,1); vw->Draw(vw->Bounds()); vw->ResizeToPreferred(); float w=0,h=0; vw->GetPreferredSize(&w,&h); printf("Preferred size = %f x %f\n",w,h); } string = new BStringView(BRect(0,0,100,20),"String", "Ready to profile..."); if( string ) { string->SetViewColor(0xc0,0xc0,0xc0); this->AddChild(string); float w=0, h=0; string->GetPreferredSize(&w,&h); MoveTo(30,30); ResizeTo(w,h); } BMenuBar* menu = new BMenuBar(BRect(),"MainMenu",B_FOLLOW_NONE); if( menu ) { this->AddChild(menu); float w=0, h=0; menu->GetPreferredSize(&w,&h); printf("Preferred Size = (%f,%f)\n",w,h); menu->SetFont(be_plain_font); menu->GetPreferredSize(&w,&h); printf("Preferred Size = (%f,%f)\n",w,h); menu->SetFont(be_bold_font); menu->GetPreferredSize(&w,&h); printf("Preferred Size = (%f,%f)\n",w,h); menu->SetFont(be_fixed_font); menu->GetPreferredSize(&w,&h); printf("Preferred Size = (%f,%f)\n",w,h); } }
CSelectTeamWindow::CSelectTeamWindow() : CSingletonWindow( BRect(0,0,10,10), B_TRANSLATE("Select Team"), B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, B_CURRENT_WORKSPACE) { static const float windowWidth = 200; float windowHeight; BView *view = new CSelectTeamWindowView(BRect(0, 0, windowWidth, 10)); view->GetPreferredSize(NULL, &windowHeight); view->ResizeToPreferred(); BRect screenRect = BScreen(this).Frame(); // center window float wx = (screenRect.Width()-windowWidth)/2; float wy = (screenRect.Height()-windowHeight)/2; MoveTo(wx, wy); ResizeTo(windowWidth, windowHeight); AddChild(view); Show(); }
void CSettingsGroup::FrameResized(float width, float height) { CBox::FrameResized(width, height); BRect clientRect = ClientRect(); float ypos = clientRect.top+dist; float columnWidth = (clientRect.Width() - numColumns*dist - dist) / numColumns; for(int32 i=0 ; i<CountChildren() ; i++) { BView *child = ChildAt(i); float childWidth, childHeight; child->GetPreferredSize(&childWidth, &childHeight); int32 column = i%numColumns; child->MoveTo(clientRect.left+column*(columnWidth+dist)+dist, ypos); child->ResizeTo(columnWidth, childHeight); if(((i+1)%numColumns) == 0) ypos += childHeight+dist; } }
void ArpConfigurePanel::GetPreferredSize(float* width, float* height) { float maxw=0, maxh=0; size_t i; // Get dimensions of all configuration views. for( i=0; i<mConfigViews->size(); i++ ) { BView* view = 0; if( (view=mConfigViews->at(i)) != 0 ) { ArpD(cdb << ADH << "Processing dimens for view #" << i << ", name=" << view->Name() << endl); float vwidth=0, vheight=0; // If this view is not attached to the window (i.e., it // is not currently displayed by the tab view), then it // may not be able to report correct dimensions. To fix // this, we temporarily add it to your view. if( !view->Window() ) { ArpD(cdb << ADH << "Temporarily attaching view to window." << endl); bool hidden = view->IsHidden(); view->Hide(); AddChild(view); view->GetPreferredSize(&vwidth, &vheight); RemoveChild(view); if( !hidden ) view->Show(); } else { view->GetPreferredSize(&vwidth, &vheight); } ArpD(cdb << ADH << "Preferred width=" << vwidth << ", height=" << vheight << endl); if( vwidth > maxw ) maxw = vwidth; if( vheight > maxh ) maxh = vheight; } } ArpD(cdb << ADH << "Final size=(" << (maxw+mTabWidth) << ", " << (maxh+mTabHeight) << ")" << endl); if( width ) *width = maxw + mTabWidth + 2; if( height ) *height = maxh + mTabHeight + 2; }
void ToolSelectionWindow::FrameResized(float width, float height) { BView* matrix = ChildAt(0); if (matrix != NULL) { float tmpHeight; matrix->GetPreferredSize(&width, &tmpHeight); if ((width != Bounds().Width()) || (tmpHeight != Bounds().Height())) ResizeTo(width, height); } }
void CInternalSettingsView::FrameResized(float width, float height) { float ypos = dist; for(int32 i=0 ; i<CountChildren() ; i++) { BView *child = ChildAt(i); float childWidth, childHeight; child->GetPreferredSize(&childWidth, &childHeight); child->MoveTo(dist, ypos); child->ResizeTo(width-2*dist, childHeight); ypos += childHeight+dist; } }
void ScreenshotWindow::_ShowSettings(bool activate) { if (!fSettingsWindow && !activate) return; // Find a translator translator_id translator; if (fUtility.FindTranslator(fImageFileType, translator) != B_OK) return; // Create a window with a configuration view BView* view; BRect rect(0, 0, 239, 239); status_t status = BTranslatorRoster::Default()->MakeConfigurationView( translator, NULL, &view, &rect); if (status != B_OK || view == NULL) { // TODO: proper translation, better error dialog BAlert* alert = new BAlert(NULL, strerror(status), "OK"); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->Go(); } else if (fSettingsWindow != NULL) { 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(); } }
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(); } } }
float PBox::BuildGUI(BMessage viewTemplate, BMessage settings, BView *view) { BMessage curr; float yOffset = kEdgeOffset + kControlOffset; float xOffset = 0; const float kControlWidth = view->Bounds().Width() - (kEdgeOffset * 2); BMessage postAdded; for (int i=0; viewTemplate.FindMessage("setting",i,&curr) == B_OK; i++ ) { char temp[512]; // get text etc from template const char * name = curr.FindString("name"); const char * desc = curr.FindString("description"); const char * value = NULL; int32 type = -1; bool secret = false; bool freeText = true; bool multiLine = false; BView *control = NULL; BMenu *menu = NULL; BMessage* enabling = NULL; if ( name != NULL && strcmp(name,"app_sig") == 0 ) { // skip app-sig setting continue; } if (curr.FindInt32("type", &type) != B_OK) { printf("Error getting type for %s, skipping\n", name); continue; }; switch (type) { case B_STRING_TYPE: { if (curr.FindString("valid_value")) { // It's a "select one of these" setting freeText = false; menu = new BPopUpMenu(name); // menu->SetDivider(be_plain_font->StringWidth(name) + 10); for (int j = 0; curr.FindString("valid_value", j); j++) { menu->AddItem(new BMenuItem(curr.FindString("valid_value", j),NULL)); }; value = NULL; value = curr.FindString("default"); if (value && menu->FindItem(value)) menu->FindItem(value)->SetMarked(true); value = settings.FindString(name); if (value && menu->FindItem(value)) menu->FindItem(value)->SetMarked(true); } else { // It's a free-text setting if (curr.FindBool("multi_line", &multiLine) != B_OK) multiLine = false; value = settings.FindString(name); if (!value) value = curr.FindString("default"); if (curr.FindBool("is_secret",&secret) != B_OK) secret = false; } } break; case B_INT32_TYPE: { if (curr.FindInt32("valid_value")) { // It's a "select one of these" setting freeText = false; menu = new BPopUpMenu(name); int32 v = 0; for ( int j = 0; curr.FindInt32("valid_value",j,&v) == B_OK; j++ ) { sprintf(temp,"%ld", v); menu->AddItem(new BMenuItem(temp, NULL)); }; if ( curr.FindInt32("default",&v) == B_OK ) { sprintf(temp,"%ld",v); value = temp; menu->FindItem(value)->SetMarked(true); } if ( settings.FindInt32(name,&v) == B_OK ) { sprintf(temp,"%ld",v); value = temp; menu->FindItem(value)->SetMarked(true); } } else { // It's a free-text (but number) setting int32 v = 0; if (settings.FindInt32(name,&v) == B_OK) { sprintf(temp,"%ld",v); value = temp; } else if ( curr.FindInt32("default",&v) == B_OK ) { sprintf(temp,"%ld",v); value = temp; } if (curr.FindBool("is_secret",&secret) != B_OK) secret = false; } } break; case B_BOOL_TYPE: { bool active; if (settings.FindBool(name, &active) != B_OK) { if (curr.FindBool("default", &active) != B_OK) { active = false; }; }; for (int j = 0; curr.FindString("enable_control", j); j++) { if(!enabling) enabling = new BMessage('enab'); enabling->AddString("enable_control",curr.FindString("enable_control",j) ); if(!active) postAdded.AddString("disable",curr.FindString("enable_control", j)); }; control = new BCheckBox(BRect(0, 0, kControlWidth, fFontHeight), name, _T(desc), enabling); if (active) ((BCheckBox*)control)->SetValue(B_CONTROL_ON); } break; default: { continue; }; }; if (!value) value = ""; if (!control) { if (freeText) { if (multiLine == false) { control = new BTextControl( BRect(0, 0, kControlWidth, fFontHeight), name, _T(desc), value, NULL); if (secret) { ((BTextControl *)control)->TextView()->HideTyping(true); ((BTextControl *)control)->SetText(_T(value)); }; ((BTextControl *)control)->SetDivider(kDividerWidth); } else { BRect rect; BRect textRect; if (desc) //andrea: add description only if available. { BRect labelRect(0, 0, kDividerWidth, fFontHeight); BStringView *label = new BStringView(labelRect, "NA", _T(desc), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW); view->AddChild(label); label->MoveTo(kEdgeOffset, yOffset); rect = BRect(0, 0, kControlWidth - kDividerWidth, fFontHeight * 4); rect.right -= B_V_SCROLL_BAR_WIDTH + kEdgeOffset + kControlOffset; xOffset = kEdgeOffset + kDividerWidth; } else { rect = BRect(0, 0, kControlWidth, fFontHeight * 4); rect.right -= B_V_SCROLL_BAR_WIDTH + kControlOffset; xOffset = 0; } textRect = rect; textRect.InsetBy(kEdgeOffset, kEdgeOffset); textRect.OffsetTo(1.0, 1.0); BTextView *textView = new BTextView(rect, name, textRect, B_FOLLOW_ALL_SIDES, B_WILL_DRAW); control = new BScrollView("NA", textView, B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_NAVIGABLE, false, true); textView->SetText(_T(value)); }; } else { control = new BMenuField(BRect(0, 0, kControlWidth, fFontHeight), name, _T(desc), menu); float size=kDividerWidth; if(control->StringWidth(_T(desc)) > kDividerWidth) size=control->StringWidth(_T(desc)) + 20; ((BMenuField *)control)->SetDivider(size); }; }; view->AddChild(control); if(enabling) ((BCheckBox*)control)->SetTarget(this); float h, w = 0; control->GetPreferredSize(&w, &h); if (h < control->Bounds().Height()) h = control->Bounds().Height(); control->MoveTo(kEdgeOffset + xOffset, yOffset); yOffset += kControlOffset + h ; xOffset = 0; }; for (int j = 0; postAdded.FindString("disable", j); j++) { const char* name=postAdded.FindString("disable", j); BView* viewz=view->FindView(name); if(viewz) ((BControl*)viewz)->SetEnabled(false); } //if ( yOffset < view->Bounds().Height() ) // yOffset = view->Bounds().Height(); return yOffset;//view->ResizeTo( view->Bounds().Width(), yOffset }
void ModulesView::_OpenSaver() { // create new screen saver preview & config BView* view = fPreviewView->AddPreview(); fCurrentName = fSettings.ModuleName(); fSaverRunner = new ScreenSaverRunner(Window(), view, true, fSettings); BScreenSaver* saver = _ScreenSaver(); #ifdef __HAIKU__ BRect rect = fSettingsBox->InnerFrame().InsetByCopy(4, 4); #else BRect rect = fSettingsBox->Bounds().InsetByCopy(4, 4); rect.top += 14; #endif fSettingsView = new BView(rect, "SettingsView", B_FOLLOW_ALL, B_WILL_DRAW); fSettingsView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fSettingsBox->AddChild(fSettingsView); if (saver != NULL) { fSaverRunner->Run(); saver->StartConfig(fSettingsView); } if (fSettingsView->ChildAt(0) == NULL) { // There are no settings at all, we add the module name here to // let it look a bit better at least. BPrivate::BuildScreenSaverDefaultSettingsView(fSettingsView, fSettings.ModuleName()[0] ? fSettings.ModuleName() : B_TRANSLATE("Blackness"), saver || !fSettings.ModuleName()[0] ? B_TRANSLATE("No options available") : B_TRANSLATE("Could not load screen saver")); } ScreenSaverWindow* window = dynamic_cast<ScreenSaverWindow*>(Window()); if (window == NULL) return; // find the minimal size of the settings view float right = 0, bottom = 0; int32 i = 0; while ((view = fSettingsView->ChildAt(i++)) != NULL) { // very simple heuristic... float viewRight = view->Frame().right; if ((view->ResizingMode() & _rule_(0, 0xf, 0, 0xf)) == B_FOLLOW_LEFT_RIGHT) { float width, height; view->GetPreferredSize(&width, &height); viewRight = view->Frame().left + width / 2; } else if ((view->ResizingMode() & _rule_(0, 0xf, 0, 0xf)) == B_FOLLOW_RIGHT) viewRight = 8 + view->Frame().Width(); float viewBottom = view->Frame().bottom; if ((view->ResizingMode() & _rule_(0xf, 0, 0xf, 0)) == B_FOLLOW_TOP_BOTTOM) { float width, height; view->GetPreferredSize(&width, &height); viewBottom = view->Frame().top + height; } else if ((view->ResizingMode() & _rule_(0xf, 0, 0xf, 0)) == B_FOLLOW_BOTTOM) viewBottom = 8 + view->Frame().Height(); if (viewRight > right) right = viewRight; if (viewBottom > bottom) bottom = viewBottom; } if (right < kMinSettingsWidth) right = kMinSettingsWidth; if (bottom < kMinSettingsHeight) bottom = kMinSettingsHeight; BPoint leftTop = fSettingsView->LeftTop(); fSettingsView->ConvertToScreen(&leftTop); window->ConvertFromScreen(&leftTop); window->SetMinimalSizeLimit(leftTop.x + right + 16, leftTop.y + bottom + 16); }
void TestWindow::MakeTermSettings() { BView* settings = 0; BView* root = 0; BWindow* win = 0; try { // Pick some arbitrary initial frame for the window. BRect initFrame(0,0,100,100); // Create our three objects: the settings view, the top-level view // in the window, and the window itself. settings = GetTermSettings(BMessenger(), BMessage()); root = new BView(initFrame, "root", B_FOLLOW_ALL, B_WILL_DRAW); win = new BWindow(initFrame, "Terminal Settings", B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS); // Set the background color of the root view and add it to the window. root->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); win->AddChild(root); // Set the size and position of the settings view -- inset a little // from the root -- and add it. float fw = be_plain_font->StringWidth("W"); font_height fhs; be_plain_font->GetHeight(&fhs); float fh = fhs.ascent+fhs.descent+fhs.leading; settings->MoveTo(fw, fh); settings->ResizeTo(initFrame.right-fw*2, initFrame.bottom-fh*2); root->AddChild(settings); win->Run(); mTermWin = win; mTermSet = settings; if( root ) { // Send a message to the view with our current global settings. // If the view is an ArpRootView, it will get the message and // know what to do with it. const BMessage* curGlobs = this->root->Globals()->GlobalValues(); if( curGlobs ) { BMessage globals(*curGlobs); globals.what = ARP_PREF_MSG; BMessage ret; mTermSet.SendMessage(&globals, &ret); } } // Get preferred size of settings view, and make final window dimensions // from this. float width=0, height=0; settings->GetPreferredSize(&width, &height); width += fw*2; height += fh*2; float minw=0,minh=0,maxw=0,maxh=0; win->GetSizeLimits(&minw,&maxw,&minh,&maxh); win->SetSizeLimits(width,maxw,height,maxh); BRect frm = Frame(); win->ResizeTo(width, height); BRect cfrm = Frame(); win->MoveTo( frm.left + (frm.Width()-cfrm.Width())/2, frm.top + (frm.Height()-cfrm.Height())/2); win->Show(); mTermWin = win; mTermSet = settings; } catch(...) { delete settings; delete root; delete win; } }