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 CHECK_NULL(filenameFilterCallbackMethodID); 49 50 setFileInternalMethodID = (*env)->GetMethodID(env, cx, 51 "setFileInternal", "(Ljava/lang/String;[Ljava/lang/String;)V"); 52 DASSERT(setFileInternalMethodID != NULL); 53 CHECK_NULL(setFileInternalMethodID); 54 55 widgetFieldID = (*env)->GetFieldID(env, cx, "widget", "J"); 56 DASSERT(widgetFieldID != NULL); 57 } 58 59 static gboolean filenameFilterCallback(const GtkFileFilterInfo * filter_info, gpointer obj) 60 { 61 JNIEnv *env; 62 jstring filename; 63 64 env = (JNIEnv *) JNU_GetEnv(jvm, JNI_VERSION_1_2); 65 66 filename = (*env)->NewStringUTF(env, filter_info->filename); 67 JNU_CHECK_EXCEPTION_RETURN(env, FALSE); 68 69 return (*env)->CallBooleanMethod(env, obj, filenameFilterCallbackMethodID, 70 filename); 71 } 72 73 static void quit(JNIEnv * env, jobject jpeer, gboolean isSignalHandler) 74 { 75 jthrowable pendingException; 76 if (pendingException = (*env)->ExceptionOccurred(env)) { 384 if (fp_gtk_check_version(2, 8, 0) == NULL) { 385 fp_gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER( 386 dialog), TRUE); 387 } 388 389 /* Set the initial location */ 390 if (x >= 0 && y >= 0) { 391 fp_gtk_window_move((GtkWindow*)dialog, (gint)x, (gint)y); 392 393 // NOTE: it doesn't set the initial size for the file chooser 394 // as it seems like the file chooser overrides the size internally 395 } 396 397 fp_g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK( 398 handle_response), jpeer); 399 400 (*env)->SetLongField(env, jpeer, widgetFieldID, ptr_to_jlong(dialog)); 401 402 fp_gtk_widget_show(dialog); 403 404 fp_gtk_main(); 405 fp_gdk_threads_leave(); 406 } 407 | 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 <X11/X.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 static JavaVM *jvm; 37 38 /* To cache some method IDs */ 39 static jmethodID filenameFilterCallbackMethodID = NULL; 40 static jmethodID setFileInternalMethodID = NULL; 41 static jfieldID widgetFieldID = NULL; 42 static jmethodID setWindowMethodID = NULL; 43 44 JNIEXPORT void JNICALL Java_sun_awt_X11_GtkFileDialogPeer_initIDs 45 (JNIEnv *env, jclass cx) 46 { 47 filenameFilterCallbackMethodID = (*env)->GetMethodID(env, cx, 48 "filenameFilterCallback", "(Ljava/lang/String;)Z"); 49 DASSERT(filenameFilterCallbackMethodID != NULL); 50 CHECK_NULL(filenameFilterCallbackMethodID); 51 52 setFileInternalMethodID = (*env)->GetMethodID(env, cx, 53 "setFileInternal", "(Ljava/lang/String;[Ljava/lang/String;)V"); 54 DASSERT(setFileInternalMethodID != NULL); 55 CHECK_NULL(setFileInternalMethodID); 56 57 widgetFieldID = (*env)->GetFieldID(env, cx, "widget", "J"); 58 DASSERT(widgetFieldID != NULL); 59 60 setWindowMethodID = (*env)->GetMethodID(env, cx, "setWindow", "(J)Z"); 61 DASSERT(setWindowMethodID != NULL); 62 CHECK_NULL(setWindowMethodID); 63 } 64 65 static gboolean filenameFilterCallback(const GtkFileFilterInfo * filter_info, gpointer obj) 66 { 67 JNIEnv *env; 68 jstring filename; 69 70 env = (JNIEnv *) JNU_GetEnv(jvm, JNI_VERSION_1_2); 71 72 filename = (*env)->NewStringUTF(env, filter_info->filename); 73 JNU_CHECK_EXCEPTION_RETURN(env, FALSE); 74 75 return (*env)->CallBooleanMethod(env, obj, filenameFilterCallbackMethodID, 76 filename); 77 } 78 79 static void quit(JNIEnv * env, jobject jpeer, gboolean isSignalHandler) 80 { 81 jthrowable pendingException; 82 if (pendingException = (*env)->ExceptionOccurred(env)) { 390 if (fp_gtk_check_version(2, 8, 0) == NULL) { 391 fp_gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER( 392 dialog), TRUE); 393 } 394 395 /* Set the initial location */ 396 if (x >= 0 && y >= 0) { 397 fp_gtk_window_move((GtkWindow*)dialog, (gint)x, (gint)y); 398 399 // NOTE: it doesn't set the initial size for the file chooser 400 // as it seems like the file chooser overrides the size internally 401 } 402 403 fp_g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK( 404 handle_response), jpeer); 405 406 (*env)->SetLongField(env, jpeer, widgetFieldID, ptr_to_jlong(dialog)); 407 408 fp_gtk_widget_show(dialog); 409 410 XID xid = fp_gdk_x11_drawable_get_xid(dialog->window); 411 if( (*env)->CallBooleanMethod(env, jpeer, setWindowMethodID, xid) ) { 412 fp_gtk_main(); 413 } 414 415 fp_gdk_threads_leave(); 416 } 417 |