зеркало из https://github.com/mozilla/pjs.git
This checkin enables mozilla to support the printing of selection, the printing of page ranges, and
the printing of headers and footers. Printing of selection is implemented by the frames figuring out if they are in the selection and painting if they or not they they don't paint. This also only allows the printing of the first page of selections, alothough it is well documented where this is implemeted so it can be removed. Bugs 63426, 31218, 61075 r=dcone,kmcclusk,erik,buster sr=waterson
This commit is contained in:
Родитель
2a5865bf0e
Коммит
faa0188b6f
|
@ -23,6 +23,44 @@
|
|||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
%{ 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
|
||||
|
||||
%}
|
||||
|
||||
/**
|
||||
* Simplified graphics interface for JS rendering.
|
||||
|
@ -32,14 +70,107 @@
|
|||
|
||||
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;
|
||||
|
||||
NS_IMETHOD GetDefaultFont(nsFont &aFont) = 0;
|
||||
|
||||
|
||||
// non-scriptable helper method
|
||||
NS_IMETHOD GetMargin(nsMargin& aMargin) = 0;
|
||||
%}
|
||||
|
||||
/**
|
||||
* PageMargin.
|
||||
* Set PageMargins
|
||||
*/
|
||||
void SetMargins(in PRInt32 aTop, in PRInt32 aLeft, in PRInt32 aRight, in PRInt32 aBottom);
|
||||
|
||||
|
||||
/**
|
||||
* Get PageMargins
|
||||
*/
|
||||
void GetMargins(out PRInt32 aTop, out PRInt32 aLeft, out PRInt32 aRight, out PRInt32 aBottom);
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
void SetPrintOptions(in PRInt32 aType, in PRBool aTurnOnOff);
|
||||
|
||||
/**
|
||||
* Get PrintOptions
|
||||
*/
|
||||
void GetPrintOptions(in PRInt32 aType, out PRBool aTurnOnOff);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Read Prefs
|
||||
*/
|
||||
void ReadPrefs();
|
||||
|
||||
/**
|
||||
* Write Prefs
|
||||
*/
|
||||
void WritePrefs();
|
||||
|
||||
};
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPrintOptions.h"
|
||||
#include "nsGfxCIID.h"
|
||||
|
||||
#include "nsIPref.h"
|
||||
#include "prenv.h" /* for PR_GetEnv */
|
||||
|
@ -36,6 +38,7 @@
|
|||
|
||||
static NS_DEFINE_IID( kAppShellServiceCID, NS_APPSHELL_SERVICE_CID );
|
||||
static NS_DEFINE_CID(kDialogParamBlockCID, NS_DialogParamBlock_CID);
|
||||
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
|
||||
|
||||
//#include "prmem.h"
|
||||
//#include "plstr.h"
|
||||
|
@ -124,16 +127,30 @@ NS_IMPL_RELEASE(nsDeviceContextSpecGTK)
|
|||
*/
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK :: Init(PRBool aQuiet)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
NS_WITH_SERVICE(nsIPrintOptions, printService, kPrintOptionsCID, &rv);
|
||||
|
||||
// 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);
|
||||
nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv) && pPrefs) {
|
||||
(void) pPrefs->SetBoolPref("print.selection_radio_enabled", isOn);
|
||||
}
|
||||
}
|
||||
|
||||
char *path;
|
||||
|
||||
PRBool reversed = PR_FALSE, color = PR_FALSE, landscape = PR_FALSE;
|
||||
PRBool tofile = PR_FALSE;
|
||||
PRBool tofile = PR_FALSE, allpagesRange = PR_TRUE, pageRange = PR_FALSE, selectionRange = PR_FALSE;
|
||||
PRInt32 paper_size = NS_LETTER_SIZE;
|
||||
int ileft = 500, iright = 0, itop = 500, ibottom = 0;
|
||||
PRInt32 fromPage = 1, toPage = 1;
|
||||
int ileft = 500, iright = 500, itop = 500, ibottom = 500;
|
||||
char *command;
|
||||
char *printfile = nsnull;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
rv = NS_OK;
|
||||
nsCOMPtr<nsIDialogParamBlock> ioParamBlock;
|
||||
|
||||
rv = nsComponentManager::CreateInstance(kDialogParamBlockCID,
|
||||
|
@ -179,14 +196,58 @@ NS_IMETHODIMP nsDeviceContextSpecGTK :: Init(PRBool aQuiet)
|
|||
(void) pPrefs->GetBoolPref("print.print_landscape", &landscape);
|
||||
(void) pPrefs->GetIntPref("print.print_paper_size", &paper_size);
|
||||
(void) pPrefs->CopyCharPref("print.print_command", (char **) &command);
|
||||
(void) pPrefs->GetIntPref("print.print_margin_top", &itop);
|
||||
(void) pPrefs->GetIntPref("print.print_margin_left", &ileft);
|
||||
(void) pPrefs->GetIntPref("print.print_margin_bottom", &ibottom);
|
||||
(void) pPrefs->GetIntPref("print.print_margin_right", &iright);
|
||||
|
||||
// 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);
|
||||
|
||||
(void) pPrefs->CopyCharPref("print.print_file", (char **) &printfile);
|
||||
(void) pPrefs->GetBoolPref("print.print_tofile", &tofile);
|
||||
|
||||
(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("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" );
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
#include <commdlg.h>
|
||||
#include "nsGfxCIID.h"
|
||||
#include "plstr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "nsIPrintOptions.h"
|
||||
|
||||
nsDeviceContextSpecFactoryWin :: nsDeviceContextSpecFactoryWin()
|
||||
{
|
||||
|
@ -38,6 +41,7 @@ nsDeviceContextSpecFactoryWin :: ~nsDeviceContextSpecFactoryWin()
|
|||
|
||||
static NS_DEFINE_IID(kIDeviceContextSpecIID, NS_IDEVICE_CONTEXT_SPEC_IID);
|
||||
static NS_DEFINE_IID(kDeviceContextSpecCID, NS_DEVICE_CONTEXT_SPEC_CID);
|
||||
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsDeviceContextSpecFactoryWin, nsIDeviceContextSpecFactory)
|
||||
|
||||
|
@ -52,19 +56,30 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryWin :: CreateDeviceContextSpec(nsIDevice
|
|||
nsIDeviceContextSpec *&aNewSpec,
|
||||
PRBool aQuiet)
|
||||
{
|
||||
PRINTDLG prntdlg;
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
NS_WITH_SERVICE(nsIPrintOptions, printService, kPrintOptionsCID, &rv);
|
||||
|
||||
PRINTDLG prntdlg;
|
||||
|
||||
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_NOSELECTION | PD_HIDEPRINTTOFILE;
|
||||
prntdlg.nFromPage = 0;
|
||||
prntdlg.nToPage = 0;
|
||||
prntdlg.Flags = PD_ALLPAGES | PD_RETURNIC | PD_HIDEPRINTTOFILE;
|
||||
|
||||
// if there is a current selection then enable the "Selection" radio button
|
||||
if (printService) {
|
||||
PRBool isOn;
|
||||
printService->GetPrintOptions(NS_PRINT_OPTIONS_ENABLE_SELECTION_RADIO, &isOn);
|
||||
if (!isOn) {
|
||||
prntdlg.Flags |= PD_NOSELECTION;
|
||||
}
|
||||
}
|
||||
prntdlg.nFromPage = 1;
|
||||
prntdlg.nToPage = 1;
|
||||
prntdlg.nMinPage = 0;
|
||||
prntdlg.nMaxPage = 0;
|
||||
prntdlg.nMaxPage = 1000;
|
||||
prntdlg.nCopies = 1;
|
||||
prntdlg.hInstance = NULL;
|
||||
prntdlg.lCustData = 0;
|
||||
|
@ -80,8 +95,6 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryWin :: CreateDeviceContextSpec(nsIDevice
|
|||
prntdlg.Flags = PD_RETURNDEFAULT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOL res = ::PrintDlg(&prntdlg);
|
||||
|
||||
if (TRUE == res)
|
||||
|
@ -95,10 +108,48 @@ NS_IMETHODIMP nsDeviceContextSpecFactoryWin :: CreateDeviceContextSpec(nsIDevice
|
|||
PL_strcpy(device, &(((char *)devnames)[devnames->wDeviceOffset]));
|
||||
PL_strcpy(driver, &(((char *)devnames)[devnames->wDriverOffset]));
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
printf("printer: driver %s, device %s\n", driver, device);
|
||||
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
|
||||
printf("printer: driver %s, device %s flags: %d\n", driver, device, prntdlg.Flags);
|
||||
#endif
|
||||
|
||||
// fill the print options with the info from the dialog
|
||||
if(printService) {
|
||||
|
||||
if (prntdlg.Flags & PD_SELECTION) {
|
||||
printService->SetPrintRange(ePrintRange_Selection);
|
||||
|
||||
} else if (prntdlg.Flags & PD_PAGENUMS) {
|
||||
printService->SetPrintRange(ePrintRange_SpecifiedPageRange);
|
||||
printService->SetPageRange(prntdlg.nFromPage, prntdlg.nToPage);
|
||||
|
||||
} else { // (prntdlg.Flags & PD_ALLPAGES)
|
||||
printService->SetPrintRange(ePrintRange_AllPages);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(DEBUG_rods) || defined(DEBUG_dcone)
|
||||
PRBool printSelection = prntdlg.Flags & PD_SELECTION;
|
||||
PRBool printAllPages = prntdlg.Flags & PD_ALLPAGES;
|
||||
PRBool printNumPages = prntdlg.Flags & PD_PAGENUMS;
|
||||
PRInt32 fromPageNum = 0;
|
||||
PRInt32 toPageNum = 0;
|
||||
|
||||
if (printNumPages) {
|
||||
fromPageNum = prntdlg.nFromPage;
|
||||
toPageNum = prntdlg.nToPage;
|
||||
}
|
||||
if (printSelection) {
|
||||
printf("Printing the selection\n");
|
||||
|
||||
} else if (printAllPages) {
|
||||
printf("Printing all the pages\n");
|
||||
|
||||
} else {
|
||||
printf("Printing from page no. %d to %d\n", fromPageNum, toPageNum);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
nsIDeviceContextSpec *devspec = nsnull;
|
||||
|
||||
nsComponentManager::CreateInstance(kDeviceContextSpecCID, nsnull, kIDeviceContextSpecIID, (void **)&devspec);
|
||||
|
|
|
@ -21,18 +21,72 @@
|
|||
*/
|
||||
|
||||
#include "nsPrintOptionsImpl.h"
|
||||
#include "nsCoord.h"
|
||||
#include "nsUnitConversion.h"
|
||||
|
||||
// For Prefs
|
||||
#include "nsIPref.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsPrintOptions, nsIPrintOptions)
|
||||
|
||||
// Pref Constants
|
||||
const char * kMarginTop = "print.print_margin_top";
|
||||
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
|
||||
const char * kPrintEvenPages = "print.print_evenpages";
|
||||
const char * kPrintOddPages = "print.print_oddpages";
|
||||
const char * kPrintDocTitle = "print.print_doctitle";
|
||||
const char * kPrintDocLoc = "print.print_doclocation";
|
||||
const char * kPageNums = "print.print_pagenumbers";
|
||||
const char * kPageNumsJust = "print.print_pagenumjust";
|
||||
const char * kPrintPageTotals = "print.print_pagetotals";
|
||||
const char * kPrintDate = "print.print_date";
|
||||
|
||||
// There are currently NOT supported
|
||||
//const char * kPrintBevelLines = "print.print_bevellines";
|
||||
//const char * kPrintBlackText = "print.print_blacktext";
|
||||
//const char * kPrintBlackLines = "print.print_blacklines";
|
||||
//const char * kPrintLastPageFirst = "print.print_lastpagefirst";
|
||||
//const char * kPrintBackgrounds = "print.print_backgrounds";
|
||||
|
||||
const char * kLeftJust = "left";
|
||||
const char * kCenterJust = "center";
|
||||
const char * kRightJust = "right";
|
||||
|
||||
#define form_properties "chrome://communicator/locale/printing.properties"
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsPrintOptionsImpl.h
|
||||
* @update 6/21/00 dwc
|
||||
*/
|
||||
nsPrintOptions::nsPrintOptions()
|
||||
nsPrintOptions::nsPrintOptions() :
|
||||
mPrintRange(ePrintRange_AllPages),
|
||||
mStartPageNum(0),
|
||||
mEndPageNum(0),
|
||||
mPrintOptions(0L)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
|
||||
/* member initializers and constructor code */
|
||||
nscoord halfInch = NS_INCHES_TO_TWIPS(0.5);
|
||||
SetMargins(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;
|
||||
|
||||
mDefaultFont = new nsFont("Times", NS_FONT_STYLE_NORMAL,NS_FONT_VARIANT_NORMAL,
|
||||
NS_FONT_WEIGHT_NORMAL,0,NSIntPointsToTwips(10));
|
||||
|
||||
ReadPrefs();
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
|
@ -41,20 +95,79 @@ nsPrintOptions::nsPrintOptions()
|
|||
*/
|
||||
nsPrintOptions::~nsPrintOptions()
|
||||
{
|
||||
/* destructor code */
|
||||
if (mDefaultFont != nsnull) {
|
||||
delete mDefaultFont;
|
||||
}
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsPrintOptionsImpl.h
|
||||
* @update 1/12/01 rods
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsPrintOptions::SetDefaultFont(const nsFont &aFont)
|
||||
{
|
||||
if (mDefaultFont != nsnull) {
|
||||
delete mDefaultFont;
|
||||
}
|
||||
mDefaultFont = new nsFont(aFont);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsPrintOptionsImpl.h
|
||||
* @update 1/12/01 rods
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsPrintOptions::SetFontNamePointSize(const nsString& aFontName, nscoord aPointSize)
|
||||
{
|
||||
if (mDefaultFont != nsnull && aFontName.Length() > 0 && aPointSize > 0) {
|
||||
mDefaultFont->name = aFontName;
|
||||
mDefaultFont->size = NSIntPointsToTwips(aPointSize);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsPrintOptionsImpl.h
|
||||
* @update 1/12/01 rods
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsPrintOptions::GetDefaultFont(nsFont &aFont)
|
||||
{
|
||||
aFont = *mDefaultFont;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsPrintOptionsImpl.h
|
||||
* @update 6/21/00 dwc
|
||||
* @update 1/12/01 rods
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsPrintOptions::SetMargins(PRInt32 aTop, PRInt32 aLeft, PRInt32 aRight, PRInt32 aBottom)
|
||||
{
|
||||
mTopMargin = aTop;
|
||||
mLeftMargin = aLeft;
|
||||
mRightMargin = aRight;
|
||||
mBottomMargin = aBottom;
|
||||
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;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -64,13 +177,10 @@ nsPrintOptions::SetMargins(PRInt32 aTop, PRInt32 aLeft, PRInt32 aRight, PRInt32
|
|||
* @update 6/21/00 dwc
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsPrintOptions::GetMargins(PRInt32 *aTop, PRInt32 *aLeft, PRInt32 *aRight, PRInt32 *aBottom)
|
||||
nsPrintOptions::GetMargin(nsMargin& aMargin)
|
||||
{
|
||||
*aTop = mTopMargin;
|
||||
*aLeft = mLeftMargin;
|
||||
*aRight = mRightMargin;
|
||||
*aBottom = mBottomMargin;
|
||||
|
||||
aMargin = mMargin;
|
||||
//aMargin.SizeTo(mLeftMargin, mTopMargin, mRightMargin, mBottomMargin);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -84,3 +194,329 @@ 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
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsPrintOptions::SetPrintOptions(PRInt32 aType, PRBool aTurnOnOff)
|
||||
{
|
||||
if (aTurnOnOff) {
|
||||
mPrintOptions |= aType;
|
||||
} else {
|
||||
mPrintOptions &= ~aType;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsPrintOptionsImpl.h
|
||||
* @update 1/12/01 rods
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsPrintOptions::GetPrintOptions(PRInt32 aType, PRBool *aTurnOnOff)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aTurnOnOff);
|
||||
*aTurnOnOff = mPrintOptions & aType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsPrintOptionsImpl.h
|
||||
* @update 1/12/01 rods
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsPrintOptions::GetPrintOptionsBits(PRInt32 *aBits)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aBits);
|
||||
*aBits = mPrintOptions;
|
||||
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
|
||||
* @update 1/12/01 rods
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsPrintOptions::ReadPrefs()
|
||||
{
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
if (prefs) {
|
||||
ReadInchesToTwipsPref(prefs, kMarginTop, mMargin.top);
|
||||
ReadInchesToTwipsPref(prefs, kMarginLeft, mMargin.left);
|
||||
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);
|
||||
|
||||
ReadJustification(prefs, kPageNumsJust, mPageNumJust, NS_PRINT_JUSTIFY_LEFT);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsPrintOptionsImpl.h
|
||||
* @update 1/12/01 rods
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsPrintOptions::WritePrefs()
|
||||
{
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
if (prefs) {
|
||||
WriteInchesFromTwipsPref(prefs, kMarginTop, mMargin.top);
|
||||
WriteInchesFromTwipsPref(prefs, kMarginLeft, mMargin.left);
|
||||
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);
|
||||
|
||||
WriteJustification(prefs, kPageNumsJust, mPageNumJust);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------
|
||||
//-- Protected Methods
|
||||
//-----------------------------------------------------
|
||||
void nsPrintOptions::ReadBitFieldPref(nsIPref * aPref,
|
||||
const char * aPrefId,
|
||||
PRInt32 anOption)
|
||||
{
|
||||
PRBool b;
|
||||
if (NS_SUCCEEDED(aPref->GetBoolPref(aPrefId, &b))) {
|
||||
SetPrintOptions(anOption, b);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------
|
||||
void nsPrintOptions::WriteBitFieldPref(nsIPref * aPref,
|
||||
const char * aPrefId,
|
||||
PRInt32 anOption)
|
||||
{
|
||||
PRBool b;
|
||||
GetPrintOptions(anOption, &b);
|
||||
aPref->SetBoolPref(aPrefId, b);
|
||||
}
|
||||
|
||||
//---------------------------------------------------
|
||||
void nsPrintOptions::ReadInchesToTwipsPref(nsIPref * aPref,
|
||||
const char * aPrefId,
|
||||
nscoord& aTwips)
|
||||
{
|
||||
char * str = nsnull;
|
||||
nsresult rv = aPref->CopyCharPref(aPrefId, &str);
|
||||
if (NS_SUCCEEDED(rv) && str) {
|
||||
nsAutoString justStr;
|
||||
justStr.AssignWithConversion(str);
|
||||
PRInt32 errCode;
|
||||
float inches = justStr.ToFloat(&errCode);
|
||||
if (NS_SUCCEEDED(errCode)) {
|
||||
aTwips = NS_INCHES_TO_TWIPS(inches);
|
||||
} else {
|
||||
aTwips = 0;
|
||||
}
|
||||
nsMemory::Free(str);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------
|
||||
void nsPrintOptions::WriteInchesFromTwipsPref(nsIPref * aPref,
|
||||
const char * aPrefId,
|
||||
nscoord aTwips)
|
||||
{
|
||||
double inches = NS_TWIPS_TO_INCHES(aTwips);
|
||||
nsAutoString inchesStr;
|
||||
inchesStr.AppendFloat(inches);
|
||||
char * str = inchesStr.ToNewCString();
|
||||
if (str) {
|
||||
aPref->SetCharPref(aPrefId, str);
|
||||
} else {
|
||||
aPref->SetCharPref(aPrefId, "0.5");
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------
|
||||
void nsPrintOptions::ReadJustification(nsIPref * aPref,
|
||||
const char * aPrefId,
|
||||
PRInt32& aJust,
|
||||
PRInt32 aInitValue)
|
||||
{
|
||||
aJust = aInitValue;
|
||||
char * str = nsnull;
|
||||
nsresult rv = aPref->CopyCharPref(aPrefId, &str);
|
||||
if (NS_SUCCEEDED(rv) && str) {
|
||||
nsAutoString justStr;
|
||||
justStr.AssignWithConversion(str);
|
||||
|
||||
if (justStr.EqualsWithConversion(kRightJust)) {
|
||||
aJust = NS_PRINT_JUSTIFY_RIGHT;
|
||||
|
||||
} else if (justStr.EqualsWithConversion(kCenterJust)) {
|
||||
aJust = NS_PRINT_JUSTIFY_CENTER;
|
||||
|
||||
} else {
|
||||
aJust = NS_PRINT_JUSTIFY_LEFT;
|
||||
}
|
||||
nsMemory::Free(str);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------
|
||||
void nsPrintOptions::WriteJustification(nsIPref * aPref,
|
||||
const char * aPrefId,
|
||||
PRInt32 aJust)
|
||||
{
|
||||
switch (aJust) {
|
||||
case NS_PRINT_JUSTIFY_LEFT:
|
||||
aPref->SetCharPref(aPrefId, kLeftJust);
|
||||
break;
|
||||
|
||||
case NS_PRINT_JUSTIFY_CENTER:
|
||||
aPref->SetCharPref(aPrefId, kCenterJust);
|
||||
break;
|
||||
|
||||
case NS_PRINT_JUSTIFY_RIGHT:
|
||||
aPref->SetCharPref(aPrefId, kRightJust);
|
||||
break;
|
||||
} //switch
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "nsIPrintOptions.h"
|
||||
|
||||
class nsIPref;
|
||||
|
||||
//*****************************************************************************
|
||||
//*** nsPrintOptions
|
||||
|
@ -35,17 +36,39 @@ 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 ReadInchesToTwipsPref(nsIPref * aPref, const char * aPrefId, nscoord& aTwips);
|
||||
void WriteInchesFromTwipsPref(nsIPref * aPref, const char * aPrefId, nscoord aTwips);
|
||||
|
||||
// Members
|
||||
PRInt32 mTopMargin;
|
||||
PRInt32 mLeftMargin;
|
||||
PRInt32 mRightMargin;
|
||||
PRInt32 mBottomMargin;
|
||||
nsMargin mMargin;
|
||||
|
||||
nsPrintRange mPrintRange;
|
||||
PRInt32 mStartPageNum; // only used for ePrintRange_SpecifiedRange
|
||||
PRInt32 mEndPageNum;
|
||||
PRInt32 mPageNumJust;
|
||||
|
||||
PRInt32 mPrintOptions;
|
||||
|
||||
nsFont* mDefaultFont;
|
||||
nsString mTitle;
|
||||
nsString mURL;
|
||||
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче