|
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 #include "nsPrintSettingsWin.h" |
|
6 #include "nsCRT.h" |
|
7 |
|
8 NS_IMPL_ISUPPORTS_INHERITED(nsPrintSettingsWin, |
|
9 nsPrintSettings, |
|
10 nsIPrintSettingsWin) |
|
11 |
|
12 /** --------------------------------------------------- |
|
13 * See documentation in nsPrintSettingsWin.h |
|
14 * @update |
|
15 */ |
|
16 nsPrintSettingsWin::nsPrintSettingsWin() : |
|
17 nsPrintSettings(), |
|
18 mDeviceName(nullptr), |
|
19 mDriverName(nullptr), |
|
20 mDevMode(nullptr) |
|
21 { |
|
22 |
|
23 } |
|
24 |
|
25 /** --------------------------------------------------- |
|
26 * See documentation in nsPrintSettingsWin.h |
|
27 * @update |
|
28 */ |
|
29 nsPrintSettingsWin::nsPrintSettingsWin(const nsPrintSettingsWin& aPS) : |
|
30 mDeviceName(nullptr), |
|
31 mDriverName(nullptr), |
|
32 mDevMode(nullptr) |
|
33 { |
|
34 *this = aPS; |
|
35 } |
|
36 |
|
37 /** --------------------------------------------------- |
|
38 * See documentation in nsPrintSettingsWin.h |
|
39 * @update |
|
40 */ |
|
41 nsPrintSettingsWin::~nsPrintSettingsWin() |
|
42 { |
|
43 if (mDeviceName) nsMemory::Free(mDeviceName); |
|
44 if (mDriverName) nsMemory::Free(mDriverName); |
|
45 if (mDevMode) ::HeapFree(::GetProcessHeap(), 0, mDevMode); |
|
46 } |
|
47 |
|
48 /* [noscript] attribute charPtr deviceName; */ |
|
49 NS_IMETHODIMP nsPrintSettingsWin::SetDeviceName(const char16_t * aDeviceName) |
|
50 { |
|
51 if (mDeviceName) { |
|
52 nsMemory::Free(mDeviceName); |
|
53 } |
|
54 mDeviceName = aDeviceName?wcsdup(char16ptr_t(aDeviceName)):nullptr; |
|
55 return NS_OK; |
|
56 } |
|
57 NS_IMETHODIMP nsPrintSettingsWin::GetDeviceName(char16_t **aDeviceName) |
|
58 { |
|
59 NS_ENSURE_ARG_POINTER(aDeviceName); |
|
60 *aDeviceName = mDeviceName?reinterpret_cast<char16_t*>(wcsdup(mDeviceName)):nullptr; |
|
61 return NS_OK; |
|
62 } |
|
63 |
|
64 /* [noscript] attribute charPtr driverName; */ |
|
65 NS_IMETHODIMP nsPrintSettingsWin::SetDriverName(const char16_t * aDriverName) |
|
66 { |
|
67 if (mDriverName) { |
|
68 nsMemory::Free(mDriverName); |
|
69 } |
|
70 mDriverName = aDriverName?wcsdup(char16ptr_t(aDriverName)):nullptr; |
|
71 return NS_OK; |
|
72 } |
|
73 NS_IMETHODIMP nsPrintSettingsWin::GetDriverName(char16_t **aDriverName) |
|
74 { |
|
75 NS_ENSURE_ARG_POINTER(aDriverName); |
|
76 *aDriverName = mDriverName?reinterpret_cast<char16_t*>(wcsdup(mDriverName)):nullptr; |
|
77 return NS_OK; |
|
78 } |
|
79 |
|
80 void nsPrintSettingsWin::CopyDevMode(DEVMODEW* aInDevMode, DEVMODEW *& aOutDevMode) |
|
81 { |
|
82 aOutDevMode = nullptr; |
|
83 size_t size = aInDevMode->dmSize + aInDevMode->dmDriverExtra; |
|
84 aOutDevMode = (LPDEVMODEW)::HeapAlloc (::GetProcessHeap(), HEAP_ZERO_MEMORY, size); |
|
85 if (aOutDevMode) { |
|
86 memcpy(aOutDevMode, aInDevMode, size); |
|
87 } |
|
88 |
|
89 } |
|
90 |
|
91 /* [noscript] attribute nsDevMode devMode; */ |
|
92 NS_IMETHODIMP nsPrintSettingsWin::GetDevMode(DEVMODEW * *aDevMode) |
|
93 { |
|
94 NS_ENSURE_ARG_POINTER(aDevMode); |
|
95 |
|
96 if (mDevMode) { |
|
97 CopyDevMode(mDevMode, *aDevMode); |
|
98 } else { |
|
99 *aDevMode = nullptr; |
|
100 } |
|
101 return NS_OK; |
|
102 } |
|
103 |
|
104 NS_IMETHODIMP nsPrintSettingsWin::SetDevMode(DEVMODEW * aDevMode) |
|
105 { |
|
106 if (mDevMode) { |
|
107 ::HeapFree(::GetProcessHeap(), 0, mDevMode); |
|
108 mDevMode = nullptr; |
|
109 } |
|
110 |
|
111 if (aDevMode) { |
|
112 CopyDevMode(aDevMode, mDevMode); |
|
113 } |
|
114 return NS_OK; |
|
115 } |
|
116 |
|
117 //------------------------------------------- |
|
118 nsresult |
|
119 nsPrintSettingsWin::_Clone(nsIPrintSettings **_retval) |
|
120 { |
|
121 nsPrintSettingsWin* printSettings = new nsPrintSettingsWin(*this); |
|
122 return printSettings->QueryInterface(NS_GET_IID(nsIPrintSettings), (void**)_retval); // ref counts |
|
123 } |
|
124 |
|
125 //------------------------------------------- |
|
126 nsPrintSettingsWin& nsPrintSettingsWin::operator=(const nsPrintSettingsWin& rhs) |
|
127 { |
|
128 if (this == &rhs) { |
|
129 return *this; |
|
130 } |
|
131 |
|
132 ((nsPrintSettings&) *this) = rhs; |
|
133 |
|
134 if (mDeviceName) { |
|
135 free(mDeviceName); |
|
136 } |
|
137 |
|
138 if (mDriverName) { |
|
139 free(mDriverName); |
|
140 } |
|
141 |
|
142 // Use free because we used the native malloc to create the memory |
|
143 if (mDevMode) { |
|
144 ::HeapFree(::GetProcessHeap(), 0, mDevMode); |
|
145 } |
|
146 |
|
147 mDeviceName = rhs.mDeviceName?wcsdup(rhs.mDeviceName):nullptr; |
|
148 mDriverName = rhs.mDriverName?wcsdup(rhs.mDriverName):nullptr; |
|
149 |
|
150 if (rhs.mDevMode) { |
|
151 CopyDevMode(rhs.mDevMode, mDevMode); |
|
152 } else { |
|
153 mDevMode = nullptr; |
|
154 } |
|
155 |
|
156 return *this; |
|
157 } |
|
158 |
|
159 //------------------------------------------- |
|
160 /* void assign (in nsIPrintSettings aPS); */ |
|
161 nsresult |
|
162 nsPrintSettingsWin::_Assign(nsIPrintSettings *aPS) |
|
163 { |
|
164 nsPrintSettingsWin *psWin = static_cast<nsPrintSettingsWin*>(aPS); |
|
165 *this = *psWin; |
|
166 return NS_OK; |
|
167 } |
|
168 |
|
169 //---------------------------------------------------------------------- |
|
170 // Testing of assign and clone |
|
171 // This define turns on the testing module below |
|
172 // so at start up it writes and reads the prefs. |
|
173 #ifdef DEBUG_rodsX |
|
174 #include "nsIPrintOptions.h" |
|
175 #include "nsIServiceManager.h" |
|
176 class Tester { |
|
177 public: |
|
178 Tester(); |
|
179 }; |
|
180 Tester::Tester() |
|
181 { |
|
182 nsCOMPtr<nsIPrintSettings> ps; |
|
183 nsresult rv; |
|
184 nsCOMPtr<nsIPrintOptions> printService = do_GetService("@mozilla.org/gfx/printsettings-service;1", &rv); |
|
185 if (NS_SUCCEEDED(rv)) { |
|
186 rv = printService->CreatePrintSettings(getter_AddRefs(ps)); |
|
187 } |
|
188 |
|
189 if (ps) { |
|
190 ps->SetPrintOptions(nsIPrintSettings::kPrintOddPages, true); |
|
191 ps->SetPrintOptions(nsIPrintSettings::kPrintEvenPages, false); |
|
192 ps->SetMarginTop(1.0); |
|
193 ps->SetMarginLeft(1.0); |
|
194 ps->SetMarginBottom(1.0); |
|
195 ps->SetMarginRight(1.0); |
|
196 ps->SetScaling(0.5); |
|
197 ps->SetPrintBGColors(true); |
|
198 ps->SetPrintBGImages(true); |
|
199 ps->SetPrintRange(15); |
|
200 ps->SetHeaderStrLeft(NS_ConvertUTF8toUTF16("Left").get()); |
|
201 ps->SetHeaderStrCenter(NS_ConvertUTF8toUTF16("Center").get()); |
|
202 ps->SetHeaderStrRight(NS_ConvertUTF8toUTF16("Right").get()); |
|
203 ps->SetFooterStrLeft(NS_ConvertUTF8toUTF16("Left").get()); |
|
204 ps->SetFooterStrCenter(NS_ConvertUTF8toUTF16("Center").get()); |
|
205 ps->SetFooterStrRight(NS_ConvertUTF8toUTF16("Right").get()); |
|
206 ps->SetPaperName(NS_ConvertUTF8toUTF16("Paper Name").get()); |
|
207 ps->SetPaperSizeType(10); |
|
208 ps->SetPaperData(1); |
|
209 ps->SetPaperWidth(100.0); |
|
210 ps->SetPaperHeight(50.0); |
|
211 ps->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters); |
|
212 ps->SetPrintReversed(true); |
|
213 ps->SetPrintInColor(true); |
|
214 ps->SetOrientation(nsIPrintSettings::kLandscapeOrientation); |
|
215 ps->SetPrintCommand(NS_ConvertUTF8toUTF16("Command").get()); |
|
216 ps->SetNumCopies(2); |
|
217 ps->SetPrinterName(NS_ConvertUTF8toUTF16("Printer Name").get()); |
|
218 ps->SetPrintToFile(true); |
|
219 ps->SetToFileName(NS_ConvertUTF8toUTF16("File Name").get()); |
|
220 ps->SetPrintPageDelay(1000); |
|
221 |
|
222 nsCOMPtr<nsIPrintSettings> ps2; |
|
223 if (NS_SUCCEEDED(rv)) { |
|
224 rv = printService->CreatePrintSettings(getter_AddRefs(ps2)); |
|
225 } |
|
226 |
|
227 ps2->Assign(ps); |
|
228 |
|
229 nsCOMPtr<nsIPrintSettings> psClone; |
|
230 ps2->Clone(getter_AddRefs(psClone)); |
|
231 |
|
232 } |
|
233 |
|
234 } |
|
235 Tester gTester; |
|
236 #endif |
|
237 |