Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | // -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | var gDialog; |
michael@0 | 8 | var paramBlock; |
michael@0 | 9 | var gPrefs = null; |
michael@0 | 10 | var gPrintService = null; |
michael@0 | 11 | var gPrintSettings = null; |
michael@0 | 12 | var gStringBundle = null; |
michael@0 | 13 | var gDoingMetric = false; |
michael@0 | 14 | |
michael@0 | 15 | var gPrintSettingsInterface = Components.interfaces.nsIPrintSettings; |
michael@0 | 16 | var gDoDebug = false; |
michael@0 | 17 | |
michael@0 | 18 | //--------------------------------------------------- |
michael@0 | 19 | function initDialog() |
michael@0 | 20 | { |
michael@0 | 21 | gDialog = new Object; |
michael@0 | 22 | |
michael@0 | 23 | gDialog.orientation = document.getElementById("orientation"); |
michael@0 | 24 | gDialog.portrait = document.getElementById("portrait"); |
michael@0 | 25 | gDialog.landscape = document.getElementById("landscape"); |
michael@0 | 26 | |
michael@0 | 27 | gDialog.printBG = document.getElementById("printBG"); |
michael@0 | 28 | |
michael@0 | 29 | gDialog.shrinkToFit = document.getElementById("shrinkToFit"); |
michael@0 | 30 | |
michael@0 | 31 | gDialog.marginGroup = document.getElementById("marginGroup"); |
michael@0 | 32 | |
michael@0 | 33 | gDialog.marginPage = document.getElementById("marginPage"); |
michael@0 | 34 | gDialog.marginTop = document.getElementById("marginTop"); |
michael@0 | 35 | gDialog.marginBottom = document.getElementById("marginBottom"); |
michael@0 | 36 | gDialog.marginLeft = document.getElementById("marginLeft"); |
michael@0 | 37 | gDialog.marginRight = document.getElementById("marginRight"); |
michael@0 | 38 | |
michael@0 | 39 | gDialog.topInput = document.getElementById("topInput"); |
michael@0 | 40 | gDialog.bottomInput = document.getElementById("bottomInput"); |
michael@0 | 41 | gDialog.leftInput = document.getElementById("leftInput"); |
michael@0 | 42 | gDialog.rightInput = document.getElementById("rightInput"); |
michael@0 | 43 | |
michael@0 | 44 | gDialog.hLeftOption = document.getElementById("hLeftOption"); |
michael@0 | 45 | gDialog.hCenterOption = document.getElementById("hCenterOption"); |
michael@0 | 46 | gDialog.hRightOption = document.getElementById("hRightOption"); |
michael@0 | 47 | |
michael@0 | 48 | gDialog.fLeftOption = document.getElementById("fLeftOption"); |
michael@0 | 49 | gDialog.fCenterOption = document.getElementById("fCenterOption"); |
michael@0 | 50 | gDialog.fRightOption = document.getElementById("fRightOption"); |
michael@0 | 51 | |
michael@0 | 52 | gDialog.scalingLabel = document.getElementById("scalingInput"); |
michael@0 | 53 | gDialog.scalingInput = document.getElementById("scalingInput"); |
michael@0 | 54 | |
michael@0 | 55 | gDialog.enabled = false; |
michael@0 | 56 | |
michael@0 | 57 | gDialog.strings = new Array; |
michael@0 | 58 | gDialog.strings[ "marginUnits.inches" ] = document.getElementById("marginUnits.inches").childNodes[0].nodeValue; |
michael@0 | 59 | gDialog.strings[ "marginUnits.metric" ] = document.getElementById("marginUnits.metric").childNodes[0].nodeValue; |
michael@0 | 60 | gDialog.strings[ "customPrompt.title" ] = document.getElementById("customPrompt.title").childNodes[0].nodeValue; |
michael@0 | 61 | gDialog.strings[ "customPrompt.prompt" ] = document.getElementById("customPrompt.prompt").childNodes[0].nodeValue; |
michael@0 | 62 | |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | //--------------------------------------------------- |
michael@0 | 66 | function isListOfPrinterFeaturesAvailable() |
michael@0 | 67 | { |
michael@0 | 68 | var has_printerfeatures = false; |
michael@0 | 69 | |
michael@0 | 70 | try { |
michael@0 | 71 | has_printerfeatures = gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".has_special_printerfeatures"); |
michael@0 | 72 | } catch(ex) { |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | return has_printerfeatures; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | //--------------------------------------------------- |
michael@0 | 79 | function checkDouble(element) |
michael@0 | 80 | { |
michael@0 | 81 | element.value = element.value.replace(/[^.0-9]/g, ""); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | // Theoretical paper width/height. |
michael@0 | 85 | var gPageWidth = 8.5; |
michael@0 | 86 | var gPageHeight = 11.0; |
michael@0 | 87 | |
michael@0 | 88 | //--------------------------------------------------- |
michael@0 | 89 | function setOrientation() |
michael@0 | 90 | { |
michael@0 | 91 | var selection = gDialog.orientation.selectedItem; |
michael@0 | 92 | |
michael@0 | 93 | var style = "background-color:white;"; |
michael@0 | 94 | if ((selection == gDialog.portrait && gPageWidth > gPageHeight) || |
michael@0 | 95 | (selection == gDialog.landscape && gPageWidth < gPageHeight)) { |
michael@0 | 96 | // Swap width/height. |
michael@0 | 97 | var temp = gPageHeight; |
michael@0 | 98 | gPageHeight = gPageWidth; |
michael@0 | 99 | gPageWidth = temp; |
michael@0 | 100 | } |
michael@0 | 101 | var div = gDoingMetric ? 100 : 10; |
michael@0 | 102 | style += "width:" + gPageWidth/div + unitString() + ";height:" + gPageHeight/div + unitString() + ";"; |
michael@0 | 103 | gDialog.marginPage.setAttribute( "style", style ); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | //--------------------------------------------------- |
michael@0 | 107 | function unitString() |
michael@0 | 108 | { |
michael@0 | 109 | return (gPrintSettings.paperSizeUnit == gPrintSettingsInterface.kPaperSizeInches) ? "in" : "mm"; |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | //--------------------------------------------------- |
michael@0 | 113 | function checkMargin( value, max, other ) |
michael@0 | 114 | { |
michael@0 | 115 | // Don't draw this margin bigger than permitted. |
michael@0 | 116 | return Math.min(value, max - other.value); |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | //--------------------------------------------------- |
michael@0 | 120 | function changeMargin( node ) |
michael@0 | 121 | { |
michael@0 | 122 | // Correct invalid input. |
michael@0 | 123 | checkDouble(node); |
michael@0 | 124 | |
michael@0 | 125 | // Reset the margin height/width for this node. |
michael@0 | 126 | var val = node.value; |
michael@0 | 127 | var nodeToStyle; |
michael@0 | 128 | var attr="width"; |
michael@0 | 129 | if ( node == gDialog.topInput ) { |
michael@0 | 130 | nodeToStyle = gDialog.marginTop; |
michael@0 | 131 | val = checkMargin( val, gPageHeight, gDialog.bottomInput ); |
michael@0 | 132 | attr = "height"; |
michael@0 | 133 | } else if ( node == gDialog.bottomInput ) { |
michael@0 | 134 | nodeToStyle = gDialog.marginBottom; |
michael@0 | 135 | val = checkMargin( val, gPageHeight, gDialog.topInput ); |
michael@0 | 136 | attr = "height"; |
michael@0 | 137 | } else if ( node == gDialog.leftInput ) { |
michael@0 | 138 | nodeToStyle = gDialog.marginLeft; |
michael@0 | 139 | val = checkMargin( val, gPageWidth, gDialog.rightInput ); |
michael@0 | 140 | } else { |
michael@0 | 141 | nodeToStyle = gDialog.marginRight; |
michael@0 | 142 | val = checkMargin( val, gPageWidth, gDialog.leftInput ); |
michael@0 | 143 | } |
michael@0 | 144 | var style = attr + ":" + (val/10) + unitString() + ";"; |
michael@0 | 145 | nodeToStyle.setAttribute( "style", style ); |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | //--------------------------------------------------- |
michael@0 | 149 | function changeMargins() |
michael@0 | 150 | { |
michael@0 | 151 | changeMargin( gDialog.topInput ); |
michael@0 | 152 | changeMargin( gDialog.bottomInput ); |
michael@0 | 153 | changeMargin( gDialog.leftInput ); |
michael@0 | 154 | changeMargin( gDialog.rightInput ); |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | //--------------------------------------------------- |
michael@0 | 158 | function customize( node ) |
michael@0 | 159 | { |
michael@0 | 160 | // If selection is now "Custom..." then prompt user for custom setting. |
michael@0 | 161 | if ( node.value == 6 ) { |
michael@0 | 162 | var prompter = Components.classes[ "@mozilla.org/embedcomp/prompt-service;1" ] |
michael@0 | 163 | .getService( Components.interfaces.nsIPromptService ); |
michael@0 | 164 | var title = gDialog.strings[ "customPrompt.title" ]; |
michael@0 | 165 | var promptText = gDialog.strings[ "customPrompt.prompt" ]; |
michael@0 | 166 | var result = { value: node.custom }; |
michael@0 | 167 | var ok = prompter.prompt(window, title, promptText, result, null, { value: false } ); |
michael@0 | 168 | if ( ok ) { |
michael@0 | 169 | node.custom = result.value; |
michael@0 | 170 | } |
michael@0 | 171 | } |
michael@0 | 172 | } |
michael@0 | 173 | |
michael@0 | 174 | //--------------------------------------------------- |
michael@0 | 175 | function setHeaderFooter( node, value ) |
michael@0 | 176 | { |
michael@0 | 177 | node.value= hfValueToId(value); |
michael@0 | 178 | if (node.value == 6) { |
michael@0 | 179 | // Remember current Custom... value. |
michael@0 | 180 | node.custom = value; |
michael@0 | 181 | } else { |
michael@0 | 182 | // Start with empty Custom... value. |
michael@0 | 183 | node.custom = ""; |
michael@0 | 184 | } |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | var gHFValues = new Array; |
michael@0 | 188 | gHFValues[ "&T" ] = 1; |
michael@0 | 189 | gHFValues[ "&U" ] = 2; |
michael@0 | 190 | gHFValues[ "&D" ] = 3; |
michael@0 | 191 | gHFValues[ "&P" ] = 4; |
michael@0 | 192 | gHFValues[ "&PT" ] = 5; |
michael@0 | 193 | |
michael@0 | 194 | function hfValueToId(val) |
michael@0 | 195 | { |
michael@0 | 196 | if ( val in gHFValues ) { |
michael@0 | 197 | return gHFValues[val]; |
michael@0 | 198 | } |
michael@0 | 199 | if ( val.length ) { |
michael@0 | 200 | return 6; // Custom... |
michael@0 | 201 | } else { |
michael@0 | 202 | return 0; // --blank-- |
michael@0 | 203 | } |
michael@0 | 204 | } |
michael@0 | 205 | |
michael@0 | 206 | function hfIdToValue(node) |
michael@0 | 207 | { |
michael@0 | 208 | var result = ""; |
michael@0 | 209 | switch ( parseInt( node.value ) ) { |
michael@0 | 210 | case 0: |
michael@0 | 211 | break; |
michael@0 | 212 | case 1: |
michael@0 | 213 | result = "&T"; |
michael@0 | 214 | break; |
michael@0 | 215 | case 2: |
michael@0 | 216 | result = "&U"; |
michael@0 | 217 | break; |
michael@0 | 218 | case 3: |
michael@0 | 219 | result = "&D"; |
michael@0 | 220 | break; |
michael@0 | 221 | case 4: |
michael@0 | 222 | result = "&P"; |
michael@0 | 223 | break; |
michael@0 | 224 | case 5: |
michael@0 | 225 | result = "&PT"; |
michael@0 | 226 | break; |
michael@0 | 227 | case 6: |
michael@0 | 228 | result = node.custom; |
michael@0 | 229 | break; |
michael@0 | 230 | } |
michael@0 | 231 | return result; |
michael@0 | 232 | } |
michael@0 | 233 | |
michael@0 | 234 | function setPrinterDefaultsForSelectedPrinter() |
michael@0 | 235 | { |
michael@0 | 236 | if (gPrintSettings.printerName == "") { |
michael@0 | 237 | gPrintSettings.printerName = gPrintService.defaultPrinterName; |
michael@0 | 238 | } |
michael@0 | 239 | |
michael@0 | 240 | // First get any defaults from the printer |
michael@0 | 241 | gPrintService.initPrintSettingsFromPrinter(gPrintSettings.printerName, gPrintSettings); |
michael@0 | 242 | |
michael@0 | 243 | // now augment them with any values from last time |
michael@0 | 244 | gPrintService.initPrintSettingsFromPrefs(gPrintSettings, true, gPrintSettingsInterface.kInitSaveAll); |
michael@0 | 245 | |
michael@0 | 246 | if (gDoDebug) { |
michael@0 | 247 | dump("pagesetup/setPrinterDefaultsForSelectedPrinter: printerName='"+gPrintSettings.printerName+"', orientation='"+gPrintSettings.orientation+"'\n"); |
michael@0 | 248 | } |
michael@0 | 249 | } |
michael@0 | 250 | |
michael@0 | 251 | //--------------------------------------------------- |
michael@0 | 252 | function loadDialog() |
michael@0 | 253 | { |
michael@0 | 254 | var print_orientation = 0; |
michael@0 | 255 | var print_margin_top = 0.5; |
michael@0 | 256 | var print_margin_left = 0.5; |
michael@0 | 257 | var print_margin_bottom = 0.5; |
michael@0 | 258 | var print_margin_right = 0.5; |
michael@0 | 259 | |
michael@0 | 260 | try { |
michael@0 | 261 | gPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); |
michael@0 | 262 | |
michael@0 | 263 | gPrintService = Components.classes["@mozilla.org/gfx/printsettings-service;1"]; |
michael@0 | 264 | if (gPrintService) { |
michael@0 | 265 | gPrintService = gPrintService.getService(); |
michael@0 | 266 | if (gPrintService) { |
michael@0 | 267 | gPrintService = gPrintService.QueryInterface(Components.interfaces.nsIPrintSettingsService); |
michael@0 | 268 | } |
michael@0 | 269 | } |
michael@0 | 270 | } catch(ex) { |
michael@0 | 271 | dump("loadDialog: ex="+ex+"\n"); |
michael@0 | 272 | } |
michael@0 | 273 | |
michael@0 | 274 | setPrinterDefaultsForSelectedPrinter(); |
michael@0 | 275 | |
michael@0 | 276 | gDialog.printBG.checked = gPrintSettings.printBGColors || gPrintSettings.printBGImages; |
michael@0 | 277 | |
michael@0 | 278 | gDialog.shrinkToFit.checked = gPrintSettings.shrinkToFit; |
michael@0 | 279 | |
michael@0 | 280 | gDialog.scalingLabel.disabled = gDialog.scalingInput.disabled = gDialog.shrinkToFit.checked; |
michael@0 | 281 | |
michael@0 | 282 | var marginGroupLabel = gDialog.marginGroup.label; |
michael@0 | 283 | if (gPrintSettings.paperSizeUnit == gPrintSettingsInterface.kPaperSizeInches) { |
michael@0 | 284 | marginGroupLabel = marginGroupLabel.replace(/#1/, gDialog.strings["marginUnits.inches"]); |
michael@0 | 285 | gDoingMetric = false; |
michael@0 | 286 | } else { |
michael@0 | 287 | marginGroupLabel = marginGroupLabel.replace(/#1/, gDialog.strings["marginUnits.metric"]); |
michael@0 | 288 | // Also, set global page dimensions for A4 paper, in millimeters (assumes portrait at this point). |
michael@0 | 289 | gPageWidth = 2100; |
michael@0 | 290 | gPageHeight = 2970; |
michael@0 | 291 | gDoingMetric = true; |
michael@0 | 292 | } |
michael@0 | 293 | gDialog.marginGroup.label = marginGroupLabel; |
michael@0 | 294 | |
michael@0 | 295 | print_orientation = gPrintSettings.orientation; |
michael@0 | 296 | print_margin_top = convertMarginInchesToUnits(gPrintSettings.marginTop, gDoingMetric); |
michael@0 | 297 | print_margin_left = convertMarginInchesToUnits(gPrintSettings.marginLeft, gDoingMetric); |
michael@0 | 298 | print_margin_right = convertMarginInchesToUnits(gPrintSettings.marginRight, gDoingMetric); |
michael@0 | 299 | print_margin_bottom = convertMarginInchesToUnits(gPrintSettings.marginBottom, gDoingMetric); |
michael@0 | 300 | |
michael@0 | 301 | if (gDoDebug) { |
michael@0 | 302 | dump("print_orientation "+print_orientation+"\n"); |
michael@0 | 303 | |
michael@0 | 304 | dump("print_margin_top "+print_margin_top+"\n"); |
michael@0 | 305 | dump("print_margin_left "+print_margin_left+"\n"); |
michael@0 | 306 | dump("print_margin_right "+print_margin_right+"\n"); |
michael@0 | 307 | dump("print_margin_bottom "+print_margin_bottom+"\n"); |
michael@0 | 308 | } |
michael@0 | 309 | |
michael@0 | 310 | if (print_orientation == gPrintSettingsInterface.kPortraitOrientation) { |
michael@0 | 311 | gDialog.orientation.selectedItem = gDialog.portrait; |
michael@0 | 312 | } else if (print_orientation == gPrintSettingsInterface.kLandscapeOrientation) { |
michael@0 | 313 | gDialog.orientation.selectedItem = gDialog.landscape; |
michael@0 | 314 | } |
michael@0 | 315 | |
michael@0 | 316 | // Set orientation the first time on a timeout so the dialog sizes to the |
michael@0 | 317 | // maximum height specified in the .xul file. Otherwise, if the user switches |
michael@0 | 318 | // from landscape to portrait, the content grows and the buttons are clipped. |
michael@0 | 319 | setTimeout( setOrientation, 0 ); |
michael@0 | 320 | |
michael@0 | 321 | gDialog.topInput.value = print_margin_top.toFixed(1); |
michael@0 | 322 | gDialog.bottomInput.value = print_margin_bottom.toFixed(1); |
michael@0 | 323 | gDialog.leftInput.value = print_margin_left.toFixed(1); |
michael@0 | 324 | gDialog.rightInput.value = print_margin_right.toFixed(1); |
michael@0 | 325 | changeMargins(); |
michael@0 | 326 | |
michael@0 | 327 | setHeaderFooter( gDialog.hLeftOption, gPrintSettings.headerStrLeft ); |
michael@0 | 328 | setHeaderFooter( gDialog.hCenterOption, gPrintSettings.headerStrCenter ); |
michael@0 | 329 | setHeaderFooter( gDialog.hRightOption, gPrintSettings.headerStrRight ); |
michael@0 | 330 | |
michael@0 | 331 | setHeaderFooter( gDialog.fLeftOption, gPrintSettings.footerStrLeft ); |
michael@0 | 332 | setHeaderFooter( gDialog.fCenterOption, gPrintSettings.footerStrCenter ); |
michael@0 | 333 | setHeaderFooter( gDialog.fRightOption, gPrintSettings.footerStrRight ); |
michael@0 | 334 | |
michael@0 | 335 | gDialog.scalingInput.value = (gPrintSettings.scaling * 100).toFixed(0); |
michael@0 | 336 | |
michael@0 | 337 | // Enable/disable widgets based in the information whether the selected |
michael@0 | 338 | // printer supports the matching feature or not |
michael@0 | 339 | if (isListOfPrinterFeaturesAvailable()) { |
michael@0 | 340 | if (gPrefs.getBoolPref("print.tmp.printerfeatures." + gPrintSettings.printerName + ".can_change_orientation")) |
michael@0 | 341 | gDialog.orientation.removeAttribute("disabled"); |
michael@0 | 342 | else |
michael@0 | 343 | gDialog.orientation.setAttribute("disabled","true"); |
michael@0 | 344 | } |
michael@0 | 345 | |
michael@0 | 346 | // Give initial focus to the orientation radio group. |
michael@0 | 347 | // Done on a timeout due to to bug 103197. |
michael@0 | 348 | setTimeout( function() { gDialog.orientation.focus(); }, 0 ); |
michael@0 | 349 | } |
michael@0 | 350 | |
michael@0 | 351 | //--------------------------------------------------- |
michael@0 | 352 | function onLoad() |
michael@0 | 353 | { |
michael@0 | 354 | // Init gDialog. |
michael@0 | 355 | initDialog(); |
michael@0 | 356 | |
michael@0 | 357 | if (window.arguments[0] != null) { |
michael@0 | 358 | gPrintSettings = window.arguments[0].QueryInterface(Components.interfaces.nsIPrintSettings); |
michael@0 | 359 | paramBlock = window.arguments[1].QueryInterface(Components.interfaces.nsIDialogParamBlock); |
michael@0 | 360 | } else if (gDoDebug) { |
michael@0 | 361 | alert("window.arguments[0] == null!"); |
michael@0 | 362 | } |
michael@0 | 363 | |
michael@0 | 364 | // default return value is "cancel" |
michael@0 | 365 | paramBlock.SetInt(0, 0); |
michael@0 | 366 | |
michael@0 | 367 | if (gPrintSettings) { |
michael@0 | 368 | loadDialog(); |
michael@0 | 369 | } else if (gDoDebug) { |
michael@0 | 370 | alert("Could initialize gDialog, PrintSettings is null!"); |
michael@0 | 371 | } |
michael@0 | 372 | } |
michael@0 | 373 | |
michael@0 | 374 | function convertUnitsMarginToInches(aVal, aIsMetric) |
michael@0 | 375 | { |
michael@0 | 376 | if (aIsMetric) { |
michael@0 | 377 | return aVal / 25.4; |
michael@0 | 378 | } else { |
michael@0 | 379 | return aVal; |
michael@0 | 380 | } |
michael@0 | 381 | } |
michael@0 | 382 | |
michael@0 | 383 | function convertMarginInchesToUnits(aVal, aIsMetric) |
michael@0 | 384 | { |
michael@0 | 385 | if (aIsMetric) { |
michael@0 | 386 | return aVal * 25.4; |
michael@0 | 387 | } else { |
michael@0 | 388 | return aVal; |
michael@0 | 389 | } |
michael@0 | 390 | } |
michael@0 | 391 | |
michael@0 | 392 | //--------------------------------------------------- |
michael@0 | 393 | function onAccept() |
michael@0 | 394 | { |
michael@0 | 395 | |
michael@0 | 396 | if (gPrintSettings) { |
michael@0 | 397 | if ( gDialog.orientation.selectedItem == gDialog.portrait ) { |
michael@0 | 398 | gPrintSettings.orientation = gPrintSettingsInterface.kPortraitOrientation; |
michael@0 | 399 | } else { |
michael@0 | 400 | gPrintSettings.orientation = gPrintSettingsInterface.kLandscapeOrientation; |
michael@0 | 401 | } |
michael@0 | 402 | |
michael@0 | 403 | // save these out so they can be picked up by the device spec |
michael@0 | 404 | gPrintSettings.marginTop = convertUnitsMarginToInches(gDialog.topInput.value, gDoingMetric); |
michael@0 | 405 | gPrintSettings.marginLeft = convertUnitsMarginToInches(gDialog.leftInput.value, gDoingMetric); |
michael@0 | 406 | gPrintSettings.marginBottom = convertUnitsMarginToInches(gDialog.bottomInput.value, gDoingMetric); |
michael@0 | 407 | gPrintSettings.marginRight = convertUnitsMarginToInches(gDialog.rightInput.value, gDoingMetric); |
michael@0 | 408 | |
michael@0 | 409 | gPrintSettings.headerStrLeft = hfIdToValue(gDialog.hLeftOption); |
michael@0 | 410 | gPrintSettings.headerStrCenter = hfIdToValue(gDialog.hCenterOption); |
michael@0 | 411 | gPrintSettings.headerStrRight = hfIdToValue(gDialog.hRightOption); |
michael@0 | 412 | |
michael@0 | 413 | gPrintSettings.footerStrLeft = hfIdToValue(gDialog.fLeftOption); |
michael@0 | 414 | gPrintSettings.footerStrCenter = hfIdToValue(gDialog.fCenterOption); |
michael@0 | 415 | gPrintSettings.footerStrRight = hfIdToValue(gDialog.fRightOption); |
michael@0 | 416 | |
michael@0 | 417 | gPrintSettings.printBGColors = gDialog.printBG.checked; |
michael@0 | 418 | gPrintSettings.printBGImages = gDialog.printBG.checked; |
michael@0 | 419 | |
michael@0 | 420 | gPrintSettings.shrinkToFit = gDialog.shrinkToFit.checked; |
michael@0 | 421 | |
michael@0 | 422 | var scaling = document.getElementById("scalingInput").value; |
michael@0 | 423 | if (scaling < 10.0) { |
michael@0 | 424 | scaling = 10.0; |
michael@0 | 425 | } |
michael@0 | 426 | if (scaling > 500.0) { |
michael@0 | 427 | scaling = 500.0; |
michael@0 | 428 | } |
michael@0 | 429 | scaling /= 100.0; |
michael@0 | 430 | gPrintSettings.scaling = scaling; |
michael@0 | 431 | |
michael@0 | 432 | if (gDoDebug) { |
michael@0 | 433 | dump("******* Page Setup Accepting ******\n"); |
michael@0 | 434 | dump("print_margin_top "+gDialog.topInput.value+"\n"); |
michael@0 | 435 | dump("print_margin_left "+gDialog.leftInput.value+"\n"); |
michael@0 | 436 | dump("print_margin_right "+gDialog.bottomInput.value+"\n"); |
michael@0 | 437 | dump("print_margin_bottom "+gDialog.rightInput.value+"\n"); |
michael@0 | 438 | } |
michael@0 | 439 | } |
michael@0 | 440 | |
michael@0 | 441 | // set return value to "ok" |
michael@0 | 442 | if (paramBlock) { |
michael@0 | 443 | paramBlock.SetInt(0, 1); |
michael@0 | 444 | } else { |
michael@0 | 445 | dump("*** FATAL ERROR: No paramBlock\n"); |
michael@0 | 446 | } |
michael@0 | 447 | |
michael@0 | 448 | var flags = gPrintSettingsInterface.kInitSaveMargins | |
michael@0 | 449 | gPrintSettingsInterface.kInitSaveHeaderLeft | |
michael@0 | 450 | gPrintSettingsInterface.kInitSaveHeaderCenter | |
michael@0 | 451 | gPrintSettingsInterface.kInitSaveHeaderRight | |
michael@0 | 452 | gPrintSettingsInterface.kInitSaveFooterLeft | |
michael@0 | 453 | gPrintSettingsInterface.kInitSaveFooterCenter | |
michael@0 | 454 | gPrintSettingsInterface.kInitSaveFooterRight | |
michael@0 | 455 | gPrintSettingsInterface.kInitSaveBGColors | |
michael@0 | 456 | gPrintSettingsInterface.kInitSaveBGImages | |
michael@0 | 457 | gPrintSettingsInterface.kInitSaveInColor | |
michael@0 | 458 | gPrintSettingsInterface.kInitSaveReversed | |
michael@0 | 459 | gPrintSettingsInterface.kInitSaveOrientation | |
michael@0 | 460 | gPrintSettingsInterface.kInitSaveOddEvenPages | |
michael@0 | 461 | gPrintSettingsInterface.kInitSaveShrinkToFit | |
michael@0 | 462 | gPrintSettingsInterface.kInitSaveScaling; |
michael@0 | 463 | |
michael@0 | 464 | gPrintService.savePrintSettingsToPrefs(gPrintSettings, true, flags); |
michael@0 | 465 | |
michael@0 | 466 | return true; |
michael@0 | 467 | } |
michael@0 | 468 | |
michael@0 | 469 | //--------------------------------------------------- |
michael@0 | 470 | function onCancel() |
michael@0 | 471 | { |
michael@0 | 472 | // set return value to "cancel" |
michael@0 | 473 | if (paramBlock) { |
michael@0 | 474 | paramBlock.SetInt(0, 0); |
michael@0 | 475 | } else { |
michael@0 | 476 | dump("*** FATAL ERROR: No paramBlock\n"); |
michael@0 | 477 | } |
michael@0 | 478 | |
michael@0 | 479 | return true; |
michael@0 | 480 | } |
michael@0 | 481 |