DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (0ddcbf234291)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
<?xml version="1.0"?>
<!-- ***** BEGIN LICENSE BLOCK *****
   - Version: MPL 1.1/GPL 2.0/LGPL 2.1
   -
   - The contents of this file are subject to the Mozilla Public License Version
   - 1.1 (the "License"); you may not use this file except in compliance with
   - the License. You may obtain a copy of the License at
   - http://www.mozilla.org/MPL/
   -
   - Software distributed under the License is distributed on an "AS IS" basis,
   - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
   - for the specific language governing rights and limitations under the
   - License.
   -
   - The Original Code is the print preview toolbar.
   -
   - The Initial Developer of the Original Code is
   - Netscape Communications Corporation.
   - Portions created by the Initial Developer are Copyright (C) 2002
   - the Initial Developer. All Rights Reserved.
   -
   - Contributor(s):
   -  Samir Gehani <sgehani@netscape.com> (Original Author)
   -  Rod Spears <rods@netscape.com> 
   -
   - Alternatively, the contents of this file may be used under the terms of
   - either the GNU General Public License Version 2 or later (the "GPL"), or
   - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
   - in which case the provisions of the GPL or the LGPL are applicable instead
   - of those above. If you wish to allow use of your version of this file only
   - under the terms of either the GPL or the LGPL, and not to allow others to
   - use your version of this file under the terms of the MPL, indicate your
   - decision by deleting the provisions above and replace them with the notice
   - and other provisions required by the LGPL or the GPL. If you do not delete
   - the provisions above, a recipient may use your version of this file under
   - the terms of any one of the MPL, the GPL or the LGPL.
   -
   - ***** END LICENSE BLOCK ***** -->

<!DOCTYPE bindings SYSTEM "chrome://communicator/locale/printPreview.dtd">

