3 * Copyright 1999-2000 Y.Takagi. All Rights Reserved.
6 #include "PrinterCap.h"
7 #include "PrinterData.h"
9 BaseCap::BaseCap(const string
&label
)
22 BaseCap::Label() const
24 return fLabel
.c_str();
28 EnumCap::EnumCap(const string
&label
, bool isDefault
)
43 PaperCap::PaperCap(const string
&label
, bool isDefault
, JobData::Paper paper
,
44 const BRect
&paperRect
, const BRect
&physicalRect
)
46 EnumCap(label
, isDefault
),
48 fPaperRect(paperRect
),
49 fPhysicalRect(physicalRect
)
61 PaperSourceCap::PaperSourceCap(const string
&label
, bool isDefault
,
62 JobData::PaperSource paperSource
)
64 EnumCap(label
, isDefault
),
65 fPaperSource(paperSource
)
71 PaperSourceCap::ID() const
77 ResolutionCap::ResolutionCap(const string
&label
, bool isDefault
,
78 int32 id
, int xResolution
, int yResolution
)
80 EnumCap(label
, isDefault
),
82 fXResolution(xResolution
),
83 fYResolution(yResolution
)
89 ResolutionCap::ID() const
95 OrientationCap::OrientationCap(const string
&label
, bool isDefault
,
96 JobData::Orientation orientation
)
98 EnumCap(label
, isDefault
),
99 fOrientation(orientation
)
105 OrientationCap::ID() const
111 PrintStyleCap::PrintStyleCap(const string
&label
, bool isDefault
,
112 JobData::PrintStyle printStyle
)
114 EnumCap(label
, isDefault
),
115 fPrintStyle(printStyle
)
121 PrintStyleCap::ID() const
127 BindingLocationCap::BindingLocationCap(const string
&label
, bool isDefault
,
128 JobData::BindingLocation bindingLocation
)
130 EnumCap(label
, isDefault
),
131 fBindingLocation(bindingLocation
)
137 BindingLocationCap::ID() const
139 return fBindingLocation
;
143 ColorCap::ColorCap(const string
&label
, bool isDefault
, JobData::Color color
)
145 EnumCap(label
, isDefault
),
158 ProtocolClassCap::ProtocolClassCap(const string
&label
, bool isDefault
,
159 int32 protocolClass
, const string
&description
)
161 EnumCap(label
, isDefault
),
162 fProtocolClass(protocolClass
),
163 fDescription(description
)
169 ProtocolClassCap::ID() const
171 return fProtocolClass
;
175 DriverSpecificCap::DriverSpecificCap(const string
& label
, int32 category
,
178 EnumCap(label
, false),
186 DriverSpecificCap::ID() const
192 ListItemCap::ListItemCap(const string
& label
, bool isDefault
, int32 id
)
194 EnumCap(label
, isDefault
),
201 ListItemCap::ID() const
207 BooleanCap::BooleanCap(const string
& label
, bool defaultValue
)
210 fDefaultValue(defaultValue
)
216 BooleanCap::DefaultValue() const
218 return fDefaultValue
;
222 IntRangeCap::IntRangeCap(const string
& label
, int lower
, int upper
,
228 fDefaultValue(defaultValue
)
234 IntRangeCap::Lower() const
241 IntRangeCap::Upper() const
248 IntRangeCap::DefaultValue() const
250 return fDefaultValue
;
254 DoubleRangeCap::DoubleRangeCap(const string
& label
, double lower
, double upper
,
260 fDefaultValue(defaultValue
)
266 DoubleRangeCap::Lower() const
273 DoubleRangeCap::Upper() const
280 DoubleRangeCap::DefaultValue() const
282 return fDefaultValue
;
286 PrinterCap::PrinterCap(const PrinterData
*printer_data
)
288 fPrinterData(printer_data
)
293 PrinterCap::~PrinterCap()
299 PrinterCap::GetDefaultCap(CapID category
) const
301 int count
= CountCap(category
);
305 const BaseCap
**base_cap
= GetCaps(category
);
307 const EnumCap
* enumCap
= dynamic_cast<const EnumCap
*>(*base_cap
);
311 if (enumCap
->fIsDefault
) {
318 return static_cast<const EnumCap
*>(GetCaps(category
)[0]);
322 template<typename Predicate
>
324 PrinterCap::FindCap(CapID category
, Predicate
& predicate
) const
326 int count
= CountCap(category
);
330 const BaseCap
**base_cap
= GetCaps(category
);
332 if (predicate(*base_cap
)) {
342 PrinterCap::FindCap(CapID category
, int id
) const
344 IDPredicate
predicate(id
);
345 return static_cast<const EnumCap
*>(FindCap(category
, predicate
));
350 PrinterCap::FindCap(CapID category
, const char* label
) const
352 LabelPredicate
predicate(label
);
353 return FindCap(category
, predicate
);
358 PrinterCap::FindCapWithKey(CapID category
, const char* key
) const
360 KeyPredicate
predicate(key
);
361 return static_cast<const EnumCap
*>(FindCap(category
, predicate
));
366 PrinterCap::FindBooleanCap(CapID category
) const
368 if (CountCap(category
) != 1)
370 return dynamic_cast<const BooleanCap
*>(GetCaps(category
)[0]);
375 PrinterCap::FindIntRangeCap(CapID category
) const
377 if (CountCap(category
) != 1)
379 return dynamic_cast<const IntRangeCap
*>(GetCaps(category
)[0]);
383 const DoubleRangeCap
*
384 PrinterCap::FindDoubleRangeCap(CapID category
) const
386 if (CountCap(category
) != 1)
388 return dynamic_cast<const DoubleRangeCap
*>(GetCaps(category
)[0]);
393 PrinterCap::GetProtocolClass() const {
394 return fPrinterData
->GetProtocolClass();
399 PrinterCap::GetPrinterData() const