JNIEXPORT jlong JNICALL Java_bor_util_JAWT_getDrawingSurfaceWindowIdAWT(JNIEnv* env, jclass clazz, jobject canvas, jlong dsHandle, jlong dsiHandle, jlong display, jint screen) {


//@line:233

   #ifndef VK_USE_PLATFORM_ANDROID_KHR 		
      JAWT_DrawingSurface *ds = reinterpret_cast<JAWT_DrawingSurface*>(dsHandle);
      JAWT_DrawingSurfaceInfo *dsi = reinterpret_cast<JAWT_DrawingSurfaceInfo *>(dsiHandle);
      jint lock;
      jlong window;
      
      ds->env = env;      
      lock = ds->Lock(ds);
      if ( (lock & JAWT_LOCK_ERROR) != 0 ) {
          printf("Error locking surface \n");
          ds->Unlock(ds);
          lock = ds->Lock(ds);
      }
      
      #ifdef VK_USE_PLATFORM_WIN32_KHR   
          JAWT_Win32DrawingSurfaceInfo *dsi_win = (JAWT_Win32DrawingSurfaceInfo*) dsi->platformInfo;
          window = (jlong)dsi_win->hwnd;
      #else 
          JAWT_X11DrawingSurfaceInfo *dsi_x11 = (JAWT_X11DrawingSurfaceInfo*) dsi->platformInfo;
          window = (jint)dsi_x11->drawable;
      #endif    
      ds->Unlock(ds);
      return reinterpret_cast<jlong>(window); 
  #elif
     return (jlong)0;
  #endif  
     

}
Example #2
0
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);
	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;
}
static inline jboolean wrapped_Java_bor_util_JAWT_getRectangle0
(JNIEnv* env, jclass clazz, jlong dsHandle, jintArray obj_val, int* val) {

//@line:515

    #ifndef VK_USE_PLATFORM_ANDROID_KHR                                                      
         JAWT_DrawingSurface *ds;
         JAWT_DrawingSurfaceInfo* dsi;
         jint lock;
                           
         ds  = reinterpret_cast<JAWT_DrawingSurface *>(dsHandle);          
         ds->env = env;
         lock = ds->Lock(ds);
         if ( (lock & JAWT_LOCK_ERROR) != 0 ) {
                  printf("Error locking surface \n");
                  return JNI_FALSE;
          }             
         // update dsi
         dsi = ds->GetDrawingSurfaceInfo(ds);                                     
          val[0] = dsi->bounds.x;
          val[1] = dsi->bounds.y;
          val[2] = dsi->bounds.width;
          val[3] = dsi->bounds.height;          
         // Free the drawing surface info
         ds->FreeDrawingSurfaceInfo(dsi);        
         // unlock  the drawing surface
         ds->Unlock(ds);               
         return JNI_TRUE;
    #elif
      return JNI_FALSE;
    #endif 
          
       
}
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 jlong JNICALL Java_bor_util_JAWT_getDrawingSurfaceInfo0(JNIEnv* env, jclass clazz, jlong dsObj) {


//@line:144

   #ifndef VK_USE_PLATFORM_ANDROID_KHR 
	
	JAWT_DrawingSurface *ds = reinterpret_cast<JAWT_DrawingSurface*>(dsObj);
      	JAWT_DrawingSurfaceInfo *dsi;
       	jint lock;

        ds->env = env;
        lock = ds->Lock(ds);
        if ((lock & JAWT_LOCK_ERROR) != 0) {
	     fprintf(stderr, "Error locking surface. Try again...\n");
	     //try again
	     ds->Unlock(ds);
	     lock = ds->Lock(ds);
	     // check 
	     if ((lock & JAWT_LOCK_ERROR) != 0) {
	        fprintf(stderr, "Error locking surface #2. Give up!\n");
	        return 0;
	     }
        }

       dsi = ds->GetDrawingSurfaceInfo(ds);

       if (dsi == NULL) {
	     fprintf(stderr, "Error GetDrawingSurfaceInfo\n");
	     ds->Unlock(ds);
	     return 0;
       }
       //unlock
       ds->Unlock(ds);
      return reinterpret_cast<jlong>(dsi);
     
  #elif
    return (jlong)0;
  #endif 
      
      

}
Example #8
0
/*****************************************************************************
 *
 * 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);
}
Example #9
0
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);
}
Example #10
0
JNIEXPORT void JNICALL Java_com_turbovnc_vncviewer_Viewport_x11FullScreen
  (JNIEnv *env, jobject obj, jboolean on)
{
  JAWT awt;
  JAWT_DrawingSurface *ds = NULL;
  JAWT_DrawingSurfaceInfo *dsi = NULL;
  JAWT_X11DrawingSurfaceInfo *x11dsi = NULL;
  jfieldID fid;
  jclass cls;

  awt.version = JAWT_VERSION_1_3;
  if (!handle) {
    if ((handle = dlopen("libjawt.so", RTLD_LAZY)) == NULL)
      _throw(dlerror());
    if ((__JAWT_GetAWT =
         (__JAWT_GetAWT_type)dlsym(handle, "JAWT_GetAWT")) == NULL)
      _throw(dlerror());
  }

  if (__JAWT_GetAWT(env, &awt) == JNI_FALSE)
    _throw("Could not initialize AWT native interface");

  if ((ds = awt.GetDrawingSurface(env, obj)) == NULL)
    _throw("Could not get drawing surface");

  if ((ds->Lock(ds) & JAWT_LOCK_ERROR) != 0)
    _throw("Could not lock surface");

  if ((dsi = ds->GetDrawingSurfaceInfo(ds)) == NULL)
    _throw("Could not get drawing surface info");

  if ((x11dsi = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo) == NULL)
    _throw("Could not get X11 drawing surface info");

  netwm_fullscreen(x11dsi->display, x11dsi->drawable, on);
  XSync(x11dsi->display, False);

  if ((cls = (*env)->GetObjectClass(env, obj)) == NULL ||
      (fid = (*env)->GetFieldID(env, cls, "x11win", "J")) == 0)
    _throw("Could not store X window handle");
  (*env)->SetLongField(env, obj, fid, x11dsi->drawable);

  printf("TurboVNC Helper: %s X11 full-screen mode for window 0x%.8lx\n",
         on ? "Enabling" : "Disabling", x11dsi->drawable);

  bailout:
  if (ds) {
    if (dsi) ds->FreeDrawingSurfaceInfo(dsi);
    ds->Unlock(ds);
    awt.FreeDrawingSurface(ds);
  }
}
Example #11
0
/*****************************************************************************
 *
 * 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;
}
Example #12
0
JNIEXPORT void JNICALL Java_com_turbovnc_vncviewer_Viewport_grabKeyboard
  (JNIEnv *env, jobject obj, jboolean on, jboolean pointer)
{
  JAWT awt;
  JAWT_DrawingSurface *ds = NULL;
  JAWT_DrawingSurfaceInfo *dsi = NULL;
  JAWT_Win32DrawingSurfaceInfo *w32dsi = NULL;

  if (on) {
    awt.version = JAWT_VERSION_1_3;
    if (!handle) {
      if ((handle = LoadLibrary("jawt")) == NULL)
        _throww32();
      if ((__JAWT_GetAWT =
           (__JAWT_GetAWT_type)GetProcAddress(handle, "JAWT_GetAWT")) == NULL)
        _throww32();
    }

    if (__JAWT_GetAWT(env, &awt) == JNI_FALSE)
      _throw("Could not initialize AWT native interface");

    if ((ds = awt.GetDrawingSurface(env, obj)) == NULL)
      _throw("Could not get drawing surface");

    if ((ds->Lock(ds) & JAWT_LOCK_ERROR) != 0)
      _throw("Could not lock surface");

    if ((dsi = ds->GetDrawingSurfaceInfo(ds)) == NULL)
      _throw("Could not get drawing surface info");

    if ((w32dsi = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo) == NULL)
      _throw("Could not get Win32 drawing surface info");

    LowLevelHook::Activate(w32dsi->hwnd);
    printf("TurboVNC Helper: Grabbed keyboard for window 0x%.8llx\n",
           (unsigned long long)w32dsi->hwnd);
  } else {
    LowLevelHook::Deactivate();
    printf("TurboVNC Helper: Ungrabbed keyboard\n");
  }

  bailout:
  if (ds) {
    if (dsi) ds->FreeDrawingSurfaceInfo(dsi);
    ds->Unlock(ds);
    awt.FreeDrawingSurface(ds);
  }
}
static inline jboolean wrapped_Java_bor_util_JAWT_getHwndHdc
(JNIEnv* env, jclass clazz, jlong dsHandle, jlongArray obj_val, long long* val) {

//@line:470
 
    #ifndef VK_USE_PLATFORM_ANDROID_KHR       
          JAWT_DrawingSurface *ds;
          JAWT_DrawingSurfaceInfo* dsi;                
          jint lock = 0; 
          
          ds = reinterpret_cast<JAWT_DrawingSurface *>(dsHandle);               
          ds->env = env;          
          lock = ds->Lock(ds);          
          if((lock & JAWT_LOCK_ERROR) != 0){
               printf("getHWND() - Error locking surface. Try again...\n");
               ds->Unlock(ds);
               lock = ds->Lock(ds);               
               if((lock & JAWT_LOCK_ERROR) != 0){
                   printf("getHWND() - Error #2 locking surface. Give up. \n");
                   return JNI_FALSE;
               }
           }          
           // update dsi
           dsi = ds->GetDrawingSurfaceInfo(ds);
                                 
       // Get the platform-specific drawing info       
       #ifdef VK_USE_PLATFORM_WIN32_KHR  
                JAWT_Win32DrawingSurfaceInfo *dsi_win;      
                dsi_win = (JAWT_Win32DrawingSurfaceInfo *)dsi->platformInfo;
                if(dsi_win == NULL) return JNI_FALSE;                
                val[0] = (jlong) dsi_win->hwnd;    
                val[1] = (jlong) dsi_win->hdc;               
        #else
                 JAWT_X11DrawingSurfaceInfo *dsi_x11;
                 dsi_x11 = (JAWT_X11DrawingSurfaceInfo *)dsi->platformInfo;
                 if(dsi_x11 == NULL) return JNI_FALSE;                 
                 val[0] = (jlong) dsi_x11->drawable;   
                 val[1] = (jlong) dsi_x11->display;    
        #endif   
        
        // release dsi       
        ds->FreeDrawingSurfaceInfo(dsi); 
        return JNI_TRUE;          
    #elif
      return JNI_FALSE;
    #endif               
    
}
JNIEXPORT jboolean JNICALL Java_bor_util_JAWT_unlock0(JNIEnv* env, jclass clazz, jlong drawingSurface) {


//@line:448
 
    #ifndef VK_USE_PLATFORM_ANDROID_KHR
        JAWT_DrawingSurface *ds = reinterpret_cast<JAWT_DrawingSurface*>(drawingSurface);                
        ds->env = env;
        ds->Unlock(ds);                                
        return JNI_TRUE;
    #elif
      return JNI_FALSE;
    #endif 
    

}
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;
}
/*
 * 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);


}
Example #18
0
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);
}
Example #19
0
/*
 * 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);
}
Example #20
0
/*
 * 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;
}
Example #21
0
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);

}
Example #22
0
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_bor_util_JAWT_lock0(JNIEnv* env, jclass clazz, jlong drawingSurface) {


//@line:409
 
   #ifndef VK_USE_PLATFORM_ANDROID_KHR
        JAWT_DrawingSurface *ds = reinterpret_cast<JAWT_DrawingSurface*>(drawingSurface);
        jint lock = 0;
        ds->env = env;
        lock = ds->Lock(ds);
        if ((lock & JAWT_LOCK_ERROR) == 0) {
            return JNI_TRUE;
        } 
        else{ 
           cout<< "Failed lock AWT DrawingSurface!" <<endl;
           if ((lock & JAWT_LOCK_SURFACE_CHANGED) != 0) {
               // try again
               ds->Unlock(ds);
               lock = ds->Lock(ds);            
               if ((lock & JAWT_LOCK_ERROR) == 0) {
                 cout<< "Success on 2nd attempt to lock AWT DrawingSurface!" <<endl;
                  return JNI_TRUE;
               }else{ 
                   cout<< "Failed second attempt to lock AWT!" <<endl;
                   return JNI_FALSE;            
                 }
            } else{
                  return JNI_TRUE;
               }
        } //else
    #elif
      return JNI_FALSE;
    #endif     
     

}
/*
 * 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 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__ */
}
Example #26
0
/*
 * 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);
}
Example #27
0
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);
}
Example #28
0
/*
 * Class:     sage_UIUtils
 * Method:    getHWND
 * Signature: (Ljava/awt/Canvas;)J
 */
