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