Impl print preview for mail and addrbook

Here we are moving the printing JS code into its own file called printing.js
Bug 158110 r=bienvenu sr=sspitzer
This commit is contained in:
rods%netscape.com 2002-10-03 11:04:57 +00:00
Родитель df510b6c24
Коммит 1a7d18fde3
9 изменённых файлов: 167 добавлений и 119 удалений

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

@ -41,7 +41,6 @@
const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
var gPrintSettingsAreGlobal = true;
var gSavePrintSettings = true;
var gPrintSettings = null;
var gChromeState = null; // chrome state before we went into print preview
var gOldCloseHandler = null; // close handler before we went into print preview
var gInPrintPreviewMode = false;
@ -175,37 +174,6 @@ function BrowserExitPrintPreview()
mainWin.setAttribute("onclose", gOldCloseHandler);
}
function GetPrintSettings()
{
var prevPS = gPrintSettings;
try {
if (gPrintSettings == null) {
var pref = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
if (pref) {
gPrintSettingsAreGlobal = pref.getBoolPref("print.use_global_printsettings", false);
gSavePrintSettings = pref.getBoolPref("print.save_print_settings", false);
}
var psService = Components.classes["@mozilla.org/gfx/printsettings-service;1"]
.getService(Components.interfaces.nsIPrintSettingsService);
if (gPrintSettingsAreGlobal) {
gPrintSettings = psService.globalPrintSettings;
if (gSavePrintSettings) {
psService.initPrintSettingsFromPrefs(gPrintSettings, false, gPrintSettings.kInitSaveNativeData);
}
} else {
gPrintSettings = psService.newPrintSettings;
}
}
} catch (e) {
dump("GetPrintSettings "+e);
}
return gPrintSettings;
}
// This observer is called once the progress dialog has been "opened"
var gPrintPreviewObs = {
observe: function(aSubject, aTopic, aData)
@ -311,50 +279,6 @@ function FinishPrintPreview()
}
function BrowserPrintSetup()
{
var didOK = false;
try {
var ifreq = _content.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var webBrowserPrint = ifreq.getInterface(Components.interfaces.nsIWebBrowserPrint);
if (webBrowserPrint) {
gPrintSettings = GetPrintSettings();
}
didOK = goPageSetup(window, gPrintSettings); // from utilityOverlay.js
if (didOK) { // from utilityOverlay.js
if (webBrowserPrint) {
if (gPrintSettingsAreGlobal && gSavePrintSettings) {
var psService = Components.classes["@mozilla.org/gfx/printsettings-service;1"]
.getService(Components.interfaces.nsIPrintSettingsService);
psService.savePrintSettingsToPrefs(gPrintSettings, false, gPrintSettings.kInitSaveNativeData);
}
}
}
} catch (e) {
dump("BrowserPrintSetup "+e);
}
return didOK;
}
function BrowserPrint()
{
try {
var ifreq = _content.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var webBrowserPrint = ifreq.getInterface(Components.interfaces.nsIWebBrowserPrint);
if (webBrowserPrint) {
gPrintSettings = GetPrintSettings();
webBrowserPrint.print(gPrintSettings, null);
}
} catch (e) {
// Pressing cancel is expressed as an NS_ERROR_ABORT return value,
// causing an exception to be thrown which we catch here.
// Unfortunately this will also consume helpful failures, so add a
// dump(e); // if you need to debug
}
}
function BrowserSetDefaultCharacterSet(aCharset)
{
// no longer needed; set when setting Force; see bug 79608

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

@ -71,6 +71,7 @@ Contributor(s):
<script type="application/x-javascript" src="chrome://communicator/content/contentAreaClick.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/contentAreaDD.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/findUtils.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/printing.js"/>
<!-- Shared Bookmarks Utility Library -->
<script type="application/x-javascript" src="chrome://communicator/content/bookmarks/bookmarksOverlay.js"/>
@ -210,11 +211,11 @@ Contributor(s):
<toolbarbutton id="print-button" type="menu-button" class="toolbarbutton-1"
label="&printButton.label;" persist="hidden"
oncommand="if (event.target==this) BrowserPrint();"
oncommand="if (event.target==this) NSPrint();"
tooltiptext="&printButton.tooltip;">
<menupopup id="printMenu">
<menuitem id="printMenuItemToolbar" label="&printCmd.label;" accesskey="&printCmd.accesskey;"
default="true" oncommand="BrowserPrint()"/>
default="true" oncommand="NSPrint()"/>
<menuitem label="&printPreviewCmd.label;" accesskey="&printPreviewCmd.accesskey;"
oncommand="setTimeout(BrowserPrintPreview, 0);"/>
</menupopup>

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

@ -118,8 +118,8 @@
<command id="Browser:SavePage" oncommand="saveDocument(window._content.document);"/>
<command id="Browser:EditPage" oncommand="editPageOrFrame();" observes="isImage"/>
<command id="Browser:Open" oncommand="BrowserOpenWindow();"/>
<command id="Browser:PrintSetup" oncommand="BrowserPrintSetup();"/>
<command id="Browser:Print" oncommand="BrowserPrint();"/>
<command id="Browser:PrintSetup" oncommand="NSPrintSetup();"/>
<command id="Browser:Print" oncommand="NSPrint();"/>
<command id="Browser:PrintPreview" oncommand="BrowserPrintPreview();"/>
<command id="cmd_quit"/>
<command id="cmd_close" oncommand="BrowserCloseTabOrWindow()"/>

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

@ -55,6 +55,7 @@
<script type="application/x-javascript" src="chrome://global/content/nsTransferable.js"/>
<script type="application/x-javascript" src="chrome://global/content/nsDragAndDrop.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/contentAreaDD.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/printing.js"/>
<script type="application/x-javascript" src="chrome://navigator/content/browser.js"/>
<script type="application/x-javascript" src="chrome://navigator/content/viewsource.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/findUtils.js"/>
@ -138,9 +139,8 @@
<menuitem key="key_editPage" command="cmd_editPage"
label="&editPageCmd.label;" accesskey="&editPageCmd.accesskey;"/>
<menuseparator/>
<menuitem key="printKb" command="Browser:Print"
label="&printCmd.label;" accesskey="&printCmd.accesskey;"/>
<!-- <menuitem accesskey="&printPreviewCmd.accesskey;" observes="Browser:PrintPreview"/> -->
<menuitem label="&printCmd.label;" accesskey="&printCmd.accesskey;" key="printKb" command="Browser:Print"/>
<menuitem id="printPreviewMenuItem" label="&printPreviewCmd.label;" accesskey="&printPreviewCmd.accesskey;" command="Browser:PrintPreview"/>
</menupopup>
</menu>

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

@ -29,6 +29,7 @@ comm.jar:
content/communicator/printPageSetup.js (resources/content/printPageSetup.js)
content/communicator/printPageSetup.xul (resources/content/printPageSetup.xul)
content/communicator/printPreviewBindings.xml (resources/content/printPreviewBindings.xml)
content/communicator/printing.js (resources/content/printing.js)
content/communicator/plugins.html (resources/content/plugins.html)
en-US.jar:

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

@ -51,7 +51,7 @@
<content>
<xul:button label="&print.label;" accesskey="&print.accesskey;"
oncommand="BrowserPrint();"/>
oncommand="NSPrint();"/>
<xul:button label="&pageSetup.label;" accesskey="&pageSetup.accesskey;"
oncommand="doPageSetup();"/>
@ -164,9 +164,11 @@
this._debug("constructor");
var print = _getWebBrowserPrint();
this.mTotalPages.value = print.printPreviewNumPages;
try {
this.mTotalPages.value = print.printPreviewNumPages;
_getValuesFromPS();
} catch(e) {}
_getValuesFromPS();
// XXX TEMPORARY
// XXX Until bug 119491 ("Cleanup global vars in PostScript and Xprint
@ -202,7 +204,7 @@
<method name="doPageSetup">
<body>
<![CDATA[
var didOK = BrowserPrintSetup();
var didOK = NSPrintSetup();
if (didOK) {
// the changes that effect the UI
this._getValuesFromPS();

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

@ -0,0 +1,138 @@
/* -*- Mode: Java; 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):
* Blake Ross <blakeross@telocity.com>
* Peter Annema <disttsc@bart.nl>
* Samir Gehani <sgehani@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 ***** */
var gPrintSettings = null;
function GetPrintSettings()
{
var prevPS = gPrintSettings;
try {
if (gPrintSettings == null) {
var pref = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
if (pref) {
gPrintSettingsAreGlobal = pref.getBoolPref("print.use_global_printsettings", false);
gSavePrintSettings = pref.getBoolPref("print.save_print_settings", false);
}
var psService = Components.classes["@mozilla.org/gfx/printsettings-service;1"]
.getService(Components.interfaces.nsIPrintSettingsService);
if (gPrintSettingsAreGlobal) {
gPrintSettings = psService.globalPrintSettings;
if (gSavePrintSettings) {
psService.initPrintSettingsFromPrefs(gPrintSettings, false, gPrintSettings.kInitSaveNativeData);
}
} else {
gPrintSettings = psService.newPrintSettings;
}
}
} catch (e) {
dump("GetPrintSettings "+e);
}
return gPrintSettings;
}
function goPageSetup(domwin, printSettings)
{
try {
if (printSettings == null) {
dump("***************** PrintSettings arg is null!");
return false;
}
// This code calls the printoptions service to bring up the printoptions
// dialog. This will be an xp dialog if the platform did not override
// the ShowPrintSetupDialog method.
var printingPromptService = Components.classes["@mozilla.org/embedcomp/printingprompt-service;1"]
.getService(Components.interfaces.nsIPrintingPromptService);
printingPromptService.showPageSetup(domwin, printSettings, null);
return true;
} catch(e) {
return false;
}
return true;
}
function NSPrintSetup()
{
var didOK = false;
try {
gPrintSettings = GetPrintSettings();
var webBrowserPrint = null;
if (_content) {
var ifreq = _content.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
webBrowserPrint = ifreq.getInterface(Components.interfaces.nsIWebBrowserPrint);
}
didOK = goPageSetup(window, gPrintSettings); // from printing.js
if (didOK) {
if (webBrowserPrint) {
if (gPrintSettingsAreGlobal && gSavePrintSettings) {
var psService = Components.classes["@mozilla.org/gfx/printsettings-service;1"]
.getService(Components.interfaces.nsIPrintSettingsService);
psService.savePrintSettingsToPrefs(gPrintSettings, false, gPrintSettings.kInitSaveNativeData);
}
}
}
} catch (e) {
dump("BrowserPrintSetup "+e);
}
return didOK;
}
function NSPrint()
{
try {
var ifreq = _content.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var webBrowserPrint = ifreq.getInterface(Components.interfaces.nsIWebBrowserPrint);
if (webBrowserPrint) {
gPrintSettings = GetPrintSettings();
webBrowserPrint.print(gPrintSettings, null);
}
} catch (e) {
// Pressing cancel is expressed as an NS_ERROR_ABORT return value,
// causing an exception to be thrown which we catch here.
// Unfortunately this will also consume helpful failures, so add a
// dump(e); // if you need to debug
}
}

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

@ -128,26 +128,6 @@ function getBrowserURL() {
return "chrome://navigator/content/navigator.xul";
}
function goPageSetup(domwin, printSettings)
{
try {
if (printSettings == null) {
alert("PrintSettings arg is null!");
}
// This code calls the printoptions service to bring up the printoptions
// dialog. This will be an xp dialog if the platform did not override
// the ShowPrintSetupDialog method.
var printingPromptService = Components.classes["@mozilla.org/embedcomp/printingprompt-service;1"]
.getService(Components.interfaces.nsIPrintingPromptService);
printingPromptService.showPageSetup(domwin, printSettings, null);
return true;
} catch(e) {
return false;
}
return true;
}
function goPreferences(containerID, paneURL, itemID)
{
var resizable;

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

@ -37,6 +37,7 @@ var targetFile;
var docTitle = "";
var docURL = "";
var progressParams = null;
var switchUI = true;
function elipseString(aStr, doFront)
{
@ -83,13 +84,25 @@ var progressListener = {
var percentPrint = getString( "progressText" );
percentPrint = replaceInsert( percentPrint, 1, 100 );
dialog.progressText.setAttribute("value", percentPrint);
window.close();
}
},
onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress)
{
if (switchUI)
{
dialog.tempLabel.setAttribute("hidden", "true");
dialog.progress.setAttribute("hidden", "false");
dialog.cancel.setAttribute("disabled", "false");
var progressLabel = getString("progress");
if (progressLabel == "") {
progressLabel = "Progress:"; // better than nothing
}
switchUI = false;
}
if (progressParams)
{
var docTitleStr = elipseString(progressParams.docTitle, false);
@ -243,7 +256,6 @@ function onLoad() {
// set our web progress listener on the helper app launcher
printProgress.registerListener(progressListener);
moveToAlertPosition();
//We need to delay the set title else dom will overwrite it
window.setTimeout(doneIniting, 500);
}
@ -278,15 +290,5 @@ function onCancel ()
function doneIniting()
{
dialog.tempLabel.setAttribute("hidden", "true");
dialog.progress.setAttribute("hidden", "false");
dialog.cancel.setAttribute("disabled", "false");
var progressLabel = getString("progress");
if (progressLabel == "") {
progressLabel = "Progress:"; // better than nothing
}
//dialog.progressLabel.value = progressLabel;
printProgress.doneIniting();
}