src/solaris/native/sun/awt/sun_awt_X11_GtkFileDialogPeer.c

Print this page


   1 /*
   2  * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 

  26 #include <jni.h>
  27 #include <stdio.h>
  28 #include <jni_util.h>
  29 #include <string.h>
  30 #include "gtk2_interface.h"
  31 #include "sun_awt_X11_GtkFileDialogPeer.h"
  32 #include "java_awt_FileDialog.h"
  33 #include "debug_assert.h"
  34 


  35 static JavaVM *jvm;
  36 
  37 /* To cache some method IDs */
  38 static jmethodID filenameFilterCallbackMethodID = NULL;
  39 static jmethodID setFileInternalMethodID = NULL;
  40 static jfieldID  widgetFieldID = NULL;
  41 
  42 JNIEXPORT void JNICALL Java_sun_awt_X11_GtkFileDialogPeer_initIDs
  43 (JNIEnv *env, jclass cx)
  44 {
  45     filenameFilterCallbackMethodID = (*env)->GetMethodID(env, cx,
  46             "filenameFilterCallback", "(Ljava/lang/String;)Z");
  47     DASSERT(filenameFilterCallbackMethodID != NULL);
  48 
  49     setFileInternalMethodID = (*env)->GetMethodID(env, cx,
  50             "setFileInternal", "(Ljava/lang/String;[Ljava/lang/String;)V");
  51     DASSERT(setFileInternalMethodID != NULL);
  52 
  53     widgetFieldID = (*env)->GetFieldID(env, cx, "widget", "J");
  54     DASSERT(widgetFieldID != NULL);


 271         jcurrent_folder = (*env)->NewStringUTF(env, "/");
 272         jfilenames = toPathAndFilenamesArray(env, filenames);
 273     } else {
 274         jcurrent_folder = (*env)->NewStringUTF(env, current_folder);
 275         jfilenames = toFilenamesArray(env, filenames);
 276     }
 277     (*env)->CallVoidMethod(env, obj, setFileInternalMethodID, jcurrent_folder,
 278             jfilenames);
 279     fp_g_free(current_folder);
 280 
 281     quit(env, (jobject)obj, TRUE);
 282 }
 283 
 284 /*
 285  * Class:     sun_awt_X11_GtkFileDialogPeer
 286  * Method:    run
 287  * Signature: (Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/io/FilenameFilter;ZII)V
 288  */
 289 JNIEXPORT void JNICALL
 290 Java_sun_awt_X11_GtkFileDialogPeer_run(JNIEnv * env, jobject jpeer,

 291         jstring jtitle, jint mode, jstring jdir, jstring jfile,
 292         jobject jfilter, jboolean multiple, int x, int y)
 293 {
 294     GtkWidget *dialog = NULL;
 295     GtkFileFilter *filter;
 296 
 297     if (jvm == NULL) {
 298         (*env)->GetJavaVM(env, &jvm);
 299     }
 300 
 301     fp_gdk_threads_enter();
 302 
 303     const char *title = jtitle == NULL? "": (*env)->GetStringUTFChars(env, jtitle, 0);
 304 
 305     if (mode == java_awt_FileDialog_SAVE) {
 306         /* Save action */
 307         dialog = fp_gtk_file_chooser_dialog_new(title, NULL,
 308                 GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL,
 309                 GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
 310     }


 352     }
 353 
 354     /* Other Properties */
 355     if (fp_gtk_check_version(2, 8, 0) == NULL) {
 356         fp_gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(
 357                 dialog), TRUE);
 358     }
 359 
 360     /* Set the initial location */
 361     if (x >= 0 && y >= 0) {
 362         fp_gtk_window_move((GtkWindow*)dialog, (gint)x, (gint)y);
 363 
 364         // NOTE: it doesn't set the initial size for the file chooser
 365         // as it seems like the file chooser overrides the size internally
 366     }
 367 
 368     fp_g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(
 369             handle_response), jpeer);
 370 
 371     (*env)->SetLongField(env, jpeer, widgetFieldID, ptr_to_jlong(dialog));





 372 
 373     fp_gtk_widget_show(dialog);
 374 
 375     fp_gtk_main();
 376     fp_gdk_threads_leave();
 377 }
 378 
   1 /*
   2  * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include <X11/Xlib.h>
  27 #include <jni.h>
  28 #include <stdio.h>
  29 #include <jni_util.h>
  30 #include <string.h>
  31 #include "gtk2_interface.h"
  32 #include "sun_awt_X11_GtkFileDialogPeer.h"
  33 #include "java_awt_FileDialog.h"
  34 #include "debug_assert.h"
  35 
  36 extern Display *awt_display;
  37 
  38 static JavaVM *jvm;
  39 
  40 /* To cache some method IDs */
  41 static jmethodID filenameFilterCallbackMethodID = NULL;
  42 static jmethodID setFileInternalMethodID = NULL;
  43 static jfieldID  widgetFieldID = NULL;
  44 
  45 JNIEXPORT void JNICALL Java_sun_awt_X11_GtkFileDialogPeer_initIDs
  46 (JNIEnv *env, jclass cx)
  47 {
  48     filenameFilterCallbackMethodID = (*env)->GetMethodID(env, cx,
  49             "filenameFilterCallback", "(Ljava/lang/String;)Z");
  50     DASSERT(filenameFilterCallbackMethodID != NULL);
  51 
  52     setFileInternalMethodID = (*env)->GetMethodID(env, cx,
  53             "setFileInternal", "(Ljava/lang/String;[Ljava/lang/String;)V");
  54     DASSERT(setFileInternalMethodID != NULL);
  55 
  56     widgetFieldID = (*env)->GetFieldID(env, cx, "widget", "J");
  57     DASSERT(widgetFieldID != NULL);


 274         jcurrent_folder = (*env)->NewStringUTF(env, "/");
 275         jfilenames = toPathAndFilenamesArray(env, filenames);
 276     } else {
 277         jcurrent_folder = (*env)->NewStringUTF(env, current_folder);
 278         jfilenames = toFilenamesArray(env, filenames);
 279     }
 280     (*env)->CallVoidMethod(env, obj, setFileInternalMethodID, jcurrent_folder,
 281             jfilenames);
 282     fp_g_free(current_folder);
 283 
 284     quit(env, (jobject)obj, TRUE);
 285 }
 286 
 287 /*
 288  * Class:     sun_awt_X11_GtkFileDialogPeer
 289  * Method:    run
 290  * Signature: (Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/io/FilenameFilter;ZII)V
 291  */
 292 JNIEXPORT void JNICALL
 293 Java_sun_awt_X11_GtkFileDialogPeer_run(JNIEnv * env, jobject jpeer,
 294         jlong owner,
 295         jstring jtitle, jint mode, jstring jdir, jstring jfile,
 296         jobject jfilter, jboolean multiple, int x, int y)
 297 {
 298     GtkWidget *dialog = NULL;
 299     GtkFileFilter *filter;
 300 
 301     if (jvm == NULL) {
 302         (*env)->GetJavaVM(env, &jvm);
 303     }
 304 
 305     fp_gdk_threads_enter();
 306 
 307     const char *title = jtitle == NULL? "": (*env)->GetStringUTFChars(env, jtitle, 0);
 308 
 309     if (mode == java_awt_FileDialog_SAVE) {
 310         /* Save action */
 311         dialog = fp_gtk_file_chooser_dialog_new(title, NULL,
 312                 GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL,
 313                 GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
 314     }


 356     }
 357 
 358     /* Other Properties */
 359     if (fp_gtk_check_version(2, 8, 0) == NULL) {
 360         fp_gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(
 361                 dialog), TRUE);
 362     }
 363 
 364     /* Set the initial location */
 365     if (x >= 0 && y >= 0) {
 366         fp_gtk_window_move((GtkWindow*)dialog, (gint)x, (gint)y);
 367 
 368         // NOTE: it doesn't set the initial size for the file chooser
 369         // as it seems like the file chooser overrides the size internally
 370     }
 371 
 372     fp_g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(
 373             handle_response), jpeer);
 374 
 375     (*env)->SetLongField(env, jpeer, widgetFieldID, ptr_to_jlong(dialog));
 376 
 377     if (owner && dialog) {
 378         fp_gtk_widget_realize(dialog);
 379         XSetTransientForHint(awt_display, fp_gdk_x11_drawable_get_xid(dialog->window), owner);
 380     }
 381 
 382     fp_gtk_widget_show(dialog);
 383 
 384     fp_gtk_main();
 385     fp_gdk_threads_leave();
 386 }
 387