xref: /haiku/src/libs/print/libprint/JobSetupDlg.cpp (revision 308f0e195dc9a71620970f8ebfe6e02fe6e27ddc)
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 
59f53abcbdSMichael Pfeiffer 	int	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 
73f53abcbdSMichael Pfeiffer 	int	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 
1325a695bceSMichael Pfeiffer JobSetupView::JobSetupView(JobData *job_data, PrinterData *printer_data,
1335a695bceSMichael Pfeiffer 	const PrinterCap *printer_cap)
134a7dde370SMichael Pfeiffer 	:
135a7dde370SMichael Pfeiffer 	BView("jobSetup", B_WILL_DRAW),
136*308f0e19SMichael Pfeiffer 	fCopies(NULL),
137*308f0e19SMichael Pfeiffer 	fFromPage(NULL),
138*308f0e19SMichael Pfeiffer 	fToPage(NULL),
139a7dde370SMichael Pfeiffer 	fJobData(job_data),
140a7dde370SMichael Pfeiffer 	fPrinterData(printer_data),
141*308f0e19SMichael Pfeiffer 	fPrinterCap(printer_cap),
142*308f0e19SMichael Pfeiffer 	fColorType(NULL),
143*308f0e19SMichael Pfeiffer 	fDitherType(NULL),
144*308f0e19SMichael Pfeiffer 	fGamma(NULL),
145*308f0e19SMichael Pfeiffer 	fInkDensity(NULL),
146*308f0e19SMichael Pfeiffer 	fHalftone(NULL),
147*308f0e19SMichael Pfeiffer 	fAll(NULL),
148*308f0e19SMichael Pfeiffer 	fCollate(NULL),
149*308f0e19SMichael Pfeiffer 	fReverse(NULL),
150*308f0e19SMichael Pfeiffer 	fPages(NULL),
151*308f0e19SMichael Pfeiffer 	fPaperFeed(NULL),
152*308f0e19SMichael Pfeiffer 	fDuplex(NULL),
153*308f0e19SMichael Pfeiffer 	fNup(NULL),
154*308f0e19SMichael Pfeiffer 	fAllPages(NULL),
155*308f0e19SMichael Pfeiffer 	fOddNumberedPages(NULL),
156*308f0e19SMichael 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 
203*308f0e19SMichael Pfeiffer 	if (IsHalftoneConfigurationNeeded())
204*308f0e19SMichael 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 
332*308f0e19SMichael Pfeiffer 	if (IsHalftoneConfigurationNeeded()) {
3335a695bceSMichael Pfeiffer 		BGroupView* halftoneGroup = new BGroupView(B_VERTICAL, 0);
3345a695bceSMichael Pfeiffer 		BGroupLayout* halftoneLayout = halftoneGroup->GroupLayout();
3355a695bceSMichael Pfeiffer 		halftoneLayout->AddView(fHalftone);
336*308f0e19SMichael Pfeiffer 		fHalftoneBox->AddChild(halftoneGroup);
337*308f0e19SMichael 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);
343*308f0e19SMichael Pfeiffer 	if (IsHalftoneConfigurationNeeded()) {
344*308f0e19SMichael Pfeiffer 		qualityGridLayout->AddItem(fDitherMenuField->CreateLabelLayoutItem(),
345*308f0e19SMichael Pfeiffer 			0, 1);
346*308f0e19SMichael Pfeiffer 		qualityGridLayout->AddItem(fDitherMenuField->CreateMenuBarLayoutItem(),
347*308f0e19SMichael Pfeiffer 			1, 1);
3485a695bceSMichael Pfeiffer 		qualityGridLayout->AddView(fGamma, 0, 2, 2);
3495a695bceSMichael Pfeiffer 		qualityGridLayout->AddView(fInkDensity, 0, 3, 2);
350*308f0e19SMichael Pfeiffer 		qualityGridLayout->AddView(fHalftoneBox, 0, 4, 2);
351*308f0e19SMichael 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 
429*308f0e19SMichael Pfeiffer 	/* TODO remove
430*308f0e19SMichael Pfeiffer 	if (IsHalftoneConfigurationNeeded())
431*308f0e19SMichael Pfeiffer 
4325a695bceSMichael Pfeiffer 		fHalftone->preview(fJobData->getGamma(), fJobData->getInkDensity(),
433*308f0e19SMichael Pfeiffer 			fJobData->getDitherType(),
434*308f0e19SMichael Pfeiffer 			fJobData->getColor() != JobData::kMonochrome);
435*308f0e19SMichael Pfeiffer 	*/
436*308f0e19SMichael Pfeiffer 	UpdateHalftonePreview();
43712fd6cc2SKarsten Heimrich 
43812fd6cc2SKarsten Heimrich 	UpdateButtonEnabledState();
43912fd6cc2SKarsten Heimrich }
44012fd6cc2SKarsten Heimrich 
441a7dde370SMichael Pfeiffer 
442*308f0e19SMichael Pfeiffer bool
443*308f0e19SMichael Pfeiffer JobSetupView::IsHalftoneConfigurationNeeded()
444*308f0e19SMichael Pfeiffer {
445*308f0e19SMichael Pfeiffer 	return fPrinterCap->isSupport(PrinterCap::kHalftone);
446*308f0e19SMichael Pfeiffer }
447*308f0e19SMichael Pfeiffer 
448*308f0e19SMichael Pfeiffer 
449*308f0e19SMichael Pfeiffer void
450*308f0e19SMichael Pfeiffer JobSetupView::CreateHalftoneConfigurationUI()
451*308f0e19SMichael Pfeiffer {
452*308f0e19SMichael Pfeiffer 	// dither type
453*308f0e19SMichael Pfeiffer 	fDitherType = new BPopUpMenu("");
454*308f0e19SMichael Pfeiffer 	fDitherType->SetRadioMode(true);
455*308f0e19SMichael Pfeiffer 	FillCapabilityMenu(fDitherType, kMsgQuality, gDitherTypes,
456*308f0e19SMichael Pfeiffer 		sizeof(gDitherTypes) / sizeof(gDitherTypes[0]),
457*308f0e19SMichael Pfeiffer 		fJobData->getDitherType());
458*308f0e19SMichael Pfeiffer 	fDitherMenuField = new BMenuField("dithering", "Dot Pattern:",
459*308f0e19SMichael Pfeiffer 		fDitherType);
460*308f0e19SMichael Pfeiffer 	fDitherType->SetTargetForItems(this);
461*308f0e19SMichael Pfeiffer 
462*308f0e19SMichael Pfeiffer 	// halftone preview view
463*308f0e19SMichael Pfeiffer 	fHalftoneBox = new BBox("halftoneBox");
464*308f0e19SMichael Pfeiffer 	fHalftoneBox->SetBorder(B_PLAIN_BORDER);
465*308f0e19SMichael Pfeiffer 
466*308f0e19SMichael Pfeiffer 	// TODO make layout compatible
467*308f0e19SMichael Pfeiffer 	BSize size(240, 14 * 4);
468*308f0e19SMichael Pfeiffer 	BRect rect(0, 0, size.width, size.height);
469*308f0e19SMichael Pfeiffer 	fHalftone = new HalftoneView(rect, "halftone",
470*308f0e19SMichael Pfeiffer 		B_FOLLOW_ALL, B_WILL_DRAW);
471*308f0e19SMichael Pfeiffer 	fHalftone->SetExplicitMinSize(size);
472*308f0e19SMichael Pfeiffer 	fHalftone->SetExplicitMaxSize(size);
473*308f0e19SMichael Pfeiffer 
474*308f0e19SMichael Pfeiffer 	// gamma
475*308f0e19SMichael Pfeiffer 	fGamma = new JSDSlider("gamma", "Gamma", new BMessage(kMsgQuality),
476*308f0e19SMichael Pfeiffer 		-300, 300);
477*308f0e19SMichael Pfeiffer 
478*308f0e19SMichael Pfeiffer 	fGamma->SetLimitLabels("Lighter", "Darker");
479*308f0e19SMichael Pfeiffer 	fGamma->SetValue((int32)(100 * log(fJobData->getGamma()) / log(2.0)));
480*308f0e19SMichael Pfeiffer 	fGamma->SetHashMarks(B_HASH_MARKS_BOTH);
481*308f0e19SMichael Pfeiffer 	fGamma->SetHashMarkCount(7);
482*308f0e19SMichael Pfeiffer 	fGamma->SetModificationMessage(new BMessage(kMsgQuality));
483*308f0e19SMichael Pfeiffer 	fGamma->SetTarget(this);
484*308f0e19SMichael Pfeiffer 
485*308f0e19SMichael Pfeiffer 	// ink density
486*308f0e19SMichael Pfeiffer 	fInkDensity = new JSDSlider("inkDensity", "Ink Usage",
487*308f0e19SMichael Pfeiffer 		new BMessage(kMsgQuality), 0, 127);
488*308f0e19SMichael Pfeiffer 
489*308f0e19SMichael Pfeiffer 	fInkDensity->SetLimitLabels("Min", "Max");
490*308f0e19SMichael Pfeiffer 	fInkDensity->SetValue((int32)fJobData->getInkDensity());
491*308f0e19SMichael Pfeiffer 	fInkDensity->SetHashMarks(B_HASH_MARKS_BOTH);
492*308f0e19SMichael Pfeiffer 	fInkDensity->SetHashMarkCount(10);
493*308f0e19SMichael Pfeiffer 	fInkDensity->SetModificationMessage(new BMessage(kMsgQuality));
494*308f0e19SMichael Pfeiffer 	fInkDensity->SetTarget(this);
495*308f0e19SMichael Pfeiffer }
496*308f0e19SMichael Pfeiffer 
497*308f0e19SMichael Pfeiffer 
49812fd6cc2SKarsten Heimrich void
499f53abcbdSMichael Pfeiffer JobSetupView::FillCapabilityMenu(BPopUpMenu* menu, uint32 message,
500f53abcbdSMichael Pfeiffer 	PrinterCap::CapID category, int id)
501f53abcbdSMichael Pfeiffer {
502f53abcbdSMichael Pfeiffer 	int count = fPrinterCap->countCap(category);
503f53abcbdSMichael Pfeiffer 	const BaseCap **capabilities = fPrinterCap->enumCap(category);
504f53abcbdSMichael Pfeiffer 	FillCapabilityMenu(menu, message, capabilities, count, id);
505f53abcbdSMichael Pfeiffer }
506f53abcbdSMichael Pfeiffer 
507f53abcbdSMichael Pfeiffer void
508f53abcbdSMichael Pfeiffer JobSetupView::FillCapabilityMenu(BPopUpMenu* menu, uint32 message,
509f53abcbdSMichael Pfeiffer 	const BaseCap** capabilities, int count, int id)
510f53abcbdSMichael Pfeiffer {
511f53abcbdSMichael Pfeiffer 	bool marked = false;
512f53abcbdSMichael Pfeiffer 
513f53abcbdSMichael Pfeiffer 	BMenuItem* firstItem = NULL;
514f53abcbdSMichael Pfeiffer 	BMenuItem* defaultItem = NULL;
515f53abcbdSMichael Pfeiffer 	BMenuItem* item = NULL;
516f53abcbdSMichael Pfeiffer 	while (count--) {
517f53abcbdSMichael Pfeiffer 		const BaseCap* capability = *capabilities;
518f53abcbdSMichael Pfeiffer 		if (message != kMsgNone)
519f53abcbdSMichael Pfeiffer 			item = new BMenuItem(capability->fLabel.c_str(),
520*308f0e19SMichael Pfeiffer 				new BMessage(message));
521f53abcbdSMichael Pfeiffer 		else
522f53abcbdSMichael Pfeiffer 			item = new BMenuItem(capability->fLabel.c_str(), NULL);
523f53abcbdSMichael Pfeiffer 
524f53abcbdSMichael Pfeiffer 		menu->AddItem(item);
525f53abcbdSMichael Pfeiffer 
526f53abcbdSMichael Pfeiffer 		if (firstItem == NULL)
527f53abcbdSMichael Pfeiffer 			firstItem = item;
528f53abcbdSMichael Pfeiffer 
529f53abcbdSMichael Pfeiffer 		if (capability->fIsDefault)
530f53abcbdSMichael Pfeiffer 			defaultItem = item;
531f53abcbdSMichael Pfeiffer 
532f53abcbdSMichael Pfeiffer 
533f53abcbdSMichael Pfeiffer 		if (capability->ID() == id) {
534f53abcbdSMichael Pfeiffer 			item->SetMarked(true);
535f53abcbdSMichael Pfeiffer 			marked = true;
536f53abcbdSMichael Pfeiffer 		}
537f53abcbdSMichael Pfeiffer 
538f53abcbdSMichael Pfeiffer 		capabilities++;
539f53abcbdSMichael Pfeiffer 	}
540f53abcbdSMichael Pfeiffer 
541f53abcbdSMichael Pfeiffer 	if (marked)
542f53abcbdSMichael Pfeiffer 		return;
543f53abcbdSMichael Pfeiffer 
544f53abcbdSMichael Pfeiffer 	if (defaultItem != NULL)
545f53abcbdSMichael Pfeiffer 		defaultItem->SetMarked(true);
546f53abcbdSMichael Pfeiffer 	else if (firstItem != NULL)
547f53abcbdSMichael Pfeiffer 		firstItem->SetMarked(true);
548f53abcbdSMichael Pfeiffer }
549f53abcbdSMichael Pfeiffer 
550f53abcbdSMichael Pfeiffer 
551f53abcbdSMichael Pfeiffer int
552f53abcbdSMichael Pfeiffer JobSetupView::GetID(const BaseCap** capabilities, int count, const char* label,
553f53abcbdSMichael Pfeiffer 	int defaultValue)
554f53abcbdSMichael Pfeiffer {
555f53abcbdSMichael Pfeiffer 	while (count--) {
556f53abcbdSMichael Pfeiffer 		const BaseCap* capability = *capabilities;
557f53abcbdSMichael Pfeiffer 		if (capability->fLabel == label)
558f53abcbdSMichael Pfeiffer 			return capability->ID();
559f53abcbdSMichael Pfeiffer 	}
560f53abcbdSMichael Pfeiffer 	return defaultValue;
561f53abcbdSMichael Pfeiffer }
562f53abcbdSMichael Pfeiffer 
563f53abcbdSMichael Pfeiffer 
564f53abcbdSMichael Pfeiffer void
56512fd6cc2SKarsten Heimrich JobSetupView::UpdateButtonEnabledState()
56612fd6cc2SKarsten Heimrich {
56712fd6cc2SKarsten Heimrich 	bool pageRangeEnabled = fAll->Value() != B_CONTROL_ON;
56812fd6cc2SKarsten Heimrich 	fFromPage->SetEnabled(pageRangeEnabled);
56912fd6cc2SKarsten Heimrich 	fToPage->SetEnabled(pageRangeEnabled);
57012fd6cc2SKarsten Heimrich 
57112fd6cc2SKarsten Heimrich 	bool pageSelectionEnabled = fDuplex == NULL ||
57212fd6cc2SKarsten Heimrich 		fDuplex->Value() != B_CONTROL_ON;
57312fd6cc2SKarsten Heimrich 	fAllPages->SetEnabled(pageSelectionEnabled);
57412fd6cc2SKarsten Heimrich 	fOddNumberedPages->SetEnabled(pageSelectionEnabled);
57512fd6cc2SKarsten Heimrich 	fEvenNumberedPages->SetEnabled(pageSelectionEnabled);
57612fd6cc2SKarsten Heimrich }
57712fd6cc2SKarsten Heimrich 
578a7dde370SMichael Pfeiffer 
57912fd6cc2SKarsten Heimrich void
58012fd6cc2SKarsten Heimrich JobSetupView::MessageReceived(BMessage *msg)
58112fd6cc2SKarsten Heimrich {
58212fd6cc2SKarsten Heimrich 	switch (msg->what) {
58312fd6cc2SKarsten Heimrich 	case kMsgRangeAll:
58412fd6cc2SKarsten Heimrich 	case kMsgRangeSelection:
58512fd6cc2SKarsten Heimrich 	case kMsgDuplexChanged:
58612fd6cc2SKarsten Heimrich 		UpdateButtonEnabledState();
58712fd6cc2SKarsten Heimrich 		break;
58812fd6cc2SKarsten Heimrich 
58912fd6cc2SKarsten Heimrich 	case kMsgQuality:
590*308f0e19SMichael Pfeiffer 		UpdateHalftonePreview();
59112fd6cc2SKarsten Heimrich 		break;
59212fd6cc2SKarsten Heimrich 
59312fd6cc2SKarsten Heimrich 	case kMsgCollateChanged:
59412fd6cc2SKarsten Heimrich 		fPages->setCollate(fCollate->Value() == B_CONTROL_ON);
59512fd6cc2SKarsten Heimrich 		break;
59612fd6cc2SKarsten Heimrich 
59712fd6cc2SKarsten Heimrich 	case kMsgReverseChanged:
59812fd6cc2SKarsten Heimrich 		fPages->setReverse(fReverse->Value() == B_CONTROL_ON);
59912fd6cc2SKarsten Heimrich 		break;
60012fd6cc2SKarsten Heimrich 	}
60112fd6cc2SKarsten Heimrich }
60212fd6cc2SKarsten Heimrich 
603a7dde370SMichael Pfeiffer 
604*308f0e19SMichael Pfeiffer void
605*308f0e19SMichael Pfeiffer JobSetupView::UpdateHalftonePreview()
606*308f0e19SMichael Pfeiffer {
607*308f0e19SMichael Pfeiffer 	if (!IsHalftoneConfigurationNeeded())
608*308f0e19SMichael Pfeiffer 		return;
609*308f0e19SMichael Pfeiffer 
610*308f0e19SMichael Pfeiffer 	fHalftone->preview(Gamma(), InkDensity(), DitherType(),
611*308f0e19SMichael Pfeiffer 		Color() != JobData::kMonochrome);
612*308f0e19SMichael Pfeiffer }
613*308f0e19SMichael Pfeiffer 
614*308f0e19SMichael Pfeiffer 
61512fd6cc2SKarsten Heimrich JobData::Color
616f53abcbdSMichael Pfeiffer JobSetupView::Color()
61712fd6cc2SKarsten Heimrich {
618f53abcbdSMichael Pfeiffer 	const char *label = fColorType->FindMarked()->Label();
619f53abcbdSMichael Pfeiffer 	const BaseCap* capability = fPrinterCap->findCap(PrinterCap::kColor, label);
620f53abcbdSMichael Pfeiffer 	if (capability == NULL)
62112fd6cc2SKarsten Heimrich 		return JobData::kMonochrome;
622f53abcbdSMichael Pfeiffer 
623f53abcbdSMichael Pfeiffer 	const ColorCap* colorCap = static_cast<const ColorCap*>(capability);
624f53abcbdSMichael Pfeiffer 	return colorCap->fColor;
62512fd6cc2SKarsten Heimrich }
62612fd6cc2SKarsten Heimrich 
627a7dde370SMichael Pfeiffer 
62812fd6cc2SKarsten Heimrich Halftone::DitherType
629f53abcbdSMichael Pfeiffer JobSetupView::DitherType()
63012fd6cc2SKarsten Heimrich {
631f53abcbdSMichael Pfeiffer 	const char *label = fDitherType->FindMarked()->Label();
632f53abcbdSMichael Pfeiffer 	int id = GetID(gDitherTypes, sizeof(gDitherTypes) / sizeof(gDitherTypes[0]),
633f53abcbdSMichael Pfeiffer 		label, Halftone::kTypeFloydSteinberg);
634f53abcbdSMichael Pfeiffer 	return static_cast<Halftone::DitherType>(id);
63512fd6cc2SKarsten Heimrich }
63612fd6cc2SKarsten Heimrich 
63712fd6cc2SKarsten Heimrich float
638f53abcbdSMichael Pfeiffer JobSetupView::Gamma()
63912fd6cc2SKarsten Heimrich {
64012fd6cc2SKarsten Heimrich 	const float value = (float)fGamma->Value();
64112fd6cc2SKarsten Heimrich 	return pow(2.0, value / 100.0);
64212fd6cc2SKarsten Heimrich }
64312fd6cc2SKarsten Heimrich 
644a7dde370SMichael Pfeiffer 
64512fd6cc2SKarsten Heimrich float
646f53abcbdSMichael Pfeiffer JobSetupView::InkDensity()
64712fd6cc2SKarsten Heimrich {
64812fd6cc2SKarsten Heimrich 	const float value = (float)(127 - fInkDensity->Value());
64912fd6cc2SKarsten Heimrich 	return value;
65012fd6cc2SKarsten Heimrich }
65112fd6cc2SKarsten Heimrich 
652a7dde370SMichael Pfeiffer 
653f53abcbdSMichael Pfeiffer JobData::PaperSource
654f53abcbdSMichael Pfeiffer JobSetupView::PaperSource()
655f53abcbdSMichael Pfeiffer {
656f53abcbdSMichael Pfeiffer 	const char *label = fPaperFeed->FindMarked()->Label();
657f53abcbdSMichael Pfeiffer 	const BaseCap* capability = fPrinterCap->findCap(PrinterCap::kPaperSource,
658f53abcbdSMichael Pfeiffer 		label);
659f53abcbdSMichael Pfeiffer 
660f53abcbdSMichael Pfeiffer 	if (capability == NULL)
661f53abcbdSMichael Pfeiffer 		capability = fPrinterCap->getDefaultCap(PrinterCap::kPaperSource);
662f53abcbdSMichael Pfeiffer 	return static_cast<const PaperSourceCap*>(capability)->fPaperSource;
663f53abcbdSMichael Pfeiffer 
664f53abcbdSMichael Pfeiffer }
665f53abcbdSMichael Pfeiffer 
66612fd6cc2SKarsten Heimrich bool
66712fd6cc2SKarsten Heimrich JobSetupView::UpdateJobData(bool showPreview)
66812fd6cc2SKarsten Heimrich {
66912fd6cc2SKarsten Heimrich 	fJobData->setShowPreview(showPreview);
670f53abcbdSMichael Pfeiffer 	fJobData->setColor(Color());
671*308f0e19SMichael Pfeiffer 	if (IsHalftoneConfigurationNeeded()) {
672f53abcbdSMichael Pfeiffer 		fJobData->setGamma(Gamma());
673f53abcbdSMichael Pfeiffer 		fJobData->setInkDensity(InkDensity());
674f53abcbdSMichael Pfeiffer 		fJobData->setDitherType(DitherType());
675*308f0e19SMichael Pfeiffer 	}
67612fd6cc2SKarsten Heimrich 
67712fd6cc2SKarsten Heimrich 	int first_page;
67812fd6cc2SKarsten Heimrich 	int last_page;
67912fd6cc2SKarsten Heimrich 
68012fd6cc2SKarsten Heimrich 	if (B_CONTROL_ON == fAll->Value()) {
68112fd6cc2SKarsten Heimrich 		first_page = 1;
68212fd6cc2SKarsten Heimrich 		last_page  = -1;
68312fd6cc2SKarsten Heimrich 	} else {
68412fd6cc2SKarsten Heimrich 		first_page = atoi(fFromPage->Text());
68512fd6cc2SKarsten Heimrich 		last_page  = atoi(fToPage->Text());
68612fd6cc2SKarsten Heimrich 	}
68712fd6cc2SKarsten Heimrich 
68812fd6cc2SKarsten Heimrich 	fJobData->setFirstPage(first_page);
68912fd6cc2SKarsten Heimrich 	fJobData->setLastPage(last_page);
69012fd6cc2SKarsten Heimrich 
691f53abcbdSMichael Pfeiffer 	fJobData->setPaperSource(PaperSource());
69212fd6cc2SKarsten Heimrich 
693f53abcbdSMichael Pfeiffer 	fJobData->setNup(GetID(gNups, sizeof(gNups) / sizeof(gNups[0]),
694f53abcbdSMichael Pfeiffer 		fNup->FindMarked()->Label(), 1));
69512fd6cc2SKarsten Heimrich 
69612fd6cc2SKarsten Heimrich 	if (fPrinterCap->isSupport(PrinterCap::kPrintStyle)) {
697f53abcbdSMichael Pfeiffer 		fJobData->setPrintStyle((B_CONTROL_ON == fDuplex->Value())
698f53abcbdSMichael Pfeiffer 			? JobData::kDuplex : JobData::kSimplex);
69912fd6cc2SKarsten Heimrich 	}
70012fd6cc2SKarsten Heimrich 
70112fd6cc2SKarsten Heimrich 	fJobData->setCopies(atoi(fCopies->Text()));
70212fd6cc2SKarsten Heimrich 
70312fd6cc2SKarsten Heimrich 	fJobData->setCollate((B_CONTROL_ON == fCollate->Value()) ? true : false);
70412fd6cc2SKarsten Heimrich 	fJobData->setReverse((B_CONTROL_ON == fReverse->Value()) ? true : false);
70512fd6cc2SKarsten Heimrich 
70612fd6cc2SKarsten Heimrich 	JobData::PageSelection pageSelection = JobData::kAllPages;
70712fd6cc2SKarsten Heimrich 	if (fOddNumberedPages->Value() == B_CONTROL_ON)
70812fd6cc2SKarsten Heimrich 		pageSelection = JobData::kOddNumberedPages;
70912fd6cc2SKarsten Heimrich 	if (fEvenNumberedPages->Value() == B_CONTROL_ON)
71012fd6cc2SKarsten Heimrich 		pageSelection = JobData::kEvenNumberedPages;
71112fd6cc2SKarsten Heimrich 	fJobData->setPageSelection(pageSelection);
71212fd6cc2SKarsten Heimrich 
71312fd6cc2SKarsten Heimrich 	fJobData->save();
71412fd6cc2SKarsten Heimrich 	return true;
71512fd6cc2SKarsten Heimrich }
71612fd6cc2SKarsten Heimrich 
71712fd6cc2SKarsten Heimrich 
7185a695bceSMichael Pfeiffer JobSetupDlg::JobSetupDlg(JobData *job_data, PrinterData *printer_data,
7195a695bceSMichael Pfeiffer 	const PrinterCap *printer_cap)
720a7dde370SMichael Pfeiffer 	:
721a7dde370SMichael Pfeiffer 	DialogWindow(BRect(100, 100, 200, 200), "PrintJob Setup",
722a7dde370SMichael Pfeiffer 		B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,
7235a695bceSMichael Pfeiffer 		B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE
7245a695bceSMichael Pfeiffer 			| B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS)
72512fd6cc2SKarsten Heimrich {
72612fd6cc2SKarsten Heimrich 	SetResult(B_ERROR);
72712fd6cc2SKarsten Heimrich 	AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
72812fd6cc2SKarsten Heimrich 
7295a695bceSMichael Pfeiffer 	fJobSetup = new JobSetupView(job_data, printer_data, printer_cap);
7305a695bceSMichael Pfeiffer 	SetLayout(new BGroupLayout(B_VERTICAL));
7315a695bceSMichael Pfeiffer 	AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
7325a695bceSMichael Pfeiffer 		.Add(fJobSetup)
7335a695bceSMichael Pfeiffer 		.SetInsets(10, 10, 10, 10)
7345a695bceSMichael Pfeiffer 	);
73512fd6cc2SKarsten Heimrich }
73612fd6cc2SKarsten Heimrich 
737a7dde370SMichael Pfeiffer 
73812fd6cc2SKarsten Heimrich void
73912fd6cc2SKarsten Heimrich JobSetupDlg::MessageReceived(BMessage *msg)
74012fd6cc2SKarsten Heimrich {
74112fd6cc2SKarsten Heimrich 	switch (msg->what) {
74212fd6cc2SKarsten Heimrich 	case kMsgOK:
74312fd6cc2SKarsten Heimrich 	case kMsgPreview:
74412fd6cc2SKarsten Heimrich 		fJobSetup->UpdateJobData(msg->what == kMsgPreview);
74512fd6cc2SKarsten Heimrich 		SetResult(B_NO_ERROR);
74612fd6cc2SKarsten Heimrich 		PostMessage(B_QUIT_REQUESTED);
74712fd6cc2SKarsten Heimrich 		break;
74812fd6cc2SKarsten Heimrich 
74912fd6cc2SKarsten Heimrich 	case kMsgCancel:
75012fd6cc2SKarsten Heimrich 		PostMessage(B_QUIT_REQUESTED);
75112fd6cc2SKarsten Heimrich 		break;
75212fd6cc2SKarsten Heimrich 
75312fd6cc2SKarsten Heimrich 	default:
75412fd6cc2SKarsten Heimrich 		DialogWindow::MessageReceived(msg);
75512fd6cc2SKarsten Heimrich 		break;
75612fd6cc2SKarsten Heimrich 	}
75712fd6cc2SKarsten Heimrich }
758