112fd6cc2SKarsten Heimrich /* 212fd6cc2SKarsten Heimrich * JobSetupDlg.cpp 312fd6cc2SKarsten Heimrich * Copyright 1999-2000 Y.Takagi. All Rights Reserved. 412fd6cc2SKarsten Heimrich */ 512fd6cc2SKarsten Heimrich 612fd6cc2SKarsten Heimrich #include <cstdio> 712fd6cc2SKarsten Heimrich #include <cstring> 812fd6cc2SKarsten Heimrich #include <cstdlib> 912fd6cc2SKarsten Heimrich #include <string> 1012fd6cc2SKarsten Heimrich #include <fcntl.h> 1112fd6cc2SKarsten Heimrich #include <unistd.h> 1212fd6cc2SKarsten Heimrich #include <sys/stat.h> 1312fd6cc2SKarsten Heimrich #include <math.h> 1412fd6cc2SKarsten Heimrich 1512fd6cc2SKarsten Heimrich #include <Alert.h> 1612fd6cc2SKarsten Heimrich #include <Bitmap.h> 1712fd6cc2SKarsten Heimrich #include <Box.h> 1812fd6cc2SKarsten Heimrich #include <Button.h> 1912fd6cc2SKarsten Heimrich #include <CheckBox.h> 205a695bceSMichael Pfeiffer #include <GridView.h> 215a695bceSMichael Pfeiffer #include <GroupLayout.h> 225a695bceSMichael Pfeiffer #include <GroupLayoutBuilder.h> 2312fd6cc2SKarsten Heimrich #include <Looper.h> 2412fd6cc2SKarsten Heimrich #include <MessageFilter.h> 2512fd6cc2SKarsten Heimrich #include <MenuField.h> 2612fd6cc2SKarsten Heimrich #include <MenuItem.h> 2712fd6cc2SKarsten Heimrich #include <Message.h> 2812fd6cc2SKarsten Heimrich #include <Point.h> 2912fd6cc2SKarsten Heimrich #include <PopUpMenu.h> 3012fd6cc2SKarsten Heimrich #include <PrintJob.h> 3112fd6cc2SKarsten Heimrich #include <RadioButton.h> 3212fd6cc2SKarsten Heimrich #include <Rect.h> 3312fd6cc2SKarsten Heimrich #include <Slider.h> 3412fd6cc2SKarsten Heimrich #include <String.h> 3512fd6cc2SKarsten Heimrich #include <TextControl.h> 3612fd6cc2SKarsten Heimrich #include <TextView.h> 3712fd6cc2SKarsten Heimrich #include <View.h> 3812fd6cc2SKarsten Heimrich 3912fd6cc2SKarsten Heimrich #include "HalftoneView.h" 4012fd6cc2SKarsten Heimrich #include "JobSetupDlg.h" 4112fd6cc2SKarsten Heimrich #include "JobData.h" 4212fd6cc2SKarsten Heimrich #include "JSDSlider.h" 4312fd6cc2SKarsten Heimrich #include "PagesView.h" 4412fd6cc2SKarsten Heimrich #include "PrinterData.h" 4512fd6cc2SKarsten Heimrich #include "PrinterCap.h" 4612fd6cc2SKarsten Heimrich #include "DbgMsg.h" 4712fd6cc2SKarsten Heimrich 48a7dde370SMichael Pfeiffer 4912fd6cc2SKarsten Heimrich using namespace std; 5012fd6cc2SKarsten Heimrich 5112fd6cc2SKarsten Heimrich 5212fd6cc2SKarsten Heimrich struct NupCap : public BaseCap { 53a7dde370SMichael Pfeiffer NupCap(const string &label, bool isDefault, int nup) 54a7dde370SMichael Pfeiffer : 55a7dde370SMichael Pfeiffer BaseCap(label, isDefault), 56a7dde370SMichael Pfeiffer fNup(nup) 57a7dde370SMichael Pfeiffer {} 58a7dde370SMichael Pfeiffer 59*961e35fbSMichael Pfeiffer int32 ID() const { return fNup; } 60f53abcbdSMichael Pfeiffer 61a7dde370SMichael Pfeiffer int fNup; 6212fd6cc2SKarsten Heimrich }; 6312fd6cc2SKarsten Heimrich 64a7dde370SMichael Pfeiffer 6512fd6cc2SKarsten Heimrich struct DitherCap : public BaseCap { 66a7dde370SMichael Pfeiffer DitherCap(const string &label, bool isDefault, 67a7dde370SMichael Pfeiffer Halftone::DitherType ditherType) 68a7dde370SMichael Pfeiffer : 69a7dde370SMichael Pfeiffer BaseCap(label, isDefault), 70a7dde370SMichael Pfeiffer fDitherType(ditherType) 71a7dde370SMichael Pfeiffer {} 72a7dde370SMichael Pfeiffer 73*961e35fbSMichael Pfeiffer int32 ID() const { return fDitherType; } 74f53abcbdSMichael Pfeiffer 75a7dde370SMichael Pfeiffer Halftone::DitherType fDitherType; 7612fd6cc2SKarsten Heimrich }; 7712fd6cc2SKarsten Heimrich 7812fd6cc2SKarsten Heimrich 7912fd6cc2SKarsten Heimrich static const NupCap gNup1("1", true, 1); 8012fd6cc2SKarsten Heimrich static const NupCap gNup2("2", false, 2); 8112fd6cc2SKarsten Heimrich static const NupCap gNup4("4", false, 4); 8212fd6cc2SKarsten Heimrich static const NupCap gNup8("8", false, 8); 8312fd6cc2SKarsten Heimrich static const NupCap gNup9("9", false, 9); 8412fd6cc2SKarsten Heimrich static const NupCap gNup16("16", false, 16); 8512fd6cc2SKarsten Heimrich static const NupCap gNup25("25", false, 25); 8612fd6cc2SKarsten Heimrich static const NupCap gNup32("32", false, 32); 8712fd6cc2SKarsten Heimrich static const NupCap gNup36("36", false, 36); 8812fd6cc2SKarsten Heimrich 89a7dde370SMichael Pfeiffer 9012fd6cc2SKarsten Heimrich static const DitherCap gDitherType1("Crosshatch", false, Halftone::kType1); 9112fd6cc2SKarsten Heimrich static const DitherCap gDitherType2("Grid", false, Halftone::kType2); 9212fd6cc2SKarsten Heimrich static const DitherCap gDitherType3("Stipple", false, Halftone::kType3); 93a7dde370SMichael Pfeiffer static const DitherCap gDitherFloydSteinberg("Floyd-Steinberg", false, 94a7dde370SMichael Pfeiffer Halftone::kTypeFloydSteinberg); 9512fd6cc2SKarsten Heimrich 9612fd6cc2SKarsten Heimrich 97f53abcbdSMichael Pfeiffer const BaseCap *gNups[] = { 9812fd6cc2SKarsten Heimrich &gNup1, 9912fd6cc2SKarsten Heimrich &gNup2, 10012fd6cc2SKarsten Heimrich &gNup4, 10112fd6cc2SKarsten Heimrich &gNup8, 10212fd6cc2SKarsten Heimrich &gNup9, 10312fd6cc2SKarsten Heimrich &gNup16, 10412fd6cc2SKarsten Heimrich &gNup25, 10512fd6cc2SKarsten Heimrich &gNup32, 10612fd6cc2SKarsten Heimrich &gNup36 10712fd6cc2SKarsten Heimrich }; 10812fd6cc2SKarsten Heimrich 109a7dde370SMichael Pfeiffer 110f53abcbdSMichael Pfeiffer const BaseCap *gDitherTypes[] = { 11112fd6cc2SKarsten Heimrich &gDitherType1, 11212fd6cc2SKarsten Heimrich &gDitherType2, 11312fd6cc2SKarsten Heimrich &gDitherType3, 11412fd6cc2SKarsten Heimrich &gDitherFloydSteinberg 11512fd6cc2SKarsten Heimrich }; 11612fd6cc2SKarsten Heimrich 117a7dde370SMichael Pfeiffer 11812fd6cc2SKarsten Heimrich enum { 11912fd6cc2SKarsten Heimrich kMsgRangeAll = 'JSdl', 12012fd6cc2SKarsten Heimrich kMsgRangeSelection, 12112fd6cc2SKarsten Heimrich kMsgPreview, 12212fd6cc2SKarsten Heimrich kMsgCancel, 12312fd6cc2SKarsten Heimrich kMsgOK, 12412fd6cc2SKarsten Heimrich kMsgQuality, 12512fd6cc2SKarsten Heimrich kMsgCollateChanged, 12612fd6cc2SKarsten Heimrich kMsgReverseChanged, 12712fd6cc2SKarsten Heimrich kMsgDuplexChanged, 128f53abcbdSMichael Pfeiffer kMsgNone = 0 12912fd6cc2SKarsten Heimrich }; 13012fd6cc2SKarsten Heimrich 131a7dde370SMichael Pfeiffer 13256c20e82SMichael Pfeiffer JobSetupView::JobSetupView(JobData* jobData, PrinterData* printerData, 13356c20e82SMichael Pfeiffer const PrinterCap *printerCap) 134a7dde370SMichael Pfeiffer : 135a7dde370SMichael Pfeiffer BView("jobSetup", B_WILL_DRAW), 136308f0e19SMichael Pfeiffer fCopies(NULL), 137308f0e19SMichael Pfeiffer fFromPage(NULL), 138308f0e19SMichael Pfeiffer fToPage(NULL), 13956c20e82SMichael Pfeiffer fJobData(jobData), 14056c20e82SMichael Pfeiffer fPrinterData(printerData), 14156c20e82SMichael Pfeiffer fPrinterCap(printerCap), 142308f0e19SMichael Pfeiffer fColorType(NULL), 143308f0e19SMichael Pfeiffer fDitherType(NULL), 144308f0e19SMichael Pfeiffer fGamma(NULL), 145308f0e19SMichael Pfeiffer fInkDensity(NULL), 146308f0e19SMichael Pfeiffer fHalftone(NULL), 147308f0e19SMichael Pfeiffer fAll(NULL), 148308f0e19SMichael Pfeiffer fCollate(NULL), 149308f0e19SMichael Pfeiffer fReverse(NULL), 150308f0e19SMichael Pfeiffer fPages(NULL), 151308f0e19SMichael Pfeiffer fPaperFeed(NULL), 152308f0e19SMichael Pfeiffer fDuplex(NULL), 153308f0e19SMichael Pfeiffer fNup(NULL), 154308f0e19SMichael Pfeiffer fAllPages(NULL), 155308f0e19SMichael Pfeiffer fOddNumberedPages(NULL), 156308f0e19SMichael Pfeiffer fEvenNumberedPages(NULL) 15712fd6cc2SKarsten Heimrich { 15812fd6cc2SKarsten Heimrich SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 15912fd6cc2SKarsten Heimrich } 16012fd6cc2SKarsten Heimrich 161a7dde370SMichael Pfeiffer 16212fd6cc2SKarsten Heimrich BRadioButton* 1635a695bceSMichael Pfeiffer JobSetupView::CreatePageSelectionItem(const char* name, const char* label, 16412fd6cc2SKarsten Heimrich JobData::PageSelection pageSelection) 16512fd6cc2SKarsten Heimrich { 1665a695bceSMichael Pfeiffer BRadioButton* button = new BRadioButton(name, label, NULL); 16712fd6cc2SKarsten Heimrich if (fJobData->getPageSelection() == pageSelection) { 16812fd6cc2SKarsten Heimrich button->SetValue(B_CONTROL_ON); 16912fd6cc2SKarsten Heimrich } 17012fd6cc2SKarsten Heimrich return button; 17112fd6cc2SKarsten Heimrich } 17212fd6cc2SKarsten Heimrich 173a7dde370SMichael Pfeiffer 17412fd6cc2SKarsten Heimrich void 17512fd6cc2SKarsten Heimrich JobSetupView::AllowOnlyDigits(BTextView* textView, int maxDigits) 17612fd6cc2SKarsten Heimrich { 17712fd6cc2SKarsten Heimrich int num; 17812fd6cc2SKarsten Heimrich for (num = 0; num <= 255; num++) { 17912fd6cc2SKarsten Heimrich textView->DisallowChar(num); 18012fd6cc2SKarsten Heimrich } 18112fd6cc2SKarsten Heimrich for (num = 0; num <= 9; num++) { 18212fd6cc2SKarsten Heimrich textView->AllowChar('0' + num); 18312fd6cc2SKarsten Heimrich } 18412fd6cc2SKarsten Heimrich textView->SetMaxBytes(maxDigits); 18512fd6cc2SKarsten Heimrich } 18612fd6cc2SKarsten Heimrich 187a7dde370SMichael Pfeiffer 18812fd6cc2SKarsten Heimrich void 18912fd6cc2SKarsten Heimrich JobSetupView::AttachedToWindow() 19012fd6cc2SKarsten Heimrich { 1915a695bceSMichael Pfeiffer // quality 1925a695bceSMichael Pfeiffer BBox* qualityBox = new BBox("quality"); 1935a695bceSMichael Pfeiffer qualityBox->SetLabel("Quality"); 19412fd6cc2SKarsten Heimrich 1955a695bceSMichael Pfeiffer // color 1965a695bceSMichael Pfeiffer fColorType = new BPopUpMenu("color"); 19712fd6cc2SKarsten Heimrich fColorType->SetRadioMode(true); 198f53abcbdSMichael Pfeiffer FillCapabilityMenu(fColorType, kMsgQuality, PrinterCap::kColor, 199f53abcbdSMichael Pfeiffer fJobData->getColor()); 2005a695bceSMichael Pfeiffer BMenuField* colorMenuField = new BMenuField("color", "Color:", fColorType); 20112fd6cc2SKarsten Heimrich fColorType->SetTargetForItems(this); 20212fd6cc2SKarsten Heimrich 203308f0e19SMichael Pfeiffer if (IsHalftoneConfigurationNeeded()) 204308f0e19SMichael Pfeiffer CreateHalftoneConfigurationUI(); 20512fd6cc2SKarsten Heimrich 2065a695bceSMichael Pfeiffer // page range 20712fd6cc2SKarsten Heimrich 2085a695bceSMichael Pfeiffer BBox* pageRangeBox = new BBox("pageRange"); 2095a695bceSMichael Pfeiffer pageRangeBox->SetLabel("Page Range"); 21012fd6cc2SKarsten Heimrich 2115a695bceSMichael Pfeiffer fAll = new BRadioButton("all", "Print all Pages", new BMessage(kMsgRangeAll)); 21212fd6cc2SKarsten Heimrich 2135a695bceSMichael Pfeiffer BRadioButton *range = new BRadioButton("selection", "Print selected Pages:", 2145a695bceSMichael Pfeiffer new BMessage(kMsgRangeSelection)); 21512fd6cc2SKarsten Heimrich 2165a695bceSMichael Pfeiffer fFromPage = new BTextControl("from", "From:", "", NULL); 21712fd6cc2SKarsten Heimrich fFromPage->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT); 21812fd6cc2SKarsten Heimrich AllowOnlyDigits(fFromPage->TextView(), 6); 21912fd6cc2SKarsten Heimrich 2205a695bceSMichael Pfeiffer fToPage = new BTextControl("to", "To:", "", NULL); 22112fd6cc2SKarsten Heimrich fToPage->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT); 22212fd6cc2SKarsten Heimrich AllowOnlyDigits(fToPage->TextView(), 6); 22312fd6cc2SKarsten Heimrich 22412fd6cc2SKarsten Heimrich int first_page = fJobData->getFirstPage(); 22512fd6cc2SKarsten Heimrich int last_page = fJobData->getLastPage(); 22612fd6cc2SKarsten Heimrich 22712fd6cc2SKarsten Heimrich if (first_page <= 1 && last_page <= 0) { 22812fd6cc2SKarsten Heimrich fAll->SetValue(B_CONTROL_ON); 22912fd6cc2SKarsten Heimrich } else { 2305a695bceSMichael Pfeiffer range->SetValue(B_CONTROL_ON); 23112fd6cc2SKarsten Heimrich if (first_page < 1) 23212fd6cc2SKarsten Heimrich first_page = 1; 23312fd6cc2SKarsten Heimrich if (first_page > last_page) 23412fd6cc2SKarsten Heimrich last_page = -1; 23512fd6cc2SKarsten Heimrich 23612fd6cc2SKarsten Heimrich BString oss1; 23712fd6cc2SKarsten Heimrich oss1 << first_page; 23812fd6cc2SKarsten Heimrich fFromPage->SetText(oss1.String()); 23912fd6cc2SKarsten Heimrich 24012fd6cc2SKarsten Heimrich BString oss2; 24112fd6cc2SKarsten Heimrich oss2 << last_page; 24212fd6cc2SKarsten Heimrich fToPage->SetText(oss2.String()); 24312fd6cc2SKarsten Heimrich } 24412fd6cc2SKarsten Heimrich 24512fd6cc2SKarsten Heimrich fAll->SetTarget(this); 2465a695bceSMichael Pfeiffer range->SetTarget(this); 24712fd6cc2SKarsten Heimrich 2485a695bceSMichael Pfeiffer // paper source 24912fd6cc2SKarsten Heimrich fPaperFeed = new BPopUpMenu(""); 25012fd6cc2SKarsten Heimrich fPaperFeed->SetRadioMode(true); 251f53abcbdSMichael Pfeiffer FillCapabilityMenu(fPaperFeed, kMsgNone, PrinterCap::kPaperSource, 252f53abcbdSMichael Pfeiffer fJobData->getPaperSource()); 2535a695bceSMichael Pfeiffer BMenuField* paperSourceMenufield = new BMenuField("paperSource", 2545a695bceSMichael Pfeiffer "Paper Source:", fPaperFeed); 25512fd6cc2SKarsten Heimrich 2565a695bceSMichael Pfeiffer // Pages per sheet 25712fd6cc2SKarsten Heimrich fNup = new BPopUpMenu(""); 25812fd6cc2SKarsten Heimrich fNup->SetRadioMode(true); 259f53abcbdSMichael Pfeiffer FillCapabilityMenu(fNup, kMsgNone, gNups, sizeof(gNups) / sizeof(gNups[0]), 260f53abcbdSMichael Pfeiffer fJobData->getNup()); 2615a695bceSMichael Pfeiffer BMenuField* pagesPerSheet = new BMenuField("pagesPerSheet", 2625a695bceSMichael Pfeiffer "Pages Per Sheet:", fNup); 26312fd6cc2SKarsten Heimrich 2645a695bceSMichael Pfeiffer // duplex 26512fd6cc2SKarsten Heimrich if (fPrinterCap->isSupport(PrinterCap::kPrintStyle)) { 2665a695bceSMichael Pfeiffer fDuplex = new BCheckBox("duplex", "Duplex", 2675a695bceSMichael Pfeiffer new BMessage(kMsgDuplexChanged)); 26812fd6cc2SKarsten Heimrich if (fJobData->getPrintStyle() != JobData::kSimplex) { 26912fd6cc2SKarsten Heimrich fDuplex->SetValue(B_CONTROL_ON); 27012fd6cc2SKarsten Heimrich } 27112fd6cc2SKarsten Heimrich fDuplex->SetTarget(this); 27212fd6cc2SKarsten Heimrich } else { 27312fd6cc2SKarsten Heimrich fDuplex = NULL; 27412fd6cc2SKarsten Heimrich } 27512fd6cc2SKarsten Heimrich 2765a695bceSMichael Pfeiffer // copies 2775a695bceSMichael Pfeiffer fCopies = new BTextControl("copies", "Number of Copies:", "", NULL); 27812fd6cc2SKarsten Heimrich AllowOnlyDigits(fCopies->TextView(), 3); 27912fd6cc2SKarsten Heimrich 2805a695bceSMichael Pfeiffer BString copies; 2815a695bceSMichael Pfeiffer copies << fJobData->getCopies(); 2825a695bceSMichael Pfeiffer fCopies->SetText(copies.String()); 28312fd6cc2SKarsten Heimrich 2845a695bceSMichael Pfeiffer // collate 2855a695bceSMichael Pfeiffer fCollate = new BCheckBox("collate", "Collate", 2865a695bceSMichael Pfeiffer new BMessage(kMsgCollateChanged)); 28712fd6cc2SKarsten Heimrich if (fJobData->getCollate()) { 28812fd6cc2SKarsten Heimrich fCollate->SetValue(B_CONTROL_ON); 28912fd6cc2SKarsten Heimrich } 29012fd6cc2SKarsten Heimrich fCollate->SetTarget(this); 29112fd6cc2SKarsten Heimrich 2925a695bceSMichael Pfeiffer // reverse 2935a695bceSMichael Pfeiffer fReverse = new BCheckBox("reverse", "Reverse Order", 2945a695bceSMichael Pfeiffer new BMessage(kMsgReverseChanged)); 29512fd6cc2SKarsten Heimrich if (fJobData->getReverse()) { 29612fd6cc2SKarsten Heimrich fReverse->SetValue(B_CONTROL_ON); 29712fd6cc2SKarsten Heimrich } 29812fd6cc2SKarsten Heimrich fReverse->SetTarget(this); 29912fd6cc2SKarsten Heimrich 3005a695bceSMichael Pfeiffer // pages view 3015a695bceSMichael Pfeiffer // TODO make layout API compatible 3025a695bceSMichael Pfeiffer fPages = new PagesView(BRect(0, 0, 150, 40), "pages", B_FOLLOW_ALL, 3035a695bceSMichael Pfeiffer B_WILL_DRAW); 30412fd6cc2SKarsten Heimrich fPages->setCollate(fJobData->getCollate()); 30512fd6cc2SKarsten Heimrich fPages->setReverse(fJobData->getReverse()); 3065a695bceSMichael Pfeiffer fPages->SetExplicitMinSize(BSize(150, 40)); 3075a695bceSMichael Pfeiffer fPages->SetExplicitMaxSize(BSize(150, 40)); 30812fd6cc2SKarsten Heimrich 3095a695bceSMichael Pfeiffer // page selection 3105a695bceSMichael Pfeiffer BBox* pageSelectionBox = new BBox("pageSelection"); 31112fd6cc2SKarsten Heimrich pageSelectionBox->SetLabel("Page Selection"); 31212fd6cc2SKarsten Heimrich 3135a695bceSMichael Pfeiffer fAllPages = CreatePageSelectionItem("allPages", "All Pages", 3145a695bceSMichael Pfeiffer JobData::kAllPages); 3155a695bceSMichael Pfeiffer fOddNumberedPages = CreatePageSelectionItem("oddPages", 3165a695bceSMichael Pfeiffer "Odd-Numbered Pages", JobData::kOddNumberedPages); 3175a695bceSMichael Pfeiffer fEvenNumberedPages = CreatePageSelectionItem("evenPages", 3185a695bceSMichael Pfeiffer "Even-Numbered Pages", JobData::kEvenNumberedPages); 3195a695bceSMichael Pfeiffer 3205a695bceSMichael Pfeiffer // separator line 3215a695bceSMichael Pfeiffer BBox *separator = new BBox("separator"); 3225a695bceSMichael Pfeiffer separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); 3235a695bceSMichael Pfeiffer 3245a695bceSMichael Pfeiffer // buttons 3255a695bceSMichael Pfeiffer BButton* preview = new BButton("preview", "Preview" B_UTF8_ELLIPSIS, 3265a695bceSMichael Pfeiffer new BMessage(kMsgPreview)); 3275a695bceSMichael Pfeiffer BButton* cancel = new BButton("cancel", "Cancel", 3285a695bceSMichael Pfeiffer new BMessage(kMsgCancel)); 3295a695bceSMichael Pfeiffer BButton* ok = new BButton("ok", "OK", new BMessage(kMsgOK)); 3305a695bceSMichael Pfeiffer ok->MakeDefault(true); 3315a695bceSMichael Pfeiffer 332308f0e19SMichael Pfeiffer if (IsHalftoneConfigurationNeeded()) { 3335a695bceSMichael Pfeiffer BGroupView* halftoneGroup = new BGroupView(B_VERTICAL, 0); 3345a695bceSMichael Pfeiffer BGroupLayout* halftoneLayout = halftoneGroup->GroupLayout(); 3355a695bceSMichael Pfeiffer halftoneLayout->AddView(fHalftone); 336308f0e19SMichael Pfeiffer fHalftoneBox->AddChild(halftoneGroup); 337308f0e19SMichael Pfeiffer } 3385a695bceSMichael Pfeiffer 3395a695bceSMichael Pfeiffer BGridView* qualityGrid = new BGridView(); 3405a695bceSMichael Pfeiffer BGridLayout* qualityGridLayout = qualityGrid->GridLayout(); 3415a695bceSMichael Pfeiffer qualityGridLayout->AddItem(colorMenuField->CreateLabelLayoutItem(), 0, 0); 3425a695bceSMichael Pfeiffer qualityGridLayout->AddItem(colorMenuField->CreateMenuBarLayoutItem(), 1, 0); 343308f0e19SMichael Pfeiffer if (IsHalftoneConfigurationNeeded()) { 344308f0e19SMichael Pfeiffer qualityGridLayout->AddItem(fDitherMenuField->CreateLabelLayoutItem(), 345308f0e19SMichael Pfeiffer 0, 1); 346308f0e19SMichael Pfeiffer qualityGridLayout->AddItem(fDitherMenuField->CreateMenuBarLayoutItem(), 347308f0e19SMichael Pfeiffer 1, 1); 3485a695bceSMichael Pfeiffer qualityGridLayout->AddView(fGamma, 0, 2, 2); 3495a695bceSMichael Pfeiffer qualityGridLayout->AddView(fInkDensity, 0, 3, 2); 350308f0e19SMichael Pfeiffer qualityGridLayout->AddView(fHalftoneBox, 0, 4, 2); 351308f0e19SMichael Pfeiffer } 3525a695bceSMichael Pfeiffer qualityGridLayout->SetSpacing(0, 0); 3535a695bceSMichael Pfeiffer qualityGridLayout->SetInsets(5, 5, 5, 5); 3545a695bceSMichael Pfeiffer qualityBox->AddChild(qualityGrid); 3555a695bceSMichael Pfeiffer 3565a695bceSMichael Pfeiffer BGridView* pageRangeGrid = new BGridView(); 3575a695bceSMichael Pfeiffer BGridLayout* pageRangeLayout = pageRangeGrid->GridLayout(); 3585a695bceSMichael Pfeiffer pageRangeLayout->AddItem(fFromPage->CreateLabelLayoutItem(), 0, 0); 3595a695bceSMichael Pfeiffer pageRangeLayout->AddItem(fFromPage->CreateTextViewLayoutItem(), 1, 0); 3605a695bceSMichael Pfeiffer pageRangeLayout->AddItem(fToPage->CreateLabelLayoutItem(), 0, 1); 3615a695bceSMichael Pfeiffer pageRangeLayout->AddItem(fToPage->CreateTextViewLayoutItem(), 1, 1); 3625a695bceSMichael Pfeiffer pageRangeLayout->SetInsets(0, 0, 0, 0); 3635a695bceSMichael Pfeiffer pageRangeLayout->SetSpacing(0, 0); 3645a695bceSMichael Pfeiffer 3655a695bceSMichael Pfeiffer BGroupView* pageRangeGroup = new BGroupView(B_VERTICAL, 0); 3665a695bceSMichael Pfeiffer BGroupLayout* pageRangeGroupLayout = pageRangeGroup->GroupLayout(); 3675a695bceSMichael Pfeiffer pageRangeGroupLayout->AddView(fAll); 3685a695bceSMichael Pfeiffer pageRangeGroupLayout->AddView(range); 3695a695bceSMichael Pfeiffer pageRangeGroupLayout->AddView(pageRangeGrid); 3705a695bceSMichael Pfeiffer pageRangeGroupLayout->SetInsets(5, 5, 5, 5); 3715a695bceSMichael Pfeiffer pageRangeBox->AddChild(pageRangeGroup); 3725a695bceSMichael Pfeiffer 3735a695bceSMichael Pfeiffer BGridView* settings = new BGridView(); 3745a695bceSMichael Pfeiffer BGridLayout* settingsLayout = settings->GridLayout(); 3755a695bceSMichael Pfeiffer settingsLayout->AddItem(paperSourceMenufield->CreateLabelLayoutItem(), 0, 3765a695bceSMichael Pfeiffer 0); 3775a695bceSMichael Pfeiffer settingsLayout->AddItem(paperSourceMenufield->CreateMenuBarLayoutItem(), 1, 3785a695bceSMichael Pfeiffer 0); 3795a695bceSMichael Pfeiffer settingsLayout->AddItem(pagesPerSheet->CreateLabelLayoutItem(), 0, 1); 3805a695bceSMichael Pfeiffer settingsLayout->AddItem(pagesPerSheet->CreateMenuBarLayoutItem(), 1, 1); 3815a695bceSMichael Pfeiffer int row = 2; 3825a695bceSMichael Pfeiffer if (fDuplex != NULL) { 3835a695bceSMichael Pfeiffer settingsLayout->AddView(fDuplex, 0, row, 2); 3845a695bceSMichael Pfeiffer row ++; 3855a695bceSMichael Pfeiffer } 3865a695bceSMichael Pfeiffer settingsLayout->AddItem(fCopies->CreateLabelLayoutItem(), 0, row); 3875a695bceSMichael Pfeiffer settingsLayout->AddItem(fCopies->CreateTextViewLayoutItem(), 1, row); 3885a695bceSMichael Pfeiffer settingsLayout->SetSpacing(0, 0); 38912fd6cc2SKarsten Heimrich 39012fd6cc2SKarsten Heimrich 3915a695bceSMichael Pfeiffer BGroupView* pageSelectionGroup = new BGroupView(B_VERTICAL, 0); 3925a695bceSMichael Pfeiffer BGroupLayout* groupLayout = pageSelectionGroup->GroupLayout(); 3935a695bceSMichael Pfeiffer groupLayout->AddView(fAllPages); 3945a695bceSMichael Pfeiffer groupLayout->AddView(fOddNumberedPages); 3955a695bceSMichael Pfeiffer groupLayout->AddView(fEvenNumberedPages); 3965a695bceSMichael Pfeiffer groupLayout->SetInsets(5, 5, 5, 5); 3975a695bceSMichael Pfeiffer pageSelectionBox->AddChild(pageSelectionGroup); 39812fd6cc2SKarsten Heimrich 3995a695bceSMichael Pfeiffer SetLayout(new BGroupLayout(B_VERTICAL)); 4005a695bceSMichael Pfeiffer AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) 4015a695bceSMichael Pfeiffer .AddGroup(B_HORIZONTAL, 10, 1.0f) 4025a695bceSMichael Pfeiffer .AddGroup(B_VERTICAL, 10, 1.0f) 4035a695bceSMichael Pfeiffer .Add(qualityBox) 4045a695bceSMichael Pfeiffer .Add(pageRangeBox) 4055a695bceSMichael Pfeiffer .AddGlue() 4065a695bceSMichael Pfeiffer .End() 4075a695bceSMichael Pfeiffer .AddGroup(B_VERTICAL, 0, 1.0f) 4085a695bceSMichael Pfeiffer .Add(settings) 4095a695bceSMichael Pfeiffer .AddStrut(5) 4105a695bceSMichael Pfeiffer .Add(fCollate) 4115a695bceSMichael Pfeiffer .Add(fReverse) 4125a695bceSMichael Pfeiffer .Add(fPages) 4135a695bceSMichael Pfeiffer .AddStrut(5) 4145a695bceSMichael Pfeiffer .Add(pageSelectionBox) 4155a695bceSMichael Pfeiffer .AddGlue() 4165a695bceSMichael Pfeiffer .End() 4175a695bceSMichael Pfeiffer .End() 4185a695bceSMichael Pfeiffer .AddGlue() 4195a695bceSMichael Pfeiffer .Add(separator) 4205a695bceSMichael Pfeiffer .AddGroup(B_HORIZONTAL, 10, 1.0f) 4215a695bceSMichael Pfeiffer .AddGlue() 4225a695bceSMichael Pfeiffer .Add(cancel) 4235a695bceSMichael Pfeiffer .Add(preview) 4245a695bceSMichael Pfeiffer .Add(ok) 4255a695bceSMichael Pfeiffer .End() 4265a695bceSMichael Pfeiffer .SetInsets(0, 0, 0, 0) 4275a695bceSMichael Pfeiffer ); 42812fd6cc2SKarsten Heimrich 429308f0e19SMichael Pfeiffer UpdateHalftonePreview(); 43012fd6cc2SKarsten Heimrich 43112fd6cc2SKarsten Heimrich UpdateButtonEnabledState(); 43212fd6cc2SKarsten Heimrich } 43312fd6cc2SKarsten Heimrich 434a7dde370SMichael Pfeiffer 435308f0e19SMichael Pfeiffer bool 436308f0e19SMichael Pfeiffer JobSetupView::IsHalftoneConfigurationNeeded() 437308f0e19SMichael Pfeiffer { 438308f0e19SMichael Pfeiffer return fPrinterCap->isSupport(PrinterCap::kHalftone); 439308f0e19SMichael Pfeiffer } 440308f0e19SMichael Pfeiffer 441308f0e19SMichael Pfeiffer 442308f0e19SMichael Pfeiffer void 443308f0e19SMichael Pfeiffer JobSetupView::CreateHalftoneConfigurationUI() 444308f0e19SMichael Pfeiffer { 445308f0e19SMichael Pfeiffer // dither type 446308f0e19SMichael Pfeiffer fDitherType = new BPopUpMenu(""); 447308f0e19SMichael Pfeiffer fDitherType->SetRadioMode(true); 448308f0e19SMichael Pfeiffer FillCapabilityMenu(fDitherType, kMsgQuality, gDitherTypes, 449308f0e19SMichael Pfeiffer sizeof(gDitherTypes) / sizeof(gDitherTypes[0]), 450308f0e19SMichael Pfeiffer fJobData->getDitherType()); 451308f0e19SMichael Pfeiffer fDitherMenuField = new BMenuField("dithering", "Dot Pattern:", 452308f0e19SMichael Pfeiffer fDitherType); 453308f0e19SMichael Pfeiffer fDitherType->SetTargetForItems(this); 454308f0e19SMichael Pfeiffer 455308f0e19SMichael Pfeiffer // halftone preview view 456308f0e19SMichael Pfeiffer fHalftoneBox = new BBox("halftoneBox"); 457308f0e19SMichael Pfeiffer fHalftoneBox->SetBorder(B_PLAIN_BORDER); 458308f0e19SMichael Pfeiffer 459308f0e19SMichael Pfeiffer // TODO make layout compatible 460308f0e19SMichael Pfeiffer BSize size(240, 14 * 4); 461308f0e19SMichael Pfeiffer BRect rect(0, 0, size.width, size.height); 462308f0e19SMichael Pfeiffer fHalftone = new HalftoneView(rect, "halftone", 463308f0e19SMichael Pfeiffer B_FOLLOW_ALL, B_WILL_DRAW); 464308f0e19SMichael Pfeiffer fHalftone->SetExplicitMinSize(size); 465308f0e19SMichael Pfeiffer fHalftone->SetExplicitMaxSize(size); 466308f0e19SMichael Pfeiffer 467308f0e19SMichael Pfeiffer // gamma 468308f0e19SMichael Pfeiffer fGamma = new JSDSlider("gamma", "Gamma", new BMessage(kMsgQuality), 469308f0e19SMichael Pfeiffer -300, 300); 470308f0e19SMichael Pfeiffer 471308f0e19SMichael Pfeiffer fGamma->SetLimitLabels("Lighter", "Darker"); 472308f0e19SMichael Pfeiffer fGamma->SetValue((int32)(100 * log(fJobData->getGamma()) / log(2.0))); 473308f0e19SMichael Pfeiffer fGamma->SetHashMarks(B_HASH_MARKS_BOTH); 474308f0e19SMichael Pfeiffer fGamma->SetHashMarkCount(7); 475308f0e19SMichael Pfeiffer fGamma->SetModificationMessage(new BMessage(kMsgQuality)); 476308f0e19SMichael Pfeiffer fGamma->SetTarget(this); 477308f0e19SMichael Pfeiffer 478308f0e19SMichael Pfeiffer // ink density 479308f0e19SMichael Pfeiffer fInkDensity = new JSDSlider("inkDensity", "Ink Usage", 480308f0e19SMichael Pfeiffer new BMessage(kMsgQuality), 0, 127); 481308f0e19SMichael Pfeiffer 482308f0e19SMichael Pfeiffer fInkDensity->SetLimitLabels("Min", "Max"); 483308f0e19SMichael Pfeiffer fInkDensity->SetValue((int32)fJobData->getInkDensity()); 484308f0e19SMichael Pfeiffer fInkDensity->SetHashMarks(B_HASH_MARKS_BOTH); 485308f0e19SMichael Pfeiffer fInkDensity->SetHashMarkCount(10); 486308f0e19SMichael Pfeiffer fInkDensity->SetModificationMessage(new BMessage(kMsgQuality)); 487308f0e19SMichael Pfeiffer fInkDensity->SetTarget(this); 488308f0e19SMichael Pfeiffer } 489308f0e19SMichael Pfeiffer 490308f0e19SMichael Pfeiffer 49112fd6cc2SKarsten Heimrich void 492f53abcbdSMichael Pfeiffer JobSetupView::FillCapabilityMenu(BPopUpMenu* menu, uint32 message, 493f53abcbdSMichael Pfeiffer PrinterCap::CapID category, int id) 494f53abcbdSMichael Pfeiffer { 495f53abcbdSMichael Pfeiffer int count = fPrinterCap->countCap(category); 496f53abcbdSMichael Pfeiffer const BaseCap **capabilities = fPrinterCap->enumCap(category); 497f53abcbdSMichael Pfeiffer FillCapabilityMenu(menu, message, capabilities, count, id); 498f53abcbdSMichael Pfeiffer } 499f53abcbdSMichael Pfeiffer 500f53abcbdSMichael Pfeiffer void 501f53abcbdSMichael Pfeiffer JobSetupView::FillCapabilityMenu(BPopUpMenu* menu, uint32 message, 502f53abcbdSMichael Pfeiffer const BaseCap** capabilities, int count, int id) 503f53abcbdSMichael Pfeiffer { 504f53abcbdSMichael Pfeiffer bool marked = false; 505f53abcbdSMichael Pfeiffer 506f53abcbdSMichael Pfeiffer BMenuItem* firstItem = NULL; 507f53abcbdSMichael Pfeiffer BMenuItem* defaultItem = NULL; 508f53abcbdSMichael Pfeiffer BMenuItem* item = NULL; 509f53abcbdSMichael Pfeiffer while (count--) { 510f53abcbdSMichael Pfeiffer const BaseCap* capability = *capabilities; 511f53abcbdSMichael Pfeiffer if (message != kMsgNone) 512f53abcbdSMichael Pfeiffer item = new BMenuItem(capability->fLabel.c_str(), 513308f0e19SMichael Pfeiffer new BMessage(message)); 514f53abcbdSMichael Pfeiffer else 515f53abcbdSMichael Pfeiffer item = new BMenuItem(capability->fLabel.c_str(), NULL); 516f53abcbdSMichael Pfeiffer 517f53abcbdSMichael Pfeiffer menu->AddItem(item); 518f53abcbdSMichael Pfeiffer 519f53abcbdSMichael Pfeiffer if (firstItem == NULL) 520f53abcbdSMichael Pfeiffer firstItem = item; 521f53abcbdSMichael Pfeiffer 522f53abcbdSMichael Pfeiffer if (capability->fIsDefault) 523f53abcbdSMichael Pfeiffer defaultItem = item; 524f53abcbdSMichael Pfeiffer 525f53abcbdSMichael Pfeiffer 526f53abcbdSMichael Pfeiffer if (capability->ID() == id) { 527f53abcbdSMichael Pfeiffer item->SetMarked(true); 528f53abcbdSMichael Pfeiffer marked = true; 529f53abcbdSMichael Pfeiffer } 530f53abcbdSMichael Pfeiffer 531f53abcbdSMichael Pfeiffer capabilities++; 532f53abcbdSMichael Pfeiffer } 533f53abcbdSMichael Pfeiffer 534f53abcbdSMichael Pfeiffer if (marked) 535f53abcbdSMichael Pfeiffer return; 536f53abcbdSMichael Pfeiffer 537f53abcbdSMichael Pfeiffer if (defaultItem != NULL) 538f53abcbdSMichael Pfeiffer defaultItem->SetMarked(true); 539f53abcbdSMichael Pfeiffer else if (firstItem != NULL) 540f53abcbdSMichael Pfeiffer firstItem->SetMarked(true); 541f53abcbdSMichael Pfeiffer } 542f53abcbdSMichael Pfeiffer 543f53abcbdSMichael Pfeiffer 544f53abcbdSMichael Pfeiffer int 545f53abcbdSMichael Pfeiffer JobSetupView::GetID(const BaseCap** capabilities, int count, const char* label, 546f53abcbdSMichael Pfeiffer int defaultValue) 547f53abcbdSMichael Pfeiffer { 548f53abcbdSMichael Pfeiffer while (count--) { 549f53abcbdSMichael Pfeiffer const BaseCap* capability = *capabilities; 550f53abcbdSMichael Pfeiffer if (capability->fLabel == label) 551f53abcbdSMichael Pfeiffer return capability->ID(); 552f53abcbdSMichael Pfeiffer } 553f53abcbdSMichael Pfeiffer return defaultValue; 554f53abcbdSMichael Pfeiffer } 555f53abcbdSMichael Pfeiffer 556f53abcbdSMichael Pfeiffer 557f53abcbdSMichael Pfeiffer void 55812fd6cc2SKarsten Heimrich JobSetupView::UpdateButtonEnabledState() 55912fd6cc2SKarsten Heimrich { 56012fd6cc2SKarsten Heimrich bool pageRangeEnabled = fAll->Value() != B_CONTROL_ON; 56112fd6cc2SKarsten Heimrich fFromPage->SetEnabled(pageRangeEnabled); 56212fd6cc2SKarsten Heimrich fToPage->SetEnabled(pageRangeEnabled); 56312fd6cc2SKarsten Heimrich 56412fd6cc2SKarsten Heimrich bool pageSelectionEnabled = fDuplex == NULL || 56512fd6cc2SKarsten Heimrich fDuplex->Value() != B_CONTROL_ON; 56612fd6cc2SKarsten Heimrich fAllPages->SetEnabled(pageSelectionEnabled); 56712fd6cc2SKarsten Heimrich fOddNumberedPages->SetEnabled(pageSelectionEnabled); 56812fd6cc2SKarsten Heimrich fEvenNumberedPages->SetEnabled(pageSelectionEnabled); 56912fd6cc2SKarsten Heimrich } 57012fd6cc2SKarsten Heimrich 571a7dde370SMichael Pfeiffer 57212fd6cc2SKarsten Heimrich void 57356c20e82SMichael Pfeiffer JobSetupView::MessageReceived(BMessage* message) 57412fd6cc2SKarsten Heimrich { 57556c20e82SMichael Pfeiffer switch (message->what) { 57612fd6cc2SKarsten Heimrich case kMsgRangeAll: 57712fd6cc2SKarsten Heimrich case kMsgRangeSelection: 57812fd6cc2SKarsten Heimrich case kMsgDuplexChanged: 57912fd6cc2SKarsten Heimrich UpdateButtonEnabledState(); 58012fd6cc2SKarsten Heimrich break; 58112fd6cc2SKarsten Heimrich 58212fd6cc2SKarsten Heimrich case kMsgQuality: 583308f0e19SMichael Pfeiffer UpdateHalftonePreview(); 58412fd6cc2SKarsten Heimrich break; 58512fd6cc2SKarsten Heimrich 58612fd6cc2SKarsten Heimrich case kMsgCollateChanged: 58712fd6cc2SKarsten Heimrich fPages->setCollate(fCollate->Value() == B_CONTROL_ON); 58812fd6cc2SKarsten Heimrich break; 58912fd6cc2SKarsten Heimrich 59012fd6cc2SKarsten Heimrich case kMsgReverseChanged: 59112fd6cc2SKarsten Heimrich fPages->setReverse(fReverse->Value() == B_CONTROL_ON); 59212fd6cc2SKarsten Heimrich break; 59312fd6cc2SKarsten Heimrich } 59412fd6cc2SKarsten Heimrich } 59512fd6cc2SKarsten Heimrich 596a7dde370SMichael Pfeiffer 597308f0e19SMichael Pfeiffer void 598308f0e19SMichael Pfeiffer JobSetupView::UpdateHalftonePreview() 599308f0e19SMichael Pfeiffer { 600308f0e19SMichael Pfeiffer if (!IsHalftoneConfigurationNeeded()) 601308f0e19SMichael Pfeiffer return; 602308f0e19SMichael Pfeiffer 603308f0e19SMichael Pfeiffer fHalftone->preview(Gamma(), InkDensity(), DitherType(), 604308f0e19SMichael Pfeiffer Color() != JobData::kMonochrome); 605308f0e19SMichael Pfeiffer } 606308f0e19SMichael Pfeiffer 607308f0e19SMichael Pfeiffer 60812fd6cc2SKarsten Heimrich JobData::Color 609f53abcbdSMichael Pfeiffer JobSetupView::Color() 61012fd6cc2SKarsten Heimrich { 611f53abcbdSMichael Pfeiffer const char *label = fColorType->FindMarked()->Label(); 612f53abcbdSMichael Pfeiffer const BaseCap* capability = fPrinterCap->findCap(PrinterCap::kColor, label); 613f53abcbdSMichael Pfeiffer if (capability == NULL) 61412fd6cc2SKarsten Heimrich return JobData::kMonochrome; 615f53abcbdSMichael Pfeiffer 616f53abcbdSMichael Pfeiffer const ColorCap* colorCap = static_cast<const ColorCap*>(capability); 617f53abcbdSMichael Pfeiffer return colorCap->fColor; 61812fd6cc2SKarsten Heimrich } 61912fd6cc2SKarsten Heimrich 620a7dde370SMichael Pfeiffer 62112fd6cc2SKarsten Heimrich Halftone::DitherType 622f53abcbdSMichael Pfeiffer JobSetupView::DitherType() 62312fd6cc2SKarsten Heimrich { 624f53abcbdSMichael Pfeiffer const char *label = fDitherType->FindMarked()->Label(); 625f53abcbdSMichael Pfeiffer int id = GetID(gDitherTypes, sizeof(gDitherTypes) / sizeof(gDitherTypes[0]), 626f53abcbdSMichael Pfeiffer label, Halftone::kTypeFloydSteinberg); 627f53abcbdSMichael Pfeiffer return static_cast<Halftone::DitherType>(id); 62812fd6cc2SKarsten Heimrich } 62912fd6cc2SKarsten Heimrich 63012fd6cc2SKarsten Heimrich float 631f53abcbdSMichael Pfeiffer JobSetupView::Gamma() 63212fd6cc2SKarsten Heimrich { 63312fd6cc2SKarsten Heimrich const float value = (float)fGamma->Value(); 63412fd6cc2SKarsten Heimrich return pow(2.0, value / 100.0); 63512fd6cc2SKarsten Heimrich } 63612fd6cc2SKarsten Heimrich 637a7dde370SMichael Pfeiffer 63812fd6cc2SKarsten Heimrich float 639f53abcbdSMichael Pfeiffer JobSetupView::InkDensity() 64012fd6cc2SKarsten Heimrich { 64112fd6cc2SKarsten Heimrich const float value = (float)(127 - fInkDensity->Value()); 64212fd6cc2SKarsten Heimrich return value; 64312fd6cc2SKarsten Heimrich } 64412fd6cc2SKarsten Heimrich 645a7dde370SMichael Pfeiffer 646f53abcbdSMichael Pfeiffer JobData::PaperSource 647f53abcbdSMichael Pfeiffer JobSetupView::PaperSource() 648f53abcbdSMichael Pfeiffer { 649f53abcbdSMichael Pfeiffer const char *label = fPaperFeed->FindMarked()->Label(); 650f53abcbdSMichael Pfeiffer const BaseCap* capability = fPrinterCap->findCap(PrinterCap::kPaperSource, 651f53abcbdSMichael Pfeiffer label); 652f53abcbdSMichael Pfeiffer 653f53abcbdSMichael Pfeiffer if (capability == NULL) 654f53abcbdSMichael Pfeiffer capability = fPrinterCap->getDefaultCap(PrinterCap::kPaperSource); 655f53abcbdSMichael Pfeiffer return static_cast<const PaperSourceCap*>(capability)->fPaperSource; 656f53abcbdSMichael Pfeiffer 657f53abcbdSMichael Pfeiffer } 658f53abcbdSMichael Pfeiffer 65912fd6cc2SKarsten Heimrich bool 66012fd6cc2SKarsten Heimrich JobSetupView::UpdateJobData(bool showPreview) 66112fd6cc2SKarsten Heimrich { 66212fd6cc2SKarsten Heimrich fJobData->setShowPreview(showPreview); 663f53abcbdSMichael Pfeiffer fJobData->setColor(Color()); 664308f0e19SMichael Pfeiffer if (IsHalftoneConfigurationNeeded()) { 665f53abcbdSMichael Pfeiffer fJobData->setGamma(Gamma()); 666f53abcbdSMichael Pfeiffer fJobData->setInkDensity(InkDensity()); 667f53abcbdSMichael Pfeiffer fJobData->setDitherType(DitherType()); 668308f0e19SMichael Pfeiffer } 66912fd6cc2SKarsten Heimrich 67012fd6cc2SKarsten Heimrich int first_page; 67112fd6cc2SKarsten Heimrich int last_page; 67212fd6cc2SKarsten Heimrich 67312fd6cc2SKarsten Heimrich if (B_CONTROL_ON == fAll->Value()) { 67412fd6cc2SKarsten Heimrich first_page = 1; 67512fd6cc2SKarsten Heimrich last_page = -1; 67612fd6cc2SKarsten Heimrich } else { 67712fd6cc2SKarsten Heimrich first_page = atoi(fFromPage->Text()); 67812fd6cc2SKarsten Heimrich last_page = atoi(fToPage->Text()); 67912fd6cc2SKarsten Heimrich } 68012fd6cc2SKarsten Heimrich 68112fd6cc2SKarsten Heimrich fJobData->setFirstPage(first_page); 68212fd6cc2SKarsten Heimrich fJobData->setLastPage(last_page); 68312fd6cc2SKarsten Heimrich 684f53abcbdSMichael Pfeiffer fJobData->setPaperSource(PaperSource()); 68512fd6cc2SKarsten Heimrich 686f53abcbdSMichael Pfeiffer fJobData->setNup(GetID(gNups, sizeof(gNups) / sizeof(gNups[0]), 687f53abcbdSMichael Pfeiffer fNup->FindMarked()->Label(), 1)); 68812fd6cc2SKarsten Heimrich 68912fd6cc2SKarsten Heimrich if (fPrinterCap->isSupport(PrinterCap::kPrintStyle)) { 690f53abcbdSMichael Pfeiffer fJobData->setPrintStyle((B_CONTROL_ON == fDuplex->Value()) 691f53abcbdSMichael Pfeiffer ? JobData::kDuplex : JobData::kSimplex); 69212fd6cc2SKarsten Heimrich } 69312fd6cc2SKarsten Heimrich 69412fd6cc2SKarsten Heimrich fJobData->setCopies(atoi(fCopies->Text())); 69512fd6cc2SKarsten Heimrich 69656c20e82SMichael Pfeiffer fJobData->setCollate(B_CONTROL_ON == fCollate->Value()); 69756c20e82SMichael Pfeiffer fJobData->setReverse(B_CONTROL_ON == fReverse->Value()); 69812fd6cc2SKarsten Heimrich 69912fd6cc2SKarsten Heimrich JobData::PageSelection pageSelection = JobData::kAllPages; 70012fd6cc2SKarsten Heimrich if (fOddNumberedPages->Value() == B_CONTROL_ON) 70112fd6cc2SKarsten Heimrich pageSelection = JobData::kOddNumberedPages; 70212fd6cc2SKarsten Heimrich if (fEvenNumberedPages->Value() == B_CONTROL_ON) 70312fd6cc2SKarsten Heimrich pageSelection = JobData::kEvenNumberedPages; 70412fd6cc2SKarsten Heimrich fJobData->setPageSelection(pageSelection); 70512fd6cc2SKarsten Heimrich 70612fd6cc2SKarsten Heimrich fJobData->save(); 70712fd6cc2SKarsten Heimrich return true; 70812fd6cc2SKarsten Heimrich } 70912fd6cc2SKarsten Heimrich 71012fd6cc2SKarsten Heimrich 71156c20e82SMichael Pfeiffer JobSetupDlg::JobSetupDlg(JobData* jobData, PrinterData* printerData, 71256c20e82SMichael Pfeiffer const PrinterCap* printerCap) 713a7dde370SMichael Pfeiffer : 714a7dde370SMichael Pfeiffer DialogWindow(BRect(100, 100, 200, 200), "PrintJob Setup", 715a7dde370SMichael Pfeiffer B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, 7165a695bceSMichael Pfeiffer B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE 7175a695bceSMichael Pfeiffer | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS) 71812fd6cc2SKarsten Heimrich { 71912fd6cc2SKarsten Heimrich SetResult(B_ERROR); 72012fd6cc2SKarsten Heimrich AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); 72112fd6cc2SKarsten Heimrich 72256c20e82SMichael Pfeiffer fJobSetup = new JobSetupView(jobData, printerData, printerCap); 7235a695bceSMichael Pfeiffer SetLayout(new BGroupLayout(B_VERTICAL)); 7245a695bceSMichael Pfeiffer AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) 7255a695bceSMichael Pfeiffer .Add(fJobSetup) 7265a695bceSMichael Pfeiffer .SetInsets(10, 10, 10, 10) 7275a695bceSMichael Pfeiffer ); 72812fd6cc2SKarsten Heimrich } 72912fd6cc2SKarsten Heimrich 730a7dde370SMichael Pfeiffer 73112fd6cc2SKarsten Heimrich void 73256c20e82SMichael Pfeiffer JobSetupDlg::MessageReceived(BMessage* message) 73312fd6cc2SKarsten Heimrich { 73456c20e82SMichael Pfeiffer switch (message->what) { 73512fd6cc2SKarsten Heimrich case kMsgOK: 73612fd6cc2SKarsten Heimrich case kMsgPreview: 73756c20e82SMichael Pfeiffer fJobSetup->UpdateJobData(message->what == kMsgPreview); 73812fd6cc2SKarsten Heimrich SetResult(B_NO_ERROR); 73912fd6cc2SKarsten Heimrich PostMessage(B_QUIT_REQUESTED); 74012fd6cc2SKarsten Heimrich break; 74112fd6cc2SKarsten Heimrich 74212fd6cc2SKarsten Heimrich case kMsgCancel: 74312fd6cc2SKarsten Heimrich PostMessage(B_QUIT_REQUESTED); 74412fd6cc2SKarsten Heimrich break; 74512fd6cc2SKarsten Heimrich 74612fd6cc2SKarsten Heimrich default: 74756c20e82SMichael Pfeiffer DialogWindow::MessageReceived(message); 74812fd6cc2SKarsten Heimrich break; 74912fd6cc2SKarsten Heimrich } 75012fd6cc2SKarsten Heimrich } 751