1 # -*- Mode
: C
; tab
-width
: 4; indent
-tabs
-mode
: nil
; c
-basic
-offset
: 2 -*-
2 # ***** BEGIN LICENSE BLOCK
*****
3 # Version
: MPL
1.1/GPL 2.0/LGPL
2.1
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/
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
15 # The Original Code is mozilla
.org printing front
-end
.
17 # The Initial Developer
of the Original Code is
18 # Netscape Communications Corporation
.
19 # Portions created by the Initial Developer are
Copyright (C
) 2002
20 # the Initial Developer
. All Rights Reserved
.
23 # Rod Spears
<rods
@netscape
.com
>
24 # Pierre Chanial
<p_ch
@verizon
.net
>
26 # Alternatively
, the contents
of this file may be used under the terms
of
27 # either the GNU General Public License Version
2 or
later (the
"GPL"), or
28 # the GNU Lesser General Public License Version
2.1 or
later (the
"LGPL"),
29 # in which
case the provisions
of the GPL or the LGPL are applicable instead
30 # of those above
. If you wish to allow
use of your version
of this file only
31 # under the terms
of either the GPL or the LGPL
, and not to allow others to
32 # use your version
of this file under the terms
of the MPL
, indicate your
33 # decision by deleting the provisions above and replace them
with the notice
34 # and other provisions required by the GPL or the LGPL
. If you
do not
delete
35 # the provisions above
, a recipient may
use your version
of this file under
36 # the terms
of any one
of the MPL
, the GPL or the LGPL
.
38 # ***** END LICENSE BLOCK
*****
40 // dialog is just an array we'll use to store various properties from the dialog document...
43 // the printProgress is a nsIPrintProgress object
44 var printProgress
= null;
46 // random global variables...
51 var progressParams
= null;
53 function elipseString(aStr
, doFront
)
55 if (aStr
.length
> 3 && (aStr
.substr(0, 3) == "..." || aStr
.substr(aStr
.length
-4, 3) == "..."))
59 if (aStr
.length
<= fixedLen
)
63 return "..." + aStr
.substr(aStr
.length
-fixedLen
, fixedLen
);
65 return aStr
.substr(0, fixedLen
) + "...";
68 // all progress notifications are done through the nsIWebProgressListener implementation...
69 var progressListener
= {
71 onStateChange: function (aWebProgress
, aRequest
, aStateFlags
, aStatus
)
73 if (aStateFlags
& Components
.interfaces
.nsIWebProgressListener
.STATE_STOP
)
77 onProgressChange: function (aWebProgress
, aRequest
, aCurSelfProgress
, aMaxSelfProgress
, aCurTotalProgress
, aMaxTotalProgress
)
81 var docTitleStr
= elipseString(progressParams
.docTitle
, false);
82 if (docTitleStr
!= docTitle
) {
83 docTitle
= docTitleStr
;
84 dialog
.title
.value
= docTitle
;
86 var docURLStr
= elipseString(progressParams
.docURL
, true);
87 if (docURLStr
!= docURL
&& dialog
.title
!= null) {
90 dialog
.title
.value
= docURLStr
;
94 onLocationChange: function (aWebProgress
, aRequest
, aLocation
) {},
95 onSecurityChange: function (aWebProgress
, aRequest
, state
) {},
97 onStatusChange: function (aWebProgress
, aRequest
, aStatus
, aMessage
)
100 dialog
.title
.setAttribute("value", aMessage
);
103 QueryInterface: function (iid
)
105 if (iid
.equals(Components
.interfaces
.nsIWebProgressListener
) || iid
.equals(Components
.interfaces
.nsISupportsWeakReference
))
107 throw Components
.results
.NS_NOINTERFACE
;
112 // Set global variables.
113 printProgress
= window
.arguments
[0];
114 if (window
.arguments
[1]) {
115 progressParams
= window
.arguments
[1].QueryInterface(Components
.interfaces
.nsIPrintProgressParams
)
116 if (progressParams
) {
117 docTitle
= elipseString(progressParams
.docTitle
, false);
118 docURL
= elipseString(progressParams
.docURL
, true);
122 if (!printProgress
) {
123 dump( "Invalid argument to printPreviewProgress.xul\n" );
129 dialog
.strings
= new Array
;
130 dialog
.title
= document
.getElementById("dialog.title");
131 dialog
.titleLabel
= document
.getElementById("dialog.titleLabel");
133 dialog
.title
.value
= docTitle
;
135 // set our web progress listener on the helper app launcher
136 printProgress
.registerListener(progressListener
);
137 moveToAlertPosition();
139 //We need to delay the set title else dom will overwrite it
140 window
.setTimeout(doneIniting
, 100);
148 printProgress
.unregisterListener(progressListener
);
149 printProgress
= null;
154 function getString (stringId
) {
155 // Check if we've fetched this string already.
156 if (!(stringId
in dialog
.strings
)) {
158 var elem
= document
.getElementById( "dialog.strings."+stringId
);
160 if (elem
&& elem
.childNodes
&& elem
.childNodes
[0] &&
161 elem
.childNodes
[0].nodeValue
)
162 dialog
.strings
[stringId
] = elem
.childNodes
[0].nodeValue
;
163 // If unable to fetch string, use an empty string.
165 dialog
.strings
[stringId
] = "";
166 } catch (e
) { dialog
.strings
[stringId
] = ""; }
168 return dialog
.strings
[stringId
];
171 // If the user presses cancel, tell the app launcher and close the dialog...
174 // Cancel app launcher.
176 printProgress
.processCanceledByUser
= true;
178 catch(e
) {return true;}
180 // don't Close up dialog by returning false, the backend will close the dialog when everything will be aborted.
184 function doneIniting()
186 // called by function timeout in onLoad
187 printProgress
.doneIniting();