xref: /haiku/src/libs/print/libprint/JobSetupDlg.cpp (revision de18d919e7c940b402a6e213f7deb21e2f187e22)
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>
20*de18d919SMichael 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 
5312fd6cc2SKarsten Heimrich struct NupCap : public BaseCap {
54a7dde370SMichael Pfeiffer 	NupCap(const string &label, bool isDefault, int nup)
55a7dde370SMichael Pfeiffer 		:
56a7dde370SMichael Pfeiffer 		BaseCap(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 
6612fd6cc2SKarsten Heimrich struct DitherCap : public BaseCap {
67a7dde370SMichael Pfeiffer 	DitherCap(const string &label, bool isDefault,
68a7dde370SMichael Pfeiffer 		Halftone::DitherType ditherType)
69a7dde370SMichael Pfeiffer 		:
70a7dde370SMichael Pfeiffer 		BaseCap(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 
11912fd6cc2SKarsten Heimrich enum {
12012fd6cc2SKarsten Heimrich 	kMsgRangeAll = 'JSdl',
12112fd6cc2SKarsten Heimrich 	kMsgRangeSelection,
12212fd6cc2SKarsten Heimrich 	kMsgPreview,
12312fd6cc2SKarsten Heimrich 	kMsgCancel,
12412fd6cc2SKarsten Heimrich 	kMsgOK,
12512fd6cc2SKarsten Heimrich 	kMsgQuality,
12612fd6cc2SKarsten Heimrich 	kMsgCollateChanged,
12712fd6cc2SKarsten Heimrich 	kMsgReverseChanged,
12812fd6cc2SKarsten Heimrich 	kMsgDuplexChanged,
129f53abcbdSMichael Pfeiffer 	kMsgNone = 0
13012fd6cc2SKarsten Heimrich };
13112fd6cc2SKarsten Heimrich 
132a7dde370SMichael Pfeiffer 
13356c20e82SMichael Pfeiffer JobSetupView::JobSetupView(JobData* jobData, PrinterData* printerData,
13456c20e82SMichael Pfeiffer 	const PrinterCap *printerCap)
135a7dde370SMichael Pfeiffer 	:
136a7dde370SMichael Pfeiffer 	BView("jobSetup", B_WILL_DRAW),
137308f0e19SMichael Pfeiffer 	fCopies(NULL),
138308f0e19SMichael Pfeiffer 	fFromPage(NULL),
139308f0e19SMichael Pfeiffer 	fToPage(NULL),
14056c20e82SMichael Pfeiffer 	fJobData(jobData),
14156c20e82SMichael Pfeiffer 	fPrinterData(printerData),
14256c20e82SMichael Pfeiffer 	fPrinterCap(printerCap),
143308f0e19SMichael Pfeiffer 	fColorType(NULL),
144308f0e19SMichael Pfeiffer 	fDitherType(NULL),
145308f0e19SMichael Pfeiffer 	fGamma(NULL),
146308f0e19SMichael Pfeiffer 	fInkDensity(NULL),
147308f0e19SMichael Pfeiffer 	fHalftone(NULL),
148308f0e19SMichael Pfeiffer 	fAll(NULL),
149308f0e19SMichael Pfeiffer 	fCollate(NULL),
150308f0e19SMichael Pfeiffer 	fReverse(NULL),
151308f0e19SMichael Pfeiffer 	fPages(NULL),
152308f0e19SMichael Pfeiffer 	fPaperFeed(NULL),
153308f0e19SMichael Pfeiffer 	fDuplex(NULL),
154308f0e19SMichael Pfeiffer 	fNup(NULL),
155308f0e19SMichael Pfeiffer 	fAllPages(NULL),
156308f0e19SMichael Pfeiffer 	fOddNumberedPages(NULL),
157308f0e19SMichael Pfeiffer 	fEvenNumberedPages(NULL)
15812fd6cc2SKarsten Heimrich {
15912fd6cc2SKarsten Heimrich 	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
16012fd6cc2SKarsten Heimrich }
16112fd6cc2SKarsten Heimrich 
162a7dde370SMichael Pfeiffer 
16312fd6cc2SKarsten Heimrich BRadioButton*
1645a695bceSMichael Pfeiffer JobSetupView::CreatePageSelectionItem(const char* name, const char* label,
16512fd6cc2SKarsten Heimrich 	JobData::PageSelection pageSelection)
16612fd6cc2SKarsten Heimrich {
1675a695bceSMichael Pfeiffer 	BRadioButton* button = new BRadioButton(name, label, NULL);
16812fd6cc2SKarsten Heimrich 	if (fJobData->getPageSelection() == pageSelection) {
16912fd6cc2SKarsten Heimrich 		button->SetValue(B_CONTROL_ON);
17012fd6cc2SKarsten Heimrich 	}
17112fd6cc2SKarsten Heimrich 	return button;
17212fd6cc2SKarsten Heimrich }
17312fd6cc2SKarsten Heimrich 
174a7dde370SMichael Pfeiffer 
17512fd6cc2SKarsten Heimrich void
17612fd6cc2SKarsten Heimrich JobSetupView::AllowOnlyDigits(BTextView* textView, int maxDigits)
17712fd6cc2SKarsten Heimrich {
17812fd6cc2SKarsten Heimrich 	int num;
17912fd6cc2SKarsten Heimrich 	for (num = 0; num <= 255; num++) {
18012fd6cc2SKarsten Heimrich 		textView->DisallowChar(num);
18112fd6cc2SKarsten Heimrich 	}
18212fd6cc2SKarsten Heimrich 	for (num = 0; num <= 9; num++) {
18312fd6cc2SKarsten Heimrich 		textView->AllowChar('0' + num);
18412fd6cc2SKarsten Heimrich 	}
18512fd6cc2SKarsten Heimrich 	textView->SetMaxBytes(maxDigits);
18612fd6cc2SKarsten Heimrich }
18712fd6cc2SKarsten Heimrich 
188a7dde370SMichael Pfeiffer 
18912fd6cc2SKarsten Heimrich void
19012fd6cc2SKarsten Heimrich JobSetupView::AttachedToWindow()
19112fd6cc2SKarsten Heimrich {
1925a695bceSMichael Pfeiffer 	// quality
1935a695bceSMichael Pfeiffer 	BBox* qualityBox = new BBox("quality");
1945a695bceSMichael Pfeiffer 	qualityBox->SetLabel("Quality");
19512fd6cc2SKarsten Heimrich 
1965a695bceSMichael Pfeiffer 	// color
1975a695bceSMichael Pfeiffer 	fColorType = new BPopUpMenu("color");
19812fd6cc2SKarsten Heimrich 	fColorType->SetRadioMode(true);
199f53abcbdSMichael Pfeiffer 	FillCapabilityMenu(fColorType, kMsgQuality, PrinterCap::kColor,
200f53abcbdSMichael Pfeiffer 		fJobData->getColor());
2015a695bceSMichael Pfeiffer 	BMenuField* colorMenuField = new BMenuField("color", "Color:", fColorType);
20212fd6cc2SKarsten Heimrich 	fColorType->SetTargetForItems(this);
20312fd6cc2SKarsten Heimrich 
204308f0e19SMichael Pfeiffer 	if (IsHalftoneConfigurationNeeded())
205308f0e19SMichael Pfeiffer 		CreateHalftoneConfigurationUI();
20612fd6cc2SKarsten Heimrich 
2075a695bceSMichael Pfeiffer 	// page range
20812fd6cc2SKarsten Heimrich 
2095a695bceSMichael Pfeiffer 	BBox* pageRangeBox = new BBox("pageRange");
2105a695bceSMichael Pfeiffer 	pageRangeBox->SetLabel("Page Range");
21112fd6cc2SKarsten Heimrich 
2125a695bceSMichael Pfeiffer 	fAll = new BRadioButton("all", "Print all Pages", new BMessage(kMsgRangeAll));
21312fd6cc2SKarsten Heimrich 
2145a695bceSMichael Pfeiffer 	BRadioButton *range = new BRadioButton("selection", "Print selected Pages:",
2155a695bceSMichael Pfeiffer 		new BMessage(kMsgRangeSelection));
21612fd6cc2SKarsten Heimrich 
2175a695bceSMichael Pfeiffer 	fFromPage = new BTextControl("from", "From:", "", NULL);
21812fd6cc2SKarsten Heimrich 	fFromPage->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
21912fd6cc2SKarsten Heimrich 	AllowOnlyDigits(fFromPage->TextView(), 6);
22012fd6cc2SKarsten Heimrich 
2215a695bceSMichael Pfeiffer 	fToPage = new BTextControl("to", "To:", "", NULL);
22212fd6cc2SKarsten Heimrich 	fToPage->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
22312fd6cc2SKarsten Heimrich 	AllowOnlyDigits(fToPage->TextView(), 6);
22412fd6cc2SKarsten Heimrich 
22512fd6cc2SKarsten Heimrich 	int first_page = fJobData->getFirstPage();
22612fd6cc2SKarsten Heimrich 	int last_page  = fJobData->getLastPage();
22712fd6cc2SKarsten Heimrich 
22812fd6cc2SKarsten Heimrich 	if (first_page <= 1 && last_page <= 0) {
22912fd6cc2SKarsten Heimrich 		fAll->SetValue(B_CONTROL_ON);
23012fd6cc2SKarsten Heimrich 	} else {
2315a695bceSMichael Pfeiffer 		range->SetValue(B_CONTROL_ON);
23212fd6cc2SKarsten Heimrich 		if (first_page < 1)
23312fd6cc2SKarsten Heimrich 			first_page = 1;
23412fd6cc2SKarsten Heimrich 		if (first_page > last_page)
23512fd6cc2SKarsten Heimrich 			last_page = -1;
23612fd6cc2SKarsten Heimrich 
23712fd6cc2SKarsten Heimrich 		BString oss1;
23812fd6cc2SKarsten Heimrich 		oss1 << first_page;
23912fd6cc2SKarsten Heimrich 		fFromPage->SetText(oss1.String());
24012fd6cc2SKarsten Heimrich 
24112fd6cc2SKarsten Heimrich 		BString oss2;
24212fd6cc2SKarsten Heimrich 		oss2 << last_page;
24312fd6cc2SKarsten Heimrich 		fToPage->SetText(oss2.String());
24412fd6cc2SKarsten Heimrich 	}
24512fd6cc2SKarsten Heimrich 
24612fd6cc2SKarsten Heimrich 	fAll->SetTarget(this);
2475a695bceSMichael Pfeiffer 	range->SetTarget(this);
24812fd6cc2SKarsten Heimrich 
2495a695bceSMichael Pfeiffer 	// paper source
25012fd6cc2SKarsten Heimrich 	fPaperFeed = new BPopUpMenu("");
25112fd6cc2SKarsten Heimrich 	fPaperFeed->SetRadioMode(true);
252f53abcbdSMichael Pfeiffer 	FillCapabilityMenu(fPaperFeed, kMsgNone, PrinterCap::kPaperSource,
253f53abcbdSMichael Pfeiffer 		fJobData->getPaperSource());
2545a695bceSMichael Pfeiffer 	BMenuField* paperSourceMenufield = new BMenuField("paperSource",
2555a695bceSMichael Pfeiffer 		"Paper Source:", fPaperFeed);
25612fd6cc2SKarsten Heimrich 
2575a695bceSMichael Pfeiffer 	// Pages per sheet
25812fd6cc2SKarsten Heimrich 	fNup = new BPopUpMenu("");
25912fd6cc2SKarsten Heimrich 	fNup->SetRadioMode(true);
260f53abcbdSMichael Pfeiffer 	FillCapabilityMenu(fNup, kMsgNone, gNups, sizeof(gNups) / sizeof(gNups[0]),
261*de18d919SMichael Pfeiffer 		(int)fJobData->getNup());
2625a695bceSMichael Pfeiffer 	BMenuField* pagesPerSheet = new BMenuField("pagesPerSheet",
2635a695bceSMichael Pfeiffer 		"Pages Per Sheet:", fNup);
26412fd6cc2SKarsten Heimrich 
2655a695bceSMichael Pfeiffer 	// duplex
26612fd6cc2SKarsten Heimrich 	if (fPrinterCap->isSupport(PrinterCap::kPrintStyle)) {
2675a695bceSMichael Pfeiffer 		fDuplex = new BCheckBox("duplex", "Duplex",
2685a695bceSMichael Pfeiffer 			new BMessage(kMsgDuplexChanged));
26912fd6cc2SKarsten Heimrich 		if (fJobData->getPrintStyle() != JobData::kSimplex) {
27012fd6cc2SKarsten Heimrich 			fDuplex->SetValue(B_CONTROL_ON);
27112fd6cc2SKarsten Heimrich 		}
27212fd6cc2SKarsten Heimrich 		fDuplex->SetTarget(this);
27312fd6cc2SKarsten Heimrich 	} else {
27412fd6cc2SKarsten Heimrich 		fDuplex = NULL;
27512fd6cc2SKarsten Heimrich 	}
27612fd6cc2SKarsten Heimrich 
2775a695bceSMichael Pfeiffer 	// copies
2785a695bceSMichael Pfeiffer 	fCopies = new BTextControl("copies", "Number of Copies:", "", NULL);
27912fd6cc2SKarsten Heimrich 	AllowOnlyDigits(fCopies->TextView(), 3);
28012fd6cc2SKarsten Heimrich 
2815a695bceSMichael Pfeiffer 	BString copies;
2825a695bceSMichael Pfeiffer 	copies << fJobData->getCopies();
2835a695bceSMichael Pfeiffer 	fCopies->SetText(copies.String());
28412fd6cc2SKarsten Heimrich 
2855a695bceSMichael Pfeiffer 	// collate
2865a695bceSMichael Pfeiffer 	fCollate = new BCheckBox("collate", "Collate",
2875a695bceSMichael Pfeiffer 		new BMessage(kMsgCollateChanged));
28812fd6cc2SKarsten Heimrich 	if (fJobData->getCollate()) {
28912fd6cc2SKarsten Heimrich 		fCollate->SetValue(B_CONTROL_ON);
29012fd6cc2SKarsten Heimrich 	}
29112fd6cc2SKarsten Heimrich 	fCollate->SetTarget(this);
29212fd6cc2SKarsten Heimrich 
2935a695bceSMichael Pfeiffer 	// reverse
2945a695bceSMichael Pfeiffer 	fReverse = new BCheckBox("reverse", "Reverse Order",
2955a695bceSMichael Pfeiffer 		new BMessage(kMsgReverseChanged));
29612fd6cc2SKarsten Heimrich 	if (fJobData->getReverse()) {
29712fd6cc2SKarsten Heimrich 		fReverse->SetValue(B_CONTROL_ON);
29812fd6cc2SKarsten Heimrich 	}
29912fd6cc2SKarsten Heimrich 	fReverse->SetTarget(this);
30012fd6cc2SKarsten Heimrich 
3015a695bceSMichael Pfeiffer 	// pages view
3025a695bceSMichael Pfeiffer 	// TODO make layout API compatible
3035a695bceSMichael Pfeiffer 	fPages = new PagesView(BRect(0, 0, 150, 40), "pages", B_FOLLOW_ALL,
3045a695bceSMichael Pfeiffer 		B_WILL_DRAW);
30512fd6cc2SKarsten Heimrich 	fPages->setCollate(fJobData->getCollate());
30612fd6cc2SKarsten Heimrich 	fPages->setReverse(fJobData->getReverse());
3075a695bceSMichael Pfeiffer 	fPages->SetExplicitMinSize(BSize(150, 40));
3085a695bceSMichael Pfeiffer 	fPages->SetExplicitMaxSize(BSize(150, 40));
30912fd6cc2SKarsten Heimrich 
3105a695bceSMichael Pfeiffer 	// page selection
3115a695bceSMichael Pfeiffer 	BBox* pageSelectionBox = new BBox("pageSelection");
31212fd6cc2SKarsten Heimrich 	pageSelectionBox->SetLabel("Page Selection");
31312fd6cc2SKarsten Heimrich 
3145a695bceSMichael Pfeiffer 	fAllPages = CreatePageSelectionItem("allPages", "All Pages",
3155a695bceSMichael Pfeiffer 		JobData::kAllPages);
3165a695bceSMichael Pfeiffer 	fOddNumberedPages = CreatePageSelectionItem("oddPages",
3175a695bceSMichael Pfeiffer 		"Odd-Numbered Pages", JobData::kOddNumberedPages);
3185a695bceSMichael Pfeiffer 	fEvenNumberedPages = CreatePageSelectionItem("evenPages",
3195a695bceSMichael Pfeiffer 		"Even-Numbered Pages", JobData::kEvenNumberedPages);
3205a695bceSMichael Pfeiffer 
3215a695bceSMichael Pfeiffer 	// separator line
3225a695bceSMichael Pfeiffer 	BBox *separator = new BBox("separator");
3235a695bceSMichael Pfeiffer 	separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1));
3245a695bceSMichael Pfeiffer 
3255a695bceSMichael Pfeiffer 	// buttons
3265a695bceSMichael Pfeiffer 	BButton* preview = new BButton("preview", "Preview" B_UTF8_ELLIPSIS,
3275a695bceSMichael Pfeiffer 		new BMessage(kMsgPreview));
3285a695bceSMichael Pfeiffer 	BButton* cancel = new BButton("cancel", "Cancel",
3295a695bceSMichael Pfeiffer 		new BMessage(kMsgCancel));
3305a695bceSMichael Pfeiffer 	BButton* ok = new BButton("ok", "OK", new BMessage(kMsgOK));
3315a695bceSMichael Pfeiffer 	ok->MakeDefault(true);
3325a695bceSMichael Pfeiffer 
333308f0e19SMichael Pfeiffer 	if (IsHalftoneConfigurationNeeded()) {
3345a695bceSMichael Pfeiffer 		BGroupView* halftoneGroup = new BGroupView(B_VERTICAL, 0);
3355a695bceSMichael Pfeiffer 		BGroupLayout* halftoneLayout = halftoneGroup->GroupLayout();
3365a695bceSMichael Pfeiffer 		halftoneLayout->AddView(fHalftone);
337308f0e19SMichael Pfeiffer 		fHalftoneBox->AddChild(halftoneGroup);
338308f0e19SMichael Pfeiffer 	}
3395a695bceSMichael Pfeiffer 
3405a695bceSMichael Pfeiffer 	BGridView* qualityGrid = new BGridView();
3415a695bceSMichael Pfeiffer 	BGridLayout* qualityGridLayout = qualityGrid->GridLayout();
3425a695bceSMichael Pfeiffer 	qualityGridLayout->AddItem(colorMenuField->CreateLabelLayoutItem(), 0, 0);
3435a695bceSMichael Pfeiffer 	qualityGridLayout->AddItem(colorMenuField->CreateMenuBarLayoutItem(), 1, 0);
344308f0e19SMichael Pfeiffer 	if (IsHalftoneConfigurationNeeded()) {
345308f0e19SMichael Pfeiffer 		qualityGridLayout->AddItem(fDitherMenuField->CreateLabelLayoutItem(),
346308f0e19SMichael Pfeiffer 			0, 1);
347308f0e19SMichael Pfeiffer 		qualityGridLayout->AddItem(fDitherMenuField->CreateMenuBarLayoutItem(),
348308f0e19SMichael Pfeiffer 			1, 1);
3495a695bceSMichael Pfeiffer 		qualityGridLayout->AddView(fGamma, 0, 2, 2);
3505a695bceSMichael Pfeiffer 		qualityGridLayout->AddView(fInkDensity, 0, 3, 2);
351308f0e19SMichael Pfeiffer 		qualityGridLayout->AddView(fHalftoneBox, 0, 4, 2);
352*de18d919SMichael Pfeiffer 	} else {
353*de18d919SMichael Pfeiffer 		AddDriverSpecificSettings(qualityGridLayout, 1);
354308f0e19SMichael Pfeiffer 	}
3555a695bceSMichael Pfeiffer 	qualityGridLayout->SetSpacing(0, 0);
3565a695bceSMichael Pfeiffer 	qualityGridLayout->SetInsets(5, 5, 5, 5);
3575a695bceSMichael Pfeiffer 	qualityBox->AddChild(qualityGrid);
3585a695bceSMichael Pfeiffer 
3595a695bceSMichael Pfeiffer 	BGridView* pageRangeGrid = new BGridView();
3605a695bceSMichael Pfeiffer 	BGridLayout* pageRangeLayout = pageRangeGrid->GridLayout();
3615a695bceSMichael Pfeiffer 	pageRangeLayout->AddItem(fFromPage->CreateLabelLayoutItem(), 0, 0);
3625a695bceSMichael Pfeiffer 	pageRangeLayout->AddItem(fFromPage->CreateTextViewLayoutItem(), 1, 0);
3635a695bceSMichael Pfeiffer 	pageRangeLayout->AddItem(fToPage->CreateLabelLayoutItem(), 0, 1);
3645a695bceSMichael Pfeiffer 	pageRangeLayout->AddItem(fToPage->CreateTextViewLayoutItem(), 1, 1);
3655a695bceSMichael Pfeiffer 	pageRangeLayout->SetInsets(0, 0, 0, 0);
3665a695bceSMichael Pfeiffer 	pageRangeLayout->SetSpacing(0, 0);
3675a695bceSMichael Pfeiffer 
3685a695bceSMichael Pfeiffer 	BGroupView* pageRangeGroup = new BGroupView(B_VERTICAL, 0);
3695a695bceSMichael Pfeiffer 	BGroupLayout* pageRangeGroupLayout = pageRangeGroup->GroupLayout();
3705a695bceSMichael Pfeiffer 	pageRangeGroupLayout->AddView(fAll);
3715a695bceSMichael Pfeiffer 	pageRangeGroupLayout->AddView(range);
3725a695bceSMichael Pfeiffer 	pageRangeGroupLayout->AddView(pageRangeGrid);
3735a695bceSMichael Pfeiffer 	pageRangeGroupLayout->SetInsets(5, 5, 5, 5);
3745a695bceSMichael Pfeiffer 	pageRangeBox->AddChild(pageRangeGroup);
3755a695bceSMichael Pfeiffer 
3765a695bceSMichael Pfeiffer 	BGridView* settings = new BGridView();
3775a695bceSMichael Pfeiffer 	BGridLayout* settingsLayout = settings->GridLayout();
3785a695bceSMichael Pfeiffer 	settingsLayout->AddItem(paperSourceMenufield->CreateLabelLayoutItem(), 0,
3795a695bceSMichael Pfeiffer 		0);
3805a695bceSMichael Pfeiffer 	settingsLayout->AddItem(paperSourceMenufield->CreateMenuBarLayoutItem(), 1,
3815a695bceSMichael Pfeiffer 		0);
3825a695bceSMichael Pfeiffer 	settingsLayout->AddItem(pagesPerSheet->CreateLabelLayoutItem(), 0, 1);
3835a695bceSMichael Pfeiffer 	settingsLayout->AddItem(pagesPerSheet->CreateMenuBarLayoutItem(), 1, 1);
3845a695bceSMichael Pfeiffer 	int row = 2;
3855a695bceSMichael Pfeiffer 	if (fDuplex != NULL) {
3865a695bceSMichael Pfeiffer 		settingsLayout->AddView(fDuplex, 0, row, 2);
3875a695bceSMichael Pfeiffer 		row ++;
3885a695bceSMichael Pfeiffer 	}
3895a695bceSMichael Pfeiffer 	settingsLayout->AddItem(fCopies->CreateLabelLayoutItem(), 0, row);
3905a695bceSMichael Pfeiffer 	settingsLayout->AddItem(fCopies->CreateTextViewLayoutItem(), 1, row);
3915a695bceSMichael Pfeiffer 	settingsLayout->SetSpacing(0, 0);
39212fd6cc2SKarsten Heimrich 
39312fd6cc2SKarsten Heimrich 
3945a695bceSMichael Pfeiffer 	BGroupView* pageSelectionGroup = new BGroupView(B_VERTICAL, 0);
3955a695bceSMichael Pfeiffer 	BGroupLayout* groupLayout = pageSelectionGroup->GroupLayout();
3965a695bceSMichael Pfeiffer 	groupLayout->AddView(fAllPages);
3975a695bceSMichael Pfeiffer 	groupLayout->AddView(fOddNumberedPages);
3985a695bceSMichael Pfeiffer 	groupLayout->AddView(fEvenNumberedPages);
3995a695bceSMichael Pfeiffer 	groupLayout->SetInsets(5, 5, 5, 5);
4005a695bceSMichael Pfeiffer 	pageSelectionBox->AddChild(pageSelectionGroup);
40112fd6cc2SKarsten Heimrich 
4025a695bceSMichael Pfeiffer 	SetLayout(new BGroupLayout(B_VERTICAL));
4035a695bceSMichael Pfeiffer 	AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
4045a695bceSMichael Pfeiffer 		.AddGroup(B_HORIZONTAL, 10, 1.0f)
4055a695bceSMichael Pfeiffer 			.AddGroup(B_VERTICAL, 10, 1.0f)
4065a695bceSMichael Pfeiffer 				.Add(qualityBox)
4075a695bceSMichael Pfeiffer 				.Add(pageRangeBox)
4085a695bceSMichael Pfeiffer 				.AddGlue()
4095a695bceSMichael Pfeiffer 			.End()
4105a695bceSMichael Pfeiffer 			.AddGroup(B_VERTICAL, 0, 1.0f)
4115a695bceSMichael Pfeiffer 				.Add(settings)
4125a695bceSMichael Pfeiffer 				.AddStrut(5)
4135a695bceSMichael Pfeiffer 				.Add(fCollate)
4145a695bceSMichael Pfeiffer 				.Add(fReverse)
4155a695bceSMichael Pfeiffer 				.Add(fPages)
4165a695bceSMichael Pfeiffer 				.AddStrut(5)
4175a695bceSMichael Pfeiffer 				.Add(pageSelectionBox)
4185a695bceSMichael Pfeiffer 				.AddGlue()
4195a695bceSMichael Pfeiffer 			.End()
4205a695bceSMichael Pfeiffer 		.End()
4215a695bceSMichael Pfeiffer 		.AddGlue()
4225a695bceSMichael Pfeiffer 		.Add(separator)
4235a695bceSMichael Pfeiffer 		.AddGroup(B_HORIZONTAL, 10, 1.0f)
4245a695bceSMichael Pfeiffer 			.AddGlue()
4255a695bceSMichael Pfeiffer 			.Add(cancel)
4265a695bceSMichael Pfeiffer 			.Add(preview)
4275a695bceSMichael Pfeiffer 			.Add(ok)
4285a695bceSMichael Pfeiffer 		.End()
4295a695bceSMichael Pfeiffer 		.SetInsets(0, 0, 0, 0)
4305a695bceSMichael Pfeiffer 	);
43112fd6cc2SKarsten Heimrich 
432308f0e19SMichael Pfeiffer 	UpdateHalftonePreview();
43312fd6cc2SKarsten Heimrich 
43412fd6cc2SKarsten Heimrich 	UpdateButtonEnabledState();
43512fd6cc2SKarsten Heimrich }
43612fd6cc2SKarsten Heimrich 
437a7dde370SMichael Pfeiffer 
438308f0e19SMichael Pfeiffer bool
439308f0e19SMichael Pfeiffer JobSetupView::IsHalftoneConfigurationNeeded()
440308f0e19SMichael Pfeiffer {
441308f0e19SMichael Pfeiffer 	return fPrinterCap->isSupport(PrinterCap::kHalftone);
442308f0e19SMichael Pfeiffer }
443308f0e19SMichael Pfeiffer 
444308f0e19SMichael Pfeiffer 
445308f0e19SMichael Pfeiffer void
446308f0e19SMichael Pfeiffer JobSetupView::CreateHalftoneConfigurationUI()
447308f0e19SMichael Pfeiffer {
448308f0e19SMichael Pfeiffer 	// dither type
449308f0e19SMichael Pfeiffer 	fDitherType = new BPopUpMenu("");
450308f0e19SMichael Pfeiffer 	fDitherType->SetRadioMode(true);
451308f0e19SMichael Pfeiffer 	FillCapabilityMenu(fDitherType, kMsgQuality, gDitherTypes,
452308f0e19SMichael Pfeiffer 		sizeof(gDitherTypes) / sizeof(gDitherTypes[0]),
453*de18d919SMichael Pfeiffer 		(int)fJobData->getDitherType());
454308f0e19SMichael Pfeiffer 	fDitherMenuField = new BMenuField("dithering", "Dot Pattern:",
455308f0e19SMichael Pfeiffer 		fDitherType);
456308f0e19SMichael Pfeiffer 	fDitherType->SetTargetForItems(this);
457308f0e19SMichael Pfeiffer 
458308f0e19SMichael Pfeiffer 	// halftone preview view
459308f0e19SMichael Pfeiffer 	fHalftoneBox = new BBox("halftoneBox");
460308f0e19SMichael Pfeiffer 	fHalftoneBox->SetBorder(B_PLAIN_BORDER);
461308f0e19SMichael Pfeiffer 
462308f0e19SMichael Pfeiffer 	// TODO make layout compatible
463308f0e19SMichael Pfeiffer 	BSize size(240, 14 * 4);
464308f0e19SMichael Pfeiffer 	BRect rect(0, 0, size.width, size.height);
465308f0e19SMichael Pfeiffer 	fHalftone = new HalftoneView(rect, "halftone",
466308f0e19SMichael Pfeiffer 		B_FOLLOW_ALL, B_WILL_DRAW);
467308f0e19SMichael Pfeiffer 	fHalftone->SetExplicitMinSize(size);
468308f0e19SMichael Pfeiffer 	fHalftone->SetExplicitMaxSize(size);
469308f0e19SMichael Pfeiffer 
470308f0e19SMichael Pfeiffer 	// gamma
471308f0e19SMichael Pfeiffer 	fGamma = new JSDSlider("gamma", "Gamma", new BMessage(kMsgQuality),
472308f0e19SMichael Pfeiffer 		-300, 300);
473308f0e19SMichael Pfeiffer 
474308f0e19SMichael Pfeiffer 	fGamma->SetLimitLabels("Lighter", "Darker");
475308f0e19SMichael Pfeiffer 	fGamma->SetValue((int32)(100 * log(fJobData->getGamma()) / log(2.0)));
476308f0e19SMichael Pfeiffer 	fGamma->SetHashMarks(B_HASH_MARKS_BOTH);
477308f0e19SMichael Pfeiffer 	fGamma->SetHashMarkCount(7);
478308f0e19SMichael Pfeiffer 	fGamma->SetModificationMessage(new BMessage(kMsgQuality));
479308f0e19SMichael Pfeiffer 	fGamma->SetTarget(this);
480308f0e19SMichael Pfeiffer 
481308f0e19SMichael Pfeiffer 	// ink density
482308f0e19SMichael Pfeiffer 	fInkDensity = new JSDSlider("inkDensity", "Ink Usage",
483308f0e19SMichael Pfeiffer 		new BMessage(kMsgQuality), 0, 127);
484308f0e19SMichael Pfeiffer 
485308f0e19SMichael Pfeiffer 	fInkDensity->SetLimitLabels("Min", "Max");
486308f0e19SMichael Pfeiffer 	fInkDensity->SetValue((int32)fJobData->getInkDensity());
487308f0e19SMichael Pfeiffer 	fInkDensity->SetHashMarks(B_HASH_MARKS_BOTH);
488308f0e19SMichael Pfeiffer 	fInkDensity->SetHashMarkCount(10);
489308f0e19SMichael Pfeiffer 	fInkDensity->SetModificationMessage(new BMessage(kMsgQuality));
490308f0e19SMichael Pfeiffer 	fInkDensity->SetTarget(this);
491308f0e19SMichael Pfeiffer }
492308f0e19SMichael Pfeiffer 
493308f0e19SMichael Pfeiffer 
49412fd6cc2SKarsten Heimrich void
495*de18d919SMichael Pfeiffer JobSetupView::AddDriverSpecificSettings(BGridLayout* gridLayout, int row)
496f53abcbdSMichael Pfeiffer {
497*de18d919SMichael Pfeiffer 	if (!fPrinterCap->isSupport(PrinterCap::kDriverSpecificCapabilities))
498*de18d919SMichael Pfeiffer 		return;
499*de18d919SMichael Pfeiffer 
500*de18d919SMichael Pfeiffer 	int count = fPrinterCap->countCap(PrinterCap::kDriverSpecificCapabilities);
501*de18d919SMichael Pfeiffer 	const BaseCap** capabilities = fPrinterCap->enumCap(
502*de18d919SMichael Pfeiffer 		PrinterCap::kDriverSpecificCapabilities);
503*de18d919SMichael Pfeiffer 
504*de18d919SMichael Pfeiffer 	for (int i = 0; i < count; i ++) {
505*de18d919SMichael Pfeiffer 		const DriverSpecificCap* capability = static_cast<const DriverSpecificCap*>(
506*de18d919SMichael Pfeiffer 			capabilities[i]);
507*de18d919SMichael Pfeiffer 
508*de18d919SMichael Pfeiffer 		const char* label = capability->fLabel.c_str();
509*de18d919SMichael Pfeiffer 		BPopUpMenu* popUpMenu = new BPopUpMenu(label);
510*de18d919SMichael Pfeiffer 		popUpMenu->SetRadioMode(true);
511*de18d919SMichael Pfeiffer 
512*de18d919SMichael Pfeiffer 		PrinterCap::CapID category = static_cast<PrinterCap::CapID>(
513*de18d919SMichael Pfeiffer 			capability->ID());
514*de18d919SMichael Pfeiffer 
515*de18d919SMichael Pfeiffer 		const BaseCap** categoryCapabilities = fPrinterCap->enumCap(category);
516*de18d919SMichael Pfeiffer 
517*de18d919SMichael Pfeiffer 		int categoryCount = fPrinterCap->countCap(category);
518*de18d919SMichael Pfeiffer 
519*de18d919SMichael Pfeiffer 		string value = GetDriverSpecificValue(category, capability->Key());
520*de18d919SMichael Pfeiffer 		PrinterCap::KeyPredicate predicate(value.c_str());
521*de18d919SMichael Pfeiffer 
522*de18d919SMichael Pfeiffer 		FillCapabilityMenu(popUpMenu, kMsgNone, categoryCapabilities,
523*de18d919SMichael Pfeiffer 			categoryCount, predicate);
524*de18d919SMichael Pfeiffer 
525*de18d919SMichael Pfeiffer 		BString menuLabel = label;
526*de18d919SMichael Pfeiffer 		menuLabel << ":";
527*de18d919SMichael Pfeiffer 		BMenuField* menuField = new BMenuField(label, menuLabel.String(),
528*de18d919SMichael Pfeiffer 			popUpMenu);
529*de18d919SMichael Pfeiffer 		popUpMenu->SetTargetForItems(this);
530*de18d919SMichael Pfeiffer 
531*de18d919SMichael Pfeiffer 		gridLayout->AddItem(menuField->CreateLabelLayoutItem(),
532*de18d919SMichael Pfeiffer 			0, row);
533*de18d919SMichael Pfeiffer 		gridLayout->AddItem(menuField->CreateMenuBarLayoutItem(),
534*de18d919SMichael Pfeiffer 			1, row);
535*de18d919SMichael Pfeiffer 		row ++;
536*de18d919SMichael Pfeiffer 
537*de18d919SMichael Pfeiffer 		fDriverSpecificLists[category] = popUpMenu;
538*de18d919SMichael Pfeiffer 	}
539f53abcbdSMichael Pfeiffer }
540f53abcbdSMichael Pfeiffer 
541*de18d919SMichael Pfeiffer 
542*de18d919SMichael Pfeiffer string
543*de18d919SMichael Pfeiffer JobSetupView::GetDriverSpecificValue(PrinterCap::CapID category,
544*de18d919SMichael Pfeiffer 	const char* key)
545*de18d919SMichael Pfeiffer {
546*de18d919SMichael Pfeiffer 	if (fJobData->HasDriverSpecificSetting(key))
547*de18d919SMichael Pfeiffer 		return fJobData->DriverSpecificSetting(key);
548*de18d919SMichael Pfeiffer 
549*de18d919SMichael Pfeiffer 	const BaseCap* defaultCapability = fPrinterCap->getDefaultCap(category);
550*de18d919SMichael Pfeiffer 	return defaultCapability->fKey;
551*de18d919SMichael Pfeiffer }
552*de18d919SMichael Pfeiffer 
553*de18d919SMichael Pfeiffer 
554*de18d919SMichael Pfeiffer template<typename Predicate>
555f53abcbdSMichael Pfeiffer void
556f53abcbdSMichael Pfeiffer JobSetupView::FillCapabilityMenu(BPopUpMenu* menu, uint32 message,
557*de18d919SMichael Pfeiffer 	const BaseCap** capabilities, int count, Predicate& predicate)
558f53abcbdSMichael Pfeiffer {
559f53abcbdSMichael Pfeiffer 	bool marked = false;
560f53abcbdSMichael Pfeiffer 
561f53abcbdSMichael Pfeiffer 	BMenuItem* firstItem = NULL;
562f53abcbdSMichael Pfeiffer 	BMenuItem* defaultItem = NULL;
563f53abcbdSMichael Pfeiffer 	BMenuItem* item = NULL;
564f53abcbdSMichael Pfeiffer 	while (count--) {
565f53abcbdSMichael Pfeiffer 		const BaseCap* capability = *capabilities;
566f53abcbdSMichael Pfeiffer 		if (message != kMsgNone)
567f53abcbdSMichael Pfeiffer 			item = new BMenuItem(capability->fLabel.c_str(),
568308f0e19SMichael Pfeiffer 				new BMessage(message));
569f53abcbdSMichael Pfeiffer 		else
570f53abcbdSMichael Pfeiffer 			item = new BMenuItem(capability->fLabel.c_str(), NULL);
571f53abcbdSMichael Pfeiffer 
572f53abcbdSMichael Pfeiffer 		menu->AddItem(item);
573f53abcbdSMichael Pfeiffer 
574f53abcbdSMichael Pfeiffer 		if (firstItem == NULL)
575f53abcbdSMichael Pfeiffer 			firstItem = item;
576f53abcbdSMichael Pfeiffer 
577f53abcbdSMichael Pfeiffer 		if (capability->fIsDefault)
578f53abcbdSMichael Pfeiffer 			defaultItem = item;
579f53abcbdSMichael Pfeiffer 
580f53abcbdSMichael Pfeiffer 
581*de18d919SMichael Pfeiffer 		if (predicate(capability)) {
582f53abcbdSMichael Pfeiffer 			item->SetMarked(true);
583f53abcbdSMichael Pfeiffer 			marked = true;
584f53abcbdSMichael Pfeiffer 		}
585f53abcbdSMichael Pfeiffer 
586f53abcbdSMichael Pfeiffer 		capabilities++;
587f53abcbdSMichael Pfeiffer 	}
588f53abcbdSMichael Pfeiffer 
589f53abcbdSMichael Pfeiffer 	if (marked)
590f53abcbdSMichael Pfeiffer 		return;
591f53abcbdSMichael Pfeiffer 
592f53abcbdSMichael Pfeiffer 	if (defaultItem != NULL)
593f53abcbdSMichael Pfeiffer 		defaultItem->SetMarked(true);
594f53abcbdSMichael Pfeiffer 	else if (firstItem != NULL)
595f53abcbdSMichael Pfeiffer 		firstItem->SetMarked(true);
596f53abcbdSMichael Pfeiffer }
597f53abcbdSMichael Pfeiffer 
598f53abcbdSMichael Pfeiffer 
599*de18d919SMichael Pfeiffer void
600*de18d919SMichael Pfeiffer JobSetupView::FillCapabilityMenu(BPopUpMenu* menu, uint32 message,
601*de18d919SMichael Pfeiffer 	PrinterCap::CapID category, int id)
602*de18d919SMichael Pfeiffer {
603*de18d919SMichael Pfeiffer 	PrinterCap::IDPredicate predicate(id);
604*de18d919SMichael Pfeiffer 	int count = fPrinterCap->countCap(category);
605*de18d919SMichael Pfeiffer 	const BaseCap **capabilities = fPrinterCap->enumCap(category);
606*de18d919SMichael Pfeiffer 	FillCapabilityMenu(menu, message, capabilities, count, predicate);
607*de18d919SMichael Pfeiffer }
608*de18d919SMichael Pfeiffer 
609*de18d919SMichael Pfeiffer 
610*de18d919SMichael Pfeiffer void
611*de18d919SMichael Pfeiffer JobSetupView::FillCapabilityMenu(BPopUpMenu* menu, uint32 message,
612*de18d919SMichael Pfeiffer 	const BaseCap** capabilities, int count, int id)
613*de18d919SMichael Pfeiffer {
614*de18d919SMichael Pfeiffer 	PrinterCap::IDPredicate predicate(id);
615*de18d919SMichael Pfeiffer 	FillCapabilityMenu(menu, message, capabilities, count, predicate);
616*de18d919SMichael Pfeiffer }
617*de18d919SMichael Pfeiffer 
618*de18d919SMichael Pfeiffer 
619f53abcbdSMichael Pfeiffer int
620f53abcbdSMichael Pfeiffer JobSetupView::GetID(const BaseCap** capabilities, int count, const char* label,
621f53abcbdSMichael Pfeiffer 	int defaultValue)
622f53abcbdSMichael Pfeiffer {
623f53abcbdSMichael Pfeiffer 	while (count--) {
624f53abcbdSMichael Pfeiffer 		const BaseCap* capability = *capabilities;
625f53abcbdSMichael Pfeiffer 		if (capability->fLabel == label)
626f53abcbdSMichael Pfeiffer 			return capability->ID();
627f53abcbdSMichael Pfeiffer 	}
628f53abcbdSMichael Pfeiffer 	return defaultValue;
629f53abcbdSMichael Pfeiffer }
630f53abcbdSMichael Pfeiffer 
631f53abcbdSMichael Pfeiffer 
632f53abcbdSMichael Pfeiffer void
63312fd6cc2SKarsten Heimrich JobSetupView::UpdateButtonEnabledState()
63412fd6cc2SKarsten Heimrich {
63512fd6cc2SKarsten Heimrich 	bool pageRangeEnabled = fAll->Value() != B_CONTROL_ON;
63612fd6cc2SKarsten Heimrich 	fFromPage->SetEnabled(pageRangeEnabled);
63712fd6cc2SKarsten Heimrich 	fToPage->SetEnabled(pageRangeEnabled);
63812fd6cc2SKarsten Heimrich 
63912fd6cc2SKarsten Heimrich 	bool pageSelectionEnabled = fDuplex == NULL ||
64012fd6cc2SKarsten Heimrich 		fDuplex->Value() != B_CONTROL_ON;
64112fd6cc2SKarsten Heimrich 	fAllPages->SetEnabled(pageSelectionEnabled);
64212fd6cc2SKarsten Heimrich 	fOddNumberedPages->SetEnabled(pageSelectionEnabled);
64312fd6cc2SKarsten Heimrich 	fEvenNumberedPages->SetEnabled(pageSelectionEnabled);
64412fd6cc2SKarsten Heimrich }
64512fd6cc2SKarsten Heimrich 
646a7dde370SMichael Pfeiffer 
64712fd6cc2SKarsten Heimrich void
64856c20e82SMichael Pfeiffer JobSetupView::MessageReceived(BMessage* message)
64912fd6cc2SKarsten Heimrich {
65056c20e82SMichael Pfeiffer 	switch (message->what) {
65112fd6cc2SKarsten Heimrich 	case kMsgRangeAll:
65212fd6cc2SKarsten Heimrich 	case kMsgRangeSelection:
65312fd6cc2SKarsten Heimrich 	case kMsgDuplexChanged:
65412fd6cc2SKarsten Heimrich 		UpdateButtonEnabledState();
65512fd6cc2SKarsten Heimrich 		break;
65612fd6cc2SKarsten Heimrich 
65712fd6cc2SKarsten Heimrich 	case kMsgQuality:
658308f0e19SMichael Pfeiffer 		UpdateHalftonePreview();
65912fd6cc2SKarsten Heimrich 		break;
66012fd6cc2SKarsten Heimrich 
66112fd6cc2SKarsten Heimrich 	case kMsgCollateChanged:
66212fd6cc2SKarsten Heimrich 		fPages->setCollate(fCollate->Value() == B_CONTROL_ON);
66312fd6cc2SKarsten Heimrich 		break;
66412fd6cc2SKarsten Heimrich 
66512fd6cc2SKarsten Heimrich 	case kMsgReverseChanged:
66612fd6cc2SKarsten Heimrich 		fPages->setReverse(fReverse->Value() == B_CONTROL_ON);
66712fd6cc2SKarsten Heimrich 		break;
66812fd6cc2SKarsten Heimrich 	}
66912fd6cc2SKarsten Heimrich }
67012fd6cc2SKarsten Heimrich 
671a7dde370SMichael Pfeiffer 
672308f0e19SMichael Pfeiffer void
673308f0e19SMichael Pfeiffer JobSetupView::UpdateHalftonePreview()
674308f0e19SMichael Pfeiffer {
675308f0e19SMichael Pfeiffer 	if (!IsHalftoneConfigurationNeeded())
676308f0e19SMichael Pfeiffer 		return;
677308f0e19SMichael Pfeiffer 
678308f0e19SMichael Pfeiffer 	fHalftone->preview(Gamma(), InkDensity(), DitherType(),
679308f0e19SMichael Pfeiffer 		Color() != JobData::kMonochrome);
680308f0e19SMichael Pfeiffer }
681308f0e19SMichael Pfeiffer 
682308f0e19SMichael Pfeiffer 
68312fd6cc2SKarsten Heimrich JobData::Color
684f53abcbdSMichael Pfeiffer JobSetupView::Color()
68512fd6cc2SKarsten Heimrich {
686f53abcbdSMichael Pfeiffer 	const char *label = fColorType->FindMarked()->Label();
687f53abcbdSMichael Pfeiffer 	const BaseCap* capability = fPrinterCap->findCap(PrinterCap::kColor, label);
688f53abcbdSMichael Pfeiffer 	if (capability == NULL)
68912fd6cc2SKarsten Heimrich 		return JobData::kMonochrome;
690f53abcbdSMichael Pfeiffer 
691f53abcbdSMichael Pfeiffer 	const ColorCap* colorCap = static_cast<const ColorCap*>(capability);
692f53abcbdSMichael Pfeiffer 	return colorCap->fColor;
69312fd6cc2SKarsten Heimrich }
69412fd6cc2SKarsten Heimrich 
695a7dde370SMichael Pfeiffer 
69612fd6cc2SKarsten Heimrich Halftone::DitherType
697f53abcbdSMichael Pfeiffer JobSetupView::DitherType()
69812fd6cc2SKarsten Heimrich {
699f53abcbdSMichael Pfeiffer 	const char *label = fDitherType->FindMarked()->Label();
700f53abcbdSMichael Pfeiffer 	int id = GetID(gDitherTypes, sizeof(gDitherTypes) / sizeof(gDitherTypes[0]),
701f53abcbdSMichael Pfeiffer 		label, Halftone::kTypeFloydSteinberg);
702f53abcbdSMichael Pfeiffer 	return static_cast<Halftone::DitherType>(id);
70312fd6cc2SKarsten Heimrich }
70412fd6cc2SKarsten Heimrich 
70512fd6cc2SKarsten Heimrich float
706f53abcbdSMichael Pfeiffer JobSetupView::Gamma()
70712fd6cc2SKarsten Heimrich {
70812fd6cc2SKarsten Heimrich 	const float value = (float)fGamma->Value();
70912fd6cc2SKarsten Heimrich 	return pow(2.0, value / 100.0);
71012fd6cc2SKarsten Heimrich }
71112fd6cc2SKarsten Heimrich 
712a7dde370SMichael Pfeiffer 
71312fd6cc2SKarsten Heimrich float
714f53abcbdSMichael Pfeiffer JobSetupView::InkDensity()
71512fd6cc2SKarsten Heimrich {
71612fd6cc2SKarsten Heimrich 	const float value = (float)(127 - fInkDensity->Value());
71712fd6cc2SKarsten Heimrich 	return value;
71812fd6cc2SKarsten Heimrich }
71912fd6cc2SKarsten Heimrich 
720a7dde370SMichael Pfeiffer 
721f53abcbdSMichael Pfeiffer JobData::PaperSource
722f53abcbdSMichael Pfeiffer JobSetupView::PaperSource()
723f53abcbdSMichael Pfeiffer {
724f53abcbdSMichael Pfeiffer 	const char *label = fPaperFeed->FindMarked()->Label();
725f53abcbdSMichael Pfeiffer 	const BaseCap* capability = fPrinterCap->findCap(PrinterCap::kPaperSource,
726f53abcbdSMichael Pfeiffer 		label);
727f53abcbdSMichael Pfeiffer 
728f53abcbdSMichael Pfeiffer 	if (capability == NULL)
729f53abcbdSMichael Pfeiffer 		capability = fPrinterCap->getDefaultCap(PrinterCap::kPaperSource);
730f53abcbdSMichael Pfeiffer 	return static_cast<const PaperSourceCap*>(capability)->fPaperSource;
731f53abcbdSMichael Pfeiffer 
732f53abcbdSMichael Pfeiffer }
733f53abcbdSMichael Pfeiffer 
73412fd6cc2SKarsten Heimrich bool
73512fd6cc2SKarsten Heimrich JobSetupView::UpdateJobData(bool showPreview)
73612fd6cc2SKarsten Heimrich {
73712fd6cc2SKarsten Heimrich 	fJobData->setShowPreview(showPreview);
738f53abcbdSMichael Pfeiffer 	fJobData->setColor(Color());
739308f0e19SMichael Pfeiffer 	if (IsHalftoneConfigurationNeeded()) {
740f53abcbdSMichael Pfeiffer 		fJobData->setGamma(Gamma());
741f53abcbdSMichael Pfeiffer 		fJobData->setInkDensity(InkDensity());
742f53abcbdSMichael Pfeiffer 		fJobData->setDitherType(DitherType());
743308f0e19SMichael Pfeiffer 	}
74412fd6cc2SKarsten Heimrich 
74512fd6cc2SKarsten Heimrich 	int first_page;
74612fd6cc2SKarsten Heimrich 	int last_page;
74712fd6cc2SKarsten Heimrich 
74812fd6cc2SKarsten Heimrich 	if (B_CONTROL_ON == fAll->Value()) {
74912fd6cc2SKarsten Heimrich 		first_page = 1;
75012fd6cc2SKarsten Heimrich 		last_page  = -1;
75112fd6cc2SKarsten Heimrich 	} else {
75212fd6cc2SKarsten Heimrich 		first_page = atoi(fFromPage->Text());
75312fd6cc2SKarsten Heimrich 		last_page  = atoi(fToPage->Text());
75412fd6cc2SKarsten Heimrich 	}
75512fd6cc2SKarsten Heimrich 
75612fd6cc2SKarsten Heimrich 	fJobData->setFirstPage(first_page);
75712fd6cc2SKarsten Heimrich 	fJobData->setLastPage(last_page);
75812fd6cc2SKarsten Heimrich 
759f53abcbdSMichael Pfeiffer 	fJobData->setPaperSource(PaperSource());
76012fd6cc2SKarsten Heimrich 
761f53abcbdSMichael Pfeiffer 	fJobData->setNup(GetID(gNups, sizeof(gNups) / sizeof(gNups[0]),
762f53abcbdSMichael Pfeiffer 		fNup->FindMarked()->Label(), 1));
76312fd6cc2SKarsten Heimrich 
76412fd6cc2SKarsten Heimrich 	if (fPrinterCap->isSupport(PrinterCap::kPrintStyle)) {
765f53abcbdSMichael Pfeiffer 		fJobData->setPrintStyle((B_CONTROL_ON == fDuplex->Value())
766f53abcbdSMichael Pfeiffer 			? JobData::kDuplex : JobData::kSimplex);
76712fd6cc2SKarsten Heimrich 	}
76812fd6cc2SKarsten Heimrich 
76912fd6cc2SKarsten Heimrich 	fJobData->setCopies(atoi(fCopies->Text()));
77012fd6cc2SKarsten Heimrich 
77156c20e82SMichael Pfeiffer 	fJobData->setCollate(B_CONTROL_ON == fCollate->Value());
77256c20e82SMichael Pfeiffer 	fJobData->setReverse(B_CONTROL_ON == fReverse->Value());
77312fd6cc2SKarsten Heimrich 
77412fd6cc2SKarsten Heimrich 	JobData::PageSelection pageSelection = JobData::kAllPages;
77512fd6cc2SKarsten Heimrich 	if (fOddNumberedPages->Value() == B_CONTROL_ON)
77612fd6cc2SKarsten Heimrich 		pageSelection = JobData::kOddNumberedPages;
77712fd6cc2SKarsten Heimrich 	if (fEvenNumberedPages->Value() == B_CONTROL_ON)
77812fd6cc2SKarsten Heimrich 		pageSelection = JobData::kEvenNumberedPages;
77912fd6cc2SKarsten Heimrich 	fJobData->setPageSelection(pageSelection);
78012fd6cc2SKarsten Heimrich 
781*de18d919SMichael Pfeiffer 	std::map<PrinterCap::CapID, BPopUpMenu*>::iterator it =
782*de18d919SMichael Pfeiffer 		fDriverSpecificLists.begin();
783*de18d919SMichael Pfeiffer 	for(; it != fDriverSpecificLists.end(); it++) {
784*de18d919SMichael Pfeiffer 		PrinterCap::CapID category = it->first;
785*de18d919SMichael Pfeiffer 		BPopUpMenu* popUpMenu = it->second;
786*de18d919SMichael Pfeiffer 		const char* key = fPrinterCap->findCap(
787*de18d919SMichael Pfeiffer 			PrinterCap::kDriverSpecificCapabilities, (int)category)->Key();
788*de18d919SMichael Pfeiffer 		const char* label = popUpMenu->FindMarked()->Label();
789*de18d919SMichael Pfeiffer 		const char* value = fPrinterCap->findCap(category, label)->Key();
790*de18d919SMichael Pfeiffer 		fJobData->SetDriverSpecificSetting(key, value);
791*de18d919SMichael Pfeiffer 	}
792*de18d919SMichael Pfeiffer 
79312fd6cc2SKarsten Heimrich 	fJobData->save();
79412fd6cc2SKarsten Heimrich 	return true;
79512fd6cc2SKarsten Heimrich }
79612fd6cc2SKarsten Heimrich 
79712fd6cc2SKarsten Heimrich 
79856c20e82SMichael Pfeiffer JobSetupDlg::JobSetupDlg(JobData* jobData, PrinterData* printerData,
79956c20e82SMichael Pfeiffer 	const PrinterCap* printerCap)
800a7dde370SMichael Pfeiffer 	:
801a7dde370SMichael Pfeiffer 	DialogWindow(BRect(100, 100, 200, 200), "PrintJob Setup",
802a7dde370SMichael Pfeiffer 		B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,
8035a695bceSMichael Pfeiffer 		B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE
8045a695bceSMichael Pfeiffer 			| B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS)
80512fd6cc2SKarsten Heimrich {
80612fd6cc2SKarsten Heimrich 	SetResult(B_ERROR);
80712fd6cc2SKarsten Heimrich 	AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
80812fd6cc2SKarsten Heimrich 
80956c20e82SMichael Pfeiffer 	fJobSetup = new JobSetupView(jobData, printerData, printerCap);
8105a695bceSMichael Pfeiffer 	SetLayout(new BGroupLayout(B_VERTICAL));
8115a695bceSMichael Pfeiffer 	AddChild(BGroupLayoutBuilder(B_VERTICAL, 0)
8125a695bceSMichael Pfeiffer 		.Add(fJobSetup)
8135a695bceSMichael Pfeiffer 		.SetInsets(10, 10, 10, 10)
8145a695bceSMichael Pfeiffer 	);
81512fd6cc2SKarsten Heimrich }
81612fd6cc2SKarsten Heimrich 
817a7dde370SMichael Pfeiffer 
81812fd6cc2SKarsten Heimrich void
81956c20e82SMichael Pfeiffer JobSetupDlg::MessageReceived(BMessage* message)
82012fd6cc2SKarsten Heimrich {
82156c20e82SMichael Pfeiffer 	switch (message->what) {
82212fd6cc2SKarsten Heimrich 	case kMsgOK:
82312fd6cc2SKarsten Heimrich 	case kMsgPreview:
82456c20e82SMichael Pfeiffer 		fJobSetup->UpdateJobData(message->what == kMsgPreview);
82512fd6cc2SKarsten Heimrich 		SetResult(B_NO_ERROR);
82612fd6cc2SKarsten Heimrich 		PostMessage(B_QUIT_REQUESTED);
82712fd6cc2SKarsten Heimrich 		break;
82812fd6cc2SKarsten Heimrich 
82912fd6cc2SKarsten Heimrich 	case kMsgCancel:
83012fd6cc2SKarsten Heimrich 		PostMessage(B_QUIT_REQUESTED);
83112fd6cc2SKarsten Heimrich 		break;
83212fd6cc2SKarsten Heimrich 
83312fd6cc2SKarsten Heimrich 	default:
83456c20e82SMichael Pfeiffer 		DialogWindow::MessageReceived(message);
83512fd6cc2SKarsten Heimrich 		break;
83612fd6cc2SKarsten Heimrich 	}
83712fd6cc2SKarsten Heimrich }
838