OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [native/] [jni/] [gtk-peer/] [gnu_java_awt_peer_gtk_GtkFileDialogPeer.c] - Blame information for rev 774

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
/* gtkfiledialogpeer.c -- Native implementation of GtkFileDialogPeer
2
   Copyright (C) 1998, 1999, 2002, 2004 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
 
39
#include "gtkpeer.h"
40
#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h"
41
#include "gnu_java_awt_peer_gtk_GtkFileDialogPeer.h"
42
 
43
#define AWT_FILEDIALOG_LOAD 0
44
#define AWT_FILEDIALOG_SAVE 1
45
 
46
static void handle_response_cb (GtkDialog *dialog,
47
                                gint responseId,
48
                                jobject peer_obj);
49
 
50
static jmethodID gtkSetFilenameID;
51
static jmethodID gtkHideFileDialogID;
52
static jmethodID gtkDisposeFileDialogID;
53
static jmethodID filenameFilterCallbackID;
54
 
55
void
56
cp_gtk_filedialog_init_jni (void)
57
{
58
  jclass gtkfiledialogpeer;
59
 
60
  gtkfiledialogpeer =
61
    (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(),
62
                                    "gnu/java/awt/peer/gtk/GtkFileDialogPeer");
63
 
64
  gtkDisposeFileDialogID =
65
    (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
66
                                      gtkfiledialogpeer,
67
                                      "gtkDisposeFileDialog", "()V");
68
 
69
  gtkHideFileDialogID =
70
    (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
71
                                      gtkfiledialogpeer,
72
                                      "gtkHideFileDialog", "()V");
73
 
74
  gtkSetFilenameID =
75
    (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
76
                                      gtkfiledialogpeer,
77
                                      "gtkSetFilename",
78
                                      "(Ljava/lang/String;)V");
79
 
80
  filenameFilterCallbackID =
81
    (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
82
                                      gtkfiledialogpeer,
83
                                      "filenameFilterCallback",
84
                                      "(Ljava/lang/String;)Z");
85
}
86
 
87
/*
88
 * Make a new file selection dialog
89
 */
90
 
91
JNIEXPORT void JNICALL
92
Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_create
93
  (JNIEnv *env, jobject obj, jobject parent, jint mode)
94
{
95
  void *parentp;
96
  gpointer widget;
97
 
98
  gdk_threads_enter ();
99
 
100
  /* Create global reference and save it for future use */
101
  gtkpeer_set_global_ref (env, obj);
102
 
103
  parentp = gtkpeer_get_widget(env, parent);
104
 
105
  if (mode == AWT_FILEDIALOG_LOAD)
106
    widget = gtk_file_chooser_dialog_new
107
      ("Open File",
108
       GTK_WINDOW(parentp),
109
       GTK_FILE_CHOOSER_ACTION_OPEN,
110
       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
111
       GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
112
       NULL);
113
  else
114
    {
115
      widget = gtk_file_chooser_dialog_new
116
        ("Save File",
117
         GTK_WINDOW(parentp),
118
         GTK_FILE_CHOOSER_ACTION_SAVE,
119
         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
120
         GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
121
         NULL);
122
#if GTK_MINOR_VERSION >= 8
123
      gtk_file_chooser_set_do_overwrite_confirmation
124
        (GTK_FILE_CHOOSER (widget), TRUE);
125
#endif
126
    }
127
 
128
 
129
  /* GtkFileChooserDialog is not modal by default */
130
  gtk_window_set_modal (GTK_WINDOW (widget), TRUE);
131
 
132
  /* We must add this window to the group so input in the others are
133
     disable while it is being shown */
134
  gtk_window_group_add_window (cp_gtk_global_window_group,
135
                               GTK_WINDOW (widget));
136
 
137
  gtkpeer_set_widget (env, obj, widget);
138
 
139
  gdk_threads_leave ();
140
}
141
 
142
JNIEXPORT void JNICALL
143
Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_connectSignals
144
  (JNIEnv *env, jobject obj)
145
{
146
  void *ptr = NULL;
147
  jobject gref;
148
 
149
  gdk_threads_enter ();
150
 
151
  ptr = gtkpeer_get_widget (env, obj);
152
  gref = gtkpeer_get_global_ref (env, obj);
153
 
154
  /* FileDialog signals */
155
  g_signal_connect (G_OBJECT (ptr), "response",
156
                    G_CALLBACK (handle_response_cb), gref);
157
 
158
  /* Component signals */
159
  cp_gtk_component_connect_signals (G_OBJECT (ptr), gref);
160
 
161
  gdk_threads_leave ();
162
}
163
 
164
JNIEXPORT jstring JNICALL
165
Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeGetDirectory
166
    (JNIEnv *env, jobject obj)
