JNIEXPORT void JNICALL SWT_AWT_NATIVE(setDebug) (JNIEnv *env, jclass that, jobject frame, jboolean debug) { JAWT awt; JAWT_DrawingSurface* ds; JAWT_DrawingSurfaceInfo* dsi; JAWT_X11DrawingSurfaceInfo* dsi_x11; jint lock; awt.version = JAWT_VERSION_1_3; if (JAWT_GetAWT(env, &awt) != 0) { ds = awt.GetDrawingSurface(env, frame); if (ds != NULL) { lock = ds->Lock(ds); if ((lock & JAWT_LOCK_ERROR) == 0) { dsi = ds->GetDrawingSurfaceInfo(ds); dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo; XSynchronize(dsi_x11->display, debug); ds->FreeDrawingSurfaceInfo(dsi); ds->Unlock(ds); } } awt.FreeDrawingSurface(ds); } }
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_AWTSurfaceLock_lockAndInitHandle (JNIEnv *env, jclass clazz, jobject lock_buffer_handle, jobject canvas) { JAWT awt; JAWT_DrawingSurface* ds; JAWT_DrawingSurfaceInfo *dsi; AWTSurfaceLock *awt_lock = (AWTSurfaceLock *)(*env)->GetDirectBufferAddress(env, lock_buffer_handle); awt.version = JAWT_VERSION_1_4; if (JAWT_GetAWT(env, &awt) == JNI_FALSE) { throwException(env, "Could not get the JAWT interface"); return JNI_FALSE; } ds = awt.GetDrawingSurface(env, canvas); if (ds == NULL) { throwException(env, "Could not get the drawing surface"); return JNI_FALSE; } if((ds->Lock(ds) & JAWT_LOCK_ERROR) != 0) { awt.FreeDrawingSurface(ds); throwException(env, "Could not lock the drawing surface"); return JNI_FALSE; } dsi = ds->GetDrawingSurfaceInfo(ds); if (dsi != NULL) { awt_lock->awt = awt; awt_lock->ds = ds; awt_lock->dsi = dsi; return JNI_TRUE; } ds->Unlock(ds); awt.FreeDrawingSurface(ds); return JNI_FALSE; }
JNIEXPORT jintLong JNICALL SWT_AWT_NATIVE(getAWTHandle) (JNIEnv *env, jclass that, jobject canvas) { JAWT awt; JAWT_DrawingSurface* ds; JAWT_DrawingSurfaceInfo* dsi; JAWT_Win32DrawingSurfaceInfo* dsi_win; jintLong result = 0; jint lock; awt.version = JAWT_VERSION_1_3; if (JAWT_GetAWT(env, &awt) != 0) { ds = awt.GetDrawingSurface(env, canvas); if (ds != NULL) { lock = ds->Lock(ds); if ((lock & JAWT_LOCK_ERROR) == 0) { dsi = ds->GetDrawingSurfaceInfo(ds); dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo; result = (jintLong)dsi_win->hwnd; ds->FreeDrawingSurfaceInfo(dsi); ds->Unlock(ds); } } awt.FreeDrawingSurface(ds); } return result; }
extern "C" NS_EXPORT jlong JNICALL MOZILLA_NATIVE(getNativeHandleFromAWT) (JNIEnv* env, jobject clazz, jobject widget) { PRUint64 handle = 0; #ifdef XP_MACOSX JAWT awt; awt.version = JAWT_VERSION_1_4; jboolean result = JAWT_GetAWT(env, &awt); if (result == JNI_FALSE) return 0; JAWT_DrawingSurface* ds = awt.GetDrawingSurface(env, widget); if (ds != nullptr) { jint lock = ds->Lock(ds); if (!(lock & JAWT_LOCK_ERROR)) { JAWT_DrawingSurfaceInfo* dsi = ds->GetDrawingSurfaceInfo(ds); if (dsi) { handle = GetPlatformHandle(dsi); ds->FreeDrawingSurfaceInfo(dsi); } ds->Unlock(ds); } awt.FreeDrawingSurface(ds); } #else NS_WARNING("getNativeHandleFromAWT JNI method not implemented"); #endif return handle; }
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_AWTSurfaceLock_lockAndInitHandle (JNIEnv *env, jclass clazz, jobject lock_buffer_handle, jobject canvas) { JAWT awt; JAWT_DrawingSurface* ds; JAWT_DrawingSurfaceInfo *dsi; AWTSurfaceLock *awt_lock = (AWTSurfaceLock *)(*env)->GetDirectBufferAddress(env, lock_buffer_handle); jboolean result = JNI_FALSE; #ifdef __MACH__ // try get JAWT with JAWT_MACOSX_USE_CALAYER Opt In awt.version = JAWT_VERSION_1_4 | 0x80000000;//JAWT_MACOSX_USE_CALAYER; result = JAWT_GetAWT(env, &awt); #endif if (result == JNI_FALSE) { // now try without CALAYER awt.version = JAWT_VERSION_1_4; if (JAWT_GetAWT(env, &awt) == JNI_FALSE) { throwException(env, "Could not get the JAWT interface"); return JNI_FALSE; } } ds = awt.GetDrawingSurface(env, canvas); if (ds == NULL) { throwException(env, "Could not get the drawing surface"); return JNI_FALSE; } if((ds->Lock(ds) & JAWT_LOCK_ERROR) != 0) { awt.FreeDrawingSurface(ds); throwException(env, "Could not lock the drawing surface"); return JNI_FALSE; } dsi = ds->GetDrawingSurfaceInfo(ds); if (dsi != NULL) { awt_lock->awt = awt; awt_lock->ds = ds; awt_lock->dsi = dsi; return JNI_TRUE; } ds->Unlock(ds); awt.FreeDrawingSurface(ds); return JNI_FALSE; }
EXTERN_C_ENTER JNIEXPORT jboolean JNICALL Java_org_lwjgl_system_jawt_JAWTFunctions_nJAWT_1GetAWT(JNIEnv *__env, jclass clazz, jlong __functionAddress, jlong awtAddress) { JAWT_GetAWTPROC JAWT_GetAWT = (JAWT_GetAWTPROC)(intptr_t)__functionAddress; intptr_t awt = (intptr_t)awtAddress; UNUSED_PARAM(clazz) return JAWT_GetAWT(__env, awt); }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nUnlockAWT(JNIEnv *env, jclass clazz) { JAWT jawt; jawt.version = JAWT_VERSION_1_4; if (JAWT_GetAWT(env, &jawt) != JNI_TRUE) { throwException(env, "GetAWT failed"); return; } jawt.Unlock(env); }
/***************************************************************************** * * Class : NativeView * Method : getNativeWindow * Signature : ()J * Description: returns the native systemw window handle of this object */ JNIEXPORT jlong JNICALL Java_NativeView_getNativeWindow (JNIEnv * env, jobject obj_this) { jboolean result ; jint lock ; JAWT awt ; JAWT_DrawingSurface* ds ; JAWT_DrawingSurfaceInfo* dsi ; JAWT_Win32DrawingSurfaceInfo* dsi_win ; HDC hdc ; HWND hWnd ; LONG hFuncPtr; /* Get the AWT */ awt.version = JAWT_VERSION_1_3; result = JAWT_GetAWT(env, &awt); MY_ASSERT(result!=JNI_FALSE,"wrong jawt version"); /* Get the drawing surface */ if ((ds = awt.GetDrawingSurface(env, obj_this)) == NULL) return 0L; /* Lock the drawing surface */ lock = ds->Lock(ds); MY_ASSERT((lock & JAWT_LOCK_ERROR)==0,"can't lock the drawing surface"); /* Get the drawing surface info */ dsi = ds->GetDrawingSurfaceInfo(ds); /* Get the platform-specific drawing info */ dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo; hdc = dsi_win->hdc; hWnd = dsi_win->hwnd; /* Free the drawing surface info */ ds->FreeDrawingSurfaceInfo(dsi); /* Unlock the drawing surface */ ds->Unlock(ds); /* Free the drawing surface */ awt.FreeDrawingSurface(ds); /* Register own window procedure Do it one times only! Otherwhise multiple instances will be registered and calls on such construct produce a stack overflow. */ if (GetProp( hWnd, OLD_PROC_KEY )==0) { hFuncPtr = SetWindowLong( hWnd, GWL_WNDPROC, (DWORD)NativeViewWndProc ); SetProp( hWnd, OLD_PROC_KEY, (HANDLE)hFuncPtr ); } return ((jlong)hWnd); }
JNIEXPORT jint JNICALL Java_vnmr_ui_VNMRFrame_syncXwin (JNIEnv *env, jobject obj, jobject source) { JAWT awt; JAWT_DrawingSurface *ds; JAWT_DrawingSurfaceInfo *dsi; JAWT_X11DrawingSurfaceInfo *dsi_win; Display* dpy; Drawable xwin; GC gc; jint ret; jint lock; ret = 0; awt.version = JAWT_VERSION_1_4; if (JAWT_GetAWT(env, &awt) == JNI_FALSE) { printf(" JAVA AWT not found \n"); return (ret); } ds = awt.GetDrawingSurface(env, source); if (ds == NULL) { printf(" JAVA Window not found \n"); return (ret); } lock = ds->Lock(ds); if ((lock & JAWT_LOCK_ERROR) != 0) { printf(" JAVA Error on locking window \n"); awt.FreeDrawingSurface(ds); return (ret); } dsi = ds->GetDrawingSurfaceInfo(ds); if (dsi != NULL) { dsi_win = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo; if (dsi_win != NULL) { xwin = dsi_win->drawable; dpy = dsi_win->display; XSynchronize(dpy, 1); gc = XCreateGC(dpy, xwin, 0, 0); XSetForeground(dpy, gc, 2); XFreeGC(dpy, gc); XSynchronize(dpy, 0); ret = 1; } ds->FreeDrawingSurfaceInfo(dsi); } ds->Unlock(ds); awt.FreeDrawingSurface(ds); return (ret); }
/***************************************************************************** * * Class : NativeView * Method : getNativeWindow * Signature : ()J * Description: returns the native systemw window handle of this object */ JNIEXPORT jlong JNICALL Java_embeddedobj_test_NativeView_getNativeWindow (JNIEnv * env, jobject obj_this) { jboolean result ; jint lock ; JAWT awt ; JAWT_DrawingSurface* ds ; JAWT_DrawingSurfaceInfo* dsi ; #ifdef WNT JAWT_Win32DrawingSurfaceInfo* dsi_win ; #else // FIXME: Where is dsi_x11 defined? // Added below because I'm guessing this test breaks // JAWT_X11DrawingSurfaceInfo*dsi_x11 ; #endif jlong drawable; /* Get the AWT */ awt.version = JAWT_VERSION_1_3; result = JAWT_GetAWT(env, &awt); MY_ASSERT(result!=JNI_FALSE,"wrong jawt version"); /* Get the drawing surface */ if ((ds = awt.GetDrawingSurface(env, obj_this)) == NULL) return 0L; /* Lock the drawing surface */ lock = ds->Lock(ds); MY_ASSERT((lock & JAWT_LOCK_ERROR)==0,"can't lock the drawing surface"); /* Get the drawing surface info */ dsi = ds->GetDrawingSurfaceInfo(ds); /* Get the platform-specific drawing info */ #ifdef WNT dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo; drawable = (jlong)dsi_win->hwnd; #else dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo; drawable = (jlong)dsi_x11->drawable; #endif /* Free the drawing surface info */ ds->FreeDrawingSurfaceInfo(dsi); /* Unlock the drawing surface */ ds->Unlock(ds); /* Free the drawing surface */ awt.FreeDrawingSurface(ds); return drawable; }
/* * Class: com_sun_star_beans_LocalOfficeWindow * Method: getNativeWindow * Signature: ()J */ SAL_DLLPUBLIC_EXPORT jlong JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindow (JNIEnv * env, jobject obj_this) { jboolean result; jint lock; JAWT awt; JAWT_DrawingSurface* ds; JAWT_DrawingSurfaceInfo* dsi; JAWT_X11DrawingSurfaceInfo* dsi_x11; Drawable drawable; /* Get the AWT */ awt.version = JAWT_VERSION_1_3; result = JAWT_GetAWT(env, &awt); if (result == JNI_FALSE) ThrowException(env, "java/lang/RuntimeException", "JAWT_GetAWT failed"); /* Get the drawing surface */ if ((ds = awt.GetDrawingSurface(env, obj_this)) == NULL) return 0L; /* Lock the drawing surface */ lock = ds->Lock(ds); if ( (lock & JAWT_LOCK_ERROR) != 0) ThrowException(env, "java/lang/RuntimeException", "Could not get AWT drawing surface."); /* Get the drawing surface info */ dsi = ds->GetDrawingSurfaceInfo(ds); /* Get the platform-specific drawing info */ dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo; drawable = dsi_x11->drawable; /* Free the drawing surface info */ ds->FreeDrawingSurfaceInfo(dsi); /* Unlock the drawing surface */ ds->Unlock(ds); /* Free the drawing surface */ awt.FreeDrawingSurface(ds); return ((jlong)drawable); }
JNIEXPORT void JNICALL Java_org_jclutter_awt_JClutterCanvas_paint(JNIEnv *env, jobject canvas, jobject graphics){ JAWT awt; JAWT_DrawingSurface* ds; JAWT_DrawingSurfaceInfo* dsi; JAWT_Win32DrawingSurfaceInfo* dsi_win; jboolean result; jint lock; // Get the AWT awt.version = JAWT_VERSION_1_3; result = JAWT_GetAWT(env, &awt); assert(result != JNI_FALSE); // Get the drawing surface ds = awt.GetDrawingSurface(env, canvas); assert(ds != NULL); // Lock the drawing surface lock = ds->Lock(ds); assert((lock & JAWT_LOCK_ERROR) == 0); // Get the drawing surface info dsi = ds->GetDrawingSurfaceInfo(ds); // Get the platform-specific drawing info dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo; // TODO : What to do next ? HWND hWnd = dsi_win->hwnd; clutter_win32_set_stage_foreign( clutter_stage_get_default(), hWnd); // Free the drawing surface info ds->FreeDrawingSurfaceInfo(dsi); // Unlock the drawing surface ds->Unlock(ds); // Free the drawing surface awt.FreeDrawingSurface(ds); }
JNIEXPORT jint JNICALL Java_vnmr_ui_VNMRFrame_getXwinId (JNIEnv *env, jobject obj, jobject source) { JAWT awt; JAWT_DrawingSurface *ds; JAWT_DrawingSurfaceInfo *dsi; JAWT_X11DrawingSurfaceInfo *dsi_win; Display* dpy; jint lock, wid; wid = 0; awt.version = JAWT_VERSION_1_4; if (JAWT_GetAWT(env, &awt) == JNI_FALSE) { printf(" JAVA AWT not found \n"); return (wid); } ds = awt.GetDrawingSurface(env, source); if (ds == NULL) { printf(" JAVA Window not found \n"); return (wid); } lock = ds->Lock(ds); if ((lock & JAWT_LOCK_ERROR) != 0) { printf(" JAVA Error on locking window \n"); awt.FreeDrawingSurface(ds); return (wid); } dsi = ds->GetDrawingSurfaceInfo(ds); if (dsi != NULL) { dsi_win = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo; if (dsi_win != NULL) { wid = (jint) dsi_win->drawable; } ds->FreeDrawingSurfaceInfo(dsi); } ds->Unlock(ds); awt.FreeDrawingSurface(ds); return (wid); }
/* * Class: NativeView * Method: getNativeWindow * Signature: ()J */ JNIEXPORT jlong JNICALL Java_NativeView_getNativeWindow (JNIEnv * env, jobject obj_this) { jboolean result ; jint lock ; JAWT awt ; JAWT_DrawingSurface* ds ; JAWT_DrawingSurfaceInfo* dsi ; JAWT_X11DrawingSurfaceInfo* dsi_x11 ; Drawable drawable; Display* display ; /* Get the AWT */ awt.version = JAWT_VERSION_1_3; result = JAWT_GetAWT(env, &awt); MY_ASSERT(result != JNI_FALSE,"wrong jawt version"); /* Get the drawing surface */ if ((ds = awt.GetDrawingSurface(env, obj_this)) == NULL) return 0L; /* Lock the drawing surface */ lock = ds->Lock(ds); MY_ASSERT((lock & JAWT_LOCK_ERROR)==0,"can't lock the drawing surface"); /* Get the drawing surface info */ dsi = ds->GetDrawingSurfaceInfo(ds); /* Get the platform-specific drawing info */ dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo; drawable = dsi_x11->drawable; display = dsi_x11->display; /* Free the drawing surface info */ ds->FreeDrawingSurfaceInfo(dsi); /* Unlock the drawing surface */ ds->Unlock(ds); /* Free the drawing surface */ awt.FreeDrawingSurface(ds); return ((jlong)drawable); }
/* * Class: com_thinkparity_ophelia_browser_util_window_win32_Win32WindowUtil * Method: GetWindowHandle * Signature: (Ljava/awt/Window;)J */ JNIEXPORT jint JNICALL Java_com_thinkparity_ophelia_browser_util_window_win32_Win32WindowUtil_GetWindowHandle(JNIEnv* env, jobject refThis, jobject window) { /* NOTE big fat reminder, in c you need to pre-declare vars at the * beginning of the code block */ jboolean result; jint lock; JAWT awt; JAWT_DrawingSurface* drawingSurface; JAWT_DrawingSurfaceInfo* info; JAWT_Win32DrawingSurfaceInfo* win32Info; HWND windowHandle; // grab awt awt.version = JAWT_VERSION_1_3; result = JAWT_GetAWT(env, &awt); assert(result != JNI_FALSE); // grab and lock the drawing surface drawingSurface = awt.GetDrawingSurface(env, window); assert(drawingSurface != NULL); lock = drawingSurface->Lock(drawingSurface); assert((lock & JAWT_LOCK_ERROR) == 0); // grab info info = drawingSurface->GetDrawingSurfaceInfo(drawingSurface); win32Info = (JAWT_Win32DrawingSurfaceInfo*) info->platformInfo; // grab handle windowHandle = win32Info->hwnd; // release info drawingSurface->FreeDrawingSurfaceInfo(info); // unlock drawing surface drawingSurface->Unlock(drawingSurface); // release drawing surface awt.FreeDrawingSurface(drawingSurface); return (int) windowHandle; }
/* * Returns a locked info structure for the supplied canvas. If we are * unable to aquire the information an exception will be thrown and * display and drawable will be NULL. If the information was aquire * then the canvas will locked and can be unlocked by calling * freeCanvasInfo. */ CanvasInfo getCanvasInfo(JNIEnv *env, jobject canvas) { CanvasInfo info; jboolean result; jint lock; memset(&info, sizeof info, 0); info.awt.version = JAWT_VERSION_1_4; result = JAWT_GetAWT(env, &info.awt); if (result == JNI_FALSE) { handleError(env, OPENGL_CANVAS_EXCEPTION, "Unable to get JAWT_GetAWT.\n"); return info; } info.ds = info.awt.GetDrawingSurface(env, canvas); if (info.ds == NULL) { handleError(env, OPENGL_CANVAS_EXCEPTION, "Unable to get JAWT drawing surface."); return info; } lock = info.ds->Lock(info.ds); if (lock & JAWT_LOCK_ERROR) { handleError(env, OPENGL_CANVAS_EXCEPTION, "Unable to lock JAWT surface."); return info; } info.dsi = info.ds->GetDrawingSurfaceInfo(info.ds); if (info.dsi == NULL) { handleError(env, OPENGL_CANVAS_EXCEPTION, "Unable to get drawing surface info."); info.ds->Unlock(info.ds); if ((*env)->ExceptionOccurred(env)) { (*env)->ExceptionDescribe(env); } return info; } return info; }
JNIEXPORT void JNICALL Java_win32_WindowsUtils_flash (JNIEnv *env, jobject f, jobject component, jboolean bool) { JAWT awt; JAWT_DrawingSurface* ds; JAWT_DrawingSurfaceInfo* dsi; JAWT_Win32DrawingSurfaceInfo* dsi_win; jboolean result; jint lock; // Get the AWT awt.version = JAWT_VERSION_1_3; result = JAWT_GetAWT(env, &awt); assert(result != JNI_FALSE); // Get the drawing surface ds = awt.GetDrawingSurface(env, component); if(ds == NULL) return; // Lock the drawing surface lock = ds->Lock(ds); assert((lock & JAWT_LOCK_ERROR) == 0); // Get the drawing surface info dsi = ds->GetDrawingSurfaceInfo(ds); // Get the platform-specific drawing info dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo; FlashWindow(dsi_win->hwnd,bool); // Free the drawing surface info ds->FreeDrawingSurfaceInfo(dsi); // Unlock the drawing surface ds->Unlock(ds); // Free the drawing surface awt.FreeDrawingSurface(ds); }
JNIEXPORT jlong JNICALL Java_net_sf_jdshow_JAWTUtils_getWindowHandle (JNIEnv *env, jclass, jobject canvas) { JAWT awt; JAWT_DrawingSurface* ds; JAWT_DrawingSurfaceInfo* dsi; JAWT_Win32DrawingSurfaceInfo* dsi_win; jboolean result; jint lock; // Get the AWT awt.version = JAWT_VERSION_1_3; result = JAWT_GetAWT(env, &awt); assert(result != JNI_FALSE); // Get the drawing surface ds = awt.GetDrawingSurface(env, canvas); if(ds == NULL) return 0; // Lock the drawing surface lock = ds->Lock(ds); assert((lock & JAWT_LOCK_ERROR) == 0); // Get the drawing surface info dsi = ds->GetDrawingSurfaceInfo(ds); // Get the platform-specific drawing info dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo; HDC hdc = dsi_win->hdc; HWND hWnd = dsi_win->hwnd; // Free the drawing surface info ds->FreeDrawingSurfaceInfo(dsi); // Unlock the drawing surface ds->Unlock(ds); // Free the drawing surface awt.FreeDrawingSurface(ds); return (jlong) hWnd; }
JNIEXPORT jboolean JNICALL Java_org_jitsi_impl_neomedia_jmfext_media_renderer_video_JAWTRenderer_paint (JNIEnv *env, jclass clazz, jlong handle, jobject component, jobject g, jint zOrder) { #ifdef __ANDROID__ return JAWTRenderer_paint(0, NULL, clazz, handle, g, zOrder); #else /* #ifdef __ANDROID__ */ JAWT awt; jboolean awtIsAvailable; jboolean wantsPaint; awt.version = JAWT_VERSION_1_4; #ifdef __APPLE__ #ifndef JAWT_MACOSX_USE_CALAYER #define JAWT_MACOSX_USE_CALAYER 0x80000000 #endif /* #ifndef JAWT_MACOSX_USE_CALAYER */ awt.version |= JAWT_MACOSX_USE_CALAYER; awtIsAvailable = JAWT_GetAWT(env, &awt); /* * We do not know whether JAWT_GetAWT will fail when JAWT_MACOSX_USE_CALAYER * is specified and not supported or it will rather remove the flag from the * version field of JAWT. That's why we will call the function in question * again in case of failure with the flag removed. */ if (JNI_FALSE == awtIsAvailable) { awt.version &= ~JAWT_MACOSX_USE_CALAYER; awtIsAvailable = JAWT_GetAWT(env, &awt); } #else /* #ifdef __APPLE__ */ awtIsAvailable = JAWT_GetAWT(env, &awt); #endif /* #ifdef __APPLE__ */ wantsPaint = JNI_TRUE; if (JNI_TRUE == awtIsAvailable) { JAWT_DrawingSurface *ds; ds = awt.GetDrawingSurface(env, component); if (ds) { jint dsLock; dsLock = ds->Lock(ds); if (0 == (dsLock & JAWT_LOCK_ERROR)) { JAWT_DrawingSurfaceInfo *dsi; dsi = ds->GetDrawingSurfaceInfo(ds); if (dsi && dsi->platformInfo) { /* * The function arguments env and component are now * available as the fields env and target, respectively, of * the JAWT_DrawingSurface which is itself the value of the * field ds of the JAWT_DrawingSurfaceInfo. */ wantsPaint = JAWTRenderer_paint( awt.version, dsi, clazz, handle, g, zOrder); ds->FreeDrawingSurfaceInfo(dsi); } ds->Unlock(ds); } awt.FreeDrawingSurface(ds); } } return wantsPaint; #endif /* #ifdef __ANDROID__ */ }
/* * Class: MyCanvas * Method: paint * Signature: (Ljava/awt/Graphics;)V */ JNIEXPORT void JNICALL Java_MyCanvas_paint (JNIEnv* env, jobject canvas, jobject graphics) { JAWT awt; JAWT_DrawingSurface* ds; JAWT_DrawingSurfaceInfo* dsi; JAWT_X11DrawingSurfaceInfo* dsi_x11; jboolean result; jint lock; GC gc; jobject ref; /* Get the AWT */ awt.version = JAWT_VERSION_1_4; if (JAWT_GetAWT(env, &awt) == JNI_FALSE) { printf("AWT Not found\n"); return; } /* Lock the AWT */ awt.Lock(env); /* Unlock the AWT */ awt.Unlock(env); /* Get the drawing surface */ ds = awt.GetDrawingSurface(env, canvas); if (ds == NULL) { printf("NULL drawing surface\n"); return; } /* Lock the drawing surface */ lock = ds->Lock(ds); printf("Lock value %d\n", (int)lock); if((lock & JAWT_LOCK_ERROR) != 0) { printf("Error locking surface\n"); awt.FreeDrawingSurface(ds); return; } /* Get the drawing surface info */ dsi = ds->GetDrawingSurfaceInfo(ds); if (dsi == NULL) { printf("Error getting surface info\n"); ds->Unlock(ds); awt.FreeDrawingSurface(ds); return; } /* Get the platform-specific drawing info */ dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo; /* Now paint */ gc = XCreateGC(dsi_x11->display, dsi_x11->drawable, 0, 0); XSetForeground(dsi_x11->display, gc, 0); XFillRectangle(dsi_x11->display, dsi_x11->drawable, gc, 5, 5, 90, 90); XFreeGC(dsi_x11->display, gc); ref = awt.GetComponent(env, (void*)(dsi_x11->drawable)); if (!(*env)->IsSameObject(env, ref, canvas)) { printf("Error! Different objects!\n"); } /* Free the drawing surface info */ ds->FreeDrawingSurfaceInfo(dsi); /* Unlock the drawing surface */ ds->Unlock(ds); /* Free the drawing surface */ awt.FreeDrawingSurface(ds); }
JNIEXPORT void JNICALL Java_nothome_mswindows_IECanvas_initialize(JNIEnv *pEnv, jobject pCanvas, jboolean bUseMozilla) { HWND hwndIn = 0; // get the AWT version JAWT awt; JAWT_DrawingSurface* ds; JAWT_DrawingSurfaceInfo* dsi; JAWT_Win32DrawingSurfaceInfo* dsi_win; jboolean result; jint lock; // find awt version awt.version = JAWT_VERSION_1_3; result = JAWT_GetAWT(pEnv, &awt); if (result == NULL) { printf("Needs AWT version 1.3 or newer!\n"); return; } ds = awt.GetDrawingSurface(pEnv, pCanvas); if (ds == NULL) { printf("unable to get drawing surface!\n"); return; } lock = ds->Lock(ds); if ((lock & JAWT_LOCK_ERROR) != 0) { printf("unable to lock drawing surface!\n"); return; } dsi = ds->GetDrawingSurfaceInfo(ds); dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo; // get hwnd! //printf("the hwnd returned from jawt; [0x%x]\n", dsi_win->hwnd); hwndIn = dsi_win->hwnd; ds->FreeDrawingSurfaceInfo(dsi); ds->Unlock(ds); awt.FreeDrawingSurface(ds); // done! if (hwndIn == 0) { printf("Unable to get HWND to parent Canvas, aborting!\n"); return; } printf("using mozilla? %d", bUseMozilla); // Start new thread ThreadParam *pThreadParam = new ThreadParam; pEnv->GetJavaVM(&(pThreadParam->pJavaVM)); // Lock the jobject referance so we can call java code safely. pThreadParam->pObjRef = pEnv->NewGlobalRef(pCanvas); pThreadParam->hashCode = Registry::GetHashCode(pEnv, pThreadParam->pObjRef); CIECanvas *pNull = NULL; // Sometimes the resize call is sent before the canvas is created. Registry::Add((void*)pThreadParam->hashCode, (void*&) pNull); pThreadParam->hwnd = (HWND) hwndIn; pThreadParam->bUseMozilla = bUseMozilla; if (pThreadParam->pObjRef == 0) { printf("error when doing global ref to obj..\n"); return; } _beginthread(runATL, 0, pThreadParam); }
/* * Class: com_sun_star_comp_beans_LocalOfficeWindow * Method: getNativeWindow * Signature: ()J */ JNIEXPORT jlong JNICALL Java_com_sun_star_comp_beans_LocalOfficeWindow_getNativeWindow (JNIEnv * env, jobject obj_this) { jboolean result; jint lock; JAWT awt; JAWT_DrawingSurface* ds; JAWT_DrawingSurfaceInfo* dsi; JAWT_Win32DrawingSurfaceInfo* dsi_win; HDC hdc; HWND hWnd; LONG hFuncPtr; /* Get the AWT */ awt.version = JAWT_VERSION_1_3; result = JAWT_GetAWT(env, &awt); if (result == JNI_FALSE) ThrowException(env, "java/lang/RuntimeException", "JAWT_GetAWT failed"); /* Get the drawing surface */ if ((ds = awt.GetDrawingSurface(env, obj_this)) == NULL) return 0L; /* Lock the drawing surface */ lock = ds->Lock(ds); if ( (lock & JAWT_LOCK_ERROR) != 0) ThrowException(env, "java/lang/RuntimeException", "Could not get AWT drawing surface."); /* Get the drawing surface info */ dsi = ds->GetDrawingSurfaceInfo(ds); /* Get the platform-specific drawing info */ dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo; hdc = dsi_win->hdc; hWnd = dsi_win->hwnd; /* Free the drawing surface info */ ds->FreeDrawingSurfaceInfo(dsi); /* Unlock the drawing surface */ ds->Unlock(ds); /* Free the drawing surface */ awt.FreeDrawingSurface(ds); /* Register own window procedure Do it one times only! Otherwhise multiple instances will be registered and calls on such construct produce a stack overflow. */ if (GetProp( hWnd, OLD_PROC_KEY )==0) { hFuncPtr = SetWindowLong( hWnd, GWL_WNDPROC, (DWORD)OpenOfficeWndProc ); SetProp( hWnd, OLD_PROC_KEY, (HANDLE)hFuncPtr ); } return ((jlong)hWnd); }
JNIEXPORT void JNICALL Java_MyCanvas_paint (JNIEnv* env, jobject canvas, jobject graphics) { /* Get the AWT */ JAWT awt; awt.version = JAWT_VERSION_1_4; if (JAWT_GetAWT(env, &awt) == JNI_FALSE) { printf("AWT Not found\n"); return; } /* Lock the AWT */ awt.Lock(env); /* Unlock the AWT */ awt.Unlock(env); /* Get the drawing surface */ JAWT_DrawingSurface* ds = awt.GetDrawingSurface(env, canvas); if (ds == NULL) { printf("NULL drawing surface\n"); return; } /* Lock the drawing surface */ jint lock = ds->Lock(ds); printf("Lock value %d\n", (int)lock); if((lock & JAWT_LOCK_ERROR) != 0) { printf("Error locking surface\n"); return; } /* Get the drawing surface info */ JAWT_DrawingSurfaceInfo* dsi = ds->GetDrawingSurfaceInfo(ds); if (dsi == NULL) { printf("Error getting surface info\n"); ds->Unlock(ds); return; } /* Get the platform-specific drawing info */ JAWT_Win32DrawingSurfaceInfo* dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo; /* Now paint */ PAINTSTRUCT ps; /* Do not use the HDC returned from BeginPaint()!! */ ::BeginPaint(dsi_win->hwnd, &ps); HBRUSH hbrush = (HBRUSH)::GetStockObject(BLACK_BRUSH); RECT rect; rect.left = 5; rect.top = 5; rect.right = 95; rect.bottom = 95; ::FillRect(dsi_win->hdc, &rect, hbrush); ::EndPaint(dsi_win->hwnd, &ps); jobject ref = awt.GetComponent(env, (void*)(dsi_win->hwnd)); if (!env->IsSameObject(ref, canvas)) { printf("Error! Different objects!\n"); } /* Free the drawing surface info */ ds->FreeDrawingSurfaceInfo(dsi); /* Unlock the drawing surface */ ds->Unlock(ds); /* Free the drawing surface */ awt.FreeDrawingSurface(ds); }