!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is Mozilla Communicator client code, released
16 * March 31, 1998.
17 *
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998-1999
21 * the Initial Developer. All Rights Reserved.
22 *
23 * Contributor(s):
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
39 /* This is where functions related to the print engine are kept */
40
41 /* globals for a particular window */
42 var printEngineContractID = "@mozilla.org/messenger/msgPrintEngine;1";
43 var printEngineWindow;
44 var printEngine;
45 var printSettings = null;
46
47 const kMsgBundle = "chrome://messenger/locale/messenger.properties";
48
49 /* Functions related to startup */
OnLoadPrintEngine
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
50 function OnLoadPrintEngine()
51 {
52 PrintEngineCreateGlobals();
53 InitPrintEngineWindow();
54 printEngine.startPrintOperation(printSettings);
55 }
56
PrintEngineCreateGlobals
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
57 function PrintEngineCreateGlobals()
58 {
59 /* get the print engine instance */
60 printEngine = Components.classes[printEngineContractID].createInstance();
61 printEngine = printEngine.QueryInterface(Components.interfaces.nsIMsgPrintEngine);
62 printSettings = PrintUtils.getPrintSettings();
63 if (printSettings) {
64 printSettings.isCancelled = false;
65 }
66 }
67
getWebNavigation
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
68 function getWebNavigation()
69 {
70 try {
71 return getPPBrowser().webNavigation;
72 } catch (e) {
73 return null;
74 }
75 }
76
getNavToolbox
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
77 function getNavToolbox()
78 {
79 return document.getElementById("content");
80 }
81
getPPBrowser
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
82 function getPPBrowser()
83 {
84 return document.getElementById("content");
85 }
86
getBundle
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
87 function getBundle(aURI)
88 {
89 if (!aURI)
90 return null;
91
92 var bundle = null;
93 try
94 {
95 var strBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"].
96 getService(Components.interfaces.nsIStringBundleService);
97 bundle = strBundleService.createBundle(aURI);
98 }
99 catch (ex)
100 {
101 bundle = null;
102 debug("Exception getting bundle " + aURI + ": " + ex);
103 }
104
105 return bundle;
106 }
107
setPPTitle
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
108 function setPPTitle(aTitle)
109 {
110 var title = aTitle;
111 try {
112 var gBrandBundle = document.getElementById("bundle_brand");
113 if (gBrandBundle) {
114 var msgBundle = this.getBundle(kMsgBundle);
115 if (msgBundle) {
116 var brandStr = gBrandBundle.getString("brandShortName")
117 var array = [title, brandStr];
118 title = msgBundle.formatStringFromName("PreviewTitle", array, array.length);
119 }
120 }
121 } catch (e) {}
122 document.title = title;
123 }
124
onEnterPrintPreview
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
125 function onEnterPrintPreview()
126 {
127 setPPTitle(getWebNavigation().document.title);
128 printEngine.showWindow(true);
129 }
130
onExitPrintPreview
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
131 function onExitPrintPreview()
132 {
133 window.close();
134 }
135
136 // Pref listener constants
137 const gStartupPPObserver =
138 {
observe
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
139 observe: function(subject, topic, prefName)
140 {
141 PrintUtils.printPreview(onEnterPrintPreview, onExitPrintPreview);
142 }
143 };
144
InitPrintEngineWindow
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
145 function InitPrintEngineWindow()
146 {
147 /* Tell the nsIPrintEngine object what window is rendering the email */
148 printEngine.setWindow(window);
149
150 /* hide the printEngine window. see bug #73995 */
151
152 /* See if we got arguments.
153 * Window was opened via window.openDialog. Copy argument
154 * and perform compose initialization
155 */
156 if ( window.arguments && window.arguments[0] != null ) {
157 var numSelected = window.arguments[0];
158 var uriArray = window.arguments[1];
159 var statusFeedback = window.arguments[2];
160
161 if (window.arguments[3]) {
162 printEngine.doPrintPreview = window.arguments[3];
163 } else {
164 printEngine.doPrintPreview = false;
165 }
166 printEngine.showWindow(false);
167
168 if (window.arguments.length > 4) {
169 printEngine.setMsgType(window.arguments[4]);
170 } else {
171 printEngine.setMsgType(Components.interfaces.nsIMsgPrintEngine.MNAB_START);
172 }
173
174 if (window.arguments.length > 5) {
175 printEngine.setParentWindow(window.arguments[5]);
176 } else {
177 printEngine.setParentWindow(null);
178 }
179
180 printEngine.setStatusFeedback(statusFeedback);
181 printEngine.setStartupPPObserver(gStartupPPObserver);
182
183 if (numSelected > 0) {
184 printEngine.setPrintURICount(numSelected);
185 for (var i = 0; i < numSelected; i++) {
186 printEngine.addPrintURI(uriArray[i]);
187 //dump(uriArray[i] + "\n");
188 }
189 }
190 }
191 }
192
ClearPrintEnginePane
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
193 function ClearPrintEnginePane()
194 {
195 if (window.frames["content"].location.href != "about:blank")
196 window.frames["content"].location.href = "about:blank";
197 }
198
StopUrls
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
199 function StopUrls()
200 {
201 printEngine.stopUrls();
202 }
203
PrintEnginePrint
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
204 function PrintEnginePrint()
205 {
206 printEngineWindow = window.openDialog("chrome://messenger/content/msgPrintEngine.xul", "", "chrome,dialog=no,all,centerscreen", false);
207 }
208
PrintEnginePrintPreview
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
209 function PrintEnginePrintPreview()
210 {
211 printEngineWindow = window.openDialog("chrome://messenger/content/msgPrintEngine.xul", "", "chrome,dialog=no,all,centerscreen", true);
212 }