3 * Copyright 1999-2000 Y.Takagi. All Rights Reserved.
9 #include <InterfaceDefs.h>
14 #include "PrinterCap.h"
17 static const char *kJDXRes
= "xres";
18 static const char *kJDYRes
= "yres";
19 static const char *kJDCopies
= "copies";
20 static const char *kJDOrientation
= "orientation";
21 static const char *kJDScaling
= "scale";
22 static const char *kJDScaledPaperRect
= "paper_rect";
23 static const char *kJDScaledPrintableRect
= "printable_rect";
24 static const char *kJDFirstPage
= "first_page";
25 static const char *kJDLastPage
= "last_page";
27 static const char *kJDShowPreview
= "JJJJ_showPreview";
28 static const char *kJDPaper
= "JJJJ_paper";
29 static const char *kJDNup
= "JJJJ_nup";
30 static const char *kJDGamma
= "JJJJ_gamma";
31 static const char *kJDInkDensity
= "JJJJ_ink_density";
32 static const char *kJDPaperSource
= "JJJJ_paper_source";
33 static const char *kJDCollate
= "JJJJ_collate";
34 static const char *kJDReverse
= "JJJJ_reverse";
35 static const char *kJDPrintStyle
= "JJJJ_print_style";
36 static const char *kJDBindingLocation
= "JJJJ_binding_location";
37 static const char *kJDPageOrder
= "JJJJ_page_order";
38 static const char *kJDColor
= "JJJJ_color";
39 static const char *kJDDitherType
= "JJJJ_dither_type";
40 static const char *kJDPaperRect
= "JJJJ_paper_rect";
41 static const char* kJDPrintableRect
= "JJJJ_printable_rect";
42 static const char* kJDPageSelection
= "JJJJ_page_selection";
43 static const char* kJDMarginUnit
= "JJJJ_margin_unit";
44 static const char* kJDPhysicalRect
= "JJJJ_physical_rect";
45 static const char* kJDScaledPhysicalRect
= "JJJJ_scaled_physical_rect";
46 static const char* kJDResolution
= "JJJJ_resolution";
47 static const char* kJDDriverSpecificSettings
= "JJJJ_driverSpecificSettings";
50 DriverSpecificSettings::DriverSpecificSettings()
55 DriverSpecificSettings::DriverSpecificSettings(
56 const DriverSpecificSettings
& settings
)
58 fSettings(settings
.fSettings
)
63 DriverSpecificSettings
&
64 DriverSpecificSettings::operator=(const DriverSpecificSettings
&settings
)
66 fSettings
= settings
.fSettings
;
72 DriverSpecificSettings::MakeEmpty()
74 fSettings
.MakeEmpty();
79 DriverSpecificSettings::HasString(const char* key
) const
82 return fSettings
.FindString(key
, &value
) == B_OK
;
87 DriverSpecificSettings::GetString(const char* key
) const
89 ASSERT(HasString(key
));
90 const char* value
= NULL
;
91 fSettings
.FindString(key
, &value
);
97 DriverSpecificSettings::SetString(const char* key
, const char* value
)
100 fSettings
.ReplaceString(key
, value
);
102 fSettings
.AddString(key
, value
);
107 DriverSpecificSettings::HasBoolean(const char* key
) const
110 return fSettings
.FindBool(key
, &value
) == B_OK
;
115 DriverSpecificSettings::GetBoolean(const char* key
) const
117 ASSERT(HasBoolean(key
));
119 fSettings
.FindBool(key
, &value
);
125 DriverSpecificSettings::SetBoolean(const char* key
, bool value
)
128 fSettings
.ReplaceBool(key
, value
);
130 fSettings
.AddBool(key
, value
);
135 DriverSpecificSettings::HasInt(const char* key
) const
138 return fSettings
.FindInt32(key
, &value
) == B_OK
;
143 DriverSpecificSettings::GetInt(const char* key
) const
147 fSettings
.FindInt32(key
, &value
);
153 DriverSpecificSettings::SetInt(const char* key
, int32 value
)
156 fSettings
.ReplaceInt32(key
, value
);
158 fSettings
.AddInt32(key
, value
);
163 DriverSpecificSettings::HasDouble(const char* key
) const
166 return fSettings
.FindDouble(key
, &value
) == B_OK
;
171 DriverSpecificSettings::GetDouble(const char* key
) const
173 ASSERT(HasDouble(key
));
175 fSettings
.FindDouble(key
, &value
);
181 DriverSpecificSettings::SetDouble(const char* key
, double value
)
184 fSettings
.ReplaceDouble(key
, value
);
186 fSettings
.AddDouble(key
, value
);
191 DriverSpecificSettings::Message()
197 JobData::JobData(BMessage
*message
, const PrinterCap
*printerCap
, SettingType settingType
)
199 Load(message
, printerCap
, settingType
);
208 JobData::JobData(const JobData
&jobData
)
215 JobData::operator=(const JobData
&jobData
)
217 fShowPreview
= jobData
.fShowPreview
;
218 fPaper
= jobData
.fPaper
;
219 fResolutionID
= jobData
.fResolutionID
;
220 fXRes
= jobData
.fXRes
;
221 fYRes
= jobData
.fYRes
;
222 fOrientation
= jobData
.fOrientation
;
223 fScaling
= jobData
.fScaling
;
224 fPaperRect
= jobData
.fPaperRect
;
225 fScaledPaperRect
= jobData
.fScaledPaperRect
;
226 fPrintableRect
= jobData
.fPrintableRect
;
227 fScaledPrintableRect
= jobData
.fScaledPrintableRect
;
229 fFirstPage
= jobData
.fFirstPage
;
230 fLastPage
= jobData
.fLastPage
;
231 fGamma
= jobData
.fGamma
;
232 fInkDensity
= jobData
.fInkDensity
;
233 fPaperSource
= jobData
.fPaperSource
;
234 fCopies
= jobData
.fCopies
;
235 fCollate
= jobData
.fCollate
;
236 fReverse
= jobData
.fReverse
;
237 fPrintStyle
= jobData
.fPrintStyle
;
238 fBindingLocation
= jobData
.fBindingLocation
;
239 fPageOrder
= jobData
.fPageOrder
;
240 fSettingType
= jobData
.fSettingType
;
242 fColor
= jobData
.fColor
;
243 fDitherType
= jobData
.fDitherType
;
244 fPageSelection
= jobData
.fPageSelection
;
245 fMarginUnit
= jobData
.fMarginUnit
;
246 fPhysicalRect
= jobData
.fPhysicalRect
;
247 fScaledPhysicalRect
= jobData
.fScaledPhysicalRect
;
248 fDriverSpecificSettings
= jobData
.fDriverSpecificSettings
;
254 JobData::Load(BMessage
* message
, const PrinterCap
* printerCap
,
255 SettingType settingType
)
258 fSettingType
= settingType
;
260 const PaperCap
*paperCap
= NULL
;
262 if (message
->HasBool(kJDShowPreview
))
263 fShowPreview
= message
->FindBool(kJDShowPreview
);
265 fShowPreview
= false;
267 if (message
->HasInt32(kJDPaper
))
268 fPaper
= (Paper
)message
->FindInt32(kJDPaper
);
269 else if (printerCap
->Supports(PrinterCap::kPaper
)) {
270 paperCap
= (const PaperCap
*)printerCap
->GetDefaultCap(
272 fPaper
= paperCap
->fPaper
;
276 if (message
->HasInt32(kJDResolution
)) {
277 message
->FindInt32(kJDResolution
, &fResolutionID
);
278 } else if (printerCap
->Supports(PrinterCap::kResolution
)) {
279 fResolutionID
= printerCap
->GetDefaultCap(PrinterCap::kResolution
)
282 // should not reach here!
286 if (message
->HasInt64(kJDXRes
)) {
288 message
->FindInt64(kJDXRes
, &xres64
);
290 } else if (printerCap
->Supports(PrinterCap::kResolution
)) {
291 fXRes
= ((const ResolutionCap
*)printerCap
->GetDefaultCap(
292 PrinterCap::kResolution
))->fXResolution
;
297 if (message
->HasInt64(kJDYRes
)) {
299 message
->FindInt64(kJDYRes
, &yres64
);
301 } else if (printerCap
->Supports(PrinterCap::kResolution
)) {
302 fYRes
= ((const ResolutionCap
*)printerCap
->GetDefaultCap(
303 PrinterCap::kResolution
))->fYResolution
;
308 if (message
->HasInt32(kJDOrientation
))
309 fOrientation
= (Orientation
)message
->FindInt32(kJDOrientation
);
310 else if (printerCap
->Supports(PrinterCap::kOrientation
))
311 fOrientation
= ((const OrientationCap
*)printerCap
->GetDefaultCap(
312 PrinterCap::kOrientation
))->fOrientation
;
314 fOrientation
= kPortrait
;
316 if (message
->HasFloat(kJDScaling
))
317 fScaling
= message
->FindFloat(kJDScaling
);
321 if (message
->HasRect(kJDPaperRect
)) {
322 fPaperRect
= message
->FindRect(kJDPaperRect
);
323 } else if (paperCap
!= NULL
) {
324 fPaperRect
= paperCap
->fPaperRect
;
327 if (message
->HasRect(kJDScaledPaperRect
)) {
328 fScaledPaperRect
= message
->FindRect(kJDScaledPaperRect
);
330 fScaledPaperRect
= fPaperRect
;
333 if (message
->HasRect(kJDPrintableRect
)) {
334 fPrintableRect
= message
->FindRect(kJDPrintableRect
);
335 } else if (paperCap
!= NULL
) {
336 fPrintableRect
= paperCap
->fPhysicalRect
;
339 if (message
->HasRect(kJDScaledPrintableRect
)) {
340 fScaledPrintableRect
= message
->FindRect(kJDScaledPrintableRect
);
342 fScaledPrintableRect
= fPrintableRect
;
345 if (message
->HasRect(kJDPhysicalRect
)) {
346 fPhysicalRect
= message
->FindRect(kJDPhysicalRect
);
347 } else if (paperCap
!= NULL
) {
348 fPhysicalRect
= paperCap
->fPhysicalRect
;
351 if (message
->HasRect(kJDScaledPhysicalRect
)) {
352 fScaledPhysicalRect
= message
->FindRect(kJDScaledPhysicalRect
);
354 fScaledPhysicalRect
= fPhysicalRect
;
357 if (message
->HasInt32(kJDFirstPage
))
358 fFirstPage
= message
->FindInt32(kJDFirstPage
);
362 if (message
->HasInt32(kJDLastPage
))
363 fLastPage
= message
->FindInt32(kJDLastPage
);
367 if (message
->HasInt32(kJDNup
))
368 fNup
= message
->FindInt32(kJDNup
);
372 if (message
->HasFloat(kJDGamma
))
373 fGamma
= fMsg
->FindFloat(kJDGamma
);
377 if (message
->HasFloat(kJDInkDensity
))
378 fInkDensity
= fMsg
->FindFloat(kJDInkDensity
);
382 if (message
->HasInt32(kJDPaperSource
))
383 fPaperSource
= (PaperSource
)fMsg
->FindInt32(kJDPaperSource
);
384 else if (printerCap
->Supports(PrinterCap::kPaperSource
))
385 fPaperSource
= ((const PaperSourceCap
*)printerCap
->GetDefaultCap(
386 PrinterCap::kPaperSource
))->fPaperSource
;
388 fPaperSource
= kAuto
;
390 if (message
->HasInt32(kJDCopies
))
391 fCopies
= message
->FindInt32(kJDCopies
);
395 if (message
->HasBool(kJDCollate
))
396 fCollate
= message
->FindBool(kJDCollate
);
400 if (message
->HasBool(kJDReverse
))
401 fReverse
= message
->FindBool(kJDReverse
);
405 if (message
->HasInt32(kJDPrintStyle
))
406 fPrintStyle
= (PrintStyle
)message
->FindInt32(kJDPrintStyle
);
407 else if (printerCap
->Supports(PrinterCap::kPrintStyle
))
408 fPrintStyle
= ((const PrintStyleCap
*)printerCap
->GetDefaultCap(
409 PrinterCap::kPrintStyle
))->fPrintStyle
;
411 fPrintStyle
= kSimplex
;
413 if (message
->HasInt32(kJDBindingLocation
))
414 fBindingLocation
= (BindingLocation
)message
->FindInt32(
416 else if (printerCap
->Supports(PrinterCap::kBindingLocation
))
417 fBindingLocation
= ((const BindingLocationCap
*)printerCap
->
418 GetDefaultCap(PrinterCap::kBindingLocation
))->fBindingLocation
;
420 fBindingLocation
= kLongEdgeLeft
;
422 if (message
->HasInt32(kJDPageOrder
))
423 fPageOrder
= (PageOrder
)message
->FindInt32(kJDPageOrder
);
425 fPageOrder
= kAcrossFromLeft
;
427 if (message
->HasInt32(kJDColor
))
428 fColor
= (Color
)message
->FindInt32(kJDColor
);
429 else if (printerCap
->Supports(PrinterCap::kColor
))
430 fColor
= ((const ColorCap
*)printerCap
->GetDefaultCap(
431 PrinterCap::kColor
))->fColor
;
433 fColor
= kMonochrome
;
435 if (message
->HasInt32(kJDDitherType
))
436 fDitherType
= (Halftone::DitherType
)message
->FindInt32(kJDDitherType
);
438 fDitherType
= Halftone::kTypeFloydSteinberg
;
440 if (message
->HasInt32(kJDPageSelection
))
441 fPageSelection
= (PageSelection
)message
->FindInt32(kJDPageSelection
);
443 fPageSelection
= kAllPages
;
445 if (message
->HasInt32(kJDMarginUnit
))
446 fMarginUnit
= (MarginUnit
)message
->FindInt32(kJDMarginUnit
);
448 fMarginUnit
= kUnitInch
;
450 if (message
->HasMessage(kJDDriverSpecificSettings
))
451 message
->FindMessage(kJDDriverSpecificSettings
,
452 &fDriverSpecificSettings
.Message());
457 JobData::Save(BMessage
* message
)
459 if (message
== NULL
) {
464 message
->RemoveName(kJDPaper
);
465 message
->AddInt32(kJDPaper
, fPaper
);
467 message
->RemoveName(kJDResolution
);
468 message
->AddInt32(kJDResolution
, fResolutionID
);
470 message
->RemoveName(kJDXRes
);
471 message
->AddInt64(kJDXRes
, fXRes
);
473 message
->RemoveName(kJDYRes
);
474 message
->AddInt64(kJDYRes
, fYRes
);
476 message
->RemoveName(kJDOrientation
);
477 message
->AddInt32(kJDOrientation
, fOrientation
);
479 message
->RemoveName(kJDScaling
);
480 message
->AddFloat(kJDScaling
, fScaling
);
482 message
->RemoveName(kJDPaperRect
);
483 message
->AddRect(kJDPaperRect
, fPaperRect
);
485 message
->RemoveName(kJDScaledPaperRect
);
486 message
->AddRect(kJDScaledPaperRect
, fScaledPaperRect
);
488 message
->RemoveName(kJDPrintableRect
);
489 message
->AddRect(kJDPrintableRect
, fPrintableRect
);
491 message
->RemoveName(kJDScaledPrintableRect
);
492 message
->AddRect(kJDScaledPrintableRect
, fScaledPrintableRect
);
494 message
->RemoveName(kJDPhysicalRect
);
495 message
->AddRect(kJDPhysicalRect
, fPhysicalRect
);
497 message
->RemoveName(kJDScaledPhysicalRect
);
498 message
->AddRect(kJDScaledPhysicalRect
, fScaledPhysicalRect
);
500 message
->RemoveName(kJDMarginUnit
);
501 message
->AddInt32(kJDMarginUnit
, fMarginUnit
);
503 // page settings end here
507 // make sure job settings are not present in page settings
508 message
->RemoveName(kJDShowPreview
);
509 if (fSettingType
== kJobSettings
)
510 message
->AddBool(kJDShowPreview
, fShowPreview
);
512 message
->RemoveName(kJDNup
);
513 if (fSettingType
== kJobSettings
)
514 message
->AddInt32(kJDNup
, fNup
);
516 message
->RemoveName(kJDFirstPage
);
517 if (fSettingType
== kJobSettings
)
518 message
->AddInt32(kJDFirstPage
, fFirstPage
);
520 message
->RemoveName(kJDLastPage
);
521 if (fSettingType
== kJobSettings
)
522 message
->AddInt32(kJDLastPage
, fLastPage
);
524 message
->RemoveName(kJDGamma
);
525 if (fSettingType
== kJobSettings
)
526 message
->AddFloat(kJDGamma
, fGamma
);
528 message
->RemoveName(kJDInkDensity
);
529 if (fSettingType
== kJobSettings
)
530 message
->AddFloat(kJDInkDensity
, fInkDensity
);
532 message
->RemoveName(kJDPaperSource
);
533 if (fSettingType
== kJobSettings
)
534 message
->AddInt32(kJDPaperSource
, fPaperSource
);
536 message
->RemoveName(kJDCopies
);
537 if (fSettingType
== kJobSettings
)
538 message
->AddInt32(kJDCopies
, fCopies
);
540 message
->RemoveName(kJDCollate
);
541 if (fSettingType
== kJobSettings
)
542 message
->AddBool(kJDCollate
, fCollate
);
544 message
->RemoveName(kJDReverse
);
545 if (fSettingType
== kJobSettings
)
546 message
->AddBool(kJDReverse
, fReverse
);
548 message
->RemoveName(kJDPrintStyle
);
549 if (fSettingType
== kJobSettings
)
550 message
->AddInt32(kJDPrintStyle
, fPrintStyle
);
552 message
->RemoveName(kJDBindingLocation
);
553 if (fSettingType
== kJobSettings
)
554 message
->AddInt32(kJDBindingLocation
, fBindingLocation
);
556 message
->RemoveName(kJDPageOrder
);
557 if (fSettingType
== kJobSettings
)
558 message
->AddInt32(kJDPageOrder
, fPageOrder
);
560 message
->RemoveName(kJDColor
);
561 if (fSettingType
== kJobSettings
)
562 message
->AddInt32(kJDColor
, fColor
);
564 message
->RemoveName(kJDDitherType
);
565 if (fSettingType
== kJobSettings
)
566 message
->AddInt32(kJDDitherType
, fDitherType
);
568 message
->RemoveName(kJDPageSelection
);
569 if (fSettingType
== kJobSettings
)
570 message
->AddInt32(kJDPageSelection
, fPageSelection
);
572 message
->RemoveName(kJDDriverSpecificSettings
);
573 if (fSettingType
== kJobSettings
)
575 message
->AddMessage(kJDDriverSpecificSettings
,
576 &fDriverSpecificSettings
.Message());
581 DriverSpecificSettings
&
584 return fDriverSpecificSettings
;
588 const DriverSpecificSettings
&
589 JobData::Settings() const
591 return fDriverSpecificSettings
;