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, bool isDefault) 10 : 11 fLabel(label), 12 fIsDefault(isDefault) 13 { 14 } 15 16 17 BaseCap::~BaseCap() 18 { 19 } 20 21 22 const char* 23 BaseCap::Key() const 24 { 25 return fKey.c_str(); 26 } 27 28 29 PaperCap::PaperCap(const string &label, bool isDefault, JobData::Paper paper, 30 const BRect &paperRect, const BRect &physicalRect) 31 : 32 BaseCap(label, isDefault), 33 fPaper(paper), 34 fPaperRect(paperRect), 35 fPhysicalRect(physicalRect) 36 { 37 } 38 39 40 int32 41 PaperCap::ID() const 42 { 43 return fPaper; 44 } 45 46 47 PaperSourceCap::PaperSourceCap(const string &label, bool isDefault, 48 JobData::PaperSource paperSource) 49 : 50 BaseCap(label, isDefault), 51 fPaperSource(paperSource) 52 { 53 } 54 55 56 int32 57 PaperSourceCap::ID() const 58 { 59 return fPaperSource; 60 } 61 62 63 ResolutionCap::ResolutionCap(const string &label, bool isDefault, 64 int32 id, int xResolution, int yResolution) 65 : 66 BaseCap(label, isDefault), 67 fID(id), 68 fXResolution(xResolution), 69 fYResolution(yResolution) 70 { 71 } 72 73 74 int32 75 ResolutionCap::ID() const 76 { 77 return fID; 78 } 79 80 81 OrientationCap::OrientationCap(const string &label, bool isDefault, 82 JobData::Orientation orientation) 83 : 84 BaseCap(label, isDefault), 85 fOrientation(orientation) 86 { 87 } 88 89 90 int32 91 OrientationCap::ID() const 92 { 93 return fOrientation; 94 } 95 96 97 PrintStyleCap::PrintStyleCap(const string &label, bool isDefault, 98 JobData::PrintStyle printStyle) 99 : 100 BaseCap(label, isDefault), 101 fPrintStyle(printStyle) 102 { 103 } 104 105 106 int32 107 PrintStyleCap::ID() const 108 { 109 return fPrintStyle; 110 } 111 112 113 BindingLocationCap::BindingLocationCap(const string &label, bool isDefault, 114 JobData::BindingLocation bindingLocation) 115 : 116 BaseCap(label, isDefault), 117 fBindingLocation(bindingLocation) 118 { 119 } 120 121 122 int32 123 BindingLocationCap::ID() const 124 { 125 return fBindingLocation; 126 } 127 128 129 ColorCap::ColorCap(const string &label, bool isDefault, JobData::Color color) 130 : 131 BaseCap(label, isDefault), 132 fColor(color) 133 { 134 } 135 136 137 int32 138 ColorCap::ID() const 139 { 140 return fColor; 141 } 142 143 144 ProtocolClassCap::ProtocolClassCap(const string &label, bool isDefault, 145 int32 protocolClass, const string &description) 146 : 147 BaseCap(label, isDefault), 148 fProtocolClass(protocolClass), 149 fDescription(description) 150 { 151 } 152 153 154 int32 155 ProtocolClassCap::ID() const 156 { 157 return fProtocolClass; 158 } 159 160 161 DriverSpecificCap::DriverSpecificCap(const string& label, bool isDefault, 162 int32 category, Type type) 163 : 164 BaseCap(label, isDefault), 165 fCategory(category), 166 fType(type) 167 { 168 } 169 170 171 int32 172 DriverSpecificCap::ID() const 173 { 174 return fCategory; 175 } 176 177 178 PrinterCap::PrinterCap(const PrinterData *printer_data) 179 : 180 fPrinterData(printer_data) 181 { 182 } 183 184 185 PrinterCap::~PrinterCap() 186 { 187 } 188 189 190 const BaseCap* 191 PrinterCap::getDefaultCap(CapID category) const 192 { 193 int count = countCap(category); 194 if (count <= 0) 195 return NULL; 196 197 const BaseCap **base_cap = enumCap(category); 198 while (count--) { 199 if ((*base_cap)->fIsDefault) { 200 return *base_cap; 201 } 202 base_cap++; 203 } 204 205 return enumCap(category)[0]; 206 } 207 208 209 const BaseCap* 210 PrinterCap::findCap(CapID category, int id) const 211 { 212 int count = countCap(category); 213 if (count <= 0) 214 return NULL; 215 216 const BaseCap **base_cap = enumCap(category); 217 while (count--) { 218 if ((*base_cap)->ID() == id) { 219 return *base_cap; 220 } 221 base_cap++; 222 } 223 return NULL; 224 } 225 226 227 const BaseCap* 228 PrinterCap::findCap(CapID category, const char* label) const 229 { 230 int count = countCap(category); 231 if (count <= 0) 232 return NULL; 233 234 const BaseCap **base_cap = enumCap(category); 235 while (count--) { 236 if ((*base_cap)->fLabel == label) { 237 return *base_cap; 238 } 239 base_cap++; 240 } 241 return NULL; 242 243 } 244 245 int 246 PrinterCap::getProtocolClass() const { 247 return fPrinterData->getProtocolClass(); 248 } 249 250 251 const 252 PrinterData *PrinterCap::getPrinterData() const 253 { 254 return fPrinterData; 255 } 256