Added UI for printing selectd frame

Bug 66783 r=kmcclusk,ben,dcone sr=buster
This commit is contained in:
rods%netscape.com 2006-02-07 01:12:20 +00:00
Родитель 4024aa1319
Коммит 801dc5544d
5 изменённых файлов: 622 добавлений и 406 удалений

Просмотреть файл

@ -26,98 +26,63 @@
%{ C++
#include "nsMargin.h"
#include "nsFont.h"
enum nsPrintRange {
ePrintRange_AllPages, // print all pages
ePrintRange_SpecifiedPageRange, // only print pages in the specified range
ePrintRange_Selection, // only print the selection
ePrintRange_FocusFrame // only print the frame with the current focus
};
/**
* Print Option Printing state bits.
*/
typedef PRUint32 nsPrintOptionsType;
#define NS_PRINT_OPTIONS_PRINT_ODD_PAGES 0x00000001
#define NS_PRINT_OPTIONS_PRINT_EVEN_PAGES 0x00000002
#define NS_PRINT_OPTIONS_PRINT_DOC_TITLE 0x00000004
#define NS_PRINT_OPTIONS_PRINT_DOC_LOCATION 0x00000008
#define NS_PRINT_OPTIONS_PRINT_PAGE_NUMS 0x00000010
#define NS_PRINT_OPTIONS_PRINT_PAGE_TOTAL 0x00000020
#define NS_PRINT_OPTIONS_PRINT_DATE_PRINTED 0x00000040
#define NS_PRINT_OPTIONS_ENABLE_SELECTION_RADIO 0x00000080
// There are currently NOT supported
#define NS_PRINT_OPTIONS_PRINT_BEVEL_LINES 0x00000100
#define NS_PRINT_OPTIONS_PRINT_BLACK_TEXT 0x00000200
#define NS_PRINT_OPTIONS_PRINT_BLACK_LINES 0x00000400
#define NS_PRINT_OPTIONS_PRINT_LAST_PAGE_FIRST 0x00000800
#define NS_PRINT_OPTIONS_PRINT_BACKGROUNDS 0x00001000
// Justification Flags
#define NS_PRINT_JUSTIFY_LEFT 0x00000001
#define NS_PRINT_JUSTIFY_CENTER 0x00000002
#define NS_PRINT_JUSTIFY_RIGHT 0x00000004
%}
/**
* Native types
*/
[ref] native nsNativeMarginRef(nsMargin);
[ref] native nsNativeFontRef(nsFont);
[ref] native nsNativeStringRef(nsString);
/**
* Simplified graphics interface for JS rendering.
*/
[scriptable, uuid(CAE87E20-479E-11d4-A856-00105A183419)]
interface nsIPrintOptions : nsISupports
{
%{C++
// Set Default Font of Header and footer
NS_IMETHOD SetDefaultFont(const nsFont &aFont) = 0;
NS_IMETHOD SetFontNamePointSize(const nsString& aFontName, nscoord aPointSize) = 0;
/* Print Option Flags for Bit Field*/
const long kOptPrintOddPages = 0x00000001;
const long kOptPrintEvenPages = 0x00000002;
const long kOptPrintDocTitle = 0x00000004;
const long kOptPrintDocLoc = 0x00000008;
const long kOptPrintPageNums = 0x00000010;
const long kOptPrintPageTotal = 0x00000020;
const long kOptPrintDatePrinted = 0x00000040;
const long kPrintOptionsEnableSelectionRB = 0x00000080;
NS_IMETHOD GetDefaultFont(nsFont &aFont) = 0;
/* Print Range Enums */
const long kRangeAllPages = 0;
const long kRangeSpecifiedPageRange = 1;
const long kRangeSelection = 2;
const long kRangeFocusFrame = 3;
// non-scriptable helper method
NS_IMETHOD GetMargin(nsMargin& aMargin) = 0;
%}
/* Justification Enums */
const long kJustLeft = 0;
const long kJustCenter = 1;
const long kJustRight = 2;
/**
* Set PageMargins
* Page Size Constants
*/
void SetMargins(in PRInt32 aTop, in PRInt32 aLeft, in PRInt32 aRight, in PRInt32 aBottom);
const short kLetterPaperSize = 0;
const short kLegalPaperSize = 1;
const short kExecutivePaperSize = 2;
const short kA4PaperSize = 3;
/**
* Get PageMargins
* Print Frame Constants
*/
void GetMargins(out PRInt32 aTop, out PRInt32 aLeft, out PRInt32 aRight, out PRInt32 aBottom);
const short kFramesAsIs = 0;
const short kSelectedFrame = 1;
const short kEachFrameSep = 2;
/**
* Show Native Print Options dialog, this may not be supported on all platforms
*/
void ShowNativeDialog();
/**
* Set Print Range
*/
void SetPrintRange(in PRInt32 aPrintRange);
/**
* Get Print Range
*/
void GetPrintRange(out PRInt32 aPrintRange);
/**
* Set Page Range
*/
void SetPageRange(in PRInt32 aStartPage, in PRInt32 aEndPage);
/**
* Get Page Range
*/
void GetPageRange(out PRInt32 aStartPage, out PRInt32 aEndPage);
/**
* Set PrintOptions
*/
@ -126,42 +91,12 @@ interface nsIPrintOptions : nsISupports
/**
* Get PrintOptions
*/
void GetPrintOptions(in PRInt32 aType, out PRBool aTurnOnOff);
PRBool GetPrintOptions(in PRInt32 aType);
/**
* Set PrintOptions Bit field
*/
void GetPrintOptionsBits(out PRInt32 aBits);
/**
* Set Title field for Header
*/
void SetTitle(in wstring aTitle);
/**
* Get Title field for Header
*/
void GetTitle(out wstring aTitle);
/**
* Set URL field for Header
*/
void SetURL(in wstring aURL);
/**
* Get URL field for Header
*/
void GetURL(out wstring aURL);
/**
* Set Page Number Print Justification
*/
void SetPageNumJust(in PRInt32 aJust);
/**
* Set Page Number Print Justification
*/
void GetPageNumJust(out PRInt32 aJust);
PRInt32 GetPrintOptionsBits();
/**
* Read Prefs
@ -173,4 +108,45 @@ interface nsIPrintOptions : nsISupports
*/
void WritePrefs();
/**
* Data Members
*/
attribute long startPageRange;
attribute long endPageRange;
attribute double marginTop; /* these are in inches */
attribute double marginLeft;
attribute double marginBottom;
attribute double marginRight;
attribute short printRange;
attribute short pageNumJust;
attribute wstring title;
attribute wstring docURL;
attribute boolean isPrintFrame;
attribute short printFrameType;
/* Additional XP Related */
attribute boolean printReversed;
attribute boolean printInColor; /* a false means grayscale */
attribute long paperSize; /* see page size consts */
attribute wstring printCommand;
attribute boolean printToFile;
attribute wstring toFileName;
/* No Script Methods */
[noscript] void SetFontNamePointSize(in nsNativeStringRef aName, in PRInt32 aPointSize);
[noscript] void SetMarginInTwips(in nsNativeMarginRef aMargin);
/* Purposely made this an "in" arg */
[noscript] void GetMarginInTwips(in nsNativeMarginRef aMargin);
[noscript] void SetDefaultFont(in nsNativeFontRef aMargin);
/* Purposely made this an "in" arg */
[noscript] void GetDefaultFont(in nsNativeFontRef aMargin);
};

