From 5a695bce105f327b826d66fb194d6564d6c3580a Mon Sep 17 00:00:00 2001 From: Michael Pfeiffer Date: Sat, 16 Oct 2010 19:56:34 +0000 Subject: [PATCH] * Use layout API in libprint dialogs. * Use layout API in preview printer add-on. * Use layout API in some dialogs in PDF Writer. * Removed unused class PrinterSetupWindow from PDF Writer. * Improved layout in print_server configuration dialog. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38986 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- build/jam/HaikuImage | 10 +- headers/libs/print/libprint/JSDSlider.h | 9 +- headers/libs/print/libprint/JobSetupDlg.h | 7 +- headers/libs/print/libprint/MarginView.h | 40 +- headers/libs/print/libprint/PageSetupDlg.h | 9 +- src/add-ons/print/drivers/pdf/source/Jamfile | 1 - .../drivers/pdf/source/JobSetupWindow.cpp | 251 +++---- .../print/drivers/pdf/source/JobSetupWindow.h | 1 - .../drivers/pdf/source/PageSetupWindow.cpp | 145 ++-- .../drivers/pdf/source/PrinterDriver.cpp | 6 +- .../drivers/pdf/source/PrinterSetupWindow.cpp | 249 ------- .../drivers/pdf/source/PrinterSetupWindow.h | 72 -- .../print/drivers/preview/JobSetupWindow.cpp | 107 ++- .../print/drivers/preview/PageSetupWindow.cpp | 113 ++- src/libs/print/libprint/JSDSlider.cpp | 15 +- src/libs/print/libprint/JobSetupDlg.cpp | 655 ++++++------------ src/libs/print/libprint/MarginView.cpp | 447 +++++------- src/libs/print/libprint/PageSetupDlg.cpp | 206 ++---- src/libs/print/libprint/StatusWindow.cpp | 4 +- src/servers/print/ConfigWindow.cpp | 40 +- 20 files changed, 779 insertions(+), 1608 deletions(-) delete mode 100644 src/add-ons/print/drivers/pdf/source/PrinterSetupWindow.cpp delete mode 100644 src/add-ons/print/drivers/pdf/source/PrinterSetupWindow.h diff --git a/build/jam/HaikuImage b/build/jam/HaikuImage index fbb4fb7779..d0b0d4fc30 100644 --- a/build/jam/HaikuImage +++ b/build/jam/HaikuImage @@ -139,8 +139,14 @@ SYSTEM_ADD_ONS_MEDIA = cortex_audioadapter.media_addon #legacy.media_addon ; SYSTEM_ADD_ONS_MEDIA_PLUGINS = $(X86_ONLY)ffmpeg raw_decoder ; -SYSTEM_ADD_ONS_PRINT = Canon\ LIPS3\ Compatible Canon\ LIPS4\ Compatible - PCL5\ Compatible PCL6\ Compatible PDF\ Writer PS\ Compatible Preview +SYSTEM_ADD_ONS_PRINT = + Canon\ LIPS3\ Compatible + Canon\ LIPS4\ Compatible + PCL5\ Compatible + PCL6\ Compatible + PDF\ Writer + PS\ Compatible + Preview ; SYSTEM_ADD_ONS_PRINT_TRANSPORT = HP\ JetDirect IPP LPR Parallel\ Port Print\ To\ File Serial\ Port USB\ Port diff --git a/headers/libs/print/libprint/JSDSlider.h b/headers/libs/print/libprint/JSDSlider.h index 2c1a042bc3..ee921ab189 100644 --- a/headers/libs/print/libprint/JSDSlider.h +++ b/headers/libs/print/libprint/JSDSlider.h @@ -17,15 +17,12 @@ class JSDSlider : public BSlider { public: - JSDSlider(BRect frame, const char* name, const char *label, - BMessage *msg, int32 min, int32 max, thumb_style t); + JSDSlider(const char* name, const char* label, + BMessage* msg, int32 min, int32 max); virtual ~JSDSlider(); -#ifdef __HAIKU__ virtual const char* UpdateText() const; -#else - virtual char* UpdateText() const; -#endif + private: mutable BString fResult; }; diff --git a/headers/libs/print/libprint/JobSetupDlg.h b/headers/libs/print/libprint/JobSetupDlg.h index f164bfbd00..a65228f2f9 100644 --- a/headers/libs/print/libprint/JobSetupDlg.h +++ b/headers/libs/print/libprint/JobSetupDlg.h @@ -26,14 +26,15 @@ class PagesView; class JobSetupView : public BView { public: - JobSetupView(BRect frame, JobData *job_data, PrinterData *printer_data, const PrinterCap *printer_cap); + JobSetupView(JobData* job_data, PrinterData* printer_data, + const PrinterCap* printer_cap); virtual void AttachedToWindow(); - virtual void MessageReceived(BMessage *msg); + virtual void MessageReceived(BMessage* msg); bool UpdateJobData(bool showPreview); private: void UpdateButtonEnabledState(); - BRadioButton* AddPageSelectionItem(BView* parent, BRect rect, const char* name, const char* label, + BRadioButton* CreatePageSelectionItem(const char* name, const char* label, JobData::PageSelection pageSelection); void AllowOnlyDigits(BTextView* textView, int maxDigits); JobData::Color getColor(); diff --git a/headers/libs/print/libprint/MarginView.h b/headers/libs/print/libprint/MarginView.h index 5d784cbee2..040394cb56 100644 --- a/headers/libs/print/libprint/MarginView.h +++ b/headers/libs/print/libprint/MarginView.h @@ -143,6 +143,24 @@ enum MarginUnit { kUnitPoint }; +class PageView : public BView +{ +public: + PageView(); + + void SetPageSize(float pageWidth, float pageHeight); + void SetMargins(BRect margins); + + virtual void Draw(BRect bounds); + + +private: + float fPageWidth; + float fPageHeight; + + BRect fMargins; +}; + /** * Class MarginView */ @@ -151,7 +169,7 @@ class MarginView : public BBox friend class MarginManager; public: - MarginView(BRect rect, int32 pageWidth = 0, + MarginView(int32 pageWidth = 0, int32 pageHeight = 0, BRect margins = BRect(1, 1, 1, 1), // 1 inch MarginUnit unit = kUnitInch); @@ -159,8 +177,6 @@ public: virtual ~MarginView(); virtual void AttachedToWindow(); - virtual void Draw(BRect rect); - virtual void FrameResized(float width, float height); virtual void MessageReceived(BMessage *msg); // point.x = width, point.y = height @@ -190,33 +206,25 @@ private: // performed internally using the supplied popup void _SetMarginUnit(MarginUnit unit); - // Calculate the view size for the margins - void _CalculateViewSize(uint32 msg); - private: BTextControl* fTop; BTextControl* fBottom; BTextControl* fLeft; BTextControl* fRight; - // rect that holds the margins for the page as a set of point offsets - BRect fMargins; - - // the maximum size of the page view calculated from the view size - float fMaxPageWidth; - float fMaxPageHeight; - // the actual size of the page in points float fPageHeight; float fPageWidth; + // rect that holds the margins for the page as a set of point offsets + BRect fMargins; + // the units used to calculate the page size MarginUnit fMarginUnit; float fUnitValue; - // the size of the drawing area we have to draw the view in pixels - float fViewHeight; - float fViewWidth; + PageView* fPage; + BStringView* fPageSize; }; #endif // _MARGIN_VIEW_H diff --git a/headers/libs/print/libprint/PageSetupDlg.h b/headers/libs/print/libprint/PageSetupDlg.h index 659098cf61..2cb5bd47bf 100644 --- a/headers/libs/print/libprint/PageSetupDlg.h +++ b/headers/libs/print/libprint/PageSetupDlg.h @@ -20,7 +20,8 @@ class MarginView; class PageSetupView : public BView { public: - PageSetupView(BRect frame, JobData *job_data, PrinterData *printer_data, const PrinterCap *printer_cap); + PageSetupView(JobData *job_data, PrinterData *printer_data, + const PrinterCap *printer_cap); ~PageSetupView(); virtual void AttachedToWindow(); bool UpdateJobData(); @@ -43,11 +44,13 @@ private: class PageSetupDlg : public DialogWindow { public: - PageSetupDlg(JobData *job_data, PrinterData *printer_data, const PrinterCap *printer_cap); + PageSetupDlg(JobData *job_data, PrinterData *printer_data, + const PrinterCap *printer_cap); virtual void MessageReceived(BMessage *message); private: - BMessageFilter *fFilter; + BMessageFilter* fFilter; + PageSetupView* fPageSetupView; }; #endif /* __PAGESETUPDLG_H */ diff --git a/src/add-ons/print/drivers/pdf/source/Jamfile b/src/add-ons/print/drivers/pdf/source/Jamfile index 783c16bfff..8518c861b6 100644 --- a/src/add-ons/print/drivers/pdf/source/Jamfile +++ b/src/add-ons/print/drivers/pdf/source/Jamfile @@ -35,7 +35,6 @@ Addon PDF\ Writer : PrinterDriver.cpp PrinterPrefs.cpp PrinterSettings.cpp - PrinterSetupWindow.cpp RegExp.cpp Report.cpp Scanner.cpp diff --git a/src/add-ons/print/drivers/pdf/source/JobSetupWindow.cpp b/src/add-ons/print/drivers/pdf/source/JobSetupWindow.cpp index ca8be30496..d200d45baa 100644 --- a/src/add-ons/print/drivers/pdf/source/JobSetupWindow.cpp +++ b/src/add-ons/print/drivers/pdf/source/JobSetupWindow.cpp @@ -3,6 +3,7 @@ PDF Writer printer driver. Copyright (c) 2001-2003 OpenBeOS. +Copyright (c) 2010 Haiku, Inc. Authors: Philippe Houdoin @@ -29,6 +30,9 @@ THE SOFTWARE. */ +#include +#include +#include #include #include #include @@ -40,51 +44,40 @@ THE SOFTWARE. #include "DocInfoWindow.h" static const char* includeKeys[] = { - "doc_info", + "doc_info", #if HAVE_FULLVERSION_PDF_LIB - "master_password", "user_password", "permissions", + "master_password", "user_password", "permissions", #endif NULL }; // -------------------------------------------------- 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) + : 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) { - fSetupMsg = msg; - fExitSem = create_sem(0, "JobSetup"); - fResult = B_ERROR; - + 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); + int32 firstPage; fSetupMsg->FindInt32("first_page", &firstPage); + int32 lastPage; fSetupMsg->FindInt32("last_page", &lastPage); + BMessage doc_info; - if (B_OK != fSetupMsg->FindMessage("doc_info", &doc_info)) { + if (fSetupMsg->FindMessage("doc_info", &doc_info) != B_OK) { // default fields doc_info.AddString("Author", ""); doc_info.AddString("Subject", ""); @@ -92,157 +85,84 @@ JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName) fSetupMsg->AddMessage("doc_info", &doc_info); } AddFields(&fDocInfo, fSetupMsg, NULL, includeKeys); + + bool allPages = firstPage == 1 && lastPage == MAX_INT32; - 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; - - // add a "all" radiobutton - fAll = new BRadioButton(BRect(x, y, x+100, y+20), "all_pages", kAllPagesLabel, - new BMessage(ALL_PAGES_MGS)); - fAll->ResizeToPreferred(); - fAll->GetPreferredSize(&w, &h); + fAll = new BRadioButton("allPages", "Print all pages", + new BMessage(ALL_PAGES_MGS)); fAll->SetValue(allPages); - panel->AddChild(fAll); - y += h + kMargin; // "new line" - - // add a range selection raddiobutton - fRange = new BRadioButton(BRect(x, y, x+100, y+20), "pages_range_selection", kPagesRangeSelectionLabel, - new BMessage(RANGE_SELECTION_MSG)); - fRange->ResizeToPreferred(); - fRange->GetPreferredSize(&w, &h); + fRange = new BRadioButton("pagesRange", "Print pages:", + new BMessage(RANGE_SELECTION_MSG)); fRange->SetValue(!allPages); - panel->AddChild(fRange); - x += w + kMargin; - - // add a "from" field - if (allPages) { - buffer[0] = 0; - } else { - sprintf(buffer, "%d", (int)firstPage); - } - fFrom = new BTextControl(BRect(x, y, x+100, y+20), "from_field", kFromLabel, buffer, - new BMessage(RANGE_FROM_MSG)); + fFrom = new BTextControl("from", "From:", "SomeSpaceHere", NULL); fFrom->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT); - fFrom->SetDivider(be_plain_font->StringWidth(kFromLabelExtraSpace)); - fFrom->ResizeToPreferred(); - fFrom->GetPreferredSize(&w, &h); - panel->AddChild(fFrom); + fFrom->SetEnabled(!allPages); - x += w + kMargin; - - // add a "to" field - if (allPages) { - buffer[0] = 0; - } else { - sprintf(buffer, "%d", (int)lastPage); - } - fTo = new BTextControl(BRect(x, y, x+100, y+20), "to_field", kToLabel, buffer, - new BMessage(RANGE_TO_MSG)); + fTo = new BTextControl("to", "To:", "", NULL); fTo->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT); - fTo->SetDivider(be_plain_font->StringWidth(kToLabelExtraSpace)); - fTo->ResizeToPreferred(); - fTo->GetPreferredSize(&w, &h); - panel->AddChild(fTo); + fTo->SetEnabled(!allPages); - y += h + kMargin + kMargin; // "new line" - x = r.left + kMargin; + BString buffer; + buffer << firstPage; + fFrom->SetText(buffer.String()); - // add a separator line... - line = new BBox(BRect(r.left, y - 1, r.right, y), NULL, - B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP ); - panel->AddChild(line); + buffer = ""; + buffer << lastPage; + fTo->SetText(buffer.String()); - y += 2 + kMargin + kMargin; // "new line" + for (uint32 i = 0; i < '0'; i++) { + fTo->TextView()->DisallowChar(i); + fFrom->TextView()->DisallowChar(i); + } - // add a "OK" button, and make it default - ok = new BButton(BRect(x, y, x+100, y+20), NULL, "OK", new BMessage(OK_MSG), B_FOLLOW_RIGHT | B_FOLLOW_TOP); + 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); - ok->ResizeToPreferred(); - ok->GetPreferredSize(&w, &h); - x = r.right - w - kMargin; - ok->MoveTo(x, ok->Frame().top); // put the ok bottom at bottom right corner - panel->AddChild(ok); - // add a "Cancel" button - cancel = new BButton(BRect(x, y, x + 100, y + 20), NULL, "Cancel", new BMessage(CANCEL_MSG), B_FOLLOW_RIGHT | B_FOLLOW_TOP); - cancel->ResizeToPreferred(); - cancel->GetPreferredSize(&w, &h); - cancel->MoveTo(x - w - kMargin, y); // put cancel button left next the ok button - panel->AddChild(cancel); + 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); - // add a "DocInfo" button - BButton *button = new BButton(r, NULL, "Doc Info", new BMessage(DOC_INFO_MSG), - B_FOLLOW_RIGHT | B_FOLLOW_TOP); - button->GetPreferredSize(&w, &h); - button->ResizeToPreferred(); - button->MoveTo(8, y); - panel->AddChild(button); - - // Finally, add our panel to window - AddChild(panel); - - // Auto resize window - ResizeTo(ok->Frame().right + kMargin, ok->Frame().bottom + kMargin); + 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) + ); } // -------------------------------------------------- void -JobSetupWindow::UpdateJobMessage() +JobSetupWindow::UpdateJobMessage() { int32 copies = 1; @@ -290,14 +210,19 @@ JobSetupWindow::MessageReceived(BMessage *msg) fResult = B_OK; release_sem(fExitSem); break; - + case CANCEL_MSG: release_sem(fExitSem); break; - case RANGE_FROM_MSG: - case RANGE_TO_MSG: - fRange->SetValue(B_CONTROL_ON); + case ALL_PAGES_MGS: + fTo->SetEnabled(false); + fFrom->SetEnabled(false); + break; + + case RANGE_SELECTION_MSG: + fTo->SetEnabled(true); + fFrom->SetEnabled(true); break; case DOC_INFO_MSG: @@ -309,7 +234,7 @@ JobSetupWindow::MessageReceived(BMessage *msg) break; } } - + // -------------------------------------------------- status_t diff --git a/src/add-ons/print/drivers/pdf/source/JobSetupWindow.h b/src/add-ons/print/drivers/pdf/source/JobSetupWindow.h index e95e70918a..5895ff7836 100644 --- a/src/add-ons/print/drivers/pdf/source/JobSetupWindow.h +++ b/src/add-ons/print/drivers/pdf/source/JobSetupWindow.h @@ -71,7 +71,6 @@ private: status_t fResult; BMessage *fSetupMsg; BMessage fDocInfo; - BTextControl *fCopies; BRadioButton *fAll; BRadioButton *fRange; BTextControl *fFrom; diff --git a/src/add-ons/print/drivers/pdf/source/PageSetupWindow.cpp b/src/add-ons/print/drivers/pdf/source/PageSetupWindow.cpp index 344546221f..946234643e 100644 --- a/src/add-ons/print/drivers/pdf/source/PageSetupWindow.cpp +++ b/src/add-ons/print/drivers/pdf/source/PageSetupWindow.cpp @@ -45,6 +45,9 @@ THE SOFTWARE. #include #include +#include +#include +#include #include #include #include @@ -92,15 +95,16 @@ static const char *pdf_compatibility[] = { "1.3", "1.4", NULL }; 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), + : 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), fResult(B_ERROR), fSetupMsg(msg), fAdvancedSettings(*msg), fPrinterDirName(printerName) { - fExitSem = create_sem(0, "PageSetup"); + fExitSem = create_sem(0, "PageSetup"); if (printerName) SetTitle(BString(printerName).Append(" page setup").String()); @@ -151,29 +155,13 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName) 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, + fMarginView = new MarginView(int32(width), int32(height), margin, MarginUnit(units)); - panel->AddChild(fMarginView); - fMarginView->SetResizingMode(B_FOLLOW_NONE); - BPopUpMenu* m = new BPopUpMenu("Page size"); - m->SetRadioMode(true); + BPopUpMenu* pageSize = new BPopUpMenu("Page size"); + pageSize->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 = new BMenuField("page_size", "Page size:", pageSize); fPageSizeMenu->Menu()->SetLabelFromMarked(true); for (int32 i = 0; pageFormat[i].label != NULL; i++) { @@ -181,98 +169,97 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName) message->AddFloat("width", pageFormat[i].width); message->AddFloat("height", pageFormat[i].height); BMenuItem* item = new BMenuItem(pageFormat[i].label, message); - m->AddItem(item); + pageSize->AddItem(item); if (label.Compare(pageFormat[i].label) == 0) item->SetMarked(true); } - m = new BPopUpMenu("Orientation"); - m->SetRadioMode(true); + BPopUpMenu* orientationPopUpMenu = new BPopUpMenu("Orientation"); + orientationPopUpMenu->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 = 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); - m->AddItem(item); + orientationPopUpMenu->AddItem(item); if (fCurrentOrientation == orientation[i].orientation) item->SetMarked(true); } - m = new BPopUpMenu("PDF compatibility"); - m->SetRadioMode(true); + BPopUpMenu* compatibility = new BPopUpMenu("PDF compatibility"); + compatibility->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 = 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); - m->AddItem(item); + compatibility->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 = new BSlider("pdf_compression", + "Compression:", NULL, 0, 9, B_HORIZONTAL); 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); + BBox *separator = new BBox("separator"); + separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); - 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); + BButton *cancel = new BButton("cancel", "Cancel", new BMessage(CANCEL_MSG)); + BButton *ok = new BButton("ok", "OK", new BMessage(OK_MSG)); ok->MakeDefault(true); - ResizeTo(bounds.right + 10.0, bounds.bottom + 10.0); - BButton *button = new BButton(bounds, NULL, "Fonts" B_UTF8_ELLIPSIS, + BButton *fontsButton = new BButton("fonts", "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, + BButton* advancedButton = new BButton("advanced", + "Advanced" B_UTF8_ELLIPSIS, new BMessage(ADVANCED_MSG)); - panel->AddChild(button); - button->ResizeToPreferred(); - button->MoveTo(bounds.right + 10, bounds.top); + + 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()); diff --git a/src/add-ons/print/drivers/pdf/source/PrinterDriver.cpp b/src/add-ons/print/drivers/pdf/source/PrinterDriver.cpp index c7b5d3cb8c..d00d2078c0 100644 --- a/src/add-ons/print/drivers/pdf/source/PrinterDriver.cpp +++ b/src/add-ons/print/drivers/pdf/source/PrinterDriver.cpp @@ -37,7 +37,6 @@ THE SOFTWARE. #include "PrinterDriver.h" -#include "PrinterSetupWindow.h" #include "PageSetupWindow.h" #include "JobSetupWindow.h" #include "StatusWindow.h" @@ -222,10 +221,7 @@ status_t PrinterDriver::PrinterSetup(char *printerName) // name of printer, to attach printer settings { - PrinterSetupWindow *psw; - - psw = new PrinterSetupWindow(printerName); - return psw->Go(); + return B_OK; } diff --git a/src/add-ons/print/drivers/pdf/source/PrinterSetupWindow.cpp b/src/add-ons/print/drivers/pdf/source/PrinterSetupWindow.cpp deleted file mode 100644 index b96d12ff2a..0000000000 --- a/src/add-ons/print/drivers/pdf/source/PrinterSetupWindow.cpp +++ /dev/null @@ -1,249 +0,0 @@ -/* - -PDF Writer printer driver. - -Copyright (c) 2001 OpenBeOS. - -Authors: - Philippe Houdoin - Simon Gauvin - Michael Pfeiffer - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ - -#include -#include -#include - -#include "PrinterSetupWindow.h" - -// -------------------------------------------------- -PrinterSetupWindow::PrinterSetupWindow(char *printerName) - : HWindow(BRect(0,0,300,300), printerName, B_TITLED_WINDOW_LOOK, - B_MODAL_APP_WINDOW_FEEL, B_NOT_ZOOMABLE) -{ - fExitSem = create_sem(0, "PrinterSetup"); - fResult = B_ERROR; - fPrinterName = printerName; - - if (printerName) { - BString title; - title << printerName << " Printer Setup"; - SetTitle(title.String()); - } else - SetTitle("Printer Setup"); - - // ---- Ok, build a default job setup user interface - BRect r; - BButton *button; - float x, y, w, h; - font_height fh; - - r = Bounds(); - - // add a *dialog* background - BBox *panel = new BBox(r, "top_panel", B_FOLLOW_ALL, - B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, - B_PLAIN_BORDER); - - - const int kInterSpace = 8; - const int kHorzMargin = 10; - const int kVertMargin = 10; - - x = kHorzMargin; - y = kVertMargin; - - // add a label before the list - const char *kModelLabel = "Printer model"; - - be_plain_font->GetHeight(&fh); - - w = Bounds().Width(); - w -= 2 * kHorzMargin; - h = 150; - - BBox * model_group = new BBox(BRect(x, y, x+w, y+h), "model_group", B_FOLLOW_ALL_SIDES); - model_group->SetLabel(kModelLabel); - - BRect rlv = model_group->Bounds(); - - rlv.InsetBy(kHorzMargin, kVertMargin); - rlv.top += fh.ascent + fh.descent + fh.leading; - rlv.right -= B_V_SCROLL_BAR_WIDTH; - fModelList = new BListView(rlv, "model_list", - B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL_SIDES ); - - BScrollView * sv = new BScrollView( "model_list_scrollview", fModelList, - B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS, false, true ); - model_group->AddChild(sv); - - panel->AddChild(model_group); - - y += (h + kInterSpace); - - x = r.right - kHorzMargin; - - // add a "OK" button, and make it default - fOkButton = new BButton(BRect(x, y, x + 400, y), NULL, "OK", new BMessage(OK_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); - fOkButton->ResizeToPreferred(); - fOkButton->GetPreferredSize(&w, &h); - x -= w; - fOkButton->MoveTo(x, y); - fOkButton->MakeDefault(true); - fOkButton->SetEnabled(false); - - panel->AddChild(fOkButton); - - x -= kInterSpace; - - // add a "Cancel" button - button = new BButton(BRect(x, y, x + 400, y), NULL, "Cancel", new BMessage(CANCEL_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); - button->ResizeToPreferred(); - button->GetPreferredSize(&w, &h); - x -= w; - button->MoveTo(x, y); - panel->AddChild(button); - - y += (h + kInterSpace); - - panel->ResizeTo(Bounds().Width(), y); - ResizeTo(Bounds().Width(), y); - - float minWidth, maxWidth, minHeight, maxHeight; - - GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight); - SetSizeLimits(panel->Frame().Width(), panel->Frame().Width(), - panel->Frame().Height(), maxHeight); - - // Finally, add our panel to window - AddChild(panel); - - BDirectory Folder; - BEntry entry; - - Folder.SetTo ("/boot/beos/etc/bubblejet"); - if (Folder.InitCheck() != B_OK) - return; - - while (Folder.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) { - char name[B_FILE_NAME_LENGTH]; - if (entry.GetName(name) == B_NO_ERROR) - fModelList->AddItem (new BStringItem(name)); - } - - fModelList->SetSelectionMessage(new BMessage(MODEL_MSG)); - fModelList->SetInvocationMessage(new BMessage(OK_MSG)); -} - - -// -------------------------------------------------- -PrinterSetupWindow::~PrinterSetupWindow() -{ - delete_sem(fExitSem); -} - - -// -------------------------------------------------- -bool -PrinterSetupWindow::QuitRequested() -{ - release_sem(fExitSem); - return true; -} - - -// -------------------------------------------------- -void -PrinterSetupWindow::MessageReceived(BMessage *msg) -{ - switch (msg->what) { - case OK_MSG: - { - // Test model selection (if any), save it in printerName node and return - BNode spoolDir; - BPath * path; - - if (fModelList->CurrentSelection() < 0) - break; - - BStringItem * item = dynamic_cast - (fModelList->ItemAt(fModelList->CurrentSelection())); - - if (!item) - break; - - path = new BPath(); - - find_directory(B_USER_SETTINGS_DIRECTORY, path); - path->Append("printers"); - path->Append(fPrinterName); - - spoolDir.SetTo(path->Path()); - delete path; - - if (spoolDir.InitCheck() != B_OK) { - BAlert * alert = new BAlert("Uh oh!", - "Couldn't find printer spool directory.", "OK"); - alert->Go(); - } else { - spoolDir.WriteAttr("printer_model", B_STRING_TYPE, 0, item->Text(), - strlen(item->Text())); - fResult = B_OK; - } - - release_sem(fExitSem); - break; - } - - case CANCEL_MSG: - fResult = B_ERROR; - release_sem(fExitSem); - break; - - case MODEL_MSG: - fOkButton->SetEnabled((fModelList->CurrentSelection() >= 0)); - break; - - default: - inherited::MessageReceived(msg); - break; - }; -} - - -// -------------------------------------------------- -status_t -PrinterSetupWindow::Go() -{ - MoveTo(300, 300); - Show(); - - while (acquire_sem(fExitSem) == B_INTERRUPTED) { - } - - // cache the value as after Quit() this object is deleted - status_t result = fResult; - if (Lock()) - Quit(); - - return result; -} diff --git a/src/add-ons/print/drivers/pdf/source/PrinterSetupWindow.h b/src/add-ons/print/drivers/pdf/source/PrinterSetupWindow.h deleted file mode 100644 index b1fffcd80f..0000000000 --- a/src/add-ons/print/drivers/pdf/source/PrinterSetupWindow.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - -PDF Writer printer driver. - -Copyright (c) 2001 OpenBeOS. - -Authors: - Philippe Houdoin - Simon Gauvin - Michael Pfeiffer - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ - -#ifndef PRINTERSETUPWINDOW_H -#define PRINTERSETUPWINDOW_H - -#include -#include "BlockingWindow.h" -#include "PrintUtils.h" - -class PrinterSetupWindow : public HWindow -{ -public: - // Constructors, destructors, operators... - - PrinterSetupWindow(char *printerName); - ~PrinterSetupWindow(); - - typedef HWindow inherited; - - // public constantes - enum { - OK_MSG = 'ok__', - CANCEL_MSG = 'cncl', - MODEL_MSG = 'modl' - }; - - // Virtual function overrides -public: - virtual void MessageReceived(BMessage *msg); - virtual bool QuitRequested(); - status_t Go(); - - // From here, it's none of your business! ;-) -private: - BButton *fOkButton; - BListView *fModelList; - char *fPrinterName; - long fExitSem; - status_t fResult; -}; - -#endif - diff --git a/src/add-ons/print/drivers/preview/JobSetupWindow.cpp b/src/add-ons/print/drivers/preview/JobSetupWindow.cpp index 439c7575fb..0986bd7d98 100644 --- a/src/add-ons/print/drivers/preview/JobSetupWindow.cpp +++ b/src/add-ons/print/drivers/preview/JobSetupWindow.cpp @@ -18,15 +18,19 @@ #include #include +#include +#include +#include #include #include #include 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), + : BlockingWindow(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), fPrinterName(printerName), fSetupMsg(msg) { @@ -40,42 +44,20 @@ JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName) 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", + fAll = new BRadioButton("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:", + fRange = new BRadioButton("pagesRange", "Print selected 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 = new BTextControl("from", "From:", "SomeSpaceHere", NULL); 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 = new BTextControl("to", "To:", "", NULL); 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; @@ -96,28 +78,37 @@ JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName) 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); + BBox *separator = new BBox("separator"); + separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); - 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); + BButton *cancel = new BButton("cancel", "Cancel", new BMessage(CANCEL_MSG)); + BButton *ok = new BButton("ok", "OK", new BMessage(OK_MSG)); ok->MakeDefault(true); - ResizeTo(bounds.right + 10.0, bounds.bottom + 10.0); + + 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) + .AddGlue() + .Add(cancel) + .Add(ok) + .End() + .SetInsets(10, 10, 10, 10) + ); + BRect winFrame(Frame()); BRect screenFrame(BScreen().Frame()); @@ -154,27 +145,27 @@ void JobSetupWindow::MessageReceived(BMessage *msg) { switch (msg->what) { - case OK_MSG: { + case OK_MSG: UpdateJobMessage(); Quit(B_OK); - } break; + break; - case CANCEL_MSG: { + case CANCEL_MSG: Quit(B_ERROR); - } break; + break; - case ALL_PAGES_MGS : { + case ALL_PAGES_MGS: fTo->SetEnabled(false); fFrom->SetEnabled(false); - } break; + break; - case RANGE_SELECTION_MSG : { + case RANGE_SELECTION_MSG: fTo->SetEnabled(true); fFrom->SetEnabled(true); - } break; + break; - default: { + default: BlockingWindow::MessageReceived(msg); - } break; + break; } } diff --git a/src/add-ons/print/drivers/preview/PageSetupWindow.cpp b/src/add-ons/print/drivers/preview/PageSetupWindow.cpp index 90b828e997..0a886b697c 100644 --- a/src/add-ons/print/drivers/preview/PageSetupWindow.cpp +++ b/src/add-ons/print/drivers/preview/PageSetupWindow.cpp @@ -20,6 +20,9 @@ #include #include +#include +#include +#include #include #include #include @@ -90,9 +93,11 @@ static struct 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), + : 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), fSetupMsg(msg), fPrinterDirName(printerName) { @@ -134,28 +139,14 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName) 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, + fMarginView = new MarginView(int32(width), int32(height), margin, MarginUnit(units)); - panel->AddChild(fMarginView); - fMarginView->SetResizingMode(B_FOLLOW_NONE); - BPopUpMenu* m = new BPopUpMenu("Page size"); - m->SetRadioMode(true); + BPopUpMenu* pageSizePopUpMenu = new BPopUpMenu("Page size"); + pageSizePopUpMenu->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 = new BMenuField("page_size", "Page size:", pageSizePopUpMenu); fPageSizeMenu->Menu()->SetLabelFromMarked(true); for (int32 i = 0; pageFormat[i].label != NULL; i++) { @@ -163,27 +154,24 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName) message->AddFloat("width", pageFormat[i].width); message->AddFloat("height", pageFormat[i].height); BMenuItem* item = new BMenuItem(pageFormat[i].label, message); - m->AddItem(item); + pageSizePopUpMenu->AddItem(item); if (label.Compare(pageFormat[i].label) == 0) item->SetMarked(true); } - m = new BPopUpMenu("Orientation"); - m->SetRadioMode(true); + BPopUpMenu* orientationPopUpMenu = new BPopUpMenu("Orientation"); + orientationPopUpMenu->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 = 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); - m->AddItem(item); + orientationPopUpMenu->AddItem(item); if (fCurrentOrientation == orientation[i].orientation) item->SetMarked(true); @@ -196,13 +184,8 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName) else scale = "100"; - bounds.OffsetBy(0.0, fOrientationMenu->Bounds().Height() + 10.0); - bounds.right -= 30.0; - fScaleControl = new BTextControl(bounds, "scale", "Scale [%]:", + fScaleControl = new BTextControl("scale", "Scale [%]:", scale.String(), NULL); - panel->AddChild(fScaleControl); - fScaleControl->ResizeToPreferred(); - fScaleControl->SetDivider(divider); for (uint32 i = 0; i < '0'; i++) fScaleControl->TextView()->DisallowChar(i); @@ -212,32 +195,44 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName) 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); + BBox *separator = new BBox("separator"); + separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); - 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); + BButton *cancel = new BButton("cancel", "Cancel", new BMessage(CANCEL_MSG)); + BButton *ok = new BButton("ok", "OK", new BMessage(OK_MSG)); ok->MakeDefault(true); - ResizeTo(bounds.right + 10.0, bounds.bottom + 10.0); + + 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()); diff --git a/src/libs/print/libprint/JSDSlider.cpp b/src/libs/print/libprint/JSDSlider.cpp index bb4a858bed..536f67bf6b 100644 --- a/src/libs/print/libprint/JSDSlider.cpp +++ b/src/libs/print/libprint/JSDSlider.cpp @@ -14,9 +14,9 @@ #include -JSDSlider::JSDSlider(BRect frame, const char* name, const char *label, - BMessage *msg, int32 min, int32 max, thumb_style t) - : BSlider(frame, name, label, msg, min, max, t) +JSDSlider::JSDSlider(const char* name, const char* label, + BMessage* msg, int32 min, int32 max) + : BSlider(name, label, msg, min, max, B_HORIZONTAL) { } @@ -26,10 +26,7 @@ JSDSlider::~JSDSlider() } -#ifdef __HAIKU__ -const -#endif -char* +const char* JSDSlider::UpdateText() const { // When the slider's Draw method is called, this method will also be called. @@ -49,9 +46,5 @@ JSDSlider::UpdateText() const } fResult.SetTo(string); -#ifdef __HAIKU__ return fResult.String(); -#else - return const_cast(fResult.String()); -#endif } diff --git a/src/libs/print/libprint/JobSetupDlg.cpp b/src/libs/print/libprint/JobSetupDlg.cpp index 60a2a8da6b..09bfa7dc78 100644 --- a/src/libs/print/libprint/JobSetupDlg.cpp +++ b/src/libs/print/libprint/JobSetupDlg.cpp @@ -17,6 +17,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -44,292 +47,10 @@ #if (!__MWERKS__ || defined(MSIPL_USING_NAMESPACE)) using namespace std; -#else +#else #define std #endif -//#define PRINT_COPIES 100 - -#define QUALITY_H 10 -#define QUALITY_V 10 -#define QUALITY_WIDTH 180 - - #define BPP_H 10 - #define BPP_V 15 - #define BPP_WIDTH 120 - #define BPP_HEIGHT 16 - - #define DITHER_H BPP_H - #define DITHER_V BPP_V + BPP_HEIGHT + 10 - #define DITHER_WIDTH BPP_WIDTH - #define DITHER_HEIGHT BPP_HEIGHT - - #define GAMMA_H BPP_H - #define GAMMA_V DITHER_V + DITHER_HEIGHT + 10 - #define GAMMA_WIDTH QUALITY_WIDTH - 20 - #define GAMMA_HEIGHT 55 // BPP_HEIGHT - - #define INK_DENSITY_H BPP_H - #define INK_DENSITY_V GAMMA_V + GAMMA_HEIGHT + 5 - #define INK_DENSITY_WIDTH GAMMA_WIDTH - #define INK_DENSITY_HEIGHT 55 // BPP_HEIGHT - - #define HALFTONE_H INK_DENSITY_H - #define HALFTONE_V INK_DENSITY_V + INK_DENSITY_HEIGHT + 5 - #define HALFTONE_WIDTH 160 - #define HALFTONE_HEIGHT 4*11 - -#define QUALITY_HEIGHT HALFTONE_V + HALFTONE_HEIGHT + 5 - -#define PAGERABGE_H QUALITY_H -#define PAGERABGE_V QUALITY_V + QUALITY_HEIGHT + 5 -#define PAGERABGE_WIDTH QUALITY_WIDTH -#define PAGERABGE_HEIGHT 70 - - #define ALL_H 10 - #define ALL_V 20 - #define ALL_WIDTH 36 - #define ALL_HEIGHT 16 - - #define SELECTION_H ALL_H - #define SELECTION_V ALL_V + ALL_HEIGHT + 4 - #define SELECTION_WIDTH 16 - #define SELECTION_HEIGHT 16 - - #define FROM_H (SELECTION_H + SELECTION_WIDTH + 1) - #define FROM_V ALL_V + 19 - #define FROM_WIDTH 73 - #define FROM_HEIGHT 16 - - #define TO_H (FROM_H + FROM_WIDTH + 7) - #define TO_V FROM_V - #define TO_WIDTH 59 - #define TO_HEIGHT FROM_HEIGHT - -#define PRINT_WIDTH 365 -#define PRINT_HEIGHT QUALITY_HEIGHT + PAGERABGE_HEIGHT + 60 - -#define PAPERFEED_H QUALITY_H + QUALITY_WIDTH + 10 -#define PAPERFEED_V QUALITY_V + 5 -#define PAPERFEED_WIDTH 160 -#define PAPERFEED_HEIGHT 16 - -#define NUP_H PAPERFEED_H -#define NUP_V PAPERFEED_V + PAPERFEED_HEIGHT + 7 -#define NUP_WIDTH PAPERFEED_WIDTH -#define NUP_HEIGHT 16 -#define MENU_HEIGHT 16 - -#define COPIES_H PAPERFEED_H -#define COPIES_V NUP_V + NUP_HEIGHT + 10 -#define COPIES_WIDTH 140 -#define COPIES_HEIGHT 16 - -#define DUPLEX_H PAPERFEED_H -#define DUPLEX_V COPIES_V + COPIES_HEIGHT + 7 -#define DUPLEX_WIDTH PAPERFEED_WIDTH -#define DUPLEX_HEIGHT 16 - -#define COLLATE_H PAPERFEED_H -#define COLLATE_V DUPLEX_V + DUPLEX_HEIGHT + 5 -#define COLLATE_WIDTH PAPERFEED_WIDTH -#define COLLATE_HEIGHT 16 - -#define REVERSE_H PAPERFEED_H -#define REVERSE_V COLLATE_V + COLLATE_HEIGHT + 5 -#define REVERSE_WIDTH PAPERFEED_WIDTH -#define REVERSE_HEIGHT 16 - -#define PAGES_H PAPERFEED_H -#define PAGES_V REVERSE_V + REVERSE_HEIGHT + 5 -#define PAGES_WIDTH PAPERFEED_WIDTH -#define PAGES_HEIGHT 40 - -#define PAGE_SELECTION_H PAPERFEED_H -#define PAGE_SELECTION_V PAGES_V + PAGES_HEIGHT + 5 -#define PAGE_SELECTION_WIDTH PAPERFEED_WIDTH -#define PAGE_SELECTION_HEIGHT 3 * 16 + 30 - - #define PS_ALL_PAGES_H 10 - #define PS_ALL_PAGES_V 20 - #define PS_ALL_PAGES_WIDTH PAGE_SELECTION_WIDTH - 20 - #define PS_ALL_PAGES_HEIGHT 16 - - #define PS_ODD_PAGES_H PS_ALL_PAGES_H - #define PS_ODD_PAGES_V PS_ALL_PAGES_V + PS_ALL_PAGES_HEIGHT - #define PS_ODD_PAGES_WIDTH PS_ALL_PAGES_WIDTH - #define PS_ODD_PAGES_HEIGHT PS_ALL_PAGES_HEIGHT - - #define PS_EVEN_PAGES_H PS_ALL_PAGES_H - #define PS_EVEN_PAGES_V PS_ODD_PAGES_V + PS_ODD_PAGES_HEIGHT - #define PS_EVEN_PAGES_WIDTH PS_ALL_PAGES_WIDTH - #define PS_EVEN_PAGES_HEIGHT PS_ALL_PAGES_HEIGHT - -#define PRINT_BUTTON_WIDTH 70 -#define PRINT_BUTTON_HEIGHT 20 - -#define PRINT_LINE_V (PRINT_HEIGHT - PRINT_BUTTON_HEIGHT - 23) - -#define PRINT_OK_BUTTON_H (PRINT_WIDTH - PRINT_BUTTON_WIDTH - 10) -#define PRINT_OK_BUTTON_V (PRINT_HEIGHT - PRINT_BUTTON_HEIGHT - 11) - -#define PREVIEW_H (PRINT_OK_BUTTON_H - PRINT_BUTTON_WIDTH - 12) -#define PREVIEW_V (PRINT_OK_BUTTON_V) - -#define PRINT_CANCEL_BUTTON_H (PREVIEW_H - PRINT_BUTTON_WIDTH - 12) -#define PRINT_CANCEL_BUTTON_V PRINT_OK_BUTTON_V - -const BRect quality_rect( - QUALITY_H, - QUALITY_V, - QUALITY_H + QUALITY_WIDTH, - QUALITY_V + QUALITY_HEIGHT); - -BRect bpp_rect( - BPP_H, - BPP_V, - BPP_H + BPP_WIDTH, - BPP_V + BPP_HEIGHT); - -BRect dither_rect( - DITHER_H, - DITHER_V, - DITHER_H + DITHER_WIDTH, - DITHER_V + DITHER_HEIGHT); - -const BRect ink_density_rect( - INK_DENSITY_H, - INK_DENSITY_V, - INK_DENSITY_H + INK_DENSITY_WIDTH, - INK_DENSITY_V + INK_DENSITY_HEIGHT); - -const BRect halftone_rect( - HALFTONE_H, - HALFTONE_V, - HALFTONE_H + HALFTONE_WIDTH, - HALFTONE_V + HALFTONE_HEIGHT); - -const BRect gamma_rect( - GAMMA_H, - GAMMA_V, - GAMMA_H + GAMMA_WIDTH, - GAMMA_V + GAMMA_HEIGHT); - -const BRect pagerange_rect( - PAGERABGE_H, - PAGERABGE_V, - PAGERABGE_H + PAGERABGE_WIDTH, - PAGERABGE_V + PAGERABGE_HEIGHT); - -const BRect all_button_rect( - ALL_H, - ALL_V, - ALL_H + ALL_WIDTH, - ALL_V + ALL_HEIGHT); - -const BRect selection_rect( - SELECTION_H, - SELECTION_V, - SELECTION_H + SELECTION_WIDTH, - SELECTION_V + SELECTION_HEIGHT); - -const BRect from_rect( - FROM_H, - FROM_V, - FROM_H + FROM_WIDTH, - FROM_V + FROM_HEIGHT); - -const BRect to_rect( - TO_H, - TO_V, - TO_H + TO_WIDTH, - TO_V + TO_HEIGHT); - -const BRect paperfeed_rect( - PAPERFEED_H, - PAPERFEED_V, - PAPERFEED_H + PAPERFEED_WIDTH, - PAPERFEED_V + PAPERFEED_HEIGHT); - -BRect nup_rect( - NUP_H, - NUP_V, - NUP_H + NUP_WIDTH, - NUP_V + NUP_HEIGHT); - -const BRect copies_rect( - COPIES_H, - COPIES_V, - COPIES_H + COPIES_WIDTH, - COPIES_V + COPIES_HEIGHT); - -const BRect duplex_rect( - DUPLEX_H, - DUPLEX_V, - DUPLEX_H + DUPLEX_WIDTH, - DUPLEX_V + DUPLEX_HEIGHT); - -const BRect collate_rect( - COLLATE_H, - COLLATE_V, - COLLATE_H + COLLATE_WIDTH, - COLLATE_V + COLLATE_HEIGHT); - -const BRect reverse_rect( - REVERSE_H, - REVERSE_V, - REVERSE_H + REVERSE_WIDTH, - REVERSE_V + REVERSE_HEIGHT); - -const BRect pages_rect( - PAGES_H, - PAGES_V, - PAGES_H + PAGES_WIDTH, - PAGES_V + PAGES_HEIGHT); - -const BRect page_selection_rect( - PAGE_SELECTION_H, - PAGE_SELECTION_V, - PAGE_SELECTION_H + PAGE_SELECTION_WIDTH, - PAGE_SELECTION_V + PAGE_SELECTION_HEIGHT); - -const BRect page_selection_all_pages_rect( - PS_ALL_PAGES_H, - PS_ALL_PAGES_V, - PS_ALL_PAGES_H + PS_ALL_PAGES_WIDTH, - PS_ALL_PAGES_V + PS_ALL_PAGES_HEIGHT); - -const BRect page_selection_odd_pages_rect( - PS_ODD_PAGES_H, - PS_ODD_PAGES_V, - PS_ODD_PAGES_H + PS_ODD_PAGES_WIDTH, - PS_ODD_PAGES_V + PS_ODD_PAGES_HEIGHT); - -const BRect page_selection_even_pages_rect( - PS_EVEN_PAGES_H, - PS_EVEN_PAGES_V, - PS_EVEN_PAGES_H + PS_EVEN_PAGES_WIDTH, - PS_EVEN_PAGES_V + PS_EVEN_PAGES_HEIGHT); - -const BRect ok_rect( - PRINT_OK_BUTTON_H, - PRINT_OK_BUTTON_V, - PRINT_OK_BUTTON_H + PRINT_BUTTON_WIDTH, - PRINT_OK_BUTTON_V + PRINT_BUTTON_HEIGHT); - -const BRect cancel_rect( - PRINT_CANCEL_BUTTON_H, - PRINT_CANCEL_BUTTON_V, - PRINT_CANCEL_BUTTON_H + PRINT_BUTTON_WIDTH, - PRINT_CANCEL_BUTTON_V + PRINT_BUTTON_HEIGHT); - -const BRect preview_rect( - PREVIEW_H, - PREVIEW_V, - PREVIEW_H + PRINT_BUTTON_WIDTH, - PREVIEW_V + PRINT_BUTTON_HEIGHT); - - struct SurfaceCap : public BaseCap { color_space surface_type; @@ -404,21 +125,24 @@ enum { kMsgDuplexChanged, }; -JobSetupView::JobSetupView(BRect frame, JobData *job_data, PrinterData *printer_data, const PrinterCap *printer_cap) - : BView(frame, "", B_FOLLOW_ALL, B_WILL_DRAW), fJobData(job_data), fPrinterData(printer_data), fPrinterCap(printer_cap) +JobSetupView::JobSetupView(JobData *job_data, PrinterData *printer_data, + const PrinterCap *printer_cap) + : BView("jobSetup", B_WILL_DRAW) + , fJobData(job_data) + , fPrinterData(printer_data) + , fPrinterCap(printer_cap) { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); } BRadioButton* -JobSetupView::AddPageSelectionItem(BView* parent, BRect rect, const char* name, const char* label, +JobSetupView::CreatePageSelectionItem(const char* name, const char* label, JobData::PageSelection pageSelection) { - BRadioButton* button = new BRadioButton(rect, name, label, NULL); + BRadioButton* button = new BRadioButton(name, label, NULL); if (fJobData->getPageSelection() == pageSelection) { button->SetValue(B_CONTROL_ON); } - parent->AddChild(button); return button; } @@ -438,54 +162,22 @@ JobSetupView::AllowOnlyDigits(BTextView* textView, int maxDigits) void JobSetupView::AttachedToWindow() { - BBox *box; - BMenuItem *item = NULL; - BMenuField *menufield; - BButton *button; - float width; - bool marked; - int count; + // quality + BBox* qualityBox = new BBox("quality"); + qualityBox->SetLabel("Quality"); - /* quality */ - - box = new BBox(quality_rect); - AddChild(box); - box->SetLabel("Quality"); - -/* - // always B_RGB32 - fSurfaceType = new BPopUpMenu(""); - fSurfaceType->SetRadioMode(true); - - count = sizeof(gSurfaces) / sizeof(gSurfaces[0]); - const SurfaceCap **surface_cap = gSurfaces; - uint32 support_flags; - while (count--) { - if (bitmaps_support_space((*surface_cap)->surface_type, &support_flags)) { - item = new BMenuItem((*surface_cap)->label.c_str(), NULL); - fSurfaceType->AddItem(item); - if ((*surface_cap)->surface_type == fJobData->getSurfaceType()) { - item->SetMarked(true); - marked = true; - } - } - surface_cap++; - } - menufield = new BMenuField(bpp_rect, "", "Surface Type", fSurfaceType); - box->AddChild(menufield); - width = StringWidth("Color") + 10; - menufield->SetDivider(width); -*/ - - /* color */ - marked = false; - fColorType = new BPopUpMenu(""); + // color + fColorType = new BPopUpMenu("color"); fColorType->SetRadioMode(true); - count = fPrinterCap->countCap(PrinterCap::kColor); - const ColorCap **color_cap = (const ColorCap **)fPrinterCap->enumCap(PrinterCap::kColor); + int count = fPrinterCap->countCap(PrinterCap::kColor); + const ColorCap **color_cap = (const ColorCap **)fPrinterCap->enumCap( + PrinterCap::kColor); + bool marked = false; + BMenuItem* item = NULL; while (count--) { - item = new BMenuItem((*color_cap)->label.c_str(), new BMessage(kMsgQuality)); + item = new BMenuItem((*color_cap)->label.c_str(), + new BMessage(kMsgQuality)); fColorType->AddItem(item); if ((*color_cap)->color == fJobData->getColor()) { item->SetMarked(true); @@ -495,23 +187,21 @@ JobSetupView::AttachedToWindow() } if (!marked && item) item->SetMarked(true); - bpp_rect.right = bpp_rect.left + StringWidth("Color:") + fColorType->MaxContentWidth() + 10; - menufield = new BMenuField(bpp_rect, "color", "Color:", fColorType); - box->AddChild(menufield); - width = StringWidth("Color:") + 10; - menufield->SetDivider(width); + BMenuField* colorMenuField = new BMenuField("color", "Color:", fColorType); fColorType->SetTargetForItems(this); - /* dither type */ - marked = false; + // dither type fDitherType = new BPopUpMenu(""); fDitherType->SetRadioMode(true); count = sizeof(gDitherTypes) / sizeof(gDitherTypes[0]); const DitherCap **dither_cap = gDitherTypes; + marked = false; + item = NULL; while (count--) { - item = new BMenuItem((*dither_cap)->label.c_str(), new BMessage(kMsgQuality)); + item = new BMenuItem((*dither_cap)->label.c_str(), + new BMessage(kMsgQuality)); fDitherType->AddItem(item); if ((*dither_cap)->dither_type == fJobData->getDitherType()) { item->SetMarked(true); @@ -521,68 +211,60 @@ JobSetupView::AttachedToWindow() } if (!marked && item) item->SetMarked(true); - dither_rect.right = dither_rect.left + StringWidth("Dot Pattern:") + fDitherType->MaxContentWidth() + 20; - menufield = new BMenuField(dither_rect, "dithering", "Dot Pattern:", fDitherType); - - box->AddChild(menufield); - width = StringWidth("Dot Pattern:") + 10; - menufield->SetDivider(width); + BMenuField* ditherMenuField = new BMenuField("dithering", "Dot Pattern:", + fDitherType); fDitherType->SetTargetForItems(this); - /* halftone preview view */ - BRect rect(halftone_rect); - BBox* halftoneBorder = new BBox(rect.InsetByCopy(-1, -1)); - box->AddChild(halftoneBorder); - halftoneBorder->SetBorder(B_PLAIN_BORDER); + // halftone preview view + BBox* halftoneBox = new BBox("halftoneBox"); + halftoneBox->SetBorder(B_PLAIN_BORDER); + + // TODO make layout compatible + BSize size(240, 14 * 4); + BRect rect(0, 0, size.width, size.height); + fHalftone = new HalftoneView(rect, "halftone", + B_FOLLOW_ALL, B_WILL_DRAW); + fHalftone->SetExplicitMinSize(size); + fHalftone->SetExplicitMaxSize(size); - fHalftone = new HalftoneView(rect.OffsetToCopy(1, 1), "halftone", B_FOLLOW_ALL, B_WILL_DRAW); - halftoneBorder->AddChild(fHalftone); - fHalftone->preview(fJobData->getGamma(), fJobData->getInkDensity(), fJobData->getDitherType(), fJobData->getColor() != JobData::kMonochrome); - - /* gamma */ - fGamma = new JSDSlider(gamma_rect, "gamma", "Gamma", new BMessage(kMsgQuality), -300, 300, B_BLOCK_THUMB); + // gamma + fGamma = new JSDSlider("gamma", "Gamma", new BMessage(kMsgQuality), + -300, 300); fGamma->SetLimitLabels("Lighter", "Darker"); fGamma->SetValue((int32)(100 * log(fJobData->getGamma()) / log(2.0))); fGamma->SetHashMarks(B_HASH_MARKS_BOTH); fGamma->SetHashMarkCount(7); - box->AddChild(fGamma); fGamma->SetModificationMessage(new BMessage(kMsgQuality)); fGamma->SetTarget(this); - /* ink density */ - fInkDensity = new JSDSlider(ink_density_rect, "inkDensity", "Ink Usage", new BMessage(kMsgQuality), 0, 127, B_BLOCK_THUMB); + // ink density + fInkDensity = new JSDSlider("inkDensity", "Ink Usage", + new BMessage(kMsgQuality), 0, 127); fInkDensity->SetLimitLabels("Min", "Max"); fInkDensity->SetValue((int32)fJobData->getInkDensity()); fInkDensity->SetHashMarks(B_HASH_MARKS_BOTH); fInkDensity->SetHashMarkCount(10); - box->AddChild(fInkDensity); fInkDensity->SetModificationMessage(new BMessage(kMsgQuality)); fInkDensity->SetTarget(this); - /* page range */ + // page range - box = new BBox(pagerange_rect); - AddChild(box); - box->SetLabel("Page Range"); + BBox* pageRangeBox = new BBox("pageRange"); + pageRangeBox->SetLabel("Page Range"); - fAll = new BRadioButton(all_button_rect, "all", "All", new BMessage(kMsgRangeAll)); - box->AddChild(fAll); + fAll = new BRadioButton("all", "Print all Pages", new BMessage(kMsgRangeAll)); - BRadioButton *from = new BRadioButton(selection_rect, "selection", "", new BMessage(kMsgRangeSelection)); - box->AddChild(from); + BRadioButton *range = new BRadioButton("selection", "Print selected Pages:", + new BMessage(kMsgRangeSelection)); - fFromPage = new BTextControl(from_rect, "from", "From", "", NULL); - box->AddChild(fFromPage); + fFromPage = new BTextControl("from", "From:", "", NULL); fFromPage->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT); - fFromPage->SetDivider(StringWidth("From") + 7); AllowOnlyDigits(fFromPage->TextView(), 6); - fToPage = new BTextControl(to_rect, "to", "To", "", NULL); - box->AddChild(fToPage); + fToPage = new BTextControl("to", "To:", "", NULL); fToPage->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT); - fToPage->SetDivider(StringWidth("To") + 7); AllowOnlyDigits(fToPage->TextView(), 6); int first_page = fJobData->getFirstPage(); @@ -591,7 +273,7 @@ JobSetupView::AttachedToWindow() if (first_page <= 1 && last_page <= 0) { fAll->SetValue(B_CONTROL_ON); } else { - from->SetValue(B_CONTROL_ON); + range->SetValue(B_CONTROL_ON); if (first_page < 1) first_page = 1; if (first_page > last_page) @@ -607,15 +289,16 @@ JobSetupView::AttachedToWindow() } fAll->SetTarget(this); - from->SetTarget(this); + range->SetTarget(this); - /* paper source */ - - marked = false; + // paper source fPaperFeed = new BPopUpMenu(""); fPaperFeed->SetRadioMode(true); count = fPrinterCap->countCap(PrinterCap::kPaperSource); - const PaperSourceCap **paper_source_cap = (const PaperSourceCap **)fPrinterCap->enumCap(PrinterCap::kPaperSource); + const PaperSourceCap **paper_source_cap = + (const PaperSourceCap **)fPrinterCap->enumCap(PrinterCap::kPaperSource); + marked = false; + item = NULL; while (count--) { item = new BMenuItem((*paper_source_cap)->label.c_str(), NULL); fPaperFeed->AddItem(item); @@ -627,18 +310,16 @@ JobSetupView::AttachedToWindow() } if (!marked) item->SetMarked(true); - menufield = new BMenuField(paperfeed_rect, "paperSource", "Paper Source:", fPaperFeed); - AddChild(menufield); - width = StringWidth("Number of Copies:") + 7; - menufield->SetDivider(width); + BMenuField* paperSourceMenufield = new BMenuField("paperSource", + "Paper Source:", fPaperFeed); - /* Page Per Sheet */ - - marked = false; + // Pages per sheet fNup = new BPopUpMenu(""); fNup->SetRadioMode(true); count = sizeof(gNups) / sizeof(gNups[0]); const NupCap **nup_cap = gNups; + marked = false; + item = NULL; while (count--) { item = new BMenuItem((*nup_cap)->label.c_str(), NULL); fNup->AddItem(item); @@ -650,15 +331,13 @@ JobSetupView::AttachedToWindow() } if (!marked) item->SetMarked(true); - menufield = new BMenuField(nup_rect, "pagePerSheet", "Pages Per Sheet:", fNup); - menufield->SetDivider(StringWidth("Number of Copies:") + 7); - AddChild(menufield); - - /* duplex */ + BMenuField* pagesPerSheet = new BMenuField("pagesPerSheet", + "Pages Per Sheet:", fNup); + // duplex if (fPrinterCap->isSupport(PrinterCap::kPrintStyle)) { - fDuplex = new BCheckBox(duplex_rect, "duplex", "Duplex", new BMessage(kMsgDuplexChanged)); - AddChild(fDuplex); + fDuplex = new BCheckBox("duplex", "Duplex", + new BMessage(kMsgDuplexChanged)); if (fJobData->getPrintStyle() != JobData::kSimplex) { fDuplex->SetValue(B_CONTROL_ON); } @@ -667,73 +346,157 @@ JobSetupView::AttachedToWindow() fDuplex = NULL; } - /* copies */ - - fCopies = new BTextControl(copies_rect, "copies", "Number of Copies:", "", NULL); - AddChild(fCopies); - fCopies->SetDivider(width); + // copies + fCopies = new BTextControl("copies", "Number of Copies:", "", NULL); AllowOnlyDigits(fCopies->TextView(), 3); - BString oss4; - oss4 << fJobData->getCopies(); - fCopies->SetText(oss4.String()); + BString copies; + copies << fJobData->getCopies(); + fCopies->SetText(copies.String()); - /* collate */ - - fCollate = new BCheckBox(collate_rect, "collate", "Collate", new BMessage(kMsgCollateChanged)); - fCollate->ResizeToPreferred(); - AddChild(fCollate); + // 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_rect, "reverse", "Reverse Order", new BMessage(kMsgReverseChanged)); - fReverse->ResizeToPreferred(); - AddChild(fReverse); + // reverse + fReverse = new BCheckBox("reverse", "Reverse Order", + new BMessage(kMsgReverseChanged)); if (fJobData->getReverse()) { fReverse->SetValue(B_CONTROL_ON); } fReverse->SetTarget(this); - /* pages view */ - - fPages = new PagesView(pages_rect, "pages", B_FOLLOW_ALL, B_WILL_DRAW); - AddChild(fPages); + // 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(page_selection_rect); - AddChild(pageSelectionBox); + // page selection + BBox* pageSelectionBox = new BBox("pageSelection"); pageSelectionBox->SetLabel("Page Selection"); - fAllPages = AddPageSelectionItem(pageSelectionBox, page_selection_all_pages_rect, "allPages", "All Pages", JobData::kAllPages); - fOddNumberedPages = AddPageSelectionItem(pageSelectionBox, page_selection_odd_pages_rect, "oddPages", "Odd-Numbered Pages", JobData::kOddNumberedPages); - fEvenNumberedPages = AddPageSelectionItem(pageSelectionBox, page_selection_even_pages_rect, "evenPages", "Even-Numbered Pages", JobData::kEvenNumberedPages); + fAllPages = CreatePageSelectionItem("allPages", "All Pages", + JobData::kAllPages); + fOddNumberedPages = CreatePageSelectionItem("oddPages", + "Odd-Numbered Pages", JobData::kOddNumberedPages); + fEvenNumberedPages = CreatePageSelectionItem("evenPages", + "Even-Numbered Pages", JobData::kEvenNumberedPages); + // separator line + BBox *separator = new BBox("separator"); + separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); - - /* preview */ + // buttons + BButton* preview = new BButton("preview", "Preview" B_UTF8_ELLIPSIS, + new BMessage(kMsgPreview)); + BButton* cancel = new BButton("cancel", "Cancel", + new BMessage(kMsgCancel)); + BButton* ok = new BButton("ok", "OK", new BMessage(kMsgOK)); + ok->MakeDefault(true); - button = new BButton(preview_rect, "preview", "Preview" B_UTF8_ELLIPSIS, new BMessage(kMsgPreview)); - AddChild(button); + BGroupView* halftoneGroup = new BGroupView(B_VERTICAL, 0); + BGroupLayout* halftoneLayout = halftoneGroup->GroupLayout(); + halftoneLayout->AddView(fHalftone); + halftoneBox->AddChild(halftoneGroup); - - /* cancel */ + BGridView* qualityGrid = new BGridView(); + BGridLayout* qualityGridLayout = qualityGrid->GridLayout(); + qualityGridLayout->AddItem(colorMenuField->CreateLabelLayoutItem(), 0, 0); + qualityGridLayout->AddItem(colorMenuField->CreateMenuBarLayoutItem(), 1, 0); + qualityGridLayout->AddItem(ditherMenuField->CreateLabelLayoutItem(), 0, 1); + qualityGridLayout->AddItem(ditherMenuField->CreateMenuBarLayoutItem(), 1, + 1); + qualityGridLayout->AddView(fGamma, 0, 2, 2); + qualityGridLayout->AddView(fInkDensity, 0, 3, 2); + qualityGridLayout->AddView(halftoneBox, 0, 4, 2); + qualityGridLayout->SetSpacing(0, 0); + qualityGridLayout->SetInsets(5, 5, 5, 5); + qualityBox->AddChild(qualityGrid); - button = new BButton(cancel_rect, "cancel", "Cancel", new BMessage(kMsgCancel)); - AddChild(button); + 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); - /* ok */ + 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() + .AddGlue() + .Add(separator) + .AddGroup(B_HORIZONTAL, 10, 1.0f) + .AddGlue() + .Add(cancel) + .Add(preview) + .Add(ok) + .End() + .SetInsets(0, 0, 0, 0) + ); + + fHalftone->preview(fJobData->getGamma(), fJobData->getInkDensity(), + fJobData->getDitherType(), fJobData->getColor() != JobData::kMonochrome); - // TODO OK or "Print"? - button = new BButton(ok_rect, "ok", "OK", new BMessage(kMsgOK)); - AddChild(button); - button->MakeDefault(true); - UpdateButtonEnabledState(); } @@ -900,16 +663,22 @@ JobSetupView::UpdateJobData(bool showPreview) //==================================================================== -JobSetupDlg::JobSetupDlg(JobData *job_data, PrinterData *printer_data, const PrinterCap *printer_cap) - : DialogWindow(BRect(100, 100, 100 + PRINT_WIDTH, 100 + PRINT_HEIGHT), +JobSetupDlg::JobSetupDlg(JobData *job_data, PrinterData *printer_data, + const PrinterCap *printer_cap) + : DialogWindow(BRect(100, 100, 200, 200), "PrintJob Setup", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, - B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS) + B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE + | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS) { SetResult(B_ERROR); - AddShortcut('W',B_COMMAND_KEY,new BMessage(B_QUIT_REQUESTED)); + AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); - fJobSetup = new JobSetupView(Bounds(), job_data, printer_data, printer_cap); - AddChild(fJobSetup); + fJobSetup = new JobSetupView(job_data, printer_data, printer_cap); + SetLayout(new BGroupLayout(B_VERTICAL)); + AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) + .Add(fJobSetup) + .SetInsets(10, 10, 10, 10) + ); } void diff --git a/src/libs/print/libprint/MarginView.cpp b/src/libs/print/libprint/MarginView.cpp index 38ea5179e2..3da3b4293d 100644 --- a/src/libs/print/libprint/MarginView.cpp +++ b/src/libs/print/libprint/MarginView.cpp @@ -37,6 +37,10 @@ THE SOFTWARE. #include +#include +#include +#include +#include #include #include @@ -72,28 +76,89 @@ const rgb_color kWhite = { 255,255,255,0 }; const rgb_color kGray = { 220,220,220,0 }; +PageView::PageView() +: BView("pageView", B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE) +, fPageWidth(0) +, fPageHeight(0) +, fMargins(0, 0, 0, 0) +{ + +} + + +void +PageView::SetPageSize(float pageWidth, float pageHeight) +{ + fPageWidth = pageWidth; + fPageHeight = pageHeight; +} + + +void +PageView::SetMargins(BRect margins) +{ + fMargins = margins; +} + + +void +PageView::Draw(BRect bounds) +{ + BRect frame(Frame()); + float totalWidth = frame.Width(); + float totalHeight = frame.Height(); + + // fit page into available space + // keeping the ratio fPageWidth : fPageHeight + float pageWidth = totalWidth; + float pageHeight = totalWidth * fPageHeight / fPageWidth; + if (pageHeight > totalHeight) { + pageHeight = totalHeight; + pageWidth = totalHeight * fPageWidth / fPageHeight; + } + + // center page + BPoint offset(0, 0); + offset.x = static_cast((totalWidth - pageWidth) / 2); + offset.y = static_cast((totalHeight - pageHeight) / 2); + + // draw the page + SetHighColor(kWhite); + BRect r = BRect(0, 0, pageWidth, pageHeight); + r.OffsetBy(offset); + FillRect(r); + SetHighColor(kBlack); + StrokeRect(r); + + // draw margin + SetHighColor(kRed); + SetLowColor(kWhite); + r.top += (fMargins.top / fPageHeight) * pageHeight; + r.right -= (fMargins.right / fPageWidth) * pageWidth; + r.bottom -= (fMargins.bottom / fPageHeight) * pageHeight; + r.left += (fMargins.left / fPageWidth) * pageWidth; + StrokeRect(r, kDots); +} + + /** * Constructor * - * @param frame, BRect that is the size of the view passed to the superclase * @param pageWidth, float that is the points value of the page width * @param pageHeight, float that is the points value of the page height * @param margins, BRect values of margins * @param units, unit32 enum for units used in view * @return void */ -MarginView::MarginView(BRect frame, int32 pageWidth, int32 pageHeight, +MarginView::MarginView(int32 pageWidth, int32 pageHeight, BRect margins, MarginUnit units) - : BBox(frame, NULL, B_FOLLOW_ALL) + : BBox("marginView") { fMarginUnit = units; fUnitValue = kUnitFormat[units]; SetLabel("Margins"); - fMaxPageHeight = frame.Height() - kMinUnitHeight - kOffsetY; - fMaxPageWidth = frame.Width() - kMinFieldWidth - kOffsetX; - fMargins = margins; fPageWidth = pageWidth; @@ -128,73 +193,6 @@ MarginView::AttachedToWindow() } -/** - * Draw - * - * @param BRect, the draw bounds - * @return void - */ -void -MarginView::Draw(BRect rect) -{ - BBox::Draw(rect); - - float y_offset = (float)kOffsetY; - float x_offset = (float)kOffsetX; - BRect r; - - // Calculate offsets depending on orientation - if (fPageWidth < fPageHeight) { // Portrait - x_offset = (fMaxPageWidth/2 + kOffsetX) - fViewWidth/2; - } else { // landscape - y_offset = (fMaxPageHeight/2 + kOffsetY) - fViewHeight/2; - } - - // draw the page - SetHighColor(kWhite); - r = BRect(0, 0, fViewWidth, fViewHeight); - r.OffsetBy(x_offset, y_offset); - FillRect(r); - SetHighColor(kBlack); - StrokeRect(r); - - // draw margin - SetHighColor(kRed); - SetLowColor(kWhite); - r.top += fMargins.top; - r.right -= fMargins.right; - r.bottom -= fMargins.bottom; - r.left += fMargins.left; - StrokeRect(r, kDots); - - // draw the page size label - SetHighColor(kBlack); - SetLowColor(kGray); - char str[kStringSize]; - sprintf(str, "%2.1f x %2.1f", fPageWidth/fUnitValue, fPageHeight/fUnitValue); - SetFontSize(10); - DrawString((const char *)str, BPoint(x_offset, fMaxPageHeight + 40)); -} - - -/** - * BeOS Hook Function, change the size of the margin display - * - * @param width of the page - * @param height the page - * @return void - */ -void -MarginView::FrameResized(float width, float height) -{ - fMaxPageHeight = height - kMinUnitHeight - kOffsetX; - fMaxPageWidth = width - kMinFieldWidth - kOffsetY; - - _CalculateViewSize(MARGIN_CHANGED); - Invalidate(); -} - - /** * MesssageReceived() * @@ -297,32 +295,32 @@ MarginView::Margin() const BRect margin; // convert the field text to values - float ftop = atof(fTop->Text()); - float fright = atof(fRight->Text()); - float fleft = atof(fLeft->Text()); - float fbottom = atof(fBottom->Text()); + float top = atof(fTop->Text()); + float right = atof(fRight->Text()); + float left = atof(fLeft->Text()); + float bottom = atof(fBottom->Text()); // convert to units to points switch (fMarginUnit) { case kUnitInch: // convert to points - ftop *= kInchUnits; - fright *= kInchUnits; - fleft *= kInchUnits; - fbottom *= kInchUnits; + top *= kInchUnits; + right *= kInchUnits; + left *= kInchUnits; + bottom *= kInchUnits; break; case kUnitCM: // convert to points - ftop *= kCMUnits; - fright *= kCMUnits; - fleft *= kCMUnits; - fbottom *= kCMUnits; + top *= kCMUnits; + right *= kCMUnits; + left *= kCMUnits; + bottom *= kCMUnits; break; case kUnitPoint: break; } - margin.Set(fleft, ftop, fright, fbottom); + margin.Set(left, top, right, bottom); return margin; } @@ -353,7 +351,19 @@ void MarginView::UpdateView(uint32 msg) { Window()->Lock(); - _CalculateViewSize(msg); // only Preview in Margins BBox! + + { + char pageSize[kStringSize]; + sprintf(pageSize, "%2.1f x %2.1f", + fPageWidth / fUnitValue, + fPageHeight / fUnitValue); + fPageSize->SetText(pageSize); + + fPage->SetPageSize(fPageWidth, fPageHeight); + fPage->SetMargins(Margin()); + fPage->Invalidate(); + } + Invalidate(); Window()->Unlock(); } @@ -373,85 +383,53 @@ MarginView::UpdateView(uint32 msg) void MarginView::_ConstructGUI() { + fPage = new PageView(); + fPage->SetViewColor(ViewColor()); + + fPageSize = new BStringView("pageSize", "?x?"); + BString str; // Create text fields - BRect r(Frame().Width() - be_plain_font->StringWidth("Top#") - kWidth, - kOffsetY, Frame().Width() - kOffsetX, kWidth); // top str << fMargins.top/fUnitValue; - fTop = new BTextControl( r, "top", "Top:", str.String(), NULL, - B_FOLLOW_RIGHT); + fTop = new BTextControl("top", "Top:", str.String(), NULL); fTop->SetModificationMessage(new BMessage(TOP_MARGIN_CHANGED)); - fTop->SetDivider(be_plain_font->StringWidth("Top#")); fTop->SetTarget(this); _AllowOnlyNumbers(fTop, kNumCount); - AddChild(fTop); - - - //left - r.OffsetBy(0, kOffsetY); - r.left = Frame().Width() - be_plain_font->StringWidth("Left#") - kWidth; str = ""; str << fMargins.left/fUnitValue; - fLeft = new BTextControl( r, "left", "Left:", str.String(), NULL, - B_FOLLOW_RIGHT); + fLeft = new BTextControl("left", "Left:", str.String(), NULL); fLeft->SetModificationMessage(new BMessage(LEFT_MARGIN_CHANGED)); - fLeft->SetDivider(be_plain_font->StringWidth("Left#")); fLeft->SetTarget(this); _AllowOnlyNumbers(fLeft, kNumCount); - AddChild(fLeft); - - - //bottom - r.OffsetBy(0, kOffsetY); - r.left = Frame().Width() - be_plain_font->StringWidth("Bottom#") - kWidth; str = ""; str << fMargins.bottom/fUnitValue; - fBottom = new BTextControl( r, "bottom", "Bottom:", str.String(), NULL, - B_FOLLOW_RIGHT); + fBottom = new BTextControl("bottom", "Bottom:", str.String(), NULL); fBottom->SetModificationMessage(new BMessage(BOTTOM_MARGIN_CHANGED)); - fBottom->SetDivider(be_plain_font->StringWidth("Bottom#")); fBottom->SetTarget(this); - _AllowOnlyNumbers(fBottom, kNumCount); - AddChild(fBottom); - - - //right - r.OffsetBy(0, kOffsetY); - r.left = Frame().Width() - be_plain_font->StringWidth("Right#") - kWidth; str = ""; str << fMargins.right/fUnitValue; - fRight = new BTextControl( r, "right", "Right:", str.String(), NULL, - B_FOLLOW_RIGHT); + fRight = new BTextControl("right", "Right:", str.String(), NULL); fRight->SetModificationMessage(new BMessage(RIGHT_MARGIN_CHANGED)); - fRight->SetDivider(be_plain_font->StringWidth("Right#")); fRight->SetTarget(this); _AllowOnlyNumbers(fRight, kNumCount); - AddChild(fRight); - - -// Create Units popup - r.OffsetBy(-kOffsetX, kOffsetY); - r.right += kOffsetY; + // Create Units popup BPopUpMenu *menu = new BPopUpMenu("units"); - BMenuField *mf = new BMenuField(r, "units", "Units", menu, - B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT); - mf->ResizeToPreferred(); - mf->SetDivider(be_plain_font->StringWidth("Units#")); + BMenuField *units = new BMenuField("units", "Units:", menu); BMenuItem *item; // Construct menu items @@ -463,10 +441,35 @@ MarginView::_ConstructGUI() if (fMarginUnit == kUnitMsg[i]) item->SetMarked(true); } - AddChild(mf); - // calculate the sizes for drawing page view - _CalculateViewSize(MARGIN_CHANGED); + 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); } @@ -489,6 +492,7 @@ MarginView::_AllowOnlyNumbers(BTextControl *textControl, int32 maxNum) tv->AllowChar(i); tv->AllowChar(B_BACKSPACE); + // TODO internationalization; e.g. "." or "," tv->AllowChar('.'); tv->SetMaxBytes(maxNum); } @@ -524,56 +528,56 @@ MarginView::_SetMarginUnit(MarginUnit unit) fUnitValue = kUnitFormat[unit]; // convert the field text to values - float ftop = atof(fTop->Text()); - float fright = atof(fRight->Text()); - float fleft = atof(fLeft->Text()); - float fbottom = atof(fBottom->Text()); + float top = atof(fTop->Text()); + float right = atof(fRight->Text()); + float left = atof(fLeft->Text()); + float bottom = atof(fBottom->Text()); // convert to target units switch (fMarginUnit) { case kUnitInch: // convert to points - ftop *= kInchUnits; - fright *= kInchUnits; - fleft *= kInchUnits; - fbottom *= kInchUnits; + top *= kInchUnits; + right *= kInchUnits; + left *= kInchUnits; + bottom *= kInchUnits; // check for target unit is cm if (unit == kUnitCM) { - ftop /= kCMUnits; - fright /= kCMUnits; - fleft /= kCMUnits; - fbottom /= kCMUnits; + top /= kCMUnits; + right /= kCMUnits; + left /= kCMUnits; + bottom /= kCMUnits; } break; case kUnitCM: // convert to points - ftop *= kCMUnits; - fright *= kCMUnits; - fleft *= kCMUnits; - fbottom *= kCMUnits; + top *= kCMUnits; + right *= kCMUnits; + left *= kCMUnits; + bottom *= kCMUnits; // check for target unit is inches if (unit == kUnitInch) { - ftop /= kInchUnits; - fright /= kInchUnits; - fleft /= kInchUnits; - fbottom /= kInchUnits; + top /= kInchUnits; + right /= kInchUnits; + left /= kInchUnits; + bottom /= kInchUnits; } break; case kUnitPoint: // check for target unit is cm if (unit == kUnitCM) { - ftop /= kCMUnits; - fright /= kCMUnits; - fleft /= kCMUnits; - fbottom /= kCMUnits; + top /= kCMUnits; + right /= kCMUnits; + left /= kCMUnits; + bottom /= kCMUnits; } // check for target unit is inches if (unit == kUnitInch) { - ftop /= kInchUnits; - fright /= kInchUnits; - fleft /= kInchUnits; - fbottom /= kInchUnits; + top /= kInchUnits; + right /= kInchUnits; + left /= kInchUnits; + bottom /= kInchUnits; } break; } @@ -584,137 +588,24 @@ MarginView::_SetMarginUnit(MarginUnit unit) // set the fields to new units BString str; - str << ftop; + str << top; fTop->SetText(str.String()); str = ""; - str << fleft; + str << left; fLeft->SetText(str.String()); str = ""; - str << fright; + str << right; fRight->SetText(str.String()); str = ""; - str << fbottom; + str << bottom; fBottom->SetText(str.String()); // update UI - _CalculateViewSize(MARGIN_CHANGED); Invalidate(); Window()->Unlock(); } - -/** - * CalculateViewSize - * - * calculate the size of the view that is used - * to show the page inside the margin box. This is dependent - * on the size of the box and the room we have to show it and - * the units that we are using and the orientation of the page. - * - * @param msg, the message for which field changed to check value bounds - * @return void - */ -void -MarginView::_CalculateViewSize(uint32 msg) -{ - // determine page orientation - if (fPageHeight < fPageWidth) { // LANDSCAPE - fViewWidth = fMaxPageWidth; - fViewHeight = fPageHeight * (fViewWidth/fPageWidth); - float hdiff = fViewHeight - fMaxPageHeight; - if (hdiff > 0) { - fViewHeight -= hdiff; - fViewWidth -= hdiff; - } - } else { // PORTRAIT - fViewHeight = fMaxPageHeight; - fViewWidth = fPageWidth * (fViewHeight/fPageHeight); - float wdiff = fViewWidth - fMaxPageWidth; - if (wdiff > 0) { - fViewHeight -= wdiff; - fViewWidth -= wdiff; - } - } - - // calculate margins based on view size - - // find the length of 1 pixel in points - // ex: 80px/800pt = 0.1px/pt - float pixelLength = fViewHeight/fPageHeight; - - // convert the margins to points - // The text field will have a number that us in the current unit - // ex 0.2" * 72pt = 14.4pts - float ftop = atof(fTop->Text()) * fUnitValue; - float fright = atof(fRight->Text()) * fUnitValue; - float fbottom = atof(fBottom->Text()) * fUnitValue; - float fleft = atof(fLeft->Text()) * fUnitValue; - - // Check that the margins don't overlap each other... - float delta = 72.0; - // minimum printable rect = 1 inch * 1 inch - float ph = fPageHeight-delta; - float pw = fPageWidth-delta; - BString str; - - // Bounds calculation rules: - if (msg == TOP_MARGIN_CHANGED) { - // top must be <= bottom - if (ftop > (ph - fbottom)) { - ftop = ph - fbottom; - str = ""; - str << ftop / fUnitValue; - Window()->Lock(); - fTop->SetText(str.String()); - Window()->Unlock(); - } - - } - - if (msg == BOTTOM_MARGIN_CHANGED) { - // bottom must be <= pageHeight - if (fbottom > (ph - ftop)) { - fbottom = ph - ftop; - str = ""; - str << fbottom / fUnitValue; - Window()->Lock(); - fBottom->SetText(str.String()); - Window()->Unlock(); - } - } - - if (msg == LEFT_MARGIN_CHANGED) { - // left must be <= right - if (fleft > (pw - fright)) { - fleft = pw - fright; - str = ""; - str << fleft / fUnitValue; - Window()->Lock(); - fLeft->SetText(str.String()); - Window()->Unlock(); - } - } - - if (msg == RIGHT_MARGIN_CHANGED) { - // right must be <= fPageWidth - if (fright > (pw - fleft)) { - fright = pw - fleft; - str = ""; - str << fright / fUnitValue; - Window()->Lock(); - fRight->SetText(str.String()); - Window()->Unlock(); - } - } - - // convert the unit value to pixels - // ex: 14.4pt * 0.1px/pt = 1.44px - fMargins.top = ftop * pixelLength; - fMargins.right = fright * pixelLength; - fMargins.bottom = fbottom * pixelLength; - fMargins.left = fleft * pixelLength; -} diff --git a/src/libs/print/libprint/PageSetupDlg.cpp b/src/libs/print/libprint/PageSetupDlg.cpp index f05691b774..c3d87493bf 100644 --- a/src/libs/print/libprint/PageSetupDlg.cpp +++ b/src/libs/print/libprint/PageSetupDlg.cpp @@ -15,6 +15,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -46,97 +49,6 @@ using namespace std; #define std #endif -#define MENU_HEIGHT 16 -#define MENU_WIDTH 200 -#define BUTTON_WIDTH 70 -#define BUTTON_HEIGHT 20 -#define TEXT_HEIGHT 16 - -#define MARGIN_H 10 -#define MARGIN_V 10 -#define MARGIN_WIDTH 180 -#define MARGIN_HEIGHT 140 - -#define PAGESETUP_WIDTH MARGIN_H + MARGIN_WIDTH + 15 + MENU_WIDTH + 10 -#define PAGESETUP_HEIGHT MARGIN_V + MARGIN_HEIGHT + BUTTON_HEIGHT + 20 - -#define PAPER_H MARGIN_H + MARGIN_WIDTH + 15 -#define PAPER_V 10 -#define PAPER_WIDTH MENU_WIDTH -#define PAPER_HEIGHT MENU_HEIGHT -#define PAPER_TEXT "Paper Size:" - -#define ORIENT_H PAPER_H -#define ORIENT_V PAPER_V + 24 -#define ORIENT_WIDTH MENU_WIDTH -#define ORIENT_HEIGHT MENU_HEIGHT -#define ORIENTATION_TEXT "Orientation:" -#define PORTRAIT_TEXT "Portrait" -#define LANDSCAPE_TEXT "Landscape" - -#define RES_H PAPER_H -#define RES_V ORIENT_V + 24 -#define RES_WIDTH MENU_WIDTH -#define RES_HEIGHT MENU_HEIGHT -#define RES_TEXT "Resolution:" - -#define SCALE_H PAPER_H -#define SCALE_V RES_V + 24 -#define SCALE_WIDTH 100 -#define SCALE_HEIGHT TEXT_HEIGHT -#define SCALE_TEXT "Scale [%]:" - -#define OK_H (PAGESETUP_WIDTH - BUTTON_WIDTH - 11) -#define OK_V (PAGESETUP_HEIGHT - BUTTON_HEIGHT - 11) -#define OK_TEXT "OK" - -#define CANCEL_H (OK_H - BUTTON_WIDTH - 12) -#define CANCEL_V OK_V -#define CANCEL_TEXT "Cancel" - -#define PRINT_LINE_V (PAGESETUP_HEIGHT - BUTTON_HEIGHT - 23) - -const BRect MARGIN_RECT( - MARGIN_H, - MARGIN_V, - MARGIN_H + MARGIN_WIDTH, - MARGIN_V + MARGIN_HEIGHT); - -const BRect ORIENTATION_RECT( - ORIENT_H, - ORIENT_V, - ORIENT_H + ORIENT_WIDTH, - ORIENT_V + ORIENT_HEIGHT); - -const BRect PAPER_RECT( - PAPER_H, - PAPER_V, - PAPER_H + PAPER_WIDTH, - PAPER_V + PAPER_HEIGHT); - -const BRect RESOLUTION_RECT( - RES_H, - RES_V, - RES_H + RES_WIDTH, - RES_V + RES_HEIGHT); - -const BRect SCALE_RECT( - SCALE_H, - SCALE_V, - SCALE_H + SCALE_WIDTH, - SCALE_V + SCALE_HEIGHT); - -const BRect OK_RECT( - OK_H, - OK_V, - OK_H + BUTTON_WIDTH, - OK_V + BUTTON_HEIGHT); - -const BRect CANCEL_RECT( - CANCEL_H, - CANCEL_V, - CANCEL_H + BUTTON_WIDTH, - CANCEL_V + BUTTON_HEIGHT); enum MSGS { kMsgCancel = 1, @@ -145,8 +57,12 @@ enum MSGS { kMsgPaperChanged, }; -PageSetupView::PageSetupView(BRect frame, JobData *job_data, PrinterData *printer_data, const PrinterCap *printer_cap) - : BView(frame, "", B_FOLLOW_ALL, B_WILL_DRAW), fJobData(job_data), fPrinterData(printer_data), fPrinterCap(printer_cap) +PageSetupView::PageSetupView(JobData *job_data, PrinterData *printer_data, + const PrinterCap *printer_cap) + : BView("pageSetupView", B_WILL_DRAW) + , fJobData(job_data) + , fPrinterData(printer_data) + , fPrinterCap(printer_cap) { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); } @@ -175,12 +91,10 @@ void PageSetupView::AttachedToWindow() { BMenuItem *item = NULL; - BMenuField *menuField; - BButton *button; bool marked; int count; - /* margin */ + // margin MarginUnit units = fJobData->getMarginUnit(); BRect paper = fJobData->getPaperRect(); BRect margin = fJobData->getPrintableRect(); @@ -191,16 +105,14 @@ PageSetupView::AttachedToWindow() margin.right = paper.right - margin.right; margin.bottom = paper.bottom - margin.bottom; - fMarginView = new MarginView(MARGIN_RECT, + fMarginView = new MarginView( paper.IntegerWidth(), paper.IntegerHeight(), margin, units); - AddChild(fMarginView); - - /* paper selection */ + // paper selection marked = false; - fPaper = new BPopUpMenu(""); + fPaper = new BPopUpMenu("paperSize"); fPaper->SetRadioMode(true); count = fPrinterCap->countCap(PrinterCap::kPaper); PaperCap **paper_cap = (PaperCap **)fPrinterCap->enumCap(PrinterCap::kPaper); @@ -218,22 +130,18 @@ PageSetupView::AttachedToWindow() } if (!marked) item->SetMarked(true); - menuField = new BMenuField(PAPER_RECT, "", PAPER_TEXT, fPaper); - AddChild(menuField); - float width = StringWidth(PAPER_TEXT) + 7; - menuField->SetDivider(width); + BMenuField* paperSize = new BMenuField("paperSize", "Paper Size:", fPaper); - /* orientaion */ + // orientation fOrientation = new BPopUpMenu("orientation"); fOrientation->SetRadioMode(true); - menuField = new BMenuField(ORIENTATION_RECT, "orientation", ORIENTATION_TEXT, fOrientation); - menuField->SetDivider(width); + BMenuField* orientation = new BMenuField("orientation", "Orientation:", fOrientation); count = fPrinterCap->countCap(PrinterCap::kOrientation); if (count == 0) { - AddOrientationItem(PORTRAIT_TEXT, JobData::kPortrait); - AddOrientationItem(LANDSCAPE_TEXT, JobData::kLandscape); + AddOrientationItem("Portrait", JobData::kPortrait); + AddOrientationItem("Landscape", JobData::kLandscape); } else { OrientationCap **orientation_cap = (OrientationCap **)fPrinterCap->enumCap(PrinterCap::kOrientation); while (count--) { @@ -243,12 +151,9 @@ PageSetupView::AttachedToWindow() } } - AddChild(menuField); - - /* resolution */ - + // resolution marked = false; - fResolution = new BPopUpMenu(""); + fResolution = new BPopUpMenu("resolution"); fResolution->SetRadioMode(true); count = fPrinterCap->countCap(PrinterCap::kResolution); ResolutionCap **resolution_cap = (ResolutionCap **)fPrinterCap->enumCap(PrinterCap::kResolution); @@ -264,16 +169,14 @@ PageSetupView::AttachedToWindow() } if (!marked) item->SetMarked(true); - menuField = new BMenuField(RESOLUTION_RECT, "", RES_TEXT, fResolution); - AddChild(menuField); - menuField->SetDivider(width); + BMenuField* resolution = new BMenuField("resolution", "Resolution:", fResolution); - /* scale */ + // scale BString scale; scale << (int)fJobData->getScaling(); - fScaling = new BTextControl(SCALE_RECT, "scale", "Scale [%]:", + fScaling = new BTextControl("scale", "Scale [%]:", scale.String(), - NULL, B_FOLLOW_RIGHT); + NULL); int num; for (num = 0; num <= 255; num++) { fScaling->TextView()->DisallowChar(num); @@ -282,20 +185,44 @@ PageSetupView::AttachedToWindow() fScaling->TextView()->AllowChar('0' + num); } fScaling->TextView()->SetMaxBytes(3); - fScaling->SetDivider(width); - AddChild(fScaling); + // cancel and ok + BButton* cancel = new BButton("cancel", "Cancel", new BMessage(kMsgCancel)); + BButton* ok = new BButton("ok", "OK", new BMessage(kMsgOK)); - /* cancel */ + ok->MakeDefault(true); - button = new BButton(CANCEL_RECT, "", CANCEL_TEXT, new BMessage(kMsgCancel)); - AddChild(button); + 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); - /* ok */ - - button = new BButton(OK_RECT, "", OK_TEXT, new BMessage(kMsgOK)); - AddChild(button); - button->MakeDefault(true); + 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) + ); } inline void @@ -424,15 +351,22 @@ PageSetupView::MessageReceived(BMessage *msg) //==================================================================== +// TODO center window on screen PageSetupDlg::PageSetupDlg(JobData *job_data, PrinterData *printer_data, const PrinterCap *printer_cap) - : DialogWindow(BRect(100, 100, 100 + PAGESETUP_WIDTH, 100 + PAGESETUP_HEIGHT), + : DialogWindow(BRect(100, 100, 160, 160), "Page Setup", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, - B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE) + B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE + | B_AUTO_UPDATE_SIZE_LIMITS) { AddShortcut('W',B_COMMAND_KEY,new BMessage(B_QUIT_REQUESTED)); - PageSetupView *view = new PageSetupView(Bounds(), job_data, printer_data, printer_cap); - AddChild(view); + fPageSetupView = new PageSetupView(job_data, printer_data, + printer_cap); + + SetLayout(new BGroupLayout(B_HORIZONTAL)); + AddChild(BGroupLayoutBuilder(B_HORIZONTAL, 0) + .Add(fPageSetupView) + ); SetResult(B_ERROR); } @@ -443,7 +377,7 @@ PageSetupDlg::MessageReceived(BMessage *msg) switch (msg->what) { case kMsgOK: Lock(); - ((PageSetupView *)ChildAt(0))->UpdateJobData(); + fPageSetupView->UpdateJobData(); Unlock(); SetResult(B_NO_ERROR); PostMessage(B_QUIT_REQUESTED); diff --git a/src/libs/print/libprint/StatusWindow.cpp b/src/libs/print/libprint/StatusWindow.cpp index 5a1f5375a3..6104608f32 100644 --- a/src/libs/print/libprint/StatusWindow.cpp +++ b/src/libs/print/libprint/StatusWindow.cpp @@ -22,8 +22,8 @@ StatusWindow::StatusWindow(bool oddPages, bool evenPages, uint32 firstPage, uint32 numPages, uint32 numCopies, uint32 nup) : BWindow (BRect(200, 200, 650, 270), "Print Status", B_DOCUMENT_WINDOW, B_NOT_RESIZABLE | B_NOT_CLOSABLE | B_NOT_ZOOMABLE) { - // oddPages - if true, only print odd umbered pages - // evenPages - if true, only print even umbered pages + // oddPages - if true, only print odd numbered pages + // evenPages - if true, only print even numbered pages // firstPage - number of first page // numPages - total number of pages (must be recalculate if odd/even is used) // numCopies - total number of document copies diff --git a/src/servers/print/ConfigWindow.cpp b/src/servers/print/ConfigWindow.cpp index 9a1a044732..394da48ca9 100644 --- a/src/servers/print/ConfigWindow.cpp +++ b/src/servers/print/ConfigWindow.cpp @@ -117,14 +117,16 @@ LeftAlign(BView* view) { return BGroupLayoutBuilder(B_HORIZONTAL) .Add(view) - .AddGlue(); + .AddGlue() + .SetInsets(0, 0, 0, 0); } ConfigWindow::ConfigWindow(config_setup_kind kind, Printer* defaultPrinter, BMessage* settings, AutoReply* sender) : - BWindow(ConfigWindow::GetWindowFrame(), B_TRANSLATE("Page setup"), + BWindow(ConfigWindow::GetWindowFrame(), + B_TRANSLATE("Page setup"), B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS), fKind(kind), @@ -174,8 +176,7 @@ ConfigWindow::ConfigWindow(config_setup_kind kind, Printer* defaultPrinter, } // separator line - BBox* separator = new BBox(dummyRect, "line", - B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); + BBox* separator = new BBox("separator"); separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); // Cancel & OK button @@ -191,41 +192,36 @@ ConfigWindow::ConfigWindow(config_setup_kind kind, Printer* defaultPrinter, builder .Add(fPrinters) - .AddStrut(5) - .Add(BGroupLayoutBuilder(B_HORIZONTAL) + .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10) .Add(fPageSetup) - .AddStrut(5) - .Add(BGroupLayoutBuilder(B_VERTICAL) + .Add(BGroupLayoutBuilder(B_VERTICAL, 0) .Add(LeftAlign(pageFormatTitle)) .Add(LeftAlign(fPageFormatText)) + .SetInsets(0, 0, 0, 0) ) .AddGlue() ); if (fJobSetup != NULL) { builder - .AddStrut(5) - .Add(BGroupLayoutBuilder(B_HORIZONTAL) + .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10) .Add(fJobSetup) - .AddStrut(5) - .Add(BGroupLayoutBuilder(B_VERTICAL) + .Add(BGroupLayoutBuilder(B_VERTICAL, 0) .Add(LeftAlign(jobSetupTitle)) .Add(LeftAlign(fJobSetupText)) + .SetInsets(0, 0, 0, 0) ) .AddGlue() ); } builder - .AddStrut(5) + .AddGlue() .Add(separator) - .AddStrut(5) .Add(BGroupLayoutBuilder(B_HORIZONTAL) - .AddGlue() - .Add(cancel) - .AddStrut(5) - .Add(fOk) - .AddGlue() + .AddGlue() + .Add(cancel) + .Add(fOk) ) .SetInsets(5, 5, 5, 5); @@ -328,11 +324,13 @@ ConfigWindow::FrameMoved(BPoint p) BRect ConfigWindow::GetWindowFrame() { + BRect frame(0, 0, 10, 10); BAutolock lock(gLock); if (lock.IsLocked()) - return Settings::GetSettings()->ConfigWindowFrame(); + frame.OffsetBy(Settings::GetSettings()->ConfigWindowFrame().LeftTop()); - return BRect(30, 30, 300, 300); + frame.OffsetBy(30, 30); + return frame; }