diff options
author | fnasser <fnasser@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-01-08 21:12:25 +0000 |
---|---|---|
committer | fnasser <fnasser@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-01-08 21:12:25 +0000 |
commit | 204a2e9c5b6424fcb314dee3fc431be07db88061 (patch) | |
tree | 240ed2d35f3bb8323d793e3af65083d1f6585530 /libjava/jni | |
parent | 3e02af1ad5f8b50982749f588582d8843b7841b7 (diff) | |
download | gcc-204a2e9c5b6424fcb314dee3fc431be07db88061.tar.gz |
* gnu/java/awt/peer/gtk/GtkFileDialogPeer.java (nativeSetFile):
New name for the former setFile native method.
(setFile): New method.
(setDirectory): Implemented.
(connectSignals): New native method.
(setFilenameFilter): Improve comment.
(getGraphics): Comment.
(gtkHideFileDialog): New method.
(gtkDisposeFileDialog): New method.
(gtkSetFilename): New method.
* java/awt/Dialog.java (show): Block on modal dialogs, but only
for FileDialog for now.
(hide): New method.
(dispose): New method.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c
(Java_gnu_java_awt_peer_gtk_GtkFileDialog_create): Replace
deprecated creation functions. Make dialog modal. Add it to the
window group.
(Java_gnu_java_awt_peer_gtk_GtkFileDialog_connectSignals): New
function.
(Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_gtkFileSelectionSetFilename):
Rename to...
(Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeSetFile): New
name.
(window_closed): New function.
(ok_clicked): New function.
(cancel_clicked): New function.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@75557 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/jni')
-rw-r--r-- | libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c | 156 |
1 files changed, 153 insertions, 3 deletions
diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c index 47a08ae8eed..9e84dde1b6e 100644 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c +++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c @@ -37,8 +37,17 @@ exception statement from your version. */ #include "gtkpeer.h" +#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" #include "gnu_java_awt_peer_gtk_GtkFileDialogPeer.h" +static void window_closed (GtkDialog *dialog, + gint responseId, + jobject peer_obj); +static void ok_clicked (GtkButton *button, + jobject peer_obj); +static void cancel_clicked (GtkButton *button, + jobject peer_obj); + /* * Make a new file selection dialog */ @@ -54,7 +63,13 @@ Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_create gdk_threads_enter (); - widget = gtk_type_new (gtk_file_selection_get_type ()); + 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 (); @@ -76,12 +91,44 @@ Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_connectJObject gdk_threads_leave (); } +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_connectSignals + (JNIEnv *env, jobject obj) +{ + void *ptr = NSA_GET_PTR (env, obj); + jobject *gref = NSA_GET_GLOBAL_REF (env, obj); + g_assert (gref); + + gdk_threads_enter (); + + gtk_widget_realize (GTK_WIDGET (ptr)); + + /* connect buttons to handlers */ + + g_signal_connect (G_OBJECT (GTK_DIALOG (ptr)), + "response", + GTK_SIGNAL_FUNC (window_closed), *gref); + + g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (ptr)->ok_button), + "clicked", + GTK_SIGNAL_FUNC (ok_clicked), *gref); + + g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (ptr)->cancel_button), + "clicked", + GTK_SIGNAL_FUNC (cancel_clicked), *gref); + + gdk_threads_leave (); + + /* Connect the superclass signals. */ + Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals (env, obj); +} + /* * Set the filename in the file selection dialog. */ JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_gtkFileSelectionSetFilename +Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeSetFile (JNIEnv *env, jobject obj, jstring filename) { void *ptr; @@ -89,9 +136,112 @@ Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_gtkFileSelectionSetFilename ptr = NSA_GET_PTR (env, obj); - str = (*env)->GetStringUTFChars (env, filename, 0); + str = (*env)->GetStringUTFChars (env, filename, 0); + gdk_threads_enter (); + gtk_file_selection_set_filename (GTK_FILE_SELECTION (ptr), str); + gdk_threads_leave (); + (*env)->ReleaseStringUTFChars (env, filename, str); } + +static void +window_closed (GtkDialog *dialog __attribute__((unused)), + gint responseId, + jobject peer_obj) +{ + static int isIDSet = 0; + static jmethodID disposeID; + void *ptr; + + // We only need this for the case when the user closed the window + if (responseId != GTK_RESPONSE_DELETE_EVENT) + return; + + ptr = NSA_GET_PTR (gdk_env, peer_obj); + + if (!isIDSet) + { + jclass cx = (*gdk_env)->GetObjectClass (gdk_env, peer_obj); + disposeID = (*gdk_env)->GetMethodID (gdk_env, cx, "gtkDisposeFileDialog", "()V"); + isIDSet = 1; + } + + gdk_threads_leave (); + + /* We can dispose of the dialog now (and unblock show) */ + (*gdk_env)->CallVoidMethod (gdk_env, peer_obj, disposeID); + + gdk_threads_enter (); +} + +static void +ok_clicked (GtkButton *button __attribute__((unused)), + jobject peer_obj) +{ + static int isIDSet = 0; + static jmethodID gtkSetFilenameID; + static jmethodID hideID; + void *ptr; + G_CONST_RETURN gchar *fileName; + + ptr = NSA_GET_PTR (gdk_env, peer_obj); + + fileName = gtk_file_selection_get_filename ( + GTK_FILE_SELECTION (GTK_WIDGET (ptr))); + + if (!isIDSet) + { + jclass cx = (*gdk_env)->GetObjectClass (gdk_env, peer_obj); + hideID = (*gdk_env)->GetMethodID (gdk_env, cx, "gtkHideFileDialog", "()V"); + gtkSetFilenameID = (*gdk_env)->GetMethodID (gdk_env, cx, + "gtkSetFilename", "(Ljava.lang.String;)V"); + isIDSet = 1; + } + + gdk_threads_leave (); + + /* Set the Java object field 'file' with this value. */ + jstring str_fileName = (*gdk_env)->NewStringUTF (gdk_env, fileName); + (*gdk_env)->CallVoidMethod (gdk_env, peer_obj, gtkSetFilenameID, str_fileName); + + /* We can hide the dialog now (and unblock show) */ + (*gdk_env)->CallVoidMethod (gdk_env, peer_obj, hideID); + + gdk_threads_enter (); +} + +static void +cancel_clicked (GtkButton *button __attribute__((unused)), + jobject peer_obj) +{ + static int isIDSet = 0; + static jmethodID gtkSetFilenameID; + static jmethodID hideID; + void *ptr; + + ptr = NSA_GET_PTR (gdk_env, peer_obj); + + if (!isIDSet) + { + jclass cx = (*gdk_env)->GetObjectClass (gdk_env, peer_obj); + hideID = (*gdk_env)->GetMethodID (gdk_env, cx, "gtkHideFileDialog", "()V"); + gtkSetFilenameID = (*gdk_env)->GetMethodID (gdk_env, cx, + "gtkSetFilename", "(Ljava.lang.String;)V"); + isIDSet = 1; + } + + gdk_threads_leave (); + + /* Set the Java object field 'file' with the null value. */ + (*gdk_env)->CallVoidMethod (gdk_env, peer_obj, gtkSetFilenameID, NULL); + + /* We can hide the dialog now (and unblock show) */ + (*gdk_env)->CallVoidMethod (gdk_env, peer_obj, hideID); + + gdk_threads_enter (); +} + + |