1 /* 2 * PrinterCap.cpp 3 * Copyright 1999-2000 Y.Takagi. All Rights Reserved. 4 */ 5 6 #include "PrinterCap.h" 7 #include "PrinterData.h" 8 9 BaseCap::BaseCap(const string &label) 10 : 11 fLabel(label) 12 { 13 } 14 15 16 BaseCap::~BaseCap() 17 { 18 } 19 20 21 const char* 22 BaseCap::Label() const 23 { 24 return fLabel.c_str(); 25 } 26 27 28 EnumCap::EnumCap(const string &label, bool isDefault) 29 : 30 BaseCap(label), 31 fIsDefault(isDefault) 32 { 33 } 34 35 36 const char* 37 EnumCap::Key() const 38 { 39 return fKey.c_str(); 40 } 41 42 43 PaperCap::PaperCap(const string &label, bool isDefault, JobData::Paper paper, 44 const BRect &paperRect, const BRect &physicalRect) 45 : 46 EnumCap(label, isDefault), 47 fPaper(paper), 48 fPaperRect(paperRect), 49 fPhysicalRect(physicalRect) 50 { 51 } 52 53 54 int32 55 PaperCap::ID() const 56 { 57 return fPaper; 58 } 59 60 61 PaperSourceCap::PaperSourceCap(const string &label, bool isDefault, 62 JobData::PaperSource paperSource) 63 : 64 EnumCap(label, isDefault), 65 fPaperSource(paperSource) 66 { 67 } 68 69 70 int32 71 PaperSourceCap::ID() const 72 { 73 return fPaperSource; 74 } 75 76 77 ResolutionCap::ResolutionCap(const string &label, bool isDefault, 78 int32 id, int xResolution, int yResolution) 79 : 80 EnumCap(label, isDefault), 81 fID(id), 82 fXResolution(xResolution), 83 fYResolution(yResolution) 84 { 85 } 86 87 88 int32 89 ResolutionCap::ID() const 90 { 91 return fID; 92 } 93 94 95 OrientationCap::OrientationCap(const string &label, bool isDefault, 96 JobData::Orientation orientation) 97 : 98 EnumCap(label, isDefault), 99 fOrientation(orientation) 100 { 101 } 102 103 104 int32 105 OrientationCap::ID() const 106 { 107 return fOrientation; 108 } 109 110 111 PrintStyleCap::PrintStyleCap(const string &label, bool isDefault, 112 JobData::PrintStyle printStyle) 113 : 114 EnumCap(label, isDefault), 115 fPrintStyle(printStyle) 116 { 117 } 118 119 120 int32 121 PrintStyleCap::ID() const 122 { 123 return fPrintStyle; 124 } 125 126 127 BindingLocationCap::BindingLocationCap(const string &label, bool isDefault, 128 JobData::BindingLocation bindingLocation) 129 : 130 EnumCap(label, isDefault), 131 fBindingLocation(bindingLocation) 132 { 133 } 134 135 136 int32 137 BindingLocationCap::ID() const 138 { 139 return fBindingLocation; 140 } 141 142 143 ColorCap::ColorCap(const string &label, bool isDefault, JobData::Color color) 144 : 145 EnumCap(label, isDefault), 146 fColor(color) 147 { 148 } 149 150 151 int32 152 ColorCap::ID() const 153 { 154 return fColor; 155 } 156 157 158 ProtocolClassCap::ProtocolClassCap(const string &label, bool isDefault, 159 int32 protocolClass, const string &description) 160 : 161 EnumCap(label, isDefault), 162 fProtocolClass(protocolClass), 163 fDescription(description) 164 { 165 } 166 167 168 int32 169 ProtocolClassCap::ID() const 170 { 171 return fProtocolClass; 172 } 173 174 175 DriverSpecificCap::DriverSpecificCap(const string& label, int32 category, 176 Type type) 177 : 178 EnumCap(label, false), 179 fCategory(category), 180 fType(type) 181 { 182 } 183 184 185 int32 186 DriverSpecificCap::ID() const 187 { 188 return fCategory; 189 } 190 191 192 ListItemCap::ListItemCap(const string& label, bool isDefault, int32 id) 193 : 194 EnumCap(label, isDefault), 195 fID(id) 196 { 197 } 198 199 200 int32 201 ListItemCap::ID() const 202 { 203 return fID; 204 } 205 206 207 BooleanCap::BooleanCap(const string& label, bool defaultValue) 208 : 209 BaseCap(label), 210 fDefaultValue(defaultValue) 211 { 212 } 213 214 215 bool 216 BooleanCap::DefaultValue() const 217 { 218 return fDefaultValue; 219 } 220 221 222 IntRangeCap::IntRangeCap(const string& label, int lower, int upper, 223 int defaultValue) 224 : 225 BaseCap(label), 226 fLower(lower), 227 fUpper(upper), 228 fDefaultValue(defaultValue) 229 { 230 } 231 232 233 int32 234 IntRangeCap::Lower() const 235 { 236 return fLower; 237 } 238 239 240 int32 241 IntRangeCap::Upper() const 242 { 243 return fUpper; 244 } 245 246 247 int32 248 IntRangeCap::DefaultValue() const 249 { 250 return fDefaultValue; 251 } 252 253 254 DoubleRangeCap::DoubleRangeCap(const string& label, double lower, double upper, 255 double defaultValue) 256 : 257 BaseCap(label), 258 fLower(lower), 259 fUpper(upper), 260 fDefaultValue(defaultValue) 261 { 262 } 263 264 265 double 266 DoubleRangeCap::Lower() const 267 { 268 return fLower; 269 } 270 271 272 double 273 DoubleRangeCap::Upper() const 274 { 275 return fUpper; 276 } 277 278 279 double 280 DoubleRangeCap::DefaultValue() const 281 { 282 return fDefaultValue; 283 } 284 285 286 PrinterCap::PrinterCap(const PrinterData *printer_data) 287 : 288 fPrinterData(printer_data) 289 { 290 } 291 292 293 PrinterCap::~PrinterCap() 294 { 295 } 296 297 298 const EnumCap* 299 PrinterCap::GetDefaultCap(CapID category) const 300 { 301 int count = CountCap(category); 302 if (count <= 0) 303 return NULL; 304 305 const BaseCap **base_cap = GetCaps(category); 306 while (count--) { 307 const EnumCap* enumCap = dynamic_cast<const EnumCap*>(*base_cap); 308 if (enumCap == NULL) 309 return NULL; 310 311 if (enumCap->fIsDefault) { 312 return enumCap; 313 } 314 315 base_cap++; 316 } 317 318 return static_cast<const EnumCap*>(GetCaps(category)[0]); 319 } 320 321 322 template<typename Predicate> 323 const BaseCap* 324 PrinterCap::FindCap(CapID category, Predicate& predicate) const 325 { 326 int count = CountCap(category); 327 if (count <= 0) 328 return NULL; 329 330 const BaseCap **base_cap = GetCaps(category); 331 while (count--) { 332 if (predicate(*base_cap)) { 333 return *base_cap; 334 } 335 base_cap++; 336 } 337 return NULL; 338 339 } 340 341 const EnumCap* 342 PrinterCap::FindCap(CapID category, int id) const 343 { 344 IDPredicate predicate(id); 345 return static_cast<const EnumCap*>(FindCap(category, predicate)); 346 } 347 348 349 const BaseCap* 350 PrinterCap::FindCap(CapID category, const char* label) const 351 { 352 LabelPredicate predicate(label); 353 return FindCap(category, predicate); 354 } 355 356 357 const EnumCap* 358 PrinterCap::FindCapWithKey(CapID category, const char* key) const 359 { 360 KeyPredicate predicate(key); 361 return static_cast<const EnumCap*>(FindCap(category, predicate)); 362 } 363 364 365 const BooleanCap* 366 PrinterCap::FindBooleanCap(CapID category) const 367 { 368 if (CountCap(category) != 1) 369 return NULL; 370 return dynamic_cast<const BooleanCap*>(GetCaps(category)[0]); 371 } 372 373 374 const IntRangeCap* 375 PrinterCap::FindIntRangeCap(CapID category) const 376 { 377 if (CountCap(category) != 1) 378 return NULL; 379 return dynamic_cast<const IntRangeCap*>(GetCaps(category)[0]); 380 } 381 382 383 const DoubleRangeCap* 384 PrinterCap::FindDoubleRangeCap(CapID category) const 385 { 386 if (CountCap(category) != 1) 387 return NULL; 388 return dynamic_cast<const DoubleRangeCap*>(GetCaps(category)[0]); 389 } 390 391 392 int 393 PrinterCap::GetProtocolClass() const { 394 return fPrinterData->GetProtocolClass(); 395 } 396 397 398 const PrinterData* 399 PrinterCap::GetPrinterData() const 400 { 401 return fPrinterData; 402 } 403