2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
#include "nsPrintSettingsWin.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsPrintSettingsWin,
|
|
|
|
nsPrintSettings,
|
|
|
|
nsIPrintSettingsWin)
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
|
|
|
* See documentation in nsPrintSettingsWin.h
|
|
|
|
* @update
|
|
|
|
*/
|
|
|
|
nsPrintSettingsWin::nsPrintSettingsWin() :
|
|
|
|
nsPrintSettings(),
|
|
|
|
mDeviceName(nsnull),
|
|
|
|
mDriverName(nsnull),
|
|
|
|
mDevMode(nsnull)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
|
|
|
* See documentation in nsPrintSettingsWin.h
|
|
|
|
* @update
|
|
|
|
*/
|
|
|
|
nsPrintSettingsWin::nsPrintSettingsWin(const nsPrintSettingsWin& aPS) :
|
|
|
|
mDeviceName(nsnull),
|
|
|
|
mDriverName(nsnull),
|
|
|
|
mDevMode(nsnull)
|
|
|
|
{
|
|
|
|
*this = aPS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
|
|
|
* See documentation in nsPrintSettingsWin.h
|
|
|
|
* @update
|
|
|
|
*/
|
|
|
|
nsPrintSettingsWin::~nsPrintSettingsWin()
|
|
|
|
{
|
|
|
|
if (mDeviceName) nsMemory::Free(mDeviceName);
|
|
|
|
if (mDriverName) nsMemory::Free(mDriverName);
|
|
|
|
if (mDevMode) ::HeapFree(::GetProcessHeap(), 0, mDevMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [noscript] attribute charPtr deviceName; */
|
2008-10-21 17:54:26 -07:00
|
|
|
NS_IMETHODIMP nsPrintSettingsWin::SetDeviceName(const PRUnichar * aDeviceName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mDeviceName) {
|
|
|
|
nsMemory::Free(mDeviceName);
|
|
|
|
}
|
2008-10-23 22:21:15 -07:00
|
|
|
mDeviceName = aDeviceName?wcsdup(aDeviceName):nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-10-21 17:54:26 -07:00
|
|
|
NS_IMETHODIMP nsPrintSettingsWin::GetDeviceName(PRUnichar **aDeviceName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDeviceName);
|
2008-10-23 22:21:15 -07:00
|
|
|
*aDeviceName = mDeviceName?wcsdup(mDeviceName):nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [noscript] attribute charPtr driverName; */
|
2008-10-21 17:54:26 -07:00
|
|
|
NS_IMETHODIMP nsPrintSettingsWin::SetDriverName(const PRUnichar * aDriverName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mDriverName) {
|
|
|
|
nsMemory::Free(mDriverName);
|
|
|
|
}
|
2008-10-23 22:21:15 -07:00
|
|
|
mDriverName = aDriverName?wcsdup(aDriverName):nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-10-21 17:54:26 -07:00
|
|
|
NS_IMETHODIMP nsPrintSettingsWin::GetDriverName(PRUnichar **aDriverName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDriverName);
|
2008-10-23 22:21:15 -07:00
|
|
|
*aDriverName = mDriverName?wcsdup(mDriverName):nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-21 17:54:26 -07:00
|
|
|
void nsPrintSettingsWin::CopyDevMode(DEVMODEW* aInDevMode, DEVMODEW *& aOutDevMode)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aOutDevMode = nsnull;
|
|
|
|
size_t size = aInDevMode->dmSize + aInDevMode->dmDriverExtra;
|
2008-10-21 17:54:26 -07:00
|
|
|
aOutDevMode = (LPDEVMODEW)::HeapAlloc (::GetProcessHeap(), HEAP_ZERO_MEMORY, size);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aOutDevMode) {
|
|
|
|
memcpy(aOutDevMode, aInDevMode, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [noscript] attribute nsDevMode devMode; */
|
2008-10-21 17:54:26 -07:00
|
|
|
NS_IMETHODIMP nsPrintSettingsWin::GetDevMode(DEVMODEW * *aDevMode)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDevMode);
|
|
|
|
|
|
|
|
if (mDevMode) {
|
|
|
|
CopyDevMode(mDevMode, *aDevMode);
|
|
|
|
} else {
|
|
|
|
*aDevMode = nsnull;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-21 17:54:26 -07:00
|
|
|
NS_IMETHODIMP nsPrintSettingsWin::SetDevMode(DEVMODEW * aDevMode)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mDevMode) {
|
|
|
|
::HeapFree(::GetProcessHeap(), 0, mDevMode);
|
|
|
|
mDevMode = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aDevMode) {
|
|
|
|
CopyDevMode(aDevMode, mDevMode);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------
|
|
|
|
nsresult
|
|
|
|
nsPrintSettingsWin::_Clone(nsIPrintSettings **_retval)
|
|
|
|
{
|
|
|
|
nsPrintSettingsWin* printSettings = new nsPrintSettingsWin(*this);
|
|
|
|
return printSettings->QueryInterface(NS_GET_IID(nsIPrintSettings), (void**)_retval); // ref counts
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------
|
|
|
|
nsPrintSettingsWin& nsPrintSettingsWin::operator=(const nsPrintSettingsWin& rhs)
|
|
|
|
{
|
|
|
|
if (this == &rhs) {
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
((nsPrintSettings&) *this) = rhs;
|
|
|
|
|
|
|
|
if (mDeviceName) {
|
|
|
|
nsCRT::free(mDeviceName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDriverName) {
|
|
|
|
nsCRT::free(mDriverName);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use free because we used the native malloc to create the memory
|
|
|
|
if (mDevMode) {
|
|
|
|
::HeapFree(::GetProcessHeap(), 0, mDevMode);
|
|
|
|
}
|
|
|
|
|
2008-10-23 22:21:15 -07:00
|
|
|
mDeviceName = rhs.mDeviceName?wcsdup(rhs.mDeviceName):nsnull;
|
|
|
|
mDriverName = rhs.mDriverName?wcsdup(rhs.mDriverName):nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (rhs.mDevMode) {
|
|
|
|
CopyDevMode(rhs.mDevMode, mDevMode);
|
|
|
|
} else {
|
|
|
|
mDevMode = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------
|
|
|
|
/* void assign (in nsIPrintSettings aPS); */
|
|
|
|
nsresult
|
|
|
|
nsPrintSettingsWin::_Assign(nsIPrintSettings *aPS)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsPrintSettingsWin *psWin = static_cast<nsPrintSettingsWin*>(aPS);
|
2007-03-22 10:30:00 -07:00
|
|
|
*this = *psWin;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Testing of assign and clone
|
|
|
|
// This define turns on the testing module below
|
|
|
|
// so at start up it writes and reads the prefs.
|
|
|
|
#ifdef DEBUG_rodsX
|
|
|
|
#include "nsIPrintOptions.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
class Tester {
|
|
|
|
public:
|
|
|
|
Tester();
|
|
|
|
};
|
|
|
|
Tester::Tester()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrintSettings> ps;
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIPrintOptions> printService = do_GetService("@mozilla.org/gfx/printsettings-service;1", &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = printService->CreatePrintSettings(getter_AddRefs(ps));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ps) {
|
2011-10-01 19:16:19 -07:00
|
|
|
ps->SetPrintOptions(nsIPrintSettings::kPrintOddPages, true);
|
|
|
|
ps->SetPrintOptions(nsIPrintSettings::kPrintEvenPages, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
ps->SetMarginTop(1.0);
|
|
|
|
ps->SetMarginLeft(1.0);
|
|
|
|
ps->SetMarginBottom(1.0);
|
|
|
|
ps->SetMarginRight(1.0);
|
|
|
|
ps->SetScaling(0.5);
|
2011-10-01 19:16:19 -07:00
|
|
|
ps->SetPrintBGColors(true);
|
|
|
|
ps->SetPrintBGImages(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
ps->SetPrintRange(15);
|
|
|
|
ps->SetHeaderStrLeft(NS_ConvertUTF8toUTF16("Left").get());
|
|
|
|
ps->SetHeaderStrCenter(NS_ConvertUTF8toUTF16("Center").get());
|
|
|
|
ps->SetHeaderStrRight(NS_ConvertUTF8toUTF16("Right").get());
|
|
|
|
ps->SetFooterStrLeft(NS_ConvertUTF8toUTF16("Left").get());
|
|
|
|
ps->SetFooterStrCenter(NS_ConvertUTF8toUTF16("Center").get());
|
|
|
|
ps->SetFooterStrRight(NS_ConvertUTF8toUTF16("Right").get());
|
|
|
|
ps->SetPaperName(NS_ConvertUTF8toUTF16("Paper Name").get());
|
|
|
|
ps->SetPaperSizeType(10);
|
|
|
|
ps->SetPaperData(1);
|
|
|
|
ps->SetPaperWidth(100.0);
|
|
|
|
ps->SetPaperHeight(50.0);
|
|
|
|
ps->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters);
|
2011-10-01 19:16:19 -07:00
|
|
|
ps->SetPrintReversed(true);
|
|
|
|
ps->SetPrintInColor(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
ps->SetOrientation(nsIPrintSettings::kLandscapeOrientation);
|
|
|
|
ps->SetPrintCommand(NS_ConvertUTF8toUTF16("Command").get());
|
|
|
|
ps->SetNumCopies(2);
|
|
|
|
ps->SetPrinterName(NS_ConvertUTF8toUTF16("Printer Name").get());
|
2011-10-01 19:16:19 -07:00
|
|
|
ps->SetPrintToFile(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
ps->SetToFileName(NS_ConvertUTF8toUTF16("File Name").get());
|
|
|
|
ps->SetPrintPageDelay(1000);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrintSettings> ps2;
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = printService->CreatePrintSettings(getter_AddRefs(ps2));
|
|
|
|
}
|
|
|
|
|
|
|
|
ps2->Assign(ps);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrintSettings> psClone;
|
|
|
|
ps2->Clone(getter_AddRefs(psClone));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
Tester gTester;
|
|
|
|
#endif
|
|
|
|
|