Просмотреть файл

@ -133,7 +133,7 @@ NS_IMETHODIMP nsDeviceContextSpecGTK :: Init(PRBool aQuiet)
// if there is a current selection then enable the "Selection" radio button
if (NS_SUCCEEDED(rv) && printService) {
PRBool isOn;
printService->GetPrintOptions(NS_PRINT_OPTIONS_ENABLE_SELECTION_RADIO, &isOn);
printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, &isOn);
nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && pPrefs) {
(void) pPrefs->SetBoolPref("print.selection_radio_enabled", isOn);
@ -141,14 +141,19 @@ NS_IMETHODIMP nsDeviceContextSpecGTK :: Init(PRBool aQuiet)
}
char *path;
PRBool reversed = PR_FALSE, color = PR_FALSE, landscape = PR_FALSE;
PRBool tofile = PR_FALSE, allpagesRange = PR_TRUE, pageRange = PR_FALSE, selectionRange = PR_FALSE;
PRInt32 paper_size = NS_LETTER_SIZE;
PRInt32 fromPage = 1, toPage = 1;
int ileft = 500, iright = 500, itop = 500, ibottom = 500;
char *command;
char *printfile = nsnull;
PRBool reversed = PR_FALSE;
PRBool color = PR_FALSE;
PRBool tofile = PR_FALSE;
PRInt16 printRange = nsIPrintOptions::kRangeAllPages;
PRInt32 paper_size = NS_LETTER_SIZE;
PRInt32 fromPage = 1;
PRInt32 toPage = 1;
PRUnichar *command = nsnull;
PRUnichar *printfile = nsnull;
double dleft = 0.5;
double dright = 0.5;
double dtop = 0.5;
double dbottom = 0.5;
rv = NS_OK;
nsCOMPtr<nsIDialogParamBlock> ioParamBlock;
@ -189,65 +194,42 @@ NS_IMETHODIMP nsDeviceContextSpecGTK :: Init(PRBool aQuiet)
PRInt32 buttonPressed = 0;
ioParamBlock->GetInt(0, &buttonPressed);
if (buttonPressed == 0) {
nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && pPrefs) {
(void) pPrefs->GetBoolPref("print.print_reversed", &reversed);
(void) pPrefs->GetBoolPref("print.print_color", &color);
(void) pPrefs->GetBoolPref("print.print_landscape", &landscape);
(void) pPrefs->GetIntPref("print.print_paper_size", &paper_size);
(void) pPrefs->CopyCharPref("print.print_command", (char **) &command);
// the _js extention means these were set via script with the xp
// dialog as integers, int * 1000, meaning a 0.5 inches is 500
// the "real" values are set into the prefs as strings
// the PrintOption object will save out these values as twips
// in the prefs with these names without the _js extention
(void) pPrefs->GetIntPref("print.print_margin_top_js", &itop);
(void) pPrefs->GetIntPref("print.print_margin_left_js", &ileft);
(void) pPrefs->GetIntPref("print.print_margin_bottom_js", &ibottom);
(void) pPrefs->GetIntPref("print.print_margin_right_js", &iright);
if (printService) {
printService->GetPrintReversed(&reversed);
printService->GetPrintInColor(&color);
printService->GetPaperSize(&paper_size);
printService->GetPrintCommand(&command);
printService->GetPrintRange(&printRange);
printService->GetToFileName(&printfile);
printService->GetPrintToFile(&tofile);
printService->GetStartPageRange(&fromPage);
printService->GetEndPageRange(&toPage);
printService->GetMarginTop(&dtop);
printService->GetMarginLeft(&dleft);
printService->GetMarginBottom(&dbottom);
printService->GetMarginRight(&dright);
(void) pPrefs->CopyCharPref("print.print_file", (char **) &printfile);
(void) pPrefs->GetBoolPref("print.print_tofile", &tofile);
if (command != nsnull && printfile != nsnull) {
// convert Unicode strings to cstrings
nsAutoString cmdStr;
nsAutoString printFileStr;
cmdStr = command;
printFileStr = printfile;
char * pCmdStr = cmdStr.ToNewCString();
char * pPrintFileStr = printFileStr.ToNewCString();
sprintf( mPrData.command, pCmdStr );
sprintf( mPrData.path, pPrintFileStr);
nsMemory::Free(pCmdStr);
nsMemory::Free(pPrintFileStr);
}
(void) pPrefs->GetBoolPref("print.print_allpagesrange", &allpagesRange);
(void) pPrefs->GetBoolPref("print.print_pagerange", &pageRange);
(void) pPrefs->GetBoolPref("print.print_selectionrange", &selectionRange);
(void) pPrefs->GetIntPref("print.print_frompage", &fromPage);
(void) pPrefs->GetIntPref("print.print_topage", &toPage);
sprintf( mPrData.command, command );
sprintf( mPrData.path, printfile );
// fill the print options with the info from the dialog
if(printService) {
// convert the script values to twips
nsMargin margin;
margin.SizeTo(NS_INCHES_TO_TWIPS(float(ileft)/1000.0),
NS_INCHES_TO_TWIPS(float(itop)/1000.0),
NS_INCHES_TO_TWIPS(float(iright)/1000.0),
NS_INCHES_TO_TWIPS(float(ibottom)/1000.0));
printService->SetMargins(margin.top, margin.left, margin.right, margin.bottom);
#ifdef DEBUG_rods
printf("margins: %d,%d,%d,%d\n", itop, ileft, ibottom, iright);
printf("margins: %d,%d,%d,%d (twips)\n", margin.top, margin.left, margin.bottom, margin.right);
printf("allpagesRange %d\n", allpagesRange);
printf("pageRange %d\n", pageRange);
printf("selectionRange %d\n", selectionRange);
printf("margins: %5.2f,%5.2f,%5.2f,%5.2f\n", dtop, dleft, dbottom, dright);
printf("printRange %d\n", printRange);
printf("fromPage %d\n", fromPage);
printf("toPage %d\n", toPage);
#endif
if (selectionRange) {
printService->SetPrintRange(ePrintRange_Selection);
} else if (pageRange) {
printService->SetPrintRange(ePrintRange_SpecifiedPageRange);
printService->SetPageRange(fromPage, toPage);
} else { // (allpagesRange)
printService->SetPrintRange(ePrintRange_AllPages);
}
}
} else {
#ifndef VMS
sprintf( mPrData.command, "lpr" );
@ -258,25 +240,31 @@ NS_IMETHODIMP nsDeviceContextSpecGTK :: Init(PRBool aQuiet)
#endif
}
mPrData.top = itop / 1000.0;
mPrData.bottom = ibottom / 1000.0;
mPrData.left = ileft / 1000.0;
mPrData.right = iright / 1000.0;
mPrData.fpf = !reversed;
mPrData.top = dtop;
mPrData.bottom = dbottom;
mPrData.left = dleft;
mPrData.right = dright;
mPrData.fpf = !reversed;
mPrData.grayscale = !color;
mPrData.size = paper_size;
mPrData.size = paper_size;
mPrData.toPrinter = !tofile;
// PWD, HOME, or fail
if (!printfile) {
if ( ( path = PR_GetEnv( "PWD" ) ) == (char *) NULL )
if ( ( path = PR_GetEnv( "HOME" ) ) == (char *) NULL )
strcpy( mPrData.path, "mozilla.ps" );
if ( ( path = PR_GetEnv( "HOME" ) ) == (char *) NULL )
strcpy( mPrData.path, "mozilla.ps" );
if ( path != (char *) NULL )
sprintf( mPrData.path, "%s/mozilla.ps", path );
sprintf( mPrData.path, "%s/mozilla.ps", path );
else
return NS_ERROR_FAILURE;
return NS_ERROR_FAILURE;
}
if (command != nsnull) {
nsMemory::Free(command);
}
if (printfile != nsnull) {
nsMemory::Free(printfile);
}
return NS_OK;
@ -288,7 +276,6 @@ NS_IMETHODIMP nsDeviceContextSpecGTK :: Init(PRBool aQuiet)
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsDeviceContextSpecGTK :: GetToPrinter( PRBool &aToPrinter )

Просмотреть файл

@ -30,6 +30,9 @@
#include "nsIPrintOptions.h"
// This is for extending the dialog
#include <dlgs.h>
nsDeviceContextSpecFactoryWin :: nsDeviceContextSpecFactoryWin()
{
NS_INIT_REFCNT();
@ -50,45 +53,104 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryWin :: Init(void)
return NS_OK;
}
//--------------------------------------------------------
static void SetRadio(HWND aParent,
UINT aId,
PRBool aIsSet,
PRBool isEnabled = PR_TRUE)
{
HWND wnd = GetDlgItem (aParent, aId);
if (!wnd) {
return;
}
if (!isEnabled) {
::EnableWindow(wnd, FALSE);
return;
}
::EnableWindow(wnd, TRUE);
::SendMessage(wnd, BM_SETCHECK, (WPARAM)aIsSet, (LPARAM)0);
}
//--------------------------------------------------------
static UINT gFrameSelectedRadioBtn = NULL;
//--------------------------------------------------------
UINT CALLBACK PrintHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
if (uiMsg == WM_COMMAND) {
gFrameSelectedRadioBtn = LOWORD(wParam);
} else if (uiMsg == WM_INITDIALOG) {
PRINTDLG * printDlg = (PRINTDLG *)lParam;
PRBool doingFrames = (PRBool)printDlg->lCustData;
HWND collateChk = GetDlgItem (hdlg, chx2);
if (collateChk) {
::ShowWindow(collateChk, SW_SHOW);
}
if (!doingFrames) {
// we are using this function to disabe the group box
SetRadio(hdlg, grp3, PR_FALSE, PR_FALSE);
// now disable radiobuttons
SetRadio(hdlg, rad4, PR_FALSE, PR_FALSE);
SetRadio(hdlg, rad5, PR_FALSE, PR_FALSE);
SetRadio(hdlg, rad6, PR_FALSE, PR_FALSE);
} else {
SetRadio(hdlg, rad4, PR_FALSE, PR_FALSE); // XXX this is just temporary
SetRadio(hdlg, rad5, PR_TRUE);
SetRadio(hdlg, rad6, PR_FALSE);
}
}
return 0L;
}
//XXX this method needs to do what the API says...
NS_IMETHODIMP nsDeviceContextSpecFactoryWin :: CreateDeviceContextSpec(nsIWidget *aWidget,
nsIDeviceContextSpec *&aNewSpec,
PRBool aQuiet)
{
NS_ENSURE_ARG_POINTER(aWidget);
nsresult rv = NS_ERROR_FAILURE;
NS_WITH_SERVICE(nsIPrintOptions, printService, kPrintOptionsCID, &rv);
PRINTDLG prntdlg;
HWND hWnd = (HWND)aWidget->GetNativeData(NS_NATIVE_WINDOW);
HINSTANCE hInstance = (HINSTANCE)::GetWindowLong(hWnd, GWL_HINSTANCE);
prntdlg.lStructSize = sizeof(prntdlg);
prntdlg.hwndOwner = NULL; //XXX need to find a window here. MMP
prntdlg.hDevMode = NULL;
prntdlg.hDevNames = NULL;
prntdlg.hDC = NULL;
prntdlg.Flags = PD_ALLPAGES | PD_RETURNIC | PD_HIDEPRINTTOFILE;
prntdlg.Flags = PD_ALLPAGES | PD_RETURNIC | PD_HIDEPRINTTOFILE |
PD_ENABLEPRINTTEMPLATE | PD_ENABLEPRINTHOOK | PD_USEDEVMODECOPIESANDCOLLATE;
// if there is a current selection then enable the "Selection" radio button
PRBool isPrintFrames = PR_FALSE;
if (printService) {
PRBool isOn;
printService->GetPrintOptions(NS_PRINT_OPTIONS_ENABLE_SELECTION_RADIO, &isOn);
printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, &isOn);
if (!isOn) {
prntdlg.Flags |= PD_NOSELECTION;
}
printService->GetIsPrintFrame(&isPrintFrames);
}
prntdlg.nFromPage = 1;
prntdlg.nToPage = 1;
prntdlg.nMinPage = 0;
prntdlg.nMaxPage = 1000;
prntdlg.nCopies = 1;
prntdlg.hInstance = NULL;
prntdlg.lCustData = 0;
prntdlg.lpfnPrintHook = NULL;
prntdlg.lpfnSetupHook = NULL;
prntdlg.lpPrintTemplateName = NULL;
prntdlg.nFromPage = 1;
prntdlg.nToPage = 1;
prntdlg.nMinPage = 0;
prntdlg.nMaxPage = 1000;
prntdlg.nCopies = 1;
prntdlg.hInstance = hInstance;
prntdlg.lCustData = (DWORD)isPrintFrames;
prntdlg.lpfnPrintHook = PrintHookProc;
prntdlg.lpfnSetupHook = NULL;
prntdlg.lpPrintTemplateName = (LPCTSTR)"PRINTDLGNEW";
prntdlg.lpSetupTemplateName = NULL;
prntdlg.hPrintTemplate = NULL;
prntdlg.hSetupTemplate = NULL;
prntdlg.hPrintTemplate = NULL;
prntdlg.hSetupTemplate = NULL;
if(PR_TRUE == aQuiet){
@ -116,16 +178,33 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryWin :: CreateDeviceContextSpec(nsIWidget
if(printService) {
if (prntdlg.Flags & PD_SELECTION) {
printService->SetPrintRange(ePrintRange_Selection);
printService->SetPrintRange(nsIPrintOptions::kRangeSelection);
} else if (prntdlg.Flags & PD_PAGENUMS) {
printService->SetPrintRange(ePrintRange_SpecifiedPageRange);
printService->SetPageRange(prntdlg.nFromPage, prntdlg.nToPage);
printService->SetPrintRange(nsIPrintOptions::kRangeSpecifiedPageRange);
printService->SetStartPageRange(prntdlg.nFromPage);
printService->SetEndPageRange( prntdlg.nToPage);
} else { // (prntdlg.Flags & PD_ALLPAGES)
printService->SetPrintRange(ePrintRange_AllPages);
printService->SetPrintRange(nsIPrintOptions::kRangeAllPages);
}
}
// check to see about the frame radio buttons
switch (gFrameSelectedRadioBtn) {
case rad4:
printService->SetPrintFrameType(nsIPrintOptions::kFramesAsIs);
break;
case rad5:
printService->SetPrintFrameType(nsIPrintOptions::kSelectedFrame);
break;
case rad6:
printService->SetPrintFrameType(nsIPrintOptions::kEachFrameSep);
break;
default:
printService->SetIsPrintFrame(PR_FALSE);
} // switch
}
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
PRBool printSelection = prntdlg.Flags & PD_SELECTION;

Просмотреть файл

@ -28,7 +28,29 @@
#include "nsIPref.h"
#include "nsIServiceManager.h"
NS_IMPL_ISUPPORTS1(nsPrintOptions, nsIPrintOptions)
//NS_IMPL_ISUPPORTS1(nsPrintOptions, nsIPrintOptions)
NS_IMPL_ADDREF(nsPrintOptions)
NS_IMPL_RELEASE(nsPrintOptions)
NS_IMETHODIMP nsPrintOptions::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
*aInstancePtr = NULL;
if (aIID.Equals(NS_GET_IID(nsIPrintOptions))) {
*aInstancePtr = (void*) (nsIPrintOptions*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsISupports))) {
*aInstancePtr = (void*) ((nsISupports*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
// Pref Constants
const char * kMarginTop = "print.print_margin_top";
@ -36,7 +58,7 @@ const char * kMarginLeft = "print.print_margin_left";
const char * kMarginBottom = "print.print_margin_bottom";
const char * kMarginRight = "print.print_margin_right";
// Prefs for Print Option
// Prefs for Print Options
const char * kPrintEvenPages = "print.print_evenpages";
const char * kPrintOddPages = "print.print_oddpages";
const char * kPrintDocTitle = "print.print_doctitle";
@ -46,6 +68,14 @@ const char * kPageNumsJust = "print.print_pagenumjust";
const char * kPrintPageTotals = "print.print_pagetotals";
const char * kPrintDate = "print.print_date";
// Additional Prefs
const char * kPrintReversed = "print.print_reversed";
const char * kPrintColor = "print.print_color";
const char * kPrintPaperSize = "print.print_paper_size";
const char * kPrintCommand = "print.print_command";
const char * kPrintFile = "print.print_file";
const char * kPrintToFile = "print.print_tofile";
// There are currently NOT supported
//const char * kPrintBevelLines = "print.print_bevellines";
//const char * kPrintBlackText = "print.print_blacktext";
@ -64,24 +94,31 @@ const char * kRightJust = "right";
* @update 6/21/00 dwc
*/
nsPrintOptions::nsPrintOptions() :
mPrintRange(ePrintRange_AllPages),
mStartPageNum(0),
mEndPageNum(0),
mPrintOptions(0L)
mPrintRange(kRangeAllPages),
mStartPageNum(1),
mEndPageNum(1),
mPrintOptions(0L),
mPrintReversed(PR_FALSE),
mPrintInColor(PR_TRUE),
mPaperSize(kLetterPaperSize),
mPrintToFile(PR_FALSE),
mPrintFrameType(kSelectedFrame),
mIsPrintFrame(PR_FALSE),
mPageNumJust(kJustLeft)
{
NS_INIT_ISUPPORTS();
/* member initializers and constructor code */
nscoord halfInch = NS_INCHES_TO_TWIPS(0.5);
SetMargins(halfInch, halfInch, halfInch, halfInch);
mMargin.SizeTo(halfInch, halfInch, halfInch, halfInch);
mPrintOptions = NS_PRINT_OPTIONS_PRINT_EVEN_PAGES |
NS_PRINT_OPTIONS_PRINT_ODD_PAGES |
NS_PRINT_OPTIONS_PRINT_DOC_LOCATION |
NS_PRINT_OPTIONS_PRINT_DOC_TITLE |
NS_PRINT_OPTIONS_PRINT_PAGE_NUMS |
NS_PRINT_OPTIONS_PRINT_PAGE_TOTAL |
NS_PRINT_OPTIONS_PRINT_DATE_PRINTED;
mPrintOptions = kOptPrintOddPages |
kOptPrintEvenPages |
kOptPrintDocTitle |
kOptPrintDocLoc |
kOptPrintPageNums |
kOptPrintPageTotal |
kOptPrintDatePrinted;
mDefaultFont = new nsFont("Times", NS_FONT_STYLE_NORMAL,NS_FONT_VARIANT_NORMAL,
NS_FONT_WEIGHT_NORMAL,0,NSIntPointsToTwips(10));
@ -105,12 +142,12 @@ nsPrintOptions::~nsPrintOptions()
* @update 1/12/01 rods
*/
NS_IMETHODIMP
nsPrintOptions::SetDefaultFont(const nsFont &aFont)
nsPrintOptions::SetFontNamePointSize(nsString& aFontName, PRInt32 aPointSize)
{
if (mDefaultFont != nsnull) {
delete mDefaultFont;
if (mDefaultFont != nsnull && aFontName.Length() > 0 && aPointSize > 0) {
mDefaultFont->name = aFontName;
mDefaultFont->size = NSIntPointsToTwips(aPointSize);
}
mDefaultFont = new nsFont(aFont);
return NS_OK;
}
@ -119,12 +156,12 @@ nsPrintOptions::SetDefaultFont(const nsFont &aFont)
* @update 1/12/01 rods
*/
NS_IMETHODIMP
nsPrintOptions::SetFontNamePointSize(const nsString& aFontName, nscoord aPointSize)
nsPrintOptions::SetDefaultFont(nsFont &aFont)
{
if (mDefaultFont != nsnull && aFontName.Length() > 0 && aPointSize > 0) {
mDefaultFont->name = aFontName;
mDefaultFont->size = NSIntPointsToTwips(aPointSize);
if (mDefaultFont != nsnull) {
delete mDefaultFont;
}
mDefaultFont = new nsFont(aFont);
return NS_OK;
}
@ -145,30 +182,9 @@ nsPrintOptions::GetDefaultFont(nsFont &aFont)
* @update 1/12/01 rods
*/
NS_IMETHODIMP
nsPrintOptions::SetMargins(PRInt32 aTop, PRInt32 aLeft, PRInt32 aRight, PRInt32 aBottom)
nsPrintOptions::SetMarginInTwips(nsMargin& aMargin)
{
mMargin.SizeTo(aLeft, aTop, aRight, aBottom);
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
* @update 6/21/00 dwc
* @update 1/12/01 rods
*/
NS_IMETHODIMP
nsPrintOptions::GetMargins(PRInt32 *aTop, PRInt32 *aLeft, PRInt32 *aRight, PRInt32 *aBottom)
{
NS_ENSURE_ARG_POINTER(aTop);
NS_ENSURE_ARG_POINTER(aLeft);
NS_ENSURE_ARG_POINTER(aRight);
NS_ENSURE_ARG_POINTER(aBottom);
*aTop = mMargin.top;
*aLeft = mMargin.left;
*aRight = mMargin.right;
*aBottom = mMargin.bottom;
mMargin = aMargin;
return NS_OK;
}
@ -177,10 +193,9 @@ nsPrintOptions::GetMargins(PRInt32 *aTop, PRInt32 *aLeft, PRInt32 *aRight, PRInt
* @update 6/21/00 dwc
*/
NS_IMETHODIMP
nsPrintOptions::GetMargin(nsMargin& aMargin)
nsPrintOptions::GetMarginInTwips(nsMargin& aMargin)
{
aMargin = mMargin;
//aMargin.SizeTo(mLeftMargin, mTopMargin, mRightMargin, mBottomMargin);
return NS_OK;
}
@ -195,56 +210,6 @@ nsPrintOptions::ShowNativeDialog()
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
* @update 1/12/01 rods
*/
NS_IMETHODIMP
nsPrintOptions::SetPrintRange(PRInt32 aPrintRange)
{
mPrintRange = (nsPrintRange)aPrintRange;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
* @update 1/12/01 rods
*/
NS_IMETHODIMP
nsPrintOptions::GetPrintRange(PRInt32 *aPrintRange)
{
NS_ENSURE_ARG_POINTER(aPrintRange);
*aPrintRange = (PRInt32)mPrintRange;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
* @update 1/12/01 rods
*/
NS_IMETHODIMP
nsPrintOptions::SetPageRange(PRInt32 aStartPage, PRInt32 aEndPage)
{
mStartPageNum = aStartPage;
mEndPageNum = aEndPage;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
* @update 1/12/01 rods
*/
NS_IMETHODIMP
nsPrintOptions::GetPageRange(PRInt32 *aStartPage, PRInt32 *aEndPage)
{
NS_ENSURE_ARG_POINTER(aStartPage);
NS_ENSURE_ARG_POINTER(aEndPage);
*aStartPage = mStartPageNum;
*aEndPage = mEndPageNum;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
* @update 1/12/01 rods
@ -284,77 +249,6 @@ nsPrintOptions::GetPrintOptionsBits(PRInt32 *aBits)
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
* @update 1/12/01 rods
*/
NS_IMETHODIMP
nsPrintOptions::SetTitle(const PRUnichar *aTitle)
{
NS_ENSURE_ARG_POINTER(aTitle);
mTitle = aTitle;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
* @update 1/12/01 rods
*/
NS_IMETHODIMP
nsPrintOptions::GetTitle(PRUnichar **aTitle)
{
NS_ENSURE_ARG_POINTER(aTitle);
*aTitle = mTitle.ToNewUnicode();
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
* @update 1/12/01 rods
*/
NS_IMETHODIMP
nsPrintOptions::SetURL(const PRUnichar *aURL)
{
NS_ENSURE_ARG_POINTER(aURL);
mURL = aURL;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
* @update 1/12/01 rods
*/
NS_IMETHODIMP
nsPrintOptions::GetURL(PRUnichar **aURL)
{
NS_ENSURE_ARG_POINTER(aURL);
*aURL = mURL.ToNewUnicode();
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
* @update 1/12/01 rods
*/
NS_IMETHODIMP
nsPrintOptions::SetPageNumJust(PRInt32 aJust)
{
mPageNumJust = aJust;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
* @update 1/12/01 rods
*/
NS_IMETHODIMP
nsPrintOptions::GetPageNumJust(PRInt32 *aJust)
{
NS_ENSURE_ARG_POINTER(aJust);
*aJust = (PRInt32)mPageNumJust;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
@ -370,15 +264,23 @@ nsPrintOptions::ReadPrefs()
ReadInchesToTwipsPref(prefs, kMarginBottom, mMargin.bottom);
ReadInchesToTwipsPref(prefs, kMarginRight, mMargin.right);
ReadBitFieldPref(prefs, kPrintEvenPages, NS_PRINT_OPTIONS_PRINT_EVEN_PAGES);
ReadBitFieldPref(prefs, kPrintOddPages, NS_PRINT_OPTIONS_PRINT_ODD_PAGES);
ReadBitFieldPref(prefs, kPrintDocTitle, NS_PRINT_OPTIONS_PRINT_DOC_TITLE);
ReadBitFieldPref(prefs, kPrintDocLoc, NS_PRINT_OPTIONS_PRINT_DOC_LOCATION);
ReadBitFieldPref(prefs, kPageNums, NS_PRINT_OPTIONS_PRINT_PAGE_NUMS);
ReadBitFieldPref(prefs, kPrintPageTotals, NS_PRINT_OPTIONS_PRINT_PAGE_TOTAL);
ReadBitFieldPref(prefs, kPrintDate, NS_PRINT_OPTIONS_PRINT_DATE_PRINTED);
ReadBitFieldPref(prefs, kPrintEvenPages, kOptPrintEvenPages);
ReadBitFieldPref(prefs, kPrintOddPages, kOptPrintOddPages);
ReadBitFieldPref(prefs, kPrintDocTitle, kOptPrintDocTitle);
ReadBitFieldPref(prefs, kPrintDocLoc, kOptPrintDocLoc);
ReadBitFieldPref(prefs, kPageNums, kOptPrintPageNums);
ReadBitFieldPref(prefs, kPrintPageTotals, kOptPrintPageTotal);
ReadBitFieldPref(prefs, kPrintDate, kOptPrintDatePrinted);
ReadJustification(prefs, kPageNumsJust, mPageNumJust, NS_PRINT_JUSTIFY_LEFT);
ReadJustification(prefs, kPageNumsJust, mPageNumJust, kJustLeft);
// Read Additional XP Prefs
prefs->GetBoolPref(kPrintReversed, &mPrintReversed);
prefs->GetBoolPref(kPrintColor, &mPrintInColor);
prefs->GetIntPref(kPrintPaperSize, &mPaperSize);
ReadPrefString(prefs, kPrintCommand, mPrintCommand);
prefs->GetBoolPref(kPrintFile, &mPrintToFile);
ReadPrefString(prefs, kPrintToFile, mToFileName);
return NS_OK;
}
@ -399,24 +301,296 @@ nsPrintOptions::WritePrefs()
WriteInchesFromTwipsPref(prefs, kMarginBottom, mMargin.bottom);
WriteInchesFromTwipsPref(prefs, kMarginRight, mMargin.right);
WriteBitFieldPref(prefs, kPrintEvenPages, NS_PRINT_OPTIONS_PRINT_EVEN_PAGES);
WriteBitFieldPref(prefs, kPrintOddPages, NS_PRINT_OPTIONS_PRINT_ODD_PAGES);
WriteBitFieldPref(prefs, kPrintDocTitle, NS_PRINT_OPTIONS_PRINT_DOC_TITLE);
WriteBitFieldPref(prefs, kPrintDocLoc, NS_PRINT_OPTIONS_PRINT_DOC_LOCATION);
WriteBitFieldPref(prefs, kPageNums, NS_PRINT_OPTIONS_PRINT_PAGE_NUMS);
WriteBitFieldPref(prefs, kPrintPageTotals, NS_PRINT_OPTIONS_PRINT_PAGE_TOTAL);
WriteBitFieldPref(prefs, kPrintDate, NS_PRINT_OPTIONS_PRINT_DATE_PRINTED);
WriteBitFieldPref(prefs, kPrintEvenPages, kOptPrintEvenPages);
WriteBitFieldPref(prefs, kPrintOddPages, kOptPrintOddPages);
WriteBitFieldPref(prefs, kPrintDocTitle, kOptPrintDocTitle);
WriteBitFieldPref(prefs, kPrintDocLoc, kOptPrintDocLoc);
WriteBitFieldPref(prefs, kPageNums, kOptPrintPageNums);
WriteBitFieldPref(prefs, kPrintPageTotals, kOptPrintPageTotal);
WriteBitFieldPref(prefs, kPrintDate, kOptPrintDatePrinted);
WriteJustification(prefs, kPageNumsJust, mPageNumJust);
// Write Additional XP Prefs
prefs->SetBoolPref(kPrintReversed, mPrintReversed);
prefs->SetBoolPref(kPrintColor, mPrintInColor);
prefs->SetIntPref(kPrintPaperSize, mPaperSize);
WritePrefString(prefs, kPrintCommand, mPrintCommand);
prefs->SetBoolPref(kPrintFile, mPrintToFile);
WritePrefString(prefs, kPrintToFile, mToFileName);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
/* attribute long startPageRange; */
NS_IMETHODIMP nsPrintOptions::GetStartPageRange(PRInt32 *aStartPageRange)
{
//NS_ENSURE_ARG_POINTER(aStartPageRange);
*aStartPageRange = mStartPageNum;
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetStartPageRange(PRInt32 aStartPageRange)
{
mStartPageNum = aStartPageRange;
return NS_OK;
}
/* attribute long endPageRange; */
NS_IMETHODIMP nsPrintOptions::GetEndPageRange(PRInt32 *aEndPageRange)
{
//NS_ENSURE_ARG_POINTER(aEndPageRange);
*aEndPageRange = mEndPageNum;
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetEndPageRange(PRInt32 aEndPageRange)
{
mEndPageNum = aEndPageRange;
return NS_OK;
}
/* attribute boolean printReversed; */
NS_IMETHODIMP nsPrintOptions::GetPrintReversed(PRBool *aPrintReversed)
{
//NS_ENSURE_ARG_POINTER(aPrintReversed);
*aPrintReversed = mPrintReversed;
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetPrintReversed(PRBool aPrintReversed)
{
mPrintReversed = aPrintReversed;
return NS_OK;
}
/* attribute boolean printInColor; */
NS_IMETHODIMP nsPrintOptions::GetPrintInColor(PRBool *aPrintInColor)
{
//NS_ENSURE_ARG_POINTER(aPrintInColor);
*aPrintInColor = mPrintInColor;
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetPrintInColor(PRBool aPrintInColor)
{
mPrintInColor = aPrintInColor;
return NS_OK;
}
/* attribute short paperSize; */
NS_IMETHODIMP nsPrintOptions::GetPaperSize(PRInt32 *aPaperSize)
{
//NS_ENSURE_ARG_POINTER(aPaperSize);
*aPaperSize = mPaperSize;
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetPaperSize(PRInt32 aPaperSize)
{
mPaperSize = aPaperSize;
return NS_OK;
}
/* attribute wstring printCommand; */
NS_IMETHODIMP nsPrintOptions::GetPrintCommand(PRUnichar * *aPrintCommand)
{
//NS_ENSURE_ARG_POINTER(aPrintCommand);
*aPrintCommand = mPrintCommand.ToNewUnicode();
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetPrintCommand(const PRUnichar * aPrintCommand)
{
mPrintCommand = aPrintCommand;
return NS_OK;
}
/* attribute boolean printToFile; */
NS_IMETHODIMP nsPrintOptions::GetPrintToFile(PRBool *aPrintToFile)
{
//NS_ENSURE_ARG_POINTER(aPrintToFile);
*aPrintToFile = mPrintToFile;
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetPrintToFile(PRBool aPrintToFile)
{
mPrintToFile = aPrintToFile;
return NS_OK;
}
/* attribute wstring toFileName; */
NS_IMETHODIMP nsPrintOptions::GetToFileName(PRUnichar * *aToFileName)
{
//NS_ENSURE_ARG_POINTER(aToFileName);
*aToFileName = mToFileName.ToNewUnicode();
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetToFileName(const PRUnichar * aToFileName)
{
mToFileName = aToFileName;
return NS_OK;
}
/* attribute double marginTop; */
NS_IMETHODIMP nsPrintOptions::GetMarginTop(double *aMarginTop)
{
NS_ENSURE_ARG_POINTER(aMarginTop);
*aMarginTop = NS_TWIPS_TO_INCHES(mMargin.top);
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetMarginTop(double aMarginTop)
{
mMargin.top = NS_INCHES_TO_TWIPS(float(aMarginTop));
return NS_OK;
}
/* attribute double marginLeft; */
NS_IMETHODIMP nsPrintOptions::GetMarginLeft(double *aMarginLeft)
{
NS_ENSURE_ARG_POINTER(aMarginLeft);
*aMarginLeft = NS_TWIPS_TO_INCHES(mMargin.left);
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetMarginLeft(double aMarginLeft)
{
mMargin.left = NS_INCHES_TO_TWIPS(float(aMarginLeft));
return NS_OK;
}
/* attribute double marginBottom; */
NS_IMETHODIMP nsPrintOptions::GetMarginBottom(double *aMarginBottom)
{
NS_ENSURE_ARG_POINTER(aMarginBottom);
*aMarginBottom = NS_TWIPS_TO_INCHES(mMargin.bottom);
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetMarginBottom(double aMarginBottom)
{
mMargin.bottom = NS_INCHES_TO_TWIPS(float(aMarginBottom));
return NS_OK;
}
/* attribute double marginRight; */
NS_IMETHODIMP nsPrintOptions::GetMarginRight(double *aMarginRight)
{
NS_ENSURE_ARG_POINTER(aMarginRight);
*aMarginRight = NS_TWIPS_TO_INCHES(mMargin.right);
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetMarginRight(double aMarginRight)
{
mMargin.right = NS_INCHES_TO_TWIPS(float(aMarginRight));
return NS_OK;
}
/* attribute long printRange; */
NS_IMETHODIMP nsPrintOptions::GetPrintRange(PRInt16 *aPrintRange)
{
NS_ENSURE_ARG_POINTER(aPrintRange);
*aPrintRange = mPrintRange;
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetPrintRange(PRInt16 aPrintRange)
{
mPrintRange = aPrintRange;
return NS_OK;
}
/* attribute long pageNumJust; */
NS_IMETHODIMP nsPrintOptions::GetPageNumJust(PRInt16 *aPageNumJust)
{
NS_ENSURE_ARG_POINTER(aPageNumJust);
*aPageNumJust = mPageNumJust;
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetPageNumJust(PRInt16 aPageNumJust)
{
mPageNumJust = aPageNumJust;
return NS_OK;
}
/* attribute wstring docTitle; */
NS_IMETHODIMP nsPrintOptions::GetTitle(PRUnichar * *aTitle)
{
NS_ENSURE_ARG_POINTER(aTitle);
*aTitle = mTitle.ToNewUnicode();
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetTitle(const PRUnichar * aTitle)
{
NS_ENSURE_ARG_POINTER(aTitle);
mTitle = aTitle;
return NS_OK;
}
/* attribute wstring docURL; */
NS_IMETHODIMP nsPrintOptions::GetDocURL(PRUnichar * *aDocURL)
{
NS_ENSURE_ARG_POINTER(aDocURL);
*aDocURL = mURL.ToNewUnicode();
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetDocURL(const PRUnichar * aDocURL)
{
NS_ENSURE_ARG_POINTER(aDocURL);
mURL = aDocURL;
return NS_OK;
}
/* attribute boolean isPrintFrame; */
NS_IMETHODIMP nsPrintOptions::GetIsPrintFrame(PRBool *aIsPrintFrame)
{
NS_ENSURE_ARG_POINTER(aIsPrintFrame);
*aIsPrintFrame = (PRInt32)mIsPrintFrame;
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetIsPrintFrame(PRBool aIsPrintFrame)
{
mIsPrintFrame = aIsPrintFrame;
return NS_OK;
}
/* attribute long printFrame; */
NS_IMETHODIMP nsPrintOptions::GetPrintFrameType(PRInt16 *aPrintFrameType)
{
NS_ENSURE_ARG_POINTER(aPrintFrameType);
*aPrintFrameType = (PRInt32)mPrintFrameType;
return NS_OK;
}
NS_IMETHODIMP nsPrintOptions::SetPrintFrameType(PRInt16 aPrintFrameType)
{
mPrintFrameType = aPrintFrameType;
return NS_OK;
}
//-----------------------------------------------------
//-- Protected Methods
//-----------------------------------------------------
//---------------------------------------------------
nsresult nsPrintOptions::ReadPrefString(nsIPref * aPref,
const char * aPrefId,
nsString& aString)
{
char * str = nsnull;
nsresult rv = aPref->CopyCharPref(aPrefId, &str);
if (NS_SUCCEEDED(rv) && str) {
aString.AssignWithConversion(str);
nsMemory::Free(str);
}
return rv;
}
nsresult nsPrintOptions::WritePrefString(nsIPref * aPref,
const char * aPrefId,
nsString& aString)
{
NS_ENSURE_ARG_POINTER(aPref);
NS_ENSURE_ARG_POINTER(aPrefId);
PRUnichar * str = aString.ToNewUnicode();
nsresult rv = aPref->SetUnicharPref(aPrefId, str);
nsMemory::Free(str);
return rv;
}
void nsPrintOptions::ReadBitFieldPref(nsIPref * aPref,
const char * aPrefId,
PRInt32 anOption)
@ -474,49 +648,45 @@ void nsPrintOptions::WriteInchesFromTwipsPref(nsIPref * aPref,
}
}
//---------------------------------------------------
void nsPrintOptions::ReadJustification(nsIPref * aPref,
const char * aPrefId,
PRInt32& aJust,
PRInt32 aInitValue)
PRInt16& aJust,
PRInt16 aInitValue)
{
aJust = aInitValue;
char * str = nsnull;
nsresult rv = aPref->CopyCharPref(aPrefId, &str);
if (NS_SUCCEEDED(rv) && str) {
nsAutoString justStr;
justStr.AssignWithConversion(str);
nsAutoString justStr;
if (NS_SUCCEEDED(ReadPrefString(aPref, aPrefId, justStr))) {
if (justStr.EqualsWithConversion(kRightJust)) {
aJust = NS_PRINT_JUSTIFY_RIGHT;
aJust = kJustRight;
} else if (justStr.EqualsWithConversion(kCenterJust)) {
aJust = NS_PRINT_JUSTIFY_CENTER;
aJust = kJustCenter;
} else {
aJust = NS_PRINT_JUSTIFY_LEFT;
aJust = kJustLeft;
}
nsMemory::Free(str);
}
}
//---------------------------------------------------
void nsPrintOptions::WriteJustification(nsIPref * aPref,
const char * aPrefId,
PRInt32 aJust)
PRInt16 aJust)
{
switch (aJust) {
case NS_PRINT_JUSTIFY_LEFT:
case kJustLeft:
aPref->SetCharPref(aPrefId, kLeftJust);
break;
case NS_PRINT_JUSTIFY_CENTER:
case kJustCenter:
aPref->SetCharPref(aPrefId, kCenterJust);
break;
case NS_PRINT_JUSTIFY_RIGHT:
case kJustRight:
aPref->SetCharPref(aPrefId, kRightJust);
break;
} //switch
}

Просмотреть файл

@ -36,40 +36,44 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPRINTOPTIONS
// C++ methods
NS_IMETHOD SetDefaultFont(const nsFont &aFont);
NS_IMETHOD SetFontNamePointSize(const nsString& aFontName, nscoord aPointSize);
NS_IMETHOD GetDefaultFont(nsFont &aFont);
// non-scriptable C++ helper method
NS_IMETHOD GetMargin(nsMargin& aMargin);
nsPrintOptions();
virtual ~nsPrintOptions();
protected:
void ReadBitFieldPref(nsIPref * aPref, const char * aPrefId, PRInt32 anOption);
void WriteBitFieldPref(nsIPref * aPref, const char * aPrefId, PRInt32 anOption);
void ReadJustification(nsIPref * aPref, const char * aPrefId, PRInt32& aJust, PRInt32 aInitValue);
void WriteJustification(nsIPref * aPref, const char * aPrefId, PRInt32 aJust);
void ReadJustification(nsIPref * aPref, const char * aPrefId, PRInt16& aJust, PRInt16 aInitValue);
void WriteJustification(nsIPref * aPref, const char * aPrefId, PRInt16 aJust);
void ReadInchesToTwipsPref(nsIPref * aPref, const char * aPrefId, nscoord& aTwips);
void WriteInchesFromTwipsPref(nsIPref * aPref, const char * aPrefId, nscoord aTwips);
nsresult ReadPrefString(nsIPref * aPref, const char * aPrefId, nsString& aString);
nsresult WritePrefString(nsIPref * aPref, const char * aPrefId, nsString& aString);
// Members
nsMargin mMargin;
PRInt32 mPrintOptions;
nsPrintRange mPrintRange;
// scriptable data members
PRInt16 mPrintRange;
PRInt32 mStartPageNum; // only used for ePrintRange_SpecifiedRange
PRInt32 mEndPageNum;
PRInt32 mPageNumJust;
PRInt16 mPageNumJust;
PRInt32 mPrintOptions;
PRInt16 mPrintFrameType;
PRBool mIsPrintFrame;
nsFont* mDefaultFont;
nsString mTitle;
nsString mURL;
PRBool mPrintReversed;
PRBool mPrintInColor; // a false means grayscale
PRInt32 mPaperSize; // see page size consts
nsString mPrintCommand;
PRBool mPrintToFile;
nsString mToFileName;
};