BButton* BAlert::_CreateButton(int32 which, const char* label) { BMessage* message = new BMessage(kAlertButtonMsg); if (message == NULL) return NULL; message->AddInt32("which", which); BRect rect; rect.top = Bounds().bottom - kBottomOffset; rect.bottom = rect.top; char name[32]; snprintf(name, sizeof(name), "_b%ld_", which); BButton* button = new(std::nothrow) BButton(rect, name, label, message, B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); if (button == NULL) return NULL; float width, height; button->GetPreferredSize(&width, &height); if (fButtonWidth == B_WIDTH_AS_USUAL) { float fontFactor = be_plain_font->Size() / 11.0f; width = max_c(width, kButtonUsualWidth * fontFactor); } button->ResizeTo(width, height); button->MoveBy(0.0f, -height); return button; }
ConfigWindow::ConfigWindow() : BWindow(BRect(100.0, 100.0, 580.0, 540.0), "E-mail", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE), fLastSelectedAccount(NULL), fSaveSettings(false) { // create controls BRect rect(Bounds()); BView *top = new BView(rect, NULL, B_FOLLOW_ALL, 0); top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(top); // determine font height font_height fontHeight; top->GetFontHeight(&fontHeight); int32 height = (int32)(fontHeight.ascent + fontHeight.descent + fontHeight.leading) + 5; rect.InsetBy(5, 5); rect.bottom -= 11 + height; BTabView *tabView = new BTabView(rect, NULL); BView *view; rect = tabView->Bounds(); rect.bottom -= tabView->TabHeight() + 4; tabView->AddTab(view = new BView(rect, NULL, B_FOLLOW_ALL, 0)); tabView->TabAt(0)->SetLabel(B_TRANSLATE("Accounts")); view->SetViewColor(top->ViewColor()); // accounts listview rect = view->Bounds().InsetByCopy(8, 8); rect.right = 140 - B_V_SCROLL_BAR_WIDTH; rect.bottom -= height + 12; fAccountsListView = new AccountsListView(rect); view->AddChild(new BScrollView(NULL, fAccountsListView, B_FOLLOW_ALL, 0, false, true)); rect.right += B_V_SCROLL_BAR_WIDTH; rect.top = rect.bottom + 8; rect.bottom = rect.top + height; BRect sizeRect = rect; sizeRect.right = sizeRect.left + 30 + view->StringWidth( B_TRANSLATE("Add")); view->AddChild(new BButton(sizeRect, NULL, B_TRANSLATE("Add"), new BMessage(kMsgAddAccount), B_FOLLOW_BOTTOM)); sizeRect.left = sizeRect.right+3; sizeRect.right = sizeRect.left + 30 + view->StringWidth( B_TRANSLATE("Remove")); view->AddChild(fRemoveButton = new BButton( sizeRect, NULL, B_TRANSLATE("Remove"), new BMessage(kMsgRemoveAccount), B_FOLLOW_BOTTOM)); // accounts config view rect = view->Bounds(); rect.left = fAccountsListView->Frame().right + B_V_SCROLL_BAR_WIDTH + 16; rect.right -= 10; view->AddChild(fConfigView = new CenterContainer(rect)); MakeHowToView(); // general settings rect = tabView->Bounds(); rect.bottom -= tabView->TabHeight() + 4; tabView->AddTab(view = new CenterContainer(rect)); tabView->TabAt(1)->SetLabel(B_TRANSLATE("Settings")); rect = view->Bounds().InsetByCopy(8, 8); rect.right -= 1; rect.bottom = rect.top + height * 5 + 15; BBox *box = new BBox(rect); box->SetLabel(B_TRANSLATE("Mail checking")); view->AddChild(box); rect = box->Bounds().InsetByCopy(8, 8); rect.top += 7; rect.bottom = rect.top + height + 5; BRect tile = rect.OffsetByCopy(0, 1); int32 labelWidth = (int32)view->StringWidth(B_TRANSLATE("Check every")) + 6; tile.right = 80 + labelWidth; fIntervalControl = new BTextControl(tile, "time", B_TRANSLATE("Check every"), NULL, NULL); fIntervalControl->SetDivider(labelWidth); box->AddChild(fIntervalControl); BPopUpMenu *frequencyPopUp = new BPopUpMenu(B_EMPTY_STRING); const char *frequencyStrings[] = { B_TRANSLATE("never"), B_TRANSLATE("minutes"), B_TRANSLATE("hours"), B_TRANSLATE("days") }; BMenuItem *item; for (int32 i = 0; i < 4; i++) { frequencyPopUp->AddItem(item = new BMenuItem(frequencyStrings[i], new BMessage(kMsgIntervalUnitChanged))); if (i == 1) item->SetMarked(true); } tile.left = tile.right + 5; tile.right = rect.right; tile.OffsetBy(0,-1); fIntervalUnitField = new BMenuField(tile, "frequency", B_EMPTY_STRING, frequencyPopUp); fIntervalUnitField->SetDivider(0.0); box->AddChild(fIntervalUnitField); rect.OffsetBy(0,height + 9); rect.bottom -= 2; fPPPActiveCheckBox = new BCheckBox(rect, "ppp active", B_TRANSLATE("Only when dial-up is connected"), NULL); box->AddChild(fPPPActiveCheckBox); rect.OffsetBy(0,height + 9); rect.bottom -= 2; fPPPActiveSendCheckBox = new BCheckBox(rect, "ppp activesend", B_TRANSLATE("Schedule outgoing mail when dial-up is disconnected"), NULL); box->AddChild(fPPPActiveSendCheckBox); // Miscellaneous settings box rect = box->Frame(); rect.bottom = rect.top + 3 * height + 30; box = new BBox(rect); box->SetLabel(B_TRANSLATE("Miscellaneous")); view->AddChild(box); BPopUpMenu *statusPopUp = new BPopUpMenu(B_EMPTY_STRING); const char *statusModes[] = { B_TRANSLATE("Never"), B_TRANSLATE("While sending"), B_TRANSLATE("While sending and receiving"), B_TRANSLATE("Always") }; BMessage *msg; for (int32 i = 0; i < 4; i++) { statusPopUp->AddItem(item = new BMenuItem(statusModes[i], msg = new BMessage(kMsgShowStatusWindowChanged))); msg->AddInt32("ShowStatusWindow", i); if (i == 0) item->SetMarked(true); } rect = box->Bounds().InsetByCopy(8,8); rect.top += 7; rect.bottom = rect.top + height + 5; labelWidth = (int32)view->StringWidth( B_TRANSLATE("Show connection status window:")) + 8; fStatusModeField = new BMenuField(rect, "show status", B_TRANSLATE("Show connection status window:"), statusPopUp); fStatusModeField->SetDivider(labelWidth); box->AddChild(fStatusModeField); rect = fStatusModeField->Frame();; rect.OffsetBy(0, rect.Height() + 10); BButton *button = new BButton(rect, B_EMPTY_STRING, B_TRANSLATE("Edit mailbox menu…"), msg = new BMessage(B_REFS_RECEIVED)); button->ResizeToPreferred(); box->AddChild(button); button->SetTarget(BMessenger("application/x-vnd.Be-TRAK")); BPath path; find_directory(B_USER_SETTINGS_DIRECTORY, &path); path.Append("Mail/Menu Links"); BEntry entry(path.Path()); if (entry.InitCheck() == B_OK && entry.Exists()) { entry_ref ref; entry.GetRef(&ref); msg->AddRef("refs", &ref); } else button->SetEnabled(false); rect = button->Frame(); rect.OffsetBy(rect.Width() + 30,0); fAutoStartCheckBox = new BCheckBox(rect, "start daemon", B_TRANSLATE("Start mail services on startup"), NULL); fAutoStartCheckBox->ResizeToPreferred(); box->AddChild(fAutoStartCheckBox); // save/revert buttons top->AddChild(tabView); rect = tabView->Frame(); rect.top = rect.bottom + 5; rect.bottom = rect.top + height + 5; BButton *saveButton = new BButton(rect, "apply", B_TRANSLATE("Apply"), new BMessage(kMsgSaveSettings)); float w,h; saveButton->GetPreferredSize(&w, &h); saveButton->ResizeTo(w, h); saveButton->MoveTo(rect.right - w, rect.top); top->AddChild(saveButton); BButton *revertButton = new BButton(rect, "revert", B_TRANSLATE("Revert"), new BMessage(kMsgRevertSettings)); revertButton->GetPreferredSize(&w, &h); revertButton->ResizeTo(w,h); revertButton->MoveTo(saveButton->Frame().left - 25 - w, rect.top); top->AddChild(revertButton); LoadSettings(); // this will also move our window to the stored position fAccountsListView->SetSelectionMessage(new BMessage(kMsgAccountSelected)); fAccountsListView->MakeFocus(true); }
ConfigWindow::ConfigWindow() : BWindow(BRect(200.0, 200.0, 640.0, 640.0), "E-mail", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE), fLastSelectedAccount(NULL), fSaveSettings(false) { /*** create controls ***/ BRect rect(Bounds()); BView *top = new BView(rect,NULL,B_FOLLOW_ALL,0); top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(top); // determine font height font_height fontHeight; top->GetFontHeight(&fontHeight); int32 height = (int32)(fontHeight.ascent + fontHeight.descent + fontHeight.leading) + 5; rect.InsetBy(5,5); rect.bottom -= 11 + height; BTabView *tabView = new BTabView(rect,NULL); BView *view,*generalView; rect = tabView->Bounds(); rect.bottom -= tabView->TabHeight() + 4; tabView->AddTab(view = new BView(rect,NULL,B_FOLLOW_ALL,0)); tabView->TabAt(0)->SetLabel(MDR_DIALECT_CHOICE ("Accounts","アカウント")); view->SetViewColor(top->ViewColor()); // accounts listview rect = view->Bounds().InsetByCopy(8,8); rect.right = 140 - B_V_SCROLL_BAR_WIDTH; rect.bottom -= height + 12; fAccountsListView = new AccountsListView(rect); view->AddChild(new BScrollView(NULL,fAccountsListView,B_FOLLOW_ALL,0,false,true)); rect.right += B_V_SCROLL_BAR_WIDTH; rect.top = rect.bottom + 8; rect.bottom = rect.top + height; BRect sizeRect = rect; sizeRect.right = sizeRect.left + 30 + view->StringWidth(MDR_DIALECT_CHOICE ("Add","追加")); view->AddChild(new BButton(sizeRect,NULL,MDR_DIALECT_CHOICE ("Add","追加"), new BMessage(kMsgAddAccount),B_FOLLOW_BOTTOM)); sizeRect.left = sizeRect.right+3; sizeRect.right = sizeRect.left + 30 + view->StringWidth(MDR_DIALECT_CHOICE ("Remove","削除")); view->AddChild(fRemoveButton = new BButton(sizeRect,NULL,MDR_DIALECT_CHOICE ("Remove","削除"), new BMessage(kMsgRemoveAccount),B_FOLLOW_BOTTOM)); // accounts config view rect = view->Bounds(); rect.left = fAccountsListView->Frame().right + B_V_SCROLL_BAR_WIDTH + 16; rect.right -= 10; view->AddChild(fConfigView = new CenterContainer(rect)); MakeHowToView(); // general settings rect = tabView->Bounds(); rect.bottom -= tabView->TabHeight() + 4; tabView->AddTab(view = new CenterContainer(rect)); tabView->TabAt(1)->SetLabel(MDR_DIALECT_CHOICE ("General","一般")); rect = view->Bounds().InsetByCopy(8,8); rect.right -= 1; rect.bottom = rect.top + height * 5 + 15; BBox *box = new BBox(rect); box->SetLabel(MDR_DIALECT_CHOICE ("Retrieval Frequency","メールチェック間隔")); view->AddChild(box); rect = box->Bounds().InsetByCopy(8,8); rect.top += 7; rect.bottom = rect.top + height + 5; BRect tile = rect.OffsetByCopy(0,1); int32 labelWidth = (int32)view->StringWidth(MDR_DIALECT_CHOICE ("Check every:","メールチェック間隔:"))+6; tile.right = 80 + labelWidth; fIntervalControl = new BTextControl(tile,"time",MDR_DIALECT_CHOICE ("Check every:","メールチェック間隔:"), NULL,NULL); fIntervalControl->SetDivider(labelWidth); box->AddChild(fIntervalControl); BPopUpMenu *frequencyPopUp = new BPopUpMenu(B_EMPTY_STRING); const char *frequencyStrings[] = { MDR_DIALECT_CHOICE ("Never","チェックしない"), MDR_DIALECT_CHOICE ("Minutes","分毎チェック"), MDR_DIALECT_CHOICE ("Hours","時間毎チェック"), MDR_DIALECT_CHOICE ("Days","日間毎チェック")}; BMenuItem *item; for (int32 i = 0;i < 4;i++) { frequencyPopUp->AddItem(item = new BMenuItem(frequencyStrings[i],new BMessage(kMsgIntervalUnitChanged))); if (i == 1) item->SetMarked(true); } tile.left = tile.right + 5; tile.right = rect.right; tile.OffsetBy(0,-1); fIntervalUnitField = new BMenuField(tile,"frequency", B_EMPTY_STRING, frequencyPopUp); fIntervalUnitField->SetDivider(0.0); box->AddChild(fIntervalUnitField); rect.OffsetBy(0,height + 9); rect.bottom -= 2; fPPPActiveCheckBox = new BCheckBox(rect,"ppp active", MDR_DIALECT_CHOICE ("only when PPP is active","PPP接続中時のみ"), NULL); box->AddChild(fPPPActiveCheckBox); rect.OffsetBy(0,height + 9); rect.bottom -= 2; fPPPActiveSendCheckBox = new BCheckBox(rect,"ppp activesend", MDR_DIALECT_CHOICE ("Queue outgoing mail when PPP is inactive","PPP切断時、送信メールを送信箱に入れる"), NULL); box->AddChild(fPPPActiveSendCheckBox); rect = box->Frame(); rect.bottom = rect.top + 4*height + 20; box = new BBox(rect); box->SetLabel(MDR_DIALECT_CHOICE ("Status Window","送受信状況の表示")); view->AddChild(box); BPopUpMenu *statusPopUp = new BPopUpMenu(B_EMPTY_STRING); const char *statusModes[] = { MDR_DIALECT_CHOICE ("Never","表示しない"), MDR_DIALECT_CHOICE ("While Sending","送信時"), MDR_DIALECT_CHOICE ("While Sending / Fetching","送受信時"), MDR_DIALECT_CHOICE ("Always","常に表示")}; BMessage *msg; for (int32 i = 0;i < 4;i++) { statusPopUp->AddItem(item = new BMenuItem(statusModes[i],msg = new BMessage(kMsgShowStatusWindowChanged))); msg->AddInt32("ShowStatusWindow",i); if (i == 0) item->SetMarked(true); } rect = box->Bounds().InsetByCopy(8,8); rect.top += 7; rect.bottom = rect.top + height + 5; labelWidth = (int32)view->StringWidth( MDR_DIALECT_CHOICE ("Show Status Window:","ステータスの表示:")) + 8; fStatusModeField = new BMenuField(rect,"show status", MDR_DIALECT_CHOICE ("Show Status Window:","ステータスの表示:"), statusPopUp); fStatusModeField->SetDivider(labelWidth); box->AddChild(fStatusModeField); BPopUpMenu *lookPopUp = new BPopUpMenu(B_EMPTY_STRING); const char *windowLookStrings[] = { MDR_DIALECT_CHOICE ("Normal, With Tab","タブ付通常"), MDR_DIALECT_CHOICE ("Normal, Border Only","ボーダーのみ通常"), MDR_DIALECT_CHOICE ("Floating","フローティング"), MDR_DIALECT_CHOICE ("Thin Border","細いボーダー"), MDR_DIALECT_CHOICE ("No Border","ボーダー無し")}; for (int32 i = 0;i < 5;i++) { lookPopUp->AddItem(item = new BMenuItem(windowLookStrings[i],msg = new BMessage(kMsgStatusLookChanged))); msg->AddInt32("StatusWindowLook",i); if (i == 0) item->SetMarked(true); } rect.OffsetBy(0, height + 6); fStatusLookField = new BMenuField(rect,"status look", MDR_DIALECT_CHOICE ("Window Look:","ウィンドウ外観:"),lookPopUp); fStatusLookField->SetDivider(labelWidth); box->AddChild(fStatusLookField); BPopUpMenu *workspacesPopUp = new BPopUpMenu(B_EMPTY_STRING); workspacesPopUp->AddItem(item = new BMenuItem( MDR_DIALECT_CHOICE ("Current Workspace","使用中ワークスペース"), msg = new BMessage(kMsgStatusWorkspaceChanged))); msg->AddInt32("StatusWindowWorkSpace", 0); workspacesPopUp->AddItem(item = new BMenuItem( MDR_DIALECT_CHOICE ("All Workspaces","全てのワークスペース"), msg = new BMessage(kMsgStatusWorkspaceChanged))); msg->AddInt32("StatusWindowWorkSpace", -1); rect.OffsetBy(0,height + 6); fStatusWorkspaceField = new BMenuField(rect,"status workspace", MDR_DIALECT_CHOICE ("Window visible on:","表示場所:"),workspacesPopUp); fStatusWorkspaceField->SetDivider(labelWidth); box->AddChild(fStatusWorkspaceField); rect = box->Frame(); rect.bottom = rect.top + 3*height + 13; box = new BBox(rect); box->SetLabel(MDR_DIALECT_CHOICE ("Deskbar Icon","デスクバーアイコンリンク")); view->AddChild(box); rect = box->Bounds().InsetByCopy(8,8); rect.top += 7; rect.bottom = rect.top + height + 5; BStringView *stringView = new BStringView(rect,B_EMPTY_STRING, MDR_DIALECT_CHOICE ( "The menu links are links to folders in a real folder like the Be menu.", "デスクバーで表示する項目の設定")); box->AddChild(stringView); stringView->SetAlignment(B_ALIGN_CENTER); stringView->ResizeToPreferred(); // BStringView::ResizeToPreferred() changes the width, so that the // alignment has no effect anymore stringView->ResizeTo(rect.Width(), stringView->Bounds().Height()); rect.left += 100; rect.right -= 100; rect.OffsetBy(0,height + 1); BButton *button = new BButton(rect,B_EMPTY_STRING, MDR_DIALECT_CHOICE ("Configure Menu Links","メニューリンクの設定"), msg = new BMessage(B_REFS_RECEIVED)); box->AddChild(button); button->SetTarget(BMessenger("application/x-vnd.Be-TRAK")); BPath path; find_directory(B_USER_SETTINGS_DIRECTORY, &path); path.Append("Mail/Menu Links"); BEntry entry(path.Path()); if (entry.InitCheck() == B_OK && entry.Exists()) { entry_ref ref; entry.GetRef(&ref); msg->AddRef("refs", &ref); } else button->SetEnabled(false); rect = box->Frame(); rect.bottom = rect.top + 2*height + 6; box = new BBox(rect); box->SetLabel(MDR_DIALECT_CHOICE ("Misc.","その他の設定")); view->AddChild(box); rect = box->Bounds().InsetByCopy(8,8); rect.top += 7; rect.bottom = rect.top + height + 5; fAutoStartCheckBox = new BCheckBox(rect,"start daemon", MDR_DIALECT_CHOICE ("Auto-Start Mail Daemon","Mail Daemonを自動起動"),NULL); box->AddChild(fAutoStartCheckBox); // about page rect = tabView->Bounds(); rect.bottom -= tabView->TabHeight() + 4; tabView->AddTab(view = new BView(rect,NULL,B_FOLLOW_ALL,0)); tabView->TabAt(2)->SetLabel(MDR_DIALECT_CHOICE ("About","情報")); view->SetViewColor(top->ViewColor()); AboutTextView *about = new AboutTextView(rect); about->SetViewColor(top->ViewColor()); view->AddChild(about); // save/cancel/revert buttons top->AddChild(tabView); rect = tabView->Frame(); rect.top = rect.bottom + 5; rect.bottom = rect.top + height + 5; BButton *saveButton = new BButton(rect,"save", MDR_DIALECT_CHOICE ("Save","保存"), new BMessage(kMsgSaveSettings)); float w,h; saveButton->GetPreferredSize(&w,&h); saveButton->ResizeTo(w,h); saveButton->MoveTo(rect.right - w, rect.top); top->AddChild(saveButton); BButton *cancelButton = new BButton(rect,"cancel", MDR_DIALECT_CHOICE ("Cancel","中止"), new BMessage(kMsgCancelSettings)); cancelButton->GetPreferredSize(&w,&h); cancelButton->ResizeTo(w,h); #ifdef HAVE_APPLY_BUTTON cancelButton->MoveTo(saveButton->Frame().left - w - 5,rect.top); #else cancelButton->MoveTo(saveButton->Frame().left - w - 20,rect.top); #endif top->AddChild(cancelButton); #ifdef HAVE_APPLY_BUTTON BButton *applyButton = new BButton(rect,"apply", MDR_DIALECT_CHOICE ("Apply","適用"), new BMessage(kMsgApplySettings)); applyButton->GetPreferredSize(&w,&h); applyButton->ResizeTo(w,h); applyButton->MoveTo(cancelButton->Frame().left - w - 20,rect.top); top->AddChild(applyButton); #endif BButton *revertButton = new BButton(rect,"revert", MDR_DIALECT_CHOICE ("Revert","復元"), new BMessage(kMsgRevertSettings)); revertButton->GetPreferredSize(&w,&h); revertButton->ResizeTo(w,h); #ifdef HAVE_APPLY_BUTTON revertButton->MoveTo(applyButton->Frame().left - w - 5,rect.top); #else revertButton->MoveTo(cancelButton->Frame().left - w - 6,rect.top); #endif top->AddChild(revertButton); LoadSettings(); fAccountsListView->SetSelectionMessage(new BMessage(kMsgAccountSelected)); }
/*! Tweaks the layout according to the configuration. */ void BAlert::_Prepare() { // Must have at least one button if (CountButtons() == 0) debugger("BAlerts must have at least one button."); float fontFactor = be_plain_font->Size() / 11.0f; if (fIconView->Bitmap() == NULL) fIconView->SetBitmap(_CreateTypeIcon()); if (fButtonWidth == B_WIDTH_AS_USUAL) { float usualWidth = kButtonUsualWidth * fontFactor; for (int32 index = 0; index < CountButtons(); index++) { BButton* button = ButtonAt(index); if (button->MinSize().width < usualWidth) button->SetExplicitSize(BSize(usualWidth, B_SIZE_UNSET)); } } else if (fButtonWidth == B_WIDTH_FROM_WIDEST) { // Get width of widest label float maxWidth = 0; for (int32 index = 0; index < CountButtons(); index++) { BButton* button = ButtonAt(index); float width; button->GetPreferredSize(&width, NULL); if (width > maxWidth) maxWidth = width; } for (int32 index = 0; index < CountButtons(); index++) { BButton* button = ButtonAt(index); button->SetExplicitSize(BSize(maxWidth, B_SIZE_UNSET)); } } if (fButtonSpacing == B_OFFSET_SPACING && CountButtons() > 1) { // Insert some strut fButtonLayout->AddItem(1, BSpaceLayoutItem::CreateHorizontalStrut( kButtonOffsetSpacing * fontFactor)); } // Position the alert so that it is centered vertically but offset a bit // horizontally in the parent window's frame or, if unavailable, the // screen frame. float minWindowWidth = (fButtonSpacing == B_OFFSET_SPACING ? kWindowOffsetMinWidth : kWindowMinWidth) * fontFactor; GetLayout()->SetExplicitMinSize(BSize(minWindowWidth, B_SIZE_UNSET)); ResizeToPreferred(); // Return early if we've already been moved... if (Frame().left != 0 && Frame().right != 0) return; // otherwise center ourselves on-top of parent window/screen BWindow* parent = dynamic_cast<BWindow*>(BLooper::LooperForThread( find_thread(NULL))); const BRect frame = parent != NULL ? parent->Frame() : BScreen(this).Frame(); MoveTo(static_cast<BWindow*>(this)->AlertPosition(frame)); // Hidden by BAlert::AlertPosition() }
void OptionsPanel :: AttachedToWindow( void ) { SetViewColor( ui_color(B_PANEL_BACKGROUND_COLOR) ) ; BRect fr ; if( Parent() ) fr = Parent()->Frame() ; else fr = Window()->Frame() ; fr.top = Frame().top ; fr.right = fr.Width() ; fr.left = 0 ; fr.bottom = fr.top + 5 ; // Set Later MoveTo( fr.left, fr.top ) ; ResizeTo( fr.Width(), fr.Height() ) ; font_height fh ; GetFontHeight( &fh ) ; BRect r ; r.top = 5 ; r.left = fr.Width() * 2/3 ; r.right = r.left + ( r.Height() * 2 ) + 1 ; r.bottom = r.top + 10 ; BButton * addButton = new BButton( r, "Add", "+", new BMessage( Messages::AddPanel ) , B_FOLLOW_RIGHT | B_FOLLOW_TOP ) ; AddChild( addButton ) ; float h , w ; addButton->GetPreferredSize( &h, &w ) ; if( h > w ) h = w ; else w = h ; addButton->ResizeTo( w, h ) ; r.left += ( w + 4 ) ; r.right += ( w + 4 ) ; BButton * rmButton = new BButton( r, "Remove", "-", new BMessage( Messages::RemovePanel ) , B_FOLLOW_RIGHT | B_FOLLOW_TOP ) ; AddChild( rmButton ) ; rmButton->ResizeTo( w, h ) ; r.left = 10 ; r.top = addButton->Frame().bottom + 2 ; r.right = r.left + 10 ; r.bottom = r.top + 10 ; fpMaxDepthCheck = new BCheckBox( r, "depth_check", kMaxDepthString , NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP ) ; AddChild( fpMaxDepthCheck ) ; fpMaxDepthCheck->ResizeToPreferred() ; r = fpMaxDepthCheck->Frame() ; float centre = r.top + r.Height()/2 ; r.left = r.right + 5 ; r.top = centre - (fh.ascent + fh.descent + fh.leading) * 3/4 ; r.bottom = centre + (fh.ascent + fh.descent + fh.leading) * 3/4 ; r.right = r.left + StringWidth( "xx37xx" ) ; fpMaxDepthEdit = new EditBox( r, "depth_edit", B_FOLLOW_LEFT | B_FOLLOW_TOP ) ; AddChild( fpMaxDepthEdit ) ; r.top = r.bottom + 7 ; r.bottom = r.top + 20 ; r.left = 10 ; r.right = r.left + 50 ; BButton * settingsButton = new BButton( r, "settings", "Settings" B_UTF8_ELLIPSIS, new BMessage( Messages::Settings ) , B_FOLLOW_LEFT | B_FOLLOW_TOP ) ; AddChild( settingsButton ) ; settingsButton->ResizeToPreferred() ; settingsButton->SetTarget( Window() ) ; r.right = fr.Width() - 25 ; r.left = r.right - 50 ; fpFindButton = new BButton( r, "go", "Find", new BMessage( Messages::StartFind ) , B_FOLLOW_RIGHT | B_FOLLOW_TOP ) ; AddChild( fpFindButton ) ; fpFindButton->ResizeToPreferred() ; r = fpFindButton->Frame() ; fpFindButton->MoveTo( fr.Width() - 20 - r.Width(), r.top ) ; fpFindButton->SetTarget( Window() ) ; fpFindButton->MakeDefault(true) ; r = fpFindButton->Frame() ; r.bottom = r.top - 3 ; r.top = r.bottom - 8 ; fpPoleFrame = new ColouredView( r, "pole_frame" ) ; fpPoleFrame->SetViewColor( Colours::Grey60 ) ; AddChild( fpPoleFrame ) ; r.OffsetTo( 1 , 1 ) ; fpBarberPole = new BarberPole( r, "pole", B_FOLLOW_RIGHT | B_FOLLOW_TOP ) ; fpBarberPole->SetHighColor( WaitBarDisabledHighColor ) ; fpBarberPole->SetLowColor ( WaitBarDisabledLowColor ) ; fpPoleFrame->AddChild( fpBarberPole ) ; fpPoleFrame->Hide() ; r = fpFindButton->Frame() ; fr.bottom = fr.top + r.bottom + 8 ; ResizeTo( fr.Width(), fr.Height() ) ; fr = addButton->Frame() ; addButton->MoveTo( r.left + 10, fr.top ) ; rmButton ->MoveTo( r.left + 17 + fr.Width(), fr.top ) ; }
// -------------------------------------------------- JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName) : HWindow(BRect(0, 0, 320, 160), "Job Setup", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE) { fSetupMsg = msg; fExitSem = create_sem(0, "JobSetup"); fResult = B_ERROR; if (printerName) { BString title; title << printerName << " Job Setup"; SetTitle(title.String()); fPrinterName = printerName; } // ---- Ok, build a default job setup user interface BRect r; BBox *panel; BBox *line; BButton *ok; BButton *cancel; BStringView *sv; float x, y, w, h; float indent; int32 copies; int32 firstPage; int32 lastPage; bool allPages; char buffer[80]; // PrinterDriver ensures that property exists fSetupMsg->FindInt32("copies", &copies); fSetupMsg->FindInt32("first_page", &firstPage); fSetupMsg->FindInt32("last_page", &lastPage); BMessage doc_info; if (B_OK != fSetupMsg->FindMessage("doc_info", &doc_info)) { // default fields doc_info.AddString("Author", ""); doc_info.AddString("Subject", ""); doc_info.AddString("Keywords", ""); fSetupMsg->AddMessage("doc_info", &doc_info); } AddFields(&fDocInfo, fSetupMsg, NULL, includeKeys); allPages = firstPage == 1 && lastPage == MAX_INT32; r = Bounds(); // add a *dialog* background panel = new BBox(r, "top_panel", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER); const int kMargin = 6; //const char *kCopiesLabel = "Copies:"; const char *kCopiesLabelExtraSpace = "Copies:##"; const char *kPagesRangeLabel = "Pages:"; const char *kAllPagesLabel = "All"; const char *kPagesRangeSelectionLabel = ""; const char *kFromLabel = "From:"; const char *kFromLabelExtraSpace = "From:##"; const char *kToLabel = "To:"; const char *kToLabelExtraSpace = "To:##"; r = panel->Bounds(); x = r.left + kMargin; y = r.top + kMargin; // add a "copies" input field /* Simon: temporarily removed this code sprintf(buffer, "%d", (int)copies); fCopies = new BTextControl(BRect(x, y, x+100, y+20), "copies", kCopiesLabel, buffer, new BMessage(NB_COPIES_MSG)); fCopies->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT); fCopies->ResizeToPreferred(); fCopies->GetPreferredSize(&w, &h); panel->AddChild(fCopies); y += h + kMargin; // "new line" */ // add a "pages" label sv = new BStringView(BRect(x, y, x+100, y+20), "pages_range", kPagesRangeLabel); panel->AddChild(sv); sv->ResizeToPreferred(); sv->GetPreferredSize(&w, &h); // align "copies" textcontrol field on the "allPages" radiobutton bellow... indent = be_plain_font->StringWidth(kCopiesLabelExtraSpace); w += kMargin; if ( w > indent ) indent = w; // fCopies->SetDivider(indent); x += indent; // add a "all" radiobutton fAll = new BRadioButton(BRect(x, y, x+100, y+20), "all_pages", kAllPagesLabel, new BMessage(ALL_PAGES_MGS)); fAll->ResizeToPreferred(); fAll->GetPreferredSize(&w, &h); fAll->SetValue(allPages); panel->AddChild(fAll); y += h + kMargin; // "new line" // add a range selection raddiobutton fRange = new BRadioButton(BRect(x, y, x+100, y+20), "pages_range_selection", kPagesRangeSelectionLabel, new BMessage(RANGE_SELECTION_MSG)); fRange->ResizeToPreferred(); fRange->GetPreferredSize(&w, &h); fRange->SetValue(!allPages); panel->AddChild(fRange); x += w + kMargin; // add a "from" field if (allPages) { buffer[0] = 0; } else { sprintf(buffer, "%d", (int)firstPage); } fFrom = new BTextControl(BRect(x, y, x+100, y+20), "from_field", kFromLabel, buffer, new BMessage(RANGE_FROM_MSG)); fFrom->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT); fFrom->SetDivider(be_plain_font->StringWidth(kFromLabelExtraSpace)); fFrom->ResizeToPreferred(); fFrom->GetPreferredSize(&w, &h); panel->AddChild(fFrom); x += w + kMargin; // add a "to" field if (allPages) { buffer[0] = 0; } else { sprintf(buffer, "%d", (int)lastPage); } fTo = new BTextControl(BRect(x, y, x+100, y+20), "to_field", kToLabel, buffer, new BMessage(RANGE_TO_MSG)); fTo->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT); fTo->SetDivider(be_plain_font->StringWidth(kToLabelExtraSpace)); fTo->ResizeToPreferred(); fTo->GetPreferredSize(&w, &h); panel->AddChild(fTo); y += h + kMargin + kMargin; // "new line" x = r.left + kMargin; // add a separator line... line = new BBox(BRect(r.left, y - 1, r.right, y), NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP ); panel->AddChild(line); y += 2 + kMargin + kMargin; // "new line" // add a "OK" button, and make it default ok = new BButton(BRect(x, y, x+100, y+20), NULL, "OK", new BMessage(OK_MSG), B_FOLLOW_RIGHT | B_FOLLOW_TOP); ok->MakeDefault(true); ok->ResizeToPreferred(); ok->GetPreferredSize(&w, &h); x = r.right - w - kMargin; ok->MoveTo(x, ok->Frame().top); // put the ok bottom at bottom right corner panel->AddChild(ok); // add a "Cancel" button cancel = new BButton(BRect(x, y, x + 100, y + 20), NULL, "Cancel", new BMessage(CANCEL_MSG), B_FOLLOW_RIGHT | B_FOLLOW_TOP); cancel->ResizeToPreferred(); cancel->GetPreferredSize(&w, &h); cancel->MoveTo(x - w - kMargin, y); // put cancel button left next the ok button panel->AddChild(cancel); // add a "DocInfo" button BButton *button = new BButton(r, NULL, "Doc Info", new BMessage(DOC_INFO_MSG), B_FOLLOW_RIGHT | B_FOLLOW_TOP); button->GetPreferredSize(&w, &h); button->ResizeToPreferred(); button->MoveTo(8, y); panel->AddChild(button); // Finally, add our panel to window AddChild(panel); // Auto resize window ResizeTo(ok->Frame().right + kMargin, ok->Frame().bottom + kMargin); }
// -------------------------------------------------------------- NetworkSetupWindow::NetworkSetupWindow(const char *title) : BWindow(BRect(100, 100, 600, 600), title, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS) { BMenu *show_menu; BMenu *profiles_menu; BMenuField *menu_field; BBox *top_box, *bottom_box, *line; // *group BButton *button; BCheckBox *check; BRect r; float x, w, h; float size, min_size = 360; // TODO: cleanup this mess! show_menu = new BPopUpMenu("<please select me!>"); _BuildShowMenu(show_menu, SHOW_MSG); #define H_MARGIN 10 #define V_MARGIN 10 #define SMALL_MARGIN 3 // Resize the window to minimal width ResizeTo(fMinAddonViewRect.Width() + 2 * H_MARGIN, Bounds().Height()); top_box = new BBox(Bounds(), NULL, B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER); AddChild(top_box); r = top_box->Bounds(); r.InsetBy(H_MARGIN, V_MARGIN); // ---- Profiles section profiles_menu = new BPopUpMenu("<none>"); menu_field = new BMenuField(r, "profiles_menu", PROFILE_LABEL, profiles_menu); menu_field->SetFont(be_bold_font); menu_field->SetDivider(be_bold_font->StringWidth(PROFILE_LABEL "#")); top_box->AddChild(menu_field); menu_field->ResizeToPreferred(); menu_field->GetPreferredSize(&w, &h); size = w; button = new BButton(r, "manage_profiles", MANAGE_PROFILES_LABEL, new BMessage(MANAGE_PROFILES_MSG), B_FOLLOW_TOP | B_FOLLOW_RIGHT); button->GetPreferredSize(&w, &h); button->ResizeToPreferred(); button->MoveTo(r.right - w, r.top); top_box->AddChild(button); size += SMALL_MARGIN + w; min_size = max_c(min_size, (H_MARGIN + size + H_MARGIN)); r.top += h + V_MARGIN; // ---- Separator line between Profiles section and Settings section line = new BBox(BRect(r.left, r.top, r.right, r.top + 1), NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP ); top_box->AddChild(line); _BuildProfilesMenu(profiles_menu, SELECT_PROFILE_MSG); r.top += 2 + V_MARGIN; // ---- Settings section // Make the show popup field half the whole width and centered menu_field = new BMenuField(r, "show_menu", SHOW_LABEL, show_menu); menu_field->SetFont(be_bold_font); menu_field->SetDivider(be_bold_font->StringWidth(SHOW_LABEL "#")); top_box->AddChild(menu_field); menu_field->ResizeToPreferred(); menu_field->GetPreferredSize(&w, &h); r.top += h+1 + V_MARGIN; min_size = max_c(min_size, (H_MARGIN + w + H_MARGIN)); r = fMinAddonViewRect.OffsetByCopy(H_MARGIN, r.top); fPanel = new BBox(r, "showview_box", B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER); top_box->AddChild(fPanel); top_box->ResizeTo(Bounds().Width(), r.bottom + 1 + V_MARGIN); // ---- Bottom globals buttons section r = Bounds(); r.top = top_box->Frame().bottom + 1; bottom_box = new BBox(r, NULL, B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER); AddChild(bottom_box); r.OffsetTo(0, 0); r.InsetBy(H_MARGIN, V_MARGIN); check = new BCheckBox(r, "dont_touch", DONT_TOUCH_LABEL, new BMessage(DONT_TOUCH_MSG), B_FOLLOW_TOP | B_FOLLOW_LEFT); check->GetPreferredSize(&w, &h); check->ResizeToPreferred(); check->SetValue(B_CONTROL_ON); check->MoveTo(H_MARGIN, r.top); bottom_box->AddChild(check); size = w; button = new BButton(r, "apply_now", APPLY_NOW_LABEL, new BMessage(APPLY_NOW_MSG), B_FOLLOW_TOP | B_FOLLOW_RIGHT); button->GetPreferredSize(&w, &h); button->ResizeToPreferred(); x = r.right - w; button->MoveTo(x, r.top); bottom_box->AddChild(button); fApplyNowButton = button; size += SMALL_MARGIN + w; button = new BButton(r, "revert", REVERT_LABEL, new BMessage(REVERT_MSG), B_FOLLOW_TOP | B_FOLLOW_RIGHT); button->GetPreferredSize(&w, &h); button->ResizeToPreferred(); button->MoveTo(x - w - SMALL_MARGIN, r.top); bottom_box->AddChild(button); fRevertButton = button; fRevertButton->SetEnabled(false); size += SMALL_MARGIN + w; min_size = max_c(min_size, (H_MARGIN + size + H_MARGIN)); r.bottom = r.top + h; r.InsetBy(-H_MARGIN, -V_MARGIN); bottom_box->ResizeTo(Bounds().Width(), r.Height()); // Resize window to enclose top and bottom boxes ResizeTo(Bounds().Width(), bottom_box->Frame().bottom); // Enable boxes resizing modes top_box->SetResizingMode(B_FOLLOW_ALL); fPanel->SetResizingMode(B_FOLLOW_ALL); bottom_box->SetResizingMode(B_FOLLOW_BOTTOM | B_FOLLOW_LEFT_RIGHT); // Set default/minimal window size ResizeTo(min_size, Bounds().Height()); SetSizeLimits(min_size, 20000, Bounds().Height(), 20000); fAddonView = NULL; }