author | dcherepanov |
Tue, 17 Feb 2009 14:30:52 +0300 | |
changeset 2456 | 45ee87a35349 |
parent 1954 | b93b85df3211 |
child 2464 | 3c6755bdc55f |
permissions | -rw-r--r-- |
2 | 1 |
/* |
1954 | 2 |
* Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
1954 | 26 |
#include "awt.h" |
2 | 27 |
#include "awt_PrintDialog.h" |
28 |
#include "awt_Dialog.h" |
|
29 |
#include "awt_PrintControl.h" |
|
30 |
#include "awt_Window.h" |
|
31 |
#include "ComCtl32Util.h" |
|
32 |
#include <sun_awt_windows_WPrintDialog.h> |
|
33 |
#include <sun_awt_windows_WPrintDialogPeer.h> |
|
34 |
||
35 |
jfieldID AwtPrintDialog::controlID; |
|
36 |
jfieldID AwtPrintDialog::parentID; |
|
37 |
||
38 |
jmethodID AwtPrintDialog::setHWndMID; |
|
39 |
||
40 |
BOOL |
|
41 |
AwtPrintDialog::PrintDlg(LPPRINTDLG data) { |
|
42 |
return static_cast<BOOL>(reinterpret_cast<INT_PTR>( |
|
43 |
AwtToolkit::GetInstance().InvokeFunction( |
|
1954 | 44 |
reinterpret_cast<void *(*)(void *)>(::PrintDlg), data))); |
2 | 45 |
} |
46 |
||
47 |
LRESULT CALLBACK PrintDialogWndProc(HWND hWnd, UINT message, |
|
48 |
WPARAM wParam, LPARAM lParam) |
|
49 |
{ |
|
50 |
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); |
|
51 |
||
52 |
switch (message) { |
|
53 |
case WM_COMMAND: { |
|
54 |
if ((LOWORD(wParam) == IDOK) || |
|
55 |
(LOWORD(wParam) == IDCANCEL)) |
|
56 |
{ |
|
57 |
// If we recieve on of these two notifications, the dialog |
|
58 |
// is about to be closed. It's time to unblock all the |
|
59 |
// windows blocked by this dialog, as doing so from the |
|
60 |
// WM_DESTROY handler is too late |
|
61 |
jobject peer = (jobject)(::GetProp(hWnd, ModalDialogPeerProp)); |
|
62 |
env->CallVoidMethod(peer, AwtPrintDialog::setHWndMID, (jlong)0); |
|
63 |
} |
|
64 |
break; |
|
65 |
} |
|
66 |
} |
|
67 |
||
2456
45ee87a35349
6792023: Print suspends on Windows 2000 Pro since 6u12 b01
dcherepanov
parents:
1954
diff
changeset
|
68 |
WNDPROC lpfnWndProc = (WNDPROC)(::GetProp(hWnd, NativeDialogWndProcProp)); |
45ee87a35349
6792023: Print suspends on Windows 2000 Pro since 6u12 b01
dcherepanov
parents:
1954
diff
changeset
|
69 |
return ComCtl32Util::GetInstance().DefWindowProc(lpfnWndProc, hWnd, message, wParam, lParam); |
2 | 70 |
} |
71 |
||
72 |
static UINT_PTR CALLBACK |
|
73 |
PrintDialogHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam) |
|
74 |
{ |
|
75 |
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); |
|
76 |
||
77 |
TRY; |
|
78 |
||
79 |
switch(uiMsg) { |
|
80 |
case WM_INITDIALOG: { |
|
81 |
PRINTDLG *pd = (PRINTDLG *)lParam; |
|
82 |
jobject peer = (jobject)(pd->lCustData); |
|
83 |
env->CallVoidMethod(peer, AwtPrintDialog::setHWndMID, |
|
84 |
(jlong)hdlg); |
|
85 |
::SetProp(hdlg, ModalDialogPeerProp, reinterpret_cast<HANDLE>(peer)); |
|
86 |
||
87 |
// fix for 4632159 - disable CS_SAVEBITS |
|
88 |
DWORD style = ::GetClassLong(hdlg, GCL_STYLE); |
|
89 |
::SetClassLong(hdlg,GCL_STYLE, style & ~CS_SAVEBITS); |
|
90 |
||
91 |
::SetFocus(hdlg); |
|
92 |
||
93 |
// set appropriate icon for parentless dialogs |
|
94 |
jobject awtParent = env->GetObjectField(peer, AwtPrintDialog::parentID); |
|
95 |
if (awtParent == NULL) { |
|
96 |
::SendMessage(hdlg, WM_SETICON, (WPARAM)ICON_BIG, |
|
97 |
(LPARAM)AwtToolkit::GetInstance().GetAwtIcon()); |
|
98 |
} else { |
|
99 |
env->DeleteLocalRef(awtParent); |
|
100 |
} |
|
101 |
||
102 |
// subclass dialog's parent to receive additional messages |
|
2456
45ee87a35349
6792023: Print suspends on Windows 2000 Pro since 6u12 b01
dcherepanov
parents:
1954
diff
changeset
|
103 |
WNDPROC lpfnWndProc = ComCtl32Util::GetInstance().SubclassHWND(hdlg, |
45ee87a35349
6792023: Print suspends on Windows 2000 Pro since 6u12 b01
dcherepanov
parents:
1954
diff
changeset
|
104 |
PrintDialogWndProc); |
45ee87a35349
6792023: Print suspends on Windows 2000 Pro since 6u12 b01
dcherepanov
parents:
1954
diff
changeset
|
105 |
::SetProp(hdlg, NativeDialogWndProcProp, reinterpret_cast<HANDLE>(lpfnWndProc)); |
2 | 106 |
|
107 |
break; |
|
108 |
} |
|
109 |
case WM_DESTROY: { |
|
2456
45ee87a35349
6792023: Print suspends on Windows 2000 Pro since 6u12 b01
dcherepanov
parents:
1954
diff
changeset
|
110 |
WNDPROC lpfnWndProc = (WNDPROC)(::GetProp(hdlg, NativeDialogWndProcProp)); |
2 | 111 |
ComCtl32Util::GetInstance().UnsubclassHWND(hdlg, |
112 |
PrintDialogWndProc, |
|
2456
45ee87a35349
6792023: Print suspends on Windows 2000 Pro since 6u12 b01
dcherepanov
parents:
1954
diff
changeset
|
113 |
lpfnWndProc); |
2 | 114 |
::RemoveProp(hdlg, ModalDialogPeerProp); |
2456
45ee87a35349
6792023: Print suspends on Windows 2000 Pro since 6u12 b01
dcherepanov
parents:
1954
diff
changeset
|
115 |
::RemoveProp(hdlg, NativeDialogWndProcProp); |
2 | 116 |
break; |
117 |
} |
|
118 |
} |
|
119 |
return FALSE; |
|
120 |
||
121 |
CATCH_BAD_ALLOC_RET(TRUE); |
|
122 |
} |
|
123 |
||
124 |
void AwtPrintDialog::_ToFront(void *param) |
|
125 |
{ |
|
126 |
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); |
|
127 |
||
128 |
jobject self = (jobject)param; |
|
129 |
HWND hdlg = (HWND)(env->GetLongField(self, AwtComponent::hwndID)); |
|
130 |
if (::IsWindow(hdlg)) |
|
131 |
{ |
|
132 |
::SetWindowPos(hdlg, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); |
|
133 |
} |
|
134 |
||
135 |
env->DeleteGlobalRef(self); |
|
136 |
} |
|
137 |
||
138 |
void AwtPrintDialog::_ToBack(void *param) |
|
139 |
{ |
|
140 |
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); |
|
141 |
||
142 |
jobject self = (jobject)param; |
|
143 |
HWND hdlg = (HWND)(env->GetLongField(self, AwtComponent::hwndID)); |
|
144 |
if (::IsWindow(hdlg)) |
|
145 |
{ |
|
146 |
::SetWindowPos(hdlg, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); |
|
147 |
} |
|
148 |
||
149 |
env->DeleteGlobalRef(self); |
|
150 |
} |
|
151 |
||
152 |
||
153 |
extern "C" { |
|
154 |
JNIEXPORT void JNICALL |
|
155 |
Java_sun_awt_windows_WPrintDialog_initIDs(JNIEnv *env, jclass cls) |
|
156 |
{ |
|
157 |
TRY; |
|
158 |
||
159 |
AwtPrintDialog::controlID = |
|
160 |
env->GetFieldID(cls, "pjob", "Ljava/awt/print/PrinterJob;"); |
|
161 |
DASSERT(AwtPrintDialog::controlID != NULL); |
|
162 |
||
163 |
AwtPrintControl::initIDs(env, cls); |
|
164 |
||
165 |
CATCH_BAD_ALLOC; |
|
166 |
} |
|
167 |
||
168 |
JNIEXPORT void JNICALL |
|
169 |
Java_sun_awt_windows_WPrintDialog_setPeer(JNIEnv *env, jobject target, |
|
170 |
jobject peer) |
|
171 |
{ |
|
172 |
TRY; |
|
173 |
||
174 |
env->SetObjectField(target, AwtComponent::peerID, peer); |
|
175 |
||
176 |
CATCH_BAD_ALLOC; |
|
177 |
} |
|
178 |
||
179 |
JNIEXPORT void JNICALL |
|
180 |
Java_sun_awt_windows_WPrintDialogPeer_initIDs(JNIEnv *env, jclass cls) |
|
181 |
{ |
|
182 |
TRY; |
|
183 |
||
184 |
AwtPrintDialog::parentID = |
|
185 |
env->GetFieldID(cls, "parent", "Lsun/awt/windows/WComponentPeer;"); |
|
186 |
AwtPrintDialog::setHWndMID = |
|
187 |
env->GetMethodID(cls, "setHWnd", "(J)V"); |
|
188 |
||
189 |
DASSERT(AwtPrintDialog::parentID != NULL); |
|
190 |
DASSERT(AwtPrintDialog::setHWndMID != NULL); |
|
191 |
||
192 |
CATCH_BAD_ALLOC; |
|
193 |
} |
|
194 |
||
195 |
JNIEXPORT jboolean JNICALL |
|
196 |
Java_sun_awt_windows_WPrintDialogPeer__1show(JNIEnv *env, jobject peer) |
|
197 |
{ |
|
198 |
TRY; |
|
199 |
||
200 |
jboolean result = JNI_FALSE; |
|
201 |
||
202 |
// as peer object is used later on another thread, create a global ref |
|
203 |
jobject peerGlobalRef = env->NewGlobalRef(peer); |
|
204 |
DASSERT(peerGlobalRef != NULL); |
|
205 |
jobject target = env->GetObjectField(peerGlobalRef, AwtObject::targetID); |
|
206 |
DASSERT(target != NULL); |
|
207 |
jobject parent = env->GetObjectField(peerGlobalRef, AwtPrintDialog::parentID); |
|
208 |
jobject control = env->GetObjectField(target, AwtPrintDialog::controlID); |
|
209 |
DASSERT(control != NULL); |
|
210 |
||
211 |
AwtComponent *awtParent = (parent != NULL) ? (AwtComponent *)JNI_GET_PDATA(parent) : NULL; |
|
212 |
HWND hwndOwner = awtParent ? awtParent->GetHWnd() : NULL; |
|
213 |
||
214 |
PRINTDLG pd; |
|
215 |
memset(&pd, 0, sizeof(PRINTDLG)); |
|
216 |
pd.lStructSize = sizeof(PRINTDLG); |
|
217 |
pd.lCustData = (LPARAM)peerGlobalRef; |
|
218 |
BOOL ret = AwtPrintControl::InitPrintDialog(env, control, pd); |
|
219 |
if (!ret) { |
|
220 |
/* Couldn't use the printer, or spooler isn't running |
|
221 |
* Call Page dialog with ' PD_RETURNDEFAULT' so it doesn't try |
|
222 |
* to show the dialog, but does prompt the user to install a printer. |
|
223 |
* If this returns false, then they declined and we just return. |
|
224 |
*/ |
|
225 |
pd.Flags = PD_RETURNDEFAULT | PD_RETURNDC; |
|
226 |
ret = AwtPrintDialog::PrintDlg(&pd); |
|
227 |
} |
|
228 |
if (!ret) { |
|
229 |
result = JNI_FALSE; |
|
230 |
} |
|
231 |
else |
|
232 |
{ |
|
233 |
pd.lpfnPrintHook = (LPPRINTHOOKPROC)PrintDialogHookProc; |
|
234 |
pd.lpfnSetupHook = (LPSETUPHOOKPROC)PrintDialogHookProc; |
|
235 |
pd.Flags |= PD_ENABLESETUPHOOK | PD_ENABLEPRINTHOOK; |
|
236 |
/* |
|
237 |
Fix for 6488834. |
|
238 |
To disable Win32 native parent modality we have to set |
|
239 |
hwndOwner field to either NULL or some hidden window. For |
|
240 |
parentless dialogs we use NULL to show them in the taskbar, |
|
241 |
and for all other dialogs AwtToolkit's HWND is used. |
|
242 |
*/ |
|
243 |
if (awtParent != NULL) |
|
244 |
{ |
|
245 |
pd.hwndOwner = AwtToolkit::GetInstance().GetHWnd(); |
|
246 |
} |
|
247 |
else |
|
248 |
{ |
|
249 |
pd.hwndOwner = NULL; |
|
250 |
} |
|
251 |
||
252 |
AwtDialog::CheckInstallModalHook(); |
|
253 |
||
254 |
BOOL ret = AwtPrintDialog::PrintDlg(&pd); |
|
255 |
if (ret) |
|
256 |
{ |
|
257 |
AwtPrintControl::UpdateAttributes(env, control, pd); |
|
258 |
result = JNI_TRUE; |
|
259 |
} |
|
260 |
else |
|
261 |
{ |
|
262 |
result = JNI_FALSE; |
|
263 |
} |
|
264 |
||
265 |
DASSERT(env->GetLongField(peer, AwtComponent::hwndID) == 0L); |
|
266 |
||
267 |
AwtDialog::CheckUninstallModalHook(); |
|
268 |
||
269 |
AwtDialog::ModalActivateNextWindow(NULL, target, peer); |
|
270 |
} |
|
271 |
||
272 |
env->DeleteGlobalRef(peerGlobalRef); |
|
273 |
env->DeleteLocalRef(target); |
|
274 |
if (parent != NULL) { |
|
275 |
env->DeleteLocalRef(parent); |
|
276 |
} |
|
277 |
env->DeleteLocalRef(control); |
|
278 |
||
279 |
return result; |
|
280 |
||
281 |
CATCH_BAD_ALLOC_RET(0); |
|
282 |
} |
|
283 |
||
284 |
JNIEXPORT void JNICALL |
|
285 |
Java_sun_awt_windows_WPrintDialogPeer_toFront(JNIEnv *env, jobject peer) |
|
286 |
{ |
|
287 |
TRY; |
|
288 |
||
289 |
AwtToolkit::GetInstance().SyncCall(AwtPrintDialog::_ToFront, |
|
290 |
(void *)(env->NewGlobalRef(peer))); |
|
291 |
// global ref is deleted in _ToFront |
|
292 |
||
293 |
CATCH_BAD_ALLOC; |
|
294 |
} |
|
295 |
||
296 |
JNIEXPORT void JNICALL |
|
297 |
Java_sun_awt_windows_WPrintDialogPeer_toBack(JNIEnv *env, jobject peer) |
|
298 |
{ |
|
299 |
TRY; |
|
300 |
||
301 |
AwtToolkit::GetInstance().SyncCall(AwtPrintDialog::_ToBack, |
|
302 |
(void *)(env->NewGlobalRef(peer))); |
|
303 |
// global ref is deleted in _ToBack |
|
304 |
||
305 |
CATCH_BAD_ALLOC; |
|
306 |
} |
|
307 |
||
308 |
} /* extern "C" */ |