FrissWindow::FrissWindow(FrissConfig* config, XmlNode* theList, BRect frame, const char* Title) : BWindow(frame, Title, B_TITLED_WINDOW, B_FRAME_EVENTS | B_AUTO_UPDATE_SIZE_LIMITS) { SetLayout(new BGroupLayout(B_VERTICAL)); BGridView* background = new BGridView("background"); background->GridLayout()->SetSpacing(0, 0); background->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(background); feedList = new BListView("feedlist", B_SINGLE_SELECTION_LIST); myf = new FrissView(config, theList); /* Nun noch den Dragger einbauen. * B_ORIGIN scheint unten rechts zu sein, also noch entsprechend * die linke obere Ecke setzen (ich wusste vorher auch nicht, dass * der Dragger 7x7 Pixel groß ist :-) */ BDragger* myd = new BDragger(myf, B_WILL_DRAW ); myd->SetExplicitMaxSize(BSize(7, 7)); BGridLayoutBuilder(background) .SetInsets(7, 7, 0, 0) .Add(new BScrollView("scroll", feedList, 0, false, true), 0, 0) .Add(myf, 1, 0) .Add(myd, 2, 1); background->GridLayout()->SetColumnWeight(0, 0.4); background->GridLayout()->SetMaxColumnWidth(0, 200); BMessage* m = new BMessage(msg_SelFeed); feedList->SetSelectionMessage(m); m = new BMessage(msg_EditFeed); feedList->SetInvocationMessage(m); PopulateFeeds(theList); }
KeyRequestView() : BView("KeyRequestView", B_WILL_DRAW), fPassword(NULL) { SetViewUIColor(B_PANEL_BACKGROUND_COLOR); BGroupLayout* rootLayout = new(std::nothrow) BGroupLayout(B_VERTICAL); if (rootLayout == NULL) return; SetLayout(rootLayout); BGridView* controls = new(std::nothrow) BGridView(); if (controls == NULL) return; BGridLayout* layout = controls->GridLayout(); float inset = ceilf(be_plain_font->Size() * 0.7); rootLayout->SetInsets(inset, inset, inset, inset); rootLayout->SetSpacing(inset); layout->SetSpacing(inset, inset); BStringView* label = new(std::nothrow) BStringView("keyringLabel", B_TRANSLATE("Keyring:")); if (label == NULL) return; int32 row = 0; layout->AddView(label, 0, row); fKeyringName = new(std::nothrow) BStringView("keyringName", ""); if (fKeyringName == NULL) return; layout->AddView(fKeyringName, 1, row++); fPassword = new(std::nothrow) BTextControl(B_TRANSLATE("Password:"******"", NULL); if (fPassword == NULL) return; BLayoutItem* layoutItem = fPassword->CreateTextViewLayoutItem(); layoutItem->SetExplicitMinSize(BSize(fPassword->StringWidth( "0123456789012345678901234567890123456789") + inset, B_SIZE_UNSET)); layout->AddItem(fPassword->CreateLabelLayoutItem(), 0, row); layout->AddItem(layoutItem, 1, row++); BGroupView* buttons = new(std::nothrow) BGroupView(B_HORIZONTAL); if (buttons == NULL) return; fCancelButton = new(std::nothrow) BButton(B_TRANSLATE("Cancel"), new BMessage(kMessageCancel)); buttons->GroupLayout()->AddView(fCancelButton); buttons->GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue()); fUnlockButton = new(std::nothrow) BButton(B_TRANSLATE("Unlock"), new BMessage(kMessageUnlock)); buttons->GroupLayout()->AddView(fUnlockButton); BTextView* message = new(std::nothrow) BTextView("message"); message->SetText(B_TRANSLATE("An application wants to access the " "keyring below, but it is locked with a passphrase. Please enter " "the passphrase to unlock the keyring.\n" "If you unlock the keyring, it stays unlocked until the system is " "shut down or the keyring is manually locked again.\n" "If you cancel this dialog the keyring will remain locked.")); message->SetViewUIColor(B_PANEL_BACKGROUND_COLOR); rgb_color textColor = ui_color(B_PANEL_TEXT_COLOR); message->SetFontAndColor(be_plain_font, B_FONT_ALL, &textColor); message->MakeEditable(false); message->MakeSelectable(false); message->SetWordWrap(true); rootLayout->AddView(message); rootLayout->AddView(controls); rootLayout->AddView(buttons); }
EthernetSettingsView::EthernetSettingsView() : BView("EthernetSettingsView", 0, NULL), fCurrentSettings(NULL) { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fSocket = socket(AF_INET, SOCK_DGRAM, 0); _GatherInterfaces(); // build the GUI BGroupLayout* rootLayout = new BGroupLayout(B_VERTICAL); SetLayout(rootLayout); BGridView* controlsGroup = new BGridView(); BGridLayout* layout = controlsGroup->GridLayout(); // insets float inset = ceilf(be_plain_font->Size() * 0.7); rootLayout->SetInsets(inset, inset, inset, inset); rootLayout->SetSpacing(inset); layout->SetSpacing(inset, inset); BPopUpMenu* deviceMenu = new BPopUpMenu(B_TRANSLATE("<no adapter>")); for (int32 i = 0; i < fInterfaces.CountItems(); i++) { BString& name = *fInterfaces.ItemAt(i); BString label = name; BMessage* info = new BMessage(kMsgInfo); info->AddString("interface", name.String()); BMenuItem* item = new BMenuItem(label.String(), info); deviceMenu->AddItem(item); } BPopUpMenu* modeMenu = new BPopUpMenu("modes"); modeMenu->AddItem(new BMenuItem(B_TRANSLATE("Static"), new BMessage(kMsgStaticMode))); modeMenu->AddItem(new BMenuItem(B_TRANSLATE("DHCP"), new BMessage(kMsgDHCPMode))); modeMenu->AddSeparatorItem(); modeMenu->AddItem(new BMenuItem(B_TRANSLATE("Disabled"), new BMessage(kMsgDisabledMode))); BPopUpMenu* networkMenu = new BPopUpMenu("networks"); fDeviceMenuField = new BMenuField(B_TRANSLATE("Adapter:"), deviceMenu); layout->AddItem(fDeviceMenuField->CreateLabelLayoutItem(), 0, 0); layout->AddItem(fDeviceMenuField->CreateMenuBarLayoutItem(), 1, 0); fNetworkMenuField = new BMenuField(B_TRANSLATE("Network:"), networkMenu); layout->AddItem(fNetworkMenuField->CreateLabelLayoutItem(), 0, 1); layout->AddItem(fNetworkMenuField->CreateMenuBarLayoutItem(), 1, 1); fTypeMenuField = new BMenuField(B_TRANSLATE("Mode:"), modeMenu); layout->AddItem(fTypeMenuField->CreateLabelLayoutItem(), 0, 2); layout->AddItem(fTypeMenuField->CreateMenuBarLayoutItem(), 1, 2); fIPTextControl = new BTextControl(B_TRANSLATE("IP address:"), "", NULL); SetupTextControl(fIPTextControl); BLayoutItem* layoutItem = fIPTextControl->CreateTextViewLayoutItem(); layoutItem->SetExplicitMinSize(BSize( fIPTextControl->StringWidth("XXX.XXX.XXX.XXX") + inset, B_SIZE_UNSET)); layout->AddItem(fIPTextControl->CreateLabelLayoutItem(), 0, 3); layout->AddItem(layoutItem, 1, 3); fNetMaskTextControl = new BTextControl(B_TRANSLATE("Netmask:"), "", NULL); SetupTextControl(fNetMaskTextControl); layout->AddItem(fNetMaskTextControl->CreateLabelLayoutItem(), 0, 4); layout->AddItem(fNetMaskTextControl->CreateTextViewLayoutItem(), 1, 4); fGatewayTextControl = new BTextControl(B_TRANSLATE("Gateway:"), "", NULL); SetupTextControl(fGatewayTextControl); layout->AddItem(fGatewayTextControl->CreateLabelLayoutItem(), 0, 5); layout->AddItem(fGatewayTextControl->CreateTextViewLayoutItem(), 1, 5); // TODO: Replace the DNS text controls by a BListView with add/remove // functionality and so on... fPrimaryDNSTextControl = new BTextControl(B_TRANSLATE("DNS #1:"), "", NULL); SetupTextControl(fPrimaryDNSTextControl); layout->AddItem(fPrimaryDNSTextControl->CreateLabelLayoutItem(), 0, 6); layout->AddItem(fPrimaryDNSTextControl->CreateTextViewLayoutItem(), 1, 6); fSecondaryDNSTextControl = new BTextControl(B_TRANSLATE("DNS #2:"), "", NULL); SetupTextControl(fSecondaryDNSTextControl); layout->AddItem(fSecondaryDNSTextControl->CreateLabelLayoutItem(), 0, 7); layout->AddItem(fSecondaryDNSTextControl->CreateTextViewLayoutItem(), 1, 7); fDomainTextControl = new BTextControl(B_TRANSLATE("Domain:"), "", NULL); SetupTextControl(fDomainTextControl); layout->AddItem(fDomainTextControl->CreateLabelLayoutItem(), 0, 8); layout->AddItem(fDomainTextControl->CreateTextViewLayoutItem(), 1, 8); fErrorMessage = new BStringView("error", ""); fErrorMessage->SetAlignment(B_ALIGN_LEFT); fErrorMessage->SetFont(be_bold_font); fErrorMessage->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); layout->AddView(fErrorMessage, 1, 9); // button group (TODO: move to window, but take care of // enabling/disabling) BGroupView* buttonGroup = new BGroupView(B_HORIZONTAL); fRevertButton = new BButton(B_TRANSLATE("Revert"), new BMessage(kMsgRevert)); fRevertButton->SetEnabled(false); buttonGroup->GroupLayout()->AddView(fRevertButton); buttonGroup->GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue()); fApplyButton = new BButton(B_TRANSLATE("Apply"), new BMessage(kMsgApply)); fApplyButton->SetEnabled(false); buttonGroup->GroupLayout()->AddView(fApplyButton); rootLayout->AddView(controlsGroup); rootLayout->AddView(buttonGroup); }
void PageSetupView::AttachedToWindow() { BMenuItem *item = NULL; bool marked; int count; // margin MarginUnit units = fJobData->GetMarginUnit(); BRect paper = fJobData->GetPaperRect(); BRect margin = fJobData->GetPrintableRect(); // re-calculate the margin from the printable rect in points margin.top -= paper.top; margin.left -= paper.left; margin.right = paper.right - margin.right; margin.bottom = paper.bottom - margin.bottom; fMarginView = new MarginView( paper.IntegerWidth(), paper.IntegerHeight(), margin, units); // paper selection marked = false; fPaper = new BPopUpMenu("paperSize"); fPaper->SetRadioMode(true); count = fPrinterCap->CountCap(PrinterCap::kPaper); PaperCap **paper_cap = (PaperCap **)fPrinterCap->GetCaps(PrinterCap::kPaper); while (count--) { BMessage *msg = new BMessage(kMsgPaperChanged); msg->AddPointer("paperCap", *paper_cap); item = new BMenuItem((*paper_cap)->fLabel.c_str(), msg); fPaper->AddItem(item); item->SetTarget(this); if ((*paper_cap)->fPaper == fJobData->GetPaper()) { item->SetMarked(true); marked = true; } paper_cap++; } if (!marked) item->SetMarked(true); BMenuField* paperSize = new BMenuField("paperSize", "Paper size:", fPaper); // orientation fOrientation = new BPopUpMenu("orientation"); fOrientation->SetRadioMode(true); BMenuField* orientation = new BMenuField("orientation", "Orientation:", fOrientation); count = fPrinterCap->CountCap(PrinterCap::kOrientation); if (count == 0) { AddOrientationItem("Portrait", JobData::kPortrait); AddOrientationItem("Landscape", JobData::kLandscape); } else { OrientationCap **orientation_cap = (OrientationCap **)fPrinterCap->GetCaps(PrinterCap::kOrientation); while (count--) { AddOrientationItem((*orientation_cap)->fLabel.c_str(), (*orientation_cap)->fOrientation); orientation_cap++; } } // resolution marked = false; fResolution = new BPopUpMenu("resolution"); fResolution->SetRadioMode(true); count = fPrinterCap->CountCap(PrinterCap::kResolution); ResolutionCap **resolution_cap = (ResolutionCap **)fPrinterCap->GetCaps(PrinterCap::kResolution); while (count--) { item = new BMenuItem((*resolution_cap)->fLabel.c_str(), NULL); fResolution->AddItem(item); item->SetTarget(this); if (((*resolution_cap)->fXResolution == fJobData->GetXres()) && ((*resolution_cap)->fYResolution == fJobData->GetYres())) { item->SetMarked(true); marked = true; } resolution_cap++; } if (!marked) item->SetMarked(true); BMenuField* resolution = new BMenuField("resolution", "Resolution:", fResolution); // scale BString scale; scale << (int)fJobData->GetScaling(); fScaling = new BTextControl("scale", "Scale [%]:", scale.String(), NULL); int num; for (num = 0; num <= 255; num++) { fScaling->TextView()->DisallowChar(num); } for (num = 0; num <= 9; num++) { fScaling->TextView()->AllowChar('0' + num); } fScaling->TextView()->SetMaxBytes(3); // cancel and ok BButton* cancel = new BButton("cancel", "Cancel", new BMessage(kMsgCancel)); BButton* ok = new BButton("ok", "OK", new BMessage(kMsgOK)); ok->MakeDefault(true); BGridView* settings = new BGridView(); BGridLayout* settingsLayout = settings->GridLayout(); settingsLayout->AddItem(paperSize->CreateLabelLayoutItem(), 0, 0); settingsLayout->AddItem(paperSize->CreateMenuBarLayoutItem(), 1, 0); settingsLayout->AddItem(orientation->CreateLabelLayoutItem(), 0, 1); settingsLayout->AddItem(orientation->CreateMenuBarLayoutItem(), 1, 1); settingsLayout->AddItem(resolution->CreateLabelLayoutItem(), 0, 2); settingsLayout->AddItem(resolution->CreateMenuBarLayoutItem(), 1, 2); settingsLayout->AddItem(fScaling->CreateLabelLayoutItem(), 0, 3); settingsLayout->AddItem(fScaling->CreateTextViewLayoutItem(), 1, 3); settingsLayout->SetSpacing(0, 0); SetLayout(new BGroupLayout(B_VERTICAL)); AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) .AddGroup(B_HORIZONTAL, 5, 1.0f) .AddGroup(B_VERTICAL, 0, 1.0f) .Add(fMarginView) .AddGlue() .End() .AddGroup(B_VERTICAL, 0, 1.0f) .Add(settings) .AddGlue() .End() .End() .AddGroup(B_HORIZONTAL, 10, 1.0f) .AddGlue() .Add(cancel) .Add(ok) .End() .SetInsets(10, 10, 10, 10) ); }
int main(int argc, char** argv) { BApplication app("application/x-vnd.antares-look"); BWindow* window = new Window(BRect(50, 50, 100, 100), "Look at these pretty controls!", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS | B_QUIT_ON_WINDOW_CLOSE); window->SetLayout(new BGroupLayout(B_HORIZONTAL)); // create some controls // BListView BListView* listView = new BListView(); for (int32 i = 0; i < 20; i++) { BString itemLabel("List item "); itemLabel << i + 1; listView->AddItem(new BStringItem(itemLabel.String())); } BScrollView* scrollView = new BScrollView("scroller", listView, 0, true, true); scrollView->SetExplicitMinSize(BSize(300, 140)); // BColumnListView BColumnListView* columnListView = new BColumnListView("clv", 0, B_FANCY_BORDER); // for (int32 i = 0; i < 20; i++) { // BString itemLabel("List Item "); // itemLabel << i + 1; // columnListView->AddItem(new BStringItem(itemLabel.String())); // } BGridView* controls = new BGridView(kInset, kInset); BGridLayout* layout = controls->GridLayout(); controls->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED)); int32 row = 0; add_controls<BButton>(layout, row); add_controls<BCheckBox>(layout, row); add_controls<BRadioButton>(layout, row); add_menu_fields(layout, row); add_text_controls(layout, row); add_sliders(layout, row); add_status_bars(layout, row); BColorControl* colorControl = new BColorControl(B_ORIGIN, B_CELLS_32x8, 8.0f, "color control"); layout->AddView(colorControl, 0, row, 4); BTabView* tabView = new BTabView("tab view", B_WIDTH_FROM_WIDEST); BView* content = BGroupLayoutBuilder(B_VERTICAL, kInset) .Add(scrollView) .Add(columnListView) .Add(controls) .SetInsets(kInset, kInset, kInset, kInset); content->SetName("Tab 1"); tabView->AddTab(content); BView* tab2 = new BView("Tab 2", 0); tab2->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); tabView->AddTab(tab2); tabView->AddTab(new BView("Tab 3", 0)); BMenuBar* menuBar = new BMenuBar("menu bar"); BMenu* menu = new BMenu("File"); menu->AddItem(new BMenuItem("Test Open BFilePanel", new BMessage(MSG_TEST_OPEN_FILE_PANEL))); menu->AddItem(new BMenuItem("Test Save BFilePanel", new BMessage(MSG_TEST_SAVE_FILE_PANEL))); menu->AddItem(new BMenuItem("Click me!", NULL)); menu->AddItem(new BMenuItem("Another option", NULL)); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED))); menuBar->AddItem(menu); menu = new BMenu("Edit"); menu->SetEnabled(false); menu->AddItem(new BMenuItem("Cut", NULL)); menu->AddItem(new BMenuItem("Copy", NULL)); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem("Past", NULL)); menuBar->AddItem(menu); menu = new BMenu("One Item"); menu->AddItem(new BMenuItem("Only", NULL)); menuBar->AddItem(menu); menu = new BMenu("Sub Menu"); BMenu* subMenu = new BMenu("Click me"); subMenu->AddItem(new BMenuItem("Either", NULL)); subMenu->AddItem(new BMenuItem("Or", NULL)); subMenu->SetRadioMode(true); menu->AddItem(subMenu); menuBar->AddItem(menu); BButton* okButton = new BButton("OK", new BMessage(B_QUIT_REQUESTED)); window->AddChild(BGroupLayoutBuilder(B_VERTICAL) .Add(menuBar) .Add(BGroupLayoutBuilder(B_VERTICAL, kInset) .Add(tabView) .Add(BGroupLayoutBuilder(B_HORIZONTAL, kInset) .Add(new BButton("Revert", new BMessage(MSG_TOGGLE_LOOK))) .Add(BSpaceLayoutItem::CreateGlue()) .Add(new BButton("Cancel", NULL)) .Add(okButton) ) .SetInsets(kInset, kInset, kInset, kInset) ) ); window->SetDefaultButton(okButton); window->Show(); app.Run(); return 0; }
TPrefsWindow::TPrefsWindow(BRect rect, BFont* font, int32* level, bool* wrap, bool* attachAttributes, bool* cquotes, int32* account, int32* replyTo, char** preamble, char** sig, uint32* encoding, bool* warnUnencodable, bool* spellCheckStartOn, bool* autoMarkRead, uint8* buttonBar) : BWindow(rect, B_TRANSLATE("Mail preferences"), B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS), fNewWrap(wrap), fWrap(*fNewWrap), fNewAttachAttributes(attachAttributes), fAttachAttributes(*fNewAttachAttributes), fNewButtonBar(buttonBar), fButtonBar(*fNewButtonBar), fNewColoredQuotes(cquotes), fColoredQuotes(*fNewColoredQuotes), fNewAccount(account), fAccount(*fNewAccount), fNewReplyTo(replyTo), fReplyTo(*fNewReplyTo), fNewPreamble(preamble), fNewSignature(sig), fSignature((char*)malloc(strlen(*fNewSignature) + 1)), fNewFont(font), fFont(*fNewFont), fNewEncoding(encoding), fEncoding(*fNewEncoding), fNewWarnUnencodable(warnUnencodable), fWarnUnencodable(*fNewWarnUnencodable), fNewSpellCheckStartOn(spellCheckStartOn), fSpellCheckStartOn(*fNewSpellCheckStartOn), fNewAutoMarkRead(autoMarkRead), fAutoMarkRead(*autoMarkRead) { strcpy(fSignature, *fNewSignature); BMenuField* menu; // group boxes const float kSpacing = 8; BGridView* interfaceView = new BGridView(kSpacing, kSpacing); BGridLayout* interfaceLayout = interfaceView->GridLayout(); interfaceLayout->SetInsets(kSpacing, kSpacing, kSpacing, kSpacing); BGridView* mailView = new BGridView(kSpacing, kSpacing); BGridLayout* mailLayout = mailView->GridLayout(); mailLayout->SetInsets(kSpacing, kSpacing, kSpacing, kSpacing); interfaceLayout->AlignLayoutWith(mailLayout, B_HORIZONTAL); BBox* interfaceBox = new BBox(B_FANCY_BORDER, interfaceView); interfaceBox->SetLabel(B_TRANSLATE("User interface")); BBox* mailBox = new BBox(B_FANCY_BORDER, mailView); mailBox->SetLabel(B_TRANSLATE("Mailing")); // revert, ok & cancel BButton* okButton = new BButton("ok", B_TRANSLATE("OK"), new BMessage(P_OK)); okButton->MakeDefault(true); BButton* cancelButton = new BButton("cancel", B_TRANSLATE("Cancel"), new BMessage(P_CANCEL)); fRevert = new BButton("revert", B_TRANSLATE("Revert"), new BMessage(P_REVERT)); fRevert->SetEnabled(false); // User Interface int32 layoutRow = 0; fButtonBarMenu = _BuildButtonBarMenu(*buttonBar); menu = new BMenuField("bar", B_TRANSLATE("Button bar:"), fButtonBarMenu); add_menu_to_layout(menu, interfaceLayout, layoutRow); fFontMenu = _BuildFontMenu(font); menu = new BMenuField("font", B_TRANSLATE("Font:"), fFontMenu); add_menu_to_layout(menu, interfaceLayout, layoutRow); fSizeMenu = _BuildSizeMenu(font); menu = new BMenuField("size", B_TRANSLATE("Size:"), fSizeMenu); add_menu_to_layout(menu, interfaceLayout, layoutRow); fColoredQuotesMenu = _BuildColoredQuotesMenu(fColoredQuotes); menu = new BMenuField("cquotes", B_TRANSLATE("Colored quotes:"), fColoredQuotesMenu); add_menu_to_layout(menu, interfaceLayout, layoutRow); fSpellCheckStartOnMenu = _BuildSpellCheckStartOnMenu(fSpellCheckStartOn); menu = new BMenuField("spellCheckStartOn", B_TRANSLATE("Initial spell check mode:"), fSpellCheckStartOnMenu); add_menu_to_layout(menu, interfaceLayout, layoutRow); fAutoMarkReadMenu = _BuildAutoMarkReadMenu(fAutoMarkRead); menu = new BMenuField("autoMarkRead", B_TRANSLATE("Automatically mark mail as read:"), fAutoMarkReadMenu); add_menu_to_layout(menu, interfaceLayout, layoutRow); // Mail Accounts layoutRow = 0; fAccountMenu = _BuildAccountMenu(fAccount); menu = new BMenuField("account", B_TRANSLATE("Default account:"), fAccountMenu); add_menu_to_layout(menu, mailLayout, layoutRow); fReplyToMenu = _BuildReplyToMenu(fReplyTo); menu = new BMenuField("replyTo", B_TRANSLATE("Reply account:"), fReplyToMenu); add_menu_to_layout(menu, mailLayout, layoutRow); // Mail Contents fReplyPreamble = new BTextControl("replytext", B_TRANSLATE("Reply preamble:"), *preamble, new BMessage(P_REPLY_PREAMBLE)); fReplyPreamble->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); fReplyPreambleMenu = _BuildReplyPreambleMenu(); menu = new BMenuField("replyPreamble", NULL, fReplyPreambleMenu); menu->SetExplicitMaxSize(BSize(27, B_SIZE_UNSET)); mailLayout->AddItem(fReplyPreamble->CreateLabelLayoutItem(), 0, layoutRow); mailLayout->AddItem(fReplyPreamble->CreateTextViewLayoutItem(), 1, layoutRow); mailLayout->AddView(menu, 2, layoutRow); layoutRow++; fSignatureMenu = _BuildSignatureMenu(*sig); menu = new BMenuField("sig", B_TRANSLATE("Auto signature:"), fSignatureMenu); add_menu_to_layout(menu, mailLayout, layoutRow); fEncodingMenu = _BuildEncodingMenu(fEncoding); menu = new BMenuField("enc", B_TRANSLATE("Encoding:"), fEncodingMenu); add_menu_to_layout(menu, mailLayout, layoutRow); fWarnUnencodableMenu = _BuildWarnUnencodableMenu(fWarnUnencodable); menu = new BMenuField("warnUnencodable", B_TRANSLATE("Warn unencodable:"), fWarnUnencodableMenu); add_menu_to_layout(menu, mailLayout, layoutRow); fWrapMenu = _BuildWrapMenu(*wrap); menu = new BMenuField("wrap", B_TRANSLATE("Text wrapping:"), fWrapMenu); add_menu_to_layout(menu, mailLayout, layoutRow); fAttachAttributesMenu = _BuildAttachAttributesMenu(*attachAttributes); menu = new BMenuField("attachAttributes", B_TRANSLATE("Attach attributes:"), fAttachAttributesMenu); add_menu_to_layout(menu, mailLayout, layoutRow); SetLayout(new BGroupLayout(B_HORIZONTAL)); AddChild(BGroupLayoutBuilder(B_VERTICAL, kSpacing) .Add(interfaceBox) .Add(mailBox) .Add(BGroupLayoutBuilder(B_HORIZONTAL, kSpacing) .Add(fRevert) .AddGlue() .Add(cancelButton) .Add(okButton) ) .SetInsets(kSpacing, kSpacing, kSpacing, kSpacing) ); Show(); }
ServerSettingsView::ServerSettingsView(const account_info &info) : BGroupView("server", B_VERTICAL), fInboundAccount(true), fOutboundAccount(true), fInboundAuthMenu(NULL), fOutboundAuthMenu(NULL), fInboundEncrItemStart(NULL), fOutboundEncrItemStart(NULL), fImageID(-1) { SetViewUIColor(B_PANEL_BACKGROUND_COLOR); fInboundAccount = true; fOutboundAccount = true; // inbound BBox* box = new BBox("inbound"); box->SetLabel(B_TRANSLATE("Incoming")); AddChild(box); BString serverName; if (info.inboundType == IMAP) serverName = info.providerInfo.imap_server; else serverName = info.providerInfo.pop_server; BGridView* grid = new BGridView("inner"); grid->GridLayout()->SetInsets(B_USE_DEFAULT_SPACING); box->AddChild(grid); fInboundNameView = new BTextControl("inbound", B_TRANSLATE("Server Name:"), serverName, new BMessage(kServerChangedMsg)); grid->GridLayout()->AddItem(fInboundNameView->CreateLabelLayoutItem(), 0, 0); grid->GridLayout()->AddItem(fInboundNameView->CreateTextViewLayoutItem(), 1, 0); int32 row = 1; _GetAuthEncrMenu(info.inboundProtocol, fInboundAuthMenu, fInboundEncryptionMenu); if (fInboundAuthMenu != NULL) { int authID = info.providerInfo.authentification_pop; if (info.inboundType == POP) fInboundAuthMenu->Menu()->ItemAt(authID)->SetMarked(true); fInboundAuthItemStart = fInboundAuthMenu->Menu()->FindMarked(); grid->GridLayout()->AddItem(fInboundAuthMenu->CreateLabelLayoutItem(), 0, row); grid->GridLayout()->AddItem(fInboundAuthMenu->CreateMenuBarLayoutItem(), 1, row++); } if (fInboundEncryptionMenu != NULL) { BMenuItem *item = NULL; if (info.inboundType == POP) { item = fInboundEncryptionMenu->Menu()->ItemAt( info.providerInfo.ssl_pop); if (item != NULL) item->SetMarked(true); } if (info.inboundType == IMAP) { item = fInboundEncryptionMenu->Menu()->ItemAt( info.providerInfo.ssl_imap); if (item != NULL) item->SetMarked(true); } fInboundEncrItemStart = fInboundEncryptionMenu->Menu()->FindMarked(); grid->GridLayout()->AddItem( fInboundEncryptionMenu->CreateLabelLayoutItem(), 0, row); grid->GridLayout()->AddItem( fInboundEncryptionMenu->CreateMenuBarLayoutItem(), 1, row++); } grid->GridLayout()->AddItem(BSpaceLayoutItem::CreateGlue(), 0, row); if (!fInboundAccount) box->Hide(); // outbound box = new BBox("outbound"); box->SetLabel(B_TRANSLATE("Outgoing")); AddChild(box); grid = new BGridView("inner"); grid->GridLayout()->SetInsets(B_USE_DEFAULT_SPACING); box->AddChild(grid); serverName = info.providerInfo.smtp_server; fOutboundNameView = new BTextControl("outbound", B_TRANSLATE("Server name:"), serverName.String(), new BMessage(kServerChangedMsg)); grid->GridLayout()->AddItem(fOutboundNameView->CreateLabelLayoutItem(), 0, 0); grid->GridLayout()->AddItem(fOutboundNameView->CreateTextViewLayoutItem(), 1, 0); row = 1; _GetAuthEncrMenu(info.outboundProtocol, fOutboundAuthMenu, fOutboundEncryptionMenu); if (fOutboundAuthMenu != NULL) { BMenuItem* item = fOutboundAuthMenu->Menu()->ItemAt( info.providerInfo.authentification_smtp); if (item != NULL) item->SetMarked(true); fOutboundAuthItemStart = item; grid->GridLayout()->AddItem(fOutboundAuthMenu->CreateLabelLayoutItem(), 0, row); grid->GridLayout()->AddItem( fOutboundAuthMenu->CreateMenuBarLayoutItem(), 1, row++); } if (fOutboundEncryptionMenu != NULL) { BMenuItem* item = fOutboundEncryptionMenu->Menu()->ItemAt( info.providerInfo.ssl_smtp); if (item != NULL) item->SetMarked(true); fOutboundEncrItemStart = item; grid->GridLayout()->AddItem( fOutboundEncryptionMenu->CreateLabelLayoutItem(), 0, row); grid->GridLayout()->AddItem( fOutboundEncryptionMenu->CreateMenuBarLayoutItem(), 1, row++); } grid->GridLayout()->AddItem(BSpaceLayoutItem::CreateGlue(), 0, row); if (!fOutboundAccount) box->Hide(); }
PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName) : BlockingWindow(BRect(0, 0, 100, 100), "Page setup", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE), fSetupMsg(msg), fPrinterDirName(printerName) { if (printerName) SetTitle(BString(printerName).Append(" Page setup").String()); // load orientation if (fSetupMsg->FindInt32("orientation", &fCurrentOrientation) != B_OK) fCurrentOrientation = PrinterDriver::PORTRAIT_ORIENTATION; // load page rect BRect page; float width = letter_width; float height = letter_height; if (fSetupMsg->FindRect("preview:paper_rect", &page) == B_OK) { width = page.Width(); height = page.Height(); } else { page.Set(0, 0, width, height); } BString label; if (fSetupMsg->FindString("preview:paper_size", &label) != B_OK) label = "Letter"; // Load units int32 units; if (fSetupMsg->FindInt32("units", &units) != B_OK) units = kUnitInch; // re-calculate the margin from the printable rect in points BRect margin = page; if (fSetupMsg->FindRect("preview:printable_rect", &margin) == B_OK) { margin.top -= page.top; margin.left -= page.left; margin.right = page.right - margin.right; margin.bottom = page.bottom - margin.bottom; } else { margin.Set(28.34, 28.34, 28.34, 28.34); // 28.34 dots = 1cm } fMarginView = new MarginView(int32(width), int32(height), margin, MarginUnit(units)); BPopUpMenu* pageSizePopUpMenu = new BPopUpMenu("Page size"); pageSizePopUpMenu->SetRadioMode(true); fPageSizeMenu = new BMenuField("page_size", "Page size:", pageSizePopUpMenu); fPageSizeMenu->Menu()->SetLabelFromMarked(true); for (int32 i = 0; pageFormat[i].label != NULL; i++) { BMessage* message = new BMessage(PAGE_SIZE_CHANGED); message->AddFloat("width", pageFormat[i].width); message->AddFloat("height", pageFormat[i].height); BMenuItem* item = new BMenuItem(pageFormat[i].label, message); pageSizePopUpMenu->AddItem(item); if (label.Compare(pageFormat[i].label) == 0) item->SetMarked(true); } BPopUpMenu* orientationPopUpMenu = new BPopUpMenu("Orientation"); orientationPopUpMenu->SetRadioMode(true); fOrientationMenu = new BMenuField("orientation", "Orientation:", orientationPopUpMenu); fOrientationMenu->Menu()->SetLabelFromMarked(true); for (int32 i = 0; orientation[i].label != NULL; i++) { BMessage* message = new BMessage(ORIENTATION_CHANGED); message->AddInt32("orientation", orientation[i].orientation); BMenuItem* item = new BMenuItem(orientation[i].label, message); orientationPopUpMenu->AddItem(item); if (fCurrentOrientation == orientation[i].orientation) item->SetMarked(true); } float scale0; BString scale; if (fSetupMsg->FindFloat("scale", &scale0) == B_OK) scale << (int)scale0; else scale = "100"; fScaleControl = new BTextControl("scale", "Scale [%]:", scale.String(), NULL); for (uint32 i = 0; i < '0'; i++) fScaleControl->TextView()->DisallowChar(i); for (uint32 i = '9' + 1; i < 255; i++) fScaleControl->TextView()->DisallowChar(i); fScaleControl->TextView()->SetMaxBytes(3); BBox *separator = new BBox("separator"); separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); BButton *cancel = new BButton("cancel", "Cancel", new BMessage(CANCEL_MSG)); BButton *ok = new BButton("ok", "OK", new BMessage(OK_MSG)); ok->MakeDefault(true); BGridView* settings = new BGridView(); BGridLayout* settingsLayout = settings->GridLayout(); settingsLayout->AddItem(fPageSizeMenu->CreateLabelLayoutItem(), 0, 0); settingsLayout->AddItem(fPageSizeMenu->CreateMenuBarLayoutItem(), 1, 0); settingsLayout->AddItem(fOrientationMenu->CreateLabelLayoutItem(), 0, 1); settingsLayout->AddItem(fOrientationMenu->CreateMenuBarLayoutItem(), 1, 1); settingsLayout->AddItem(fScaleControl->CreateLabelLayoutItem(), 0, 2); settingsLayout->AddItem(fScaleControl->CreateTextViewLayoutItem(), 1, 2); settingsLayout->SetSpacing(0, 0); SetLayout(new BGroupLayout(B_VERTICAL)); AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) .AddGroup(B_HORIZONTAL, 5, 1) .AddGroup(B_VERTICAL, 0, 1.0f) .Add(fMarginView) .AddGlue() .End() .AddGroup(B_VERTICAL, 0, 1.0f) .Add(settings) .AddGlue() .End() .End() .Add(separator) .AddGroup(B_HORIZONTAL, 10, 1.0f) .AddGlue() .Add(cancel) .Add(ok) .End() .SetInsets(10, 10, 10, 10) ); BRect winFrame(Frame()); BRect screenFrame(BScreen().Frame()); MoveTo((screenFrame.right - winFrame.right) / 2, (screenFrame.bottom - winFrame.bottom) / 2); }
void JobSetupView::AttachedToWindow() { // quality BBox* qualityBox = new BBox("quality"); qualityBox->SetLabel("Quality"); // color fColorType = new BPopUpMenu("color"); fColorType->SetRadioMode(true); FillCapabilityMenu(fColorType, kMsgQuality, PrinterCap::kColor, fJobData->GetColor()); BMenuField* colorMenuField = new BMenuField("color", "Color:", fColorType); fColorType->SetTargetForItems(this); if (IsHalftoneConfigurationNeeded()) CreateHalftoneConfigurationUI(); // page range BBox* pageRangeBox = new BBox("pageRange"); pageRangeBox->SetLabel("Page Range"); fAll = new BRadioButton("all", "Print all Pages", new BMessage(kMsgRangeAll)); BRadioButton *range = new BRadioButton("selection", "Print selected Pages:", new BMessage(kMsgRangeSelection)); fFromPage = new BTextControl("from", "From:", "", NULL); fFromPage->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT); AllowOnlyDigits(fFromPage->TextView(), 6); fToPage = new BTextControl("to", "To:", "", NULL); fToPage->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT); AllowOnlyDigits(fToPage->TextView(), 6); int first_page = fJobData->GetFirstPage(); int last_page = fJobData->GetLastPage(); if (first_page <= 1 && last_page <= 0) { fAll->SetValue(B_CONTROL_ON); } else { range->SetValue(B_CONTROL_ON); if (first_page < 1) first_page = 1; if (first_page > last_page) last_page = -1; BString oss1; oss1 << first_page; fFromPage->SetText(oss1.String()); BString oss2; oss2 << last_page; fToPage->SetText(oss2.String()); } fAll->SetTarget(this); range->SetTarget(this); // paper source fPaperFeed = new BPopUpMenu(""); fPaperFeed->SetRadioMode(true); FillCapabilityMenu(fPaperFeed, kMsgNone, PrinterCap::kPaperSource, fJobData->GetPaperSource()); BMenuField* paperSourceMenufield = new BMenuField("paperSource", "Paper Source:", fPaperFeed); // Pages per sheet fNup = new BPopUpMenu(""); fNup->SetRadioMode(true); FillCapabilityMenu(fNup, kMsgNone, gNups, sizeof(gNups) / sizeof(gNups[0]), (int)fJobData->GetNup()); BMenuField* pagesPerSheet = new BMenuField("pagesPerSheet", "Pages Per Sheet:", fNup); // duplex if (fPrinterCap->Supports(PrinterCap::kPrintStyle)) { fDuplex = new BCheckBox("duplex", "Duplex", new BMessage(kMsgDuplexChanged)); if (fJobData->GetPrintStyle() != JobData::kSimplex) { fDuplex->SetValue(B_CONTROL_ON); } fDuplex->SetTarget(this); } else { fDuplex = NULL; } // copies fCopies = new BTextControl("copies", "Number of Copies:", "", NULL); AllowOnlyDigits(fCopies->TextView(), 3); BString copies; copies << fJobData->GetCopies(); fCopies->SetText(copies.String()); // collate fCollate = new BCheckBox("collate", "Collate", new BMessage(kMsgCollateChanged)); if (fJobData->GetCollate()) { fCollate->SetValue(B_CONTROL_ON); } fCollate->SetTarget(this); // reverse fReverse = new BCheckBox("reverse", "Reverse Order", new BMessage(kMsgReverseChanged)); if (fJobData->GetReverse()) { fReverse->SetValue(B_CONTROL_ON); } fReverse->SetTarget(this); // pages view // TODO make layout API compatible fPages = new PagesView(BRect(0, 0, 150, 40), "pages", B_FOLLOW_ALL, B_WILL_DRAW); fPages->SetCollate(fJobData->GetCollate()); fPages->SetReverse(fJobData->GetReverse()); fPages->SetExplicitMinSize(BSize(150, 40)); fPages->SetExplicitMaxSize(BSize(150, 40)); // page selection BBox* pageSelectionBox = new BBox("pageSelection"); pageSelectionBox->SetLabel("Page Selection"); fAllPages = CreatePageSelectionItem("allPages", "All Pages", JobData::kAllPages); fOddNumberedPages = CreatePageSelectionItem("oddPages", "Odd-Numbered Pages", JobData::kOddNumberedPages); fEvenNumberedPages = CreatePageSelectionItem("evenPages", "Even-Numbered Pages", JobData::kEvenNumberedPages); fPreview = new BCheckBox("preview", "Show preview before printing", NULL); if (fJobData->GetShowPreview()) fPreview->SetValue(B_CONTROL_ON); // separator line BBox *separator = new BBox("separator"); separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); // buttons BButton* cancel = new BButton("cancel", "Cancel", new BMessage(kMsgCancel)); BButton* ok = new BButton("ok", "OK", new BMessage(kMsgOK)); ok->MakeDefault(true); if (IsHalftoneConfigurationNeeded()) { BGroupView* halftoneGroup = new BGroupView(B_VERTICAL, 0); BGroupLayout* halftoneLayout = halftoneGroup->GroupLayout(); halftoneLayout->AddView(fHalftone); fHalftoneBox->AddChild(halftoneGroup); } BGridView* qualityGrid = new BGridView(); BGridLayout* qualityGridLayout = qualityGrid->GridLayout(); qualityGridLayout->AddItem(colorMenuField->CreateLabelLayoutItem(), 0, 0); qualityGridLayout->AddItem(colorMenuField->CreateMenuBarLayoutItem(), 1, 0); if (IsHalftoneConfigurationNeeded()) { qualityGridLayout->AddItem(fDitherMenuField->CreateLabelLayoutItem(), 0, 1); qualityGridLayout->AddItem(fDitherMenuField->CreateMenuBarLayoutItem(), 1, 1); qualityGridLayout->AddView(fGamma, 0, 2, 2); qualityGridLayout->AddView(fInkDensity, 0, 3, 2); qualityGridLayout->AddView(fHalftoneBox, 0, 4, 2); } else { AddDriverSpecificSettings(qualityGridLayout, 1); } qualityGridLayout->SetSpacing(0, 0); qualityGridLayout->SetInsets(5, 5, 5, 5); qualityBox->AddChild(qualityGrid); // TODO put qualityGrid in a scroll view // the layout of the box surrounding the scroll view using the following // code is not correct; the box still has the size of the qualityGird; // and the scroll view is vertically centered inside the box! //BScrollView* qualityScroller = new BScrollView("qualityScroller", // qualityGrid, 0, false, true); //qualityScroller->SetExplicitMaxSize(BSize(500, 500)); //qualityBox->AddChild(qualityScroller); BGridView* pageRangeGrid = new BGridView(); BGridLayout* pageRangeLayout = pageRangeGrid->GridLayout(); pageRangeLayout->AddItem(fFromPage->CreateLabelLayoutItem(), 0, 0); pageRangeLayout->AddItem(fFromPage->CreateTextViewLayoutItem(), 1, 0); pageRangeLayout->AddItem(fToPage->CreateLabelLayoutItem(), 0, 1); pageRangeLayout->AddItem(fToPage->CreateTextViewLayoutItem(), 1, 1); pageRangeLayout->SetInsets(0, 0, 0, 0); pageRangeLayout->SetSpacing(0, 0); BGroupView* pageRangeGroup = new BGroupView(B_VERTICAL, 0); BGroupLayout* pageRangeGroupLayout = pageRangeGroup->GroupLayout(); pageRangeGroupLayout->AddView(fAll); pageRangeGroupLayout->AddView(range); pageRangeGroupLayout->AddView(pageRangeGrid); pageRangeGroupLayout->SetInsets(5, 5, 5, 5); pageRangeBox->AddChild(pageRangeGroup); BGridView* settings = new BGridView(); BGridLayout* settingsLayout = settings->GridLayout(); settingsLayout->AddItem(paperSourceMenufield->CreateLabelLayoutItem(), 0, 0); settingsLayout->AddItem(paperSourceMenufield->CreateMenuBarLayoutItem(), 1, 0); settingsLayout->AddItem(pagesPerSheet->CreateLabelLayoutItem(), 0, 1); settingsLayout->AddItem(pagesPerSheet->CreateMenuBarLayoutItem(), 1, 1); int row = 2; if (fDuplex != NULL) { settingsLayout->AddView(fDuplex, 0, row, 2); row ++; } settingsLayout->AddItem(fCopies->CreateLabelLayoutItem(), 0, row); settingsLayout->AddItem(fCopies->CreateTextViewLayoutItem(), 1, row); settingsLayout->SetSpacing(0, 0); BGroupView* pageSelectionGroup = new BGroupView(B_VERTICAL, 0); BGroupLayout* groupLayout = pageSelectionGroup->GroupLayout(); groupLayout->AddView(fAllPages); groupLayout->AddView(fOddNumberedPages); groupLayout->AddView(fEvenNumberedPages); groupLayout->SetInsets(5, 5, 5, 5); pageSelectionBox->AddChild(pageSelectionGroup); SetLayout(new BGroupLayout(B_VERTICAL)); AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) .AddGroup(B_HORIZONTAL, 10, 1.0f) .AddGroup(B_VERTICAL, 10, 1.0f) .Add(qualityBox) .Add(pageRangeBox) .AddGlue() .End() .AddGroup(B_VERTICAL, 0, 1.0f) .Add(settings) .AddStrut(5) .Add(fCollate) .Add(fReverse) .Add(fPages) .AddStrut(5) .Add(pageSelectionBox) .AddGlue() .End() .End() .Add(fPreview) .AddGlue() .Add(separator) .AddGroup(B_HORIZONTAL, 10, 1.0f) .AddGlue() .Add(cancel) .Add(ok) .End() .SetInsets(0, 0, 0, 0) ); UpdateHalftonePreview(); UpdateButtonEnabledState(); }
/** * _ConstructGUI() * * Creates the GUI for the View. MUST be called AFTER the View is attached to * the Window, or will crash and/or create strange behaviour * * @param none * @return void */ void MarginView::_ConstructGUI() { fPage = new PageView(); fPage->SetViewColor(ViewColor()); fPageSize = new BStringView("pageSize", "?x?"); BString str; // Create text fields // top str << fMargins.top/fUnitValue; fTop = new BTextControl("top", "Top:", str.String(), NULL); fTop->SetModificationMessage(new BMessage(TOP_MARGIN_CHANGED)); fTop->SetTarget(this); _AllowOnlyNumbers(fTop, kNumCount); //left str = ""; str << fMargins.left/fUnitValue; fLeft = new BTextControl("left", "Left:", str.String(), NULL); fLeft->SetModificationMessage(new BMessage(LEFT_MARGIN_CHANGED)); fLeft->SetTarget(this); _AllowOnlyNumbers(fLeft, kNumCount); //bottom str = ""; str << fMargins.bottom/fUnitValue; fBottom = new BTextControl("bottom", "Bottom:", str.String(), NULL); fBottom->SetModificationMessage(new BMessage(BOTTOM_MARGIN_CHANGED)); fBottom->SetTarget(this); _AllowOnlyNumbers(fBottom, kNumCount); //right str = ""; str << fMargins.right/fUnitValue; fRight = new BTextControl("right", "Right:", str.String(), NULL); fRight->SetModificationMessage(new BMessage(RIGHT_MARGIN_CHANGED)); fRight->SetTarget(this); _AllowOnlyNumbers(fRight, kNumCount); // Create Units popup BPopUpMenu *menu = new BPopUpMenu("units"); BMenuField *units = new BMenuField("units", "Units:", menu); BMenuItem *item; // Construct menu items for (int32 i = 0; kUnitNames[i] != NULL; i++) { BMessage *msg = new BMessage(MARGIN_UNIT_CHANGED); msg->AddInt32("marginUnit", kUnitMsg[i]); menu->AddItem(item = new BMenuItem(kUnitNames[i], msg)); item->SetTarget(this); if (fMarginUnit == kUnitMsg[i]) item->SetMarked(true); } BGridView* settings = new BGridView(); BGridLayout* settingsLayout = settings->GridLayout(); settingsLayout->AddItem(fTop->CreateLabelLayoutItem(), 0, 0); settingsLayout->AddItem(fTop->CreateTextViewLayoutItem(), 1, 0); settingsLayout->AddItem(fLeft->CreateLabelLayoutItem(), 0, 1); settingsLayout->AddItem(fLeft->CreateTextViewLayoutItem(), 1, 1); settingsLayout->AddItem(fBottom->CreateLabelLayoutItem(), 0, 2); settingsLayout->AddItem(fBottom->CreateTextViewLayoutItem(), 1, 2); settingsLayout->AddItem(fRight->CreateLabelLayoutItem(), 0, 3); settingsLayout->AddItem(fRight->CreateTextViewLayoutItem(), 1, 3); settingsLayout->AddItem(units->CreateLabelLayoutItem(), 0, 4); settingsLayout->AddItem(units->CreateMenuBarLayoutItem(), 1, 4); settingsLayout->SetSpacing(0, 0); BGroupView* groupView = new BGroupView(B_HORIZONTAL, 10); BGroupLayout* groupLayout = groupView->GroupLayout(); groupLayout->AddView(BGroupLayoutBuilder(B_VERTICAL, 0) .Add(fPage) .Add(fPageSize) .SetInsets(0, 0, 0, 0) .TopView() ); groupLayout->AddView(settings); groupLayout->SetInsets(5, 5, 5, 5); AddChild(groupView); UpdateView(MARGIN_CHANGED); }
PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName) : HWindow(BRect(0, 0, 200, 100), "Page setup", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE), fResult(B_ERROR), fSetupMsg(msg), fAdvancedSettings(*msg), fPrinterDirName(printerName) { fExitSem = create_sem(0, "PageSetup"); if (printerName) SetTitle(BString(printerName).Append(" page setup").String()); if (fSetupMsg->FindInt32("orientation", &fCurrentOrientation) != B_OK) fCurrentOrientation = PrinterDriver::PORTRAIT_ORIENTATION; BRect page; float width = letter_width; float height = letter_height; if (fSetupMsg->FindRect("paper_rect", &page) == B_OK) { width = page.Width(); height = page.Height(); } else { page.Set(0, 0, width, height); } BString label; if (fSetupMsg->FindString("pdf_paper_size", &label) != B_OK) label = "Letter"; int32 compression; fSetupMsg->FindInt32("pdf_compression", &compression); int32 units; if (fSetupMsg->FindInt32("units", &units) != B_OK) units = kUnitInch; // re-calculate the margin from the printable rect in points BRect margin = page; if (fSetupMsg->FindRect("printable_rect", &margin) == B_OK) { margin.top -= page.top; margin.left -= page.left; margin.right = page.right - margin.right; margin.bottom = page.bottom - margin.bottom; } else { margin.Set(28.34, 28.34, 28.34, 28.34); // 28.34 dots = 1cm } BString setting_value; if (fSetupMsg->FindString("pdf_compatibility", &setting_value) != B_OK) setting_value = "1.3"; // Load font settings fFonts = new Fonts(); fFonts->CollectFonts(); BMessage fonts; if (fSetupMsg->FindMessage("fonts", &fonts) == B_OK) fFonts->SetTo(&fonts); fMarginView = new MarginView(int32(width), int32(height), margin, MarginUnit(units)); BPopUpMenu* pageSize = new BPopUpMenu("Page size"); pageSize->SetRadioMode(true); fPageSizeMenu = new BMenuField("page_size", "Page size:", pageSize); fPageSizeMenu->Menu()->SetLabelFromMarked(true); for (int32 i = 0; pageFormat[i].label != NULL; i++) { BMessage* message = new BMessage(PAGE_SIZE_CHANGED); message->AddFloat("width", pageFormat[i].width); message->AddFloat("height", pageFormat[i].height); BMenuItem* item = new BMenuItem(pageFormat[i].label, message); pageSize->AddItem(item); if (label.Compare(pageFormat[i].label) == 0) item->SetMarked(true); } BPopUpMenu* orientationPopUpMenu = new BPopUpMenu("Orientation"); orientationPopUpMenu->SetRadioMode(true); fOrientationMenu = new BMenuField("orientation", "Orientation:", orientationPopUpMenu); fOrientationMenu->Menu()->SetLabelFromMarked(true); for (int32 i = 0; orientation[i].label != NULL; i++) { BMessage* message = new BMessage(ORIENTATION_CHANGED); message->AddInt32("orientation", orientation[i].orientation); BMenuItem* item = new BMenuItem(orientation[i].label, message); orientationPopUpMenu->AddItem(item); if (fCurrentOrientation == orientation[i].orientation) item->SetMarked(true); } BPopUpMenu* compatibility = new BPopUpMenu("PDF compatibility"); compatibility->SetRadioMode(true); fPDFCompatibilityMenu = new BMenuField("pdf_compatibility", "PDF compatibility:", compatibility); fPDFCompatibilityMenu->Menu()->SetLabelFromMarked(true); for (int32 i = 0; pdf_compatibility[i] != NULL; i++) { BMenuItem* item = new BMenuItem(pdf_compatibility[i], NULL); compatibility->AddItem(item); if (setting_value == pdf_compatibility[i]) item->SetMarked(true); } fPDFCompressionSlider = new BSlider("pdf_compression", "Compression:", NULL, 0, 9, B_HORIZONTAL); fPDFCompressionSlider->SetLimitLabels("None", "Best"); fPDFCompressionSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); fPDFCompressionSlider->SetValue(compression); BBox *separator = new BBox("separator"); separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); BButton *cancel = new BButton("cancel", "Cancel", new BMessage(CANCEL_MSG)); BButton *ok = new BButton("ok", "OK", new BMessage(OK_MSG)); ok->MakeDefault(true); BButton *fontsButton = new BButton("fonts", "Fonts" B_UTF8_ELLIPSIS, new BMessage(FONTS_MSG)); BButton* advancedButton = new BButton("advanced", "Advanced" B_UTF8_ELLIPSIS, new BMessage(ADVANCED_MSG)); BGridView* settings = new BGridView(); BGridLayout* settingsLayout = settings->GridLayout(); settingsLayout->AddItem(fPageSizeMenu->CreateLabelLayoutItem(), 0, 0); settingsLayout->AddItem(fPageSizeMenu->CreateMenuBarLayoutItem(), 1, 0); settingsLayout->AddItem(fOrientationMenu->CreateLabelLayoutItem(), 0, 1); settingsLayout->AddItem(fOrientationMenu->CreateMenuBarLayoutItem(), 1, 1); settingsLayout->AddItem(fPDFCompatibilityMenu->CreateLabelLayoutItem(), 0, 2); settingsLayout->AddItem(fPDFCompatibilityMenu->CreateMenuBarLayoutItem(), 1, 2); settingsLayout->AddView(fPDFCompressionSlider, 0, 3, 2); settingsLayout->SetSpacing(0, 0); SetLayout(new BGroupLayout(B_VERTICAL)); AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) .AddGroup(B_HORIZONTAL, 5, 1) .AddGroup(B_VERTICAL, 0, 1.0f) .Add(fMarginView) .AddGlue() .End() .AddGroup(B_VERTICAL, 0, 1.0f) .Add(settings) .AddGlue() .End() .End() .Add(separator) .AddGroup(B_HORIZONTAL, 10, 1.0f) .Add(fontsButton) .Add(advancedButton) .AddGlue() .Add(cancel) .Add(ok) .End() .SetInsets(10, 10, 10, 10) ); BRect winFrame(Frame()); BRect screenFrame(BScreen().Frame()); MoveTo((screenFrame.right - winFrame.right) / 2, (screenFrame.bottom - winFrame.bottom) / 2); }
// -------------------------------------------------- JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName) : HWindow(BRect(0, 0, 100, 100), "Job Setup", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE) { fSetupMsg = msg; fExitSem = create_sem(0, "JobSetup"); fResult = B_ERROR; if (printerName) { BString title; title << printerName << " Job Setup"; SetTitle(title.String()); fPrinterName = printerName; } // PrinterDriver ensures that property exists int32 firstPage; fSetupMsg->FindInt32("first_page", &firstPage); int32 lastPage; fSetupMsg->FindInt32("last_page", &lastPage); BMessage doc_info; if (fSetupMsg->FindMessage("doc_info", &doc_info) != B_OK) { // 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); bool allPages = firstPage == 1 && lastPage == MAX_INT32; fAll = new BRadioButton("allPages", "Print all pages", new BMessage(ALL_PAGES_MGS)); fAll->SetValue(allPages); fRange = new BRadioButton("pagesRange", "Print pages:", new BMessage(RANGE_SELECTION_MSG)); fRange->SetValue(!allPages); fFrom = new BTextControl("from", "From:", "SomeSpaceHere", NULL); fFrom->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT); fFrom->SetEnabled(!allPages); fTo = new BTextControl("to", "To:", "", NULL); fTo->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT); fTo->SetEnabled(!allPages); BString buffer; buffer << firstPage; fFrom->SetText(buffer.String()); buffer = ""; buffer << lastPage; fTo->SetText(buffer.String()); for (uint32 i = 0; i < '0'; i++) { fTo->TextView()->DisallowChar(i); fFrom->TextView()->DisallowChar(i); } for (uint32 i = '9' + 1; i < 255; i++) { fTo->TextView()->DisallowChar(i); fFrom->TextView()->DisallowChar(i); } BBox *separator = new BBox("separator"); separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); BButton *documentInfo = new BButton("documentInfo", "Document" B_UTF8_ELLIPSIS, new BMessage(DOC_INFO_MSG)); BButton *cancel = new BButton("cancel", "Cancel", new BMessage(CANCEL_MSG)); BButton *ok = new BButton("ok", "OK", new BMessage(OK_MSG)); ok->MakeDefault(true); BGridView* settings = new BGridView(); BGridLayout* settingsLayout = settings->GridLayout(); settingsLayout->AddItem(fFrom->CreateLabelLayoutItem(), 0, 0); settingsLayout->AddItem(fFrom->CreateTextViewLayoutItem(), 1, 0); settingsLayout->AddItem(fTo->CreateLabelLayoutItem(), 0, 1); settingsLayout->AddItem(fTo->CreateTextViewLayoutItem(), 1, 1); settingsLayout->SetSpacing(0, 0); SetLayout(new BGroupLayout(B_VERTICAL)); AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) .Add(fAll) .Add(fRange) .Add(settings) .AddGlue() .Add(separator) .AddGroup(B_HORIZONTAL, 10, 1.0f) .Add(documentInfo) .AddGlue() .Add(cancel) .Add(ok) .End() .SetInsets(10, 10, 10, 10) ); }