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"
8 NS_IMPL_ISUPPORTS_INHERITED(nsPrintSettingsWin
,
12 /** ---------------------------------------------------
13 * See documentation in nsPrintSettingsWin.h
16 nsPrintSettingsWin::nsPrintSettingsWin() :
25 /** ---------------------------------------------------
26 * See documentation in nsPrintSettingsWin.h
29 nsPrintSettingsWin::nsPrintSettingsWin(const nsPrintSettingsWin
& aPS
) :
37 /** ---------------------------------------------------
38 * See documentation in nsPrintSettingsWin.h
41 nsPrintSettingsWin::~nsPrintSettingsWin()
43 if (mDeviceName
) nsMemory::Free(mDeviceName
);
44 if (mDriverName
) nsMemory::Free(mDriverName
);
45 if (mDevMode
) ::HeapFree(::GetProcessHeap(), 0, mDevMode
);
48 /* [noscript] attribute charPtr deviceName; */
49 NS_IMETHODIMP
nsPrintSettingsWin::SetDeviceName(const char16_t
* aDeviceName
)
52 nsMemory::Free(mDeviceName
);
54 mDeviceName
= aDeviceName
?wcsdup(char16ptr_t(aDeviceName
)):nullptr;
57 NS_IMETHODIMP
nsPrintSettingsWin::GetDeviceName(char16_t
**aDeviceName
)
59 NS_ENSURE_ARG_POINTER(aDeviceName
);
60 *aDeviceName
= mDeviceName
?reinterpret_cast<char16_t
*>(wcsdup(mDeviceName
)):nullptr;
64 /* [noscript] attribute charPtr driverName; */
65 NS_IMETHODIMP
nsPrintSettingsWin::SetDriverName(const char16_t
* aDriverName
)
68 nsMemory::Free(mDriverName
);
70 mDriverName
= aDriverName
?wcsdup(char16ptr_t(aDriverName
)):nullptr;
73 NS_IMETHODIMP
nsPrintSettingsWin::GetDriverName(char16_t
**aDriverName
)
75 NS_ENSURE_ARG_POINTER(aDriverName
);
76 *aDriverName
= mDriverName
?reinterpret_cast<char16_t
*>(wcsdup(mDriverName
)):nullptr;
80 void nsPrintSettingsWin::CopyDevMode(DEVMODEW
* aInDevMode
, DEVMODEW
*& aOutDevMode
)
82 aOutDevMode
= nullptr;
83 size_t size
= aInDevMode
->dmSize
+ aInDevMode
->dmDriverExtra
;
84 aOutDevMode
= (LPDEVMODEW
)::HeapAlloc (::GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
86 memcpy(aOutDevMode
, aInDevMode
, size
);
91 /* [noscript] attribute nsDevMode devMode; */
92 NS_IMETHODIMP
nsPrintSettingsWin::GetDevMode(DEVMODEW
* *aDevMode
)
94 NS_ENSURE_ARG_POINTER(aDevMode
);
97 CopyDevMode(mDevMode
, *aDevMode
);
104 NS_IMETHODIMP
nsPrintSettingsWin::SetDevMode(DEVMODEW
* aDevMode
)
107 ::HeapFree(::GetProcessHeap(), 0, mDevMode
);
112 CopyDevMode(aDevMode
, mDevMode
);
117 //-------------------------------------------
119 nsPrintSettingsWin::_Clone(nsIPrintSettings
**_retval
)
121 nsPrintSettingsWin
* printSettings
= new nsPrintSettingsWin(*this);
122 return printSettings
->QueryInterface(NS_GET_IID(nsIPrintSettings
), (void**)_retval
); // ref counts
125 //-------------------------------------------
126 nsPrintSettingsWin
& nsPrintSettingsWin::operator=(const nsPrintSettingsWin
& rhs
)
132 ((nsPrintSettings
&) *this) = rhs
;
142 // Use free because we used the native malloc to create the memory
144 ::HeapFree(::GetProcessHeap(), 0, mDevMode
);
147 mDeviceName
= rhs
.mDeviceName
?wcsdup(rhs
.mDeviceName
):nullptr;
148 mDriverName
= rhs
.mDriverName
?wcsdup(rhs
.mDriverName
):nullptr;
151 CopyDevMode(rhs
.mDevMode
, mDevMode
);
159 //-------------------------------------------
160 /* void assign (in nsIPrintSettings aPS); */
162 nsPrintSettingsWin::_Assign(nsIPrintSettings
*aPS
)
164 nsPrintSettingsWin
*psWin
= static_cast<nsPrintSettingsWin
*>(aPS
);
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.
174 #include "nsIPrintOptions.h"
175 #include "nsIServiceManager.h"
182 nsCOMPtr
<nsIPrintSettings
> ps
;
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
));
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);
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);
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());
217 ps
->SetPrinterName(NS_ConvertUTF8toUTF16("Printer Name").get());
218 ps
->SetPrintToFile(true);
219 ps
->SetToFileName(NS_ConvertUTF8toUTF16("File Name").get());
220 ps
->SetPrintPageDelay(1000);
222 nsCOMPtr
<nsIPrintSettings
> ps2
;
223 if (NS_SUCCEEDED(rv
)) {
224 rv
= printService
->CreatePrintSettings(getter_AddRefs(ps2
));
229 nsCOMPtr
<nsIPrintSettings
> psClone
;
230 ps2
->Clone(getter_AddRefs(psClone
));