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 nsDeviceContextSpecWin_h___
7 #define nsDeviceContextSpecWin_h___
8 
9 #include "nsCOMPtr.h"
10 #include "nsIDeviceContextSpec.h"
11 #include "nsIPrinterEnumerator.h"
12 #include "nsIPrintSettings.h"
13 #include "nsISupportsPrimitives.h"
14 #include <windows.h>
15 #include "mozilla/Attributes.h"
16 #include "mozilla/RefPtr.h"
17 
18 class nsIWidget;
19 
20 class nsDeviceContextSpecWin : public nsIDeviceContextSpec {
21  public:
22   nsDeviceContextSpecWin();
23 
24   NS_DECL_ISUPPORTS
25 
26   already_AddRefed<PrintTarget> MakePrintTarget() final;
BeginDocument(const nsAString & aTitle,const nsAString & aPrintToFileName,int32_t aStartPage,int32_t aEndPage)27   NS_IMETHOD BeginDocument(const nsAString& aTitle,
28                            const nsAString& aPrintToFileName,
29                            int32_t aStartPage, int32_t aEndPage) override {
30     return NS_OK;
31   }
EndDocument()32   NS_IMETHOD EndDocument() override { return NS_OK; }
BeginPage()33   NS_IMETHOD BeginPage() override { return NS_OK; }
EndPage()34   NS_IMETHOD EndPage() override { return NS_OK; }
35 
36   NS_IMETHOD Init(nsIWidget* aWidget, nsIPrintSettings* aPS,
37                   bool aIsPrintPreview) override;
38 
39   float GetDPI() final;
40 
41   float GetPrintingScale() final;
42 
GetDriverName(nsAString & aDriverName)43   void GetDriverName(nsAString& aDriverName) const {
44     aDriverName = mDriverName;
45   }
GetDeviceName(nsAString & aDeviceName)46   void GetDeviceName(nsAString& aDeviceName) const {
47     aDeviceName = mDeviceName;
48   }
49 
50   // The GetDevMode will return a pointer to a DevMode
51   // whether it is from the Global memory handle or just the DevMode
52   // To get the DevMode from the Global memory Handle it must lock it
53   // So this call must be paired with a call to UnlockGlobalHandle
54   void GetDevMode(LPDEVMODEW& aDevMode);
55 
56   // helper functions
57   nsresult GetDataFromPrinter(const nsAString& aName,
58                               nsIPrintSettings* aPS = nullptr);
59 
60  protected:
61   void SetDeviceName(const nsAString& aDeviceName);
62   void SetDriverName(const nsAString& aDriverName);
63   void SetDevMode(LPDEVMODEW aDevMode);
64 
65   virtual ~nsDeviceContextSpecWin();
66 
67   nsString mDriverName;
68   nsString mDeviceName;
69   LPDEVMODEW mDevMode;
70 
71   nsCOMPtr<nsIPrintSettings> mPrintSettings;
72   int16_t mOutputFormat = nsIPrintSettings::kOutputFormatNative;
73 
74 #ifdef MOZ_ENABLE_SKIA_PDF
75 
76   // This variable is independant of nsIPrintSettings::kOutputFormatPDF.
77   // It controls both whether normal printing is done via PDF using Skia and
78   // whether print-to-PDF uses Skia.
79   bool mPrintViaSkPDF;
80 #endif
81 };
82 
83 //-------------------------------------------------------------------------
84 // Printer Enumerator
85 //-------------------------------------------------------------------------
86 class nsPrinterEnumeratorWin final : public nsIPrinterEnumerator {
87   ~nsPrinterEnumeratorWin();
88 
89  public:
90   nsPrinterEnumeratorWin();
91   NS_DECL_ISUPPORTS
92   NS_DECL_NSIPRINTERENUMERATOR
93 };
94 
95 #endif
96