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_GtkCheckboxGroupPeer_remove (JNIEnv *env, jobject obj, jobject checkbox) { GtkRadioButton *button; void *ptr; GSList *list; gdk_threads_enter (); ptr = NSA_GET_PTR (env, checkbox); button = GTK_RADIO_BUTTON (ptr); /* Update the group to point to some other widget in the group. We have to do this because Gtk doesn't have a separate object to represent a radio button's group. */ for (list = gtk_radio_button_get_group (button); list != NULL; list = list->next) { if (list->data != button) break; } NSA_SET_PTR (env, obj, list ? list->data : NULL); gdk_threads_leave (); }
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_copyState (JNIEnv *env, jobject obj, jobject old) { struct graphics *g, *g_old; g = (struct graphics *) malloc (sizeof (struct graphics)); g_old = (struct graphics *) NSA_GET_PTR (env, old); *g = *g_old; gdk_threads_enter (); g->gc = gdk_gc_new (g->drawable); gdk_gc_copy (g->gc, g_old->gc); if (GDK_STABLE_IS_PIXMAP (g->drawable)) gdk_pixmap_ref (g->drawable); else /* GDK_IS_WINDOW (g->drawable) */ gdk_window_ref (g->drawable); gdk_colormap_ref (g->cm); gdk_threads_leave (); NSA_SET_PTR (env, obj, g); }
/* copy the native state of the peer (GtkWidget *) to the native state of the graphics object */ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_initState__Lgnu_java_awt_peer_gtk_GtkComponentPeer_2 (JNIEnv *env, jobject obj, jobject peer) { struct graphics *g = (struct graphics *) malloc (sizeof (struct graphics)); void *ptr; GtkWidget *widget; GdkColor color; ptr = NSA_GET_PTR (env, peer); g->x_offset = g->y_offset = 0; gdk_threads_enter (); widget = GTK_WIDGET (ptr); g->drawable = (GdkDrawable *) widget->window; gdk_window_ref (g->drawable); g->cm = gtk_widget_get_colormap (widget); gdk_colormap_ref (g->cm); g->gc = gdk_gc_new (g->drawable); gdk_gc_copy (g->gc, widget->style->fg_gc[GTK_STATE_NORMAL]); color = widget->style->fg[GTK_STATE_NORMAL]; gdk_threads_leave (); NSA_SET_PTR (env, obj, g); }
JNIEXPORT jintArray JNICALL Java_gnu_java_awt_peer_gtk_GdkFontMetrics_initState (JNIEnv *env, jobject obj, jstring fname, jint size) { jintArray array; jint *metrics; const char *cfname; char *xlfd; GdkFont *font; XFontStruct *xfont; cfname = (*env)->GetStringUTFChars (env, fname, NULL); xlfd = g_strdup_printf (cfname, (size * 10)); (*env)->ReleaseStringUTFChars (env, fname, cfname); array = (*env)->NewIntArray (env, NUM_METRICS); metrics = (*env)->GetIntArrayElements (env, array, NULL); gdk_threads_enter (); font = gdk_font_load (xlfd); xfont = GDK_FONT_XFONT (font); metrics[ASCENT] = font->ascent; metrics[MAX_ASCENT] = xfont->max_bounds.ascent; metrics[DESCENT] = font->descent; metrics[MAX_DESCENT] = xfont->max_bounds.descent; metrics[MAX_ADVANCE] = xfont->max_bounds.width; gdk_threads_leave (); g_free (xlfd); (*env)->ReleaseIntArrayElements (env, array, metrics, 0); NSA_SET_PTR (env, obj, font); return array; }
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_peer_gtk_GtkFileDialogPeer_create (JNIEnv *env, jobject obj) { gpointer widget; gdk_threads_enter (); widget = gtk_type_new (gtk_file_selection_get_type ()); gdk_threads_leave (); NSA_SET_PTR (env, obj, widget); }
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_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_GtkCheckboxMenuItemPeer_create (JNIEnv *env, jobject obj, jstring label) { GtkWidget *widget; const char *str; str = (*env)->GetStringUTFChars (env, label, NULL); gdk_threads_enter (); widget = gtk_check_menu_item_new_with_label (str); gtk_check_menu_item_set_show_toggle (GTK_CHECK_MENU_ITEM (widget), 1); gtk_widget_show (widget); gdk_threads_leave (); (*env)->ReleaseStringUTFChars (env, label, str); NSA_SET_PTR (env, obj, widget); }
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_initState__II (JNIEnv *env, jobject obj, jint width, jint height) { struct graphics *g; g = (struct graphics *) malloc (sizeof (struct graphics)); g->x_offset = g->y_offset = 0; gdk_threads_enter (); g->drawable = (GdkDrawable *) gdk_pixmap_new (NULL, width, height, gdk_rgb_get_visual ()->depth); g->cm = gdk_rgb_get_cmap (); gdk_colormap_ref (g->cm); g->gc = gdk_gc_new (g->drawable); gdk_threads_leave (); NSA_SET_PTR (env, obj, g); }
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_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_GtkWindowPeer_create (JNIEnv *env, jobject obj, jint type) { gpointer window; GtkWidget *vbox, *layout; gdk_threads_enter (); window = gtk_window_new (type); vbox = gtk_vbox_new (0, 0); layout = gtk_layout_new (NULL, NULL); gtk_box_pack_end (GTK_BOX (vbox), layout, 1, 1, 0); gtk_container_add (GTK_CONTAINER (window), vbox); gtk_widget_show (layout); gtk_widget_show (vbox); gdk_threads_leave (); NSA_SET_PTR (env, obj, window); }
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_GtkMenuItemPeer_create (JNIEnv *env, jobject obj, jstring label) { GtkWidget *widget; const char *str; str = (*env)->GetStringUTFChars (env, label, NULL); gdk_threads_enter (); if (strcmp (str, "-") == 0) /* "-" signals that we need a separator */ widget = gtk_menu_item_new (); else widget = gtk_menu_item_new_with_label (str); connect_activate_hook (env, obj, GTK_MENU_ITEM (widget)); gtk_widget_show (widget); gdk_threads_leave (); (*env)->ReleaseStringUTFChars (env, label, str); NSA_SET_PTR (env, obj, widget); }
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_nativeSetCheckboxGroup (JNIEnv *env, jobject obj, jobject group) { GtkRadioButton *button; void *native_group, *ptr; ptr = NSA_GET_PTR (env, obj); gdk_threads_enter (); /* FIXME: we can't yet switch between a checkbutton and a radiobutton. However, AWT requires this. For now we just crash. */ button = GTK_RADIO_BUTTON (ptr); native_group = NSA_GET_PTR (env, group); if (native_group == NULL) gtk_radio_button_set_group (button, NULL); else gtk_radio_button_set_group (button, gtk_radio_button_group (GTK_RADIO_BUTTON (native_group))); gdk_threads_leave (); /* If the native group wasn't set on the new CheckboxGroup, then set it now so that the right thing will happen with the next radiobutton. The native state for a CheckboxGroup is a pointer to one of the widgets in the group. We are careful to keep this always pointing at a live widget; whenever a widget is destroyed (or otherwise removed from the group), the CheckboxGroup peer is notified. */ if (native_group == NULL) NSA_SET_PTR (env, group, native_group); }
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); }