Mercurial > hg > RemoteEditor > vim7
comparison src/gui_gtk.c @ 39:c16898406ff2
synchorinize version 7.3.081
author | one@zeus.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Fri, 17 Dec 2010 17:43:06 +0900 |
parents | e170173ecb68 |
children | 67300faee616 |
comparison
equal
deleted
inserted
replaced
38:e06a1cd7230d | 39:c16898406ff2 |
---|---|
60 # define ENABLE_NLS /* so the texts in the dialog boxes are translated */ | 60 # define ENABLE_NLS /* so the texts in the dialog boxes are translated */ |
61 # endif | 61 # endif |
62 # include <gnome.h> | 62 # include <gnome.h> |
63 #endif | 63 #endif |
64 | 64 |
65 #if defined(FEAT_GUI_DIALOG) && !defined(HAVE_GTK2) | |
66 # include "../pixmaps/alert.xpm" | |
67 # include "../pixmaps/error.xpm" | |
68 # include "../pixmaps/generic.xpm" | |
69 # include "../pixmaps/info.xpm" | |
70 # include "../pixmaps/quest.xpm" | |
71 #endif | |
72 | |
73 #if defined(FEAT_TOOLBAR) && !defined(HAVE_GTK2) | |
74 /* | |
75 * Icons used by the toolbar code. | |
76 */ | |
77 #include "../pixmaps/tb_new.xpm" | |
78 #include "../pixmaps/tb_open.xpm" | |
79 #include "../pixmaps/tb_close.xpm" | |
80 #include "../pixmaps/tb_save.xpm" | |
81 #include "../pixmaps/tb_print.xpm" | |
82 #include "../pixmaps/tb_cut.xpm" | |
83 #include "../pixmaps/tb_copy.xpm" | |
84 #include "../pixmaps/tb_paste.xpm" | |
85 #include "../pixmaps/tb_find.xpm" | |
86 #include "../pixmaps/tb_find_next.xpm" | |
87 #include "../pixmaps/tb_find_prev.xpm" | |
88 #include "../pixmaps/tb_find_help.xpm" | |
89 #include "../pixmaps/tb_exit.xpm" | |
90 #include "../pixmaps/tb_undo.xpm" | |
91 #include "../pixmaps/tb_redo.xpm" | |
92 #include "../pixmaps/tb_help.xpm" | |
93 #include "../pixmaps/tb_macro.xpm" | |
94 #include "../pixmaps/tb_make.xpm" | |
95 #include "../pixmaps/tb_save_all.xpm" | |
96 #include "../pixmaps/tb_jump.xpm" | |
97 #include "../pixmaps/tb_ctags.xpm" | |
98 #include "../pixmaps/tb_load_session.xpm" | |
99 #include "../pixmaps/tb_save_session.xpm" | |
100 #include "../pixmaps/tb_new_session.xpm" | |
101 #include "../pixmaps/tb_blank.xpm" | |
102 #include "../pixmaps/tb_maximize.xpm" | |
103 #include "../pixmaps/tb_split.xpm" | |
104 #include "../pixmaps/tb_minimize.xpm" | |
105 #include "../pixmaps/tb_shell.xpm" | |
106 #include "../pixmaps/tb_replace.xpm" | |
107 #include "../pixmaps/tb_vsplit.xpm" | |
108 #include "../pixmaps/tb_maxwidth.xpm" | |
109 #include "../pixmaps/tb_minwidth.xpm" | |
110 #endif /* FEAT_TOOLBAR && !HAVE_GTK2 */ | |
111 | |
112 #ifdef FEAT_GUI_GTK | 65 #ifdef FEAT_GUI_GTK |
113 # include <gdk/gdkkeysyms.h> | 66 # include <gdk/gdkkeysyms.h> |
114 # include <gdk/gdk.h> | 67 # include <gdk/gdk.h> |
115 # ifdef WIN3264 | 68 # ifdef WIN3264 |
116 # include <gdk/gdkwin32.h> | 69 # include <gdk/gdkwin32.h> |
135 #endif | 88 #endif |
136 | 89 |
137 static void entry_activate_cb(GtkWidget *widget, gpointer data); | 90 static void entry_activate_cb(GtkWidget *widget, gpointer data); |
138 static void entry_changed_cb(GtkWidget *entry, GtkWidget *dialog); | 91 static void entry_changed_cb(GtkWidget *entry, GtkWidget *dialog); |
139 static void find_replace_cb(GtkWidget *widget, gpointer data); | 92 static void find_replace_cb(GtkWidget *widget, gpointer data); |
140 #ifndef HAVE_GTK2 | 93 |
141 static void gui_gtk_position_in_parent(GtkWidget *parent, GtkWidget *child, gui_win_pos_T where); | 94 #if defined(FEAT_TOOLBAR) |
142 #endif | |
143 | |
144 #if defined(FEAT_TOOLBAR) && defined(HAVE_GTK2) | |
145 /* | 95 /* |
146 * Table from BuiltIn## icon indices to GTK+ stock IDs. Order must exactly | 96 * Table from BuiltIn## icon indices to GTK+ stock IDs. Order must exactly |
147 * match toolbar_names[] in menu.c! All stock icons including the "vim-*" | 97 * match toolbar_names[] in menu.c! All stock icons including the "vim-*" |
148 * ones can be overridden in your gtkrc file. | 98 * ones can be overridden in your gtkrc file. |
149 */ | 99 */ |
283 } | 233 } |
284 | 234 |
285 return image; | 235 return image; |
286 } | 236 } |
287 | 237 |
288 /*ARGSUSED*/ | |
289 static gint | 238 static gint |
290 toolbar_button_focus_in_event(GtkWidget *widget, GdkEventFocus *event, gpointer data) | 239 toolbar_button_focus_in_event(GtkWidget *widget UNUSED, |
291 { | 240 GdkEventFocus *event UNUSED, |
292 /* When we're in a GtkPlug, we don't have window focus events, only widget focus. | 241 gpointer data UNUSED) |
293 * To emulate stand-alone gvim, if a button gets focus (e.g., <Tab> into GtkPlug) | 242 { |
294 * immediately pass it to mainwin. | 243 /* When we're in a GtkPlug, we don't have window focus events, only widget |
295 */ | 244 * focus. To emulate stand-alone gvim, if a button gets focus (e.g., |
245 * <Tab> into GtkPlug) immediately pass it to mainwin. */ | |
296 if (gtk_socket_id != 0) | 246 if (gtk_socket_id != 0) |
297 gtk_widget_grab_focus(gui.drawarea); | 247 gtk_widget_grab_focus(gui.drawarea); |
298 | 248 |
299 return TRUE; | 249 return TRUE; |
300 } | 250 } |
301 #endif /* FEAT_TOOLBAR && HAVE_GTK2 */ | 251 #endif /* FEAT_TOOLBAR */ |
302 | 252 |
303 #if (defined(FEAT_TOOLBAR) && defined(HAVE_GTK2)) || defined(PROTO) | 253 #if defined(FEAT_TOOLBAR) || defined(PROTO) |
304 | 254 |
305 void | 255 void |
306 gui_gtk_register_stock_icons(void) | 256 gui_gtk_register_stock_icons(void) |
307 { | 257 { |
308 # include "../pixmaps/stock_icons.h" | 258 # include "../pixmaps/stock_icons.h" |
328 # undef ADD_ICON | 278 # undef ADD_ICON |
329 gtk_icon_factory_add_default(factory); | 279 gtk_icon_factory_add_default(factory); |
330 g_object_unref(factory); | 280 g_object_unref(factory); |
331 } | 281 } |
332 | 282 |
333 #endif /* FEAT_TOOLBAR && HAVE_GTK2 */ | 283 #endif /* FEAT_TOOLBAR */ |
334 | 284 |
335 | |
336 /* | |
337 * Only use accelerators when gtk_menu_ensure_uline_accel_group() is | |
338 * available, which is in version 1.2.1. That was the first version where | |
339 * accelerators properly worked (according to the change log). | |
340 */ | |
341 #ifdef GTK_CHECK_VERSION | |
342 # if GTK_CHECK_VERSION(1, 2, 1) | |
343 # define GTK_USE_ACCEL | |
344 # endif | |
345 #endif | |
346 | 285 |
347 #if defined(FEAT_MENU) || defined(PROTO) | 286 #if defined(FEAT_MENU) || defined(PROTO) |
348 | 287 |
349 /* | 288 /* |
350 * Translate Vim's mnemonic tagging to GTK+ style and convert to UTF-8 | 289 * Translate Vim's mnemonic tagging to GTK+ style and convert to UTF-8 |
362 char_u *buf; | 301 char_u *buf; |
363 char_u *psrc; | 302 char_u *psrc; |
364 char_u *pdest; | 303 char_u *pdest; |
365 int n_underscores = 0; | 304 int n_underscores = 0; |
366 | 305 |
367 # ifdef HAVE_GTK2 | |
368 name = CONVERT_TO_UTF8(name); | 306 name = CONVERT_TO_UTF8(name); |
369 # endif | |
370 if (name == NULL) | 307 if (name == NULL) |
371 return NULL; | 308 return NULL; |
372 | 309 |
373 for (psrc = name; *psrc != NUL && *psrc != TAB; ++psrc) | 310 for (psrc = name; *psrc != NUL && *psrc != TAB; ++psrc) |
374 if (*psrc == '_') | 311 if (*psrc == '_') |
399 } | 336 } |
400 } | 337 } |
401 *pdest = NUL; | 338 *pdest = NUL; |
402 } | 339 } |
403 | 340 |
404 # ifdef HAVE_GTK2 | |
405 CONVERT_TO_UTF8_FREE(name); | 341 CONVERT_TO_UTF8_FREE(name); |
406 # endif | |
407 return buf; | 342 return buf; |
408 } | 343 } |
409 | |
410 # ifdef HAVE_GTK2 | |
411 | 344 |
412 static void | 345 static void |
413 menu_item_new(vimmenu_T *menu, GtkWidget *parent_widget) | 346 menu_item_new(vimmenu_T *menu, GtkWidget *parent_widget) |
414 { | 347 { |
415 GtkWidget *box; | 348 GtkWidget *box; |
443 | 376 |
444 gtk_container_add(GTK_CONTAINER(menu->id), box); | 377 gtk_container_add(GTK_CONTAINER(menu->id), box); |
445 gtk_widget_show_all(menu->id); | 378 gtk_widget_show_all(menu->id); |
446 } | 379 } |
447 | 380 |
448 # else /* !HAVE_GTK2 */ | |
449 | |
450 /* | |
451 * Create a highly customized menu item by hand instead of by using: | |
452 * | |
453 * gtk_menu_item_new_with_label(menu->dname); | |
454 * | |
455 * This is necessary, since there is no other way in GTK+ 1 to get the | |
456 * not automatically parsed accelerator stuff right. | |
457 */ | |
458 static void | |
459 menu_item_new(vimmenu_T *menu, GtkWidget *parent_widget) | |
460 { | |
461 GtkWidget *widget; | |
462 GtkWidget *bin; | |
463 GtkWidget *label; | |
464 char_u *name; | |
465 guint accel_key; | |
466 | |
467 widget = gtk_widget_new(GTK_TYPE_MENU_ITEM, | |
468 "GtkWidget::visible", TRUE, | |
469 "GtkWidget::sensitive", TRUE, | |
470 /* "GtkWidget::parent", parent->submenu_id, */ | |
471 NULL); | |
472 bin = gtk_widget_new(GTK_TYPE_HBOX, | |
473 "GtkWidget::visible", TRUE, | |
474 "GtkWidget::parent", widget, | |
475 "GtkBox::spacing", 16, | |
476 NULL); | |
477 label = gtk_widget_new(GTK_TYPE_ACCEL_LABEL, | |
478 "GtkWidget::visible", TRUE, | |
479 "GtkWidget::parent", bin, | |
480 "GtkAccelLabel::accel_widget", widget, | |
481 "GtkMisc::xalign", 0.0, | |
482 NULL); | |
483 menu->label = label; | |
484 | |
485 if (menu->actext) | |
486 gtk_widget_new(GTK_TYPE_LABEL, | |
487 "GtkWidget::visible", TRUE, | |
488 "GtkWidget::parent", bin, | |
489 "GtkLabel::label", menu->actext, | |
490 "GtkMisc::xalign", 1.0, | |
491 NULL); | |
492 | |
493 /* | |
494 * Translate VIM accelerator tagging into GTK+'s. Note that since GTK uses | |
495 * underscores as the accelerator key, we need to add an additional under- | |
496 * score for each understore that appears in the menu name. | |
497 */ | |
498 # ifdef GTK_USE_ACCEL | |
499 name = translate_mnemonic_tag(menu->name, | |
500 (p_wak[0] != 'n' || !GTK_IS_MENU_BAR(parent_widget))); | |
501 # else | |
502 name = translate_mnemonic_tag(menu->name, FALSE); | |
503 # endif | |
504 | |
505 /* let GTK do its thing */ | |
506 accel_key = gtk_label_parse_uline(GTK_LABEL(label), (const char *)name); | |
507 vim_free(name); | |
508 | |
509 # ifdef GTK_USE_ACCEL | |
510 /* Don't add accelator if 'winaltkeys' is "no". */ | |
511 if (accel_key != GDK_VoidSymbol) | |
512 { | |
513 if (GTK_IS_MENU_BAR(parent_widget)) | |
514 { | |
515 if (*p_wak != 'n') | |
516 gtk_widget_add_accelerator(widget, | |
517 "activate_item", | |
518 gui.accel_group, | |
519 accel_key, GDK_MOD1_MASK, | |
520 (GtkAccelFlags)0); | |
521 } | |
522 else | |
523 { | |
524 gtk_widget_add_accelerator(widget, | |
525 "activate_item", | |
526 gtk_menu_ensure_uline_accel_group(GTK_MENU(parent_widget)), | |
527 accel_key, 0, | |
528 (GtkAccelFlags)0); | |
529 } | |
530 } | |
531 # endif /* GTK_USE_ACCEL */ | |
532 | |
533 menu->id = widget; | |
534 } | |
535 | |
536 # endif /* !HAVE_GTK2 */ | |
537 | |
538 void | 381 void |
539 gui_mch_add_menu(vimmenu_T *menu, int idx) | 382 gui_mch_add_menu(vimmenu_T *menu, int idx) |
540 { | 383 { |
541 vimmenu_T *parent; | 384 vimmenu_T *parent; |
542 GtkWidget *parent_widget; | 385 GtkWidget *parent_widget; |
559 /* since the tearoff should always appear first, increment idx */ | 402 /* since the tearoff should always appear first, increment idx */ |
560 if (parent != NULL && !menu_is_popup(parent->name)) | 403 if (parent != NULL && !menu_is_popup(parent->name)) |
561 ++idx; | 404 ++idx; |
562 | 405 |
563 gtk_menu_shell_insert(GTK_MENU_SHELL(parent_widget), menu->id, idx); | 406 gtk_menu_shell_insert(GTK_MENU_SHELL(parent_widget), menu->id, idx); |
564 | |
565 #ifndef HAVE_GTK2 | |
566 /* | |
567 * The "Help" menu is a special case, and should be placed at the far | |
568 * right hand side of the menu-bar. It's detected by its high priority. | |
569 * | |
570 * Right-aligning "Help" is considered bad UI design nowadays. | |
571 * Thus lets disable this for GTK+ 2 to match the environment. | |
572 */ | |
573 if (parent == NULL && menu->priority >= 9999) | |
574 gtk_menu_item_right_justify(GTK_MENU_ITEM(menu->id)); | |
575 #endif | |
576 | 407 |
577 menu->submenu_id = gtk_menu_new(); | 408 menu->submenu_id = gtk_menu_new(); |
578 | 409 |
579 gtk_menu_set_accel_group(GTK_MENU(menu->submenu_id), gui.accel_group); | 410 gtk_menu_set_accel_group(GTK_MENU(menu->submenu_id), gui.accel_group); |
580 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu->id), menu->submenu_id); | 411 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu->id), menu->submenu_id); |
583 if (vim_strchr(p_go, GO_TEAROFF) != NULL) | 414 if (vim_strchr(p_go, GO_TEAROFF) != NULL) |
584 gtk_widget_show(menu->tearoff_handle); | 415 gtk_widget_show(menu->tearoff_handle); |
585 gtk_menu_prepend(GTK_MENU(menu->submenu_id), menu->tearoff_handle); | 416 gtk_menu_prepend(GTK_MENU(menu->submenu_id), menu->tearoff_handle); |
586 } | 417 } |
587 | 418 |
588 /*ARGSUSED*/ | |
589 static void | 419 static void |
590 menu_item_activate(GtkWidget *widget, gpointer data) | 420 menu_item_activate(GtkWidget *widget UNUSED, gpointer data) |
591 { | 421 { |
592 gui_menu_cb((vimmenu_T *)data); | 422 gui_menu_cb((vimmenu_T *)data); |
593 | 423 } |
594 # ifndef HAVE_GTK2 | |
595 /* Work around a bug in GTK+ 1: we don't seem to get a focus-in | |
596 * event after clicking a menu item shown via :popup. */ | |
597 if (!gui.in_focus) | |
598 gui_focus_change(TRUE); | |
599 # endif | |
600 | |
601 /* make sure the menu action is taken immediately */ | |
602 if (gtk_main_level() > 0) | |
603 gtk_main_quit(); | |
604 } | |
605 | |
606 # if defined(FEAT_TOOLBAR) && !defined(HAVE_GTK2) | |
607 /* | |
608 * These are the pixmaps used for the default buttons. | |
609 * Order must exactly match toolbar_names[] in menu.c! | |
610 */ | |
611 static char **(built_in_pixmaps[]) = | |
612 { | |
613 tb_new_xpm, | |
614 tb_open_xpm, | |
615 tb_save_xpm, | |
616 tb_undo_xpm, | |
617 tb_redo_xpm, | |
618 tb_cut_xpm, | |
619 tb_copy_xpm, | |
620 tb_paste_xpm, | |
621 tb_print_xpm, | |
622 tb_help_xpm, | |
623 tb_find_xpm, | |
624 tb_save_all_xpm, | |
625 tb_save_session_xpm, | |
626 tb_new_session_xpm, | |
627 tb_load_session_xpm, | |
628 tb_macro_xpm, | |
629 tb_replace_xpm, | |
630 tb_close_xpm, | |
631 tb_maximize_xpm, | |
632 tb_minimize_xpm, | |
633 tb_split_xpm, | |
634 tb_shell_xpm, | |
635 tb_find_prev_xpm, | |
636 tb_find_next_xpm, | |
637 tb_find_help_xpm, | |
638 tb_make_xpm, | |
639 tb_jump_xpm, | |
640 tb_ctags_xpm, | |
641 tb_vsplit_xpm, | |
642 tb_maxwidth_xpm, | |
643 tb_minwidth_xpm, | |
644 tb_exit_xpm | |
645 }; | |
646 | |
647 /* | |
648 * creates a blank pixmap using tb_blank | |
649 */ | |
650 static void | |
651 pixmap_create_from_xpm(char **xpm, GdkPixmap **pixmap, GdkBitmap **mask) | |
652 { | |
653 *pixmap = gdk_pixmap_colormap_create_from_xpm_d( | |
654 NULL, | |
655 gtk_widget_get_colormap(gui.mainwin), | |
656 mask, | |
657 NULL, | |
658 xpm); | |
659 } | |
660 | |
661 /* | |
662 * creates a pixmap by using a built-in number | |
663 */ | |
664 static void | |
665 pixmap_create_by_num(int pixmap_num, GdkPixmap **pixmap, GdkBitmap **mask) | |
666 { | |
667 if (pixmap_num >= 0 && pixmap_num < (sizeof(built_in_pixmaps) | |
668 / sizeof(built_in_pixmaps[0]))) | |
669 pixmap_create_from_xpm(built_in_pixmaps[pixmap_num], pixmap, mask); | |
670 } | |
671 | |
672 /* | |
673 * Creates a pixmap by using the pixmap "name" found in 'runtimepath'/bitmaps/ | |
674 */ | |
675 static void | |
676 pixmap_create_by_dir(char_u *name, GdkPixmap **pixmap, GdkBitmap **mask) | |
677 { | |
678 char_u full_pathname[MAXPATHL + 1]; | |
679 | |
680 if (gui_find_bitmap(name, full_pathname, "xpm") == OK) | |
681 *pixmap = gdk_pixmap_colormap_create_from_xpm( | |
682 NULL, | |
683 gtk_widget_get_colormap(gui.mainwin), | |
684 mask, | |
685 &gui.mainwin->style->bg[GTK_STATE_NORMAL], | |
686 (const char *)full_pathname); | |
687 } | |
688 | |
689 /* | |
690 * Creates a pixmap by using the pixmap "fname". | |
691 */ | |
692 static void | |
693 pixmap_create_from_file(char_u *fname, GdkPixmap **pixmap, GdkBitmap **mask) | |
694 { | |
695 *pixmap = gdk_pixmap_colormap_create_from_xpm( | |
696 NULL, | |
697 gtk_widget_get_colormap(gui.mainwin), | |
698 mask, | |
699 &gui.mainwin->style->bg[GTK_STATE_NORMAL], | |
700 (const char *)fname); | |
701 } | |
702 | |
703 # endif /* FEAT_TOOLBAR && !HAVE_GTK2 */ | |
704 | 424 |
705 void | 425 void |
706 gui_mch_add_menu_item(vimmenu_T *menu, int idx) | 426 gui_mch_add_menu_item(vimmenu_T *menu, int idx) |
707 { | 427 { |
708 vimmenu_T *parent; | 428 vimmenu_T *parent; |
722 gtk_toolbar_insert_space(toolbar, idx); | 442 gtk_toolbar_insert_space(toolbar, idx); |
723 menu->id = NULL; | 443 menu->id = NULL; |
724 } | 444 } |
725 else | 445 else |
726 { | 446 { |
727 # ifdef HAVE_GTK2 | |
728 char_u *text; | 447 char_u *text; |
729 char_u *tooltip; | 448 char_u *tooltip; |
730 | 449 |
731 text = CONVERT_TO_UTF8(menu->dname); | 450 text = CONVERT_TO_UTF8(menu->dname); |
732 tooltip = CONVERT_TO_UTF8(menu->strings[MENU_INDEX_TIP]); | 451 tooltip = CONVERT_TO_UTF8(menu->strings[MENU_INDEX_TIP]); |
749 gtk_signal_connect(GTK_OBJECT(menu->id), "focus_in_event", | 468 gtk_signal_connect(GTK_OBJECT(menu->id), "focus_in_event", |
750 GTK_SIGNAL_FUNC(toolbar_button_focus_in_event), NULL); | 469 GTK_SIGNAL_FUNC(toolbar_button_focus_in_event), NULL); |
751 | 470 |
752 CONVERT_TO_UTF8_FREE(text); | 471 CONVERT_TO_UTF8_FREE(text); |
753 CONVERT_TO_UTF8_FREE(tooltip); | 472 CONVERT_TO_UTF8_FREE(tooltip); |
754 | |
755 # else /* !HAVE_GTK2 */ | |
756 | |
757 GdkPixmap *pixmap = NULL; | |
758 GdkBitmap *mask = NULL; | |
759 | |
760 /* First try user specified bitmap, then builtin, the a blank. */ | |
761 if (menu->iconfile != NULL) | |
762 { | |
763 char_u buf[MAXPATHL + 1]; | |
764 | |
765 gui_find_iconfile(menu->iconfile, buf, "xpm"); | |
766 pixmap_create_from_file(buf, &pixmap, &mask); | |
767 } | |
768 if (pixmap == NULL && !menu->icon_builtin) | |
769 pixmap_create_by_dir(menu->name, &pixmap, &mask); | |
770 if (pixmap == NULL && menu->iconidx >= 0) | |
771 pixmap_create_by_num(menu->iconidx, &pixmap, &mask); | |
772 if (pixmap == NULL) | |
773 pixmap_create_from_xpm(tb_blank_xpm, &pixmap, &mask); | |
774 if (pixmap == NULL) | |
775 return; /* should at least have blank pixmap, but if not... */ | |
776 | |
777 menu->id = gtk_toolbar_insert_item( | |
778 toolbar, | |
779 (char *)(menu->dname), | |
780 (char *)(menu->strings[MENU_INDEX_TIP]), | |
781 (char *)(menu->dname), | |
782 gtk_pixmap_new(pixmap, mask), | |
783 GTK_SIGNAL_FUNC(menu_item_activate), | |
784 (gpointer)menu, | |
785 idx); | |
786 # endif /* !HAVE_GTK2 */ | |
787 } | 473 } |
788 } | 474 } |
789 else | 475 else |
790 # endif /* FEAT_TOOLBAR */ | 476 # endif /* FEAT_TOOLBAR */ |
791 { | 477 { |
836 void | 522 void |
837 gui_gtk_set_mnemonics(int enable) | 523 gui_gtk_set_mnemonics(int enable) |
838 { | 524 { |
839 vimmenu_T *menu; | 525 vimmenu_T *menu; |
840 char_u *name; | 526 char_u *name; |
841 # if !defined(HAVE_GTK2) && defined(GTK_USE_ACCEL) | |
842 guint accel_key; | |
843 # endif | |
844 | 527 |
845 for (menu = root_menu; menu != NULL; menu = menu->next) | 528 for (menu = root_menu; menu != NULL; menu = menu->next) |
846 { | 529 { |
847 if (menu->id == NULL) | 530 if (menu->id == NULL) |
848 continue; | 531 continue; |
849 | 532 |
850 # if defined(HAVE_GTK2) | |
851 name = translate_mnemonic_tag(menu->name, enable); | 533 name = translate_mnemonic_tag(menu->name, enable); |
852 gtk_label_set_text_with_mnemonic(GTK_LABEL(menu->label), | 534 gtk_label_set_text_with_mnemonic(GTK_LABEL(menu->label), |
853 (const char *)name); | 535 (const char *)name); |
854 vim_free(name); | 536 vim_free(name); |
855 # else | |
856 # if defined(GTK_USE_ACCEL) | |
857 name = translate_mnemonic_tag(menu->name, TRUE); | |
858 if (name != NULL) | |
859 { | |
860 accel_key = gtk_label_parse_uline(GTK_LABEL(menu->label), | |
861 (const char *)name); | |
862 if (accel_key != GDK_VoidSymbol) | |
863 gtk_widget_remove_accelerator(menu->id, gui.accel_group, | |
864 accel_key, GDK_MOD1_MASK); | |
865 if (enable && accel_key != GDK_VoidSymbol) | |
866 gtk_widget_add_accelerator(menu->id, "activate_item", | |
867 gui.accel_group, | |
868 accel_key, GDK_MOD1_MASK, | |
869 (GtkAccelFlags)0); | |
870 vim_free(name); | |
871 } | |
872 if (!enable) | |
873 { | |
874 name = translate_mnemonic_tag(menu->name, FALSE); | |
875 gtk_label_parse_uline(GTK_LABEL(menu->label), (const char *)name); | |
876 vim_free(name); | |
877 } | |
878 # endif | |
879 # endif | |
880 } | 537 } |
881 } | 538 } |
882 | 539 |
883 static void | 540 static void |
884 recurse_tearoffs(vimmenu_T *menu, int val) | 541 recurse_tearoffs(vimmenu_T *menu, int val) |
902 { | 559 { |
903 recurse_tearoffs(root_menu, enable); | 560 recurse_tearoffs(root_menu, enable); |
904 } | 561 } |
905 #endif /* FEAT_MENU */ | 562 #endif /* FEAT_MENU */ |
906 | 563 |
907 | 564 #if defined(FEAT_TOOLBAR) |
908 #if defined(FEAT_TOOLBAR) && !defined(HAVE_GTK2) | |
909 /* | |
910 * Seems like there's a hole in the GTK Toolbar API: there's no provision for | |
911 * removing an item from the toolbar. Therefore I need to resort to going | |
912 * really deeply into the internal widget structures. | |
913 * | |
914 * <danielk> I'm not sure the statement above is true -- at least with | |
915 * GTK+ 2 one can just call gtk_widget_destroy() and be done with it. | |
916 * It is true though that you couldn't remove space items before GTK+ 2 | |
917 * (without digging into the internals that is). But the code below | |
918 * doesn't seem to handle those either. Well, it's obsolete anyway. | |
919 */ | |
920 static void | |
921 toolbar_remove_item_by_text(GtkToolbar *tb, const char *text) | |
922 { | |
923 GtkContainer *container; | |
924 GList *childl; | |
925 GtkToolbarChild *gtbc; | |
926 | |
927 g_return_if_fail(tb != NULL); | |
928 g_return_if_fail(GTK_IS_TOOLBAR(tb)); | |
929 container = GTK_CONTAINER(&tb->container); | |
930 | |
931 for (childl = tb->children; childl; childl = childl->next) | |
932 { | |
933 gtbc = (GtkToolbarChild *)childl->data; | |
934 | |
935 if (gtbc->type != GTK_TOOLBAR_CHILD_SPACE | |
936 && strcmp(GTK_LABEL(gtbc->label)->label, text) == 0) | |
937 { | |
938 gboolean was_visible; | |
939 | |
940 was_visible = GTK_WIDGET_VISIBLE(gtbc->widget); | |
941 gtk_widget_unparent(gtbc->widget); | |
942 | |
943 tb->children = g_list_remove_link(tb->children, childl); | |
944 g_free(gtbc); | |
945 g_list_free(childl); | |
946 tb->num_children--; | |
947 | |
948 if (was_visible && GTK_WIDGET_VISIBLE(container)) | |
949 gtk_widget_queue_resize(GTK_WIDGET(container)); | |
950 | |
951 break; | |
952 } | |
953 } | |
954 } | |
955 #endif /* FEAT_TOOLBAR && !HAVE_GTK2 */ | |
956 | |
957 | |
958 #if defined(FEAT_TOOLBAR) && defined(HAVE_GTK2) | |
959 static int | 565 static int |
960 get_menu_position(vimmenu_T *menu) | 566 get_menu_position(vimmenu_T *menu) |
961 { | 567 { |
962 vimmenu_T *node; | 568 vimmenu_T *node; |
963 int idx = 0; | 569 int idx = 0; |
968 ++idx; | 574 ++idx; |
969 } | 575 } |
970 | 576 |
971 return idx; | 577 return idx; |
972 } | 578 } |
973 #endif /* FEAT_TOOLBAR && HAVE_GTK2 */ | 579 #endif /* FEAT_TOOLBAR */ |
974 | 580 |
975 | 581 |
976 #if defined(FEAT_TOOLBAR) || defined(PROTO) | 582 #if defined(FEAT_TOOLBAR) || defined(PROTO) |
977 void | 583 void |
978 gui_mch_menu_set_tip(vimmenu_T *menu) | 584 gui_mch_menu_set_tip(vimmenu_T *menu) |
980 if (menu->id != NULL && menu->parent != NULL | 586 if (menu->id != NULL && menu->parent != NULL |
981 && gui.toolbar != NULL && menu_is_toolbar(menu->parent->name)) | 587 && gui.toolbar != NULL && menu_is_toolbar(menu->parent->name)) |
982 { | 588 { |
983 char_u *tooltip; | 589 char_u *tooltip; |
984 | 590 |
985 # ifdef HAVE_GTK2 | |
986 tooltip = CONVERT_TO_UTF8(menu->strings[MENU_INDEX_TIP]); | 591 tooltip = CONVERT_TO_UTF8(menu->strings[MENU_INDEX_TIP]); |
987 if (tooltip == NULL || utf_valid_string(tooltip, NULL)) | 592 if (tooltip == NULL || utf_valid_string(tooltip, NULL)) |
988 /* Only set the tooltip when it's valid utf-8. */ | 593 /* Only set the tooltip when it's valid utf-8. */ |
989 # else | |
990 tooltip = menu->strings[MENU_INDEX_TIP]; | |
991 # endif | |
992 gtk_tooltips_set_tip(GTK_TOOLBAR(gui.toolbar)->tooltips, | 594 gtk_tooltips_set_tip(GTK_TOOLBAR(gui.toolbar)->tooltips, |
993 menu->id, (const char *)tooltip, NULL); | 595 menu->id, (const char *)tooltip, NULL); |
994 # ifdef HAVE_GTK2 | |
995 CONVERT_TO_UTF8_FREE(tooltip); | 596 CONVERT_TO_UTF8_FREE(tooltip); |
996 # endif | |
997 } | 597 } |
998 } | 598 } |
999 #endif /* FEAT_TOOLBAR */ | 599 #endif /* FEAT_TOOLBAR */ |
1000 | 600 |
1001 | 601 |
1007 gui_mch_destroy_menu(vimmenu_T *menu) | 607 gui_mch_destroy_menu(vimmenu_T *menu) |
1008 { | 608 { |
1009 # ifdef FEAT_TOOLBAR | 609 # ifdef FEAT_TOOLBAR |
1010 if (menu->parent != NULL && menu_is_toolbar(menu->parent->name)) | 610 if (menu->parent != NULL && menu_is_toolbar(menu->parent->name)) |
1011 { | 611 { |
1012 # ifdef HAVE_GTK2 | |
1013 if (menu_is_separator(menu->name)) | 612 if (menu_is_separator(menu->name)) |
1014 gtk_toolbar_remove_space(GTK_TOOLBAR(gui.toolbar), | 613 gtk_toolbar_remove_space(GTK_TOOLBAR(gui.toolbar), |
1015 get_menu_position(menu)); | 614 get_menu_position(menu)); |
1016 else if (menu->id != NULL) | 615 else if (menu->id != NULL) |
1017 gtk_widget_destroy(menu->id); | 616 gtk_widget_destroy(menu->id); |
1018 # else | |
1019 toolbar_remove_item_by_text(GTK_TOOLBAR(gui.toolbar), | |
1020 (const char *)menu->dname); | |
1021 # endif | |
1022 } | 617 } |
1023 else | 618 else |
1024 # endif /* FEAT_TOOLBAR */ | 619 # endif /* FEAT_TOOLBAR */ |
1025 { | 620 { |
1026 if (menu->submenu_id != NULL) | 621 if (menu->submenu_id != NULL) |
1053 adjustment->upper = max + 1; | 648 adjustment->upper = max + 1; |
1054 adjustment->page_size = size; | 649 adjustment->page_size = size; |
1055 adjustment->page_increment = size < 3L ? 1L : size - 2L; | 650 adjustment->page_increment = size < 3L ? 1L : size - 2L; |
1056 adjustment->step_increment = 1.0; | 651 adjustment->step_increment = 1.0; |
1057 | 652 |
1058 #ifdef HAVE_GTK2 | |
1059 g_signal_handler_block(GTK_OBJECT(adjustment), | 653 g_signal_handler_block(GTK_OBJECT(adjustment), |
1060 (gulong)sb->handler_id); | 654 (gulong)sb->handler_id); |
1061 #else | |
1062 gtk_signal_handler_block(GTK_OBJECT(adjustment), | |
1063 (guint)sb->handler_id); | |
1064 #endif | |
1065 gtk_adjustment_changed(adjustment); | 655 gtk_adjustment_changed(adjustment); |
1066 #ifdef HAVE_GTK2 | |
1067 g_signal_handler_unblock(GTK_OBJECT(adjustment), | 656 g_signal_handler_unblock(GTK_OBJECT(adjustment), |
1068 (gulong)sb->handler_id); | 657 (gulong)sb->handler_id); |
1069 #else | |
1070 gtk_signal_handler_unblock(GTK_OBJECT(adjustment), | |
1071 (guint)sb->handler_id); | |
1072 #endif | |
1073 } | 658 } |
1074 } | 659 } |
1075 | 660 |
1076 void | 661 void |
1077 gui_mch_set_scrollbar_pos(scrollbar_T *sb, int x, int y, int w, int h) | 662 gui_mch_set_scrollbar_pos(scrollbar_T *sb, int x, int y, int w, int h) |
1107 * HACK: Get the mouse pointer position, if it appears to be on an arrow | 692 * HACK: Get the mouse pointer position, if it appears to be on an arrow |
1108 * button set "dragging" to FALSE. This assumes square buttons! | 693 * button set "dragging" to FALSE. This assumes square buttons! |
1109 */ | 694 */ |
1110 if (sb != NULL) | 695 if (sb != NULL) |
1111 { | 696 { |
1112 #ifdef HAVE_GTK2 | |
1113 dragging = TRUE; | 697 dragging = TRUE; |
1114 | 698 |
1115 if (sb->wp != NULL) | 699 if (sb->wp != NULL) |
1116 { | 700 { |
1117 int x; | 701 int x; |
1138 dragging = FALSE; | 722 dragging = FALSE; |
1139 value = sb->wp->w_topline; | 723 value = sb->wp->w_topline; |
1140 } | 724 } |
1141 } | 725 } |
1142 } | 726 } |
1143 #else | |
1144 dragging = (GTK_RANGE(sb->id)->scroll_type == GTK_SCROLL_NONE); | |
1145 #endif | |
1146 } | 727 } |
1147 | 728 |
1148 gui_drag_scrollbar(sb, value, dragging); | 729 gui_drag_scrollbar(sb, value, dragging); |
1149 | |
1150 if (gtk_main_level() > 0) | |
1151 gtk_main_quit(); | |
1152 } | 730 } |
1153 | 731 |
1154 /* SBAR_VERT or SBAR_HORIZ */ | 732 /* SBAR_VERT or SBAR_HORIZ */ |
1155 void | 733 void |
1156 gui_mch_create_scrollbar(scrollbar_T *sb, int orient) | 734 gui_mch_create_scrollbar(scrollbar_T *sb, int orient) |
1192 | 770 |
1193 #if defined(FEAT_BROWSE) || defined(PROTO) | 771 #if defined(FEAT_BROWSE) || defined(PROTO) |
1194 /* | 772 /* |
1195 * Implementation of the file selector related stuff | 773 * Implementation of the file selector related stuff |
1196 */ | 774 */ |
1197 #if defined(HAVE_GTK2) && GTK_CHECK_VERSION(2,4,0) | 775 #if GTK_CHECK_VERSION(2,4,0) |
1198 /* This has been disabled, because the GTK library rewrites | 776 # define USE_FILE_CHOOSER |
1199 * ~/.recently-used.xbel every time the main loop is quit. For Vim that means | |
1200 * on just about any event. */ | |
1201 /* # define USE_FILE_CHOOSER */ | |
1202 #endif | 777 #endif |
1203 | 778 |
1204 #ifndef USE_FILE_CHOOSER | 779 #ifndef USE_FILE_CHOOSER |
1205 /*ARGSUSED*/ | |
1206 static void | 780 static void |
1207 browse_ok_cb(GtkWidget *widget, gpointer cbdata) | 781 browse_ok_cb(GtkWidget *widget UNUSED, gpointer cbdata) |
1208 { | 782 { |
1209 gui_T *vw = (gui_T *)cbdata; | 783 gui_T *vw = (gui_T *)cbdata; |
1210 | 784 |
1211 if (vw->browse_fname != NULL) | 785 if (vw->browse_fname != NULL) |
1212 g_free(vw->browse_fname); | 786 g_free(vw->browse_fname); |
1213 | 787 |
1214 vw->browse_fname = (char_u *)g_strdup(gtk_file_selection_get_filename( | 788 vw->browse_fname = (char_u *)g_strdup(gtk_file_selection_get_filename( |
1215 GTK_FILE_SELECTION(vw->filedlg))); | 789 GTK_FILE_SELECTION(vw->filedlg))); |
1216 gtk_widget_hide(vw->filedlg); | 790 gtk_widget_hide(vw->filedlg); |
1217 if (gtk_main_level() > 0) | 791 } |
1218 gtk_main_quit(); | 792 |
1219 } | |
1220 | |
1221 /*ARGSUSED*/ | |
1222 static void | 793 static void |
1223 browse_cancel_cb(GtkWidget *widget, gpointer cbdata) | 794 browse_cancel_cb(GtkWidget *widget UNUSED, gpointer cbdata) |
1224 { | 795 { |
1225 gui_T *vw = (gui_T *)cbdata; | 796 gui_T *vw = (gui_T *)cbdata; |
1226 | 797 |
1227 if (vw->browse_fname != NULL) | 798 if (vw->browse_fname != NULL) |
1228 { | 799 { |
1229 g_free(vw->browse_fname); | 800 g_free(vw->browse_fname); |
1230 vw->browse_fname = NULL; | 801 vw->browse_fname = NULL; |
1231 } | 802 } |
1232 gtk_widget_hide(vw->filedlg); | 803 gtk_widget_hide(vw->filedlg); |
1233 if (gtk_main_level() > 0) | 804 } |
1234 gtk_main_quit(); | 805 |
1235 } | |
1236 | |
1237 /*ARGSUSED*/ | |
1238 static gboolean | 806 static gboolean |
1239 browse_destroy_cb(GtkWidget * widget) | 807 browse_destroy_cb(GtkWidget *widget UNUSED) |
1240 { | 808 { |
1241 if (gui.browse_fname != NULL) | 809 if (gui.browse_fname != NULL) |
1242 { | 810 { |
1243 g_free(gui.browse_fname); | 811 g_free(gui.browse_fname); |
1244 gui.browse_fname = NULL; | 812 gui.browse_fname = NULL; |
1245 } | 813 } |
1246 gui.filedlg = NULL; | 814 gui.filedlg = NULL; |
1247 | 815 gtk_main_quit(); |
1248 if (gtk_main_level() > 0) | |
1249 gtk_main_quit(); | |
1250 | |
1251 return FALSE; | 816 return FALSE; |
1252 } | 817 } |
1253 #endif | 818 #endif |
1254 | 819 |
1255 /* | 820 /* |
1260 * dflt default name | 825 * dflt default name |
1261 * ext not used (extension added) | 826 * ext not used (extension added) |
1262 * initdir initial directory, NULL for current dir | 827 * initdir initial directory, NULL for current dir |
1263 * filter not used (file name filter) | 828 * filter not used (file name filter) |
1264 */ | 829 */ |
1265 /*ARGSUSED*/ | |
1266 char_u * | 830 char_u * |
1267 gui_mch_browse(int saving, | 831 gui_mch_browse(int saving UNUSED, |
1268 char_u *title, | 832 char_u *title, |
1269 char_u *dflt, | 833 char_u *dflt, |
1270 char_u *ext, | 834 char_u *ext UNUSED, |
1271 char_u *initdir, | 835 char_u *initdir, |
1272 char_u *filter) | 836 char_u *filter UNUSED) |
1273 { | 837 { |
1274 #ifdef USE_FILE_CHOOSER | 838 #ifdef USE_FILE_CHOOSER |
1275 GtkWidget *fc; | 839 GtkWidget *fc; |
1276 #endif | 840 #endif |
1277 char_u dirbuf[MAXPATHL]; | 841 char_u dirbuf[MAXPATHL]; |
1278 | 842 |
1279 # ifdef HAVE_GTK2 | |
1280 title = CONVERT_TO_UTF8(title); | 843 title = CONVERT_TO_UTF8(title); |
1281 # endif | |
1282 | 844 |
1283 /* GTK has a bug, it only works with an absolute path. */ | 845 /* GTK has a bug, it only works with an absolute path. */ |
1284 if (initdir == NULL || *initdir == NUL) | 846 if (initdir == NULL || *initdir == NUL) |
1285 mch_dirname(dirbuf, MAXPATHL); | 847 mch_dirname(dirbuf, MAXPATHL); |
1286 else if (vim_FullName(initdir, dirbuf, MAXPATHL - 2, FALSE) == FAIL) | 848 else if (vim_FullName(initdir, dirbuf, MAXPATHL - 2, FALSE) == FAIL) |
1301 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | 863 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
1302 saving ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, | 864 saving ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, |
1303 NULL); | 865 NULL); |
1304 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fc), | 866 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fc), |
1305 (const gchar *)dirbuf); | 867 (const gchar *)dirbuf); |
868 if (saving && dflt != NULL && *dflt != NUL) | |
869 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(fc), (char *)dflt); | |
1306 | 870 |
1307 gui.browse_fname = NULL; | 871 gui.browse_fname = NULL; |
1308 if (gtk_dialog_run(GTK_DIALOG(fc)) == GTK_RESPONSE_ACCEPT) | 872 if (gtk_dialog_run(GTK_DIALOG(fc)) == GTK_RESPONSE_ACCEPT) |
1309 { | 873 { |
1310 char *filename; | 874 char *filename; |
1346 && STRLEN(dirbuf) + 2 + STRLEN(dflt) < MAXPATHL) | 910 && STRLEN(dirbuf) + 2 + STRLEN(dflt) < MAXPATHL) |
1347 STRCAT(dirbuf, dflt); | 911 STRCAT(dirbuf, dflt); |
1348 | 912 |
1349 gtk_file_selection_set_filename(GTK_FILE_SELECTION(gui.filedlg), | 913 gtk_file_selection_set_filename(GTK_FILE_SELECTION(gui.filedlg), |
1350 (const gchar *)dirbuf); | 914 (const gchar *)dirbuf); |
1351 # ifndef HAVE_GTK2 | |
1352 gui_gtk_position_in_parent(GTK_WIDGET(gui.mainwin), | |
1353 GTK_WIDGET(gui.filedlg), VW_POS_MOUSE); | |
1354 # endif | |
1355 | 915 |
1356 gtk_widget_show(gui.filedlg); | 916 gtk_widget_show(gui.filedlg); |
1357 while (gui.filedlg && GTK_WIDGET_DRAWABLE(gui.filedlg)) | 917 gtk_main(); |
1358 gtk_main_iteration_do(TRUE); | |
1359 #endif | 918 #endif |
1360 | 919 |
1361 # ifdef HAVE_GTK2 | |
1362 CONVERT_TO_UTF8_FREE(title); | 920 CONVERT_TO_UTF8_FREE(title); |
1363 # endif | |
1364 if (gui.browse_fname == NULL) | 921 if (gui.browse_fname == NULL) |
1365 return NULL; | 922 return NULL; |
1366 | 923 |
1367 /* shorten the file name if possible */ | 924 /* shorten the file name if possible */ |
1368 return vim_strsave(shorten_fname1(gui.browse_fname)); | 925 return vim_strsave(shorten_fname1(gui.browse_fname)); |
1369 } | 926 } |
1370 | |
1371 #if defined(HAVE_GTK2) || defined(PROTO) | |
1372 | 927 |
1373 /* | 928 /* |
1374 * Put up a directory selector | 929 * Put up a directory selector |
1375 * Returns the selected name in allocated memory, or NULL for Cancel. | 930 * Returns the selected name in allocated memory, or NULL for Cancel. |
1376 * title title for the window | 931 * title title for the window |
1377 * dflt default name | 932 * dflt default name |
1378 * initdir initial directory, NULL for current dir | 933 * initdir initial directory, NULL for current dir |
1379 */ | 934 */ |
1380 /*ARGSUSED*/ | |
1381 char_u * | 935 char_u * |
1382 gui_mch_browsedir( | 936 gui_mch_browsedir( |
1383 char_u *title, | 937 char_u *title, |
1384 char_u *initdir) | 938 char_u *initdir) |
1385 { | 939 { |
1432 # else | 986 # else |
1433 /* For GTK 2.2 and earlier: fall back to ordinary file selector. */ | 987 /* For GTK 2.2 and earlier: fall back to ordinary file selector. */ |
1434 return gui_mch_browse(0, title, NULL, NULL, initdir, NULL); | 988 return gui_mch_browse(0, title, NULL, NULL, initdir, NULL); |
1435 # endif | 989 # endif |
1436 } | 990 } |
1437 #endif | |
1438 | 991 |
1439 | 992 |
1440 #endif /* FEAT_BROWSE */ | 993 #endif /* FEAT_BROWSE */ |
1441 | 994 |
1442 #if defined(FEAT_GUI_DIALOG) && !defined(HAVE_GTK2) | 995 #if defined(FEAT_GUI_DIALOG) || defined(PROTO) |
1443 | |
1444 static char_u *dialog_textfield = NULL; | |
1445 static GtkWidget *dialog_textentry; | |
1446 | |
1447 static void | |
1448 dlg_destroy(GtkWidget *dlg) | |
1449 { | |
1450 if (dialog_textfield != NULL) | |
1451 { | |
1452 const char *text; | |
1453 | |
1454 text = gtk_entry_get_text(GTK_ENTRY(dialog_textentry)); | |
1455 vim_strncpy(dialog_textfield, (char_u *)text, IOSIZE - 1); | |
1456 } | |
1457 | |
1458 /* Destroy the dialog, will break the waiting loop. */ | |
1459 gtk_widget_destroy(dlg); | |
1460 } | |
1461 | |
1462 # ifdef FEAT_GUI_GNOME | |
1463 /* ARGSUSED */ | |
1464 static int | |
1465 gui_gnome_dialog( int type, | |
1466 char_u *title, | |
1467 char_u *message, | |
1468 char_u *buttons, | |
1469 int dfltbutton, | |
1470 char_u *textfield) | |
1471 { | |
1472 GtkWidget *dlg; | |
1473 char *gdtype; | |
1474 char_u *buttons_copy, *p, *next; | |
1475 char **buttons_list; | |
1476 int butcount, cur; | |
1477 | |
1478 /* make a copy, so that we can insert NULs */ | |
1479 if ((buttons_copy = vim_strsave(buttons)) == NULL) | |
1480 return -1; | |
1481 | |
1482 /* determine exact number of buttons and allocate array to hold them */ | |
1483 for (butcount = 0, p = buttons; *p; p++) | |
1484 { | |
1485 if (*p == '\n') | |
1486 butcount++; | |
1487 } | |
1488 butcount++; | |
1489 buttons_list = g_new0(char *, butcount + 1); | |
1490 | |
1491 /* Add pixmap */ | |
1492 switch (type) | |
1493 { | |
1494 case VIM_ERROR: | |
1495 gdtype = GNOME_MESSAGE_BOX_ERROR; | |
1496 break; | |
1497 case VIM_WARNING: | |
1498 gdtype = GNOME_MESSAGE_BOX_WARNING; | |
1499 break; | |
1500 case VIM_INFO: | |
1501 gdtype = GNOME_MESSAGE_BOX_INFO; | |
1502 break; | |
1503 case VIM_QUESTION: | |
1504 gdtype = GNOME_MESSAGE_BOX_QUESTION; | |
1505 break; | |
1506 default: | |
1507 gdtype = GNOME_MESSAGE_BOX_GENERIC; | |
1508 }; | |
1509 | |
1510 p = buttons_copy; | |
1511 for (cur = 0; cur < butcount; ++cur) | |
1512 { | |
1513 for (next = p; *next; ++next) | |
1514 { | |
1515 if (*next == DLG_HOTKEY_CHAR) | |
1516 STRMOVE(next, next + 1); | |
1517 if (*next == DLG_BUTTON_SEP) | |
1518 { | |
1519 *next++ = NUL; | |
1520 break; | |
1521 } | |
1522 } | |
1523 | |
1524 /* this should probably go into a table, but oh well */ | |
1525 if (g_strcasecmp((char *)p, "Ok") == 0) | |
1526 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_OK); | |
1527 else if (g_strcasecmp((char *)p, "Cancel") == 0) | |
1528 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_CANCEL); | |
1529 else if (g_strcasecmp((char *)p, "Yes") == 0) | |
1530 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_YES); | |
1531 else if (g_strcasecmp((char *)p, "No") == 0) | |
1532 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_NO); | |
1533 else if (g_strcasecmp((char *)p, "Close") == 0) | |
1534 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_CLOSE); | |
1535 else if (g_strcasecmp((char *)p, "Help") == 0) | |
1536 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_HELP); | |
1537 else if (g_strcasecmp((char *)p, "Apply") == 0) | |
1538 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_APPLY); | |
1539 #if 0 | |
1540 /* | |
1541 * these aren't really used that often anyway, but are listed here as | |
1542 * placeholders in case we need them. | |
1543 */ | |
1544 else if (g_strcasecmp((char *)p, "Next") == 0) | |
1545 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_NEXT); | |
1546 else if (g_strcasecmp((char *)p, "Prev") == 0) | |
1547 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_PREV); | |
1548 else if (g_strcasecmp((char *)p, "Up") == 0) | |
1549 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_UP); | |
1550 else if (g_strcasecmp((char *)p, "Down") == 0) | |
1551 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_DOWN); | |
1552 else if (g_strcasecmp((char *)p, "Font") == 0) | |
1553 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_FONT); | |
1554 #endif | |
1555 else | |
1556 buttons_list[cur] = g_strdup((char *)p); | |
1557 | |
1558 if (*next == NUL) | |
1559 break; | |
1560 | |
1561 p = next; | |
1562 } | |
1563 vim_free(buttons_copy); | |
1564 | |
1565 dlg = gnome_message_box_newv((const char *)message, | |
1566 (const char *)gdtype, | |
1567 (const char **)buttons_list); | |
1568 for (cur = 0; cur < butcount; ++cur) | |
1569 g_free(buttons_list[cur]); | |
1570 g_free(buttons_list); | |
1571 | |
1572 dialog_textfield = textfield; | |
1573 if (textfield != NULL) | |
1574 { | |
1575 /* Add text entry field */ | |
1576 dialog_textentry = gtk_entry_new(); | |
1577 gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dlg)->vbox), dialog_textentry, | |
1578 TRUE, TRUE, 0); | |
1579 gtk_entry_set_text(GTK_ENTRY(dialog_textentry), | |
1580 (const gchar *)textfield); | |
1581 gtk_entry_select_region(GTK_ENTRY(dialog_textentry), 0, | |
1582 STRLEN(textfield)); | |
1583 gtk_entry_set_max_length(GTK_ENTRY(dialog_textentry), IOSIZE - 1); | |
1584 gtk_entry_set_position(GTK_ENTRY(dialog_textentry), STRLEN(textfield)); | |
1585 gtk_widget_show(dialog_textentry); | |
1586 gtk_window_set_focus(GTK_WINDOW(dlg), dialog_textentry); | |
1587 } | |
1588 | |
1589 gtk_signal_connect_object(GTK_OBJECT(dlg), "destroy", | |
1590 GTK_SIGNAL_FUNC(dlg_destroy), GTK_OBJECT(dlg)); | |
1591 gnome_dialog_set_default(GNOME_DIALOG(dlg), dfltbutton + 1); | |
1592 gui_gtk_position_in_parent(GTK_WIDGET(gui.mainwin), | |
1593 GTK_WIDGET(dlg), VW_POS_MOUSE); | |
1594 | |
1595 return (1 + gnome_dialog_run_and_close(GNOME_DIALOG(dlg))); | |
1596 } | |
1597 | |
1598 # endif /* FEAT_GUI_GNOME */ | |
1599 | |
1600 typedef struct _ButtonData | |
1601 { | |
1602 int *status; | |
1603 int index; | |
1604 GtkWidget *dialog; | |
1605 } ButtonData; | |
1606 | |
1607 typedef struct _CancelData | |
1608 { | |
1609 int *status; | |
1610 int ignore_enter; | |
1611 GtkWidget *dialog; | |
1612 } CancelData; | |
1613 | |
1614 /* ARGSUSED */ | |
1615 static void | |
1616 dlg_button_clicked(GtkWidget * widget, ButtonData *data) | |
1617 { | |
1618 *(data->status) = data->index + 1; | |
1619 dlg_destroy(data->dialog); | |
1620 } | |
1621 | |
1622 /* | |
1623 * This makes the Escape key equivalent to the cancel button. | |
1624 */ | |
1625 /*ARGSUSED*/ | |
1626 static int | |
1627 dlg_key_press_event(GtkWidget *widget, GdkEventKey *event, CancelData *data) | |
1628 { | |
1629 /* Ignore hitting Enter (or Space) when there is no default button. */ | |
1630 if (data->ignore_enter && (event->keyval == GDK_Return | |
1631 || event->keyval == ' ')) | |
1632 return TRUE; | |
1633 else /* A different key was pressed, return to normal behavior */ | |
1634 data->ignore_enter = FALSE; | |
1635 | |
1636 if (event->keyval != GDK_Escape && event->keyval != GDK_Return) | |
1637 return FALSE; | |
1638 | |
1639 /* The result value of 0 from a dialog is signaling cancelation. | |
1640 * 1 means OK. */ | |
1641 *(data->status) = (event->keyval == GDK_Return); | |
1642 dlg_destroy(data->dialog); | |
1643 | |
1644 return TRUE; | |
1645 } | |
1646 | |
1647 /* | |
1648 * Callback function for when the dialog was destroyed by a window manager. | |
1649 */ | |
1650 static void | |
1651 dlg_destroy_cb(int *p) | |
1652 { | |
1653 *p = TRUE; /* set dialog_destroyed to break out of the loop */ | |
1654 if (gtk_main_level() > 0) | |
1655 gtk_main_quit(); | |
1656 } | |
1657 | |
1658 /* ARGSUSED */ | |
1659 int | |
1660 gui_mch_dialog( int type, /* type of dialog */ | |
1661 char_u *title, /* title of dialog */ | |
1662 char_u *message, /* message text */ | |
1663 char_u *buttons, /* names of buttons */ | |
1664 int def_but, /* default button */ | |
1665 char_u *textfield) /* text for textfield or NULL */ | |
1666 { | |
1667 char_u *names; | |
1668 char_u *p; | |
1669 int i; | |
1670 int butcount; | |
1671 int dialog_status = -1; | |
1672 int dialog_destroyed = FALSE; | |
1673 int vertical; | |
1674 | |
1675 GtkWidget *dialog; | |
1676 GtkWidget *frame; | |
1677 GtkWidget *vbox; | |
1678 GtkWidget *table; | |
1679 GtkWidget *dialogmessage; | |
1680 GtkWidget *action_area; | |
1681 GtkWidget *sub_area; | |
1682 GtkWidget *separator; | |
1683 GtkAccelGroup *accel_group; | |
1684 GtkWidget *pixmap; | |
1685 GdkPixmap *icon = NULL; | |
1686 GdkBitmap *mask = NULL; | |
1687 char **icon_data = NULL; | |
1688 | |
1689 GtkWidget **button; | |
1690 ButtonData *data; | |
1691 CancelData cancel_data; | |
1692 | |
1693 /* if our pointer is currently hidden, then we should show it. */ | |
1694 gui_mch_mousehide(FALSE); | |
1695 | |
1696 # ifdef FEAT_GUI_GNOME | |
1697 /* If Gnome is available, use it for the dialog. */ | |
1698 if (gtk_socket_id == 0) | |
1699 return gui_gnome_dialog(type, title, message, buttons, def_but, | |
1700 textfield); | |
1701 # endif | |
1702 | |
1703 if (title == NULL) | |
1704 title = (char_u *)_("Vim dialog..."); | |
1705 | |
1706 if ((type < 0) || (type > VIM_LAST_TYPE)) | |
1707 type = VIM_GENERIC; | |
1708 | |
1709 /* Check 'v' flag in 'guioptions': vertical button placement. */ | |
1710 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL); | |
1711 | |
1712 dialog = gtk_window_new(GTK_WINDOW_DIALOG); | |
1713 gtk_window_set_title(GTK_WINDOW(dialog), (const gchar *)title); | |
1714 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gui.mainwin)); | |
1715 gtk_widget_realize(dialog); | |
1716 gdk_window_set_decorations(dialog->window, GDK_DECOR_BORDER); | |
1717 gdk_window_set_functions(dialog->window, GDK_FUNC_MOVE); | |
1718 | |
1719 cancel_data.status = &dialog_status; | |
1720 cancel_data.dialog = dialog; | |
1721 gtk_signal_connect_after(GTK_OBJECT(dialog), "key_press_event", | |
1722 GTK_SIGNAL_FUNC(dlg_key_press_event), | |
1723 (gpointer) &cancel_data); | |
1724 /* Catch the destroy signal, otherwise we don't notice a window manager | |
1725 * destroying the dialog window. */ | |
1726 gtk_signal_connect_object(GTK_OBJECT(dialog), "destroy", | |
1727 GTK_SIGNAL_FUNC(dlg_destroy_cb), | |
1728 (gpointer)&dialog_destroyed); | |
1729 | |
1730 gtk_grab_add(dialog); | |
1731 | |
1732 /* this makes it look beter on Motif style window managers */ | |
1733 frame = gtk_frame_new(NULL); | |
1734 gtk_container_add(GTK_CONTAINER(dialog), frame); | |
1735 gtk_widget_show(frame); | |
1736 | |
1737 vbox = gtk_vbox_new(FALSE, 0); | |
1738 gtk_container_add(GTK_CONTAINER(frame), vbox); | |
1739 gtk_widget_show(vbox); | |
1740 | |
1741 table = gtk_table_new(1, 3, FALSE); | |
1742 gtk_table_set_row_spacings(GTK_TABLE(table), 4); | |
1743 gtk_table_set_col_spacings(GTK_TABLE(table), 8); | |
1744 gtk_container_border_width(GTK_CONTAINER(table), 4); | |
1745 gtk_box_pack_start(GTK_BOX(vbox), table, 4, 4, 0); | |
1746 gtk_widget_show(table); | |
1747 | |
1748 /* Add pixmap */ | |
1749 switch (type) | |
1750 { | |
1751 case VIM_GENERIC: | |
1752 icon_data = generic_xpm; | |
1753 break; | |
1754 case VIM_ERROR: | |
1755 icon_data = error_xpm; | |
1756 break; | |
1757 case VIM_WARNING: | |
1758 icon_data = alert_xpm; | |
1759 break; | |
1760 case VIM_INFO: | |
1761 icon_data = info_xpm; | |
1762 break; | |
1763 case VIM_QUESTION: | |
1764 icon_data = quest_xpm; | |
1765 break; | |
1766 default: | |
1767 icon_data = generic_xpm; | |
1768 }; | |
1769 icon = gdk_pixmap_colormap_create_from_xpm_d(NULL, | |
1770 gtk_widget_get_colormap(dialog), | |
1771 &mask, NULL, icon_data); | |
1772 if (icon) | |
1773 { | |
1774 pixmap = gtk_pixmap_new(icon, mask); | |
1775 /* gtk_misc_set_alignment(GTK_MISC(pixmap), 0.5, 0.5); */ | |
1776 gtk_table_attach_defaults(GTK_TABLE(table), pixmap, 0, 1, 0, 1); | |
1777 gtk_widget_show(pixmap); | |
1778 } | |
1779 | |
1780 /* Add label */ | |
1781 dialogmessage = gtk_label_new((const gchar *)message); | |
1782 gtk_table_attach_defaults(GTK_TABLE(table), dialogmessage, 1, 2, 0, 1); | |
1783 gtk_widget_show(dialogmessage); | |
1784 | |
1785 dialog_textfield = textfield; | |
1786 if (textfield != NULL) | |
1787 { | |
1788 /* Add text entry field */ | |
1789 dialog_textentry = gtk_entry_new(); | |
1790 gtk_widget_set_usize(dialog_textentry, 400, -2); | |
1791 gtk_box_pack_start(GTK_BOX(vbox), dialog_textentry, TRUE, TRUE, 0); | |
1792 gtk_entry_set_text(GTK_ENTRY(dialog_textentry), | |
1793 (const gchar *)textfield); | |
1794 gtk_entry_select_region(GTK_ENTRY(dialog_textentry), 0, | |
1795 STRLEN(textfield)); | |
1796 gtk_entry_set_max_length(GTK_ENTRY(dialog_textentry), IOSIZE - 1); | |
1797 gtk_entry_set_position(GTK_ENTRY(dialog_textentry), STRLEN(textfield)); | |
1798 gtk_widget_show(dialog_textentry); | |
1799 } | |
1800 | |
1801 /* Add box for buttons */ | |
1802 action_area = gtk_hbox_new(FALSE, 0); | |
1803 gtk_container_border_width(GTK_CONTAINER(action_area), 4); | |
1804 gtk_box_pack_end(GTK_BOX(vbox), action_area, FALSE, TRUE, 0); | |
1805 gtk_widget_show(action_area); | |
1806 | |
1807 /* Add a [vh]box in the hbox to center the buttons in the dialog. */ | |
1808 if (vertical) | |
1809 sub_area = gtk_vbox_new(FALSE, 0); | |
1810 else | |
1811 sub_area = gtk_hbox_new(FALSE, 0); | |
1812 gtk_container_set_border_width(GTK_CONTAINER(sub_area), 0); | |
1813 gtk_box_pack_start(GTK_BOX(action_area), sub_area, TRUE, FALSE, 0); | |
1814 gtk_widget_show(sub_area); | |
1815 | |
1816 /* | |
1817 * Create the buttons. | |
1818 */ | |
1819 | |
1820 /* | |
1821 * Translate the Vim accelerator character into an underscore for GTK+. | |
1822 * Double underscores to keep them in the label. | |
1823 */ | |
1824 /* count the number of underscores */ | |
1825 i = 1; | |
1826 for (p = buttons; *p; ++p) | |
1827 if (*p == '_') | |
1828 ++i; | |
1829 | |
1830 /* make a copy of "buttons" with the translated characters */ | |
1831 names = alloc(STRLEN(buttons) + i); | |
1832 if (names == NULL) | |
1833 return -1; | |
1834 | |
1835 p = names; | |
1836 for (i = 0; buttons[i]; ++i) | |
1837 { | |
1838 if (buttons[i] == DLG_HOTKEY_CHAR) | |
1839 *p++ = '_'; | |
1840 else | |
1841 { | |
1842 if (buttons[i] == '_') | |
1843 *p++ = '_'; | |
1844 *p++ = buttons[i]; | |
1845 } | |
1846 } | |
1847 *p = NUL; | |
1848 | |
1849 /* Count the number of buttons and allocate button[] and data[]. */ | |
1850 butcount = 1; | |
1851 for (p = names; *p; ++p) | |
1852 if (*p == DLG_BUTTON_SEP) | |
1853 ++butcount; | |
1854 button = (GtkWidget **)alloc((unsigned)(butcount * sizeof(GtkWidget *))); | |
1855 data = (ButtonData *)alloc((unsigned)(butcount * sizeof(ButtonData))); | |
1856 if (button == NULL || data == NULL) | |
1857 { | |
1858 vim_free(names); | |
1859 vim_free(button); | |
1860 vim_free(data); | |
1861 return -1; | |
1862 } | |
1863 | |
1864 /* Attach the new accelerator group to the window. */ | |
1865 accel_group = gtk_accel_group_new(); | |
1866 gtk_accel_group_attach(accel_group, GTK_OBJECT(dialog)); | |
1867 | |
1868 p = names; | |
1869 for (butcount = 0; *p; ++butcount) | |
1870 { | |
1871 char_u *next; | |
1872 GtkWidget *label; | |
1873 # ifdef GTK_USE_ACCEL | |
1874 guint accel_key; | |
1875 # endif | |
1876 | |
1877 /* Chunk out this single button. */ | |
1878 for (next = p; *next; ++next) | |
1879 { | |
1880 if (*next == DLG_BUTTON_SEP) | |
1881 { | |
1882 *next++ = NUL; | |
1883 break; | |
1884 } | |
1885 } | |
1886 | |
1887 button[butcount] = gtk_button_new(); | |
1888 GTK_WIDGET_SET_FLAGS(button[butcount], GTK_CAN_DEFAULT); | |
1889 | |
1890 label = gtk_accel_label_new(""); | |
1891 gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(label), dialog); | |
1892 | |
1893 # ifdef GTK_USE_ACCEL | |
1894 accel_key = gtk_label_parse_uline(GTK_LABEL(label), (const gchar *)p); | |
1895 /* Don't add accelator if 'winaltkeys' is "no". */ | |
1896 if (accel_key != GDK_VoidSymbol) | |
1897 { | |
1898 gtk_widget_add_accelerator(button[butcount], | |
1899 "clicked", | |
1900 accel_group, | |
1901 accel_key, 0, | |
1902 (GtkAccelFlags)0); | |
1903 } | |
1904 # else | |
1905 (void)gtk_label_parse_uline(GTK_LABEL(label), (const gchar *)p); | |
1906 # endif | |
1907 | |
1908 gtk_container_add(GTK_CONTAINER(button[butcount]), label); | |
1909 gtk_widget_show_all(button[butcount]); | |
1910 | |
1911 data[butcount].status = &dialog_status; | |
1912 data[butcount].index = butcount; | |
1913 data[butcount].dialog = dialog; | |
1914 gtk_signal_connect(GTK_OBJECT(button[butcount]), | |
1915 (const char *)"clicked", | |
1916 GTK_SIGNAL_FUNC(dlg_button_clicked), | |
1917 (gpointer) &data[butcount]); | |
1918 | |
1919 gtk_box_pack_start(GTK_BOX(sub_area), button[butcount], | |
1920 TRUE, FALSE, 0); | |
1921 p = next; | |
1922 } | |
1923 | |
1924 vim_free(names); | |
1925 | |
1926 cancel_data.ignore_enter = FALSE; | |
1927 if (butcount > 0) | |
1928 { | |
1929 --def_but; /* 1 is first button */ | |
1930 if (def_but >= butcount) | |
1931 def_but = -1; | |
1932 if (def_but >= 0) | |
1933 { | |
1934 gtk_widget_grab_focus(button[def_but]); | |
1935 gtk_widget_grab_default(button[def_but]); | |
1936 } | |
1937 else | |
1938 /* No default, ignore hitting Enter. */ | |
1939 cancel_data.ignore_enter = TRUE; | |
1940 } | |
1941 | |
1942 if (textfield != NULL) | |
1943 gtk_window_set_focus(GTK_WINDOW(dialog), dialog_textentry); | |
1944 | |
1945 separator = gtk_hseparator_new(); | |
1946 gtk_box_pack_end(GTK_BOX(vbox), separator, FALSE, TRUE, 0); | |
1947 gtk_widget_show(separator); | |
1948 | |
1949 dialog_status = -1; | |
1950 | |
1951 gui_gtk_position_in_parent(GTK_WIDGET(gui.mainwin), | |
1952 GTK_WIDGET(dialog), VW_POS_MOUSE); | |
1953 | |
1954 gtk_widget_show(dialog); | |
1955 | |
1956 /* loop here until the dialog goes away */ | |
1957 while (dialog_status == -1 && !dialog_destroyed | |
1958 && GTK_WIDGET_DRAWABLE(dialog)) | |
1959 gtk_main_iteration_do(TRUE); | |
1960 | |
1961 if (dialog_status < 0) | |
1962 dialog_status = 0; | |
1963 if (dialog_status != 1 && textfield != NULL) | |
1964 *textfield = NUL; /* dialog was cancelled */ | |
1965 | |
1966 /* let the garbage collector know that we don't need it any longer */ | |
1967 gtk_accel_group_unref(accel_group); | |
1968 | |
1969 vim_free(button); | |
1970 vim_free(data); | |
1971 | |
1972 return dialog_status; | |
1973 } | |
1974 | |
1975 #endif /* FEAT_GUI_DIALOG && !HAVE_GTK2 */ | |
1976 | |
1977 | |
1978 #if (defined(FEAT_GUI_DIALOG) && defined(HAVE_GTK2)) || defined(PROTO) | |
1979 | 996 |
1980 static GtkWidget * | 997 static GtkWidget * |
1981 create_message_dialog(int type, char_u *title, char_u *message) | 998 create_message_dialog(int type, char_u *title, char_u *message) |
1982 { | 999 { |
1983 GtkWidget *dialog; | 1000 GtkWidget *dialog; |
2213 int ignore_enter; /* no default button, ignore "Enter" */ | 1230 int ignore_enter; /* no default button, ignore "Enter" */ |
2214 int noalt; /* accept accelerators without Alt */ | 1231 int noalt; /* accept accelerators without Alt */ |
2215 GtkDialog *dialog; /* Widget of the dialog */ | 1232 GtkDialog *dialog; /* Widget of the dialog */ |
2216 } DialogInfo; | 1233 } DialogInfo; |
2217 | 1234 |
2218 /*ARGSUSED2*/ | |
2219 static gboolean | 1235 static gboolean |
2220 dialog_key_press_event_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | 1236 dialog_key_press_event_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) |
2221 { | 1237 { |
2222 DialogInfo *di = (DialogInfo *)data; | 1238 DialogInfo *di = (DialogInfo *)data; |
2223 | 1239 |
2269 GtkWidget *alignment; | 1285 GtkWidget *alignment; |
2270 | 1286 |
2271 entry = gtk_entry_new(); | 1287 entry = gtk_entry_new(); |
2272 gtk_widget_show(entry); | 1288 gtk_widget_show(entry); |
2273 | 1289 |
1290 /* Make Enter work like pressing OK. */ | |
1291 gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE); | |
1292 | |
2274 text = CONVERT_TO_UTF8(textfield); | 1293 text = CONVERT_TO_UTF8(textfield); |
2275 gtk_entry_set_text(GTK_ENTRY(entry), (const char *)text); | 1294 gtk_entry_set_text(GTK_ENTRY(entry), (const char *)text); |
2276 CONVERT_TO_UTF8_FREE(text); | 1295 CONVERT_TO_UTF8_FREE(text); |
2277 | 1296 |
2278 alignment = gtk_alignment_new((float)0.5, (float)0.5, | 1297 alignment = gtk_alignment_new((float)0.5, (float)0.5, |
2322 CONVERT_FROM_UTF8_FREE(text); | 1341 CONVERT_FROM_UTF8_FREE(text); |
2323 } | 1342 } |
2324 gtk_widget_destroy(dialog); | 1343 gtk_widget_destroy(dialog); |
2325 } | 1344 } |
2326 | 1345 |
2327 /* Terrible hack: When the text area still has focus when we remove the | |
2328 * dialog, somehow gvim loses window focus. This is with "point to type" | |
2329 * in the KDE 3.1 window manager. Warp the mouse pointer to outside the | |
2330 * window and back to avoid that. */ | |
2331 if (!gui.in_focus) | |
2332 { | |
2333 int x, y; | |
2334 | |
2335 gdk_window_get_pointer(gui.drawarea->window, &x, &y, NULL); | |
2336 gui_mch_setmouse(-100, -100); | |
2337 gui_mch_setmouse(x, y); | |
2338 } | |
2339 | |
2340 return response > 0 ? response : 0; | 1346 return response > 0 ? response : 0; |
2341 } | 1347 } |
2342 | 1348 |
2343 #endif /* FEAT_GUI_DIALOG && HAVE_GTK2 */ | 1349 #endif /* FEAT_GUI_DIALOG */ |
2344 | 1350 |
2345 | 1351 |
2346 #if defined(FEAT_MENU) || defined(PROTO) | 1352 #if defined(FEAT_MENU) || defined(PROTO) |
2347 | 1353 |
2348 void | 1354 void |
2349 gui_mch_show_popupmenu(vimmenu_T *menu) | 1355 gui_mch_show_popupmenu(vimmenu_T *menu) |
2350 { | 1356 { |
2351 # if defined(FEAT_XIM) && defined(HAVE_GTK2) | 1357 # if defined(FEAT_XIM) |
2352 /* | 1358 /* |
2353 * Append a submenu for selecting an input method. This is | 1359 * Append a submenu for selecting an input method. This is |
2354 * currently the only way to switch input methods at runtime. | 1360 * currently the only way to switch input methods at runtime. |
2355 */ | 1361 */ |
2356 if (xic != NULL && g_object_get_data(G_OBJECT(menu->submenu_id), | 1362 if (xic != NULL && g_object_get_data(G_OBJECT(menu->submenu_id), |
2377 gtk_im_multicontext_append_menuitems(GTK_IM_MULTICONTEXT(xic), | 1383 gtk_im_multicontext_append_menuitems(GTK_IM_MULTICONTEXT(xic), |
2378 GTK_MENU_SHELL(submenu)); | 1384 GTK_MENU_SHELL(submenu)); |
2379 g_object_set_data(G_OBJECT(menu->submenu_id), | 1385 g_object_set_data(G_OBJECT(menu->submenu_id), |
2380 "vim-has-im-menu", GINT_TO_POINTER(TRUE)); | 1386 "vim-has-im-menu", GINT_TO_POINTER(TRUE)); |
2381 } | 1387 } |
2382 # endif /* FEAT_XIM && HAVE_GTK2 */ | 1388 # endif /* FEAT_XIM */ |
2383 | 1389 |
2384 gtk_menu_popup(GTK_MENU(menu->submenu_id), | 1390 gtk_menu_popup(GTK_MENU(menu->submenu_id), |
2385 NULL, NULL, | 1391 NULL, NULL, |
2386 (GtkMenuPositionFunc)NULL, NULL, | 1392 (GtkMenuPositionFunc)NULL, NULL, |
2387 3U, (guint32)GDK_CURRENT_TIME); | 1393 3U, (guint32)GDK_CURRENT_TIME); |
2396 * at the current text cursor position. | 1402 * at the current text cursor position. |
2397 * | 1403 * |
2398 * Note: The push_in output argument seems to affect scrolling of huge | 1404 * Note: The push_in output argument seems to affect scrolling of huge |
2399 * menus that don't fit on the screen. Leave it at the default for now. | 1405 * menus that don't fit on the screen. Leave it at the default for now. |
2400 */ | 1406 */ |
2401 /*ARGSUSED0*/ | |
2402 static void | 1407 static void |
2403 popup_menu_position_func(GtkMenu *menu, | 1408 popup_menu_position_func(GtkMenu *menu UNUSED, |
2404 gint *x, gint *y, | 1409 gint *x, gint *y, |
2405 # ifdef HAVE_GTK2 | 1410 gboolean *push_in UNUSED, |
2406 gboolean *push_in, | 1411 gpointer user_data UNUSED) |
2407 # endif | |
2408 gpointer user_data) | |
2409 { | 1412 { |
2410 gdk_window_get_origin(gui.drawarea->window, x, y); | 1413 gdk_window_get_origin(gui.drawarea->window, x, y); |
2411 | 1414 |
2412 if (popup_mouse_pos) | 1415 if (popup_mouse_pos) |
2413 { | 1416 { |
2462 GtkWidget *find; /* 'Find Next' action button */ | 1465 GtkWidget *find; /* 'Find Next' action button */ |
2463 GtkWidget *replace; /* 'Replace With' action button */ | 1466 GtkWidget *replace; /* 'Replace With' action button */ |
2464 GtkWidget *all; /* 'Replace All' action button */ | 1467 GtkWidget *all; /* 'Replace All' action button */ |
2465 } SharedFindReplace; | 1468 } SharedFindReplace; |
2466 | 1469 |
2467 static SharedFindReplace find_widgets = { NULL, }; | 1470 static SharedFindReplace find_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; |
2468 static SharedFindReplace repl_widgets = { NULL, }; | 1471 static SharedFindReplace repl_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; |
2469 | 1472 |
2470 /* ARGSUSED */ | |
2471 static int | 1473 static int |
2472 find_key_press_event( | 1474 find_key_press_event( |
2473 GtkWidget *widget, | 1475 GtkWidget *widget UNUSED, |
2474 GdkEventKey *event, | 1476 GdkEventKey *event, |
2475 SharedFindReplace *frdp) | 1477 SharedFindReplace *frdp) |
2476 { | 1478 { |
2477 /* If the user is holding one of the key modifiers we will just bail out, | 1479 /* If the user is holding one of the key modifiers we will just bail out, |
2478 * thus preserving the possibility of normal focus traversal. | 1480 * thus preserving the possibility of normal focus traversal. |
2485 { | 1487 { |
2486 gtk_widget_hide(frdp->dialog); | 1488 gtk_widget_hide(frdp->dialog); |
2487 | 1489 |
2488 return TRUE; | 1490 return TRUE; |
2489 } | 1491 } |
2490 /* | |
2491 * What the **** is this for? Disabled for GTK+ 2 because due to | |
2492 * gtk_signal_connect_after() it doesn't have any effect anyway. | |
2493 * (Fortunately.) | |
2494 */ | |
2495 #ifndef HAVE_GTK2 | |
2496 /* block traversal resulting from those keys */ | |
2497 if (event->keyval == GDK_Left | |
2498 || event->keyval == GDK_Right | |
2499 || event->keyval == GDK_space) | |
2500 return TRUE; | |
2501 #endif | |
2502 | 1492 |
2503 /* It would be delightful if it where possible to do search history | 1493 /* It would be delightful if it where possible to do search history |
2504 * operations on the K_UP and K_DOWN keys here. | 1494 * operations on the K_UP and K_DOWN keys here. |
2505 */ | 1495 */ |
2506 | 1496 |
2507 return FALSE; | 1497 return FALSE; |
2508 } | 1498 } |
2509 | 1499 |
2510 #ifdef HAVE_GTK2 | |
2511 static GtkWidget * | 1500 static GtkWidget * |
2512 create_image_button(const char *stock_id, const char *label) | 1501 create_image_button(const char *stock_id, const char *label) |
2513 { | 1502 { |
2514 char_u *text; | 1503 char_u *text; |
2515 GtkWidget *box; | 1504 GtkWidget *box; |
2553 vim_free(*buffer); | 1542 vim_free(*buffer); |
2554 *buffer = string_convert(&output_conv, (char_u *)message, NULL); | 1543 *buffer = string_convert(&output_conv, (char_u *)message, NULL); |
2555 | 1544 |
2556 return (const char *)*buffer; | 1545 return (const char *)*buffer; |
2557 } | 1546 } |
2558 #endif /* HAVE_GTK2 */ | |
2559 | 1547 |
2560 static void | 1548 static void |
2561 find_replace_dialog_create(char_u *arg, int do_replace) | 1549 find_replace_dialog_create(char_u *arg, int do_replace) |
2562 { | 1550 { |
2563 #ifndef HAVE_GTK2 | |
2564 GtkWidget *frame; | |
2565 #endif | |
2566 GtkWidget *hbox; /* main top down box */ | 1551 GtkWidget *hbox; /* main top down box */ |
2567 GtkWidget *actionarea; | 1552 GtkWidget *actionarea; |
2568 GtkWidget *table; | 1553 GtkWidget *table; |
2569 GtkWidget *tmp; | 1554 GtkWidget *tmp; |
2570 GtkWidget *vbox; | 1555 GtkWidget *vbox; |
2571 gboolean sensitive; | 1556 gboolean sensitive; |
2572 SharedFindReplace *frdp; | 1557 SharedFindReplace *frdp; |
2573 char_u *entry_text; | 1558 char_u *entry_text; |
2574 int wword = FALSE; | 1559 int wword = FALSE; |
2575 int mcase = !p_ic; | 1560 int mcase = !p_ic; |
2576 #ifdef HAVE_GTK2 | |
2577 char_u *conv_buffer = NULL; | 1561 char_u *conv_buffer = NULL; |
2578 # define CONV(message) convert_localized_message(&conv_buffer, (message)) | 1562 # define CONV(message) convert_localized_message(&conv_buffer, (message)) |
2579 #else | |
2580 # define CONV(message) (message) | |
2581 #endif | |
2582 | 1563 |
2583 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets); | 1564 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets); |
2584 | 1565 |
2585 /* Get the search string to use. */ | 1566 /* Get the search string to use. */ |
2586 entry_text = get_find_dialog_text(arg, &wword, &mcase); | 1567 entry_text = get_find_dialog_text(arg, &wword, &mcase); |
2587 | 1568 |
2588 #ifdef HAVE_GTK2 | |
2589 if (entry_text != NULL && output_conv.vc_type != CONV_NONE) | 1569 if (entry_text != NULL && output_conv.vc_type != CONV_NONE) |
2590 { | 1570 { |
2591 char_u *old_text = entry_text; | 1571 char_u *old_text = entry_text; |
2592 entry_text = string_convert(&output_conv, entry_text, NULL); | 1572 entry_text = string_convert(&output_conv, entry_text, NULL); |
2593 vim_free(old_text); | 1573 vim_free(old_text); |
2594 } | 1574 } |
2595 #endif | |
2596 | 1575 |
2597 /* | 1576 /* |
2598 * If the dialog already exists, just raise it. | 1577 * If the dialog already exists, just raise it. |
2599 */ | 1578 */ |
2600 if (frdp->dialog) | 1579 if (frdp->dialog) |
2601 { | 1580 { |
2602 #ifndef HAVE_GTK2 | |
2603 /* always make the dialog appear where you want it even if the mainwin | |
2604 * has moved -- dbv */ | |
2605 gui_gtk_position_in_parent(GTK_WIDGET(gui.mainwin), | |
2606 GTK_WIDGET(frdp->dialog), VW_POS_MOUSE); | |
2607 gui_gtk_synch_fonts(); | |
2608 | |
2609 if (!GTK_WIDGET_VISIBLE(frdp->dialog)) | |
2610 { | |
2611 gtk_widget_grab_focus(frdp->what); | |
2612 gtk_widget_show(frdp->dialog); | |
2613 } | |
2614 #endif | |
2615 if (entry_text != NULL) | 1581 if (entry_text != NULL) |
2616 { | 1582 { |
2617 gtk_entry_set_text(GTK_ENTRY(frdp->what), (char *)entry_text); | 1583 gtk_entry_set_text(GTK_ENTRY(frdp->what), (char *)entry_text); |
2618 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->wword), | 1584 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->wword), |
2619 (gboolean)wword); | 1585 (gboolean)wword); |
2620 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->mcase), | 1586 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->mcase), |
2621 (gboolean)mcase); | 1587 (gboolean)mcase); |
2622 } | 1588 } |
2623 #ifdef HAVE_GTK2 | |
2624 gtk_window_present(GTK_WINDOW(frdp->dialog)); | 1589 gtk_window_present(GTK_WINDOW(frdp->dialog)); |
2625 #else | |
2626 gdk_window_raise(frdp->dialog->window); | |
2627 #endif | |
2628 vim_free(entry_text); | 1590 vim_free(entry_text); |
2629 return; | 1591 return; |
2630 } | 1592 } |
2631 | 1593 |
2632 #ifdef HAVE_GTK2 | |
2633 frdp->dialog = gtk_dialog_new(); | 1594 frdp->dialog = gtk_dialog_new(); |
2634 gtk_dialog_set_has_separator(GTK_DIALOG(frdp->dialog), FALSE); | 1595 gtk_dialog_set_has_separator(GTK_DIALOG(frdp->dialog), FALSE); |
2635 gtk_window_set_transient_for(GTK_WINDOW(frdp->dialog), GTK_WINDOW(gui.mainwin)); | 1596 gtk_window_set_transient_for(GTK_WINDOW(frdp->dialog), GTK_WINDOW(gui.mainwin)); |
2636 gtk_window_set_destroy_with_parent(GTK_WINDOW(frdp->dialog), TRUE); | 1597 gtk_window_set_destroy_with_parent(GTK_WINDOW(frdp->dialog), TRUE); |
2637 #else | |
2638 frdp->dialog = gtk_window_new(GTK_WINDOW_DIALOG); | |
2639 #endif | |
2640 | 1598 |
2641 if (do_replace) | 1599 if (do_replace) |
2642 { | 1600 { |
2643 #ifndef HAVE_GTK2 | |
2644 gtk_window_set_wmclass(GTK_WINDOW(frdp->dialog), "searchrepl", "gvim"); | |
2645 #endif | |
2646 gtk_window_set_title(GTK_WINDOW(frdp->dialog), | 1601 gtk_window_set_title(GTK_WINDOW(frdp->dialog), |
2647 CONV(_("VIM - Search and Replace..."))); | 1602 CONV(_("VIM - Search and Replace..."))); |
2648 } | 1603 } |
2649 else | 1604 else |
2650 { | 1605 { |
2651 #ifndef HAVE_GTK2 | |
2652 gtk_window_set_wmclass(GTK_WINDOW(frdp->dialog), "search", "gvim"); | |
2653 #endif | |
2654 gtk_window_set_title(GTK_WINDOW(frdp->dialog), | 1606 gtk_window_set_title(GTK_WINDOW(frdp->dialog), |
2655 CONV(_("VIM - Search..."))); | 1607 CONV(_("VIM - Search..."))); |
2656 } | 1608 } |
2657 | 1609 |
2658 #ifndef HAVE_GTK2 /* Utter crack. Shudder. */ | |
2659 gtk_widget_realize(frdp->dialog); | |
2660 gdk_window_set_decorations(frdp->dialog->window, | |
2661 GDK_DECOR_TITLE | GDK_DECOR_BORDER | GDK_DECOR_RESIZEH); | |
2662 gdk_window_set_functions(frdp->dialog->window, | |
2663 GDK_FUNC_RESIZE | GDK_FUNC_MOVE); | |
2664 #endif | |
2665 | |
2666 #ifndef HAVE_GTK2 | |
2667 /* this makes it look better on Motif style window managers */ | |
2668 frame = gtk_frame_new(NULL); | |
2669 gtk_container_add(GTK_CONTAINER(frdp->dialog), frame); | |
2670 #endif | |
2671 | |
2672 hbox = gtk_hbox_new(FALSE, 0); | 1610 hbox = gtk_hbox_new(FALSE, 0); |
2673 #ifdef HAVE_GTK2 | |
2674 gtk_container_set_border_width(GTK_CONTAINER(hbox), 10); | 1611 gtk_container_set_border_width(GTK_CONTAINER(hbox), 10); |
2675 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(frdp->dialog)->vbox), hbox); | 1612 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(frdp->dialog)->vbox), hbox); |
2676 #else | |
2677 gtk_container_add(GTK_CONTAINER(frame), hbox); | |
2678 #endif | |
2679 | 1613 |
2680 if (do_replace) | 1614 if (do_replace) |
2681 table = gtk_table_new(1024, 4, FALSE); | 1615 table = gtk_table_new(1024, 4, FALSE); |
2682 else | 1616 else |
2683 table = gtk_table_new(1024, 3, FALSE); | 1617 table = gtk_table_new(1024, 3, FALSE); |
2771 gtk_box_pack_start(GTK_BOX(vbox), frdp->up, TRUE, TRUE, 0); | 1705 gtk_box_pack_start(GTK_BOX(vbox), frdp->up, TRUE, TRUE, 0); |
2772 frdp->down = gtk_radio_button_new_with_label( | 1706 frdp->down = gtk_radio_button_new_with_label( |
2773 gtk_radio_button_group(GTK_RADIO_BUTTON(frdp->up)), | 1707 gtk_radio_button_group(GTK_RADIO_BUTTON(frdp->up)), |
2774 CONV(_("Down"))); | 1708 CONV(_("Down"))); |
2775 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->down), TRUE); | 1709 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->down), TRUE); |
2776 #ifdef HAVE_GTK2 | |
2777 gtk_container_set_border_width(GTK_CONTAINER(vbox), 2); | 1710 gtk_container_set_border_width(GTK_CONTAINER(vbox), 2); |
2778 #endif | |
2779 gtk_box_pack_start(GTK_BOX(vbox), frdp->down, TRUE, TRUE, 0); | 1711 gtk_box_pack_start(GTK_BOX(vbox), frdp->down, TRUE, TRUE, 0); |
2780 | 1712 |
2781 /* vbox to hold the action buttons */ | 1713 /* vbox to hold the action buttons */ |
2782 actionarea = gtk_vbutton_box_new(); | 1714 actionarea = gtk_vbutton_box_new(); |
2783 gtk_container_border_width(GTK_CONTAINER(actionarea), 2); | 1715 gtk_container_border_width(GTK_CONTAINER(actionarea), 2); |
2784 #ifndef HAVE_GTK2 | |
2785 if (do_replace) | |
2786 { | |
2787 gtk_button_box_set_layout(GTK_BUTTON_BOX(actionarea), | |
2788 GTK_BUTTONBOX_END); | |
2789 gtk_button_box_set_spacing(GTK_BUTTON_BOX(actionarea), 0); | |
2790 } | |
2791 #endif | |
2792 gtk_box_pack_end(GTK_BOX(hbox), actionarea, FALSE, FALSE, 0); | 1716 gtk_box_pack_end(GTK_BOX(hbox), actionarea, FALSE, FALSE, 0); |
2793 | 1717 |
2794 /* 'Find Next' button */ | 1718 /* 'Find Next' button */ |
2795 #ifdef HAVE_GTK2 | |
2796 frdp->find = create_image_button(GTK_STOCK_FIND, _("Find Next")); | 1719 frdp->find = create_image_button(GTK_STOCK_FIND, _("Find Next")); |
2797 #else | |
2798 frdp->find = gtk_button_new_with_label(_("Find Next")); | |
2799 #endif | |
2800 gtk_widget_set_sensitive(frdp->find, sensitive); | 1720 gtk_widget_set_sensitive(frdp->find, sensitive); |
2801 | 1721 |
2802 gtk_signal_connect(GTK_OBJECT(frdp->find), "clicked", | 1722 gtk_signal_connect(GTK_OBJECT(frdp->find), "clicked", |
2803 GTK_SIGNAL_FUNC(find_replace_cb), | 1723 GTK_SIGNAL_FUNC(find_replace_cb), |
2804 (do_replace) ? GINT_TO_POINTER(FRD_R_FINDNEXT) | 1724 (do_replace) ? GINT_TO_POINTER(FRD_R_FINDNEXT) |
2809 gtk_widget_grab_default(frdp->find); | 1729 gtk_widget_grab_default(frdp->find); |
2810 | 1730 |
2811 if (do_replace) | 1731 if (do_replace) |
2812 { | 1732 { |
2813 /* 'Replace' button */ | 1733 /* 'Replace' button */ |
2814 #ifdef HAVE_GTK2 | |
2815 frdp->replace = create_image_button(GTK_STOCK_CONVERT, _("Replace")); | 1734 frdp->replace = create_image_button(GTK_STOCK_CONVERT, _("Replace")); |
2816 #else | |
2817 frdp->replace = gtk_button_new_with_label(_("Replace")); | |
2818 #endif | |
2819 gtk_widget_set_sensitive(frdp->replace, sensitive); | 1735 gtk_widget_set_sensitive(frdp->replace, sensitive); |
2820 GTK_WIDGET_SET_FLAGS(frdp->replace, GTK_CAN_DEFAULT); | 1736 GTK_WIDGET_SET_FLAGS(frdp->replace, GTK_CAN_DEFAULT); |
2821 gtk_box_pack_start(GTK_BOX(actionarea), frdp->replace, FALSE, FALSE, 0); | 1737 gtk_box_pack_start(GTK_BOX(actionarea), frdp->replace, FALSE, FALSE, 0); |
2822 gtk_signal_connect(GTK_OBJECT(frdp->replace), "clicked", | 1738 gtk_signal_connect(GTK_OBJECT(frdp->replace), "clicked", |
2823 GTK_SIGNAL_FUNC(find_replace_cb), | 1739 GTK_SIGNAL_FUNC(find_replace_cb), |
2824 GINT_TO_POINTER(FRD_REPLACE)); | 1740 GINT_TO_POINTER(FRD_REPLACE)); |
2825 | 1741 |
2826 /* 'Replace All' button */ | 1742 /* 'Replace All' button */ |
2827 #ifdef HAVE_GTK2 | |
2828 frdp->all = create_image_button(GTK_STOCK_CONVERT, _("Replace All")); | 1743 frdp->all = create_image_button(GTK_STOCK_CONVERT, _("Replace All")); |
2829 #else | |
2830 frdp->all = gtk_button_new_with_label(_("Replace All")); | |
2831 #endif | |
2832 gtk_widget_set_sensitive(frdp->all, sensitive); | 1744 gtk_widget_set_sensitive(frdp->all, sensitive); |
2833 GTK_WIDGET_SET_FLAGS(frdp->all, GTK_CAN_DEFAULT); | 1745 GTK_WIDGET_SET_FLAGS(frdp->all, GTK_CAN_DEFAULT); |
2834 gtk_box_pack_start(GTK_BOX(actionarea), frdp->all, FALSE, FALSE, 0); | 1746 gtk_box_pack_start(GTK_BOX(actionarea), frdp->all, FALSE, FALSE, 0); |
2835 gtk_signal_connect(GTK_OBJECT(frdp->all), "clicked", | 1747 gtk_signal_connect(GTK_OBJECT(frdp->all), "clicked", |
2836 GTK_SIGNAL_FUNC(find_replace_cb), | 1748 GTK_SIGNAL_FUNC(find_replace_cb), |
2837 GINT_TO_POINTER(FRD_REPLACEALL)); | 1749 GINT_TO_POINTER(FRD_REPLACEALL)); |
2838 } | 1750 } |
2839 | 1751 |
2840 /* 'Cancel' button */ | 1752 /* 'Cancel' button */ |
2841 #ifdef HAVE_GTK2 | |
2842 tmp = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | 1753 tmp = gtk_button_new_from_stock(GTK_STOCK_CLOSE); |
2843 #else | |
2844 tmp = gtk_button_new_with_label(_("Cancel")); | |
2845 #endif | |
2846 GTK_WIDGET_SET_FLAGS(tmp, GTK_CAN_DEFAULT); | 1754 GTK_WIDGET_SET_FLAGS(tmp, GTK_CAN_DEFAULT); |
2847 gtk_box_pack_end(GTK_BOX(actionarea), tmp, FALSE, FALSE, 0); | 1755 gtk_box_pack_end(GTK_BOX(actionarea), tmp, FALSE, FALSE, 0); |
2848 gtk_signal_connect_object(GTK_OBJECT(tmp), | 1756 gtk_signal_connect_object(GTK_OBJECT(tmp), |
2849 "clicked", GTK_SIGNAL_FUNC(gtk_widget_hide), | 1757 "clicked", GTK_SIGNAL_FUNC(gtk_widget_hide), |
2850 GTK_OBJECT(frdp->dialog)); | 1758 GTK_OBJECT(frdp->dialog)); |
2851 gtk_signal_connect_object(GTK_OBJECT(frdp->dialog), | 1759 gtk_signal_connect_object(GTK_OBJECT(frdp->dialog), |
2852 "delete_event", GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete), | 1760 "delete_event", GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete), |
2853 GTK_OBJECT(frdp->dialog)); | 1761 GTK_OBJECT(frdp->dialog)); |
2854 | 1762 |
2855 tmp = gtk_vseparator_new(); | 1763 tmp = gtk_vseparator_new(); |
2856 #ifdef HAVE_GTK2 | |
2857 gtk_box_pack_end(GTK_BOX(hbox), tmp, FALSE, FALSE, 10); | 1764 gtk_box_pack_end(GTK_BOX(hbox), tmp, FALSE, FALSE, 10); |
2858 #else | 1765 |
2859 gtk_box_pack_end(GTK_BOX(hbox), tmp, FALSE, TRUE, 0); | |
2860 #endif | |
2861 | |
2862 #ifndef HAVE_GTK2 | |
2863 gtk_widget_grab_focus(frdp->what); | |
2864 | |
2865 /* show the frame and realize the frdp->dialog this gives us a window size | |
2866 * request that we'll use to position the window within the boundary of | |
2867 * the mainwin --dbv */ | |
2868 gtk_widget_show_all(frame); | |
2869 gui_gtk_position_in_parent(GTK_WIDGET(gui.mainwin), | |
2870 GTK_WIDGET(frdp->dialog), VW_POS_MOUSE); | |
2871 gui_gtk_synch_fonts(); | |
2872 gtk_widget_show_all(frdp->dialog); | |
2873 #endif | |
2874 | |
2875 #ifdef HAVE_GTK2 | |
2876 /* Suppress automatic show of the unused action area */ | 1766 /* Suppress automatic show of the unused action area */ |
2877 gtk_widget_hide(GTK_DIALOG(frdp->dialog)->action_area); | 1767 gtk_widget_hide(GTK_DIALOG(frdp->dialog)->action_area); |
2878 gtk_widget_show_all(hbox); | 1768 gtk_widget_show_all(hbox); |
2879 gtk_widget_show(frdp->dialog); | 1769 gtk_widget_show(frdp->dialog); |
2880 #endif | |
2881 | 1770 |
2882 vim_free(entry_text); | 1771 vim_free(entry_text); |
2883 #ifdef HAVE_GTK2 | |
2884 vim_free(conv_buffer); | 1772 vim_free(conv_buffer); |
2885 #endif | |
2886 #undef CONV | 1773 #undef CONV |
2887 } | 1774 } |
2888 | 1775 |
2889 void | 1776 void |
2890 gui_mch_find_dialog(exarg_T *eap) | 1777 gui_mch_find_dialog(exarg_T *eap) |
2897 gui_mch_replace_dialog(exarg_T *eap) | 1784 gui_mch_replace_dialog(exarg_T *eap) |
2898 { | 1785 { |
2899 if (gui.in_use) | 1786 if (gui.in_use) |
2900 find_replace_dialog_create(eap->arg, TRUE); | 1787 find_replace_dialog_create(eap->arg, TRUE); |
2901 } | 1788 } |
2902 | |
2903 | |
2904 #if !defined(HAVE_GTK2) || defined(PROTO) | |
2905 /* | |
2906 * Synchronize all gui elements, which are dependant upon the | |
2907 * main text font used. Those are in esp. the find/replace dialogs. | |
2908 * If you don't understand why this should be needed, please try to | |
2909 * search for "pięść" in iso8859-2. | |
2910 * | |
2911 * (<danielk> I converted the comment above to UTF-8 to put | |
2912 * a stopper to the encoding mess. Forgive me :) | |
2913 * | |
2914 * Obsolete with GTK2. | |
2915 */ | |
2916 void | |
2917 gui_gtk_synch_fonts(void) | |
2918 { | |
2919 SharedFindReplace *frdp; | |
2920 int do_replace; | |
2921 | |
2922 /* OK this loop is a bit tricky... */ | |
2923 for (do_replace = 0; do_replace <= 1; ++do_replace) | |
2924 { | |
2925 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets); | |
2926 if (frdp->dialog) | |
2927 { | |
2928 GtkStyle *style; | |
2929 | |
2930 /* synch the font with whats used by the text itself */ | |
2931 style = gtk_style_copy(gtk_widget_get_style(frdp->what)); | |
2932 gdk_font_unref(style->font); | |
2933 # ifdef FEAT_XFONTSET | |
2934 if (gui.fontset != NOFONTSET) | |
2935 style->font = gui.fontset; | |
2936 else | |
2937 # endif | |
2938 style->font = gui.norm_font; | |
2939 gdk_font_ref(style->font); | |
2940 gtk_widget_set_style(frdp->what, style); | |
2941 gtk_style_unref(style); | |
2942 if (do_replace) | |
2943 { | |
2944 style = gtk_style_copy(gtk_widget_get_style(frdp->with)); | |
2945 gdk_font_unref(style->font); | |
2946 # ifdef FEAT_XFONTSET | |
2947 if (gui.fontset != NOFONTSET) | |
2948 style->font = gui.fontset; | |
2949 else | |
2950 # endif | |
2951 style->font = gui.norm_font; | |
2952 gdk_font_ref(style->font); | |
2953 gtk_widget_set_style(frdp->with, style); | |
2954 gtk_style_unref(style); | |
2955 } | |
2956 } | |
2957 } | |
2958 } | |
2959 #endif /* !HAVE_GTK2 */ | |
2960 | |
2961 | 1789 |
2962 /* | 1790 /* |
2963 * Callback for actions of the find and replace dialogs | 1791 * Callback for actions of the find and replace dialogs |
2964 */ | 1792 */ |
2965 /*ARGSUSED*/ | |
2966 static void | 1793 static void |
2967 find_replace_cb(GtkWidget *widget, gpointer data) | 1794 find_replace_cb(GtkWidget *widget UNUSED, gpointer data) |
2968 { | 1795 { |
2969 int flags; | 1796 int flags; |
2970 char_u *find_text; | 1797 char_u *find_text; |
2971 char_u *repl_text; | 1798 char_u *repl_text; |
2972 gboolean direction_down; | 1799 gboolean direction_down; |
2973 SharedFindReplace *sfr; | 1800 SharedFindReplace *sfr; |
2974 int rc; | |
2975 | 1801 |
2976 flags = (int)(long)data; /* avoid a lint warning here */ | 1802 flags = (int)(long)data; /* avoid a lint warning here */ |
2977 | 1803 |
2978 /* Get the search/replace strings from the dialog */ | 1804 /* Get the search/replace strings from the dialog */ |
2979 if (flags == FRD_FINDNEXT) | 1805 if (flags == FRD_FINDNEXT) |
2993 if (GTK_TOGGLE_BUTTON(sfr->wword)->active) | 1819 if (GTK_TOGGLE_BUTTON(sfr->wword)->active) |
2994 flags |= FRD_WHOLE_WORD; | 1820 flags |= FRD_WHOLE_WORD; |
2995 if (GTK_TOGGLE_BUTTON(sfr->mcase)->active) | 1821 if (GTK_TOGGLE_BUTTON(sfr->mcase)->active) |
2996 flags |= FRD_MATCH_CASE; | 1822 flags |= FRD_MATCH_CASE; |
2997 | 1823 |
2998 #ifdef HAVE_GTK2 | |
2999 repl_text = CONVERT_FROM_UTF8(repl_text); | 1824 repl_text = CONVERT_FROM_UTF8(repl_text); |
3000 find_text = CONVERT_FROM_UTF8(find_text); | 1825 find_text = CONVERT_FROM_UTF8(find_text); |
3001 #endif | 1826 gui_do_findrepl(flags, find_text, repl_text, direction_down); |
3002 rc = gui_do_findrepl(flags, find_text, repl_text, direction_down); | |
3003 #ifdef HAVE_GTK2 | |
3004 CONVERT_FROM_UTF8_FREE(repl_text); | 1827 CONVERT_FROM_UTF8_FREE(repl_text); |
3005 CONVERT_FROM_UTF8_FREE(find_text); | 1828 CONVERT_FROM_UTF8_FREE(find_text); |
3006 #endif | |
3007 | |
3008 if (rc && gtk_main_level() > 0) | |
3009 gtk_main_quit(); /* make sure cmd will be handled immediately */ | |
3010 } | 1829 } |
3011 | 1830 |
3012 /* our usual callback function */ | 1831 /* our usual callback function */ |
3013 /*ARGSUSED*/ | |
3014 static void | 1832 static void |
3015 entry_activate_cb(GtkWidget *widget, gpointer data) | 1833 entry_activate_cb(GtkWidget *widget UNUSED, gpointer data) |
3016 { | 1834 { |
3017 gtk_widget_grab_focus(GTK_WIDGET(data)); | 1835 gtk_widget_grab_focus(GTK_WIDGET(data)); |
3018 } | 1836 } |
3019 | 1837 |
3020 /* | 1838 /* |
3053 } | 1871 } |
3054 | 1872 |
3055 /* | 1873 /* |
3056 * ":helpfind" | 1874 * ":helpfind" |
3057 */ | 1875 */ |
3058 /*ARGSUSED*/ | |
3059 void | 1876 void |
3060 ex_helpfind(eap) | 1877 ex_helpfind(eap) |
3061 exarg_T *eap; | 1878 exarg_T *eap UNUSED; |
3062 { | 1879 { |
3063 /* This will fail when menus are not loaded. Well, it's only for | 1880 /* This will fail when menus are not loaded. Well, it's only for |
3064 * backwards compatibility anyway. */ | 1881 * backwards compatibility anyway. */ |
3065 do_cmdline_cmd((char_u *)"emenu ToolBar.FindHelp"); | 1882 do_cmdline_cmd((char_u *)"emenu ToolBar.FindHelp"); |
3066 } | 1883 } |
3067 | |
3068 #if !defined(HAVE_GTK2) || defined(PROTO) /* Crack crack crack. Brrrr. */ | |
3069 | |
3070 /* gui_gtk_position_in_parent | |
3071 * | |
3072 * this function causes a child window to be placed within the boundary of | |
3073 * the parent (mainwin) window. | |
3074 * | |
3075 * you can specify where the window will be positioned by the third argument | |
3076 * (defined in gui.h): | |
3077 * VW_POS_CENTER at center of parent window | |
3078 * VW_POS_MOUSE center of child at mouse position | |
3079 * VW_POS_TOP_CENTER top of child at top of parent centered | |
3080 * horizontally about the mouse. | |
3081 * | |
3082 * NOTE: for this function to act as desired the child window must have a | |
3083 * window size requested. this can be accomplished by packing/placing | |
3084 * child widgets onto a gtk_frame widget rather than the gtk_window | |
3085 * widget... | |
3086 * | |
3087 * brent -- dbv | |
3088 */ | |
3089 static void | |
3090 gui_gtk_position_in_parent( | |
3091 GtkWidget *parent, | |
3092 GtkWidget *child, | |
3093 gui_win_pos_T where) | |
3094 { | |
3095 GtkRequisition c_size; | |
3096 gint xPm, yPm; | |
3097 gint xP, yP, wP, hP, pos_x, pos_y; | |
3098 | |
3099 /* make sure the child widget is set up then get its size. */ | |
3100 gtk_widget_size_request(child, &c_size); | |
3101 | |
3102 /* get origin and size of parent window */ | |
3103 gdk_window_get_origin((GdkWindow *)(parent->window), &xP, &yP); | |
3104 gdk_window_get_size((GdkWindow *)(parent->window), &wP, &hP); | |
3105 | |
3106 if (c_size.width > wP || c_size.height > hP) | |
3107 { | |
3108 /* doh! maybe the user should consider giving gVim a little more | |
3109 * screen real estate */ | |
3110 gtk_widget_set_uposition(child , xP + 2 , yP + 2); | |
3111 return; | |
3112 } | |
3113 | |
3114 if (where == VW_POS_MOUSE) | |
3115 { | |
3116 /* position window at mouse pointer */ | |
3117 gtk_widget_get_pointer(parent, &xPm, &yPm); | |
3118 pos_x = xP + xPm - (c_size.width) / 2; | |
3119 pos_y = yP + yPm - (c_size.height) / 2; | |
3120 } | |
3121 else | |
3122 { | |
3123 /* set child x origin so it is in center of Vim window */ | |
3124 pos_x = xP + (wP - c_size.width) / 2; | |
3125 | |
3126 if (where == VW_POS_TOP_CENTER) | |
3127 pos_y = yP + 2; | |
3128 else | |
3129 /* where == VW_POS_CENTER */ | |
3130 pos_y = yP + (hP - c_size.height) / 2; | |
3131 } | |
3132 | |
3133 /* now, make sure the window will be inside the Vim window... */ | |
3134 if (pos_x < xP) | |
3135 pos_x = xP + 2; | |
3136 if (pos_y < yP) | |
3137 pos_y = yP + 2; | |
3138 if ((pos_x + c_size.width) > (wP + xP)) | |
3139 pos_x = xP + wP - c_size.width - 2; | |
3140 /* Assume 'guiheadroom' indicates the title bar height... */ | |
3141 if ((pos_y + c_size.height + p_ghr / 2) > (hP + yP)) | |
3142 | |
3143 gtk_widget_set_uposition(child, pos_x, pos_y); | |
3144 } | |
3145 | |
3146 #endif /* !HAVE_GTK2 */ |