本文整理汇总了C++中BButton::GetPreferredSize方法的典型用法代码示例。如果您正苦于以下问题:C++ BButton::GetPreferredSize方法的具体用法?C++ BButton::GetPreferredSize怎么用?C++ BButton::GetPreferredSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BButton
的用法示例。
在下文中一共展示了BButton::GetPreferredSize方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BMessage
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;
}
示例2: rect
//.........这里部分代码省略.........
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);
}
示例3: rect
//.........这里部分代码省略.........
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));
}
示例4: ButtonAt
/*! 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()
}
示例5: BMessage
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 ;
//.........这里部分代码省略.........
示例6: BMessage
// --------------------------------------------------
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;
//.........这里部分代码省略.........
示例7: BMessage
// --------------------------------------------------------------
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);
//.........这里部分代码省略.........