home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 May / PCWorld_2003-05_cd.bin / Komunik / phoenix / chrome / comm.jar / content / communicator / printPreviewBindings.xml < prev    next >
Encoding:
Extensible Markup Language  |  2002-10-03  |  19.4 KB  |  534 lines

  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. <!DOCTYPE window SYSTEM "chrome://communicator/locale/printPreview.dtd">
  41.  
  42. <bindings id="printPreviewBindings"
  43.    xmlns="http://www.mozilla.org/xbl"
  44.    xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  45.  
  46.   <binding id="printpreviewtoolbar" 
  47.            extends="chrome://global/content/bindings/toolbar.xml#toolbar">
  48.     <resources>
  49.       <stylesheet src="chrome://communicator/skin/printing.css"/>
  50.     </resources>
  51.  
  52.     <content>
  53.       <xul:button label="&print.label;" accesskey="&print.accesskey;"
  54.         oncommand="NSPrint();"/>
  55.  
  56.       <xul:button label="&pageSetup.label;" accesskey="&pageSetup.accesskey;"
  57.         oncommand="doPageSetup();"/>
  58.  
  59.       <xul:vbox align="center" pack="center">
  60.         <xul:label value="&page.label;"/>
  61.       </xul:vbox>
  62.       <xul:toolbarbutton class="toolbarbutton-icon home-arrow"
  63.         oncommand="parentNode.navigate(0, 0, 'home');"/>
  64.       <xul:toolbarbutton class="toolbarbutton-icon last-arrow" 
  65.         oncommand="parentNode.navigate(-1, 0, 0);"/>
  66.       <xul:hbox align="center" pack="center">
  67.         <xul:textbox size="3" value="1" lastvalid="1"
  68.           onblur="navigate(0, this.value, 0);"
  69.           onkeypress="if (event.keyCode==13) navigate(0, this.value, 0);"/>
  70.         <xul:label value="&of.label;"/>
  71.         <xul:label value="1"/>
  72.       </xul:hbox>
  73.       <xul:toolbarbutton class="toolbarbutton-icon next-arrow" 
  74.         oncommand="parentNode.navigate(1, 0, 0);"/>
  75.       <xul:toolbarbutton class="toolbarbutton-icon end-arrow"
  76.         oncommand="parentNode.navigate(0, 0, 'end');"/>
  77.  
  78.       <xul:toolbarseparator class="toolbarseparator-primary"/>
  79.       <xul:vbox align="center" pack="center">
  80.         <xul:label value="&scale.label;"/>
  81.       </xul:vbox>
  82.  
  83.       <xul:hbox align="center" pack="center">
  84.         <xul:menulist crop="none" 
  85.           oncommand="parentNode.parentNode.scale(this.selectedItem.value);">
  86.           <xul:menupopup>
  87.             <xul:menuitem value="0.3" label="&p30.label;"/>
  88.             <xul:menuitem value="0.4" label="&p40.label;"/>
  89.             <xul:menuitem value="0.5" label="&p50.label;"/>
  90.             <xul:menuitem value="0.6" label="&p60.label;"/>
  91.             <xul:menuitem value="0.7" label="&p70.label;"/>
  92.             <xul:menuitem value="0.8" label="&p80.label;"/>
  93.             <xul:menuitem value="0.9" label="&p90.label;"/>
  94.             <xul:menuitem value="1" label="&p100.label;"/>
  95.             <xul:menuitem value="1.25" label="&p125.label;"/>
  96.             <xul:menuitem value="1.5" label="&p150.label;"/>
  97.             <xul:menuitem value="1.75" label="&p175.label;"/>
  98.             <xul:menuitem value="2" label="&p200.label;"/>
  99.             <xul:menuseparator/>
  100.             <xul:menuitem flex="1" value="ShrinkToFit" 
  101.               label="&ShrinkToFit.label;"/>
  102.             <xul:menuitem value="Custom" label="&Custom.label;"/>
  103.           </xul:menupopup>
  104.         </xul:menulist>
  105.       </xul:hbox>
  106.  
  107.       <xul:toolbarseparator class="toolbarseparator-primary"/>
  108.       <xul:vbox align="center" pack="center">
  109.         <xul:hbox align="center" pack="center">
  110.           <xul:toolbarbutton label="&portrait.label;" checked="true"
  111.             type="radio" group="orient" class="toolbar-portrait-page"
  112.             oncommand="parentNode.parentNode.parentNode.orient('portrait');"/>
  113.           <xul:toolbarbutton label="&landscape.label;" 
  114.             type="radio" group="orient" class="toolbar-landscape-page"
  115.             oncommand="parentNode.parentNode.parentNode.orient('landscape');"/>
  116.         </xul:hbox>
  117.       </xul:vbox>
  118.  
  119.       <xul:toolbarseparator/>
  120.       <xul:toolbarseparator class="toolbarseparator-primary"/>
  121.       <xul:button label="&close.label;" accesskey="&close.accesskey;"
  122.         oncommand="BrowserExitPrintPreview();"/>
  123.       <xul:data value="&customPrompt.title;"/>
  124.     </content>
  125.  
  126.     <implementation>
  127.       <field name="mDebug">
  128.         false
  129.       </field>
  130.       <field name="mPrintButton">
  131.         document.getAnonymousNodes(this)[0]
  132.       </field>
  133.       <field name="mPageTextBox">
  134.         document.getAnonymousNodes(this)[5].childNodes[0]
  135.       </field>
  136.       <field name="mTotalPages">
  137.         document.getAnonymousNodes(this)[5].childNodes[2]
  138.       </field>
  139.       <field name="mScaleLabel">
  140.         document.getAnonymousNodes(this)[9].firstChild
  141.       </field>
  142.       <field name="mScaleCombobox">
  143.         document.getAnonymousNodes(this)[10].firstChild
  144.       </field>
  145.       <field name="mOrientButtonsBox">
  146.         document.getAnonymousNodes(this)[12].firstChild
  147.       </field>
  148.       <field name="mPortaitButton">
  149.         this.mOrientButtonsBox.childNodes[0]
  150.       </field>
  151.       <field name="mLandscapeButton">
  152.         this.mOrientButtonsBox.childNodes[1]
  153.       </field>
  154.       <field name="mCustomTitle">
  155.         document.getAnonymousNodes(this)[16].firstChild
  156.       </field>
  157.       <field name="mPrintPreviewObs">
  158.       </field>
  159.       <field name="mWebProgress">
  160.       </field>
  161.      
  162.       <constructor>
  163.       <![CDATA[
  164.         this._debug("constructor");
  165.  
  166.         var print = _getWebBrowserPrint();
  167.         try {
  168.           this.mTotalPages.value = print.printPreviewNumPages;
  169.           _getValuesFromPS();
  170.         } catch(e) {}
  171.  
  172.  
  173.         // XXX TEMPORARY
  174.         // XXX Until bug 119491 ("Cleanup global vars in PostScript and Xprint
  175.         // modules") is fixed we will hide the ``Print...'' button
  176.         // XXX the scaling widgets, and the orientation widgets on unices.
  177.         var canPrint = true;
  178.         try
  179.         {
  180.           var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  181.           canPrint = prefs.getBoolPref("print.whileInPrintPreview");
  182.         } catch(e) {}
  183.  
  184.         if (!canPrint)
  185.         {
  186.           // hide print button
  187.           this.mPrintButton.setAttribute("hidden", "true");
  188.  
  189.           // hide page setup button
  190.           document.getAnonymousNodes(this)[1].setAttribute("hidden", "true");
  191.  
  192.           // hide scale widgets (indices: 8, 9, 10, 11)
  193.           // hide orient widgets (indices: 12, 13)
  194.           var i;
  195.           for (i = 8; i <= 13; ++i)
  196.           {
  197.             document.getAnonymousNodes(this)[i].setAttribute("hidden", "true");
  198.           }
  199.         }
  200.         // XXX TEMPORARY
  201.       ]]>
  202.       </constructor>
  203.  
  204.       <method name="doPageSetup">
  205.         <body>
  206.         <![CDATA[
  207.           var didOK = NSPrintSetup();
  208.           if (didOK) {
  209.             // the changes that effect the UI
  210.             this._getValuesFromPS();
  211.  
  212.             // Now do PrintPreview
  213.             var print    = this._getWebBrowserPrint();
  214.             var settings = print.currentPrintSettings;
  215.             this.doPrintPreview(print, settings, this.mTotalPages, null);
  216.           }
  217.         ]]>
  218.         </body>
  219.       </method>
  220.  
  221.       <method name="navigate">
  222.         <parameter name="aDirection"/>
  223.         <parameter name="aPageNum"/>
  224.         <parameter name="aHomeOrEnd"/>
  225.         <body>
  226.         <![CDATA[
  227.           this._debug("navigate: " + aDirection + " " + aPageNum + 
  228.                       " " + aHomeOrEnd);
  229.           
  230.           var print = this._getWebBrowserPrint();
  231.           var validInput = false;
  232.  
  233.           // we use only one of aHomeOrEnd, aDirection, or aPageNum
  234.           if (aHomeOrEnd)
  235.           {
  236.             var homeOrEnd;
  237.             if (aHomeOrEnd == "home")
  238.             {
  239.               homeOrEnd = print.PRINTPREVIEW_HOME;
  240.               this.mPageTextBox.value = 1;  
  241.             }
  242.             else
  243.             {
  244.               homeOrEnd = print.PRINTPREVIEW_END;
  245.               this.mPageTextBox.value = print.printPreviewNumPages;
  246.             }
  247.             
  248.             print.printPreviewNavigate(homeOrEnd, 0);
  249.             validInput = true;
  250.           }
  251.           else if (aDirection)
  252.           {
  253.             var textBoxStr  = this.mPageTextBox.value;
  254.             var newPageNum  = parseInt(textBoxStr) + aDirection;
  255.             var total = print.printPreviewNumPages;
  256.  
  257.             // bounds check potentially user-entered number
  258.             if (newPageNum > 0 && newPageNum <= total) 
  259.             {
  260.               this.mPageTextBox.value = newPageNum;
  261.               print.printPreviewNavigate(
  262.                 print.PRINTPREVIEW_GOTO_PAGENUM, newPageNum);
  263.               validInput = true;
  264.             }
  265.           }
  266.           else 
  267.           {
  268.             var total = print.printPreviewNumPages;
  269.  
  270.             // bounds check potentially user-entered number
  271.             if (aPageNum > 0 && aPageNum <= total) 
  272.             {
  273.               print.printPreviewNavigate(
  274.                 print.PRINTPREVIEW_GOTO_PAGENUM, aPageNum);
  275.               validInput = true;
  276.             }
  277.           }
  278.  
  279.           if (validInput)          
  280.           {
  281.             // store the valid page number for future use to replace 
  282.             // the textbox value if erroneous input made it in
  283.             this.mPageTextBox.setAttribute(
  284.               "lastvalid", this.mPageTextBox.value);
  285.           }
  286.           else
  287.           { 
  288.             // restore last known valid value in place of erroneous input
  289.             this.mPageTextBox.value = 
  290.               this.mPageTextBox.getAttribute("lastvalid");
  291.           }
  292.         ]]>
  293.         </body>
  294.       </method>
  295.  
  296.       <method name="promptForScaleValue">
  297.         <parameter name="aValue"/>
  298.         <body>
  299.         <![CDATA[
  300.           var value = Math.round(aValue);
  301.           var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
  302.           var promptStr = this.mScaleLabel.value;
  303.           var renameTitle = this.mCustomTitle;
  304.           var result = {value:value};
  305.           var confirmed = promptService.prompt(window, renameTitle, promptStr, result, null, {value:value});
  306.           this._debug("confirmed: " + confirmed);
  307.           if (!confirmed || (!result.value) || (result.value == "") || result.value == value) {
  308.             return(-1);
  309.           }
  310.           return result.value;
  311.         ]]>
  312.         </body>
  313.       </method>
  314.  
  315.       <method name="setScaleCombobox">
  316.         <parameter name="aValue"/>
  317.         <body>
  318.         <![CDATA[
  319.           var scaleValues = [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.25, 1.5, 1.75, 2];
  320.  
  321.           aValue = new Number(aValue);
  322.  
  323.           var inx = -1;
  324.           for (var i=0;i<scaleValues.length;i++) {
  325.             if (aValue == scaleValues[i]) {
  326.               this.mScaleCombobox.selectedIndex = i;
  327.               return;
  328.             }
  329.           }
  330.           this.mScaleCombobox.value = "Custom";
  331.         ]]>
  332.         </body>
  333.       </method>
  334.  
  335.       <method name="doPrintPreview">
  336.         <parameter name="aWebBrowserPrint"/>
  337.         <parameter name="aPrintSettings"/>
  338.         <parameter name="aTotalPages"/>
  339.         <parameter name="aScaleCombobox"/>
  340.         <body>
  341.         <![CDATA[
  342.  
  343.           // This observer is called once the progress dialog has been "opened"
  344.           this.mPrintPreviewObs = {
  345.               mDOMWin:null,
  346.               mWebBrowserPrint:null,
  347.               mPrintSettings:null,
  348.               mWebProgress:null,
  349.               mTotalPages:null,
  350.               mScaleCombobox:null,
  351.  
  352.               observe: function(aSubject, aTopic, aData)
  353.               {
  354.                 // First do PrintPreview
  355.                 this.mWebBrowserPrint.printPreview(this.mPrintSettings, this.mDOMWin, this.mWebProgress.value);
  356.  
  357.                 // update total number of pages since this could have changed
  358.                 this.mTotalPages.value = this.mWebBrowserPrint.printPreviewNumPages;
  359.                 if (this.mScaleCombobox) {
  360.                   this.mScaleCombobox.setAttribute('lastValidInx', this.mScaleCombobox.selectedIndex);
  361.                 }
  362.               },
  363.  
  364.               QueryInterface : function(iid)
  365.               {
  366.                if (iid.equals(Components.interfaces.nsIObserver) || iid.equals(Components.interfaces.nsISupportsWeakReference))
  367.                 return this;
  368.      
  369.                throw Components.results.NS_NOINTERFACE;
  370.               }
  371.           };
  372.  
  373.           var ifreq;
  374.           var webBrowserPrint;  
  375.           var domWin;  
  376.           try {
  377.             var ifreq = _content.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
  378.             domWin = ifreq.QueryInterface(Components.interfaces.nsIDOMWindow);
  379.           } catch (e) {
  380.             // Pressing cancel is expressed as an NS_ERROR_ABORT return value,
  381.             // causing an exception to be thrown which we catch here.
  382.             // Unfortunately this will also consume helpful failures, so add a
  383.             //dump(e); // if you need to debug
  384.           }
  385.  
  386.           // Here we get the PrintingPromptService tso we can display the PP Progress from script
  387.           // For the browser implemented via XUL with the PP toolbar we cannot let it be
  388.           // automatically opened from the print engine because the XUL scrollbars in the PP window
  389.           // will layout before the content window and a crash will occur.
  390.           //
  391.           // Doing it all from script, means it lays out before hand and we can let printing do it's own thing
  392.           this.mWebProgress = new Object();
  393.  
  394.           // set up observer's global data for invoking Print Preview
  395.           this.mPrintPreviewObs.mDOMWin          = domWin;
  396.           this.mPrintPreviewObs.mWebBrowserPrint = aWebBrowserPrint;
  397.           this.mPrintPreviewObs.mPrintSettings   = aPrintSettings;
  398.           this.mPrintPreviewObs.mWebProgress     = this.mWebProgress;
  399.           this.mPrintPreviewObs.mTotalPages      = aTotalPages;
  400.           this.mPrintPreviewObs.mScaleCombobox   = aScaleCombobox;
  401.  
  402.           var printPreviewParams    = new Object();
  403.           var notifyOnOpen          = new Object();
  404.           var printingPromptService = Components.classes["@mozilla.org/embedcomp/printingprompt-service;1"]
  405.                                           .getService(Components.interfaces.nsIPrintingPromptService);
  406.           if (printingPromptService) {
  407.             printingPromptService.showProgress(domWin, aWebBrowserPrint, aPrintSettings, 
  408.                                                this.mPrintPreviewObs, false, this.mWebProgress, 
  409.                                                printPreviewParams, notifyOnOpen);
  410.             if (printPreviewParams.value) {
  411.               var webNav = getWebNavigation();
  412.               printPreviewParams.value.docTitle = webNav.document.title;
  413.               printPreviewParams.value.docURL   = webNav.currentURI.spec;
  414.             }
  415.           }
  416.         ]]>
  417.         </body>
  418.       </method>
  419.  
  420.  
  421.       <method name="scale">
  422.         <parameter name="aValue"/>
  423.         <body>
  424.         <![CDATA[
  425.           this._debug("scale: " + aValue);
  426.  
  427.           var print = this._getWebBrowserPrint();
  428.           var settings = print.currentPrintSettings;
  429.           if (aValue == "ShrinkToFit") {
  430.             if (!settings.shrinkToFit) {
  431.               settings.shrinkToFit = true;
  432.               this.doPrintPreview(print, settings, this.mTotalPages, this.mScaleCombobox);
  433.               return;
  434.             } else {
  435.               return;
  436.             }
  437.           }
  438.  
  439.           if (aValue == "Custom") {
  440.             aValue = this.promptForScaleValue(settings.scaling * 100.0);
  441.             this._debug("promptForScaleValue "+aValue);
  442.             if (aValue >= 10) {
  443.               aValue /= 100.0;
  444.             } else {
  445.               this.mScaleCombobox.selectedIndex = this.mScaleCombobox.getAttribute('lastValidInx');
  446.               return;
  447.             }
  448.           }
  449.  
  450.           this.setScaleCombobox(aValue);
  451.           this.mScaleCombobox.setAttribute('lastValidInx', this.mScaleCombobox.selectedIndex);
  452.  
  453.           settings.shrinkToFit = false;
  454.           settings.scaling = aValue;
  455.           this.doPrintPreview(print, settings, this.mTotalPages, null);
  456.         ]]>
  457.         </body>
  458.       </method>
  459.  
  460.       <method name="orient">
  461.         <parameter name="aOrientation"/>
  462.         <body>
  463.         <![CDATA[
  464.           this._debug("orient: " + aOrientation);
  465.  
  466.           var orientValue;
  467.           const kIPrintSettings = Components.interfaces.nsIPrintSettings;
  468.           if (aOrientation == "portrait")
  469.           {
  470.             this.mPortaitButton.checked = true;
  471.             this.mLandscapeButton.checked = false;
  472.             orientValue = kIPrintSettings.kPortraitOrientation;
  473.           } 
  474.           else
  475.           {
  476.             this.mPortaitButton.checked = false;
  477.             this.mLandscapeButton.checked = true;
  478.             orientValue = kIPrintSettings.kLandscapeOrientation;
  479.           }
  480.  
  481.           var print = this._getWebBrowserPrint();
  482.           var settings = print.currentPrintSettings;
  483.           settings.orientation = orientValue;
  484.           this.doPrintPreview(print, settings, this.mTotalPages, null);
  485.         ]]>
  486.         </body>
  487.       </method>
  488.  
  489.       <method name="_getWebBrowserPrint">
  490.         <body>
  491.         <![CDATA[
  492.           var ifreq = _content.QueryInterface(
  493.             Components.interfaces.nsIInterfaceRequestor);
  494.           return ifreq.getInterface(Components.interfaces.nsIWebBrowserPrint);
  495.         ]]>
  496.         </body>
  497.       </method>
  498.  
  499.       <method name="_getValuesFromPS">
  500.         <body>
  501.         <![CDATA[
  502.           var print = this._getWebBrowserPrint();
  503.           var settings = print.currentPrintSettings;
  504.  
  505.           var isPortrait = settings.orientation == Components.interfaces.nsIPrintSettings.kPortraitOrientation;
  506.  
  507.           this.mPortaitButton.checked = isPortrait;
  508.           this.mLandscapeButton.checked = !isPortrait;
  509.  
  510.           if (settings.shrinkToFit) {
  511.             this._debug("setting ShrinkToFit");
  512.             this.mScaleCombobox.value = "ShrinkToFit";
  513.           } else {
  514.             this.setScaleCombobox(settings.scaling);
  515.           }
  516.  
  517.         ]]>
  518.         </body>
  519.       </method>
  520.  
  521.       <method name="_debug">
  522.         <parameter name="aMsg"/>
  523.         <body>
  524.         <![CDATA[
  525.           if (this.mDebug)
  526.             dump("\t *** pptoolbar: " + aMsg + "\n");
  527.         ]]>
  528.         </body>
  529.       </method>
  530.     </implementation>
  531.   </binding>
  532.  
  533. </bindings>
  534.