зеркало из https://github.com/mozilla/pjs.git
Implement the assign method with an "=" operator
Bug 151628 r=ccarlen sr=jst BUg CVS: ----------------------------------------------------------------------
This commit is contained in:
Родитель
938aaaf369
Коммит
ae80bd8a7d
|
@ -171,6 +171,11 @@ interface nsIPrintSettings : nsISupports
|
|||
*/
|
||||
nsIPrintSettings clone();
|
||||
|
||||
/**
|
||||
* Assigns the internal values from the "in" arg to the current object
|
||||
*/
|
||||
void assign(in nsIPrintSettings aPS);
|
||||
|
||||
/**
|
||||
* Data Members
|
||||
*/
|
||||
|
|
|
@ -60,8 +60,7 @@ nsPrintOptionsMac::~nsPrintOptionsMac()
|
|||
/** ---------------------------------------------------
|
||||
* See documentation in nsPrintOptionsImpl.h
|
||||
*/
|
||||
/* nsIPrintSettings CreatePrintSettings (); */
|
||||
NS_IMETHODIMP nsPrintOptionsMac::CreatePrintSettings(nsIPrintSettings **_retval)
|
||||
NS_IMETHODIMP nsPrintOptionsMac::_CreatePrintSettings(nsIPrintSettings **_retval)
|
||||
{
|
||||
nsresult rv;
|
||||
nsPrintSettingsMac* printSettings = new nsPrintSettingsMac(); // does not initially ref count
|
||||
|
|
|
@ -42,8 +42,9 @@ public:
|
|||
|
||||
NS_IMETHOD GetNativeData(PRInt16 aDataType, void * *_retval);
|
||||
|
||||
NS_IMETHOD CreatePrintSettings(nsIPrintSettings **_retval);
|
||||
protected:
|
||||
nsresult _CreatePrintSettings(nsIPrintSettings **_retval);
|
||||
|
||||
nsresult ReadPrefs(nsIPrintSettings* aPS, const nsString& aPrefName, PRUint32 aFlags);
|
||||
nsresult WritePrefs(nsIPrintSettings* aPS, const nsString& aPrefName, PRUint32 aFlags);
|
||||
};
|
||||
|
|
|
@ -67,8 +67,7 @@ nsPrintOptionsX::~nsPrintOptionsX()
|
|||
/** ---------------------------------------------------
|
||||
* See documentation in nsPrintOptionsImpl.h
|
||||
*/
|
||||
/* nsIPrintSettings CreatePrintSettings (); */
|
||||
NS_IMETHODIMP nsPrintOptionsX::CreatePrintSettings(nsIPrintSettings **_retval)
|
||||
nsresult nsPrintOptionsX::_CreatePrintSettings(nsIPrintSettings **_retval)
|
||||
{
|
||||
nsresult rv;
|
||||
nsPrintSettingsX* printSettings = new nsPrintSettingsX; // does not initially ref count
|
||||
|
|
|
@ -56,9 +56,8 @@ public:
|
|||
|
||||
NS_IMETHOD GetNativeData(PRInt16 aDataType, void * *_retval);
|
||||
|
||||
NS_IMETHOD CreatePrintSettings(nsIPrintSettings **_retval);
|
||||
|
||||
protected:
|
||||
nsresult _CreatePrintSettings(nsIPrintSettings **_retval);
|
||||
|
||||
nsresult ReadPrefs(nsIPrintSettings* aPS, const nsString& aPrefName, PRUint32 aFlags);
|
||||
nsresult WritePrefs(nsIPrintSettings* aPS, const nsString& aPrefName, PRUint32 aFlags);
|
||||
|
|
|
@ -61,6 +61,15 @@ nsPrintSettingsMac::nsPrintSettingsMac() :
|
|||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
nsPrintSettingsMac::nsPrintSettingsMac(const nsPrintSettingsMac& src) :
|
||||
mPrintRecord(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
*this = src;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
nsPrintSettingsMac::~nsPrintSettingsMac()
|
||||
|
@ -69,6 +78,27 @@ nsPrintSettingsMac::~nsPrintSettingsMac()
|
|||
::DisposeHandle((Handle)mPrintRecord);
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
nsPrintSettingsMac& nsPrintSettingsMac::operator=(const nsPrintSettingsMac& rhs)
|
||||
{
|
||||
if (this == &rhs) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsPrintSettings::operator=(rhs);
|
||||
|
||||
if (mPrintRecord) {
|
||||
::DisposeHandle((Handle)mPrintRecord);
|
||||
mPrintRecord = nsnull;
|
||||
}
|
||||
Handle copyH = (Handle)rhs.mPrintRecord;
|
||||
if (::HandToHand(©H) == noErr)
|
||||
mPrintRecord = (THPrint)copyH;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
NS_IMETHODIMP nsPrintSettingsMac::Init()
|
||||
|
@ -181,3 +211,28 @@ NS_IMETHODIMP nsPrintSettingsMac::WritePageSetupToPrefs()
|
|||
|
||||
return prefBranch->SetCharPref(MAC_OS_PAGE_SETUP_PREFNAME, encodedData);
|
||||
}
|
||||
|
||||
//-------------------------------------------
|
||||
nsresult nsPrintSettingsMac::_Clone(nsIPrintSettings **_retval)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
*_retval = nsnull;
|
||||
|
||||
nsPrintSettingsMac *newSettings = new nsPrintSettingsMac(*this);
|
||||
if (!newSettings)
|
||||
return NS_ERROR_FAILURE;
|
||||
*_retval = newSettings;
|
||||
NS_ADDREF(*_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------
|
||||
nsresult nsPrintSettingsMac::_Assign(nsIPrintSettings *aPS)
|
||||
{
|
||||
nsPrintSettingsMac *printSettingsMac = dynamic_cast<nsPrintSettingsMac*>(aPS);
|
||||
if (!printSettingsMac)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
*this = *printSettingsMac;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,11 @@ public:
|
|||
nsresult Init();
|
||||
|
||||
protected:
|
||||
nsPrintSettingsMac(const nsPrintSettingsMac& src);
|
||||
nsPrintSettingsMac& operator=(const nsPrintSettingsMac& rhs);
|
||||
|
||||
nsresult _Clone(nsIPrintSettings **_retval);
|
||||
nsresult _Assign(nsIPrintSettings *aPS);
|
||||
|
||||
THPrint mPrintRecord;
|
||||
|
||||
|
|
|
@ -65,6 +65,16 @@ nsPrintSettingsX::nsPrintSettingsX() :
|
|||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
nsPrintSettingsX::nsPrintSettingsX(const nsPrintSettingsX& src) :
|
||||
mPageFormat(kPMNoPageFormat),
|
||||
mPrintSettings(kPMNoPrintSettings)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
*this = src;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
nsPrintSettingsX::~nsPrintSettingsX()
|
||||
|
@ -75,6 +85,53 @@ nsPrintSettingsX::~nsPrintSettingsX()
|
|||
}
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
nsPrintSettingsX& nsPrintSettingsX::operator=(const nsPrintSettingsX& rhs)
|
||||
{
|
||||
if (this == &rhs) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsPrintSettings::operator=(rhs);
|
||||
|
||||
OSStatus status;
|
||||
|
||||
if (mPageFormat != kPMNoPageFormat) {
|
||||
::PMDisposePageFormat(mPageFormat);
|
||||
mPageFormat = kPMNoPageFormat;
|
||||
}
|
||||
if (rhs.mPageFormat != kPMNoPageFormat) {
|
||||
PMPageFormat pageFormat;
|
||||
status = ::PMNewPageFormat(&pageFormat);
|
||||
if (status == noErr) {
|
||||
status = ::PMCopyPageFormat(rhs.mPageFormat, pageFormat);
|
||||
if (status == noErr)
|
||||
mPageFormat = pageFormat;
|
||||
else
|
||||
::PMDisposePageFormat(pageFormat);
|
||||
}
|
||||
}
|
||||
|
||||
if (mPrintSettings != kPMNoPrintSettings) {
|
||||
::PMDisposePrintSettings(mPrintSettings);
|
||||
mPrintSettings = kPMNoPrintSettings;
|
||||
}
|
||||
if (rhs.mPrintSettings != kPMNoPrintSettings) {
|
||||
PMPrintSettings printSettings;
|
||||
status = ::PMNewPrintSettings(&printSettings);
|
||||
if (status == noErr) {
|
||||
status = ::PMCopyPrintSettings(rhs.mPrintSettings, printSettings);
|
||||
if (status == noErr)
|
||||
mPrintSettings = printSettings;
|
||||
else
|
||||
::PMDisposePrintSettings(printSettings);
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
nsresult nsPrintSettingsX::Init()
|
||||
|
@ -252,3 +309,29 @@ NS_IMETHODIMP nsPrintSettingsX::WritePageFormatToPrefs()
|
|||
|
||||
return prefBranch->SetCharPref(MAC_OS_X_PAGE_SETUP_PREFNAME, encodedData);
|
||||
}
|
||||
|
||||
//-------------------------------------------
|
||||
nsresult nsPrintSettingsX::_Clone(nsIPrintSettings **_retval)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
*_retval = nsnull;
|
||||
|
||||
nsPrintSettingsX *newSettings = new nsPrintSettingsX(*this);
|
||||
if (!newSettings)
|
||||
return NS_ERROR_FAILURE;
|
||||
*_retval = newSettings;
|
||||
NS_ADDREF(*_retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------
|
||||
NS_IMETHODIMP nsPrintSettingsX::_Assign(nsIPrintSettings *aPS)
|
||||
{
|
||||
nsPrintSettingsX *printSettingsX = dynamic_cast<nsPrintSettingsX*>(aPS);
|
||||
if (!printSettingsX)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
*this = *printSettingsX;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,12 @@ public:
|
|||
nsresult Init();
|
||||
|
||||
protected:
|
||||
nsPrintSettingsX(const nsPrintSettingsX& src);
|
||||
nsPrintSettingsX& operator=(const nsPrintSettingsX& rhs);
|
||||
|
||||
nsresult _Clone(nsIPrintSettings **_retval);
|
||||
nsresult _Assign(nsIPrintSettings *aPS);
|
||||
|
||||
PMPageFormat mPageFormat;
|
||||
PMPrintSettings mPrintSettings;
|
||||
};
|
||||
|
|
|
@ -840,8 +840,7 @@ NS_IMETHODIMP nsPrintOptions::GetNativeData(PRInt16 aDataType, void * *_retval)
|
|||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* nsIPrintSettings CreatePrintSettings (); */
|
||||
NS_IMETHODIMP nsPrintOptions::CreatePrintSettings(nsIPrintSettings **_retval)
|
||||
nsresult nsPrintOptions::_CreatePrintSettings(nsIPrintSettings **_retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsPrintSettings* printSettings = new nsPrintSettings(); // does not initially ref count
|
||||
|
@ -855,6 +854,12 @@ NS_IMETHODIMP nsPrintOptions::CreatePrintSettings(nsIPrintSettings **_retval)
|
|||
return rv;
|
||||
}
|
||||
|
||||
/* nsIPrintSettings CreatePrintSettings (); */
|
||||
NS_IMETHODIMP nsPrintOptions::CreatePrintSettings(nsIPrintSettings **_retval)
|
||||
{
|
||||
return _CreatePrintSettings(_retval);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------
|
||||
//-----------------------------------------------------
|
||||
//-- nsIPrintSettingsService
|
||||
|
|
|
@ -60,6 +60,9 @@ protected:
|
|||
virtual nsresult WritePrefs(nsIPrintSettings* aPS, const nsString& aPrefName, PRUint32 aFlags);
|
||||
const char* GetPrefName(const char * aPrefName,
|
||||
const nsString& aPrinterName);
|
||||
|
||||
// May be implemented by the platform-specific derived class
|
||||
virtual nsresult _CreatePrintSettings(nsIPrintSettings **_retval);
|
||||
|
||||
// Members
|
||||
nsCOMPtr<nsIPrintSettings> mGlobalPrintSettings;
|
||||
|
|
|
@ -95,40 +95,11 @@ nsPrintSettings::nsPrintSettings() :
|
|||
* See documentation in nsPrintSettingsImpl.h
|
||||
* @update 6/21/00 dwc
|
||||
*/
|
||||
nsPrintSettings::nsPrintSettings(const nsPrintSettings* aPS) :
|
||||
mPrintOptions(aPS->mPrintOptions),
|
||||
mPrintRange(aPS->mPrintRange),
|
||||
mStartPageNum(aPS->mStartPageNum),
|
||||
mEndPageNum(aPS->mEndPageNum),
|
||||
mScaling(aPS->mScaling),
|
||||
mPrintBGColors(aPS->mPrintBGColors),
|
||||
mPrintBGImages(aPS->mPrintBGImages),
|
||||
mPrintFrameTypeUsage(aPS->mPrintFrameTypeUsage),
|
||||
mPrintFrameType(aPS->mPrintFrameType),
|
||||
mHowToEnableFrameUI(aPS->mHowToEnableFrameUI),
|
||||
mIsCancelled(aPS->mIsCancelled),
|
||||
mPrintSilent(aPS->mPrintSilent),
|
||||
mPrintPreview(aPS->mPrintPreview),
|
||||
mShrinkToFit(aPS->mShrinkToFit),
|
||||
mPrintPageDelay(aPS->mPrintPageDelay),
|
||||
mPaperData(aPS->mPaperData),
|
||||
mPaperSizeType(aPS->mPaperSizeType),
|
||||
mPaperWidth(aPS->mPaperWidth),
|
||||
mPaperHeight(aPS->mPaperHeight),
|
||||
mPaperSizeUnit(aPS->mPaperSizeUnit),
|
||||
mPrintReversed(aPS->mPrintReversed),
|
||||
mPrintInColor(aPS->mPrintInColor),
|
||||
mOrientation(aPS->mOrientation),
|
||||
mNumCopies(aPS->mNumCopies),
|
||||
mPrintToFile(aPS->mPrintToFile),
|
||||
mMargin(aPS->mMargin)
|
||||
nsPrintSettings::nsPrintSettings(const nsPrintSettings& aPS)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
|
||||
for (PRInt32 i=0;i<3;i++) {
|
||||
mHeaderStrs[i] = aPS->mHeaderStrs[i];
|
||||
mFooterStrs[i] = aPS->mFooterStrs[i];
|
||||
}
|
||||
*this = aPS;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
|
@ -227,8 +198,12 @@ NS_IMETHODIMP nsPrintSettings::GetPrinterName(PRUnichar * *aPrinter)
|
|||
}
|
||||
NS_IMETHODIMP nsPrintSettings::SetPrinterName(const PRUnichar * aPrinter)
|
||||
{
|
||||
mPrinter = aPrinter;
|
||||
return NS_OK;
|
||||
if (aPrinter) {
|
||||
mPrinter = aPrinter;
|
||||
} else {
|
||||
mPrinter.SetLength(0);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute long numCopies; */
|
||||
|
@ -253,7 +228,11 @@ NS_IMETHODIMP nsPrintSettings::GetPrintCommand(PRUnichar * *aPrintCommand)
|
|||
}
|
||||
NS_IMETHODIMP nsPrintSettings::SetPrintCommand(const PRUnichar * aPrintCommand)
|
||||
{
|
||||
mPrintCommand = aPrintCommand;
|
||||
if (aPrintCommand) {
|
||||
mPrintCommand = aPrintCommand;
|
||||
} else {
|
||||
mPrintCommand.SetLength(0);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -279,7 +258,11 @@ NS_IMETHODIMP nsPrintSettings::GetToFileName(PRUnichar * *aToFileName)
|
|||
}
|
||||
NS_IMETHODIMP nsPrintSettings::SetToFileName(const PRUnichar * aToFileName)
|
||||
{
|
||||
mToFileName = aToFileName;
|
||||
if (aToFileName) {
|
||||
mToFileName = aToFileName;
|
||||
} else {
|
||||
mToFileName.SetLength(0);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -413,8 +396,11 @@ NS_IMETHODIMP nsPrintSettings::GetTitle(PRUnichar * *aTitle)
|
|||
}
|
||||
NS_IMETHODIMP nsPrintSettings::SetTitle(const PRUnichar * aTitle)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aTitle);
|
||||
mTitle = aTitle;
|
||||
if (aTitle) {
|
||||
mTitle = aTitle;
|
||||
} else {
|
||||
mTitle.SetLength(0);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -431,8 +417,11 @@ NS_IMETHODIMP nsPrintSettings::GetDocURL(PRUnichar * *aDocURL)
|
|||
}
|
||||
NS_IMETHODIMP nsPrintSettings::SetDocURL(const PRUnichar * aDocURL)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDocURL);
|
||||
mURL = aDocURL;
|
||||
if (aDocURL) {
|
||||
mURL = aDocURL;
|
||||
} else {
|
||||
mURL.SetLength(0);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -659,8 +648,11 @@ NS_IMETHODIMP nsPrintSettings::GetPaperName(PRUnichar * *aPaperName)
|
|||
}
|
||||
NS_IMETHODIMP nsPrintSettings::SetPaperName(const PRUnichar * aPaperName)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aPaperName);
|
||||
mPaperName = aPaperName;
|
||||
if (aPaperName) {
|
||||
mPaperName = aPaperName;
|
||||
} else {
|
||||
mPaperName.SetLength(0);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -796,9 +788,9 @@ nsPrintSettings::GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight)
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsPrintSettings::CloneObj(nsIPrintSettings **_retval)
|
||||
nsPrintSettings::_Clone(nsIPrintSettings **_retval)
|
||||
{
|
||||
nsPrintSettings* printSettings = new nsPrintSettings(this);
|
||||
nsPrintSettings* printSettings = new nsPrintSettings(*this);
|
||||
return printSettings->QueryInterface(NS_GET_IID(nsIPrintSettings), (void**)_retval); // ref counts
|
||||
}
|
||||
|
||||
|
@ -806,5 +798,72 @@ nsPrintSettings::CloneObj(nsIPrintSettings **_retval)
|
|||
NS_IMETHODIMP
|
||||
nsPrintSettings::Clone(nsIPrintSettings **_retval)
|
||||
{
|
||||
return CloneObj(_retval);
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
return _Clone(_retval);
|
||||
}
|
||||
|
||||
/* void assign (in nsIPrintSettings aPS); */
|
||||
nsresult
|
||||
nsPrintSettings::_Assign(nsIPrintSettings *aPS)
|
||||
{
|
||||
nsPrintSettings *ps = NS_STATIC_CAST(nsPrintSettings*, aPS);
|
||||
*this = *ps;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void assign (in nsIPrintSettings aPS); */
|
||||
NS_IMETHODIMP
|
||||
nsPrintSettings::Assign(nsIPrintSettings *aPS)
|
||||
{
|
||||
NS_ENSURE_ARG(aPS);
|
||||
return _Assign(aPS);
|
||||
}
|
||||
|
||||
//-------------------------------------------
|
||||
nsPrintSettings& nsPrintSettings::operator=(const nsPrintSettings& rhs)
|
||||
{
|
||||
if (this == &rhs) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
mStartPageNum = rhs.mStartPageNum;
|
||||
mEndPageNum = rhs.mEndPageNum;
|
||||
mMargin = rhs.mMargin;
|
||||
mScaling = rhs.mScaling;
|
||||
mPrintBGColors = rhs.mPrintBGColors;
|
||||
mPrintBGImages = rhs.mPrintBGImages;
|
||||
mPrintRange = rhs.mPrintRange;
|
||||
mTitle = rhs.mTitle;
|
||||
mURL = rhs.mURL;
|
||||
mHowToEnableFrameUI = rhs.mHowToEnableFrameUI;
|
||||
mIsCancelled = rhs.mIsCancelled;
|
||||
mPrintFrameTypeUsage = rhs.mPrintFrameTypeUsage;
|
||||
mPrintFrameType = rhs.mPrintFrameType;
|
||||
mPrintSilent = rhs.mPrintSilent;
|
||||
mShrinkToFit = rhs.mShrinkToFit;
|
||||
mShowPrintProgress = rhs.mShowPrintProgress;
|
||||
mPaperName = rhs.mPaperName;
|
||||
mPaperSizeType = rhs.mPaperSizeType;
|
||||
mPaperData = rhs.mPaperData;
|
||||
mPaperWidth = rhs.mPaperWidth;
|
||||
mPaperHeight = rhs.mPaperHeight;
|
||||
mPaperSizeUnit = rhs.mPaperSizeUnit;
|
||||
mPrintReversed = rhs.mPrintReversed;
|
||||
mPrintInColor = rhs.mPrintInColor;
|
||||
mPaperSize = rhs.mPaperSize;
|
||||
mOrientation = rhs.mOrientation;
|
||||
mPrintCommand = rhs.mPrintCommand;
|
||||
mNumCopies = rhs.mNumCopies;
|
||||
mPrinter = rhs.mPrinter;
|
||||
mPrintToFile = rhs.mPrintToFile;
|
||||
mToFileName = rhs.mToFileName;
|
||||
mPrintPageDelay = rhs.mPrintPageDelay;
|
||||
|
||||
for (PRInt32 i=0;i<NUM_HEAD_FOOT;i++) {
|
||||
mHeaderStrs[i] = rhs.mHeaderStrs[i];
|
||||
mFooterStrs[i] = rhs.mFooterStrs[i];
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include "nsMargin.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#define NUM_HEAD_FOOT 3
|
||||
|
||||
//*****************************************************************************
|
||||
//*** nsPrintSettings
|
||||
//*****************************************************************************
|
||||
|
@ -37,17 +39,22 @@ public:
|
|||
NS_DECL_NSIPRINTSETTINGS
|
||||
|
||||
nsPrintSettings();
|
||||
nsPrintSettings(const nsPrintSettings* aPS);
|
||||
nsPrintSettings(const nsPrintSettings& aPS);
|
||||
virtual ~nsPrintSettings();
|
||||
|
||||
protected:
|
||||
virtual nsresult CloneObj(nsIPrintSettings **_retval);
|
||||
nsPrintSettings& operator=(const nsPrintSettings& rhs);
|
||||
|
||||
protected:
|
||||
// May be implemented by the platform-specific derived class
|
||||
virtual nsresult _Clone(nsIPrintSettings **_retval);
|
||||
virtual nsresult _Assign(nsIPrintSettings *aPS);
|
||||
|
||||
typedef enum {
|
||||
eHeader,
|
||||
eFooter
|
||||
} nsHeaderFooterEnum;
|
||||
|
||||
|
||||
nsresult GetMarginStrs(PRUnichar * *aTitle, nsHeaderFooterEnum aType, PRInt16 aJust);
|
||||
nsresult SetMarginStrs(const PRUnichar * aTitle, nsHeaderFooterEnum aType, PRInt16 aJust);
|
||||
|
||||
|
@ -76,8 +83,8 @@ protected:
|
|||
nsString mTitle;
|
||||
nsString mURL;
|
||||
nsString mPageNumberFormat;
|
||||
nsString mHeaderStrs[3];
|
||||
nsString mFooterStrs[3];
|
||||
nsString mHeaderStrs[NUM_HEAD_FOOT];
|
||||
nsString mFooterStrs[NUM_HEAD_FOOT];
|
||||
|
||||
nsString mPaperName;
|
||||
PRInt16 mPaperData;
|
||||
|
|
|
@ -783,7 +783,7 @@ NS_IMETHODIMP nsDeviceContextWin :: BeginDocument(PRUnichar * aTitle, PRUnichar*
|
|||
docinfo.lpszDocName = title != nsnull?title:"Mozilla Document";
|
||||
|
||||
#ifdef DEBUG_rods
|
||||
docinfo.lpszOutput = "p.ps";
|
||||
docinfo.lpszOutput = "\\p.ps";
|
||||
#else
|
||||
docinfo.lpszOutput = docName;
|
||||
#endif
|
||||
|
|
|
@ -59,20 +59,12 @@ nsPrintSettingsWin::nsPrintSettingsWin() :
|
|||
* See documentation in nsPrintSettingsWin.h
|
||||
* @update
|
||||
*/
|
||||
nsPrintSettingsWin::nsPrintSettingsWin(const nsPrintSettingsWin* aPS) :
|
||||
nsPrintSettings(aPS),
|
||||
nsPrintSettingsWin::nsPrintSettingsWin(const nsPrintSettingsWin& aPS) :
|
||||
mDeviceName(nsnull),
|
||||
mDriverName(nsnull),
|
||||
mDevMode(nsnull)
|
||||
{
|
||||
if (aPS->mDeviceName) mDeviceName = nsCRT::strdup(aPS->mDeviceName);
|
||||
if (aPS->mDriverName) mDriverName = nsCRT::strdup(aPS->mDriverName);
|
||||
|
||||
if (aPS->mDevMode) {
|
||||
size_t size = sizeof(*aPS->mDevMode);
|
||||
mDevMode = (LPDEVMODE)malloc(size);
|
||||
memcpy(mDevMode, aPS->mDevMode, size);
|
||||
}
|
||||
*this = aPS;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
|
@ -81,8 +73,8 @@ nsPrintSettingsWin::nsPrintSettingsWin(const nsPrintSettingsWin* aPS) :
|
|||
*/
|
||||
nsPrintSettingsWin::~nsPrintSettingsWin()
|
||||
{
|
||||
if (mDeviceName) nsCRT::free(mDeviceName);
|
||||
if (mDriverName) nsCRT::free(mDriverName);
|
||||
if (mDeviceName) nsMemory::Free(mDeviceName);
|
||||
if (mDriverName) nsMemory::Free(mDriverName);
|
||||
if (mDevMode) free(mDevMode);
|
||||
}
|
||||
|
||||
|
@ -90,7 +82,7 @@ nsPrintSettingsWin::~nsPrintSettingsWin()
|
|||
NS_IMETHODIMP nsPrintSettingsWin::SetDeviceName(char * aDeviceName)
|
||||
{
|
||||
if (mDeviceName) {
|
||||
nsCRT::free(mDeviceName);
|
||||
nsMemory::Free(mDeviceName);
|
||||
}
|
||||
mDeviceName = aDeviceName?nsCRT::strdup(aDeviceName):nsnull;
|
||||
return NS_OK;
|
||||
|
@ -106,7 +98,7 @@ NS_IMETHODIMP nsPrintSettingsWin::GetDeviceName(char * *aDeviceName)
|
|||
NS_IMETHODIMP nsPrintSettingsWin::SetDriverName(char * aDriverName)
|
||||
{
|
||||
if (mDriverName) {
|
||||
nsCRT::free(mDriverName);
|
||||
nsMemory::Free(mDriverName);
|
||||
}
|
||||
mDriverName = aDriverName?nsCRT::strdup(aDriverName):nsnull;
|
||||
return NS_OK;
|
||||
|
@ -132,6 +124,7 @@ NS_IMETHODIMP nsPrintSettingsWin::GetDevMode(DEVMODE * *aDevMode)
|
|||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsPrintSettingsWin::SetDevMode(DEVMODE * aDevMode)
|
||||
{
|
||||
if (mDevMode) {
|
||||
|
@ -147,10 +140,127 @@ NS_IMETHODIMP nsPrintSettingsWin::SetDevMode(DEVMODE * aDevMode)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* nsIPrintSettings clone (); */
|
||||
//-------------------------------------------
|
||||
nsresult
|
||||
nsPrintSettingsWin::CloneObj(nsIPrintSettings **_retval)
|
||||
nsPrintSettingsWin::_Clone(nsIPrintSettings **_retval)
|
||||
{
|
||||
nsPrintSettingsWin* printSettings = new nsPrintSettingsWin(this);
|
||||
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) {
|
||||
free(mDevMode);
|
||||
}
|
||||
|
||||
mDeviceName = rhs.mDeviceName?nsCRT::strdup(rhs.mDeviceName):nsnull;
|
||||
mDriverName = rhs.mDriverName?nsCRT::strdup(rhs.mDriverName):nsnull;
|
||||
|
||||
if (rhs.mDevMode) {
|
||||
size_t size = sizeof(*rhs.mDevMode);
|
||||
mDevMode = (LPDEVMODE)malloc(size);
|
||||
memcpy(mDevMode, rhs.mDevMode, size);
|
||||
} else {
|
||||
mDevMode = nsnull;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//-------------------------------------------
|
||||
/* void assign (in nsIPrintSettings aPS); */
|
||||
nsresult
|
||||
nsPrintSettingsWin::_Assign(nsIPrintSettings *aPS)
|
||||
{
|
||||
nsPrintSettingsWin *psWin = NS_STATIC_CAST(nsPrintSettingsWin*, aPS);
|
||||
*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) {
|
||||
ps->SetPrintOptions(nsIPrintSettings::kPrintOddPages, PR_TRUE);
|
||||
ps->SetPrintOptions(nsIPrintSettings::kPrintEvenPages, PR_FALSE);
|
||||
ps->SetMarginTop(1.0);
|
||||
ps->SetMarginLeft(1.0);
|
||||
ps->SetMarginBottom(1.0);
|
||||
ps->SetMarginRight(1.0);
|
||||
ps->SetScaling(0.5);
|
||||
ps->SetPrintBGColors(PR_TRUE);
|
||||
ps->SetPrintBGImages(PR_TRUE);
|
||||
ps->SetPrintRange(15);
|
||||
ps->SetHeaderStrLeft(NS_ConvertUTF8toUCS2("Left").get());
|
||||
ps->SetHeaderStrCenter(NS_ConvertUTF8toUCS2("Center").get());
|
||||
ps->SetHeaderStrRight(NS_ConvertUTF8toUCS2("Right").get());
|
||||
ps->SetFooterStrLeft(NS_ConvertUTF8toUCS2("Left").get());
|
||||
ps->SetFooterStrCenter(NS_ConvertUTF8toUCS2("Center").get());
|
||||
ps->SetFooterStrRight(NS_ConvertUTF8toUCS2("Right").get());
|
||||
ps->SetPaperName(NS_ConvertUTF8toUCS2("Paper Name").get());
|
||||
ps->SetPaperSizeType(10);
|
||||
ps->SetPaperData(1);
|
||||
ps->SetPaperWidth(100.0);
|
||||
ps->SetPaperHeight(50.0);
|
||||
ps->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters);
|
||||
ps->SetPrintReversed(PR_TRUE);
|
||||
ps->SetPrintInColor(PR_TRUE);
|
||||
ps->SetPaperSize(5);
|
||||
ps->SetOrientation(nsIPrintSettings::kLandscapeOrientation);
|
||||
ps->SetPrintCommand(NS_ConvertUTF8toUCS2("Command").get());
|
||||
ps->SetNumCopies(2);
|
||||
ps->SetPrinterName(NS_ConvertUTF8toUCS2("Printer Name").get());
|
||||
ps->SetPrintToFile(PR_TRUE);
|
||||
ps->SetToFileName(NS_ConvertUTF8toUCS2("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
|
||||
|
||||
|
|
|
@ -39,13 +39,23 @@ public:
|
|||
NS_DECL_NSIPRINTSETTINGSWIN
|
||||
|
||||
nsPrintSettingsWin();
|
||||
nsPrintSettingsWin(const nsPrintSettingsWin* aPS);
|
||||
nsPrintSettingsWin(const nsPrintSettingsWin& aPS);
|
||||
virtual ~nsPrintSettingsWin();
|
||||
|
||||
/**
|
||||
* Makes a new copy
|
||||
*/
|
||||
virtual nsresult CloneObj(nsIPrintSettings **_retval);
|
||||
virtual nsresult _Clone(nsIPrintSettings **_retval);
|
||||
|
||||
/**
|
||||
* Assigns values
|
||||
*/
|
||||
virtual nsresult _Assign(nsIPrintSettings* aPS);
|
||||
|
||||
/**
|
||||
* Assignment
|
||||
*/
|
||||
nsPrintSettingsWin& operator=(const nsPrintSettingsWin& rhs);
|
||||
|
||||
protected:
|
||||
char* mDeviceName;
|
||||
|
|
Загрузка…
Ссылка в новой задаче