1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
37 #include "nsPrintSettingsWin.h"
40 NS_IMPL_ISUPPORTS_INHERITED1(nsPrintSettingsWin
,
44 /** ---------------------------------------------------
45 * See documentation in nsPrintSettingsWin.h
48 nsPrintSettingsWin::nsPrintSettingsWin() :
57 /** ---------------------------------------------------
58 * See documentation in nsPrintSettingsWin.h
61 nsPrintSettingsWin::nsPrintSettingsWin(const nsPrintSettingsWin
& aPS
) :
69 /** ---------------------------------------------------
70 * See documentation in nsPrintSettingsWin.h
73 nsPrintSettingsWin::~nsPrintSettingsWin()
75 if (mDeviceName
) nsMemory::Free(mDeviceName
);
76 if (mDriverName
) nsMemory::Free(mDriverName
);
77 if (mDevMode
) ::HeapFree(::GetProcessHeap(), 0, mDevMode
);
80 /* [noscript] attribute charPtr deviceName; */
81 NS_IMETHODIMP
nsPrintSettingsWin::SetDeviceName(const PRUnichar
* aDeviceName
)
84 nsMemory::Free(mDeviceName
);
86 mDeviceName
= aDeviceName
?wcsdup(aDeviceName
):nsnull
;
89 NS_IMETHODIMP
nsPrintSettingsWin::GetDeviceName(PRUnichar
**aDeviceName
)
91 NS_ENSURE_ARG_POINTER(aDeviceName
);
92 *aDeviceName
= mDeviceName
?wcsdup(mDeviceName
):nsnull
;
96 /* [noscript] attribute charPtr driverName; */
97 NS_IMETHODIMP
nsPrintSettingsWin::SetDriverName(const PRUnichar
* aDriverName
)
100 nsMemory::Free(mDriverName
);
102 mDriverName
= aDriverName
?wcsdup(aDriverName
):nsnull
;
105 NS_IMETHODIMP
nsPrintSettingsWin::GetDriverName(PRUnichar
**aDriverName
)
107 NS_ENSURE_ARG_POINTER(aDriverName
);
108 *aDriverName
= mDriverName
?wcsdup(mDriverName
):nsnull
;
112 void nsPrintSettingsWin::CopyDevMode(DEVMODEW
* aInDevMode
, DEVMODEW
*& aOutDevMode
)
114 aOutDevMode
= nsnull
;
115 size_t size
= aInDevMode
->dmSize
+ aInDevMode
->dmDriverExtra
;
116 aOutDevMode
= (LPDEVMODEW
)::HeapAlloc (::GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
118 memcpy(aOutDevMode
, aInDevMode
, size
);
123 /* [noscript] attribute nsDevMode devMode; */
124 NS_IMETHODIMP
nsPrintSettingsWin::GetDevMode(DEVMODEW
* *aDevMode
)
126 NS_ENSURE_ARG_POINTER(aDevMode
);
129 CopyDevMode(mDevMode
, *aDevMode
);
136 NS_IMETHODIMP
nsPrintSettingsWin::SetDevMode(DEVMODEW
* aDevMode
)
139 ::HeapFree(::GetProcessHeap(), 0, mDevMode
);
144 CopyDevMode(aDevMode
, mDevMode
);
149 //-------------------------------------------
151 nsPrintSettingsWin::_Clone(nsIPrintSettings
**_retval
)
153 nsPrintSettingsWin
* printSettings
= new nsPrintSettingsWin(*this);
154 return printSettings
->QueryInterface(NS_GET_IID(nsIPrintSettings
), (void**)_retval
); // ref counts
157 //-------------------------------------------
158 nsPrintSettingsWin
& nsPrintSettingsWin::operator=(const nsPrintSettingsWin
& rhs
)
164 ((nsPrintSettings
&) *this) = rhs
;
167 nsCRT::free(mDeviceName
);
171 nsCRT::free(mDriverName
);
174 // Use free because we used the native malloc to create the memory
176 ::HeapFree(::GetProcessHeap(), 0, mDevMode
);
179 mDeviceName
= rhs
.mDeviceName
?wcsdup(rhs
.mDeviceName
):nsnull
;
180 mDriverName
= rhs
.mDriverName
?wcsdup(rhs
.mDriverName
):nsnull
;
183 CopyDevMode(rhs
.mDevMode
, mDevMode
);
191 //-------------------------------------------
192 /* void assign (in nsIPrintSettings aPS); */
194 nsPrintSettingsWin::_Assign(nsIPrintSettings
*aPS
)
196 nsPrintSettingsWin
*psWin
= static_cast<nsPrintSettingsWin
*>(aPS
);
201 //----------------------------------------------------------------------
202 // Testing of assign and clone
203 // This define turns on the testing module below
204 // so at start up it writes and reads the prefs.
206 #include "nsIPrintOptions.h"
207 #include "nsIServiceManager.h"
214 nsCOMPtr
<nsIPrintSettings
> ps
;
216 nsCOMPtr
<nsIPrintOptions
> printService
= do_GetService("@mozilla.org/gfx/printsettings-service;1", &rv
);
217 if (NS_SUCCEEDED(rv
)) {
218 rv
= printService
->CreatePrintSettings(getter_AddRefs(ps
));
222 ps
->SetPrintOptions(nsIPrintSettings::kPrintOddPages
, PR_TRUE
);
223 ps
->SetPrintOptions(nsIPrintSettings::kPrintEvenPages
, PR_FALSE
);
224 ps
->SetMarginTop(1.0);
225 ps
->SetMarginLeft(1.0);
226 ps
->SetMarginBottom(1.0);
227 ps
->SetMarginRight(1.0);
229 ps
->SetPrintBGColors(PR_TRUE
);
230 ps
->SetPrintBGImages(PR_TRUE
);
231 ps
->SetPrintRange(15);
232 ps
->SetHeaderStrLeft(NS_ConvertUTF8toUTF16("Left").get());
233 ps
->SetHeaderStrCenter(NS_ConvertUTF8toUTF16("Center").get());
234 ps
->SetHeaderStrRight(NS_ConvertUTF8toUTF16("Right").get());
235 ps
->SetFooterStrLeft(NS_ConvertUTF8toUTF16("Left").get());
236 ps
->SetFooterStrCenter(NS_ConvertUTF8toUTF16("Center").get());
237 ps
->SetFooterStrRight(NS_ConvertUTF8toUTF16("Right").get());
238 ps
->SetPaperName(NS_ConvertUTF8toUTF16("Paper Name").get());
239 ps
->SetPaperSizeType(10);
241 ps
->SetPaperWidth(100.0);
242 ps
->SetPaperHeight(50.0);
243 ps
->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters
);
244 ps
->SetPrintReversed(PR_TRUE
);
245 ps
->SetPrintInColor(PR_TRUE
);
246 ps
->SetOrientation(nsIPrintSettings::kLandscapeOrientation
);
247 ps
->SetPrintCommand(NS_ConvertUTF8toUTF16("Command").get());
249 ps
->SetPrinterName(NS_ConvertUTF8toUTF16("Printer Name").get());
250 ps
->SetPrintToFile(PR_TRUE
);
251 ps
->SetToFileName(NS_ConvertUTF8toUTF16("File Name").get());
252 ps
->SetPrintPageDelay(1000);
254 nsCOMPtr
<nsIPrintSettings
> ps2
;
255 if (NS_SUCCEEDED(rv
)) {
256 rv
= printService
->CreatePrintSettings(getter_AddRefs(ps2
));
261 nsCOMPtr
<nsIPrintSettings
> psClone
;
262 ps2
->Clone(getter_AddRefs(psClone
));