1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsPrintSettingsX_h_
7 #define nsPrintSettingsX_h_
9 #include "nsPrintSettingsImpl.h"
10 #import <Cocoa/Cocoa.h>
13 #define NS_PRINTSETTINGSX_IID \
15 0x0DF2FDBD, 0x906D, 0x4726, { \
16 0x9E, 0x4D, 0xCF, 0xE0, 0x87, 0x8D, 0x70, 0x7C \
21 class nsPrintSettingsX
: public nsPrintSettings
{
23 NS_DECLARE_STATIC_IID_ACCESSOR(NS_PRINTSETTINGSX_IID
)
24 NS_DECL_ISUPPORTS_INHERITED
27 explicit nsPrintSettingsX(const PrintSettingsInitializer
& aSettings
);
29 nsresult
Init() { return NS_OK
; }
31 void SetDestination(uint16_t aDestination
) { mDestination
= aDestination
; }
32 void GetDestination(uint16_t* aDestination
) { *aDestination
= mDestination
; }
34 void SetDisposition(const nsString
& aDisposition
) {
35 mDisposition
= aDisposition
;
37 void GetDisposition(nsString
& aDisposition
) { aDisposition
= mDisposition
; }
39 // Get a Cocoa NSPrintInfo that is configured with our current settings.
40 // This follows Create semantics, so the caller is responsible to release
41 // the returned object when no longer required.
43 // Pass true for aWithScaling to have the print scaling factor included in
44 // the returned printInfo. Normally we pass false, as scaling is handled
45 // by Gecko and we don't want the Cocoa print system to impose scaling again
46 // on the output, but if we're retrieving the info in order to populate the
47 // system print UI, then we do want to know about it.
48 NSPrintInfo
* CreateOrCopyPrintInfo(bool aWithScaling
= false);
50 // Update our internal settings to reflect the properties of the given
53 // If aAdoptPrintInfo is set, the given NSPrintInfo will be retained and
54 // returned by subsequent CreateOrCopyPrintInfo calls, which is required
55 // for custom settings from the OS print dialog to be passed through to
56 // print jobs. However, this means that subsequent changes to print settings
57 // via the generic nsPrintSettings methods will NOT be reflected in the
58 // resulting NSPrintInfo.
59 void SetFromPrintInfo(NSPrintInfo
* aPrintInfo
, bool aAdoptPrintInfo
);
62 virtual ~nsPrintSettingsX() {
63 if (mSystemPrintInfo
) {
64 [mSystemPrintInfo release
];
68 nsPrintSettingsX
& operator=(const nsPrintSettingsX
& rhs
);
70 nsresult
_Clone(nsIPrintSettings
** _retval
) override
;
71 nsresult
_Assign(nsIPrintSettings
* aPS
) override
;
73 int GetCocoaUnit(int16_t aGeckoUnit
);
75 double PaperSizeFromCocoaPoints(double aPointsValue
) {
77 (mPaperSizeUnit
== kPaperSizeInches
? 1.0 / 72.0 : 25.4 / 72.0);
80 double CocoaPointsFromPaperSize(double aSizeUnitValue
) {
81 return aSizeUnitValue
*
82 (mPaperSizeUnit
== kPaperSizeInches
? 72.0 : 72.0 / 25.4);
85 // Needed to correctly track the various job dispositions (spool, preview,
86 // save to file) that the user can choose via the system print dialog.
87 // Unfortunately it seems to be necessary to set both the Cocoa "job
88 // disposition" and the PrintManager "destination type" in order for all the
89 // various workflows such as "Save to Web Receipts" to work.
90 nsString mDisposition
;
91 uint16_t mDestination
;
93 // If the user has used the system print UI, we retain a reference to its
94 // printInfo because it may contain settings that we don't know how to handle
95 // and that will be lost if we round-trip through nsPrintSettings fields.
96 // We'll use this printInfo if asked to run a print job.
98 // This "wrapped" printInfo is NOT serialized or copied when printSettings
99 // objects are passed around; it is used only by the settings object to which
100 // it was originally passed.
101 NSPrintInfo
* mSystemPrintInfo
= nullptr;
104 NS_DEFINE_STATIC_IID_ACCESSOR(nsPrintSettingsX
, NS_PRINTSETTINGSX_IID
)
106 #endif // nsPrintSettingsX_h_