JNIEXPORT jlong JNICALL Java_sage_UIUtils_getHWND
	(JNIEnv *env, jclass jc, jobject canvas)
{
	JAWT awt;
	JAWT_DrawingSurface* ds = NULL;
	JAWT_DrawingSurfaceInfo* dsi = NULL;
	JAWT_Win32DrawingSurfaceInfo* dsi_win = NULL;
	jboolean result;
	jint lock;

	env->MonitorEnter(canvas);

	loadAWTLib();

	// Get the AWT, we have to explicitly load it otherwise it'll try it load it
	// when we execute and the link will fail.
	typedef jboolean (JNICALL *AWTPROC)(JNIEnv* env, JAWT* awt);
	
	awt.version = JAWT_VERSION_1_4;
#ifdef _WIN64
	AWTPROC lpfnProc = (AWTPROC)GetProcAddress(sageLoadedAwtLib, "JAWT_GetAWT");
#else
	AWTPROC lpfnProc = (AWTPROC)GetProcAddress(sageLoadedAwtLib, "_JAWT_GetAWT@8");
#endif
	result = lpfnProc(env, &awt);
	if (result == JNI_FALSE)
	{
		slog((env, "Failed loading JAWT lib\r\n"));
		env->MonitorExit(canvas);
		return 0;
	}

	awt.Lock(env);

	// Get the drawing surface
	ds = awt.GetDrawingSurface(env, canvas);
	if (ds == NULL)
	{
		slog((env, "Failed getting drawing surface for AWT\r\n"));
		env->MonitorExit(canvas);
		awt.Unlock(env);
		return 0;
	}

	// Lock the drawing surface
	lock = ds->Lock(ds);
	if ((lock & JAWT_LOCK_ERROR) != 0)
	{
		slog((env, "Failed locking the drawing surface for AWT\r\n"));
		// Free the drawing surface
		awt.FreeDrawingSurface(ds);
		env->MonitorExit(canvas);
		awt.Unlock(env);
		return 0;
	}

	// Get the drawing surface info
	dsi = ds->GetDrawingSurfaceInfo(ds);
	if (dsi == NULL)
	{
		slog((env, "Failed getting dsi for AWT\r\n"));
		// Unlock the drawing surface
		ds->Unlock(ds);
		// Free the drawing surface
		awt.FreeDrawingSurface(ds);
		env->MonitorExit(canvas);
		awt.Unlock(env);
		return 0;
	}

	// Get the platform-specific drawing info
	dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;

	jlong rv = (jlong) 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);

	env->MonitorExit(canvas);
	awt.Unlock(env);
	return rv;
}
Example #29
0
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);
}
Example #30
0
JNIEXPORT void JNICALL Java_com_turbovnc_vncviewer_Viewport_grabKeyboard
  (JNIEnv *env, jobject obj, jboolean on, jboolean pointer)
{
  JAWT awt;
  JAWT_DrawingSurface *ds = NULL;
  JAWT_DrawingSurfaceInfo *dsi = NULL;
  JAWT_X11DrawingSurfaceInfo *x11dsi = NULL;
  int ret;

  awt.version = JAWT_VERSION_1_3;
  if (!handle) {
    if ((handle = dlopen("libjawt.so", RTLD_LAZY)) == NULL)
      _throw(dlerror());
    if ((__JAWT_GetAWT =
         (__JAWT_GetAWT_type)dlsym(handle, "JAWT_GetAWT")) == NULL)
      _throw(dlerror());
  }

  if (__JAWT_GetAWT(env, &awt) == JNI_FALSE)
    _throw("Could not initialize AWT native interface");

  if ((ds = awt.GetDrawingSurface(env, obj)) == NULL)
    _throw("Could not get drawing surface");

  if ((ds->Lock(ds) & JAWT_LOCK_ERROR) != 0)
    _throw("Could not lock surface");

  if ((dsi = ds->GetDrawingSurfaceInfo(ds)) == NULL)
    _throw("Could not get drawing surface info");

  if ((x11dsi = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo) == NULL)
    _throw("Could not get X11 drawing surface info");

  XSync(x11dsi->display, False);
  if (on) {
    int count = 5;
    while ((ret = XGrabKeyboard(x11dsi->display, x11dsi->drawable, True,
                                GrabModeAsync, GrabModeAsync, CurrentTime))
           != GrabSuccess) {
      switch (ret) {
        case AlreadyGrabbed:
          _throw("Could not grab keyboard: already grabbed by another application");
        case GrabInvalidTime:
          _throw("Could not grab keyboard: invalid time");
        case GrabNotViewable:
          /* The window should theoretically be viewable by now, but in
             practice, sometimes a race condition occurs with Swing.  It is
             unclear why, since everything should be happening in the EDT. */
          if (count == 0)
            _throw("Could not grab keyboard: window not viewable");
          usleep(100000);
          count--;
          continue;
        case GrabFrozen:
          _throw("Could not grab keyboard: keyboard frozen by another application");
      }
    }

    if (pointer) {
      ret = XGrabPointer(x11dsi->display, x11dsi->drawable, True,
                         ButtonPressMask | ButtonReleaseMask |
                         ButtonMotionMask | PointerMotionMask, GrabModeAsync,
                         GrabModeAsync, None, None, CurrentTime);
      switch (ret) {
        case AlreadyGrabbed:
          _throw("Could not grab pointer: already grabbed by another application");
        case GrabInvalidTime:
          _throw("Could not grab pointer: invalid time");
        case GrabNotViewable:
          _throw("Could not grab pointer: window not viewable");
        case GrabFrozen:
          _throw("Could not grab pointer: pointer frozen by another application");
      }
    }

    printf("TurboVNC Helper: Grabbed keyboard%s for window 0x%.8lx\n",
           pointer? " & pointer" : "", x11dsi->drawable);
  } else {
    XUngrabKeyboard(x11dsi->display, CurrentTime);
    if (pointer)
      XUngrabPointer(x11dsi->display, CurrentTime);
    printf("TurboVNC Helper: Ungrabbed keyboard%s\n",
           pointer ? " & pointer" : "");
  }
  XSync(x11dsi->display, False);

  bailout:
  if (ds) {
    if (dsi) ds->FreeDrawingSurfaceInfo(dsi);
    ds->Unlock(ds);
    awt.FreeDrawingSurface(ds);
  }
}