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 {
22 public:
23   nsDeviceContextSpecWin();
24 
25   NS_DECL_ISUPPORTS
26 
27   virtual already_AddRefed<PrintTarget> MakePrintTarget() final;
BeginDocument(const nsAString & aTitle,const nsAString & aPrintToFileName,int32_t aStartPage,int32_t aEndPage)28   NS_IMETHOD BeginDocument(const nsAString& aTitle,
29                            const nsAString& aPrintToFileName,
30                            int32_t          aStartPage,
31                            int32_t          aEndPage) override { return NS_OK; }
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, bool aIsPrintPreview) override;
37 
38   float GetDPI() final;
39 
40   float GetPrintingScale() final;
41 
GetDriverName(wchar_t * & aDriverName)42   void GetDriverName(wchar_t *&aDriverName) const   { aDriverName = mDriverName;     }
GetDeviceName(wchar_t * & aDeviceName)43   void GetDeviceName(wchar_t *&aDeviceName) const   { aDeviceName = mDeviceName;     }
44 
45   // The GetDevMode will return a pointer to a DevMode
46   // whether it is from the Global memory handle or just the DevMode
47   // To get the DevMode from the Global memory Handle it must lock it
48   // So this call must be paired with a call to UnlockGlobalHandle
49   void GetDevMode(LPDEVMODEW &aDevMode);
50 
51   // helper functions
52   nsresult GetDataFromPrinter(char16ptr_t aName, nsIPrintSettings* aPS = nullptr);
53 
54 protected:
55 
56   void SetDeviceName(char16ptr_t aDeviceName);
57   void SetDriverName(char16ptr_t aDriverName);
58   void SetDevMode(LPDEVMODEW aDevMode);
59 
60   virtual ~nsDeviceContextSpecWin();
61 
62   wchar_t*      mDriverName;
63   wchar_t*      mDeviceName;
64   LPDEVMODEW mDevMode;
65 
66   nsCOMPtr<nsIPrintSettings> mPrintSettings;
67   int16_t mOutputFormat = nsIPrintSettings::kOutputFormatNative;
68 };
69 
70 
71 //-------------------------------------------------------------------------
72 // Printer Enumerator
73 //-------------------------------------------------------------------------
74 class nsPrinterEnumeratorWin final : public nsIPrinterEnumerator
75 {
76   ~nsPrinterEnumeratorWin();
77 
78 public:
79   nsPrinterEnumeratorWin();
80   NS_DECL_ISUPPORTS
81   NS_DECL_NSIPRINTERENUMERATOR
82 };
83 
84 #endif
85