annotate src/gui_gtk.c @ 3472:b36640b2f671 v7.3.500

updated for version 7.3.500 Problem: Ming makefile unconditionally sets WINVER. Solution: Only defined when not already defined. (Yasuhiro Matsumoto)
author Bram Moolenaar <bram@vim.org>
date Fri, 20 Apr 2012 16:13:25 +0200
parents 7653420fdc45
children 982f84487daf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 * Porting to GTK+ was done by:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 *
68
a97c6902ecd9 updated for version 7.0030
vimboss
parents: 41
diff changeset
13 * (C) 1998,1999,2000 by Marcin Dalecki <martin@dalecki.de>
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 * With GREAT support and continuous encouragements by Andy Kahn and of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 * course Bram Moolenaar!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 * Support for GTK+ 2 was added by:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 * (C) 2002,2003 Jason Hildebrand <jason@peaceworks.ca>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 * Daniel Elstner <daniel.elstner@gmx.net>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 * Best supporting actor (He helped somewhat, aesthetically speaking):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 * Maxime Romano <verbophobe@hotmail.com>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 #ifdef FEAT_GUI_GTK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 # include "gui_gtk_f.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 /* GTK defines MAX and MIN, but some system header files as well. Undefine
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 * them and don't use them. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 #ifdef MIN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 # undef MIN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 #ifdef MAX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 # undef MAX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 #ifdef FEAT_GUI_GNOME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 /* Gnome redefines _() and N_(). Grrr... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 # ifdef _
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 # undef _
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 # ifdef N_
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 # undef N_
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 # ifdef textdomain
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 # undef textdomain
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 # ifdef bindtextdomain
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 # undef bindtextdomain
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 # endif
1286
152e52624521 updated for version 7.1-001
vimboss
parents: 1215
diff changeset
56 # ifdef bind_textdomain_codeset
152e52624521 updated for version 7.1-001
vimboss
parents: 1215
diff changeset
57 # undef bind_textdomain_codeset
1215
1d08aac0aea9 updated for version 7.1b
vimboss
parents: 1025
diff changeset
58 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 # if defined(FEAT_GETTEXT) && !defined(ENABLE_NLS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 # define ENABLE_NLS /* so the texts in the dialog boxes are translated */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 # include <gnome.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 #ifdef FEAT_GUI_GTK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 # include <gdk/gdkkeysyms.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 # include <gdk/gdk.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 # ifdef WIN3264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 # include <gdk/gdkwin32.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 # include <gdk/gdkx.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 # include <gtk/gtk.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 /* define these items to be able to generate prototypes without GTK */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 typedef int GtkWidget;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 # define gpointer int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 # define guint8 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 # define GdkPixmap int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 # define GdkBitmap int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 # define GtkIconFactory int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 # define GtkToolbar int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 # define GtkAdjustment int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 # define gboolean int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 # define GdkEventKey int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 # define CancelData int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 static void entry_activate_cb(GtkWidget *widget, gpointer data);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 static void entry_changed_cb(GtkWidget *entry, GtkWidget *dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 static void find_replace_cb(GtkWidget *widget, gpointer data);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
94 #if defined(FEAT_TOOLBAR)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 * Table from BuiltIn## icon indices to GTK+ stock IDs. Order must exactly
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 * match toolbar_names[] in menu.c! All stock icons including the "vim-*"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 * ones can be overridden in your gtkrc file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 static const char * const menu_stock_ids[] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 /* 00 */ GTK_STOCK_NEW,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 /* 01 */ GTK_STOCK_OPEN,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 /* 02 */ GTK_STOCK_SAVE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 /* 03 */ GTK_STOCK_UNDO,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 /* 04 */ GTK_STOCK_REDO,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 /* 05 */ GTK_STOCK_CUT,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 /* 06 */ GTK_STOCK_COPY,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 /* 07 */ GTK_STOCK_PASTE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 /* 08 */ GTK_STOCK_PRINT,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 /* 09 */ GTK_STOCK_HELP,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 /* 10 */ GTK_STOCK_FIND,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 /* 11 */ "vim-save-all",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 /* 12 */ "vim-session-save",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 /* 13 */ "vim-session-new",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 /* 14 */ "vim-session-load",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 /* 15 */ GTK_STOCK_EXECUTE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 /* 16 */ GTK_STOCK_FIND_AND_REPLACE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 /* 17 */ GTK_STOCK_CLOSE, /* FIXME: fuzzy */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 /* 18 */ "vim-window-maximize",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 /* 19 */ "vim-window-minimize",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 /* 20 */ "vim-window-split",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 /* 21 */ "vim-shell",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 /* 22 */ GTK_STOCK_GO_BACK,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 /* 23 */ GTK_STOCK_GO_FORWARD,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 /* 24 */ "vim-find-help",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 /* 25 */ GTK_STOCK_CONVERT,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 /* 26 */ GTK_STOCK_JUMP_TO,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 /* 27 */ "vim-build-tags",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 /* 28 */ "vim-window-split-vertical",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 /* 29 */ "vim-window-maximize-width",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 /* 30 */ "vim-window-minimize-width",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 /* 31 */ GTK_STOCK_QUIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 add_stock_icon(GtkIconFactory *factory,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 const char *stock_id,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 const guint8 *inline_data,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 int data_length)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 GdkPixbuf *pixbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 GtkIconSet *icon_set;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 pixbuf = gdk_pixbuf_new_from_inline(data_length, inline_data, FALSE, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 icon_set = gtk_icon_set_new_from_pixbuf(pixbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 gtk_icon_factory_add(factory, stock_id, icon_set);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 gtk_icon_set_unref(icon_set);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 g_object_unref(pixbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 lookup_menu_iconfile(char_u *iconfile, char_u *dest)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 expand_env(iconfile, dest, MAXPATHL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 if (mch_isFullName(dest))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 return vim_fexists(dest);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 static const char suffixes[][4] = {"png", "xpm", "bmp"};
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 char_u buf[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 unsigned int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 for (i = 0; i < G_N_ELEMENTS(suffixes); ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 if (gui_find_bitmap(dest, buf, (char *)suffixes[i]) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 STRCPY(dest, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 static GtkWidget *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 load_menu_iconfile(char_u *name, GtkIconSize icon_size)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 GtkWidget *image = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 GtkIconSet *icon_set;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 GtkIconSource *icon_source;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 * Rather than loading the icon directly into a GtkImage, create
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 * a new GtkIconSet and put it in there. This way we can easily
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 * scale the toolbar icons on the fly when needed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 icon_set = gtk_icon_set_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 icon_source = gtk_icon_source_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 gtk_icon_source_set_filename(icon_source, (const char *)name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 gtk_icon_set_add_source(icon_set, icon_source);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 image = gtk_image_new_from_icon_set(icon_set, icon_size);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 gtk_icon_source_free(icon_source);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 gtk_icon_set_unref(icon_set);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 return image;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 static GtkWidget *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 create_menu_icon(vimmenu_T *menu, GtkIconSize icon_size)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 GtkWidget *image = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 char_u buf[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 /* First use a specified "icon=" argument. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 if (menu->iconfile != NULL && lookup_menu_iconfile(menu->iconfile, buf))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 image = load_menu_iconfile(buf, icon_size);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 /* If not found and not builtin specified try using the menu name. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 if (image == NULL && !menu->icon_builtin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 && lookup_menu_iconfile(menu->name, buf))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 image = load_menu_iconfile(buf, icon_size);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 /* Still not found? Then use a builtin icon, a blank one as fallback. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 if (image == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 const char *stock_id;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 const int n_ids = G_N_ELEMENTS(menu_stock_ids);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 if (menu->iconidx >= 0 && menu->iconidx < n_ids)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 stock_id = menu_stock_ids[menu->iconidx];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 stock_id = GTK_STOCK_MISSING_IMAGE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 image = gtk_image_new_from_stock(stock_id, icon_size);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 return image;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237
790
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
238 static gint
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
239 toolbar_button_focus_in_event(GtkWidget *widget UNUSED,
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
240 GdkEventFocus *event UNUSED,
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
241 gpointer data UNUSED)
790
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
242 {
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
243 /* When we're in a GtkPlug, we don't have window focus events, only widget
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
244 * focus. To emulate stand-alone gvim, if a button gets focus (e.g.,
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
245 * <Tab> into GtkPlug) immediately pass it to mainwin. */
790
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
246 if (gtk_socket_id != 0)
856
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
247 gtk_widget_grab_focus(gui.drawarea);
790
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
248
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
249 return TRUE;
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
250 }
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
251 #endif /* FEAT_TOOLBAR */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
253 #if defined(FEAT_TOOLBAR) || defined(PROTO)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 gui_gtk_register_stock_icons(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 # include "../pixmaps/stock_icons.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 GtkIconFactory *factory;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 factory = gtk_icon_factory_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 # define ADD_ICON(Name, Data) add_stock_icon(factory, Name, Data, (int)sizeof(Data))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 ADD_ICON("vim-build-tags", stock_vim_build_tags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 ADD_ICON("vim-find-help", stock_vim_find_help);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 ADD_ICON("vim-save-all", stock_vim_save_all);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 ADD_ICON("vim-session-load", stock_vim_session_load);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 ADD_ICON("vim-session-new", stock_vim_session_new);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 ADD_ICON("vim-session-save", stock_vim_session_save);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 ADD_ICON("vim-shell", stock_vim_shell);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 ADD_ICON("vim-window-maximize", stock_vim_window_maximize);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 ADD_ICON("vim-window-maximize-width", stock_vim_window_maximize_width);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 ADD_ICON("vim-window-minimize", stock_vim_window_minimize);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 ADD_ICON("vim-window-minimize-width", stock_vim_window_minimize_width);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 ADD_ICON("vim-window-split", stock_vim_window_split);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 ADD_ICON("vim-window-split-vertical", stock_vim_window_split_vertical);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 # undef ADD_ICON
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 gtk_icon_factory_add_default(factory);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 g_object_unref(factory);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
283 #endif /* FEAT_TOOLBAR */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 #if defined(FEAT_MENU) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 * Translate Vim's mnemonic tagging to GTK+ style and convert to UTF-8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 * if necessary. The caller must vim_free() the returned string.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 * Input Output
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 * _ __
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 * && &
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 * & _ stripped if use_mnemonic == FALSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 * <Tab> end of menu label text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 translate_mnemonic_tag(char_u *name, int use_mnemonic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 char_u *psrc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 char_u *pdest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 int n_underscores = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 name = CONVERT_TO_UTF8(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 if (name == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 for (psrc = name; *psrc != NUL && *psrc != TAB; ++psrc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 if (*psrc == '_')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 ++n_underscores;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 buf = alloc((unsigned)(psrc - name + n_underscores + 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 if (buf != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 pdest = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 for (psrc = name; *psrc != NUL && *psrc != TAB; ++psrc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 if (*psrc == '_')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322 *pdest++ = '_';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 *pdest++ = '_';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 else if (*psrc != '&')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 *pdest++ = *psrc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 else if (*(psrc + 1) == '&')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 *pdest++ = *psrc++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 else if (use_mnemonic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 *pdest++ = '_';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 *pdest = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 CONVERT_TO_UTF8_FREE(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 return buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 menu_item_new(vimmenu_T *menu, GtkWidget *parent_widget)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 GtkWidget *box;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 char_u *text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 int use_mnemonic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 /* It would be neat to have image menu items, but that would require major
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 * changes to Vim's menu system. Not to mention that all the translations
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 * had to be updated. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 menu->id = gtk_menu_item_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 box = gtk_hbox_new(FALSE, 20);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 use_mnemonic = (p_wak[0] != 'n' || !GTK_IS_MENU_BAR(parent_widget));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 text = translate_mnemonic_tag(menu->name, use_mnemonic);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 menu->label = gtk_label_new_with_mnemonic((const char *)text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 vim_free(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 gtk_box_pack_start(GTK_BOX(box), menu->label, FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 if (menu->actext != NULL && menu->actext[0] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 text = CONVERT_TO_UTF8(menu->actext);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 gtk_box_pack_end(GTK_BOX(box),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 gtk_label_new((const char *)text),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 CONVERT_TO_UTF8_FREE(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 gtk_container_add(GTK_CONTAINER(menu->id), box);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 gtk_widget_show_all(menu->id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 gui_mch_add_menu(vimmenu_T *menu, int idx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 vimmenu_T *parent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 GtkWidget *parent_widget;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 if (menu->name[0] == ']' || menu_is_popup(menu->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 menu->submenu_id = gtk_menu_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 parent = menu->parent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 if ((parent != NULL && parent->submenu_id == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 || !menu_is_menubar(menu->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 parent_widget = (parent != NULL) ? parent->submenu_id : gui.menubar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 menu_item_new(menu, parent_widget);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 /* since the tearoff should always appear first, increment idx */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 if (parent != NULL && !menu_is_popup(parent->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 ++idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 gtk_menu_shell_insert(GTK_MENU_SHELL(parent_widget), menu->id, idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 menu->submenu_id = gtk_menu_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 gtk_menu_set_accel_group(GTK_MENU(menu->submenu_id), gui.accel_group);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu->id), menu->submenu_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 menu->tearoff_handle = gtk_tearoff_menu_item_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 if (vim_strchr(p_go, GO_TEAROFF) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 gtk_widget_show(menu->tearoff_handle);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 gtk_menu_prepend(GTK_MENU(menu->submenu_id), menu->tearoff_handle);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 static void
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
420 menu_item_activate(GtkWidget *widget UNUSED, gpointer data)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 gui_menu_cb((vimmenu_T *)data);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 gui_mch_add_menu_item(vimmenu_T *menu, int idx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 vimmenu_T *parent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 parent = menu->parent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 # ifdef FEAT_TOOLBAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 if (menu_is_toolbar(parent->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 GtkToolbar *toolbar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 toolbar = GTK_TOOLBAR(gui.toolbar);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 menu->submenu_id = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 if (menu_is_separator(menu->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 gtk_toolbar_insert_space(toolbar, idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 menu->id = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 char_u *text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 char_u *tooltip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 text = CONVERT_TO_UTF8(menu->dname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 tooltip = CONVERT_TO_UTF8(menu->strings[MENU_INDEX_TIP]);
26
404aac550f35 updated for version 7.0017
vimboss
parents: 7
diff changeset
452 if (tooltip != NULL && !utf_valid_string(tooltip, NULL))
404aac550f35 updated for version 7.0017
vimboss
parents: 7
diff changeset
453 /* Invalid text, can happen when 'encoding' is changed. Avoid
404aac550f35 updated for version 7.0017
vimboss
parents: 7
diff changeset
454 * a nasty GTK error message, skip the tooltip. */
404aac550f35 updated for version 7.0017
vimboss
parents: 7
diff changeset
455 CONVERT_TO_UTF8_FREE(tooltip);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 menu->id = gtk_toolbar_insert_item(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 toolbar,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 (const char *)text,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 (const char *)tooltip,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 create_menu_icon(menu, gtk_toolbar_get_icon_size(toolbar)),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 G_CALLBACK(&menu_item_activate),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 menu,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466
856
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
467 if (gtk_socket_id != 0)
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
468 gtk_signal_connect(GTK_OBJECT(menu->id), "focus_in_event",
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
469 GTK_SIGNAL_FUNC(toolbar_button_focus_in_event), NULL);
790
c8680debe1cc updated for version 7.0230
vimboss
parents: 419
diff changeset
470
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 CONVERT_TO_UTF8_FREE(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 CONVERT_TO_UTF8_FREE(tooltip);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 # endif /* FEAT_TOOLBAR */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 /* No parent, must be a non-menubar menu */
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
479 if (parent == NULL || parent->submenu_id == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 /* Make place for the possible tearoff handle item. Not in the popup
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 * menu, it doesn't have a tearoff item. */
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
484 if (!menu_is_popup(parent->name))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 ++idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 if (menu_is_separator(menu->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 /* Separator: Just add it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 menu->id = gtk_menu_item_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 gtk_widget_set_sensitive(menu->id, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 gtk_widget_show(menu->id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 gtk_menu_insert(GTK_MENU(parent->submenu_id), menu->id, idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 /* Add textual menu item. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 menu_item_new(menu, parent->submenu_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 gtk_widget_show(menu->id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 gtk_menu_insert(GTK_MENU(parent->submenu_id), menu->id, idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 if (menu->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 gtk_signal_connect(GTK_OBJECT(menu->id), "activate",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 GTK_SIGNAL_FUNC(menu_item_activate), menu);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508 #endif /* FEAT_MENU */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 gui_mch_set_text_area_pos(int x, int y, int w, int h)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 gtk_form_move_resize(GTK_FORM(gui.formwin), gui.drawarea, x, y, w, h);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 #if defined(FEAT_MENU) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 /*
1215
1d08aac0aea9 updated for version 7.1b
vimboss
parents: 1025
diff changeset
520 * Enable or disable accelerators for the toplevel menus.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 gui_gtk_set_mnemonics(int enable)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 vimmenu_T *menu;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 for (menu = root_menu; menu != NULL; menu = menu->next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 if (menu->id == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 name = translate_mnemonic_tag(menu->name, enable);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 gtk_label_set_text_with_mnemonic(GTK_LABEL(menu->label),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 (const char *)name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 vim_free(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 recurse_tearoffs(vimmenu_T *menu, int val)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 for (; menu != NULL; menu = menu->next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545 if (menu->submenu_id != NULL && menu->tearoff_handle != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 && menu->name[0] != ']' && !menu_is_popup(menu->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 if (val)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549 gtk_widget_show(menu->tearoff_handle);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 gtk_widget_hide(menu->tearoff_handle);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 recurse_tearoffs(menu->children, val);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 gui_mch_toggle_tearoffs(int enable)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 recurse_tearoffs(root_menu, enable);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 #endif /* FEAT_MENU */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
564 #if defined(FEAT_TOOLBAR)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 get_menu_position(vimmenu_T *menu)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 vimmenu_T *node;
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 867
diff changeset
569 int idx = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 for (node = menu->parent->children; node != menu; node = node->next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 g_return_val_if_fail(node != NULL, -1);
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 867
diff changeset
574 ++idx;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 867
diff changeset
577 return idx;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 }
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
579 #endif /* FEAT_TOOLBAR */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 #if defined(FEAT_TOOLBAR) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 gui_mch_menu_set_tip(vimmenu_T *menu)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 if (menu->id != NULL && menu->parent != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 && gui.toolbar != NULL && menu_is_toolbar(menu->parent->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 char_u *tooltip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 tooltip = CONVERT_TO_UTF8(menu->strings[MENU_INDEX_TIP]);
26
404aac550f35 updated for version 7.0017
vimboss
parents: 7
diff changeset
592 if (tooltip == NULL || utf_valid_string(tooltip, NULL))
404aac550f35 updated for version 7.0017
vimboss
parents: 7
diff changeset
593 /* Only set the tooltip when it's valid utf-8. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 gtk_tooltips_set_tip(GTK_TOOLBAR(gui.toolbar)->tooltips,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 menu->id, (const char *)tooltip, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 CONVERT_TO_UTF8_FREE(tooltip);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 #endif /* FEAT_TOOLBAR */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 #if defined(FEAT_MENU) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 * Destroy the machine specific menu widget.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 gui_mch_destroy_menu(vimmenu_T *menu)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 # ifdef FEAT_TOOLBAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 if (menu->parent != NULL && menu_is_toolbar(menu->parent->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 if (menu_is_separator(menu->name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 gtk_toolbar_remove_space(GTK_TOOLBAR(gui.toolbar),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 get_menu_position(menu));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 else if (menu->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 gtk_widget_destroy(menu->id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 # endif /* FEAT_TOOLBAR */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 if (menu->submenu_id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622 gtk_widget_destroy(menu->submenu_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624 if (menu->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 gtk_widget_destroy(menu->id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 menu->submenu_id = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 menu->id = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631 #endif /* FEAT_MENU */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 * Scrollbar stuff.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638 gui_mch_set_scrollbar_thumb(scrollbar_T *sb, long val, long size, long max)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640 if (sb->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642 GtkAdjustment *adjustment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 adjustment = gtk_range_get_adjustment(GTK_RANGE(sb->id));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 adjustment->lower = 0.0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 adjustment->value = val;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 adjustment->upper = max + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 adjustment->page_size = size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 adjustment->page_increment = size < 3L ? 1L : size - 2L;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 adjustment->step_increment = 1.0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 g_signal_handler_block(GTK_OBJECT(adjustment),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 (gulong)sb->handler_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655 gtk_adjustment_changed(adjustment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 g_signal_handler_unblock(GTK_OBJECT(adjustment),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 (gulong)sb->handler_id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 gui_mch_set_scrollbar_pos(scrollbar_T *sb, int x, int y, int w, int h)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 if (sb->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 gtk_form_move_resize(GTK_FORM(gui.formwin), sb->id, x, y, w, h);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669 * Take action upon scrollbar dragging.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672 adjustment_value_changed(GtkAdjustment *adjustment, gpointer data)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674 scrollbar_T *sb;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 long value;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 int dragging = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678 #ifdef FEAT_XIM
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 /* cancel any preediting */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 if (im_is_preediting())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 xim_reset();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684 sb = gui_find_scrollbar((long)data);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 value = (long)adjustment->value;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 * The dragging argument must be right for the scrollbar to work with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 * closed folds. This isn't documented, hopefully this will keep on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 * working in later GTK versions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 * FIXME: Well, it doesn't work in GTK2. :)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 * HACK: Get the mouse pointer position, if it appears to be on an arrow
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 * button set "dragging" to FALSE. This assumes square buttons!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695 if (sb != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 dragging = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 if (sb->wp != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701 int x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 int y;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703 GdkModifierType state;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704 int width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705 int height;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707 /* vertical scrollbar: need to set "dragging" properly in case
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 * there are closed folds. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 gdk_window_get_pointer(sb->id->window, &x, &y, &state);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 gdk_window_get_size(sb->id->window, &width, &height);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711 if (x >= 0 && x < width && y >= 0 && y < height)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713 if (y < width)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 /* up arrow: move one (closed fold) line up */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716 dragging = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 value = sb->wp->w_topline - 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 else if (y > height - width)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 /* down arrow: move one (closed fold) line down */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 dragging = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723 value = sb->wp->w_topline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729 gui_drag_scrollbar(sb, value, dragging);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732 /* SBAR_VERT or SBAR_HORIZ */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 gui_mch_create_scrollbar(scrollbar_T *sb, int orient)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 if (orient == SBAR_HORIZ)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 sb->id = gtk_hscrollbar_new(NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 else if (orient == SBAR_VERT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 sb->id = gtk_vscrollbar_new(NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 if (sb->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 GtkAdjustment *adjustment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745 GTK_WIDGET_UNSET_FLAGS(sb->id, GTK_CAN_FOCUS);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 gtk_form_put(GTK_FORM(gui.formwin), sb->id, 0, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
747
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
748 adjustment = gtk_range_get_adjustment(GTK_RANGE(sb->id));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
749
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 sb->handler_id = gtk_signal_connect(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
751 GTK_OBJECT(adjustment), "value_changed",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752 GTK_SIGNAL_FUNC(adjustment_value_changed),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753 GINT_TO_POINTER(sb->ident));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754 gui_mch_update();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 #if defined(FEAT_WINDOWS) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760 gui_mch_destroy_scrollbar(scrollbar_T *sb)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
762 if (sb->id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
764 gtk_widget_destroy(sb->id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765 sb->id = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
766 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 gui_mch_update();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771 #if defined(FEAT_BROWSE) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 * Implementation of the file selector related stuff
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774 */
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
775 #if GTK_CHECK_VERSION(2,4,0)
2301
6f63294a1781 Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents: 2275
diff changeset
776 # define USE_FILE_CHOOSER
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
777 #endif
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
778
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
779 #ifndef USE_FILE_CHOOSER
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 static void
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
781 browse_ok_cb(GtkWidget *widget UNUSED, gpointer cbdata)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 gui_T *vw = (gui_T *)cbdata;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785 if (vw->browse_fname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786 g_free(vw->browse_fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
788 vw->browse_fname = (char_u *)g_strdup(gtk_file_selection_get_filename(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789 GTK_FILE_SELECTION(vw->filedlg)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 gtk_widget_hide(vw->filedlg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 static void
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
794 browse_cancel_cb(GtkWidget *widget UNUSED, gpointer cbdata)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 gui_T *vw = (gui_T *)cbdata;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
798 if (vw->browse_fname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 g_free(vw->browse_fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
801 vw->browse_fname = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 gtk_widget_hide(vw->filedlg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 static gboolean
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
807 browse_destroy_cb(GtkWidget *widget UNUSED)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809 if (gui.browse_fname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
811 g_free(gui.browse_fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
812 gui.browse_fname = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
813 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
814 gui.filedlg = NULL;
2301
6f63294a1781 Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents: 2275
diff changeset
815 gtk_main_quit();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
816 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
817 }
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
818 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
819
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
820 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
821 * Put up a file requester.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
822 * Returns the selected name in allocated memory, or NULL for Cancel.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
823 * saving, select file to write
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
824 * title title for the window
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
825 * dflt default name
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
826 * ext not used (extension added)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
827 * initdir initial directory, NULL for current dir
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
828 * filter not used (file name filter)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
829 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
830 char_u *
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
831 gui_mch_browse(int saving UNUSED,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
832 char_u *title,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
833 char_u *dflt,
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
834 char_u *ext UNUSED,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
835 char_u *initdir,
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
836 char_u *filter UNUSED)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
837 {
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
838 #ifdef USE_FILE_CHOOSER
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
839 GtkWidget *fc;
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
840 #endif
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
841 char_u dirbuf[MAXPATHL];
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
842
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
843 title = CONVERT_TO_UTF8(title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
844
1003
a1c1f001b99d updated for version 7.0-129
vimboss
parents: 944
diff changeset
845 /* GTK has a bug, it only works with an absolute path. */
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
846 if (initdir == NULL || *initdir == NUL)
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
847 mch_dirname(dirbuf, MAXPATHL);
1003
a1c1f001b99d updated for version 7.0-129
vimboss
parents: 944
diff changeset
848 else if (vim_FullName(initdir, dirbuf, MAXPATHL - 2, FALSE) == FAIL)
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
849 dirbuf[0] = NUL;
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
850 /* Always need a trailing slash for a directory. */
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
851 add_pathsep(dirbuf);
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
852
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
853 /* If our pointer is currently hidden, then we should show it. */
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
854 gui_mch_mousehide(FALSE);
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
855
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
856 #ifdef USE_FILE_CHOOSER
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
857 /* We create the dialog each time, so that the button text can be "Open"
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
858 * or "Save" according to the action. */
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
859 fc = gtk_file_chooser_dialog_new((const gchar *)title,
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
860 GTK_WINDOW(gui.mainwin),
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
861 saving ? GTK_FILE_CHOOSER_ACTION_SAVE
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
862 : GTK_FILE_CHOOSER_ACTION_OPEN,
1025
b6627f01c67d updated for version 7.0-151
vimboss
parents: 1003
diff changeset
863 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
864 saving ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
865 NULL);
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
866 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fc),
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
867 (const gchar *)dirbuf);
2301
6f63294a1781 Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents: 2275
diff changeset
868 if (saving && dflt != NULL && *dflt != NUL)
6f63294a1781 Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents: 2275
diff changeset
869 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(fc), (char *)dflt);
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
870
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
871 gui.browse_fname = NULL;
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
872 if (gtk_dialog_run(GTK_DIALOG(fc)) == GTK_RESPONSE_ACCEPT)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873 {
856
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
874 char *filename;
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
875
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
876 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fc));
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
877 gui.browse_fname = (char_u *)g_strdup(filename);
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
878 g_free(filename);
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
879 }
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
880 gtk_widget_destroy(GTK_WIDGET(fc));
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
881
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
882 #else
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
883
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
884 if (gui.filedlg == NULL)
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
885 {
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
886 GtkFileSelection *fs; /* shortcut */
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
887
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
888 gui.filedlg = gtk_file_selection_new((const gchar *)title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
889 gtk_window_set_modal(GTK_WINDOW(gui.filedlg), TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
890 gtk_window_set_transient_for(GTK_WINDOW(gui.filedlg),
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
891 GTK_WINDOW(gui.mainwin));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
892 fs = GTK_FILE_SELECTION(gui.filedlg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
894 gtk_container_border_width(GTK_CONTAINER(fs), 4);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
895
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
896 gtk_signal_connect(GTK_OBJECT(fs->ok_button),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897 "clicked", GTK_SIGNAL_FUNC(browse_ok_cb), &gui);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
898 gtk_signal_connect(GTK_OBJECT(fs->cancel_button),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
899 "clicked", GTK_SIGNAL_FUNC(browse_cancel_cb), &gui);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
900 /* gtk_signal_connect() doesn't work for destroy, it causes a hang */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
901 gtk_signal_connect_object(GTK_OBJECT(gui.filedlg),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902 "destroy", GTK_SIGNAL_FUNC(browse_destroy_cb),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
903 GTK_OBJECT(gui.filedlg));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
904 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
905 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
906 gtk_window_set_title(GTK_WINDOW(gui.filedlg), (const gchar *)title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
907
1003
a1c1f001b99d updated for version 7.0-129
vimboss
parents: 944
diff changeset
908 /* Concatenate "initdir" and "dflt". */
a1c1f001b99d updated for version 7.0-129
vimboss
parents: 944
diff changeset
909 if (dflt != NULL && *dflt != NUL
a1c1f001b99d updated for version 7.0-129
vimboss
parents: 944
diff changeset
910 && STRLEN(dirbuf) + 2 + STRLEN(dflt) < MAXPATHL)
a1c1f001b99d updated for version 7.0-129
vimboss
parents: 944
diff changeset
911 STRCAT(dirbuf, dflt);
a1c1f001b99d updated for version 7.0-129
vimboss
parents: 944
diff changeset
912
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
913 gtk_file_selection_set_filename(GTK_FILE_SELECTION(gui.filedlg),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
914 (const gchar *)dirbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
915
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
916 gtk_widget_show(gui.filedlg);
2301
6f63294a1781 Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents: 2275
diff changeset
917 gtk_main();
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
918 #endif
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
919
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
920 CONVERT_TO_UTF8_FREE(title);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
921 if (gui.browse_fname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
922 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
923
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
924 /* shorten the file name if possible */
1411
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1355
diff changeset
925 return vim_strsave(shorten_fname1(gui.browse_fname));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
926 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
927
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
928 /*
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
929 * Put up a directory selector
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
930 * Returns the selected name in allocated memory, or NULL for Cancel.
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
931 * title title for the window
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
932 * dflt default name
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
933 * initdir initial directory, NULL for current dir
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
934 */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
935 char_u *
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
936 gui_mch_browsedir(
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
937 char_u *title,
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
938 char_u *initdir)
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
939 {
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
940 # if defined(GTK_FILE_CHOOSER) /* Only in GTK 2.4 and later. */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
941 char_u dirbuf[MAXPATHL];
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
942 char_u *p;
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
943 GtkWidget *dirdlg; /* file selection dialog */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
944 char_u *dirname = NULL;
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
945
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
946 title = CONVERT_TO_UTF8(title);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
947
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
948 dirdlg = gtk_file_chooser_dialog_new(
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
949 (const gchar *)title,
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
950 GTK_WINDOW(gui.mainwin),
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
951 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
952 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
953 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
954 NULL);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
955
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
956 CONVERT_TO_UTF8_FREE(title);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
957
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
958 /* if our pointer is currently hidden, then we should show it. */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
959 gui_mch_mousehide(FALSE);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
960
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
961 /* GTK appears to insist on an absolute path. */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
962 if (initdir == NULL || *initdir == NUL
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
963 || vim_FullName(initdir, dirbuf, MAXPATHL - 10, FALSE) == FAIL)
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
964 mch_dirname(dirbuf, MAXPATHL - 10);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
965
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
966 /* Always need a trailing slash for a directory.
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
967 * Also add a dummy file name, so that we get to the directory. */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
968 add_pathsep(dirbuf);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
969 STRCAT(dirbuf, "@zd(*&1|");
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
970 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dirdlg),
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
971 (const gchar *)dirbuf);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
972
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
973 /* Run the dialog. */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
974 if (gtk_dialog_run(GTK_DIALOG(dirdlg)) == GTK_RESPONSE_ACCEPT)
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
975 dirname = (char_u *)gtk_file_chooser_get_filename(
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
976 GTK_FILE_CHOOSER(dirdlg));
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
977 gtk_widget_destroy(dirdlg);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
978 if (dirname == NULL)
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
979 return NULL;
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
980
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
981 /* shorten the file name if possible */
1411
0e6b369b9760 updated for version 7.1-126
vimboss
parents: 1355
diff changeset
982 p = vim_strsave(shorten_fname1(dirname));
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
983 g_free(dirname);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
984 return p;
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
985
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
986 # else
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
987 /* For GTK 2.2 and earlier: fall back to ordinary file selector. */
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
988 return gui_mch_browse(0, title, NULL, NULL, initdir, NULL);
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
989 # endif
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
990 }
ac33b7c03fac updated for version 7.0018
vimboss
parents: 26
diff changeset
991
270
a20218704019 updated for version 7.0072
vimboss
parents: 133
diff changeset
992
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
993 #endif /* FEAT_BROWSE */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
994
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
995 #if defined(FEAT_GUI_DIALOG) || defined(PROTO)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
996
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
997 static GtkWidget *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
998 create_message_dialog(int type, char_u *title, char_u *message)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
999 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1000 GtkWidget *dialog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1001 GtkMessageType message_type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1002
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1003 switch (type)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005 case VIM_ERROR: message_type = GTK_MESSAGE_ERROR; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1006 case VIM_WARNING: message_type = GTK_MESSAGE_WARNING; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1007 case VIM_QUESTION: message_type = GTK_MESSAGE_QUESTION; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1008 default: message_type = GTK_MESSAGE_INFO; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1009 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1010
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1011 message = CONVERT_TO_UTF8(message);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1012 dialog = gtk_message_dialog_new(GTK_WINDOW(gui.mainwin),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1013 GTK_DIALOG_DESTROY_WITH_PARENT,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1014 message_type,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1015 GTK_BUTTONS_NONE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1016 "%s", (const char *)message);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1017 CONVERT_TO_UTF8_FREE(message);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1018
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1019 if (title != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1020 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1021 title = CONVERT_TO_UTF8(title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1022 gtk_window_set_title(GTK_WINDOW(dialog), (const char *)title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1023 CONVERT_TO_UTF8_FREE(title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1024 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1025 else if (type == VIM_GENERIC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1026 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1027 gtk_window_set_title(GTK_WINDOW(dialog), "VIM");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1028 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1029
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1030 return dialog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1031 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1032
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1033 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1034 * Split up button_string into individual button labels by inserting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1035 * NUL bytes. Also replace the Vim-style mnemonic accelerator prefix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1036 * '&' with '_'. button_string must point to allocated memory!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1037 * Return an allocated array of pointers into button_string.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1038 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1039 static char **
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1040 split_button_string(char_u *button_string, int *n_buttons)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1041 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1042 char **array;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1043 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1044 unsigned int count = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1045
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1046 for (p = button_string; *p != NUL; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1047 if (*p == DLG_BUTTON_SEP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1048 ++count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1049
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1050 array = (char **)alloc((count + 1) * sizeof(char *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1051 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1052
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1053 if (array != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1054 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1055 array[count++] = (char *)button_string;
40
f1d2a58883b9 updated for version 7.0024
vimboss
parents: 39
diff changeset
1056 for (p = button_string; *p != NUL; )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1057 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1058 if (*p == DLG_BUTTON_SEP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1059 {
40
f1d2a58883b9 updated for version 7.0024
vimboss
parents: 39
diff changeset
1060 *p++ = NUL;
f1d2a58883b9 updated for version 7.0024
vimboss
parents: 39
diff changeset
1061 array[count++] = (char *)p;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1062 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1063 else if (*p == DLG_HOTKEY_CHAR)
40
f1d2a58883b9 updated for version 7.0024
vimboss
parents: 39
diff changeset
1064 *p++ = '_';
f1d2a58883b9 updated for version 7.0024
vimboss
parents: 39
diff changeset
1065 else
f1d2a58883b9 updated for version 7.0024
vimboss
parents: 39
diff changeset
1066 mb_ptr_adv(p);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1067 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1068 array[count] = NULL; /* currently not relied upon, but doesn't hurt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1069 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1070
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1071 *n_buttons = count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1072 return array;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1073 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1074
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1075 static char **
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1076 split_button_translation(const char *message)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1077 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1078 char **buttons = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1079 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1080 int n_buttons = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1081 int n_expected = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1082
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1083 for (str = (char_u *)message; *str != NUL; ++str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1084 if (*str == DLG_BUTTON_SEP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1085 ++n_expected;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1086
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1087 str = (char_u *)_(message);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1088 if (str != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1089 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1090 if (output_conv.vc_type != CONV_NONE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1091 str = string_convert(&output_conv, str, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1092 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1093 str = vim_strsave(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1094
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1095 if (str != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1096 buttons = split_button_string(str, &n_buttons);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1097 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1098 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1099 * Uh-oh... this should never ever happen. But we don't wanna crash
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1100 * if the translation is broken, thus fall back to the untranslated
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1101 * buttons string in case of emergency.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1102 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1103 if (buttons == NULL || n_buttons != n_expected)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1104 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1105 vim_free(buttons);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1106 vim_free(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1107 buttons = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1108 str = vim_strsave((char_u *)message);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1109
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1110 if (str != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1111 buttons = split_button_string(str, &n_buttons);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1112 if (buttons == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1113 vim_free(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1114 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1115
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1116 return buttons;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1117 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1118
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1119 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1120 button_equal(const char *a, const char *b)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1121 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1122 while (*a != '\0' && *b != '\0')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1123 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1124 if (*a == '_' && *++a == '\0')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1125 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1126 if (*b == '_' && *++b == '\0')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1127 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1128
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1129 if (g_unichar_tolower(g_utf8_get_char(a))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1130 != g_unichar_tolower(g_utf8_get_char(b)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1131 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1132
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1133 a = g_utf8_next_char(a);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1134 b = g_utf8_next_char(b);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1135 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1136
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1137 return (*a == '\0' && *b == '\0');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1138 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1139
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1140 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1141 dialog_add_buttons(GtkDialog *dialog, char_u *button_string)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1142 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1143 char **ok;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1144 char **ync; /* "yes no cancel" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1145 char **buttons;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1146 int n_buttons = 0;
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 867
diff changeset
1147 int idx;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1148
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1149 button_string = vim_strsave(button_string); /* must be writable */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1150 if (button_string == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1151 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1152
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1153 /* Check 'v' flag in 'guioptions': vertical button placement. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1154 if (vim_strchr(p_go, GO_VERTICAL) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1155 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1156 GtkWidget *vbutton_box;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1158 vbutton_box = gtk_vbutton_box_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1159 gtk_widget_show(vbutton_box);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1160 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(dialog)->vbox),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1161 vbutton_box, TRUE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1162 /* Overrule the "action_area" value, hopefully this works... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1163 GTK_DIALOG(dialog)->action_area = vbutton_box;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1166 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1167 * Yes this is ugly, I don't particularly like it either. But doing it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1168 * this way has the compelling advantage that translations need not to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1169 * be touched at all. See below what 'ok' and 'ync' are used for.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1170 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1171 ok = split_button_translation(N_("&Ok"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1172 ync = split_button_translation(N_("&Yes\n&No\n&Cancel"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1173 buttons = split_button_string(button_string, &n_buttons);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1174
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1175 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1176 * Yes, the buttons are in reversed order to match the GNOME 2 desktop
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1177 * environment. Don't hit me -- it's all about consistency.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178 * Well, apparently somebody changed his mind: with GTK 2.2.4 it works the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1179 * other way around...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 */
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 867
diff changeset
1181 for (idx = 1; idx <= n_buttons; ++idx)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1183 char *label;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 char_u *label8;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 867
diff changeset
1186 label = buttons[idx - 1];
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1188 * Perform some guesswork to find appropriate stock items for the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1189 * buttons. We have to compare with a sample of the translated
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1190 * button string to get things right. Yes, this is hackish :/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1192 * But even the common button labels aren't necessarily translated,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193 * since anyone can create their own dialogs using Vim functions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1194 * Thus we have to check for those too.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1196 if (ok != NULL && ync != NULL) /* almost impossible to fail */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1198 if (button_equal(label, ok[0])) label = GTK_STOCK_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1199 else if (button_equal(label, ync[0])) label = GTK_STOCK_YES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200 else if (button_equal(label, ync[1])) label = GTK_STOCK_NO;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201 else if (button_equal(label, ync[2])) label = GTK_STOCK_CANCEL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202 else if (button_equal(label, "Ok")) label = GTK_STOCK_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1203 else if (button_equal(label, "Yes")) label = GTK_STOCK_YES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1204 else if (button_equal(label, "No")) label = GTK_STOCK_NO;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205 else if (button_equal(label, "Cancel")) label = GTK_STOCK_CANCEL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1207 label8 = CONVERT_TO_UTF8((char_u *)label);
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 867
diff changeset
1208 gtk_dialog_add_button(dialog, (const gchar *)label8, idx);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209 CONVERT_TO_UTF8_FREE(label8);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212 if (ok != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1213 vim_free(*ok);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214 if (ync != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215 vim_free(*ync);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216 vim_free(ok);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217 vim_free(ync);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 vim_free(buttons);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 vim_free(button_string);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223 * Allow mnemonic accelerators to be activated without pressing <Alt>.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 * I'm not sure if it's a wise idea to do this. However, the old GTK+ 1.2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 * GUI used to work this way, and I consider the impact on UI consistency
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226 * low enough to justify implementing this as a special Vim feature.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1227 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1228 typedef struct _DialogInfo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1229 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1230 int ignore_enter; /* no default button, ignore "Enter" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1231 int noalt; /* accept accelerators without Alt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1232 GtkDialog *dialog; /* Widget of the dialog */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1233 } DialogInfo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1234
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1235 static gboolean
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1236 dialog_key_press_event_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 DialogInfo *di = (DialogInfo *)data;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239
1355
888c0645d64f updated for version 7.1-069
vimboss
parents: 1286
diff changeset
1240 /* Ignore hitting Enter (or Space) when there is no default button. */
888c0645d64f updated for version 7.1-069
vimboss
parents: 1286
diff changeset
1241 if (di->ignore_enter && (event->keyval == GDK_Return
888c0645d64f updated for version 7.1-069
vimboss
parents: 1286
diff changeset
1242 || event->keyval == ' '))
888c0645d64f updated for version 7.1-069
vimboss
parents: 1286
diff changeset
1243 return TRUE;
888c0645d64f updated for version 7.1-069
vimboss
parents: 1286
diff changeset
1244 else /* A different key was pressed, return to normal behavior */
888c0645d64f updated for version 7.1-069
vimboss
parents: 1286
diff changeset
1245 di->ignore_enter = FALSE;
888c0645d64f updated for version 7.1-069
vimboss
parents: 1286
diff changeset
1246
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1247 /* Close the dialog when hitting "Esc". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1248 if (event->keyval == GDK_Escape)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1249 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1250 gtk_dialog_response(di->dialog, GTK_RESPONSE_REJECT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1251 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1252 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1253
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254 if (di->noalt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1255 && (event->state & gtk_accelerator_get_default_mod_mask()) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1256 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1257 return gtk_window_mnemonic_activate(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1258 GTK_WINDOW(widget), event->keyval,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1259 gtk_window_get_mnemonic_modifier(GTK_WINDOW(widget)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1260 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1261
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1262 return FALSE; /* continue emission */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1263 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1265 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1266 gui_mch_dialog(int type, /* type of dialog */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1267 char_u *title, /* title of dialog */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1268 char_u *message, /* message text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1269 char_u *buttons, /* names of buttons */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1270 int def_but, /* default button */
2684
951641b8784d updated for version 7.3.102
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1271 char_u *textfield, /* text for textfield or NULL */
951641b8784d updated for version 7.3.102
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1272 int ex_cmd UNUSED)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1274 GtkWidget *dialog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1275 GtkWidget *entry = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1276 char_u *text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1277 int response;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1278 DialogInfo dialoginfo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1279
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1280 dialog = create_message_dialog(type, title, message);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1281 dialoginfo.dialog = GTK_DIALOG(dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1282 dialog_add_buttons(GTK_DIALOG(dialog), buttons);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1283
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1284 if (textfield != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1285 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1286 GtkWidget *alignment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1287
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1288 entry = gtk_entry_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1289 gtk_widget_show(entry);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1290
2649
b2789846ed39 updated for version 7.3.069
Bram Moolenaar <bram@vim.org>
parents: 2301
diff changeset
1291 /* Make Enter work like pressing OK. */
b2789846ed39 updated for version 7.3.069
Bram Moolenaar <bram@vim.org>
parents: 2301
diff changeset
1292 gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
b2789846ed39 updated for version 7.3.069
Bram Moolenaar <bram@vim.org>
parents: 2301
diff changeset
1293
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1294 text = CONVERT_TO_UTF8(textfield);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1295 gtk_entry_set_text(GTK_ENTRY(entry), (const char *)text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1296 CONVERT_TO_UTF8_FREE(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1297
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1298 alignment = gtk_alignment_new((float)0.5, (float)0.5,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1299 (float)1.0, (float)1.0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1300 gtk_container_add(GTK_CONTAINER(alignment), entry);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1301 gtk_container_set_border_width(GTK_CONTAINER(alignment), 5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1302 gtk_widget_show(alignment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1303
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1304 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1305 alignment, TRUE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1306 dialoginfo.noalt = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1307 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1308 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1309 dialoginfo.noalt = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1310
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1311 /* Allow activation of mnemonic accelerators without pressing <Alt> when
864
bc620d6bdf06 updated for version 7.0g03
vimboss
parents: 856
diff changeset
1312 * there is no textfield. Handle pressing Esc. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1313 g_signal_connect(G_OBJECT(dialog), "key_press_event",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1314 G_CALLBACK(&dialog_key_press_event_cb), &dialoginfo);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1315
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1316 if (def_but > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1317 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1318 gtk_dialog_set_default_response(GTK_DIALOG(dialog), def_but);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1319 dialoginfo.ignore_enter = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1320 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1321 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1322 /* No default button, ignore pressing Enter. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1323 dialoginfo.ignore_enter = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1324
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1325 /* Show the mouse pointer if it's currently hidden. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1326 gui_mch_mousehide(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1327
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1328 response = gtk_dialog_run(GTK_DIALOG(dialog));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1329
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1330 /* GTK_RESPONSE_NONE means the dialog was programmatically destroyed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1331 if (response != GTK_RESPONSE_NONE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1332 {
314
529f887b5cb7 updated for version 7.0082
vimboss
parents: 270
diff changeset
1333 if (response == GTK_RESPONSE_ACCEPT) /* Enter pressed */
529f887b5cb7 updated for version 7.0082
vimboss
parents: 270
diff changeset
1334 response = def_but;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1335 if (textfield != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1336 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1337 text = (char_u *)gtk_entry_get_text(GTK_ENTRY(entry));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1338 text = CONVERT_FROM_UTF8(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1339
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 401
diff changeset
1340 vim_strncpy(textfield, text, IOSIZE - 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1341
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1342 CONVERT_FROM_UTF8_FREE(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1343 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1344 gtk_widget_destroy(dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1345 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1346
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1347 return response > 0 ? response : 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1348 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1349
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
1350 #endif /* FEAT_GUI_DIALOG */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1351
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1352
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1353 #if defined(FEAT_MENU) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1354
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1355 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1356 gui_mch_show_popupmenu(vimmenu_T *menu)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1357 {
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
1358 # if defined(FEAT_XIM)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1359 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1360 * Append a submenu for selecting an input method. This is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1361 * currently the only way to switch input methods at runtime.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1362 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1363 if (xic != NULL && g_object_get_data(G_OBJECT(menu->submenu_id),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1364 "vim-has-im-menu") == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1365 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1366 GtkWidget *menuitem;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1367 GtkWidget *submenu;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1368 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1369
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1370 menuitem = gtk_separator_menu_item_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1371 gtk_widget_show(menuitem);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1372 gtk_menu_shell_append(GTK_MENU_SHELL(menu->submenu_id), menuitem);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1373
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1374 name = (char_u *)_("Input _Methods");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1375 name = CONVERT_TO_UTF8(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1376 menuitem = gtk_menu_item_new_with_mnemonic((const char *)name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1377 CONVERT_TO_UTF8_FREE(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1378 gtk_widget_show(menuitem);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1379
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1380 submenu = gtk_menu_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1381 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1382 gtk_menu_shell_append(GTK_MENU_SHELL(menu->submenu_id), menuitem);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1383
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1384 gtk_im_multicontext_append_menuitems(GTK_IM_MULTICONTEXT(xic),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1385 GTK_MENU_SHELL(submenu));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1386 g_object_set_data(G_OBJECT(menu->submenu_id),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1387 "vim-has-im-menu", GINT_TO_POINTER(TRUE));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1388 }
2275
e4d849f4df03 Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents: 2103
diff changeset
1389 # endif /* FEAT_XIM */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1390
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1391 gtk_menu_popup(GTK_MENU(menu->submenu_id),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1392 NULL, NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1393 (GtkMenuPositionFunc)NULL, NULL,
2923
7653420fdc45 updated for version 7.3.234
Bram Moolenaar <bram@vim.org>
parents: 2684
diff changeset
1394 3U, gui.event_time);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1395 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1396
401
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1397 /* Ugly global variable to pass "mouse_pos" flag from gui_make_popup() to
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1398 * popup_menu_position_func(). */
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1399 static int popup_mouse_pos;
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1400
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1401 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1402 * Menu position callback; used by gui_make_popup() to place the menu
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1403 * at the current text cursor position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1404 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1405 * Note: The push_in output argument seems to affect scrolling of huge
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1406 * menus that don't fit on the screen. Leave it at the default for now.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1407 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1408 static void
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
1409 popup_menu_position_func(GtkMenu *menu UNUSED,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1410 gint *x, gint *y,
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
1411 gboolean *push_in UNUSED,
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
1412 gpointer user_data UNUSED)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1413 {
401
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1414 gdk_window_get_origin(gui.drawarea->window, x, y);
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1415
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1416 if (popup_mouse_pos)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1417 {
401
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1418 int mx, my;
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1419
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1420 gui_mch_getmouse(&mx, &my);
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1421 *x += mx;
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1422 *y += my;
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1423 }
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1424 else if (curwin != NULL && gui.drawarea != NULL && gui.drawarea->window != NULL)
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1425 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1426 /* Find the cursor position in the current window */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1427 *x += FILL_X(W_WINCOL(curwin) + curwin->w_wcol + 1) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1428 *y += FILL_Y(W_WINROW(curwin) + curwin->w_wrow + 1) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1429 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1430 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1431
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1432 void
401
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1433 gui_make_popup(char_u *path_name, int mouse_pos)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1434 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1435 vimmenu_T *menu;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1436
401
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1437 popup_mouse_pos = mouse_pos;
4a1ead01d30b updated for version 7.0105
vimboss
parents: 344
diff changeset
1438
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1439 menu = gui_find_menu(path_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1440
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1441 if (menu != NULL && menu->submenu_id != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1442 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1443 gtk_menu_popup(GTK_MENU(menu->submenu_id),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1444 NULL, NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1445 &popup_menu_position_func, NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1446 0U, (guint32)GDK_CURRENT_TIME);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1447 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1448 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1449
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1450 #endif /* FEAT_MENU */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1451
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1452
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1453 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1454 * We don't create it twice.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1455 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1456
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1457 typedef struct _SharedFindReplace
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1458 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1459 GtkWidget *dialog; /* the main dialog widget */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1460 GtkWidget *wword; /* 'Whole word only' check button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1461 GtkWidget *mcase; /* 'Match case' check button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1462 GtkWidget *up; /* search direction 'Up' radio button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1463 GtkWidget *down; /* search direction 'Down' radio button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1464 GtkWidget *what; /* 'Find what' entry text widget */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1465 GtkWidget *with; /* 'Replace with' entry text widget */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1466 GtkWidget *find; /* 'Find Next' action button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1467 GtkWidget *replace; /* 'Replace With' action button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1468 GtkWidget *all; /* 'Replace All' action button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1469 } SharedFindReplace;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1470
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
1471 static SharedFindReplace find_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
1472 static SharedFindReplace repl_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
1473
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1474 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1475 find_key_press_event(
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
1476 GtkWidget *widget UNUSED,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1477 GdkEventKey *event,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1478 SharedFindReplace *frdp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1479 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1480 /* If the user is holding one of the key modifiers we will just bail out,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1481 * thus preserving the possibility of normal focus traversal.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1482 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1483 if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1484 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1485
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1486 /* the Escape key synthesizes a cancellation action */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1487 if (event->keyval == GDK_Escape)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1488 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1489 gtk_widget_hide(frdp->dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1490
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1491 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1492 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1493
1215
1d08aac0aea9 updated for version 7.1b
vimboss
parents: 1025
diff changeset
1494 /* It would be delightful if it where possible to do search history
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1495 * operations on the K_UP and K_DOWN keys here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1496 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1497
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1498 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1499 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1500
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1501 static GtkWidget *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1502 create_image_button(const char *stock_id, const char *label)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1503 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1504 char_u *text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1505 GtkWidget *box;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1506 GtkWidget *alignment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1507 GtkWidget *button;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1508
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1509 text = CONVERT_TO_UTF8((char_u *)label);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1510
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1511 box = gtk_hbox_new(FALSE, 3);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1512 gtk_box_pack_start(GTK_BOX(box),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1513 gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_BUTTON),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1514 FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1515 gtk_box_pack_start(GTK_BOX(box),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1516 gtk_label_new((const char *)text),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1517 FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1518
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1519 CONVERT_TO_UTF8_FREE(text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1520
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1521 alignment = gtk_alignment_new((float)0.5, (float)0.5,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1522 (float)0.0, (float)0.0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1523 gtk_container_add(GTK_CONTAINER(alignment), box);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1524 gtk_widget_show_all(alignment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1525
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1526 button = gtk_button_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1527 gtk_container_add(GTK_CONTAINER(button), alignment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1528
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1529 return button;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1530 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1531
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1532 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1533 * This is currently only used by find_replace_dialog_create(), and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1534 * I'd really like to keep it at that. In other words: don't spread
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1535 * this nasty hack all over the code. Think twice.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1536 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1537 static const char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1538 convert_localized_message(char_u **buffer, const char *message)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1539 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1540 if (output_conv.vc_type == CONV_NONE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1541 return message;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1542
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1543 vim_free(*buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1544 *buffer = string_convert(&output_conv, (char_u *)message, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1545
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1546 return (const char *)*buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1547 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1548
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1549 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1550 find_replace_dialog_create(char_u *arg, int do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1551 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1552 GtkWidget *hbox; /* main top down box */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1553 GtkWidget *actionarea;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1554 GtkWidget *table;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1555 GtkWidget *tmp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1556 GtkWidget *vbox;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1557 gboolean sensitive;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1558 SharedFindReplace *frdp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1559 char_u *entry_text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1560 int wword = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1561 int mcase = !p_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1562 char_u *conv_buffer = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1563 # define CONV(message) convert_localized_message(&conv_buffer, (message))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1564
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1565 frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1566
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1567 /* Get the search string to use. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1568 entry_text = get_find_dialog_text(arg, &wword, &mcase);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1569
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1570 if (entry_text != NULL && output_conv.vc_type != CONV_NONE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1571 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1572 char_u *old_text = entry_text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1573 entry_text = string_convert(&output_conv, entry_text, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1574 vim_free(old_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1575 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1576
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1577 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1578 * If the dialog already exists, just raise it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1579 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1580 if (frdp->dialog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1581 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1582 if (entry_text != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1583 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1584 gtk_entry_set_text(GTK_ENTRY(frdp->what), (char *)entry_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1585 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->wword),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1586 (gboolean)wword);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1587 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->mcase),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1588 (gboolean)mcase);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1589 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1590 gtk_window_present(GTK_WINDOW(frdp->dialog));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1591 vim_free(entry_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1592 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1593 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1594
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1595 frdp->dialog = gtk_dialog_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1596 gtk_dialog_set_has_separator(GTK_DIALOG(frdp->dialog), FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1597 gtk_window_set_transient_for(GTK_WINDOW(frdp->dialog), GTK_WINDOW(gui.mainwin));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1598 gtk_window_set_destroy_with_parent(GTK_WINDOW(frdp->dialog), TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1599
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1600 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1601 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1602 gtk_window_set_title(GTK_WINDOW(frdp->dialog),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1603 CONV(_("VIM - Search and Replace...")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1604 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1605 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1606 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1607 gtk_window_set_title(GTK_WINDOW(frdp->dialog),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1608 CONV(_("VIM - Search...")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1609 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1610
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1611 hbox = gtk_hbox_new(FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1612 gtk_container_set_border_width(GTK_CONTAINER(hbox), 10);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1613 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(frdp->dialog)->vbox), hbox);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1614
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1615 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1616 table = gtk_table_new(1024, 4, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1617 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1618 table = gtk_table_new(1024, 3, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1619 gtk_box_pack_start(GTK_BOX(hbox), table, TRUE, TRUE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1620 gtk_container_border_width(GTK_CONTAINER(table), 4);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1621
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1622 tmp = gtk_label_new(CONV(_("Find what:")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1623 gtk_misc_set_alignment(GTK_MISC(tmp), (gfloat)0.0, (gfloat)0.5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1624 gtk_table_attach(GTK_TABLE(table), tmp, 0, 1, 0, 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1625 GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1626 frdp->what = gtk_entry_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1627 sensitive = (entry_text != NULL && entry_text[0] != NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1628 if (entry_text != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1629 gtk_entry_set_text(GTK_ENTRY(frdp->what), (char *)entry_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1630 gtk_signal_connect(GTK_OBJECT(frdp->what), "changed",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1631 GTK_SIGNAL_FUNC(entry_changed_cb), frdp->dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1632 gtk_signal_connect_after(GTK_OBJECT(frdp->what), "key_press_event",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1633 GTK_SIGNAL_FUNC(find_key_press_event),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1634 (gpointer) frdp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1635 gtk_table_attach(GTK_TABLE(table), frdp->what, 1, 1024, 0, 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1636 GTK_EXPAND | GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1637
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1638 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1639 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1640 tmp = gtk_label_new(CONV(_("Replace with:")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1641 gtk_misc_set_alignment(GTK_MISC(tmp), (gfloat)0.0, (gfloat)0.5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1642 gtk_table_attach(GTK_TABLE(table), tmp, 0, 1, 1, 2,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1643 GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1644 frdp->with = gtk_entry_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1645 gtk_signal_connect(GTK_OBJECT(frdp->with), "activate",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1646 GTK_SIGNAL_FUNC(find_replace_cb),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1647 GINT_TO_POINTER(FRD_R_FINDNEXT));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1648 gtk_signal_connect_after(GTK_OBJECT(frdp->with), "key_press_event",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1649 GTK_SIGNAL_FUNC(find_key_press_event),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1650 (gpointer) frdp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1651 gtk_table_attach(GTK_TABLE(table), frdp->with, 1, 1024, 1, 2,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1652 GTK_EXPAND | GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1653
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1654 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1655 * Make the entry activation only change the input focus onto the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1656 * with item.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1657 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1658 gtk_signal_connect(GTK_OBJECT(frdp->what), "activate",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1659 GTK_SIGNAL_FUNC(entry_activate_cb), frdp->with);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1660 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1661 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1662 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1663 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1664 * Make the entry activation do the search.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1665 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1666 gtk_signal_connect(GTK_OBJECT(frdp->what), "activate",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1667 GTK_SIGNAL_FUNC(find_replace_cb),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1668 GINT_TO_POINTER(FRD_FINDNEXT));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1669 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1670
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1671 /* whole word only button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1672 frdp->wword = gtk_check_button_new_with_label(CONV(_("Match whole word only")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1673 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->wword),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1674 (gboolean)wword);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1675 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1676 gtk_table_attach(GTK_TABLE(table), frdp->wword, 0, 1023, 2, 3,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1677 GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1678 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1679 gtk_table_attach(GTK_TABLE(table), frdp->wword, 0, 1023, 1, 2,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1680 GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1681
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1682 /* match case button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1683 frdp->mcase = gtk_check_button_new_with_label(CONV(_("Match case")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1684 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->mcase),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1685 (gboolean)mcase);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1686 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1687 gtk_table_attach(GTK_TABLE(table), frdp->mcase, 0, 1023, 3, 4,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1688 GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1689 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1690 gtk_table_attach(GTK_TABLE(table), frdp->mcase, 0, 1023, 2, 3,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1691 GTK_FILL, GTK_EXPAND, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1692
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1693 tmp = gtk_frame_new(CONV(_("Direction")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1694 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1695 gtk_table_attach(GTK_TABLE(table), tmp, 1023, 1024, 2, 4,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1696 GTK_FILL, GTK_FILL, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1697 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1698 gtk_table_attach(GTK_TABLE(table), tmp, 1023, 1024, 1, 3,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1699 GTK_FILL, GTK_FILL, 2, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1700 vbox = gtk_vbox_new(FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1701 gtk_container_border_width(GTK_CONTAINER(vbox), 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1702 gtk_container_add(GTK_CONTAINER(tmp), vbox);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1703
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1704 /* 'Up' and 'Down' buttons */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1705 frdp->up = gtk_radio_button_new_with_label(NULL, CONV(_("Up")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1706 gtk_box_pack_start(GTK_BOX(vbox), frdp->up, TRUE, TRUE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1707 frdp->down = gtk_radio_button_new_with_label(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1708 gtk_radio_button_group(GTK_RADIO_BUTTON(frdp->up)),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1709 CONV(_("Down")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1710 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->down), TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1711 gtk_container_set_border_width(GTK_CONTAINER(vbox), 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1712 gtk_box_pack_start(GTK_BOX(vbox), frdp->down, TRUE, TRUE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1713
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1714 /* vbox to hold the action buttons */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1715 actionarea = gtk_vbutton_box_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1716 gtk_container_border_width(GTK_CONTAINER(actionarea), 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1717 gtk_box_pack_end(GTK_BOX(hbox), actionarea, FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1718
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1719 /* 'Find Next' button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1720 frdp->find = create_image_button(GTK_STOCK_FIND, _("Find Next"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1721 gtk_widget_set_sensitive(frdp->find, sensitive);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1722
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1723 gtk_signal_connect(GTK_OBJECT(frdp->find), "clicked",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1724 GTK_SIGNAL_FUNC(find_replace_cb),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1725 (do_replace) ? GINT_TO_POINTER(FRD_R_FINDNEXT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1726 : GINT_TO_POINTER(FRD_FINDNEXT));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1727
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1728 GTK_WIDGET_SET_FLAGS(frdp->find, GTK_CAN_DEFAULT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1729 gtk_box_pack_start(GTK_BOX(actionarea), frdp->find, FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1730 gtk_widget_grab_default(frdp->find);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1731
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1732 if (do_replace)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1733 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1734 /* 'Replace' button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1735 frdp->replace = create_image_button(GTK_STOCK_CONVERT, _("Replace"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1736 gtk_widget_set_sensitive(frdp->replace, sensitive);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1737 GTK_WIDGET_SET_FLAGS(frdp->replace, GTK_CAN_DEFAULT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1738 gtk_box_pack_start(GTK_BOX(actionarea), frdp->replace, FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1739 gtk_signal_connect(GTK_OBJECT(frdp->replace), "clicked",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1740 GTK_SIGNAL_FUNC(find_replace_cb),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1741 GINT_TO_POINTER(FRD_REPLACE));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1742
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1743 /* 'Replace All' button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1744 frdp->all = create_image_button(GTK_STOCK_CONVERT, _("Replace All"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1745 gtk_widget_set_sensitive(frdp->all, sensitive);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1746 GTK_WIDGET_SET_FLAGS(frdp->all, GTK_CAN_DEFAULT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1747 gtk_box_pack_start(GTK_BOX(actionarea), frdp->all, FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1748 gtk_signal_connect(GTK_OBJECT(frdp->all), "clicked",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1749 GTK_SIGNAL_FUNC(find_replace_cb),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1750 GINT_TO_POINTER(FRD_REPLACEALL));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1751 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1752
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1753 /* 'Cancel' button */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1754 tmp = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1755 GTK_WIDGET_SET_FLAGS(tmp, GTK_CAN_DEFAULT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1756 gtk_box_pack_end(GTK_BOX(actionarea), tmp, FALSE, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1757 gtk_signal_connect_object(GTK_OBJECT(tmp),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1758 "clicked", GTK_SIGNAL_FUNC(gtk_widget_hide),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1759 GTK_OBJECT(frdp->dialog));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1760 gtk_signal_connect_object(GTK_OBJECT(frdp->dialog),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1761 "delete_event", GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1762 GTK_OBJECT(frdp->dialog));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1763
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1764 tmp = gtk_vseparator_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1765 gtk_box_pack_end(GTK_BOX(hbox), tmp, FALSE, FALSE, 10);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1766
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1767 /* Suppress automatic show of the unused action area */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1768 gtk_widget_hide(GTK_DIALOG(frdp->dialog)->action_area);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1769 gtk_widget_show_all(hbox);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1770 gtk_widget_show(frdp->dialog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1771
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1772 vim_free(entry_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1773 vim_free(conv_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1774 #undef CONV
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1775 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1776
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1777 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1778 gui_mch_find_dialog(exarg_T *eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1779 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1780 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1781 find_replace_dialog_create(eap->arg, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1782 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1783
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1784 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1785 gui_mch_replace_dialog(exarg_T *eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1786 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1787 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1788 find_replace_dialog_create(eap->arg, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1789 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1790
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1791 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1792 * Callback for actions of the find and replace dialogs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1793 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1794 static void
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
1795 find_replace_cb(GtkWidget *widget UNUSED, gpointer data)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1796 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1797 int flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1798 char_u *find_text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1799 char_u *repl_text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1800 gboolean direction_down;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1801 SharedFindReplace *sfr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1802
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1803 flags = (int)(long)data; /* avoid a lint warning here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1804
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1805 /* Get the search/replace strings from the dialog */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1806 if (flags == FRD_FINDNEXT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1807 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1808 repl_text = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1809 sfr = &find_widgets;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1810 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1811 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1812 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1813 repl_text = (char_u *)gtk_entry_get_text(GTK_ENTRY(repl_widgets.with));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1814 sfr = &repl_widgets;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1815 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1816
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1817 find_text = (char_u *)gtk_entry_get_text(GTK_ENTRY(sfr->what));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1818 direction_down = GTK_TOGGLE_BUTTON(sfr->down)->active;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1819
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1820 if (GTK_TOGGLE_BUTTON(sfr->wword)->active)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1821 flags |= FRD_WHOLE_WORD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1822 if (GTK_TOGGLE_BUTTON(sfr->mcase)->active)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1823 flags |= FRD_MATCH_CASE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1824
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1825 repl_text = CONVERT_FROM_UTF8(repl_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1826 find_text = CONVERT_FROM_UTF8(find_text);
2656
4549e0e7fbb6 updated for version 7.3.076
Bram Moolenaar <bram@vim.org>
parents: 2649
diff changeset
1827 gui_do_findrepl(flags, find_text, repl_text, direction_down);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1828 CONVERT_FROM_UTF8_FREE(repl_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1829 CONVERT_FROM_UTF8_FREE(find_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1830 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1831
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1832 /* our usual callback function */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1833 static void
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
1834 entry_activate_cb(GtkWidget *widget UNUSED, gpointer data)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1835 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1836 gtk_widget_grab_focus(GTK_WIDGET(data));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1837 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1838
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1839 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1840 * Syncing the find/replace dialogs on the fly is utterly useless crack,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1841 * and causes nothing but problems. Please tell me a use case for which
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1842 * you'd need both a find dialog and a find/replace one at the same time,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1843 * without being able to actually use them separately since they're syncing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1844 * all the time. I don't think it's worthwhile to fix this nonsense,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1845 * particularly evil incarnation of braindeadness, whatever; I'd much rather
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1846 * see it extinguished from this planet. Thanks for listening. Sorry.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1847 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1848 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1849 entry_changed_cb(GtkWidget * entry, GtkWidget * dialog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1850 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1851 const gchar *entry_text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1852 gboolean nonempty;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1853
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1854 entry_text = gtk_entry_get_text(GTK_ENTRY(entry));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1855
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1856 if (!entry_text)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1857 return; /* shouldn't happen */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1858
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1859 nonempty = (entry_text[0] != '\0');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1860
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1861 if (dialog == find_widgets.dialog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1862 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1863 gtk_widget_set_sensitive(find_widgets.find, nonempty);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1864 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1865
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1866 if (dialog == repl_widgets.dialog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1867 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1868 gtk_widget_set_sensitive(repl_widgets.find, nonempty);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1869 gtk_widget_set_sensitive(repl_widgets.replace, nonempty);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1870 gtk_widget_set_sensitive(repl_widgets.all, nonempty);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1871 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1872 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1873
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1874 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1875 * ":helpfind"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1876 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1877 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1878 ex_helpfind(eap)
1884
3dd986bfef63 updated for version 7.2-181
vimboss
parents: 1693
diff changeset
1879 exarg_T *eap UNUSED;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1880 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1881 /* This will fail when menus are not loaded. Well, it's only for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1882 * backwards compatibility anyway. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1883 do_cmdline_cmd((char_u *)"emenu ToolBar.FindHelp");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1884 }