annotate src/gui_gtk.c @ 795:86ce35c9750f v7.0231

updated for version 7.0231
author vimboss
date Tue, 21 Mar 2006 21:33:03 +0000
parents c8680debe1cc
children 5a7843c57316
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 * Porting to GTK+ was done by:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 *
68
a97c6902ecd9 updated for version 7.0030
vimboss
parents: 41
diff changeset
13 * (C) 1998,1999,2000 by Marcin Dalecki <martin@dalecki.de>
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 * With GREAT support and continuous encouragements by Andy Kahn and of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 * course Bram Moolenaar!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 * Support for GTK+ 2 was added by:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 * (C) 2002,2003 Jason Hildebrand <jason@peaceworks.ca>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 * Daniel Elstner <daniel.elstner@gmx.net>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 * Best supporting actor (He helped somewhat, aesthetically speaking):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 * Maxime Romano <verbophobe@hotmail.com>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 #ifdef FEAT_GUI_GTK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 # include "gui_gtk_f.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 /* GTK defines MAX and MIN, but some system header files as well. Undefine
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 * them and don't use them. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 #ifdef MIN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 # undef MIN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 #ifdef MAX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 # undef MAX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 #ifdef FEAT_GUI_GNOME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 /* Gnome redefines _() and N_(). Grrr... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 # ifdef _
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 # undef _
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 # ifdef N_
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 # undef N_
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 # ifdef textdomain
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 # undef textdomain
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 # ifdef bindtextdomain
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 # undef bindtextdomain
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 # if defined(FEAT_GETTEXT) && !defined(ENABLE_NLS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 # define ENABLE_NLS /* so the texts in the dialog boxes are translated */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 # include <gnome.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 #if defined(FEAT_GUI_DIALOG) && !defined(HAVE_GTK2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 # include "../pixmaps/alert.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 # include "../pixmaps/error.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 # include "../pixmaps/generic.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 # include "../pixmaps/info.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 # include "../pixmaps/quest.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 #if defined(FEAT_TOOLBAR) && !defined(HAVE_GTK2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 * Icons used by the toolbar code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 #include "../pixmaps/tb_new.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 #include "../pixmaps/tb_open.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 #include "../pixmaps/tb_close.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 #include "../pixmaps/tb_save.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 #include "../pixmaps/tb_print.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 #include "../pixmaps/tb_cut.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 #include "../pixmaps/tb_copy.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 #include "../pixmaps/tb_paste.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 #include "../pixmaps/tb_find.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 #include "../pixmaps/tb_find_next.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 #include "../pixmaps/tb_find_prev.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 #include "../pixmaps/tb_find_help.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 #include "../pixmaps/tb_exit.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 #include "../pixmaps/tb_undo.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 #include "../pixmaps/tb_redo.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 #include "../pixmaps/tb_help.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 #include "../pixmaps/tb_macro.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 #include "../pixmaps/tb_make.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 #include "../pixmaps/tb_save_all.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 #include "../pixmaps/tb_jump.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 #include "../pixmaps/tb_ctags.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 #include "../pixmaps/tb_load_session.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 #include "../pixmaps/tb_save_session.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 #include "../pixmaps/tb_new_session.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 #include "../pixmaps/tb_blank.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 #include "../pixmaps/tb_maximize.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 #include "../pixmaps/tb_split.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 #include "../pixmaps/tb_minimize.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 #include "../pixmaps/tb_shell.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 #include "../pixmaps/tb_replace.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 #include "../pixmaps/tb_vsplit.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 #include "../pixmaps/tb_maxwidth.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 #include "../pixmaps/tb_minwidth.xpm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 #endif /* FEAT_TOOLBAR && !HAVE_GTK2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 #ifdef FEAT_GUI_GTK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 # include <gdk/gdkkeysyms.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 # include <gdk/gdk.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 # ifdef WIN3264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 # include <gdk/gdkwin32.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 # include <gdk/gdkx.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 # include <gtk/gtk.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 /* define these items to be able to generate prototypes without GTK */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 typedef int GtkWidget;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 # define gpointer int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 # define guint8 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 # define GdkPixmap int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 # define GdkBitmap int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 # define GtkIconFactory int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 # define GtkToolbar int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 # define GtkAdjustment int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 # define gboolean int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 # define GdkEventKey int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 # define CancelData int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 #ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 * Convenience macros to convert from 'encoding' to 'termencoding' and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 * vice versa. If no conversion is necessary the passed-in pointer is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 * returned as is, without allocating any memory. Thus additional _FREE()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 * macros are provided. The _FREE() macros also set the pointer to NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 * in order to avoid bugs due to illegal memory access only happening if
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 * 'encoding' != utf-8...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 * Defining these macros as pure expressions looks a bit tricky but
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 * avoids depending on the context of the macro expansion. One of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 * rare occasions where the comma operator comes in handy :)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 * Note: Do NOT keep the result around when handling control back to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 * the main Vim! The user could change 'encoding' at any time.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 # define CONVERT_TO_UTF8(String) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 ((output_conv.vc_type == CONV_NONE || (String) == NULL) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 ? (String) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 : string_convert(&output_conv, (String), NULL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 # define CONVERT_TO_UTF8_FREE(String) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 ((String) = ((output_conv.vc_type == CONV_NONE) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 ? (char_u *)NULL \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 : (vim_free(String), (char_u *)NULL)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 # define CONVERT_FROM_UTF8(String) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 ((input_conv.vc_type == CONV_NONE || (String) == NULL) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 ? (String) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 : string_convert(&input_conv, (String), NULL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 # define CONVERT_FROM_UTF8_FREE(String) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 ((String) = ((input_conv.vc_type == CONV_NONE) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 ? (char_u *)NULL \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 : (vim_free(String), (char_u *)NULL)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 #endif /* HAVE_GTK2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 static void entry_activate_cb(GtkWidget *widget, gpointer data);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 static void entry_changed_cb(GtkWidget *entry, GtkWidget *dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 static void find_replace_cb(GtkWidget *widget, gpointer data);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 314
diff changeset
175 #ifndef HAVE_GTK2
7033303ea0c0 updated for version 7.0089
vimboss
parents: 314
diff changeset
176 static void gui_gtk_position_in_parent(GtkWidget *parent, GtkWidget *child, gui_win_pos_T where);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 314
diff changeset
177 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 #if defined(FEAT_TOOLBAR) && defined(HAVE_GTK2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 * Table from BuiltIn## icon indices to GTK+ stock IDs. Order must exactly
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 * match toolbar_names[] in menu.c! All stock icons including the "vim-*"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 * ones can be overridden in your gtkrc file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 static const char * const menu_stock_ids[] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 /* 00 */ GTK_STOCK_NEW,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 /* 01 */ GTK_STOCK_OPEN,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 /* 02 */ GTK_STOCK_SAVE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 /* 03 */ GTK_STOCK_UNDO,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 /* 04 */ GTK_STOCK_REDO,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 /* 05 */ GTK_STOCK_CUT,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 /* 06 */ GTK_STOCK_COPY,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 /* 07 */ GTK_STOCK_PASTE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 /* 08 */ GTK_STOCK_PRINT,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 /* 09 */ GTK_STOCK_HELP,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 /* 10 */ GTK_STOCK_FIND,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 /* 11 */ "vim-save-all",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 /* 12 */ "vim-session-save",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 /* 13 */ "vim-session-new",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 /* 14 */ "vim-session-load",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 /* 15 */ GTK_STOCK_EXECUTE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 /* 16 */ GTK_STOCK_FIND_AND_REPLACE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 /* 17 */ GTK_STOCK_CLOSE, /* FIXME: fuzzy */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 /* 18 */ "vim-window-maximize",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 /* 19 */ "vim-window-minimize",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 /* 20 */ "vim-window-split",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 /* 21 */ "vim-shell",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 /* 22 */ GTK_STOCK_GO_BACK,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 /* 23 */ GTK_STOCK_GO_FORWARD,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 /* 24 */ "vim-find-help",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 /* 25 */ GTK_STOCK_CONVERT,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 /* 26 */ GTK_STOCK_JUMP_TO,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 /* 27 */ "vim-build-tags",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 /* 28 */ "vim-window-split-vertical",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 /* 29 */ "vim-window-maximize-width",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 /* 30 */ "vim-window-minimize-width",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 /* 31 */ GTK_STOCK_QUIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 add_stock_icon(GtkIconFactory *factory,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 const char *stock_id,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 const guint8 *inline_data,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 int data_length)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 GdkPixbuf *pixbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 GtkIconSet *icon_set;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 pixbuf = gdk_pixbuf_new_from_inline(data_length, inline_data, FALSE, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 icon_set = gtk_icon_set_new_from_pixbuf(pixbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 gtk_icon_factory_add(factory, stock_id, icon_set);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 gtk_icon_set_unref(icon_set);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 g_object_unref(pixbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 lookup_menu_iconfile(char_u *iconfile, char_u *dest)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 expand_env(iconfile, dest, MAXPATHL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 if (mch_isFullName(dest))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 return vim_fexists(dest);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 static const char suffixes[][4] = {"png", "xpm", "bmp"};
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 char_u buf[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 unsigned int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 for (i = 0; i < G_N_ELEMENTS(suffixes); ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 if (gui_find_bitmap(dest, buf, (char *)suffixes[i]) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 STRCPY(dest, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 static GtkWidget *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 load_menu_iconfile(char_u *name, GtkIconSize icon_size)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 GtkWidget *image = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 GtkIconSet *icon_set;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 GtkIconSource *icon_source;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 * Rather than loading the icon directly into a GtkImage, create
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 * a new GtkIconSet and put it in there. This way we can easily
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 * scale the toolbar icons on the fly when needed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 icon_set = gtk_icon_set_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 icon_source = gtk_icon_source_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 gtk_icon_source_set_filename(icon_source, (const char *)name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 gtk_icon_set_add_source(icon_set, icon_source);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 image = gtk_image_new_from_icon_set(icon_set, icon_size);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 gtk_icon_source_free(icon_source);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 gtk_icon_set_unref(icon_set);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 return image;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 static GtkWidget *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 create_menu_icon(vimmenu_T *menu, GtkIconSize icon_size)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 GtkWidget *image = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 char_u buf[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 /* First use a specified "icon=" argument. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 if (menu->iconfile != NULL && lookup_menu_iconfile(menu->iconfile, buf))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 image = load_menu_iconfile(buf, icon_size);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 /* If not found and not builtin specified try using the menu name. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 if (image == NULL && !menu->icon_builtin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 && lookup_menu_iconfile(menu->name, buf))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 image = load_menu_iconfile(buf, icon_size);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 /* Still not found? Then use a builtin icon, a blank one as fallback. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 if (image == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 const char *stock_id;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 const int n_ids = G_N_ELEMENTS(menu_stock_ids);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 if (menu->iconidx >= 0 && menu->iconidx < n_ids)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 stock_id = menu_stock_ids[menu->iconidx];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 stock_id = GTK_STOCK_MISSING_IMAGE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 image = gtk_image_new_from_stock(stock_id, icon_size);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 return image;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322
790
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
323 /*ARGSUSED*/
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
324 static gint
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
325 toolbar_button_focus_in_event(GtkWidget *widget, GdkEventFocus *event, gpointer data)
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
326 {
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
327 /* When we're in a GtkPlug, we don't have window focus events, only widget focus.
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
328 * To emulate stand-alone gvim, if a button gets focus (e.g., <Tab> into GtkPlug)
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
329 * immediately pass it to mainwin.
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
330 */
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
331 if (gtk_socket_id != 0)
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
332 gtk_widget_grab_focus(gui.drawarea);
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
333
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
334 return TRUE;
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
335 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 #endif /* FEAT_TOOLBAR && HAVE_GTK2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 #if (defined(FEAT_TOOLBAR) && defined(HAVE_GTK2)) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 gui_gtk_register_stock_icons(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 # include "../pixmaps/stock_icons.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 GtkIconFactory *factory;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 factory = gtk_icon_factory_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 # define ADD_ICON(Name, Data) add_stock_icon(factory, Name, Data, (int)sizeof(Data))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 ADD_ICON("vim-build-tags", stock_vim_build_tags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 ADD_ICON("vim-find-help", stock_vim_find_help);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 ADD_ICON("vim-save-all", stock_vim_save_all);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 ADD_ICON("vim-session-load", stock_vim_session_load);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 ADD_ICON("vim-session-new", stock_vim_session_new);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 ADD_ICON("vim-session-save", stock_vim_session_save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 ADD_ICON("vim-shell", stock_vim_shell);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 ADD_ICON("vim-window-maximize", stock_vim_window_maximize);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 ADD_ICON("vim-window-maximize-width", stock_vim_window_maximize_width);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 ADD_ICON("vim-window-minimize", stock_vim_window_minimize);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 ADD_ICON("vim-window-minimize-width", stock_vim_window_minimize_width);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 ADD_ICON("vim-window-split", stock_vim_window_split);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 ADD_ICON("vim-window-split-vertical", stock_vim_window_split_vertical);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 # undef ADD_ICON
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 gtk_icon_factory_add_default(factory);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 g_object_unref(factory);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 #endif /* FEAT_TOOLBAR && HAVE_GTK2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 * Only use accelerators when gtk_menu_ensure_uline_accel_group() is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 * available, which is in version 1.2.1. That was the first version where
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 * accelerators properly worked (according to the change log).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 #ifdef GTK_CHECK_VERSION
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 # if GTK_CHECK_VERSION(1, 2, 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 # define GTK_USE_ACCEL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 #if defined(FEAT_MENU) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 * Translate Vim's mnemonic tagging to GTK+ style and convert to UTF-8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 * if necessary. The caller must vim_free() the returned string.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 * Input Output
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 * _ __
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 * && &
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 * & _ stripped if use_mnemonic == FALSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 * <Tab> end of menu label text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 translate_mnemonic_tag(char_u *name, int use_mnemonic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 char_u *psrc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 char_u *pdest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 int n_underscores = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 # ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 name = CONVERT_TO_UTF8(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 if (name == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 for (psrc = name; *psrc != NUL && *psrc != TAB; ++psrc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 if (*psrc == '_')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 ++n_underscores;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 buf = alloc((unsigned)(psrc - name + n_underscores + 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 if (buf != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 pdest = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 for (psrc = name; *psrc != NUL && *psrc != TAB; ++psrc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 if (*psrc == '_')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 *pdest++ = '_';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 *pdest++ = '_';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 else if (*psrc != '&')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 *pdest++ = *psrc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 else if (*(psrc + 1) == '&')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 *pdest++ = *psrc++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 else if (use_mnemonic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 *pdest++ = '_';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 *pdest = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 # ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 CONVERT_TO_UTF8_FREE(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 return buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 # ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 menu_item_new(vimmenu_T *menu, GtkWidget *parent_widget)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 GtkWidget *box;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 char_u *text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 int use_mnemonic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 /* It would be neat to have image menu items, but that would require major
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 * changes to Vim's menu system. Not to mention that all the translations
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 * had to be updated. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 menu->id = gtk_menu_item_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 box = gtk_hbox_new(FALSE, 20);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 use_mnemonic = (p_wak[0] != 'n' || !GTK_IS_MENU_BAR(parent_widget));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 text = translate_mnemonic_tag(menu->name, use_mnemonic);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 menu->label = gtk_label_new_with_mnemonic((const char *)text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 vim_free(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 gtk_box_pack_start(GTK_BOX(box), menu->label, FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 if (menu->actext != NULL && menu->actext[0] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 text = CONVERT_TO_UTF8(menu->actext);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 gtk_box_pack_end(GTK_BOX(box),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 gtk_label_new((const char *)text),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 CONVERT_TO_UTF8_FREE(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 gtk_container_add(GTK_CONTAINER(menu->id), box);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 gtk_widget_show_all(menu->id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 # else /* !HAVE_GTK2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 * Create a highly customized menu item by hand instead of by using:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 * gtk_menu_item_new_with_label(menu->dname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 * This is neccessary, since there is no other way in GTK+ 1 to get the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 * not automatically parsed accellerator stuff right.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 menu_item_new(vimmenu_T *menu, GtkWidget *parent_widget)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 GtkWidget *widget;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 GtkWidget *bin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 GtkWidget *label;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 guint accel_key;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 widget = gtk_widget_new(GTK_TYPE_MENU_ITEM,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 "GtkWidget::visible", TRUE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 "GtkWidget::sensitive", TRUE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 /* "GtkWidget::parent", parent->submenu_id, */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 bin = gtk_widget_new(GTK_TYPE_HBOX,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508 "GtkWidget::visible", TRUE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 "GtkWidget::parent", widget,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 "GtkBox::spacing", 16,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 label = gtk_widget_new(GTK_TYPE_ACCEL_LABEL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 "GtkWidget::visible", TRUE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 "GtkWidget::parent", bin,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 "GtkAccelLabel::accel_widget", widget,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516 "GtkMisc::xalign", 0.0,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 menu->label = label;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 if (menu->actext)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 gtk_widget_new(GTK_TYPE_LABEL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 "GtkWidget::visible", TRUE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 "GtkWidget::parent", bin,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 "GtkLabel::label", menu->actext,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 "GtkMisc::xalign", 1.0,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 * Translate VIM accelerator tagging into GTK+'s. Note that since GTK uses
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 * underscores as the accelerator key, we need to add an additional under-
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 * score for each understore that appears in the menu name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 # ifdef GTK_USE_ACCEL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 name = translate_mnemonic_tag(menu->name,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 (p_wak[0] != 'n' || !GTK_IS_MENU_BAR(parent_widget)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 name = translate_mnemonic_tag(menu->name, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 /* let GTK do its thing */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 accel_key = gtk_label_parse_uline(GTK_LABEL(label), (const char *)name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 vim_free(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 # ifdef GTK_USE_ACCEL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545 /* Don't add accelator if 'winaltkeys' is "no". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 if (accel_key != GDK_VoidSymbol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 if (GTK_IS_MENU_BAR(parent_widget))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 if (*p_wak != 'n')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 gtk_widget_add_accelerator(widget,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 "activate_item",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 gui.accel_group,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 accel_key, GDK_MOD1_MASK,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 (GtkAccelFlags)0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 gtk_widget_add_accelerator(widget,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 "activate_item",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 gtk_menu_ensure_uline_accel_group(GTK_MENU(parent_widget)),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 accel_key, 0,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 (GtkAccelFlags)0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 # endif /* GTK_USE_ACCEL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 menu->id = widget;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 # endif /* !HAVE_GTK2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 gui_mch_add_menu(vimmenu_T *menu, int idx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 vimmenu_T *parent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 GtkWidget *parent_widget;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 if (menu->name[0] == ']' || menu_is_popup(menu->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 menu->submenu_id = gtk_menu_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 parent = menu->parent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 if ((parent != NULL && parent->submenu_id == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 || !menu_is_menubar(menu->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 parent_widget = (parent != NULL) ? parent->submenu_id : gui.menubar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 menu_item_new(menu, parent_widget);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 /* since the tearoff should always appear first, increment idx */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 if (parent != NULL && !menu_is_popup(parent->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 ++idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 gtk_menu_shell_insert(GTK_MENU_SHELL(parent_widget), menu->id, idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 #ifndef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 * The "Help" menu is a special case, and should be placed at the far
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 * right hand side of the menu-bar. It's detected by its high priority.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 * Right-aligning "Help" is considered bad UI design nowadays.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 * Thus lets disable this for GTK+ 2 to match the environment.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 if (parent == NULL && menu->priority >= 9999)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 gtk_menu_item_right_justify(GTK_MENU_ITEM(menu->id));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 menu->submenu_id = gtk_menu_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 gtk_menu_set_accel_group(GTK_MENU(menu->submenu_id), gui.accel_group);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu->id), menu->submenu_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 menu->tearoff_handle = gtk_tearoff_menu_item_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 if (vim_strchr(p_go, GO_TEAROFF) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 gtk_widget_show(menu->tearoff_handle);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 gtk_menu_prepend(GTK_MENU(menu->submenu_id), menu->tearoff_handle);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 /*ARGSUSED*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 menu_item_activate(GtkWidget *widget, gpointer data)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 gui_menu_cb((vimmenu_T *)data);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 # ifndef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 /* Work around a bug in GTK+ 1: we don't seem to get a focus-in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631 * event after clicking a menu item shown via :popup. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632 if (!gui.in_focus)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 gui_focus_change(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 /* make sure the menu action is taken immediately */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 if (gtk_main_level() > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638 gtk_main_quit();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 # if defined(FEAT_TOOLBAR) && !defined(HAVE_GTK2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 * These are the pixmaps used for the default buttons.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 * Order must exactly match toolbar_names[] in menu.c!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 static char **(built_in_pixmaps[]) =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 tb_new_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 tb_open_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 tb_save_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 tb_undo_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652 tb_redo_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 tb_cut_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 tb_copy_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655 tb_paste_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 tb_print_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 tb_help_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 tb_find_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 tb_save_all_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660 tb_save_session_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 tb_new_session_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 tb_load_session_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 tb_macro_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 tb_replace_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 tb_close_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666 tb_maximize_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667 tb_minimize_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 tb_split_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669 tb_shell_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 tb_find_prev_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671 tb_find_next_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672 tb_find_help_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673 tb_make_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674 tb_jump_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 tb_ctags_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 tb_vsplit_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677 tb_maxwidth_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678 tb_minwidth_xpm,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 tb_exit_xpm
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683 * creates a blank pixmap using tb_blank
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 pixmap_create_from_xpm(char **xpm, GdkPixmap **pixmap, GdkBitmap **mask)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 *pixmap = gdk_pixmap_colormap_create_from_xpm_d(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 gtk_widget_get_colormap(gui.mainwin),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 mask,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 xpm);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 * creates a pixmap by using a built-in number
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 pixmap_create_by_num(int pixmap_num, GdkPixmap **pixmap, GdkBitmap **mask)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 if (pixmap_num >= 0 && pixmap_num < (sizeof(built_in_pixmaps)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703 / sizeof(built_in_pixmaps[0])))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704 pixmap_create_from_xpm(built_in_pixmaps[pixmap_num], pixmap, mask);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 * Creates a pixmap by using the pixmap "name" found in 'runtimepath'/bitmaps/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711 pixmap_create_by_dir(char_u *name, GdkPixmap **pixmap, GdkBitmap **mask)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713 char_u full_pathname[MAXPATHL + 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 if (gui_find_bitmap(name, full_pathname, "xpm") == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716 *pixmap = gdk_pixmap_colormap_create_from_xpm(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 gtk_widget_get_colormap(gui.mainwin),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 mask,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720 &gui.mainwin->style->bg[GTK_STATE_NORMAL],
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 (const char *)full_pathname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 * Creates a pixmap by using the pixmap "fname".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 pixmap_create_from_file(char_u *fname, GdkPixmap **pixmap, GdkBitmap **mask)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730 *pixmap = gdk_pixmap_colormap_create_from_xpm(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732 gtk_widget_get_colormap(gui.mainwin),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 mask,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 &gui.mainwin->style->bg[GTK_STATE_NORMAL],
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 (const char *)fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 # endif /* FEAT_TOOLBAR && !HAVE_GTK2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 gui_mch_add_menu_item(vimmenu_T *menu, int idx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 vimmenu_T *parent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745 parent = menu->parent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
747 # ifdef FEAT_TOOLBAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
748 if (menu_is_toolbar(parent->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
749 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 GtkToolbar *toolbar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
751
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752 toolbar = GTK_TOOLBAR(gui.toolbar);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753 menu->submenu_id = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755 if (menu_is_separator(menu->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757 gtk_toolbar_insert_space(toolbar, idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 menu->id = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
762 # ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763 char_u *text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
764 char_u *tooltip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
766 text = CONVERT_TO_UTF8(menu->dname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 tooltip = CONVERT_TO_UTF8(menu->strings[MENU_INDEX_TIP]);
26
404aac550f35 updated for version 7.0017
vimboss
parents: 7
diff changeset
768 if (tooltip != NULL && !utf_valid_string(tooltip, NULL))
404aac550f35 updated for version 7.0017
vimboss
parents: 7
diff changeset
769 /* Invalid text, can happen when 'encoding' is changed. Avoid
404aac550f35 updated for version 7.0017
vimboss
parents: 7
diff changeset
770 * a nasty GTK error message, skip the tooltip. */
404aac550f35 updated for version 7.0017
vimboss
parents: 7
diff changeset
771 CONVERT_TO_UTF8_FREE(tooltip);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 menu->id = gtk_toolbar_insert_item(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774 toolbar,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 (const char *)text,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 (const char *)tooltip,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777 NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 create_menu_icon(menu, gtk_toolbar_get_icon_size(toolbar)),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 G_CALLBACK(&menu_item_activate),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 menu,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781 idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782
790
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
783 if (gtk_socket_id != 0)
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
784 gtk_signal_connect(GTK_OBJECT(menu->id), "focus_in_event",
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
785 GTK_SIGNAL_FUNC(toolbar_button_focus_in_event), NULL);
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
786
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787 CONVERT_TO_UTF8_FREE(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
788 CONVERT_TO_UTF8_FREE(tooltip);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 # else /* !HAVE_GTK2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792 GdkPixmap *pixmap = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 GdkBitmap *mask = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 /* First try user specified bitmap, then builtin, the a blank. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 if (menu->iconfile != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
798 char_u buf[MAXPATHL + 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 gui_find_iconfile(menu->iconfile, buf, "xpm");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
801 pixmap_create_from_file(buf, &pixmap, &mask);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 if (pixmap == NULL && !menu->icon_builtin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804 pixmap_create_by_dir(menu->name, &pixmap, &mask);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 if (pixmap == NULL && menu->iconidx >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 pixmap_create_by_num(menu->iconidx, &pixmap, &mask);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807 if (pixmap == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 pixmap_create_from_xpm(tb_blank_xpm, &pixmap, &mask);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809 if (pixmap == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810 return; /* should at least have blank pixmap, but if not... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
811
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
812 menu->id = gtk_toolbar_insert_item(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
813 toolbar,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
814 (char *)(menu->dname),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
815 (char *)(menu->strings[MENU_INDEX_TIP]),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
816 (char *)(menu->dname),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
817 gtk_pixmap_new(pixmap, mask),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
818 GTK_SIGNAL_FUNC(menu_item_activate),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
819 (gpointer)menu,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
820 idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
821 # endif /* !HAVE_GTK2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
822 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
823 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
824 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
825 # endif /* FEAT_TOOLBAR */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
826 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
827 /* No parent, must be a non-menubar menu */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
828 if (parent->submenu_id == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
829 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
830
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
831 /* Make place for the possible tearoff handle item. Not in the popup
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
832 * menu, it doesn't have a tearoff item. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
833 if (parent != NULL && !menu_is_popup(parent->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
834 ++idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
835
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
836 if (menu_is_separator(menu->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
837 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
838 /* Separator: Just add it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
839 menu->id = gtk_menu_item_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
840 gtk_widget_set_sensitive(menu->id, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
841 gtk_widget_show(menu->id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
842 gtk_menu_insert(GTK_MENU(parent->submenu_id), menu->id, idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
843
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
844 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
845 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
846
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
847 /* Add textual menu item. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
848 menu_item_new(menu, parent->submenu_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
849 gtk_widget_show(menu->id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
850 gtk_menu_insert(GTK_MENU(parent->submenu_id), menu->id, idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
851
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
852 if (menu->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
853 gtk_signal_connect(GTK_OBJECT(menu->id), "activate",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
854 GTK_SIGNAL_FUNC(menu_item_activate), menu);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
855 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
856 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
857 #endif /* FEAT_MENU */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
858
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
859
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
860 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
861 gui_mch_set_text_area_pos(int x, int y, int w, int h)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
862 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
863 gtk_form_move_resize(GTK_FORM(gui.formwin), gui.drawarea, x, y, w, h);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
864 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
865
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
866
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
867 #if defined(FEAT_MENU) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
868 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
869 * Enable or disable accelators for the toplevel menus.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
870 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
871 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
872 gui_gtk_set_mnemonics(int enable)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
874 vimmenu_T *menu;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
875 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
876 # if !defined(HAVE_GTK2) && defined(GTK_USE_ACCEL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
877 guint accel_key;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
878 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
880 for (menu = root_menu; menu != NULL; menu = menu->next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
881 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
882 if (menu->id == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
883 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
884
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
885 # if defined(HAVE_GTK2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
886 name = translate_mnemonic_tag(menu->name, enable);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
887 gtk_label_set_text_with_mnemonic(GTK_LABEL(menu->label),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
888 (const char *)name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
889 vim_free(name);
133
bcb347a8f934 updated for version 7.0044
vimboss
parents: 95
diff changeset
890 # else
bcb347a8f934 updated for version 7.0044
vimboss
parents: 95
diff changeset
891 # if defined(GTK_USE_ACCEL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
892 name = translate_mnemonic_tag(menu->name, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893 if (name != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
894 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
895 accel_key = gtk_label_parse_uline(GTK_LABEL(menu->label),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
896 (const char *)name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897 if (accel_key != GDK_VoidSymbol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
898 gtk_widget_remove_accelerator(menu->id, gui.accel_group,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
899 accel_key, GDK_MOD1_MASK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
900 if (enable && accel_key != GDK_VoidSymbol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
901 gtk_widget_add_accelerator(menu->id, "activate_item",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902 gui.accel_group,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
903 accel_key, GDK_MOD1_MASK,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
904 (GtkAccelFlags)0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
905 vim_free(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
906 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
907 if (!enable)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
908 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
909 name = translate_mnemonic_tag(menu->name, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910 gtk_label_parse_uline(GTK_LABEL(menu->label), (const char *)name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
911 vim_free(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
912 }
133
bcb347a8f934 updated for version 7.0044
vimboss
parents: 95
diff changeset
913 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
914 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
915 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
916 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
917
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
918 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
919 recurse_tearoffs(vimmenu_T *menu, int val)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
920 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
921 for (; menu != NULL; menu = menu->next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
922 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
923 if (menu->submenu_id != NULL && menu->tearoff_handle != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
924 && menu->name[0] != ']' && !menu_is_popup(menu->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
925 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
926 if (val)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
927 gtk_widget_show(menu->tearoff_handle);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
928 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
929 gtk_widget_hide(menu->tearoff_handle);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
930 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
931 recurse_tearoffs(menu->children, val);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
932 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
933 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
934
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
935 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
936 gui_mch_toggle_tearoffs(int enable)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
937 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
938 recurse_tearoffs(root_menu, enable);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
939 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
940 #endif /* FEAT_MENU */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
941
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
942
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
943 #if defined(FEAT_TOOLBAR) && !defined(HAVE_GTK2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
944 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
945 * Seems like there's a hole in the GTK Toolbar API: there's no provision for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
946 * removing an item from the toolbar. Therefore I need to resort to going
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
947 * really deeply into the internal widget structures.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
948 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
949 * <danielk> I'm not sure the statement above is true -- at least with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
950 * GTK+ 2 one can just call gtk_widget_destroy() and be done with it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
951 * It is true though that you couldn't remove space items before GTK+ 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
952 * (without digging into the internals that is). But the code below
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
953 * doesn't seem to handle those either. Well, it's obsolete anyway.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
954 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
955 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
956 toolbar_remove_item_by_text(GtkToolbar *tb, const char *text)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
957 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
958 GtkContainer *container;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
959 GList *childl;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
960 GtkToolbarChild *gtbc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
961
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
962 g_return_if_fail(tb != NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
963 g_return_if_fail(GTK_IS_TOOLBAR(tb));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
964 container = GTK_CONTAINER(&tb->container);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
965
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
966 for (childl = tb->children; childl; childl = childl->next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
967 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
968 gtbc = (GtkToolbarChild *)childl->data;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
969
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
970 if (gtbc->type != GTK_TOOLBAR_CHILD_SPACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
971 && strcmp(GTK_LABEL(gtbc->label)->label, text) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
972 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
973 gboolean was_visible;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
974
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
975 was_visible = GTK_WIDGET_VISIBLE(gtbc->widget);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
976 gtk_widget_unparent(gtbc->widget);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
977
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
978 tb->children = g_list_remove_link(tb->children, childl);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
979 g_free(gtbc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
980 g_list_free(childl);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
981 tb->num_children--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
982
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
983 if (was_visible && GTK_WIDGET_VISIBLE(container))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
984 gtk_widget_queue_resize(GTK_WIDGET(container));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
985
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
986 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
987 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
988 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
989 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
990 #endif /* FEAT_TOOLBAR && !HAVE_GTK2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
991
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
992
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
993 #if defined(FEAT_TOOLBAR) && defined(HAVE_GTK2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
994 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
995 get_menu_position(vimmenu_T *menu)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
996 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
997 vimmenu_T *node;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
998 int index = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
999
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1000 for (node = menu->parent->children; node != menu; node = node->next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1001 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1002 g_return_val_if_fail(node != NULL, -1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1003 ++index;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1006 return index;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1007 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1008 #endif /* FEAT_TOOLBAR && HAVE_GTK2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1009
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1010
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1011 #if defined(FEAT_TOOLBAR) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1012 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1013 gui_mch_menu_set_tip(vimmenu_T *menu)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1014 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1015 if (menu->id != NULL && menu->parent != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1016 && gui.toolbar != NULL && menu_is_toolbar(menu->parent->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1017 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1018 char_u *tooltip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1019
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1020 # ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1021 tooltip = CONVERT_TO_UTF8(menu->strings[MENU_INDEX_TIP]);
26
404aac550f35 updated for version 7.0017
vimboss
parents: 7
diff changeset
1022 if (tooltip == NULL || utf_valid_string(tooltip, NULL))
404aac550f35 updated for version 7.0017
vimboss
parents: 7
diff changeset
1023 /* Only set the tooltip when it's valid utf-8. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1024 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1025 tooltip = menu->strings[MENU_INDEX_TIP];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1026 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1027 gtk_tooltips_set_tip(GTK_TOOLBAR(gui.toolbar)->tooltips,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1028 menu->id, (const char *)tooltip, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1029 # ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1030 CONVERT_TO_UTF8_FREE(tooltip);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1031 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1032 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1033 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1034 #endif /* FEAT_TOOLBAR */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1035
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1036
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1037 #if defined(FEAT_MENU) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1038 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1039 * Destroy the machine specific menu widget.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1040 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1041 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1042 gui_mch_destroy_menu(vimmenu_T *menu)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1043 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1044 # ifdef FEAT_TOOLBAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1045 if (menu->parent != NULL && menu_is_toolbar(menu->parent->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1046 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1047 # ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1048 if (menu_is_separator(menu->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1049 gtk_toolbar_remove_space(GTK_TOOLBAR(gui.toolbar),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1050 get_menu_position(menu));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1051 else if (menu->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1052 gtk_widget_destroy(menu->id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1053 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1054 toolbar_remove_item_by_text(GTK_TOOLBAR(gui.toolbar),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1055 (const char *)menu->dname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1056 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1057 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1058 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1059 # endif /* FEAT_TOOLBAR */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1060 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1061 if (menu->submenu_id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1062 gtk_widget_destroy(menu->submenu_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1063
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1064 if (menu->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1065 gtk_widget_destroy(menu->id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1066 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1067
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1068 menu->submenu_id = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1069 menu->id = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1070 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1071 #endif /* FEAT_MENU */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1072
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1073
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1074 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1075 * Scrollbar stuff.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1076 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1077 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1078 gui_mch_set_scrollbar_thumb(scrollbar_T *sb, long val, long size, long max)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1079 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1080 if (sb->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1081 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1082 GtkAdjustment *adjustment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1083
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1084 adjustment = gtk_range_get_adjustment(GTK_RANGE(sb->id));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1085
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1086 adjustment->lower = 0.0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1087 adjustment->value = val;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1088 adjustment->upper = max + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1089 adjustment->page_size = size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1090 adjustment->page_increment = size < 3L ? 1L : size - 2L;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1091 adjustment->step_increment = 1.0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1092
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1093 #ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1094 g_signal_handler_block(GTK_OBJECT(adjustment),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1095 (gulong)sb->handler_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1096 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1097 gtk_signal_handler_block(GTK_OBJECT(adjustment),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1098 (guint)sb->handler_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1099 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1100 gtk_adjustment_changed(adjustment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1101 #ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1102 g_signal_handler_unblock(GTK_OBJECT(adjustment),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1103 (gulong)sb->handler_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1104 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1105 gtk_signal_handler_unblock(GTK_OBJECT(adjustment),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1106 (guint)sb->handler_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1107 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1108 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1109 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1110
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1111 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1112 gui_mch_set_scrollbar_pos(scrollbar_T *sb, int x, int y, int w, int h)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1113 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1114 if (sb->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1115 gtk_form_move_resize(GTK_FORM(gui.formwin), sb->id, x, y, w, h);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1116 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1117
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1118 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1119 * Take action upon scrollbar dragging.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1120 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1121 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1122 adjustment_value_changed(GtkAdjustment *adjustment, gpointer data)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1123 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1124 scrollbar_T *sb;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1125 long value;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1126 int dragging = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1127
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1128 #ifdef FEAT_XIM
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1129 /* cancel any preediting */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1130 if (im_is_preediting())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1131 xim_reset();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1132 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1133
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1134 sb = gui_find_scrollbar((long)data);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1135 value = (long)adjustment->value;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1136 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1137 * The dragging argument must be right for the scrollbar to work with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1138 * closed folds. This isn't documented, hopefully this will keep on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1139 * working in later GTK versions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1140 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1141 * FIXME: Well, it doesn't work in GTK2. :)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1142 * HACK: Get the mouse pointer position, if it appears to be on an arrow
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1143 * button set "dragging" to FALSE. This assumes square buttons!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1144 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1145 if (sb != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1146 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1147 #ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1148 dragging = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1149
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1150 if (sb->wp != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1151 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1152 int x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1153 int y;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1154 GdkModifierType state;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1155 int width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1156 int height;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1158 /* vertical scrollbar: need to set "dragging" properly in case
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1159 * there are closed folds. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1160 gdk_window_get_pointer(sb->id->window, &x, &y, &state);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1161 gdk_window_get_size(sb->id->window, &width, &height);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1162 if (x >= 0 && x < width && y >= 0 && y < height)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1163 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164 if (y < width)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1166 /* up arrow: move one (closed fold) line up */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1167 dragging = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1168 value = sb->wp->w_topline - 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1169 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1170 else if (y > height - width)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1171 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1172 /* down arrow: move one (closed fold) line down */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1173 dragging = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1174 value = sb->wp->w_topline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1175 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1176 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1177 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1179 dragging = (GTK_RANGE(sb->id)->scroll_type == GTK_SCROLL_NONE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1181 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1183 gui_drag_scrollbar(sb, value, dragging);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185 if (gtk_main_level() > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1186 gtk_main_quit();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1188
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1189 /* SBAR_VERT or SBAR_HORIZ */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1190 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191 gui_mch_create_scrollbar(scrollbar_T *sb, int orient)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1192 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193 if (orient == SBAR_HORIZ)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1194 sb->id = gtk_hscrollbar_new(NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195 else if (orient == SBAR_VERT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1196 sb->id = gtk_vscrollbar_new(NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1198 if (sb->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1199 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200 GtkAdjustment *adjustment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202 GTK_WIDGET_UNSET_FLAGS(sb->id, GTK_CAN_FOCUS);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1203 gtk_form_put(GTK_FORM(gui.formwin), sb->id, 0, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1204
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205 adjustment = gtk_range_get_adjustment(GTK_RANGE(sb->id));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1207 sb->handler_id = gtk_signal_connect(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1208 GTK_OBJECT(adjustment), "value_changed",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209 GTK_SIGNAL_FUNC(adjustment_value_changed),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210 GINT_TO_POINTER(sb->ident));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211 gui_mch_update();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1213 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215 #if defined(FEAT_WINDOWS) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217 gui_mch_destroy_scrollbar(scrollbar_T *sb)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 if (sb->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221 gtk_widget_destroy(sb->id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222 sb->id = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 gui_mch_update();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1227
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1228 #if defined(FEAT_BROWSE) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1229 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1230 * Implementation of the file selector related stuff
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1231 */
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1232 #if defined(HAVE_GTK2) && GTK_CHECK_VERSION(2,4,0)
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1233 # define USE_FILE_CHOOSER
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1234 #endif
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1235
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1236 #ifndef USE_FILE_CHOOSER
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237 /*ARGSUSED*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239 browse_ok_cb(GtkWidget *widget, gpointer cbdata)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1240 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1241 gui_T *vw = (gui_T *)cbdata;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1242
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243 if (vw->browse_fname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1244 g_free(vw->browse_fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1245
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1246 vw->browse_fname = (char_u *)g_strdup(gtk_file_selection_get_filename(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1247 GTK_FILE_SELECTION(vw->filedlg)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1248 gtk_widget_hide(vw->filedlg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1249 if (gtk_main_level() > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1250 gtk_main_quit();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1251 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1252
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1253 /*ARGSUSED*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1255 browse_cancel_cb(GtkWidget *widget, gpointer cbdata)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1256 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1257 gui_T *vw = (gui_T *)cbdata;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1258
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1259 if (vw->browse_fname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1260 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1261 g_free(vw->browse_fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1262 vw->browse_fname = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1263 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1264 gtk_widget_hide(vw->filedlg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1265 if (gtk_main_level() > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1266 gtk_main_quit();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1267 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1268
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1269 /*ARGSUSED*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1270 static gboolean
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1271 browse_destroy_cb(GtkWidget * widget)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1272 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273 if (gui.browse_fname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1274 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1275 g_free(gui.browse_fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1276 gui.browse_fname = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1277 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1278 gui.filedlg = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1279
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1280 if (gtk_main_level() > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1281 gtk_main_quit();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1282
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1283 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1284 }
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1285 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1286
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1287 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1288 * Put up a file requester.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1289 * Returns the selected name in allocated memory, or NULL for Cancel.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1290 * saving, select file to write
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1291 * title title for the window
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1292 * dflt default name
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1293 * ext not used (extension added)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1294 * initdir initial directory, NULL for current dir
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1295 * filter not used (file name filter)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1296 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1297 /*ARGSUSED*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1298 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1299 gui_mch_browse(int saving,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1300 char_u *title,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1301 char_u *dflt,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1302 char_u *ext,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1303 char_u *initdir,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1304 char_u *filter)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1305 {
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1306 #ifdef USE_FILE_CHOOSER
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1307 GtkWidget *fc;
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1308 #endif
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1309 char_u dirbuf[MAXPATHL];
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1310 char_u *p;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1311
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1312 # ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1313 title = CONVERT_TO_UTF8(title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1314 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1315
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1316 /* Concatenate "initdir" and "dflt". */
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1317 if (initdir == NULL || *initdir == NUL)
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1318 mch_dirname(dirbuf, MAXPATHL);
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1319 else if (STRLEN(initdir) + 2 < MAXPATHL)
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1320 STRCPY(dirbuf, initdir);
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1321 else
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1322 dirbuf[0] = NUL;
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1323 /* Always need a trailing slash for a directory. */
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1324 add_pathsep(dirbuf);
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1325 if (dflt != NULL && *dflt != NUL
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1326 && STRLEN(dirbuf) + 2 + STRLEN(dflt) < MAXPATHL)
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1327 STRCAT(dirbuf, dflt);
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1328
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1329 /* If our pointer is currently hidden, then we should show it. */
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1330 gui_mch_mousehide(FALSE);
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1331
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1332 #ifdef USE_FILE_CHOOSER
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1333 /* We create the dialog each time, so that the button text can be "Open"
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1334 * or "Save" according to the action. */
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1335 fc = gtk_file_chooser_dialog_new((const gchar *)title,
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1336 GTK_WINDOW(gui.mainwin),
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1337 saving ? GTK_FILE_CHOOSER_ACTION_SAVE
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1338 : GTK_FILE_CHOOSER_ACTION_OPEN,
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1339 saving ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1340 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1341 NULL);
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1342 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fc),
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1343 (const gchar *)dirbuf);
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1344
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1345 gui.browse_fname = NULL;
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1346 if (gtk_dialog_run(GTK_DIALOG(fc)) == GTK_RESPONSE_ACCEPT)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1347 {
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1348 char *filename;
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1349
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1350 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fc));
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1351 gui.browse_fname = (char_u *)g_strdup(filename);
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1352 g_free(filename);
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1353 }
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1354 gtk_widget_destroy(GTK_WIDGET(fc));
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1355
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1356 #else
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1357
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1358 if (gui.filedlg == NULL)
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1359 {
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1360 GtkFileSelection *fs; /* shortcut */
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1361
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1362 gui.filedlg = gtk_file_selection_new((const gchar *)title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1363 gtk_window_set_modal(GTK_WINDOW(gui.filedlg), TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1364 gtk_window_set_transient_for(GTK_WINDOW(gui.filedlg),
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1365 GTK_WINDOW(gui.mainwin));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1366 fs = GTK_FILE_SELECTION(gui.filedlg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1367
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1368 gtk_container_border_width(GTK_CONTAINER(fs), 4);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1369
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1370 gtk_signal_connect(GTK_OBJECT(fs->ok_button),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1371 "clicked", GTK_SIGNAL_FUNC(browse_ok_cb), &gui);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1372 gtk_signal_connect(GTK_OBJECT(fs->cancel_button),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1373 "clicked", GTK_SIGNAL_FUNC(browse_cancel_cb), &gui);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1374 /* gtk_signal_connect() doesn't work for destroy, it causes a hang */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1375 gtk_signal_connect_object(GTK_OBJECT(gui.filedlg),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1376 "destroy", GTK_SIGNAL_FUNC(browse_destroy_cb),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1377 GTK_OBJECT(gui.filedlg));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1378 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1379 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1380 gtk_window_set_title(GTK_WINDOW(gui.filedlg), (const gchar *)title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1381
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1382 gtk_file_selection_set_filename(GTK_FILE_SELECTION(gui.filedlg),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1383 (const gchar *)dirbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1384 # ifndef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1385 gui_gtk_position_in_parent(GTK_WIDGET(gui.mainwin),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1386 GTK_WIDGET(gui.filedlg), VW_POS_MOUSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1387 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1388
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1389 gtk_widget_show(gui.filedlg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1390 while (gui.filedlg && GTK_WIDGET_DRAWABLE(gui.filedlg))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1391 gtk_main_iteration_do(TRUE);
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1392 #endif
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1393
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1394 # ifdef HAVE_GTK2
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1395 CONVERT_TO_UTF8_FREE(title);
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1396 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1397 if (gui.browse_fname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1398 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1399
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1400 /* shorten the file name if possible */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1401 mch_dirname(dirbuf, MAXPATHL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1402 p = shorten_fname(gui.browse_fname, dirbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1403 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1404 p = gui.browse_fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1405 return vim_strsave(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1406 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1407
41
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1408 #if defined(HAVE_GTK2) || defined(PROTO)
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1409
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1410 /*
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1411 * Put up a directory selector
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1412 * Returns the selected name in allocated memory, or NULL for Cancel.
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1413 * title title for the window
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1414 * dflt default name
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1415 * initdir initial directory, NULL for current dir
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1416 */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1417 /*ARGSUSED*/
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1418 char_u *
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1419 gui_mch_browsedir(
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1420 char_u *title,
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1421 char_u *initdir)
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1422 {
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1423 # if defined(GTK_FILE_CHOOSER) /* Only in GTK 2.4 and later. */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1424 char_u dirbuf[MAXPATHL];
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1425 char_u *p;
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1426 GtkWidget *dirdlg; /* file selection dialog */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1427 char_u *dirname = NULL;
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1428
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1429 title = CONVERT_TO_UTF8(title);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1430
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1431 dirdlg = gtk_file_chooser_dialog_new(
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1432 (const gchar *)title,
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1433 GTK_WINDOW(gui.mainwin),
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1434 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1435 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1436 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1437 NULL);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1438
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1439 CONVERT_TO_UTF8_FREE(title);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1440
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1441 /* if our pointer is currently hidden, then we should show it. */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1442 gui_mch_mousehide(FALSE);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1443
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1444 /* GTK appears to insist on an absolute path. */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1445 if (initdir == NULL || *initdir == NUL
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1446 || vim_FullName(initdir, dirbuf, MAXPATHL - 10, FALSE) == FAIL)
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1447 mch_dirname(dirbuf, MAXPATHL - 10);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1448
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1449 /* Always need a trailing slash for a directory.
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1450 * Also add a dummy file name, so that we get to the directory. */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1451 add_pathsep(dirbuf);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1452 STRCAT(dirbuf, "@zd(*&1|");
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1453 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dirdlg),
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1454 (const gchar *)dirbuf);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1455
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1456 /* Run the dialog. */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1457 if (gtk_dialog_run(GTK_DIALOG(dirdlg)) == GTK_RESPONSE_ACCEPT)
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1458 dirname = (char_u *)gtk_file_chooser_get_filename(
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1459 GTK_FILE_CHOOSER(dirdlg));
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1460 gtk_widget_destroy(dirdlg);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1461 if (dirname == NULL)
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1462 return NULL;
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1463
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1464 /* shorten the file name if possible */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1465 mch_dirname(dirbuf, MAXPATHL);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1466 p = shorten_fname(dirname, dirbuf);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1467 if (p == NULL || *p == NUL)
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1468 p = dirname;
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1469 p = vim_strsave(p);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1470 g_free(dirname);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1471 return p;
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1472
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1473 # else
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1474 /* For GTK 2.2 and earlier: fall back to ordinary file selector. */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1475 return gui_mch_browse(0, title, NULL, NULL, initdir, NULL);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1476 # endif
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1477 }
41
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1478 #endif
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
1479
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
1480
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1481 #endif /* FEAT_BROWSE */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1482
95
a2081e6febb8 updated for version 7.0037
vimboss
parents: 68
diff changeset
1483 #if defined(FEAT_GUI_DIALOG) && !defined(HAVE_GTK2)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1484
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1485 static char_u *dialog_textfield = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1486 static GtkWidget *dialog_textentry;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1487
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1488 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1489 dlg_destroy(GtkWidget *dlg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1490 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1491 if (dialog_textfield != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1492 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1493 const char *text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1494
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1495 text = gtk_entry_get_text(GTK_ENTRY(dialog_textentry));
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 401
diff changeset
1496 vim_strncpy(dialog_textfield, (char_u *)text, IOSIZE - 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1497 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1498
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1499 /* Destroy the dialog, will break the waiting loop. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1500 gtk_widget_destroy(dlg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1501 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1502
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1503 # ifdef FEAT_GUI_GNOME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1504 /* ARGSUSED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1505 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1506 gui_gnome_dialog( int type,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1507 char_u *title,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1508 char_u *message,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1509 char_u *buttons,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1510 int dfltbutton,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1511 char_u *textfield)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1512 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1513 GtkWidget *dlg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1514 char *gdtype;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1515 char_u *buttons_copy, *p, *next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1516 char **buttons_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1517 int butcount, cur;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1518
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1519 /* make a copy, so that we can insert NULs */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1520 if ((buttons_copy = vim_strsave(buttons)) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1521 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1522
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1523 /* determine exact number of buttons and allocate array to hold them */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1524 for (butcount = 0, p = buttons; *p; p++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1525 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1526 if (*p == '\n')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1527 butcount++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1528 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1529 butcount++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1530 buttons_list = g_new0(char *, butcount + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1531
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1532 /* Add pixmap */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1533 switch (type)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1534 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1535 case VIM_ERROR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1536 gdtype = GNOME_MESSAGE_BOX_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1537 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1538 case VIM_WARNING:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1539 gdtype = GNOME_MESSAGE_BOX_WARNING;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1540 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1541 case VIM_INFO:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1542 gdtype = GNOME_MESSAGE_BOX_INFO;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1543 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1544 case VIM_QUESTION:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1545 gdtype = GNOME_MESSAGE_BOX_QUESTION;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1546 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1547 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1548 gdtype = GNOME_MESSAGE_BOX_GENERIC;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1549 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1550
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1551 p = buttons_copy;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1552 for (cur = 0; cur < butcount; ++cur)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1553 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1554 for (next = p; *next; ++next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1555 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1556 if (*next == DLG_HOTKEY_CHAR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1557 mch_memmove(next, next + 1, STRLEN(next));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1558 if (*next == DLG_BUTTON_SEP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1559 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1560 *next++ = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1561 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1562 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1563 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1564
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1565 /* this should probably go into a table, but oh well */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1566 if (g_strcasecmp((char *)p, "Ok") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1567 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_OK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1568 else if (g_strcasecmp((char *)p, "Cancel") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1569 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_CANCEL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1570 else if (g_strcasecmp((char *)p, "Yes") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1571 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_YES);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1572 else if (g_strcasecmp((char *)p, "No") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1573 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_NO);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1574 else if (g_strcasecmp((char *)p, "Close") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1575 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_CLOSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1576 else if (g_strcasecmp((char *)p, "Help") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1577 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_HELP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1578 else if (g_strcasecmp((char *)p, "Apply") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1579 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_APPLY);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1580 #if 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1581 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1582 * these aren't really used that often anyway, but are listed here as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1583 * placeholders in case we need them.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1584 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1585 else if (g_strcasecmp((char *)p, "Next") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1586 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_NEXT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1587 else if (g_strcasecmp((char *)p, "Prev") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1588 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_PREV);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1589 else if (g_strcasecmp((char *)p, "Up") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1590 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_UP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1591 else if (g_strcasecmp((char *)p, "Down") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1592 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_DOWN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1593 else if (g_strcasecmp((char *)p, "Font") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1594 buttons_list[cur] = g_strdup(GNOME_STOCK_BUTTON_FONT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1595 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1596 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1597 buttons_list[cur] = g_strdup((char *)p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1598
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1599 if (*next == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1600 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1601
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1602 p = next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1603 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1604 vim_free(buttons_copy);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1605
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1606 dlg = gnome_message_box_newv((const char *)message,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1607 (const char *)gdtype,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1608 (const char **)buttons_list);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1609 for (cur = 0; cur < butcount; ++cur)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1610 g_free(buttons_list[cur]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1611 g_free(buttons_list);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1612
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1613 dialog_textfield = textfield;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1614 if (textfield != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1615 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1616 /* Add text entry field */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1617 dialog_textentry = gtk_entry_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1618 gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dlg)->vbox), dialog_textentry,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1619 TRUE, TRUE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1620 gtk_entry_set_text(GTK_ENTRY(dialog_textentry),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1621 (const gchar *)textfield);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1622 gtk_entry_select_region(GTK_ENTRY(dialog_textentry), 0,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1623 STRLEN(textfield));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1624 gtk_entry_set_max_length(GTK_ENTRY(dialog_textentry), IOSIZE - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1625 gtk_entry_set_position(GTK_ENTRY(dialog_textentry), STRLEN(textfield));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1626 gtk_widget_show(dialog_textentry);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1627 gtk_window_set_focus(GTK_WINDOW(dlg), dialog_textentry);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1628 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1629
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1630 gtk_signal_connect_object(GTK_OBJECT(dlg), "destroy",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1631 GTK_SIGNAL_FUNC(dlg_destroy), GTK_OBJECT(dlg));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1632 gnome_dialog_set_default(GNOME_DIALOG(dlg), dfltbutton + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1633 gui_gtk_position_in_parent(GTK_WIDGET(gui.mainwin),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1634 GTK_WIDGET(dlg), VW_POS_MOUSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1635
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1636 return (1 + gnome_dialog_run_and_close(GNOME_DIALOG(dlg)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1637 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1638
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1639 # endif /* FEAT_GUI_GNOME */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1640
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1641 typedef struct _ButtonData
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1642 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1643 int *status;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1644 int index;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1645 GtkWidget *dialog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1646 } ButtonData;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1647
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1648 typedef struct _CancelData
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1649 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1650 int *status;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1651 int ignore_enter;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1652 GtkWidget *dialog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1653 } CancelData;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1654
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1655 /* ARGSUSED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1656 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1657 dlg_button_clicked(GtkWidget * widget, ButtonData *data)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1658 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1659 *(data->status) = data->index + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1660 dlg_destroy(data->dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1661 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1662
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1663 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1664 * This makes the Escape key equivalent to the cancel button.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1665 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1666 /*ARGSUSED*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1667 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1668 dlg_key_press_event(GtkWidget * widget, GdkEventKey * event, CancelData *data)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1669 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1670 /* Ignore hitting Enter when there is no default button. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1671 if (data->ignore_enter && event->keyval == GDK_Return)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1672 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1673
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1674 if (event->keyval != GDK_Escape && event->keyval != GDK_Return)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1675 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1676
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1677 /* The result value of 0 from a dialog is signaling cancelation.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1678 * 1 means OK. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1679 *(data->status) = (event->keyval == GDK_Return);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1680 dlg_destroy(data->dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1681
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1682 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1683 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1684
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1685 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1686 * Callback function for when the dialog was destroyed by a window manager.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1687 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1688 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1689 dlg_destroy_cb(int *p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1690 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1691 *p = TRUE; /* set dialog_destroyed to break out of the loop */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1692 if (gtk_main_level() > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1693 gtk_main_quit();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1694 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1695
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1696 /* ARGSUSED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1697 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1698 gui_mch_dialog( int type, /* type of dialog */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1699 char_u *title, /* title of dialog */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1700 char_u *message, /* message text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1701 char_u *buttons, /* names of buttons */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1702 int def_but, /* default button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1703 char_u *textfield) /* text for textfield or NULL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1704 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1705 char_u *names;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1706 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1707 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1708 int butcount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1709 int dialog_status = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1710 int dialog_destroyed = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1711 int vertical;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1712
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1713 GtkWidget *dialog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1714 GtkWidget *frame;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1715 GtkWidget *vbox;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1716 GtkWidget *table;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1717 GtkWidget *dialogmessage;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1718 GtkWidget *action_area;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1719 GtkWidget *sub_area;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1720 GtkWidget *separator;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1721 GtkAccelGroup *accel_group;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1722 GtkWidget *pixmap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1723 GdkPixmap *icon = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1724 GdkBitmap *mask = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1725 char **icon_data = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1726
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1727 GtkWidget **button;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1728 ButtonData *data;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1729 CancelData cancel_data;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1730
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1731 /* if our pointer is currently hidden, then we should show it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1732 gui_mch_mousehide(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1733
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1734 # ifdef FEAT_GUI_GNOME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1735 /* If Gnome is available, use it for the dialog. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1736 if (gtk_socket_id == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1737 return gui_gnome_dialog(type, title, message, buttons, def_but,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1738 textfield);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1739 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1740
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1741 if (title == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1742 title = (char_u *)_("Vim dialog...");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1743
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1744 if ((type < 0) || (type > VIM_LAST_TYPE))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1745 type = VIM_GENERIC;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1746
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1747 /* Check 'v' flag in 'guioptions': vertical button placement. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1748 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1749
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1750 dialog = gtk_window_new(GTK_WINDOW_DIALOG);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1751 gtk_window_set_title(GTK_WINDOW(dialog), (const gchar *)title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1752 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gui.mainwin));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1753 gtk_widget_realize(dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1754 gdk_window_set_decorations(dialog->window, GDK_DECOR_BORDER);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1755 gdk_window_set_functions(dialog->window, GDK_FUNC_MOVE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1756
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1757 cancel_data.status = &dialog_status;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1758 cancel_data.dialog = dialog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1759 gtk_signal_connect_after(GTK_OBJECT(dialog), "key_press_event",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1760 GTK_SIGNAL_FUNC(dlg_key_press_event),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1761 (gpointer) &cancel_data);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1762 /* Catch the destroy signal, otherwise we don't notice a window manager
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1763 * destroying the dialog window. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1764 gtk_signal_connect_object(GTK_OBJECT(dialog), "destroy",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1765 GTK_SIGNAL_FUNC(dlg_destroy_cb),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1766 (gpointer)&dialog_destroyed);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1767
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1768 gtk_grab_add(dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1769
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1770 /* this makes it look beter on Motif style window managers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1771 frame = gtk_frame_new(NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1772 gtk_container_add(GTK_CONTAINER(dialog), frame);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1773 gtk_widget_show(frame);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1774
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1775 vbox = gtk_vbox_new(FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1776 gtk_container_add(GTK_CONTAINER(frame), vbox);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1777 gtk_widget_show(vbox);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1778
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1779 table = gtk_table_new(1, 3, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1780 gtk_table_set_row_spacings(GTK_TABLE(table), 4);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1781 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1782 gtk_container_border_width(GTK_CONTAINER(table), 4);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1783 gtk_box_pack_start(GTK_BOX(vbox), table, 4, 4, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1784 gtk_widget_show(table);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1785
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1786 /* Add pixmap */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1787 switch (type)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1788 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1789 case VIM_GENERIC:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1790 icon_data = generic_xpm;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1791 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1792 case VIM_ERROR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1793 icon_data = error_xpm;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1794 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1795 case VIM_WARNING:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1796 icon_data = alert_xpm;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1797 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1798 case VIM_INFO:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1799 icon_data = info_xpm;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1800 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1801 case VIM_QUESTION:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1802 icon_data = quest_xpm;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1803 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1804 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1805 icon_data = generic_xpm;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1806 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1807 icon = gdk_pixmap_colormap_create_from_xpm_d(NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1808 gtk_widget_get_colormap(dialog),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1809 &mask, NULL, icon_data);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1810 if (icon)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1811 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1812 pixmap = gtk_pixmap_new(icon, mask);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1813 /* gtk_misc_set_alignment(GTK_MISC(pixmap), 0.5, 0.5); */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1814 gtk_table_attach_defaults(GTK_TABLE(table), pixmap, 0, 1, 0, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1815 gtk_widget_show(pixmap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1816 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1817
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1818 /* Add label */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1819 dialogmessage = gtk_label_new((const gchar *)message);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1820 gtk_table_attach_defaults(GTK_TABLE(table), dialogmessage, 1, 2, 0, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1821 gtk_widget_show(dialogmessage);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1822
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1823 dialog_textfield = textfield;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1824 if (textfield != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1825 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1826 /* Add text entry field */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1827 dialog_textentry = gtk_entry_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1828 gtk_widget_set_usize(dialog_textentry, 400, -2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1829 gtk_box_pack_start(GTK_BOX(vbox), dialog_textentry, TRUE, TRUE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1830 gtk_entry_set_text(GTK_ENTRY(dialog_textentry),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1831 (const gchar *)textfield);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1832 gtk_entry_select_region(GTK_ENTRY(dialog_textentry), 0,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1833 STRLEN(textfield));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1834 gtk_entry_set_max_length(GTK_ENTRY(dialog_textentry), IOSIZE - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1835 gtk_entry_set_position(GTK_ENTRY(dialog_textentry), STRLEN(textfield));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1836 gtk_widget_show(dialog_textentry);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1837 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1838
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1839 /* Add box for buttons */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1840 action_area = gtk_hbox_new(FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1841 gtk_container_border_width(GTK_CONTAINER(action_area), 4);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1842 gtk_box_pack_end(GTK_BOX(vbox), action_area, FALSE, TRUE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1843 gtk_widget_show(action_area);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1844
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1845 /* Add a [vh]box in the hbox to center the buttons in the dialog. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1846 if (vertical)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1847 sub_area = gtk_vbox_new(FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1848 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1849 sub_area = gtk_hbox_new(FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1850 gtk_container_set_border_width(GTK_CONTAINER(sub_area), 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1851 gtk_box_pack_start(GTK_BOX(action_area), sub_area, TRUE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1852 gtk_widget_show(sub_area);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1853
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1854 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1855 * Create the buttons.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1856 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1857
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1858 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1859 * Translate the Vim accelerator character into an underscore for GTK+.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1860 * Double underscores to keep them in the label.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1861 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1862 /* count the number of underscores */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1863 i = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1864 for (p = buttons; *p; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1865 if (*p == '_')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1866 ++i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1867
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1868 /* make a copy of "buttons" with the translated characters */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1869 names = alloc(STRLEN(buttons) + i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1870 if (names == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1871 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1872
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1873 p = names;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1874 for (i = 0; buttons[i]; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1875 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1876 if (buttons[i] == DLG_HOTKEY_CHAR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1877 *p++ = '_';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1878 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1879 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1880 if (buttons[i] == '_')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1881 *p++ = '_';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1882 *p++ = buttons[i];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1883 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1884 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1885 *p = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1886
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1887 /* Count the number of buttons and allocate button[] and data[]. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1888 butcount = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1889 for (p = names; *p; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1890 if (*p == DLG_BUTTON_SEP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1891 ++butcount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1892 button = (GtkWidget **)alloc((unsigned)(butcount * sizeof(GtkWidget *)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1893 data = (ButtonData *)alloc((unsigned)(butcount * sizeof(ButtonData)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1894 if (button == NULL || data == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1895 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1896 vim_free(names);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1897 vim_free(button);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1898 vim_free(data);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1899 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1900 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1901
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1902 /* Attach the new accelerator group to the window. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1903 accel_group = gtk_accel_group_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1904 gtk_accel_group_attach(accel_group, GTK_OBJECT(dialog));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1905
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1906 p = names;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1907 for (butcount = 0; *p; ++butcount)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1908 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1909 char_u *next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1910 GtkWidget *label;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1911 # ifdef GTK_USE_ACCEL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1912 guint accel_key;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1913 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1914
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1915 /* Chunk out this single button. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1916 for (next = p; *next; ++next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1917 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1918 if (*next == DLG_BUTTON_SEP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1919 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1920 *next++ = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1921 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1922 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1923 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1924
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1925 button[butcount] = gtk_button_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1926 GTK_WIDGET_SET_FLAGS(button[butcount], GTK_CAN_DEFAULT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1927
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1928 label = gtk_accel_label_new("");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1929 gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(label), dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1930
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1931 # ifdef GTK_USE_ACCEL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1932 accel_key = gtk_label_parse_uline(GTK_LABEL(label), (const gchar *)p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1933 /* Don't add accelator if 'winaltkeys' is "no". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1934 if (accel_key != GDK_VoidSymbol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1935 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1936 gtk_widget_add_accelerator(button[butcount],
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1937 "clicked",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1938 accel_group,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1939 accel_key, 0,
133
bcb347a8f934 updated for version 7.0044
vimboss
parents: 95
diff changeset
1940 (GtkAccelFlags)0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1941 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1942 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1943 (void)gtk_label_parse_uline(GTK_LABEL(label), (const gchar *)p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1944 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1945
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1946 gtk_container_add(GTK_CONTAINER(button[butcount]), label);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1947 gtk_widget_show_all(button[butcount]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1948
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1949 data[butcount].status = &dialog_status;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1950 data[butcount].index = butcount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1951 data[butcount].dialog = dialog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1952 gtk_signal_connect(GTK_OBJECT(button[butcount]),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1953 (const char *)"clicked",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1954 GTK_SIGNAL_FUNC(dlg_button_clicked),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1955 (gpointer) &data[butcount]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1956
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1957 gtk_box_pack_start(GTK_BOX(sub_area), button[butcount],
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1958 TRUE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1959 p = next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1960 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1961
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1962 vim_free(names);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1963
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1964 cancel_data.ignore_enter = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1965 if (butcount > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1966 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1967 --def_but; /* 1 is first button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1968 if (def_but >= butcount)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1969 def_but = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1970 if (def_but >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1971 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1972 gtk_widget_grab_focus(button[def_but]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1973 gtk_widget_grab_default(button[def_but]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1974 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1975 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1976 /* No default, ignore hitting Enter. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1977 cancel_data.ignore_enter = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1978 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1979
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1980 if (textfield != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1981 gtk_window_set_focus(GTK_WINDOW(dialog), dialog_textentry);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1982
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1983 separator = gtk_hseparator_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1984 gtk_box_pack_end(GTK_BOX(vbox), separator, FALSE, TRUE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1985 gtk_widget_show(separator);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1986
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1987 dialog_status = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1988
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1989 gui_gtk_position_in_parent(GTK_WIDGET(gui.mainwin),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1990 GTK_WIDGET(dialog), VW_POS_MOUSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1991
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1992 gtk_widget_show(dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1993
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1994 /* loop here until the dialog goes away */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1995 while (dialog_status == -1 && !dialog_destroyed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1996 && GTK_WIDGET_DRAWABLE(dialog))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1997 gtk_main_iteration_do(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1998
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1999 if (dialog_status < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2000 dialog_status = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2001 if (dialog_status != 1 && textfield != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2002 *textfield = NUL; /* dialog was cancelled */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2003
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2004 /* let the garbage collector know that we don't need it any longer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2005 gtk_accel_group_unref(accel_group);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2006
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2007 vim_free(button);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2008 vim_free(data);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2009
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2010 return dialog_status;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2011 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2012
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2013 #endif /* FEAT_GUI_DIALOG && !HAVE_GTK2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2014
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2015
95
a2081e6febb8 updated for version 7.0037
vimboss
parents: 68
diff changeset
2016 #if (defined(FEAT_GUI_DIALOG) && defined(HAVE_GTK2)) || defined(PROTO)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2017
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2018 static GtkWidget *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2019 create_message_dialog(int type, char_u *title, char_u *message)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2020 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2021 GtkWidget *dialog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2022 GtkMessageType message_type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2023
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2024 switch (type)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2025 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2026 case VIM_ERROR: message_type = GTK_MESSAGE_ERROR; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2027 case VIM_WARNING: message_type = GTK_MESSAGE_WARNING; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2028 case VIM_QUESTION: message_type = GTK_MESSAGE_QUESTION; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2029 default: message_type = GTK_MESSAGE_INFO; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2030 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2031
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2032 message = CONVERT_TO_UTF8(message);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2033 dialog = gtk_message_dialog_new(GTK_WINDOW(gui.mainwin),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2034 GTK_DIALOG_DESTROY_WITH_PARENT,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2035 message_type,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2036 GTK_BUTTONS_NONE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2037 "%s", (const char *)message);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2038 CONVERT_TO_UTF8_FREE(message);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2039
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2040 if (title != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2041 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2042 title = CONVERT_TO_UTF8(title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2043 gtk_window_set_title(GTK_WINDOW(dialog), (const char *)title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2044 CONVERT_TO_UTF8_FREE(title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2045 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2046 else if (type == VIM_GENERIC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2047 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2048 gtk_window_set_title(GTK_WINDOW(dialog), "VIM");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2049 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2050
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2051 return dialog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2052 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2053
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2054 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2055 * Split up button_string into individual button labels by inserting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2056 * NUL bytes. Also replace the Vim-style mnemonic accelerator prefix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2057 * '&' with '_'. button_string must point to allocated memory!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2058 * Return an allocated array of pointers into button_string.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2059 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2060 static char **
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2061 split_button_string(char_u *button_string, int *n_buttons)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2062 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2063 char **array;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2064 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2065 unsigned int count = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2066
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2067 for (p = button_string; *p != NUL; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2068 if (*p == DLG_BUTTON_SEP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2069 ++count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2070
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2071 array = (char **)alloc((count + 1) * sizeof(char *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2072 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2073
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2074 if (array != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2075 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2076 array[count++] = (char *)button_string;
40
f1d2a58883b9 updated for version 7.0024
vimboss
parents: 39
diff changeset
2077 for (p = button_string; *p != NUL; )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2078 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2079 if (*p == DLG_BUTTON_SEP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2080 {
40
f1d2a58883b9 updated for version 7.0024
vimboss
parents: 39
diff changeset
2081 *p++ = NUL;
f1d2a58883b9 updated for version 7.0024
vimboss
parents: 39
diff changeset
2082 array[count++] = (char *)p;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2083 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2084 else if (*p == DLG_HOTKEY_CHAR)
40
f1d2a58883b9 updated for version 7.0024
vimboss
parents: 39
diff changeset
2085 *p++ = '_';
f1d2a58883b9 updated for version 7.0024
vimboss
parents: 39
diff changeset
2086 else
f1d2a58883b9 updated for version 7.0024
vimboss
parents: 39
diff changeset
2087 mb_ptr_adv(p);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2088 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2089 array[count] = NULL; /* currently not relied upon, but doesn't hurt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2090 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2091
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2092 *n_buttons = count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2093 return array;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2094 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2095
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2096 static char **
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2097 split_button_translation(const char *message)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2098 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2099 char **buttons = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2100 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2101 int n_buttons = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2102 int n_expected = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2103
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2104 for (str = (char_u *)message; *str != NUL; ++str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2105 if (*str == DLG_BUTTON_SEP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2106 ++n_expected;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2107
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2108 str = (char_u *)_(message);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2109 if (str != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2110 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2111 if (output_conv.vc_type != CONV_NONE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2112 str = string_convert(&output_conv, str, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2113 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2114 str = vim_strsave(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2115
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2116 if (str != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2117 buttons = split_button_string(str, &n_buttons);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2118 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2119 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2120 * Uh-oh... this should never ever happen. But we don't wanna crash
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2121 * if the translation is broken, thus fall back to the untranslated
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2122 * buttons string in case of emergency.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2123 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2124 if (buttons == NULL || n_buttons != n_expected)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2125 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2126 vim_free(buttons);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2127 vim_free(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2128 buttons = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2129 str = vim_strsave((char_u *)message);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2130
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2131 if (str != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2132 buttons = split_button_string(str, &n_buttons);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2133 if (buttons == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2134 vim_free(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2135 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2136
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2137 return buttons;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2138 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2139
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2140 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2141 button_equal(const char *a, const char *b)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2142 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2143 while (*a != '\0' && *b != '\0')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2144 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2145 if (*a == '_' && *++a == '\0')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2146 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2147 if (*b == '_' && *++b == '\0')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2148 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2149
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2150 if (g_unichar_tolower(g_utf8_get_char(a))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2151 != g_unichar_tolower(g_utf8_get_char(b)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2152 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2153
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2154 a = g_utf8_next_char(a);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2155 b = g_utf8_next_char(b);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2156 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2157
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2158 return (*a == '\0' && *b == '\0');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2159 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2160
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2161 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2162 dialog_add_buttons(GtkDialog *dialog, char_u *button_string)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2163 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2164 char **ok;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2165 char **ync; /* "yes no cancel" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2166 char **buttons;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2167 int n_buttons = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2168 int index;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2169
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2170 button_string = vim_strsave(button_string); /* must be writable */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2171 if (button_string == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2172 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2173
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2174 /* Check 'v' flag in 'guioptions': vertical button placement. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2175 if (vim_strchr(p_go, GO_VERTICAL) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2176 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2177 GtkWidget *vbutton_box;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2178
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2179 vbutton_box = gtk_vbutton_box_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2180 gtk_widget_show(vbutton_box);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2181 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(dialog)->vbox),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2182 vbutton_box, TRUE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2183 /* Overrule the "action_area" value, hopefully this works... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2184 GTK_DIALOG(dialog)->action_area = vbutton_box;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2185 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2186
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2187 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2188 * Yes this is ugly, I don't particularly like it either. But doing it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2189 * this way has the compelling advantage that translations need not to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2190 * be touched at all. See below what 'ok' and 'ync' are used for.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2191 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2192 ok = split_button_translation(N_("&Ok"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2193 ync = split_button_translation(N_("&Yes\n&No\n&Cancel"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2194 buttons = split_button_string(button_string, &n_buttons);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2195
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2196 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2197 * Yes, the buttons are in reversed order to match the GNOME 2 desktop
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2198 * environment. Don't hit me -- it's all about consistency.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2199 * Well, apparently somebody changed his mind: with GTK 2.2.4 it works the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2200 * other way around...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2201 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2202 for (index = 1; index <= n_buttons; ++index)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2203 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2204 char *label;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2205 char_u *label8;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2206
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2207 label = buttons[index - 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2208 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2209 * Perform some guesswork to find appropriate stock items for the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2210 * buttons. We have to compare with a sample of the translated
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2211 * button string to get things right. Yes, this is hackish :/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2212 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2213 * But even the common button labels aren't necessarily translated,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2214 * since anyone can create their own dialogs using Vim functions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2215 * Thus we have to check for those too.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2216 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2217 if (ok != NULL && ync != NULL) /* almost impossible to fail */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2218 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2219 if (button_equal(label, ok[0])) label = GTK_STOCK_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2220 else if (button_equal(label, ync[0])) label = GTK_STOCK_YES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2221 else if (button_equal(label, ync[1])) label = GTK_STOCK_NO;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2222 else if (button_equal(label, ync[2])) label = GTK_STOCK_CANCEL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2223 else if (button_equal(label, "Ok")) label = GTK_STOCK_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2224 else if (button_equal(label, "Yes")) label = GTK_STOCK_YES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2225 else if (button_equal(label, "No")) label = GTK_STOCK_NO;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2226 else if (button_equal(label, "Cancel")) label = GTK_STOCK_CANCEL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2227 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2228 label8 = CONVERT_TO_UTF8((char_u *)label);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2229 gtk_dialog_add_button(dialog, (const gchar *)label8, index);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2230 CONVERT_TO_UTF8_FREE(label8);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2231 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2232
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2233 if (ok != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2234 vim_free(*ok);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2235 if (ync != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2236 vim_free(*ync);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2237 vim_free(ok);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2238 vim_free(ync);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2239 vim_free(buttons);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2240 vim_free(button_string);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2241 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2242
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2243 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2244 * Allow mnemonic accelerators to be activated without pressing <Alt>.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2245 * I'm not sure if it's a wise idea to do this. However, the old GTK+ 1.2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2246 * GUI used to work this way, and I consider the impact on UI consistency
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2247 * low enough to justify implementing this as a special Vim feature.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2248 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2249 typedef struct _DialogInfo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2250 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2251 int ignore_enter; /* no default button, ignore "Enter" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2252 int noalt; /* accept accelerators without Alt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2253 GtkDialog *dialog; /* Widget of the dialog */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2254 } DialogInfo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2255
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2256 /*ARGSUSED2*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2257 static gboolean
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2258 dialog_key_press_event_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2259 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2260 DialogInfo *di = (DialogInfo *)data;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2261
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2262 /* Ignore hitting "Enter" if there is no default button. */
314
529f887b5cb7 updated for version 7.0082
vimboss
parents: 270
diff changeset
2263 if (event->keyval == GDK_Return)
529f887b5cb7 updated for version 7.0082
vimboss
parents: 270
diff changeset
2264 {
529f887b5cb7 updated for version 7.0082
vimboss
parents: 270
diff changeset
2265 if (!di->ignore_enter)
529f887b5cb7 updated for version 7.0082
vimboss
parents: 270
diff changeset
2266 gtk_dialog_response(di->dialog, GTK_RESPONSE_ACCEPT);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2267 return TRUE;
314
529f887b5cb7 updated for version 7.0082
vimboss
parents: 270
diff changeset
2268 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2269
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2270 /* Close the dialog when hitting "Esc". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2271 if (event->keyval == GDK_Escape)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2272 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2273 gtk_dialog_response(di->dialog, GTK_RESPONSE_REJECT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2274 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2275 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2276
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2277 if (di->noalt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2278 && (event->state & gtk_accelerator_get_default_mod_mask()) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2279 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2280 return gtk_window_mnemonic_activate(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2281 GTK_WINDOW(widget), event->keyval,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2282 gtk_window_get_mnemonic_modifier(GTK_WINDOW(widget)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2283 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2284
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2285 return FALSE; /* continue emission */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2286 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2287
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2288 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2289 gui_mch_dialog(int type, /* type of dialog */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2290 char_u *title, /* title of dialog */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2291 char_u *message, /* message text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2292 char_u *buttons, /* names of buttons */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2293 int def_but, /* default button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2294 char_u *textfield) /* text for textfield or NULL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2295 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2296 GtkWidget *dialog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2297 GtkWidget *entry = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2298 char_u *text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2299 int response;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2300 DialogInfo dialoginfo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2301
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2302 dialog = create_message_dialog(type, title, message);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2303 dialoginfo.dialog = GTK_DIALOG(dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2304 dialog_add_buttons(GTK_DIALOG(dialog), buttons);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2305
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2306 if (textfield != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2307 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2308 GtkWidget *alignment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2309
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2310 entry = gtk_entry_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2311 gtk_widget_show(entry);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2312
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2313 text = CONVERT_TO_UTF8(textfield);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2314 gtk_entry_set_text(GTK_ENTRY(entry), (const char *)text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2315 CONVERT_TO_UTF8_FREE(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2316
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2317 alignment = gtk_alignment_new((float)0.5, (float)0.5,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2318 (float)1.0, (float)1.0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2319 gtk_container_add(GTK_CONTAINER(alignment), entry);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2320 gtk_container_set_border_width(GTK_CONTAINER(alignment), 5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2321 gtk_widget_show(alignment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2322
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2323 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2324 alignment, TRUE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2325 dialoginfo.noalt = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2326 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2327 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2328 dialoginfo.noalt = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2329
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2330 /* Allow activation of mnemonic accelerators without pressing <Alt> when
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2331 * there is no textfield. Handle pressing Enter and Esc. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2332 g_signal_connect(G_OBJECT(dialog), "key_press_event",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2333 G_CALLBACK(&dialog_key_press_event_cb), &dialoginfo);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2334
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2335 if (def_but > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2336 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2337 gtk_dialog_set_default_response(GTK_DIALOG(dialog), def_but);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2338 dialoginfo.ignore_enter = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2339 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2340 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2341 /* No default button, ignore pressing Enter. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2342 dialoginfo.ignore_enter = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2343
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2344 /* Show the mouse pointer if it's currently hidden. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2345 gui_mch_mousehide(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2346
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2347 response = gtk_dialog_run(GTK_DIALOG(dialog));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2348
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2349 /* GTK_RESPONSE_NONE means the dialog was programmatically destroyed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2350 if (response != GTK_RESPONSE_NONE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2351 {
314
529f887b5cb7 updated for version 7.0082
vimboss
parents: 270
diff changeset
2352 if (response == GTK_RESPONSE_ACCEPT) /* Enter pressed */
529f887b5cb7 updated for version 7.0082
vimboss
parents: 270
diff changeset
2353 response = def_but;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2354 if (textfield != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2355 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2356 text = (char_u *)gtk_entry_get_text(GTK_ENTRY(entry));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2357 text = CONVERT_FROM_UTF8(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2358
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 401
diff changeset
2359 vim_strncpy(textfield, text, IOSIZE - 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2360
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2361 CONVERT_FROM_UTF8_FREE(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2362 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2363 gtk_widget_destroy(dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2364 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2365
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2366 /* Terrible hack: When the text area still has focus when we remove the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2367 * dialog, somehow gvim loses window focus. This is with "point to type"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2368 * in the KDE 3.1 window manager. Warp the mouse pointer to outside the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2369 * window and back to avoid that. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2370 if (!gui.in_focus)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2371 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2372 int x, y;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2373
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2374 gdk_window_get_pointer(gui.drawarea->window, &x, &y, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2375 gui_mch_setmouse(-100, -100);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2376 gui_mch_setmouse(x, y);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2377 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2378
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2379 return response > 0 ? response : 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2380 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2381
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2382 #endif /* FEAT_GUI_DIALOG && HAVE_GTK2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2383
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2384
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2385 #if defined(FEAT_MENU) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2386
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2387 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2388 gui_mch_show_popupmenu(vimmenu_T *menu)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2389 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2390 # if defined(FEAT_XIM) && defined(HAVE_GTK2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2391 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2392 * Append a submenu for selecting an input method. This is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2393 * currently the only way to switch input methods at runtime.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2394 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2395 if (xic != NULL && g_object_get_data(G_OBJECT(menu->submenu_id),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2396 "vim-has-im-menu") == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2397 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2398 GtkWidget *menuitem;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2399 GtkWidget *submenu;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2400 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2401
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2402 menuitem = gtk_separator_menu_item_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2403 gtk_widget_show(menuitem);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2404 gtk_menu_shell_append(GTK_MENU_SHELL(menu->submenu_id), menuitem);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2405
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2406 name = (char_u *)_("Input _Methods");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2407 name = CONVERT_TO_UTF8(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2408 menuitem = gtk_menu_item_new_with_mnemonic((const char *)name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2409 CONVERT_TO_UTF8_FREE(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2410 gtk_widget_show(menuitem);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2411
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2412 submenu = gtk_menu_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2413 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2414 gtk_menu_shell_append(GTK_MENU_SHELL(menu->submenu_id), menuitem);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2415
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2416 gtk_im_multicontext_append_menuitems(GTK_IM_MULTICONTEXT(xic),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2417 GTK_MENU_SHELL(submenu));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2418 g_object_set_data(G_OBJECT(menu->submenu_id),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2419 "vim-has-im-menu", GINT_TO_POINTER(TRUE));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2420 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2421 # endif /* FEAT_XIM && HAVE_GTK2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2422
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2423 gtk_menu_popup(GTK_MENU(menu->submenu_id),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2424 NULL, NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2425 (GtkMenuPositionFunc)NULL, NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2426 3U, (guint32)GDK_CURRENT_TIME);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2427 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2428
401
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
2429 /* Ugly global variable to pass "mouse_pos" flag from gui_make_popup() to
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
2430 * popup_menu_position_func(). */
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
2431 static int popup_mouse_pos;
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
2432
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2433 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2434 * Menu position callback; used by gui_make_popup() to place the menu
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2435 * at the current text cursor position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2436 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2437 * Note: The push_in output argument seems to affect scrolling of huge
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2438 * menus that don't fit on the screen. Leave it at the default for now.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2439 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2440 /*ARGSUSED0*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2441 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2442 popup_menu_position_func(GtkMenu *menu,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2443 gint *x, gint *y,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2444 # ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2445 gboolean *push_in,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2446 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2447 gpointer user_data)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2448 {
401
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
2449 gdk_window_get_origin(gui.drawarea->window, x, y);
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
2450
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
2451 if (popup_mouse_pos)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2452 {
401
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
2453 int mx, my;
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
2454
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
2455 gui_mch_getmouse(&mx, &my);
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
2456 *x += mx;
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
2457 *y += my;
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
2458 }
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
2459 else if (curwin != NULL && gui.drawarea != NULL && gui.drawarea->window != NULL)
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
2460 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2461 /* Find the cursor position in the current window */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2462 *x += FILL_X(W_WINCOL(curwin) + curwin->w_wcol + 1) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2463 *y += FILL_Y(W_WINROW(curwin) + curwin->w_wrow + 1) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2464 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2465 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2466
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2467 void
401
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
2468 gui_make_popup(char_u *path_name, int mouse_pos)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2469 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2470 vimmenu_T *menu;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2471
401
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
2472 popup_mouse_pos = mouse_pos;
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
2473
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2474 menu = gui_find_menu(path_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2475
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2476 if (menu != NULL && menu->submenu_id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2477 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2478 gtk_menu_popup(GTK_MENU(menu->submenu_id),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2479 NULL, NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2480 &popup_menu_position_func, NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2481 0U, (guint32)GDK_CURRENT_TIME);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2482 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2483 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2484
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2485 #endif /* FEAT_MENU */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2486
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2487
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2488 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2489 * We don't create it twice.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2490 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2491
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2492 typedef struct _SharedFindReplace
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2493 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2494 GtkWidget *dialog; /* the main dialog widget */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2495 GtkWidget *wword; /* 'Whole word only' check button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2496 GtkWidget *mcase; /* 'Match case' check button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2497 GtkWidget *up; /* search direction 'Up' radio button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2498 GtkWidget *down; /* search direction 'Down' radio button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2499 GtkWidget *what; /* 'Find what' entry text widget */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2500 GtkWidget *with; /* 'Replace with' entry text widget */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2501 GtkWidget *find; /* 'Find Next' action button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2502 GtkWidget *replace; /* 'Replace With' action button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2503 GtkWidget *all; /* 'Replace All' action button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2504 } SharedFindReplace;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2505
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2506 static SharedFindReplace find_widgets = { NULL, };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2507 static SharedFindReplace repl_widgets = { NULL, };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2508
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2509 /* ARGSUSED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2510 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2511 find_key_press_event(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2512 GtkWidget *widget,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2513 GdkEventKey *event,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2514 SharedFindReplace *frdp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2515 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2516 /* If the user is holding one of the key modifiers we will just bail out,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2517 * thus preserving the possibility of normal focus traversal.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2518 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2519 if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2520 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2521
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2522 /* the Escape key synthesizes a cancellation action */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2523 if (event->keyval == GDK_Escape)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2524 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2525 gtk_widget_hide(frdp->dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2526
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2527 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2528 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2529 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2530 * What the **** is this for? Disabled for GTK+ 2 because due to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2531 * gtk_signal_connect_after() it doesn't have any effect anyway.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2532 * (Fortunately.)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2533 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2534 #ifndef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2535 /* block traversal resulting from those keys */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2536 if (event->keyval == GDK_Left
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2537 || event->keyval == GDK_Right
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2538 || event->keyval == GDK_space)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2539 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2540 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2541
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2542 /* It would be delightfull if it where possible to do search history
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2543 * operations on the K_UP and K_DOWN keys here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2544 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2545
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2546 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2547 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2548
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2549 #ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2550 static GtkWidget *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2551 create_image_button(const char *stock_id, const char *label)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2552 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2553 char_u *text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2554 GtkWidget *box;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2555 GtkWidget *alignment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2556 GtkWidget *button;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2557
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2558 text = CONVERT_TO_UTF8((char_u *)label);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2559
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2560 box = gtk_hbox_new(FALSE, 3);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2561 gtk_box_pack_start(GTK_BOX(box),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2562 gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_BUTTON),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2563 FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2564 gtk_box_pack_start(GTK_BOX(box),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2565 gtk_label_new((const char *)text),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2566 FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2567
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2568 CONVERT_TO_UTF8_FREE(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2569
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2570 alignment = gtk_alignment_new((float)0.5, (float)0.5,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2571 (float)0.0, (float)0.0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2572 gtk_container_add(GTK_CONTAINER(alignment), box);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2573 gtk_widget_show_all(alignment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2574
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2575 button = gtk_button_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2576 gtk_container_add(GTK_CONTAINER(button), alignment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2577
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2578 return button;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2579 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2580
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2581 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2582 * This is currently only used by find_replace_dialog_create(), and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2583 * I'd really like to keep it at that. In other words: don't spread
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2584 * this nasty hack all over the code. Think twice.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2585 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2586 static const char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2587 convert_localized_message(char_u **buffer, const char *message)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2588 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2589 if (output_conv.vc_type == CONV_NONE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2590 return message;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2591
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2592 vim_free(*buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2593 *buffer = string_convert(&output_conv, (char_u *)message, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2594
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2595 return (const char *)*buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2596 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2597 #endif /* HAVE_GTK2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2598
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2599 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2600 find_replace_dialog_create(char_u *arg, int do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2601 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2602 #ifndef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2603 GtkWidget *frame;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2604 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2605 GtkWidget *hbox; /* main top down box */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2606 GtkWidget *actionarea;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2607 GtkWidget *table;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2608 GtkWidget *tmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2609 GtkWidget *vbox;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2610 gboolean sensitive;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2611 SharedFindReplace *frdp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2612 char_u *entry_text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2613 int wword = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2614 int mcase = !p_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2615 #ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2616 char_u *conv_buffer = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2617 # define CONV(message) convert_localized_message(&conv_buffer, (message))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2618 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2619 # define CONV(message) (message)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2620 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2621
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2622 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2623
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2624 /* Get the search string to use. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2625 entry_text = get_find_dialog_text(arg, &wword, &mcase);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2626
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2627 #ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2628 if (entry_text != NULL && output_conv.vc_type != CONV_NONE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2629 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2630 char_u *old_text = entry_text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2631 entry_text = string_convert(&output_conv, entry_text, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2632 vim_free(old_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2633 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2634 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2635
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2636 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2637 * If the dialog already exists, just raise it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2638 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2639 if (frdp->dialog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2640 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2641 #ifndef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2642 /* always make the dialog appear where you want it even if the mainwin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2643 * has moved -- dbv */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2644 gui_gtk_position_in_parent(GTK_WIDGET(gui.mainwin),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2645 GTK_WIDGET(frdp->dialog), VW_POS_MOUSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2646 gui_gtk_synch_fonts();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2647
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2648 if (!GTK_WIDGET_VISIBLE(frdp->dialog))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2649 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2650 gtk_widget_grab_focus(frdp->what);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2651 gtk_widget_show(frdp->dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2652 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2653 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2654 if (entry_text != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2655 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2656 gtk_entry_set_text(GTK_ENTRY(frdp->what), (char *)entry_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2657 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->wword),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2658 (gboolean)wword);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2659 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->mcase),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2660 (gboolean)mcase);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2661 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2662 #ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2663 gtk_window_present(GTK_WINDOW(frdp->dialog));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2664 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2665 gdk_window_raise(frdp->dialog->window);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2666 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2667 vim_free(entry_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2668 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2669 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2670
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2671 #ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2672 frdp->dialog = gtk_dialog_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2673 gtk_dialog_set_has_separator(GTK_DIALOG(frdp->dialog), FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2674 gtk_window_set_transient_for(GTK_WINDOW(frdp->dialog), GTK_WINDOW(gui.mainwin));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2675 gtk_window_set_destroy_with_parent(GTK_WINDOW(frdp->dialog), TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2676 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2677 frdp->dialog = gtk_window_new(GTK_WINDOW_DIALOG);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2678 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2679
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2680 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2681 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2682 #ifndef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2683 gtk_window_set_wmclass(GTK_WINDOW(frdp->dialog), "searchrepl", "gvim");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2684 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2685 gtk_window_set_title(GTK_WINDOW(frdp->dialog),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2686 CONV(_("VIM - Search and Replace...")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2687 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2688 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2689 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2690 #ifndef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2691 gtk_window_set_wmclass(GTK_WINDOW(frdp->dialog), "search", "gvim");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2692 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2693 gtk_window_set_title(GTK_WINDOW(frdp->dialog),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2694 CONV(_("VIM - Search...")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2695 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2696
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2697 #ifndef HAVE_GTK2 /* Utter crack. Shudder. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2698 gtk_widget_realize(frdp->dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2699 gdk_window_set_decorations(frdp->dialog->window,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2700 GDK_DECOR_TITLE | GDK_DECOR_BORDER | GDK_DECOR_RESIZEH);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2701 gdk_window_set_functions(frdp->dialog->window,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2702 GDK_FUNC_RESIZE | GDK_FUNC_MOVE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2703 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2704
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2705 #ifndef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2706 /* this makes it look better on Motif style window managers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2707 frame = gtk_frame_new(NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2708 gtk_container_add(GTK_CONTAINER(frdp->dialog), frame);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2709 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2710
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2711 hbox = gtk_hbox_new(FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2712 #ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2713 gtk_container_set_border_width(GTK_CONTAINER(hbox), 10);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2714 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(frdp->dialog)->vbox), hbox);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2715 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2716 gtk_container_add(GTK_CONTAINER(frame), hbox);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2717 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2718
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2719 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2720 table = gtk_table_new(1024, 4, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2721 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2722 table = gtk_table_new(1024, 3, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2723 gtk_box_pack_start(GTK_BOX(hbox), table, TRUE, TRUE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2724 gtk_container_border_width(GTK_CONTAINER(table), 4);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2725
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2726 tmp = gtk_label_new(CONV(_("Find what:")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2727 gtk_misc_set_alignment(GTK_MISC(tmp), (gfloat)0.0, (gfloat)0.5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2728 gtk_table_attach(GTK_TABLE(table), tmp, 0, 1, 0, 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2729 GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2730 frdp->what = gtk_entry_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2731 sensitive = (entry_text != NULL && entry_text[0] != NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2732 if (entry_text != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2733 gtk_entry_set_text(GTK_ENTRY(frdp->what), (char *)entry_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2734 gtk_signal_connect(GTK_OBJECT(frdp->what), "changed",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2735 GTK_SIGNAL_FUNC(entry_changed_cb), frdp->dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2736 gtk_signal_connect_after(GTK_OBJECT(frdp->what), "key_press_event",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2737 GTK_SIGNAL_FUNC(find_key_press_event),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2738 (gpointer) frdp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2739 gtk_table_attach(GTK_TABLE(table), frdp->what, 1, 1024, 0, 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2740 GTK_EXPAND | GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2741
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2742 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2743 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2744 tmp = gtk_label_new(CONV(_("Replace with:")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2745 gtk_misc_set_alignment(GTK_MISC(tmp), (gfloat)0.0, (gfloat)0.5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2746 gtk_table_attach(GTK_TABLE(table), tmp, 0, 1, 1, 2,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2747 GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2748 frdp->with = gtk_entry_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2749 gtk_signal_connect(GTK_OBJECT(frdp->with), "activate",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2750 GTK_SIGNAL_FUNC(find_replace_cb),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2751 GINT_TO_POINTER(FRD_R_FINDNEXT));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2752 gtk_signal_connect_after(GTK_OBJECT(frdp->with), "key_press_event",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2753 GTK_SIGNAL_FUNC(find_key_press_event),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2754 (gpointer) frdp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2755 gtk_table_attach(GTK_TABLE(table), frdp->with, 1, 1024, 1, 2,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2756 GTK_EXPAND | GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2757
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2758 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2759 * Make the entry activation only change the input focus onto the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2760 * with item.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2761 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2762 gtk_signal_connect(GTK_OBJECT(frdp->what), "activate",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2763 GTK_SIGNAL_FUNC(entry_activate_cb), frdp->with);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2764 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2765 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2766 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2767 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2768 * Make the entry activation do the search.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2769 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2770 gtk_signal_connect(GTK_OBJECT(frdp->what), "activate",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2771 GTK_SIGNAL_FUNC(find_replace_cb),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2772 GINT_TO_POINTER(FRD_FINDNEXT));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2773 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2774
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2775 /* whole word only button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2776 frdp->wword = gtk_check_button_new_with_label(CONV(_("Match whole word only")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2777 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->wword),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2778 (gboolean)wword);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2779 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2780 gtk_table_attach(GTK_TABLE(table), frdp->wword, 0, 1023, 2, 3,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2781 GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2782 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2783 gtk_table_attach(GTK_TABLE(table), frdp->wword, 0, 1023, 1, 2,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2784 GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2785
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2786 /* match case button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2787 frdp->mcase = gtk_check_button_new_with_label(CONV(_("Match case")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2788 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->mcase),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2789 (gboolean)mcase);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2790 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2791 gtk_table_attach(GTK_TABLE(table), frdp->mcase, 0, 1023, 3, 4,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2792 GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2793 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2794 gtk_table_attach(GTK_TABLE(table), frdp->mcase, 0, 1023, 2, 3,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2795 GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2796
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2797 tmp = gtk_frame_new(CONV(_("Direction")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2798 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2799 gtk_table_attach(GTK_TABLE(table), tmp, 1023, 1024, 2, 4,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2800 GTK_FILL, GTK_FILL, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2801 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2802 gtk_table_attach(GTK_TABLE(table), tmp, 1023, 1024, 1, 3,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2803 GTK_FILL, GTK_FILL, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2804 vbox = gtk_vbox_new(FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2805 gtk_container_border_width(GTK_CONTAINER(vbox), 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2806 gtk_container_add(GTK_CONTAINER(tmp), vbox);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2807
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2808 /* 'Up' and 'Down' buttons */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2809 frdp->up = gtk_radio_button_new_with_label(NULL, CONV(_("Up")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2810 gtk_box_pack_start(GTK_BOX(vbox), frdp->up, TRUE, TRUE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2811 frdp->down = gtk_radio_button_new_with_label(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2812 gtk_radio_button_group(GTK_RADIO_BUTTON(frdp->up)),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2813 CONV(_("Down")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2814 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->down), TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2815 #ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2816 gtk_container_set_border_width(GTK_CONTAINER(vbox), 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2817 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2818 gtk_box_pack_start(GTK_BOX(vbox), frdp->down, TRUE, TRUE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2819
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2820 /* vbox to hold the action buttons */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2821 actionarea = gtk_vbutton_box_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2822 gtk_container_border_width(GTK_CONTAINER(actionarea), 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2823 #ifndef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2824 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2825 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2826 gtk_button_box_set_layout(GTK_BUTTON_BOX(actionarea),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2827 GTK_BUTTONBOX_END);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2828 gtk_button_box_set_spacing(GTK_BUTTON_BOX(actionarea), 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2829 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2830 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2831 gtk_box_pack_end(GTK_BOX(hbox), actionarea, FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2832
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2833 /* 'Find Next' button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2834 #ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2835 frdp->find = create_image_button(GTK_STOCK_FIND, _("Find Next"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2836 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2837 frdp->find = gtk_button_new_with_label(_("Find Next"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2838 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2839 gtk_widget_set_sensitive(frdp->find, sensitive);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2840
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2841 gtk_signal_connect(GTK_OBJECT(frdp->find), "clicked",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2842 GTK_SIGNAL_FUNC(find_replace_cb),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2843 (do_replace) ? GINT_TO_POINTER(FRD_R_FINDNEXT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2844 : GINT_TO_POINTER(FRD_FINDNEXT));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2845
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2846 GTK_WIDGET_SET_FLAGS(frdp->find, GTK_CAN_DEFAULT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2847 gtk_box_pack_start(GTK_BOX(actionarea), frdp->find, FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2848 gtk_widget_grab_default(frdp->find);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2849
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2850 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2851 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2852 /* 'Replace' button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2853 #ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2854 frdp->replace = create_image_button(GTK_STOCK_CONVERT, _("Replace"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2855 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2856 frdp->replace = gtk_button_new_with_label(_("Replace"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2857 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2858 gtk_widget_set_sensitive(frdp->replace, sensitive);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2859 GTK_WIDGET_SET_FLAGS(frdp->replace, GTK_CAN_DEFAULT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2860 gtk_box_pack_start(GTK_BOX(actionarea), frdp->replace, FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2861 gtk_signal_connect(GTK_OBJECT(frdp->replace), "clicked",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2862 GTK_SIGNAL_FUNC(find_replace_cb),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2863 GINT_TO_POINTER(FRD_REPLACE));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2864
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2865 /* 'Replace All' button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2866 #ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2867 frdp->all = create_image_button(GTK_STOCK_CONVERT, _("Replace All"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2868 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2869 frdp->all = gtk_button_new_with_label(_("Replace All"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2870 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2871 gtk_widget_set_sensitive(frdp->all, sensitive);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2872 GTK_WIDGET_SET_FLAGS(frdp->all, GTK_CAN_DEFAULT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2873 gtk_box_pack_start(GTK_BOX(actionarea), frdp->all, FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2874 gtk_signal_connect(GTK_OBJECT(frdp->all), "clicked",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2875 GTK_SIGNAL_FUNC(find_replace_cb),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2876 GINT_TO_POINTER(FRD_REPLACEALL));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2877 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2878
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2879 /* 'Cancel' button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2880 #ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2881 tmp = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2882 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2883 tmp = gtk_button_new_with_label(_("Cancel"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2884 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2885 GTK_WIDGET_SET_FLAGS(tmp, GTK_CAN_DEFAULT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2886 gtk_box_pack_end(GTK_BOX(actionarea), tmp, FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2887 gtk_signal_connect_object(GTK_OBJECT(tmp),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2888 "clicked", GTK_SIGNAL_FUNC(gtk_widget_hide),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2889 GTK_OBJECT(frdp->dialog));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2890 gtk_signal_connect_object(GTK_OBJECT(frdp->dialog),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2891 "delete_event", GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2892 GTK_OBJECT(frdp->dialog));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2893
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2894 tmp = gtk_vseparator_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2895 #ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2896 gtk_box_pack_end(GTK_BOX(hbox), tmp, FALSE, FALSE, 10);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2897 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2898 gtk_box_pack_end(GTK_BOX(hbox), tmp, FALSE, TRUE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2899 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2900
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2901 #ifndef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2902 gtk_widget_grab_focus(frdp->what);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2903
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2904 /* show the frame and realize the frdp->dialog this gives us a window size
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2905 * request that we'll use to position the window within the boundary of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2906 * the mainwin --dbv */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2907 gtk_widget_show_all(frame);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2908 gui_gtk_position_in_parent(GTK_WIDGET(gui.mainwin),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2909 GTK_WIDGET(frdp->dialog), VW_POS_MOUSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2910 gui_gtk_synch_fonts();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2911 gtk_widget_show_all(frdp->dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2912 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2913
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2914 #ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2915 /* Suppress automatic show of the unused action area */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2916 gtk_widget_hide(GTK_DIALOG(frdp->dialog)->action_area);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2917 gtk_widget_show_all(hbox);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2918 gtk_widget_show(frdp->dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2919 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2920
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2921 vim_free(entry_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2922 #ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2923 vim_free(conv_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2924 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2925 #undef CONV
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2926 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2927
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2928 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2929 gui_mch_find_dialog(exarg_T *eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2930 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2931 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2932 find_replace_dialog_create(eap->arg, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2933 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2934
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2935 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2936 gui_mch_replace_dialog(exarg_T *eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2937 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2938 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2939 find_replace_dialog_create(eap->arg, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2940 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2941
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2942
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2943 #if !defined(HAVE_GTK2) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2944 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2945 * Synchronize all gui elements, which are dependant upon the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2946 * main text font used. Those are in esp. the find/replace dialogs.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2947 * If you don't understand why this should be needed, please try to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2948 * search for "pięść" in iso8859-2.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2949 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2950 * (<danielk> I converted the comment above to UTF-8 to put
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2951 * a stopper to the encoding mess. Forgive me :)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2952 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2953 * Obsolete with GTK2.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2954 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2955 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2956 gui_gtk_synch_fonts(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2957 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2958 SharedFindReplace *frdp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2959 int do_replace;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2960
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2961 /* OK this loop is a bit tricky... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2962 for (do_replace = 0; do_replace <= 1; ++do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2963 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2964 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2965 if (frdp->dialog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2966 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2967 GtkStyle *style;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2968
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2969 /* synch the font with whats used by the text itself */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2970 style = gtk_style_copy(gtk_widget_get_style(frdp->what));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2971 gdk_font_unref(style->font);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2972 # ifdef FEAT_XFONTSET
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2973 if (gui.fontset != NOFONTSET)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2974 style->font = gui.fontset;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2975 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2976 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2977 style->font = gui.norm_font;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2978 gdk_font_ref(style->font);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2979 gtk_widget_set_style(frdp->what, style);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2980 gtk_style_unref(style);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2981 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2982 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2983 style = gtk_style_copy(gtk_widget_get_style(frdp->with));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2984 gdk_font_unref(style->font);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2985 # ifdef FEAT_XFONTSET
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2986 if (gui.fontset != NOFONTSET)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2987 style->font = gui.fontset;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2988 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2989 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2990 style->font = gui.norm_font;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2991 gdk_font_ref(style->font);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2992 gtk_widget_set_style(frdp->with, style);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2993 gtk_style_unref(style);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2994 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2995 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2996 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2997 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2998 #endif /* !HAVE_GTK2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2999
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3000
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3001 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3002 * Callback for actions of the find and replace dialogs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3003 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3004 /*ARGSUSED*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3005 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3006 find_replace_cb(GtkWidget *widget, gpointer data)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3007 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3008 int flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3009 char_u *find_text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3010 char_u *repl_text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3011 gboolean direction_down;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3012 SharedFindReplace *sfr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3013 int rc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3014
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3015 flags = (int)(long)data; /* avoid a lint warning here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3016
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3017 /* Get the search/replace strings from the dialog */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3018 if (flags == FRD_FINDNEXT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3019 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3020 repl_text = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3021 sfr = &find_widgets;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3022 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3023 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3024 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3025 repl_text = (char_u *)gtk_entry_get_text(GTK_ENTRY(repl_widgets.with));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3026 sfr = &repl_widgets;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3027 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3028
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3029 find_text = (char_u *)gtk_entry_get_text(GTK_ENTRY(sfr->what));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3030 direction_down = GTK_TOGGLE_BUTTON(sfr->down)->active;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3031
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3032 if (GTK_TOGGLE_BUTTON(sfr->wword)->active)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3033 flags |= FRD_WHOLE_WORD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3034 if (GTK_TOGGLE_BUTTON(sfr->mcase)->active)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3035 flags |= FRD_MATCH_CASE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3036
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3037 #ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3038 repl_text = CONVERT_FROM_UTF8(repl_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3039 find_text = CONVERT_FROM_UTF8(find_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3040 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3041 rc = gui_do_findrepl(flags, find_text, repl_text, direction_down);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3042 #ifdef HAVE_GTK2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3043 CONVERT_FROM_UTF8_FREE(repl_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3044 CONVERT_FROM_UTF8_FREE(find_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3045 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3046
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3047 if (rc && gtk_main_level() > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3048 gtk_main_quit(); /* make sure cmd will be handled immediately */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3049 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3050
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3051 /* our usual callback function */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3052 /*ARGSUSED*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3053 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3054 entry_activate_cb(GtkWidget *widget, gpointer data)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3055 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3056 gtk_widget_grab_focus(GTK_WIDGET(data));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3057 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3058
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3059 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3060 * Syncing the find/replace dialogs on the fly is utterly useless crack,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3061 * and causes nothing but problems. Please tell me a use case for which
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3062 * you'd need both a find dialog and a find/replace one at the same time,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3063 * without being able to actually use them separately since they're syncing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3064 * all the time. I don't think it's worthwhile to fix this nonsense,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3065 * particularly evil incarnation of braindeadness, whatever; I'd much rather
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3066 * see it extinguished from this planet. Thanks for listening. Sorry.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3067 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3068 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3069 entry_changed_cb(GtkWidget * entry, GtkWidget * dialog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3070 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3071 const gchar *entry_text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3072 gboolean nonempty;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3073
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3074 entry_text = gtk_entry_get_text(GTK_ENTRY(entry));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3075
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3076 if (!entry_text)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3077 return; /* shouldn't happen */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3078
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3079 nonempty = (entry_text[0] != '\0');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3080
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3081 if (dialog == find_widgets.dialog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3082 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3083 gtk_widget_set_sensitive(find_widgets.find, nonempty);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3084 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3085
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3086 if (dialog == repl_widgets.dialog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3087 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3088 gtk_widget_set_sensitive(repl_widgets.find, nonempty);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3089 gtk_widget_set_sensitive(repl_widgets.replace, nonempty);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3090 gtk_widget_set_sensitive(repl_widgets.all, nonempty);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3091 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3092 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3093
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3094 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3095 * ":helpfind"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3096 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3097 /*ARGSUSED*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3098 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3099 ex_helpfind(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3100 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3101 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3102 /* This will fail when menus are not loaded. Well, it's only for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3103 * backwards compatibility anyway. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3104 do_cmdline_cmd((char_u *)"emenu ToolBar.FindHelp");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3105 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3106
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3107 #if !defined(HAVE_GTK2) || defined(PROTO) /* Crack crack crack. Brrrr. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3108
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3109 /* gui_gtk_position_in_parent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3110 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3111 * this function causes a child window to be placed within the boundary of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3112 * the parent (mainwin) window.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3113 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3114 * you can specify where the window will be positioned by the third argument
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3115 * (defined in gui.h):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3116 * VW_POS_CENTER at center of parent window
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3117 * VW_POS_MOUSE center of child at mouse position
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3118 * VW_POS_TOP_CENTER top of child at top of parent centered
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3119 * horizontally about the mouse.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3120 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3121 * NOTE: for this function to act as desired the child window must have a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3122 * window size requested. this can be accomplished by packing/placing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3123 * child widgets onto a gtk_frame widget rather than the gtk_window
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3124 * widget...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3125 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3126 * brent -- dbv
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3127 */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 314
diff changeset
3128 static void
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3129 gui_gtk_position_in_parent(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3130 GtkWidget *parent,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3131 GtkWidget *child,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3132 gui_win_pos_T where)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3133 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3134 GtkRequisition c_size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3135 gint xPm, yPm;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3136 gint xP, yP, wP, hP, pos_x, pos_y;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3137
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3138 /* make sure the child widget is set up then get its size. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3139 gtk_widget_size_request(child, &c_size);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3140
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3141 /* get origin and size of parent window */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3142 gdk_window_get_origin((GdkWindow *)(parent->window), &xP, &yP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3143 gdk_window_get_size((GdkWindow *)(parent->window), &wP, &hP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3144
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3145 if (c_size.width > wP || c_size.height > hP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3146 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3147 /* doh! maybe the user should consider giving gVim a little more
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3148 * screen real estate */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3149 gtk_widget_set_uposition(child , xP + 2 , yP + 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3150 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3151 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3152
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3153 if (where == VW_POS_MOUSE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3154 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3155 /* position window at mouse pointer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3156 gtk_widget_get_pointer(parent, &xPm, &yPm);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3157 pos_x = xP + xPm - (c_size.width) / 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3158 pos_y = yP + yPm - (c_size.height) / 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3159 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3160 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3161 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3162 /* set child x origin so it is in center of Vim window */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3163 pos_x = xP + (wP - c_size.width) / 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3164
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3165 if (where == VW_POS_TOP_CENTER)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3166 pos_y = yP + 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3167 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3168 /* where == VW_POS_CENTER */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3169 pos_y = yP + (hP - c_size.height) / 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3170 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3171
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3172 /* now, make sure the window will be inside the Vim window... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3173 if (pos_x < xP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3174 pos_x = xP + 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3175 if (pos_y < yP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3176 pos_y = yP + 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3177 if ((pos_x + c_size.width) > (wP + xP))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3178 pos_x = xP + wP - c_size.width - 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3179 /* Assume 'guiheadroom' indicates the title bar height... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3180 if ((pos_y + c_size.height + p_ghr / 2) > (hP + yP))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3181
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3182 gtk_widget_set_uposition(child, pos_x, pos_y);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3183 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3184
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3185 #endif /* !HAVE_GTK2 */