< prev index next >

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

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 25,39 **** #include <jni.h> #include <stdio.h> #include <jni_util.h> #include <string.h> ! #include "gtk2_interface.h" #include "sun_awt_X11_GtkFileDialogPeer.h" #include "java_awt_FileDialog.h" #include "debug_assert.h" static JavaVM *jvm; /* To cache some method IDs */ static jmethodID filenameFilterCallbackMethodID = NULL; static jmethodID setFileInternalMethodID = NULL; --- 25,40 ---- #include <jni.h> #include <stdio.h> #include <jni_util.h> #include <string.h> ! #include "gtk_interface.h" #include "sun_awt_X11_GtkFileDialogPeer.h" #include "java_awt_FileDialog.h" #include "debug_assert.h" + typedef void GtkWidget; static JavaVM *jvm; /* To cache some method IDs */ static jmethodID filenameFilterCallbackMethodID = NULL; static jmethodID setFileInternalMethodID = NULL;
*** 82,105 **** if (dialog != NULL) { // Callbacks from GTK signals are made within the GTK lock // So, within a signal handler there is no need to call ! // gdk_threads_enter() / fp_gdk_threads_leave() if (!isSignalHandler) { ! fp_gdk_threads_enter(); } ! fp_gtk_widget_hide (dialog); ! fp_gtk_widget_destroy (dialog); ! fp_gtk_main_quit (); (*env)->SetLongField(env, jpeer, widgetFieldID, 0); if (!isSignalHandler) { ! fp_gdk_threads_leave(); } } if (pendingException) { (*env)->Throw(env, pendingException); --- 83,106 ---- if (dialog != NULL) { // Callbacks from GTK signals are made within the GTK lock // So, within a signal handler there is no need to call ! // gdk_threads_enter() / gtk->gdk_threads_leave() if (!isSignalHandler) { ! gtk->gdk_threads_enter(); } ! gtk->gtk_widget_hide (dialog); ! gtk->gtk_widget_destroy (dialog); ! gtk->gtk_main_quit (); (*env)->SetLongField(env, jpeer, widgetFieldID, 0); if (!isSignalHandler) { ! gtk->gdk_threads_leave(); } } if (pendingException) { (*env)->Throw(env, pendingException);
*** 125,144 **** JNIEXPORT void JNICALL Java_sun_awt_X11_GtkFileDialogPeer_toFront (JNIEnv * env, jobject jpeer) { GtkWidget * dialog; ! fp_gdk_threads_enter(); dialog = (GtkWidget*)jlong_to_ptr( (*env)->GetLongField(env, jpeer, widgetFieldID)); if (dialog != NULL) { ! fp_gtk_window_present((GtkWindow*)dialog); } ! fp_gdk_threads_leave(); } /* * Class: sun_awt_X11_GtkFileDialogPeer * Method: setBounds --- 126,145 ---- JNIEXPORT void JNICALL Java_sun_awt_X11_GtkFileDialogPeer_toFront (JNIEnv * env, jobject jpeer) { GtkWidget * dialog; ! gtk->gdk_threads_enter(); dialog = (GtkWidget*)jlong_to_ptr( (*env)->GetLongField(env, jpeer, widgetFieldID)); if (dialog != NULL) { ! gtk->gtk_window_present((GtkWindow*)dialog); } ! gtk->gdk_threads_leave(); } /* * Class: sun_awt_X11_GtkFileDialogPeer * Method: setBounds
*** 147,171 **** JNIEXPORT void JNICALL Java_sun_awt_X11_GtkFileDialogPeer_setBounds (JNIEnv * env, jobject jpeer, jint x, jint y, jint width, jint height, jint op) { GtkWindow* dialog; ! fp_gdk_threads_enter(); dialog = (GtkWindow*)jlong_to_ptr( (*env)->GetLongField(env, jpeer, widgetFieldID)); if (dialog != NULL) { if (x >= 0 && y >= 0) { ! fp_gtk_window_move(dialog, (gint)x, (gint)y); } if (width > 0 && height > 0) { ! fp_gtk_window_resize(dialog, (gint)width, (gint)height); } } ! fp_gdk_threads_leave(); } /* * baseDir should be freed by user. */ --- 148,172 ---- JNIEXPORT void JNICALL Java_sun_awt_X11_GtkFileDialogPeer_setBounds (JNIEnv * env, jobject jpeer, jint x, jint y, jint width, jint height, jint op) { GtkWindow* dialog; ! gtk->gdk_threads_enter(); dialog = (GtkWindow*)jlong_to_ptr( (*env)->GetLongField(env, jpeer, widgetFieldID)); if (dialog != NULL) { if (x >= 0 && y >= 0) { ! gtk->gtk_window_move(dialog, (gint)x, (gint)y); } if (width > 0 && height > 0) { ! gtk->gtk_window_resize(dialog, (gint)width, (gint)height); } } ! gtk->gdk_threads_leave(); } /* * baseDir should be freed by user. */
*** 174,195 **** GSList *it = list; gchar* prevDir = NULL; gboolean isAllDirsSame = TRUE; while (it) { ! gchar* dir = fp_g_path_get_dirname((gchar*) it->data); if (prevDir && strcmp(prevDir, dir) != 0) { isAllDirsSame = FALSE; ! fp_g_free(dir); break; } if (!prevDir) { prevDir = strdup(dir); } ! fp_g_free(dir); it = it->next; } if (isAllDirsSame) { --- 175,196 ---- GSList *it = list; gchar* prevDir = NULL; gboolean isAllDirsSame = TRUE; while (it) { ! gchar* dir = gtk->g_path_get_dirname((gchar*) it->data); if (prevDir && strcmp(prevDir, dir) != 0) { isAllDirsSame = FALSE; ! gtk->g_free(dir); break; } if (!prevDir) { prevDir = strdup(dir); } ! gtk->g_free(dir); it = it->next; } if (isAllDirsSame) {
*** 225,235 **** (*env)->ExceptionClear(env); JNU_ThrowInternalError(env, "Could not get java.lang.String class"); return NULL; } ! array = (*env)->NewObjectArray(env, fp_gtk_g_slist_length(list), stringCls, NULL); if (array == NULL) { (*env)->ExceptionClear(env); JNU_ThrowInternalError(env, "Could not instantiate array files array"); return NULL; } --- 226,236 ---- (*env)->ExceptionClear(env); JNU_ThrowInternalError(env, "Could not get java.lang.String class"); return NULL; } ! array = (*env)->NewObjectArray(env, gtk->gtk_g_slist_length(list), stringCls, NULL); if (array == NULL) { (*env)->ExceptionClear(env); JNU_ThrowInternalError(env, "Could not instantiate array files array"); return NULL; }
*** 279,289 **** env = (JNIEnv *) JNU_GetEnv(jvm, JNI_VERSION_1_2); filenames = NULL; if (responseId == GTK_RESPONSE_ACCEPT) { ! filenames = fp_gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(aDialog)); } jfilenames = toFilenamesArray(env, filenames, &jcurrent_folder); if (!(*env)->ExceptionCheck(env)) { --- 280,290 ---- env = (JNIEnv *) JNU_GetEnv(jvm, JNI_VERSION_1_2); filenames = NULL; if (responseId == GTK_RESPONSE_ACCEPT) { ! filenames = gtk->gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(aDialog)); } jfilenames = toFilenamesArray(env, filenames, &jcurrent_folder); if (!(*env)->ExceptionCheck(env)) {
*** 310,343 **** if (jvm == NULL) { (*env)->GetJavaVM(env, &jvm); JNU_CHECK_EXCEPTION(env); } ! fp_gdk_threads_enter(); const char *title = jtitle == NULL? "": (*env)->GetStringUTFChars(env, jtitle, 0); if (title == NULL) { (*env)->ExceptionClear(env); JNU_ThrowOutOfMemoryError(env, "Could not get title"); return; } if (mode == java_awt_FileDialog_SAVE) { /* Save action */ ! dialog = fp_gtk_file_chooser_dialog_new(title, NULL, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); } else { /* Default action OPEN */ ! dialog = fp_gtk_file_chooser_dialog_new(title, NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); /* Set multiple selection mode, that is allowed only in OPEN action */ if (multiple) { ! fp_gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), multiple); } } if (jtitle != NULL) { --- 311,344 ---- if (jvm == NULL) { (*env)->GetJavaVM(env, &jvm); JNU_CHECK_EXCEPTION(env); } ! gtk->gdk_threads_enter(); const char *title = jtitle == NULL? "": (*env)->GetStringUTFChars(env, jtitle, 0); if (title == NULL) { (*env)->ExceptionClear(env); JNU_ThrowOutOfMemoryError(env, "Could not get title"); return; } if (mode == java_awt_FileDialog_SAVE) { /* Save action */ ! dialog = gtk->gtk_file_chooser_dialog_new(title, NULL, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); } else { /* Default action OPEN */ ! dialog = gtk->gtk_file_chooser_dialog_new(title, NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); /* Set multiple selection mode, that is allowed only in OPEN action */ if (multiple) { ! gtk->gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), multiple); } } if (jtitle != NULL) {
*** 350,360 **** if (dir == NULL) { (*env)->ExceptionClear(env); JNU_ThrowOutOfMemoryError(env, "Could not get dir"); return; } ! fp_gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), dir); (*env)->ReleaseStringUTFChars(env, jdir, dir); } /* Set the filename */ if (jfile != NULL) { --- 351,361 ---- if (dir == NULL) { (*env)->ExceptionClear(env); JNU_ThrowOutOfMemoryError(env, "Could not get dir"); return; } ! gtk->gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), dir); (*env)->ReleaseStringUTFChars(env, jdir, dir); } /* Set the filename */ if (jfile != NULL) {
*** 363,407 **** (*env)->ExceptionClear(env); JNU_ThrowOutOfMemoryError(env, "Could not get filename"); return; } if (mode == java_awt_FileDialog_SAVE) { ! fp_gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename); } else { ! fp_gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), filename); } (*env)->ReleaseStringUTFChars(env, jfile, filename); } /* Set the file filter */ if (jfilter != NULL) { ! filter = fp_gtk_file_filter_new(); ! fp_gtk_file_filter_add_custom(filter, GTK_FILE_FILTER_FILENAME, filenameFilterCallback, jpeer, NULL); ! fp_gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter); } /* Other Properties */ ! if (fp_gtk_check_version(2, 8, 0) == NULL) { ! fp_gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER( dialog), TRUE); } /* Set the initial location */ if (x >= 0 && y >= 0) { ! fp_gtk_window_move((GtkWindow*)dialog, (gint)x, (gint)y); // NOTE: it doesn't set the initial size for the file chooser // as it seems like the file chooser overrides the size internally } ! fp_g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK( ! handle_response), jpeer); (*env)->SetLongField(env, jpeer, widgetFieldID, ptr_to_jlong(dialog)); ! fp_gtk_widget_show(dialog); ! fp_gtk_main(); ! fp_gdk_threads_leave(); } --- 364,409 ---- (*env)->ExceptionClear(env); JNU_ThrowOutOfMemoryError(env, "Could not get filename"); return; } if (mode == java_awt_FileDialog_SAVE) { ! gtk->gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename); } else { ! gtk->gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), filename); } (*env)->ReleaseStringUTFChars(env, jfile, filename); } /* Set the file filter */ if (jfilter != NULL) { ! filter = gtk->gtk_file_filter_new(); ! gtk->gtk_file_filter_add_custom(filter, GTK_FILE_FILTER_FILENAME, filenameFilterCallback, jpeer, NULL); ! gtk->gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter); } /* Other Properties */ ! if (gtk->gtk_check_version(2, 8, 0) == NULL || ! gtk->gtk_check_version(3, 0, 0) == NULL) { ! gtk->gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER( dialog), TRUE); } /* Set the initial location */ if (x >= 0 && y >= 0) { ! gtk->gtk_window_move((GtkWindow*)dialog, (gint)x, (gint)y); // NOTE: it doesn't set the initial size for the file chooser // as it seems like the file chooser overrides the size internally } ! gtk->g_signal_connect_data(dialog, "response", G_CALLBACK( ! handle_response), jpeer, 0, 0); (*env)->SetLongField(env, jpeer, widgetFieldID, ptr_to_jlong(dialog)); ! gtk->gtk_widget_show(dialog); ! gtk->gtk_main(); ! gtk->gdk_threads_leave(); }
< prev index next >