comparison src/gui_gtk.c @ 270:a20218704019

updated for version 7.0072
author vimboss
date Wed, 18 May 2005 22:17:12 +0000
parents bcb347a8f934
children 529f887b5cb7
comparison
equal deleted inserted replaced
269:8273a51fc8dd 270:a20218704019
1207 1207
1208 #if defined(FEAT_BROWSE) || defined(PROTO) 1208 #if defined(FEAT_BROWSE) || defined(PROTO)
1209 /* 1209 /*
1210 * Implementation of the file selector related stuff 1210 * Implementation of the file selector related stuff
1211 */ 1211 */
1212 1212 #if defined(HAVE_GTK2) && GTK_CHECK_VERSION(2,4,0)
1213 # define USE_FILE_CHOOSER
1214 #endif
1215
1216 #ifndef USE_FILE_CHOOSER
1213 /*ARGSUSED*/ 1217 /*ARGSUSED*/
1214 static void 1218 static void
1215 browse_ok_cb(GtkWidget *widget, gpointer cbdata) 1219 browse_ok_cb(GtkWidget *widget, gpointer cbdata)
1216 { 1220 {
1217 gui_T *vw = (gui_T *)cbdata; 1221 gui_T *vw = (gui_T *)cbdata;
1256 if (gtk_main_level() > 0) 1260 if (gtk_main_level() > 0)
1257 gtk_main_quit(); 1261 gtk_main_quit();
1258 1262
1259 return FALSE; 1263 return FALSE;
1260 } 1264 }
1265 #endif
1261 1266
1262 /* 1267 /*
1263 * Put up a file requester. 1268 * Put up a file requester.
1264 * Returns the selected name in allocated memory, or NULL for Cancel. 1269 * Returns the selected name in allocated memory, or NULL for Cancel.
1265 * saving, select file to write 1270 * saving, select file to write
1276 char_u *dflt, 1281 char_u *dflt,
1277 char_u *ext, 1282 char_u *ext,
1278 char_u *initdir, 1283 char_u *initdir,
1279 char_u *filter) 1284 char_u *filter)
1280 { 1285 {
1281 GtkFileSelection *fs; /* shortcut */ 1286 #ifdef USE_FILE_CHOOSER
1287 GtkWidget *fc;
1288 #endif
1282 char_u dirbuf[MAXPATHL]; 1289 char_u dirbuf[MAXPATHL];
1283 char_u *p; 1290 char_u *p;
1284 1291
1285 # ifdef HAVE_GTK2 1292 # ifdef HAVE_GTK2
1286 title = CONVERT_TO_UTF8(title); 1293 title = CONVERT_TO_UTF8(title);
1287 # endif 1294 # endif
1288
1289 if (!gui.filedlg)
1290 {
1291 gui.filedlg = gtk_file_selection_new((const gchar *)title);
1292 gtk_window_set_modal(GTK_WINDOW(gui.filedlg), TRUE);
1293 gtk_window_set_transient_for(GTK_WINDOW(gui.filedlg),
1294 GTK_WINDOW(gui.mainwin));
1295 fs = GTK_FILE_SELECTION(gui.filedlg);
1296
1297 gtk_container_border_width(GTK_CONTAINER(fs), 4);
1298
1299 gtk_signal_connect(GTK_OBJECT(fs->ok_button),
1300 "clicked", GTK_SIGNAL_FUNC(browse_ok_cb), &gui);
1301 gtk_signal_connect(GTK_OBJECT(fs->cancel_button),
1302 "clicked", GTK_SIGNAL_FUNC(browse_cancel_cb), &gui);
1303 /* gtk_signal_connect() doesn't work for destroy, it causes a hang */
1304 gtk_signal_connect_object(GTK_OBJECT(gui.filedlg),
1305 "destroy", GTK_SIGNAL_FUNC(browse_destroy_cb),
1306 GTK_OBJECT(gui.filedlg));
1307 }
1308 else
1309 gtk_window_set_title(GTK_WINDOW(gui.filedlg), (const gchar *)title);
1310
1311 # ifdef HAVE_GTK2
1312 CONVERT_TO_UTF8_FREE(title);
1313 # endif
1314
1315 /* if our pointer is currently hidden, then we should show it. */
1316 gui_mch_mousehide(FALSE);
1317 1295
1318 /* Concatenate "initdir" and "dflt". */ 1296 /* Concatenate "initdir" and "dflt". */
1319 if (initdir == NULL || *initdir == NUL) 1297 if (initdir == NULL || *initdir == NUL)
1320 mch_dirname(dirbuf, MAXPATHL); 1298 mch_dirname(dirbuf, MAXPATHL);
1321 else if (STRLEN(initdir) + 2 < MAXPATHL) 1299 else if (STRLEN(initdir) + 2 < MAXPATHL)
1326 add_pathsep(dirbuf); 1304 add_pathsep(dirbuf);
1327 if (dflt != NULL && *dflt != NUL 1305 if (dflt != NULL && *dflt != NUL
1328 && STRLEN(dirbuf) + 2 + STRLEN(dflt) < MAXPATHL) 1306 && STRLEN(dirbuf) + 2 + STRLEN(dflt) < MAXPATHL)
1329 STRCAT(dirbuf, dflt); 1307 STRCAT(dirbuf, dflt);
1330 1308
1309 /* If our pointer is currently hidden, then we should show it. */
1310 gui_mch_mousehide(FALSE);
1311
1312 #ifdef USE_FILE_CHOOSER
1313 /* We create the dialog each time, so that the button text can be "Open"
1314 * or "Save" according to the action. */
1315 fc = gtk_file_chooser_dialog_new((const gchar *)title,
1316 GTK_WINDOW(gui.mainwin),
1317 saving ? GTK_FILE_CHOOSER_ACTION_SAVE
1318 : GTK_FILE_CHOOSER_ACTION_OPEN,
1319 saving ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1320 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1321 NULL);
1322 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fc),
1323 (const gchar *)dirbuf);
1324
1325 gui.browse_fname = NULL;
1326 if (gtk_dialog_run(GTK_DIALOG(fc)) == GTK_RESPONSE_ACCEPT)
1327 {
1328 char *filename;
1329
1330 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fc));
1331 gui.browse_fname = (char_u *)g_strdup(filename);
1332 g_free(filename);
1333 }
1334 gtk_widget_destroy(GTK_WIDGET(fc));
1335
1336 #else
1337
1338 if (gui.filedlg == NULL)
1339 {
1340 GtkFileSelection *fs; /* shortcut */
1341
1342 gui.filedlg = gtk_file_selection_new((const gchar *)title);
1343 gtk_window_set_modal(GTK_WINDOW(gui.filedlg), TRUE);
1344 gtk_window_set_transient_for(GTK_WINDOW(gui.filedlg),
1345 GTK_WINDOW(gui.mainwin));
1346 fs = GTK_FILE_SELECTION(gui.filedlg);
1347
1348 gtk_container_border_width(GTK_CONTAINER(fs), 4);
1349
1350 gtk_signal_connect(GTK_OBJECT(fs->ok_button),
1351 "clicked", GTK_SIGNAL_FUNC(browse_ok_cb), &gui);
1352 gtk_signal_connect(GTK_OBJECT(fs->cancel_button),
1353 "clicked", GTK_SIGNAL_FUNC(browse_cancel_cb), &gui);
1354 /* gtk_signal_connect() doesn't work for destroy, it causes a hang */
1355 gtk_signal_connect_object(GTK_OBJECT(gui.filedlg),
1356 "destroy", GTK_SIGNAL_FUNC(browse_destroy_cb),
1357 GTK_OBJECT(gui.filedlg));
1358 }
1359 else
1360 gtk_window_set_title(GTK_WINDOW(gui.filedlg), (const gchar *)title);
1361
1331 gtk_file_selection_set_filename(GTK_FILE_SELECTION(gui.filedlg), 1362 gtk_file_selection_set_filename(GTK_FILE_SELECTION(gui.filedlg),
1332 (const gchar *)dirbuf); 1363 (const gchar *)dirbuf);
1333 # ifndef HAVE_GTK2 1364 # ifndef HAVE_GTK2
1334 gui_gtk_position_in_parent(GTK_WIDGET(gui.mainwin), 1365 gui_gtk_position_in_parent(GTK_WIDGET(gui.mainwin),
1335 GTK_WIDGET(gui.filedlg), VW_POS_MOUSE); 1366 GTK_WIDGET(gui.filedlg), VW_POS_MOUSE);
1336 # endif 1367 # endif
1337 1368
1338 gtk_widget_show(gui.filedlg); 1369 gtk_widget_show(gui.filedlg);
1339 while (gui.filedlg && GTK_WIDGET_DRAWABLE(gui.filedlg)) 1370 while (gui.filedlg && GTK_WIDGET_DRAWABLE(gui.filedlg))
1340 gtk_main_iteration_do(TRUE); 1371 gtk_main_iteration_do(TRUE);
1341 1372 #endif
1373
1374 # ifdef HAVE_GTK2
1375 CONVERT_TO_UTF8_FREE(title);
1376 # endif
1342 if (gui.browse_fname == NULL) 1377 if (gui.browse_fname == NULL)
1343 return NULL; 1378 return NULL;
1344 1379
1345 /* shorten the file name if possible */ 1380 /* shorten the file name if possible */
1346 mch_dirname(dirbuf, MAXPATHL); 1381 mch_dirname(dirbuf, MAXPATHL);
1419 /* For GTK 2.2 and earlier: fall back to ordinary file selector. */ 1454 /* For GTK 2.2 and earlier: fall back to ordinary file selector. */
1420 return gui_mch_browse(0, title, NULL, NULL, initdir, NULL); 1455 return gui_mch_browse(0, title, NULL, NULL, initdir, NULL);
1421 # endif 1456 # endif
1422 } 1457 }
1423 #endif 1458 #endif
1459
1424 1460
1425 #endif /* FEAT_BROWSE */ 1461 #endif /* FEAT_BROWSE */
1426 1462
1427 #if defined(FEAT_GUI_DIALOG) && !defined(HAVE_GTK2) 1463 #if defined(FEAT_GUI_DIALOG) && !defined(HAVE_GTK2)
1428 1464
3102 pos_y = yP + 2; 3138 pos_y = yP + 2;
3103 if ((pos_x + c_size.width) > (wP + xP)) 3139 if ((pos_x + c_size.width) > (wP + xP))
3104 pos_x = xP + wP - c_size.width - 2; 3140 pos_x = xP + wP - c_size.width - 2;
3105 /* Assume 'guiheadroom' indicates the title bar height... */ 3141 /* Assume 'guiheadroom' indicates the title bar height... */
3106 if ((pos_y + c_size.height + p_ghr / 2) > (hP + yP)) 3142 if ((pos_y + c_size.height + p_ghr / 2) > (hP + yP))
3107 pos_y = yP + hP - c_size.height - 2 - p_ghr / 2;
3108 3143
3109 gtk_widget_set_uposition(child, pos_x, pos_y); 3144 gtk_widget_set_uposition(child, pos_x, pos_y);
3110 } 3145 }
3111 3146
3112 #endif /* !HAVE_GTK2 */ 3147 #endif /* !HAVE_GTK2 */