xref: /haiku/src/libs/print/libprint/JobSetupDlg.cpp (revision 0e216008df8e39c560df9c3aa67a64d6cd7d7aac)
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>
20de18d919SMichael Pfeiffer #include <Debug.h>
215a695bceSMichael Pfeiffer #include <GridView.h>
225a695bceSMichael Pfeiffer #include <GroupLayout.h>
235a695bceSMichael Pfeiffer #include <GroupLayoutBuilder.h>
2412fd6cc2SKarsten Heimrich #include <Looper.h>
2512fd6cc2SKarsten Heimrich #include <MessageFilter.h>
2612fd6cc2SKarsten Heimrich #include <MenuField.h>
2712fd6cc2SKarsten Heimrich #include <MenuItem.h>
2812fd6cc2SKarsten Heimrich #include <Message.h>
2912fd6cc2SKarsten Heimrich #include <Point.h>
3012fd6cc2SKarsten Heimrich #include <PopUpMenu.h>
3112fd6cc2SKarsten Heimrich #include <PrintJob.h>
3212fd6cc2SKarsten Heimrich #include <RadioButton.h>
3312fd6cc2SKarsten Heimrich #include <Rect.h>
3412fd6cc2SKarsten Heimrich #include <Slider.h>
3512fd6cc2SKarsten Heimrich #include <String.h>
3612fd6cc2SKarsten Heimrich #include <TextControl.h>
3712fd6cc2SKarsten Heimrich #include <TextView.h>
3812fd6cc2SKarsten Heimrich #include <View.h>
3912fd6cc2SKarsten Heimrich 
4012fd6cc2SKarsten Heimrich #include "HalftoneView.h"
4112fd6cc2SKarsten Heimrich #include "JobSetupDlg.h"
4212fd6cc2SKarsten Heimrich #include "JobData.h"
4312fd6cc2SKarsten Heimrich #include "JSDSlider.h"
4412fd6cc2SKarsten Heimrich #include "PagesView.h"
4512fd6cc2SKarsten Heimrich #include "PrinterData.h"
4612fd6cc2SKarsten Heimrich #include "PrinterCap.h"
4712fd6cc2SKarsten Heimrich #include "DbgMsg.h"
4812fd6cc2SKarsten Heimrich 
49a7dde370SMichael Pfeiffer 
5012fd6cc2SKarsten Heimrich using namespace std;
5112fd6cc2SKarsten Heimrich 
5212fd6cc2SKarsten Heimrich 
53f14cab2dSMichael Pfeiffer struct NupCap : public EnumCap {
54a7dde370SMichael Pfeiffer 	NupCap(const string &label, bool isDefault, int nup)
55a7dde370SMichael Pfeiffer 		:
56f14cab2dSMichael Pfeiffer 		EnumCap(label, isDefault),
57a7dde370SMichael Pfeiffer 		fNup(nup)
58a7dde370SMichael Pfeiffer 	{}
59a7dde370SMichael Pfeiffer 
60961e35fbSMichael Pfeiffer 	int32	ID() const { return fNup; }
61f53abcbdSMichael Pfeiffer 
62a7dde370SMichael Pfeiffer 	int	fNup;
6312fd6cc2SKarsten Heimrich };
6412fd6cc2SKarsten Heimrich 
65a7dde370SMichael Pfeiffer 
66f14cab2dSMichael Pfeiffer struct DitherCap : public EnumCap {
67a7dde370SMichael Pfeiffer 	DitherCap(const string &label, bool isDefault,
68a7dde370SMichael Pfeiffer 		Halftone::DitherType ditherType)
69a7dde370SMichael Pfeiffer 		:
70f14cab2dSMichael Pfeiffer 		EnumCap(label, isDefault),
71a7dde370SMichael Pfeiffer 		fDitherType(ditherType)
72a7dde370SMichael Pfeiffer 	{}
73a7dde370SMichael Pfeiffer 
74961e35fbSMichael Pfeiffer 	int32	ID() const { return fDitherType; }
75f53abcbdSMichael Pfeiffer 
76a7dde370SMichael Pfeiffer 	Halftone::DitherType fDitherType;
7712fd6cc2SKarsten Heimrich };
7812fd6cc2SKarsten Heimrich 
7912fd6cc2SKarsten Heimrich 
8012fd6cc2SKarsten Heimrich static const NupCap gNup1("1", true,  1);
8112fd6cc2SKarsten Heimrich static const NupCap gNup2("2",   false, 2);
8212fd6cc2SKarsten Heimrich static const NupCap gNup4("4",   false, 4);
8312fd6cc2SKarsten Heimrich static const NupCap gNup8("8",   false, 8);
8412fd6cc2SKarsten Heimrich static const NupCap gNup9("9",   false, 9);
8512fd6cc2SKarsten Heimrich static const NupCap gNup16("16", false, 16);
8612fd6cc2SKarsten Heimrich static const NupCap gNup25("25", false, 25);
8712fd6cc2SKarsten Heimrich static const NupCap gNup32("32", false, 32);
8812fd6cc2SKarsten Heimrich static const NupCap gNup36("36", false, 36);
8912fd6cc2SKarsten Heimrich 
90a7dde370SMichael Pfeiffer 
9112fd6cc2SKarsten Heimrich static const DitherCap gDitherType1("Crosshatch", false, Halftone::kType1);
9212fd6cc2SKarsten Heimrich static const DitherCap gDitherType2("Grid", false, Halftone::kType2);
9312fd6cc2SKarsten Heimrich static const DitherCap gDitherType3("Stipple", false, Halftone::kType3);
94a7dde370SMichael Pfeiffer static const DitherCap gDitherFloydSteinberg("Floyd-Steinberg", false,
95a7dde370SMichael Pfeiffer 	Halftone::kTypeFloydSteinberg);
9612fd6cc2SKarsten Heimrich 
9712fd6cc2SKarsten Heimrich 
98f53abcbdSMichael Pfeiffer const BaseCap *gNups[] = {
9912fd6cc2SKarsten Heimrich 	&gNup1,
10012fd6cc2SKarsten Heimrich 	&gNup2,
10112fd6cc2SKarsten Heimrich 	&gNup4,
10212fd6cc2SKarsten Heimrich 	&gNup8,
10312fd6cc2SKarsten Heimrich 	&gNup9,
10412fd6cc2SKarsten Heimrich 	&gNup16,
10512fd6cc2SKarsten Heimrich 	&gNup25,
10612fd6cc2SKarsten Heimrich 	&gNup32,
10712fd6cc2SKarsten Heimrich 	&gNup36
10812fd6cc2SKarsten Heimrich };
10912fd6cc2SKarsten Heimrich 
110a7dde370SMichael Pfeiffer 
111f53abcbdSMichael Pfeiffer const BaseCap *gDitherTypes[] = {
11212fd6cc2SKarsten Heimrich 	&gDitherType1,
11312fd6cc2SKarsten Heimrich 	&gDitherType2,
11412fd6cc2SKarsten Heimrich 	&gDitherType3,
11512fd6cc2SKarsten Heimrich 	&gDitherFloydSteinberg
11612fd6cc2SKarsten Heimrich };
11712fd6cc2SKarsten Heimrich 
118a7dde370SMichael Pfeiffer 
119f14cab2dSMichael Pfeiffer static const char* kCategoryID = "id";
120f14cab2dSMichael Pfeiffer 
121f14cab2dSMichael Pfeiffer 
12212fd6cc2SKarsten Heimrich enum {
12312fd6cc2SKarsten Heimrich 	kMsgRangeAll = 'JSdl',
12412fd6cc2SKarsten Heimrich 	kMsgRangeSelection,
12512fd6cc2SKarsten Heimrich 	kMsgCancel,
12612fd6cc2SKarsten Heimrich 	kMsgOK,
12712fd6cc2SKarsten Heimrich 	kMsgQuality,
12812fd6cc2SKarsten Heimrich 	kMsgCollateChanged,
12912fd6cc2SKarsten Heimrich 	kMsgReverseChanged,
13012fd6cc2SKarsten Heimrich 	kMsgDuplexChanged,
131f14cab2dSMichael Pfeiffer 	kMsgIntSliderChanged,
132f14cab2dSMichael Pfeiffer 	kMsgDoubleSliderChanged,
133f53abcbdSMichael Pfeiffer 	kMsgNone = 0
13412fd6cc2SKarsten Heimrich };
13512fd6cc2SKarsten Heimrich 
136a7dde370SMichael Pfeiffer 
137f14cab2dSMichael Pfeiffer BString& operator<<(BString& text, double value)
138f14cab2dSMichael Pfeiffer {
139f14cab2dSMichael Pfeiffer 	text << (float)value;
140f14cab2dSMichael Pfeiffer 	return text;
141f14cab2dSMichael Pfeiffer }
142f14cab2dSMichael Pfeiffer 
14356c20e82SMichael Pfeiffer JobSetupView::JobSetupView(JobData* jobData, PrinterData* printerData,
14456c20e82SMichael Pfeiffer 	const PrinterCap *printerCap)
145a7dde370SMichael Pfeiffer 	:
146a7dde370SMichael Pfeiffer 	BView("jobSetup", B_WILL_DRAW),
147308f0e19SMichael Pfeiffer 	fCopies(NULL),
148308f0e19SMichael Pfeiffer 	fFromPage(NULL),
149308f0e19SMichael Pfeiffer 	fToPage(NULL),
15056c20e82SMichael Pfeiffer 	fJobData(jobData),
15156c20e82SMichael Pfeiffer 	fPrinterData(printerData),
15256c20e82SMichael Pfeiffer 	fPrinterCap(printerCap),
153308f0e19SMichael Pfeiffer 	fColorType(NULL),
154308f0e19SMichael Pfeiffer 	fDitherType(NULL),
155308f0e19SMichael Pfeiffer 	fGamma(NULL),
156308f0e19SMichael Pfeiffer 	fInkDensity(NULL),
157308f0e19SMichael Pfeiffer 	fHalftone(NULL),
158308f0e19SMichael Pfeiffer 	fAll(NULL),
159308f0e19SMichael Pfeiffer 	fCollate(NULL),
160308f0e19SMichael Pfeiffer 	fReverse(NULL),
161308f0e19SMichael Pfeiffer 	fPages(NULL),
162308f0e19SMichael Pfeiffer 	fPaperFeed(NULL),
163308f0e19SMichael Pfeiffer 	fDuplex(NULL),
164308f0e19SMichael Pfeiffer 	fNup(NULL),
165308f0e19SMichael Pfeiffer 	fAllPages(NULL),
166308f0e19SMichael Pfeiffer 	fOddNumberedPages(NULL),
167308f0e19SMichael Pfeiffer 	fEvenNumberedPages(NULL)
16812fd6cc2SKarsten Heimrich {
16912fd6cc2SKarsten Heimrich 	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
17012fd6cc2SKarsten Heimrich }
17112fd6cc2SKarsten Heimrich 
172a7dde370SMichael Pfeiffer 
17312fd6cc2SKarsten Heimrich BRadioButton*
1745a695bceSMichael Pfeiffer JobSetupView::CreatePageSelectionItem(const char* name, const char* label,
17512fd6cc2SKarsten Heimrich 	JobData::PageSelection pageSelection)
17612fd6cc2SKarsten Heimrich {
1775a695bceSMichael Pfeiffer 	BRadioButton* button = new BRadioButton(name, label, NULL);
17812fd6cc2SKarsten Heimrich 	if (fJobData->getPageSelection() == pageSelection) {
17912fd6cc2SKarsten Heimrich 		button->SetValue(B_CONTROL_ON);
18012fd6cc2SKarsten Heimrich 	}
18112fd6cc2SKarsten Heimrich 	return button;
18212fd6cc2SKarsten Heimrich }
18312fd6cc2SKarsten Heimrich 
184a7dde370SMichael Pfeiffer 
18512fd6cc2SKarsten Heimrich void
18612fd6cc2SKarsten Heimrich JobSetupView::AllowOnlyDigits(BTextView* textView, int maxDigits)
18712fd6cc2SKarsten Heimrich {
18812fd6cc2SKarsten Heimrich 	int num;
18912fd6cc2SKarsten Heimrich 	for (num = 0; num <= 255; num++) {
19012fd6cc2SKarsten Heimrich 		textView->DisallowChar(num);
19112fd6cc2SKarsten Heimrich 	}
19212fd6cc2SKarsten Heimrich 	for (num = 0; num <= 9; num++) {
19312fd6cc2SKarsten Heimrich 		textView->AllowChar('0' + num);
19412fd6cc2SKarsten Heimrich 	}
19512fd6cc2SKarsten Heimrich 	textView->SetMaxBytes(maxDigits);
19612fd6cc2SKarsten Heimrich }
19712fd6cc2SKarsten Heimrich 
198a7dde370SMichael Pfeiffer 
19912fd6cc2SKarsten Heimrich void
20012fd6cc2SKarsten Heimrich JobSetupView::AttachedToWindow()
20112fd6cc2SKarsten Heimrich {
2025a695bceSMichael Pfeiffer 	// quality
2035a695bceSMichael Pfeiffer 	BBox* qualityBox = new BBox("quality");
2045a695bceSMichael Pfeiffer 	qualityBox->SetLabel("Quality");
20512fd6cc2SKarsten Heimrich 
2065a695bceSMichael Pfeiffer 	// color
2075a695bceSMichael Pfeiffer 	fColorType = new BPopUpMenu("color");
20812fd6cc2SKarsten Heimrich 	fColorType->SetRadioMode(true);
209f53abcbdSMichael Pfeiffer 	FillCapabilityMenu(fColorType, kMsgQuality, PrinterCap::kColor,
210f53abcbdSMichael Pfeiffer 		fJobData->getColor());
2115a695bceSMichael Pfeiffer 	BMenuField* colorMenuField = new BMenuField("color", "Color:", fColorType);
21212fd6cc2SKarsten Heimrich 	fColorType->SetTargetForItems(this);
21312fd6cc2SKarsten Heimrich 
214308f0e19SMichael Pfeiffer 	if (IsHalftoneConfigurationNeeded())
215308f0e19SMichael Pfeiffer 		CreateHalftoneConfigurationUI();
21612fd6cc2SKarsten Heimrich 
2175a695bceSMichael Pfeiffer 	// page range
21812fd6cc2SKarsten Heimrich 
2195a695bceSMichael Pfeiffer 	BBox* pageRangeBox = new BBox("pageRange");
2205a695bceSMichael Pfeiffer 	pageRangeBox->SetLabel("Page Range");
22112fd6cc2SKarsten Heimrich 
2225a695bceSMichael Pfeiffer 	fAll = new BRadioButton("all", "Print all Pages", new BMessage(kMsgRangeAll));
22312fd6cc2SKarsten Heimrich 
2245a695bceSMichael Pfeiffer 	BRadioButton *range = new BRadioButton("selection", "Print selected Pages:",
2255a695bceSMichael Pfeiffer 		new BMessage(kMsgRangeSelection));
22612fd6cc2SKarsten Heimrich 
2275a695bceSMichael Pfeiffer 	fFromPage = new BTextControl("from", "From:", "", NULL);
22812fd6cc2SKarsten Heimrich 	fFromPage->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
22912fd6cc2SKarsten Heimrich 	AllowOnlyDigits(fFromPage->TextView(), 6);
23012fd6cc2SKarsten Heimrich 
2315a695bceSMichael Pfeiffer 	fToPage = new BTextControl("to", "To:", "", NULL);
23212fd6cc2SKarsten Heimrich 	fToPage->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
23312fd6cc2SKarsten Heimrich 	AllowOnlyDigits(fToPage->TextView(), 6);
23412fd6cc2SKarsten Heimrich 
23512fd6cc2SKarsten Heimrich 	int first_page = fJobData->getFirstPage();
23612fd6cc2SKarsten Heimrich 	int last_page  = fJobData->getLastPage();
23712fd6cc2SKarsten Heimrich 
23812fd6cc2SKarsten Heimrich 	if (first_page <= 1 && last_page <= 0) {
23912fd6cc2SKarsten Heimrich 		fAll->SetValue(B_CONTROL_ON);
24012fd6cc2SKarsten Heimrich 	} else {
2415a695bceSMichael Pfeiffer 		range->SetValue(B_CONTROL_ON);
24212fd6cc2SKarsten Heimrich 		if (first_page < 1)
24312fd6cc2SKarsten Heimrich 			first_page = 1;
24412fd6cc2SKarsten Heimrich 		if (first_page > last_page)
24512fd6cc2SKarsten Heimrich 			last_page = -1;
24612fd6cc2SKarsten Heimrich 
24712fd6cc2SKarsten Heimrich 		BString oss1;
24812fd6cc2SKarsten Heimrich 		oss1 << first_page;
24912fd6cc2SKarsten Heimrich 		fFromPage->SetText(oss1.String());
25012fd6cc2SKarsten Heimrich 
25112fd6cc2SKarsten Heimrich 		BString oss2;
25212fd6cc2SKarsten Heimrich 		oss2 << last_page;
25312fd6cc2SKarsten Heimrich 		fToPage->SetText(oss2.String());
25412fd6cc2SKarsten Heimrich 	}
25512fd6cc2SKarsten Heimrich 
25612fd6cc2SKarsten Heimrich 	fAll->SetTarget(this);
2575a695bceSMichael Pfeiffer 	range->SetTarget(this);
25812fd6cc2SKarsten Heimrich 
2595a695bceSMichael Pfeiffer 	// paper source
26012fd6cc2SKarsten Heimrich 	fPaperFeed = new BPopUpMenu("");
26112fd6cc2SKarsten Heimrich 	fPaperFeed->SetRadioMode(true);
262f53abcbdSMichael Pfeiffer 	FillCapabilityMenu(fPaperFeed, kMsgNone, PrinterCap::kPaperSource,
263f53abcbdSMichael Pfeiffer 		fJobData->getPaperSource());
2645a695bceSMichael Pfeiffer 	BMenuField* paperSourceMenufield = new BMenuField("paperSource",
2655a695bceSMichael Pfeiffer 		"Paper Source:", fPaperFeed);
26612fd6cc2SKarsten Heimrich 
2675a695bceSMichael Pfeiffer 	// Pages per sheet
26812fd6cc2SKarsten Heimrich 	fNup = new BPopUpMenu("");
26912fd6cc2SKarsten Heimrich 	fNup->SetRadioMode(true);
270f14cab2dSMichael Pfeiffer 	FillCapabilityMenu(fNup, kMsgNone, gNups,
271f14cab2dSMichael Pfeiffer 		sizeof(gNups) / sizeof(gNups[0]), (int)fJobData->getNup());
2725a695bceSMichael Pfeiffer 	BMenuField* pagesPerSheet = new BMenuField("pagesPerSheet",
2735a695bceSMichael Pfeiffer 		"Pages Per Sheet:", fNup);
27412fd6cc2SKarsten Heimrich 
2755a695bceSMichael Pfeiffer 	// duplex
27612fd6cc2SKarsten Heimrich 	if (fPrinterCap->isSupport(PrinterCap::kPrintStyle)) {
2775a695bceSMichael Pfeiffer 		fDuplex = new BCheckBox("duplex", "Duplex",
2785a695bceSMichael Pfeiffer 			new BMessage(kMsgDuplexChanged));
27912fd6cc2SKarsten Heimrich 		if (fJobData->getPrintStyle() != JobData::kSimplex) {
28012fd6cc2SKarsten Heimrich 			fDuplex->SetValue(B_CONTROL_ON);
28112fd6cc2SKarsten Heimrich 		}
28212fd6cc2SKarsten Heimrich 		fDuplex->SetTarget(this);
28312fd6cc2SKarsten Heimrich 	} else {
28412fd6cc2SKarsten Heimrich 		fDuplex = NULL;
28512fd6cc2SKarsten Heimrich 	}
28612fd6cc2SKarsten Heimrich 
2875a695bceSMichael Pfeiffer 	// copies
2885a695bceSMichael Pfeiffer 	fCopies = new BTextControl("copies", "Number of Copies:", "", NULL);
28912fd6cc2SKarsten Heimrich 	AllowOnlyDigits(fCopies->TextView(), 3);
29012fd6cc2SKarsten Heimrich 
2915a695bceSMichael Pfeiffer 	BString copies;
2925a695bceSMichael Pfeiffer 	copies << fJobData->getCopies();
2935a695bceSMichael Pfeiffer 	fCopies->SetText(copies.String());
29412fd6cc2SKarsten Heimrich 
2955a695bceSMichael Pfeiffer 	// collate
2965a695bceSMichael Pfeiffer 	fCollate = new BCheckBox("collate", "Collate",
2975a695bceSMichael Pfeiffer 		new BMessage(kMsgCollateChanged));
29812fd6cc2SKarsten Heimrich 	if (fJobData->getCollate()) {
29912fd6cc2SKarsten Heimrich 		fCollate->SetValue(B_CONTROL_ON);
30012fd6cc2SKarsten Heimrich 	}
30112fd6cc2SKarsten Heimrich 	fCollate->SetTarget(this);
30212fd6cc2SKarsten Heimrich 
3035a695bceSMichael Pfeiffer 	// reverse
3045a695bceSMichael Pfeiffer 	fReverse = new BCheckBox("reverse", "Reverse Order",
3055a695bceSMichael Pfeiffer 		new BMessage(kMsgReverseChanged));
30612fd6cc2SKarsten Heimrich 	if (fJobData->getReverse()) {
30712fd6cc2SKarsten Heimrich 		fReverse->SetValue(B_CONTROL_ON);
30812fd6cc2SKarsten Heimrich 	}
30912fd6cc2SKarsten Heimrich 	fReverse->SetTarget(this);
31012fd6cc2SKarsten Heimrich 
3115a695bceSMichael Pfeiffer 	// pages view
3125a695bceSMichael Pfeiffer 	// TODO make layout API compatible
3135a695bceSMichael Pfeiffer 	fPages = new PagesView(BRect(0, 0, 150, 40), "pages", B_FOLLOW_ALL,
3145a695bceSMichael Pfeiffer 		B_WILL_DRAW);
31512fd6cc2SKarsten Heimrich 	fPages->setCollate(fJobData->getCollate());
31612fd6cc2SKarsten Heimrich 	fPages->setReverse(fJobData->getReverse());
3175a695bceSMichael Pfeiffer 	fPages->SetExplicitMinSize(BSize(150, 40));
3185a695bceSMichael Pfeiffer 	fPages->SetExplicitMaxSize(BSize(150, 40));
31912fd6cc2SKarsten Heimrich 
3205a695bceSMichael Pfeiffer 	// page selection
3215a695bceSMichael Pfeiffer 	BBox* pageSelectionBox = new BBox("pageSelection");
32212fd6cc2SKarsten Heimrich 	pageSelectionBox->SetLabel("Page Selection");
32312fd6cc2SKarsten Heimrich 
3245a695bceSMichael Pfeiffer 	fAllPages = CreatePageSelectionItem("allPages", "All Pages",
3255a695bceSMichael Pfeiffer 		JobData::kAllPages);
3265a695bceSMichael Pfeiffer 	fOddNumberedPages = CreatePageSelectionItem("oddPages",
3275a695bceSMichael Pfeiffer 		"Odd-Numbered Pages", JobData::kOddNumberedPages);
3285a695bceSMichael Pfeiffer 	fEvenNumberedPages = CreatePageSelectionItem("evenPages",
3295a695bceSMichael Pfeiffer 		"Even-Numbered Pages", JobData::kEvenNumberedPages);
3305a695bceSMichael Pfeiffer 
331ae83b2f1SMichael Pfeiffer 	fPreview = new BCheckBox("preview", "Show preview before printing", NULL);
332ae83b2f1SMichael Pfeiffer 	if (fJobData->getShowPreview())
333ae83b2f1SMichael Pfeiffer 		fPreview->SetValue(B_CONTROL_ON);
334ae83b2f1SMichael Pfeiffer 
3355a695bceSMichael Pfeiffer 	// separator line
3365a695bceSMichael Pfeiffer 	BBox *separator = new BBox("separator");
3375a695bceSMichael Pfeiffer 	separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1));
3385a695bceSMichael Pfeiffer 
3395a695bceSMichael Pfeiffer 	// buttons
3405a695bceSMichael Pfeiffer 	BButton* cancel = new BButton("cancel", "Cancel",
3415a695bceSMichael Pfeiffer 		new BMessage(kMsgCancel));
3425a695bceSMichael Pfeiffer 	BButton* ok = new BButton("ok", "OK", new BMessage(kMsgOK));
3435a695bceSMichael Pfeiffer 	ok->MakeDefault(true);
3445a695bceSMichael Pfeiffer 
345308f0e19SMichael Pfeiffer 	if (IsHalftoneConfigurationNeeded()) {
3465a695bceSMichael Pfeiffer 		BGroupView* halftoneGroup = new BGroupView(B_VERTICAL, 0);
3475a695bceSMichael Pfeiffer 		BGroupLayout* halftoneLayout = halftoneGroup->GroupLayout();
3485a695bceSMichael Pfeiffer 		halftoneLayout->AddView(fHalftone);
349308f0e19SMichael Pfeiffer 		fHalftoneBox->AddChild(halftoneGroup);
350308f0e19SMichael Pfeiffer 	}
3515a695bceSMichael Pfeiffer 
3525a695bceSMichael Pfeiffer 	BGridView* qualityGrid = new BGridView();
3535a695bceSMichael Pfeiffer 	BGridLayout* qualityGridLayout = qualityGrid->GridLayout();
3545a695bceSMichael Pfeiffer 	qualityGridLayout->AddItem(colorMenuField->CreateLabelLayoutItem(), 0, 0);
3555a695bceSMichael Pfeiffer 	qualityGridLayout->AddItem(colorMenuField->CreateMenuBarLayoutItem(), 1, 0);
356308f0e19SMichael Pfeiffer 	if (IsHalftoneConfigurationNeeded()) {
357308f0e19SMichael Pfeiffer 		qualityGridLayout->AddItem(fDitherMenuField->CreateLabelLayoutItem(),
358308f0e19SMichael Pfeiffer 			0, 1);
359308f0e19SMichael Pfeiffer 		qualityGridLayout->AddItem(fDitherMenuField->CreateMenuBarLayoutItem(),
360308f0e19SMichael Pfeiffer 			1, 1);
3615a695bceSMichael Pfeiffer 		qualityGridLayout->AddView(fGamma, 0, 2, 2);
3625a695bceSMichael Pfeiffer 		qualityGridLayout->AddView(fInkDensity, 0, 3, 2);
363308f0e19SMichael Pfeiffer 		qualityGridLayout->AddView(fHalftoneBox, 0, 4, 2);
364de18d919SMichael Pfeiffer 	} else {
365de18d919SMichael Pfeiffer 		AddDriverSpecificSettings(qualityGridLayout, 1);
366308f0e19SMichael Pfeiffer 	}
3675a695bceSMichael Pfeiffer 	qualityGridLayout->SetSpacing(0, 0);
3685a695bceSMichael Pfeiffer 	qualityGridLayout->SetInsets(5, 5, 5, 5);
3695a695bceSMichael Pfeiffer 	qualityBox->AddChild(qualityGrid);
370f14cab2dSMichael Pfeiffer 	// TODO put qualityGrid in a scroll view
371f14cab2dSMichael Pfeiffer 	// the layout of the box surrounding the scroll view using the following
372f14cab2dSMichael Pfeiffer 	// code is not correct; the box still has the size of the qualityGird;
373f14cab2dSMichael Pfeiffer 	// and the scroll view is vertically centered inside the box!
374f14cab2dSMichael Pfeiffer 	//BScrollView* qualityScroller = new BScrollView("qualityScroller",
375f14cab2dSMichael Pfeiffer 	//	qualityGrid, 0, false, true);
376f14cab2dSMichael Pfeiffer 	//qualityScroller->SetExplicitMaxSize(BSize(500, 500));
377f14cab2dSMichael Pfeiffer 	//qualityBox->AddChild(qualityScroller);
3785a695bceSMichael Pfeiffer 
3795a695bceSMichael Pfeiffer 	BGridView* pageRangeGrid = new BGridView();
3805a695bceSMichael Pfeiffer 	BGridLayout* pageRangeLayout = pageRangeGrid->GridLayout();
3815a695bceSMichael Pfeiffer 	pageRangeLayout->AddItem(fFromPage->CreateLabelLayoutItem(), 0, 0);
3825a695bceSMichael Pfeiffer 	pageRangeLayout->AddItem(fFromPage->CreateTextViewLayoutItem(), 1, 0);
3835a695bceSMichael Pfeiffer 	pageRangeLayout->AddItem(fToPage->CreateLabelLayoutItem(), 0, 1);
3845a695bceSMichael Pfeiffer 	pageRangeLayout->AddItem(fToPage->CreateTextViewLayoutItem(), 1, 1);
3855a695bceSMichael Pfeiffer 	pageRangeLayout->SetInsets(0, 0, 0, 0);
3865a695bceSMichael Pfeiffer 	pageRangeLayout->SetSpacing(0, 0);
3875a695bceSMichael Pfeiffer 
3885a695bceSMichael Pfeiffer 	BGroupView* pageRangeGroup = new BGroupView(B_VERTICAL, 0);
3895a695bceSMichael Pfeiffer 	BGroupLayout* pageRangeGroupLayout = pageRangeGroup->GroupLayout();
3905a695bceSMichael Pfeiffer 	pageRangeGroupLayout->AddView(fAll);
3915a695bceSMichael Pfeiffer 	pageRangeGroupLayout->AddView(range);
3925a695bceSMichael Pfeiffer 	pageRangeGroupLayout->AddView(pageRangeGrid);
3935a695bceSMichael Pfeiffer 	pageRangeGroupLayout->SetInsets(5, 5, 5, 5);
3945a695bceSMichael Pfeiffer 	pageRangeBox->AddChild(pageRangeGroup);
3955a695bceSMichael Pfeiffer 
3965a695bceSMichael Pfeiffer 	BGridView* settings = new BGridView();
3975a695bceSMichael Pfeiffer 	BGridLayout* settingsLayout = settings->GridLayout();
3985a695bceSMichael Pfeiffer 	settingsLayout->AddItem(paperSourceMenufield->CreateLabelLayoutItem(), 0,
3995a695bceSMichael Pfeiffer 		0);
4005a695bceSMichael Pfeiffer 	settingsLayout->AddItem(paperSourceMenufield->CreateMenuBarLayoutItem(), 1,
4015a695bceSMichael Pfeiffer 		0);
4025a695bceSMichael Pfeiffer 	settingsLayout->AddItem(pagesPerSheet->CreateLabelLayoutItem(), 0, 1);
4035a695bceSMichael Pfeiffer 	settingsLayout->AddItem(pagesPerSheet->CreateMenuBarLayoutItem(), 1, 1);
4045a695bceSMichael Pfeiffer 	int row = 2;
4055a695bceSMichael Pfeiffer 	if (fDuplex != NULL) {
4065a695bceSMichael Pfeiffer 		settingsLayout->AddView(fDuplex, 0, row, 2);
4075a695bceSMichael Pfeiffer 		row ++;
4085a695bceSMichael Pfeiffer 	}
4095a695bceSMichael Pfeiffer 	settingsLayout->AddItem(fCopies->CreateLabelLayoutItem(), 0, row);
4105a695bceSMichael Pfeiffer 	settingsLayout->AddItem(fCopies->CreateTextViewLayoutItem(), 1, row);
4115a695bceSMichael Pfeiffer 	settingsLayout->SetSpacing(0, 0);
41212fd6cc2SKarsten Heimrich 
41312fd6cc2SKarsten Heimrich 
4145a695bceSMichael Pfeiffer 	BGroupView* pageSelectionGroup = new BGroupView(B_VERTICAL, 0);
4155a695bceSMichael Pfeiffer 	BGroupLayout* groupLayout = pageSelectionGroup->GroupLayout();
4165a695bceSMichael Pfeiffer 	groupLayout->AddView(fAllPages);
4175a695bceSMichael Pfeiffer 	groupLayout->AddView(fOddNumberedPages);
4185a695bceSMichael Pfeiffer 	groupLayout->AddView(fEvenNumberedPages);
4195a695bceSMichael Pfeiffer 	groupLayout->SetInsets(5, 5, 5, 5);
4205a695bceSMichael Pfeiffer 	pageSelectionBox->AddChild(pageSelectionGroup);
42112fd6cc2SKarsten Heimrich 
4225a695bceSMichael Pfeiffer 	SetLayout(new BGroupLayout(B_VERTICAL));
4235a695bceSMichael Pfeiffer 	AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
4245a695bceSMichael Pfeiffer 		.AddGroup(B_HORIZONTAL, 10, 1.0f)
4255a695bceSMichael Pfeiffer 			.AddGroup(B_VERTICAL, 10, 1.0f)
4265a695bceSMichael Pfeiffer 				.Add(qualityBox)
4275a695bceSMichael Pfeiffer 				.Add(pageRangeBox)
4285a695bceSMichael Pfeiffer 				.AddGlue()
4295a695bceSMichael Pfeiffer 			.End()
4305a695bceSMichael Pfeiffer 			.AddGroup(B_VERTICAL, 0, 1.0f)
4315a695bceSMichael Pfeiffer 				.Add(settings)
4325a695bceSMichael Pfeiffer 				.AddStrut(5)
4335a695bceSMichael Pfeiffer 				.Add(fCollate)
4345a695bceSMichael Pfeiffer 				.Add(fReverse)
4355a695bceSMichael Pfeiffer 				.Add(fPages)
4365a695bceSMichael Pfeiffer 				.AddStrut(5)
4375a695bceSMichael Pfeiffer 				.Add(pageSelectionBox)
4385a695bceSMichael Pfeiffer 				.AddGlue()
4395a695bceSMichael Pfeiffer 			.End()
4405a695bceSMichael Pfeiffer 		.End()
441ae83b2f1SMichael Pfeiffer 		.Add(fPreview)
4425a695bceSMichael Pfeiffer 		.AddGlue()
4435a695bceSMichael Pfeiffer 		.Add(separator)
4445a695bceSMichael Pfeiffer 		.AddGroup(B_HORIZONTAL, 10, 1.0f)
4455a695bceSMichael Pfeiffer 			.AddGlue()
4465a695bceSMichael Pfeiffer 			.Add(cancel)
4475a695bceSMichael Pfeiffer 			.Add(ok)
4485a695bceSMichael Pfeiffer 		.End()
4495a695bceSMichael Pfeiffer 		.SetInsets(0, 0, 0, 0)
4505a695bceSMichael Pfeiffer 	);
45112fd6cc2SKarsten Heimrich 
452308f0e19SMichael Pfeiffer 	UpdateHalftonePreview();
45312fd6cc2SKarsten Heimrich 
45412fd6cc2SKarsten Heimrich 	UpdateButtonEnabledState();
45512fd6cc2SKarsten Heimrich }
45612fd6cc2SKarsten Heimrich 
457a7dde370SMichael Pfeiffer 
458308f0e19SMichael Pfeiffer bool
459308f0e19SMichael Pfeiffer JobSetupView::IsHalftoneConfigurationNeeded()
460308f0e19SMichael Pfeiffer {
461308f0e19SMichael Pfeiffer 	return fPrinterCap->isSupport(PrinterCap::kHalftone);
462308f0e19SMichael Pfeiffer }
463308f0e19SMichael Pfeiffer 
464308f0e19SMichael Pfeiffer 
465308f0e19SMichael Pfeiffer void
466308f0e19SMichael Pfeiffer JobSetupView::CreateHalftoneConfigurationUI()
467308f0e19SMichael Pfeiffer {
468308f0e19SMichael Pfeiffer 	// dither type
469308f0e19SMichael Pfeiffer 	fDitherType = new BPopUpMenu("");
470308f0e19SMichael Pfeiffer 	fDitherType->SetRadioMode(true);
471308f0e19SMichael Pfeiffer 	FillCapabilityMenu(fDitherType, kMsgQuality, gDitherTypes,
472308f0e19SMichael Pfeiffer 		sizeof(gDitherTypes) / sizeof(gDitherTypes[0]),
473de18d919SMichael Pfeiffer 		(int)fJobData->getDitherType());
474308f0e19SMichael Pfeiffer 	fDitherMenuField = new BMenuField("dithering", "Dot Pattern:",
475308f0e19SMichael Pfeiffer 		fDitherType);
476308f0e19SMichael Pfeiffer 	fDitherType->SetTargetForItems(this);
477308f0e19SMichael Pfeiffer 
478308f0e19SMichael Pfeiffer 	// halftone preview view
479308f0e19SMichael Pfeiffer 	fHalftoneBox = new BBox("halftoneBox");
480308f0e19SMichael Pfeiffer 	fHalftoneBox->SetBorder(B_PLAIN_BORDER);
481308f0e19SMichael Pfeiffer 
482308f0e19SMichael Pfeiffer 	// TODO make layout compatible
483308f0e19SMichael Pfeiffer 	BSize size(240, 14 * 4);
484308f0e19SMichael Pfeiffer 	BRect rect(0, 0, size.width, size.height);
485308f0e19SMichael Pfeiffer 	fHalftone = new HalftoneView(rect, "halftone",
486308f0e19SMichael Pfeiffer 		B_FOLLOW_ALL, B_WILL_DRAW);
487308f0e19SMichael Pfeiffer 	fHalftone->SetExplicitMinSize(size);
488308f0e19SMichael Pfeiffer 	fHalftone->SetExplicitMaxSize(size);
489308f0e19SMichael Pfeiffer 
490308f0e19SMichael Pfeiffer 	// gamma
491308f0e19SMichael Pfeiffer 	fGamma = new JSDSlider("gamma", "Gamma", new BMessage(kMsgQuality),
492308f0e19SMichael Pfeiffer 		-300, 300);
493308f0e19SMichael Pfeiffer 
494308f0e19SMichael Pfeiffer 	fGamma->SetLimitLabels("Lighter", "Darker");
495308f0e19SMichael Pfeiffer 	fGamma->SetValue((int32)(100 * log(fJobData->getGamma()) / log(2.0)));
496308f0e19SMichael Pfeiffer 	fGamma->SetHashMarks(B_HASH_MARKS_BOTH);
497308f0e19SMichael Pfeiffer 	fGamma->SetHashMarkCount(7);
498308f0e19SMichael Pfeiffer 	fGamma->SetModificationMessage(new BMessage(kMsgQuality));
499308f0e19SMichael Pfeiffer 	fGamma->SetTarget(this);
500308f0e19SMichael Pfeiffer 
501308f0e19SMichael Pfeiffer 	// ink density
502308f0e19SMichael Pfeiffer 	fInkDensity = new JSDSlider("inkDensity", "Ink Usage",
503308f0e19SMichael Pfeiffer 		new BMessage(kMsgQuality), 0, 127);
504308f0e19SMichael Pfeiffer 
505308f0e19SMichael Pfeiffer 	fInkDensity->SetLimitLabels("Min", "Max");
506308f0e19SMichael Pfeiffer 	fInkDensity->SetValue((int32)fJobData->getInkDensity());
507308f0e19SMichael Pfeiffer 	fInkDensity->SetHashMarks(B_HASH_MARKS_BOTH);
508308f0e19SMichael Pfeiffer 	fInkDensity->SetHashMarkCount(10);
509308f0e19SMichael Pfeiffer 	fInkDensity->SetModificationMessage(new BMessage(kMsgQuality));
510308f0e19SMichael Pfeiffer 	fInkDensity->SetTarget(this);
511308f0e19SMichael Pfeiffer }
512308f0e19SMichael Pfeiffer 
513308f0e19SMichael Pfeiffer 
51412fd6cc2SKarsten Heimrich void
515de18d919SMichael Pfeiffer JobSetupView::AddDriverSpecificSettings(BGridLayout* gridLayout, int row)
516f53abcbdSMichael Pfeiffer {
517de18d919SMichael Pfeiffer 	if (!fPrinterCap->isSupport(PrinterCap::kDriverSpecificCapabilities))
518de18d919SMichael Pfeiffer 		return;
519de18d919SMichael Pfeiffer 
520de18d919SMichael Pfeiffer 	int count = fPrinterCap->countCap(PrinterCap::kDriverSpecificCapabilities);
521de18d919SMichael Pfeiffer 	const BaseCap** capabilities = fPrinterCap->enumCap(
522de18d919SMichael Pfeiffer 		PrinterCap::kDriverSpecificCapabilities);
523de18d919SMichael Pfeiffer 
524de18d919SMichael Pfeiffer 	for (int i = 0; i < count; i ++) {
525f14cab2dSMichael Pfeiffer 		const DriverSpecificCap* capability =
526f14cab2dSMichael Pfeiffer 			static_cast<const DriverSpecificCap*>(capabilities[i]);
527de18d919SMichael Pfeiffer 
528f14cab2dSMichael Pfeiffer 		switch (capability->fType) {
529f14cab2dSMichael Pfeiffer 			case DriverSpecificCap::kList:
530f14cab2dSMichael Pfeiffer 				AddPopUpMenu(capability, gridLayout, row);
531f14cab2dSMichael Pfeiffer 				break;
532f14cab2dSMichael Pfeiffer 			case DriverSpecificCap::kBoolean:
533f14cab2dSMichael Pfeiffer 				AddCheckBox(capability, gridLayout, row);
534f14cab2dSMichael Pfeiffer 				break;
535f14cab2dSMichael Pfeiffer 			case DriverSpecificCap::kIntRange:
536f14cab2dSMichael Pfeiffer 			case DriverSpecificCap::kIntDimension:
537f14cab2dSMichael Pfeiffer 				AddIntSlider(capability, gridLayout, row);
538f14cab2dSMichael Pfeiffer 				break;
539f14cab2dSMichael Pfeiffer 			case DriverSpecificCap::kDoubleRange:
540f14cab2dSMichael Pfeiffer 				AddDoubleSlider(capability, gridLayout, row);
541f14cab2dSMichael Pfeiffer 				break;
542f14cab2dSMichael Pfeiffer 
543f14cab2dSMichael Pfeiffer 		}
544f14cab2dSMichael Pfeiffer 	}
545f14cab2dSMichael Pfeiffer }
546f14cab2dSMichael Pfeiffer 
547f14cab2dSMichael Pfeiffer 
548f14cab2dSMichael Pfeiffer void
549f14cab2dSMichael Pfeiffer JobSetupView::AddPopUpMenu(const DriverSpecificCap* capability,
550f14cab2dSMichael Pfeiffer 	BGridLayout* gridLayout, int& row)
551f14cab2dSMichael Pfeiffer {
552de18d919SMichael Pfeiffer 	const char* label = capability->fLabel.c_str();
553de18d919SMichael Pfeiffer 	BPopUpMenu* popUpMenu = new BPopUpMenu(label);
554de18d919SMichael Pfeiffer 	popUpMenu->SetRadioMode(true);
555de18d919SMichael Pfeiffer 
556de18d919SMichael Pfeiffer 	PrinterCap::CapID category = static_cast<PrinterCap::CapID>(
557de18d919SMichael Pfeiffer 		capability->ID());
558de18d919SMichael Pfeiffer 
559de18d919SMichael Pfeiffer 	const BaseCap** categoryCapabilities = fPrinterCap->enumCap(category);
560de18d919SMichael Pfeiffer 
561de18d919SMichael Pfeiffer 	int categoryCount = fPrinterCap->countCap(category);
562de18d919SMichael Pfeiffer 
563de18d919SMichael Pfeiffer 	string value = GetDriverSpecificValue(category, capability->Key());
564de18d919SMichael Pfeiffer 	PrinterCap::KeyPredicate predicate(value.c_str());
565de18d919SMichael Pfeiffer 
566de18d919SMichael Pfeiffer 	FillCapabilityMenu(popUpMenu, kMsgNone, categoryCapabilities,
567de18d919SMichael Pfeiffer 		categoryCount, predicate);
568de18d919SMichael Pfeiffer 
569de18d919SMichael Pfeiffer 	BString menuLabel = label;
570de18d919SMichael Pfeiffer 	menuLabel << ":";
571de18d919SMichael Pfeiffer 	BMenuField* menuField = new BMenuField(label, menuLabel.String(),
572de18d919SMichael Pfeiffer 		popUpMenu);
573de18d919SMichael Pfeiffer 	popUpMenu->SetTargetForItems(this);
574de18d919SMichael Pfeiffer 
575de18d919SMichael Pfeiffer 	gridLayout->AddItem(menuField->CreateLabelLayoutItem(),
576de18d919SMichael Pfeiffer 		0, row);
577de18d919SMichael Pfeiffer 	gridLayout->AddItem(menuField->CreateMenuBarLayoutItem(),
578de18d919SMichael Pfeiffer 		1, row);
579de18d919SMichael Pfeiffer 	row ++;
580de18d919SMichael Pfeiffer 
581f14cab2dSMichael Pfeiffer 	fDriverSpecificPopUpMenus[category] = popUpMenu;
582de18d919SMichael Pfeiffer }
583f14cab2dSMichael Pfeiffer 
584f14cab2dSMichael Pfeiffer 
585f14cab2dSMichael Pfeiffer void
586f14cab2dSMichael Pfeiffer JobSetupView::AddCheckBox(const DriverSpecificCap* capability,
587f14cab2dSMichael Pfeiffer 	BGridLayout* gridLayout, int& row)
588f14cab2dSMichael Pfeiffer {
589f14cab2dSMichael Pfeiffer 	PrinterCap::CapID category = static_cast<PrinterCap::CapID>(
590f14cab2dSMichael Pfeiffer 		capability->ID());
591f14cab2dSMichael Pfeiffer 	const BooleanCap* booleanCap = fPrinterCap->findBooleanCap(category);
592f14cab2dSMichael Pfeiffer 	if (booleanCap == NULL) {
593f14cab2dSMichael Pfeiffer 		fprintf(stderr, "Internal error: BooleanCap for '%s' not found!\n",
594f14cab2dSMichael Pfeiffer 			capability->Label());
595f14cab2dSMichael Pfeiffer 		return;
596f14cab2dSMichael Pfeiffer 	}
597f14cab2dSMichael Pfeiffer 
598f14cab2dSMichael Pfeiffer 	const char* key = capability->Key();
599f14cab2dSMichael Pfeiffer 	BString name;
600f14cab2dSMichael Pfeiffer 	name << "pds_" << key;
601f14cab2dSMichael Pfeiffer 	BCheckBox* checkBox = new BCheckBox(name.String(), capability->Label(),
602f14cab2dSMichael Pfeiffer 		NULL);
603f14cab2dSMichael Pfeiffer 
604f14cab2dSMichael Pfeiffer 	bool value = booleanCap->DefaultValue();
605f14cab2dSMichael Pfeiffer 	if (fJobData->Settings().HasBoolean(key))
606f14cab2dSMichael Pfeiffer 		value = fJobData->Settings().GetBoolean(key);
607f14cab2dSMichael Pfeiffer 	if (value)
608f14cab2dSMichael Pfeiffer 		checkBox->SetValue(B_CONTROL_ON);
609f14cab2dSMichael Pfeiffer 
610f14cab2dSMichael Pfeiffer 	gridLayout->AddView(checkBox, 0, row, 2);
611f14cab2dSMichael Pfeiffer 	row ++;
612f14cab2dSMichael Pfeiffer 
613f14cab2dSMichael Pfeiffer 	fDriverSpecificCheckBoxes[capability->Key()] = checkBox;
614f14cab2dSMichael Pfeiffer }
615f14cab2dSMichael Pfeiffer 
616f14cab2dSMichael Pfeiffer 
617f14cab2dSMichael Pfeiffer void
618f14cab2dSMichael Pfeiffer JobSetupView::AddIntSlider(const DriverSpecificCap* capability,
619f14cab2dSMichael Pfeiffer 	BGridLayout* gridLayout, int& row)
620f14cab2dSMichael Pfeiffer {
621f14cab2dSMichael Pfeiffer 	PrinterCap::CapID category = static_cast<PrinterCap::CapID>(
622f14cab2dSMichael Pfeiffer 		capability->ID());
623f14cab2dSMichael Pfeiffer 	const IntRangeCap* range = fPrinterCap->findIntRangeCap(category);
624f14cab2dSMichael Pfeiffer 	if (range == NULL) {
625f14cab2dSMichael Pfeiffer 		fprintf(stderr, "Internal error: IntRangeCap for '%s' not found!\n",
626f14cab2dSMichael Pfeiffer 			capability->Label());
627f14cab2dSMichael Pfeiffer 		return;
628f14cab2dSMichael Pfeiffer 	}
629f14cab2dSMichael Pfeiffer 
630f14cab2dSMichael Pfeiffer 	const char* label = capability->Label();
631f14cab2dSMichael Pfeiffer 	const char* key = capability->Key();
632f14cab2dSMichael Pfeiffer 	BString name;
633f14cab2dSMichael Pfeiffer 	name << "pds_" << key;
634f14cab2dSMichael Pfeiffer 	BMessage* message = new BMessage(kMsgIntSliderChanged);
635f14cab2dSMichael Pfeiffer 	message->AddInt32(kCategoryID, category);
636f14cab2dSMichael Pfeiffer 	BSlider* slider = new BSlider(name.String(), label,
637f14cab2dSMichael Pfeiffer 		message, 0, 1000, B_HORIZONTAL);
638f14cab2dSMichael Pfeiffer 	slider->SetModificationMessage(new BMessage(*message));
639f14cab2dSMichael Pfeiffer 	slider->SetTarget(this);
640f14cab2dSMichael Pfeiffer 
641f14cab2dSMichael Pfeiffer 	int32 value = range->DefaultValue();
642f14cab2dSMichael Pfeiffer 	if (fJobData->Settings().HasInt(key))
643f14cab2dSMichael Pfeiffer 		value = fJobData->Settings().GetInt(key);
644f14cab2dSMichael Pfeiffer 	float position = (value - range->Lower()) /
645f14cab2dSMichael Pfeiffer 		(range->Upper() - range->Lower());
646f14cab2dSMichael Pfeiffer 	slider->SetPosition(position);
647f14cab2dSMichael Pfeiffer 
648f14cab2dSMichael Pfeiffer 	gridLayout->AddView(slider, 0, row, 2);
649f14cab2dSMichael Pfeiffer 	row ++;
650f14cab2dSMichael Pfeiffer 
651f14cab2dSMichael Pfeiffer 	IntRange intRange(label, key, range, slider);
652f14cab2dSMichael Pfeiffer 	fDriverSpecificIntSliders[category] = intRange;
653f14cab2dSMichael Pfeiffer 	intRange.UpdateLabel();
654f14cab2dSMichael Pfeiffer }
655f14cab2dSMichael Pfeiffer 
656f14cab2dSMichael Pfeiffer 
657f14cab2dSMichael Pfeiffer void
658f14cab2dSMichael Pfeiffer JobSetupView::AddDoubleSlider(const DriverSpecificCap* capability,
659f14cab2dSMichael Pfeiffer 	BGridLayout* gridLayout, int& row)
660f14cab2dSMichael Pfeiffer {
661f14cab2dSMichael Pfeiffer 	PrinterCap::CapID category = static_cast<PrinterCap::CapID>(
662f14cab2dSMichael Pfeiffer 		capability->ID());
663f14cab2dSMichael Pfeiffer 	const DoubleRangeCap* range = fPrinterCap->findDoubleRangeCap(category);
664f14cab2dSMichael Pfeiffer 	if (range == NULL) {
665f14cab2dSMichael Pfeiffer 		fprintf(stderr, "Internal error: DoubleRangeCap for '%s' not found!\n",
666f14cab2dSMichael Pfeiffer 			capability->Label());
667f14cab2dSMichael Pfeiffer 		return;
668f14cab2dSMichael Pfeiffer 	}
669f14cab2dSMichael Pfeiffer 
670f14cab2dSMichael Pfeiffer 	const char* label = capability->Label();
671f14cab2dSMichael Pfeiffer 	const char* key = capability->Key();
672f14cab2dSMichael Pfeiffer 	BString name;
673f14cab2dSMichael Pfeiffer 	name << "pds_" << key;
674f14cab2dSMichael Pfeiffer 	BMessage* message = new BMessage(kMsgDoubleSliderChanged);
675f14cab2dSMichael Pfeiffer 	message->AddInt32(kCategoryID, category);
676f14cab2dSMichael Pfeiffer 	BSlider* slider = new BSlider(name.String(), label,
677f14cab2dSMichael Pfeiffer 		message, 0, 1000, B_HORIZONTAL);
678f14cab2dSMichael Pfeiffer 	slider->SetModificationMessage(new BMessage(*message));
679f14cab2dSMichael Pfeiffer 	slider->SetTarget(this);
680f14cab2dSMichael Pfeiffer 
681f14cab2dSMichael Pfeiffer 	double value = range->DefaultValue();
682f14cab2dSMichael Pfeiffer 	if (fJobData->Settings().HasDouble(key))
683f14cab2dSMichael Pfeiffer 		value = fJobData->Settings().GetDouble(key);
684f14cab2dSMichael Pfeiffer 	float position = static_cast<float>((value - range->Lower()) /
685f14cab2dSMichael Pfeiffer 		(range->Upper() - range->Lower()));
686f14cab2dSMichael Pfeiffer 	slider->SetPosition(position);
687f14cab2dSMichael Pfeiffer 
688f14cab2dSMichael Pfeiffer 	gridLayout->AddView(slider, 0, row, 2);
689f14cab2dSMichael Pfeiffer 	row ++;
690f14cab2dSMichael Pfeiffer 
691f14cab2dSMichael Pfeiffer 	DoubleRange doubleRange(label, key, range, slider);
692f14cab2dSMichael Pfeiffer 	fDriverSpecificDoubleSliders[category] = doubleRange;
693f14cab2dSMichael Pfeiffer 	doubleRange.UpdateLabel();
694f53abcbdSMichael Pfeiffer }
695f53abcbdSMichael Pfeiffer 
696de18d919SMichael Pfeiffer 
697de18d919SMichael Pfeiffer string
698de18d919SMichael Pfeiffer JobSetupView::GetDriverSpecificValue(PrinterCap::CapID category,
699de18d919SMichael Pfeiffer 	const char* key)
700de18d919SMichael Pfeiffer {
701f14cab2dSMichael Pfeiffer 	if (fJobData->Settings().HasString(key))
702f14cab2dSMichael Pfeiffer 		return fJobData->Settings().GetString(key);
703de18d919SMichael Pfeiffer 
704f14cab2dSMichael Pfeiffer 	const EnumCap* defaultCapability = fPrinterCap->getDefaultCap(category);
705de18d919SMichael Pfeiffer 	return defaultCapability->fKey;
706de18d919SMichael Pfeiffer }
707de18d919SMichael Pfeiffer 
708de18d919SMichael Pfeiffer 
709de18d919SMichael Pfeiffer template<typename Predicate>
710f53abcbdSMichael Pfeiffer void
711f53abcbdSMichael Pfeiffer JobSetupView::FillCapabilityMenu(BPopUpMenu* menu, uint32 message,
712de18d919SMichael Pfeiffer 	const BaseCap** capabilities, int count, Predicate& predicate)
713f53abcbdSMichael Pfeiffer {
714f53abcbdSMichael Pfeiffer 	bool marked = false;
715f53abcbdSMichael Pfeiffer 
716f53abcbdSMichael Pfeiffer 	BMenuItem* firstItem = NULL;
717f53abcbdSMichael Pfeiffer 	BMenuItem* defaultItem = NULL;
718f53abcbdSMichael Pfeiffer 	BMenuItem* item = NULL;
719f53abcbdSMichael Pfeiffer 	while (count--) {
720f14cab2dSMichael Pfeiffer 		const EnumCap* capability = dynamic_cast<const EnumCap*>(*capabilities);
721f53abcbdSMichael Pfeiffer 		if (message != kMsgNone)
722f53abcbdSMichael Pfeiffer 			item = new BMenuItem(capability->fLabel.c_str(),
723308f0e19SMichael Pfeiffer 				new BMessage(message));
724f53abcbdSMichael Pfeiffer 		else
725f53abcbdSMichael Pfeiffer 			item = new BMenuItem(capability->fLabel.c_str(), NULL);
726f53abcbdSMichael Pfeiffer 
727f53abcbdSMichael Pfeiffer 		menu->AddItem(item);
728f53abcbdSMichael Pfeiffer 
729f53abcbdSMichael Pfeiffer 		if (firstItem == NULL)
730f53abcbdSMichael Pfeiffer 			firstItem = item;
731f53abcbdSMichael Pfeiffer 
732f53abcbdSMichael Pfeiffer 		if (capability->fIsDefault)
733f53abcbdSMichael Pfeiffer 			defaultItem = item;
734f53abcbdSMichael Pfeiffer 
735f53abcbdSMichael Pfeiffer 
736de18d919SMichael Pfeiffer 		if (predicate(capability)) {
737f53abcbdSMichael Pfeiffer 			item->SetMarked(true);
738f53abcbdSMichael Pfeiffer 			marked = true;
739f53abcbdSMichael Pfeiffer 		}
740f53abcbdSMichael Pfeiffer 
741f53abcbdSMichael Pfeiffer 		capabilities++;
742f53abcbdSMichael Pfeiffer 	}
743f53abcbdSMichael Pfeiffer 
744f53abcbdSMichael Pfeiffer 	if (marked)
745f53abcbdSMichael Pfeiffer 		return;
746f53abcbdSMichael Pfeiffer 
747f53abcbdSMichael Pfeiffer 	if (defaultItem != NULL)
748f53abcbdSMichael Pfeiffer 		defaultItem->SetMarked(true);
749f53abcbdSMichael Pfeiffer 	else if (firstItem != NULL)
750f53abcbdSMichael Pfeiffer 		firstItem->SetMarked(true);
751f53abcbdSMichael Pfeiffer }
752f53abcbdSMichael Pfeiffer 
753f53abcbdSMichael Pfeiffer 
754de18d919SMichael Pfeiffer void
755de18d919SMichael Pfeiffer JobSetupView::FillCapabilityMenu(BPopUpMenu* menu, uint32 message,
756de18d919SMichael Pfeiffer 	PrinterCap::CapID category, int id)
757de18d919SMichael Pfeiffer {
758de18d919SMichael Pfeiffer 	PrinterCap::IDPredicate predicate(id);
759de18d919SMichael Pfeiffer 	int count = fPrinterCap->countCap(category);
760de18d919SMichael Pfeiffer 	const BaseCap **capabilities = fPrinterCap->enumCap(category);
761de18d919SMichael Pfeiffer 	FillCapabilityMenu(menu, message, capabilities, count, predicate);
762de18d919SMichael Pfeiffer }
763de18d919SMichael Pfeiffer 
764de18d919SMichael Pfeiffer 
765de18d919SMichael Pfeiffer void
766de18d919SMichael Pfeiffer JobSetupView::FillCapabilityMenu(BPopUpMenu* menu, uint32 message,
767de18d919SMichael Pfeiffer 	const BaseCap** capabilities, int count, int id)
768de18d919SMichael Pfeiffer {
769de18d919SMichael Pfeiffer 	PrinterCap::IDPredicate predicate(id);
770de18d919SMichael Pfeiffer 	FillCapabilityMenu(menu, message, capabilities, count, predicate);
771de18d919SMichael Pfeiffer }
772de18d919SMichael Pfeiffer 
773de18d919SMichael Pfeiffer 
774f53abcbdSMichael Pfeiffer int
775f53abcbdSMichael Pfeiffer JobSetupView::GetID(const BaseCap** capabilities, int count, const char* label,
776f53abcbdSMichael Pfeiffer 	int defaultValue)
777f53abcbdSMichael Pfeiffer {
778f53abcbdSMichael Pfeiffer 	while (count--) {
779f14cab2dSMichael Pfeiffer 		const EnumCap* capability =
780f14cab2dSMichael Pfeiffer 			dynamic_cast<const EnumCap*>(*capabilities);
781f14cab2dSMichael Pfeiffer 		if (capability == NULL)
782f14cab2dSMichael Pfeiffer 			break;
783f14cab2dSMichael Pfeiffer 
784f53abcbdSMichael Pfeiffer 		if (capability->fLabel == label)
785f53abcbdSMichael Pfeiffer 			return capability->ID();
786f53abcbdSMichael Pfeiffer 	}
787f53abcbdSMichael Pfeiffer 	return defaultValue;
788f53abcbdSMichael Pfeiffer }
789f53abcbdSMichael Pfeiffer 
790f53abcbdSMichael Pfeiffer 
791f53abcbdSMichael Pfeiffer void
79212fd6cc2SKarsten Heimrich JobSetupView::UpdateButtonEnabledState()
79312fd6cc2SKarsten Heimrich {
79412fd6cc2SKarsten Heimrich 	bool pageRangeEnabled = fAll->Value() != B_CONTROL_ON;
79512fd6cc2SKarsten Heimrich 	fFromPage->SetEnabled(pageRangeEnabled);
79612fd6cc2SKarsten Heimrich 	fToPage->SetEnabled(pageRangeEnabled);
79712fd6cc2SKarsten Heimrich 
79812fd6cc2SKarsten Heimrich 	bool pageSelectionEnabled = fDuplex == NULL ||
79912fd6cc2SKarsten Heimrich 		fDuplex->Value() != B_CONTROL_ON;
80012fd6cc2SKarsten Heimrich 	fAllPages->SetEnabled(pageSelectionEnabled);
80112fd6cc2SKarsten Heimrich 	fOddNumberedPages->SetEnabled(pageSelectionEnabled);
80212fd6cc2SKarsten Heimrich 	fEvenNumberedPages->SetEnabled(pageSelectionEnabled);
80312fd6cc2SKarsten Heimrich }
80412fd6cc2SKarsten Heimrich 
805a7dde370SMichael Pfeiffer 
80612fd6cc2SKarsten Heimrich void
80756c20e82SMichael Pfeiffer JobSetupView::MessageReceived(BMessage* message)
80812fd6cc2SKarsten Heimrich {
80956c20e82SMichael Pfeiffer 	switch (message->what) {
81012fd6cc2SKarsten Heimrich 	case kMsgRangeAll:
81112fd6cc2SKarsten Heimrich 	case kMsgRangeSelection:
81212fd6cc2SKarsten Heimrich 	case kMsgDuplexChanged:
81312fd6cc2SKarsten Heimrich 		UpdateButtonEnabledState();
81412fd6cc2SKarsten Heimrich 		break;
81512fd6cc2SKarsten Heimrich 
81612fd6cc2SKarsten Heimrich 	case kMsgQuality:
817308f0e19SMichael Pfeiffer 		UpdateHalftonePreview();
81812fd6cc2SKarsten Heimrich 		break;
81912fd6cc2SKarsten Heimrich 
82012fd6cc2SKarsten Heimrich 	case kMsgCollateChanged:
82112fd6cc2SKarsten Heimrich 		fPages->setCollate(fCollate->Value() == B_CONTROL_ON);
82212fd6cc2SKarsten Heimrich 		break;
82312fd6cc2SKarsten Heimrich 
82412fd6cc2SKarsten Heimrich 	case kMsgReverseChanged:
82512fd6cc2SKarsten Heimrich 		fPages->setReverse(fReverse->Value() == B_CONTROL_ON);
82612fd6cc2SKarsten Heimrich 		break;
827f14cab2dSMichael Pfeiffer 
828f14cab2dSMichael Pfeiffer 	case kMsgIntSliderChanged:
829f14cab2dSMichael Pfeiffer 		UpdateIntSlider(message);
830f14cab2dSMichael Pfeiffer 		break;
831f14cab2dSMichael Pfeiffer 
832f14cab2dSMichael Pfeiffer 	case kMsgDoubleSliderChanged:
833f14cab2dSMichael Pfeiffer 		UpdateDoubleSlider(message);
834f14cab2dSMichael Pfeiffer 		break;
83512fd6cc2SKarsten Heimrich 	}
83612fd6cc2SKarsten Heimrich }
83712fd6cc2SKarsten Heimrich 
838a7dde370SMichael Pfeiffer 
839308f0e19SMichael Pfeiffer void
840308f0e19SMichael Pfeiffer JobSetupView::UpdateHalftonePreview()
841308f0e19SMichael Pfeiffer {
842308f0e19SMichael Pfeiffer 	if (!IsHalftoneConfigurationNeeded())
843308f0e19SMichael Pfeiffer 		return;
844308f0e19SMichael Pfeiffer 
845308f0e19SMichael Pfeiffer 	fHalftone->preview(Gamma(), InkDensity(), DitherType(),
846308f0e19SMichael Pfeiffer 		Color() != JobData::kMonochrome);
847308f0e19SMichael Pfeiffer }
848308f0e19SMichael Pfeiffer 
849308f0e19SMichael Pfeiffer 
850f14cab2dSMichael Pfeiffer void
851f14cab2dSMichael Pfeiffer JobSetupView::UpdateIntSlider(BMessage* message)
852f14cab2dSMichael Pfeiffer {
853f14cab2dSMichael Pfeiffer 	int32 id;
854f14cab2dSMichael Pfeiffer 	if (message->FindInt32(kCategoryID, &id) != B_OK)
855f14cab2dSMichael Pfeiffer 		return;
856f14cab2dSMichael Pfeiffer 	PrinterCap::CapID capID = static_cast<PrinterCap::CapID>(id);
857f14cab2dSMichael Pfeiffer 	fDriverSpecificIntSliders[capID].UpdateLabel();
858f14cab2dSMichael Pfeiffer }
859f14cab2dSMichael Pfeiffer 
860f14cab2dSMichael Pfeiffer 
861f14cab2dSMichael Pfeiffer void
862f14cab2dSMichael Pfeiffer JobSetupView::UpdateDoubleSlider(BMessage* message)
863f14cab2dSMichael Pfeiffer {
864f14cab2dSMichael Pfeiffer 	int32 id;
865f14cab2dSMichael Pfeiffer 	if (message->FindInt32(kCategoryID, &id) != B_OK)
866f14cab2dSMichael Pfeiffer 		return;
867f14cab2dSMichael Pfeiffer 	PrinterCap::CapID capID = static_cast<PrinterCap::CapID>(id);
868f14cab2dSMichael Pfeiffer 	fDriverSpecificDoubleSliders[capID].UpdateLabel();
869f14cab2dSMichael Pfeiffer }
870f14cab2dSMichael Pfeiffer 
871f14cab2dSMichael Pfeiffer 
87212fd6cc2SKarsten Heimrich JobData::Color
873f53abcbdSMichael Pfeiffer JobSetupView::Color()
87412fd6cc2SKarsten Heimrich {
875f53abcbdSMichael Pfeiffer 	const char *label = fColorType->FindMarked()->Label();
876f53abcbdSMichael Pfeiffer 	const BaseCap* capability = fPrinterCap->findCap(PrinterCap::kColor, label);
877f53abcbdSMichael Pfeiffer 	if (capability == NULL)
87812fd6cc2SKarsten Heimrich 		return JobData::kMonochrome;
879f53abcbdSMichael Pfeiffer 
880f53abcbdSMichael Pfeiffer 	const ColorCap* colorCap = static_cast<const ColorCap*>(capability);
881f53abcbdSMichael Pfeiffer 	return colorCap->fColor;
88212fd6cc2SKarsten Heimrich }
88312fd6cc2SKarsten Heimrich 
884a7dde370SMichael Pfeiffer 
88512fd6cc2SKarsten Heimrich Halftone::DitherType
886f53abcbdSMichael Pfeiffer JobSetupView::DitherType()
88712fd6cc2SKarsten Heimrich {
888f53abcbdSMichael Pfeiffer 	const char *label = fDitherType->FindMarked()->Label();
889f53abcbdSMichael Pfeiffer 	int id = GetID(gDitherTypes, sizeof(gDitherTypes) / sizeof(gDitherTypes[0]),
890f53abcbdSMichael Pfeiffer 		label, Halftone::kTypeFloydSteinberg);
891f53abcbdSMichael Pfeiffer 	return static_cast<Halftone::DitherType>(id);
89212fd6cc2SKarsten Heimrich }
89312fd6cc2SKarsten Heimrich 
89412fd6cc2SKarsten Heimrich float
895f53abcbdSMichael Pfeiffer JobSetupView::Gamma()
89612fd6cc2SKarsten Heimrich {
89712fd6cc2SKarsten Heimrich 	const float value = (float)fGamma->Value();
89812fd6cc2SKarsten Heimrich 	return pow(2.0, value / 100.0);
89912fd6cc2SKarsten Heimrich }
90012fd6cc2SKarsten Heimrich 
901a7dde370SMichael Pfeiffer 
90212fd6cc2SKarsten Heimrich float
903f53abcbdSMichael Pfeiffer JobSetupView::InkDensity()
90412fd6cc2SKarsten Heimrich {
90512fd6cc2SKarsten Heimrich 	const float value = (float)(127 - fInkDensity->Value());
90612fd6cc2SKarsten Heimrich 	return value;
90712fd6cc2SKarsten Heimrich }
90812fd6cc2SKarsten Heimrich 
909a7dde370SMichael Pfeiffer 
910f53abcbdSMichael Pfeiffer JobData::PaperSource
911f53abcbdSMichael Pfeiffer JobSetupView::PaperSource()
912f53abcbdSMichael Pfeiffer {
913f53abcbdSMichael Pfeiffer 	const char *label = fPaperFeed->FindMarked()->Label();
914f53abcbdSMichael Pfeiffer 	const BaseCap* capability = fPrinterCap->findCap(PrinterCap::kPaperSource,
915f53abcbdSMichael Pfeiffer 		label);
916f53abcbdSMichael Pfeiffer 
917f53abcbdSMichael Pfeiffer 	if (capability == NULL)
918f53abcbdSMichael Pfeiffer 		capability = fPrinterCap->getDefaultCap(PrinterCap::kPaperSource);
919f53abcbdSMichael Pfeiffer 	return static_cast<const PaperSourceCap*>(capability)->fPaperSource;
920f53abcbdSMichael Pfeiffer 
921f53abcbdSMichael Pfeiffer }
922f53abcbdSMichael Pfeiffer 
92312fd6cc2SKarsten Heimrich bool
924ae83b2f1SMichael Pfeiffer JobSetupView::UpdateJobData()
92512fd6cc2SKarsten Heimrich {
926ae83b2f1SMichael Pfeiffer 	fJobData->setShowPreview(fPreview->Value() == B_CONTROL_ON);
927f53abcbdSMichael Pfeiffer 	fJobData->setColor(Color());
928308f0e19SMichael Pfeiffer 	if (IsHalftoneConfigurationNeeded()) {
929f53abcbdSMichael Pfeiffer 		fJobData->setGamma(Gamma());
930f53abcbdSMichael Pfeiffer 		fJobData->setInkDensity(InkDensity());
931f53abcbdSMichael Pfeiffer 		fJobData->setDitherType(DitherType());
932308f0e19SMichael Pfeiffer 	}
93312fd6cc2SKarsten Heimrich 
93412fd6cc2SKarsten Heimrich 	int first_page;
93512fd6cc2SKarsten Heimrich 	int last_page;
93612fd6cc2SKarsten Heimrich 
93712fd6cc2SKarsten Heimrich 	if (B_CONTROL_ON == fAll->Value()) {
93812fd6cc2SKarsten Heimrich 		first_page = 1;
93912fd6cc2SKarsten Heimrich 		last_page  = -1;
94012fd6cc2SKarsten Heimrich 	} else {
94112fd6cc2SKarsten Heimrich 		first_page = atoi(fFromPage->Text());
94212fd6cc2SKarsten Heimrich 		last_page  = atoi(fToPage->Text());
94312fd6cc2SKarsten Heimrich 	}
94412fd6cc2SKarsten Heimrich 
94512fd6cc2SKarsten Heimrich 	fJobData->setFirstPage(first_page);
94612fd6cc2SKarsten Heimrich 	fJobData->setLastPage(last_page);
94712fd6cc2SKarsten Heimrich 
948f53abcbdSMichael Pfeiffer 	fJobData->setPaperSource(PaperSource());
94912fd6cc2SKarsten Heimrich 
950f53abcbdSMichael Pfeiffer 	fJobData->setNup(GetID(gNups, sizeof(gNups) / sizeof(gNups[0]),
951f53abcbdSMichael Pfeiffer 		fNup->FindMarked()->Label(), 1));
95212fd6cc2SKarsten Heimrich 
95312fd6cc2SKarsten Heimrich 	if (fPrinterCap->isSupport(PrinterCap::kPrintStyle)) {
954f53abcbdSMichael Pfeiffer 		fJobData->setPrintStyle((B_CONTROL_ON == fDuplex->Value())
955f53abcbdSMichael Pfeiffer 			? JobData::kDuplex : JobData::kSimplex);
95612fd6cc2SKarsten Heimrich 	}
95712fd6cc2SKarsten Heimrich 
95812fd6cc2SKarsten Heimrich 	fJobData->setCopies(atoi(fCopies->Text()));
95912fd6cc2SKarsten Heimrich 
96056c20e82SMichael Pfeiffer 	fJobData->setCollate(B_CONTROL_ON == fCollate->Value());
96156c20e82SMichael Pfeiffer 	fJobData->setReverse(B_CONTROL_ON == fReverse->Value());
96212fd6cc2SKarsten Heimrich 
96312fd6cc2SKarsten Heimrich 	JobData::PageSelection pageSelection = JobData::kAllPages;
96412fd6cc2SKarsten Heimrich 	if (fOddNumberedPages->Value() == B_CONTROL_ON)
96512fd6cc2SKarsten Heimrich 		pageSelection = JobData::kOddNumberedPages;
96612fd6cc2SKarsten Heimrich 	if (fEvenNumberedPages->Value() == B_CONTROL_ON)
96712fd6cc2SKarsten Heimrich 		pageSelection = JobData::kEvenNumberedPages;
96812fd6cc2SKarsten Heimrich 	fJobData->setPageSelection(pageSelection);
96912fd6cc2SKarsten Heimrich 
970f14cab2dSMichael Pfeiffer 	{
971de18d919SMichael Pfeiffer 		std::map<PrinterCap::CapID, BPopUpMenu*>::iterator it =
972f14cab2dSMichael Pfeiffer 			fDriverSpecificPopUpMenus.begin();
973f14cab2dSMichael Pfeiffer 		for(; it != fDriverSpecificPopUpMenus.end(); it++) {
974de18d919SMichael Pfeiffer 			PrinterCap::CapID category = it->first;
975de18d919SMichael Pfeiffer 			BPopUpMenu* popUpMenu = it->second;
976de18d919SMichael Pfeiffer 			const char* key = fPrinterCap->findCap(
977de18d919SMichael Pfeiffer 				PrinterCap::kDriverSpecificCapabilities, (int)category)->Key();
978de18d919SMichael Pfeiffer 			const char* label = popUpMenu->FindMarked()->Label();
979f14cab2dSMichael Pfeiffer 			const char* value = static_cast<const EnumCap*>(fPrinterCap->
980f14cab2dSMichael Pfeiffer 				findCap(category, label))->Key();
981f14cab2dSMichael Pfeiffer 			fJobData->Settings().SetString(key, value);
982f14cab2dSMichael Pfeiffer 		}
983f14cab2dSMichael Pfeiffer 	}
984f14cab2dSMichael Pfeiffer 
985f14cab2dSMichael Pfeiffer 	{
986f14cab2dSMichael Pfeiffer 		std::map<string, BCheckBox*>::iterator it =
987f14cab2dSMichael Pfeiffer 			fDriverSpecificCheckBoxes.begin();
988f14cab2dSMichael Pfeiffer 		for(; it != fDriverSpecificCheckBoxes.end(); it++) {
989f14cab2dSMichael Pfeiffer 			const char* key = it->first.c_str();
990f14cab2dSMichael Pfeiffer 			BCheckBox* checkBox = it->second;
991f14cab2dSMichael Pfeiffer 			bool value = checkBox->Value() == B_CONTROL_ON;
992f14cab2dSMichael Pfeiffer 			fJobData->Settings().SetBoolean(key, value);
993f14cab2dSMichael Pfeiffer 		}
994f14cab2dSMichael Pfeiffer 	}
995f14cab2dSMichael Pfeiffer 
996f14cab2dSMichael Pfeiffer 	{
997f14cab2dSMichael Pfeiffer 		std::map<PrinterCap::CapID, IntRange>::iterator it =
998f14cab2dSMichael Pfeiffer 			fDriverSpecificIntSliders.begin();
999f14cab2dSMichael Pfeiffer 		for(; it != fDriverSpecificIntSliders.end(); it++) {
1000f14cab2dSMichael Pfeiffer 			IntRange& range = it->second;
1001f14cab2dSMichael Pfeiffer 			fJobData->Settings().SetInt(range.Key(), range.Value());
1002f14cab2dSMichael Pfeiffer 		}
1003f14cab2dSMichael Pfeiffer 	}
1004f14cab2dSMichael Pfeiffer 
1005f14cab2dSMichael Pfeiffer 	{
1006f14cab2dSMichael Pfeiffer 		std::map<PrinterCap::CapID, DoubleRange>::iterator it =
1007f14cab2dSMichael Pfeiffer 			fDriverSpecificDoubleSliders.begin();
1008f14cab2dSMichael Pfeiffer 		for(; it != fDriverSpecificDoubleSliders.end(); it++) {
1009f14cab2dSMichael Pfeiffer 			DoubleRange& range = it->second;
1010f14cab2dSMichael Pfeiffer 			fJobData->Settings().SetDouble(range.Key(), range.Value());
1011f14cab2dSMichael Pfeiffer 		}
1012de18d919SMichael Pfeiffer 	}
1013de18d919SMichael Pfeiffer 
101412fd6cc2SKarsten Heimrich 	fJobData->save();
101512fd6cc2SKarsten Heimrich 	return true;
101612fd6cc2SKarsten Heimrich }
101712fd6cc2SKarsten Heimrich 
101812fd6cc2SKarsten Heimrich 
101956c20e82SMichael Pfeiffer JobSetupDlg::JobSetupDlg(JobData* jobData, PrinterData* printerData,
102056c20e82SMichael Pfeiffer 	const PrinterCap* printerCap)
1021a7dde370SMichael Pfeiffer 	:
1022a7dde370SMichael Pfeiffer 	DialogWindow(BRect(100, 100, 200, 200), "PrintJob Setup",
1023a7dde370SMichael Pfeiffer 		B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,
10245a695bceSMichael Pfeiffer 		B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE
1025*0e216008SMichael Pfeiffer 			| B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS
1026*0e216008SMichael Pfeiffer 			| B_CLOSE_ON_ESCAPE)
102712fd6cc2SKarsten Heimrich {
102812fd6cc2SKarsten Heimrich 	SetResult(B_ERROR);
102912fd6cc2SKarsten Heimrich 	AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
103012fd6cc2SKarsten Heimrich 
103156c20e82SMichael Pfeiffer 	fJobSetup = new JobSetupView(jobData, printerData, printerCap);
10325a695bceSMichael Pfeiffer 	SetLayout(new BGroupLayout(B_VERTICAL));
10335a695bceSMichael Pfeiffer 	AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
10345a695bceSMichael Pfeiffer 		.Add(fJobSetup)
10355a695bceSMichael Pfeiffer 		.SetInsets(10, 10, 10, 10)
10365a695bceSMichael Pfeiffer 	);
103712fd6cc2SKarsten Heimrich }
103812fd6cc2SKarsten Heimrich 
1039a7dde370SMichael Pfeiffer 
104012fd6cc2SKarsten Heimrich void
104156c20e82SMichael Pfeiffer JobSetupDlg::MessageReceived(BMessage* message)
104212fd6cc2SKarsten Heimrich {
104356c20e82SMichael Pfeiffer 	switch (message->what) {
104412fd6cc2SKarsten Heimrich 	case kMsgOK:
1045ae83b2f1SMichael Pfeiffer 		fJobSetup->UpdateJobData();
104612fd6cc2SKarsten Heimrich 		SetResult(B_NO_ERROR);
104712fd6cc2SKarsten Heimrich 		PostMessage(B_QUIT_REQUESTED);
104812fd6cc2SKarsten Heimrich 		break;
104912fd6cc2SKarsten Heimrich 
105012fd6cc2SKarsten Heimrich 	case kMsgCancel:
105112fd6cc2SKarsten Heimrich 		PostMessage(B_QUIT_REQUESTED);
105212fd6cc2SKarsten Heimrich 		break;
105312fd6cc2SKarsten Heimrich 
105412fd6cc2SKarsten Heimrich 	default:
105556c20e82SMichael Pfeiffer 		DialogWindow::MessageReceived(message);
105612fd6cc2SKarsten Heimrich 		break;
105712fd6cc2SKarsten Heimrich 	}
105812fd6cc2SKarsten Heimrich }
1059