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