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/. */
5 
6 #ifndef nsPrintSettingsX_h_
7 #define nsPrintSettingsX_h_
8 
9 #include "nsPrintSettingsImpl.h"
10 #import <Cocoa/Cocoa.h>
11 
12 // clang-format off
13 #define NS_PRINTSETTINGSX_IID                        \
14   {                                                  \
15     0x0DF2FDBD, 0x906D, 0x4726, {                    \
16       0x9E, 0x4D, 0xCF, 0xE0, 0x87, 0x8D, 0x70, 0x7C \
17     }                                                \
18   }
19 // clang-format on
20 
21 class nsPrintSettingsX : public nsPrintSettings {
22  public:
23   NS_DECLARE_STATIC_IID_ACCESSOR(NS_PRINTSETTINGSX_IID)
24   NS_DECL_ISUPPORTS_INHERITED
25 
26   nsPrintSettingsX();
27   explicit nsPrintSettingsX(const PrintSettingsInitializer& aSettings);
28 
Init()29   nsresult Init() { return NS_OK; }
30 
SetDestination(uint16_t aDestination)31   void SetDestination(uint16_t aDestination) { mDestination = aDestination; }
GetDestination(uint16_t * aDestination)32   void GetDestination(uint16_t* aDestination) { *aDestination = mDestination; }
33 
SetDisposition(const nsString & aDisposition)34   void SetDisposition(const nsString& aDisposition) { mDisposition = aDisposition; }
GetDisposition(nsString & aDisposition)35   void GetDisposition(nsString& aDisposition) { aDisposition = mDisposition; }
36 
37   // Get a Cocoa NSPrintInfo that is configured with our current settings.
38   // This follows Create semantics, so the caller is responsible to release
39   // the returned object when no longer required.
40   //
41   // Pass true for aWithScaling to have the print scaling factor included in
42   // the returned printInfo. Normally we pass false, as scaling is handled
43   // by Gecko and we don't want the Cocoa print system to impose scaling again
44   // on the output, but if we're retrieving the info in order to populate the
45   // system print UI, then we do want to know about it.
46   NSPrintInfo* CreateOrCopyPrintInfo(bool aWithScaling = false);
47 
48   // Update our internal settings to reflect the properties of the given
49   // NSPrintInfo.
50   //
51   // If aAdoptPrintInfo is set, the given NSPrintInfo will be retained and
52   // returned by subsequent CreateOrCopyPrintInfo calls, which is required
53   // for custom settings from the OS print dialog to be passed through to
54   // print jobs. However, this means that subsequent changes to print settings
55   // via the generic nsPrintSettings methods will NOT be reflected in the
56   // resulting NSPrintInfo.
57   void SetFromPrintInfo(NSPrintInfo* aPrintInfo, bool aAdoptPrintInfo);
58 
59  protected:
~nsPrintSettingsX()60   virtual ~nsPrintSettingsX() {
61     if (mSystemPrintInfo) {
62       [mSystemPrintInfo release];
63     }
64   };
65 
66   nsPrintSettingsX& operator=(const nsPrintSettingsX& rhs);
67 
68   nsresult _Clone(nsIPrintSettings** _retval) override;
69   nsresult _Assign(nsIPrintSettings* aPS) override;
70 
71   int GetCocoaUnit(int16_t aGeckoUnit);
72 
PaperSizeFromCocoaPoints(double aPointsValue)73   double PaperSizeFromCocoaPoints(double aPointsValue) {
74     return aPointsValue * (mPaperSizeUnit == kPaperSizeInches ? 1.0 / 72.0 : 25.4 / 72.0);
75   }
76 
CocoaPointsFromPaperSize(double aSizeUnitValue)77   double CocoaPointsFromPaperSize(double aSizeUnitValue) {
78     return aSizeUnitValue * (mPaperSizeUnit == kPaperSizeInches ? 72.0 : 72.0 / 25.4);
79   }
80 
81   // Needed to correctly track the various job dispositions (spool, preview,
82   // save to file) that the user can choose via the system print dialog.
83   // Unfortunately it seems to be necessary to set both the Cocoa "job
84   // disposition" and the PrintManager "destination type" in order for all the
85   // various workflows such as "Save to Web Receipts" to work.
86   nsString mDisposition;
87   uint16_t mDestination;
88 
89   // If the user has used the system print UI, we retain a reference to its
90   // printInfo because it may contain settings that we don't know how to handle
91   // and that will be lost if we round-trip through nsPrintSettings fields.
92   // We'll use this printInfo if asked to run a print job.
93   //
94   // This "wrapped" printInfo is NOT serialized or copied when printSettings
95   // objects are passed around; it is used only by the settings object to which
96   // it was originally passed.
97   NSPrintInfo* mSystemPrintInfo = nullptr;
98 };
99 
100 NS_DEFINE_STATIC_IID_ACCESSOR(nsPrintSettingsX, NS_PRINTSETTINGSX_IID)
101 
102 #endif  // nsPrintSettingsX_h_
103