mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Add the new pluggable dialog work, in build, not used
BUg 135441 r=dcone,pink sr=attinasi
This commit is contained in:
parent
288186b2f3
commit
52ee2df50b
77
gfx/idl/nsIPrintSettingsMac.idl
Normal file
77
gfx/idl/nsIPrintSettingsMac.idl
Normal file
@ -0,0 +1,77 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** 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) 2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Don Cone <dcone@netscape.com>
|
||||
* Conrad Carlen <ccarlen@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 "nsISupports.idl"
|
||||
|
||||
%{ C++
|
||||
#include <Printing.h>
|
||||
%}
|
||||
|
||||
/**
|
||||
* Native types
|
||||
*/
|
||||
native nsTHPrint(THPrint);
|
||||
|
||||
/**
|
||||
* Simplified PrintSettings for Mac interface
|
||||
*
|
||||
* @status UNDER_REVIEW
|
||||
*/
|
||||
[scriptable, uuid(3C85F9F5-3A9D-4bce-8CF8-A1B14E5E8508)]
|
||||
|
||||
interface nsIPrintSettingsMac : nsISupports
|
||||
{
|
||||
/*
|
||||
* thPrint attribute
|
||||
*
|
||||
* Getter returns a clone of the current data
|
||||
* Setter copies (does not take ownership of) the input
|
||||
*/
|
||||
|
||||
[noscript] attribute nsTHPrint tHPrint;
|
||||
|
||||
/*
|
||||
* readPageSetupFromPrefs and writePageSetupToPrefs
|
||||
*
|
||||
* Read and write a print record to/from prefs.
|
||||
*/
|
||||
[noscript] void readPageSetupFromPrefs();
|
||||
[noscript] void writePageSetupToPrefs();
|
||||
};
|
82
gfx/idl/nsIPrintSettingsX.idl
Normal file
82
gfx/idl/nsIPrintSettingsX.idl
Normal file
@ -0,0 +1,82 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** 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) 2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Conrad Carlen <ccarlen@netscape.com>
|
||||
* Don Cone <dcone@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 "nsISupports.idl"
|
||||
|
||||
%{ C++
|
||||
#include <PMApplication.h>
|
||||
%}
|
||||
|
||||
/**
|
||||
* Native types
|
||||
*/
|
||||
native nsPMPageFormat(PMPageFormat);
|
||||
native nsPMPrintSettings(PMPrintSettings);
|
||||
|
||||
|
||||
/**
|
||||
* Simplified PrintSettings for OSX interface
|
||||
*
|
||||
* @status UNDER_REVIEW
|
||||
*/
|
||||
[scriptable, uuid(CD2A0A4F-0DE9-4c51-9232-42668F559F94)]
|
||||
|
||||
interface nsIPrintSettingsX : nsISupports
|
||||
{
|
||||
|
||||
/*
|
||||
* PMPageFormat and PMPrintSettings attributes
|
||||
*
|
||||
* Getter returns a clone of the current data
|
||||
* Setter copies (does not take ownership of) the input
|
||||
*/
|
||||
[noscript] attribute nsPMPageFormat pMPageFormat;
|
||||
|
||||
[noscript] attribute nsPMPrintSettings pMPrintSettings;
|
||||
|
||||
/*
|
||||
* readPageFormatFromPrefs and writePageFormatToPrefs
|
||||
*
|
||||
* Read and write a flattened PMPageFormat to/from prefs.
|
||||
* This also contains any custom data we appended to the dialog
|
||||
*/
|
||||
[noscript] void readPageFormatFromPrefs();
|
||||
[noscript] void writePageFormatToPrefs();
|
||||
};
|
70
gfx/public/nsPDECommon.h
Normal file
70
gfx/public/nsPDECommon.h
Normal file
@ -0,0 +1,70 @@
|
||||
/* -*- 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):
|
||||
*
|
||||
*
|
||||
* 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 nsPDECommon_h___
|
||||
#define nsPDECommon_h___
|
||||
|
||||
|
||||
#define kPDE_Creator 'MOZZ'
|
||||
|
||||
|
||||
typedef struct {
|
||||
Boolean mHaveSelection;
|
||||
Boolean mHaveFrames;
|
||||
Boolean mHaveFrameSelected;
|
||||
Boolean mPrintSelection;
|
||||
Boolean mPrintFrameAsIs;
|
||||
Boolean mPrintSelectedFrame;
|
||||
Boolean mPrintFramesSeperatly;
|
||||
Boolean mShrinkToFit;
|
||||
} nsPrintExtensions;
|
||||
|
||||
|
||||
|
||||
#define kPrintTitlesDefault false // the initial default value of our page format custom data
|
||||
|
||||
// Our tag for the Print Settings ticket. This should be defined in an application
|
||||
// header that is common to this file and the applications' files so that it
|
||||
// can get access to the data set in the Print Settings.
|
||||
#define kAppPrintDialogPDEOnlyKey CFSTR("com.apple.print.PrintSettingsTicket.MOZZ")
|
||||
|
||||
#define kPrintSelectionOnlyDefault false // the initial default value of custom print settings custom data
|
||||
|
||||
|
||||
|
||||
#endif
|
107
gfx/public/nsWatchTask.h
Normal file
107
gfx/public/nsWatchTask.h
Normal file
@ -0,0 +1,107 @@
|
||||
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
|
||||
/* ***** 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):
|
||||
*
|
||||
*
|
||||
* 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 WatchTask_h__
|
||||
#define WatchTask_h__
|
||||
|
||||
|
||||
#ifndef XP_MACOSX
|
||||
#include <Retrace.h>
|
||||
#endif
|
||||
#include <Quickdraw.h>
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
|
||||
|
||||
//
|
||||
// class nsWatchTask
|
||||
//
|
||||
// A nice little class that installs/removes a VBL to set the cursor to
|
||||
// the watch if we're away from the event loop for a while. Will also
|
||||
// animate the watch cursor.
|
||||
//
|
||||
|
||||
class nsWatchTask
|
||||
{
|
||||
public:
|
||||
nsWatchTask ( ) ;
|
||||
~nsWatchTask ( ) ;
|
||||
|
||||
// Registers the VBL task and does other various init tasks to begin
|
||||
// watching for time away from the event loop. It is ok to call other
|
||||
// methods on this object w/out calling Start().
|
||||
NS_GFX void Start ( ) ;
|
||||
|
||||
// call from the main event loop
|
||||
NS_GFX void EventLoopReached ( ) ;
|
||||
|
||||
// turn off when we know we're going into an area where it's ok
|
||||
// that WNE is not called (eg, the menu code)
|
||||
void Suspend ( ) { mSuspended = PR_TRUE; };
|
||||
void Resume ( ) { mSuspended = PR_FALSE; };
|
||||
|
||||
static NS_GFX nsWatchTask& GetTask ( ) ;
|
||||
|
||||
private:
|
||||
|
||||
enum {
|
||||
kRepeatInterval = 10, // check every 1/6 of a second if we should show watch (10/60)
|
||||
kTicksToShowWatch = 45, // show watch if haven't seen WNE for 3/4 second (45/60)
|
||||
kStepsInAnimation = 12
|
||||
};
|
||||
|
||||
// the VBL task
|
||||
static pascal void DoWatchTask(nsWatchTask* theTaskPtr) ;
|
||||
|
||||
#if !TARGET_CARBON
|
||||
VBLTask mTask; // this must be first!!
|
||||
#endif
|
||||
long mChecksum; // 'mozz' to validate we have real data at interrupt time (not needed?)
|
||||
void* mSelf; // so we can get back to |this| from the static routine
|
||||
long mTicks; // last time the event loop was hit
|
||||
Cursor mWatchCursor; // the watch cursor
|
||||
PRPackedBool mBusy; // are we currently spinning the cursor?
|
||||
PRPackedBool mSuspended; // set if we've temporarily suspended operation
|
||||
PRPackedBool mInstallSucceeded; // did we succeed in installing the task? (used in dtor)
|
||||
short mAnimation; // stage of animation
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
183
gfx/src/mac/nsPrintSettingsMac.cpp
Normal file
183
gfx/src/mac/nsPrintSettingsMac.cpp
Normal file
@ -0,0 +1,183 @@
|
||||
/* -*- 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):
|
||||
* Conrad Carlen <ccarlen@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 "nsPrintSettingsMac.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "plbase64.h"
|
||||
#include "prmem.h"
|
||||
#include "nsGfxUtils.h"
|
||||
|
||||
// Constants
|
||||
#define PRINTING_PREF_BRANCH "print."
|
||||
#define MAC_OS_PAGE_SETUP_PREFNAME "macos.pagesetup"
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED1(nsPrintSettingsMac,
|
||||
nsPrintSettings,
|
||||
nsIPrintSettingsMac)
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
nsPrintSettingsMac::nsPrintSettingsMac() :
|
||||
mPrintRecord(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
nsPrintSettingsMac::~nsPrintSettingsMac()
|
||||
{
|
||||
if (mPrintRecord)
|
||||
::DisposeHandle((Handle)mPrintRecord);
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
NS_IMETHODIMP nsPrintSettingsMac::Init()
|
||||
{
|
||||
// create the print style and print record
|
||||
mPrintRecord = (THPrint)::NewHandleClear(sizeof(TPrint));
|
||||
if (!mPrintRecord)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
::PrOpen();
|
||||
if (::PrError() != noErr)
|
||||
return NS_ERROR_FAILURE;
|
||||
::PrintDefault(mPrintRecord);
|
||||
::PrClose();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
NS_IMETHODIMP nsPrintSettingsMac::GetTHPrint(THPrint *aThPrint)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aThPrint);
|
||||
*aThPrint = nsnull;
|
||||
|
||||
if (!mPrintRecord)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
Handle temp = (Handle)mPrintRecord;
|
||||
if (::HandToHand(&temp) != noErr)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
*aThPrint = (THPrint)temp;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
NS_IMETHODIMP nsPrintSettingsMac::SetTHPrint(THPrint aThPrint)
|
||||
{
|
||||
NS_ENSURE_ARG(aThPrint);
|
||||
|
||||
if (mPrintRecord) {
|
||||
::DisposeHandle((Handle)mPrintRecord);
|
||||
mPrintRecord = nsnull;
|
||||
}
|
||||
mPrintRecord = aThPrint;
|
||||
if (::HandToHand((Handle *)&mPrintRecord) != noErr)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
NS_IMETHODIMP nsPrintSettingsMac::ReadPageSetupFromPrefs()
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPrefService> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch;
|
||||
rv = prefService->GetBranch(PRINTING_PREF_BRANCH, getter_AddRefs(prefBranch));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsXPIDLCString encodedData;
|
||||
rv = prefBranch->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;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
|
||||
NS_IMETHODIMP nsPrintSettingsMac::WritePageSetupToPrefs()
|
||||
{
|
||||
if (!mPrintRecord)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPrefService> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch;
|
||||
rv = prefService->GetBranch(PRINTING_PREF_BRANCH, getter_AddRefs(prefBranch));
|
||||
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 prefBranch->SetCharPref(MAC_OS_PAGE_SETUP_PREFNAME, encodedData);
|
||||
}
|
56
gfx/src/mac/nsPrintSettingsMac.h
Normal file
56
gfx/src/mac/nsPrintSettingsMac.h
Normal file
@ -0,0 +1,56 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications, Inc. Portions created by Netscape are
|
||||
* Copyright (C) 1999, Mozilla. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef nsPrintSettingsMac_h__
|
||||
#define nsPrintSettingsMac_h__
|
||||
|
||||
#include "nsPrintSettingsImpl.h"
|
||||
#include "nsIPrintSettingsMac.h"
|
||||
#include <Printing.h>
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
//*** nsPrintSettingsMac
|
||||
//*****************************************************************************
|
||||
#if !TARGET_CARBON
|
||||
|
||||
class nsPrintSettingsMac : public nsPrintSettings,
|
||||
public nsIPrintSettingsMac
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIPRINTSETTINGSMAC
|
||||
|
||||
nsPrintSettingsMac();
|
||||
virtual ~nsPrintSettingsMac();
|
||||
|
||||
nsresult Init();
|
||||
|
||||
protected:
|
||||
|
||||
THPrint mPrintRecord;
|
||||
|
||||
};
|
||||
|
||||
#endif /* TARGET_CARBON */
|
||||
|
||||
#endif /* nsPrintSettingsMac_h__ */
|
249
gfx/src/mac/nsPrintSettingsX.cpp
Normal file
249
gfx/src/mac/nsPrintSettingsX.cpp
Normal file
@ -0,0 +1,249 @@
|
||||
/* -*- 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):
|
||||
* Conrad Carlen <ccarlen@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 "nsPrintSettingsX.h"
|
||||
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIServiceManagerUtils.h"
|
||||
|
||||
#include "plbase64.h"
|
||||
#include "prmem.h"
|
||||
#include "nsGfxUtils.h"
|
||||
|
||||
// Constants
|
||||
#define PRINTING_PREF_BRANCH "print."
|
||||
#define MAC_OS_X_PAGE_SETUP_PREFNAME "macosx.pagesetup"
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED1(nsPrintSettingsX,
|
||||
nsPrintSettings,
|
||||
nsIPrintSettingsX)
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
nsPrintSettingsX::nsPrintSettingsX() :
|
||||
mPageFormat(kPMNoPageFormat),
|
||||
mPrintSettings(kPMNoPrintSettings)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
nsPrintSettingsX::~nsPrintSettingsX()
|
||||
{
|
||||
if (mPageFormat != kPMNoPageFormat) {
|
||||
::PMDisposePageFormat(mPageFormat);
|
||||
mPageFormat = kPMNoPageFormat;
|
||||
}
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
nsresult nsPrintSettingsX::Init()
|
||||
{
|
||||
OSStatus status;
|
||||
|
||||
status = ::PMNewPageFormat(&mPageFormat);
|
||||
if (status != noErr)
|
||||
return NS_ERROR_FAILURE;
|
||||
status = ::PMNewPrintSettings(&mPrintSettings);
|
||||
if (status != noErr)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
status = ::PMBegin();
|
||||
NS_ASSERTION(status == noErr, "Error from PMBegin()");
|
||||
if (status == noErr) {
|
||||
status = ::PMDefaultPageFormat(mPageFormat);
|
||||
NS_ASSERTION(status == noErr, "Error from PMDefaultPageFormat()");
|
||||
status = ::PMDefaultPrintSettings(mPrintSettings);
|
||||
NS_ASSERTION(status == noErr, "Error from PMDefaultPrintSettings()");
|
||||
|
||||
::PMEnd();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
NS_IMETHODIMP nsPrintSettingsX::GetPMPageFormat(PMPageFormat *aPMPageFormat)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aPMPageFormat);
|
||||
*aPMPageFormat = kPMNoPageFormat;
|
||||
NS_ENSURE_STATE(mPageFormat != kPMNoPageFormat);
|
||||
|
||||
PMPageFormat pageFormat;
|
||||
OSStatus status = ::PMNewPageFormat(&pageFormat);
|
||||
if (status != noErr) return NS_ERROR_FAILURE;
|
||||
|
||||
status = ::PMCopyPageFormat(mPageFormat, pageFormat);
|
||||
if (status != noErr) {
|
||||
::PMDisposePageFormat(pageFormat);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
*aPMPageFormat = pageFormat;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
NS_IMETHODIMP nsPrintSettingsX::SetPMPageFormat(PMPageFormat aPMPageFormat)
|
||||
{
|
||||
NS_ENSURE_ARG(aPMPageFormat);
|
||||
NS_ENSURE_STATE(mPageFormat != kPMNoPageFormat);
|
||||
|
||||
OSErr status = ::PMCopyPageFormat(aPMPageFormat, mPageFormat);
|
||||
if (status != noErr)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
NS_IMETHODIMP nsPrintSettingsX::GetPMPrintSettings(PMPrintSettings *aPMPrintSettings)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aPMPrintSettings);
|
||||
*aPMPrintSettings = kPMNoPrintSettings;
|
||||
NS_ENSURE_STATE(mPrintSettings != kPMNoPrintSettings);
|
||||
|
||||
PMPrintSettings printSettings;
|
||||
OSStatus status = ::PMNewPrintSettings(&printSettings);
|
||||
if (status != noErr) return NS_ERROR_FAILURE;
|
||||
|
||||
status = ::PMCopyPrintSettings(mPrintSettings, printSettings);
|
||||
if (status != noErr) {
|
||||
::PMDisposePrintSettings(printSettings);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
*aPMPrintSettings = printSettings;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
NS_IMETHODIMP nsPrintSettingsX::SetPMPrintSettings(PMPrintSettings aPMPrintSettings)
|
||||
{
|
||||
NS_ENSURE_ARG(aPMPrintSettings);
|
||||
NS_ENSURE_STATE(mPrintSettings != kPMNoPrintSettings);
|
||||
|
||||
OSErr status = ::PMCopyPrintSettings(aPMPrintSettings, mPrintSettings);
|
||||
if (status != noErr)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
NS_IMETHODIMP nsPrintSettingsX::ReadPageFormatFromPrefs()
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPrefService> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch;
|
||||
rv = prefService->GetBranch(PRINTING_PREF_BRANCH, getter_AddRefs(prefBranch));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsXPIDLCString encodedData;
|
||||
rv = prefBranch->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);
|
||||
|
||||
return (status == noErr) ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
*/
|
||||
NS_IMETHODIMP nsPrintSettingsX::WritePageFormatToPrefs()
|
||||
{
|
||||
if (mPageFormat == kPMNoPageFormat)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPrefService> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch;
|
||||
rv = prefService->GetBranch(PRINTING_PREF_BRANCH, getter_AddRefs(prefBranch));
|
||||
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 prefBranch->SetCharPref(MAC_OS_X_PAGE_SETUP_PREFNAME, encodedData);
|
||||
}
|
50
gfx/src/mac/nsPrintSettingsX.h
Normal file
50
gfx/src/mac/nsPrintSettingsX.h
Normal file
@ -0,0 +1,50 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications, Inc. Portions created by Netscape are
|
||||
* Copyright (C) 1999, Mozilla. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef nsPrintSettingsX_h__
|
||||
#define nsPrintSettingsX_h__
|
||||
|
||||
#include "nsPrintSettingsImpl.h"
|
||||
#include "nsIPrintSettingsX.h"
|
||||
|
||||
//*****************************************************************************
|
||||
//*** nsPrintSettingsX
|
||||
//*****************************************************************************
|
||||
|
||||
class nsPrintSettingsX : public nsPrintSettings,
|
||||
public nsIPrintSettingsX
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIPRINTSETTINGSX
|
||||
|
||||
nsPrintSettingsX();
|
||||
virtual ~nsPrintSettingsX();
|
||||
|
||||
nsresult Init();
|
||||
|
||||
protected:
|
||||
PMPageFormat mPageFormat;
|
||||
PMPrintSettings mPrintSettings;
|
||||
};
|
||||
|
||||
#endif /* nsPrintSettingsX_h__ */
|
Loading…
Reference in New Issue
Block a user