<bindings id="printPreviewBindings"
   xmlns="http://www.mozilla.org/xbl"
   xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <binding id="printpreviewtoolbar" 
           extends="chrome://global/content/bindings/toolbar.xml#toolbar">
    <resources>
      <stylesheet src="chrome://global/skin/printPreview.css"/>
    </resources>

    <content>
      <xul:button label="&print.label;" accesskey="&print.accesskey;"
        oncommand="PrintUtils.print();"/>

      <xul:button label="&pageSetup.label;" accesskey="&pageSetup.accesskey;"
        oncommand="this.parentNode.doPageSetup();"/>

      <xul:vbox align="center" pack="center">
        <xul:label value="&page.label;" accesskey="&page.accesskey;" control="pageNumber"/>
      </xul:vbox>
      <xul:toolbarbutton class="toolbarbutton-icon home-arrow"
        oncommand="parentNode.navigate(0, 0, 'home');" tooltiptext="&homearrow.tooltip;"/>
      <xul:toolbarbutton class="toolbarbutton-icon left-arrow" 
        oncommand="parentNode.navigate(-1, 0, 0);" tooltiptext="&leftarrow.tooltip;"/>
      <xul:hbox align="center" pack="center">
        <xul:textbox id="pageNumber" size="3" value="1" lastvalid="1"
          onchange="navigate(0, this.value, 0);"/>
        <xul:label value="&of.label;"/>
        <xul:label value="1"/>
      </xul:hbox>
      <xul:toolbarbutton class="toolbarbutton-icon right-arrow" 
        oncommand="parentNode.navigate(1, 0, 0);" tooltiptext="&rightarrow.tooltip;"/>
      <xul:toolbarbutton class="toolbarbutton-icon end-arrow"
        oncommand="parentNode.navigate(0, 0, 'end');" tooltiptext="&endarrow.tooltip;"/>

      <xul:toolbarseparator class="toolbarseparator-primary"/>
      <xul:vbox align="center" pack="center">
        <xul:label value="&scale.label;" accesskey="&scale.accesskey;" control="scale"/>
      </xul:vbox>

      <xul:hbox align="center" pack="center">
        <xul:menulist id="scale" crop="none"
          oncommand="parentNode.parentNode.scale(this.selectedItem.value);">
          <xul:menupopup>
            <xul:menuitem value="0.3" label="&p30.label;"/>
            <xul:menuitem value="0.4" label="&p40.label;"/>
            <xul:menuitem value="0.5" label="&p50.label;"/>
            <xul:menuitem value="0.6" label="&p60.label;"/>
            <xul:menuitem value="0.7" label="&p70.label;"/>
            <xul:menuitem value="0.8" label="&p80.label;"/>
            <xul:menuitem value="0.9" label="&p90.label;"/>
            <xul:menuitem value="1" label="&p100.label;"/>
            <xul:menuitem value="1.25" label="&p125.label;"/>
            <xul:menuitem value="1.5" label="&p150.label;"/>
            <xul:menuitem value="1.75" label="&p175.label;"/>
            <xul:menuitem value="2" label="&p200.label;"/>
            <xul:menuseparator/>
            <xul:menuitem flex="1" value="ShrinkToFit" 
              label="&ShrinkToFit.label;"/>
            <xul:menuitem value="Custom" label="&Custom.label;"/>
          </xul:menupopup>
        </xul:menulist>
      </xul:hbox>

      <xul:toolbarseparator class="toolbarseparator-primary"/>
      <xul:hbox align="center" pack="center">
        <xul:toolbarbutton label="&portrait.label;" checked="true"
          accesskey="&portrait.accesskey;"
          type="radio" group="orient" class="toolbar-portrait-page"
          oncommand="parentNode.parentNode.orient('portrait');"/>
        <xul:toolbarbutton label="&landscape.label;"
          accesskey="&landscape.accesskey;"
          type="radio" group="orient" class="toolbar-landscape-page"
          oncommand="parentNode.parentNode.orient('landscape');"/>
      </xul:hbox>

      <xul:toolbarseparator class="toolbarseparator-primary"/>
      <xul:button label="&close.label;" accesskey="&close.accesskey;"
        oncommand="PrintUtils.exitPrintPreview();"/>
      <xul:data value="&customPrompt.title;"/>
    </content>

    <implementation>
      <field name="mDebug">
        false
      </field>
      <field name="mPrintButton">
        document.getAnonymousNodes(this)[0]
      </field>
      <field name="mPageTextBox">
        document.getAnonymousNodes(this)[5].firstChild
      </field>
      <field name="mTotalPages">
        document.getAnonymousNodes(this)[5].lastChild
      </field>
      <field name="mScaleLabel">
        document.getAnonymousNodes(this)[9].firstChild
      </field>
      <field name="mScaleCombobox">
        document.getAnonymousNodes(this)[10].firstChild
      </field>
      <field name="mOrientButtonsBox">
        document.getAnonymousNodes(this)[12]
      </field>
      <field name="mPortaitButton">
        this.mOrientButtonsBox.childNodes[0]
      </field>
      <field name="mLandscapeButton">
        this.mOrientButtonsBox.childNodes[1]
      </field>
      <field name="mCustomTitle">
        document.getAnonymousNodes(this)[15].firstChild
      </field>
      <field name="mPrintPreviewObs">
      </field>
      <field name="mWebProgress">
      </field>
     
      <constructor>
      <![CDATA[
        this._debug("constructor");

        var print = PrintUtils.getWebBrowserPrint();
        this.mTotalPages.value = print.printPreviewNumPages;

        this.updateToolbar();

        // Hide the ``Print...'' button when the underlying gfx code does not
        // support multiple devicecontext to be used concurrently
        // (e.g. printing and printpreview at the same time; required as 
        // legacy support for unices.'s PostScript module (Xprint
        // on unices. does not have problems with that))
        // XXX the scaling widgets, and the orientation widgets on unices.
        var canPrint = true;
        try
        {
          var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
          canPrint = prefs.getBoolPref("print.whileInPrintPreview");
          if (!canPrint)
          {           
            // Ask the printerfeatures database if this printer device 
            // supports multiple device instances which can be used
            // concurrently
            var smdci = prefs.getBoolPref("print.tmp.printerfeatures." + 
                                          print.currentPrintSettings.printerName +
                                          ".can_use_multiple_devicecontexts_concurrently");

            // We can print from print preview when we can use multiple
            // devicecontext instances in parallel (regardless what
            // "print.whileInPrintPreview" may say here...)
            if (smdci)
            {
              canPrint = true;
            }
          }

        } catch(e) {}

        if (!canPrint)
        {
          // hide print button
          this.mPrintButton.setAttribute("hidden", "true");

          // hide page setup button
          document.getAnonymousNodes(this)[1].setAttribute("hidden", "true");

          // hide scale widgets (indices: 8, 9, 10, 11)
          // hide orient widgets (indices: 12, 13)
          for (var i = 8; i <= 13; ++i)
          {
            document.getAnonymousNodes(this)[i].setAttribute("hidden", "true");
          }
        }
      ]]>
      </constructor>

      <method name="doPageSetup">
        <body>
        <![CDATA[
          var didOK = PrintUtils.showPageSetup();
          if (didOK) {
            // the changes that effect the UI
            this.updateToolbar();

            // Now do PrintPreview
            PrintUtils.printPreview();
          }
        ]]>
        </body>
      </method>

      <method name="navigate">
        <parameter name="aDirection"/>
        <parameter name="aPageNum"/>
        <parameter name="aHomeOrEnd"/>
        <body>
        <![CDATA[
          this._debug("navigate: " + aDirection + " " + aPageNum + 
                      " " + aHomeOrEnd);

          var print = PrintUtils.getWebBrowserPrint();
          var validInput = false;
          var total;

          // we use only one of aHomeOrEnd, aDirection, or aPageNum
          if (aHomeOrEnd)
          {
            var homeOrEnd;
            if (aHomeOrEnd == "home")
            {
              homeOrEnd = print.PRINTPREVIEW_HOME;
              this.mPageTextBox.value = 1;  
            }
            else
            {
              homeOrEnd = print.PRINTPREVIEW_END;
              this.mPageTextBox.value = print.printPreviewNumPages;
            }
            
            print.printPreviewNavigate(homeOrEnd, 0);
            validInput = true;
          }
          else if (aDirection)
          {
            var textBoxStr = this.mPageTextBox.value;
            var newPageNum = parseInt(textBoxStr) + aDirection;
            total = print.printPreviewNumPages;

            // bounds check potentially user-entered number
            if (newPageNum > 0 && newPageNum <= total)
            {
              this.mPageTextBox.value = newPageNum;
              print.printPreviewNavigate(
                print.PRINTPREVIEW_GOTO_PAGENUM, newPageNum);
              validInput = true;
            }
          }
          else 
          {
            total = print.printPreviewNumPages;

            // bounds check potentially user-entered number
            if (aPageNum > 0 && aPageNum <= total)
            {
              print.printPreviewNavigate(
                print.PRINTPREVIEW_GOTO_PAGENUM, aPageNum);
              validInput = true;
            }
          }

          if (validInput)          
          {
            // store the valid page number for future use to replace 
            // the textbox value if erroneous input made it in
            this.mPageTextBox.setAttribute(
              "lastvalid", this.mPageTextBox.value);
          }
          else
          { 
            // restore last known valid value in place of erroneous input
            this.mPageTextBox.value = 
              this.mPageTextBox.getAttribute("lastvalid");
          }
        ]]>
        </body>
      </method>

      <method name="promptForScaleValue">
        <parameter name="aValue"/>
        <body>
        <![CDATA[
          var value = Math.round(aValue);
          var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
                                        .getService(Components.interfaces.nsIPromptService);
          var result = {value:value};
          var confirmed = promptService.prompt(window, this.mCustomTitle,
                                               this.mScaleLabel.value, result,
                                               null, {value:value});
          this._debug("confirmed: " + confirmed);
          if (!confirmed || !result.value || result.value == "" || result.value == value) {
            return(-1);
          }
          return result.value;
        ]]>
        </body>
      </method>

      <method name="setScaleCombobox">
        <parameter name="aValue"/>
        <body>
        <![CDATA[
          var scaleValues = [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.25, 1.5, 1.75, 2];

          aValue = new Number(aValue);

          for (var i = 0; i < scaleValues.length; i++) {
            if (aValue == scaleValues[i]) {
              this.mScaleCombobox.selectedIndex = i;
              return;
            }
          }
          this.mScaleCombobox.value = "Custom";
        ]]>
        </body>
      </method>

      <method name="scale">
        <parameter name="aValue"/>
        <body>
        <![CDATA[
          this._debug("scale: " + aValue);

          var settings = PrintUtils.getPrintSettings();
          if (aValue == "ShrinkToFit") {
            if (!settings.shrinkToFit) {
              settings.shrinkToFit = true;
              this.savePrintSettings(settings, settings.kInitSaveShrinkToFit | settings.kInitSaveScaling);
              PrintUtils.printPreview();
            }
            return;
          }

          if (aValue == "Custom") {
            aValue = this.promptForScaleValue(settings.scaling * 100.0);
            this._debug("promptForScaleValue "+aValue);
            if (aValue >= 10) {
              aValue /= 100;
            } else {
              this.mScaleCombobox.selectedIndex = this.mScaleCombobox.getAttribute('lastValidInx');
              return;
            }
          }

          this.setScaleCombobox(aValue);
          this.mScaleCombobox.setAttribute('lastValidInx', this.mScaleCombobox.selectedIndex);

          if (settings.scaling != aValue)
          {
            settings.shrinkToFit = false;
            settings.scaling = aValue;
            this.savePrintSettings(settings, settings.kInitSaveShrinkToFit | settings.kInitSaveScaling);
            PrintUtils.printPreview();
          }
        ]]>
        </body>
      </method>

      <method name="orient">
        <parameter name="aOrientation"/>
        <body>
        <![CDATA[
          this._debug("orient: " + aOrientation);

          const kIPrintSettings = Components.interfaces.nsIPrintSettings;
          var orientValue = (aOrientation == "portrait") ? kIPrintSettings.kPortraitOrientation :
                                                           kIPrintSettings.kLandscapeOrientation;
          var settings = PrintUtils.getPrintSettings();
          if (settings.orientation != orientValue)
          {
            settings.orientation = orientValue;
            this.savePrintSettings(settings, settings.kInitSaveOrientation);
            PrintUtils.printPreview();
          }
        ]]>
        </body>
      </method>

      <method name="updateToolbar">
        <body>
        <![CDATA[
          var print = PrintUtils.getWebBrowserPrint();
          var settings = PrintUtils.getPrintSettings();

          var isPortrait = settings.orientation == Components.interfaces.nsIPrintSettings.kPortraitOrientation;

          this.mPortaitButton.checked = isPortrait;
          this.mLandscapeButton.checked = !isPortrait;

          if (settings.shrinkToFit) {
            this._debug("setting ShrinkToFit");
            this.mScaleCombobox.value = "ShrinkToFit";
          } else {
            this.setScaleCombobox(settings.scaling);
          }

          this.mTotalPages.value = print.printPreviewNumPages;
          this.mPageTextBox.value = 1;
        ]]>
        </body>
      </method>

      <method name="savePrintSettings">
        <parameter name="settings"/>
        <parameter name="flags"/>
        <body><![CDATA[
          var printService = Components.classes["@mozilla.org/gfx/printsettings-service;1"]
                                       .getService(Components.interfaces.nsIPrintSettingsService);
          printService.savePrintSettingsToPrefs(settings, true, flags);
        ]]></body>
      </method>

      <method name="_debug">
        <parameter name="aMsg"/>
        <body>
        <![CDATA[
          if (this.mDebug)
            dump("\t *** printPreviewBindings: " + aMsg + "\n");
        ]]>
        </body>
      </method>
    </implementation>
  </binding>

</bindings>