1 /* 2 * Copyright 1999-2000 Y.Takagi. All Rights Reserved. 3 * 4 * Copyright 2010, Haiku. All rights reserved. 5 * Distributed under the terms of the MIT License. 6 * 7 * Authors: 8 * Michael Pfeiffer 9 */ 10 11 12 #include "GPCapabilities.h" 13 14 #include "GPBinding.h" 15 #include "GPData.h" 16 #include "PrinterData.h" 17 18 19 GPCapabilities::GPCapabilities(const PrinterData* printer_data) 20 : 21 PrinterCap(printer_data) 22 { 23 InitCapabilitiesFromGutenprint(); 24 } 25 26 27 GPCapabilities::~GPCapabilities() 28 { 29 } 30 31 int 32 GPCapabilities::CountCap(CapID category) const 33 { 34 const GPArray<struct BaseCap>* capabilities; 35 36 switch (category) { 37 case kPaper: 38 return fPageSizes.Size(); 39 case kPaperSource: 40 return fInputSlots.Size(); 41 case kResolution: 42 return fResolutions.Size(); 43 case kColor: 44 return fPrintingModes.Size(); 45 case kDriverSpecificCapabilities: 46 return fDriverSpecificCategories.Size(); 47 48 default: 49 capabilities = DriverSpecificCapabilities(category); 50 if (capabilities == NULL) 51 return 0; 52 return capabilities->Size(); 53 } 54 } 55 56 57 const BaseCap** 58 GPCapabilities::GetCaps(CapID category) const 59 { 60 typedef const BaseCap** ArrayType; 61 const GPArray<struct BaseCap>* capabilities; 62 63 switch (category) { 64 case kPaper: 65 return (ArrayType)fPageSizes.Array(); 66 case kPaperSource: 67 return (ArrayType)fInputSlots.Array(); 68 case kResolution: 69 return (ArrayType)fResolutions.Array(); 70 case kColor: 71 return (ArrayType)fPrintingModes.Array(); 72 case kDriverSpecificCapabilities: 73 return (ArrayType)fDriverSpecificCategories.Array(); 74 75 default: 76 capabilities = DriverSpecificCapabilities(category); 77 if (capabilities == NULL) 78 return NULL; 79 return (ArrayType)capabilities->Array(); 80 } 81 } 82 83 84 bool 85 GPCapabilities::Supports(CapID category) const 86 { 87 switch (category) { 88 case kPaper: 89 case kPaperSource: 90 case kResolution: 91 case kColor: 92 return true; 93 94 default: 95 return CountCap(category) > 0; 96 } 97 } 98 99 void 100 GPCapabilities::InitCapabilitiesFromGutenprint() 101 { 102 const GPData* data = dynamic_cast<const GPData*>(GetPrinterData()); 103 ASSERT(data != NULL); 104 // capabilities are available only after printer model 105 // has been selected 106 if (data->fGutenprintDriverName == "") 107 return; 108 109 110 GPBinding binding; 111 binding.GetCapabilities(data->fGutenprintDriverName.String(), this); 112 } 113 114 115 const GPArray<struct BaseCap>* 116 GPCapabilities::DriverSpecificCapabilities(int32 category) const 117 { 118 DriverSpecificCapabilitiesType::const_iterator it = 119 fDriverSpecificCapabilities.find(category); 120 if (it == fDriverSpecificCapabilities.end()) 121 return NULL; 122 return &it->second; 123 } 124 125