home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 March / PCWorld_2005-03_cd.bin / komunikace / kmeleon / kmeleon09.exe / toolkit.jar / content / global / printPreviewProgress.js < prev    next >
Text File  |  2004-01-13  |  5KB  |  168 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "License"); you may not use this file except in
  5.  * compliance with the License.  You may obtain a copy of the License at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  10.  * for the specific language governing rights and limitations under the
  11.  * License.
  12.  *
  13.  * The Original Code is Mozilla Communicator client code, 
  14.  * released March 31, 1998. 
  15.  *
  16.  * The Initial Developer of the Original Code is Netscape Communications 
  17.  * Corporation.  Portions created by Netscape are 
  18.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  19.  * Reserved.
  20.  *
  21.  * Contributors:
  22.  *     Rod Spears <rods@netscape.com>
  23.  */
  24.  
  25. // dialog is just an array we'll use to store various properties from the dialog document...
  26. var dialog;
  27.  
  28. // the printProgress is a nsIPrintProgress object
  29. var printProgress = null; 
  30.  
  31. // random global variables...
  32. var targetFile;
  33.  
  34. var progressParams = null;
  35.  
  36. // all progress notifications are done through the nsIWebProgressListener implementation...
  37. var progressListener = {
  38.     onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus)
  39.     {
  40.       
  41.       if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP)
  42.       {
  43.         window.close();
  44.       }
  45.     },
  46.     
  47.     onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress)
  48.     {
  49.       if (progressParams)
  50.       {
  51.         dialog.title.crop = progressParams.docTitle ? "end" : "center";
  52.         dialog.title.value = progressParams.docTitle || progressParams.docURL;
  53.       }
  54.     },
  55.  
  56.       onLocationChange: function(aWebProgress, aRequest, aLocation)
  57.     {
  58.       // we can ignore this notification
  59.     },
  60.  
  61.     onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage)
  62.     {
  63.       if (aMessage != "")
  64.         dialog.title.setAttribute("value", aMessage);
  65.     },
  66.  
  67.     onSecurityChange: function(aWebProgress, aRequest, state)
  68.     {
  69.       // we can ignore this notification
  70.     },
  71.  
  72.     QueryInterface : function(iid)
  73.     {
  74.      if (iid.equals(Components.interfaces.nsIWebProgressListener) || iid.equals(Components.interfaces.nsISupportsWeakReference))
  75.       return this;
  76.      
  77.      throw Components.results.NS_NOINTERFACE;
  78.     }
  79. };
  80.  
  81. function onLoad() {
  82.     // Set global variables.
  83.     printProgress = window.arguments[0];
  84.  
  85.     if ( !printProgress ) {
  86.         dump( "Invalid argument to printPreviewProgress.xul\n" );
  87.         window.close()
  88.         return;
  89.     }
  90.  
  91.     dialog          = new Object;
  92.     dialog.strings  = new Array;
  93.     dialog.title      = document.getElementById("dialog.title");
  94.     dialog.titleLabel = document.getElementById("dialog.titleLabel");
  95.  
  96.     if (window.arguments[1]) {
  97.       progressParams = window.arguments[1].QueryInterface(Components.interfaces.nsIPrintProgressParams)
  98.       if (progressParams) {
  99.         dialog.title.crop = progressParams.docTitle ? "end" : "center";
  100.         dialog.title.value = progressParams.docTitle || progressParams.docURL;
  101.       }
  102.     }
  103.  
  104.     // set our web progress listener on the helper app launcher
  105.     printProgress.registerListener(progressListener);
  106.     moveToAlertPosition();
  107.  
  108.     //We need to delay the set title else dom will overwrite it
  109.     window.setTimeout(doneIniting, 100);
  110. }
  111.  
  112. function onUnload() 
  113. {
  114.   if (printProgress)
  115.   {
  116.    try 
  117.    {
  118.      printProgress.unregisterListener(progressListener);
  119.      printProgress = null;
  120.    }
  121.     
  122.    catch( exception ) {}
  123.   }
  124. }
  125.  
  126. function getString( stringId ) {
  127.    // Check if we've fetched this string already.
  128.    if (!(stringId in dialog.strings)) {
  129.       // Try to get it.
  130.       var elem = document.getElementById( "dialog.strings."+stringId );
  131.       try {
  132.         if ( elem
  133.            &&
  134.            elem.childNodes
  135.            &&
  136.            elem.childNodes[0]
  137.            &&
  138.            elem.childNodes[0].nodeValue ) {
  139.          dialog.strings[ stringId ] = elem.childNodes[0].nodeValue;
  140.         } else {
  141.           // If unable to fetch string, use an empty string.
  142.           dialog.strings[ stringId ] = "";
  143.         }
  144.       } catch (e) { dialog.strings[ stringId ] = ""; }
  145.    }
  146.    return dialog.strings[ stringId ];
  147. }
  148.  
  149. // If the user presses cancel, tell the app launcher and close the dialog...
  150. function onCancel () 
  151. {
  152.   // Cancel app launcher.
  153.    try 
  154.    {
  155.      printProgress.processCanceledByUser = true;
  156.    }
  157.    catch( exception ) {return true;}
  158.     
  159.   // don't Close up dialog by returning false, the backend will close the dialog when everything will be aborted.
  160.   return false;
  161. }
  162.  
  163. function doneIniting() 
  164. {
  165.   // called by function timeout in onLoad
  166.   printProgress.doneIniting();
  167. }
  168.