Fix for bug 36796 - implement page setup on Mac and Mac OS X. r=sdagley, sr=alecf.

This commit is contained in:
sfraser%netscape.com 2001-10-12 23:48:34 +00:00
Родитель e32deee1a5
Коммит 1dc9295f24
16 изменённых файлов: 883 добавлений и 361 удалений

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

@ -188,4 +188,11 @@ interface nsIPrintOptions : nsISupports
[noscript] void GetDefaultFont(in nsNativeFontRef aMargin);
/**
* Native data constants
*/
const short kNativeDataPrintRecord = 0;
[noscript] voidPtr GetNativeData(in short aDataType);
};

28
gfx/macbuild/GFXConfig.h Normal file
Просмотреть файл

@ -0,0 +1,28 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#define _IMPL_NS_GFX 1
#if TARGET_CARBON
// we can't use the carbon printing session APIs
#define PM_USE_SESSION_APIS 0
#endif

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

@ -1,25 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#define _IMPL_NS_GFX 1
#include "MacPrefix_debug.h"

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

@ -1,25 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#define _IMPL_NS_GFX 1
#include "MacSharedPrefix.h"

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

@ -44,14 +44,14 @@
#include "nsIPrintOptions.h"
#include "nsGfxCIID.h"
#include "nsGfxUtils.h"
#if !TARGET_CARBON
#include "nsMacResources.h"
#include <Resources.h>
#include <Dialogs.h>
#endif
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
#if !TARGET_CARBON
enum {
@ -66,13 +66,13 @@ enum {
// items to support the additional items for the dialog
#define DITL_ADDITIONS 128
static pascal TPPrDlg MyJobDlgInit(THPrint); // Our extention to PrJobInit
static TPPrDlg PrtJobDialog; // pointer to job dialog
static TPPrDlg gPrtJobDialog; // pointer to job dialog
static long prFirstItem; // our first item in the extended dialog
static PItemUPP prPItemProc; // store the old item handler here
static nsIPrintOptions *gCurrOptions;
static PRBool gPrintSelection;
static UserItemUPP myDrawListUPP=0;
static UserItemUPP gDrawListUPP = nsnull;
typedef struct dialog_item_struct {
@ -93,31 +93,28 @@ typedef struct append_item_list_struct {
* Construct the nsDeviceContextSpecMac
* @update dc 12/02/98
*/
nsDeviceContextSpecMac :: nsDeviceContextSpecMac()
nsDeviceContextSpecMac::nsDeviceContextSpecMac()
: mPrtRec(nsnull)
, mPrintManagerOpen(PR_FALSE)
{
NS_INIT_REFCNT();
mPrtRec = nsnull;
mPrintManagerOpen = PR_FALSE;
}
/** -------------------------------------------------------
* Destroy the nsDeviceContextSpecMac
* @update dc 12/02/98
*/
nsDeviceContextSpecMac :: ~nsDeviceContextSpecMac()
nsDeviceContextSpecMac::~nsDeviceContextSpecMac()
{
ClosePrintManager();
if(mPrtRec != nsnull){
if (mPrtRec) {
::DisposeHandle((Handle)mPrtRec);
mPrtRec = nsnull;
ClosePrintManager();
}
}
static NS_DEFINE_IID(kDeviceContextSpecIID, NS_IDEVICE_CONTEXT_SPEC_IID);
NS_IMPL_ISUPPORTS2(nsDeviceContextSpecMac, nsIDeviceContextSpec, nsIPrintingContext)
#if !TARGET_CARBON
@ -128,12 +125,17 @@ NS_IMPL_ISUPPORTS2(nsDeviceContextSpecMac, nsIDeviceContextSpec, nsIPrintingCont
*/
static pascal void MyBBoxDraw(WindowPtr theWindow, short aItemNo)
{
short itemType;
Rect itemBox;
Handle itemH;
short itemType;
Rect itemBox;
Handle itemH;
::GetDialogItem((DialogPtr)PrtJobDialog,prFirstItem+eDrawFrameID-1,&itemType,&itemH,&itemBox);
::FrameRect(&itemBox);
::GetDialogItem((DialogPtr)gPrtJobDialog, prFirstItem + eDrawFrameID-1, &itemType, &itemH, &itemBox);
// use appearance if possible
if ((long)DrawThemeSecondaryGroup != kUnresolvedCFragSymbolAddress)
::DrawThemeSecondaryGroup(&itemBox, kThemeStateActive);
else
::FrameRect(&itemBox);
}
@ -143,7 +145,7 @@ Handle itemH;
*/
static pascal void MyJobItems(TPPrDlg aDialog, short aItemNo)
{
short myItem,firstItem,i,itemType;
short myItem, firstItem, i, itemType;
short value;
Rect itemBox;
Handle itemH;
@ -151,57 +153,64 @@ Handle itemH;
firstItem = prFirstItem;
myItem = aItemNo-firstItem+1;
if(myItem>0) {
if (myItem>0) {
switch (myItem) {
case ePrintSelectionCheckboxID:
::GetDialogItem((DialogPtr)aDialog,firstItem,&itemType,&itemH,&itemBox);
gPrintSelection = (gPrintSelection==PR_TRUE)?PR_FALSE:PR_TRUE;
::SetControlValue((ControlHandle)itemH,gPrintSelection);
::GetDialogItem((DialogPtr)aDialog, firstItem, &itemType, &itemH, &itemBox);
gPrintSelection = !gPrintSelection;
::SetControlValue((ControlHandle)itemH, gPrintSelection);
break;
case ePrintFrameAsIsCheckboxID:
case ePrintSelectedFrameCheckboxID:
case ePrintAllFramesCheckboxID:
for(i=ePrintFrameAsIsCheckboxID;i<=ePrintAllFramesCheckboxID;i++){
::GetDialogItem((DialogPtr)aDialog,firstItem+i-1,&itemType,&itemH,&itemBox);
::SetControlValue((ControlHandle)itemH,i==myItem);
for (i=ePrintFrameAsIsCheckboxID; i<=ePrintAllFramesCheckboxID; i++){
::GetDialogItem((DialogPtr)aDialog, firstItem+i-1, &itemType, &itemH, &itemBox);
::SetControlValue((ControlHandle)itemH, i==myItem);
}
default: break;
break;
default:
break;
}
} else {
// chain to standard Item handler
CallPItemProc(prPItemProc,(DialogPtr)aDialog,aItemNo);
CallPItemProc(prPItemProc, (DialogPtr)aDialog, aItemNo);
if(aDialog->fDone) {
if (aDialog->fDone)
{
nsCOMPtr<nsIPrintOptions> printOptionsService = do_GetService("@mozilla.org/gfx/printoptions;1");
// cleanup and set the print options to what we want
if (gCurrOptions) {
if (printOptionsService)
{
// print selection
::GetDialogItem((DialogPtr)aDialog,firstItem+ePrintSelectionCheckboxID-1,&itemType,&itemH,&itemBox);
::GetDialogItem((DialogPtr)aDialog, firstItem+ePrintSelectionCheckboxID-1, &itemType, &itemH, &itemBox);
value = ::GetControlValue((ControlHandle)itemH);
if(1==value){
gCurrOptions->SetPrintRange(nsIPrintOptions::kRangeSelection);
if (1==value){
printOptionsService->SetPrintRange(nsIPrintOptions::kRangeSelection);
} else {
gCurrOptions->SetPrintRange(nsIPrintOptions::kRangeAllPages);
printOptionsService->SetPrintRange(nsIPrintOptions::kRangeAllPages);
}
// print frames as is
::GetDialogItem((DialogPtr)aDialog,firstItem+ePrintFrameAsIsCheckboxID-1,&itemType,&itemH,&itemBox);
::GetDialogItem((DialogPtr)aDialog, firstItem+ePrintFrameAsIsCheckboxID-1, &itemType, &itemH, &itemBox);
value = ::GetControlValue((ControlHandle)itemH);
if(1==value){
gCurrOptions->SetPrintFrameType(nsIPrintOptions::kFramesAsIs);
if (1==value){
printOptionsService->SetPrintFrameType(nsIPrintOptions::kFramesAsIs);
}
// selected frame
::GetDialogItem((DialogPtr)aDialog,firstItem+ePrintSelectedFrameCheckboxID-1,&itemType,&itemH,&itemBox);
::GetDialogItem((DialogPtr)aDialog, firstItem+ePrintSelectedFrameCheckboxID-1, &itemType, &itemH, &itemBox);
value = ::GetControlValue((ControlHandle)itemH);
if(1==value){
gCurrOptions->SetPrintFrameType(nsIPrintOptions::kSelectedFrame);
if (1==value){
printOptionsService->SetPrintFrameType(nsIPrintOptions::kSelectedFrame);
}
// print all frames
::GetDialogItem((DialogPtr)aDialog,firstItem+ePrintAllFramesCheckboxID-1,&itemType,&itemH,&itemBox);
::GetDialogItem((DialogPtr)aDialog, firstItem+ePrintAllFramesCheckboxID-1, &itemType, &itemH, &itemBox);
value = ::GetControlValue((ControlHandle)itemH);
if(1==value){
gCurrOptions->SetPrintFrameType(nsIPrintOptions::kEachFrameSep);
if (1==value){
printOptionsService->SetPrintFrameType(nsIPrintOptions::kEachFrameSep);
}
}
}
@ -223,13 +232,13 @@ ItemListHandle dlg_Item_List;
firstItem = (**dlg_Item_List).max_index+2;
theResult = nsMacResources::OpenLocalResourceFile();
if(theResult == NS_OK) {
myAppendDITLH = (ItemListHandle)::GetResource('DITL',aDITLID);
if(nsnull == myAppendDITLH) {
if (theResult == NS_OK) {
myAppendDITLH = (ItemListHandle)::GetResource('DITL', aDITLID);
if (nsnull == myAppendDITLH) {
// some sort of error
theResult = NS_ERROR_FAILURE;
} else {
::AppendDITL((DialogPtr)aDialog,(Handle)myAppendDITLH,appendDITLBottom);
::AppendDITL((DialogPtr)aDialog, (Handle)myAppendDITLH, appendDITLBottom);
::ReleaseResource((Handle) myAppendDITLH);
}
theResult = nsMacResources::CloseLocalResourceFile();
@ -245,64 +254,67 @@ ItemListHandle dlg_Item_List;
*/
static pascal TPPrDlg MyJobDlgInit(THPrint aHPrint)
{
PRInt32 i;
short itemType;
Handle itemH;
Rect itemBox;
PRBool isOn;
PRInt16 howToEnableFrameUI = nsIPrintOptions::kFrameEnableNone;
PRInt32 i;
short itemType;
Handle itemH;
Rect itemBox;
PRBool isOn;
PRInt16 howToEnableFrameUI = nsIPrintOptions::kFrameEnableNone;
prFirstItem = AppendToDialog(gPrtJobDialog, DITL_ADDITIONS);
prFirstItem = AppendToDialog(PrtJobDialog,DITL_ADDITIONS);
nsCOMPtr<nsIPrintOptions> printOptionsService = do_GetService("@mozilla.org/gfx/printoptions;1");
if (gCurrOptions) {
gCurrOptions->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, &isOn);
gCurrOptions->GetHowToEnableFrameUI(&howToEnableFrameUI);
if (printOptionsService) {
printOptionsService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, &isOn);
printOptionsService->GetHowToEnableFrameUI(&howToEnableFrameUI);
}
::GetDialogItem((DialogPtr) PrtJobDialog,prFirstItem+ePrintSelectionCheckboxID-1,&itemType,&itemH,&itemBox);
if( isOn ) {
::HiliteControl((ControlHandle)itemH,0);
::GetDialogItem((DialogPtr) gPrtJobDialog, prFirstItem+ePrintSelectionCheckboxID-1, &itemType, &itemH, &itemBox);
if ( isOn ) {
::HiliteControl((ControlHandle)itemH, 0);
} else {
::HiliteControl((ControlHandle)itemH,255) ;
::HiliteControl((ControlHandle)itemH, 255);
}
gPrintSelection = PR_FALSE;
::SetControlValue((ControlHandle) itemH,gPrintSelection);
::SetControlValue((ControlHandle) itemH, gPrintSelection);
if (howToEnableFrameUI == nsIPrintOptions::kFrameEnableAll) {
for(i = ePrintFrameAsIsCheckboxID;i <= ePrintAllFramesCheckboxID;i++){
::GetDialogItem((DialogPtr) PrtJobDialog,prFirstItem+i-1,&itemType,&itemH,&itemBox);
::SetControlValue((ControlHandle) itemH,(i==2));
::HiliteControl((ControlHandle)itemH,0);
for (i = ePrintFrameAsIsCheckboxID; i <= ePrintAllFramesCheckboxID; i++){
::GetDialogItem((DialogPtr) gPrtJobDialog, prFirstItem+i-1, &itemType, &itemH, &itemBox);
::SetControlValue((ControlHandle) itemH, (i==2));
::HiliteControl((ControlHandle)itemH, 0);
}
} else if (howToEnableFrameUI == nsIPrintOptions::kFrameEnableAsIsAndEach) {
for(i = ePrintFrameAsIsCheckboxID;i <= ePrintAllFramesCheckboxID;i++){
::GetDialogItem((DialogPtr) PrtJobDialog,prFirstItem+i-1,&itemType,&itemH,&itemBox);
::SetControlValue((ControlHandle) itemH,(i==2));
if( i == 3){
::HiliteControl((ControlHandle)itemH,255) ;
}
else if (howToEnableFrameUI == nsIPrintOptions::kFrameEnableAsIsAndEach) {
for (i = ePrintFrameAsIsCheckboxID; i <= ePrintAllFramesCheckboxID; i++){
::GetDialogItem((DialogPtr) gPrtJobDialog, prFirstItem+i-1, &itemType, &itemH, &itemBox);
::SetControlValue((ControlHandle) itemH, (i==2));
if ( i == 3){
::HiliteControl((ControlHandle)itemH, 255);
}
}
} else {
for(i = ePrintFrameAsIsCheckboxID;i <= ePrintAllFramesCheckboxID;i++){
::GetDialogItem((DialogPtr) PrtJobDialog,prFirstItem+i-1,&itemType,&itemH,&itemBox);
::SetControlValue((ControlHandle) itemH,FALSE);
::HiliteControl((ControlHandle)itemH,255) ;
}
else {
for (i = ePrintFrameAsIsCheckboxID; i <= ePrintAllFramesCheckboxID; i++){
::GetDialogItem((DialogPtr) gPrtJobDialog, prFirstItem+i-1, &itemType, &itemH, &itemBox);
::SetControlValue((ControlHandle) itemH, FALSE);
::HiliteControl((ControlHandle)itemH, 255);
}
}
// attach our handler
prPItemProc = PrtJobDialog->pItemProc;
PrtJobDialog->pItemProc = NewPItemUPP(MyJobItems);
prPItemProc = gPrtJobDialog->pItemProc;
gPrtJobDialog->pItemProc = NewPItemUPP(MyJobItems);
// attach a draw routine
myDrawListUPP = NewUserItemProc(MyBBoxDraw);
::GetDialogItem((DialogPtr)PrtJobDialog,prFirstItem+eDrawFrameID-1,&itemType,&itemH,&itemBox);
::SetDialogItem((DialogPtr)PrtJobDialog,prFirstItem+eDrawFrameID-1,itemType,(Handle)myDrawListUPP,&itemBox);
gDrawListUPP = NewUserItemProc(MyBBoxDraw);
::GetDialogItem((DialogPtr)gPrtJobDialog, prFirstItem+eDrawFrameID-1, &itemType, &itemH, &itemBox);
::SetDialogItem((DialogPtr)gPrtJobDialog, prFirstItem+eDrawFrameID-1, itemType, (Handle)gDrawListUPP, &itemBox);
return PrtJobDialog;
return gPrtJobDialog;
}
#endif
@ -312,97 +324,110 @@ PRInt16 howToEnableFrameUI = nsIPrintOptions::kFrameEnableNone;
* Initialize the nsDeviceContextSpecMac
* @update dc 05/04/2001
*/
NS_IMETHODIMP nsDeviceContextSpecMac :: Init(PRBool aQuiet)
NS_IMETHODIMP nsDeviceContextSpecMac::Init(PRBool aQuiet)
{
nsresult theResult = NS_ERROR_FAILURE;
#if !TARGET_CARBON
THPrint hPrintRec; // handle to print record
GrafPtr oldport;
PDlgInitUPP theInitProcPtr;
THPrint hPrintRec; // handle to print record
GrafPtr oldport;
PDlgInitUPP theInitProcPtr;
::GetPort(&oldport);
nsresult rv;
nsCOMPtr<nsIPrintOptions> printOptionsService = do_GetService("@mozilla.org/gfx/printoptions;1", &rv);
if (NS_FAILED(rv)) return rv;
// open the printing manager
::PrOpen();
if(::PrError() == noErr){
mPrintManagerOpen = PR_TRUE;
// Allocate a print record
hPrintRec = (THPrint)::NewHandle(sizeof(TPrint));
if(nsnull != hPrintRec){
// fill in default values
::PrintDefault(hPrintRec);
// make sure the print record is valid
::PrValidate(hPrintRec);
if(PrError() != noErr){
DisposeHandle((Handle)hPrintRec);
return theResult;
}
// get pointer to invisible job dialog box
PrtJobDialog = PrJobInit(hPrintRec);
if(PrError() != noErr){
DisposeHandle((Handle)hPrintRec);
return theResult;
}
// create a UUP for the dialog init procedure
theInitProcPtr = NewPDlgInitProc(MyJobDlgInit);
if(nsnull == theInitProcPtr){
DisposeHandle((Handle)hPrintRec);
return theResult;
}
// standard print dialog, if true print
nsWatchTask::GetTask().Suspend();
if (::PrError() != noErr)
return NS_ERROR_FAILURE;
// about to put up the dialog, so get the initial settings
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIPrintOptions> printService =
do_GetService(kPrintOptionsCID, &rv);
if (printService) {
gCurrOptions = printService;
} else {
gCurrOptions=nsnull;
}
if(PrDlgMain(hPrintRec,theInitProcPtr)){
// have the print record
theResult = NS_OK;
mPrtRec = hPrintRec;
}else{
// don't print
::DisposeHandle((Handle)hPrintRec);
::SetPort(oldport);
theResult = NS_ERROR_ABORT;
}
// clean up our dialog routines
DisposePItemUPP(PrtJobDialog->pItemProc);
PrtJobDialog->pItemProc = prPItemProc; // put back the old just in case
DisposePItemUPP(theInitProcPtr);
DisposePItemUPP(myDrawListUPP);
nsWatchTask::GetTask().Resume();
}
mPrintManagerOpen = PR_TRUE;
// Allocate a print record
hPrintRec = (THPrint)::NewHandleClear(sizeof(TPrint));
if (!hPrintRec) return NS_ERROR_OUT_OF_MEMORY;
StHandleOwner printRecOwner((Handle)hPrintRec);
// see if we have a print record
void* printRecordData = nsnull;
rv = printOptionsService->GetNativeData(nsIPrintOptions::kNativeDataPrintRecord, &printRecordData);
if (NS_SUCCEEDED(rv) && printRecordData)
{
::BlockMoveData(printRecordData, *hPrintRec, sizeof(TPrint));
}
#endif
return theResult;
else
{
// fill in default values
::PrintDefault(hPrintRec);
}
if (printRecordData)
{
nsMemory::Free(printRecordData);
printRecordData = nsnull;
}
// make sure the print record is valid
::PrValidate(hPrintRec);
if (::PrError() != noErr)
return NS_ERROR_FAILURE;
// get pointer to invisible job dialog box
gPrtJobDialog = ::PrJobInit(hPrintRec);
if (::PrError() != noErr)
return NS_ERROR_FAILURE;
// create a UUP for the dialog init procedure
theInitProcPtr = NewPDlgInitProc(MyJobDlgInit);
if (!theInitProcPtr)
return NS_ERROR_FAILURE;
// standard print dialog, if true print
nsWatchTask::GetTask().Suspend();
// put up the print dialog
if (::PrDlgMain(hPrintRec, theInitProcPtr))
{
// have the print record
rv = NS_OK;
printRecOwner.ClearHandle(false);
mPrtRec = hPrintRec;
}
else
{
// don't print
::SetPort(oldport);
rv = NS_ERROR_ABORT;
}
// clean up our dialog routines
DisposePItemUPP(gPrtJobDialog->pItemProc);
gPrtJobDialog->pItemProc = prPItemProc; // put back the old just in case
DisposePItemUPP(theInitProcPtr);
DisposePItemUPP(gDrawListUPP);
gDrawListUPP = nsnull;
nsWatchTask::GetTask().Resume();
return rv;
#endif /* TARGET_CARBON */
return NS_ERROR_FAILURE;
}
/** -------------------------------------------------------
* Closes the printmanager if it is open.
* @update dc 12/03/98
*/
NS_IMETHODIMP nsDeviceContextSpecMac :: ClosePrintManager()
NS_IMETHODIMP nsDeviceContextSpecMac::ClosePrintManager()
{
PRBool isPMOpen;
this->PrintManagerOpen(&isPMOpen);
if(isPMOpen){
PRBool isPMOpen;
PrintManagerOpen(&isPMOpen);
if (isPMOpen) {
#if !TARGET_CARBON
::PrClose();
#endif
@ -437,12 +462,12 @@ NS_IMETHODIMP nsDeviceContextSpecMac::EndPage()
NS_IMETHODIMP nsDeviceContextSpecMac::GetPrinterResolution(double* aResolution)
{
nsresult rv = NS_OK;
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
return rv;
}
NS_IMETHODIMP nsDeviceContextSpecMac::GetPageRect(double* aTop, double* aLeft, double* aBottom, double* aRight)
{
nsresult rv = NS_OK;
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
return rv;
}

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

@ -21,6 +21,7 @@
*
* Contributor(s):
* Patrick C. Beard <beard@netscape.com>
* Simon Fraser <sfraser@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -38,16 +39,23 @@
* ***** END LICENSE BLOCK ***** */
#include "nsDeviceContextSpecX.h"
#include "prmem.h"
#include "plstr.h"
#include "nsIServiceManager.h"
#include "nsIPrintOptions.h"
/** -------------------------------------------------------
* Construct the nsDeviceContextSpecX
* @update dc 12/02/98
*/
nsDeviceContextSpecX::nsDeviceContextSpecX()
: mPrintSession(0), mPageFormat(kPMNoPageFormat), mPrintSettings(kPMNoPrintSettings),
mSavedPort(0)
: mPrintingContext(0)
, mPageFormat(kPMNoPageFormat)
, mPrintSettings(kPMNoPrintSettings)
, mSavedPort(0)
, mBeganPrinting(PR_FALSE)
{
NS_INIT_REFCNT();
}
@ -69,35 +77,59 @@ NS_IMPL_ISUPPORTS2(nsDeviceContextSpecX, nsIDeviceContextSpec, nsIPrintingContex
*/
NS_IMETHODIMP nsDeviceContextSpecX::Init(PRBool aQuiet)
{
// create a print session. then a default print settings.
OSStatus status = ::PMCreateSession(&mPrintSession);
if (status != noErr) return NS_ERROR_FAILURE;
status = ::PMCreatePageFormat(&mPageFormat);
if (status != noErr) return NS_ERROR_FAILURE;
status = ::PMSessionDefaultPageFormat(mPrintSession, mPageFormat);
if (status != noErr) return NS_ERROR_FAILURE;
status = ::PMCreatePrintSettings(&mPrintSettings);
if (status != noErr) return NS_ERROR_FAILURE;
status = ::PMSessionDefaultPrintSettings(mPrintSession, mPrintSettings);
if (status != noErr) return NS_ERROR_FAILURE;
nsresult rv;
nsCOMPtr<nsIPrintOptions> printOptionsService = do_GetService("@mozilla.org/gfx/printoptions;1", &rv);
if (NS_FAILED(rv)) return rv;
if (! aQuiet) {
Boolean accepted = false;
status = ::PMSessionPrintDialog(mPrintSession, mPrintSettings, mPageFormat, &accepted);
if (! accepted)
return NS_ERROR_ABORT;
}
// Because page setup can get called at any time, we can't use the session APIs here.
OSStatus status = ::PMBegin();
if (status != noErr) return NS_ERROR_FAILURE;
return NS_OK;
mBeganPrinting = PR_TRUE;
PMPageFormat optionsPageFormat = kPMNoPageFormat;
rv = printOptionsService->GetNativeData(nsIPrintOptions::kNativeDataPrintRecord, (void **)&optionsPageFormat);
if (NS_FAILED(rv)) return rv;
status = ::PMNewPageFormat(&mPageFormat);
if (status != noErr) return NS_ERROR_FAILURE;
if (optionsPageFormat != kPMNoPageFormat)
{
status = ::PMCopyPageFormat(optionsPageFormat, mPageFormat);
::PMDisposePageFormat(optionsPageFormat);
}
else
status = ::PMDefaultPageFormat(mPageFormat);
if (status != noErr) return NS_ERROR_FAILURE;
Boolean validated;
::PMValidatePageFormat(mPageFormat, &validated);
status = ::PMNewPrintSettings(&mPrintSettings);
if (status != noErr) return NS_ERROR_FAILURE;
status = ::PMDefaultPrintSettings(mPrintSettings);
if (status != noErr) return NS_ERROR_FAILURE;
if (! aQuiet)
{
Boolean accepted = false;
status = ::PMPrintDialog(mPrintSettings, mPageFormat, &accepted);
if (! accepted)
return NS_ERROR_ABORT;
if (status != noErr)
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecX::PrintManagerOpen(PRBool* aIsOpen)
{
*aIsOpen = (mPrintSession != 0);
*aIsOpen = mBeganPrinting;
return NS_OK;
}
@ -108,17 +140,20 @@ NS_IMETHODIMP nsDeviceContextSpecX::PrintManagerOpen(PRBool* aIsOpen)
NS_IMETHODIMP nsDeviceContextSpecX::ClosePrintManager()
{
if (mPrintSettings != kPMNoPrintSettings)
::PMRelease(mPrintSettings);
::PMDisposePrintSettings(mPrintSettings);
if (mPageFormat != kPMNoPageFormat)
::PMRelease(mPageFormat);
if (mPrintSession)
::PMRelease(mPrintSession);
::PMDisposePageFormat(mPageFormat);
if (mBeganPrinting)
::PMEnd();
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecX::BeginDocument()
{
OSStatus status = ::PMSessionBeginDocument(mPrintSession, mPrintSettings, mPageFormat);
OSStatus status = ::PMBeginDocument(mPrintSettings, mPageFormat, &mPrintingContext);
if (status != noErr) return NS_ERROR_FAILURE;
return NS_OK;
@ -126,20 +161,20 @@ NS_IMETHODIMP nsDeviceContextSpecX::BeginDocument()
NS_IMETHODIMP nsDeviceContextSpecX::EndDocument()
{
PMSessionEndDocument(mPrintSession);
::PMEndDocument(mPrintingContext);
mPrintingContext = 0;
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextSpecX::BeginPage()
{
// see http://devworld.apple.com/techpubs/carbon/graphics/CarbonPrintingManager/Carbon_Printing_Manager/Functions/PMSessionBeginPage.html
OSStatus status = ::PMSessionBeginPage(mPrintSession, mPageFormat, NULL);
OSStatus status = ::PMBeginPage(mPrintingContext, NULL);
if (status != noErr) return NS_ERROR_FAILURE;
::GetPort(&mSavedPort);
GrafPtr printingPort;
status = ::PMSessionGetGraphicsContext(mPrintSession, kPMGraphicsContextQuickdraw,
&(void*)printingPort);
status = ::PMGetGrafPtr(mPrintingContext, &printingPort);
if (status != noErr) return NS_ERROR_FAILURE;
::SetPort(printingPort);
return NS_OK;
@ -147,8 +182,9 @@ NS_IMETHODIMP nsDeviceContextSpecX::BeginPage()
NS_IMETHODIMP nsDeviceContextSpecX::EndPage()
{
OSStatus status = ::PMSessionEndPage(mPrintSession);
if (mSavedPort) {
OSStatus status = ::PMEndPage(mPrintingContext);
if (mSavedPort)
{
::SetPort(mSavedPort);
mSavedPort = 0;
}
@ -158,15 +194,10 @@ NS_IMETHODIMP nsDeviceContextSpecX::EndPage()
NS_IMETHODIMP nsDeviceContextSpecX::GetPrinterResolution(double* aResolution)
{
PMPrinter currentPrinter;
OSStatus status = ::PMSessionGetCurrentPrinter(mPrintSession, &currentPrinter);
if (status != noErr) return NS_ERROR_FAILURE;
PMResolution defaultResolution;
status = ::PMPrinterGetPrinterResolution(currentPrinter, kPMDefaultResolution, &defaultResolution);
OSStatus status = ::PMGetPrinterResolution(kPMDefaultResolution, &defaultResolution);
if (status == noErr)
*aResolution = defaultResolution.hRes;
::PMRelease(currentPrinter);
return (status == noErr ? NS_OK : NS_ERROR_FAILURE);
}
@ -174,7 +205,7 @@ NS_IMETHODIMP nsDeviceContextSpecX::GetPrinterResolution(double* aResolution)
NS_IMETHODIMP nsDeviceContextSpecX::GetPageRect(double* aTop, double* aLeft, double* aBottom, double* aRight)
{
PMRect pageRect;
PMGetAdjustedPageRect(mPageFormat, &pageRect);
::PMGetAdjustedPageRect(mPageFormat, &pageRect);
*aTop = pageRect.top, *aLeft = pageRect.left;
*aBottom = pageRect.bottom, *aRight = pageRect.right;
return NS_OK;

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

@ -43,9 +43,11 @@
#include "nsIDeviceContextSpec.h"
#include "nsIPrintingContext.h"
#include "nsDeviceContextMac.h"
#include <PMApplication.h>
class nsDeviceContextSpecX : public nsIDeviceContextSpec, public nsIPrintingContext {
class nsDeviceContextSpecX : public nsIDeviceContextSpec, public nsIPrintingContext
{
public:
/**
* Construct a nsDeviceContextSpecMac, which is an object which contains and manages a mac printrecord
@ -101,10 +103,12 @@ protected:
virtual ~nsDeviceContextSpecX();
protected:
PMPrintSession mPrintSession; // printing session.
PMPageFormat mPageFormat; // page format.
PMPrintSettings mPrintSettings; // print settings.
CGrafPtr mSavedPort; // saved graphics port.
PMPrintContext mPrintingContext; // printing context (non-session APIs)
PMPageFormat mPageFormat; // page format.
PMPrintSettings mPrintSettings; // print settings.
CGrafPtr mSavedPort; // saved graphics port.
PRBool mBeganPrinting;
};
#endif

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

@ -50,14 +50,15 @@
#include "nsScriptableRegion.h"
#if TARGET_CARBON
#include "nsDeviceContextSpecX.h"
#include "nsPrintOptionsX.h"
#else
#include "nsDeviceContextSpecMac.h"
#include "nsPrintOptionsMac.h"
#endif
#include "nsDeviceContextSpecFactoryM.h"
#include "nsScreenManagerMac.h"
#include "nsBlender.h"
#include "nsCOMPtr.h"
#include "nsPrintOptionsMac.h"
static NS_DEFINE_IID(kCFontMetrics, NS_FONT_METRICS_CID);
static NS_DEFINE_IID(kCFontEnumerator, NS_FONT_ENUMERATOR_CID);
@ -154,7 +155,11 @@ nsresult nsGfxFactoryMac::CreateInstance(nsISupports *aOuter,
inst = dcSpec;
}
else if (mClassID.Equals(kCPrintOptions)) {
#if TARGET_CARBON
NS_NEWXPCOM(inst, nsPrintOptionsX);
#else
NS_NEWXPCOM(inst, nsPrintOptionsMac);
#endif
}
else if (mClassID.Equals(kCDeviceContextSpecFactory)) {
NS_NEWXPCOM(inst, nsDeviceContextSpecFactoryMac);

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

@ -180,6 +180,42 @@ protected:
};
/** ------------------------------------------------------------
* Utility class stack-based handle ownership
*/
class StHandleOwner
{
public:
StHandleOwner(Handle inHandle)
: mHandle(inHandle)
{
}
~StHandleOwner()
{
if (mHandle)
::DisposeHandle(mHandle);
}
Handle GetHandle() { return mHandle; }
void ClearHandle(Boolean disposeIt = false)
{
if (disposeIt)
::DisposeHandle(mHandle);
mHandle = nsnull;
}
protected:
Handle mHandle;
};
/** ------------------------------------------------------------
* Utility class for saving, locking, and restoring handle state
* Ok with null handle

Двоичные данные
gfx/src/mac/nsMacGFX.rsrc

Двоичный файл не отображается.

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

@ -35,9 +35,19 @@
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsCOMPtr.h"
#include "nsIPref.h"
#include "nsIServiceManager.h"
#include "nsWatchTask.h"
#include "nsPrintOptionsMac.h"
#include "nsGfxUtils.h"
#include "plbase64.h"
#include "prmem.h"
#define MAC_OS_PAGE_SETUP_PREFNAME "print.macos.pagesetup"
/** ---------------------------------------------------
* See documentation in nsPrintOptionsWin.h
@ -46,11 +56,21 @@
nsPrintOptionsMac::nsPrintOptionsMac()
{
// create the print style and print record
mPrintRecord = (THPrint)::NewHandle(sizeof(TPrint));
if(nsnull != mPrintRecord){
::PrintDefault(mPrintRecord);
}
mPrintRecord = (THPrint)::NewHandleClear(sizeof(TPrint));
if (mPrintRecord)
{
nsresult rv = ReadPageSetupFromPrefs();
::PrOpen();
if (::PrError() == noErr)
{
if (NS_FAILED(rv))
::PrintDefault(mPrintRecord);
else
::PrValidate(mPrintRecord);
::PrClose();
}
}
}
@ -60,12 +80,10 @@ nsPrintOptionsMac::nsPrintOptionsMac()
*/
nsPrintOptionsMac::~nsPrintOptionsMac()
{
// get rid of the print record
if(nsnull != mPrintRecord){
if (mPrintRecord) {
::DisposeHandle((Handle)mPrintRecord);
}
}
/** ---------------------------------------------------
@ -74,10 +92,131 @@ nsPrintOptionsMac::~nsPrintOptionsMac()
*/
NS_IMETHODIMP
nsPrintOptionsMac::ShowNativeDialog(void)
{
if(nsnull != mPrintRecord){
::PrStlDialog(mPrintRecord); // open up and process the style record
}
return (NS_OK);
{
if (!mPrintRecord) return NS_ERROR_NOT_INITIALIZED;
// open the printing manager
::PrOpen();
if(::PrError() != noErr)
return NS_ERROR_FAILURE;
::PrValidate(mPrintRecord);
NS_ASSERTION(::PrError() == noErr, "Printing error");
nsWatchTask::GetTask().Suspend();
Boolean dialogOK = ::PrStlDialog(mPrintRecord); // open up and process the style record
nsWatchTask::GetTask().Resume();
OSErr err = ::PrError();
::PrClose();
if (err != noErr)
return NS_ERROR_FAILURE;
return NS_OK;
}
NS_IMETHODIMP
nsPrintOptionsMac::ReadPrefs()
{
// it doesn't really matter if this fails
nsresult rv = ReadPageSetupFromPrefs();
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to write page setup to prefs");
return nsPrintOptions::ReadPrefs();
}
NS_IMETHODIMP
nsPrintOptionsMac::WritePrefs()
{
// it doesn't really matter if this fails
nsresult rv = WritePageSetupToPrefs();
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to save page setup to prefs");
return nsPrintOptions::WritePrefs();
}
/* [noscript] voidPtr GetNativeData (in short aDataType); */
NS_IMETHODIMP
nsPrintOptionsMac::GetNativeData(PRInt16 aDataType, void * *_retval)
{
nsresult rv = NS_OK;
NS_ENSURE_ARG_POINTER(_retval);
*_retval = nsnull;
switch (aDataType)
{
case kNativeDataPrintRecord:
if (mPrintRecord)
{
void* printRecord = nsMemory::Alloc(sizeof(TPrint));
if (!printRecord) {
rv = NS_ERROR_OUT_OF_MEMORY;
break;
}
::BlockMoveData(*mPrintRecord, printRecord, sizeof(TPrint));
*_retval = printRecord;
}
break;
default:
rv = NS_ERROR_FAILURE;
break;
}
return rv;
}
#pragma mark -
nsresult
nsPrintOptionsMac::ReadPageSetupFromPrefs()
{
nsresult rv;
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_FAILED(rv))
return rv;
nsXPIDLCString encodedData;
rv = prefs->GetCharPref(MAC_OS_PAGE_SETUP_PREFNAME, getter_Copies(encodedData));
if (NS_FAILED(rv))
return rv;
// decode the base64
PRInt32 encodedDataLen = nsCRT::strlen(encodedData.get());
char* decodedData = ::PL_Base64Decode(encodedData.get(), encodedDataLen, nsnull);
if (!decodedData)
return NS_ERROR_FAILURE;
if (((encodedDataLen * 3) / 4) >= sizeof(TPrint))
::BlockMoveData(decodedData, *mPrintRecord, sizeof(TPrint));
else
rv = NS_ERROR_FAILURE; // the data was too small
PR_Free(decodedData);
return rv;
}
nsresult
nsPrintOptionsMac::WritePageSetupToPrefs()
{
if (!mPrintRecord)
return NS_ERROR_NOT_INITIALIZED;
nsresult rv;
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_FAILED(rv))
return rv;
StHandleLocker locker((Handle)mPrintRecord);
nsXPIDLCString encodedData;
encodedData.Adopt(::PL_Base64Encode((char *)*mPrintRecord, sizeof(TPrint), nsnull));
if (!encodedData.get())
return NS_ERROR_OUT_OF_MEMORY;
return prefs->SetCharPref(MAC_OS_PAGE_SETUP_PREFNAME, encodedData);
}

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

@ -35,32 +35,28 @@
class nsPrintOptionsMac : public nsPrintOptions
{
public:
nsPrintOptionsMac();
virtual ~nsPrintOptionsMac();
nsPrintOptionsMac();
virtual ~nsPrintOptionsMac();
private:
THPrint GetPrintRecord(void) {return mPrintRecord;}
NS_IMETHOD ShowNativeDialog(void);
NS_IMETHOD GetNativeData(PRInt16 aDataType, void * *_retval);
NS_IMETHOD ShowNativeDialog(void);
// members
THPrint mPrintRecord;
};
#else
class nsPrintOptionsMac : public nsPrintOptions
{
public:
nsPrintOptionsMac() { };
virtual ~nsPrintOptionsMac() { };
private:
//XXX FILL IN PRINT OPTIONS HERE FOR CARBON
NS_IMETHOD ReadPrefs();
NS_IMETHOD WritePrefs();
protected:
nsresult ReadPageSetupFromPrefs();
nsresult WritePageSetupToPrefs();
THPrint GetPrintRecord(void) { return mPrintRecord; }
protected:
THPrint mPrintRecord;
};
#endif
#endif /* TARGET_CARBON */
#endif /* nsPrintOptionsMac_h__ */

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

@ -0,0 +1,239 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Simon Fraser <sfraser@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <PMApplication.h>
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsWatchTask.h"
#include "nsPrintOptionsX.h"
#include "nsIPref.h"
#include "nsGfxUtils.h"
#include "plbase64.h"
#include "prmem.h"
#define MAC_OS_X_PAGE_SETUP_PREFNAME "print.macosx.pagesetup"
/** ---------------------------------------------------
*/
nsPrintOptionsX::nsPrintOptionsX()
: mPageFormat(kPMNoPageFormat)
{
OSStatus status = ::PMNewPageFormat(&mPageFormat);
NS_ASSERTION(status == noErr, "Error creating print settings");
status = ::PMBegin();
NS_ASSERTION(status == noErr, "Error from PMBegin()");
nsresult rv = ReadPageSetupFromPrefs();
if (NS_FAILED(rv))
::PMDefaultPageFormat(mPageFormat);
else
{
Boolean valid;
::PMValidatePageFormat(mPageFormat, &valid);
}
::PMEnd();
}
/** ---------------------------------------------------
*/
nsPrintOptionsX::~nsPrintOptionsX()
{
if (mPageFormat)
::PMDisposePageFormat(mPageFormat);
}
/** ---------------------------------------------------
*/
NS_IMETHODIMP
nsPrintOptionsX::ShowNativeDialog(void)
{
NS_ASSERTION(mPageFormat != kPMNoPageFormat, "No page format");
if (mPageFormat == kPMNoPageFormat)
return NS_ERROR_NOT_INITIALIZED;
OSStatus status = ::PMBegin();
if (status != noErr) return NS_ERROR_FAILURE;
Boolean validated;
::PMValidatePageFormat(mPageFormat, &validated);
Boolean accepted = false;
status = ::PMPageSetupDialog(mPageFormat, &accepted);
::PMEnd();
if (status != noErr)
return NS_ERROR_FAILURE;
if (!accepted)
return NS_ERROR_ABORT;
return NS_OK;
}
NS_IMETHODIMP
nsPrintOptionsX::ReadPrefs()
{
// it doesn't really matter if this fails
nsresult rv = ReadPageSetupFromPrefs();
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to write page setup to prefs");
return nsPrintOptions::ReadPrefs();
}
NS_IMETHODIMP
nsPrintOptionsX::WritePrefs()
{
// it doesn't really matter if this fails
nsresult rv = WritePageSetupToPrefs();
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to save page setup to prefs");
return nsPrintOptions::WritePrefs();
}
/* [noscript] voidPtr GetNativeData (in short aDataType); */
NS_IMETHODIMP
nsPrintOptionsX::GetNativeData(PRInt16 aDataType, void * *_retval)
{
nsresult rv = NS_OK;
NS_ENSURE_ARG_POINTER(_retval);
*_retval = nsnull;
switch (aDataType)
{
case kNativeDataPrintRecord:
// we need to clone and pass out
PMPageFormat pageFormat = kPMNoPageFormat;
OSStatus status = ::PMNewPageFormat(&pageFormat);
if (status != noErr) return NS_ERROR_FAILURE;
status = ::PMCopyPageFormat(mPageFormat, pageFormat);
if (status != noErr) {
::PMDisposePageFormat(pageFormat);
return NS_ERROR_FAILURE;
}
*_retval = pageFormat;
break;
default:
rv = NS_ERROR_FAILURE;
break;
}
return rv;
}
#pragma mark -
nsresult
nsPrintOptionsX::ReadPageSetupFromPrefs()
{
nsresult rv;
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_FAILED(rv))
return rv;
nsXPIDLCString encodedData;
rv = prefs->GetCharPref(MAC_OS_X_PAGE_SETUP_PREFNAME, getter_Copies(encodedData));
if (NS_FAILED(rv))
return rv;
// decode the base64
PRInt32 encodedDataLen = nsCRT::strlen(encodedData.get());
char* decodedData = ::PL_Base64Decode(encodedData.get(), encodedDataLen, nsnull);
if (!decodedData)
return NS_ERROR_FAILURE;
Handle decodedDataHandle = nsnull;
OSErr err = ::PtrToHand(decodedData, &decodedDataHandle, (encodedDataLen * 3) / 4);
PR_Free(decodedData);
if (err != noErr)
return NS_ERROR_OUT_OF_MEMORY;
StHandleOwner handleOwner(decodedDataHandle);
PMPageFormat newPageFormat = kPMNoPageFormat;
OSStatus status = ::PMUnflattenPageFormat(decodedDataHandle, &newPageFormat);
if (status != noErr)
return NS_ERROR_FAILURE;
status = ::PMCopyPageFormat(newPageFormat, mPageFormat);
::PMDisposePageFormat(newPageFormat);
newPageFormat = kPMNoPageFormat;
return (status == noErr) ? NS_OK : NS_ERROR_FAILURE;
}
nsresult
nsPrintOptionsX::WritePageSetupToPrefs()
{
if (mPageFormat == kPMNoPageFormat)
return NS_ERROR_NOT_INITIALIZED;
nsresult rv;
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_FAILED(rv))
return rv;
Handle pageFormatHandle = nsnull;
OSStatus err = ::PMFlattenPageFormat(mPageFormat, &pageFormatHandle);
if (err != noErr)
return NS_ERROR_FAILURE;
StHandleOwner handleOwner(pageFormatHandle);
StHandleLocker handleLocker(pageFormatHandle);
nsXPIDLCString encodedData;
encodedData.Adopt(::PL_Base64Encode(*pageFormatHandle, ::GetHandleSize(pageFormatHandle), nsnull));
if (!encodedData.get())
return NS_ERROR_OUT_OF_MEMORY;
return prefs->SetCharPref(MAC_OS_X_PAGE_SETUP_PREFNAME, encodedData);
}

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

@ -0,0 +1,77 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Simon Fraser <sfraser@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsPrintOptionsX_h__
#define nsPrintOptionsX_h__
#include <PMDefinitions.h>
#include "nsPrintOptionsImpl.h"
//*****************************************************************************
//*** nsPrintOptions
//*****************************************************************************
class nsPrintOptionsX : public nsPrintOptions
{
public:
nsPrintOptionsX();
virtual ~nsPrintOptionsX();
NS_IMETHOD ShowNativeDialog(void);
NS_IMETHOD ReadPrefs(void);
NS_IMETHOD WritePrefs(void);
NS_IMETHOD GetNativeData(PRInt16 aDataType, void * *_retval);
protected:
nsresult ReadPageSetupFromPrefs();
nsresult WritePageSetupToPrefs();
protected:
PMPageFormat mPageFormat; // persist this between runs
};
#endif /* nsPrintOptionsX_h__ */

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

@ -45,68 +45,46 @@
#include "nsIPref.h"
#include "nsIServiceManager.h"
//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;
}
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";
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 Options
const char * kPrintEvenPages = "print.print_evenpages";
const char * kPrintOddPages = "print.print_oddpages";
const char * kPrintHeaderStr1 = "print.print_headerleft";
const char * kPrintHeaderStr2 = "print.print_headercenter";
const char * kPrintHeaderStr3 = "print.print_headerright";
const char * kPrintFooterStr1 = "print.print_footerleft";
const char * kPrintFooterStr2 = "print.print_footercenter";
const char * kPrintFooterStr3 = "print.print_footerright";
const char kPrintEvenPages[] = "print.print_evenpages";
const char kPrintOddPages[] = "print.print_oddpages";
const char kPrintHeaderStr1[] = "print.print_headerleft";
const char kPrintHeaderStr2[] = "print.print_headercenter";
const char kPrintHeaderStr3[] = "print.print_headerright";
const char kPrintFooterStr1[] = "print.print_footerleft";
const char kPrintFooterStr2[] = "print.print_footercenter";
const char kPrintFooterStr3[] = "print.print_footerright";
// Additional Prefs
const char * kPrintReversed = "print.print_reversed";
const char * kPrintColor = "print.print_color";
const char * kPrintPaperSize = "print.print_paper_size";
const char * kPrintOrientation= "print.print_orientation";
const char * kPrintCommand = "print.print_command";
const char * kPrintFile = "print.print_file";
const char * kPrintToFile = "print.print_tofile";
const char * kPrintPageDelay = "print.print_pagedelay";
const char kPrintReversed[] = "print.print_reversed";
const char kPrintColor[] = "print.print_color";
const char kPrintPaperSize[] = "print.print_paper_size";
const char kPrintOrientation[]= "print.print_orientation";
const char kPrintCommand[] = "print.print_command";
const char kPrintFile[] = "print.print_file";
const char kPrintToFile[] = "print.print_tofile";
const char kPrintPageDelay[] = "print.print_pagedelay";
// 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 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";
const char kLeftJust[] = "left";
const char kCenterJust[] = "center";
const char kRightJust[] = "right";
nsFont* nsPrintOptions::mDefaultFont = nsnull;
nsFont* nsPrintOptions::sDefaultFont = nsnull;
/** ---------------------------------------------------
* See documentation in nsPrintOptionsImpl.h
@ -136,8 +114,8 @@ nsPrintOptions::nsPrintOptions() :
mPrintOptions = kOptPrintOddPages | kOptPrintEvenPages;
if (mDefaultFont == nsnull) {
mDefaultFont = new nsFont("Times", NS_FONT_STYLE_NORMAL,NS_FONT_VARIANT_NORMAL,
if (sDefaultFont == nsnull) {
sDefaultFont = new nsFont("Times", NS_FONT_STYLE_NORMAL,NS_FONT_VARIANT_NORMAL,
NS_FONT_WEIGHT_NORMAL,0,NSIntPointsToTwips(10));
}
@ -157,9 +135,9 @@ nsPrintOptions::nsPrintOptions() :
*/
nsPrintOptions::~nsPrintOptions()
{
if (mDefaultFont != nsnull) {
delete mDefaultFont;
mDefaultFont = nsnull;
if (sDefaultFont != nsnull) {
delete sDefaultFont;
sDefaultFont = nsnull;
}
}
@ -170,9 +148,9 @@ nsPrintOptions::~nsPrintOptions()
NS_IMETHODIMP
nsPrintOptions::SetFontNamePointSize(nsString& aFontName, PRInt32 aPointSize)
{
if (mDefaultFont != nsnull && aFontName.Length() > 0 && aPointSize > 0) {
mDefaultFont->name = aFontName;
mDefaultFont->size = NSIntPointsToTwips(aPointSize);
if (sDefaultFont != nsnull && aFontName.Length() > 0 && aPointSize > 0) {
sDefaultFont->name = aFontName;
sDefaultFont->size = NSIntPointsToTwips(aPointSize);
}
return NS_OK;
}
@ -184,10 +162,10 @@ nsPrintOptions::SetFontNamePointSize(nsString& aFontName, PRInt32 aPointSize)
NS_IMETHODIMP
nsPrintOptions::SetDefaultFont(nsFont &aFont)
{
if (mDefaultFont != nsnull) {
delete mDefaultFont;
if (sDefaultFont != nsnull) {
delete sDefaultFont;
}
mDefaultFont = new nsFont(aFont);
sDefaultFont = new nsFont(aFont);
return NS_OK;
}
@ -198,7 +176,7 @@ nsPrintOptions::SetDefaultFont(nsFont &aFont)
NS_IMETHODIMP
nsPrintOptions::GetDefaultFont(nsFont &aFont)
{
aFont = *mDefaultFont;
aFont = *sDefaultFont;
return NS_OK;
}
@ -232,8 +210,7 @@ nsPrintOptions::GetMarginInTwips(nsMargin& aMargin)
NS_IMETHODIMP
nsPrintOptions::ShowNativeDialog()
{
return NS_OK;
return NS_ERROR_NOT_IMPLEMENTED;
}
/** ---------------------------------------------------
@ -737,6 +714,14 @@ NS_IMETHODIMP nsPrintOptions::SetPrintSilent(PRBool aPrintSilent)
return NS_OK;
}
/* [noscript] voidPtr GetNativeData (in short aDataType); */
NS_IMETHODIMP nsPrintOptions::GetNativeData(PRInt16 aDataType, void * *_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
*_retval = nsnull;
return NS_ERROR_NOT_IMPLEMENTED;
}
//-----------------------------------------------------
//-- Protected Methods

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

@ -87,7 +87,7 @@ protected:
PRBool mPrintToFile;
nsString mToFileName;
static nsFont* mDefaultFont;
static nsFont* sDefaultFont;
};