1 /*
2 * JobSetupDlg.cpp
3 * Copyright 1999-2000 Y.Takagi. All Rights Reserved.
4 */
5
6 #ifndef __JOBSETUPDLG_H
7 #define __JOBSETUPDLG_H
8
9 #include <View.h>
10 #include <map>
11
12 #include "DialogWindow.h"
13
14 #include "JobData.h"
15 #include "Halftone.h"
16 #include "JSDSlider.h"
17 #include "PrinterCap.h"
18
19 class BCheckBox;
20 class BGridLayout;
21 class BPopUpMenu;
22 class BRadioButton;
23 class BSlider;
24 class BTextControl;
25 class BTextView;
26 class HalftoneView;
27 class JobData;
28 class PagesView;
29 class PrinterCap;
30 class PrinterData;
31
32
33 template<typename T, typename R>
34 class Range
35 {
36 public:
37 Range();
38 Range(const char* label, const char* key, const R* range, BSlider* slider);
39 const char* Key() const;
40 T Value();
41 void UpdateLabel();
42
43 private:
44 const char* fLabel;
45 const char* fKey;
46 const R* fRange;
47 BSlider* fSlider;
48 };
49
50
51 template<typename T, typename R>
Range()52 Range<T, R>::Range()
53 :
54 fKey(NULL),
55 fRange(NULL),
56 fSlider(NULL)
57 {
58 }
59
60
61 template<typename T, typename R>
Range(const char * label,const char * key,const R * range,BSlider * slider)62 Range<T, R>::Range(const char* label, const char* key, const R* range,
63 BSlider* slider)
64 :
65 fLabel(label),
66 fKey(key),
67 fRange(range),
68 fSlider(slider)
69 {
70
71 }
72
73
74 template<typename T, typename R>
75 const char*
Key()76 Range<T, R>::Key() const
77 {
78 return fKey;
79 }
80
81
82 template<typename T, typename R>
83 T
Value()84 Range<T, R>::Value()
85 {
86 return static_cast<T>(fRange->Lower() +
87 (fRange->Upper() - fRange->Lower()) * fSlider->Position());
88 }
89
90
91 template<typename T, typename R>
92 void
UpdateLabel()93 Range<T, R>::UpdateLabel()
94 {
95 BString label = fLabel;
96 label << " (" << Value() << ")";
97 fSlider->SetLabel(label.String());
98 }
99
100
101 typedef Range<int32, IntRangeCap> IntRange;
102 typedef Range<double, DoubleRangeCap> DoubleRange;
103
104 class JobSetupView : public BView {
105 public:
106 JobSetupView(JobData* jobData, PrinterData* printerData,
107 const PrinterCap* printerCap);
108 virtual void AttachedToWindow();
109 virtual void MessageReceived(BMessage* message);
110 bool UpdateJobData();
111
112 private:
113 void UpdateButtonEnabledState();
114 bool IsHalftoneConfigurationNeeded();
115 void CreateHalftoneConfigurationUI();
116 void AddDriverSpecificSettings(BGridLayout* gridLayout, int row);
117 void AddPopUpMenu(const DriverSpecificCap* capability,
118 BGridLayout* gridLayout, int& row);
119 void AddCheckBox(const DriverSpecificCap* capability,
120 BGridLayout* gridLayout, int& row);
121 void AddIntSlider(const DriverSpecificCap* capability,
122 BGridLayout* gridLayout, int& row);
123 void AddDoubleSlider(const DriverSpecificCap* capability,
124 BGridLayout* gridLayout, int& row);
125 string GetDriverSpecificValue(PrinterCap::CapID category,
126 const char* key);
127 template<typename Predicate>
128 void FillCapabilityMenu(BPopUpMenu* menu, uint32 message,
129 const BaseCap** capabilities, int count,
130 Predicate& predicate);
131 void FillCapabilityMenu(BPopUpMenu* menu, uint32 message,
132 PrinterCap::CapID category, int id);
133 void FillCapabilityMenu(BPopUpMenu* menu, uint32 message,
134 const BaseCap** capabilities, int count, int id);
135 int GetID(const BaseCap** capabilities, int count,
136 const char* label, int defaultValue);
137 BRadioButton* CreatePageSelectionItem(const char* name,
138 const char* label,
139 JobData::PageSelection pageSelection);
140 void AllowOnlyDigits(BTextView* textView, int maxDigits);
141 void UpdateHalftonePreview();
142 void UpdateIntSlider(BMessage* message);
143 void UpdateDoubleSlider(BMessage* message);
144
145 JobData::Color Color();
146 Halftone::DitherType DitherType();
147 float Gamma();
148 float InkDensity();
149 JobData::PaperSource PaperSource();
150
151
152 BTextControl* fCopies;
153 BTextControl* fFromPage;
154 BTextControl* fToPage;
155 JobData* fJobData;
156 PrinterData* fPrinterData;
157 const PrinterCap* fPrinterCap;
158 BPopUpMenu* fColorType;
159 BPopUpMenu* fDitherType;
160 BMenuField* fDitherMenuField;
161 JSDSlider* fGamma;
162 JSDSlider* fInkDensity;
163 HalftoneView* fHalftone;
164 BBox* fHalftoneBox;
165 BRadioButton* fAll;
166 BCheckBox* fCollate;
167 BCheckBox* fReverse;
168 PagesView* fPages;
169 BPopUpMenu* fPaperFeed;
170 BCheckBox* fDuplex;
171 BPopUpMenu* fNup;
172 BRadioButton* fAllPages;
173 BRadioButton* fOddNumberedPages;
174 BRadioButton* fEvenNumberedPages;
175 std::map<PrinterCap::CapID, BPopUpMenu*> fDriverSpecificPopUpMenus;
176 std::map<string, BCheckBox*> fDriverSpecificCheckBoxes;
177 std::map<PrinterCap::CapID, IntRange> fDriverSpecificIntSliders;
178 std::map<PrinterCap::CapID, DoubleRange> fDriverSpecificDoubleSliders;
179 BCheckBox* fPreview;
180 };
181
182 class JobSetupDlg : public DialogWindow {
183 public:
184 JobSetupDlg(JobData* jobData, PrinterData* printerData,
185 const PrinterCap* printerCap);
186 virtual void MessageReceived(BMessage* message);
187
188 private:
189 JobSetupView* fJobSetup;
190 };
191
192 #endif /* __JOBSETUPDLG_H */
193