home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0"?>
-
-
- <!DOCTYPE window SYSTEM "chrome://global/locale/printPreview.dtd">
-
- <bindings id="printPreviewBindings"
- xmlns="http://www.mozilla.org/xbl"
- xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
-
- <binding id="printpreviewtoolbar"
- extends="chrome://global/content/bindings/toolbar.xml#toolbar">
- <resources>
- <stylesheet src="chrome://global/skin/printPreview.css"/>
- </resources>
-
- <content>
- <xul:button label="&print.label;" accesskey="&print.accesskey;"
- oncommand="PrintUtils.print();"/>
-
- <xul:button label="&pageSetup.label;" accesskey="&pageSetup.accesskey;"
- oncommand="this.parentNode.doPageSetup();"/>
-
- <xul:vbox align="center" pack="center">
- <xul:label value="&page.label;"/>
- </xul:vbox>
- <xul:toolbarbutton class="home-arrow"
- oncommand="parentNode.navigate(0, 0, 'home');"/>
- <xul:toolbarbutton class="left-arrow"
- oncommand="parentNode.navigate(-1, 0, 0);"/>
- <xul:hbox align="center" pack="center">
- <xul:textbox size="3" value="1" lastvalid="1"
- onblur="navigate(0, this.value, 0);"
- onkeypress="if (event.keyCode==13) navigate(0, this.value, 0);"/>
- <xul:label value="&of.label;"/>
- <xul:label value="1"/>
- </xul:hbox>
- <xul:toolbarbutton class="right-arrow"
- oncommand="parentNode.navigate(1, 0, 0);"/>
- <xul:toolbarbutton class="end-arrow"
- oncommand="parentNode.navigate(0, 0, 'end');"/>
-
- <xul:toolbarseparator class="toolbarseparator-primary"/>
- <xul:vbox align="center" pack="center">
- <xul:label value="&scale.label;"/>
- </xul:vbox>
-
- <xul:hbox align="center" pack="center">
- <xul:menulist crop="none"
- oncommand="parentNode.parentNode.scale(this.selectedItem.value);">
- <xul:menupopup>
- <xul:menuitem value="0.3" label="&p30.label;"/>
- <xul:menuitem value="0.4" label="&p40.label;"/>
- <xul:menuitem value="0.5" label="&p50.label;"/>
- <xul:menuitem value="0.6" label="&p60.label;"/>
- <xul:menuitem value="0.7" label="&p70.label;"/>
- <xul:menuitem value="0.8" label="&p80.label;"/>
- <xul:menuitem value="0.9" label="&p90.label;"/>
- <xul:menuitem value="1" label="&p100.label;"/>
- <xul:menuitem value="1.25" label="&p125.label;"/>
- <xul:menuitem value="1.5" label="&p150.label;"/>
- <xul:menuitem value="1.75" label="&p175.label;"/>
- <xul:menuitem value="2" label="&p200.label;"/>
- <xul:menuseparator/>
- <xul:menuitem flex="1" value="ShrinkToFit"
- label="&ShrinkToFit.label;"/>
- <xul:menuitem value="Custom" label="&Custom.label;"/>
- </xul:menupopup>
- </xul:menulist>
- </xul:hbox>
-
- <xul:toolbarseparator class="toolbarseparator-primary"/>
- <xul:hbox align="center" pack="center">
- <xul:toolbarbutton label="&portrait.label;" checked="true"
- type="radio" group="orient" class="toolbar-portrait-page"
- oncommand="parentNode.parentNode.orient('portrait');"/>
- <xul:toolbarbutton label="&landscape.label;"
- type="radio" group="orient" class="toolbar-landscape-page"
- oncommand="parentNode.parentNode.orient('landscape');"/>
- </xul:hbox>
-
- <xul:toolbarseparator class="toolbarseparator-primary"/>
- <xul:button label="&close.label;" accesskey="&close.accesskey;"
- oncommand="PrintUtils.exitPrintPreview();"/>
- <xul:data value="&customPrompt.title;"/>
- </content>
-
- <implementation>
- <field name="mPrintButton">
- document.getAnonymousNodes(this)[0]
- </field>
- <field name="mPageTextBox">
- document.getAnonymousNodes(this)[5].childNodes[0]
- </field>
- <field name="mTotalPages">
- document.getAnonymousNodes(this)[5].childNodes[2]
- </field>
- <field name="mScaleLabel">
- document.getAnonymousNodes(this)[9].firstChild
- </field>
- <field name="mScaleCombobox">
- document.getAnonymousNodes(this)[10].firstChild
- </field>
- <field name="mOrientButtonsBox">
- document.getAnonymousNodes(this)[12]
- </field>
- <field name="mPortaitButton">
- this.mOrientButtonsBox.childNodes[0]
- </field>
- <field name="mLandscapeButton">
- this.mOrientButtonsBox.childNodes[1]
- </field>
- <field name="mCustomTitle">
- document.getAnonymousNodes(this)[15].firstChild
- </field>
- <field name="mPrintPreviewObs">
- </field>
- <field name="mWebProgress">
- </field>
-
- <constructor>
- <![CDATA[
- var print = PrintUtils.getWebBrowserPrint();
- this.mTotalPages.value = print.printPreviewNumPages;
-
- this.updateToolbar();
-
- // Hide the ``Print...'' button when the underlying gfx code does not
- // support multiple devicecontext to be used concurrently
- // (e.g. printing and printpreview at the same time; required as
- // legacy support for unices.'s PostScript module (Xprint
- // on unices.does not have problems with that))
- // XXX the scaling widgets, and the orientation widgets on unices.
- var canPrint = true;
- try
- {
- var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
- canPrint = prefs.getBoolPref("print.whileInPrintPreview");
- if (!canPrint)
- {
- // Ask the printerfeatures database if this printer device
- // supports multiple device instances which can be used
- // concurrently
- var smdci = prefs.getBoolPref("print.tmp.printerfeatures." +
- print.currentPrintSettings.printerName +
- ".can_use_multiple_devicecontexts_concurrently");
-
- // We can print from print preview when we can use multiple
- // devicecontext instances in parallel (regardless what
- // "print.whileInPrintPreview" may say here...)
- if (smdci)
- {
- canPrint = true;
- }
- }
-
- } catch(e) {}
-
- if (!canPrint)
- {
- // hide print button
- this.mPrintButton.setAttribute("hidden", "true");
-
- // hide page setup button
- document.getAnonymousNodes(this)[1].setAttribute("hidden", "true");
-
- // hide scale widgets (indices: 8, 9, 10, 11)
- // hide orient widgets (indices: 12, 13)
- for (var i = 8; i <= 13; ++i)
- {
- document.getAnonymousNodes(this)[i].setAttribute("hidden", "true");
- }
- }
- ]]>
- </constructor>
-
- <method name="doPageSetup">
- <body>
- <![CDATA[
- var didOK = PrintUtils.showPageSetup();
- if (didOK) {
- // the changes that effect the UI
- this.updateToolbar();
-
- // Now do PrintPreview
- PrintUtils.printPreview();
- }
- ]]>
- </body>
- </method>
-
- <method name="navigate">
- <parameter name="aDirection"/>
- <parameter name="aPageNum"/>
- <parameter name="aHomeOrEnd"/>
- <body>
- <![CDATA[
- var print = PrintUtils.getWebBrowserPrint();
- var validInput = false;
- var total;
-
- // we use only one of aHomeOrEnd, aDirection, or aPageNum
- if (aHomeOrEnd)
- {
- var homeOrEnd;
- if (aHomeOrEnd == "home")
- {
- homeOrEnd = print.PRINTPREVIEW_HOME;
- this.mPageTextBox.value = 1;
- }
- else
- {
- homeOrEnd = print.PRINTPREVIEW_END;
- this.mPageTextBox.value = print.printPreviewNumPages;
- }
-
- print.printPreviewNavigate(homeOrEnd, 0);
- validInput = true;
- }
- else if (aDirection)
- {
- var textBoxStr = this.mPageTextBox.value;
- var newPageNum = parseInt(textBoxStr) + aDirection;
- total = print.printPreviewNumPages;
-
- // bounds check potentially user-entered number
- if (newPageNum > 0 && newPageNum <= total)
- {
- this.mPageTextBox.value = newPageNum;
- print.printPreviewNavigate(
- print.PRINTPREVIEW_GOTO_PAGENUM, newPageNum);
- validInput = true;
- }
- }
- else
- {
- total = print.printPreviewNumPages;
-
- // bounds check potentially user-entered number
- if (aPageNum > 0 && aPageNum <= total)
- {
- print.printPreviewNavigate(
- print.PRINTPREVIEW_GOTO_PAGENUM, aPageNum);
- validInput = true;
- }
- }
-
- if (validInput)
- {
- // store the valid page number for future use to replace
- // the textbox value if erroneous input made it in
- this.mPageTextBox.setAttribute(
- "lastvalid", this.mPageTextBox.value);
- }
- else
- {
- // restore last known valid value in place of erroneous input
- this.mPageTextBox.value =
- this.mPageTextBox.getAttribute("lastvalid");
- }
- ]]>
- </body>
- </method>
-
- <method name="promptForScaleValue">
- <parameter name="aValue"/>
- <body>
- <![CDATA[
- var value = Math.round(aValue);
- var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
- var promptStr = this.mScaleLabel.value;
- var renameTitle = this.mCustomTitle;
- var result = {value:value};
- var confirmed = promptService.prompt(window, renameTitle, promptStr, result, null, {value:value});
- if (!confirmed || (!result.value) || (result.value == "") || result.value == value) {
- return(-1);
- }
- return result.value;
- ]]>
- </body>
- </method>
-
- <method name="setScaleCombobox">
- <parameter name="aValue"/>
- <body>
- <![CDATA[
- var scaleValues = [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.25, 1.5, 1.75, 2];
-
- aValue = new Number(aValue);
-
- var inx = -1;
- for (var i=0;i<scaleValues.length;i++) {
- if (aValue == scaleValues[i]) {
- this.mScaleCombobox.selectedIndex = i;
- return;
- }
- }
- this.mScaleCombobox.value = "Custom";
- ]]>
- </body>
- </method>
-
- <method name="scale">
- <parameter name="aValue"/>
- <body>
- <![CDATA[
- var print = PrintUtils.getWebBrowserPrint();
- var settings = print.currentPrintSettings;
- if (aValue == "ShrinkToFit") {
- if (!settings.shrinkToFit) {
- settings.shrinkToFit = true;
- PrintUtils.savePrintSettings(settings);
- PrintUtils.printPreview();
- }
- return;
- }
-
- if (aValue == "Custom") {
- aValue = this.promptForScaleValue(settings.scaling * 100.0);
- if (aValue >= 10) {
- aValue /= 100.0;
- } else {
- this.mScaleCombobox.selectedIndex = this.mScaleCombobox.getAttribute('lastValidInx');
- return;
- }
- }
-
- this.setScaleCombobox(aValue);
- this.mScaleCombobox.setAttribute('lastValidInx', this.mScaleCombobox.selectedIndex);
-
- settings.shrinkToFit = false;
- settings.scaling = aValue;
- PrintUtils.savePrintSettings(settings);
- PrintUtils.printPreview();
- ]]>
- </body>
- </method>
-
- <method name="orient">
- <parameter name="aOrientation"/>
- <body>
- <![CDATA[
- var orientValue;
- const kIPrintSettings = Components.interfaces.nsIPrintSettings;
- if (aOrientation == "portrait")
- {
- this.mPortaitButton.checked = true;
- this.mLandscapeButton.checked = false;
- orientValue = kIPrintSettings.kPortraitOrientation;
- }
- else
- {
- this.mPortaitButton.checked = false;
- this.mLandscapeButton.checked = true;
- orientValue = kIPrintSettings.kLandscapeOrientation;
- }
-
- var print = PrintUtils.getWebBrowserPrint();
- var settings = print.currentPrintSettings;
- settings.orientation = orientValue;
- PrintUtils.savePrintSettings(settings);
- PrintUtils.printPreview();
- ]]>
- </body>
- </method>
-
- <method name="updateToolbar">
- <body>
- <![CDATA[
- var print = PrintUtils.getWebBrowserPrint();
- var settings = print.currentPrintSettings;
-
- var isPortrait = settings.orientation == Components.interfaces.nsIPrintSettings.kPortraitOrientation;
-
- this.mPortaitButton.checked = isPortrait;
- this.mLandscapeButton.checked = !isPortrait;
-
- if (settings.shrinkToFit) {
- this.mScaleCombobox.value = "ShrinkToFit";
- } else {
- this.setScaleCombobox(settings.scaling);
- }
- ]]>
- </body>
- </method>
- </implementation>
- </binding>
-
- </bindings>
-