michael@0: // -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: var dialog; michael@0: var gPrintBundle; michael@0: var gPrintSettings = null; michael@0: var gPrintSettingsInterface = Components.interfaces.nsIPrintSettings; michael@0: var gPaperArray; michael@0: var gPlexArray; michael@0: var gResolutionArray; michael@0: var gColorSpaceArray; michael@0: var gPrefs; michael@0: michael@0: var default_command = "lpr"; michael@0: var gPrintSetInterface = Components.interfaces.nsIPrintSettings; michael@0: var doDebug = true; michael@0: michael@0: //--------------------------------------------------- michael@0: function checkDouble(element, maxVal) michael@0: { michael@0: var value = element.value; michael@0: if (value && value.length > 0) { michael@0: value = value.replace(/[^\.|^0-9]/g,""); michael@0: if (!value) { michael@0: element.value = ""; michael@0: } else { michael@0: if (value > maxVal) { michael@0: element.value = maxVal; michael@0: } else { michael@0: element.value = value; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: //--------------------------------------------------- michael@0: function isListOfPrinterFeaturesAvailable() michael@0: { michael@0: var has_printerfeatures = false; michael@0: michael@0: try { michael@0: has_printerfeatures = gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".has_special_printerfeatures"); michael@0: } catch(ex) { michael@0: } michael@0: michael@0: return has_printerfeatures; michael@0: } michael@0: michael@0: //--------------------------------------------------- michael@0: function getDoubleStr(val, dec) michael@0: { michael@0: var str = val.toString(); michael@0: var inx = str.indexOf("."); michael@0: return str.substring(0, inx+dec+1); michael@0: } michael@0: michael@0: //--------------------------------------------------- michael@0: function initDialog() michael@0: { michael@0: gPrintBundle = document.getElementById("printBundle"); michael@0: michael@0: dialog = new Object; michael@0: michael@0: dialog.paperList = document.getElementById("paperList"); michael@0: dialog.paperGroup = document.getElementById("paperGroup"); michael@0: michael@0: dialog.plexList = document.getElementById("plexList"); michael@0: dialog.plexGroup = document.getElementById("plexGroup"); michael@0: michael@0: dialog.resolutionList = document.getElementById("resolutionList"); michael@0: dialog.resolutionGroup = document.getElementById("resolutionGroup"); michael@0: michael@0: dialog.jobTitleLabel = document.getElementById("jobTitleLabel"); michael@0: dialog.jobTitleGroup = document.getElementById("jobTitleGroup"); michael@0: dialog.jobTitleInput = document.getElementById("jobTitleInput"); michael@0: michael@0: dialog.cmdLabel = document.getElementById("cmdLabel"); michael@0: dialog.cmdGroup = document.getElementById("cmdGroup"); michael@0: dialog.cmdInput = document.getElementById("cmdInput"); michael@0: michael@0: dialog.colorspaceList = document.getElementById("colorspaceList"); michael@0: dialog.colorspaceGroup = document.getElementById("colorspaceGroup"); michael@0: michael@0: dialog.colorGroup = document.getElementById("colorGroup"); michael@0: dialog.colorRadioGroup = document.getElementById("colorRadioGroup"); michael@0: dialog.colorRadio = document.getElementById("colorRadio"); michael@0: dialog.grayRadio = document.getElementById("grayRadio"); michael@0: michael@0: dialog.fontsGroup = document.getElementById("fontsGroup"); michael@0: dialog.downloadFonts = document.getElementById("downloadFonts"); michael@0: michael@0: dialog.topInput = document.getElementById("topInput"); michael@0: dialog.bottomInput = document.getElementById("bottomInput"); michael@0: dialog.leftInput = document.getElementById("leftInput"); michael@0: dialog.rightInput = document.getElementById("rightInput"); michael@0: } michael@0: michael@0: //--------------------------------------------------- michael@0: function round10(val) michael@0: { michael@0: return Math.round(val * 10) / 10; michael@0: } michael@0: michael@0: michael@0: //--------------------------------------------------- michael@0: function paperListElement(aPaperListElement) michael@0: { michael@0: this.paperListElement = aPaperListElement; michael@0: } michael@0: michael@0: paperListElement.prototype = michael@0: { michael@0: clearPaperList: michael@0: function () michael@0: { michael@0: // remove the menupopup node child of the menulist. michael@0: this.paperListElement.removeChild(this.paperListElement.firstChild); michael@0: }, michael@0: michael@0: appendPaperNames: michael@0: function (aDataObject) michael@0: { michael@0: var popupNode = document.createElement("menupopup"); michael@0: for (var i=0;i -1) { michael@0: selectElement.paperListElement.selectedIndex = selectedInx; michael@0: } michael@0: michael@0: //dialog.paperList = selectElement; michael@0: } michael@0: michael@0: //--------------------------------------------------- michael@0: function plexListElement(aPlexListElement) michael@0: { michael@0: this.plexListElement = aPlexListElement; michael@0: } michael@0: michael@0: plexListElement.prototype = michael@0: { michael@0: clearPlexList: michael@0: function () michael@0: { michael@0: // remove the menupopup node child of the menulist. michael@0: this.plexListElement.removeChild(this.plexListElement.firstChild); michael@0: }, michael@0: michael@0: appendPlexNames: michael@0: function (aDataObject) michael@0: { michael@0: var popupNode = document.createElement("menupopup"); michael@0: for (var i=0;i -1) { michael@0: selectElement.plexListElement.selectedIndex = selectedInx; michael@0: } michael@0: michael@0: //dialog.plexList = selectElement; michael@0: } michael@0: michael@0: //--------------------------------------------------- michael@0: function resolutionListElement(aResolutionListElement) michael@0: { michael@0: this.resolutionListElement = aResolutionListElement; michael@0: } michael@0: michael@0: resolutionListElement.prototype = michael@0: { michael@0: clearResolutionList: michael@0: function () michael@0: { michael@0: // remove the menupopup node child of the menulist. michael@0: this.resolutionListElement.removeChild(this.resolutionListElement.firstChild); michael@0: }, michael@0: michael@0: appendResolutionNames: michael@0: function (aDataObject) michael@0: { michael@0: var popupNode = document.createElement("menupopup"); michael@0: for (var i=0;i -1) { michael@0: selectElement.resolutionListElement.selectedIndex = selectedInx; michael@0: } michael@0: michael@0: //dialog.resolutionList = selectElement; michael@0: } michael@0: michael@0: //--------------------------------------------------- michael@0: function colorspaceListElement(aColorspaceListElement) michael@0: { michael@0: this.colorspaceListElement = aColorspaceListElement; michael@0: } michael@0: michael@0: colorspaceListElement.prototype = michael@0: { michael@0: clearColorspaceList: michael@0: function () michael@0: { michael@0: // remove the menupopup node child of the menulist. michael@0: this.colorspaceListElement.removeChild(this.colorspaceListElement.firstChild); michael@0: }, michael@0: michael@0: appendColorspaceNames: michael@0: function (aDataObject) michael@0: { michael@0: var popupNode = document.createElement("menupopup"); michael@0: for (var i=0;i -1) { michael@0: selectElement.colorspaceListElement.selectedIndex = selectedInx; michael@0: } michael@0: michael@0: //dialog.colorspaceList = selectElement; michael@0: } michael@0: michael@0: //--------------------------------------------------- michael@0: function loadDialog() michael@0: { michael@0: var print_paper_type = 0; michael@0: var print_paper_unit = 0; michael@0: var print_paper_width = 0.0; michael@0: var print_paper_height = 0.0; michael@0: var print_paper_name = ""; michael@0: var print_plex_name = ""; michael@0: var print_resolution_name = ""; michael@0: var print_colorspace = ""; michael@0: var print_color = true; michael@0: var print_downloadfonts = true; michael@0: var print_command = default_command; michael@0: var print_jobtitle = ""; michael@0: michael@0: gPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); michael@0: michael@0: if (gPrintSettings) { michael@0: print_paper_type = gPrintSettings.paperSizeType; michael@0: print_paper_unit = gPrintSettings.paperSizeUnit; michael@0: print_paper_width = gPrintSettings.paperWidth; michael@0: print_paper_height = gPrintSettings.paperHeight; michael@0: print_paper_name = gPrintSettings.paperName; michael@0: print_plex_name = gPrintSettings.plexName; michael@0: print_resolution_name = gPrintSettings.resolutionName; michael@0: print_colorspace = gPrintSettings.colorspace; michael@0: print_color = gPrintSettings.printInColor; michael@0: print_downloadfonts = gPrintSettings.downloadFonts; michael@0: print_command = gPrintSettings.printCommand; michael@0: print_jobtitle = gPrintSettings.title; michael@0: } michael@0: michael@0: if (doDebug) { michael@0: dump("loadDialog******************************\n"); michael@0: dump("paperSizeType "+print_paper_unit+"\n"); michael@0: dump("paperWidth "+print_paper_width+"\n"); michael@0: dump("paperHeight "+print_paper_height+"\n"); michael@0: dump("paperName "+print_paper_name+"\n"); michael@0: dump("plexName "+print_plex_name+"\n"); michael@0: dump("resolutionName "+print_resolution_name+"\n"); michael@0: dump("colorspace "+print_colorspace+"\n"); michael@0: dump("print_color "+print_color+"\n"); michael@0: dump("print_downloadfonts "+print_downloadfonts+"\n"); michael@0: dump("print_command "+print_command+"\n"); michael@0: dump("print_jobtitle "+print_jobtitle+"\n"); michael@0: } michael@0: michael@0: createPaperArray(); michael@0: michael@0: var paperSelectedInx = 0; michael@0: for (var i=0;i