home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / xulrunner-1.9.0.14 / chrome / toolkit.jar / content / global / printPreviewBindings.xml < prev    next >
Encoding:
Extensible Markup Language  |  2007-06-13  |  14.2 KB  |  398 lines

  1. <?xml version="1.0"?>
  2.  
  3.  
  4. <!DOCTYPE bindings [
  5. <!ENTITY % printPreviewDTD SYSTEM "chrome://global/locale/printPreview.dtd" >
  6. %printPreviewDTD;
  7. <!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd">
  8. %globalDTD;
  9. ]>
  10.  
  11. <bindings id="printPreviewBindings"
  12.    xmlns="http://www.mozilla.org/xbl"
  13.    xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  14.  
  15.   <binding id="printpreviewtoolbar" 
  16.            extends="chrome://global/content/bindings/toolbar.xml#toolbar">
  17.     <resources>
  18.       <stylesheet src="chrome://global/skin/printPreview.css"/>
  19.     </resources>
  20.  
  21.     <content>
  22.       <xul:button label="&print.label;" accesskey="&print.accesskey;"
  23.         oncommand="PrintUtils.print();" icon="print"/>
  24.  
  25.       <xul:button label="&pageSetup.label;" accesskey="&pageSetup.accesskey;"
  26.         oncommand="this.parentNode.doPageSetup();"/>
  27.  
  28.       <xul:vbox align="center" pack="center">
  29.         <xul:label value="&page.label;" accesskey="&page.accesskey;" control="pageNumber"/>
  30.       </xul:vbox>
  31.       <xul:toolbarbutton class="home-arrow tabbable" chromedir="&locale.dir;"
  32.         oncommand="parentNode.navigate(0, 0, 'home');" tooltiptext="&homearrow.tooltip;"/>
  33.       <xul:toolbarbutton class="left-arrow tabbable" chromedir="&locale.dir;"
  34.         oncommand="parentNode.navigate(-1, 0, 0);" tooltiptext="&leftarrow.tooltip;"/>
  35.       <xul:hbox align="center" pack="center">
  36.         <xul:textbox id="pageNumber" size="3" value="1" lastvalid="1"
  37.           onchange="navigate(0, this.value, 0);"/>
  38.         <xul:label value="&of.label;"/>
  39.         <xul:label value="1"/>
  40.       </xul:hbox>
  41.       <xul:toolbarbutton class="right-arrow tabbable" chromedir="&locale.dir;"
  42.         oncommand="parentNode.navigate(1, 0, 0);" tooltiptext="&rightarrow.tooltip;"/>
  43.       <xul:toolbarbutton class="end-arrow tabbable" chromedir="&locale.dir;"
  44.         oncommand="parentNode.navigate(0, 0, 'end');" tooltiptext="&endarrow.tooltip;"/>
  45.  
  46.       <xul:toolbarseparator class="toolbarseparator-primary"/>
  47.       <xul:vbox align="center" pack="center">
  48.         <xul:label value="&scale.label;" accesskey="&scale.accesskey;" control="scale"/>
  49.       </xul:vbox>
  50.  
  51.       <xul:hbox align="center" pack="center">
  52.         <xul:menulist id="scale" crop="none" 
  53.           oncommand="parentNode.parentNode.scale(this.selectedItem.value);">
  54.           <xul:menupopup>
  55.             <xul:menuitem value="0.3" label="&p30.label;"/>
  56.             <xul:menuitem value="0.4" label="&p40.label;"/>
  57.             <xul:menuitem value="0.5" label="&p50.label;"/>
  58.             <xul:menuitem value="0.6" label="&p60.label;"/>
  59.             <xul:menuitem value="0.7" label="&p70.label;"/>
  60.             <xul:menuitem value="0.8" label="&p80.label;"/>
  61.             <xul:menuitem value="0.9" label="&p90.label;"/>
  62.             <xul:menuitem value="1" label="&p100.label;"/>
  63.             <xul:menuitem value="1.25" label="&p125.label;"/>
  64.             <xul:menuitem value="1.5" label="&p150.label;"/>
  65.             <xul:menuitem value="1.75" label="&p175.label;"/>
  66.             <xul:menuitem value="2" label="&p200.label;"/>
  67.             <xul:menuseparator/>
  68.             <xul:menuitem flex="1" value="ShrinkToFit" 
  69.               label="&ShrinkToFit.label;"/>
  70.             <xul:menuitem value="Custom" label="&Custom.label;"/>
  71.           </xul:menupopup>
  72.         </xul:menulist>
  73.       </xul:hbox>
  74.  
  75.       <xul:toolbarseparator class="toolbarseparator-primary"/>
  76.       <xul:hbox align="center" pack="center">
  77.         <xul:toolbarbutton label="&portrait.label;" checked="true"
  78.           accesskey="&portrait.accesskey;"
  79.           type="radio" group="orient" class="toolbar-portrait-page tabbable"
  80.           oncommand="parentNode.parentNode.orient('portrait');"/>
  81.         <xul:toolbarbutton label="&landscape.label;" 
  82.           accesskey="&landscape.accesskey;"
  83.           type="radio" group="orient" class="toolbar-landscape-page tabbable"
  84.           oncommand="parentNode.parentNode.orient('landscape');"/>
  85.       </xul:hbox>
  86.  
  87.       <xul:toolbarseparator class="toolbarseparator-primary"/>
  88.       <xul:button label="&close.label;" accesskey="&close.accesskey;"
  89.         oncommand="PrintUtils.exitPrintPreview();" icon="close"/>
  90.       <xul:data value="&customPrompt.title;"/>
  91.     </content>
  92.  
  93.     <implementation>
  94.       <field name="mPrintButton">
  95.         document.getAnonymousNodes(this)[0]
  96.       </field>
  97.       <field name="mPageTextBox">
  98.         document.getAnonymousNodes(this)[5].childNodes[0]
  99.       </field>
  100.       <field name="mTotalPages">
  101.         document.getAnonymousNodes(this)[5].childNodes[2]
  102.       </field>
  103.       <field name="mScaleLabel">
  104.         document.getAnonymousNodes(this)[9].firstChild
  105.       </field>
  106.       <field name="mScaleCombobox">
  107.         document.getAnonymousNodes(this)[10].firstChild
  108.       </field>
  109.       <field name="mOrientButtonsBox">
  110.         document.getAnonymousNodes(this)[12]
  111.       </field>
  112.       <field name="mPortaitButton">
  113.         this.mOrientButtonsBox.childNodes[0]
  114.       </field>
  115.       <field name="mLandscapeButton">
  116.         this.mOrientButtonsBox.childNodes[1]
  117.       </field>
  118.       <field name="mCustomTitle">
  119.         document.getAnonymousNodes(this)[15].firstChild
  120.       </field>
  121.       <field name="mPrintPreviewObs">
  122.       </field>
  123.       <field name="mWebProgress">
  124.       </field>
  125.      
  126.       <constructor>
  127.       <![CDATA[
  128.         var print = PrintUtils.getWebBrowserPrint();
  129.         this.mTotalPages.value = print.printPreviewNumPages;
  130.  
  131.         this.updateToolbar();
  132.  
  133.         // Hide the ``Print...'' button when the underlying gfx code does not
  134.         // support multiple devicecontext to be used concurrently
  135.         // (e.g. printing and printpreview at the same time; required as 
  136.         // legacy support for unices.'s PostScript module
  137.         // XXX the scaling widgets, and the orientation widgets on unices.
  138.         var canPrint = true;
  139.         try
  140.         {
  141.           var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  142.           canPrint = prefs.getBoolPref("print.whileInPrintPreview");
  143.           if (!canPrint)
  144.           {           
  145.             // Ask the printerfeatures database if this printer device 
  146.             // supports multiple device instances which can be used
  147.             // concurrently
  148.             var smdci = prefs.getBoolPref("print.tmp.printerfeatures." + 
  149.                                           print.currentPrintSettings.printerName +
  150.                                           ".can_use_multiple_devicecontexts_concurrently");
  151.  
  152.             // We can print from print preview when we can use multiple
  153.             // devicecontext instances in parallel (regardless what
  154.             // "print.whileInPrintPreview" may say here...)
  155.             if (smdci)
  156.             {
  157.               canPrint = true;
  158.             }
  159.           }
  160.  
  161.         } catch(e) {}
  162.  
  163.         if (!canPrint)
  164.         {
  165.           // hide print button
  166.           this.mPrintButton.setAttribute("hidden", "true");
  167.  
  168.           // hide page setup button
  169.           document.getAnonymousNodes(this)[1].setAttribute("hidden", "true");
  170.  
  171.           // hide scale widgets (indices: 8, 9, 10, 11)
  172.           // hide orient widgets (indices: 12, 13)
  173.           for (var i = 8; i <= 13; ++i)
  174.           {
  175.             document.getAnonymousNodes(this)[i].setAttribute("hidden", "true");
  176.           }
  177.         }
  178.       ]]>
  179.       </constructor>
  180.  
  181.       <method name="doPageSetup">
  182.         <body>
  183.         <![CDATA[
  184.           var didOK = PrintUtils.showPageSetup();
  185.           if (didOK) {
  186.             // the changes that effect the UI
  187.             this.updateToolbar();
  188.  
  189.             // Now do PrintPreview
  190.             PrintUtils.printPreview();
  191.           }
  192.         ]]>
  193.         </body>
  194.       </method>
  195.  
  196.       <method name="navigate">
  197.         <parameter name="aDirection"/>
  198.         <parameter name="aPageNum"/>
  199.         <parameter name="aHomeOrEnd"/>
  200.         <body>
  201.         <![CDATA[          
  202.           var print = PrintUtils.getWebBrowserPrint();
  203.           var validInput = false;
  204.           var total;
  205.  
  206.           // we use only one of aHomeOrEnd, aDirection, or aPageNum
  207.           if (aHomeOrEnd)
  208.           {
  209.             var homeOrEnd;
  210.             if (aHomeOrEnd == "home")
  211.             {
  212.               homeOrEnd = print.PRINTPREVIEW_HOME;
  213.               this.mPageTextBox.value = 1;  
  214.             }
  215.             else
  216.             {
  217.               homeOrEnd = print.PRINTPREVIEW_END;
  218.               this.mPageTextBox.value = print.printPreviewNumPages;
  219.             }
  220.             
  221.             print.printPreviewNavigate(homeOrEnd, 0);
  222.             validInput = true;
  223.           }
  224.           else if (aDirection)
  225.           {
  226.             var textBoxStr  = this.mPageTextBox.value;
  227.             var newPageNum  = parseInt(textBoxStr) + aDirection;
  228.             total = print.printPreviewNumPages;
  229.  
  230.             // bounds check potentially user-entered number
  231.             if (newPageNum > 0 && newPageNum <= total) 
  232.             {
  233.               this.mPageTextBox.value = newPageNum;
  234.               print.printPreviewNavigate(
  235.                 print.PRINTPREVIEW_GOTO_PAGENUM, newPageNum);
  236.               validInput = true;
  237.             }
  238.           }
  239.           else 
  240.           {
  241.             total = print.printPreviewNumPages;
  242.  
  243.             // bounds check potentially user-entered number
  244.             if (aPageNum > 0 && aPageNum <= total) 
  245.             {
  246.               print.printPreviewNavigate(
  247.                 print.PRINTPREVIEW_GOTO_PAGENUM, aPageNum);
  248.               validInput = true;
  249.             }
  250.           }
  251.  
  252.           if (validInput)          
  253.           {
  254.             // store the valid page number for future use to replace 
  255.             // the textbox value if erroneous input made it in
  256.             this.mPageTextBox.setAttribute(
  257.               "lastvalid", this.mPageTextBox.value);
  258.           }
  259.           else
  260.           { 
  261.             // restore last known valid value in place of erroneous input
  262.             this.mPageTextBox.value = 
  263.               this.mPageTextBox.getAttribute("lastvalid");
  264.           }
  265.         ]]>
  266.         </body>
  267.       </method>
  268.  
  269.       <method name="promptForScaleValue">
  270.         <parameter name="aValue"/>
  271.         <body>
  272.         <![CDATA[
  273.           var value = Math.round(aValue);
  274.           var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
  275.           var promptStr = this.mScaleLabel.value;
  276.           var renameTitle = this.mCustomTitle;
  277.           var result = {value:value};
  278.           var confirmed = promptService.prompt(window, renameTitle, promptStr, result, null, {value:value});
  279.           if (!confirmed || (!result.value) || (result.value == "") || result.value == value) {
  280.             return(-1);
  281.           }
  282.           return result.value;
  283.         ]]>
  284.         </body>
  285.       </method>
  286.  
  287.       <method name="setScaleCombobox">
  288.         <parameter name="aValue"/>
  289.         <body>
  290.         <![CDATA[
  291.           var scaleValues = [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.25, 1.5, 1.75, 2];
  292.  
  293.           aValue = new Number(aValue);
  294.  
  295.           for (var i = 0; i < scaleValues.length; i++) {
  296.             if (aValue == scaleValues[i]) {
  297.               this.mScaleCombobox.selectedIndex = i;
  298.               return;
  299.             }
  300.           }
  301.           this.mScaleCombobox.value = "Custom";
  302.         ]]>
  303.         </body>
  304.       </method>
  305.  
  306.       <method name="scale">
  307.         <parameter name="aValue"/>
  308.         <body>
  309.         <![CDATA[
  310.           var settings = PrintUtils.getPrintSettings();
  311.           if (aValue == "ShrinkToFit") {
  312.             if (!settings.shrinkToFit) {
  313.               settings.shrinkToFit = true;
  314.               this.savePrintSettings(settings, settings.kInitSaveShrinkToFit | settings.kInitSaveScaling);
  315.               PrintUtils.printPreview();
  316.             }
  317.             return;
  318.           }
  319.  
  320.           if (aValue == "Custom") {
  321.             aValue = this.promptForScaleValue(settings.scaling * 100.0);
  322.             if (aValue >= 10) {
  323.               aValue /= 100.0;
  324.             } else {
  325.               this.mScaleCombobox.selectedIndex = this.mScaleCombobox.getAttribute('lastValidInx');
  326.               return;
  327.             }
  328.           }
  329.  
  330.           this.setScaleCombobox(aValue);
  331.           this.mScaleCombobox.setAttribute('lastValidInx', this.mScaleCombobox.selectedIndex);
  332.  
  333.           if (settings.scaling != aValue)
  334.           {
  335.             settings.shrinkToFit = false;
  336.             settings.scaling = aValue;
  337.             this.savePrintSettings(settings, settings.kInitSaveShrinkToFit | settings.kInitSaveScaling);
  338.             PrintUtils.printPreview();
  339.           }
  340.         ]]>
  341.         </body>
  342.       </method>
  343.  
  344.       <method name="orient">
  345.         <parameter name="aOrientation"/>
  346.         <body>
  347.         <![CDATA[
  348.           const kIPrintSettings = Components.interfaces.nsIPrintSettings;
  349.           var orientValue = (aOrientation == "portrait") ? kIPrintSettings.kPortraitOrientation :
  350.                                                            kIPrintSettings.kLandscapeOrientation;
  351.           var settings = PrintUtils.getPrintSettings();
  352.           if (settings.orientation != orientValue)
  353.           {
  354.             settings.orientation = orientValue;
  355.             this.savePrintSettings(settings, settings.kInitSaveOrientation);
  356.             PrintUtils.printPreview();
  357.           }
  358.         ]]>
  359.         </body>
  360.       </method>
  361.  
  362.       <method name="updateToolbar">
  363.         <body>
  364.         <![CDATA[
  365.           var print = PrintUtils.getWebBrowserPrint();
  366.           var settings = PrintUtils.getPrintSettings();
  367.  
  368.           var isPortrait = settings.orientation == Components.interfaces.nsIPrintSettings.kPortraitOrientation;
  369.  
  370.           this.mPortaitButton.checked = isPortrait;
  371.           this.mLandscapeButton.checked = !isPortrait;
  372.  
  373.           if (settings.shrinkToFit) {
  374.             this.mScaleCombobox.value = "ShrinkToFit";
  375.           } else {
  376.             this.setScaleCombobox(settings.scaling);
  377.           }
  378.  
  379.           this.mTotalPages.value = print.printPreviewNumPages;
  380.           this.mPageTextBox.value = 1;
  381.         ]]>
  382.         </body>
  383.       </method>
  384.  
  385.       <method name="savePrintSettings">
  386.         <parameter name="settings"/>
  387.         <parameter name="flags"/>
  388.         <body><![CDATA[
  389.           var PSSVC = Components.classes["@mozilla.org/gfx/printsettings-service;1"]
  390.                                 .getService(Components.interfaces.nsIPrintSettingsService);
  391.           PSSVC.savePrintSettingsToPrefs(settings, true, flags);
  392.         ]]></body>
  393.       </method>
  394.     </implementation>
  395.   </binding>
  396.  
  397. </bindings>
  398.