status_t BJoystick::GetButtonNameAt(int32 index, BString *outName) { CALLED(); if (index >= CountButtons()) return B_BAD_INDEX; if (outName == NULL) return B_BAD_VALUE; // TODO: actually retrieve the name from the driver (via a new ioctl) *outName = "Button "; *outName << index; return B_OK; }
/*! 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() }