diff options
author | Sven Gothel <[email protected]> | 2010-12-12 07:51:06 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-12-12 07:51:06 +0100 |
commit | 48f6568ebffdd557651460fb5f3f7f4abbca2440 (patch) | |
tree | 2cbd9cc815ab54fcd61fccae17e7d75ca6cc6d51 /src/newt/native/WindowsWindow.c | |
parent | f3512c700b2b3161eb773e77d0d41567acb710be (diff) |
Windows RegisterClass: Use new RegisteredClassFactory (window class), Misc.
This solves the issue when an applet is started/stop and started again,
or another applet runs in the same JVM.
Also soves the issue for multiple JVMs.
RegisteredClassFactory can be instanced to manage one shared window class,
currently in use for GDI's dummy window and NEWT.
A class base name and a window proc handle must be passed in the factory cstr.
Before registering, the class is tested if already exists,
eg another applet in the same JVM.
If registration fails, the class name will iterate until successful or MAX_INT reached,
eg if multiple JVMs are running.
Added NativeWindow Common Native Code.
Diffstat (limited to 'src/newt/native/WindowsWindow.c')
-rw-r--r-- | src/newt/native/WindowsWindow.c | 105 |
1 files changed, 22 insertions, 83 deletions
diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c index 0a675157d..cafdaeef8 100644 --- a/src/newt/native/WindowsWindow.c +++ b/src/newt/native/WindowsWindow.c @@ -1047,71 +1047,6 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsDisplay_Dispatch } /* - * Class: com_jogamp_newt_impl_windows_WindowsDisplay - * Method: LoadLibraryW - * Signature: (Ljava/lang/String;)J - */ -JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_windows_WindowsDisplay_LoadLibraryW0 - (JNIEnv *env, jclass clazz, jstring dllName) -{ - jchar* _dllName = NewtCommon_GetNullTerminatedStringChars(env, dllName); - HMODULE lib = LoadLibraryW(_dllName); - free(_dllName); - return (jlong) (intptr_t) lib; -} - -/* - * Class: com_jogamp_newt_impl_windows_WindowsDisplay - * Method: RegisterWindowClass - * Signature: (Ljava/lang/String;J)I - */ -JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_windows_WindowsDisplay_RegisterWindowClass0 - (JNIEnv *env, jclass clazz, jstring wndClassName, jlong hInstance) -{ - ATOM res; - WNDCLASS wc; -#ifndef UNICODE - const char* _wndClassName = NULL; -#endif - - /* register class */ - wc.style = CS_HREDRAW | CS_VREDRAW; - wc.lpfnWndProc = (WNDPROC)wndProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - /* This cast is legal because the HMODULE for a DLL is the same as - its HINSTANCE -- see MSDN docs for DllMain */ - wc.hInstance = (HINSTANCE) (intptr_t) hInstance; - wc.hIcon = NULL; - wc.hCursor = LoadCursor( NULL, IDC_ARROW); - wc.hbrBackground = GetStockObject(BLACK_BRUSH); - wc.lpszMenuName = NULL; -#ifdef UNICODE - wc.lpszClassName = NewtCommon_GetNullTerminatedStringChars(env, wndClassName); -#else - _wndClassName = (*env)->GetStringUTFChars(env, wndClassName, NULL); - wc.lpszClassName = strdup(_wndClassName); - (*env)->ReleaseStringUTFChars(env, wndClassName, _wndClassName); -#endif - res = RegisterClass(&wc); - - free((void *)wc.lpszClassName); - - return (jint)res; -} - -/* - * Class: com_jogamp_newt_impl_windows_WindowsDisplay - * Method: CleanupWindowResources - * Signature: (java/lang/String;J)V - */ -JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsDisplay_UnregisterWindowClass0 - (JNIEnv *env, jclass clazz, jint wndClassAtom, jlong hInstance) -{ - UnregisterClass(MAKEINTATOM(wndClassAtom), (HINSTANCE) (intptr_t) hInstance); -} - -/* * Class: com_jogamp_newt_impl_windows_WindowsScreen * Method: getWidthImpl * Signature: (I)I @@ -1363,15 +1298,27 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_initI /* * Class: com_jogamp_newt_impl_windows_WindowsWindow + * Method: getNewtWndProc0 + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_getNewtWndProc0 + (JNIEnv *env, jclass clazz) +{ + return (jlong) (intptr_t) wndProc; +} + +/* + * Class: com_jogamp_newt_impl_windows_WindowsWindow * Method: CreateWindow - * Signature: (JILjava/lang/String;JJZIIII)J */ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_CreateWindow0 - (JNIEnv *env, jobject obj, jlong parent, jint wndClassAtom, jstring jWndName, jlong hInstance, jlong visualID, - jboolean bIsUndecorated, - jint jx, jint jy, jint defaultWidth, jint defaultHeight) + (JNIEnv *env, jobject obj, + jlong hInstance, jstring jWndClassName, jstring jWndName, + jlong parent, jlong visualID, jboolean bIsUndecorated, + jint jx, jint jy, jint defaultWidth, jint defaultHeight) { HWND parentWindow = (HWND) (intptr_t) parent; + const TCHAR* wndClassName = NULL; const TCHAR* wndName = NULL; DWORD windowStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE | WS_TABSTOP; int x=(int)jx, y=(int)jy; @@ -1379,8 +1326,10 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_CreateWi HWND window = NULL; #ifdef UNICODE + wndClassName = NewtCommon_GetNullTerminatedStringChars(env, jWndClassName); wndName = NewtCommon_GetNullTerminatedStringChars(env, jWndName); #else + wndClassName = (*env)->GetStringUTFChars(env, jWndClassName, NULL); wndName = (*env)->GetStringUTFChars(env, jWndName, NULL); #endif @@ -1400,13 +1349,13 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_CreateWi (void) visualID; // FIXME: use the visualID .. - window = CreateWindow(MAKEINTATOM(wndClassAtom), wndName, windowStyle, + window = CreateWindow(wndClassName, wndName, windowStyle, x, y, width, height, parentWindow, NULL, (HINSTANCE) (intptr_t) hInstance, NULL); - DBG_PRINT("*** WindowsWindow: CreateWindow thread 0xX, parent %p, window %p, %d/%d %dx%d\n", + DBG_PRINT("*** WindowsWindow: CreateWindow thread 0x%X, parent %p, window %p, %d/%d %dx%d\n", (int)GetCurrentThreadId(), parentWindow, window, x, y, width, height); if (NULL == window) { @@ -1427,8 +1376,10 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_CreateWi } #ifdef UNICODE + free((void*) wndClassName); free((void*) wndName); #else + (*env)->ReleaseStringUTFChars(env, jWndClassName, wndClassName); (*env)->ReleaseStringUTFChars(env, jWndName, wndName); #endif @@ -1437,18 +1388,6 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_CreateWi /* * Class: com_jogamp_newt_impl_windows_WindowsWindow - * Method: DestroyWindow - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_DestroyWindow0 - (JNIEnv *env, jobject obj, jlong window) -{ - DBG_PRINT("*** WindowsWindow: DestroyWindow thread 0x%X, window %p\n", (int)GetCurrentThreadId(), window); - DestroyWindow((HWND) (intptr_t) window); -} - -/* - * Class: com_jogamp_newt_impl_windows_WindowsWindow * Method: MonitorFromWindow * Signature: (J)J */ |