xref: /haiku/src/libs/print/libprint/JobSetupDlg.cpp (revision f696e88a2ccab23dedcbf03dc8e7560f1770338b)
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 
13756c20e82SMichael Pfeiffer JobSetupView::JobSetupView(JobData* jobData, PrinterData* printerData,
13856c20e82SMichael Pfeiffer 	const PrinterCap *printerCap)
139a7dde370SMichael Pfeiffer 	:
140a7dde370SMichael Pfeiffer 	BView("jobSetup", B_WILL_DRAW),
141308f0e19SMichael Pfeiffer 	fCopies(NULL),
142308f0e19SMichael Pfeiffer 	fFromPage(NULL),
143308f0e19SMichael Pfeiffer 	fToPage(NULL),
14456c20e82SMichael Pfeiffer 	fJobData(jobData),
14556c20e82SMichael Pfeiffer 	fPrinterData(printerData),
14656c20e82SMichael Pfeiffer 	fPrinterCap(printerCap),
147308f0e19SMichael Pfeiffer 	fColorType(NULL),
148308f0e19SMichael Pfeiffer 	fDitherType(NULL),
149308f0e19SMichael Pfeiffer 	fGamma(NULL),
150308f0e19SMichael Pfeiffer 	fInkDensity(NULL),
151308f0e19SMichael Pfeiffer 	fHalftone(NULL),
152308f0e19SMichael Pfeiffer 	fAll(NULL),
153308f0e19SMichael Pfeiffer 	fCollate(NULL),
154308f0e19SMichael Pfeiffer 	fReverse(NULL),
155308f0e19SMichael Pfeiffer 	fPages(NULL),
156308f0e19SMichael Pfeiffer 	fPaperFeed(NULL),
157308f0e19SMichael Pfeiffer 	fDuplex(NULL),
158308f0e19SMichael Pfeiffer 	fNup(NULL),
159308f0e19SMichael Pfeiffer 	fAllPages(NULL),
160308f0e19SMichael Pfeiffer 	fOddNumberedPages(NULL),
161308f0e19SMichael Pfeiffer 	fEvenNumberedPages(NULL)
16212fd6cc2SKarsten Heimrich {
163*f696e88aSlooncraz 	SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
16412fd6cc2SKarsten Heimrich }
16512fd6cc2SKarsten Heimrich 
166a7dde370SMichael Pfeiffer 
16712fd6cc2SKarsten Heimrich BRadioButton*
1685a695bceSMichael Pfeiffer JobSetupView::CreatePageSelectionItem(const char* name, const char* label,
16912fd6cc2SKarsten Heimrich 	JobData::PageSelection pageSelection)
17012fd6cc2SKarsten Heimrich {
1715a695bceSMichael Pfeiffer 	BRadioButton* button = new BRadioButton(name, label, NULL);
1724410ee12SMichael Pfeiffer 	if (fJobData->GetPageSelection() == pageSelection) {
17312fd6cc2SKarsten Heimrich 		button->SetValue(B_CONTROL_ON);
17412fd6cc2SKarsten Heimrich 	}
17512fd6cc2SKarsten Heimrich 	return button;
17612fd6cc2SKarsten Heimrich }
17712fd6cc2SKarsten Heimrich 
178a7dde370SMichael Pfeiffer 
17912fd6cc2SKarsten Heimrich void
18012fd6cc2SKarsten Heimrich JobSetupView::AllowOnlyDigits(BTextView* textView, int maxDigits)
18112fd6cc2SKarsten Heimrich {
18212fd6cc2SKarsten Heimrich 	int num;
18312fd6cc2SKarsten Heimrich 	for (num = 0; num <= 255; num++) {
18412fd6cc2SKarsten Heimrich 		textView->DisallowChar(num);
18512fd6cc2SKarsten Heimrich 	}
18612fd6cc2SKarsten Heimrich 	for (num = 0; num <= 9; num++) {
18712fd6cc2SKarsten Heimrich 		textView->AllowChar('0' + num);
18812fd6cc2SKarsten Heimrich 	}
18912fd6cc2SKarsten Heimrich 	textView->SetMaxBytes(maxDigits);
19012fd6cc2SKarsten Heimrich }
19112fd6cc2SKarsten Heimrich 
192a7dde370SMichael Pfeiffer 
19312fd6cc2SKarsten Heimrich void
19412fd6cc2SKarsten Heimrich JobSetupView::AttachedToWindow()
19512fd6cc2SKarsten Heimrich {
1965a695bceSMichael Pfeiffer 	// quality
1975a695bceSMichael Pfeiffer 	BBox* qualityBox = new BBox("quality");
1985a695bceSMichael Pfeiffer 	qualityBox->SetLabel("Quality");
19912fd6cc2SKarsten Heimrich 
2005a695bceSMichael Pfeiffer 	// color
2015a695bceSMichael Pfeiffer 	fColorType = new BPopUpMenu("color");
20212fd6cc2SKarsten Heimrich 	fColorType->SetRadioMode(true);
203f53abcbdSMichael Pfeiffer 	FillCapabilityMenu(fColorType, kMsgQuality, PrinterCap::kColor,
2044410ee12SMichael Pfeiffer 		fJobData->GetColor());
2055a695bceSMichael Pfeiffer 	BMenuField* colorMenuField = new BMenuField("color", "Color:", fColorType);
20612fd6cc2SKarsten Heimrich 	fColorType->SetTargetForItems(this);
20712fd6cc2SKarsten Heimrich 
208308f0e19SMichael Pfeiffer 	if (IsHalftoneConfigurationNeeded())
209308f0e19SMichael Pfeiffer 		CreateHalftoneConfigurationUI();
21012fd6cc2SKarsten Heimrich 
2115a695bceSMichael Pfeiffer 	// page range
21212fd6cc2SKarsten Heimrich 
2135a695bceSMichael Pfeiffer 	BBox* pageRangeBox = new BBox("pageRange");
2145a695bceSMichael Pfeiffer 	pageRangeBox->SetLabel("Page Range");
21512fd6cc2SKarsten Heimrich 
2165a695bceSMichael Pfeiffer 	fAll = new BRadioButton("all", "Print all Pages", new BMessage(kMsgRangeAll));
21712fd6cc2SKarsten Heimrich 
2185a695bceSMichael Pfeiffer 	BRadioButton *range = new BRadioButton("selection", "Print selected Pages:",
2195a695bceSMichael Pfeiffer 		new BMessage(kMsgRangeSelection));
22012fd6cc2SKarsten Heimrich 
2215a695bceSMichael Pfeiffer 	fFromPage = new BTextControl("from", "From:", "", NULL);
22212fd6cc2SKarsten Heimrich 	fFromPage->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
22312fd6cc2SKarsten Heimrich 	AllowOnlyDigits(fFromPage->TextView(), 6);
22412fd6cc2SKarsten Heimrich 
2255a695bceSMichael Pfeiffer 	fToPage = new BTextControl("to", "To:", "", NULL);
22612fd6cc2SKarsten Heimrich 	fToPage->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
22712fd6cc2SKarsten Heimrich 	AllowOnlyDigits(fToPage->TextView(), 6);
22812fd6cc2SKarsten Heimrich 
2294410ee12SMichael Pfeiffer 	int first_page = fJobData->GetFirstPage();
2304410ee12SMichael Pfeiffer 	int last_page  = fJobData->GetLastPage();
23112fd6cc2SKarsten Heimrich 
23212fd6cc2SKarsten Heimrich 	if (first_page <= 1 && last_page <= 0) {
23312fd6cc2SKarsten Heimrich 		fAll->SetValue(B_CONTROL_ON);
23412fd6cc2SKarsten Heimrich 	} else {
2355a695bceSMichael Pfeiffer 		range->SetValue(B_CONTROL_ON);
23612fd6cc2SKarsten Heimrich 		if (first_page < 1)
23712fd6cc2SKarsten Heimrich 			first_page = 1;
23812fd6cc2SKarsten Heimrich 		if (first_page > last_page)
23912fd6cc2SKarsten Heimrich 			last_page = -1;
24012fd6cc2SKarsten Heimrich 
24112fd6cc2SKarsten Heimrich 		BString oss1;
24212fd6cc2SKarsten Heimrich 		oss1 << first_page;
24312fd6cc2SKarsten Heimrich 		fFromPage->SetText(oss1.String());
24412fd6cc2SKarsten Heimrich 
24512fd6cc2SKarsten Heimrich 		BString oss2;
24612fd6cc2SKarsten Heimrich 		oss2 << last_page;
24712fd6cc2SKarsten Heimrich 		fToPage->SetText(oss2.String());
24812fd6cc2SKarsten Heimrich 	}
24912fd6cc2SKarsten Heimrich 
25012fd6cc2SKarsten Heimrich 	fAll->SetTarget(this);
2515a695bceSMichael Pfeiffer 	range->SetTarget(this);
25212fd6cc2SKarsten Heimrich 
2535a695bceSMichael Pfeiffer 	// paper source
25412fd6cc2SKarsten Heimrich 	fPaperFeed = new BPopUpMenu("");
25512fd6cc2SKarsten Heimrich 	fPaperFeed->SetRadioMode(true);
256f53abcbdSMichael Pfeiffer 	FillCapabilityMenu(fPaperFeed, kMsgNone, PrinterCap::kPaperSource,
2574410ee12SMichael Pfeiffer 		fJobData->GetPaperSource());
2585a695bceSMichael Pfeiffer 	BMenuField* paperSourceMenufield = new BMenuField("paperSource",
2595a695bceSMichael Pfeiffer 		"Paper Source:", fPaperFeed);
26012fd6cc2SKarsten Heimrich 
2615a695bceSMichael Pfeiffer 	// Pages per sheet
26212fd6cc2SKarsten Heimrich 	fNup = new BPopUpMenu("");
26312fd6cc2SKarsten Heimrich 	fNup->SetRadioMode(true);
264f14cab2dSMichael Pfeiffer 	FillCapabilityMenu(fNup, kMsgNone, gNups,
2654410ee12SMichael Pfeiffer 		sizeof(gNups) / sizeof(gNups[0]), (int)fJobData->GetNup());
2665a695bceSMichael Pfeiffer 	BMenuField* pagesPerSheet = new BMenuField("pagesPerSheet",
2675a695bceSMichael Pfeiffer 		"Pages Per Sheet:", fNup);
26812fd6cc2SKarsten Heimrich 
2695a695bceSMichael Pfeiffer 	// duplex
270331c9220SMichael Pfeiffer 	if (fPrinterCap->Supports(PrinterCap::kPrintStyle)) {
2715a695bceSMichael Pfeiffer 		fDuplex = new BCheckBox("duplex", "Duplex",
2725a695bceSMichael Pfeiffer 			new BMessage(kMsgDuplexChanged));
2734410ee12SMichael Pfeiffer 		if (fJobData->GetPrintStyle() != JobData::kSimplex) {
27412fd6cc2SKarsten Heimrich 			fDuplex->SetValue(B_CONTROL_ON);
27512fd6cc2SKarsten Heimrich 		}
27612fd6cc2SKarsten Heimrich 		fDuplex->SetTarget(this);
27712fd6cc2SKarsten Heimrich 	} else {
27812fd6cc2SKarsten Heimrich 		fDuplex = NULL;
27912fd6cc2SKarsten Heimrich 	}
28012fd6cc2SKarsten Heimrich 
2815a695bceSMichael Pfeiffer 	// copies
2825a695bceSMichael Pfeiffer 	fCopies = new BTextControl("copies", "Number of Copies:", "", NULL);
28312fd6cc2SKarsten Heimrich 	AllowOnlyDigits(fCopies->TextView(), 3);
28412fd6cc2SKarsten Heimrich 
2855a695bceSMichael Pfeiffer 	BString copies;
2864410ee12SMichael Pfeiffer 	copies << fJobData->GetCopies();
2875a695bceSMichael Pfeiffer 	fCopies->SetText(copies.String());
28812fd6cc2SKarsten Heimrich 
2895a695bceSMichael Pfeiffer 	// collate
2905a695bceSMichael Pfeiffer 	fCollate = new BCheckBox("collate", "Collate",
2915a695bceSMichael Pfeiffer 		new BMessage(kMsgCollateChanged));
2924410ee12SMichael Pfeiffer 	if (fJobData->GetCollate()) {
29312fd6cc2SKarsten Heimrich 		fCollate->SetValue(B_CONTROL_ON);
29412fd6cc2SKarsten Heimrich 	}
29512fd6cc2SKarsten Heimrich 	fCollate->SetTarget(this);
29612fd6cc2SKarsten Heimrich 
2975a695bceSMichael Pfeiffer 	// reverse
2985a695bceSMichael Pfeiffer 	fReverse = new BCheckBox("reverse", "Reverse Order",
2995a695bceSMichael Pfeiffer 		new BMessage(kMsgReverseChanged));
3004410ee12SMichael Pfeiffer 	if (fJobData->GetReverse()) {
30112fd6cc2SKarsten Heimrich 		fReverse->SetValue(B_CONTROL_ON);
30212fd6cc2SKarsten Heimrich 	}
30312fd6cc2SKarsten Heimrich 	fReverse->SetTarget(this);
30412fd6cc2SKarsten Heimrich 
3055a695bceSMichael Pfeiffer 	// pages view
3065a695bceSMichael Pfeiffer 	// TODO make layout API compatible
3075a695bceSMichael Pfeiffer 	fPages = new PagesView(BRect(0, 0, 150, 40), "pages", B_FOLLOW_ALL,
3085a695bceSMichael Pfeiffer 		B_WILL_DRAW);
3094410ee12SMichael Pfeiffer 	fPages->SetCollate(fJobData->GetCollate());
3104410ee12SMichael Pfeiffer 	fPages->SetReverse(fJobData->GetReverse());
3115a695bceSMichael Pfeiffer 	fPages->SetExplicitMinSize(BSize(150, 40));
3125a695bceSMichael Pfeiffer 	fPages->SetExplicitMaxSize(BSize(150, 40));
31312fd6cc2SKarsten Heimrich 
3145a695bceSMichael Pfeiffer 	// page selection
3155a695bceSMichael Pfeiffer 	BBox* pageSelectionBox = new BBox("pageSelection");
31612fd6cc2SKarsten Heimrich 	pageSelectionBox->SetLabel("Page Selection");
31712fd6cc2SKarsten Heimrich 
3185a695bceSMichael Pfeiffer 	fAllPages = CreatePageSelectionItem("allPages", "All Pages",
3195a695bceSMichael Pfeiffer 		JobData::kAllPages);
3205a695bceSMichael Pfeiffer 	fOddNumberedPages = CreatePageSelectionItem("oddPages",
3215a695bceSMichael Pfeiffer 		"Odd-Numbered Pages", JobData::kOddNumberedPages);
3225a695bceSMichael Pfeiffer 	fEvenNumberedPages = CreatePageSelectionItem("evenPages",
3235a695bceSMichael Pfeiffer 		"Even-Numbered Pages", JobData::kEvenNumberedPages);
3245a695bceSMichael Pfeiffer 
325ae83b2f1SMichael Pfeiffer 	fPreview = new BCheckBox("preview", "Show preview before printing", NULL);
3264410ee12SMichael Pfeiffer 	if (fJobData->GetShowPreview())
327ae83b2f1SMichael Pfeiffer 		fPreview->SetValue(B_CONTROL_ON);
328ae83b2f1SMichael Pfeiffer 
3295a695bceSMichael Pfeiffer 	// separator line
3305a695bceSMichael Pfeiffer 	BBox *separator = new BBox("separator");
3315a695bceSMichael Pfeiffer 	separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1));
3325a695bceSMichael Pfeiffer 
3335a695bceSMichael Pfeiffer 	// buttons
3345a695bceSMichael Pfeiffer 	BButton* cancel = new BButton("cancel", "Cancel",
3355a695bceSMichael Pfeiffer 		new BMessage(kMsgCancel));
3365a695bceSMichael Pfeiffer 	BButton* ok = new BButton("ok", "OK", new BMessage(kMsgOK));
3375a695bceSMichael Pfeiffer 	ok->MakeDefault(true);
3385a695bceSMichael Pfeiffer 
339308f0e19SMichael Pfeiffer 	if (IsHalftoneConfigurationNeeded()) {
3405a695bceSMichael Pfeiffer 		BGroupView* halftoneGroup = new BGroupView(B_VERTICAL, 0);
3415a695bceSMichael Pfeiffer 		BGroupLayout* halftoneLayout = halftoneGroup->GroupLayout();
3425a695bceSMichael Pfeiffer 		halftoneLayout->AddView(fHalftone);
343308f0e19SMichael Pfeiffer 		fHalftoneBox->AddChild(halftoneGroup);
344308f0e19SMichael Pfeiffer 	}
3455a695bceSMichael Pfeiffer 
3465a695bceSMichael Pfeiffer 	BGridView* qualityGrid = new BGridView();
3475a695bceSMichael Pfeiffer 	BGridLayout* qualityGridLayout = qualityGrid->GridLayout();
3485a695bceSMichael Pfeiffer 	qualityGridLayout->AddItem(colorMenuField->CreateLabelLayoutItem(), 0, 0);
3495a695bceSMichael Pfeiffer 	qualityGridLayout->AddItem(colorMenuField->CreateMenuBarLayoutItem(), 1, 0);
350308f0e19SMichael Pfeiffer 	if (IsHalftoneConfigurationNeeded()) {
351308f0e19SMichael Pfeiffer 		qualityGridLayout->AddItem(fDitherMenuField->CreateLabelLayoutItem(),
352308f0e19SMichael Pfeiffer 			0, 1);
353308f0e19SMichael Pfeiffer 		qualityGridLayout->AddItem(fDitherMenuField->CreateMenuBarLayoutItem(),
354308f0e19SMichael Pfeiffer 			1, 1);
3555a695bceSMichael Pfeiffer 		qualityGridLayout->AddView(fGamma, 0, 2, 2);
3565a695bceSMichael Pfeiffer 		qualityGridLayout->AddView(fInkDensity, 0, 3, 2);
357308f0e19SMichael Pfeiffer 		qualityGridLayout->AddView(fHalftoneBox, 0, 4, 2);
358de18d919SMichael Pfeiffer 	} else {
359de18d919SMichael Pfeiffer 		AddDriverSpecificSettings(qualityGridLayout, 1);
360308f0e19SMichael Pfeiffer 	}
3615a695bceSMichael Pfeiffer 	qualityGridLayout->SetSpacing(0, 0);
3625a695bceSMichael Pfeiffer 	qualityGridLayout->SetInsets(5, 5, 5, 5);
3635a695bceSMichael Pfeiffer 	qualityBox->AddChild(qualityGrid);
364f14cab2dSMichael Pfeiffer 	// TODO put qualityGrid in a scroll view
365f14cab2dSMichael Pfeiffer 	// the layout of the box surrounding the scroll view using the following
366f14cab2dSMichael Pfeiffer 	// code is not correct; the box still has the size of the qualityGird;
367f14cab2dSMichael Pfeiffer 	// and the scroll view is vertically centered inside the box!
368f14cab2dSMichael Pfeiffer 	//BScrollView* qualityScroller = new BScrollView("qualityScroller",
369f14cab2dSMichael Pfeiffer 	//	qualityGrid, 0, false, true);
370f14cab2dSMichael Pfeiffer 	//qualityScroller->SetExplicitMaxSize(BSize(500, 500));
371f14cab2dSMichael Pfeiffer 	//qualityBox->AddChild(qualityScroller);
3725a695bceSMichael Pfeiffer 
3735a695bceSMichael Pfeiffer 	BGridView* pageRangeGrid = new BGridView();
3745a695bceSMichael Pfeiffer 	BGridLayout* pageRangeLayout = pageRangeGrid->GridLayout();
3755a695bceSMichael Pfeiffer 	pageRangeLayout->AddItem(fFromPage->CreateLabelLayoutItem(), 0, 0);
3765a695bceSMichael Pfeiffer 	pageRangeLayout->AddItem(fFromPage->CreateTextViewLayoutItem(), 1, 0);
3775a695bceSMichael Pfeiffer 	pageRangeLayout->AddItem(fToPage->CreateLabelLayoutItem(), 0, 1);
3785a695bceSMichael Pfeiffer 	pageRangeLayout->AddItem(fToPage->CreateTextViewLayoutItem(), 1, 1);
3795a695bceSMichael Pfeiffer 	pageRangeLayout->SetInsets(0, 0, 0, 0);
3805a695bceSMichael Pfeiffer 	pageRangeLayout->SetSpacing(0, 0);
3815a695bceSMichael Pfeiffer 
3825a695bceSMichael Pfeiffer 	BGroupView* pageRangeGroup = new BGroupView(B_VERTICAL, 0);
3835a695bceSMichael Pfeiffer 	BGroupLayout* pageRangeGroupLayout = pageRangeGroup->GroupLayout();
3845a695bceSMichael Pfeiffer 	pageRangeGroupLayout->AddView(fAll);
3855a695bceSMichael Pfeiffer 	pageRangeGroupLayout->AddView(range);
3865a695bceSMichael Pfeiffer 	pageRangeGroupLayout->AddView(pageRangeGrid);
3875a695bceSMichael Pfeiffer 	pageRangeGroupLayout->SetInsets(5, 5, 5, 5);
3885a695bceSMichael Pfeiffer 	pageRangeBox->AddChild(pageRangeGroup);
3895a695bceSMichael Pfeiffer 
3905a695bceSMichael Pfeiffer 	BGridView* settings = new BGridView();
3915a695bceSMichael Pfeiffer 	BGridLayout* settingsLayout = settings->GridLayout();
3925a695bceSMichael Pfeiffer 	settingsLayout->AddItem(paperSourceMenufield->CreateLabelLayoutItem(), 0,
3935a695bceSMichael Pfeiffer 		0);
3945a695bceSMichael Pfeiffer 	settingsLayout->AddItem(paperSourceMenufield->CreateMenuBarLayoutItem(), 1,
3955a695bceSMichael Pfeiffer 		0);
3965a695bceSMichael Pfeiffer 	settingsLayout->AddItem(pagesPerSheet->CreateLabelLayoutItem(), 0, 1);
3975a695bceSMichael Pfeiffer 	settingsLayout->AddItem(pagesPerSheet->CreateMenuBarLayoutItem(), 1, 1);
3985a695bceSMichael Pfeiffer 	int row = 2;
3995a695bceSMichael Pfeiffer 	if (fDuplex != NULL) {
4005a695bceSMichael Pfeiffer 		settingsLayout->AddView(fDuplex, 0, row, 2);
4015a695bceSMichael Pfeiffer 		row ++;
4025a695bceSMichael Pfeiffer 	}
4035a695bceSMichael Pfeiffer 	settingsLayout->AddItem(fCopies->CreateLabelLayoutItem(), 0, row);
4045a695bceSMichael Pfeiffer 	settingsLayout->AddItem(fCopies->CreateTextViewLayoutItem(), 1, row);
4055a695bceSMichael Pfeiffer 	settingsLayout->SetSpacing(0, 0);
40612fd6cc2SKarsten Heimrich 
40712fd6cc2SKarsten Heimrich 
4085a695bceSMichael Pfeiffer 	BGroupView* pageSelectionGroup = new BGroupView(B_VERTICAL, 0);
4095a695bceSMichael Pfeiffer 	BGroupLayout* groupLayout = pageSelectionGroup->GroupLayout();
4105a695bceSMichael Pfeiffer 	groupLayout->AddView(fAllPages);
4115a695bceSMichael Pfeiffer 	groupLayout->AddView(fOddNumberedPages);
4125a695bceSMichael Pfeiffer 	groupLayout->AddView(fEvenNumberedPages);
4135a695bceSMichael Pfeiffer 	groupLayout->SetInsets(5, 5, 5, 5);
4145a695bceSMichael Pfeiffer 	pageSelectionBox->AddChild(pageSelectionGroup);
41512fd6cc2SKarsten Heimrich 
4165a695bceSMichael Pfeiffer 	SetLayout(new BGroupLayout(B_VERTICAL));
4175a695bceSMichael Pfeiffer 	AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
4185a695bceSMichael Pfeiffer 		.AddGroup(B_HORIZONTAL, 10, 1.0f)
4195a695bceSMichael Pfeiffer 			.AddGroup(B_VERTICAL, 10, 1.0f)
4205a695bceSMichael Pfeiffer 				.Add(qualityBox)
4215a695bceSMichael Pfeiffer 				.Add(pageRangeBox)
4225a695bceSMichael Pfeiffer 				.AddGlue()
4235a695bceSMichael Pfeiffer 			.End()
4245a695bceSMichael Pfeiffer 			.AddGroup(B_VERTICAL, 0, 1.0f)
4255a695bceSMichael Pfeiffer 				.Add(settings)
4265a695bceSMichael Pfeiffer 				.AddStrut(5)
4275a695bceSMichael Pfeiffer 				.Add(fCollate)
4285a695bceSMichael Pfeiffer 				.Add(fReverse)
4295a695bceSMichael Pfeiffer 				.Add(fPages)
4305a695bceSMichael Pfeiffer 				.AddStrut(5)
4315a695bceSMichael Pfeiffer 				.Add(pageSelectionBox)
4325a695bceSMichael Pfeiffer 				.AddGlue()
4335a695bceSMichael Pfeiffer 			.End()
4345a695bceSMichael Pfeiffer 		.End()
435ae83b2f1SMichael Pfeiffer 		.Add(fPreview)
4365a695bceSMichael Pfeiffer 		.AddGlue()
4375a695bceSMichael Pfeiffer 		.Add(separator)
4385a695bceSMichael Pfeiffer 		.AddGroup(B_HORIZONTAL, 10, 1.0f)
4395a695bceSMichael Pfeiffer 			.AddGlue()
4405a695bceSMichael Pfeiffer 			.Add(cancel)
4415a695bceSMichael Pfeiffer 			.Add(ok)
4425a695bceSMichael Pfeiffer 		.End()
4435a695bceSMichael Pfeiffer 		.SetInsets(0, 0, 0, 0)
4445a695bceSMichael Pfeiffer 	);
44512fd6cc2SKarsten Heimrich 
446308f0e19SMichael Pfeiffer 	UpdateHalftonePreview();
44712fd6cc2SKarsten Heimrich 
44812fd6cc2SKarsten Heimrich 	UpdateButtonEnabledState();
44912fd6cc2SKarsten Heimrich }
45012fd6cc2SKarsten Heimrich 
451a7dde370SMichael Pfeiffer 
452308f0e19SMichael Pfeiffer bool
453308f0e19SMichael Pfeiffer JobSetupView::IsHalftoneConfigurationNeeded()
454308f0e19SMichael Pfeiffer {
455331c9220SMichael Pfeiffer 	return fPrinterCap->Supports(PrinterCap::kHalftone);
456308f0e19SMichael Pfeiffer }
457308f0e19SMichael Pfeiffer 
458308f0e19SMichael Pfeiffer 
459308f0e19SMichael Pfeiffer void
460308f0e19SMichael Pfeiffer JobSetupView::CreateHalftoneConfigurationUI()
461308f0e19SMichael Pfeiffer {
462308f0e19SMichael Pfeiffer 	// dither type
463308f0e19SMichael Pfeiffer 	fDitherType = new BPopUpMenu("");
464308f0e19SMichael Pfeiffer 	fDitherType->SetRadioMode(true);
465308f0e19SMichael Pfeiffer 	FillCapabilityMenu(fDitherType, kMsgQuality, gDitherTypes,
466308f0e19SMichael Pfeiffer 		sizeof(gDitherTypes) / sizeof(gDitherTypes[0]),
4674410ee12SMichael Pfeiffer 		(int)fJobData->GetDitherType());
468308f0e19SMichael Pfeiffer 	fDitherMenuField = new BMenuField("dithering", "Dot Pattern:",
469308f0e19SMichael Pfeiffer 		fDitherType);
470308f0e19SMichael Pfeiffer 	fDitherType->SetTargetForItems(this);
471308f0e19SMichael Pfeiffer 
472308f0e19SMichael Pfeiffer 	// halftone preview view
473308f0e19SMichael Pfeiffer 	fHalftoneBox = new BBox("halftoneBox");
474308f0e19SMichael Pfeiffer 	fHalftoneBox->SetBorder(B_PLAIN_BORDER);
475308f0e19SMichael Pfeiffer 
476308f0e19SMichael Pfeiffer 	// TODO make layout compatible
477308f0e19SMichael Pfeiffer 	BSize size(240, 14 * 4);
478308f0e19SMichael Pfeiffer 	BRect rect(0, 0, size.width, size.height);
479308f0e19SMichael Pfeiffer 	fHalftone = new HalftoneView(rect, "halftone",
480308f0e19SMichael Pfeiffer 		B_FOLLOW_ALL, B_WILL_DRAW);
481308f0e19SMichael Pfeiffer 	fHalftone->SetExplicitMinSize(size);
482308f0e19SMichael Pfeiffer 	fHalftone->SetExplicitMaxSize(size);
483308f0e19SMichael Pfeiffer 
484308f0e19SMichael Pfeiffer 	// gamma
485308f0e19SMichael Pfeiffer 	fGamma = new JSDSlider("gamma", "Gamma", new BMessage(kMsgQuality),
486308f0e19SMichael Pfeiffer 		-300, 300);
487308f0e19SMichael Pfeiffer 
488308f0e19SMichael Pfeiffer 	fGamma->SetLimitLabels("Lighter", "Darker");
4894410ee12SMichael Pfeiffer 	fGamma->SetValue((int32)(100 * log(fJobData->GetGamma()) / log(2.0)));
490308f0e19SMichael Pfeiffer 	fGamma->SetHashMarks(B_HASH_MARKS_BOTH);
491308f0e19SMichael Pfeiffer 	fGamma->SetHashMarkCount(7);
492308f0e19SMichael Pfeiffer 	fGamma->SetModificationMessage(new BMessage(kMsgQuality));
493308f0e19SMichael Pfeiffer 	fGamma->SetTarget(this);
494308f0e19SMichael Pfeiffer 
495308f0e19SMichael Pfeiffer 	// ink density
496308f0e19SMichael Pfeiffer 	fInkDensity = new JSDSlider("inkDensity", "Ink Usage",
497308f0e19SMichael Pfeiffer 		new BMessage(kMsgQuality), 0, 127);
498308f0e19SMichael Pfeiffer 
499308f0e19SMichael Pfeiffer 	fInkDensity->SetLimitLabels("Min", "Max");
5004410ee12SMichael Pfeiffer 	fInkDensity->SetValue((int32)fJobData->GetInkDensity());
501308f0e19SMichael Pfeiffer 	fInkDensity->SetHashMarks(B_HASH_MARKS_BOTH);
502308f0e19SMichael Pfeiffer 	fInkDensity->SetHashMarkCount(10);
503308f0e19SMichael Pfeiffer 	fInkDensity->SetModificationMessage(new BMessage(kMsgQuality));
504308f0e19SMichael Pfeiffer 	fInkDensity->SetTarget(this);
505308f0e19SMichael Pfeiffer }
506308f0e19SMichael Pfeiffer 
507308f0e19SMichael Pfeiffer 
50812fd6cc2SKarsten Heimrich void
509de18d919SMichael Pfeiffer JobSetupView::AddDriverSpecificSettings(BGridLayout* gridLayout, int row)
510f53abcbdSMichael Pfeiffer {
511331c9220SMichael Pfeiffer 	if (!fPrinterCap->Supports(PrinterCap::kDriverSpecificCapabilities))
512de18d919SMichael Pfeiffer 		return;
513de18d919SMichael Pfeiffer 
5144410ee12SMichael Pfeiffer 	int count = fPrinterCap->CountCap(PrinterCap::kDriverSpecificCapabilities);
5154410ee12SMichael Pfeiffer 	const BaseCap** capabilities = fPrinterCap->GetCaps(
516de18d919SMichael Pfeiffer 		PrinterCap::kDriverSpecificCapabilities);
517de18d919SMichael Pfeiffer 
518de18d919SMichael Pfeiffer 	for (int i = 0; i < count; i ++) {
519f14cab2dSMichael Pfeiffer 		const DriverSpecificCap* capability =
520f14cab2dSMichael Pfeiffer 			static_cast<const DriverSpecificCap*>(capabilities[i]);
521de18d919SMichael Pfeiffer 
522f14cab2dSMichael Pfeiffer 		switch (capability->fType) {
523f14cab2dSMichael Pfeiffer 			case DriverSpecificCap::kList:
524f14cab2dSMichael Pfeiffer 				AddPopUpMenu(capability, gridLayout, row);
525f14cab2dSMichael Pfeiffer 				break;
526f14cab2dSMichael Pfeiffer 			case DriverSpecificCap::kBoolean:
527f14cab2dSMichael Pfeiffer 				AddCheckBox(capability, gridLayout, row);
528f14cab2dSMichael Pfeiffer 				break;
529f14cab2dSMichael Pfeiffer 			case DriverSpecificCap::kIntRange:
530f14cab2dSMichael Pfeiffer 			case DriverSpecificCap::kIntDimension:
531f14cab2dSMichael Pfeiffer 				AddIntSlider(capability, gridLayout, row);
532f14cab2dSMichael Pfeiffer 				break;
533f14cab2dSMichael Pfeiffer 			case DriverSpecificCap::kDoubleRange:
534f14cab2dSMichael Pfeiffer 				AddDoubleSlider(capability, gridLayout, row);
535f14cab2dSMichael Pfeiffer 				break;
536f14cab2dSMichael Pfeiffer 
537f14cab2dSMichael Pfeiffer 		}
538f14cab2dSMichael Pfeiffer 	}
539f14cab2dSMichael Pfeiffer }
540f14cab2dSMichael Pfeiffer 
541f14cab2dSMichael Pfeiffer 
542f14cab2dSMichael Pfeiffer void
543f14cab2dSMichael Pfeiffer JobSetupView::AddPopUpMenu(const DriverSpecificCap* capability,
544f14cab2dSMichael Pfeiffer 	BGridLayout* gridLayout, int& row)
545f14cab2dSMichael Pfeiffer {
546de18d919SMichael Pfeiffer 	const char* label = capability->fLabel.c_str();
547de18d919SMichael Pfeiffer 	BPopUpMenu* popUpMenu = new BPopUpMenu(label);
548de18d919SMichael Pfeiffer 	popUpMenu->SetRadioMode(true);
549de18d919SMichael Pfeiffer 
550de18d919SMichael Pfeiffer 	PrinterCap::CapID category = static_cast<PrinterCap::CapID>(
551de18d919SMichael Pfeiffer 		capability->ID());
552de18d919SMichael Pfeiffer 
5534410ee12SMichael Pfeiffer 	const BaseCap** categoryCapabilities = fPrinterCap->GetCaps(category);
554de18d919SMichael Pfeiffer 
5554410ee12SMichael Pfeiffer 	int categoryCount = fPrinterCap->CountCap(category);
556de18d919SMichael Pfeiffer 
557de18d919SMichael Pfeiffer 	string value = GetDriverSpecificValue(category, capability->Key());
558de18d919SMichael Pfeiffer 	PrinterCap::KeyPredicate predicate(value.c_str());
559de18d919SMichael Pfeiffer 
560de18d919SMichael Pfeiffer 	FillCapabilityMenu(popUpMenu, kMsgNone, categoryCapabilities,
561de18d919SMichael Pfeiffer 		categoryCount, predicate);
562de18d919SMichael Pfeiffer 
563de18d919SMichael Pfeiffer 	BString menuLabel = label;
564de18d919SMichael Pfeiffer 	menuLabel << ":";
565de18d919SMichael Pfeiffer 	BMenuField* menuField = new BMenuField(label, menuLabel.String(),
566de18d919SMichael Pfeiffer 		popUpMenu);
567de18d919SMichael Pfeiffer 	popUpMenu->SetTargetForItems(this);
568de18d919SMichael Pfeiffer 
569de18d919SMichael Pfeiffer 	gridLayout->AddItem(menuField->CreateLabelLayoutItem(),
570de18d919SMichael Pfeiffer 		0, row);
571de18d919SMichael Pfeiffer 	gridLayout->AddItem(menuField->CreateMenuBarLayoutItem(),
572de18d919SMichael Pfeiffer 		1, row);
573de18d919SMichael Pfeiffer 	row ++;
574de18d919SMichael Pfeiffer 
575f14cab2dSMichael Pfeiffer 	fDriverSpecificPopUpMenus[category] = popUpMenu;
576de18d919SMichael Pfeiffer }
577f14cab2dSMichael Pfeiffer 
578f14cab2dSMichael Pfeiffer 
579f14cab2dSMichael Pfeiffer void
580f14cab2dSMichael Pfeiffer JobSetupView::AddCheckBox(const DriverSpecificCap* capability,
581f14cab2dSMichael Pfeiffer 	BGridLayout* gridLayout, int& row)
582f14cab2dSMichael Pfeiffer {
583f14cab2dSMichael Pfeiffer 	PrinterCap::CapID category = static_cast<PrinterCap::CapID>(
584f14cab2dSMichael Pfeiffer 		capability->ID());
5854410ee12SMichael Pfeiffer 	const BooleanCap* booleanCap = fPrinterCap->FindBooleanCap(category);
586f14cab2dSMichael Pfeiffer 	if (booleanCap == NULL) {
587f14cab2dSMichael Pfeiffer 		fprintf(stderr, "Internal error: BooleanCap for '%s' not found!\n",
588f14cab2dSMichael Pfeiffer 			capability->Label());
589f14cab2dSMichael Pfeiffer 		return;
590f14cab2dSMichael Pfeiffer 	}
591f14cab2dSMichael Pfeiffer 
592f14cab2dSMichael Pfeiffer 	const char* key = capability->Key();
593f14cab2dSMichael Pfeiffer 	BString name;
594f14cab2dSMichael Pfeiffer 	name << "pds_" << key;
595f14cab2dSMichael Pfeiffer 	BCheckBox* checkBox = new BCheckBox(name.String(), capability->Label(),
596f14cab2dSMichael Pfeiffer 		NULL);
597f14cab2dSMichael Pfeiffer 
598f14cab2dSMichael Pfeiffer 	bool value = booleanCap->DefaultValue();
599f14cab2dSMichael Pfeiffer 	if (fJobData->Settings().HasBoolean(key))
600f14cab2dSMichael Pfeiffer 		value = fJobData->Settings().GetBoolean(key);
601f14cab2dSMichael Pfeiffer 	if (value)
602f14cab2dSMichael Pfeiffer 		checkBox->SetValue(B_CONTROL_ON);
603f14cab2dSMichael Pfeiffer 
604f14cab2dSMichael Pfeiffer 	gridLayout->AddView(checkBox, 0, row, 2);
605f14cab2dSMichael Pfeiffer 	row ++;
606f14cab2dSMichael Pfeiffer 
607f14cab2dSMichael Pfeiffer 	fDriverSpecificCheckBoxes[capability->Key()] = checkBox;
608f14cab2dSMichael Pfeiffer }
609f14cab2dSMichael Pfeiffer 
610f14cab2dSMichael Pfeiffer 
611f14cab2dSMichael Pfeiffer void
612f14cab2dSMichael Pfeiffer JobSetupView::AddIntSlider(const DriverSpecificCap* capability,
613f14cab2dSMichael Pfeiffer 	BGridLayout* gridLayout, int& row)
614f14cab2dSMichael Pfeiffer {
615f14cab2dSMichael Pfeiffer 	PrinterCap::CapID category = static_cast<PrinterCap::CapID>(
616f14cab2dSMichael Pfeiffer 		capability->ID());
6174410ee12SMichael Pfeiffer 	const IntRangeCap* range = fPrinterCap->FindIntRangeCap(category);
618f14cab2dSMichael Pfeiffer 	if (range == NULL) {
619f14cab2dSMichael Pfeiffer 		fprintf(stderr, "Internal error: IntRangeCap for '%s' not found!\n",
620f14cab2dSMichael Pfeiffer 			capability->Label());
621f14cab2dSMichael Pfeiffer 		return;
622f14cab2dSMichael Pfeiffer 	}
623f14cab2dSMichael Pfeiffer 
624f14cab2dSMichael Pfeiffer 	const char* label = capability->Label();
625f14cab2dSMichael Pfeiffer 	const char* key = capability->Key();
626f14cab2dSMichael Pfeiffer 	BString name;
627f14cab2dSMichael Pfeiffer 	name << "pds_" << key;
628f14cab2dSMichael Pfeiffer 	BMessage* message = new BMessage(kMsgIntSliderChanged);
629f14cab2dSMichael Pfeiffer 	message->AddInt32(kCategoryID, category);
630f14cab2dSMichael Pfeiffer 	BSlider* slider = new BSlider(name.String(), label,
631f14cab2dSMichael Pfeiffer 		message, 0, 1000, B_HORIZONTAL);
632f14cab2dSMichael Pfeiffer 	slider->SetModificationMessage(new BMessage(*message));
633f14cab2dSMichael Pfeiffer 	slider->SetTarget(this);
634f14cab2dSMichael Pfeiffer 
635f14cab2dSMichael Pfeiffer 	int32 value = range->DefaultValue();
636f14cab2dSMichael Pfeiffer 	if (fJobData->Settings().HasInt(key))
637f14cab2dSMichael Pfeiffer 		value = fJobData->Settings().GetInt(key);
638f14cab2dSMichael Pfeiffer 	float position = (value - range->Lower()) /
639f14cab2dSMichael Pfeiffer 		(range->Upper() - range->Lower());
640f14cab2dSMichael Pfeiffer 	slider->SetPosition(position);
641f14cab2dSMichael Pfeiffer 
642f14cab2dSMichael Pfeiffer 	gridLayout->AddView(slider, 0, row, 2);
643f14cab2dSMichael Pfeiffer 	row ++;
644f14cab2dSMichael Pfeiffer 
645f14cab2dSMichael Pfeiffer 	IntRange intRange(label, key, range, slider);
646f14cab2dSMichael Pfeiffer 	fDriverSpecificIntSliders[category] = intRange;
647f14cab2dSMichael Pfeiffer 	intRange.UpdateLabel();
648f14cab2dSMichael Pfeiffer }
649f14cab2dSMichael Pfeiffer 
650f14cab2dSMichael Pfeiffer 
651f14cab2dSMichael Pfeiffer void
652f14cab2dSMichael Pfeiffer JobSetupView::AddDoubleSlider(const DriverSpecificCap* capability,
653f14cab2dSMichael Pfeiffer 	BGridLayout* gridLayout, int& row)
654f14cab2dSMichael Pfeiffer {
655f14cab2dSMichael Pfeiffer 	PrinterCap::CapID category = static_cast<PrinterCap::CapID>(
656f14cab2dSMichael Pfeiffer 		capability->ID());
6574410ee12SMichael Pfeiffer 	const DoubleRangeCap* range = fPrinterCap->FindDoubleRangeCap(category);
658f14cab2dSMichael Pfeiffer 	if (range == NULL) {
659f14cab2dSMichael Pfeiffer 		fprintf(stderr, "Internal error: DoubleRangeCap for '%s' not found!\n",
660f14cab2dSMichael Pfeiffer 			capability->Label());
661f14cab2dSMichael Pfeiffer 		return;
662f14cab2dSMichael Pfeiffer 	}
663f14cab2dSMichael Pfeiffer 
664f14cab2dSMichael Pfeiffer 	const char* label = capability->Label();
665f14cab2dSMichael Pfeiffer 	const char* key = capability->Key();
666f14cab2dSMichael Pfeiffer 	BString name;
667f14cab2dSMichael Pfeiffer 	name << "pds_" << key;
668f14cab2dSMichael Pfeiffer 	BMessage* message = new BMessage(kMsgDoubleSliderChanged);
669f14cab2dSMichael Pfeiffer 	message->AddInt32(kCategoryID, category);
670f14cab2dSMichael Pfeiffer 	BSlider* slider = new BSlider(name.String(), label,
671f14cab2dSMichael Pfeiffer 		message, 0, 1000, B_HORIZONTAL);
672f14cab2dSMichael Pfeiffer 	slider->SetModificationMessage(new BMessage(*message));
673f14cab2dSMichael Pfeiffer 	slider->SetTarget(this);
674f14cab2dSMichael Pfeiffer 
675f14cab2dSMichael Pfeiffer 	double value = range->DefaultValue();
676f14cab2dSMichael Pfeiffer 	if (fJobData->Settings().HasDouble(key))
677f14cab2dSMichael Pfeiffer 		value = fJobData->Settings().GetDouble(key);
678f14cab2dSMichael Pfeiffer 	float position = static_cast<float>((value - range->Lower()) /
679f14cab2dSMichael Pfeiffer 		(range->Upper() - range->Lower()));
680f14cab2dSMichael Pfeiffer 	slider->SetPosition(position);
681f14cab2dSMichael Pfeiffer 
682f14cab2dSMichael Pfeiffer 	gridLayout->AddView(slider, 0, row, 2);
683f14cab2dSMichael Pfeiffer 	row ++;
684f14cab2dSMichael Pfeiffer 
685f14cab2dSMichael Pfeiffer 	DoubleRange doubleRange(label, key, range, slider);
686f14cab2dSMichael Pfeiffer 	fDriverSpecificDoubleSliders[category] = doubleRange;
687f14cab2dSMichael Pfeiffer 	doubleRange.UpdateLabel();
688f53abcbdSMichael Pfeiffer }
689f53abcbdSMichael Pfeiffer 
690de18d919SMichael Pfeiffer 
691de18d919SMichael Pfeiffer string
692de18d919SMichael Pfeiffer JobSetupView::GetDriverSpecificValue(PrinterCap::CapID category,
693de18d919SMichael Pfeiffer 	const char* key)
694de18d919SMichael Pfeiffer {
695f14cab2dSMichael Pfeiffer 	if (fJobData->Settings().HasString(key))
696f14cab2dSMichael Pfeiffer 		return fJobData->Settings().GetString(key);
697de18d919SMichael Pfeiffer 
6984410ee12SMichael Pfeiffer 	const EnumCap* defaultCapability = fPrinterCap->GetDefaultCap(category);
699de18d919SMichael Pfeiffer 	return defaultCapability->fKey;
700de18d919SMichael Pfeiffer }
701de18d919SMichael Pfeiffer 
702de18d919SMichael Pfeiffer 
703de18d919SMichael Pfeiffer template<typename Predicate>
704f53abcbdSMichael Pfeiffer void
705f53abcbdSMichael Pfeiffer JobSetupView::FillCapabilityMenu(BPopUpMenu* menu, uint32 message,
706de18d919SMichael Pfeiffer 	const BaseCap** capabilities, int count, Predicate& predicate)
707f53abcbdSMichael Pfeiffer {
708f53abcbdSMichael Pfeiffer 	bool marked = false;
709f53abcbdSMichael Pfeiffer 
710f53abcbdSMichael Pfeiffer 	BMenuItem* firstItem = NULL;
711f53abcbdSMichael Pfeiffer 	BMenuItem* defaultItem = NULL;
712f53abcbdSMichael Pfeiffer 	BMenuItem* item = NULL;
713f53abcbdSMichael Pfeiffer 	while (count--) {
714f14cab2dSMichael Pfeiffer 		const EnumCap* capability = dynamic_cast<const EnumCap*>(*capabilities);
715f53abcbdSMichael Pfeiffer 		if (message != kMsgNone)
716f53abcbdSMichael Pfeiffer 			item = new BMenuItem(capability->fLabel.c_str(),
717308f0e19SMichael Pfeiffer 				new BMessage(message));
718f53abcbdSMichael Pfeiffer 		else
719f53abcbdSMichael Pfeiffer 			item = new BMenuItem(capability->fLabel.c_str(), NULL);
720f53abcbdSMichael Pfeiffer 
721f53abcbdSMichael Pfeiffer 		menu->AddItem(item);
722f53abcbdSMichael Pfeiffer 
723f53abcbdSMichael Pfeiffer 		if (firstItem == NULL)
724f53abcbdSMichael Pfeiffer 			firstItem = item;
725f53abcbdSMichael Pfeiffer 
726f53abcbdSMichael Pfeiffer 		if (capability->fIsDefault)
727f53abcbdSMichael Pfeiffer 			defaultItem = item;
728f53abcbdSMichael Pfeiffer 
729f53abcbdSMichael Pfeiffer 
730de18d919SMichael Pfeiffer 		if (predicate(capability)) {
731f53abcbdSMichael Pfeiffer 			item->SetMarked(true);
732f53abcbdSMichael Pfeiffer 			marked = true;
733f53abcbdSMichael Pfeiffer 		}
734f53abcbdSMichael Pfeiffer 
735f53abcbdSMichael Pfeiffer 		capabilities++;
736f53abcbdSMichael Pfeiffer 	}
737f53abcbdSMichael Pfeiffer 
738f53abcbdSMichael Pfeiffer 	if (marked)
739f53abcbdSMichael Pfeiffer 		return;
740f53abcbdSMichael Pfeiffer 
741f53abcbdSMichael Pfeiffer 	if (defaultItem != NULL)
742f53abcbdSMichael Pfeiffer 		defaultItem->SetMarked(true);
743f53abcbdSMichael Pfeiffer 	else if (firstItem != NULL)
744f53abcbdSMichael Pfeiffer 		firstItem->SetMarked(true);
745f53abcbdSMichael Pfeiffer }
746f53abcbdSMichael Pfeiffer 
747f53abcbdSMichael Pfeiffer 
748de18d919SMichael Pfeiffer void
749de18d919SMichael Pfeiffer JobSetupView::FillCapabilityMenu(BPopUpMenu* menu, uint32 message,
750de18d919SMichael Pfeiffer 	PrinterCap::CapID category, int id)
751de18d919SMichael Pfeiffer {
752de18d919SMichael Pfeiffer 	PrinterCap::IDPredicate predicate(id);
7534410ee12SMichael Pfeiffer 	int count = fPrinterCap->CountCap(category);
7544410ee12SMichael Pfeiffer 	const BaseCap **capabilities = fPrinterCap->GetCaps(category);
755de18d919SMichael Pfeiffer 	FillCapabilityMenu(menu, message, capabilities, count, predicate);
756de18d919SMichael Pfeiffer }
757de18d919SMichael Pfeiffer 
758de18d919SMichael Pfeiffer 
759de18d919SMichael Pfeiffer void
760de18d919SMichael Pfeiffer JobSetupView::FillCapabilityMenu(BPopUpMenu* menu, uint32 message,
761de18d919SMichael Pfeiffer 	const BaseCap** capabilities, int count, int id)
762de18d919SMichael Pfeiffer {
763de18d919SMichael Pfeiffer 	PrinterCap::IDPredicate predicate(id);
764de18d919SMichael Pfeiffer 	FillCapabilityMenu(menu, message, capabilities, count, predicate);
765de18d919SMichael Pfeiffer }
766de18d919SMichael Pfeiffer 
767de18d919SMichael Pfeiffer 
768f53abcbdSMichael Pfeiffer int
769f53abcbdSMichael Pfeiffer JobSetupView::GetID(const BaseCap** capabilities, int count, const char* label,
770f53abcbdSMichael Pfeiffer 	int defaultValue)
771f53abcbdSMichael Pfeiffer {
772f53abcbdSMichael Pfeiffer 	while (count--) {
773f14cab2dSMichael Pfeiffer 		const EnumCap* capability =
774f14cab2dSMichael Pfeiffer 			dynamic_cast<const EnumCap*>(*capabilities);
775f14cab2dSMichael Pfeiffer 		if (capability == NULL)
776f14cab2dSMichael Pfeiffer 			break;
777f14cab2dSMichael Pfeiffer 
778f53abcbdSMichael Pfeiffer 		if (capability->fLabel == label)
779f53abcbdSMichael Pfeiffer 			return capability->ID();
780f53abcbdSMichael Pfeiffer 	}
781f53abcbdSMichael Pfeiffer 	return defaultValue;
782f53abcbdSMichael Pfeiffer }
783f53abcbdSMichael Pfeiffer 
784f53abcbdSMichael Pfeiffer 
785f53abcbdSMichael Pfeiffer void
78612fd6cc2SKarsten Heimrich JobSetupView::UpdateButtonEnabledState()
78712fd6cc2SKarsten Heimrich {
78812fd6cc2SKarsten Heimrich 	bool pageRangeEnabled = fAll->Value() != B_CONTROL_ON;
78912fd6cc2SKarsten Heimrich 	fFromPage->SetEnabled(pageRangeEnabled);
79012fd6cc2SKarsten Heimrich 	fToPage->SetEnabled(pageRangeEnabled);
79112fd6cc2SKarsten Heimrich 
79212fd6cc2SKarsten Heimrich 	bool pageSelectionEnabled = fDuplex == NULL ||
79312fd6cc2SKarsten Heimrich 		fDuplex->Value() != B_CONTROL_ON;
79412fd6cc2SKarsten Heimrich 	fAllPages->SetEnabled(pageSelectionEnabled);
79512fd6cc2SKarsten Heimrich 	fOddNumberedPages->SetEnabled(pageSelectionEnabled);
79612fd6cc2SKarsten Heimrich 	fEvenNumberedPages->SetEnabled(pageSelectionEnabled);
79712fd6cc2SKarsten Heimrich }
79812fd6cc2SKarsten Heimrich 
799a7dde370SMichael Pfeiffer 
80012fd6cc2SKarsten Heimrich void
80156c20e82SMichael Pfeiffer JobSetupView::MessageReceived(BMessage* message)
80212fd6cc2SKarsten Heimrich {
80356c20e82SMichael Pfeiffer 	switch (message->what) {
80412fd6cc2SKarsten Heimrich 	case kMsgRangeAll:
80512fd6cc2SKarsten Heimrich 	case kMsgRangeSelection:
80612fd6cc2SKarsten Heimrich 	case kMsgDuplexChanged:
80712fd6cc2SKarsten Heimrich 		UpdateButtonEnabledState();
80812fd6cc2SKarsten Heimrich 		break;
80912fd6cc2SKarsten Heimrich 
81012fd6cc2SKarsten Heimrich 	case kMsgQuality:
811308f0e19SMichael Pfeiffer 		UpdateHalftonePreview();
81212fd6cc2SKarsten Heimrich 		break;
81312fd6cc2SKarsten Heimrich 
81412fd6cc2SKarsten Heimrich 	case kMsgCollateChanged:
8154410ee12SMichael Pfeiffer 		fPages->SetCollate(fCollate->Value() == B_CONTROL_ON);
81612fd6cc2SKarsten Heimrich 		break;
81712fd6cc2SKarsten Heimrich 
81812fd6cc2SKarsten Heimrich 	case kMsgReverseChanged:
8194410ee12SMichael Pfeiffer 		fPages->SetReverse(fReverse->Value() == B_CONTROL_ON);
82012fd6cc2SKarsten Heimrich 		break;
821f14cab2dSMichael Pfeiffer 
822f14cab2dSMichael Pfeiffer 	case kMsgIntSliderChanged:
823f14cab2dSMichael Pfeiffer 		UpdateIntSlider(message);
824f14cab2dSMichael Pfeiffer 		break;
825f14cab2dSMichael Pfeiffer 
826f14cab2dSMichael Pfeiffer 	case kMsgDoubleSliderChanged:
827f14cab2dSMichael Pfeiffer 		UpdateDoubleSlider(message);
828f14cab2dSMichael Pfeiffer 		break;
82912fd6cc2SKarsten Heimrich 	}
83012fd6cc2SKarsten Heimrich }
83112fd6cc2SKarsten Heimrich 
832a7dde370SMichael Pfeiffer 
833308f0e19SMichael Pfeiffer void
834308f0e19SMichael Pfeiffer JobSetupView::UpdateHalftonePreview()
835308f0e19SMichael Pfeiffer {
836308f0e19SMichael Pfeiffer 	if (!IsHalftoneConfigurationNeeded())
837308f0e19SMichael Pfeiffer 		return;
838308f0e19SMichael Pfeiffer 
8394410ee12SMichael Pfeiffer 	fHalftone->Preview(Gamma(), InkDensity(), DitherType(),
840308f0e19SMichael Pfeiffer 		Color() != JobData::kMonochrome);
841308f0e19SMichael Pfeiffer }
842308f0e19SMichael Pfeiffer 
843308f0e19SMichael Pfeiffer 
844f14cab2dSMichael Pfeiffer void
845f14cab2dSMichael Pfeiffer JobSetupView::UpdateIntSlider(BMessage* message)
846f14cab2dSMichael Pfeiffer {
847f14cab2dSMichael Pfeiffer 	int32 id;
848f14cab2dSMichael Pfeiffer 	if (message->FindInt32(kCategoryID, &id) != B_OK)
849f14cab2dSMichael Pfeiffer 		return;
850f14cab2dSMichael Pfeiffer 	PrinterCap::CapID capID = static_cast<PrinterCap::CapID>(id);
851f14cab2dSMichael Pfeiffer 	fDriverSpecificIntSliders[capID].UpdateLabel();
852f14cab2dSMichael Pfeiffer }
853f14cab2dSMichael Pfeiffer 
854f14cab2dSMichael Pfeiffer 
855f14cab2dSMichael Pfeiffer void
856f14cab2dSMichael Pfeiffer JobSetupView::UpdateDoubleSlider(BMessage* message)
857f14cab2dSMichael Pfeiffer {
858f14cab2dSMichael Pfeiffer 	int32 id;
859f14cab2dSMichael Pfeiffer 	if (message->FindInt32(kCategoryID, &id) != B_OK)
860f14cab2dSMichael Pfeiffer 		return;
861f14cab2dSMichael Pfeiffer 	PrinterCap::CapID capID = static_cast<PrinterCap::CapID>(id);
862f14cab2dSMichael Pfeiffer 	fDriverSpecificDoubleSliders[capID].UpdateLabel();
863f14cab2dSMichael Pfeiffer }
864f14cab2dSMichael Pfeiffer 
865f14cab2dSMichael Pfeiffer 
86612fd6cc2SKarsten Heimrich JobData::Color
867f53abcbdSMichael Pfeiffer JobSetupView::Color()
86812fd6cc2SKarsten Heimrich {
869f53abcbdSMichael Pfeiffer 	const char *label = fColorType->FindMarked()->Label();
8704410ee12SMichael Pfeiffer 	const BaseCap* capability = fPrinterCap->FindCap(PrinterCap::kColor, label);
871f53abcbdSMichael Pfeiffer 	if (capability == NULL)
87212fd6cc2SKarsten Heimrich 		return JobData::kMonochrome;
873f53abcbdSMichael Pfeiffer 
874f53abcbdSMichael Pfeiffer 	const ColorCap* colorCap = static_cast<const ColorCap*>(capability);
875f53abcbdSMichael Pfeiffer 	return colorCap->fColor;
87612fd6cc2SKarsten Heimrich }
87712fd6cc2SKarsten Heimrich 
878a7dde370SMichael Pfeiffer 
87912fd6cc2SKarsten Heimrich Halftone::DitherType
880f53abcbdSMichael Pfeiffer JobSetupView::DitherType()
88112fd6cc2SKarsten Heimrich {
882f53abcbdSMichael Pfeiffer 	const char *label = fDitherType->FindMarked()->Label();
883f53abcbdSMichael Pfeiffer 	int id = GetID(gDitherTypes, sizeof(gDitherTypes) / sizeof(gDitherTypes[0]),
884f53abcbdSMichael Pfeiffer 		label, Halftone::kTypeFloydSteinberg);
885f53abcbdSMichael Pfeiffer 	return static_cast<Halftone::DitherType>(id);
88612fd6cc2SKarsten Heimrich }
88712fd6cc2SKarsten Heimrich 
88812fd6cc2SKarsten Heimrich float
889f53abcbdSMichael Pfeiffer JobSetupView::Gamma()
89012fd6cc2SKarsten Heimrich {
89112fd6cc2SKarsten Heimrich 	const float value = (float)fGamma->Value();
89212fd6cc2SKarsten Heimrich 	return pow(2.0, value / 100.0);
89312fd6cc2SKarsten Heimrich }
89412fd6cc2SKarsten Heimrich 
895a7dde370SMichael Pfeiffer 
89612fd6cc2SKarsten Heimrich float
897f53abcbdSMichael Pfeiffer JobSetupView::InkDensity()
89812fd6cc2SKarsten Heimrich {
89912fd6cc2SKarsten Heimrich 	const float value = (float)(127 - fInkDensity->Value());
90012fd6cc2SKarsten Heimrich 	return value;
90112fd6cc2SKarsten Heimrich }
90212fd6cc2SKarsten Heimrich 
903a7dde370SMichael Pfeiffer 
904f53abcbdSMichael Pfeiffer JobData::PaperSource
905f53abcbdSMichael Pfeiffer JobSetupView::PaperSource()
906f53abcbdSMichael Pfeiffer {
907f53abcbdSMichael Pfeiffer 	const char *label = fPaperFeed->FindMarked()->Label();
9084410ee12SMichael Pfeiffer 	const BaseCap* capability = fPrinterCap->FindCap(PrinterCap::kPaperSource,
909f53abcbdSMichael Pfeiffer 		label);
910f53abcbdSMichael Pfeiffer 
911f53abcbdSMichael Pfeiffer 	if (capability == NULL)
9124410ee12SMichael Pfeiffer 		capability = fPrinterCap->GetDefaultCap(PrinterCap::kPaperSource);
913f53abcbdSMichael Pfeiffer 	return static_cast<const PaperSourceCap*>(capability)->fPaperSource;
914f53abcbdSMichael Pfeiffer 
915f53abcbdSMichael Pfeiffer }
916f53abcbdSMichael Pfeiffer 
91712fd6cc2SKarsten Heimrich bool
918ae83b2f1SMichael Pfeiffer JobSetupView::UpdateJobData()
91912fd6cc2SKarsten Heimrich {
9204410ee12SMichael Pfeiffer 	fJobData->SetShowPreview(fPreview->Value() == B_CONTROL_ON);
9214410ee12SMichael Pfeiffer 	fJobData->SetColor(Color());
922308f0e19SMichael Pfeiffer 	if (IsHalftoneConfigurationNeeded()) {
9234410ee12SMichael Pfeiffer 		fJobData->SetGamma(Gamma());
9244410ee12SMichael Pfeiffer 		fJobData->SetInkDensity(InkDensity());
9254410ee12SMichael Pfeiffer 		fJobData->SetDitherType(DitherType());
926308f0e19SMichael Pfeiffer 	}
92712fd6cc2SKarsten Heimrich 
92812fd6cc2SKarsten Heimrich 	int first_page;
92912fd6cc2SKarsten Heimrich 	int last_page;
93012fd6cc2SKarsten Heimrich 
93112fd6cc2SKarsten Heimrich 	if (B_CONTROL_ON == fAll->Value()) {
93212fd6cc2SKarsten Heimrich 		first_page = 1;
93312fd6cc2SKarsten Heimrich 		last_page  = -1;
93412fd6cc2SKarsten Heimrich 	} else {
93512fd6cc2SKarsten Heimrich 		first_page = atoi(fFromPage->Text());
93612fd6cc2SKarsten Heimrich 		last_page  = atoi(fToPage->Text());
93712fd6cc2SKarsten Heimrich 	}
93812fd6cc2SKarsten Heimrich 
9394410ee12SMichael Pfeiffer 	fJobData->SetFirstPage(first_page);
9404410ee12SMichael Pfeiffer 	fJobData->SetLastPage(last_page);
94112fd6cc2SKarsten Heimrich 
9424410ee12SMichael Pfeiffer 	fJobData->SetPaperSource(PaperSource());
94312fd6cc2SKarsten Heimrich 
9444410ee12SMichael Pfeiffer 	fJobData->SetNup(GetID(gNups, sizeof(gNups) / sizeof(gNups[0]),
945f53abcbdSMichael Pfeiffer 		fNup->FindMarked()->Label(), 1));
94612fd6cc2SKarsten Heimrich 
947331c9220SMichael Pfeiffer 	if (fPrinterCap->Supports(PrinterCap::kPrintStyle)) {
9484410ee12SMichael Pfeiffer 		fJobData->SetPrintStyle((B_CONTROL_ON == fDuplex->Value())
949f53abcbdSMichael Pfeiffer 			? JobData::kDuplex : JobData::kSimplex);
95012fd6cc2SKarsten Heimrich 	}
95112fd6cc2SKarsten Heimrich 
9524410ee12SMichael Pfeiffer 	fJobData->SetCopies(atoi(fCopies->Text()));
95312fd6cc2SKarsten Heimrich 
9544410ee12SMichael Pfeiffer 	fJobData->SetCollate(B_CONTROL_ON == fCollate->Value());
9554410ee12SMichael Pfeiffer 	fJobData->SetReverse(B_CONTROL_ON == fReverse->Value());
95612fd6cc2SKarsten Heimrich 
95712fd6cc2SKarsten Heimrich 	JobData::PageSelection pageSelection = JobData::kAllPages;
95812fd6cc2SKarsten Heimrich 	if (fOddNumberedPages->Value() == B_CONTROL_ON)
95912fd6cc2SKarsten Heimrich 		pageSelection = JobData::kOddNumberedPages;
96012fd6cc2SKarsten Heimrich 	if (fEvenNumberedPages->Value() == B_CONTROL_ON)
96112fd6cc2SKarsten Heimrich 		pageSelection = JobData::kEvenNumberedPages;
9624410ee12SMichael Pfeiffer 	fJobData->SetPageSelection(pageSelection);
96312fd6cc2SKarsten Heimrich 
964f14cab2dSMichael Pfeiffer 	{
965de18d919SMichael Pfeiffer 		std::map<PrinterCap::CapID, BPopUpMenu*>::iterator it =
966f14cab2dSMichael Pfeiffer 			fDriverSpecificPopUpMenus.begin();
967f14cab2dSMichael Pfeiffer 		for(; it != fDriverSpecificPopUpMenus.end(); it++) {
968de18d919SMichael Pfeiffer 			PrinterCap::CapID category = it->first;
969de18d919SMichael Pfeiffer 			BPopUpMenu* popUpMenu = it->second;
9704410ee12SMichael Pfeiffer 			const char* key = fPrinterCap->FindCap(
971de18d919SMichael Pfeiffer 				PrinterCap::kDriverSpecificCapabilities, (int)category)->Key();
972de18d919SMichael Pfeiffer 			const char* label = popUpMenu->FindMarked()->Label();
973f14cab2dSMichael Pfeiffer 			const char* value = static_cast<const EnumCap*>(fPrinterCap->
9744410ee12SMichael Pfeiffer 				FindCap(category, label))->Key();
975f14cab2dSMichael Pfeiffer 			fJobData->Settings().SetString(key, value);
976f14cab2dSMichael Pfeiffer 		}
977f14cab2dSMichael Pfeiffer 	}
978f14cab2dSMichael Pfeiffer 
979f14cab2dSMichael Pfeiffer 	{
980f14cab2dSMichael Pfeiffer 		std::map<string, BCheckBox*>::iterator it =
981f14cab2dSMichael Pfeiffer 			fDriverSpecificCheckBoxes.begin();
982f14cab2dSMichael Pfeiffer 		for(; it != fDriverSpecificCheckBoxes.end(); it++) {
983f14cab2dSMichael Pfeiffer 			const char* key = it->first.c_str();
984f14cab2dSMichael Pfeiffer 			BCheckBox* checkBox = it->second;
985f14cab2dSMichael Pfeiffer 			bool value = checkBox->Value() == B_CONTROL_ON;
986f14cab2dSMichael Pfeiffer 			fJobData->Settings().SetBoolean(key, value);
987f14cab2dSMichael Pfeiffer 		}
988f14cab2dSMichael Pfeiffer 	}
989f14cab2dSMichael Pfeiffer 
990f14cab2dSMichael Pfeiffer 	{
991f14cab2dSMichael Pfeiffer 		std::map<PrinterCap::CapID, IntRange>::iterator it =
992f14cab2dSMichael Pfeiffer 			fDriverSpecificIntSliders.begin();
993f14cab2dSMichael Pfeiffer 		for(; it != fDriverSpecificIntSliders.end(); it++) {
994f14cab2dSMichael Pfeiffer 			IntRange& range = it->second;
995f14cab2dSMichael Pfeiffer 			fJobData->Settings().SetInt(range.Key(), range.Value());
996f14cab2dSMichael Pfeiffer 		}
997f14cab2dSMichael Pfeiffer 	}
998f14cab2dSMichael Pfeiffer 
999f14cab2dSMichael Pfeiffer 	{
1000f14cab2dSMichael Pfeiffer 		std::map<PrinterCap::CapID, DoubleRange>::iterator it =
1001f14cab2dSMichael Pfeiffer 			fDriverSpecificDoubleSliders.begin();
1002f14cab2dSMichael Pfeiffer 		for(; it != fDriverSpecificDoubleSliders.end(); it++) {
1003f14cab2dSMichael Pfeiffer 			DoubleRange& range = it->second;
1004f14cab2dSMichael Pfeiffer 			fJobData->Settings().SetDouble(range.Key(), range.Value());
1005f14cab2dSMichael Pfeiffer 		}
1006de18d919SMichael Pfeiffer 	}
1007de18d919SMichael Pfeiffer 
10084410ee12SMichael Pfeiffer 	fJobData->Save();
100912fd6cc2SKarsten Heimrich 	return true;
101012fd6cc2SKarsten Heimrich }
101112fd6cc2SKarsten Heimrich 
101212fd6cc2SKarsten Heimrich 
101356c20e82SMichael Pfeiffer JobSetupDlg::JobSetupDlg(JobData* jobData, PrinterData* printerData,
101456c20e82SMichael Pfeiffer 	const PrinterCap* printerCap)
1015a7dde370SMichael Pfeiffer 	:
1016a7dde370SMichael Pfeiffer 	DialogWindow(BRect(100, 100, 200, 200), "PrintJob Setup",
1017a7dde370SMichael Pfeiffer 		B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,
10185a695bceSMichael Pfeiffer 		B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE
10190e216008SMichael Pfeiffer 			| B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS
10200e216008SMichael Pfeiffer 			| B_CLOSE_ON_ESCAPE)
102112fd6cc2SKarsten Heimrich {
102212fd6cc2SKarsten Heimrich 	SetResult(B_ERROR);
102312fd6cc2SKarsten Heimrich 	AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
102412fd6cc2SKarsten Heimrich 
102556c20e82SMichael Pfeiffer 	fJobSetup = new JobSetupView(jobData, printerData, printerCap);
10265a695bceSMichael Pfeiffer 	SetLayout(new BGroupLayout(B_VERTICAL));
10275a695bceSMichael Pfeiffer 	AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
10285a695bceSMichael Pfeiffer 		.Add(fJobSetup)
10295a695bceSMichael Pfeiffer 		.SetInsets(10, 10, 10, 10)
10305a695bceSMichael Pfeiffer 	);
103112fd6cc2SKarsten Heimrich }
103212fd6cc2SKarsten Heimrich 
1033a7dde370SMichael Pfeiffer 
103412fd6cc2SKarsten Heimrich void
103556c20e82SMichael Pfeiffer JobSetupDlg::MessageReceived(BMessage* message)
103612fd6cc2SKarsten Heimrich {
103756c20e82SMichael Pfeiffer 	switch (message->what) {
103812fd6cc2SKarsten Heimrich 	case kMsgOK:
1039ae83b2f1SMichael Pfeiffer 		fJobSetup->UpdateJobData();
104012fd6cc2SKarsten Heimrich 		SetResult(B_NO_ERROR);
104112fd6cc2SKarsten Heimrich 		PostMessage(B_QUIT_REQUESTED);
104212fd6cc2SKarsten Heimrich 		break;
104312fd6cc2SKarsten Heimrich 
104412fd6cc2SKarsten Heimrich 	case kMsgCancel:
104512fd6cc2SKarsten Heimrich 		PostMessage(B_QUIT_REQUESTED);
104612fd6cc2SKarsten Heimrich 		break;
104712fd6cc2SKarsten Heimrich 
104812fd6cc2SKarsten Heimrich 	default:
104956c20e82SMichael Pfeiffer 		DialogWindow::MessageReceived(message);
105012fd6cc2SKarsten Heimrich 		break;
105112fd6cc2SKarsten Heimrich 	}
105212fd6cc2SKarsten Heimrich }
1053