1/* 2 * PrinterCap.h 3 * Copyright 1999-2000 Y.Takagi. All Rights Reserved. 4 */ 5 6#ifndef __PRINTERCAP_H 7#define __PRINTERCAP_H 8 9#include <string> 10#include <Rect.h> 11#include "JobData.h" 12 13using namespace std; 14 15enum { 16 kUnknownPrinter = 0 17}; 18 19struct BaseCap { 20 BaseCap(const string &label); 21 virtual ~BaseCap(); 22 23 const char* Label() const; 24 25 string fLabel; 26}; 27 28struct EnumCap : public BaseCap { 29 EnumCap(const string& label, bool isDefault); 30 31 virtual int32 ID() const = 0; 32 const char* Key() const; 33 34 bool fIsDefault; 35 string fKey; 36}; 37 38 39struct PaperCap : public EnumCap { 40 PaperCap(const string &label, bool isDefault, 41 JobData::Paper paper, const BRect &paperRect, 42 const BRect &physicalRect); 43 44 int32 ID() const; 45 46 JobData::Paper fPaper; 47 BRect fPaperRect; 48 BRect fPhysicalRect; 49}; 50 51struct PaperSourceCap : public EnumCap { 52 PaperSourceCap(const string &label, bool isDefault, 53 JobData::PaperSource paperSource); 54 55 int32 ID() const; 56 57 JobData::PaperSource fPaperSource; 58}; 59 60struct ResolutionCap : public EnumCap { 61 ResolutionCap(const string &label, bool isDefault, 62 int32 id, int xResolution, int yResolution); 63 64 int32 ID() const; 65 66 int32 fID; 67 int fXResolution; 68 int fYResolution; 69}; 70 71struct OrientationCap : public EnumCap { 72 OrientationCap(const string &label, bool isDefault, 73 JobData::Orientation orientation); 74 75 int32 ID() const; 76 77 JobData::Orientation fOrientation; 78}; 79 80struct PrintStyleCap : public EnumCap { 81 PrintStyleCap(const string &label, bool isDefault, 82 JobData::PrintStyle printStyle); 83 84 int32 ID() const; 85 86 JobData::PrintStyle fPrintStyle; 87}; 88 89struct BindingLocationCap : public EnumCap { 90 BindingLocationCap(const string &label, 91 bool isDefault, 92 JobData::BindingLocation bindingLocation); 93 94 int32 ID() const; 95 96 JobData::BindingLocation fBindingLocation; 97}; 98 99struct ColorCap : public EnumCap { 100 ColorCap(const string &label, bool isDefault, 101 JobData::Color color); 102 103 int32 ID() const; 104 105 JobData::Color fColor; 106}; 107 108struct ProtocolClassCap : public EnumCap { 109 ProtocolClassCap(const string &label, 110 bool isDefault, int32 protocolClass, 111 const string &description); 112 113 int32 ID() const; 114 115 int32 fProtocolClass; 116 string fDescription; 117}; 118 119 120struct DriverSpecificCap : public EnumCap { 121 enum Type { 122 kList, 123 kBoolean, 124 kIntRange, 125 kIntDimension, 126 kDoubleRange 127 }; 128 129 DriverSpecificCap(const string& label, 130 int32 category, Type type); 131 132 int32 ID() const; 133 134 int32 fCategory; 135 Type fType; 136}; 137 138struct ListItemCap : public EnumCap { 139 ListItemCap(const string& label, 140 bool isDefault, int32 id); 141 142 int32 ID() const; 143 144private: 145 int32 fID; 146}; 147 148struct BooleanCap : public BaseCap { 149 BooleanCap(const string& label, bool defaultValue); 150 151 bool DefaultValue() const; 152 153private: 154 bool fDefaultValue; 155}; 156 157struct IntRangeCap : public BaseCap { 158 IntRangeCap(const string& label, int lower, 159 int upper, int defaultValue); 160 161 int32 Lower() const; 162 int32 Upper() const; 163 int32 DefaultValue() const; 164 165private: 166 int32 fLower; 167 int32 fUpper; 168 int32 fDefaultValue; 169}; 170 171struct DoubleRangeCap : public BaseCap { 172 DoubleRangeCap(const string& label, double lower, 173 double upper, double defaultValue); 174 175 double Lower() const; 176 double Upper() const; 177 double DefaultValue() const; 178 179 double fLower; 180 double fUpper; 181 double fDefaultValue; 182}; 183 184class PrinterData; 185 186class PrinterCap { 187public: 188 PrinterCap(const PrinterData *printer_data); 189 virtual ~PrinterCap(); 190 191 enum CapID { 192 kPaper, 193 kPaperSource, 194 kResolution, 195 kOrientation, 196 kPrintStyle, 197 kBindingLocation, 198 kColor, 199 kProtocolClass, 200 kDriverSpecificCapabilities, 201 202 // Static boolean settings follow. 203 // For them Supports() has to be implemented only. 204 kCopyCommand, // supports printer page copy command? 205 kHalftone, // needs the printer driver the configuration 206 // for class Halftone? 207 kCanRotatePageInLandscape, 208 // can the printer driver rotate the page 209 // printing in landscape 210 211 // The driver specific generic capabilities start here 212 kDriverSpecificCapabilitiesBegin = 100 213 }; 214 215 struct IDPredicate 216 { 217 IDPredicate(int id) 218 : fID(id) 219 { 220 } 221 222 223 bool operator()(const BaseCap* baseCap) { 224 const EnumCap* enumCap = dynamic_cast<const EnumCap*>(baseCap); 225 if (enumCap == NULL) 226 return false; 227 return enumCap->ID() == fID; 228 } 229 230 int fID; 231 }; 232 233 struct LabelPredicate 234 { 235 LabelPredicate(const char* label) 236 : fLabel(label) 237 { 238 } 239 240 241 bool operator()(const BaseCap* baseCap) { 242 return baseCap->fLabel == fLabel; 243 } 244 245 const char* fLabel; 246 247 }; 248 249 struct KeyPredicate 250 { 251 KeyPredicate(const char* key) 252 : fKey(key) 253 { 254 } 255 256 257 bool operator()(const BaseCap* baseCap) { 258 const EnumCap* enumCap = dynamic_cast<const EnumCap*>(baseCap); 259 if (enumCap == NULL) 260 return false; 261 return enumCap->fKey == fKey; 262 } 263 264 const char* fKey; 265 266 }; 267 268 virtual int CountCap(CapID category) const = 0; 269 virtual bool Supports(CapID category) const = 0; 270 virtual const BaseCap** GetCaps(CapID category) const = 0; 271 272 const EnumCap* GetDefaultCap(CapID category) const; 273 const EnumCap* FindCap(CapID category, int id) const; 274 const BaseCap* FindCap(CapID category, const char* label) const; 275 const EnumCap* FindCapWithKey(CapID category, const char* key) 276 const; 277 278 const BooleanCap* FindBooleanCap(CapID category) const; 279 const IntRangeCap* FindIntRangeCap(CapID category) const; 280 const DoubleRangeCap* FindDoubleRangeCap(CapID category) const; 281 282 int GetProtocolClass() const; 283 284protected: 285 PrinterCap(const PrinterCap& printerCap); 286 PrinterCap& operator=(const PrinterCap& printerCap); 287 template<typename Predicate> 288 const BaseCap* FindCap(CapID category, Predicate& predicate) const; 289 290 const PrinterData* GetPrinterData() const; 291 292private: 293 const PrinterData* fPrinterData; 294}; 295 296 297 298 299#endif /* __PRINTERCAP_H */ 300