aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Djärv2004-11-13 23:09:11 +0000
committerJan Djärv2004-11-13 23:09:11 +0000
commit457a8155aacb495b8db94ed2c0d69b1e926f9012 (patch)
tree8924159cf1bbe7613715f549eadbbcb8deeb4428 /src
parent955afc1373adcb10cc74e70b7136f7fc8eaff405 (diff)
downloademacs-457a8155aacb495b8db94ed2c0d69b1e926f9012.tar.gz
emacs-457a8155aacb495b8db94ed2c0d69b1e926f9012.zip
* gtkutil.c (xg_file_sel_ok, xg_file_sel_cancel)
(xg_file_sel_destroy): Removed. (xg_file_response_cb, pop_down_file_dialog, xg_get_file_name_from_chooser, xg_get_file_name_from_selector): New functions. (xg_get_file_with_chooser, xg_get_file_with_selection): Take new argument func, set it to xg_get_file_name_from_chooser/selector. Move common code to xg_get_file_name. Return widget created. (xg_get_file_name): Set name, transient for, modal and destroy with parent here. Connect response signal to xg_file_response_cb, connect delete-event to gtk_true. Record pop_down_file_dialog for unwind. Do event loop and call x_menu_wait_for_event in loop. (xg_create_widget): Make dialogs modal.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog14
-rw-r--r--src/gtkutil.c223
2 files changed, 125 insertions, 112 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 390ade23e10..3a8260b0584 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,19 @@
12004-11-13 Jan Dj,Ad(Brv <jan.h.d@swipnet.se> 12004-11-13 Jan Dj,Ad(Brv <jan.h.d@swipnet.se>
2 2
3 * gtkutil.c (xg_file_sel_ok, xg_file_sel_cancel)
4 (xg_file_sel_destroy): Removed.
5 (xg_file_response_cb, pop_down_file_dialog,
6 xg_get_file_name_from_chooser, xg_get_file_name_from_selector):
7 New functions.
8 (xg_get_file_with_chooser, xg_get_file_with_selection): Take
9 new argument func, set it to xg_get_file_name_from_chooser/selector.
10 Move common code to xg_get_file_name. Return widget created.
11 (xg_get_file_name): Set name, transient for, modal and destroy
12 with parent here. Connect response signal to xg_file_response_cb,
13 connect delete-event to gtk_true. Record pop_down_file_dialog
14 for unwind. Do event loop and call x_menu_wait_for_event in loop.
15 (xg_create_widget): Make dialogs modal.
16
3 * xmenu.c (unuse_menu_items, pop_down_menu): Arg is of type 17 * xmenu.c (unuse_menu_items, pop_down_menu): Arg is of type
4 Lisp_Object. 18 Lisp_Object.
5 (popup_get_selection): Move unwind protect ... 19 (popup_get_selection): Move unwind protect ...
diff --git a/src/gtkutil.c b/src/gtkutil.c
index f5f05709e48..90cee0c7272 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -1122,41 +1122,73 @@ create_dialog (wv, select_cb, deactivate_cb)
1122/*********************************************************************** 1122/***********************************************************************
1123 File dialog functions 1123 File dialog functions
1124 ***********************************************************************/ 1124 ***********************************************************************/
1125enum
1126{
1127 XG_FILE_NOT_DONE,
1128 XG_FILE_OK,
1129 XG_FILE_CANCEL,
1130 XG_FILE_DESTROYED,
1131};
1132
1133#ifdef HAVE_GTK_FILE_BOTH 1125#ifdef HAVE_GTK_FILE_BOTH
1134int use_old_gtk_file_dialog; 1126int use_old_gtk_file_dialog;
1135#endif 1127#endif
1136 1128
1129/* Function that is called when the file dialog pops down.
1130 W is the dialog widget, RESPONSE is the response code.
1131 USER_DATA is what we passed in to g_signal_connect (pointer to int). */
1132
1133static void
1134xg_file_response_cb (w,
1135 response,
1136 user_data)
1137 GtkDialog *w;
1138 gint response;
1139 gpointer user_data;
1140{
1141 int *ptr = (int *) user_data;
1142 *ptr = response;
1143}
1144
1145
1146/* Destroy the dialog. This makes it pop down. */
1147
1148static Lisp_Object
1149pop_down_file_dialog (arg)
1150 Lisp_Object arg;
1151{
1152 struct Lisp_Save_Value *p = XSAVE_VALUE (arg);
1153 gtk_widget_destroy (GTK_WIDGET (p->pointer));
1154 return Qnil;
1155}
1156
1157typedef char * (*xg_get_file_func) P_ ((GtkWidget *));
1137 1158
1138#ifdef HAVE_GTK_FILE_CHOOSER_DIALOG_NEW 1159#ifdef HAVE_GTK_FILE_CHOOSER_DIALOG_NEW
1160
1161/* Return the selected file for file chooser dialog W.
1162 The returned string must be free:d. */
1163
1164static char *
1165xg_get_file_name_from_chooser (w)
1166 GtkWidget *w;
1167{
1168 return gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (w));
1169}
1170
1139/* Read a file name from the user using a file chooser dialog. 1171/* Read a file name from the user using a file chooser dialog.
1140 F is the current frame. 1172 F is the current frame.
1141 PROMPT is a prompt to show to the user. May not be NULL. 1173 PROMPT is a prompt to show to the user. May not be NULL.
1142 DEFAULT_FILENAME is a default selection to be displayed. May be NULL. 1174 DEFAULT_FILENAME is a default selection to be displayed. May be NULL.
1143 If MUSTMATCH_P is non-zero, the returned file name must be an existing 1175 If MUSTMATCH_P is non-zero, the returned file name must be an existing
1144 file. 1176 file. *FUNC is set to a function that can be used to retrieve the
1177 selected file name from the returned widget.
1145 1178
1146 Returns a file name or NULL if no file was selected. 1179 Returns the created widget. */
1147 The returned string must be freed by the caller. */
1148 1180
1149static char * 1181static GtkWidget *
1150xg_get_file_with_chooser (f, prompt, default_filename, mustmatch_p, only_dir_p) 1182xg_get_file_with_chooser (f, prompt, default_filename,
1183 mustmatch_p, only_dir_p, func)
1151 FRAME_PTR f; 1184 FRAME_PTR f;
1152 char *prompt; 1185 char *prompt;
1153 char *default_filename; 1186 char *default_filename;
1154 int mustmatch_p, only_dir_p; 1187 int mustmatch_p, only_dir_p;
1188 xg_get_file_func *func;
1155{ 1189{
1156 GtkWidget *filewin; 1190 GtkWidget *filewin;
1157 GtkWindow *gwin = GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)); 1191 GtkWindow *gwin = GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f));
1158
1159 char *fn = 0;
1160 GtkFileChooserAction action = (mustmatch_p ? 1192 GtkFileChooserAction action = (mustmatch_p ?
1161 GTK_FILE_CHOOSER_ACTION_OPEN : 1193 GTK_FILE_CHOOSER_ACTION_OPEN :
1162 GTK_FILE_CHOOSER_ACTION_SAVE); 1194 GTK_FILE_CHOOSER_ACTION_SAVE);
@@ -1171,12 +1203,6 @@ xg_get_file_with_chooser (f, prompt, default_filename, mustmatch_p, only_dir_p)
1171 GTK_RESPONSE_OK, 1203 GTK_RESPONSE_OK,
1172 NULL); 1204 NULL);
1173 1205
1174 xg_set_screen (filewin, f);
1175 gtk_widget_set_name (filewin, "emacs-filedialog");
1176 gtk_window_set_transient_for (GTK_WINDOW (filewin), gwin);
1177 gtk_window_set_destroy_with_parent (GTK_WINDOW (filewin), TRUE);
1178
1179
1180 if (default_filename) 1206 if (default_filename)
1181 { 1207 {
1182 Lisp_Object file; 1208 Lisp_Object file;
@@ -1197,104 +1223,49 @@ xg_get_file_with_chooser (f, prompt, default_filename, mustmatch_p, only_dir_p)
1197 UNGCPRO; 1223 UNGCPRO;
1198 } 1224 }
1199 1225
1200 gtk_widget_show (filewin); 1226 *func = xg_get_file_name_from_chooser;
1201 1227 return filewin;
1202 if (gtk_dialog_run (GTK_DIALOG (filewin)) == GTK_RESPONSE_OK)
1203 fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filewin));
1204
1205 gtk_widget_destroy (filewin);
1206
1207 return fn;
1208} 1228}
1209#endif /* HAVE_GTK_FILE_CHOOSER_DIALOG_NEW */ 1229#endif /* HAVE_GTK_FILE_CHOOSER_DIALOG_NEW */
1210 1230
1211#ifdef HAVE_GTK_FILE_SELECTION_NEW 1231#ifdef HAVE_GTK_FILE_SELECTION_NEW
1212/* Callback function invoked when the Ok button is pressed in
1213 a file dialog.
1214 W is the file dialog widget,
1215 ARG points to an integer where we record what has happend. */
1216
1217static void
1218xg_file_sel_ok (w, arg)
1219 GtkWidget *w;
1220 gpointer arg;
1221{
1222 *(int*)arg = XG_FILE_OK;
1223}
1224
1225/* Callback function invoked when the Cancel button is pressed in
1226 a file dialog.
1227 W is the file dialog widget,
1228 ARG points to an integer where we record what has happend. */
1229
1230static void
1231xg_file_sel_cancel (w, arg)
1232 GtkWidget *w;
1233 gpointer arg;
1234{
1235 *(int*)arg = XG_FILE_CANCEL;
1236}
1237 1232
1238/* Callback function invoked when the file dialog is destroyed (i.e. 1233/* Return the selected file for file selector dialog W.
1239 popped down). We must keep track of this, because if this 1234 The returned string must be free:d. */
1240 happens, GTK destroys the widget. But if for example, Ok is pressed,
1241 the dialog is popped down, but the dialog widget is not destroyed.
1242 W is the file dialog widget,
1243 ARG points to an integer where we record what has happend. */
1244 1235
1245static void 1236static char *
1246xg_file_sel_destroy (w, arg) 1237xg_get_file_name_from_selector (w)
1247 GtkWidget *w; 1238 GtkWidget *w;
1248 gpointer arg;
1249{ 1239{
1250 *(int*)arg = XG_FILE_DESTROYED; 1240 GtkFileSelection *filesel = GTK_FILE_SELECTION (w);
1241 return xstrdup ((char*) gtk_file_selection_get_filename (filesel));
1251} 1242}
1252 1243
1253/* Read a file name from the user using a file selection dialog. 1244/* Create a file selection dialog.
1254 F is the current frame. 1245 F is the current frame.
1255 PROMPT is a prompt to show to the user. May not be NULL. 1246 PROMPT is a prompt to show to the user. May not be NULL.
1256 DEFAULT_FILENAME is a default selection to be displayed. May be NULL. 1247 DEFAULT_FILENAME is a default selection to be displayed. May be NULL.
1257 If MUSTMATCH_P is non-zero, the returned file name must be an existing 1248 If MUSTMATCH_P is non-zero, the returned file name must be an existing
1258 file. 1249 file. *FUNC is set to a function that can be used to retrieve the
1250 selected file name from the returned widget.
1259 1251
1260 Returns a file name or NULL if no file was selected. 1252 Returns the created widget. */
1261 The returned string must be freed by the caller. */
1262 1253
1263static char * 1254static GtkWidget *
1264xg_get_file_with_selection (f, prompt, default_filename, 1255xg_get_file_with_selection (f, prompt, default_filename,
1265 mustmatch_p, only_dir_p) 1256 mustmatch_p, only_dir_p, func)
1266 FRAME_PTR f; 1257 FRAME_PTR f;
1267 char *prompt; 1258 char *prompt;
1268 char *default_filename; 1259 char *default_filename;
1269 int mustmatch_p, only_dir_p; 1260 int mustmatch_p, only_dir_p;
1261 xg_get_file_func *func;
1270{ 1262{
1271 GtkWidget *filewin; 1263 GtkWidget *filewin;
1272 GtkFileSelection *filesel; 1264 GtkFileSelection *filesel;
1273 int filesel_done = XG_FILE_NOT_DONE;
1274 char *fn = 0;
1275 1265
1276 filewin = gtk_file_selection_new (prompt); 1266 filewin = gtk_file_selection_new (prompt);
1277 filesel = GTK_FILE_SELECTION (filewin); 1267 filesel = GTK_FILE_SELECTION (filewin);
1278 1268
1279 xg_set_screen (filewin, f);
1280 gtk_widget_set_name (filewin, "emacs-filedialog");
1281 gtk_window_set_transient_for (GTK_WINDOW (filewin),
1282 GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)));
1283 gtk_window_set_destroy_with_parent (GTK_WINDOW (filewin), TRUE);
1284
1285 g_signal_connect (G_OBJECT (filesel->ok_button),
1286 "clicked",
1287 G_CALLBACK (xg_file_sel_ok),
1288 &filesel_done);
1289 g_signal_connect (G_OBJECT (filesel->cancel_button),
1290 "clicked",
1291 G_CALLBACK (xg_file_sel_cancel),
1292 &filesel_done);
1293 g_signal_connect (G_OBJECT (filesel),
1294 "destroy",
1295 G_CALLBACK (xg_file_sel_destroy),
1296 &filesel_done);
1297
1298 if (default_filename) 1269 if (default_filename)
1299 gtk_file_selection_set_filename (filesel, default_filename); 1270 gtk_file_selection_set_filename (filesel, default_filename);
1300 1271
@@ -1305,19 +1276,9 @@ xg_get_file_with_selection (f, prompt, default_filename,
1305 gtk_file_selection_hide_fileop_buttons (filesel); 1276 gtk_file_selection_hide_fileop_buttons (filesel);
1306 } 1277 }
1307 1278
1279 *func = xg_get_file_name_from_selector;
1308 1280
1309 gtk_widget_show_all (filewin); 1281 return filewin;
1310
1311 while (filesel_done == XG_FILE_NOT_DONE)
1312 gtk_main_iteration ();
1313
1314 if (filesel_done == XG_FILE_OK)
1315 fn = xstrdup ((char*) gtk_file_selection_get_filename (filesel));
1316
1317 if (filesel_done != XG_FILE_DESTROYED)
1318 gtk_widget_destroy (filewin);
1319
1320 return fn;
1321} 1282}
1322#endif /* HAVE_GTK_FILE_SELECTION_NEW */ 1283#endif /* HAVE_GTK_FILE_SELECTION_NEW */
1323 1284
@@ -1341,26 +1302,63 @@ xg_get_file_name (f, prompt, default_filename, mustmatch_p, only_dir_p)
1341 char *default_filename; 1302 char *default_filename;
1342 int mustmatch_p, only_dir_p; 1303 int mustmatch_p, only_dir_p;
1343{ 1304{
1305 GtkWidget *w;
1306 int count = SPECPDL_INDEX ();
1307 char *fn = 0;
1308 int filesel_done = 0;
1309 xg_get_file_func func;
1310
1344#ifdef HAVE_GTK_FILE_BOTH 1311#ifdef HAVE_GTK_FILE_BOTH
1345 if (use_old_gtk_file_dialog) 1312 if (use_old_gtk_file_dialog)
1346 return xg_get_file_with_selection (f, prompt, default_filename, 1313 w = xg_get_file_with_selection (f, prompt, default_filename,
1347 mustmatch_p, only_dir_p); 1314 mustmatch_p, only_dir_p, &func);
1348 return xg_get_file_with_chooser (f, prompt, default_filename, 1315 else
1349 mustmatch_p, only_dir_p); 1316 w = xg_get_file_with_chooser (f, prompt, default_filename,
1317 mustmatch_p, only_dir_p, &func);
1350 1318
1351#else /* not HAVE_GTK_FILE_BOTH */ 1319#else /* not HAVE_GTK_FILE_BOTH */
1352 1320
1353#ifdef HAVE_GTK_FILE_SELECTION_DIALOG_NEW 1321#ifdef HAVE_GTK_FILE_SELECTION_DIALOG_NEW
1354 return xg_get_file_with_selection (f, prompt, default_filename, 1322 w = xg_get_file_with_selection (f, prompt, default_filename,
1355 mustmatch_p, only_dir_p); 1323 mustmatch_p, only_dir_p, &func);
1356#endif 1324#endif
1357#ifdef HAVE_GTK_FILE_CHOOSER_DIALOG_NEW 1325#ifdef HAVE_GTK_FILE_CHOOSER_DIALOG_NEW
1358 return xg_get_file_with_chooser (f, prompt, default_filename, 1326 w = xg_get_file_with_chooser (f, prompt, default_filename,
1359 mustmatch_p, only_dir_p); 1327 mustmatch_p, only_dir_p, &func);
1360#endif 1328#endif
1361 1329
1362#endif /* HAVE_GTK_FILE_BOTH */ 1330#endif /* HAVE_GTK_FILE_BOTH */
1363 return 0; 1331
1332 xg_set_screen (w, f);
1333 gtk_widget_set_name (w, "emacs-filedialog");
1334 gtk_window_set_transient_for (GTK_WINDOW (w),
1335 GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)));
1336 gtk_window_set_destroy_with_parent (GTK_WINDOW (w), TRUE);
1337 gtk_window_set_modal (GTK_WINDOW (w), TRUE);
1338
1339 g_signal_connect (G_OBJECT (w),
1340 "response",
1341 G_CALLBACK (xg_file_response_cb),
1342 &filesel_done);
1343
1344 /* Don't destroy the widget if closed by the window manager close button. */
1345 g_signal_connect (G_OBJECT (w), "delete-event", G_CALLBACK (gtk_true), NULL);
1346
1347 gtk_widget_show (w);
1348
1349 record_unwind_protect (pop_down_file_dialog, make_save_value (w, 0));
1350 while (! filesel_done)
1351 {
1352 x_menu_wait_for_event (0);
1353 gtk_main_iteration ();
1354 }
1355
1356 if (filesel_done == GTK_RESPONSE_OK)
1357 fn = (*func) (w);
1358
1359 unbind_to (count, Qnil);
1360
1361 return fn;
1364} 1362}
1365 1363
1366 1364
@@ -1999,6 +1997,7 @@ xg_create_widget (type, name, f, val,
1999 GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f))); 1997 GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)));
2000 gtk_window_set_destroy_with_parent (GTK_WINDOW (w), TRUE); 1998 gtk_window_set_destroy_with_parent (GTK_WINDOW (w), TRUE);
2001 gtk_widget_set_name (w, "emacs-dialog"); 1999 gtk_widget_set_name (w, "emacs-dialog");
2000 gtk_window_set_modal (GTK_WINDOW (w), TRUE);
2002 } 2001 }
2003 else if (menu_bar_p || pop_up_p) 2002 else if (menu_bar_p || pop_up_p)
2004 { 2003 {