JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_nativeCreate
  (JNIEnv *env, jobject obj, jobject group, jboolean state)
{
  GtkWidget *button;

  /* Create global reference and save it for future use */
  NSA_SET_GLOBAL_REF (env, obj);

  gdk_threads_enter ();

  if (group == NULL)
    button = gtk_check_button_new_with_label ("");
  else
    {
      void *native_group = NSA_GET_PTR (env, group);
      button = gtk_radio_button_new_with_label_from_widget (native_group, "");
      if (native_group == NULL)
	{
	  /* Set the native group so we can use the correct value the
	     next time around.  FIXME: this doesn't work!  */
	  NSA_SET_PTR (env, group, button);
	}
    }
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), state);

  gdk_threads_leave ();

  NSA_SET_PTR (env, obj, button);
}
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_create
  (JNIEnv *env, jobject obj, jobject group)
{
  GtkWidget *button;

  NSA_SET_GLOBAL_REF (env, obj);

  gdk_threads_enter ();

  if (group == NULL)
    button = gtk_check_button_new_with_label ("");
  else
    {
      void *native_group = NSA_GET_PTR (env, group);
      button = gtk_radio_button_new_with_label_from_widget (native_group, "");
      if (native_group == NULL)
	{
	  /* Set the native group so we can use the correct value the
	     next time around.  FIXME: this doesn't work!  */
	  NSA_SET_PTR (env, group, button);
	}
    }

  gdk_threads_leave ();

  NSA_SET_PTR (env, obj, button);
}
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkLabelPeer_create
  (JNIEnv *env, jobject obj, jstring text, jfloat xalign)
{
  GtkWidget *label;
  GtkWidget *eventbox;
  const char *str;

  NSA_SET_GLOBAL_REF (env, obj);

  str = (*env)->GetStringUTFChars (env, text, 0);

  gdk_threads_enter ();

  eventbox = gtk_event_box_new ();
  label = gtk_label_new (str);
  gtk_misc_set_alignment (GTK_MISC (label), xalign, 0.5);
  gtk_container_add (GTK_CONTAINER (eventbox), label);
  gtk_widget_show (label);

  gdk_threads_leave ();

  (*env)->ReleaseStringUTFChars (env, text, str);

  NSA_SET_PTR (env, obj, eventbox);
}
JNIEXPORT void JNICALL 
Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_create 
  (JNIEnv *env, jobject obj, jobject comp)
{
  void *ptr;
  
  gdk_threads_enter ();
  
  NSA_SET_GLOBAL_REF (env, obj);  
  NSA_SET_GLOBAL_REF (env, comp);
  
  ptr = NSA_GET_PTR (env, comp);
  widget = get_widget (GTK_WIDGET (ptr));

  gdk_threads_leave ();
}
jobject
classpath_jawt_create_lock ()
{
  JNIEnv *env = gdk_env ();
  jobject lock = (*env)->NewStringUTF (env, "jawt-lock");
  NSA_SET_GLOBAL_REF (env, lock);
  return lock;
}
Example #6
0
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_create
(JNIEnv *env, jobject obj, jobject parent, int mode)
{
    void *parentp;
    gpointer widget;

    gdk_threads_enter ();

    /* Create global reference and save it for future use */
    NSA_SET_GLOBAL_REF (env, obj);

    parentp = NSA_GET_PTR(env, parent);

    if (mode == AWT_FILEDIALOG_LOAD)
        widget = gtk_file_chooser_dialog_new
                 ("Open File",
                  GTK_WINDOW(parentp),
                  GTK_FILE_CHOOSER_ACTION_OPEN,
                  GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                  GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
                  NULL);
    else
    {
        widget = gtk_file_chooser_dialog_new
                 ("Save File",
                  GTK_WINDOW(parentp),
                  GTK_FILE_CHOOSER_ACTION_SAVE,
                  GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                  GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
                  NULL);
#if GTK_MINOR_VERSION >= 8
        gtk_file_chooser_set_do_overwrite_confirmation
        (GTK_FILE_CHOOSER (widget), TRUE);
#endif
    }


    /* GtkFileChooserDialog is not modal by default */
    gtk_window_set_modal (GTK_WINDOW (widget), TRUE);

    /* We must add this window to the group so input in the others are
       disable while it is being shown */
    gtk_window_group_add_window (cp_gtk_global_window_group,
                                 GTK_WINDOW (widget));

    NSA_SET_PTR (env, obj, widget);

    gdk_threads_leave ();
}
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuBarPeer_create
  (JNIEnv *env, jobject obj)
{
  GtkWidget *widget;

  /* Create global reference and save it for future use */
  NSA_SET_GLOBAL_REF (env, obj);

  gdk_threads_enter ();
  
  widget = gtk_menu_bar_new ();
  gtk_widget_show (widget);

  gdk_threads_leave ();

  NSA_SET_PTR (env, obj, widget);
}
JNIEXPORT void JNICALL 
Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_create
  (JNIEnv *env, jobject obj,
   jint textview_width, jint textview_height,  jint scroll)
{
  GtkWidget *text;
  GtkWidget *sw;
  GtkWidget *eventbox;

  gdk_threads_enter ();

  /* Create global reference and save it for future use */
  NSA_SET_GLOBAL_REF (env, obj);

  text = gtk_text_view_new ();
  gtk_widget_set_size_request (text, textview_width, textview_height);
  gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW (text), TRUE);

  gtk_widget_show (text);

  eventbox = gtk_event_box_new ();
  sw = gtk_scrolled_window_new (NULL, NULL);
  gtk_container_add (GTK_CONTAINER (sw), text);
  gtk_container_add (GTK_CONTAINER (eventbox), sw);
  gtk_widget_show (sw);
  
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
     /* horizontal scrollbar */
     (scroll == AWT_TEXTAREA_SCROLLBARS_BOTH
      || scroll == AWT_TEXTAREA_SCROLLBARS_HORIZONTAL_ONLY) ? 
       GTK_POLICY_ALWAYS : GTK_POLICY_NEVER,
     /* vertical scrollbar */
     (scroll == AWT_TEXTAREA_SCROLLBARS_BOTH
      || scroll == AWT_TEXTAREA_SCROLLBARS_VERTICAL_ONLY) ? 
       GTK_POLICY_ALWAYS : GTK_POLICY_NEVER);

  gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text),
			       (scroll == AWT_TEXTAREA_SCROLLBARS_BOTH
				|| scroll == AWT_TEXTAREA_SCROLLBARS_HORIZONTAL_ONLY)
			       ? GTK_WRAP_NONE : GTK_WRAP_WORD);

  NSA_SET_PTR (env, obj, eventbox);

  gdk_threads_leave ();
}
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkButtonPeer_create
  (JNIEnv *env, jobject obj)
{
  GtkWidget *button;

  /* Create global reference and save it for future use */
  NSA_SET_GLOBAL_REF (env, obj);

  gdk_threads_enter ();
  
  button = gtk_button_new();
  gtk_widget_show (button);

  gdk_threads_leave ();

  NSA_SET_PTR (env, obj, button);
}
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GdkGraphics_connectSignals
  (JNIEnv *env, jobject obj, jobject peer)
{
  void *ptr;
  jobject *gref;

  NSA_SET_GLOBAL_REF (env, obj);
  gref = NSA_GET_GLOBAL_REF (env, obj);

  ptr = NSA_GET_PTR (env, peer);

  gdk_threads_enter ();

  g_signal_connect_after (G_OBJECT (ptr), "realize",
                          G_CALLBACK (realize_cb), *gref);

  gdk_threads_leave ();
}
JNIEXPORT void JNICALL 
Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_create
  (JNIEnv *env, jobject obj, jint text_width)
{
  GtkWidget *entry;

  /* Create global reference and save it for future use */
  NSA_SET_GLOBAL_REF (env, obj);

  gdk_threads_enter ();

  entry = gtk_entry_new ();
  gtk_widget_set_size_request (entry,
			       text_width + 2 * get_border_width (entry), -1);

  gdk_threads_leave ();

  NSA_SET_PTR (env, obj, entry);
}
JNIEXPORT void JNICALL 
Java_gnu_java_awt_peer_gtk_GtkChoicePeer_create 
  (JNIEnv *env, jobject obj)
{
  GtkWidget *combobox;
  GtkWidget *eventbox;
  jobject *gref;

  gdk_threads_enter ();
  
  NSA_SET_GLOBAL_REF (env, obj);
  gref = NSA_GET_GLOBAL_REF (env, obj);
  
  eventbox = gtk_event_box_new ();
  combobox = gtk_combo_box_new_text ();
  gtk_container_add (GTK_CONTAINER (eventbox), combobox);
  gtk_widget_show (combobox);  

  NSA_SET_PTR (env, obj, eventbox);

  gdk_threads_leave ();
}
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkEmbeddedWindowPeer_create
  (JNIEnv *env, jobject obj, jlong socket_id)
{
  GtkWidget *window;
  GtkWidget *fixed;

  gdk_threads_enter ();

  NSA_SET_GLOBAL_REF (env, obj);

  window = gtk_plug_new ((GdkNativeWindow) socket_id);

  fixed = gtk_fixed_new ();
  gtk_container_add (GTK_CONTAINER (window), fixed);

  gtk_widget_show (fixed);

  NSA_SET_PTR (env, obj, window);

  gdk_threads_leave ();
}
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkMenuPeer_create
  (JNIEnv *env, jobject obj, jstring label)
{
  GtkWidget *menu_title, *menu, *toplevel;
  const char *str;

  gdk_threads_enter ();
  
  NSA_SET_GLOBAL_REF (env, obj);

  str = (*env)->GetStringUTFChars (env, label, NULL);

  menu = gtk_menu_new ();
  
  if (str != NULL)
    menu_title = gtk_menu_item_new_with_label (str);
  else
    menu_title = gtk_menu_item_new();

  gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_title), menu);

  /* Allow this menu to grab the pointer. */
  toplevel = gtk_widget_get_toplevel (menu);
  if (GTK_IS_WINDOW (toplevel))
    {
      gtk_window_group_add_window (cp_gtk_global_window_group,
                                   GTK_WINDOW(toplevel));
    }

  gtk_widget_show (menu_title);

  NSA_SET_PTR (env, obj, menu_title);

  (*env)->ReleaseStringUTFChars (env, label, str);

  gdk_threads_leave ();
}
JNIEXPORT void JNICALL 
Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_create 
  (JNIEnv *env, jobject obj)
{
  gpointer widget;

  /* Create global reference and save it for future use */
  NSA_SET_GLOBAL_REF (env, obj);

  gdk_threads_enter ();
  
  widget = gtk_file_selection_new ("");
  /* GtkFileSelect is not modal by default */
  gtk_window_set_modal (GTK_WINDOW (widget), TRUE);

  /* We must add this window to the group so input in the others are
     disable while it is being shown */
  gtk_window_group_add_window (global_gtk_window_group, GTK_WINDOW (widget));

  gdk_threads_leave ();

  NSA_SET_PTR (env, obj, widget);
}
JNIEXPORT void JNICALL 
Java_gnu_java_awt_peer_gtk_GtkScrollbarPeer_create
(JNIEnv *env, jobject obj, jint orientation, jint value, 
 jint min, jint max, jint step_incr, jint page_incr, jint visible_amount)
{
  GtkWidget *sb;
  GtkObject *adj;

  /* Create global reference and save it for future use */
  NSA_SET_GLOBAL_REF (env, obj);

  gdk_threads_enter ();
  
  adj = gtk_adjustment_new (value, min, max, 
			    step_incr, page_incr, 
			    visible_amount);

  sb = (orientation) ? gtk_vscrollbar_new (GTK_ADJUSTMENT (adj)) :
                       gtk_hscrollbar_new (GTK_ADJUSTMENT (adj));

  gdk_threads_leave ();

  NSA_SET_PTR (env, obj, sb);
}