BButton* ScreenWindow::_CreateColumnRowButton(bool columns, bool plus) { BMessage* message = new BMessage(kMsgWorkspaceLayoutChanged); message->AddInt32("delta_x", columns ? (plus ? 1 : -1) : 0); message->AddInt32("delta_y", !columns ? (plus ? 1 : -1) : 0); BButton* button = new BButton(plus ? "+" : "-", message); button->SetFontSize(be_plain_font->Size() * 0.9); BSize size = button->MinSize(); size.width = button->StringWidth("+") + 16; button->SetExplicitMinSize(size); button->SetExplicitMaxSize(size); fWorkspacesButtons[(columns ? 0 : 2) + (plus ? 1 : 0)] = button; return button; }
/*! 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() }