summaryrefslogtreecommitdiffstats
path: root/src/nativewindow/native
diff options
context:
space:
mode:
authorRandolf Schultz <[email protected]>2013-11-28 14:55:03 +0100
committerSven Gothel <[email protected]>2013-11-28 14:55:03 +0100
commite9c711a86aa05f4f24c69972532833f5a98911a3 (patch)
tree691d01a02de553dd2c8f6d87ed90b1c56d4dc2a6 /src/nativewindow/native
parenteb9225c928b9a1a5660c865921fcd91f85cd1cd0 (diff)
Bug 907 - Initial patch allowing Jogl to respond to other applications that try to retrieve window names
Diffstat (limited to 'src/nativewindow/native')
-rw-r--r--src/nativewindow/native/win32/GDImisc.c189
1 files changed, 186 insertions, 3 deletions
diff --git a/src/nativewindow/native/win32/GDImisc.c b/src/nativewindow/native/win32/GDImisc.c
index 23be47380..40f42f285 100644
--- a/src/nativewindow/native/win32/GDImisc.c
+++ b/src/nativewindow/native/win32/GDImisc.c
@@ -31,6 +31,93 @@ static const char * const ClazzNamePointCstrSignature = "(II)V";
static jclass pointClz = NULL;
static jmethodID pointCstr = NULL;
+static DWORD threadid = 0;
+
+typedef struct ThreadParam_s
+{
+ jlong jHInstance;
+ const TCHAR* wndClassName;
+ const TCHAR* wndName;
+ jint x;
+ jint y;
+ jint width;
+ jint height;
+ volatile HWND *hWndPtr;
+ volatile BOOL *threadReady;
+} ThreadParam;
+
+#define TM_OPENWIN WM_APP+1
+#define TM_CLOSEWIN WM_APP+2
+#define TM_STOP WM_APP+3
+
+DWORD WINAPI ThreadFunc(LPVOID param)
+{
+ MSG msg;
+ BOOL bRet;
+ ThreadParam *startupThreadParam = (ThreadParam*)param;
+
+ /* there can not be any messages for us now, as the creator waits for
+ threadReady before continuing, but we must use this PeekMessage() to
+ create the thread message queue */
+ PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
+
+ /* now we can safely say: we have a qeue and are ready to receive messages */
+ *(startupThreadParam->threadReady) = TRUE;
+
+ while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
+ {
+ if (bRet == -1)
+ {
+ return 0;
+ }
+ else
+ {
+ switch(msg.message)
+ {
+ case TM_OPENWIN:
+ {
+ ThreadParam *tParam = (ThreadParam*)msg.wParam;
+ HINSTANCE hInstance = (HINSTANCE) (intptr_t) tParam->jHInstance;
+ DWORD dwExStyle;
+ DWORD dwStyle;
+
+ dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
+ dwStyle = WS_OVERLAPPEDWINDOW;
+
+ HWND hwnd = CreateWindowEx( dwExStyle,
+ tParam->wndClassName,
+ tParam->wndName,
+ dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
+ tParam->x, tParam->y, tParam->width, tParam->height,
+ NULL, NULL, hInstance, NULL );
+
+ *(tParam->hWndPtr) = hwnd;
+ *(tParam->threadReady) = TRUE;
+ }
+ break;
+ case TM_CLOSEWIN:
+ {
+ ThreadParam *tParam = (ThreadParam*)msg.wParam;
+ HWND hwnd = *(tParam->hWndPtr);
+ DestroyWindow(hwnd);
+ *(tParam->threadReady) = TRUE;
+ }
+ break;
+ case TM_STOP:
+ return 0;
+ break;
+ default:
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ break;
+ }
+ }
+ }
+
+ return 0;
+} /* ThreadFunc */
+
+
HINSTANCE GetApplicationHandle() {
return GetModuleHandle(NULL);
}
@@ -59,7 +146,7 @@ Java_jogamp_nativewindow_windows_GDIUtil_CreateWindowClass
if( GetClassInfo( hInstance, clazzName, &wc ) ) {
// registered already
res = JNI_TRUE;
- } else {
+ } else {
// register now
ZeroMemory( &wc, sizeof( wc ) );
wc.style = CS_HREDRAW | CS_VREDRAW ;
@@ -81,6 +168,27 @@ Java_jogamp_nativewindow_windows_GDIUtil_CreateWindowClass
(*env)->ReleaseStringUTFChars(env, jClazzName, clazzName);
#endif
+ if(res == JNI_TRUE)
+ {
+ volatile BOOL threadReady = FALSE;
+ ThreadParam tParam = {0};
+ tParam.threadReady = &threadReady;
+
+ CreateThread(NULL, 0, ThreadFunc, (LPVOID)&tParam, 0, &(threadid));
+ if(threadid)
+ {
+ while(1)
+ {
+ if(threadReady)
+ break;
+ }
+ }
+ else
+ {
+ res = JNI_FALSE;
+ }
+ }
+
return res;
}
@@ -111,9 +219,58 @@ Java_jogamp_nativewindow_windows_GDIUtil_DestroyWindowClass
(*env)->ReleaseStringUTFChars(env, jClazzName, clazzName);
#endif
+ PostThreadMessage(threadid, TM_STOP, 0, 0);
+
return res;
}
+/* Java->C glue code:
+ * Java package: jogamp.nativewindow.windows.GDIUtil
+ * Java method: long CreateDummyWindowAndMessageLoop(long hInstance, java.lang.String className, java.lang.String windowName, int x, int y, int width, int height)
+ * C function: HANDLE CreateDummyWindowAndMessageLoop(HANDLE hInstance, LPCSTR className, LPCSTR windowName, int x, int y, int width, int height);
+ */
+JNIEXPORT jlong JNICALL
+Java_jogamp_nativewindow_windows_GDIUtil_CreateDummyWindowAndMessageLoop
+ (JNIEnv *env, jclass _unused, jlong jHInstance, jstring jWndClassName, jstring jWndName, jint x, jint y, jint width, jint height)
+{
+ volatile HWND hWnd = 0;
+ volatile BOOL threadReady = FALSE;
+ ThreadParam tParam = {0};
+
+ tParam.jHInstance = jHInstance;
+ tParam.x = x;
+ tParam.y = y;
+ tParam.width = width;
+ tParam.height = height;
+ tParam.hWndPtr = &hWnd;
+ tParam.threadReady = &threadReady;
+
+#ifdef UNICODE
+ tParam.wndClassName = NewtCommon_GetNullTerminatedStringChars(env, jWndClassName);
+ tParam.wndName = NewtCommon_GetNullTerminatedStringChars(env, jWndName);
+#else
+ tParam.wndClassName = (*env)->GetStringUTFChars(env, jWndClassName, NULL);
+ tParam.wndName = (*env)->GetStringUTFChars(env, jWndName, NULL);
+#endif
+
+ PostThreadMessage(threadid, TM_OPENWIN, (WPARAM)&tParam, 0);
+
+ while(1)
+ {
+ if(threadReady)
+ break;
+ }
+
+#ifdef UNICODE
+ free((void*) tParam.wndClassName);
+ free((void*) tParam.wndName);
+#else
+ (*env)->ReleaseStringUTFChars(env, jWndClassName, tParam.wndClassName);
+ (*env)->ReleaseStringUTFChars(env, jWndName, tParam.wndName);
+#endif
+
+ return (jlong) (intptr_t) hWnd;
+}
/* Java->C glue code:
* Java package: jogamp.nativewindow.windows.GDIUtil
@@ -188,7 +345,8 @@ JNIEXPORT jboolean JNICALL Java_jogamp_nativewindow_windows_GDIUtil_initIDs0
return JNI_TRUE;
}
-LRESULT CALLBACK DummyWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
+LRESULT CALLBACK DummyWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
@@ -200,7 +358,7 @@ LRESULT CALLBACK DummyWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
JNIEXPORT jlong JNICALL Java_jogamp_nativewindow_windows_GDIUtil_getDummyWndProc0
(JNIEnv *env, jclass clazz)
{
- return (jlong) (intptr_t) DummyWndProc;
+ return (jlong) (intptr_t) DummyWndProc;
}
/*
@@ -250,3 +408,28 @@ JNIEXPORT jboolean JNICALL Java_jogamp_nativewindow_windows_GDIUtil_IsUndecorate
return bIsUndecorated ? JNI_TRUE : JNI_FALSE;
}
+/*
+ * Class: jogamp_nativewindow_windows_GDIUtil
+ * Method: SendCloseMessage
+ */
+JNIEXPORT jboolean JNICALL Java_jogamp_nativewindow_windows_GDIUtil_SendCloseMessage
+(JNIEnv *env, jclass unused, jlong jwin)
+{
+ ThreadParam tParam = {0};
+ volatile HWND hwnd = (HWND) (intptr_t) jwin;
+ volatile BOOL threadReady = FALSE;
+
+ tParam.hWndPtr = &(hwnd);
+ tParam.threadReady = &(threadReady);
+
+ PostThreadMessage(threadid, TM_CLOSEWIN, (WPARAM)&tParam, 0);
+
+ while(1)
+ {
+ if(threadReady)
+ break;
+ }
+
+ return JNI_TRUE;
+}
+