author | amenkov |
Wed, 20 Oct 2010 15:08:39 +0400 | |
changeset 7004 | 3f92ea1ffcac |
parent 6642 | 9d6f6dbb16a4 |
child 7018 | 154795ed10de |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 1996, 2009, Oracle and/or its affiliates. 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
1954 | 26 |
#include "awt.h" |
2 | 27 |
#include <signal.h> |
28 |
#include <windowsx.h> |
|
7004
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
29 |
#include <process.h> |
2 | 30 |
|
1954 | 31 |
//#if defined(_DEBUG) && defined(_MSC_VER) && _MSC_VER >= 1000 |
32 |
//#include <crtdbg.h> |
|
33 |
//#endif |
|
2 | 34 |
|
35 |
#define _JNI_IMPLEMENTATION_ |
|
1954 | 36 |
|
2 | 37 |
#include "awt_DrawingSurface.h" |
38 |
#include "awt_AWTEvent.h" |
|
39 |
#include "awt_Component.h" |
|
40 |
#include "awt_Canvas.h" |
|
41 |
#include "awt_Clipboard.h" |
|
42 |
#include "awt_Frame.h" |
|
43 |
#include "awt_Dialog.h" |
|
44 |
#include "awt_Font.h" |
|
45 |
#include "awt_Cursor.h" |
|
46 |
#include "awt_InputEvent.h" |
|
47 |
#include "awt_KeyEvent.h" |
|
48 |
#include "awt_List.h" |
|
49 |
#include "awt_Palette.h" |
|
50 |
#include "awt_PopupMenu.h" |
|
51 |
#include "awt_Toolkit.h" |
|
52 |
#include "awt_DesktopProperties.h" |
|
53 |
#include "awt_FileDialog.h" |
|
54 |
#include "CmdIDList.h" |
|
55 |
#include "awt_new.h" |
|
56 |
#include "debug_trace.h" |
|
57 |
#include "debug_mem.h" |
|
58 |
||
59 |
#include "ComCtl32Util.h" |
|
2472
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
60 |
#include "DllUtil.h" |
2 | 61 |
|
887 | 62 |
#include "D3DPipelineManager.h" |
63 |
||
2 | 64 |
#include <awt_DnDDT.h> |
65 |
#include <awt_DnDDS.h> |
|
66 |
||
67 |
#include <java_awt_Toolkit.h> |
|
68 |
#include <java_awt_event_InputMethodEvent.h> |
|
69 |
#include <java_awt_peer_ComponentPeer.h> |
|
70 |
||
71 |
extern void initScreens(JNIEnv *env); |
|
72 |
extern "C" void awt_dnd_initialize(); |
|
73 |
extern "C" void awt_dnd_uninitialize(); |
|
74 |
extern "C" void awt_clipboard_uninitialize(JNIEnv *env); |
|
75 |
extern "C" BOOL g_bUserHasChangedInputLang; |
|
76 |
||
77 |
extern CriticalSection windowMoveLock; |
|
78 |
extern BOOL windowMoveLockHeld; |
|
79 |
||
80 |
// Needed by JAWT: see awt_DrawingSurface.cpp. |
|
81 |
extern jclass jawtVImgClass; |
|
82 |
extern jclass jawtVSMgrClass; |
|
83 |
extern jclass jawtComponentClass; |
|
84 |
extern jfieldID jawtPDataID; |
|
85 |
extern jfieldID jawtSDataID; |
|
86 |
extern jfieldID jawtSMgrID; |
|
87 |
||
887 | 88 |
extern void DWMResetCompositionEnabled(); |
89 |
||
2 | 90 |
/************************************************************************ |
91 |
* Utilities |
|
92 |
*/ |
|
93 |
||
94 |
/* Initialize the Java VM instance variable when the library is |
|
95 |
first loaded */ |
|
7004
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
96 |
JavaVM *jvm = NULL; |
2 | 97 |
|
98 |
JNIEXPORT jint JNICALL |
|
99 |
JNI_OnLoad(JavaVM *vm, void *reserved) |
|
100 |
{ |
|
101 |
TRY; |
|
102 |
||
103 |
jvm = vm; |
|
104 |
return JNI_VERSION_1_2; |
|
105 |
||
106 |
CATCH_BAD_ALLOC_RET(0); |
|
107 |
} |
|
108 |
||
109 |
extern "C" JNIEXPORT jboolean JNICALL AWTIsHeadless() { |
|
110 |
static JNIEnv *env = NULL; |
|
111 |
static jboolean isHeadless; |
|
112 |
jmethodID headlessFn; |
|
113 |
jclass graphicsEnvClass; |
|
114 |
||
115 |
if (env == NULL) { |
|
116 |
env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); |
|
117 |
graphicsEnvClass = env->FindClass( |
|
118 |
"java/awt/GraphicsEnvironment"); |
|
119 |
if (graphicsEnvClass == NULL) { |
|
120 |
return JNI_TRUE; |
|
121 |
} |
|
122 |
headlessFn = env->GetStaticMethodID( |
|
123 |
graphicsEnvClass, "isHeadless", "()Z"); |
|
124 |
if (headlessFn == NULL) { |
|
125 |
return JNI_TRUE; |
|
126 |
} |
|
127 |
isHeadless = env->CallStaticBooleanMethod(graphicsEnvClass, |
|
128 |
headlessFn); |
|
129 |
} |
|
130 |
return isHeadless; |
|
131 |
} |
|
132 |
||
133 |
#define IDT_AWT_MOUSECHECK 0x101 |
|
134 |
||
135 |
static LPCTSTR szAwtToolkitClassName = TEXT("SunAwtToolkit"); |
|
136 |
||
6642
9d6f6dbb16a4
6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents:
5506
diff
changeset
|
137 |
static const int MOUSE_BUTTONS_WINDOWS_SUPPORTED = 5; //three standard buttons + XBUTTON1 + XBUTTON2. |
9d6f6dbb16a4
6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents:
5506
diff
changeset
|
138 |
|
2 | 139 |
UINT AwtToolkit::GetMouseKeyState() |
140 |
{ |
|
141 |
static BOOL mbSwapped = ::GetSystemMetrics(SM_SWAPBUTTON); |
|
142 |
UINT mouseKeyState = 0; |
|
143 |
||
144 |
if (HIBYTE(::GetKeyState(VK_CONTROL))) |
|
145 |
mouseKeyState |= MK_CONTROL; |
|
146 |
if (HIBYTE(::GetKeyState(VK_SHIFT))) |
|
147 |
mouseKeyState |= MK_SHIFT; |
|
148 |
if (HIBYTE(::GetKeyState(VK_LBUTTON))) |
|
149 |
mouseKeyState |= (mbSwapped ? MK_RBUTTON : MK_LBUTTON); |
|
150 |
if (HIBYTE(::GetKeyState(VK_RBUTTON))) |
|
151 |
mouseKeyState |= (mbSwapped ? MK_LBUTTON : MK_RBUTTON); |
|
152 |
if (HIBYTE(::GetKeyState(VK_MBUTTON))) |
|
153 |
mouseKeyState |= MK_MBUTTON; |
|
154 |
return mouseKeyState; |
|
155 |
} |
|
156 |
||
157 |
// |
|
158 |
// Normal ::GetKeyboardState call only works if current thread has |
|
159 |
// a message pump, so provide a way for other threads to get |
|
160 |
// the keyboard state |
|
161 |
// |
|
162 |
void AwtToolkit::GetKeyboardState(PBYTE keyboardState) |
|
163 |
{ |
|
164 |
CriticalSection::Lock l(AwtToolkit::GetInstance().m_lockKB); |
|
165 |
DASSERT(!IsBadWritePtr(keyboardState, KB_STATE_SIZE)); |
|
166 |
memcpy(keyboardState, AwtToolkit::GetInstance().m_lastKeyboardState, |
|
167 |
KB_STATE_SIZE); |
|
168 |
} |
|
169 |
||
170 |
void AwtToolkit::SetBusy(BOOL busy) { |
|
171 |
||
172 |
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); |
|
173 |
||
174 |
static jclass awtAutoShutdownClass = NULL; |
|
175 |
static jmethodID notifyBusyMethodID = NULL; |
|
176 |
static jmethodID notifyFreeMethodID = NULL; |
|
177 |
||
178 |
if (awtAutoShutdownClass == NULL) { |
|
179 |
jclass awtAutoShutdownClassLocal = env->FindClass("sun/awt/AWTAutoShutdown"); |
|
180 |
if (!JNU_IsNull(env, safe_ExceptionOccurred(env))) { |
|
181 |
env->ExceptionDescribe(); |
|
182 |
env->ExceptionClear(); |
|
183 |
} |
|
184 |
DASSERT(awtAutoShutdownClassLocal != NULL); |
|
185 |
if (awtAutoShutdownClassLocal == NULL) { |
|
186 |
return; |
|
187 |
} |
|
188 |
||
189 |
awtAutoShutdownClass = (jclass)env->NewGlobalRef(awtAutoShutdownClassLocal); |
|
190 |
env->DeleteLocalRef(awtAutoShutdownClassLocal); |
|
191 |
||
192 |
notifyBusyMethodID = env->GetStaticMethodID(awtAutoShutdownClass, |
|
193 |
"notifyToolkitThreadBusy", "()V"); |
|
194 |
if (!JNU_IsNull(env, safe_ExceptionOccurred(env))) { |
|
195 |
env->ExceptionDescribe(); |
|
196 |
env->ExceptionClear(); |
|
197 |
} |
|
198 |
notifyFreeMethodID = env->GetStaticMethodID(awtAutoShutdownClass, |
|
199 |
"notifyToolkitThreadFree", "()V"); |
|
200 |
if (!JNU_IsNull(env, safe_ExceptionOccurred(env))) { |
|
201 |
env->ExceptionDescribe(); |
|
202 |
env->ExceptionClear(); |
|
203 |
} |
|
204 |
DASSERT(notifyBusyMethodID != NULL); |
|
205 |
DASSERT(notifyFreeMethodID != NULL); |
|
206 |
if (notifyBusyMethodID == NULL || notifyFreeMethodID == NULL) { |
|
207 |
return; |
|
208 |
} |
|
209 |
} /* awtAutoShutdownClass == NULL*/ |
|
210 |
||
211 |
if (busy) { |
|
212 |
env->CallStaticVoidMethod(awtAutoShutdownClass, |
|
213 |
notifyBusyMethodID); |
|
214 |
} else { |
|
215 |
env->CallStaticVoidMethod(awtAutoShutdownClass, |
|
216 |
notifyFreeMethodID); |
|
217 |
} |
|
218 |
||
219 |
if (!JNU_IsNull(env, safe_ExceptionOccurred(env))) { |
|
220 |
env->ExceptionDescribe(); |
|
221 |
env->ExceptionClear(); |
|
222 |
} |
|
223 |
} |
|
224 |
||
225 |
BOOL AwtToolkit::activateKeyboardLayout(HKL hkl) { |
|
226 |
// This call should succeed in case of one of the following: |
|
227 |
// 1. Win 9x |
|
228 |
// 2. NT with that HKL already loaded |
|
229 |
HKL prev = ::ActivateKeyboardLayout(hkl, 0); |
|
230 |
||
231 |
// If the above call fails, try loading the layout in case of NT |
|
1954 | 232 |
if (!prev) { |
2 | 233 |
// create input locale string, e.g., "00000409", from hkl. |
234 |
TCHAR inputLocale[9]; |
|
235 |
TCHAR buf[9]; |
|
236 |
_tcscpy(inputLocale, TEXT("00000000")); |
|
237 |
||
238 |
// 64-bit: ::LoadKeyboardLayout() is such a weird API - a string of |
|
239 |
// the hex value you want?! Here we're converting our HKL value to |
|
240 |
// a string. Hopefully there is no 64-bit trouble. |
|
241 |
_i64tot(reinterpret_cast<INT_PTR>(hkl), buf, 16); |
|
242 |
size_t len = _tcslen(buf); |
|
243 |
memcpy(&inputLocale[8-len], buf, len); |
|
244 |
||
245 |
// load and activate the keyboard layout |
|
246 |
hkl = ::LoadKeyboardLayout(inputLocale, 0); |
|
247 |
if (hkl != 0) { |
|
248 |
prev = ::ActivateKeyboardLayout(hkl, 0); |
|
249 |
} |
|
250 |
} |
|
251 |
||
252 |
return (prev != 0); |
|
253 |
} |
|
254 |
||
255 |
/************************************************************************ |
|
256 |
* Exported functions |
|
257 |
*/ |
|
258 |
||
259 |
extern "C" BOOL APIENTRY DllMain(HANDLE hInstance, DWORD ul_reason_for_call, |
|
260 |
LPVOID) |
|
261 |
{ |
|
262 |
// Don't use the TRY and CATCH_BAD_ALLOC_RET macros if we're detaching |
|
263 |
// the library. Doing so causes awt.dll to call back into the VM during |
|
264 |
// shutdown. This crashes the HotSpot VM. |
|
265 |
switch (ul_reason_for_call) { |
|
266 |
case DLL_PROCESS_ATTACH: |
|
267 |
TRY; |
|
268 |
AwtToolkit::GetInstance().SetModuleHandle((HMODULE)hInstance); |
|
269 |
CATCH_BAD_ALLOC_RET(FALSE); |
|
270 |
break; |
|
271 |
case DLL_PROCESS_DETACH: |
|
272 |
#ifdef DEBUG |
|
273 |
DTrace_DisableMutex(); |
|
274 |
DMem_DisableMutex(); |
|
275 |
#endif DEBUG |
|
276 |
break; |
|
277 |
} |
|
278 |
return TRUE; |
|
279 |
} |
|
280 |
||
281 |
/************************************************************************ |
|
282 |
* AwtToolkit fields |
|
283 |
*/ |
|
284 |
||
285 |
AwtToolkit AwtToolkit::theInstance; |
|
286 |
||
287 |
/* ids for WToolkit fields accessed from native code */ |
|
288 |
jmethodID AwtToolkit::windowsSettingChangeMID; |
|
289 |
jmethodID AwtToolkit::displayChangeMID; |
|
290 |
/* ids for Toolkit methods */ |
|
291 |
jmethodID AwtToolkit::getDefaultToolkitMID; |
|
292 |
jmethodID AwtToolkit::getFontMetricsMID; |
|
293 |
jmethodID AwtToolkit::insetsMID; |
|
294 |
||
295 |
/************************************************************************ |
|
296 |
* AwtToolkit methods |
|
297 |
*/ |
|
298 |
||
299 |
AwtToolkit::AwtToolkit() { |
|
300 |
m_localPump = FALSE; |
|
301 |
m_mainThreadId = 0; |
|
302 |
m_toolkitHWnd = NULL; |
|
303 |
m_inputMethodHWnd = NULL; |
|
304 |
m_verbose = FALSE; |
|
305 |
m_isActive = TRUE; |
|
306 |
m_isDisposed = FALSE; |
|
307 |
||
308 |
m_vmSignalled = FALSE; |
|
309 |
||
310 |
m_isDynamicLayoutSet = FALSE; |
|
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
311 |
m_areExtraMouseButtonsEnabled = TRUE; |
2 | 312 |
|
313 |
m_verifyComponents = FALSE; |
|
314 |
m_breakOnError = FALSE; |
|
315 |
||
316 |
m_breakMessageLoop = FALSE; |
|
317 |
m_messageLoopResult = 0; |
|
318 |
||
319 |
m_lastMouseOver = NULL; |
|
320 |
m_mouseDown = FALSE; |
|
321 |
||
322 |
m_hGetMessageHook = 0; |
|
2472
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
323 |
m_hMouseLLHook = 0; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
324 |
m_lastWindowUnderMouse = NULL; |
2 | 325 |
m_timer = 0; |
326 |
||
327 |
m_cmdIDs = new AwtCmdIDList(); |
|
328 |
m_pModalDialog = NULL; |
|
329 |
m_peer = NULL; |
|
330 |
m_dllHandle = NULL; |
|
331 |
||
332 |
m_displayChanged = FALSE; |
|
105
e08ac2105adc
6595651: Focus transfers broken for applications embedding AWT across processes
son
parents:
2
diff
changeset
|
333 |
m_embedderProcessID = 0; |
2 | 334 |
|
335 |
// XXX: keyboard mapping should really be moved out of AwtComponent |
|
336 |
AwtComponent::InitDynamicKeyMapTable(); |
|
337 |
||
338 |
// initialize kb state array |
|
339 |
::GetKeyboardState(m_lastKeyboardState); |
|
340 |
||
341 |
m_waitEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL); |
|
342 |
eventNumber = 0; |
|
343 |
} |
|
344 |
||
345 |
AwtToolkit::~AwtToolkit() { |
|
346 |
/* |
|
347 |
* The code has been moved to AwtToolkit::Dispose() method. |
|
348 |
*/ |
|
349 |
} |
|
350 |
||
351 |
HWND AwtToolkit::CreateToolkitWnd(LPCTSTR name) |
|
352 |
{ |
|
353 |
HWND hwnd = CreateWindow( |
|
354 |
szAwtToolkitClassName, |
|
355 |
(LPCTSTR)name, /* window name */ |
|
356 |
WS_DISABLED, /* window style */ |
|
357 |
-1, -1, /* position of window */ |
|
358 |
0, 0, /* width and height */ |
|
359 |
NULL, NULL, /* hWndParent and hWndMenu */ |
|
360 |
GetModuleHandle(), |
|
361 |
NULL); /* lpParam */ |
|
362 |
DASSERT(hwnd != NULL); |
|
363 |
return hwnd; |
|
364 |
} |
|
365 |
||
7004
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
366 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
367 |
struct ToolkitThreadProc_Data { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
368 |
bool result; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
369 |
HANDLE hCompleted; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
370 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
371 |
jobject thread; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
372 |
}; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
373 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
374 |
void ToolkitThreadProc(void *param) |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
375 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
376 |
ToolkitThreadProc_Data *data = (ToolkitThreadProc_Data *)param; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
377 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
378 |
bool bNotified = false; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
379 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
380 |
JNIEnv *env; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
381 |
JavaVMAttachArgs attachArgs; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
382 |
attachArgs.version = JNI_VERSION_1_2; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
383 |
attachArgs.name = "AWT-Windows"; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
384 |
attachArgs.group = NULL; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
385 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
386 |
jint res = jvm->AttachCurrentThreadAsDaemon((void **)&env, &attachArgs); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
387 |
if (res < 0) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
388 |
return; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
389 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
390 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
391 |
jobject thread = env->NewGlobalRef(data->thread); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
392 |
if (thread != NULL) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
393 |
jclass cls = env->GetObjectClass(thread); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
394 |
if (cls != NULL) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
395 |
jmethodID runId = env->GetMethodID(cls, "run", "()V"); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
396 |
if (runId != NULL) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
397 |
data->result = true; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
398 |
::SetEvent(data->hCompleted); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
399 |
bNotified = true; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
400 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
401 |
env->CallVoidMethod(thread, runId); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
402 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
403 |
if (env->ExceptionCheck()) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
404 |
env->ExceptionDescribe(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
405 |
env->ExceptionClear(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
406 |
// TODO: handle |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
407 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
408 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
409 |
env->DeleteLocalRef(cls); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
410 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
411 |
env->DeleteGlobalRef(thread); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
412 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
413 |
if (!bNotified) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
414 |
::SetEvent(data->hCompleted); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
415 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
416 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
417 |
jvm->DetachCurrentThread(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
418 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
419 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
420 |
/* |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
421 |
* Class: sun_awt_windows_WToolkit |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
422 |
* Method: startToolkitThread |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
423 |
* Signature: (Ljava/lang/Runnable;)Z |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
424 |
*/ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
425 |
JNIEXPORT jboolean JNICALL |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
426 |
Java_sun_awt_windows_WToolkit_startToolkitThread(JNIEnv *env, jclass cls, jobject thread) |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
427 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
428 |
AwtToolkit& tk = AwtToolkit::GetInstance(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
429 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
430 |
ToolkitThreadProc_Data data; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
431 |
data.result = false; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
432 |
data.thread = env->NewGlobalRef(thread); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
433 |
if (data.thread == NULL) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
434 |
return JNI_FALSE; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
435 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
436 |
data.hCompleted = ::CreateEvent(NULL, FALSE, FALSE, NULL); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
437 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
438 |
bool result = tk.GetPreloadThread() |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
439 |
.InvokeAndTerminate(ToolkitThreadProc, &data); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
440 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
441 |
if (result) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
442 |
::WaitForSingleObject(data.hCompleted, INFINITE); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
443 |
result = data.result; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
444 |
} else { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
445 |
// no awt preloading |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
446 |
// return back to the usual toolkit way |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
447 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
448 |
::CloseHandle(data.hCompleted); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
449 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
450 |
env->DeleteGlobalRef(data.thread); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
451 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
452 |
return result ? JNI_TRUE : JNI_FALSE; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
453 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
454 |
|
2 | 455 |
BOOL AwtToolkit::Initialize(BOOL localPump) { |
456 |
AwtToolkit& tk = AwtToolkit::GetInstance(); |
|
457 |
||
458 |
if (!tk.m_isActive || tk.m_mainThreadId != 0) { |
|
459 |
/* Already initialized. */ |
|
460 |
return FALSE; |
|
461 |
} |
|
462 |
||
463 |
// This call is moved here from AwtToolkit constructor. Having it |
|
464 |
// there led to the bug 6480630: there could be a situation when |
|
465 |
// ComCtl32Util was constructed but not disposed |
|
466 |
ComCtl32Util::GetInstance().InitLibraries(); |
|
467 |
||
7004
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
468 |
if (!localPump) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
469 |
// if preload thread was run, terminate it |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
470 |
preloadThread.Terminate(true); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
471 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
472 |
|
2 | 473 |
/* Register this toolkit's helper window */ |
474 |
VERIFY(tk.RegisterClass() != NULL); |
|
475 |
||
476 |
// Set up operator new/malloc out of memory handler. |
|
477 |
NewHandler::init(); |
|
478 |
||
479 |
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ |
|
480 |
// Bugs 4032109, 4047966, and 4071991 to fix AWT |
|
481 |
// crash in 16 color display mode. 16 color mode is supported. Less |
|
482 |
// than 16 color is not. |
|
483 |
// creighto@eng.sun.com 1997-10-07 |
|
484 |
// |
|
485 |
// Check for at least 16 colors |
|
486 |
HDC hDC = ::GetDC(NULL); |
|
487 |
if ((::GetDeviceCaps(hDC, BITSPIXEL) * ::GetDeviceCaps(hDC, PLANES)) < 4) { |
|
488 |
::MessageBox(NULL, |
|
489 |
TEXT("Sorry, but this release of Java requires at least 16 colors"), |
|
490 |
TEXT("AWT Initialization Error"), |
|
491 |
MB_ICONHAND | MB_APPLMODAL); |
|
492 |
::DeleteDC(hDC); |
|
493 |
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); |
|
494 |
JNU_ThrowByName(env, "java/lang/InternalError", |
|
495 |
"unsupported screen depth"); |
|
496 |
return FALSE; |
|
497 |
} |
|
498 |
::ReleaseDC(NULL, hDC); |
|
499 |
/////////////////////////////////////////////////////////////////////////// |
|
500 |
||
501 |
tk.m_localPump = localPump; |
|
502 |
tk.m_mainThreadId = ::GetCurrentThreadId(); |
|
503 |
||
504 |
/* |
|
505 |
* Create the one-and-only toolkit window. This window isn't |
|
506 |
* displayed, but is used to route messages to this thread. |
|
507 |
*/ |
|
508 |
tk.m_toolkitHWnd = tk.CreateToolkitWnd(TEXT("theAwtToolkitWindow")); |
|
509 |
DASSERT(tk.m_toolkitHWnd != NULL); |
|
510 |
||
511 |
/* |
|
512 |
* Setup a GetMessage filter to watch all messages coming out of our |
|
513 |
* queue from PreProcessMsg(). |
|
514 |
*/ |
|
515 |
tk.m_hGetMessageHook = ::SetWindowsHookEx(WH_GETMESSAGE, |
|
516 |
(HOOKPROC)GetMessageFilter, |
|
517 |
0, tk.m_mainThreadId); |
|
518 |
||
519 |
awt_dnd_initialize(); |
|
520 |
||
521 |
return TRUE; |
|
522 |
} |
|
523 |
||
524 |
BOOL AwtToolkit::Dispose() { |
|
525 |
DTRACE_PRINTLN("In AwtToolkit::Dispose()"); |
|
526 |
||
527 |
AwtToolkit& tk = AwtToolkit::GetInstance(); |
|
528 |
||
529 |
if (!tk.m_isActive || tk.m_mainThreadId != ::GetCurrentThreadId()) { |
|
530 |
return FALSE; |
|
531 |
} |
|
532 |
||
533 |
tk.m_isActive = FALSE; |
|
534 |
||
535 |
awt_dnd_uninitialize(); |
|
536 |
awt_clipboard_uninitialize((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2)); |
|
537 |
||
887 | 538 |
// dispose Direct3D-related resources. This should be done |
539 |
// before AwtObjectList::Cleanup() as the d3d will attempt to |
|
540 |
// shutdown when the last of its windows is disposed of |
|
7004
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
541 |
D3DInitializer::GetInstance().Clean(); |
887 | 542 |
|
2 | 543 |
AwtObjectList::Cleanup(); |
544 |
AwtFont::Cleanup(); |
|
545 |
||
546 |
if (tk.m_inputMethodHWnd != NULL) { |
|
547 |
::SendMessage(tk.m_inputMethodHWnd, WM_IME_CONTROL, IMC_OPENSTATUSWINDOW, 0); |
|
548 |
} |
|
549 |
tk.m_inputMethodHWnd = NULL; |
|
550 |
||
551 |
// wait for any messages to be processed, in particular, |
|
552 |
// all WM_AWT_DELETEOBJECT messages that delete components; no |
|
553 |
// new messages will appear as all the windows except toolkit |
|
554 |
// window are unsubclassed and destroyed |
|
555 |
MSG msg; |
|
556 |
while (::GetMessage(&msg, NULL, 0, 0)) { |
|
557 |
::TranslateMessage(&msg); |
|
558 |
::DispatchMessage(&msg); |
|
559 |
} |
|
560 |
||
561 |
HWND toolkitHWndToDestroy = tk.m_toolkitHWnd; |
|
562 |
tk.m_toolkitHWnd = 0; |
|
563 |
VERIFY(::DestroyWindow(toolkitHWndToDestroy) != NULL); |
|
564 |
||
565 |
tk.UnregisterClass(); |
|
566 |
||
567 |
::UnhookWindowsHookEx(tk.m_hGetMessageHook); |
|
2472
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
568 |
UninstallMouseLowLevelHook(); |
2 | 569 |
|
570 |
tk.m_mainThreadId = 0; |
|
571 |
||
572 |
delete tk.m_cmdIDs; |
|
573 |
||
574 |
::CloseHandle(m_waitEvent); |
|
575 |
||
576 |
tk.m_isDisposed = TRUE; |
|
577 |
||
578 |
return TRUE; |
|
579 |
} |
|
580 |
||
581 |
void AwtToolkit::SetDynamicLayout(BOOL dynamic) { |
|
582 |
m_isDynamicLayoutSet = dynamic; |
|
583 |
} |
|
584 |
||
585 |
BOOL AwtToolkit::IsDynamicLayoutSet() { |
|
586 |
return m_isDynamicLayoutSet; |
|
587 |
} |
|
588 |
||
589 |
BOOL AwtToolkit::IsDynamicLayoutSupported() { |
|
590 |
// SPI_GETDRAGFULLWINDOWS is only supported on Win95 if |
|
591 |
// Windows Plus! is installed. Otherwise, box frame resize. |
|
592 |
BOOL fullWindowDragEnabled = FALSE; |
|
593 |
int result = 0; |
|
594 |
result = ::SystemParametersInfo(SPI_GETDRAGFULLWINDOWS, 0, |
|
595 |
&fullWindowDragEnabled, 0); |
|
596 |
||
597 |
return (fullWindowDragEnabled && (result != 0)); |
|
598 |
} |
|
599 |
||
600 |
BOOL AwtToolkit::IsDynamicLayoutActive() { |
|
601 |
return (IsDynamicLayoutSet() && IsDynamicLayoutSupported()); |
|
602 |
} |
|
603 |
||
604 |
ATOM AwtToolkit::RegisterClass() { |
|
605 |
WNDCLASS wc; |
|
606 |
||
607 |
wc.style = 0; |
|
608 |
wc.lpfnWndProc = (WNDPROC)WndProc; |
|
609 |
wc.cbClsExtra = 0; |
|
610 |
wc.cbWndExtra = 0; |
|
611 |
wc.hInstance = AwtToolkit::GetInstance().GetModuleHandle(), |
|
612 |
wc.hIcon = AwtToolkit::GetInstance().GetAwtIcon(); |
|
613 |
wc.hCursor = NULL; |
|
614 |
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); |
|
615 |
wc.lpszMenuName = NULL; |
|
616 |
wc.lpszClassName = szAwtToolkitClassName; |
|
617 |
||
618 |
ATOM ret = ::RegisterClass(&wc); |
|
619 |
DASSERT(ret != NULL); |
|
620 |
return ret; |
|
621 |
} |
|
622 |
||
623 |
void AwtToolkit::UnregisterClass() { |
|
624 |
VERIFY(::UnregisterClass(szAwtToolkitClassName, AwtToolkit::GetInstance().GetModuleHandle())); |
|
625 |
} |
|
626 |
||
627 |
/* |
|
628 |
* Structure holding the information to create a component. This packet is |
|
629 |
* sent to the toolkit window. |
|
630 |
*/ |
|
631 |
struct ComponentCreatePacket { |
|
632 |
void* hComponent; |
|
633 |
void* hParent; |
|
634 |
void (*factory)(void*, void*); |
|
635 |
}; |
|
636 |
||
637 |
/* |
|
638 |
* Create an AwtXxxx component using a given factory function |
|
639 |
* Implemented by sending a message to the toolkit window to invoke the |
|
640 |
* factory function from that thread |
|
641 |
*/ |
|
642 |
void AwtToolkit::CreateComponent(void* component, void* parent, |
|
643 |
ComponentFactory compFactory, BOOL isParentALocalReference) |
|
644 |
{ |
|
645 |
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); |
|
646 |
||
647 |
/* Since Local references are not valid in another Thread, we need to |
|
648 |
create a global reference before we send this to the Toolkit thread. |
|
649 |
In some cases this method is called with parent being a native |
|
650 |
malloced struct so we cannot and do not need to create a Global |
|
651 |
Reference from it. This is indicated by isParentALocalReference */ |
|
652 |
||
653 |
jobject gcomponent = env->NewGlobalRef((jobject)component); |
|
654 |
jobject gparent; |
|
655 |
if (isParentALocalReference) gparent = env->NewGlobalRef((jobject)parent); |
|
656 |
ComponentCreatePacket ccp = { gcomponent, |
|
657 |
isParentALocalReference == TRUE ? gparent : parent, |
|
658 |
compFactory }; |
|
659 |
AwtToolkit::GetInstance().SendMessage(WM_AWT_COMPONENT_CREATE, 0, |
|
660 |
(LPARAM)&ccp); |
|
661 |
env->DeleteGlobalRef(gcomponent); |
|
662 |
if (isParentALocalReference) env->DeleteGlobalRef(gparent); |
|
663 |
} |
|
664 |
||
665 |
/* |
|
666 |
* Destroy an HWND that was created in the toolkit thread. Can be used on |
|
667 |
* Components and the toolkit window itself. |
|
668 |
*/ |
|
669 |
void AwtToolkit::DestroyComponentHWND(HWND hwnd) |
|
670 |
{ |
|
671 |
if (!::IsWindow(hwnd)) { |
|
672 |
return; |
|
673 |
} |
|
674 |
||
675 |
AwtToolkit& tk = AwtToolkit::GetInstance(); |
|
676 |
if ((tk.m_lastMouseOver != NULL) && |
|
677 |
(tk.m_lastMouseOver->GetHWnd() == hwnd)) |
|
678 |
{ |
|
679 |
tk.m_lastMouseOver = NULL; |
|
680 |
} |
|
681 |
||
682 |
::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)NULL); |
|
683 |
tk.SendMessage(WM_AWT_DESTROY_WINDOW, (WPARAM)hwnd, 0); |
|
684 |
} |
|
685 |
||
686 |
#ifndef SPY_MESSAGES |
|
687 |
#define SpyWinMessage(hwin,msg,str) |
|
688 |
#else |
|
689 |
void SpyWinMessage(HWND hwnd, UINT message, LPCTSTR szComment); |
|
690 |
#endif |
|
691 |
||
692 |
/* |
|
693 |
* An AwtToolkit window is just a means of routing toolkit messages to here. |
|
694 |
*/ |
|
695 |
LRESULT CALLBACK AwtToolkit::WndProc(HWND hWnd, UINT message, |
|
696 |
WPARAM wParam, LPARAM lParam) |
|
697 |
{ |
|
698 |
TRY; |
|
699 |
||
700 |
JNIEnv *env = GetEnv(); |
|
701 |
JNILocalFrame lframe(env, 10); |
|
702 |
||
703 |
SpyWinMessage(hWnd, message, TEXT("AwtToolkit")); |
|
704 |
||
705 |
AwtToolkit::GetInstance().eventNumber++; |
|
706 |
/* |
|
707 |
* Awt widget creation messages are routed here so that all |
|
708 |
* widgets are created on the main thread. Java allows widgets |
|
709 |
* to live beyond their creating thread -- by creating them on |
|
710 |
* the main thread, a widget can always be properly disposed. |
|
711 |
*/ |
|
712 |
switch (message) { |
|
713 |
case WM_AWT_EXECUTE_SYNC: { |
|
714 |
jobject peerObject = (jobject)wParam; |
|
715 |
AwtObject* object = (AwtObject *)JNI_GET_PDATA(peerObject); |
|
716 |
DASSERT( !IsBadReadPtr(object, sizeof(AwtObject))); |
|
717 |
AwtObject::ExecuteArgs *args = (AwtObject::ExecuteArgs *)lParam; |
|
718 |
DASSERT(!IsBadReadPtr(args, sizeof(AwtObject::ExecuteArgs))); |
|
719 |
LRESULT result = 0; |
|
720 |
if (object != NULL) |
|
721 |
{ |
|
722 |
result = object->WinThreadExecProc(args); |
|
723 |
} |
|
724 |
env->DeleteGlobalRef(peerObject); |
|
725 |
return result; |
|
726 |
} |
|
727 |
case WM_AWT_COMPONENT_CREATE: { |
|
728 |
ComponentCreatePacket* ccp = (ComponentCreatePacket*)lParam; |
|
729 |
DASSERT(ccp->factory != NULL); |
|
730 |
DASSERT(ccp->hComponent != NULL); |
|
731 |
(*ccp->factory)(ccp->hComponent, ccp->hParent); |
|
732 |
return 0; |
|
733 |
} |
|
734 |
case WM_AWT_DESTROY_WINDOW: { |
|
735 |
/* Destroy widgets from this same thread that created them */ |
|
736 |
VERIFY(::DestroyWindow((HWND)wParam) != NULL); |
|
737 |
return 0; |
|
738 |
} |
|
739 |
case WM_AWT_DISPOSE: { |
|
740 |
BOOL canDispose = TRUE; |
|
741 |
CriticalSection &syncCS = AwtToolkit::GetInstance().GetSyncCS(); |
|
742 |
int shouldEnterCriticalSection = (int)lParam; |
|
743 |
if (shouldEnterCriticalSection == 1) { |
|
744 |
canDispose = syncCS.TryEnter(); |
|
745 |
} |
|
746 |
if (canDispose) { |
|
747 |
AwtObject *o = (AwtObject *)wParam; |
|
748 |
o->Dispose(); |
|
749 |
if (shouldEnterCriticalSection) { |
|
750 |
syncCS.Leave(); |
|
751 |
} |
|
752 |
} else { |
|
753 |
AwtToolkit::GetInstance().PostMessage(WM_AWT_DISPOSE, wParam, lParam); |
|
754 |
} |
|
755 |
return 0; |
|
756 |
} |
|
757 |
case WM_AWT_DELETEOBJECT: { |
|
758 |
AwtObject *p = (AwtObject *)wParam; |
|
759 |
if (p->CanBeDeleted()) { |
|
760 |
// all the messages for this component are processed, so |
|
761 |
// it can be deleted |
|
762 |
delete p; |
|
763 |
} else { |
|
764 |
// postpone deletion, waiting for all the messages for this |
|
765 |
// component to be processed |
|
766 |
AwtToolkit::GetInstance().PostMessage(WM_AWT_DELETEOBJECT, wParam, (LPARAM)0); |
|
767 |
} |
|
768 |
return 0; |
|
769 |
} |
|
770 |
case WM_AWT_OBJECTLISTCLEANUP: { |
|
771 |
AwtObjectList::Cleanup(); |
|
772 |
return 0; |
|
773 |
} |
|
774 |
case WM_SYSCOLORCHANGE: { |
|
775 |
||
776 |
jclass systemColorClass = env->FindClass("java/awt/SystemColor"); |
|
777 |
DASSERT(systemColorClass); |
|
778 |
||
779 |
jmethodID mid = env->GetStaticMethodID(systemColorClass, "updateSystemColors", "()V"); |
|
780 |
DASSERT(mid); |
|
781 |
||
782 |
env->CallStaticVoidMethod(systemColorClass, mid); |
|
783 |
||
784 |
/* FALL THROUGH - NO BREAK */ |
|
785 |
} |
|
786 |
||
787 |
case WM_SETTINGCHANGE: { |
|
788 |
AwtWin32GraphicsDevice::ResetAllMonitorInfo(); |
|
789 |
/* FALL THROUGH - NO BREAK */ |
|
790 |
} |
|
791 |
// Remove this define when we move to newer (XP) version of SDK. |
|
792 |
#define WM_THEMECHANGED 0x031A |
|
793 |
case WM_THEMECHANGED: { |
|
794 |
/* Upcall to WToolkit when user changes configuration. |
|
795 |
* |
|
796 |
* NOTE: there is a bug in Windows 98 and some older versions of |
|
797 |
* Windows NT (it seems to be fixed in NT4 SP5) where no |
|
798 |
* WM_SETTINGCHANGE is sent when any of the properties under |
|
799 |
* Control Panel -> Display are changed. You must _always_ query |
|
800 |
* the system for these - you can't rely on cached values. |
|
801 |
*/ |
|
802 |
jobject peer = AwtToolkit::GetInstance().m_peer; |
|
803 |
if (peer != NULL) { |
|
804 |
env->CallVoidMethod(peer, AwtToolkit::windowsSettingChangeMID); |
|
805 |
} |
|
806 |
return 0; |
|
807 |
} |
|
887 | 808 |
#ifndef WM_DWMCOMPOSITIONCHANGED |
809 |
#define WM_DWMCOMPOSITIONCHANGED 0x031E |
|
810 |
#define WM_DWMNCRENDERINGCHANGED 0x031F |
|
811 |
#define WM_DWMCOLORIZATIONCOLORCHANGED 0x0320 |
|
812 |
#define WM_DWMWINDOWMAXIMIZEDCHANGED 0x0321 |
|
813 |
#endif // WM_DWMCOMPOSITIONCHANGED |
|
814 |
case WM_DWMCOMPOSITIONCHANGED: { |
|
815 |
DWMResetCompositionEnabled(); |
|
816 |
return 0; |
|
817 |
} |
|
818 |
||
2 | 819 |
case WM_TIMER: { |
820 |
// 6479820. Should check if a window is in manual resizing process: skip |
|
821 |
// sending any MouseExit/Enter events while inside resize-loop. |
|
822 |
// Note that window being in manual moving process could still |
|
823 |
// produce redundant enter/exit mouse events. In future, they can be |
|
824 |
// made skipped in a similar way. |
|
825 |
if (AwtWindow::IsResizing()) { |
|
826 |
return 0; |
|
827 |
} |
|
828 |
// Create an artifical MouseExit message if the mouse left to |
|
829 |
// a non-java window (bad mouse!) |
|
830 |
POINT pt; |
|
831 |
AwtToolkit& tk = AwtToolkit::GetInstance(); |
|
832 |
if (::GetCursorPos(&pt)) { |
|
833 |
HWND hWndOver = ::WindowFromPoint(pt); |
|
834 |
AwtComponent * last_M; |
|
835 |
if ( AwtComponent::GetComponent(hWndOver) == NULL && tk.m_lastMouseOver != NULL ) { |
|
836 |
last_M = tk.m_lastMouseOver; |
|
837 |
// translate point from screen to target window |
|
838 |
MapWindowPoints(HWND_DESKTOP, last_M->GetHWnd(), &pt, 1); |
|
839 |
last_M->SendMessage(WM_AWT_MOUSEEXIT, |
|
840 |
GetMouseKeyState(), |
|
841 |
POINTTOPOINTS(pt)); |
|
842 |
tk.m_lastMouseOver = 0; |
|
843 |
} |
|
844 |
} |
|
845 |
if (tk.m_lastMouseOver == NULL && tk.m_timer != 0) { |
|
846 |
VERIFY(::KillTimer(tk.m_toolkitHWnd, tk.m_timer)); |
|
847 |
tk.m_timer = 0; |
|
848 |
} |
|
849 |
return 0; |
|
850 |
} |
|
851 |
case WM_DESTROYCLIPBOARD: { |
|
852 |
if (!AwtClipboard::IsGettingOwnership()) |
|
853 |
AwtClipboard::LostOwnership((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2)); |
|
854 |
return 0; |
|
855 |
} |
|
856 |
case WM_CHANGECBCHAIN: { |
|
857 |
AwtClipboard::WmChangeCbChain(wParam, lParam); |
|
858 |
return 0; |
|
859 |
} |
|
860 |
case WM_DRAWCLIPBOARD: { |
|
861 |
AwtClipboard::WmDrawClipboard((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2), wParam, lParam); |
|
862 |
return 0; |
|
863 |
} |
|
864 |
case WM_AWT_LIST_SETMULTISELECT: { |
|
865 |
jobject peerObject = (jobject)wParam; |
|
866 |
AwtList* list = (AwtList *)JNI_GET_PDATA(peerObject); |
|
867 |
DASSERT( !IsBadReadPtr(list, sizeof(AwtObject))); |
|
868 |
list->SetMultiSelect(static_cast<BOOL>(lParam)); |
|
869 |
return 0; |
|
870 |
} |
|
871 |
||
872 |
// Special awt message to call Imm APIs. |
|
873 |
// ImmXXXX() API must be used in the main thread. |
|
874 |
// In other thread these APIs does not work correctly even if |
|
875 |
// it returs with no error. (This restriction is not documented) |
|
876 |
// So we must use thse messages to call these APIs in main thread. |
|
877 |
case WM_AWT_CREATECONTEXT: { |
|
878 |
return reinterpret_cast<LRESULT>( |
|
879 |
reinterpret_cast<void*>(ImmCreateContext())); |
|
880 |
} |
|
881 |
case WM_AWT_DESTROYCONTEXT: { |
|
882 |
ImmDestroyContext((HIMC)wParam); |
|
883 |
return 0; |
|
884 |
} |
|
885 |
case WM_AWT_ASSOCIATECONTEXT: { |
|
2952
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
886 |
EnableNativeIMEStruct *data = (EnableNativeIMEStruct*)wParam; |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
887 |
|
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
888 |
jobject peer = data->peer; |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
889 |
jobject self = data->self; |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
890 |
jint context = data->context; |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
891 |
jboolean useNativeCompWindow = data->useNativeCompWindow; |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
892 |
|
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
893 |
AwtComponent* comp = (AwtComponent*)JNI_GET_PDATA(peer); |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
894 |
if (comp != NULL) |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
895 |
{ |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
896 |
comp->SetInputMethod(self, useNativeCompWindow); |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
897 |
comp->ImmAssociateContext((HIMC)context); |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
898 |
} |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
899 |
|
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
900 |
if (peer != NULL) { |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
901 |
env->DeleteGlobalRef(peer); |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
902 |
} |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
903 |
if (self != NULL) { |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
904 |
env->DeleteGlobalRef(self); |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
905 |
} |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
906 |
|
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
907 |
delete data; |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
908 |
return 0; |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
909 |
} |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
910 |
case WM_AWT_GET_DEFAULT_IME_HANDLER: { |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
911 |
LRESULT ret = (LRESULT)FALSE; |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
912 |
jobject peer = (jobject)wParam; |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
913 |
|
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
914 |
AwtComponent* comp = (AwtComponent*)JNI_GET_PDATA(peer); |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
915 |
if (comp != NULL) { |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
916 |
HWND defaultIMEHandler = ImmGetDefaultIMEWnd(comp->GetHWnd()); |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
917 |
if (defaultIMEHandler != NULL) { |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
918 |
AwtToolkit::GetInstance().SetInputMethodWindow(defaultIMEHandler); |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
919 |
ret = (LRESULT)TRUE; |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
920 |
} |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
921 |
} |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
922 |
|
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
923 |
if (peer != NULL) { |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
924 |
env->DeleteGlobalRef(peer); |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
925 |
} |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
926 |
return ret; |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
927 |
} |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
928 |
case WM_AWT_HANDLE_NATIVE_IME_EVENT: { |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
929 |
jobject peer = (jobject)wParam; |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
930 |
AwtComponent* comp = (AwtComponent*)JNI_GET_PDATA(peer); |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
931 |
MSG* msg = (MSG*)lParam; |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
932 |
|
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
933 |
long modifiers = comp->GetJavaModifiers(); |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
934 |
if ((comp != NULL) && (msg->message==WM_CHAR || msg->message==WM_SYSCHAR)) { |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
935 |
WCHAR unicodeChar = (WCHAR)msg->wParam; |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
936 |
comp->SendKeyEvent(java_awt_event_KeyEvent_KEY_TYPED, |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
937 |
0, //to be fixed nowMillis(), |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
938 |
java_awt_event_KeyEvent_CHAR_UNDEFINED, |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
939 |
unicodeChar, |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
940 |
modifiers, |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
941 |
java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN, (jlong)0, |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
942 |
msg); |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
943 |
} else if (comp != NULL) { |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
944 |
MSG* pCopiedMsg = new MSG; |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
945 |
*pCopiedMsg = *msg; |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
946 |
comp->SendMessage(WM_AWT_HANDLE_EVENT, (WPARAM) FALSE, |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
947 |
(LPARAM) pCopiedMsg); |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
948 |
} |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
949 |
|
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
950 |
if (peer != NULL) { |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
951 |
env->DeleteGlobalRef(peer); |
0679c7600523
6829180: Removing focused component from a window causes a JVM crash for JDK7b50+ on WinXP/Vista
dcherepanov
parents:
2810
diff
changeset
|
952 |
} |
2 | 953 |
return 0; |
954 |
} |
|
955 |
case WM_AWT_ENDCOMPOSITION: { |
|
956 |
/*right now we just cancel the composition string |
|
957 |
may need to commit it in the furture |
|
958 |
Changed to commit it according to the flag 10/29/98*/ |
|
959 |
ImmNotifyIME((HIMC)wParam, NI_COMPOSITIONSTR, |
|
960 |
(lParam ? CPS_COMPLETE : CPS_CANCEL), 0); |
|
961 |
return 0; |
|
962 |
} |
|
963 |
case WM_AWT_SETCONVERSIONSTATUS: { |
|
964 |
DWORD cmode; |
|
965 |
DWORD smode; |
|
966 |
ImmGetConversionStatus((HIMC)wParam, (LPDWORD)&cmode, (LPDWORD)&smode); |
|
967 |
ImmSetConversionStatus((HIMC)wParam, (DWORD)LOWORD(lParam), smode); |
|
968 |
return 0; |
|
969 |
} |
|
970 |
case WM_AWT_GETCONVERSIONSTATUS: { |
|
971 |
DWORD cmode; |
|
972 |
DWORD smode; |
|
973 |
ImmGetConversionStatus((HIMC)wParam, (LPDWORD)&cmode, (LPDWORD)&smode); |
|
974 |
return cmode; |
|
975 |
} |
|
976 |
case WM_AWT_ACTIVATEKEYBOARDLAYOUT: { |
|
977 |
if (wParam && g_bUserHasChangedInputLang) { |
|
978 |
// Input language has been changed since the last WInputMethod.getNativeLocale() |
|
979 |
// call. So let's honor the user's selection. |
|
980 |
// Note: we need to check this flag inside the toolkit thread to synchronize access |
|
981 |
// to the flag. |
|
982 |
return FALSE; |
|
983 |
} |
|
984 |
||
985 |
if (lParam == (LPARAM)::GetKeyboardLayout(0)) { |
|
986 |
// already active |
|
987 |
return FALSE; |
|
988 |
} |
|
989 |
||
990 |
// Since ActivateKeyboardLayout does not post WM_INPUTLANGCHANGEREQUEST, |
|
991 |
// we explicitly need to do the same thing here. |
|
992 |
static BYTE keyboardState[AwtToolkit::KB_STATE_SIZE]; |
|
993 |
AwtToolkit::GetKeyboardState(keyboardState); |
|
994 |
WORD ignored; |
|
995 |
::ToAscii(VK_SPACE, ::MapVirtualKey(VK_SPACE, 0), |
|
996 |
keyboardState, &ignored, 0); |
|
997 |
||
998 |
return (LRESULT)activateKeyboardLayout((HKL)lParam); |
|
999 |
} |
|
1000 |
case WM_AWT_OPENCANDIDATEWINDOW: { |
|
1001 |
jobject peerObject = (jobject)wParam; |
|
1002 |
AwtComponent* p = (AwtComponent*)JNI_GET_PDATA(peerObject); |
|
1003 |
DASSERT( !IsBadReadPtr(p, sizeof(AwtObject))); |
|
1004 |
// fix for 4805862: use GET_X_LPARAM and GET_Y_LPARAM macros |
|
1005 |
// instead of LOWORD and HIWORD |
|
1006 |
p->OpenCandidateWindow(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); |
|
1007 |
env->DeleteGlobalRef(peerObject); |
|
1008 |
return 0; |
|
1009 |
} |
|
1010 |
||
1011 |
/* |
|
1012 |
* send this message via ::SendMessage() and the MPT will acquire the |
|
1013 |
* HANDLE synchronized with the sender's thread. The HANDLE must be |
|
1014 |
* signalled or deadlock may occur between the MPT and the caller. |
|
1015 |
*/ |
|
1016 |
||
1017 |
case WM_AWT_WAIT_FOR_SINGLE_OBJECT: { |
|
1018 |
return ::WaitForSingleObject((HANDLE)lParam, INFINITE); |
|
1019 |
} |
|
1020 |
case WM_AWT_INVOKE_METHOD: { |
|
1021 |
return (LRESULT)(*(void*(*)(void*))wParam)((void *)lParam); |
|
1022 |
} |
|
1023 |
case WM_AWT_INVOKE_VOID_METHOD: { |
|
1024 |
return (LRESULT)(*(void*(*)(void))wParam)(); |
|
1025 |
} |
|
1026 |
||
1027 |
case WM_AWT_SETOPENSTATUS: { |
|
1028 |
ImmSetOpenStatus((HIMC)wParam, (BOOL)lParam); |
|
1029 |
return 0; |
|
1030 |
} |
|
1031 |
case WM_AWT_GETOPENSTATUS: { |
|
1032 |
return (DWORD)ImmGetOpenStatus((HIMC)wParam); |
|
1033 |
} |
|
1034 |
case WM_DISPLAYCHANGE: { |
|
1035 |
// Reinitialize screens |
|
1036 |
initScreens(env); |
|
1037 |
||
1038 |
// Notify Java side - call WToolkit.displayChanged() |
|
1039 |
jclass clazz = env->FindClass("sun/awt/windows/WToolkit"); |
|
1040 |
env->CallStaticVoidMethod(clazz, AwtToolkit::displayChangeMID); |
|
1041 |
||
1042 |
GetInstance().m_displayChanged = TRUE; |
|
1043 |
||
1044 |
::PostMessage(HWND_BROADCAST, WM_PALETTEISCHANGING, NULL, NULL); |
|
1045 |
break; |
|
1046 |
} |
|
1047 |
case WM_AWT_SETCURSOR: { |
|
1048 |
::SetCursor((HCURSOR)wParam); |
|
1049 |
return TRUE; |
|
1050 |
} |
|
1051 |
/* Session management */ |
|
1052 |
case WM_QUERYENDSESSION: { |
|
1053 |
/* Shut down cleanly */ |
|
1054 |
if (JVM_RaiseSignal(SIGTERM)) { |
|
1055 |
AwtToolkit::GetInstance().m_vmSignalled = TRUE; |
|
1056 |
} |
|
1057 |
return TRUE; |
|
1058 |
} |
|
1059 |
case WM_ENDSESSION: { |
|
1060 |
// Keep pumping messages until the shutdown sequence halts the VM, |
|
1061 |
// or we exit the MessageLoop because of a WM_QUIT message |
|
1062 |
AwtToolkit& tk = AwtToolkit::GetInstance(); |
|
1063 |
||
1064 |
// if WM_QUERYENDSESSION hasn't successfully raised SIGTERM |
|
1065 |
// we ignore the ENDSESSION message |
|
1066 |
if (!tk.m_vmSignalled) { |
|
1067 |
return 0; |
|
1068 |
} |
|
1069 |
tk.MessageLoop(AwtToolkit::PrimaryIdleFunc, |
|
1070 |
AwtToolkit::CommonPeekMessageFunc); |
|
1071 |
||
1072 |
// Dispose here instead of in eventLoop so that we don't have |
|
1073 |
// to return from the WM_ENDSESSION handler. |
|
1074 |
tk.Dispose(); |
|
1075 |
||
1076 |
// Never return. The VM will halt the process. |
|
1077 |
hang_if_shutdown(); |
|
1078 |
||
1079 |
// Should never get here. |
|
1080 |
DASSERT(FALSE); |
|
1081 |
break; |
|
1082 |
} |
|
1083 |
case WM_SYNC_WAIT: |
|
1084 |
SetEvent(AwtToolkit::GetInstance().m_waitEvent); |
|
1085 |
break; |
|
1086 |
} |
|
1087 |
||
1088 |
return DefWindowProc(hWnd, message, wParam, lParam); |
|
1089 |
||
1090 |
CATCH_BAD_ALLOC_RET(0); |
|
1091 |
} |
|
1092 |
||
1093 |
LRESULT CALLBACK AwtToolkit::GetMessageFilter(int code, |
|
1094 |
WPARAM wParam, LPARAM lParam) |
|
1095 |
{ |
|
1096 |
TRY; |
|
1097 |
||
1098 |
if (code >= 0 && wParam == PM_REMOVE && lParam != 0) { |
|
1099 |
if (AwtToolkit::GetInstance().PreProcessMsg(*(MSG*)lParam) != |
|
1100 |
mrPassAlong) { |
|
1101 |
/* PreProcessMsg() wants us to eat it */ |
|
1102 |
((MSG*)lParam)->message = WM_NULL; |
|
1103 |
} |
|
1104 |
} |
|
1105 |
return ::CallNextHookEx(AwtToolkit::GetInstance().m_hGetMessageHook, code, |
|
1106 |
wParam, lParam); |
|
1107 |
||
1108 |
CATCH_BAD_ALLOC_RET(0); |
|
1109 |
} |
|
1110 |
||
2472
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1111 |
void AwtToolkit::InstallMouseLowLevelHook() |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1112 |
{ |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1113 |
// We need the low-level hook since we need to process mouse move |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1114 |
// messages outside of our windows. |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1115 |
m_hMouseLLHook = ::SetWindowsHookEx(WH_MOUSE_LL, |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1116 |
(HOOKPROC)MouseLowLevelHook, |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1117 |
GetModuleHandle(), NULL); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1118 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1119 |
// Reset the old value |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1120 |
m_lastWindowUnderMouse = NULL; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1121 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1122 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1123 |
void AwtToolkit::UninstallMouseLowLevelHook() |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1124 |
{ |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1125 |
if (m_hMouseLLHook != 0) { |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1126 |
::UnhookWindowsHookEx(m_hMouseLLHook); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1127 |
m_hMouseLLHook = 0; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1128 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1129 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1130 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1131 |
LRESULT CALLBACK AwtToolkit::MouseLowLevelHook(int code, |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1132 |
WPARAM wParam, LPARAM lParam) |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1133 |
{ |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1134 |
TRY; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1135 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1136 |
if (code >= 0 && wParam == WM_MOUSEMOVE) { |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1137 |
POINT pt = ((MSLLHOOKSTRUCT*)lParam)->pt; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1138 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1139 |
// We can't use GA_ROOTOWNER since in this case we'll go up to |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1140 |
// the root Java toplevel, not the actual owned toplevel. |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1141 |
HWND hwnd = ::GetAncestor(::WindowFromPoint(pt), GA_ROOT); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1142 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1143 |
AwtToolkit& tk = AwtToolkit::GetInstance(); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1144 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1145 |
if (tk.m_lastWindowUnderMouse != hwnd) { |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1146 |
AwtWindow *fw = NULL, *tw = NULL; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1147 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1148 |
if (tk.m_lastWindowUnderMouse) { |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1149 |
fw = (AwtWindow*) |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1150 |
AwtComponent::GetComponent(tk.m_lastWindowUnderMouse); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1151 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1152 |
if (hwnd) { |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1153 |
tw = (AwtWindow*)AwtComponent::GetComponent(hwnd); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1154 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1155 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1156 |
tk.m_lastWindowUnderMouse = hwnd; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1157 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1158 |
if (fw) { |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1159 |
fw->UpdateSecurityWarningVisibility(); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1160 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1161 |
// ... however, because we use GA_ROOT, we may find the warningIcon |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1162 |
// which is not a Java windows. |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1163 |
if (AwtWindow::IsWarningWindow(hwnd)) { |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1164 |
hwnd = ::GetParent(hwnd); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1165 |
if (hwnd) { |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1166 |
tw = (AwtWindow*)AwtComponent::GetComponent(hwnd); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1167 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1168 |
tk.m_lastWindowUnderMouse = hwnd; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1169 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1170 |
if (tw) { |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1171 |
tw->UpdateSecurityWarningVisibility(); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1172 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1173 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1174 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1175 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1176 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1177 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1178 |
return ::CallNextHookEx(AwtToolkit::GetInstance().m_hMouseLLHook, code, |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1179 |
wParam, lParam); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1180 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1181 |
CATCH_BAD_ALLOC_RET(0); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1182 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1183 |
|
2 | 1184 |
/* |
1185 |
* The main message loop |
|
1186 |
*/ |
|
1187 |
||
1188 |
const int AwtToolkit::EXIT_ENCLOSING_LOOP = 0; |
|
1189 |
const int AwtToolkit::EXIT_ALL_ENCLOSING_LOOPS = -1; |
|
1190 |
||
1191 |
||
1192 |
/** |
|
1193 |
* Called upon event idle to ensure that we have released any |
|
1194 |
* CriticalSections that we took during window event processing. |
|
1195 |
* |
|
1196 |
* Note that this gets used more often than you would think; some |
|
1197 |
* window moves actually happen over more than one event burst. So, |
|
1198 |
* for example, we might get a WINDOWPOSCHANGING event, then we |
|
1199 |
* idle and release the lock here, then eventually we get the |
|
1200 |
* WINDOWPOSCHANGED event. |
|
1201 |
* |
|
1202 |
* This method may be called from WToolkit.embeddedEventLoopIdleProcessing |
|
1203 |
* if there is a separate event loop that must do the same CriticalSection |
|
1204 |
* check. |
|
1205 |
* |
|
1206 |
* See bug #4526587 for more information. |
|
1207 |
*/ |
|
1208 |
void VerifyWindowMoveLockReleased() |
|
1209 |
{ |
|
1210 |
if (windowMoveLockHeld) { |
|
1211 |
windowMoveLockHeld = FALSE; |
|
1212 |
windowMoveLock.Leave(); |
|
1213 |
} |
|
1214 |
} |
|
1215 |
||
1216 |
UINT |
|
1217 |
AwtToolkit::MessageLoop(IDLEPROC lpIdleFunc, |
|
1218 |
PEEKMESSAGEPROC lpPeekMessageFunc) |
|
1219 |
{ |
|
1220 |
DTRACE_PRINTLN("AWT event loop started"); |
|
1221 |
||
1222 |
DASSERT(lpIdleFunc != NULL); |
|
1223 |
DASSERT(lpPeekMessageFunc != NULL); |
|
1224 |
||
1225 |
m_messageLoopResult = 0; |
|
1226 |
while (!m_breakMessageLoop) { |
|
1227 |
||
1228 |
(*lpIdleFunc)(); |
|
1229 |
||
1230 |
PumpWaitingMessages(lpPeekMessageFunc); /* pumps waiting messages */ |
|
1231 |
||
1232 |
// Catch problems with windowMoveLock critical section. In case we |
|
1233 |
// misunderstood the way windows processes window move/resize |
|
1234 |
// events, we don't want to hold onto the windowMoveLock CS forever. |
|
1235 |
// If we've finished processing events for now, release the lock |
|
1236 |
// if held. |
|
1237 |
VerifyWindowMoveLockReleased(); |
|
1238 |
} |
|
1239 |
if (m_messageLoopResult == EXIT_ALL_ENCLOSING_LOOPS) |
|
1240 |
::PostQuitMessage(EXIT_ALL_ENCLOSING_LOOPS); |
|
1241 |
m_breakMessageLoop = FALSE; |
|
1242 |
||
1243 |
DTRACE_PRINTLN("AWT event loop ended"); |
|
1244 |
||
1245 |
return m_messageLoopResult; |
|
1246 |
} |
|
1247 |
||
1248 |
/* |
|
1249 |
* Exit the enclosing message loop(s). |
|
1250 |
* |
|
1251 |
* The message will be ignored if Windows is currently is in an internal |
|
1252 |
* message loop (such as a scroll bar drag). So we first send IDCANCEL and |
|
1253 |
* WM_CANCELMODE messages to every Window on the thread. |
|
1254 |
*/ |
|
1255 |
static BOOL CALLBACK CancelAllThreadWindows(HWND hWnd, LPARAM) |
|
1256 |
{ |
|
1257 |
TRY; |
|
1258 |
||
1259 |
::SendMessage(hWnd, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), (LPARAM)hWnd); |
|
1260 |
::SendMessage(hWnd, WM_CANCELMODE, 0, 0); |
|
1261 |
||
1262 |
return TRUE; |
|
1263 |
||
1264 |
CATCH_BAD_ALLOC_RET(FALSE); |
|
1265 |
} |
|
1266 |
||
1267 |
static void DoQuitMessageLoop(void* param) { |
|
1268 |
int status = *static_cast<int*>(param); |
|
1269 |
||
1270 |
AwtToolkit::GetInstance().QuitMessageLoop(status); |
|
1271 |
} |
|
1272 |
||
1273 |
void AwtToolkit::QuitMessageLoop(int status) { |
|
1274 |
/* |
|
1275 |
* Fix for 4623377. |
|
1276 |
* Reinvoke QuitMessageLoop on the toolkit thread, so that |
|
1277 |
* m_breakMessageLoop is accessed on a single thread. |
|
1278 |
*/ |
|
1279 |
if (!AwtToolkit::IsMainThread()) { |
|
1280 |
InvokeFunction(DoQuitMessageLoop, &status); |
|
1281 |
return; |
|
1282 |
} |
|
1283 |
||
1284 |
/* |
|
1285 |
* Fix for BugTraq ID 4445747. |
|
1286 |
* EnumThreadWindows() is very slow during dnd on Win9X/ME. |
|
1287 |
* This call is unnecessary during dnd, since we postpone processing of all |
|
1288 |
* messages that can enter internal message loop until dnd is over. |
|
1289 |
*/ |
|
1290 |
if (status == EXIT_ALL_ENCLOSING_LOOPS) { |
|
1291 |
::EnumThreadWindows(MainThread(), (WNDENUMPROC)CancelAllThreadWindows, |
|
1292 |
0); |
|
1293 |
} |
|
1294 |
||
1295 |
/* |
|
1296 |
* Fix for 4623377. |
|
1297 |
* Modal loop may not exit immediatelly after WM_CANCELMODE, so it still can |
|
1298 |
* eat WM_QUIT message and the nested message loop will never exit. |
|
1299 |
* The fix is to use AwtToolkit instance variables instead of WM_QUIT to |
|
1300 |
* guarantee that we exit from the nested message loop when any possible |
|
1301 |
* modal loop quits. In this case CancelAllThreadWindows is needed only to |
|
1302 |
* ensure that the nested message loop exits quickly and doesn't wait until |
|
1303 |
* a possible modal loop completes. |
|
1304 |
*/ |
|
1305 |
m_breakMessageLoop = TRUE; |
|
1306 |
m_messageLoopResult = status; |
|
1307 |
||
1308 |
/* |
|
1309 |
* Fix for 4683602. |
|
1310 |
* Post an empty message, to wake up the toolkit thread |
|
1311 |
* if it is currently in WaitMessage(), |
|
1312 |
*/ |
|
1313 |
PostMessage(WM_NULL); |
|
1314 |
} |
|
1315 |
||
1316 |
/* |
|
1317 |
* Called by the message loop to pump the message queue when there are |
|
1318 |
* messages waiting. Can also be called anywhere to pump messages. |
|
1319 |
*/ |
|
1320 |
BOOL AwtToolkit::PumpWaitingMessages(PEEKMESSAGEPROC lpPeekMessageFunc) |
|
1321 |
{ |
|
1322 |
MSG msg; |
|
1323 |
BOOL foundOne = FALSE; |
|
1324 |
||
1325 |
DASSERT(lpPeekMessageFunc != NULL); |
|
1326 |
||
1327 |
while (!m_breakMessageLoop && (*lpPeekMessageFunc)(msg)) { |
|
1328 |
foundOne = TRUE; |
|
1329 |
if (msg.message == WM_QUIT) { |
|
1330 |
m_breakMessageLoop = TRUE; |
|
1331 |
m_messageLoopResult = static_cast<UINT>(msg.wParam); |
|
1332 |
if (m_messageLoopResult == EXIT_ALL_ENCLOSING_LOOPS) |
|
1333 |
::PostQuitMessage(static_cast<int>(msg.wParam)); // make sure all loops exit |
|
1334 |
break; |
|
1335 |
} |
|
1336 |
else if (msg.message != WM_NULL) { |
|
1337 |
/* |
|
1338 |
* The AWT in standalone mode (that is, dynamically loaded from the |
|
1339 |
* Java VM) doesn't have any translation tables to worry about, so |
|
1340 |
* TranslateAccelerator isn't called. |
|
1341 |
*/ |
|
1342 |
||
1343 |
::TranslateMessage(&msg); |
|
1344 |
::DispatchMessage(&msg); |
|
1345 |
} |
|
1346 |
} |
|
1347 |
return foundOne; |
|
1348 |
} |
|
1349 |
||
1350 |
VOID CALLBACK |
|
1351 |
AwtToolkit::PrimaryIdleFunc() { |
|
1352 |
AwtToolkit::SetBusy(FALSE); |
|
1353 |
::WaitMessage(); /* allow system to go idle */ |
|
1354 |
AwtToolkit::SetBusy(TRUE); |
|
1355 |
} |
|
1356 |
||
1357 |
VOID CALLBACK |
|
1358 |
AwtToolkit::SecondaryIdleFunc() { |
|
1359 |
::WaitMessage(); /* allow system to go idle */ |
|
1360 |
} |
|
1361 |
||
1362 |
BOOL |
|
1363 |
AwtToolkit::CommonPeekMessageFunc(MSG& msg) { |
|
1364 |
return ::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); |
|
1365 |
} |
|
1366 |
||
1367 |
/* |
|
1368 |
* Perform pre-processing on a message before it is translated & |
|
1369 |
* dispatched. Returns true to eat the message |
|
1370 |
*/ |
|
1371 |
BOOL AwtToolkit::PreProcessMsg(MSG& msg) |
|
1372 |
{ |
|
1373 |
/* |
|
1374 |
* Offer preprocessing first to the target component, then call out to |
|
1375 |
* specific mouse and key preprocessor methods |
|
1376 |
*/ |
|
1377 |
AwtComponent* p = AwtComponent::GetComponent(msg.hwnd); |
|
1378 |
if (p && p->PreProcessMsg(msg) == mrConsume) |
|
1379 |
return TRUE; |
|
1380 |
||
1954 | 1381 |
if ((msg.message >= WM_MOUSEFIRST && msg.message <= WM_MOUSELAST) || |
2 | 1382 |
(msg.message >= WM_NCMOUSEMOVE && msg.message <= WM_NCMBUTTONDBLCLK)) { |
1383 |
if (PreProcessMouseMsg(p, msg)) { |
|
1384 |
return TRUE; |
|
1385 |
} |
|
1386 |
} |
|
1387 |
else if (msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST) { |
|
1388 |
if (PreProcessKeyMsg(p, msg)) |
|
1389 |
return TRUE; |
|
1390 |
} |
|
1391 |
return FALSE; |
|
1392 |
} |
|
1393 |
||
1394 |
BOOL AwtToolkit::PreProcessMouseMsg(AwtComponent* p, MSG& msg) |
|
1395 |
{ |
|
1396 |
WPARAM mouseWParam; |
|
1397 |
LPARAM mouseLParam; |
|
1398 |
||
1399 |
/* |
|
1400 |
* Fix for BugTraq ID 4395290. |
|
1401 |
* Do not synthesize mouse enter/exit events during drag-and-drop, |
|
1402 |
* since it messes up LightweightDispatcher. |
|
1403 |
*/ |
|
1404 |
if (AwtDropTarget::IsLocalDnD()) { |
|
1405 |
return FALSE; |
|
1406 |
} |
|
1407 |
||
1954 | 1408 |
if (msg.message >= WM_MOUSEFIRST && msg.message <= WM_MOUSELAST) { |
2 | 1409 |
mouseWParam = msg.wParam; |
1410 |
mouseLParam = msg.lParam; |
|
1411 |
} else { |
|
1412 |
mouseWParam = GetMouseKeyState(); |
|
1413 |
} |
|
1414 |
||
1415 |
/* |
|
1416 |
* Get the window under the mouse, as it will be different if its |
|
1417 |
* captured. |
|
1418 |
*/ |
|
1419 |
DWORD dwCurPos = ::GetMessagePos(); |
|
1420 |
DWORD dwScreenPos = dwCurPos; |
|
1421 |
POINT curPos; |
|
1422 |
// fix for 4805862 |
|
1423 |
// According to MSDN: do not use LOWORD and HIWORD macros to extract x and |
|
1424 |
// y coordinates because these macros return incorrect results on systems |
|
1425 |
// with multiple monitors (signed values are treated as unsigned) |
|
1426 |
curPos.x = GET_X_LPARAM(dwCurPos); |
|
1427 |
curPos.y = GET_Y_LPARAM(dwCurPos); |
|
1428 |
HWND hWndFromPoint = ::WindowFromPoint(curPos); |
|
1429 |
// hWndFromPoint == 0 if mouse is over a scrollbar |
|
1430 |
AwtComponent* mouseComp = |
|
1431 |
AwtComponent::GetComponent(hWndFromPoint); |
|
1432 |
// Need extra copies for non-client area issues |
|
1433 |
AwtComponent* mouseWheelComp = mouseComp; |
|
1434 |
HWND hWndForWheel = hWndFromPoint; |
|
1435 |
||
1436 |
// If the point under the mouse isn't in the client area, |
|
1437 |
// ignore it to maintain compatibility with Solaris (#4095172) |
|
1438 |
RECT windowRect; |
|
1439 |
::GetClientRect(hWndFromPoint, &windowRect); |
|
1440 |
POINT topLeft; |
|
1441 |
topLeft.x = 0; |
|
1442 |
topLeft.y = 0; |
|
1443 |
::ClientToScreen(hWndFromPoint, &topLeft); |
|
1444 |
windowRect.top += topLeft.y; |
|
1445 |
windowRect.bottom += topLeft.y; |
|
1446 |
windowRect.left += topLeft.x; |
|
1447 |
windowRect.right += topLeft.x; |
|
1448 |
if ((curPos.y < windowRect.top) || |
|
1449 |
(curPos.y >= windowRect.bottom) || |
|
1450 |
(curPos.x < windowRect.left) || |
|
1451 |
(curPos.x >= windowRect.right)) { |
|
1452 |
mouseComp = NULL; |
|
1453 |
hWndFromPoint = NULL; |
|
1454 |
} |
|
1455 |
||
1456 |
/* |
|
1457 |
* Look for mouse transitions between windows & create |
|
1458 |
* MouseExit & MouseEnter messages |
|
1459 |
*/ |
|
1460 |
// 6479820. Should check if a window is in manual resizing process: skip |
|
1461 |
// sending any MouseExit/Enter events while inside resize-loop. |
|
1462 |
// Note that window being in manual moving process could still |
|
1463 |
// produce redundant enter/exit mouse events. In future, they can be |
|
1464 |
// made skipped in a similar way. |
|
1465 |
if (mouseComp != m_lastMouseOver && !AwtWindow::IsResizing()) { |
|
1466 |
/* |
|
1467 |
* Send the messages right to the windows so that they are in |
|
1468 |
* the right sequence. |
|
1469 |
*/ |
|
1470 |
if (m_lastMouseOver) { |
|
1471 |
dwCurPos = dwScreenPos; |
|
1472 |
curPos.x = LOWORD(dwCurPos); |
|
1473 |
curPos.y = HIWORD(dwCurPos); |
|
1474 |
::MapWindowPoints(HWND_DESKTOP, m_lastMouseOver->GetHWnd(), |
|
1475 |
&curPos, 1); |
|
1476 |
mouseLParam = MAKELPARAM((WORD)curPos.x, (WORD)curPos.y); |
|
1477 |
m_lastMouseOver->SendMessage(WM_AWT_MOUSEEXIT, mouseWParam, |
|
1478 |
mouseLParam); |
|
1479 |
} |
|
1480 |
if (mouseComp) { |
|
1481 |
dwCurPos = dwScreenPos; |
|
1482 |
curPos.x = LOWORD(dwCurPos); |
|
1483 |
curPos.y = HIWORD(dwCurPos); |
|
1484 |
::MapWindowPoints(HWND_DESKTOP, mouseComp->GetHWnd(), |
|
1485 |
&curPos, 1); |
|
1486 |
mouseLParam = MAKELPARAM((WORD)curPos.x, (WORD)curPos.y); |
|
1487 |
mouseComp->SendMessage(WM_AWT_MOUSEENTER, mouseWParam, |
|
1488 |
mouseLParam); |
|
1489 |
} |
|
1490 |
m_lastMouseOver = mouseComp; |
|
1491 |
} |
|
1492 |
||
1493 |
/* |
|
1494 |
* For MouseWheelEvents, hwnd must be changed to be the Component under |
|
1495 |
* the mouse, not the Component with the input focus. |
|
1496 |
*/ |
|
1497 |
||
1498 |
if (msg.message == WM_MOUSEWHEEL && |
|
1499 |
mouseWheelComp != NULL) { //i.e. mouse is over client area for this |
|
1500 |
//window |
|
1501 |
msg.hwnd = hWndForWheel; |
|
1502 |
} |
|
1503 |
||
1504 |
/* |
|
1505 |
* Make sure we get at least one last chance to check for transitions |
|
1506 |
* before we sleep |
|
1507 |
*/ |
|
1508 |
if (m_lastMouseOver && !m_timer) { |
|
1509 |
m_timer = ::SetTimer(m_toolkitHWnd, IDT_AWT_MOUSECHECK, 200, 0); |
|
1510 |
} |
|
1511 |
return FALSE; /* Now go ahead and process current message as usual */ |
|
1512 |
} |
|
1513 |
||
1514 |
BOOL AwtToolkit::PreProcessKeyMsg(AwtComponent* p, MSG& msg) |
|
1515 |
{ |
|
1516 |
// get keyboard state for use in AwtToolkit::GetKeyboardState |
|
1517 |
CriticalSection::Lock l(m_lockKB); |
|
1518 |
::GetKeyboardState(m_lastKeyboardState); |
|
1519 |
return FALSE; |
|
1520 |
} |
|
1521 |
||
1522 |
void *AwtToolkit::SyncCall(void *(*ftn)(void *), void *param) { |
|
1523 |
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); |
|
1524 |
if (!IsMainThread()) { |
|
1525 |
CriticalSection::Lock l(GetSyncCS()); |
|
1526 |
return (*ftn)(param); |
|
1527 |
} else { |
|
1528 |
return (*ftn)(param); |
|
1529 |
} |
|
1530 |
} |
|
1531 |
||
1532 |
void AwtToolkit::SyncCall(void (*ftn)(void *), void *param) { |
|
1533 |
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); |
|
1534 |
if (!IsMainThread()) { |
|
1535 |
CriticalSection::Lock l(GetSyncCS()); |
|
1536 |
(*ftn)(param); |
|
1537 |
} else { |
|
1538 |
(*ftn)(param); |
|
1539 |
} |
|
1540 |
} |
|
1541 |
||
1542 |
void *AwtToolkit::SyncCall(void *(*ftn)(void)) { |
|
1543 |
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); |
|
1544 |
if (!IsMainThread()) { |
|
1545 |
CriticalSection::Lock l(GetSyncCS()); |
|
1546 |
return (*ftn)(); |
|
1547 |
} else { |
|
1548 |
return (*ftn)(); |
|
1549 |
} |
|
1550 |
} |
|
1551 |
||
1552 |
void AwtToolkit::SyncCall(void (*ftn)(void)) { |
|
1553 |
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); |
|
1554 |
if (!IsMainThread()) { |
|
1555 |
CriticalSection::Lock l(GetSyncCS()); |
|
1556 |
(*ftn)(); |
|
1557 |
} else { |
|
1558 |
(*ftn)(); |
|
1559 |
} |
|
1560 |
} |
|
1561 |
||
1562 |
UINT AwtToolkit::CreateCmdID(AwtObject* object) |
|
1563 |
{ |
|
1564 |
return m_cmdIDs->Add(object); |
|
1565 |
} |
|
1566 |
||
1567 |
void AwtToolkit::RemoveCmdID(UINT id) |
|
1568 |
{ |
|
1569 |
m_cmdIDs->Remove(id); |
|
1570 |
} |
|
1571 |
||
1572 |
AwtObject* AwtToolkit::LookupCmdID(UINT id) |
|
1573 |
{ |
|
1574 |
return m_cmdIDs->Lookup(id); |
|
1575 |
} |
|
1576 |
||
1577 |
HICON AwtToolkit::GetAwtIcon() |
|
1578 |
{ |
|
1579 |
return ::LoadIcon(GetModuleHandle(), TEXT("AWT_ICON")); |
|
1580 |
} |
|
1581 |
||
1582 |
HICON AwtToolkit::GetAwtIconSm() |
|
1583 |
{ |
|
1584 |
static HICON defaultIconSm = NULL; |
|
1585 |
static int prevSmx = 0; |
|
1586 |
static int prevSmy = 0; |
|
1587 |
||
1588 |
int smx = GetSystemMetrics(SM_CXSMICON); |
|
1589 |
int smy = GetSystemMetrics(SM_CYSMICON); |
|
1590 |
||
1591 |
// Fixed 6364216: LoadImage() may leak memory |
|
1592 |
if (defaultIconSm == NULL || smx != prevSmx || smy != prevSmy) { |
|
1593 |
defaultIconSm = (HICON)LoadImage(GetModuleHandle(), TEXT("AWT_ICON"), IMAGE_ICON, smx, smy, 0); |
|
1594 |
prevSmx = smx; |
|
1595 |
prevSmy = smy; |
|
1596 |
} |
|
1597 |
return defaultIconSm; |
|
1598 |
} |
|
1599 |
||
4367
e60cfd711532
6901021: Security Warning Icon not getting displayed properly when frame loses focus
anthony
parents:
3498
diff
changeset
|
1600 |
// The icon at index 0 must be gray. See AwtWindow::GetSecurityWarningIcon() |
2472
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1601 |
HICON AwtToolkit::GetSecurityWarningIcon(UINT index, UINT w, UINT h) |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1602 |
{ |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1603 |
//Note: should not exceed 10 because of the current implementation. |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1604 |
static const int securityWarningIconCounter = 3; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1605 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1606 |
static HICON securityWarningIcon[securityWarningIconCounter] = {NULL, NULL, NULL};; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1607 |
static UINT securityWarningIconWidth[securityWarningIconCounter] = {0, 0, 0}; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1608 |
static UINT securityWarningIconHeight[securityWarningIconCounter] = {0, 0, 0}; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1609 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1610 |
index = AwtToolkit::CalculateWave(index, securityWarningIconCounter); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1611 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1612 |
if (securityWarningIcon[index] == NULL || |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1613 |
w != securityWarningIconWidth[index] || |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1614 |
h != securityWarningIconHeight[index]) |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1615 |
{ |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1616 |
if (securityWarningIcon[index] != NULL) |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1617 |
{ |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1618 |
::DestroyIcon(securityWarningIcon[index]); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1619 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1620 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1621 |
static const wchar_t securityWarningIconName[] = L"SECURITY_WARNING_"; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1622 |
wchar_t iconResourceName[sizeof(securityWarningIconName) + 2]; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1623 |
::ZeroMemory(iconResourceName, sizeof(iconResourceName)); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1624 |
wcscpy(iconResourceName, securityWarningIconName); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1625 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1626 |
wchar_t strIndex[2]; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1627 |
::ZeroMemory(strIndex, sizeof(strIndex)); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1628 |
strIndex[0] = L'0' + index; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1629 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1630 |
wcscat(iconResourceName, strIndex); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1631 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1632 |
securityWarningIcon[index] = (HICON)::LoadImage(GetModuleHandle(), |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1633 |
iconResourceName, |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1634 |
IMAGE_ICON, w, h, LR_DEFAULTCOLOR); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1635 |
securityWarningIconWidth[index] = w; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1636 |
securityWarningIconHeight[index] = h; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1637 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1638 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1639 |
return securityWarningIcon[index]; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1640 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1641 |
|
2 | 1642 |
void AwtToolkit::SetHeapCheck(long flag) { |
1643 |
if (flag) { |
|
1644 |
printf("heap checking not supported with this build\n"); |
|
1645 |
} |
|
1646 |
} |
|
1647 |
||
1648 |
void throw_if_shutdown(void) throw (awt_toolkit_shutdown) |
|
1649 |
{ |
|
1650 |
AwtToolkit::GetInstance().VerifyActive(); |
|
1651 |
} |
|
1652 |
void hang_if_shutdown(void) |
|
1653 |
{ |
|
1654 |
try { |
|
1655 |
AwtToolkit::GetInstance().VerifyActive(); |
|
1656 |
} catch (awt_toolkit_shutdown&) { |
|
1657 |
// Never return. The VM will halt the process. |
|
1658 |
::WaitForSingleObject(::CreateEvent(NULL, TRUE, FALSE, NULL), |
|
1659 |
INFINITE); |
|
1660 |
// Should never get here. |
|
1661 |
DASSERT(FALSE); |
|
1662 |
} |
|
1663 |
} |
|
1664 |
||
105
e08ac2105adc
6595651: Focus transfers broken for applications embedding AWT across processes
son
parents:
2
diff
changeset
|
1665 |
// for now we support only one embedder, but should be ready for future |
e08ac2105adc
6595651: Focus transfers broken for applications embedding AWT across processes
son
parents:
2
diff
changeset
|
1666 |
void AwtToolkit::RegisterEmbedderProcessId(HWND embedder) |
2 | 1667 |
{ |
105
e08ac2105adc
6595651: Focus transfers broken for applications embedding AWT across processes
son
parents:
2
diff
changeset
|
1668 |
if (m_embedderProcessID) { |
e08ac2105adc
6595651: Focus transfers broken for applications embedding AWT across processes
son
parents:
2
diff
changeset
|
1669 |
// we already set embedder process and do not expect |
e08ac2105adc
6595651: Focus transfers broken for applications embedding AWT across processes
son
parents:
2
diff
changeset
|
1670 |
// two different processes to embed the same AwtToolkit |
e08ac2105adc
6595651: Focus transfers broken for applications embedding AWT across processes
son
parents:
2
diff
changeset
|
1671 |
return; |
2 | 1672 |
} |
1673 |
||
105
e08ac2105adc
6595651: Focus transfers broken for applications embedding AWT across processes
son
parents:
2
diff
changeset
|
1674 |
embedder = ::GetAncestor(embedder, GA_ROOT); |
e08ac2105adc
6595651: Focus transfers broken for applications embedding AWT across processes
son
parents:
2
diff
changeset
|
1675 |
::GetWindowThreadProcessId(embedder, &m_embedderProcessID); |
2 | 1676 |
} |
1677 |
||
1678 |
JNIEnv* AwtToolkit::m_env; |
|
3498 | 1679 |
DWORD AwtToolkit::m_threadId; |
2 | 1680 |
|
1681 |
void AwtToolkit::SetEnv(JNIEnv *env) { |
|
1682 |
if (m_env != NULL) { // If already cashed (by means of embeddedInit() call). |
|
1683 |
return; |
|
1684 |
} |
|
3498 | 1685 |
m_threadId = GetCurrentThreadId(); |
2 | 1686 |
m_env = env; |
1687 |
} |
|
1688 |
||
1689 |
JNIEnv* AwtToolkit::GetEnv() { |
|
3498 | 1690 |
return (m_env == NULL || m_threadId != GetCurrentThreadId()) ? |
2 | 1691 |
(JNIEnv*)JNU_GetEnv(jvm, JNI_VERSION_1_2) : m_env; |
1692 |
} |
|
1693 |
||
2472
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1694 |
BOOL AwtToolkit::GetScreenInsets(int screenNum, RECT * rect) |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1695 |
{ |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1696 |
/* if primary display */ |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1697 |
if (screenNum == 0) { |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1698 |
RECT rRW; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1699 |
if (::SystemParametersInfo(SPI_GETWORKAREA,0,(void *) &rRW,0) == TRUE) { |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1700 |
rect->top = rRW.top; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1701 |
rect->left = rRW.left; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1702 |
rect->bottom = ::GetSystemMetrics(SM_CYSCREEN) - rRW.bottom; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1703 |
rect->right = ::GetSystemMetrics(SM_CXSCREEN) - rRW.right; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1704 |
return TRUE; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1705 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1706 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1707 |
/* if additional display */ |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1708 |
else { |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1709 |
MONITORINFO *miInfo; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1710 |
miInfo = AwtWin32GraphicsDevice::GetMonitorInfo(screenNum); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1711 |
if (miInfo) { |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1712 |
rect->top = miInfo->rcWork.top - miInfo->rcMonitor.top; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1713 |
rect->left = miInfo->rcWork.left - miInfo->rcMonitor.left; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1714 |
rect->bottom = miInfo->rcMonitor.bottom - miInfo->rcWork.bottom; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1715 |
rect->right = miInfo->rcMonitor.right - miInfo->rcWork.right; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1716 |
return TRUE; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1717 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1718 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1719 |
return FALSE; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1720 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1721 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1722 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1723 |
void AwtToolkit::GetWindowRect(HWND hWnd, LPRECT lpRect) |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1724 |
{ |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1725 |
try { |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1726 |
if (S_OK == DwmAPI::DwmGetWindowAttribute(hWnd, |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1727 |
DwmAPI::DWMWA_EXTENDED_FRAME_BOUNDS, |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1728 |
lpRect, sizeof(*lpRect))) |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1729 |
{ |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1730 |
return; |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1731 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1732 |
} catch (const DllUtil::Exception &) {} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1733 |
|
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1734 |
::GetWindowRect(hWnd, lpRect); |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1735 |
} |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
1736 |
|
7004
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1737 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1738 |
/************************************************************************ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1739 |
* AWT preloading support |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1740 |
*/ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1741 |
bool AwtToolkit::PreloadAction::EnsureInited() |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1742 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1743 |
DWORD _initThreadId = GetInitThreadID(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1744 |
if (_initThreadId != 0) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1745 |
// already inited |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1746 |
// ensure the action is inited on correct thread |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1747 |
PreloadThread &preloadThread |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1748 |
= AwtToolkit::GetInstance().GetPreloadThread(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1749 |
if (_initThreadId == preloadThread.GetThreadId()) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1750 |
if (!preloadThread.IsWrongThread()) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1751 |
return true; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1752 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1753 |
// inited on preloadThread (wrongThread), not cleaned yet |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1754 |
// have to wait cleanup completion |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1755 |
preloadThread.Wait4Finish(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1756 |
} else { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1757 |
// inited on other thread (Toolkit thread?) |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1758 |
// consider as correctly inited |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1759 |
return true; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1760 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1761 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1762 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1763 |
// init on Toolkit thread |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1764 |
AwtToolkit::GetInstance().InvokeFunction(InitWrapper, this); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1765 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1766 |
return true; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1767 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1768 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1769 |
DWORD AwtToolkit::PreloadAction::GetInitThreadID() |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1770 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1771 |
CriticalSection::Lock lock(initLock); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1772 |
return initThreadId; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1773 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1774 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1775 |
bool AwtToolkit::PreloadAction::Clean() |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1776 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1777 |
DWORD _initThreadId = GetInitThreadID(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1778 |
if (_initThreadId == ::GetCurrentThreadId()) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1779 |
// inited on this thread |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1780 |
Clean(false); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1781 |
return true; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1782 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1783 |
return false; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1784 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1785 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1786 |
/*static*/ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1787 |
void AwtToolkit::PreloadAction::InitWrapper(void *param) |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1788 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1789 |
PreloadAction *pThis = (PreloadAction *)param; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1790 |
pThis->Init(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1791 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1792 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1793 |
void AwtToolkit::PreloadAction::Init() |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1794 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1795 |
CriticalSection::Lock lock(initLock); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1796 |
if (initThreadId == 0) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1797 |
initThreadId = ::GetCurrentThreadId(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1798 |
InitImpl(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1799 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1800 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1801 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1802 |
void AwtToolkit::PreloadAction::Clean(bool reInit) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1803 |
CriticalSection::Lock lock(initLock); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1804 |
if (initThreadId != 0) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1805 |
//ASSERT(initThreadId == ::GetCurrentThreadId()); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1806 |
CleanImpl(reInit); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1807 |
initThreadId = 0; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1808 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1809 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1810 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1811 |
// PreloadThread implementation |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1812 |
AwtToolkit::PreloadThread::PreloadThread() |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1813 |
: status(None), wrongThread(false), threadId(0), |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1814 |
pActionChain(NULL), pLastProcessedAction(NULL), |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1815 |
execFunc(NULL), execParam(NULL) |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1816 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1817 |
hFinished = ::CreateEvent(NULL, TRUE, FALSE, NULL); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1818 |
hAwake = ::CreateEvent(NULL, FALSE, FALSE, NULL); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1819 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1820 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1821 |
AwtToolkit::PreloadThread::~PreloadThread() |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1822 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1823 |
//Terminate(false); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1824 |
::CloseHandle(hFinished); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1825 |
::CloseHandle(hAwake); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1826 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1827 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1828 |
bool AwtToolkit::PreloadThread::AddAction(AwtToolkit::PreloadAction *pAction) |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1829 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1830 |
CriticalSection::Lock lock(threadLock); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1831 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1832 |
if (status > Preloading) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1833 |
// too late - the thread already terminated or run as toolkit thread |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1834 |
return false; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1835 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1836 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1837 |
if (pActionChain == NULL) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1838 |
// 1st action |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1839 |
pActionChain = pAction; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1840 |
} else { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1841 |
// add the action to the chain |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1842 |
PreloadAction *pChain = pActionChain; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1843 |
while (true) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1844 |
PreloadAction *pNext = pChain->GetNext(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1845 |
if (pNext == NULL) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1846 |
break; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1847 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1848 |
pChain = pNext; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1849 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1850 |
pChain->SetNext(pAction); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1851 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1852 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1853 |
if (status > None) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1854 |
// the thread is already running (status == Preloading) |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1855 |
AwakeThread(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1856 |
return true; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1857 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1858 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1859 |
// need to start thread |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1860 |
::ResetEvent(hAwake); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1861 |
::ResetEvent(hFinished); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1862 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1863 |
HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0x100000, StaticThreadProc, |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1864 |
this, 0, &threadId); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1865 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1866 |
if (hThread == 0) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1867 |
threadId = 0; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1868 |
return false; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1869 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1870 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1871 |
status = Preloading; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1872 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1873 |
::CloseHandle(hThread); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1874 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1875 |
return true; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1876 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1877 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1878 |
bool AwtToolkit::PreloadThread::Terminate(bool wrongThread) |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1879 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1880 |
CriticalSection::Lock lock(threadLock); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1881 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1882 |
if (status != Preloading) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1883 |
return false; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1884 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1885 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1886 |
execFunc = NULL; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1887 |
execParam = NULL; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1888 |
this->wrongThread = wrongThread; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1889 |
status = Cleaning; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1890 |
AwakeThread(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1891 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1892 |
return true; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1893 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1894 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1895 |
bool AwtToolkit::PreloadThread::InvokeAndTerminate(void(_cdecl *fn)(void *), void *param) |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1896 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1897 |
CriticalSection::Lock lock(threadLock); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1898 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1899 |
if (status != Preloading) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1900 |
return false; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1901 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1902 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1903 |
execFunc = fn; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1904 |
execParam = param; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1905 |
status = fn == NULL ? Cleaning : RunningToolkit; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1906 |
AwakeThread(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1907 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1908 |
return true; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1909 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1910 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1911 |
/*static*/ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1912 |
unsigned WINAPI AwtToolkit::PreloadThread::StaticThreadProc(void *param) |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1913 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1914 |
AwtToolkit::PreloadThread *pThis = (AwtToolkit::PreloadThread *)param; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1915 |
return pThis->ThreadProc(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1916 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1917 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1918 |
unsigned AwtToolkit::PreloadThread::ThreadProc() |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1919 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1920 |
void(_cdecl *_execFunc)(void *) = NULL; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1921 |
void *_execParam = NULL; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1922 |
bool _wrongThread = false; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1923 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1924 |
// initialization |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1925 |
while (true) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1926 |
PreloadAction *pAction; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1927 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1928 |
CriticalSection::Lock lock(threadLock); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1929 |
if (status != Preloading) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1930 |
// get invoke parameters |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1931 |
_execFunc = execFunc; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1932 |
_execParam = execParam; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1933 |
_wrongThread = wrongThread; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1934 |
break; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1935 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1936 |
pAction = GetNextAction(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1937 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1938 |
if (pAction != NULL) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1939 |
pAction->Init(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1940 |
} else { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1941 |
::WaitForSingleObject(hAwake, INFINITE); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1942 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1943 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1944 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1945 |
// call a function from InvokeAndTerminate |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1946 |
if (_execFunc != NULL) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1947 |
_execFunc(_execParam); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1948 |
} else { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1949 |
// time to terminate.. |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1950 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1951 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1952 |
// cleanup |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1953 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1954 |
CriticalSection::Lock lock(threadLock); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1955 |
pLastProcessedAction = NULL; // goto 1st action in the chain |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1956 |
status = Cleaning; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1957 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1958 |
for (PreloadAction *pAction = GetNextAction(); pAction != NULL; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1959 |
pAction = GetNextAction()) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1960 |
pAction->Clean(_wrongThread); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1961 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1962 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1963 |
// don't clear threadId! it is used by PreloadAction::EnsureInited |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1964 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1965 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1966 |
CriticalSection::Lock lock(threadLock); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1967 |
status = Finished; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1968 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1969 |
::SetEvent(hFinished); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1970 |
return 0; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1971 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1972 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1973 |
AwtToolkit::PreloadAction* AwtToolkit::PreloadThread::GetNextAction() |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1974 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1975 |
CriticalSection::Lock lock(threadLock); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1976 |
PreloadAction *pAction = (pLastProcessedAction == NULL) |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1977 |
? pActionChain |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1978 |
: pLastProcessedAction->GetNext(); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1979 |
if (pAction != NULL) { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1980 |
pLastProcessedAction = pAction; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1981 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1982 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1983 |
return pAction; |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1984 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1985 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1986 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1987 |
extern "C" { |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1988 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1989 |
/* Terminates preload thread (if it's still alive |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1990 |
* - it may occur if the application doesn't use AWT). |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1991 |
* The function is called from launcher after completion main java thread. |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1992 |
*/ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1993 |
__declspec(dllexport) void preloadStop() |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1994 |
{ |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1995 |
AwtToolkit::GetInstance().GetPreloadThread().Terminate(false); |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1996 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1997 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1998 |
} |
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
1999 |
|
3f92ea1ffcac
6867515: Reduce impact of D3D initializion on startup time
amenkov
parents:
6642
diff
changeset
|
2000 |
|
2 | 2001 |
/************************************************************************ |
2002 |
* Toolkit native methods |
|
2003 |
*/ |
|
2004 |
||
2005 |
extern "C" { |
|
2006 |
||
2007 |
/* |
|
2008 |
* Class: java_awt_Toolkit |
|
2009 |
* Method: initIDs |
|
2010 |
* Signature: ()V |
|
2011 |
*/ |
|
2012 |
JNIEXPORT void JNICALL |
|
2013 |
Java_java_awt_Toolkit_initIDs(JNIEnv *env, jclass cls) { |
|
2014 |
TRY; |
|
2015 |
||
2016 |
AwtToolkit::getDefaultToolkitMID = |
|
2017 |
env->GetStaticMethodID(cls,"getDefaultToolkit","()Ljava/awt/Toolkit;"); |
|
2018 |
AwtToolkit::getFontMetricsMID = |
|
2019 |
env->GetMethodID(cls, "getFontMetrics", |
|
2020 |
"(Ljava/awt/Font;)Ljava/awt/FontMetrics;"); |
|
2021 |
AwtToolkit::insetsMID = |
|
2022 |
env->GetMethodID(env->FindClass("java/awt/Insets"), "<init>", "(IIII)V"); |
|
2023 |
||
2024 |
DASSERT(AwtToolkit::getDefaultToolkitMID != NULL); |
|
2025 |
DASSERT(AwtToolkit::getFontMetricsMID != NULL); |
|
2026 |
DASSERT(AwtToolkit::insetsMID != NULL); |
|
2027 |
||
2028 |
CATCH_BAD_ALLOC; |
|
2029 |
} |
|
2030 |
||
2031 |
||
2032 |
} /* extern "C" */ |
|
2033 |
||
2034 |
/************************************************************************ |
|
2035 |
* WToolkit native methods |
|
2036 |
*/ |
|
2037 |
||
2038 |
extern "C" { |
|
2039 |
||
2040 |
/* |
|
2041 |
* Class: sun_awt_windows_WToolkit |
|
2042 |
* Method: initIDs |
|
2043 |
* Signature: ()V |
|
2044 |
*/ |
|
2045 |
JNIEXPORT void JNICALL |
|
2046 |
Java_sun_awt_windows_WToolkit_initIDs(JNIEnv *env, jclass cls) |
|
2047 |
{ |
|
2048 |
TRY; |
|
2049 |
||
2050 |
AwtToolkit::windowsSettingChangeMID = |
|
2051 |
env->GetMethodID(cls, "windowsSettingChange", "()V"); |
|
2052 |
DASSERT(AwtToolkit::windowsSettingChangeMID != 0); |
|
2053 |
||
2054 |
AwtToolkit::displayChangeMID = |
|
2055 |
env->GetStaticMethodID(cls, "displayChanged", "()V"); |
|
2056 |
DASSERT(AwtToolkit::displayChangeMID != 0); |
|
2057 |
||
2058 |
// Set various global IDs needed by JAWT code. Note: these |
|
2059 |
// variables cannot be set by JAWT code directly due to |
|
2060 |
// different permissions that that code may be run under |
|
2061 |
// (bug 4796548). It would be nice to initialize these |
|
2062 |
// variables lazily, but given the minimal number of calls |
|
2063 |
// for this, it seems simpler to just do it at startup with |
|
2064 |
// negligible penalty. |
|
2065 |
jclass sDataClassLocal = env->FindClass("sun/java2d/SurfaceData"); |
|
2066 |
DASSERT(sDataClassLocal != 0); |
|
2067 |
jclass vImgClassLocal = env->FindClass("sun/awt/image/SunVolatileImage"); |
|
2068 |
DASSERT(vImgClassLocal != 0); |
|
2069 |
jclass vSMgrClassLocal = |
|
2070 |
env->FindClass("sun/awt/image/VolatileSurfaceManager"); |
|
2071 |
DASSERT(vSMgrClassLocal != 0); |
|
2072 |
jclass componentClassLocal = env->FindClass("java/awt/Component"); |
|
2073 |
DASSERT(componentClassLocal != 0); |
|
2074 |
jawtSMgrID = env->GetFieldID(vImgClassLocal, "volSurfaceManager", |
|
2075 |
"Lsun/awt/image/VolatileSurfaceManager;"); |
|
2076 |
DASSERT(jawtSMgrID != 0); |
|
2077 |
jawtSDataID = env->GetFieldID(vSMgrClassLocal, "sdCurrent", |
|
2078 |
"Lsun/java2d/SurfaceData;"); |
|
2079 |
DASSERT(jawtSDataID != 0); |
|
2080 |
jawtPDataID = env->GetFieldID(sDataClassLocal, "pData", "J"); |
|
2081 |
DASSERT(jawtPDataID != 0); |
|
2082 |
||
2083 |
// Save these classes in global references for later use |
|
2084 |
jawtVImgClass = (jclass)env->NewGlobalRef(vImgClassLocal); |
|
2085 |
jawtComponentClass = (jclass)env->NewGlobalRef(componentClassLocal); |
|
2086 |
||
2087 |
CATCH_BAD_ALLOC; |
|
2088 |
} |
|
2089 |
||
2090 |
||
2091 |
/* |
|
2092 |
* Class: sun_awt_windows_Toolkit |
|
2093 |
* Method: disableCustomPalette |
|
2094 |
* Signature: ()V |
|
2095 |
*/ |
|
2096 |
JNIEXPORT void JNICALL |
|
2097 |
Java_sun_awt_windows_WToolkit_disableCustomPalette(JNIEnv *env, jclass cls) { |
|
2098 |
AwtPalette::DisableCustomPalette(); |
|
2099 |
} |
|
2100 |
||
2101 |
/* |
|
2102 |
* Class: sun_awt_windows_WToolkit |
|
2103 |
* Method: embeddedInit |
|
2104 |
* Signature: ()Z |
|
2105 |
*/ |
|
2106 |
JNIEXPORT jboolean JNICALL |
|
2107 |
Java_sun_awt_windows_WToolkit_embeddedInit(JNIEnv *env, jclass cls) |
|
2108 |
{ |
|
2109 |
TRY; |
|
2110 |
||
2111 |
AwtToolkit::SetEnv(env); |
|
2112 |
||
2113 |
return AwtToolkit::GetInstance().Initialize(FALSE); |
|
2114 |
||
2115 |
CATCH_BAD_ALLOC_RET(JNI_FALSE); |
|
2116 |
} |
|
2117 |
||
2118 |
/* |
|
2119 |
* Class: sun_awt_windows_WToolkit |
|
2120 |
* Method: embeddedDispose |
|
2121 |
* Signature: ()Z |
|
2122 |
*/ |
|
2123 |
JNIEXPORT jboolean JNICALL |
|
2124 |
Java_sun_awt_windows_WToolkit_embeddedDispose(JNIEnv *env, jclass cls) |
|
2125 |
{ |
|
2126 |
TRY; |
|
2127 |
||
2128 |
BOOL retval = AwtToolkit::GetInstance().Dispose(); |
|
2129 |
AwtToolkit::GetInstance().SetPeer(env, NULL); |
|
2130 |
return retval; |
|
2131 |
||
2132 |
CATCH_BAD_ALLOC_RET(JNI_FALSE); |
|
2133 |
} |
|
2134 |
||
2135 |
/* |
|
2136 |
* Class: sun_awt_windows_WToolkit |
|
2137 |
* Method: embeddedEventLoopIdleProcessing |
|
2138 |
* Signature: ()V |
|
2139 |
*/ |
|
2140 |
JNIEXPORT void JNICALL |
|
2141 |
Java_sun_awt_windows_WToolkit_embeddedEventLoopIdleProcessing(JNIEnv *env, |
|
2142 |
jobject self) |
|
2143 |
{ |
|
2144 |
VerifyWindowMoveLockReleased(); |
|
2145 |
} |
|
2146 |
||
2147 |
||
2148 |
/* |
|
2149 |
* Class: sun_awt_windows_WToolkit |
|
2150 |
* Method: init |
|
2151 |
* Signature: ()Z |
|
2152 |
*/ |
|
2153 |
JNIEXPORT jboolean JNICALL |
|
2154 |
Java_sun_awt_windows_WToolkit_init(JNIEnv *env, jobject self) |
|
2155 |
{ |
|
2156 |
TRY; |
|
2157 |
||
2158 |
AwtToolkit::SetEnv(env); |
|
2159 |
||
2160 |
AwtToolkit::GetInstance().SetPeer(env, self); |
|
2161 |
||
2162 |
// This call will fail if the Toolkit was already initialized. |
|
2163 |
// In that case, we don't want to start another message pump. |
|
2164 |
return AwtToolkit::GetInstance().Initialize(TRUE); |
|
2165 |
||
2166 |
CATCH_BAD_ALLOC_RET(FALSE); |
|
2167 |
} |
|
2168 |
||
2169 |
/* |
|
2170 |
* Class: sun_awt_windows_WToolkit |
|
2171 |
* Method: eventLoop |
|
2172 |
* Signature: ()V |
|
2173 |
*/ |
|
2174 |
JNIEXPORT void JNICALL |
|
2175 |
Java_sun_awt_windows_WToolkit_eventLoop(JNIEnv *env, jobject self) |
|
2176 |
{ |
|
2177 |
TRY; |
|
2178 |
||
2179 |
DASSERT(AwtToolkit::GetInstance().localPump()); |
|
2180 |
||
2181 |
AwtToolkit::SetBusy(TRUE); |
|
2182 |
||
2183 |
AwtToolkit::GetInstance().MessageLoop(AwtToolkit::PrimaryIdleFunc, |
|
2184 |
AwtToolkit::CommonPeekMessageFunc); |
|
2185 |
||
2186 |
AwtToolkit::GetInstance().Dispose(); |
|
2187 |
||
2188 |
AwtToolkit::SetBusy(FALSE); |
|
2189 |
||
2190 |
/* |
|
2191 |
* IMPORTANT NOTES: |
|
2192 |
* The AwtToolkit has been destructed by now. |
|
2193 |
* DO NOT CALL any method of AwtToolkit!!! |
|
2194 |
*/ |
|
2195 |
||
2196 |
CATCH_BAD_ALLOC; |
|
2197 |
} |
|
2198 |
||
2199 |
/* |
|
2200 |
* Class: sun_awt_windows_WToolkit |
|
2201 |
* Method: shutdown |
|
2202 |
* Signature: ()V |
|
2203 |
*/ |
|
2204 |
JNIEXPORT void JNICALL |
|
2205 |
Java_sun_awt_windows_WToolkit_shutdown(JNIEnv *env, jobject self) |
|
2206 |
{ |
|
2207 |
TRY; |
|
2208 |
||
2209 |
AwtToolkit& tk = AwtToolkit::GetInstance(); |
|
2210 |
||
2211 |
tk.QuitMessageLoop(AwtToolkit::EXIT_ALL_ENCLOSING_LOOPS); |
|
2212 |
||
2213 |
while (!tk.IsDisposed()) { |
|
2214 |
Sleep(100); |
|
2215 |
} |
|
2216 |
||
2217 |
CATCH_BAD_ALLOC; |
|
2218 |
} |
|
2219 |
||
2220 |
/* |
|
2221 |
* Class: sun_awt_windows_WToolkit |
|
2222 |
* Method: startSecondaryEventLoop |
|
2223 |
* Signature: ()V; |
|
2224 |
*/ |
|
2225 |
JNIEXPORT void JNICALL |
|
2226 |
Java_sun_awt_windows_WToolkit_startSecondaryEventLoop( |
|
2227 |
JNIEnv *env, |
|
2228 |
jclass) |
|
2229 |
{ |
|
2230 |
TRY; |
|
2231 |
||
2232 |
DASSERT(AwtToolkit::MainThread() == ::GetCurrentThreadId()); |
|
2233 |
||
2234 |
AwtToolkit::GetInstance().MessageLoop(AwtToolkit::SecondaryIdleFunc, |
|
2235 |
AwtToolkit::CommonPeekMessageFunc); |
|
2236 |
||
2237 |
CATCH_BAD_ALLOC; |
|
2238 |
} |
|
2239 |
||
2240 |
/* |
|
2241 |
* Class: sun_awt_windows_WToolkit |
|
2242 |
* Method: quitSecondaryEventLoop |
|
2243 |
* Signature: ()V; |
|
2244 |
*/ |
|
2245 |
JNIEXPORT void JNICALL |
|
2246 |
Java_sun_awt_windows_WToolkit_quitSecondaryEventLoop( |
|
2247 |
JNIEnv *env, |
|
2248 |
jclass) |
|
2249 |
{ |
|
2250 |
TRY; |
|
2251 |
||
2252 |
AwtToolkit::GetInstance().QuitMessageLoop(AwtToolkit::EXIT_ENCLOSING_LOOP); |
|
2253 |
||
2254 |
CATCH_BAD_ALLOC; |
|
2255 |
} |
|
2256 |
||
2257 |
/* |
|
2258 |
* Class: sun_awt_windows_WToolkit |
|
2259 |
* Method: makeColorModel |
|
2260 |
* Signature: ()Ljava/awt/image/ColorModel; |
|
2261 |
*/ |
|
2262 |
JNIEXPORT jobject JNICALL |
|
2263 |
Java_sun_awt_windows_WToolkit_makeColorModel(JNIEnv *env, jclass cls) |
|
2264 |
{ |
|
2265 |
TRY; |
|
2266 |
||
2267 |
return AwtWin32GraphicsDevice::GetColorModel(env, JNI_FALSE, |
|
2268 |
AwtWin32GraphicsDevice::GetDefaultDeviceIndex()); |
|
2269 |
||
2270 |
CATCH_BAD_ALLOC_RET(NULL); |
|
2271 |
} |
|
2272 |
||
2273 |
/* |
|
2274 |
* Class: sun_awt_windows_WToolkit |
|
2275 |
* Method: getMaximumCursorColors |
|
2276 |
* Signature: ()I |
|
2277 |
*/ |
|
2278 |
JNIEXPORT jint JNICALL |
|
2279 |
Java_sun_awt_windows_WToolkit_getMaximumCursorColors(JNIEnv *env, jobject self) |
|
2280 |
{ |
|
2281 |
TRY; |
|
2282 |
||
2283 |
HDC hIC = ::CreateIC(TEXT("DISPLAY"), NULL, NULL, NULL); |
|
2284 |
||
2285 |
int nColor = 256; |
|
2286 |
switch (::GetDeviceCaps(hIC, BITSPIXEL) * ::GetDeviceCaps(hIC, PLANES)) { |
|
2287 |
case 1: nColor = 2; break; |
|
2288 |
case 4: nColor = 16; break; |
|
2289 |
case 8: nColor = 256; break; |
|
2290 |
case 16: nColor = 65536; break; |
|
2291 |
case 24: nColor = 16777216; break; |
|
2292 |
} |
|
2293 |
::DeleteDC(hIC); |
|
2294 |
return nColor; |
|
2295 |
||
2296 |
CATCH_BAD_ALLOC_RET(0); |
|
2297 |
} |
|
2298 |
||
2299 |
/* |
|
2300 |
* Class: sun_awt_windows_WToolkit |
|
2301 |
* Method: getScreenWidth |
|
2302 |
* Signature: ()I |
|
2303 |
*/ |
|
2304 |
JNIEXPORT jint JNICALL |
|
2305 |
Java_sun_awt_windows_WToolkit_getScreenWidth(JNIEnv *env, jobject self) |
|
2306 |
{ |
|
2307 |
TRY; |
|
2308 |
||
2309 |
return ::GetSystemMetrics(SM_CXSCREEN); |
|
2310 |
||
2311 |
CATCH_BAD_ALLOC_RET(0); |
|
2312 |
} |
|
2313 |
||
2314 |
/* |
|
2315 |
* Class: sun_awt_windows_WToolkit |
|
2316 |
* Method: getScreenHeight |
|
2317 |
* Signature: ()I |
|
2318 |
*/ |
|
2319 |
JNIEXPORT jint JNICALL |
|
2320 |
Java_sun_awt_windows_WToolkit_getScreenHeight(JNIEnv *env, jobject self) |
|
2321 |
{ |
|
2322 |
TRY; |
|
2323 |
||
2324 |
return ::GetSystemMetrics(SM_CYSCREEN); |
|
2325 |
||
2326 |
CATCH_BAD_ALLOC_RET(0); |
|
2327 |
} |
|
2328 |
||
2329 |
/* |
|
2330 |
* Class: sun_awt_windows_WToolkit |
|
2331 |
* Method: getSreenInsets |
|
2332 |
* Signature: (I)Ljava/awt/Insets; |
|
2333 |
*/ |
|
2334 |
JNIEXPORT jobject JNICALL |
|
2335 |
Java_sun_awt_windows_WToolkit_getScreenInsets(JNIEnv *env, |
|
2336 |
jobject self, |
|
2337 |
jint screen) |
|
2338 |
{ |
|
2339 |
jobject insets = NULL; |
|
2472
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
2340 |
RECT rect; |
2 | 2341 |
|
2342 |
TRY; |
|
2343 |
||
2472
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
2344 |
if (AwtToolkit::GetScreenInsets(screen, &rect)) { |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
2345 |
insets = env->NewObject(env->FindClass("java/awt/Insets"), |
2 | 2346 |
AwtToolkit::insetsMID, |
2472
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
2347 |
rect.top, |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
2348 |
rect.left, |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
2349 |
rect.bottom, |
b7aba00cabb6
6693253: Security Warning appearance requires enhancements
anthony
parents:
1962
diff
changeset
|
2350 |
rect.right); |
2 | 2351 |
} |
2352 |
||
2353 |
if (safe_ExceptionOccurred(env)) { |
|
2354 |
return 0; |
|
2355 |
} |
|
2356 |
return insets; |
|
2357 |
||
2358 |
CATCH_BAD_ALLOC_RET(NULL); |
|
2359 |
} |
|
2360 |
||
2361 |
||
2362 |
/* |
|
2363 |
* Class: sun_awt_windows_WToolkit |
|
2364 |
* Method: nativeSync |
|
2365 |
* Signature: ()V |
|
2366 |
*/ |
|
2367 |
JNIEXPORT void JNICALL |
|
2368 |
Java_sun_awt_windows_WToolkit_nativeSync(JNIEnv *env, jobject self) |
|
2369 |
{ |
|
2370 |
TRY; |
|
2371 |
||
2372 |
// Synchronize both GDI and DDraw |
|
2373 |
VERIFY(::GdiFlush()); |
|
2374 |
||
2375 |
CATCH_BAD_ALLOC; |
|
2376 |
} |
|
2377 |
||
2378 |
/* |
|
2379 |
* Class: sun_awt_windows_WToolkit |
|
2380 |
* Method: beep |
|
2381 |
* Signature: ()V |
|
2382 |
*/ |
|
2383 |
JNIEXPORT void JNICALL |
|
2384 |
Java_sun_awt_windows_WToolkit_beep(JNIEnv *env, jobject self) |
|
2385 |
{ |
|
2386 |
TRY; |
|
2387 |
||
2388 |
VERIFY(::MessageBeep(MB_OK)); |
|
2389 |
||
2390 |
CATCH_BAD_ALLOC; |
|
2391 |
} |
|
2392 |
||
2393 |
/* |
|
2394 |
* Class: sun_awt_windows_WToolkit |
|
2395 |
* Method: getLockingKeyStateNative |
|
2396 |
* Signature: (I)Z |
|
2397 |
*/ |
|
2398 |
JNIEXPORT jboolean JNICALL |
|
2399 |
Java_sun_awt_windows_WToolkit_getLockingKeyStateNative(JNIEnv *env, jobject self, jint javaKey) |
|
2400 |
{ |
|
2401 |
TRY; |
|
2402 |
||
2403 |
UINT windowsKey, modifiers; |
|
2404 |
AwtComponent::JavaKeyToWindowsKey(javaKey, &windowsKey, &modifiers); |
|
2405 |
||
2406 |
if (windowsKey == 0) { |
|
2407 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", "Keyboard doesn't have requested key"); |
|
2408 |
return JNI_FALSE; |
|
2409 |
} |
|
2410 |
||
2411 |
// low order bit in keyboardState indicates whether the key is toggled |
|
2412 |
BYTE keyboardState[AwtToolkit::KB_STATE_SIZE]; |
|
2413 |
AwtToolkit::GetKeyboardState(keyboardState); |
|
2414 |
return keyboardState[windowsKey] & 0x01; |
|
2415 |
||
2416 |
CATCH_BAD_ALLOC_RET(JNI_FALSE); |
|
2417 |
} |
|
2418 |
||
2419 |
/* |
|
2420 |
* Class: sun_awt_windows_WToolkit |
|
2421 |
* Method: setLockingKeyStateNative |
|
2422 |
* Signature: (IZ)V |
|
2423 |
*/ |
|
2424 |
JNIEXPORT void JNICALL |
|
2425 |
Java_sun_awt_windows_WToolkit_setLockingKeyStateNative(JNIEnv *env, jobject self, jint javaKey, jboolean state) |
|
2426 |
{ |
|
2427 |
TRY; |
|
2428 |
||
2429 |
UINT windowsKey, modifiers; |
|
2430 |
AwtComponent::JavaKeyToWindowsKey(javaKey, &windowsKey, &modifiers); |
|
2431 |
||
2432 |
if (windowsKey == 0) { |
|
2433 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", "Keyboard doesn't have requested key"); |
|
2434 |
return; |
|
2435 |
} |
|
2436 |
||
2437 |
// if the key isn't in the desired state yet, simulate key events to get there |
|
2438 |
// low order bit in keyboardState indicates whether the key is toggled |
|
2439 |
BYTE keyboardState[AwtToolkit::KB_STATE_SIZE]; |
|
2440 |
AwtToolkit::GetKeyboardState(keyboardState); |
|
2441 |
if ((keyboardState[windowsKey] & 0x01) != state) { |
|
2442 |
::keybd_event(windowsKey, 0, 0, 0); |
|
2443 |
::keybd_event(windowsKey, 0, KEYEVENTF_KEYUP, 0); |
|
2444 |
} |
|
2445 |
||
2446 |
CATCH_BAD_ALLOC; |
|
2447 |
} |
|
2448 |
||
2449 |
/* |
|
2450 |
* Class: sun_awt_windows_WToolkit |
|
2451 |
* Method: loadSystemColors |
|
2452 |
* Signature: ([I)V |
|
2453 |
*/ |
|
2454 |
JNIEXPORT void JNICALL |
|
2455 |
Java_sun_awt_windows_WToolkit_loadSystemColors(JNIEnv *env, jobject self, |
|
2456 |
jintArray colors) |
|
2457 |
{ |
|
2458 |
TRY; |
|
2459 |
||
2460 |
static int indexMap[] = { |
|
2461 |
COLOR_DESKTOP, /* DESKTOP */ |
|
2462 |
COLOR_ACTIVECAPTION, /* ACTIVE_CAPTION */ |
|
2463 |
COLOR_CAPTIONTEXT, /* ACTIVE_CAPTION_TEXT */ |
|
2464 |
COLOR_ACTIVEBORDER, /* ACTIVE_CAPTION_BORDER */ |
|
2465 |
COLOR_INACTIVECAPTION, /* INACTIVE_CAPTION */ |
|
2466 |
COLOR_INACTIVECAPTIONTEXT, /* INACTIVE_CAPTION_TEXT */ |
|
2467 |
COLOR_INACTIVEBORDER, /* INACTIVE_CAPTION_BORDER */ |
|
2468 |
COLOR_WINDOW, /* WINDOW */ |
|
2469 |
COLOR_WINDOWFRAME, /* WINDOW_BORDER */ |
|
2470 |
COLOR_WINDOWTEXT, /* WINDOW_TEXT */ |
|
2471 |
COLOR_MENU, /* MENU */ |
|
2472 |
COLOR_MENUTEXT, /* MENU_TEXT */ |
|
2473 |
COLOR_WINDOW, /* TEXT */ |
|
2474 |
COLOR_WINDOWTEXT, /* TEXT_TEXT */ |
|
2475 |
COLOR_HIGHLIGHT, /* TEXT_HIGHLIGHT */ |
|
2476 |
COLOR_HIGHLIGHTTEXT, /* TEXT_HIGHLIGHT_TEXT */ |
|
2477 |
COLOR_GRAYTEXT, /* TEXT_INACTIVE_TEXT */ |
|
2478 |
COLOR_3DFACE, /* CONTROL */ |
|
2479 |
COLOR_BTNTEXT, /* CONTROL_TEXT */ |
|
2480 |
COLOR_3DLIGHT, /* CONTROL_HIGHLIGHT */ |
|
2481 |
COLOR_3DHILIGHT, /* CONTROL_LT_HIGHLIGHT */ |
|
2482 |
COLOR_3DSHADOW, /* CONTROL_SHADOW */ |
|
2483 |
COLOR_3DDKSHADOW, /* CONTROL_DK_SHADOW */ |
|
2484 |
COLOR_SCROLLBAR, /* SCROLLBAR */ |
|
2485 |
COLOR_INFOBK, /* INFO */ |
|
2486 |
COLOR_INFOTEXT, /* INFO_TEXT */ |
|
2487 |
}; |
|
2488 |
||
2489 |
jint colorLen = env->GetArrayLength(colors); |
|
2490 |
jint* colorsPtr = NULL; |
|
2491 |
try { |
|
2492 |
colorsPtr = (jint *)env->GetPrimitiveArrayCritical(colors, 0); |
|
2493 |
for (int i = 0; i < sizeof indexMap && i < colorLen; i++) { |
|
2494 |
colorsPtr[i] = DesktopColor2RGB(indexMap[i]); |
|
2495 |
} |
|
2496 |
} catch (...) { |
|
2497 |
if (colorsPtr != NULL) { |
|
2498 |
env->ReleasePrimitiveArrayCritical(colors, colorsPtr, 0); |
|
2499 |
} |
|
2500 |
throw; |
|
2501 |
} |
|
2502 |
||
2503 |
env->ReleasePrimitiveArrayCritical(colors, colorsPtr, 0); |
|
2504 |
||
2505 |
CATCH_BAD_ALLOC; |
|
2506 |
} |
|
2507 |
||
2508 |
extern "C" JNIEXPORT jobject JNICALL DSGetComponent |
|
2509 |
(JNIEnv* env, void* platformInfo) |
|
2510 |
{ |
|
2511 |
TRY; |
|
2512 |
||
2513 |
HWND hWnd = (HWND)platformInfo; |
|
2514 |
if (!::IsWindow(hWnd)) |
|
2515 |
return NULL; |
|
2516 |
||
2517 |
AwtComponent* comp = AwtComponent::GetComponent(hWnd); |
|
2518 |
if (comp == NULL) |
|
2519 |
return NULL; |
|
2520 |
||
2521 |
return comp->GetTarget(env); |
|
2522 |
||
2523 |
CATCH_BAD_ALLOC_RET(NULL); |
|
2524 |
} |
|
2525 |
||
2526 |
JNIEXPORT void JNICALL |
|
2527 |
Java_sun_awt_windows_WToolkit_postDispose(JNIEnv *env, jclass clazz) |
|
2528 |
{ |
|
2529 |
#ifdef DEBUG |
|
2530 |
TRY_NO_VERIFY; |
|
2531 |
||
2532 |
// If this method was called, that means runFinalizersOnExit is turned |
|
2533 |
// on and the VM is exiting cleanly. We should signal the debug memory |
|
2534 |
// manager to generate a leaks report. |
|
2535 |
AwtDebugSupport::GenerateLeaksReport(); |
|
2536 |
||
2537 |
CATCH_BAD_ALLOC; |
|
2538 |
#endif |
|
2539 |
} |
|
2540 |
||
2541 |
/* |
|
2542 |
* Class: sun_awt_windows_WToolkit |
|
2543 |
* Method: setDynamicLayoutNative |
|
2544 |
* Signature: (Z)V |
|
2545 |
*/ |
|
2546 |
JNIEXPORT void JNICALL |
|
2547 |
Java_sun_awt_windows_WToolkit_setDynamicLayoutNative(JNIEnv *env, |
|
2548 |
jobject self, jboolean dynamic) |
|
2549 |
{ |
|
2550 |
TRY; |
|
2551 |
||
2552 |
AwtToolkit::GetInstance().SetDynamicLayout(dynamic); |
|
2553 |
||
2554 |
CATCH_BAD_ALLOC; |
|
2555 |
} |
|
2556 |
||
2557 |
/* |
|
2558 |
* Class: sun_awt_windows_WToolkit |
|
2559 |
* Method: isDynamicLayoutSupportedNative |
|
2560 |
* Signature: ()Z |
|
2561 |
*/ |
|
2562 |
JNIEXPORT jboolean JNICALL |
|
2563 |
Java_sun_awt_windows_WToolkit_isDynamicLayoutSupportedNative(JNIEnv *env, |
|
2564 |
jobject self) |
|
2565 |
{ |
|
2566 |
TRY; |
|
2567 |
||
2568 |
return (jboolean) AwtToolkit::GetInstance().IsDynamicLayoutSupported(); |
|
2569 |
||
2570 |
CATCH_BAD_ALLOC_RET(FALSE); |
|
2571 |
} |
|
2572 |
||
2573 |
/* |
|
2574 |
* Class: sun_awt_windows_WToolkit |
|
2575 |
* Method: printWindowsVersion |
|
2576 |
* Signature: ()Ljava/lang/String; |
|
2577 |
*/ |
|
2578 |
JNIEXPORT jstring JNICALL |
|
2579 |
Java_sun_awt_windows_WToolkit_getWindowsVersion(JNIEnv *env, jclass cls) |
|
2580 |
{ |
|
2581 |
TRY; |
|
2582 |
||
2583 |
WCHAR szVer[128]; |
|
2584 |
||
2585 |
DWORD version = ::GetVersion(); |
|
2586 |
swprintf(szVer, L"0x%x = %ld", version, version); |
|
2587 |
int l = lstrlen(szVer); |
|
2588 |
||
1954 | 2589 |
if (IS_WIN2000) { |
2590 |
if (IS_WINXP) { |
|
2591 |
if (IS_WINVISTA) { |
|
2592 |
swprintf(szVer + l, L" (Windows Vista)"); |
|
2 | 2593 |
} else { |
1954 | 2594 |
swprintf(szVer + l, L" (Windows XP)"); |
2 | 2595 |
} |
2596 |
} else { |
|
1954 | 2597 |
swprintf(szVer + l, L" (Windows 2000)"); |
2 | 2598 |
} |
2599 |
} else { |
|
2600 |
swprintf(szVer + l, L" (Unknown)"); |
|
2601 |
} |
|
2602 |
||
2603 |
return JNU_NewStringPlatform(env, szVer); |
|
2604 |
||
2605 |
CATCH_BAD_ALLOC_RET(NULL); |
|
2606 |
} |
|
2607 |
||
2608 |
JNIEXPORT jboolean JNICALL |
|
2609 |
Java_sun_awt_windows_WToolkit_syncNativeQueue(JNIEnv *env, jobject self, jlong timeout) |
|
2610 |
{ |
|
2611 |
AwtToolkit & tk = AwtToolkit::GetInstance(); |
|
2612 |
DWORD eventNumber = tk.eventNumber; |
|
2613 |
tk.PostMessage(WM_SYNC_WAIT, 0, 0); |
|
2614 |
::WaitForSingleObject(tk.m_waitEvent, INFINITE); |
|
2615 |
DWORD newEventNumber = tk.eventNumber; |
|
2616 |
return (newEventNumber - eventNumber) > 2; |
|
2617 |
} |
|
2618 |
||
2619 |
} /* extern "C" */ |
|
2620 |
||
2621 |
/* Convert a Windows desktop color index into an RGB value. */ |
|
2622 |
COLORREF DesktopColor2RGB(int colorIndex) { |
|
2623 |
DWORD sysColor = ::GetSysColor(colorIndex); |
|
2624 |
return ((GetRValue(sysColor)<<16) | (GetGValue(sysColor)<<8) | |
|
2625 |
(GetBValue(sysColor)) | 0xff000000); |
|
2626 |
} |
|
2627 |
||
2628 |
||
2629 |
/* |
|
2630 |
* Class: sun_awt_SunToolkit |
|
2631 |
* Method: closeSplashScreen |
|
2632 |
* Signature: ()V |
|
2633 |
*/ |
|
2634 |
extern "C" JNIEXPORT void JNICALL |
|
2635 |
Java_sun_awt_SunToolkit_closeSplashScreen(JNIEnv *env, jclass cls) |
|
2636 |
{ |
|
2637 |
typedef void (*SplashClose_t)(); |
|
2638 |
HMODULE hSplashDll = GetModuleHandle(_T("splashscreen.dll")); |
|
2639 |
if (!hSplashDll) { |
|
2640 |
return; // dll not loaded |
|
2641 |
} |
|
2642 |
SplashClose_t splashClose = (SplashClose_t)GetProcAddress(hSplashDll, |
|
2643 |
"SplashClose"); |
|
2644 |
if (splashClose) { |
|
2645 |
splashClose(); |
|
2646 |
} |
|
2647 |
} |
|
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2648 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2649 |
/* |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2650 |
* accessible from awt_Component |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2651 |
*/ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2652 |
BOOL AwtToolkit::areExtraMouseButtonsEnabled() { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2653 |
return m_areExtraMouseButtonsEnabled; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2654 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2655 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2656 |
/* |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2657 |
* Class: sun_awt_windows_WToolkit |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2658 |
* Method: setExtraMouseButtonsEnabledNative |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2659 |
* Signature: (Z)V |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2660 |
*/ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2661 |
extern "C" JNIEXPORT void JNICALL Java_sun_awt_windows_WToolkit_setExtraMouseButtonsEnabledNative |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2662 |
(JNIEnv *env, jclass self, jboolean enable){ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2663 |
TRY; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2664 |
AwtToolkit::GetInstance().setExtraMouseButtonsEnabled(enable); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2665 |
CATCH_BAD_ALLOC; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2666 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2667 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2668 |
void AwtToolkit::setExtraMouseButtonsEnabled(BOOL enable) { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2669 |
m_areExtraMouseButtonsEnabled = enable; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
1954
diff
changeset
|
2670 |
} |
2810
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2472
diff
changeset
|
2671 |
|
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2472
diff
changeset
|
2672 |
JNIEXPORT jint JNICALL Java_sun_awt_windows_WToolkit_getNumberOfButtonsImpl |
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2472
diff
changeset
|
2673 |
(JNIEnv *, jobject self) { |
6642
9d6f6dbb16a4
6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents:
5506
diff
changeset
|
2674 |
return AwtToolkit::GetNumberOfButtons(); |
2810
fa49c6a06baf
6799099: All automatic regression tests that create Robot fail on X11
dav
parents:
2472
diff
changeset
|
2675 |
} |
6642
9d6f6dbb16a4
6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents:
5506
diff
changeset
|
2676 |
|
9d6f6dbb16a4
6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents:
5506
diff
changeset
|
2677 |
UINT AwtToolkit::GetNumberOfButtons() { |
9d6f6dbb16a4
6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents:
5506
diff
changeset
|
2678 |
return MOUSE_BUTTONS_WINDOWS_SUPPORTED; |
9d6f6dbb16a4
6829267: Regression test java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java fails in RHEL5
dav
parents:
5506
diff
changeset
|
2679 |
} |