~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/toolkit/components/printing/content/printPreviewBindings.xml

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0"?>
 
2
# ***** BEGIN LICENSE BLOCK *****
 
3
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
4
#
 
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/
 
9
#
 
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
 
13
# License.
 
14
#
 
15
# The Original Code is the print preview toolbar.
 
16
#
 
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.
 
21
#
 
22
# Contributor(s):
 
23
#  Samir Gehani <sgehani@netscape.com> (Original Author)
 
24
#  Rod Spears <rods@netscape.com> 
 
25
#
 
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.
 
37
#
 
38
# ***** END LICENSE BLOCK ***** -->
 
39
 
 
40
# this file depends on printUtils.js
 
41
 
 
42
<!DOCTYPE window SYSTEM "chrome://global/locale/printPreview.dtd">
 
43
 
 
44
<bindings id="printPreviewBindings"
 
45
   xmlns="http://www.mozilla.org/xbl"
 
46
   xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
47
 
 
48
  <binding id="printpreviewtoolbar" 
 
49
           extends="chrome://global/content/bindings/toolbar.xml#toolbar">
 
50
    <resources>
 
51
      <stylesheet src="chrome://global/skin/printPreview.css"/>
 
52
    </resources>
 
53
 
 
54
    <content>
 
55
      <xul:button label="&print.label;" accesskey="&print.accesskey;"
 
56
        oncommand="PrintUtils.print();"/>
 
57
 
 
58
      <xul:button label="&pageSetup.label;" accesskey="&pageSetup.accesskey;"
 
59
        oncommand="this.parentNode.doPageSetup();"/>
 
60
 
 
61
      <xul:vbox align="center" pack="center">
 
62
        <xul:label value="&page.label;"/>
 
63
      </xul:vbox>
 
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"/>
 
74
      </xul:hbox>
 
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');"/>
 
79
 
 
80
      <xul:toolbarseparator class="toolbarseparator-primary"/>
 
81
      <xul:vbox align="center" pack="center">
 
82
        <xul:label value="&scale.label;"/>
 
83
      </xul:vbox>
 
84
 
 
85
      <xul:hbox align="center" pack="center">
 
86
        <xul:menulist crop="none" 
 
87
          oncommand="parentNode.parentNode.scale(this.selectedItem.value);">
 
88
          <xul:menupopup>
 
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;"/>
 
101
            <xul:menuseparator/>
 
102
            <xul:menuitem flex="1" value="ShrinkToFit" 
 
103
              label="&ShrinkToFit.label;"/>
 
104
            <xul:menuitem value="Custom" label="&Custom.label;"/>
 
105
          </xul:menupopup>
 
106
        </xul:menulist>
 
107
      </xul:hbox>
 
108
 
 
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');"/>
 
117
      </xul:hbox>
 
118
 
 
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;"/>
 
123
    </content>
 
124
 
 
125
    <implementation>
 
126
      <field name="mPrintButton">
 
127
        document.getAnonymousNodes(this)[0]
 
128
      </field>
 
129
      <field name="mPageTextBox">
 
130
        document.getAnonymousNodes(this)[5].childNodes[0]
 
131
      </field>
 
132
      <field name="mTotalPages">
 
133
        document.getAnonymousNodes(this)[5].childNodes[2]
 
134
      </field>
 
135
      <field name="mScaleLabel">
 
136
        document.getAnonymousNodes(this)[9].firstChild
 
137
      </field>
 
138
      <field name="mScaleCombobox">
 
139
        document.getAnonymousNodes(this)[10].firstChild
 
140
      </field>
 
141
      <field name="mOrientButtonsBox">
 
142
        document.getAnonymousNodes(this)[12]
 
143
      </field>
 
144
      <field name="mPortaitButton">
 
145
        this.mOrientButtonsBox.childNodes[0]
 
146
      </field>
 
147
      <field name="mLandscapeButton">
 
148
        this.mOrientButtonsBox.childNodes[1]
 
149
      </field>
 
150
      <field name="mCustomTitle">
 
151
        document.getAnonymousNodes(this)[15].firstChild
 
152
      </field>
 
153
      <field name="mPrintPreviewObs">
 
154
      </field>
 
155
      <field name="mWebProgress">
 
156
      </field>
 
157
     
 
158
      <constructor>
 
