1 /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2  *
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef nsPrintSettingsGTK_h_
8 #define nsPrintSettingsGTK_h_
9 
10 #include "nsPrintSettingsImpl.h"
11 
12 extern "C" {
13 #include <gtk/gtk.h>
14 #include <gtk/gtkunixprint.h>
15 }
16 
17 #define NS_PRINTSETTINGSGTK_IID                      \
18   {                                                  \
19     0x758df520, 0xc7c3, 0x11dc, {                    \
20       0x95, 0xff, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 \
21     }                                                \
22   }
23 
24 //*****************************************************************************
25 //***    nsPrintSettingsGTK
26 //*****************************************************************************
27 
28 class nsPrintSettingsGTK : public nsPrintSettings {
29  public:
30   NS_DECL_ISUPPORTS_INHERITED
31   NS_DECLARE_STATIC_IID_ACCESSOR(NS_PRINTSETTINGSGTK_IID)
32 
33   nsPrintSettingsGTK();
34   explicit nsPrintSettingsGTK(const PrintSettingsInitializer& aSettings);
35 
36   // We're overriding these methods because we want to read/write with GTK
37   // objects, not local variables. This allows a simpler settings implementation
38   // between Gecko and GTK.
39 
GetGtkPageSetup()40   GtkPageSetup* GetGtkPageSetup() { return mPageSetup; };
41   void SetGtkPageSetup(GtkPageSetup* aPageSetup);
42 
GetGtkPrintSettings()43   GtkPrintSettings* GetGtkPrintSettings() { return mPrintSettings; };
44   void SetGtkPrintSettings(GtkPrintSettings* aPrintSettings);
45 
GetGtkPrinter()46   GtkPrinter* GetGtkPrinter() { return mGTKPrinter; };
47   void SetGtkPrinter(GtkPrinter* aPrinter);
48 
49   // Reversed, color, orientation and file name are all stored in the
50   // GtkPrintSettings. Orientation is also stored in the GtkPageSetup and its
51   // setting takes priority when getting the orientation.
52   NS_IMETHOD GetPrintReversed(bool* aPrintReversed) override;
53   NS_IMETHOD SetPrintReversed(bool aPrintReversed) override;
54 
55   NS_IMETHOD GetPrintInColor(bool* aPrintInColor) override;
56   NS_IMETHOD SetPrintInColor(bool aPrintInColor) override;
57 
58   NS_IMETHOD GetOrientation(int32_t* aOrientation) override;
59   NS_IMETHOD SetOrientation(int32_t aOrientation) override;
60 
61   NS_IMETHOD GetToFileName(nsAString& aToFileName) override;
62   NS_IMETHOD SetToFileName(const nsAString& aToFileName) override;
63 
64   // Gets/Sets the printer name in the GtkPrintSettings. If no printer name is
65   // specified there, you will get back the name of the current internal
66   // GtkPrinter.
67   NS_IMETHOD GetPrinterName(nsAString& Printer) override;
68   NS_IMETHOD SetPrinterName(const nsAString& aPrinter) override;
69 
70   // Number of copies is stored/gotten from the GtkPrintSettings.
71   NS_IMETHOD GetNumCopies(int32_t* aNumCopies) override;
72   NS_IMETHOD SetNumCopies(int32_t aNumCopies) override;
73 
74   NS_IMETHOD GetScaling(double* aScaling) override;
75   NS_IMETHOD SetScaling(double aScaling) override;
76 
77   // A name recognised by GTK is strongly advised here, as this is used to
78   // create a GtkPaperSize.
79   NS_IMETHOD GetPaperId(nsAString& aPaperId) override;
80   NS_IMETHOD SetPaperId(const nsAString& aPaperId) override;
81 
82   NS_IMETHOD SetUnwriteableMarginInTwips(
83       nsIntMargin& aUnwriteableMargin) override;
84   NS_IMETHOD SetUnwriteableMarginTop(double aUnwriteableMarginTop) override;
85   NS_IMETHOD SetUnwriteableMarginLeft(double aUnwriteableMarginLeft) override;
86   NS_IMETHOD SetUnwriteableMarginBottom(
87       double aUnwriteableMarginBottom) override;
88   NS_IMETHOD SetUnwriteableMarginRight(double aUnwriteableMarginRight) override;
89 
90   NS_IMETHOD GetPaperWidth(double* aPaperWidth) override;
91   NS_IMETHOD SetPaperWidth(double aPaperWidth) override;
92 
93   NS_IMETHOD GetPaperHeight(double* aPaperHeight) override;
94   NS_IMETHOD SetPaperHeight(double aPaperHeight) override;
95 
96   NS_IMETHOD SetPaperSizeUnit(int16_t aPaperSizeUnit) override;
97 
98   NS_IMETHOD GetEffectivePageSize(double* aWidth, double* aHeight) override;
99 
100   NS_IMETHOD SetupSilentPrinting() override;
101 
102   NS_IMETHOD SetPageRanges(const nsTArray<int32_t>&) override;
103   NS_IMETHOD GetPageRanges(nsTArray<int32_t>&) override;
104 
105   NS_IMETHOD GetResolution(int32_t* aResolution) override;
106   NS_IMETHOD SetResolution(int32_t aResolution) override;
107 
108   NS_IMETHOD GetDuplex(int32_t* aDuplex) override;
109   NS_IMETHOD SetDuplex(int32_t aDuplex) override;
110 
111   NS_IMETHOD GetOutputFormat(int16_t* aOutputFormat) override;
112 
113  protected:
114   virtual ~nsPrintSettingsGTK();
115 
116   nsPrintSettingsGTK(const nsPrintSettingsGTK& src);
117   nsPrintSettingsGTK& operator=(const nsPrintSettingsGTK& rhs);
118 
119   virtual nsresult _Clone(nsIPrintSettings** _retval) override;
120   virtual nsresult _Assign(nsIPrintSettings* aPS) override;
121 
122   GtkUnit GetGTKUnit(int16_t aGeckoUnit);
123   void SaveNewPageSize();
124 
125   /**
126    * Re-initialize mUnwriteableMargin with values from mPageSetup.
127    * Should be called whenever mPageSetup is initialized or overwritten.
128    */
129   void InitUnwriteableMargin();
130 
131   /**
132    * On construction:
133    * - mPrintSettings and mPageSetup are just new objects with defaults
134    *   determined by GTK.
135    * - mGTKPrinter is nullptr!!! Remember to be careful when accessing this
136    *   property.
137    */
138   GtkPageSetup* mPageSetup;
139   GtkPrintSettings* mPrintSettings;
140   GtkPrinter* mGTKPrinter;
141 };
142 
143 NS_DEFINE_STATIC_IID_ACCESSOR(nsPrintSettingsGTK, NS_PRINTSETTINGSGTK_IID)
144 
145 #endif  // nsPrintSettingsGTK_h_
146