toolkit/components/printing/content/printjoboptions.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/printing/content/printjoboptions.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,900 @@
     1.4 +// -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 +
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +var dialog;
    1.11 +var gPrintBundle;
    1.12 +var gPrintSettings = null;
    1.13 +var gPrintSettingsInterface  = Components.interfaces.nsIPrintSettings;
    1.14 +var gPaperArray;
    1.15 +var gPlexArray;
    1.16 +var gResolutionArray;
    1.17 +var gColorSpaceArray;
    1.18 +var gPrefs;
    1.19 +
    1.20 +var default_command    = "lpr";
    1.21 +var gPrintSetInterface = Components.interfaces.nsIPrintSettings;
    1.22 +var doDebug            = true;
    1.23 +
    1.24 +//---------------------------------------------------
    1.25 +function checkDouble(element, maxVal)
    1.26 +{
    1.27 +  var value = element.value;
    1.28 +  if (value && value.length > 0) {
    1.29 +    value = value.replace(/[^\.|^0-9]/g,"");
    1.30 +    if (!value) {
    1.31 +      element.value = "";
    1.32 +    } else {
    1.33 +      if (value > maxVal) {
    1.34 +        element.value = maxVal;
    1.35 +      } else {
    1.36 +        element.value = value;
    1.37 +      }
    1.38 +    }
    1.39 +  }
    1.40 +}
    1.41 +
    1.42 +//---------------------------------------------------
    1.43 +function isListOfPrinterFeaturesAvailable()
    1.44 +{
    1.45 +  var has_printerfeatures = false;
    1.46 +  
    1.47 +  try {
    1.48 +    has_printerfeatures = gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".has_special_printerfeatures");
    1.49 +  } catch(ex) {
    1.50 +  }
    1.51 +  
    1.52 +  return has_printerfeatures;
    1.53 +}
    1.54 +
    1.55 +//---------------------------------------------------
    1.56 +function getDoubleStr(val, dec)
    1.57 +{
    1.58 +  var str = val.toString();
    1.59 +  var inx = str.indexOf(".");
    1.60 +  return str.substring(0, inx+dec+1);
    1.61 +}
    1.62 +
    1.63 +//---------------------------------------------------
    1.64 +function initDialog()
    1.65 +{
    1.66 +  gPrintBundle = document.getElementById("printBundle");
    1.67 +
    1.68 +  dialog = new Object;
    1.69 +
    1.70 +  dialog.paperList       = document.getElementById("paperList");
    1.71 +  dialog.paperGroup      = document.getElementById("paperGroup");
    1.72 +
    1.73 +  dialog.plexList        = document.getElementById("plexList");
    1.74 +  dialog.plexGroup       = document.getElementById("plexGroup");
    1.75 +
    1.76 +  dialog.resolutionList  = document.getElementById("resolutionList");
    1.77 +  dialog.resolutionGroup = document.getElementById("resolutionGroup");
    1.78 +
    1.79 +  dialog.jobTitleLabel   = document.getElementById("jobTitleLabel");
    1.80 +  dialog.jobTitleGroup   = document.getElementById("jobTitleGroup");
    1.81 +  dialog.jobTitleInput   = document.getElementById("jobTitleInput");
    1.82 +    
    1.83 +  dialog.cmdLabel        = document.getElementById("cmdLabel");
    1.84 +  dialog.cmdGroup        = document.getElementById("cmdGroup");
    1.85 +  dialog.cmdInput        = document.getElementById("cmdInput");
    1.86 +
    1.87 +  dialog.colorspaceList  = document.getElementById("colorspaceList");
    1.88 +  dialog.colorspaceGroup = document.getElementById("colorspaceGroup");
    1.89 +
    1.90 +  dialog.colorGroup      = document.getElementById("colorGroup");
    1.91 +  dialog.colorRadioGroup = document.getElementById("colorRadioGroup");
    1.92 +  dialog.colorRadio      = document.getElementById("colorRadio");
    1.93 +  dialog.grayRadio       = document.getElementById("grayRadio");
    1.94 +
    1.95 +  dialog.fontsGroup      = document.getElementById("fontsGroup");
    1.96 +  dialog.downloadFonts   = document.getElementById("downloadFonts");
    1.97 +
    1.98 +  dialog.topInput        = document.getElementById("topInput");
    1.99 +  dialog.bottomInput     = document.getElementById("bottomInput");
   1.100 +  dialog.leftInput       = document.getElementById("leftInput");
   1.101 +  dialog.rightInput      = document.getElementById("rightInput");
   1.102 +}
   1.103 +
   1.104 +//---------------------------------------------------
   1.105 +function round10(val)
   1.106 +{
   1.107 +  return Math.round(val * 10) / 10;
   1.108 +}
   1.109 +
   1.110 +
   1.111 +//---------------------------------------------------
   1.112 +function paperListElement(aPaperListElement)
   1.113 +  {
   1.114 +    this.paperListElement = aPaperListElement;
   1.115 +  }
   1.116 +
   1.117 +paperListElement.prototype =
   1.118 +  {
   1.119 +    clearPaperList:
   1.120 +      function ()
   1.121 +        {
   1.122 +          // remove the menupopup node child of the menulist.
   1.123 +          this.paperListElement.removeChild(this.paperListElement.firstChild);
   1.124 +        },
   1.125 +
   1.126 +    appendPaperNames: 
   1.127 +      function (aDataObject) 
   1.128 +        { 
   1.129 +          var popupNode = document.createElement("menupopup"); 
   1.130 +          for (var i=0;i<aDataObject.length;i++)  {
   1.131 +            var paperObj = aDataObject[i];
   1.132 +            var itemNode = document.createElement("menuitem");
   1.133 +            var label;
   1.134 +            try {
   1.135 +              label = gPrintBundle.getString(paperObj.name);
   1.136 +            } 
   1.137 +            catch (e) {
   1.138 +              /* No name in string bundle ? Then build one manually (this
   1.139 +               * usually happens when gPaperArray was build by createPaperArrayFromPrinterFeatures() ...) */              
   1.140 +              if (paperObj.inches) {
   1.141 +                label = paperObj.name + " (" + round10(paperObj.width) + "x" + round10(paperObj.height) + " inch)";
   1.142 +              }  
   1.143 +              else {
   1.144 +                label = paperObj.name + " (" + paperObj.width + "x" + paperObj.height + " mm)";
   1.145 +              }
   1.146 +            }
   1.147 +            itemNode.setAttribute("label", label);
   1.148 +            itemNode.setAttribute("value", i);
   1.149 +            popupNode.appendChild(itemNode);            
   1.150 +          }
   1.151 +          this.paperListElement.appendChild(popupNode); 
   1.152 +        } 
   1.153 +  };
   1.154 +
   1.155 +//---------------------------------------------------
   1.156 +function createPaperArrayFromDefaults()
   1.157 +{
   1.158 +  var paperNames   = ["letterSize", "legalSize", "exectiveSize", "a5Size", "a4Size", "a3Size", "a2Size", "a1Size", "a0Size"];
   1.159 +  //var paperNames   = ["&letterRadio.label;", "&legalRadio.label;", "&exectiveRadio.label;", "&a4Radio.label;", "&a3Radio.label;"];
   1.160 +  var paperWidths  = [ 8.5,  8.5,  7.25, 148.0, 210.0, 287.0, 420.0, 594.0,  841.0];
   1.161 +  var paperHeights = [11.0, 14.0, 10.50, 210.0, 297.0, 420.0, 594.0, 841.0, 1189.0];
   1.162 +  var paperInches  = [true, true, true,  false, false, false, false, false, false];
   1.163 +  // this is deprecated
   1.164 +  var paperEnums  = [0, 1, 2, 3, 4, 5, 6, 7, 8];
   1.165 +
   1.166 +  gPaperArray = new Array();
   1.167 +
   1.168 +  for (var i=0;i<paperNames.length;i++) {
   1.169 +    var obj    = new Object();
   1.170 +    obj.name   = paperNames[i];
   1.171 +    obj.width  = paperWidths[i];
   1.172 +    obj.height = paperHeights[i];
   1.173 +    obj.inches = paperInches[i];
   1.174 +    
   1.175 +    /* Calculate the width/height in millimeters */
   1.176 +    if (paperInches[i]) {
   1.177 +      obj.width_mm  = paperWidths[i]  * 25.4;
   1.178 +      obj.height_mm = paperHeights[i] * 25.4; 
   1.179 +    }
   1.180 +    else {
   1.181 +      obj.width_mm  = paperWidths[i];
   1.182 +      obj.height_mm = paperHeights[i];        
   1.183 +    }
   1.184 +    gPaperArray[i] = obj;
   1.185 +  }
   1.186 +}
   1.187 +
   1.188 +//---------------------------------------------------
   1.189 +function createPaperArrayFromPrinterFeatures()
   1.190 +{
   1.191 +  var printername = gPrintSettings.printerName;
   1.192 +  if (doDebug) {
   1.193 +    dump("createPaperArrayFromPrinterFeatures for " + printername + ".\n");
   1.194 +  }
   1.195 +
   1.196 +  gPaperArray = new Array();
   1.197 +  
   1.198 +  var numPapers = gPrefs.getIntPref("print.tmp.printerfeatures." + printername + ".paper.count");
   1.199 +  
   1.200 +  if (doDebug) {
   1.201 +    dump("processing " + numPapers + " entries...\n");
   1.202 +  }    
   1.203 +
   1.204 +  for (var i=0;i<numPapers;i++) {
   1.205 +    var obj    = new Object();
   1.206 +    obj.name      = gPrefs.getCharPref("print.tmp.printerfeatures." + printername + ".paper." + i + ".name");
   1.207 +    obj.width_mm  = gPrefs.getIntPref("print.tmp.printerfeatures."  + printername + ".paper." + i + ".width_mm");
   1.208 +    obj.height_mm = gPrefs.getIntPref("print.tmp.printerfeatures."  + printername + ".paper." + i + ".height_mm");
   1.209 +    obj.inches    = gPrefs.getBoolPref("print.tmp.printerfeatures." + printername + ".paper." + i + ".is_inch");
   1.210 +    
   1.211 +    /* Calculate the width/height in paper's native units (either inches or millimeters) */
   1.212 +    if (obj.inches) {
   1.213 +      obj.width  = obj.width_mm  / 25.4;
   1.214 +      obj.height = obj.height_mm / 25.4; 
   1.215 +    }
   1.216 +    else {
   1.217 +      obj.width  = obj.width_mm;
   1.218 +      obj.height = obj.height_mm;
   1.219 +    }
   1.220 +
   1.221 +    gPaperArray[i] = obj;
   1.222 +
   1.223 +    if (doDebug) {
   1.224 +      dump("paper index=" + i + ", name=" + obj.name + ", width=" + obj.width + ", height=" + obj.height + ".\n");
   1.225 +    }
   1.226 +  }  
   1.227 +}
   1.228 +
   1.229 +//---------------------------------------------------
   1.230 +function createPaperArray()
   1.231 +{  
   1.232 +  if (isListOfPrinterFeaturesAvailable()) {
   1.233 +    createPaperArrayFromPrinterFeatures();    
   1.234 +  }
   1.235 +  else {
   1.236 +    createPaperArrayFromDefaults();
   1.237 +  }
   1.238 +}
   1.239 +
   1.240 +//---------------------------------------------------
   1.241 +function createPaperSizeList(selectedInx)
   1.242 +{
   1.243 +  var selectElement = new paperListElement(dialog.paperList);
   1.244 +  selectElement.clearPaperList();
   1.245 +
   1.246 +  selectElement.appendPaperNames(gPaperArray);
   1.247 +
   1.248 +  if (selectedInx > -1) {
   1.249 +    selectElement.paperListElement.selectedIndex = selectedInx;
   1.250 +  }
   1.251 +
   1.252 +  //dialog.paperList = selectElement;
   1.253 +}
   1.254 +
   1.255 +//---------------------------------------------------
   1.256 +function plexListElement(aPlexListElement)
   1.257 +  {
   1.258 +    this.plexListElement = aPlexListElement;
   1.259 +  }
   1.260 +
   1.261 +plexListElement.prototype =
   1.262 +  {
   1.263 +    clearPlexList:
   1.264 +      function ()
   1.265 +        {
   1.266 +          // remove the menupopup node child of the menulist.
   1.267 +          this.plexListElement.removeChild(this.plexListElement.firstChild);
   1.268 +        },
   1.269 +
   1.270 +    appendPlexNames: 
   1.271 +      function (aDataObject) 
   1.272 +        { 
   1.273 +          var popupNode = document.createElement("menupopup"); 
   1.274 +          for (var i=0;i<aDataObject.length;i++)  {
   1.275 +            var plexObj = aDataObject[i];
   1.276 +            var itemNode = document.createElement("menuitem");
   1.277 +            var label;
   1.278 +            try {
   1.279 +              label = gPrintBundle.getString(plexObj.name);
   1.280 +            } 
   1.281 +            catch (e) {
   1.282 +              /* No name in string bundle ? Then build one manually (this
   1.283 +               * usually happens when gPlexArray was build by createPlexArrayFromPrinterFeatures() ...) */              
   1.284 +              label = plexObj.name;
   1.285 +            }
   1.286 +            itemNode.setAttribute("label", label);
   1.287 +            itemNode.setAttribute("value", i);
   1.288 +            popupNode.appendChild(itemNode);            
   1.289 +          }
   1.290 +          this.plexListElement.appendChild(popupNode); 
   1.291 +        } 
   1.292 +  };
   1.293 +
   1.294 +
   1.295 +//---------------------------------------------------
   1.296 +function createPlexArrayFromDefaults()
   1.297 +{
   1.298 +  var plexNames = ["default"];
   1.299 +
   1.300 +  gPlexArray = new Array();
   1.301 +
   1.302 +  for (var i=0;i<plexNames.length;i++) {
   1.303 +    var obj    = new Object();
   1.304 +    obj.name   = plexNames[i];
   1.305 +    
   1.306 +    gPlexArray[i] = obj;
   1.307 +  }
   1.308 +}
   1.309 +
   1.310 +//---------------------------------------------------
   1.311 +function createPlexArrayFromPrinterFeatures()
   1.312 +{
   1.313 +  var printername = gPrintSettings.printerName;
   1.314 +  if (doDebug) {
   1.315 +    dump("createPlexArrayFromPrinterFeatures for " + printername + ".\n");
   1.316 +  }
   1.317 +
   1.318 +  gPlexArray = new Array();
   1.319 +  
   1.320 +  var numPlexs = gPrefs.getIntPref("print.tmp.printerfeatures." + printername + ".plex.count");
   1.321 +  
   1.322 +  if (doDebug) {
   1.323 +    dump("processing " + numPlexs + " entries...\n");
   1.324 +  }    
   1.325 +
   1.326 +  for ( var i=0 ; i < numPlexs ; i++ ) {
   1.327 +    var obj = new Object();
   1.328 +    obj.name = gPrefs.getCharPref("print.tmp.printerfeatures." + printername + ".plex." + i + ".name");
   1.329 +
   1.330 +    gPlexArray[i] = obj;
   1.331 +
   1.332 +    if (doDebug) {
   1.333 +      dump("plex index=" + i + ", name='" + obj.name + "'.\n");
   1.334 +    }
   1.335 +  }  
   1.336 +}
   1.337 +
   1.338 +//---------------------------------------------------
   1.339 +function createPlexArray()
   1.340 +{  
   1.341 +  if (isListOfPrinterFeaturesAvailable()) {
   1.342 +    createPlexArrayFromPrinterFeatures();    
   1.343 +  }
   1.344 +  else {
   1.345 +    createPlexArrayFromDefaults();
   1.346 +  }
   1.347 +}
   1.348 +
   1.349 +//---------------------------------------------------
   1.350 +function createPlexNameList(selectedInx)
   1.351 +{
   1.352 +  var selectElement = new plexListElement(dialog.plexList);
   1.353 +  selectElement.clearPlexList();
   1.354 +
   1.355 +  selectElement.appendPlexNames(gPlexArray);
   1.356 +
   1.357 +  if (selectedInx > -1) {
   1.358 +    selectElement.plexListElement.selectedIndex = selectedInx;
   1.359 +  }
   1.360 +
   1.361 +  //dialog.plexList = selectElement;
   1.362 +}   
   1.363 +
   1.364 +//---------------------------------------------------
   1.365 +function resolutionListElement(aResolutionListElement)
   1.366 +  {
   1.367 +    this.resolutionListElement = aResolutionListElement;
   1.368 +  }
   1.369 +
   1.370 +resolutionListElement.prototype =
   1.371 +  {
   1.372 +    clearResolutionList:
   1.373 +      function ()
   1.374 +        {
   1.375 +          // remove the menupopup node child of the menulist.
   1.376 +          this.resolutionListElement.removeChild(this.resolutionListElement.firstChild);
   1.377 +        },
   1.378 +
   1.379 +    appendResolutionNames: 
   1.380 +      function (aDataObject) 
   1.381 +        { 
   1.382 +          var popupNode = document.createElement("menupopup"); 
   1.383 +          for (var i=0;i<aDataObject.length;i++)  {
   1.384 +            var resolutionObj = aDataObject[i];
   1.385 +            var itemNode = document.createElement("menuitem");
   1.386 +            var label;
   1.387 +            try {
   1.388 +              label = gPrintBundle.getString(resolutionObj.name);
   1.389 +            } 
   1.390 +            catch (e) {
   1.391 +              /* No name in string bundle ? Then build one manually (this
   1.392 +               * usually happens when gResolutionArray was build by createResolutionArrayFromPrinterFeatures() ...) */              
   1.393 +              label = resolutionObj.name;
   1.394 +            }
   1.395 +            itemNode.setAttribute("label", label);
   1.396 +            itemNode.setAttribute("value", i);
   1.397 +            popupNode.appendChild(itemNode);            
   1.398 +          }
   1.399 +          this.resolutionListElement.appendChild(popupNode); 
   1.400 +        } 
   1.401 +  };
   1.402 +
   1.403 +
   1.404 +//---------------------------------------------------
   1.405 +function createResolutionArrayFromDefaults()
   1.406 +{
   1.407 +  var resolutionNames = ["default"];
   1.408 +
   1.409 +  gResolutionArray = new Array();
   1.410 +
   1.411 +  for (var i=0;i<resolutionNames.length;i++) {
   1.412 +    var obj    = new Object();
   1.413 +    obj.name   = resolutionNames[i];
   1.414 +    
   1.415 +    gResolutionArray[i] = obj;
   1.416 +  }
   1.417 +}
   1.418 +
   1.419 +//---------------------------------------------------
   1.420 +function createResolutionArrayFromPrinterFeatures()
   1.421 +{
   1.422 +  var printername = gPrintSettings.printerName;
   1.423 +  if (doDebug) {
   1.424 +    dump("createResolutionArrayFromPrinterFeatures for " + printername + ".\n");
   1.425 +  }
   1.426 +
   1.427 +  gResolutionArray = new Array();
   1.428 +  
   1.429 +  var numResolutions = gPrefs.getIntPref("print.tmp.printerfeatures." + printername + ".resolution.count");
   1.430 +  
   1.431 +  if (doDebug) {
   1.432 +    dump("processing " + numResolutions + " entries...\n");
   1.433 +  }    
   1.434 +
   1.435 +  for ( var i=0 ; i < numResolutions ; i++ ) {
   1.436 +    var obj = new Object();
   1.437 +    obj.name = gPrefs.getCharPref("print.tmp.printerfeatures." + printername + ".resolution." + i + ".name");
   1.438 +
   1.439 +    gResolutionArray[i] = obj;
   1.440 +
   1.441 +    if (doDebug) {
   1.442 +      dump("resolution index=" + i + ", name='" + obj.name + "'.\n");
   1.443 +    }
   1.444 +  }  
   1.445 +}
   1.446 +
   1.447 +//---------------------------------------------------
   1.448 +function createResolutionArray()
   1.449 +{  
   1.450 +  if (isListOfPrinterFeaturesAvailable()) {
   1.451 +    createResolutionArrayFromPrinterFeatures();    
   1.452 +  }
   1.453 +  else {
   1.454 +    createResolutionArrayFromDefaults();
   1.455 +  }
   1.456 +}
   1.457 +
   1.458 +//---------------------------------------------------
   1.459 +function createResolutionNameList(selectedInx)
   1.460 +{
   1.461 +  var selectElement = new resolutionListElement(dialog.resolutionList);
   1.462 +  selectElement.clearResolutionList();
   1.463 +
   1.464 +  selectElement.appendResolutionNames(gResolutionArray);
   1.465 +
   1.466 +  if (selectedInx > -1) {
   1.467 +    selectElement.resolutionListElement.selectedIndex = selectedInx;
   1.468 +  }
   1.469 +
   1.470 +  //dialog.resolutionList = selectElement;
   1.471 +}  
   1.472 +
   1.473 +//---------------------------------------------------
   1.474 +function colorspaceListElement(aColorspaceListElement)
   1.475 +  {
   1.476 +    this.colorspaceListElement = aColorspaceListElement;
   1.477 +  }
   1.478 +
   1.479 +colorspaceListElement.prototype =
   1.480 +  {
   1.481 +    clearColorspaceList:
   1.482 +      function ()
   1.483 +        {
   1.484 +          // remove the menupopup node child of the menulist.
   1.485 +          this.colorspaceListElement.removeChild(this.colorspaceListElement.firstChild);
   1.486 +        },
   1.487 +
   1.488 +    appendColorspaceNames: 
   1.489 +      function (aDataObject) 
   1.490 +        { 
   1.491 +          var popupNode = document.createElement("menupopup"); 
   1.492 +          for (var i=0;i<aDataObject.length;i++)  {
   1.493 +            var colorspaceObj = aDataObject[i];
   1.494 +            var itemNode = document.createElement("menuitem");
   1.495 +            var label;
   1.496 +            try {
   1.497 +              label = gPrintBundle.getString(colorspaceObj.name);
   1.498 +            } 
   1.499 +            catch (e) {
   1.500 +              /* No name in string bundle ? Then build one manually (this
   1.501 +               * usually happens when gColorspaceArray was build by createColorspaceArrayFromPrinterFeatures() ...) */              
   1.502 +              label = colorspaceObj.name;
   1.503 +            }
   1.504 +            itemNode.setAttribute("label", label);
   1.505 +            itemNode.setAttribute("value", i);
   1.506 +            popupNode.appendChild(itemNode);            
   1.507 +          }
   1.508 +          this.colorspaceListElement.appendChild(popupNode); 
   1.509 +        } 
   1.510 +  };
   1.511 +
   1.512 +
   1.513 +//---------------------------------------------------
   1.514 +function createColorspaceArrayFromDefaults()
   1.515 +{
   1.516 +  var colorspaceNames = ["default"];
   1.517 +
   1.518 +  gColorspaceArray = new Array();
   1.519 +
   1.520 +  for (var i=0;i<colorspaceNames.length;i++) {
   1.521 +    var obj    = new Object();
   1.522 +    obj.name   = colorspaceNames[i];
   1.523 +    
   1.524 +    gColorspaceArray[i] = obj;
   1.525 +  }
   1.526 +}
   1.527 +
   1.528 +//---------------------------------------------------
   1.529 +function createColorspaceArrayFromPrinterFeatures()
   1.530 +{
   1.531 +  var printername = gPrintSettings.printerName;
   1.532 +  if (doDebug) {
   1.533 +    dump("createColorspaceArrayFromPrinterFeatures for " + printername + ".\n");
   1.534 +  }
   1.535 +
   1.536 +  gColorspaceArray = new Array();
   1.537 +  
   1.538 +  var numColorspaces = gPrefs.getIntPref("print.tmp.printerfeatures." + printername + ".colorspace.count");
   1.539 +  
   1.540 +  if (doDebug) {
   1.541 +    dump("processing " + numColorspaces + " entries...\n");
   1.542 +  }    
   1.543 +
   1.544 +  for ( var i=0 ; i < numColorspaces ; i++ ) {
   1.545 +    var obj = new Object();
   1.546 +    obj.name = gPrefs.getCharPref("print.tmp.printerfeatures." + printername + ".colorspace." + i + ".name");
   1.547 +
   1.548 +    gColorspaceArray[i] = obj;
   1.549 +
   1.550 +    if (doDebug) {
   1.551 +      dump("colorspace index=" + i + ", name='" + obj.name + "'.\n");
   1.552 +    }
   1.553 +  }  
   1.554 +}
   1.555 +
   1.556 +//---------------------------------------------------
   1.557 +function createColorspaceArray()
   1.558 +{  
   1.559 +  if (isListOfPrinterFeaturesAvailable()) {
   1.560 +    createColorspaceArrayFromPrinterFeatures();    
   1.561 +  }
   1.562 +  else {
   1.563 +    createColorspaceArrayFromDefaults();
   1.564 +  }
   1.565 +}
   1.566 +
   1.567 +//---------------------------------------------------
   1.568 +function createColorspaceNameList(selectedInx)
   1.569 +{
   1.570 +  var selectElement = new colorspaceListElement(dialog.colorspaceList);
   1.571 +  selectElement.clearColorspaceList();
   1.572 +
   1.573 +  selectElement.appendColorspaceNames(gColorspaceArray);
   1.574 +
   1.575 +  if (selectedInx > -1) {
   1.576 +    selectElement.colorspaceListElement.selectedIndex = selectedInx;
   1.577 +  }
   1.578 +
   1.579 +  //dialog.colorspaceList = selectElement;
   1.580 +}  
   1.581 +
   1.582 +//---------------------------------------------------
   1.583 +function loadDialog()
   1.584 +{
   1.585 +  var print_paper_type       = 0;
   1.586 +  var print_paper_unit       = 0;
   1.587 +  var print_paper_width      = 0.0;
   1.588 +  var print_paper_height     = 0.0;
   1.589 +  var print_paper_name       = "";
   1.590 +  var print_plex_name        = "";
   1.591 +  var print_resolution_name  = "";
   1.592 +  var print_colorspace       = "";
   1.593 +  var print_color            = true;
   1.594 +  var print_downloadfonts    = true;
   1.595 +  var print_command          = default_command;
   1.596 +  var print_jobtitle         = "";
   1.597 +
   1.598 +  gPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
   1.599 +
   1.600 +  if (gPrintSettings) {
   1.601 +    print_paper_type       = gPrintSettings.paperSizeType;
   1.602 +    print_paper_unit       = gPrintSettings.paperSizeUnit;
   1.603 +    print_paper_width      = gPrintSettings.paperWidth;
   1.604 +    print_paper_height     = gPrintSettings.paperHeight;
   1.605 +    print_paper_name       = gPrintSettings.paperName;
   1.606 +    print_plex_name        = gPrintSettings.plexName;
   1.607 +    print_resolution_name  = gPrintSettings.resolutionName;
   1.608 +    print_colorspace       = gPrintSettings.colorspace;
   1.609 +    print_color            = gPrintSettings.printInColor;
   1.610 +    print_downloadfonts    = gPrintSettings.downloadFonts;
   1.611 +    print_command          = gPrintSettings.printCommand;
   1.612 +    print_jobtitle         = gPrintSettings.title;
   1.613 +  }
   1.614 +
   1.615 +  if (doDebug) {
   1.616 +    dump("loadDialog******************************\n");
   1.617 +    dump("paperSizeType   "+print_paper_unit+"\n");
   1.618 +    dump("paperWidth      "+print_paper_width+"\n");
   1.619 +    dump("paperHeight     "+print_paper_height+"\n");
   1.620 +    dump("paperName       "+print_paper_name+"\n");
   1.621 +    dump("plexName        "+print_plex_name+"\n");
   1.622 +    dump("resolutionName  "+print_resolution_name+"\n");
   1.623 +    dump("colorspace      "+print_colorspace+"\n");
   1.624 +    dump("print_color     "+print_color+"\n");
   1.625 +    dump("print_downloadfonts "+print_downloadfonts+"\n");
   1.626 +    dump("print_command    "+print_command+"\n");
   1.627 +    dump("print_jobtitle   "+print_jobtitle+"\n");
   1.628 +  }
   1.629 +
   1.630 +  createPaperArray();
   1.631 +
   1.632 +  var paperSelectedInx = 0;
   1.633 +  for (var i=0;i<gPaperArray.length;i++) { 
   1.634 +    if (print_paper_name == gPaperArray[i].name) {
   1.635 +      paperSelectedInx = i;
   1.636 +      break;
   1.637 +    }
   1.638 +  }
   1.639 +  
   1.640 +  if (doDebug) {
   1.641 +    if (i == gPaperArray.length)
   1.642 +      dump("loadDialog: No paper found.\n");
   1.643 +    else
   1.644 +      dump("loadDialog: found paper '"+gPaperArray[paperSelectedInx].name+"'.\n");
   1.645 +  }
   1.646 +
   1.647 +  createPaperSizeList(paperSelectedInx);
   1.648 +
   1.649 +  createPlexArray();
   1.650 +  var plexSelectedInx = 0;
   1.651 +  for (var i=0;i<gPlexArray.length;i++) { 
   1.652 +    if (print_plex_name == gPlexArray[i].name) {
   1.653 +      plexSelectedInx = i;
   1.654 +      break;
   1.655 +    }
   1.656 +  }
   1.657 +
   1.658 +  if (doDebug) {
   1.659 +    if (i == gPlexArray.length)
   1.660 +      dump("loadDialog: No plex found.\n");
   1.661 +    else
   1.662 +      dump("loadDialog: found plex '"+gPlexArray[plexSelectedInx].name+"'.\n");
   1.663 +  }
   1.664 +
   1.665 +  createResolutionArray();
   1.666 +  var resolutionSelectedInx = 0;
   1.667 +  for (var i=0;i<gResolutionArray.length;i++) { 
   1.668 +    if (print_resolution_name == gResolutionArray[i].name) {
   1.669 +      resolutionSelectedInx = i;
   1.670 +      break;
   1.671 +    }
   1.672 +  }
   1.673 +  
   1.674 +  if (doDebug) {
   1.675 +    if (i == gResolutionArray.length)
   1.676 +      dump("loadDialog: No resolution found.\n");
   1.677 +    else
   1.678 +      dump("loadDialog: found resolution '"+gResolutionArray[resolutionSelectedInx].name+"'.\n");
   1.679 +  }
   1.680 +
   1.681 +  createColorspaceArray();
   1.682 +  var colorspaceSelectedInx = 0;
   1.683 +  for (var i=0;i<gColorspaceArray.length;i++) { 
   1.684 +    if (print_colorspace == gColorspaceArray[i].name) {
   1.685 +      colorspaceSelectedInx = i;
   1.686 +      break;
   1.687 +    }
   1.688 +  }
   1.689 +  
   1.690 +  if (doDebug) {
   1.691 +    if (i == gColorspaceArray.length)
   1.692 +      dump("loadDialog: No colorspace found.\n");
   1.693 +    else
   1.694 +      dump("loadDialog: found colorspace '"+gColorspaceArray[colorspaceSelectedInx].name+"'.\n");
   1.695 +  }
   1.696 +  
   1.697 +  createPlexNameList(plexSelectedInx);
   1.698 +  createResolutionNameList(resolutionSelectedInx);
   1.699 +  createColorspaceNameList(colorspaceSelectedInx);
   1.700 +    
   1.701 +  /* Enable/disable and/or hide/unhide widgets based in the information
   1.702 +   * whether the selected printer and/or print module supports the matching
   1.703 +   * feature or not */
   1.704 +  if (isListOfPrinterFeaturesAvailable()) {
   1.705 +    // job title
   1.706 +    if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".can_change_jobtitle"))
   1.707 +      dialog.jobTitleInput.removeAttribute("disabled");
   1.708 +    else
   1.709 +      dialog.jobTitleInput.setAttribute("disabled","true");
   1.710 +    if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".supports_jobtitle_change"))
   1.711 +      dialog.jobTitleGroup.removeAttribute("hidden");
   1.712 +    else
   1.713 +      dialog.jobTitleGroup.setAttribute("hidden","true");
   1.714 +
   1.715 +    // spooler command
   1.716 +    if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".can_change_spoolercommand"))
   1.717 +      dialog.cmdInput.removeAttribute("disabled");
   1.718 +    else
   1.719 +      dialog.cmdInput.setAttribute("disabled","true");
   1.720 +    if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".supports_spoolercommand_change"))
   1.721 +      dialog.cmdGroup.removeAttribute("hidden");
   1.722 +    else
   1.723 +      dialog.cmdGroup.setAttribute("hidden","true");
   1.724 +
   1.725 +    // paper size
   1.726 +    if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".can_change_paper_size"))
   1.727 +      dialog.paperList.removeAttribute("disabled");
   1.728 +    else
   1.729 +      dialog.paperList.setAttribute("disabled","true");
   1.730 +    if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".supports_paper_size_change"))
   1.731 +      dialog.paperGroup.removeAttribute("hidden");
   1.732 +    else
   1.733 +      dialog.paperGroup.setAttribute("hidden","true");
   1.734 +            
   1.735 +    // plex mode
   1.736 +    if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".can_change_plex"))
   1.737 +      dialog.plexList.removeAttribute("disabled");
   1.738 +    else
   1.739 +      dialog.plexList.setAttribute("disabled","true");
   1.740 +    if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".supports_plex_change"))
   1.741 +      dialog.plexGroup.removeAttribute("hidden");
   1.742 +    else
   1.743 +      dialog.plexGroup.setAttribute("hidden","true");
   1.744 +
   1.745 +    // resolution
   1.746 +    if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".can_change_resolution"))
   1.747 +      dialog.resolutionList.removeAttribute("disabled");
   1.748 +    else
   1.749 +      dialog.resolutionList.setAttribute("disabled","true");
   1.750 +    if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".supports_resolution_change"))
   1.751 +      dialog.resolutionGroup.removeAttribute("hidden");
   1.752 +    else
   1.753 +      dialog.resolutionGroup.setAttribute("hidden","true");
   1.754 +
   1.755 +    // color/grayscale radio
   1.756 +    if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".can_change_printincolor"))
   1.757 +      dialog.colorRadioGroup.removeAttribute("disabled");
   1.758 +    else
   1.759 +      dialog.colorRadioGroup.setAttribute("disabled","true");
   1.760 +    if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".supports_printincolor_change"))
   1.761 +      dialog.colorGroup.removeAttribute("hidden");
   1.762 +    else
   1.763 +      dialog.colorGroup.setAttribute("hidden","true");
   1.764 +
   1.765 +    // colorspace
   1.766 +    if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".can_change_colorspace"))
   1.767 +      dialog.colorspaceList.removeAttribute("disabled");
   1.768 +    else
   1.769 +      dialog.colorspaceList.setAttribute("disabled","true");
   1.770 +    if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".supports_colorspace_change"))
   1.771 +      dialog.colorspaceGroup.removeAttribute("hidden");
   1.772 +    else
   1.773 +      dialog.colorspaceGroup.setAttribute("hidden","true");
   1.774 +
   1.775 +    // font download
   1.776 +    if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".can_change_downloadfonts"))
   1.777 +      dialog.downloadFonts.removeAttribute("disabled");
   1.778 +    else
   1.779 +      dialog.downloadFonts.setAttribute("disabled","true");
   1.780 +    if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".supports_downloadfonts_change"))
   1.781 +      dialog.fontsGroup.removeAttribute("hidden");
   1.782 +    else
   1.783 +      dialog.fontsGroup.setAttribute("hidden","true");
   1.784 +  }
   1.785 +
   1.786 +  if (print_command == "") {
   1.787 +    print_command = default_command;
   1.788 +  }
   1.789 +
   1.790 +  if (print_color) {
   1.791 +    dialog.colorRadioGroup.selectedItem = dialog.colorRadio;
   1.792 +  } else {
   1.793 +    dialog.colorRadioGroup.selectedItem = dialog.grayRadio;
   1.794 +  }
   1.795 +
   1.796 +  dialog.downloadFonts.checked = print_downloadfonts;
   1.797 +
   1.798 +  dialog.cmdInput.value      = print_command;
   1.799 +  dialog.jobTitleInput.value = print_jobtitle;
   1.800 +
   1.801 +  dialog.topInput.value    = gPrintSettings.edgeTop.toFixed(2);
   1.802 +  dialog.bottomInput.value = gPrintSettings.edgeBottom.toFixed(2);
   1.803 +  dialog.leftInput.value   = gPrintSettings.edgeLeft.toFixed(2);
   1.804 +  dialog.rightInput.value  = gPrintSettings.edgeRight.toFixed(2);
   1.805 +}
   1.806 +
   1.807 +//---------------------------------------------------
   1.808 +function onLoad()
   1.809 +{
   1.810 +  // Init dialog.
   1.811 +  initDialog();
   1.812 +
   1.813 +  gPrintSettings = window.arguments[0].QueryInterface(gPrintSetInterface);
   1.814 +  paramBlock = window.arguments[1].QueryInterface(Components.interfaces.nsIDialogParamBlock);
   1.815 +
   1.816 +  if (doDebug) {
   1.817 +    if (gPrintSettings == null) alert("PrintSettings is null!");
   1.818 +    if (paramBlock == null) alert("nsIDialogParam is null!");
   1.819 +  }
   1.820 +
   1.821 +  // default return value is "cancel"
   1.822 +  paramBlock.SetInt(0, 0);
   1.823 +
   1.824 +  loadDialog();
   1.825 +}
   1.826 +
   1.827 +//---------------------------------------------------
   1.828 +function onAccept()
   1.829 +{
   1.830 +  var print_paper_type        = gPrintSettingsInterface.kPaperSizeDefined;
   1.831 +  var print_paper_unit        = gPrintSettingsInterface.kPaperSizeInches;
   1.832 +  var print_paper_width       = 0.0;
   1.833 +  var print_paper_height      = 0.0;
   1.834 +  var print_paper_name        = "";
   1.835 +  var print_plex_name         = "";
   1.836 +  var print_resolution_name   = "";
   1.837 +  var print_colorspace        = "";
   1.838 +
   1.839 +  if (gPrintSettings != null) {
   1.840 +    var paperSelectedInx = dialog.paperList.selectedIndex;
   1.841 +    var plexSelectedInx  = dialog.plexList.selectedIndex;
   1.842 +    var resolutionSelectedInx = dialog.resolutionList.selectedIndex;
   1.843 +    var colorspaceSelectedInx = dialog.colorspaceList.selectedIndex;
   1.844 +    if (gPaperArray[paperSelectedInx].inches) {
   1.845 +      print_paper_unit = gPrintSettingsInterface.kPaperSizeInches;
   1.846 +    } else {
   1.847 +      print_paper_unit = gPrintSettingsInterface.kPaperSizeMillimeters;
   1.848 +    }
   1.849 +    print_paper_width      = gPaperArray[paperSelectedInx].width;
   1.850 +    print_paper_height     = gPaperArray[paperSelectedInx].height;
   1.851 +    print_paper_name       = gPaperArray[paperSelectedInx].name;
   1.852 +    print_plex_name        = gPlexArray[plexSelectedInx].name;
   1.853 +    print_resolution_name  = gResolutionArray[resolutionSelectedInx].name;
   1.854 +    print_colorspace       = gColorspaceArray[colorspaceSelectedInx].name;
   1.855 +
   1.856 +    gPrintSettings.paperSizeType   = print_paper_type;
   1.857 +    gPrintSettings.paperSizeUnit   = print_paper_unit;
   1.858 +    gPrintSettings.paperWidth      = print_paper_width;
   1.859 +    gPrintSettings.paperHeight     = print_paper_height;
   1.860 +    gPrintSettings.paperName       = print_paper_name;
   1.861 +    gPrintSettings.plexName        = print_plex_name;
   1.862 +    gPrintSettings.resolutionName  = print_resolution_name;
   1.863 +    gPrintSettings.colorspace      = print_colorspace;
   1.864 +
   1.865 +    // save these out so they can be picked up by the device spec
   1.866 +    gPrintSettings.printInColor     = dialog.colorRadio.selected;
   1.867 +    gPrintSettings.downloadFonts    = dialog.downloadFonts.checked;
   1.868 +    gPrintSettings.printCommand     = dialog.cmdInput.value;
   1.869 +    gPrintSettings.title            = dialog.jobTitleInput.value;
   1.870 +
   1.871 +    gPrintSettings.edgeTop          = dialog.topInput.value;
   1.872 +    gPrintSettings.edgeBottom       = dialog.bottomInput.value;
   1.873 +    gPrintSettings.edgeLeft         = dialog.leftInput.value;
   1.874 +    gPrintSettings.edgeRight        = dialog.rightInput.value;
   1.875 +
   1.876 +    if (doDebug) {
   1.877 +      dump("onAccept******************************\n");
   1.878 +      dump("paperSizeType    "+print_paper_type+" (should be 1)\n");
   1.879 +      dump("paperSizeUnit    "+print_paper_unit+"\n");
   1.880 +      dump("paperWidth       "+print_paper_width+"\n");
   1.881 +      dump("paperHeight      "+print_paper_height+"\n");
   1.882 +      dump("paperName       '"+print_paper_name+"'\n");
   1.883 +      dump("plexName        '"+print_plex_name+"'\n");
   1.884 +      dump("resolutionName  '"+print_resolution_name+"'\n");
   1.885 +      dump("colorspace      '"+print_colorspace+"'\n");
   1.886 +
   1.887 +      dump("printInColor     "+gPrintSettings.printInColor+"\n");
   1.888 +      dump("downloadFonts    "+gPrintSettings.downloadFonts+"\n");
   1.889 +      dump("printCommand    '"+gPrintSettings.printCommand+"'\n");
   1.890 +    }
   1.891 +  } else {
   1.892 +    dump("************ onAccept gPrintSettings: "+gPrintSettings+"\n");
   1.893 +  }
   1.894 +
   1.895 +  if (paramBlock) {
   1.896 +    // set return value to "ok"
   1.897 +    paramBlock.SetInt(0, 1);
   1.898 +  } else {
   1.899 +    dump("*** FATAL ERROR: paramBlock missing\n");
   1.900 +  }
   1.901 +
   1.902 +  return true;
   1.903 +}

mercurial