159
      <![CDATA[
 
160
        var print = PrintUtils.getWebBrowserPrint();
 
161
        this.mTotalPages.value = print.printPreviewNumPages;
 
162
 
 
163
        this.updateToolbar();
 
164
 
 
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.
 
171
        var canPrint = true;
 
172
        try
 
173
        {
 
174
          var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
 
175
          canPrint = prefs.getBoolPref("print.whileInPrintPreview");
 
176
          if (!canPrint)
 
177
          {           
 
178
            // Ask the printerfeatures database if this printer device 
 
179
            // supports multiple device instances which can be used
 
180
            // concurrently
 
181
            var smdci = prefs.getBoolPref("print.tmp.printerfeatures." + 
 
182
                                          print.currentPrintSettings.printerName +
 
183
                                          ".can_use_multiple_devicecontexts_concurrently");
 
184
 
 
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...)
 
188
            if (smdci)
 
189
            {
 
190
              canPrint = true;
 
191
            }
 
192
          }
 
193
 
 
194
        } catch(e) {}
 
195
 
 
196
        if (!canPrint)
 
197
        {
 
198
          // hide print button
 
199
          this.mPrintButton.setAttribute("hidden", "true");
 
200
 
 
201
          // hide page setup button
 
202
          document.getAnonymousNodes(this)[1].setAttribute("hidden", "true");
 
203
 
 
204
          // hide scale widgets (indices: 8, 9, 10, 11)
 
205
          // hide orient widgets (indices: 12, 13)
 
206
          for (var i = 8; i <= 13; ++i)
 
207
          {
 
208
            document.getAnonymousNodes(this)[i].setAttribute("hidden", "true");
 
209
          }
 
210
        }
 
211
      ]]>
 
212
      </constructor>
 
213
 
 
214
      <method name="doPageSetup">
 
215
        <body>
 
216
        <![CDATA[
 
217
          var didOK = PrintUtils.showPageSetup();
 
218
          if (didOK) {
 
219
            // the changes that effect the UI
 
220
            this.updateToolbar();
 
221
 
 
222
            // Now do PrintPreview
 
223
            PrintUtils.printPreview();
 
224
          }
 
225
        ]]>
 
226
        </body>
 
227
      </method>
 
228
 
 
229
      <method name="navigate">
 
230
        <parameter name="aDirection"/>
 
231
        <parameter name="aPageNum"/>
 
232
        <parameter name="aHomeOrEnd"/>
 
233
        <body>
 
234
        <![CDATA[          
 
235
          var print = PrintUtils.getWebBrowserPrint();
 
236
          var validInput = false;
 
237
          var total;
 
238
 
 
239
          // we use only one of aHomeOrEnd, aDirection, or aPageNum
 
240
          if (aHomeOrEnd)
 
241
          {
 
242
            var homeOrEnd;
 
243
            if (aHomeOrEnd == "home")
 
244
            {
 
245
              homeOrEnd = print.PRINTPREVIEW_HOME;
 
246
              this.mPageTextBox.value = 1;  
 
247
            }
 
248
            else
 
249
            {
 
250
              homeOrEnd = print.PRINTPREVIEW_END;
 
251
              this.mPageTextBox.value = print.printPreviewNumPages;
 
252
            }
 
253
            
 
254
            print.printPreviewNavigate(homeOrEnd, 0);
 
255
            validInput = true;
 
256
          }
 
257
          else if (aDirection)
 
258
          {
 
259
            var textBoxStr  = this.mPageTextBox.value;
 
260
            var newPageNum  = parseInt(textBoxStr) + aDirection;
 
261
            total = print.printPreviewNumPages;
 
262
 
 
263
            // bounds check potentially user-entered number
 
264
            if (newPageNum > 0 && newPageNum <= total) 
 
265
            {
 
266
              this.mPageTextBox.value = newPageNum;
 
267
              print.printPreviewNavigate(
 
268
                print.PRINTPREVIEW_GOTO_PAGENUM, newPageNum);
 
269
              validInput = true;
 
270
            }
 
271
          }
 
272
          else 
 
273
          {
 
274
            total = print.printPreviewNumPages;
 
275
 
 
276
            // bounds check potentially user-entered number
 
277
            if (aPageNum > 0 && aPageNum <= total) 
 
278
            {
 
279
              print.printPreviewNavigate(
 
280
                print.PRINTPREVIEW_GOTO_PAGENUM, aPageNum);
 
281
              validInput = true;
 
282
            }
 
283
          }
 
284
 
 
285
          if (validInput)          
 
286
          {
 
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);
 
291
          }
 
292
          else
 
293
          { 
 
294
            // restore last known valid value in place of erroneous input
 
295
            this.mPageTextBox.value = 
 
296
              this.mPageTextBox.getAttribute("lastvalid");
 
297
          }
 
298
        ]]>
 
