home *** CD-ROM | disk | FTP | other *** search
/ ftp.swcp.com / ftp.swcp.com.zip / ftp.swcp.com / mac / mozilla-macos9-1.3.1.sea.bin / Mozilla1.3.1 / Chrome / comm.jar / content / communicator / printPreviewBindings.xml < prev    next >
Extensible Markup Language  |  2003-06-08  |  21KB  |  553 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.         // Hide the ``Print...'' button when the underlying gfx code does not
  174.         // support multiple devicecontext to be used concurrently
  175.         // (e.g. printing and printpreview at the same time; required as 
  176.         // legacy support for unices.'s PostScript module (Xprint
  177.         // on unices.does not have problems with that))
  178.         // XXX the scaling widgets, and the orientation widgets on unices.
  179.         var canPrint = true;
  180.         try
  181.         {
  182.           var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  183.           canPrint = prefs.getBoolPref("print.whileInPrintPreview");
  184.           if (!canPrint)
  185.           {           
  186.             // Ask the printerfeatures database if this printer device 
  187.             // supports multiple device instances which can be used
  188.             // concurrently
  189.             var smdci = prefs.getBoolPref("print.tmp.printerfeatures." + 
  190.                                           print.currentPrintSettings.printerName +
  191.                                           ".can_use_multiple_devicecontexts_concurrently");
  192.  
  193.             // We can print from print preview when we can use multiple
  194.             // devicecontext instances in parallel (regardless what
  195.             // "print.whileInPrintPreview" may say here...)
  196.             if (smdci)
  197.             {
  198.               canPrint = true;
  199.             }
  200.           }
  201.  
  202.         } catch(e) {}
  203.  
  204.         if (!canPrint)
  205.         {
  206.           // hide print button
  207.           this.mPrintButton.setAttribute("hidden", "true");
  208.  
  209.           // hide page setup button
  210.           document.getAnonymousNodes(this)[1].setAttribute("hidden", "true");
  211.  
  212.           // hide scale widgets (indices: 8, 9, 10, 11)
  213.           // hide orient widgets (indices: 12, 13)
  214.           var i;
  215.           for (i = 8; i <= 13; ++i)
  216.           {
  217.             document.getAnonymousNodes(this)[i].setAttribute("hidden", "true");
  218.           }
  219.         }
  220.       ]]>
  221.       </constructor>
  222.  
  223.       <method name="doPageSetup">
  224.         <body>
  225.         <![CDATA[
  226.           var didOK = NSPrintSetup();
  227.           if (didOK) {
  228.             // the changes that effect the UI
  229.             this._getValuesFromPS();
  230.  
  231.             // Now do PrintPreview
  232.             var print    = this._getWebBrowserPrint();
  233.             var settings = print.currentPrintSettings;
  234.             this.doPrintPreview(print, settings, this.mTotalPages, null);
  235.           }
  236.         ]]>
  237.         </body>
  238.       </method>
  239.  
  240.       <method name="navigate">
  241.         <parameter name="aDirection"/>
  242.         <parameter name="aPageNum"/>
  243.         <parameter name="aHomeOrEnd"/>
  244.         <body>
  245.         <![CDATA[
  246.           this._debug("navigate: " + aDirection + " " + aPageNum + 
  247.                       " " + aHomeOrEnd);
  248.           
  249.           var print = this._getWebBrowserPrint();
  250.           var validInput = false;
  251.  
  252.           // we use only one of aHomeOrEnd, aDirection, or aPageNum
  253.           if (aHomeOrEnd)
  254.           {
  255.             var homeOrEnd;
  256.             if (aHomeOrEnd == "home")
  257.             {
  258.               homeOrEnd = print.PRINTPREVIEW_HOME;
  259.               this.mPageTextBox.value = 1;  
  260.             }
  261.             else
  262.             {
  263.               homeOrEnd = print.PRINTPREVIEW_END;
  264.               this.mPageTextBox.value = print.printPreviewNumPages;
  265.             }
  266.             
  267.             print.printPreviewNavigate(homeOrEnd, 0);
  268.             validInput = true;
  269.           }
  270.           else if (aDirection)
  271.           {
  272.             var textBoxStr  = this.mPageTextBox.value;
  273.             var newPageNum  = parseInt(textBoxStr) + aDirection;
  274.             var total = print.printPreviewNumPages;
  275.  
  276.             // bounds check potentially user-entered number
  277.             if (newPageNum > 0 && newPageNum <= total) 
  278.             {
  279.               this.mPageTextBox.value = newPageNum;
  280.               print.printPreviewNavigate(
  281.                 print.PRINTPREVIEW_GOTO_PAGENUM, newPageNum);
  282.               validInput = true;
  283.             }
  284.           }
  285.           else 
  286.           {
  287.             var total = print.printPreviewNumPages;
  288.  
  289.             // bounds check potentially user-entered number
  290.             if (aPageNum > 0 && aPageNum <= total) 
  291.             {
  292.               print.printPreviewNavigate(
  293.                 print.PRINTPREVIEW_GOTO_PAGENUM, aPageNum);
  294.               validInput = true;
  295.             }
  296.           }
  297.  
  298.           if (validInput)          
  299.           {
  300.             // store the valid page number for future use to replace 
  301.             // the textbox value if erroneous input made it in
  302.             this.mPageTextBox.setAttribute(
  303.               "lastvalid", this.mPageTextBox.value);
  304.           }
  305.           else
  306.           { 
  307.             // restore last known valid value in place of erroneous input
  308.             this.mPageTextBox.value = 
  309.               this.mPageTextBox.getAttribute("lastvalid");
  310.           }
  311.         ]]>
  312.         </body>
  313.       </method>
  314.  
  315.       <method name="promptForScaleValue">
  316.         <parameter name="aValue"/>
  317.         <body>
  318.         <![CDATA[
  319.           var value = Math.round(aValue);
  320.           var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
  321.           var promptStr = this.mScaleLabel.value;
  322.           var renameTitle = this.mCustomTitle;
  323.           var result = {value:value};
  324.           var confirmed = promptService.prompt(window, renameTitle, promptStr, result, null, {value:value});
  325.           this._debug("confirmed: " + confirmed);
  326.           if (!confirmed || (!result.value) || (result.value == "") || result.value == value) {
  327.             return(-1);
  328.           }
  329.           return result.value;
  330.         ]]>
  331.         </body>
  332.       </method>
  333.  
  334.       <method name="setScaleCombobox">
  335.         <parameter name="aValue"/>
  336.         <body>
  337.         <![CDATA[
  338.           var scaleValues = [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.25, 1.5, 1.75, 2];
  339.  
  340.           aValue = new Number(aValue);
  341.  
  342.           var inx = -1;
  343.           for (var i=0;i<scaleValues.length;i++) {
  344.             if (aValue == scaleValues[i]) {
  345.               this.mScaleCombobox.selectedIndex = i;
  346.               return;
  347.             }
  348.           }
  349.           this.mScaleCombobox.value = "Custom";
  350.         ]]>
  351.         </body>
  352.       </method>
  353.  
  354.       <method name="doPrintPreview">
  355.         <parameter name="aWebBrowserPrint"/>
  356.         <parameter name="aPrintSettings"/>
  357.         <parameter name="aTotalPages"/>
  358.         <parameter name="aScaleCombobox"/>
  359.         <body>
  360.         <![CDATA[
  361.  
  362.           // This observer is called once the progress dialog has been "opened"
  363.           this.mPrintPreviewObs = {
  364.               mDOMWin:null,
  365.               mWebBrowserPrint:null,
  366.               mPrintSettings:null,
  367.               mWebProgress:null,
  368.               mTotalPages:null,
  369.               mScaleCombobox:null,
  370.  
  371.               observe: function(aSubject, aTopic, aData)
  372.               {
  373.                 // First do PrintPreview
  374.                 this.mWebBrowserPrint.printPreview(this.mPrintSettings, this.mDOMWin, this.mWebProgress.value);
  375.  
  376.                 // update total number of pages since this could have changed
  377.                 this.mTotalPages.value = this.mWebBrowserPrint.printPreviewNumPages;
  378.                 if (this.mScaleCombobox) {
  379.                   this.mScaleCombobox.setAttribute('lastValidInx', this.mScaleCombobox.selectedIndex);
  380.                 }
  381.               },
  382.  
  383.               QueryInterface : function(iid)
  384.               {
  385.                if (iid.equals(Components.interfaces.nsIObserver) || iid.equals(Components.interfaces.nsISupportsWeakReference))
  386.                 return this;
  387.      
  388.                throw Components.results.NS_NOINTERFACE;
  389.               }
  390.           };
  391.  
  392.           var ifreq;
  393.           var webBrowserPrint;  
  394.           var domWin;  
  395.           try {
  396.             var ifreq = _content.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
  397.             domWin = ifreq.QueryInterface(Components.interfaces.nsIDOMWindow);
  398.           } catch (e) {
  399.             // Pressing cancel is expressed as an NS_ERROR_ABORT return value,
  400.             // causing an exception to be thrown which we catch here.
  401.             // Unfortunately this will also consume helpful failures, so add a
  402.             //dump(e); // if you need to debug
  403.           }
  404.  
  405.           // Here we get the PrintingPromptService tso we can display the PP Progress from script
  406.           // For the browser implemented via XUL with the PP toolbar we cannot let it be
  407.           // automatically opened from the print engine because the XUL scrollbars in the PP window
  408.           // will layout before the content window and a crash will occur.
  409.           //
  410.           // Doing it all from script, means it lays out before hand and we can let printing do it's own thing
  411.           this.mWebProgress = new Object();
  412.  
  413.           // set up observer's global data for invoking Print Preview
  414.           this.mPrintPreviewObs.mDOMWin          = domWin;
  415.           this.mPrintPreviewObs.mWebBrowserPrint = aWebBrowserPrint;
  416.           this.mPrintPreviewObs.mPrintSettings   = aPrintSettings;
  417.           this.mPrintPreviewObs.mWebProgress     = this.mWebProgress;
  418.           this.mPrintPreviewObs.mTotalPages      = aTotalPages;
  419.           this.mPrintPreviewObs.mScaleCombobox   = aScaleCombobox;
  420.  
  421.           var printPreviewParams    = new Object();
  422.           var notifyOnOpen          = new Object();
  423.           var printingPromptService = Components.classes["@mozilla.org/embedcomp/printingprompt-service;1"]
  424.                                           .getService(Components.interfaces.nsIPrintingPromptService);
  425.           if (printingPromptService) {
  426.             printingPromptService.showProgress(domWin, aWebBrowserPrint, aPrintSettings, 
  427.                                                this.mPrintPreviewObs, false, this.mWebProgress, 
  428.                                                printPreviewParams, notifyOnOpen);
  429.             if (printPreviewParams.value) {
  430.               var webNav = getWebNavigation();
  431.               printPreviewParams.value.docTitle = webNav.document.title;
  432.               printPreviewParams.value.docURL   = webNav.currentURI.spec;
  433.             }
  434.           }
  435.         ]]>
  436.         </body>
  437.       </method>
  438.  
  439.  
  440.       <method name="scale">
  441.         <parameter name="aValue"/>
  442.         <body>
  443.         <![CDATA[
  444.           this._debug("scale: " + aValue);
  445.  
  446.           var print = this._getWebBrowserPrint();
  447.           var settings = print.currentPrintSettings;
  448.           if (aValue == "ShrinkToFit") {
  449.             if (!settings.shrinkToFit) {
  450.               settings.shrinkToFit = true;
  451.               this.doPrintPreview(print, settings, this.mTotalPages, this.mScaleCombobox);
  452.               return;
  453.             } else {
  454.               return;
  455.             }
  456.           }
  457.  
  458.           if (aValue == "Custom") {
  459.             aValue = this.promptForScaleValue(settings.scaling * 100.0);
  460.             this._debug("promptForScaleValue "+aValue);
  461.             if (aValue >= 10) {
  462.               aValue /= 100.0;
  463.             } else {
  464.               this.mScaleCombobox.selectedIndex = this.mScaleCombobox.getAttribute('lastValidInx');
  465.               return;
  466.             }
  467.           }
  468.  
  469.           this.setScaleCombobox(aValue);
  470.           this.mScaleCombobox.setAttribute('lastValidInx', this.mScaleCombobox.selectedIndex);
  471.  
  472.           settings.shrinkToFit = false;
  473.           settings.scaling = aValue;
  474.           this.doPrintPreview(print, settings, this.mTotalPages, null);
  475.         ]]>
  476.         </body>
  477.       </method>
  478.  
  479.       <method name="orient">
  480.         <parameter name="aOrientation"/>
  481.         <body>
  482.         <![CDATA[
  483.           this._debug("orient: " + aOrientation);
  484.  
  485.           var orientValue;
  486.           const kIPrintSettings = Components.interfaces.nsIPrintSettings;
  487.           if (aOrientation == "portrait")
  488.           {
  489.             this.mPortaitButton.checked = true;
  490.             this.mLandscapeButton.checked = false;
  491.             orientValue = kIPrintSettings.kPortraitOrientation;
  492.           } 
  493.           else
  494.           {
  495.             this.mPortaitButton.checked = false;
  496.             this.mLandscapeButton.checked = true;
  497.             orientValue = kIPrintSettings.kLandscapeOrientation;
  498.           }
  499.  
  500.           var print = this._getWebBrowserPrint();
  501.           var settings = print.currentPrintSettings;
  502.           settings.orientation = orientValue;
  503.           this.doPrintPreview(print, settings, this.mTotalPages, null);
  504.         ]]>
  505.         </body>
  506.       </method>
  507.  
  508.       <method name="_getWebBrowserPrint">
  509.         <body>
  510.         <![CDATA[
  511.           var ifreq = _content.QueryInterface(
  512.             Components.interfaces.nsIInterfaceRequestor);
  513.           return ifreq.getInterface(Components.interfaces.nsIWebBrowserPrint);
  514.         ]]>
  515.         </body>
  516.       </method>
  517.  
  518.       <method name="_getValuesFromPS">
  519.         <body>
  520.         <![CDATA[
  521.           var print = this._getWebBrowserPrint();
  522.           var settings = print.currentPrintSettings;
  523.  
  524.           var isPortrait = settings.orientation == Components.interfaces.nsIPrintSettings.kPortraitOrientation;
  525.  
  526.           this.mPortaitButton.checked = isPortrait;
  527.           this.mLandscapeButton.checked = !isPortrait;
  528.  
  529.           if (settings.shrinkToFit) {
  530.             this._debug("setting ShrinkToFit");
  531.             this.mScaleCombobox.value = "ShrinkToFit";
  532.           } else {
  533.             this.setScaleCombobox(settings.scaling);
  534.           }
  535.  
  536.         ]]>
  537.         </body>
  538.       </method>
  539.  
  540.       <method name="_debug">
  541.         <parameter name="aMsg"/>
  542.         <body>
  543.         <![CDATA[
  544.           if (this.mDebug)
  545.             dump("\t *** pptoolbar: " + aMsg + "\n");
  546.         ]]>
  547.         </body>
  548.       </method>
  549.     </implementation>
  550.   </binding>
  551.  
  552. </bindings>
  553.