167
{
168
  void *ptr;
169
  const char *str;
170
 
171
  gdk_threads_enter ();
172
 
173
  ptr = gtkpeer_get_widget (env, obj);
174
 
175
  str = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER(ptr));
176
 
177
  gdk_threads_leave ();
178
 
179
  return (*env)->NewStringUTF(env, str);
180
}
181
 
182
 
183
/* This function interfaces with the Java callback method of the same name.
184
   This function extracts the filename from the GtkFileFilterInfo object,
185
   and passes it to the Java method.  The Java method will call the filter's
186
   accept() method and will give back the return value. */
187
static gboolean filename_filter_cb (const GtkFileFilterInfo *filter_info,
188
                                        gpointer obj)
189
{
190
  jstring *filename;
191
  gboolean accepted;
192
 
193
  filename = (*cp_gtk_gdk_env())->NewStringUTF(cp_gtk_gdk_env(), filter_info->filename);
194
 
195
  accepted = (*cp_gtk_gdk_env())->CallBooleanMethod(cp_gtk_gdk_env(), obj,
196
                                                    filenameFilterCallbackID,
197
                                                    filename);
198
 
199
  return accepted;
200
}
201
 
202
JNIEXPORT void JNICALL
203
Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeSetFilenameFilter
204
    (JNIEnv *env, jobject obj, jobject filter_obj __attribute__((unused)))
205
{
206
  void *ptr;
207
  GtkFileFilter *filter;
208
 
209
  gdk_threads_enter ();
210
 
211
  ptr = gtkpeer_get_widget (env, obj);
212
 
213
  filter = gtk_file_filter_new();
214
  gtk_file_filter_add_custom(filter, GTK_FILE_FILTER_FILENAME,
215
                             filename_filter_cb, obj, NULL);
216
 
217
  gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(ptr), filter);
218
 
219
  gdk_threads_leave ();
220
}
221
 
222
JNIEXPORT void JNICALL
223
Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeSetDirectory
224
    (JNIEnv *env, jobject obj, jstring directory)
225
{
226
  void *ptr;
227
  const char *str;
228
 
229
  gdk_threads_enter ();
230
 
231
  ptr = gtkpeer_get_widget (env, obj);
232
 
233
  str = (*env)->GetStringUTFChars (env, directory, 0);
234
 
235
  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(ptr), str);
236
 
237
  (*env)->ReleaseStringUTFChars (env, directory, str);
238
 
239
  gdk_threads_leave ();
240
}
241
 
242
JNIEXPORT void JNICALL
243
Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeSetFile
244
    (JNIEnv *env, jobject obj, jstring filename)
245
{
246
  void *ptr;
247
  const char *str;
248
 
249
  gdk_threads_enter ();
250
 
251
  ptr = gtkpeer_get_widget (env, obj);
252
 
253
  str = (*env)->GetStringUTFChars (env, filename, 0);
254
 
255
  gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (ptr), str);
256
 
257
  (*env)->ReleaseStringUTFChars (env, filename, str);
258
 
259
  gdk_threads_leave ();
260
}
261
 
262
static void
263
handle_response_cb (GtkDialog *dialog __attribute__((unused)),
264
                    gint responseId,
265
                    jobject peer_obj)
266
{
267
  void *ptr;
268
  G_CONST_RETURN gchar *fileName;
269
  jstring str_fileName = NULL;
270
 
271
  /* We only need this for the case when the user closed the window,
272
     or clicked ok or cancel. */
273
  if (responseId != GTK_RESPONSE_DELETE_EVENT
274
      && responseId != GTK_RESPONSE_ACCEPT
275
      && responseId != GTK_RESPONSE_CANCEL)
276
    return;
277
 
278
  ptr = gtkpeer_get_widget (cp_gtk_gdk_env(), peer_obj);
279
 
280
  if (responseId == GTK_RESPONSE_DELETE_EVENT)
281
  {
282
    /* We can dispose of the dialog now (and unblock show) */
283
    (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer_obj,
284
                                         gtkDisposeFileDialogID);
285
 
286
    return;
287
  }
288
 
289
  if (responseId == GTK_RESPONSE_ACCEPT)
290
    {
291
      fileName = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (GTK_WIDGET (ptr)));
292
      str_fileName = (*cp_gtk_gdk_env())->NewStringUTF (cp_gtk_gdk_env(), fileName);
293
    }
294
 
295
  /* Set the Java object field 'file' with this value. */
296
  (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer_obj,
297
                                       gtkSetFilenameID, str_fileName);
298
 
299
  /* We can hide the dialog now (and unblock show) */
300
  (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer_obj,
301
                                       gtkHideFileDialogID);
302
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.