Ejemplo n.º 1
0
/*
 * Class:     com_sun_glass_ui_gtk_GtkCursor
 * Method:    _createCursor
 * Signature: (IILcom/sun/glass/ui/Pixels;)J
 */
JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_gtk_GtkCursor__1createCursor
  (JNIEnv * env, jobject obj, jint x, jint y, jobject pixels)
{
    GdkPixbuf *pixbuf = NULL;
    GdkCursor *cursor = NULL;
    env->CallVoidMethod(pixels, jPixelsAttachData, PTR_TO_JLONG(&pixbuf));
    if (!EXCEPTION_OCCURED(env)) {
        cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf, x, y);
    }
    g_object_unref(pixbuf);

    return PTR_TO_JLONG(cursor);
}
/**
 * Creates a cairo surface, ARGB32, native ordering, premultiplied alpha.
 */
JNIEXPORT jlong JNICALL 
Java_gnu_java_awt_peer_gtk_GtkVolatileImage_init (JNIEnv *env, 
						  jobject obj __attribute__ ((__unused__)), 
						  jobject peer,
						  jint width, jint height)
{
  GtkWidget *widget = NULL;
  GdkPixmap* pixmap;
  void *ptr = NULL;

  gdk_threads_enter();

  if( peer != NULL )
    {
      ptr = gtkpeer_get_widget (env, peer);
      g_assert (ptr != NULL);
      
      widget = GTK_WIDGET (ptr);
      g_assert (widget != NULL);
      pixmap = gdk_pixmap_new( widget->window, width, height, -1 );
    }
  else
    pixmap = gdk_pixmap_new( NULL, width, height, 
			     gdk_rgb_get_visual()->depth );

  gdk_threads_leave();

  g_assert( pixmap != NULL );

  return PTR_TO_JLONG( pixmap );
}
NS_IMETHODIMP
nsWFSecureEnv::SetStaticField(/*[in]*/ jni_type field_type,
			      /*[in]*/ jclass clazz, 
			      /*[in]*/ jfieldID fieldID,
			      /*[in]*/ jvalue val,
			      /*[in]*/ nsISecurityContext* ctx)
{
  //OJI_LOG("nsWFSecureEnv::SetStaticField");
  if (m_env == NULL || clazz == NULL || fieldID == NULL) 
     return NS_ERROR_NULL_POINTER;
   struct Java_CallInfo* call = NULL;
   nsWFSecureEnv::CreateJavaCallInfo(&call, ctx);
   call->type = Java_SetStaticField;
   call->data.__setStaticField.type = (enum jvmp_jni_type)field_type; // the same structure, really
   call->data.__setStaticField.clazz     = clazz;
   call->data.__setStaticField.fieldID   = fieldID;
   call->data.__setStaticField.value     = val;
   nsresult rv = m_jvm->ExtensionCall(1, PTR_TO_JLONG(call));
   if (!NS_FAILED(rv)) 
     {
       // XXX: do smth meaningful with possible Java exception
       if (call->jException) {
	 m_jvm->DeleteLocalRef(call->jException);
	 rv = NS_ERROR_FAILURE; 
       } else
	 rv = NS_OK;
     }
   nsWFSecureEnv::CleanupJavaCallInfo(call, ctx);
   return rv;
}   
NS_IMETHODIMP
nsWFSecureEnv::GetField(/*[in]*/  jni_type field_type,
			/*[in]*/  jobject obj, 
			/*[in]*/  jfieldID fieldID,
			/*[out]*/ jvalue* result,
			/*[in]*/  nsISecurityContext* ctx)
{
  //OJI_LOG("nsWFSecureEnv::GetField");
  if (m_env == NULL || obj == NULL || fieldID == NULL) 
    return NS_ERROR_NULL_POINTER;
  struct Java_CallInfo* call = NULL;
  nsWFSecureEnv::CreateJavaCallInfo(&call, ctx);
  call->type = Java_GetField;
  call->data.__getField.type = (enum jvmp_jni_type)field_type; // the same structure, really
  call->data.__getField.obj     = obj;
  call->data.__getField.fieldID = fieldID;
  nsresult rv = m_jvm->ExtensionCall(1, PTR_TO_JLONG(call));
  if (!NS_FAILED(rv)) 
    {
      // XXX: do smth meaningful with possible Java exception
      if (call->jException) {
	m_jvm->DeleteLocalRef(call->jException);
	 rv = NS_ERROR_FAILURE; 
       } else {
	 *result = call->data.__getField.result;
	 rv = NS_OK;
       }
     }
   nsWFSecureEnv::CleanupJavaCallInfo(call, ctx);
   return rv;
}
NS_IMETHODIMP
nsWFSecureEnv::CallNonvirtualMethod(/*[in]*/  jni_type ret_type,
				    /*[in]*/  jobject obj, 
				    /*[in]*/  jclass clazz,
				    /*[in]*/  jmethodID methodID,
				    /*[in]*/  jvalue *args, 
				    /*[out]*/ jvalue* result,
				    /*[in]*/  nsISecurityContext* ctx)
{
  if (result == NULL || obj == NULL || methodID == NULL)
        return NS_ERROR_NULL_POINTER;
  struct Java_CallInfo* call = NULL;
  nsWFSecureEnv::CreateJavaCallInfo(&call, ctx);
  //OJI_LOG5("CallMethod: %x %x %x %x", obj, methodID, args, result);
  call->type = Java_CallNonvirtualMethod;
  call->data.__callNonvirtualMethod.type     = (enum jvmp_jni_type)ret_type; // the same structure, really
  call->data.__callNonvirtualMethod.obj      = obj;
  call->data.__callNonvirtualMethod.clazz    = clazz;
  call->data.__callNonvirtualMethod.methodID = methodID;
  call->data.__callNonvirtualMethod.args     = args;
  nsresult rv = m_jvm->ExtensionCall(1, PTR_TO_JLONG(call));
  if (!NS_FAILED(rv)) 
    {
      // XXX: do smth meaningful with possible Java exception
      if (call->jException) {
	m_jvm->DeleteLocalRef(call->jException);
	rv = NS_ERROR_FAILURE; 
      } else {
	*result = call->data.__callNonvirtualMethod.result;
	rv = NS_OK;
      }
    }
  nsWFSecureEnv::CleanupJavaCallInfo(call, ctx);
  return rv;
}
//nsISecureEnv
NS_IMETHODIMP
nsWFSecureEnv::NewObject(/*[in]*/  jclass clazz, 
			 /*[in]*/  jmethodID methodID,
			 /*[in]*/  jvalue *args, 
			 /*[out]*/ jobject* result,
			 /*[in]*/  nsISecurityContext* ctx)
{
  //OJI_LOG("nsWFSecureEnv::NewObject");
  if (m_env == NULL || result == NULL)
        return NS_ERROR_NULL_POINTER;
  struct Java_CallInfo* call = NULL;
  nsWFSecureEnv::CreateJavaCallInfo(&call, ctx);
  call->type = Java_CreateObject;
  call->data.__createObject.clazz    = clazz;
  call->data.__createObject.methodID = methodID;
  call->data.__createObject.args = args;
  nsresult rv = m_jvm->ExtensionCall(1, PTR_TO_JLONG(call));
  if (!NS_FAILED(rv)) 
    {
      // XXX: do smth meaningful with possible Java exception
      if (call->jException) {
	m_jvm->DeleteLocalRef(call->jException);
	rv = NS_ERROR_FAILURE; 
      } else {
	*result = call->data.__createObject.result;
	rv = NS_OK;
      }
    }
  nsWFSecureEnv::CleanupJavaCallInfo(call, ctx);
  return rv;
}
Ejemplo n.º 7
0
NS_IMETHODIMP 
nsPluggableJVM::UnwrapJavaWrapper(jobject jobj, jint *jsobj)
{
  struct Java_CallInfo* call;
  nsresult rv = NS_OK;
  if (jsobj == NULL || !m_extID) return NS_ERROR_FAILURE;
  if (jobj == NULL) 
    { 
      *jsobj = 0;
      return NS_OK;
    }
  *jsobj = 0;
  nsWFSecureEnv::CreateJavaCallInfo(&call, NULL);
  call->type = Java_UnwrapJObject;
  call->jException = NULL;
  call->data.__unwrapJObject.jObject = jobj;
  call->data.__unwrapJObject.jstid = (jint)PR_GetCurrentThread();
  
  rv = ExtensionCall(1, PTR_TO_JLONG(call));
  if (!NS_FAILED(rv)) 
    {
      // XXX: do smth meaningful with possible Java exception
      if (call->jException) {
	DeleteLocalRef(call->jException);
	rv = NS_ERROR_FAILURE; 
      } else {
	*jsobj = call->data.__unwrapJObject.jsObject; 
      }
    }
  nsWFSecureEnv::CleanupJavaCallInfo(call, NULL);
  return rv;
}
Ejemplo n.º 8
0
NS_IMETHODIMP 
nsPluggableJVM::GetJavaWrapper(jint obj, jobject *wrapper)
{
  struct Java_CallInfo* call;
  nsresult rv = NS_OK;
  *wrapper = NULL;
  if (!m_extID) return NS_ERROR_FAILURE;
  nsWFSecureEnv::CreateJavaCallInfo(&call, NULL);
  call->type = Java_WrapJSObject;
  call->jException = NULL;
  call->data.__wrapJSObject.jsObject = obj;
  call->data.__wrapJSObject.jstid = (jint)PR_GetCurrentThread();
  
  rv = ExtensionCall(1, PTR_TO_JLONG(call));
  if (!NS_FAILED(rv)) 
    {
      // XXX: do smth meaningful with possible Java exception
      if (call->jException) {
	DeleteLocalRef(call->jException);
	rv = NS_ERROR_FAILURE; 
      } else {
	// global ref already created
	*wrapper = call->data.__wrapJSObject.jObject; 
      }
    }
  nsWFSecureEnv::CleanupJavaCallInfo(call, NULL);
  return rv;
}
Ejemplo n.º 9
0
/*
 * Class:     com_sun_glass_ui_gtk_GtkTimer
 * Method:    _start
 * Signature: (Ljava/lang/Runnable;I)J
 */
JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_gtk_GtkTimer__1start
  (JNIEnv * env, jobject obj, jobject runnable, jint period)
{
    RunnableContext* context = (RunnableContext*) malloc(sizeof(RunnableContext));
    context->runnable = env->NewGlobalRef(runnable);
    context->flag = 0;
    gdk_threads_add_timeout_full(G_PRIORITY_HIGH_IDLE, period, call_runnable_in_timer, context, NULL);
    return PTR_TO_JLONG(context);
}
static void set_image_data(GtkSelectionData *selection_data, jobject pixels)
{
    GdkPixbuf *pixbuf = NULL;

    mainEnv->CallVoidMethod(pixels, jPixelsAttachData, PTR_TO_JLONG(&pixbuf));
    if (!EXCEPTION_OCCURED(mainEnv)) {
        gtk_selection_data_set_pixbuf(selection_data, pixbuf);
    }

    g_object_unref(pixbuf);
}
JNIEXPORT jlong JNICALL 
Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getNativeFontPointer
 (JNIEnv *env, jobject obj, jint n)
{
  int i;
  PangoFcFont *font = getFont(env, obj);
  
  for (i = 0; i < n; i++)
    g_object_ref(font);
  
  return PTR_TO_JLONG(font);
}
Ejemplo n.º 12
0
static jlong NativeMemoryChunk_nativeAllocate(
    JNIEnv* env,
    jclass clzz,
    jint size) {
  UNUSED(clzz);
  void* pointer = malloc(size);
  if (!pointer) {
    (*env)->ThrowNew(env, jRuntimeException_class, "could not allocate memory");
    return 0;
  }
  return PTR_TO_JLONG(pointer);
}
Ejemplo n.º 13
0
NS_IMETHODIMP
nsWFSecureEnv::CallStaticMethod(/*[in]*/  jni_type ret_type,
                                /*[in]*/  jclass clazz,
                                /*[in]*/  jmethodID methodID,
                                /*[in]*/  jvalue *args, 
                                /*[out]*/ jvalue* result,
                                /*[in]*/  nsISecurityContext* ctx)
{
  if (result == NULL  || clazz == NULL || methodID == NULL)
    return NS_ERROR_NULL_POINTER;
  if (methodID ==  g_identityHashCodeMID)
    {
      //OJI_LOG("using cached identityHashCode");
      result->i = m_env->CallStaticIntMethodA(g_javaLangSystem, 
					      g_identityHashCodeMID, 
					      args);  
      return NS_OK;
    }
  struct Java_CallInfo* call = NULL;
  nsWFSecureEnv::CreateJavaCallInfo(&call, ctx);
  call->type = Java_CallStaticMethod;
  call->data.__callStaticMethod.type     = (enum jvmp_jni_type)ret_type; // the same structure, really
  call->data.__callStaticMethod.clazz    = clazz;
  call->data.__callStaticMethod.methodID = methodID;
  call->data.__callStaticMethod.args     = args;
  nsresult rv = m_jvm->ExtensionCall(1, PTR_TO_JLONG(call));
  if (!NS_FAILED(rv)) 
    {
      // XXX: do smth meaningful with possible Java exception
      if (call->jException) {
	m_jvm->DeleteLocalRef(call->jException);
	rv = NS_ERROR_FAILURE; 
      } else
	*result = call->data.__callStaticMethod.result;
    }
  nsWFSecureEnv::CleanupJavaCallInfo(call, ctx);
  return rv;
}
Ejemplo n.º 14
0
static gboolean dnd_source_set_image(GdkWindow *requestor, GdkAtom property, GdkAtom target)
{
    jobject pixels = dnd_source_get_data("application/x-java-rawimage");
    if (!pixels) {
        return FALSE;
    }
    
    gchar *buffer;
    gsize size;
    const char * type;
    GdkPixbuf *pixbuf = NULL;
    gboolean result = FALSE;

    if (target == TARGET_MIME_PNG_ATOM) {
        type = "png";
    } else if (target == TARGET_MIME_JPEG_ATOM) {
        type = "jpeg";
    } else if (target == TARGET_MIME_TIFF_ATOM) {
        type = "tiff";
    } else if (target == TARGET_MIME_BMP_ATOM) {
        type = "bmp";
    } else {
        return FALSE;
    }

    mainEnv->CallVoidMethod(pixels, jPixelsAttachData, PTR_TO_JLONG(&pixbuf));

    if (!EXCEPTION_OCCURED(mainEnv)
            && gdk_pixbuf_save_to_buffer(pixbuf, &buffer, &size, type, NULL, NULL)) {
        gdk_property_change(requestor, property, target,
                8, GDK_PROP_MODE_REPLACE, (guchar *)buffer, size);
        result = TRUE;
    }
    g_object_unref(pixbuf);
    return result;
}
JNIEXPORT void JNICALL 
Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getGlyphs
  (JNIEnv *env, jobject obj, jintArray codepoints, jintArray glyphs,
   jlongArray fonts)
{
  PangoFcFont *default_font, *current_font;
  PangoFontset *pfs;
  jint *cpvals;
  jint length;
  int i;

  /* Set up default font and fontset */
  default_font = getFont(env, obj);
  current_font = default_font;
  pfs = getFontSet(env, obj);

  /* Retrieve string information */
  length = (*env)->GetArrayLength (env, codepoints);
  cpvals = (*env)->GetIntArrayElements (env, codepoints, NULL);
  
  jint *glyphArray = (*env)->GetIntArrayElements (env, glyphs, NULL);
  jlong *fontArray = (*env)->GetLongArrayElements (env, fonts, NULL);

  /* A design goal of Pango is to be threadsafe, but it's admitted that it is
   * not actually threadsafe at the moment.  Using gdk locking here to be safe,
   * but I don't know if if actually helps at all... */ 
  gdk_threads_enter();

  for( i = 0; i < length; i++ )
  {
  	/* Ensure the current font has the requested character; if it doesn't,
  	 * try the default font before pulling a new font out of the fontset.
  	 * Once chosen, a font will be used until a character not in the font is
  	 * encountered. */ 
  	if (!pango_fc_font_has_char(current_font, cpvals[i]))
  	  {
  	    if (pango_fc_font_has_char(default_font, cpvals[i]))
  	      {
  	        current_font = default_font;
            g_object_ref(current_font);
  	      }
  	    else
  	      {
  	        current_font = (PangoFcFont*)pango_fontset_get_font(pfs, cpvals[i]);
  	      }
  	  }
  	else
      {
        g_object_ref(current_font);
      }
  	
  	/* Get glyph, and store both glyph and pointer to font */
    glyphArray[i] = (int)pango_fc_font_get_glyph(current_font,
                                                 (gunichar)cpvals[i]);
    fontArray[i] = PTR_TO_JLONG(current_font);
  }
  
  gdk_threads_leave();

  (*env)->ReleaseIntArrayElements (env, glyphs, glyphArray, 0);
  (*env)->ReleaseIntArrayElements (env, codepoints, cpvals, 0);
  (*env)->ReleaseLongArrayElements (env, fonts, fontArray, 0);
}
Ejemplo n.º 16
0
/*
 * Class:     com_sun_glass_ui_gtk_GtkView
 * Method:    _create
 * Signature: (Ljava/util/Map;)J
 */
JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_gtk_GtkView__1create
  (JNIEnv * env, jobject obj, jobject caps)
{
    GlassView *view = new GlassView();
    return PTR_TO_JLONG(view);
}