Bug 188508 - Upgrade print dialog PDE. r=pinkerton/sr=sfraser

git-svn-id: svn://10.0.0.236/trunk@140647 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
ccarlen%netscape.com
2003-04-03 19:20:27 +00:00
parent 634a85abf4
commit 6cde9731e0
26 changed files with 2826 additions and 1010 deletions

View File

@@ -44,12 +44,18 @@ REQUIRES = xpcom \
intl \
$(NULL)
DIRS = printpde
CPPSRCS = \
nsPrintingPromptServiceX.cpp \
nsPrintProgressParams.cpp \
nsPrintProgress.cpp \
$(NULL)
LOCAL_INCLUDES = \
-I$(srcdir)/printpde/public \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a
# static lib.
FORCE_STATIC_LIB = 1

View File

@@ -54,10 +54,6 @@
#include "nsDirectoryServiceDefs.h"
#include "nsPDECommon.h"
#ifndef XP_MACOSX
#include "nsILocalFIleMac.h"
#endif
// Printing Progress Includes
#include "nsPrintProgress.h"
#include "nsPrintProgressParams.h"
@@ -71,56 +67,30 @@
// Constants
static const char *kPrintProgressDialogURL = "chrome://global/content/printProgress.xul";
// Globals
static CFPlugInRef gPDEPlugIn = nsnull;
//-----------------------------------------------------------------------------
// Static Helpers
//-----------------------------------------------------------------------------
static CFPlugInRef LoadPDEPlugIn()
static nsresult LoadPDEPlugIn()
{
#ifndef XP_MACOSX
static CFPlugInRef gPDEPlugIn = nsnull;
if (!gPDEPlugIn) {
nsresult rv;
nsCOMPtr<nsIProperties> dirService(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
if (!dirService)
return nsnull;
nsCOMPtr<nsILocalFileMac> pluginDir;
rv = dirService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsILocalFileMac), getter_AddRefs(pluginDir));
if (NS_FAILED(rv))
return nsnull;
pluginDir->AppendNative(NS_LITERAL_CSTRING("Essential Files"));
pluginDir->AppendNative(NS_LITERAL_CSTRING("PrintDialogPDE.plugin"));
FSSpec pluginSpec;
rv = pluginDir->GetFSSpec(&pluginSpec);
if (NS_FAILED(rv))
return nsnull;
OSErr err;
FSRef pluginFSRef;
char pathBuf[512];
err = ::FSpMakeFSRef(&pluginSpec, &pluginFSRef);
if (err)
return nsnull;
err = ::FSRefMakePath(&pluginFSRef, (UInt8 *)pathBuf, sizeof(pathBuf)-1);
if (err)
return nsnull;
CFStringRef pathRef = ::CFStringCreateWithCString(NULL, pathBuf, kCFStringEncodingUTF8);
if (!pathRef)
return nsnull;
CFURLRef url = ::CFURLCreateWithFileSystemPath(NULL, pathRef, kCFURLPOSIXPathStyle, TRUE);
if (url)
gPDEPlugIn = ::CFPlugInCreate(NULL, url);
::CFRelease(pathRef);
::CFRelease(url);
CFURLRef pluginsURL = ::CFBundleCopyBuiltInPlugInsURL(CFBundleGetMainBundle());
if (pluginsURL) {
CFURLRef thePluginURL = ::CFURLCreateCopyAppendingPathComponent(nsnull,
pluginsURL,
CFSTR("PrintPDE.plugin"),
PR_FALSE);
if (thePluginURL) {
gPDEPlugIn = ::CFPlugInCreate(nsnull, thePluginURL);
::CFRelease(thePluginURL);
}
::CFRelease(pluginsURL);
}
}
#endif
return gPDEPlugIn;
return gPDEPlugIn ? NS_OK : NS_ERROR_FAILURE;
}
//*****************************************************************************
@@ -186,8 +156,14 @@ nsPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIWebBrowserPrin
PRBool isOn;
PRInt16 howToEnableFrameUI = nsIPrintSettings::kFrameEnableNone;
nsPrintExtensions printData = {false,false,false,false,false,false,false,false};
nsPrintExtensions printData = {false,false,false,false,false,false,false,false,true,true};
// Fetch the current extended data from the print settings
UInt32 bytesNeeded;
status = ::PMGetPrintSettingsExtendedData(nativePrintSettings, kMozPDECreatorCode, &bytesNeeded, NULL);
if (status == noErr && bytesNeeded == sizeof(printData))
(void)::PMGetPrintSettingsExtendedData(nativePrintSettings, kMozPDECreatorCode,&bytesNeeded, &printData);
// set the values for the plugin here
printSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn);
printData.mHaveSelection = isOn;
@@ -201,20 +177,25 @@ nsPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIWebBrowserPrin
printData.mHaveFrameSelected = false;
}
printSettings->GetShrinkToFit(&isOn);
printData.mShrinkToFit = isOn;
printData.mShrinkToFit = isOn;
printSettings->GetPrintBGColors(&isOn);
printData.mPrintBGColors = isOn;
printSettings->GetPrintBGImages(&isOn);
printData.mPrintBGImages = isOn;
CFPlugInRef pdePlugIn = ::LoadPDEPlugIn();
status = ::PMSetPrintSettingsExtendedData(nativePrintSettings, kPDE_Creator, sizeof(printData),&printData);
rv = ::LoadPDEPlugIn();
NS_ASSERTION(NS_SUCCEEDED(rv), "LoadPDEPlugIn() failed");
status = ::PMSetPrintSettingsExtendedData(nativePrintSettings, kMozPDECreatorCode, sizeof(printData),&printData);
NS_ASSERTION(status == noErr, "PMSetPrintSettingsExtendedData() failed");
Boolean accepted;
status = ::PMSessionPrintDialog(printSession, nativePrintSettings, pageFormat, &accepted);
if (status == noErr && accepted) {
UInt32 bytesNeeded;
int pageRange = -1;
status = ::PMGetPrintSettingsExtendedData(nativePrintSettings, kPDE_Creator, &bytesNeeded, NULL);
status = ::PMGetPrintSettingsExtendedData(nativePrintSettings, kMozPDECreatorCode, &bytesNeeded, NULL);
if (status == noErr && bytesNeeded == sizeof(printData)) {
status = ::PMGetPrintSettingsExtendedData(nativePrintSettings, kPDE_Creator,&bytesNeeded, &printData);
status = ::PMGetPrintSettingsExtendedData(nativePrintSettings, kMozPDECreatorCode,&bytesNeeded, &printData);
// set the correct data fields
if (printData.mPrintSelection) {
@@ -234,6 +215,8 @@ nsPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIWebBrowserPrin
printSettings->SetPrintFrameType(nsIPrintSettings::kEachFrameSep);
printSettings->SetShrinkToFit(printData.mShrinkToFit);
printSettings->SetPrintBGColors(printData.mPrintBGColors);
printSettings->SetPrintBGImages(printData.mPrintBGImages);
}
if (pageRange == -1) {

View File

@@ -0,0 +1,65 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# 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 mozilla.org code.
#
# The Initial Developer of the Original Code is
# Netscape Communications.
# Portions created by the Initial Developer are Copyright (C) 2001
# 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 MPL, 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 MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
ifdef MOZ_DEBUG
BUILDSTYLE = Development
else
BUILDSTYLE = Deployment
endif
include $(topsrcdir)/config/rules.mk
ABS_topsrcdir := $(shell cd $(topsrcdir); pwd)
ifneq ($(ABS_topsrcdir),$(MOZ_BUILD_ROOT))
export::
rsync -a --exclude .DS_Store --exclude "CVS/" $(srcdir)/PrintPDE.pbproj .
ln -fs $(srcdir)/src
ln -fs $(srcdir)/res
ln -fs $(srcdir)/public
endif
libs::
pbxbuild -buildstyle $(BUILDSTYLE) install
cp -R build/UninstalledProducts/PrintPDE.plugin $(DIST)
clean clobber::
rm -rf build

View File

@@ -0,0 +1,409 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 38;
objects = {
015B6DBE004B2AF27F000001 = {
isa = PBXBundleReference;
path = PrintPDE.plugin;
refType = 3;
};
015B6DC0004B2AF27F000001 = {
buildPhases = (
015B6DC1004B2AF27F000001,
015B6DC2004B2AF27F000001,
015B6DC3004B2AF27F000001,
015B6DC4004B2AF27F000001,
015B6DC5004B2AF27F000001,
);
buildSettings = {
FRAMEWORK_SEARCH_PATHS = "\"$(SYSTEM_LIBRARY_DIR)/Frameworks/ApplicationServices.framework/Frameworks\" \"$(SYSTEM_LIBRARY_DIR)/Frameworks/Carbon.framework/Frameworks\"";
HEADER_SEARCH_PATHS = .;
INSTALL_MODE_FLAG = "u+w";
OPTIMIZATION_CFLAGS = "-O2";
OTHER_CFLAGS = "";
OTHER_LDFLAGS = "-bundle";
PRODUCT_NAME = PrintPDE;
SECTORDER_FLAGS = "";
WARNING_CFLAGS = "-Wall -Wmost -Wno-four-char-constants -Wno-unknown-pragmas";
WRAPPER_EXTENSION = plugin;
};
dependencies = (
);
isa = PBXBundleTarget;
name = PrintPDE;
productName = PrintDialogPDE.plugin;
productReference = 015B6DBE004B2AF27F000001;
productSettingsXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>PrintPDE</string>
<key>CFBundleGetInfoString</key>
<string></string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>org.mozilla.pde.MOZZ</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>PrintPDE</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>MOZZ</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFPlugInDynamicRegistration</key>
<string>NO</string>
<key>CFPlugInFactories</key>
<dict>
<key>00000000-0000-0000-0000-000000000000</key>
<string>MyCFPlugInFactory</string>
</dict>
<key>CFPlugInTypes</key>
<dict>
<key>BCB07250-E57F-11D3-8CA6-0050E4603277</key>
<array>
<string>00000000-0000-0000-0000-000000000000</string>
</array>
</dict>
</dict>
</plist>
";
shouldUseHeadermap = 0;
};
015B6DC1004B2AF27F000001 = {
buildActionMask = 2147483647;
files = (
F73AA2E0026B518801CB2098,
F73AA2E1026B518801CB2098,
F73AA2E2026B518801CB2098,
F586CCD603BC18BC01202892,
);
isa = PBXHeadersBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
};
015B6DC2004B2AF27F000001 = {
buildActionMask = 2147483647;
files = (
F73AA2E4026B518801CB2098,
F73AA2E5026B518801CB2098,
);
isa = PBXResourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
};
015B6DC3004B2AF27F000001 = {
buildActionMask = 2147483647;
files = (
F73AA2E6026B518801CB2098,
F73AA2E7026B518801CB2098,
F73AA2E8026B518801CB2098,
);
isa = PBXSourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
};
015B6DC4004B2AF27F000001 = {
buildActionMask = 2147483647;
files = (
015B6DD2004B2D337F000001,
);
isa = PBXFrameworksBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
};
015B6DC5004B2AF27F000001 = {
buildActionMask = 2147483647;
files = (
);
isa = PBXRezBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
};
015B6DD2004B2D337F000001 = {
fileRef = 01823927FFE8053411CA24C1;
isa = PBXBuildFile;
settings = {
};
};
01823927FFE8053411CA24C1 = {
isa = PBXFrameworkReference;
name = Carbon.framework;
path = /System/Library/Frameworks/Carbon.framework;
refType = 0;
};
01ACF443FFC1C83D11CA2470 = {
buildRules = (
);
buildSettings = {
COPY_PHASE_STRIP = NO;
OPTIMIZATION_CFLAGS = "-O0";
};
isa = PBXBuildStyle;
name = Development;
};
01ACF444FFC1C83D11CA2470 = {
buildRules = (
);
buildSettings = {
COPY_PHASE_STRIP = YES;
};
isa = PBXBuildStyle;
name = Deployment;
};
//010
//011
//012
//013
//014
//080
//081
//082
//083
//084
089C1669FE841209C02AAC07 = {
buildStyles = (
01ACF443FFC1C83D11CA2470,
01ACF444FFC1C83D11CA2470,
);
isa = PBXProject;
mainGroup = 089C166AFE841209C02AAC07;
projectDirPath = "";
targets = (
015B6DC0004B2AF27F000001,
);
};
089C166AFE841209C02AAC07 = {
children = (
F849B8C8029C68B901CB2098,
089C1671FE841209C02AAC07,
19C28FB6FE9D52B211CA2CBB,
);
isa = PBXGroup;
name = CFPlugInBundle;
refType = 4;
};
089C1671FE841209C02AAC07 = {
children = (
01823927FFE8053411CA24C1,
);
isa = PBXGroup;
name = "External Frameworks and Libraries";
refType = 4;
};
//080
//081
//082
//083
//084
//190
//191
//192
//193
//194
19C28FB6FE9D52B211CA2CBB = {
children = (
015B6DBE004B2AF27F000001,
);
isa = PBXGroup;
name = Products;
refType = 4;
};
//190
//191
//192
//193
//194
//F50
//F51
//F52
//F53
//F54
F57C986203B8293D01202892 = {
isa = PBXFileReference;
path = nsPDECommon.h;
refType = 4;
};
F586CCD503BC184501202892 = {
children = (
F57C986203B8293D01202892,
);
isa = PBXGroup;
path = public;
refType = 4;
};
F586CCD603BC18BC01202892 = {
fileRef = F57C986203B8293D01202892;
isa = PBXBuildFile;
settings = {
};
};
//F50
//F51
//F52
//F53
//F54
//F70
//F71
//F72
//F73
//F74
F73AA2D2026B518801CB2098 = {
isa = PBXFileReference;
path = PDECore.h;
refType = 4;
};
F73AA2D3026B518801CB2098 = {
isa = PBXFileReference;
path = PDECustom.h;
refType = 4;
};
F73AA2D4026B518801CB2098 = {
isa = PBXFileReference;
path = PDEUtilities.h;
refType = 4;
};
F73AA2D5026B518801CB2098 = {
children = (
F73AA2D8026B518801CB2098,
F73AA2DA026B518801CB2098,
);
isa = PBXGroup;
path = res;
refType = 4;
};
F73AA2D8026B518801CB2098 = {
children = (
F73AA2D9026B518801CB2098,
);
isa = PBXVariantGroup;
name = Localizable.strings;
path = "";
refType = 4;
};
F73AA2D9026B518801CB2098 = {
isa = PBXFileReference;
name = English;
path = English.lproj/Localizable.strings;
refType = 4;
};
F73AA2DA026B518801CB2098 = {
children = (
F73AA2DB026B518801CB2098,
);
isa = PBXVariantGroup;
name = PrintPDE.nib;
path = "";
refType = 4;
};
F73AA2DB026B518801CB2098 = {
isa = PBXFileReference;
name = English;
path = English.lproj/PrintPDE.nib;
refType = 4;
};
F73AA2DC026B518801CB2098 = {
children = (
F73AA2DD026B518801CB2098,
F73AA2D2026B518801CB2098,
F73AA2DE026B518801CB2098,
F73AA2D3026B518801CB2098,
F73AA2DF026B518801CB2098,
F73AA2D4026B518801CB2098,
);
isa = PBXGroup;
path = src;
refType = 4;
};
F73AA2DD026B518801CB2098 = {
isa = PBXFileReference;
path = PDECore.c;
refType = 4;
};
F73AA2DE026B518801CB2098 = {
isa = PBXFileReference;
path = PDECustom.c;
refType = 4;
};
F73AA2DF026B518801CB2098 = {
isa = PBXFileReference;
path = PDEUtilities.c;
refType = 4;
};
F73AA2E0026B518801CB2098 = {
fileRef = F73AA2D2026B518801CB2098;
isa = PBXBuildFile;
settings = {
};
};
F73AA2E1026B518801CB2098 = {
fileRef = F73AA2D3026B518801CB2098;
isa = PBXBuildFile;
settings = {
};
};
F73AA2E2026B518801CB2098 = {
fileRef = F73AA2D4026B518801CB2098;
isa = PBXBuildFile;
settings = {
};
};
F73AA2E4026B518801CB2098 = {
fileRef = F73AA2D8026B518801CB2098;
isa = PBXBuildFile;
settings = {
};
};
F73AA2E5026B518801CB2098 = {
fileRef = F73AA2DA026B518801CB2098;
isa = PBXBuildFile;
settings = {
};
};
F73AA2E6026B518801CB2098 = {
fileRef = F73AA2DD026B518801CB2098;
isa = PBXBuildFile;
settings = {
};
};
F73AA2E7026B518801CB2098 = {
fileRef = F73AA2DE026B518801CB2098;
isa = PBXBuildFile;
settings = {
};
};
F73AA2E8026B518801CB2098 = {
fileRef = F73AA2DF026B518801CB2098;
isa = PBXBuildFile;
settings = {
};
};
//F70
//F71
//F72
//F73
//F74
//F80
//F81
//F82
//F83
//F84
F849B8C8029C68B901CB2098 = {
children = (
F586CCD503BC184501202892,
F73AA2DC026B518801CB2098,
F73AA2D5026B518801CB2098,
);
isa = PBXGroup;
name = PrintPDE;
refType = 4;
};
};
rootObject = 089C1669FE841209C02AAC07;
}

View 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 kMozPDESignature "MOZZ"
#define kMozPDECreatorCode 'MOZZ'
typedef struct {
// State info supplied by printing app
Boolean mHaveSelection;
Boolean mHaveFrames;
Boolean mHaveFrameSelected;
// The UI of the PDE allows control of these
Boolean mPrintFrameAsIs;
Boolean mPrintSelectedFrame;
Boolean mPrintFramesSeparately;
Boolean mPrintSelection;
Boolean mShrinkToFit;
Boolean mPrintBGColors;
Boolean mPrintBGImages;
} nsPrintExtensions;
// 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." kMozPDESignature)
#endif

View File

@@ -0,0 +1,4 @@
{
IBClasses = ();
IBVersion = 1;
}

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
<string>615 91 356 240 0 0 1600 1002 </string>
<key>IBFramework Version</key>
<string>286.0</string>
<key>IBLockedObjects</key>
<array/>
<key>IBSystem Version</key>
<string>6G30</string>
<key>targetFramework</key>
<string>IBCarbonFramework</string>
</dict>
</plist>

View File

@@ -0,0 +1,113 @@
<?xml version="1.0" standalone="yes"?>
<object class="NSIBObjectData">
<string name="targetFramework">IBCarbonFramework</string>
<object name="rootObject" class="NSCustomObject" id="1">
<string name="customClass">NSApplication</string>
</object>
<array count="11" name="allObjects">
<object class="IBCarbonWindow" id="166">
<string name="windowRect">195 570 431 1074 </string>
<string name="title">Window</string>
<object name="rootControl" class="IBCarbonRootControl" id="167">
<string name="bounds">0 0 236 504 </string>
<array count="1" name="subviews">
<object class="IBCarbonUserPane" id="212">
<string name="bounds">0 0 216 478 </string>
<array count="8" name="subviews">
<object class="IBCarbonCheckBox" id="210">
<string name="bounds">20 117 38 325 </string>
<ostype name="controlSignature">MOZZ</ostype>
<int name="controlID">4002</int>
<string name="title">Print Selection Only</string>
</object>
<object class="IBCarbonCheckBox" id="211">
<string name="bounds">46 117 60 325 </string>
<ostype name="controlSignature">MOZZ</ostype>
<int name="controlID">4003</int>
<string name="title">Shrink To Fit Page Width</string>
</object>
<object class="IBCarbonCheckBox" id="216">
<string name="bounds">82 117 96 325 </string>
<ostype name="controlSignature">MOZZ</ostype>
<int name="controlID">4004</int>
<string name="title">Print Background Colors</string>
</object>
<object class="IBCarbonCheckBox" id="214">
<string name="bounds">104 117 118 325 </string>
<ostype name="controlSignature">MOZZ</ostype>
<int name="controlID">4005</int>
<string name="title">Print Background Images</string>
</object>
<object class="IBCarbonRadioGroup" id="213">
<string name="bounds">135 116 196 325 </string>
<ostype name="controlSignature">MOZZ</ostype>
<int name="controlID">4001</int>
<int name="numRows">3</int>
<int name="intercellHeight">4</int>
<array count="3" name="radioTitles">
<array count="1">
<string>Radio1</string>
</array>
<array count="1">
<string>Radio2</string>
</array>
<array count="1">
<string>Radio</string>
</array>
</array>
</object>
<object class="IBCarbonStaticText" id="218">
<string name="bounds">133 20 149 109 </string>
<string name="title">Frames:</string>
<int name="justification">-1</int>
</object>
<object class="IBCarbonStaticText" id="215">
<string name="bounds">20 20 36 109 </string>
<string name="title">Options:</string>
<int name="justification">-1</int>
</object>
<object class="IBCarbonStaticText" id="217">
<string name="bounds">80 20 96 109 </string>
<string name="title">Appearance:</string>
<int name="justification">-1</int>
</object>
</array>
<ostype name="controlSignature">MOZZ</ostype>
<int name="controlID">4000</int>
<int name="featureBits">2</int>
</object>
</array>
</object>
</object>
<reference idRef="167"/>
<reference idRef="210"/>
<reference idRef="211"/>
<reference idRef="212"/>
<reference idRef="213"/>
<reference idRef="214"/>
<reference idRef="215"/>
<reference idRef="216"/>
<reference idRef="217"/>
<reference idRef="218"/>
</array>
<array count="11" name="allParents">
<reference idRef="1"/>
<reference idRef="166"/>
<reference idRef="212"/>
<reference idRef="212"/>
<reference idRef="167"/>
<reference idRef="212"/>
<reference idRef="212"/>
<reference idRef="212"/>
<reference idRef="212"/>
<reference idRef="212"/>
<reference idRef="212"/>
</array>
<dictionary count="2" name="nameTable">
<string>File&apos;s Owner</string>
<reference idRef="1"/>
<string>PrintPDE</string>
<reference idRef="166"/>
</dictionary>
<unsigned_int name="nextObjectID">219</unsigned_int>
</object>

View File

@@ -0,0 +1,741 @@
/*
********************************************************************************
$Log: not supported by cvs2svn $
(c) Copyright 2002 Apple Computer, Inc. All rights reserved.
IMPORTANT: This Apple software is supplied to you by Apple Computer,
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Computer,
Inc. may be used to endorse or promote products derived from the Apple
Software without specific prior written permission from Apple. Except
as expressly stated in this notice, no other rights or licenses, express
or implied, are granted by Apple herein, including but not limited to
any patent rights that may be infringed by your derivative works or by
other works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES
NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#include <Carbon/Carbon.h>
#include <Print/PMPrintingDialogExtensions.h>
#include "PDECustom.h"
#include "PDEUtilities.h"
enum SyncDirection {
kSyncTicketFromPane = FALSE,
kSyncPaneFromTicket = TRUE
};
/*
--------------------------------------------------------------------------------
Prototypes
--------------------------------------------------------------------------------
*/
// callbacks
static HRESULT MyQueryInterface (void*, REFIID, LPVOID*);
static ULONG MyIUnknownRetain (void*);
static ULONG MyIUnknownRelease (void*);
static OSStatus MyPMRetain (PMPlugInHeaderInterface*);
static OSStatus MyPMRelease (PMPlugInHeaderInterface**);
static OSStatus MyPMGetAPIVersion (PMPlugInHeaderInterface*, PMPlugInAPIVersion*);
static OSStatus MyPrologue (PMPDEContext*, OSType*, CFStringRef*, CFStringRef*, UInt32*, UInt32*);
static OSStatus MyInitialize (PMPDEContext, PMPDEFlags*, PMPDERef, ControlRef, PMPrintSession);
static OSStatus MySync (PMPDEContext, PMPrintSession, Boolean);
static OSStatus MyGetSummary (PMPDEContext, CFArrayRef*, CFArrayRef*);
static OSStatus MyOpen (PMPDEContext);
static OSStatus MyClose (PMPDEContext);
static OSStatus MyTerminate (PMPDEContext, OSStatus);
/*
--------------------------------------------------------------------------------
instance types for the two interfaces we support
--------------------------------------------------------------------------------
*/
typedef struct
{
const IUnknownVTbl *vtable;
SInt32 refCount;
CFUUIDRef factoryID;
} MyIUnknownInstance;
typedef struct
{
const PlugInIntfVTable *vtable;
SInt32 refCount;
} MyPDEInstance;
#pragma mark -
/*
--------------------------------------------------------------------------------
** MyCFPlugInFactory
**
** Creates an instance of the IUnknown interface (see the COM
** specification for more information about IUnknown). The name of this
** factory function needs to be associated with the factory UUID in the
** CFPlugInFactories property list entry, so it can be loaded by the
** printing system for use in the dialog.
**
--------------------------------------------------------------------------------
*/
extern void* MyCFPlugInFactory (
CFAllocatorRef allocator,
CFUUIDRef typeUUID
)
{
// our IUnknown interface function table
static const IUnknownVTbl sMyIUnknownVTable =
{
NULL, // required padding for COM
MyQueryInterface,
MyIUnknownRetain,
MyIUnknownRelease
};
CFBundleRef myBundle = NULL;
CFDictionaryRef myTypes = NULL;
CFStringRef requestType = NULL;
CFArrayRef factories = NULL;
CFStringRef factory = NULL;
CFUUIDRef factoryID = NULL;
MyIUnknownInstance *instance = NULL;
myBundle = MyGetBundle();
if (myBundle != NULL)
{
myTypes = CFBundleGetValueForInfoDictionaryKey (
myBundle, CFSTR("CFPlugInTypes"));
if (myTypes != NULL)
{
// get a reference to the requested type
// verify that the requested type matches my type (it should!)
requestType = CFUUIDCreateString (allocator, typeUUID);
if (requestType != NULL)
{
factories = CFDictionaryGetValue (myTypes, requestType);
CFRelease (requestType);
if (factories != NULL)
{ // assume the factory we want is entry [0]
factory = CFArrayGetValueAtIndex (factories, 0);
if (factory != NULL)
{
// get a reference to my factory ID
factoryID = CFUUIDCreateFromString (
allocator, factory);
if (factoryID != NULL)
{
// construct an instance of the IUnknown interface
instance = malloc (sizeof(MyIUnknownInstance));
if (instance != NULL)
{
instance->vtable = &sMyIUnknownVTable;
instance->refCount = 1;
instance->factoryID = factoryID;
CFPlugInAddInstanceForFactory (factoryID);
}
else {
CFRelease (factoryID);
}
}
}
}
}
}
}
MyDebugMessage ("Factory", (SInt32) instance);
return instance;
}
#pragma mark -
/*
--------------------------------------------------------------------------------
** MyQueryInterface
**
** Finds the requested interface and returns an instance to the caller.
** If the request is for the "base" IUnknown interface, we just bump
** the refcount.
**
--------------------------------------------------------------------------------
*/
static HRESULT MyQueryInterface (
void *this,
REFIID iID,
LPVOID *ppv
)
{
// PDE interface function table
static const PlugInIntfVTable sMyPDEVTable =
{
{
MyPMRetain,
MyPMRelease,
MyPMGetAPIVersion
},
MyPrologue,
MyInitialize,
MySync,
MyGetSummary,
MyOpen,
MyClose,
MyTerminate
};
CFUUIDRef requestID = NULL;
CFUUIDRef actualID = NULL;
HRESULT result = E_UNEXPECTED;
// get a reference to the UUID for the requested interface
requestID = CFUUIDCreateFromUUIDBytes (kCFAllocatorDefault, iID);
if (requestID != NULL)
{
// get a reference to the UUID for all PDE interfaces
actualID = CFUUIDCreateFromString (kCFAllocatorDefault, kDialogExtensionIntfIDStr);
if (actualID != NULL)
{
if (CFEqual (requestID, actualID))
{
// caller wants an instance of my PDE interface
MyPDEInstance *instance = malloc (sizeof(MyPDEInstance));
if (instance != NULL)
{
instance->vtable = &sMyPDEVTable;
instance->refCount = 1;
*ppv = instance;
result = S_OK;
}
}
else
{
if (CFEqual (requestID, IUnknownUUID))
{
// caller wants an instance of my IUnknown interface
MyIUnknownRetain (this);
*ppv = this;
result = S_OK;
}
else
{
*ppv = NULL;
result = E_NOINTERFACE;
}
}
CFRelease (actualID);
}
CFRelease (requestID);
}
MyDebugMessage("MyQueryInterface", result);
return result;
}
/*
--------------------------------------------------------------------------------
** MyIUnknownRetain
**
** Increments the reference count for the calling interface on an
** object. It should be called for every new copy of a pointer to an
** interface on a given object.
**
** Returns an integer from 1 to n, the value of the new reference
** count. This information is meant to be used for diagnostic/testing
** purposes only, because, in certain situations, the value might be
** unstable.
**
--------------------------------------------------------------------------------
*/
static ULONG MyIUnknownRetain (void* this)
{
MyIUnknownInstance* instance = (MyIUnknownInstance*) this;
ULONG refCount = 1;
if (instance != NULL) {
refCount = ++instance->refCount;
}
MyDebugMessage("MyIUnknownRetain", refCount);
return refCount;
}
/*
--------------------------------------------------------------------------------
** MyIUnknownRelease
**
** Decrements the reference count for the calling interface on an
** object. If the reference count on the object reaches zero, the
** object is freed from memory.
**
** Returns the resulting value of the reference count, which is for
** diagnostic/testing purposes only.
**
--------------------------------------------------------------------------------
*/
static ULONG MyIUnknownRelease (void* this)
{
MyIUnknownInstance* instance = (MyIUnknownInstance*) this;
ULONG refCount = 0;
if (instance != NULL)
{
refCount = --instance->refCount;
if (refCount == 0)
{
CFPlugInRemoveInstanceForFactory (instance->factoryID);
CFRelease (instance->factoryID);
free (instance);
}
}
MyDebugMessage("MyIUnknownRelease", refCount);
return refCount;
}
/*
--------------------------------------------------------------------------------
MyPMRetain
--------------------------------------------------------------------------------
*/
static OSStatus MyPMRetain (PMPlugInHeaderInterface* this)
{
MyPDEInstance* instance = (MyPDEInstance*) this;
ULONG refCount = 1;
OSStatus result = noErr;
if (instance != NULL) {
refCount = ++instance->refCount;
}
MyDebugMessage("MyPMRetain", refCount);
return result;
}
/*
--------------------------------------------------------------------------------
MyPMRelease
--------------------------------------------------------------------------------
*/
static OSStatus MyPMRelease (
PMPlugInHeaderInterface** this
)
{
MyPDEInstance* instance = (MyPDEInstance*) *this;
ULONG refCount = 0;
OSStatus result = noErr;
// clear caller's instance variable (don't ask)
*this = NULL;
if(instance != NULL)
{
// decrement instance reference count, and free if zero
refCount = --instance->refCount;
if (refCount == 0)
{
free (instance);
MyFreeTitle();
MyFreeBundle();
}
}
MyDebugMessage("MyPMRelease", refCount);
return result;
}
/*
--------------------------------------------------------------------------------
MyPMGetAPIVersion
--------------------------------------------------------------------------------
*/
static OSStatus MyPMGetAPIVersion (
PMPlugInHeaderInterface* this,
PMPlugInAPIVersion* versionPtr
)
{
OSStatus result = noErr;
// constants defined in PMPrintingDialogExtensions.h
versionPtr->buildVersionMajor = kPDEBuildVersionMajor;
versionPtr->buildVersionMinor = kPDEBuildVersionMinor;
versionPtr->baseVersionMajor = kPDEBaseVersionMajor;
versionPtr->baseVersionMinor = kPDEBaseVersionMinor;
MyDebugMessage("MyPMGetAPIVersion", result);
return result;
}
#pragma mark -
/*
--------------------------------------------------------------------------------
MyPrologue
--------------------------------------------------------------------------------
*/
/*
When the printing system displays a printing dialog, it calls the
prologue function in each registered dialog extension. If the user
chooses a different printer while the dialog is still open, each
prologue function is called again.
If a prologue function returns a non-zero result code, the printing
system will call the plug-in's terminate function.
*/
static OSStatus MyPrologue (
PMPDEContext *outContext, // session-specific global data
OSType *creator, // not used
CFStringRef *paneKind, // kind ID string for this PDE
CFStringRef *title, // localized title string
UInt32 *maxH, // maximum horizontal extent
UInt32 *maxV // maximum vertical extent
)
{
MyContext context = NULL;
OSStatus result = kPMInvalidPDEContext;
context = malloc (sizeof (MyContextBlock));
if (context != NULL)
{
context->customContext = MyCreateCustomContext();
context->initialized = FALSE;
context->userPane = NULL;
context->helpHandler = NULL;
context->helpHandlerUPP = NULL;
// assign output parameters
*outContext = (PMPDEContext) context;
*creator = kMozPDECreatorCode;
*paneKind = kMyPaneKindID;
*title = MyGetTitle();
*maxH = kMyMaxH;
*maxV = kMyMaxV;
result = noErr;
}
MyDebugMessage("MyPrologue", result);
return result;
}
/*
--------------------------------------------------------------------------------
MyInitialize
--------------------------------------------------------------------------------
*/
static OSStatus MyInitialize (
PMPDEContext inContext,
PMPDEFlags* flags,
PMPDERef ref,
ControlRef userPane,
PMPrintSession session
)
{
MyContext context = (MyContext) inContext;
OSStatus result = noErr;
*flags = kPMPDENoFlags;
context->userPane = userPane;
result = MySync (
inContext, session, kSyncPaneFromTicket);
MyDebugMessage("MyInitialize", result);
return result;
}
/*
--------------------------------------------------------------------------------
MySync
--------------------------------------------------------------------------------
*/
static OSStatus MySync (
PMPDEContext inContext,
PMPrintSession session,
Boolean syncDirection
)
{
MyContext context = (MyContext) inContext;
OSStatus result = noErr;
if (syncDirection == kSyncPaneFromTicket)
{
result = MySyncPaneFromTicket (context->customContext, session);
}
else
{
result = MySyncTicketFromPane (context->customContext, session);
}
return result;
}
/*
--------------------------------------------------------------------------------
MyGetSummary
--------------------------------------------------------------------------------
*/
/*
For each control, gets a localized description of the title & current value
*/
static OSStatus MyGetSummary (
PMPDEContext inContext,
CFArrayRef *titles,
CFArrayRef *values
)
{
MyContext context = (MyContext) inContext;
CFMutableArrayRef titleArray = NULL;
CFMutableArrayRef valueArray = NULL;
// assume the worst
OSStatus result = kPMInvalidPDEContext;
// when the second argument to CFArrayCreateMutable is 0,
// the array size is not fixed
titleArray = CFArrayCreateMutable (
kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
if (titleArray != NULL)
{
valueArray = CFArrayCreateMutable (
kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
if (valueArray != NULL)
{
result = MyGetSummaryText (
context->customContext,
titleArray,
valueArray
);
}
}
if (result != noErr)
{
if (titleArray != NULL)
{
CFRelease (titleArray);
titleArray = NULL;
}
if (valueArray != NULL)
{
CFRelease (valueArray);
valueArray = NULL;
}
}
*titles = titleArray;
*values = valueArray;
MyDebugMessage("MyGetSummary", result);
return result;
}
/*
--------------------------------------------------------------------------------
MyOpen
--------------------------------------------------------------------------------
*/
static OSStatus MyOpen (PMPDEContext inContext)
{
MyContext context = (MyContext) inContext;
OSStatus result = noErr;
if (!context->initialized)
{
// initialize pane
IBNibRef nib = NULL;
result = CreateNibReferenceWithCFBundle (
MyGetBundle(),
kMyNibFile,
&nib
);
if (result == noErr)
{
WindowRef nibWindow = NULL;
result = CreateWindowFromNib (
nib,
kMyNibWindow,
&nibWindow
);
if (result == noErr)
{
result = MyEmbedCustomControls (
context->customContext,
nibWindow,
context->userPane
);
if (result == noErr)
{
context->initialized = TRUE;
}
DisposeWindow (nibWindow);
}
DisposeNibReference (nib);
}
}
if (context->initialized)
{
result = MyInstallHelpEventHandler (
GetControlOwner (context->userPane),
&(context->helpHandler),
&(context->helpHandlerUPP)
);
}
MyDebugMessage("MyOpen", result);
return result;
}
/*
--------------------------------------------------------------------------------
MyClose
--------------------------------------------------------------------------------
*/
static OSStatus MyClose (PMPDEContext inContext)
{
MyContext context = (MyContext) inContext;
OSStatus result = noErr;
result = MyRemoveHelpEventHandler (
&(context->helpHandler),
&(context->helpHandlerUPP)
);
MyDebugMessage("MyClose", result);
return result;
}
/*
--------------------------------------------------------------------------------
MyTerminate
--------------------------------------------------------------------------------
*/
static OSStatus MyTerminate (
PMPDEContext inContext,
OSStatus inStatus
)
{
MyContext context = (MyContext) inContext;
OSStatus result = noErr;
if (context != NULL)
{
result = MyRemoveHelpEventHandler (
&(context->helpHandler),
&(context->helpHandlerUPP)
);
if (context->customContext != NULL) {
MyReleaseCustomContext (context->customContext);
}
free (context);
}
MyDebugMessage("MyTerminate", result);
return result;
}
// END OF SOURCE

View File

@@ -0,0 +1,75 @@
/*
********************************************************************************
$Log: not supported by cvs2svn $
(c) Copyright 2002 Apple Computer, Inc. All rights reserved.
IMPORTANT: This Apple software is supplied to you by Apple Computer,
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Computer,
Inc. may be used to endorse or promote products derived from the Apple
Software without specific prior written permission from Apple. Except
as expressly stated in this notice, no other rights or licenses, express
or implied, are granted by Apple herein, including but not limited to
any patent rights that may be infringed by your derivative works or by
other works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES
NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#ifndef __PDECORE__
#define __PDECORE__
#include <Carbon/Carbon.h>
/*
--------------------------------------------------------------------------------
session context
--------------------------------------------------------------------------------
*/
typedef struct
{
ControlRef userPane;
EventHandlerRef helpHandler;
EventHandlerUPP helpHandlerUPP;
void* customContext;
Boolean initialized;
} MyContextBlock;
typedef MyContextBlock* MyContext;
#endif

View File

@@ -0,0 +1,662 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <Carbon/Carbon.h>
#include <Print/PMPrintingDialogExtensions.h>
#include "PDECore.h"
#include "PDECustom.h"
#include "PDEUtilities.h"
// Static Prototypes
static void InitSettings(nsPrintExtensions* settings);
static void SyncPaneFromSettings(MyCustomContext context);
static void SyncSettingsFromPane(MyCustomContext context);
static CFStringRef GetSummaryTextBooleanValue(Boolean value);
static CFStringRef GetSummaryTextNAValue();
/*
--------------------------------------------------------------------------------
MyCreateCustomContext
--------------------------------------------------------------------------------
*/
extern MyCustomContext MyCreateCustomContext()
{
// allocate zeroed storage for a custom context
MyCustomContext context = calloc (1, sizeof (MyCustomContextBlock));
return context;
}
/*
--------------------------------------------------------------------------------
MyReleaseCustomContext
--------------------------------------------------------------------------------
*/
extern void MyReleaseCustomContext (MyCustomContext context)
{
free (context);
}
#pragma mark -
/*
--------------------------------------------------------------------------------
MyGetCustomTitle
--------------------------------------------------------------------------------
*/
/*
In this implementation, we only copy the localized title string once.
We keep a static reference to the copy for re-use.
*/
extern CFStringRef MyGetCustomTitle (Boolean stillNeeded)
{
static CFStringRef sTitle = NULL;
if (stillNeeded)
{
if (sTitle == NULL)
{
// Get the name of the application hosting us.
CFBundleRef appBundle = CFBundleGetMainBundle();
if (appBundle)
{
CFStringRef bundleString = CFBundleGetValueForInfoDictionaryKey(
appBundle, CFSTR("CFBundleName"));
// We don't get an owning reference here, so make a copy.
if (bundleString && (CFGetTypeID(bundleString) == CFStringGetTypeID()))
sTitle = CFStringCreateCopy(NULL, bundleString);
}
}
// If that failed, use a resource - we may be hosted by an unbundled app.
if (sTitle == NULL)
{
sTitle = CFCopyLocalizedStringFromTableInBundle (
CFSTR("Web Browser"),
CFSTR("Localizable"),
MyGetBundle(),
"the custom pane title");
}
}
else
{
if (sTitle != NULL)
{
CFRelease (sTitle);
sTitle = NULL;
}
}
return sTitle;
}
/*
--------------------------------------------------------------------------------
MyEmbedCustomControls
--------------------------------------------------------------------------------
*/
extern OSStatus MyEmbedCustomControls (
MyCustomContext context,
WindowRef nibWindow,
ControlRef userPane
)
{
static const ControlID containerControlID = { kMozPDECreatorCode, 4000 };
static const ControlID radioGroupControlID = { kMozPDECreatorCode, 4001 };
static const ControlID printSelCheckControlID = { kMozPDECreatorCode, 4002 };
static const ControlID shrinkToFitCheckControlID = { kMozPDECreatorCode, 4003 };
static const ControlID printBGColorsCheckControlID = { kMozPDECreatorCode, 4004 };
static const ControlID printBGImagesCheckControlID = { kMozPDECreatorCode, 4005 };
OSStatus result = noErr;
if (context != NULL)
{
ControlHandle paneControl = NULL;
// The control we're embedding into the given
// userPane is itself a user pane control.
result = MyEmbedControl(nibWindow,
userPane,
&containerControlID,
&paneControl);
if (paneControl)
{
WindowRef controlOwner = GetControlOwner(paneControl);
GetControlByID(controlOwner,
&radioGroupControlID,
&(context->controls.frameRadioGroup));
if (context->controls.frameRadioGroup != NULL)
{
// It doesn't seem to be possible to specify the titles of the
// radio buttons within a radio group control, so do it by hand :-/
// This is not done as a loop, but instead using CFSTR("abc") so
// that genstrings can grok this file. Maybe that's not worth it?
CFStringRef radioTitle;
ControlRef radioControl;
if (GetIndexedSubControl(context->controls.frameRadioGroup,
kFramesAsLaidOutIndex, &radioControl) == noErr)
{
radioTitle = CFCopyLocalizedStringFromTableInBundle(
CFSTR("As laid out on the screen"),
CFSTR("Localizable"),
MyGetBundle(),
"top radio title");
if (radioTitle)
{
SetControlTitleWithCFString(radioControl, radioTitle);
CFRelease(radioTitle);
}
}
if (GetIndexedSubControl(context->controls.frameRadioGroup,
kFramesSelectedIndex, &radioControl) == noErr)
{
radioTitle = CFCopyLocalizedStringFromTableInBundle(
CFSTR("The selected frame"),
CFSTR("Localizable"),
MyGetBundle(),
"middle radio title");
if (radioTitle)
{
SetControlTitleWithCFString(radioControl, radioTitle);
CFRelease(radioTitle);
}
}
if (GetIndexedSubControl(context->controls.frameRadioGroup,
kFramesEachSeparatelyIndex, &radioControl) == noErr)
{
radioTitle = CFCopyLocalizedStringFromTableInBundle(
CFSTR("Each frame separately"),
CFSTR("Localizable"),
MyGetBundle(),
"bottom radio title");
if (radioTitle)
{
SetControlTitleWithCFString(radioControl, radioTitle);
CFRelease(radioTitle);
}
}
}
GetControlByID(controlOwner,
&printSelCheckControlID,
&(context->controls.printSelCheck));
GetControlByID(controlOwner,
&shrinkToFitCheckControlID,
&(context->controls.shrinkToFitCheck));
GetControlByID(controlOwner,
&printBGColorsCheckControlID,
&(context->controls.printBGColorsCheck));
GetControlByID(controlOwner,
&printBGImagesCheckControlID,
&(context->controls.printBGImagesCheck));
// Now that the controls are in, sync with data.
SyncPaneFromSettings(context);
}
}
return result;
}
/*
--------------------------------------------------------------------------------
MyGetSummaryText
--------------------------------------------------------------------------------
*/
extern OSStatus MyGetSummaryText (
MyCustomContext context,
CFMutableArrayRef titleArray,
CFMutableArrayRef valueArray
)
{
CFStringRef title = NULL;
CFStringRef value = NULL;
OSStatus result = noErr;
// "Print Frames" Radio Group
title = CFCopyLocalizedStringFromTableInBundle (
CFSTR("Print Frames"),
CFSTR("Localizable"),
MyGetBundle(),
"the Print Frames radio group (for summary)");
if (title != NULL)
{
if (context->settings.mHaveFrames)
{
if (context->settings.mPrintFrameAsIs)
value = CFCopyLocalizedStringFromTableInBundle(
CFSTR("As laid out on the screen"),
CFSTR("Localizable"),
MyGetBundle(),
"Print Frames choice #1 (for summary)");
else if (context->settings.mPrintSelectedFrame)
value = CFCopyLocalizedStringFromTableInBundle(
CFSTR("The selected frame"),
CFSTR("Localizable"),
MyGetBundle(),
"Print Frames choice #2 (for summary)");
else if (context->settings.mPrintFramesSeparately)
value = CFCopyLocalizedStringFromTableInBundle(
CFSTR("Each frame separately"),
CFSTR("Localizable"),
MyGetBundle(),
"Print Frames choice #3 (for summary)");
}
else
value = GetSummaryTextNAValue();
if (value != NULL)
{
// append the title-value pair to the arrays
CFArrayAppendValue (titleArray, title);
CFArrayAppendValue (valueArray, value);
CFRelease (value);
}
CFRelease (title);
}
// Print Selection
title = CFCopyLocalizedStringFromTableInBundle(
CFSTR("Print Selection"),
CFSTR("Localizable"),
MyGetBundle(),
"Print Selection title (for summary)");
if (title != NULL)
{
if (context->settings.mHaveSelection)
value = GetSummaryTextBooleanValue(context->settings.mPrintSelection);
else
value = GetSummaryTextNAValue();
if (value != NULL)
{
// append the title-value pair to the arrays
CFArrayAppendValue (titleArray, title);
CFArrayAppendValue (valueArray, value);
CFRelease (value);
}
CFRelease (title);
}
// Shrink To Fit
title = CFCopyLocalizedStringFromTableInBundle(
CFSTR("Shrink To Fit"),
CFSTR("Localizable"),
MyGetBundle(),
"Shrink To Fit title (for summary)");
if (title != NULL)
{
value = GetSummaryTextBooleanValue(context->settings.mShrinkToFit);
if (value != NULL)
{
// append the title-value pair to the arrays
CFArrayAppendValue (titleArray, title);
CFArrayAppendValue (valueArray, value);
CFRelease (value);
}
CFRelease (title);
}
// Print BG Colors
title = CFCopyLocalizedStringFromTableInBundle(
CFSTR("Print BG Colors"),
CFSTR("Localizable"),
MyGetBundle(),
"Print BG Colors title (for summary)");
if (title != NULL)
{
value = GetSummaryTextBooleanValue(context->settings.mPrintBGColors);
if (value != NULL)
{
// append the title-value pair to the arrays
CFArrayAppendValue (titleArray, title);
CFArrayAppendValue (valueArray, value);
CFRelease (value);
}
CFRelease (title);
}
// Print BG Images
title = CFCopyLocalizedStringFromTableInBundle(
CFSTR("Print BG Images"),
CFSTR("Localizable"),
MyGetBundle(),
"Print BG Images title (for summary)");
if (title != NULL)
{
value = GetSummaryTextBooleanValue(context->settings.mPrintBGImages);
if (value != NULL)
{
// append the title-value pair to the arrays
CFArrayAppendValue (titleArray, title);
CFArrayAppendValue (valueArray, value);
CFRelease (value);
}
CFRelease (title);
}
return result;
}
#pragma mark -
/*
--------------------------------------------------------------------------------
MySyncPaneFromTicket
--------------------------------------------------------------------------------
*/
extern OSStatus MySyncPaneFromTicket (
MyCustomContext context,
PMPrintSession session
)
{
CFDataRef data = NULL;
CFIndex length = 0;
OSStatus result = noErr;
PMTicketRef ticket = NULL;
result = MyGetTicket (session, kPDE_PMPrintSettingsRef, &ticket);
if (result == noErr)
{
// copy ticket data into our settings
result = PMTicketGetCFData (
ticket,
kPMTopLevel,
kPMTopLevel,
kMyAppPrintSettingsKey,
&data
);
if (result == noErr)
{
length = CFDataGetLength (data);
if (length == sizeof(nsPrintExtensions))
{
CFDataGetBytes (
data,
CFRangeMake(0,length),
(UInt8*) &(context->settings)
);
}
else
{ // so below we use the default value for mismatched length
result = kPMKeyNotFound;
}
}
if (result == kPMKeyNotFound)
{
InitSettings(&context->settings);
result = noErr;
}
}
if (result == noErr)
SyncPaneFromSettings(context);
MyDebugMessage("MySyncPane", result);
return result;
}
/*
--------------------------------------------------------------------------------
MySyncTicketFromPane
--------------------------------------------------------------------------------
*/
extern OSStatus MySyncTicketFromPane (
MyCustomContext context,
PMPrintSession session
)
{
CFDataRef data = NULL;
OSStatus result = noErr;
PMTicketRef ticket = NULL;
result = MyGetTicket (session, kPDE_PMPrintSettingsRef, &ticket);
if (result == noErr)
{
// If our pane has never been shown, this will be a noop.
SyncSettingsFromPane(context);
data = CFDataCreate (
kCFAllocatorDefault,
(UInt8*) &context->settings,
sizeof(nsPrintExtensions)
);
if (data != NULL)
{
// update ticket
result = PMTicketSetCFData (
ticket,
kMyBundleIdentifier,
kMyAppPrintSettingsKey,
data,
kPMUnlocked
);
CFRelease (data);
}
}
MyDebugMessage("MySyncTicket", result);
return result;
}
#pragma mark -
/*
--------------------------------------------------------------------------------
Static Routines
--------------------------------------------------------------------------------
*/
static void InitSettings(nsPrintExtensions* settings)
{
settings->mHaveSelection = false;
settings->mHaveFrames = false;
settings->mHaveFrameSelected = false;
settings->mPrintFrameAsIs = false;
settings->mPrintSelectedFrame = false;
settings->mPrintFramesSeparately = false;
settings->mPrintSelection = false;
settings->mShrinkToFit = true;
settings->mPrintBGColors = true;
settings->mPrintBGImages = true;
}
static void SyncPaneFromSettings(MyCustomContext context)
{
if (context->controls.frameRadioGroup)
{
if (context->settings.mHaveFrames)
{
EnableControl(context->controls.frameRadioGroup);
if (context->settings.mPrintSelectedFrame &&
context->settings.mHaveFrameSelected)
SetControlValue(context->controls.frameRadioGroup,
kFramesSelectedIndex);
else if (context->settings.mPrintFramesSeparately)
SetControlValue(context->controls.frameRadioGroup,
kFramesEachSeparatelyIndex);
else /* (context->settings.mPrintFrameAsIs) */
SetControlValue(context->controls.frameRadioGroup,
kFramesAsLaidOutIndex);
if (!context->settings.mHaveFrameSelected)
{
ControlRef radioControl;
if (GetIndexedSubControl(context->controls.frameRadioGroup,
kFramesSelectedIndex, &radioControl) == noErr)
DisableControl(radioControl);
}
}
else
{
DisableControl(context->controls.frameRadioGroup);
SetControlValue(context->controls.frameRadioGroup, 0);
}
}
if (context->controls.printSelCheck)
{
if (context->settings.mHaveSelection)
{
EnableControl(context->controls.printSelCheck);
SetControlValue(context->controls.printSelCheck,
context->settings.mPrintSelection);
}
else
{
DisableControl(context->controls.printSelCheck);
SetControlValue(context->controls.printSelCheck, 0);
}
}
if (context->controls.shrinkToFitCheck)
SetControlValue(context->controls.shrinkToFitCheck,
context->settings.mShrinkToFit);
if (context->controls.printBGColorsCheck)
SetControlValue(context->controls.printBGColorsCheck,
context->settings.mPrintBGColors);
if (context->controls.printBGImagesCheck)
SetControlValue(context->controls.printBGImagesCheck,
context->settings.mPrintBGImages);
}
static void SyncSettingsFromPane(MyCustomContext context)
{
if (context->controls.frameRadioGroup)
{
context->settings.mPrintFrameAsIs = false;
context->settings.mPrintSelectedFrame = false;
context->settings.mPrintFramesSeparately = false;
switch (GetControlValue(context->controls.frameRadioGroup))
{
case kFramesAsLaidOutIndex:
context->settings.mPrintFrameAsIs = true;
break;
case kFramesSelectedIndex:
context->settings.mPrintSelectedFrame = true;
break;
case kFramesEachSeparatelyIndex:
context->settings.mPrintFramesSeparately = true;
break;
}
}
if (context->controls.printSelCheck)
context->settings.mPrintSelection =
GetControlValue(context->controls.printSelCheck);
if (context->controls.printSelCheck)
context->settings.mShrinkToFit =
GetControlValue(context->controls.shrinkToFitCheck);
if (context->controls.printSelCheck)
context->settings.mPrintBGColors =
GetControlValue(context->controls.printBGColorsCheck);
if (context->controls.printSelCheck)
context->settings.mPrintBGImages =
GetControlValue(context->controls.printBGImagesCheck);
}
#pragma mark -
CFStringRef GetSummaryTextBooleanValue(Boolean value)
{
if (value)
return CFCopyLocalizedStringFromTableInBundle(
CFSTR("On"),
CFSTR("Localizable"),
MyGetBundle(),
CFSTR("the value of a checkbox when selected"));
return CFCopyLocalizedStringFromTableInBundle(
CFSTR("Off"),
CFSTR("Localizable"),
MyGetBundle(),
CFSTR("the value of a checkbox when not selected"));
}
static CFStringRef GetSummaryTextNAValue()
{
return CFCopyLocalizedStringFromTableInBundle(
CFSTR("N/A"),
CFSTR("Localizable"),
MyGetBundle(),
"Not Applicable (for summary)");
}
/* END OF SOURCE */

View File

@@ -0,0 +1,212 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __PDECUSTOM__
#define __PDECUSTOM__
#ifndef nsPDECommon_h___
#include "nsPDECommon.h"
#endif
/*
--------------------------------------------------------------------------------
** kMyBundleIdentifier
**
** The identifier that's also used as the CFBundleIdentifier entry in the
** property list. This ID should always be a unique string in Java-style
** package format (substitute your vendor domain for "com.appvendor").
**
--------------------------------------------------------------------------------
*/
#define kMyBundleIdentifier \
CFSTR("org.mozilla.pde." kMozPDESignature)
/*
--------------------------------------------------------------------------------
** kMyPaneKindID
**
** For application-hosted PDEs, this unique Java-style package name is used
** to identify your custom pane. Here we simply use the bundle identifier.
**
** For printer module-hosted PDEs, a unique Java-style package name is
** recommended too, unless you are overriding a standard (Apple-supplied)
** pane -- then you should use the appropriate kind ID constant from
** PMPrintingDialogExtensions.h.
**
--------------------------------------------------------------------------------
*/
#define kMyPaneKindID kMyBundleIdentifier
/*
--------------------------------------------------------------------------------
** kMyNibFile
**
** The name of your nib file (without the ".nib" extension).
**
--------------------------------------------------------------------------------
*/
#define kMyNibFile CFSTR("PrintPDE")
/*
--------------------------------------------------------------------------------
** kMyNibWindow
**
** The name of the Carbon window created from the nib interface.
**
--------------------------------------------------------------------------------
*/
#define kMyNibWindow CFSTR("PrintPDE")
/*
--------------------------------------------------------------------------------
** kMyAppPrintSettingsKey
**
** In order to use the print settings ticket, your application-hosted PDE
** needs to define a ticket data storage and retrieval key by concatenating
** this standard prefix with its unique 4-byte signature.
**
--------------------------------------------------------------------------------
*/
#define kMyAppPrintSettingsKey \
CFSTR("com.apple.print.PrintSettingsTicket." kMozPDESignature)
/*
--------------------------------------------------------------------------------
** kMyAppPageFormatKey
**
** In order to use the page format ticket, your application-hosted PDE
** needs to define a ticket data storage and retrieval key by concatenating
** this standard prefix with its unique 4-byte signature.
**
--------------------------------------------------------------------------------
*/
#define kMyAppPageFormatKey \
CFSTR("com.apple.print.PageFormatTicket." kMozPDESignature)
/*
--------------------------------------------------------------------------------
If you provide user assistance using Help Viewer, define these two
constants. Otherwise, comment them out.
--------------------------------------------------------------------------------
*/
//#define kMyHelpFolder CFSTR("Help")
//#define kMyHelpFile CFSTR("help.html")
/*
--------------------------------------------------------------------------------
vertical and horizontal extent in pixels needed to display your
custom interface
--------------------------------------------------------------------------------
*/
enum {
kMyMaxV = 216,
kMyMaxH = 478
};
/*
--------------------------------------------------------------------------------
Indexes of radio buttons in our radio group control
--------------------------------------------------------------------------------
*/
enum {
kFramesAsLaidOutIndex = 1,
kFramesSelectedIndex,
kFramesEachSeparatelyIndex,
};
/*
--------------------------------------------------------------------------------
data types for a context that represents the state of the controls
in an instance of your custom interface
--------------------------------------------------------------------------------
*/
typedef struct {
ControlRef frameRadioGroup;
ControlRef printSelCheck;
ControlRef shrinkToFitCheck;
ControlRef printBGColorsCheck;
ControlRef printBGImagesCheck;
} MyControls;
typedef nsPrintExtensions MySettings;
typedef struct {
MyControls controls;
MySettings settings;
} MyCustomContextBlock;
typedef MyCustomContextBlock *MyCustomContext;
/*
--------------------------------------------------------------------------------
functions you need to implement in your custom code
--------------------------------------------------------------------------------
*/
/*
Sometime after calling MyGetCustomTitle (TRUE) to get the localized title
of your custom pane, we call MyGetCustomTitle (FALSE) to release the copy.
*/
extern CFStringRef MyGetCustomTitle (Boolean stillNeeded);
extern MyCustomContext MyCreateCustomContext();
extern void MyReleaseCustomContext (MyCustomContext);
extern OSStatus MyEmbedCustomControls (MyCustomContext, WindowRef, ControlRef);
extern OSStatus MyGetSummaryText (MyCustomContext, CFMutableArrayRef, CFMutableArrayRef);
extern OSStatus MySyncPaneFromTicket (MyCustomContext, PMPrintSession);
extern OSStatus MySyncTicketFromPane (MyCustomContext, PMPrintSession);
#endif

View File

@@ -0,0 +1,394 @@
/*
********************************************************************************
$Log: not supported by cvs2svn $
(c) Copyright 2002 Apple Computer, Inc. All rights reserved.
IMPORTANT: This Apple software is supplied to you by Apple Computer,
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Computer,
Inc. may be used to endorse or promote products derived from the Apple
Software without specific prior written permission from Apple. Except
as expressly stated in this notice, no other rights or licenses, express
or implied, are granted by Apple herein, including but not limited to
any patent rights that may be infringed by your derivative works or by
other works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES
NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#include <Carbon/Carbon.h>
#include <Print/PMPrintingDialogExtensions.h>
#include "PDECore.h"
#include "PDECustom.h"
#include "PDEUtilities.h"
// callback function to handle the 'help' event
static OSStatus MyHandleHelpEvent (EventHandlerCallRef, EventRef, void *userData);
/*
--------------------------------------------------------------------------------
MyDebugMessage
--------------------------------------------------------------------------------
*/
extern void MyDebugMessage (char *msg, SInt32 value)
{
char *debug = getenv ("PDEDebug");
if (debug != NULL)
{
fprintf (stdout, "%s (%d)\n", msg, (int) value);
fflush (stdout);
}
}
/*
--------------------------------------------------------------------------------
_MyGetBundle
--------------------------------------------------------------------------------
*/
static CFBundleRef _MyGetBundle (Boolean stillNeeded)
{
static CFBundleRef sBundle = NULL;
if (stillNeeded)
{
if (sBundle == NULL)
{
sBundle = CFBundleGetBundleWithIdentifier (kMyBundleIdentifier);
CFRetain (sBundle);
}
}
else
{
if (sBundle != NULL)
{
CFRelease (sBundle);
sBundle = NULL;
}
}
return sBundle;
}
/*
--------------------------------------------------------------------------------
MyGetBundle
--------------------------------------------------------------------------------
*/
extern CFBundleRef MyGetBundle()
{
return _MyGetBundle (TRUE);
}
/*
--------------------------------------------------------------------------------
MyFreeBundle
--------------------------------------------------------------------------------
*/
extern void MyFreeBundle()
{
_MyGetBundle (FALSE);
}
#pragma mark -
/*
--------------------------------------------------------------------------------
MyGetTitle
--------------------------------------------------------------------------------
*/
extern CFStringRef MyGetTitle()
{
return MyGetCustomTitle (TRUE);
}
/*
--------------------------------------------------------------------------------
MyFreeTitle
--------------------------------------------------------------------------------
*/
extern void MyFreeTitle()
{
MyGetCustomTitle (FALSE);
}
#pragma mark -
/*
--------------------------------------------------------------------------------
MyGetTicket
--------------------------------------------------------------------------------
*/
extern OSStatus MyGetTicket (
PMPrintSession session,
CFStringRef ticketID,
PMTicketRef* ticketPtr
)
{
OSStatus result = noErr;
CFTypeRef type = NULL;
PMTicketRef ticket = NULL;
*ticketPtr = NULL;
result = PMSessionGetDataFromSession (session, ticketID, &type);
if (result == noErr)
{
if (CFNumberGetValue (
(CFNumberRef) type, kCFNumberSInt32Type, (void*) &ticket))
{
*ticketPtr = ticket;
}
else {
result = kPMInvalidValue;
}
}
return result;
}
/*
--------------------------------------------------------------------------------
MyEmbedControl
--------------------------------------------------------------------------------
*/
extern OSStatus MyEmbedControl (
WindowRef nibWindow,
ControlRef userPane,
const ControlID *controlID,
ControlRef* outControl
)
{
ControlRef control = NULL;
OSStatus result = noErr;
*outControl = NULL;
result = GetControlByID (nibWindow, controlID, &control);
if (result == noErr)
{
SInt16 dh, dv;
Rect nibFrame, controlFrame, paneFrame;
(void) GetWindowBounds (nibWindow, kWindowContentRgn, &nibFrame);
(void) GetControlBounds (userPane, &paneFrame);
(void) GetControlBounds (control, &controlFrame);
// find vertical and horizontal deltas needed to position the control
// such that the nib-based interface is centered inside the dialog pane
dh = ((paneFrame.right - paneFrame.left) -
(nibFrame.right - nibFrame.left))/2;
if (dh < 0) dh = 0;
dv = ((paneFrame.bottom - paneFrame.top) -
(nibFrame.bottom - nibFrame.top))/2;
if (dv < 0) dv = 0;
OffsetRect (
&controlFrame,
paneFrame.left + dh,
paneFrame.top + dv
);
(void) SetControlBounds (control, &controlFrame);
// make visible
result = SetControlVisibility (control, TRUE, FALSE);
if (result == noErr)
{
result = EmbedControl (control, userPane);
if (result == noErr)
{
// return the control only if everything worked
*outControl = control;
}
}
}
return result;
}
#pragma mark -
/*
--------------------------------------------------------------------------------
MyReleaseContext
--------------------------------------------------------------------------------
*/
extern void MyReleaseContext (MyContext context)
{
if (context != NULL)
{
if (context->customContext != NULL) {
MyReleaseCustomContext (context->customContext);
}
free (context);
}
}
#pragma mark -
/*
--------------------------------------------------------------------------------
MyInstallHelpEventHandler
--------------------------------------------------------------------------------
*/
#define kMyNumberOfEventTypes 1
extern OSStatus MyInstallHelpEventHandler (
WindowRef inWindow,
EventHandlerRef *outHandler,
EventHandlerUPP *outHandlerUPP
)
{
static const EventTypeSpec sEventTypes [kMyNumberOfEventTypes] =
{
{ kEventClassCommand, kEventCommandProcess }
};
OSStatus result = noErr;
EventHandlerRef handler = NULL;
EventHandlerUPP handlerUPP = NewEventHandlerUPP (MyHandleHelpEvent);
result = InstallWindowEventHandler (
inWindow,
handlerUPP,
kMyNumberOfEventTypes,
sEventTypes,
NULL,
&handler
);
*outHandler = handler;
*outHandlerUPP = handlerUPP;
MyDebugMessage("InstallEventHandler", result);
return result;
}
/*
--------------------------------------------------------------------------------
MyRemoveHelpEventHandler
--------------------------------------------------------------------------------
*/
extern OSStatus MyRemoveHelpEventHandler (
EventHandlerRef *helpHandlerP,
EventHandlerUPP *helpHandlerUPP
)
{
OSStatus result = noErr;
// we remove the help handler if there is still one present
if (*helpHandlerP != NULL)
{
MyDebugMessage("Removing event handler", result);
result = RemoveEventHandler (*helpHandlerP);
*helpHandlerP = NULL;
}
if (*helpHandlerUPP != NULL)
{
DisposeEventHandlerUPP (*helpHandlerUPP);
*helpHandlerUPP = NULL;
}
return result;
}
/*
--------------------------------------------------------------------------------
MyHandleHelpEvent
--------------------------------------------------------------------------------
*/
static OSStatus MyHandleHelpEvent
(
EventHandlerCallRef call,
EventRef event,
void *userData
)
{
HICommand commandStruct;
OSStatus result = eventNotHandledErr;
GetEventParameter (
event, kEventParamDirectObject,
typeHICommand, NULL, sizeof(HICommand),
NULL, &commandStruct
);
if (commandStruct.commandID == 'help')
{
// result = MyDisplayHelp();
// MyDebugMessage("handled help event", result);
}
return result;
}
// END OF SOURCE

View File

@@ -0,0 +1,81 @@
/*
********************************************************************************
$Log: not supported by cvs2svn $
(c) Copyright 2002 Apple Computer, Inc. All rights reserved.
IMPORTANT: This Apple software is supplied to you by Apple Computer,
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Computer,
Inc. may be used to endorse or promote products derived from the Apple
Software without specific prior written permission from Apple. Except
as expressly stated in this notice, no other rights or licenses, express
or implied, are granted by Apple herein, including but not limited to
any patent rights that may be infringed by your derivative works or by
other works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES
NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE
IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
********************************************************************************
*/
#ifndef __PDEUTILITIES__
#define __PDEUTILITIES__
#include <Carbon/Carbon.h>
#include <Print/PMPrintingDialogExtensions.h>
#include "PDECore.h"
/*
--------------------------------------------------------------------------------
Prototypes
--------------------------------------------------------------------------------
*/
extern void MyDebugMessage (char *msg, SInt32 err);
extern CFBundleRef MyGetBundle();
extern void MyFreeBundle();
extern CFStringRef MyGetTitle();
extern void MyFreeTitle();
extern OSStatus MyEmbedControl (WindowRef, ControlRef, const ControlID*, ControlRef*);
extern OSStatus MyGetTicket (PMPrintSession, CFStringRef, PMTicketRef*);
extern void MyReleaseContext (MyContext);
extern OSStatus MyInstallHelpEventHandler (WindowRef, EventHandlerRef*, EventHandlerUPP *);
extern OSStatus MyRemoveHelpEventHandler (EventHandlerRef*, EventHandlerUPP *);
#endif