299
        </body>
 
300
      </method>
 
301
 
 
302
      <method name="promptForScaleValue">
 
303
        <parameter name="aValue"/>
 
304
        <body>
 
305
        <![CDATA[
 
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) {
 
313
            return(-1);
 
314
          }
 
315
          return result.value;
 
316
        ]]>
 
317
        </body>
 
318
      </method>
 
319
 
 
320
      <method name="setScaleCombobox">
 
321
        <parameter name="aValue"/>
 
322
        <body>
 
323
        <![CDATA[
 
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];
 
325
 
 
326
          aValue = new Number(aValue);
 
327
 
 
328
          var inx = -1;
 
329
          for (var i=0;i<scaleValues.length;i++) {
 
330
            if (aValue == scaleValues[i]) {
 
331
              this.mScaleCombobox.selectedIndex = i;
 
332
              return;
 
333
            }
 
334
          }
 
335
          this.mScaleCombobox.value = "Custom";
 
336
        ]]>
 
337
        </body>
 
338
      </method>
 
339
 
 
340
      <method name="scale">
 
341
        <parameter name="aValue"/>
 
342
        <body>
 
343
        <![CDATA[
 
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();
 
351
            }
 
352
            return;
 
353
          }
 
354
 
 
355
          if (aValue == "Custom") {
 
356
            aValue = this.promptForScaleValue(settings.scaling * 100.0);
 
357
            if (aValue >= 10) {
 
358
              aValue /= 100.0;
 
359
            } else {
 
360
              this.mScaleCombobox.selectedIndex = this.mScaleCombobox.getAttribute('lastValidInx');
 
361
              return;
 
362
            }
 
363
          }
 
364
 
 
365
          this.setScaleCombobox(aValue);
 
366
          this.mScaleCombobox.setAttribute('lastValidInx', this.mScaleCombobox.selectedIndex);
 
367
 
 
368
          settings.shrinkToFit = false;
 
369
          settings.scaling = aValue;
 
370
          PrintUtils.savePrintSettings(settings);
 
371
          PrintUtils.printPreview();
 
372
        ]]>
 
373
        </body>
 
374
      </method>
 
375
 
 
376
      <method name="orient">
 
377
        <parameter name="aOrientation"/>
 
378
        <body>
 
379
        <![CDATA[
 
380
          var orientValue;
 
381
          const kIPrintSettings = Components.interfaces.nsIPrintSettings;
 
382
          if (aOrientation == "portrait")
 
383
          {
 
384
            this.mPortaitButton.checked = true;
 
385
            this.mLandscapeButton.checked = false;
 
386
            orientValue = kIPrintSettings.kPortraitOrientation;
 
387
          } 
 
388
          else
 
389
          {
 
390
            this.mPortaitButton.checked = false;
 
391
            this.mLandscapeButton.checked = true;
 
392
            orientValue = kIPrintSettings.kLandscapeOrientation;
 
393
          }
 
394
 
 
395
          var print = PrintUtils.getWebBrowserPrint();
 
396
          var settings = print.currentPrintSettings;
 
397
          settings.orientation = orientValue;
 
398
          PrintUtils.savePrintSettings(settings);
 
399
          PrintUtils.printPreview();
 
400
        ]]>
 
401
        </body>
 
402
      </method>
 
403
 
 
404
      <method name="updateToolbar">
 
405
        <body>
 
406
        <![CDATA[
 
407
          var print = PrintUtils.getWebBrowserPrint();
 
408
          var settings = print.currentPrintSettings;
 
409
 
 
410
          var isPortrait = settings.orientation == Components.interfaces.nsIPrintSettings.kPortraitOrientation;
 
411
 
 
412
          this.mPortaitButton.checked = isPortrait;
 
413
          this.mLandscapeButton.checked = !isPortrait;
 
414
 
 
415
          if (settings.shrinkToFit) {
 
416
            this.mScaleCombobox.value = "ShrinkToFit";
 
417
          } else {
 
418
            this.setScaleCombobox(settings.scaling);
 
419
          }
 
420
        ]]>
 
421
        </body>
 
422
      </method>
 
423
    </implementation>
 
424
  </binding>
 
425
 
 
426
</bindings>