home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 July & August / PCWorld_2005-07-08_cd.bin / komunikace / netscape / nsb-install-8-0.exe / chrome / toolkit.jar / content / global / printPreviewBindings.xml < prev    next >
Extensible Markup Language  |  2004-11-25  |  14KB  |  389 lines

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