2
# ***** BEGIN LICENSE BLOCK *****
3
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
# The contents of this file are subject to the Mozilla Public License Version
6
# 1.1 (the "License"); you may not use this file except in compliance with
7
# the License. You may obtain a copy of the License at
8
# http://www.mozilla.org/MPL/
10
# Software distributed under the License is distributed on an "AS IS" basis,
11
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
# for the specific language governing rights and limitations under the
15
# The Original Code is the print preview toolbar.
17
# The Initial Developer of the Original Code is
18
# Netscape Communications Corporation.
19
# Portions created by the Initial Developer are Copyright (C) 2002
20
# the Initial Developer. All Rights Reserved.
23
# Samir Gehani <sgehani@netscape.com> (Original Author)
24
# Rod Spears <rods@netscape.com>
26
# Alternatively, the contents of this file may be used under the terms of
27
# either the GNU General Public License Version 2 or later (the "GPL"), or
28
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29
# in which case the provisions of the GPL or the LGPL are applicable instead
30
# of those above. If you wish to allow use of your version of this file only
31
# under the terms of either the GPL or the LGPL, and not to allow others to
32
# use your version of this file under the terms of the MPL, indicate your
33
# decision by deleting the provisions above and replace them with the notice
34
# and other provisions required by the LGPL or the GPL. If you do not delete
35
# the provisions above, a recipient may use your version of this file under
36
# the terms of any one of the MPL, the GPL or the LGPL.
38
# ***** END LICENSE BLOCK ***** -->
40
# this file depends on printUtils.js
42
<!DOCTYPE window SYSTEM "chrome://global/locale/printPreview.dtd">
44
<bindings id="printPreviewBindings"
45
xmlns="http://www.mozilla.org/xbl"
46
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
48
<binding id="printpreviewtoolbar"
49
extends="chrome://global/content/bindings/toolbar.xml#toolbar">
51
<stylesheet src="chrome://global/skin/printPreview.css"/>
55
<xul:button label="&print.label;" accesskey="&print.accesskey;"
56
oncommand="PrintUtils.print();"/>
58
<xul:button label="&pageSetup.label;" accesskey="&pageSetup.accesskey;"
59
oncommand="this.parentNode.doPageSetup();"/>
61
<xul:vbox align="center" pack="center">
62
<xul:label value="&page.label;"/>
64
<xul:toolbarbutton class="home-arrow"
65
oncommand="parentNode.navigate(0, 0, 'home');"/>
66
<xul:toolbarbutton class="left-arrow"
67
oncommand="parentNode.navigate(-1, 0, 0);"/>
68
<xul:hbox align="center" pack="center">
69
<xul:textbox size="3" value="1" lastvalid="1"
70
onblur="navigate(0, this.value, 0);"
71
onkeypress="if (event.keyCode==13) navigate(0, this.value, 0);"/>
72
<xul:label value="&of.label;"/>
73
<xul:label value="1"/>
75
<xul:toolbarbutton class="right-arrow"
76
oncommand="parentNode.navigate(1, 0, 0);"/>
77
<xul:toolbarbutton class="end-arrow"
78
oncommand="parentNode.navigate(0, 0, 'end');"/>
80
<xul:toolbarseparator class="toolbarseparator-primary"/>
81
<xul:vbox align="center" pack="center">
82
<xul:label value="&scale.label;"/>
85
<xul:hbox align="center" pack="center">
86
<xul:menulist crop="none"
87
oncommand="parentNode.parentNode.scale(this.selectedItem.value);">
89
<xul:menuitem value="0.3" label="&p30.label;"/>
90
<xul:menuitem value="0.4" label="&p40.label;"/>
91
<xul:menuitem value="0.5" label="&p50.label;"/>
92
<xul:menuitem value="0.6" label="&p60.label;"/>
93
<xul:menuitem value="0.7" label="&p70.label;"/>
94
<xul:menuitem value="0.8" label="&p80.label;"/>
95
<xul:menuitem value="0.9" label="&p90.label;"/>
96
<xul:menuitem value="1" label="&p100.label;"/>
97
<xul:menuitem value="1.25" label="&p125.label;"/>
98
<xul:menuitem value="1.5" label="&p150.label;"/>
99
<xul:menuitem value="1.75" label="&p175.label;"/>
100
<xul:menuitem value="2" label="&p200.label;"/>
102
<xul:menuitem flex="1" value="ShrinkToFit"
103
label="&ShrinkToFit.label;"/>
104
<xul:menuitem value="Custom" label="&Custom.label;"/>
109
<xul:toolbarseparator class="toolbarseparator-primary"/>
110
<xul:hbox align="center" pack="center">
111
<xul:toolbarbutton label="&portrait.label;" checked="true"
112
type="radio" group="orient" class="toolbar-portrait-page"
113
oncommand="parentNode.parentNode.orient('portrait');"/>
114
<xul:toolbarbutton label="&landscape.label;"
115
type="radio" group="orient" class="toolbar-landscape-page"
116
oncommand="parentNode.parentNode.orient('landscape');"/>
119
<xul:toolbarseparator class="toolbarseparator-primary"/>
120
<xul:button label="&close.label;" accesskey="&close.accesskey;"
121
oncommand="PrintUtils.exitPrintPreview();"/>
122
<xul:data value="&customPrompt.title;"/>
126
<field name="mPrintButton">
127
document.getAnonymousNodes(this)[0]
129
<field name="mPageTextBox">
130
document.getAnonymousNodes(this)[5].childNodes[0]
132
<field name="mTotalPages">
133
document.getAnonymousNodes(this)[5].childNodes[2]
135
<field name="mScaleLabel">
136
document.getAnonymousNodes(this)[9].firstChild
138
<field name="mScaleCombobox">
139
document.getAnonymousNodes(this)[10].firstChild
141
<field name="mOrientButtonsBox">
142
document.getAnonymousNodes(this)[12]
144
<field name="mPortaitButton">
145
this.mOrientButtonsBox.childNodes[0]
147
<field name="mLandscapeButton">
148
this.mOrientButtonsBox.childNodes[1]
150
<field name="mCustomTitle">
151
document.getAnonymousNodes(this)[15].firstChild
153
<field name="mPrintPreviewObs">
155
<field name="mWebProgress">
160
var print = PrintUtils.getWebBrowserPrint();
161
this.mTotalPages.value = print.printPreviewNumPages;
163
this.updateToolbar();
165
// Hide the ``Print...'' button when the underlying gfx code does not
166
// support multiple devicecontext to be used concurrently
167
// (e.g. printing and printpreview at the same time; required as
168
// legacy support for unices.'s PostScript module (Xprint
169
// on unices.does not have problems with that))
170
// XXX the scaling widgets, and the orientation widgets on unices.
174
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
175
canPrint = prefs.getBoolPref("print.whileInPrintPreview");
178
// Ask the printerfeatures database if this printer device
179
// supports multiple device instances which can be used
181
var smdci = prefs.getBoolPref("print.tmp.printerfeatures." +
182
print.currentPrintSettings.printerName +
183
".can_use_multiple_devicecontexts_concurrently");
185
// We can print from print preview when we can use multiple
186
// devicecontext instances in parallel (regardless what
187
// "print.whileInPrintPreview" may say here...)
199
this.mPrintButton.setAttribute("hidden", "true");
201
// hide page setup button
202
document.getAnonymousNodes(this)[1].setAttribute("hidden", "true");
204
// hide scale widgets (indices: 8, 9, 10, 11)
205
// hide orient widgets (indices: 12, 13)
206
for (var i = 8; i <= 13; ++i)
208
document.getAnonymousNodes(this)[i].setAttribute("hidden", "true");
214
<method name="doPageSetup">
217
var didOK = PrintUtils.showPageSetup();
219
// the changes that effect the UI
220
this.updateToolbar();
222
// Now do PrintPreview
223
PrintUtils.printPreview();
229
<method name="navigate">
230
<parameter name="aDirection"/>
231
<parameter name="aPageNum"/>
232
<parameter name="aHomeOrEnd"/>
235
var print = PrintUtils.getWebBrowserPrint();
236
var validInput = false;
239
// we use only one of aHomeOrEnd, aDirection, or aPageNum
243
if (aHomeOrEnd == "home")
245
homeOrEnd = print.PRINTPREVIEW_HOME;
246
this.mPageTextBox.value = 1;
250
homeOrEnd = print.PRINTPREVIEW_END;
251
this.mPageTextBox.value = print.printPreviewNumPages;
254
print.printPreviewNavigate(homeOrEnd, 0);
259
var textBoxStr = this.mPageTextBox.value;
260
var newPageNum = parseInt(textBoxStr) + aDirection;
261
total = print.printPreviewNumPages;
263
// bounds check potentially user-entered number
264
if (newPageNum > 0 && newPageNum <= total)
266
this.mPageTextBox.value = newPageNum;
267
print.printPreviewNavigate(
268
print.PRINTPREVIEW_GOTO_PAGENUM, newPageNum);
274
total = print.printPreviewNumPages;
276
// bounds check potentially user-entered number
277
if (aPageNum > 0 && aPageNum <= total)
279
print.printPreviewNavigate(
280
print.PRINTPREVIEW_GOTO_PAGENUM, aPageNum);
287
// store the valid page number for future use to replace
288
// the textbox value if erroneous input made it in
289
this.mPageTextBox.setAttribute(
290
"lastvalid", this.mPageTextBox.value);
294
// restore last known valid value in place of erroneous input
295
this.mPageTextBox.value =
296
this.mPageTextBox.getAttribute("lastvalid");
302
<method name="promptForScaleValue">
303
<parameter name="aValue"/>
306
var value = Math.round(aValue);
307
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
308
var promptStr = this.mScaleLabel.value;
309
var renameTitle = this.mCustomTitle;
310
var result = {value:value};
311
var confirmed = promptService.prompt(window, renameTitle, promptStr, result, null, {value:value});
312
if (!confirmed || (!result.value) || (result.value == "") || result.value == value) {
320
<method name="setScaleCombobox">
321
<parameter name="aValue"/>
324
var scaleValues = [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.25, 1.5, 1.75, 2];
326
aValue = new Number(aValue);
329
for (var i=0;i<scaleValues.length;i++) {
330
if (aValue == scaleValues[i]) {
331
this.mScaleCombobox.selectedIndex = i;
335
this.mScaleCombobox.value = "Custom";
340
<method name="scale">
341
<parameter name="aValue"/>
344
var print = PrintUtils.getWebBrowserPrint();
345
var settings = print.currentPrintSettings;
346
if (aValue == "ShrinkToFit") {
347
if (!settings.shrinkToFit) {
348
settings.shrinkToFit = true;
349
PrintUtils.savePrintSettings(settings);
350
PrintUtils.printPreview();
355
if (aValue == "Custom") {
356
aValue = this.promptForScaleValue(settings.scaling * 100.0);
360
this.mScaleCombobox.selectedIndex = this.mScaleCombobox.getAttribute('lastValidInx');
365
this.setScaleCombobox(aValue);
366
this.mScaleCombobox.setAttribute('lastValidInx', this.mScaleCombobox.selectedIndex);
368
settings.shrinkToFit = false;
369
settings.scaling = aValue;
370
PrintUtils.savePrintSettings(settings);
371
PrintUtils.printPreview();
376
<method name="orient">
377
<parameter name="aOrientation"/>
381
const kIPrintSettings = Components.interfaces.nsIPrintSettings;
382
if (aOrientation == "portrait")
384
this.mPortaitButton.checked = true;
385
this.mLandscapeButton.checked = false;
386
orientValue = kIPrintSettings.kPortraitOrientation;
390
this.mPortaitButton.checked = false;
391
this.mLandscapeButton.checked = true;
392
orientValue = kIPrintSettings.kLandscapeOrientation;
395
var print = PrintUtils.getWebBrowserPrint();
396
var settings = print.currentPrintSettings;
397
settings.orientation = orientValue;
398
PrintUtils.savePrintSettings(settings);
399
PrintUtils.printPreview();
404
<method name="updateToolbar">
407
var print = PrintUtils.getWebBrowserPrint();
408
var settings = print.currentPrintSettings;
410
var isPortrait = settings.orientation == Components.interfaces.nsIPrintSettings.kPortraitOrientation;
412
this.mPortaitButton.checked = isPortrait;
413
this.mLandscapeButton.checked = !isPortrait;
415
if (settings.shrinkToFit) {
416
this.mScaleCombobox.value = "ShrinkToFit";
418
this.setScaleCombobox(settings.scaling);