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