void ConfigWindow::LoadSettings() { Accounts::Delete(); Accounts::Create(fAccountsListView,fConfigView); // load in general settings BMailSettings *settings = new BMailSettings(); status_t status = SetToGeneralSettings(settings); if (status == B_OK) { // adjust own window frame BScreen screen(this); BRect screenFrame(screen.Frame().InsetByCopy(0,5)); BRect frame(settings->ConfigWindowFrame()); if (screenFrame.Contains(frame.LeftTop())) MoveTo(frame.LeftTop()); else // center on screen MoveTo((screenFrame.Width() - frame.Width()) / 2,(screenFrame.Height() - frame.Height()) / 2); } else fprintf(stderr, MDR_DIALECT_CHOICE ( "Error retrieving general settings: %s\n", "一般設定の収得に失敗: %s\n"), strerror(status)); delete settings; }
DocInfoWindow::DocInfoWindow(BMessage *docInfo) : HWindow(BRect(0, 0, 400, 250), "Document Information", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_MINIMIZABLE), fDocInfo(docInfo) { BRect bounds(Bounds()); BView *background = new BView(bounds, "bachground", B_FOLLOW_ALL, B_WILL_DRAW); background->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(background); bounds.InsetBy(10.0, 10.0); BButton *button = new BButton(bounds, "ok", "OK", new BMessage(OK_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); background->AddChild(button); button->ResizeToPreferred(); button->MoveTo(bounds.right - button->Bounds().Width(), bounds.bottom - button->Bounds().Height()); BRect buttonFrame(button->Frame()); button = new BButton(buttonFrame, "cancel", "Cancel", new BMessage(CANCEL_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); background->AddChild(button); button->ResizeToPreferred(); button->MoveTo(buttonFrame.left - (button->Bounds().Width() + 10.0), buttonFrame.top); bounds.bottom = buttonFrame.top - 10.0; #if HAVE_FULLVERSION_PDF_LIB BString permissions; if (_DocInfo()->FindString("permissions", &permissions) == B_OK) fPermissions.Decode(permissions.String()); BTabView *tabView = new BTabView(bounds, "tabView"); _SetupDocInfoView(_CreateTabPanel(tabView, "Information")); _SetupPasswordView(_CreateTabPanel(tabView, "Password")); _SetupPermissionsView(_CreateTabPanel(tabView, "Permissions")); background->AddChild(tabView); #else BBox* panel = new BBox(bounds, "top_panel", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_NO_BORDER); _SetupDocInfoView(panel); background->AddChild(panel); #endif if (fTable->ChildAt(0)) fTable->ChildAt(0)->MakeFocus(); BRect winFrame(Frame()); BRect screenFrame(BScreen().Frame()); MoveTo((screenFrame.right - winFrame.right) / 2, (screenFrame.bottom - winFrame.bottom) / 2); SetSizeLimits(400.0, 10000.0, 250.0, 10000.0); }
BPoint BAlert::AlertPosition(float width, float height) { BPoint result(100, 100); BWindow* window = dynamic_cast<BWindow*>(BLooper::LooperForThread(find_thread(NULL))); BScreen screen(window); BRect screenFrame(0, 0, 640, 480); if (screen.IsValid()) screenFrame = screen.Frame(); // Horizontally, we're smack in the middle result.x = screenFrame.left + (screenFrame.Width() / 2.0) - (width / 2.0); // This is probably sooo wrong, but it looks right on 1024 x 768 result.y = screenFrame.top + (screenFrame.Height() / 4.0) - ceil(height / 3.0); return result; }
VolumeWindow::VolumeWindow(BRect frame, bool dontBeep, int32 volumeWhich) : BWindow(frame, "VolumeWindow", B_BORDERED_WINDOW_LOOK, B_FLOATING_ALL_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | B_WILL_ACCEPT_FIRST_CLICK | B_AUTO_UPDATE_SIZE_LIMITS, 0), fUpdatedCount(0) { SetLayout(new BGroupLayout(B_HORIZONTAL)); BGroupLayout* layout = new BGroupLayout(B_HORIZONTAL); layout->SetInsets(5, 5, 5, 5); BBox* box = new BBox("sliderbox"); box->SetLayout(layout); box->SetBorder(B_PLAIN_BORDER); AddChild(box); BSlider* slider = new VolumeControl(volumeWhich, !dontBeep, new BMessage(kMsgVolumeChanged)); slider->SetModificationMessage(new BMessage(kMsgVolumeUpdate)); box->AddChild(slider); slider->SetTarget(this); ResizeTo(300, 50); // Make sure it's not outside the screen. const int32 kMargin = 3; BRect windowRect = Frame(); BRect screenFrame(BScreen(B_MAIN_SCREEN_ID).Frame()); if (screenFrame.right < windowRect.right + kMargin) MoveBy(- kMargin - windowRect.right + screenFrame.right, 0); if (screenFrame.bottom < windowRect.bottom + kMargin) MoveBy(0, - kMargin - windowRect.bottom + screenFrame.bottom); if (screenFrame.left > windowRect.left - kMargin) MoveBy(kMargin + screenFrame.left - windowRect.left, 0); if (screenFrame.top > windowRect.top - kMargin) MoveBy(0, kMargin + screenFrame.top - windowRect.top); }
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); }
JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName) : BlockingWindow(BRect(0, 0, 300, 200), "Job Setup", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE), fPrinterName(printerName), fSetupMsg(msg) { if (printerName) SetTitle(BString(printerName).Append(" Job Setup").String()); int32 firstPage; fSetupMsg->FindInt32("first_page", &firstPage); int32 lastPage; fSetupMsg->FindInt32("last_page", &lastPage); bool allPages = firstPage == 1 && lastPage == LONG_MAX; BRect bounds(Bounds()); BBox *panel = new BBox(bounds, "background", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER); AddChild(panel); bounds.InsetBy(10.0, 10.0); fAll = new BRadioButton(bounds, "allPages", "Print all pages", new BMessage(ALL_PAGES_MGS)); panel->AddChild(fAll); fAll->ResizeToPreferred(); fAll->SetValue(allPages); bounds.OffsetBy(0.0, fAll->Bounds().Height() + 10.0); fRange = new BRadioButton(bounds, "pagesRange", "Print pages:", new BMessage(RANGE_SELECTION_MSG)); panel->AddChild(fRange); fRange->ResizeToPreferred(); fRange->SetValue(!allPages); bounds.OffsetBy(0.0, fRange->Bounds().Height() + 5.0); BRect rect(bounds); rect.right = be_plain_font->StringWidth("From: SomeSpaceHere"); fFrom = new BTextControl(rect, "from", "From:", "SomeSpaceHere", NULL); panel->AddChild(fFrom); fFrom->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT); fFrom->ResizeToPreferred(); fFrom->SetDivider(be_plain_font->StringWidth("From: ")); fFrom->SetEnabled(!allPages); rect = fFrom->Frame(); fTo = new BTextControl(rect, "to", "To:", "SomeSpaceHere", NULL); panel->AddChild(fTo); fTo->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT); fTo->SetDivider(be_plain_font->StringWidth("To: ")); fTo->MoveTo(fFrom->Frame().right + 10.0, fTo->Frame().top); 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); } bounds.OffsetBy(0.0, fTo->Bounds().Height() + 10.0); BBox *line = new BBox(BRect(bounds.left - 5.0, bounds.top, bounds.right + 5.0, bounds.top + 1.0), NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP ); panel->AddChild(line); bounds.OffsetBy(0.0, 11.0); BButton *cancel = new BButton(bounds, NULL, "Cancel", new BMessage(CANCEL_MSG)); panel->AddChild(cancel); cancel->ResizeToPreferred(); BButton *ok = new BButton(bounds, NULL, "OK", new BMessage(OK_MSG)); panel->AddChild(ok, cancel); ok->ResizeToPreferred(); bounds.right = fTo->Frame().right; ok->MoveTo(bounds.right - ok->Bounds().Width(), ok->Frame().top); bounds = ok->Frame(); cancel->MoveTo(bounds.left - cancel->Bounds().Width() - 10.0, bounds.top); ok->MakeDefault(true); ResizeTo(bounds.right + 10.0, bounds.bottom + 10.0); BRect winFrame(Frame()); BRect screenFrame(BScreen().Frame()); MoveTo((screenFrame.right - winFrame.right) / 2, (screenFrame.bottom - winFrame.bottom) / 2); }
PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName) : BlockingWindow(BRect(0,0,400,220), "Page setup", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE), 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 } BRect bounds(Bounds()); BBox *panel = new BBox(bounds, "background", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER); AddChild(panel); bounds.InsetBy(10.0, 10.0); bounds.right = 230.0; bounds.bottom = 160.0; fMarginView = new MarginView(bounds, int32(width), int32(height), margin, MarginUnit(units)); panel->AddChild(fMarginView); fMarginView->SetResizingMode(B_FOLLOW_NONE); BPopUpMenu* m = new BPopUpMenu("Page size"); m->SetRadioMode(true); bounds.OffsetBy(bounds.Width() + 10.0, 5.0); float divider = be_plain_font->StringWidth("Orientation: "); fPageSizeMenu = new BMenuField(bounds, "page_size", "Page size:", m); panel->AddChild(fPageSizeMenu); fPageSizeMenu->ResizeToPreferred(); fPageSizeMenu->SetDivider(divider); 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); m->AddItem(item); if (label.Compare(pageFormat[i].label) == 0) item->SetMarked(true); } m = new BPopUpMenu("Orientation"); m->SetRadioMode(true); bounds.OffsetBy(0.0, fPageSizeMenu->Bounds().Height() + 10.0); fOrientationMenu = new BMenuField(bounds, "orientation", "Orientation:", m); panel->AddChild(fOrientationMenu); fOrientationMenu->ResizeToPreferred(); fOrientationMenu->SetDivider(divider); 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); m->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"; bounds.OffsetBy(0.0, fOrientationMenu->Bounds().Height() + 10.0); bounds.right -= 30.0; fScaleControl = new BTextControl(bounds, "scale", "Scale [%]:", scale.String(), NULL); panel->AddChild(fScaleControl); fScaleControl->ResizeToPreferred(); fScaleControl->SetDivider(divider); 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); bounds = Bounds(); bounds.InsetBy(5.0, 0.0); bounds.top = MAX(fScaleControl->Frame().bottom, fMarginView->Frame().bottom) + 10.0; BBox *line = new BBox(BRect(bounds.left, bounds.top, bounds.right, bounds.top + 1.0), NULL, B_FOLLOW_LEFT_RIGHT); panel->AddChild(line); bounds.InsetBy(5.0, 0.0); bounds.OffsetBy(0.0, 11.0); BButton *cancel = new BButton(bounds, NULL, "Cancel", new BMessage(CANCEL_MSG)); panel->AddChild(cancel); cancel->ResizeToPreferred(); BButton *ok = new BButton(bounds, NULL, "OK", new BMessage(OK_MSG)); panel->AddChild(ok, cancel); ok->ResizeToPreferred(); bounds.right = fScaleControl->Frame().right; ok->MoveTo(bounds.right - ok->Bounds().Width(), ok->Frame().top); bounds = ok->Frame(); cancel->MoveTo(bounds.left - cancel->Bounds().Width() - 10.0, bounds.top); ok->MakeDefault(true); ResizeTo(bounds.right + 10.0, bounds.bottom + 10.0); BRect winFrame(Frame()); BRect screenFrame(BScreen().Frame()); MoveTo((screenFrame.right - winFrame.right) / 2, (screenFrame.bottom - winFrame.bottom) / 2); }
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); }
PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName) : HWindow(BRect(0,0,400,220), "Page setup", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE), 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); // add a *dialog* background BRect bounds(Bounds()); BBox *panel = new BBox(bounds, "background", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER); AddChild(panel); bounds.InsetBy(10.0, 10.0); bounds.right = 230.0; bounds.bottom = 160.0; fMarginView = new MarginView(bounds, int32(width), int32(height), margin, MarginUnit(units)); panel->AddChild(fMarginView); fMarginView->SetResizingMode(B_FOLLOW_NONE); BPopUpMenu* m = new BPopUpMenu("Page size"); m->SetRadioMode(true); bounds.OffsetBy(bounds.Width() + 10.0, 5.0); float divider = be_plain_font->StringWidth("PDF compatibility: "); fPageSizeMenu = new BMenuField(bounds, "page_size", "Page size:", m); panel->AddChild(fPageSizeMenu); fPageSizeMenu->ResizeToPreferred(); fPageSizeMenu->SetDivider(divider); 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); m->AddItem(item); if (label.Compare(pageFormat[i].label) == 0) item->SetMarked(true); } m = new BPopUpMenu("Orientation"); m->SetRadioMode(true); bounds.OffsetBy(0.0, fPageSizeMenu->Bounds().Height() + 10.0); fOrientationMenu = new BMenuField(bounds, "orientation", "Orientation:", m); panel->AddChild(fOrientationMenu); fOrientationMenu->ResizeToPreferred(); fOrientationMenu->SetDivider(divider); 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); m->AddItem(item); if (fCurrentOrientation == orientation[i].orientation) item->SetMarked(true); } m = new BPopUpMenu("PDF compatibility"); m->SetRadioMode(true); bounds.OffsetBy(0.0, fOrientationMenu->Bounds().Height() + 10.0); fPDFCompatibilityMenu = new BMenuField(bounds, "pdf_compatibility", "PDF compatibility:", m); panel->AddChild(fPDFCompatibilityMenu); fPDFCompatibilityMenu->ResizeToPreferred(); fPDFCompatibilityMenu->SetDivider(divider); fPDFCompatibilityMenu->Menu()->SetLabelFromMarked(true); for (int32 i = 0; pdf_compatibility[i] != NULL; i++) { BMenuItem* item = new BMenuItem(pdf_compatibility[i], NULL); m->AddItem(item); if (setting_value == pdf_compatibility[i]) item->SetMarked(true); } bounds.OffsetBy(0.0, fPDFCompatibilityMenu->Bounds().Height() + 10.0); fPDFCompressionSlider = new BSlider(bounds, "pdf_compression", "Compression:", NULL, 0, 9); panel->AddChild(fPDFCompressionSlider); fPDFCompressionSlider->SetLimitLabels("None", "Best"); fPDFCompressionSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); fPDFCompressionSlider->SetValue(compression); fPDFCompressionSlider->ResizeToPreferred(); bounds = Bounds(); bounds.InsetBy(5.0, 0.0); bounds.top = MAX(fPDFCompressionSlider->Frame().bottom, fMarginView->Frame().bottom) + 10.0; BBox *line = new BBox(BRect(bounds.left, bounds.top, bounds.right, bounds.top + 1.0), NULL, B_FOLLOW_LEFT_RIGHT); panel->AddChild(line); bounds.InsetBy(5.0, 0.0); bounds.OffsetBy(0.0, 11.0); BButton *cancel = new BButton(bounds, NULL, "Cancel", new BMessage(CANCEL_MSG)); panel->AddChild(cancel); cancel->ResizeToPreferred(); BButton *ok = new BButton(bounds, NULL, "OK", new BMessage(OK_MSG)); panel->AddChild(ok, cancel); ok->ResizeToPreferred(); bounds.right = fPDFCompressionSlider->Frame().right; ok->MoveTo(bounds.right - ok->Bounds().Width(), ok->Frame().top); bounds = ok->Frame(); cancel->MoveTo(bounds.left - cancel->Bounds().Width() - 10.0, bounds.top); ok->MakeDefault(true); ResizeTo(bounds.right + 10.0, bounds.bottom + 10.0); BButton *button = new BButton(bounds, NULL, "Fonts" B_UTF8_ELLIPSIS, new BMessage(FONTS_MSG)); panel->AddChild(button); button->ResizeToPreferred(); button->MoveTo(fMarginView->Frame().left, bounds.top); bounds = button->Frame(); button = new BButton(bounds, NULL, "Advanced" B_UTF8_ELLIPSIS, new BMessage(ADVANCED_MSG)); panel->AddChild(button); button->ResizeToPreferred(); button->MoveTo(bounds.right + 10, bounds.top); BRect winFrame(Frame()); BRect screenFrame(BScreen().Frame()); MoveTo((screenFrame.right - winFrame.right) / 2, (screenFrame.bottom - winFrame.bottom) / 2); }