Mercurial > vim
annotate src/gui_gtk_x11.c @ 8184:1f81c571d0e7 v7.4.1385
commit https://github.com/vim/vim/commit/5e83840756f6bb446d5cd8d026c1430b203645f1
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Feb 21 23:12:41 2016 +0100
patch 7.4.1385
Problem: Compiler warning for using array.
Solution: Use the right member name. (Yegappan Lakshmanan)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 21 Feb 2016 23:15:05 +0100 |
parents | fb5ba6fbc843 |
children | 3456e2ebebd4 |
rev | line source |
---|---|
7 | 1 /* vi:set ts=8 sts=4 sw=4: |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * Porting to GTK+ was done by: | |
12 * | |
70 | 13 * (C) 1998,1999,2000 by Marcin Dalecki <martin@dalecki.de> |
7 | 14 * |
15 * With GREAT support and continuous encouragements by Andy Kahn and of | |
16 * course Bram Moolenaar! | |
17 * | |
18 * Support for GTK+ 2 was added by: | |
19 * | |
20 * (C) 2002,2003 Jason Hildebrand <jason@peaceworks.ca> | |
21 * Daniel Elstner <daniel.elstner@gmx.net> | |
22 */ | |
23 | |
24 #include "vim.h" | |
7380
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
25 #ifdef USE_GRESOURCE |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
26 #include "auto/gui_gtk_gresources.h" |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
27 #endif |
1666 | 28 |
7 | 29 #ifdef FEAT_GUI_GNOME |
30 /* Gnome redefines _() and N_(). Grrr... */ | |
31 # ifdef _ | |
32 # undef _ | |
33 # endif | |
34 # ifdef N_ | |
35 # undef N_ | |
36 # endif | |
37 # ifdef textdomain | |
38 # undef textdomain | |
39 # endif | |
40 # ifdef bindtextdomain | |
41 # undef bindtextdomain | |
42 # endif | |
1286 | 43 # ifdef bind_textdomain_codeset |
44 # undef bind_textdomain_codeset | |
1226 | 45 # endif |
7 | 46 # if defined(FEAT_GETTEXT) && !defined(ENABLE_NLS) |
47 # define ENABLE_NLS /* so the texts in the dialog boxes are translated */ | |
48 # endif | |
49 # include <gnome.h> | |
50 # include "version.h" | |
798 | 51 /* missing prototype in bonobo-dock-item.h */ |
52 extern void bonobo_dock_item_set_behavior(BonoboDockItem *dock_item, BonoboDockItemBehavior beh); | |
7 | 53 #endif |
54 | |
55 #if !defined(FEAT_GUI_GTK) && defined(PROTO) | |
56 /* When generating prototypes we don't want syntax errors. */ | |
57 # define GdkAtom int | |
58 # define GdkEventExpose int | |
59 # define GdkEventFocus int | |
60 # define GdkEventVisibility int | |
61 # define GdkEventProperty int | |
62 # define GtkContainer int | |
63 # define GtkTargetEntry int | |
64 # define GtkType int | |
65 # define GtkWidget int | |
66 # define gint int | |
67 # define gpointer int | |
68 # define guint int | |
69 # define GdkEventKey int | |
70 # define GdkEventSelection int | |
71 # define GtkSelectionData int | |
72 # define GdkEventMotion int | |
73 # define GdkEventButton int | |
74 # define GdkDragContext int | |
75 # define GdkEventConfigure int | |
76 # define GdkEventClient int | |
77 #else | |
78 # include <gdk/gdkkeysyms.h> | |
79 # include <gdk/gdk.h> | |
80 # ifdef WIN3264 | |
81 # include <gdk/gdkwin32.h> | |
82 # else | |
83 # include <gdk/gdkx.h> | |
84 # endif | |
85 | |
86 # include <gtk/gtk.h> | |
87 # include "gui_gtk_f.h" | |
88 #endif | |
89 | |
90 #ifdef HAVE_X11_SUNKEYSYM_H | |
91 # include <X11/Sunkeysym.h> | |
2714 | 92 #endif |
93 | |
7 | 94 /* |
95 * Easy-to-use macro for multihead support. | |
96 */ | |
97 #ifdef HAVE_GTK_MULTIHEAD | |
98 # define GET_X_ATOM(atom) gdk_x11_atom_to_xatom_for_display( \ | |
99 gtk_widget_get_display(gui.mainwin), atom) | |
100 #else | |
101 # define GET_X_ATOM(atom) ((Atom)(atom)) | |
102 #endif | |
103 | |
104 /* Selection type distinguishers */ | |
105 enum | |
106 { | |
107 TARGET_TYPE_NONE, | |
108 TARGET_UTF8_STRING, | |
109 TARGET_STRING, | |
110 TARGET_COMPOUND_TEXT, | |
1904 | 111 TARGET_HTML, |
7 | 112 TARGET_TEXT, |
113 TARGET_TEXT_URI_LIST, | |
114 TARGET_TEXT_PLAIN, | |
115 TARGET_VIM, | |
116 TARGET_VIMENC | |
117 }; | |
118 | |
119 /* | |
120 * Table of selection targets supported by Vim. | |
121 * Note: Order matters, preferred types should come first. | |
122 */ | |
123 static const GtkTargetEntry selection_targets[] = | |
124 { | |
125 {VIMENC_ATOM_NAME, 0, TARGET_VIMENC}, | |
126 {VIM_ATOM_NAME, 0, TARGET_VIM}, | |
1904 | 127 {"text/html", 0, TARGET_HTML}, |
7 | 128 {"UTF8_STRING", 0, TARGET_UTF8_STRING}, |
129 {"COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT}, | |
130 {"TEXT", 0, TARGET_TEXT}, | |
131 {"STRING", 0, TARGET_STRING} | |
132 }; | |
133 #define N_SELECTION_TARGETS (sizeof(selection_targets) / sizeof(selection_targets[0])) | |
134 | |
135 #ifdef FEAT_DND | |
136 /* | |
137 * Table of DnD targets supported by Vim. | |
138 * Note: Order matters, preferred types should come first. | |
139 */ | |
140 static const GtkTargetEntry dnd_targets[] = | |
141 { | |
142 {"text/uri-list", 0, TARGET_TEXT_URI_LIST}, | |
1904 | 143 {"text/html", 0, TARGET_HTML}, |
7 | 144 {"UTF8_STRING", 0, TARGET_UTF8_STRING}, |
145 {"STRING", 0, TARGET_STRING}, | |
146 {"text/plain", 0, TARGET_TEXT_PLAIN} | |
147 }; | |
148 # define N_DND_TARGETS (sizeof(dnd_targets) / sizeof(dnd_targets[0])) | |
149 #endif | |
150 | |
151 | |
152 /* | |
153 * "Monospace" is a standard font alias that should be present | |
154 * on all proper Pango/fontconfig installations. | |
155 */ | |
156 # define DEFAULT_FONT "Monospace 10" | |
157 | |
158 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
159 /* | |
160 * Atoms used to communicate save-yourself from the X11 session manager. There | |
161 * is no need to move them into the GUI struct, since they should be constant. | |
162 */ | |
163 static GdkAtom wm_protocols_atom = GDK_NONE; | |
164 static GdkAtom save_yourself_atom = GDK_NONE; | |
165 #endif | |
166 | |
167 /* | |
168 * Atoms used to control/reference X11 selections. | |
169 */ | |
1904 | 170 static GdkAtom html_atom = GDK_NONE; |
7 | 171 static GdkAtom utf8_string_atom = GDK_NONE; |
172 static GdkAtom vim_atom = GDK_NONE; /* Vim's own special selection format */ | |
173 static GdkAtom vimenc_atom = GDK_NONE; /* Vim's extended selection format */ | |
174 | |
175 /* | |
176 * Keycodes recognized by vim. | |
177 * NOTE: when changing this, the table in gui_x11.c probably needs the same | |
178 * change! | |
179 */ | |
180 static struct special_key | |
181 { | |
182 guint key_sym; | |
183 char_u code0; | |
184 char_u code1; | |
185 } | |
186 const special_keys[] = | |
187 { | |
188 {GDK_Up, 'k', 'u'}, | |
189 {GDK_Down, 'k', 'd'}, | |
190 {GDK_Left, 'k', 'l'}, | |
191 {GDK_Right, 'k', 'r'}, | |
192 {GDK_F1, 'k', '1'}, | |
193 {GDK_F2, 'k', '2'}, | |
194 {GDK_F3, 'k', '3'}, | |
195 {GDK_F4, 'k', '4'}, | |
196 {GDK_F5, 'k', '5'}, | |
197 {GDK_F6, 'k', '6'}, | |
198 {GDK_F7, 'k', '7'}, | |
199 {GDK_F8, 'k', '8'}, | |
200 {GDK_F9, 'k', '9'}, | |
201 {GDK_F10, 'k', ';'}, | |
202 {GDK_F11, 'F', '1'}, | |
203 {GDK_F12, 'F', '2'}, | |
204 {GDK_F13, 'F', '3'}, | |
205 {GDK_F14, 'F', '4'}, | |
206 {GDK_F15, 'F', '5'}, | |
207 {GDK_F16, 'F', '6'}, | |
208 {GDK_F17, 'F', '7'}, | |
209 {GDK_F18, 'F', '8'}, | |
210 {GDK_F19, 'F', '9'}, | |
211 {GDK_F20, 'F', 'A'}, | |
212 {GDK_F21, 'F', 'B'}, | |
213 {GDK_Pause, 'F', 'B'}, /* Pause == F21 according to netbeans.txt */ | |
214 {GDK_F22, 'F', 'C'}, | |
215 {GDK_F23, 'F', 'D'}, | |
216 {GDK_F24, 'F', 'E'}, | |
217 {GDK_F25, 'F', 'F'}, | |
218 {GDK_F26, 'F', 'G'}, | |
219 {GDK_F27, 'F', 'H'}, | |
220 {GDK_F28, 'F', 'I'}, | |
221 {GDK_F29, 'F', 'J'}, | |
222 {GDK_F30, 'F', 'K'}, | |
223 {GDK_F31, 'F', 'L'}, | |
224 {GDK_F32, 'F', 'M'}, | |
225 {GDK_F33, 'F', 'N'}, | |
226 {GDK_F34, 'F', 'O'}, | |
227 {GDK_F35, 'F', 'P'}, | |
228 #ifdef SunXK_F36 | |
229 {SunXK_F36, 'F', 'Q'}, | |
230 {SunXK_F37, 'F', 'R'}, | |
231 #endif | |
232 {GDK_Help, '%', '1'}, | |
233 {GDK_Undo, '&', '8'}, | |
234 {GDK_BackSpace, 'k', 'b'}, | |
235 {GDK_Insert, 'k', 'I'}, | |
236 {GDK_Delete, 'k', 'D'}, | |
237 {GDK_3270_BackTab, 'k', 'B'}, | |
238 {GDK_Clear, 'k', 'C'}, | |
239 {GDK_Home, 'k', 'h'}, | |
240 {GDK_End, '@', '7'}, | |
241 {GDK_Prior, 'k', 'P'}, | |
242 {GDK_Next, 'k', 'N'}, | |
243 {GDK_Print, '%', '9'}, | |
244 /* Keypad keys: */ | |
245 {GDK_KP_Left, 'k', 'l'}, | |
246 {GDK_KP_Right, 'k', 'r'}, | |
247 {GDK_KP_Up, 'k', 'u'}, | |
248 {GDK_KP_Down, 'k', 'd'}, | |
249 {GDK_KP_Insert, KS_EXTRA, (char_u)KE_KINS}, | |
250 {GDK_KP_Delete, KS_EXTRA, (char_u)KE_KDEL}, | |
251 {GDK_KP_Home, 'K', '1'}, | |
252 {GDK_KP_End, 'K', '4'}, | |
253 {GDK_KP_Prior, 'K', '3'}, /* page up */ | |
254 {GDK_KP_Next, 'K', '5'}, /* page down */ | |
255 | |
256 {GDK_KP_Add, 'K', '6'}, | |
257 {GDK_KP_Subtract, 'K', '7'}, | |
258 {GDK_KP_Divide, 'K', '8'}, | |
259 {GDK_KP_Multiply, 'K', '9'}, | |
260 {GDK_KP_Enter, 'K', 'A'}, | |
261 {GDK_KP_Decimal, 'K', 'B'}, | |
262 | |
263 {GDK_KP_0, 'K', 'C'}, | |
264 {GDK_KP_1, 'K', 'D'}, | |
265 {GDK_KP_2, 'K', 'E'}, | |
266 {GDK_KP_3, 'K', 'F'}, | |
267 {GDK_KP_4, 'K', 'G'}, | |
268 {GDK_KP_5, 'K', 'H'}, | |
269 {GDK_KP_6, 'K', 'I'}, | |
270 {GDK_KP_7, 'K', 'J'}, | |
271 {GDK_KP_8, 'K', 'K'}, | |
272 {GDK_KP_9, 'K', 'L'}, | |
273 | |
274 /* End of list marker: */ | |
275 {0, 0, 0} | |
276 }; | |
277 | |
278 /* | |
279 * Flags for command line options table below. | |
280 */ | |
281 #define ARG_FONT 1 | |
282 #define ARG_GEOMETRY 2 | |
283 #define ARG_REVERSE 3 | |
284 #define ARG_NOREVERSE 4 | |
285 #define ARG_BACKGROUND 5 | |
286 #define ARG_FOREGROUND 6 | |
287 #define ARG_ICONIC 7 | |
288 #define ARG_ROLE 8 | |
289 #define ARG_NETBEANS 9 | |
290 #define ARG_XRM 10 /* ignored */ | |
291 #define ARG_MENUFONT 11 /* ignored */ | |
292 #define ARG_INDEX_MASK 0x00ff | |
293 #define ARG_HAS_VALUE 0x0100 /* a value is expected after the argument */ | |
294 #define ARG_NEEDS_GUI 0x0200 /* need to initialize the GUI for this */ | |
295 #define ARG_FOR_GTK 0x0400 /* argument is handled by GTK+ or GNOME */ | |
296 #define ARG_COMPAT_LONG 0x0800 /* accept -foo but substitute with --foo */ | |
297 #define ARG_KEEP 0x1000 /* don't remove argument from argv[] */ | |
298 | |
299 /* | |
300 * This table holds all the X GUI command line options allowed. This includes | |
301 * the standard ones so that we can skip them when Vim is started without the | |
302 * GUI (but the GUI might start up later). | |
303 * | |
304 * When changing this, also update doc/gui_x11.txt and the usage message!!! | |
305 */ | |
306 typedef struct | |
307 { | |
308 const char *name; | |
309 unsigned int flags; | |
310 } | |
311 cmdline_option_T; | |
312 | |
313 static const cmdline_option_T cmdline_options[] = | |
314 { | |
315 /* We handle these options ourselves */ | |
316 {"-fn", ARG_FONT|ARG_HAS_VALUE}, | |
317 {"-font", ARG_FONT|ARG_HAS_VALUE}, | |
318 {"-geom", ARG_GEOMETRY|ARG_HAS_VALUE}, | |
319 {"-geometry", ARG_GEOMETRY|ARG_HAS_VALUE}, | |
320 {"-rv", ARG_REVERSE}, | |
321 {"-reverse", ARG_REVERSE}, | |
322 {"+rv", ARG_NOREVERSE}, | |
323 {"+reverse", ARG_NOREVERSE}, | |
324 {"-bg", ARG_BACKGROUND|ARG_HAS_VALUE}, | |
325 {"-background", ARG_BACKGROUND|ARG_HAS_VALUE}, | |
326 {"-fg", ARG_FOREGROUND|ARG_HAS_VALUE}, | |
327 {"-foreground", ARG_FOREGROUND|ARG_HAS_VALUE}, | |
328 {"-iconic", ARG_ICONIC}, | |
329 {"--role", ARG_ROLE|ARG_HAS_VALUE}, | |
330 #ifdef FEAT_NETBEANS_INTG | |
331 {"-nb", ARG_NETBEANS}, /* non-standard value format */ | |
332 {"-xrm", ARG_XRM|ARG_HAS_VALUE}, /* not implemented */ | |
333 {"-mf", ARG_MENUFONT|ARG_HAS_VALUE}, /* not implemented */ | |
334 {"-menufont", ARG_MENUFONT|ARG_HAS_VALUE}, /* not implemented */ | |
335 #endif | |
336 /* Arguments handled by GTK (and GNOME) internally. */ | |
337 {"--g-fatal-warnings", ARG_FOR_GTK}, | |
338 {"--gdk-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
339 {"--gdk-no-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
340 {"--gtk-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
341 {"--gtk-no-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
342 {"--gtk-module", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
343 {"--sync", ARG_FOR_GTK}, | |
344 {"--display", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
345 {"--name", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
346 {"--class", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
347 {"--screen", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
348 {"--gxid-host", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
349 {"--gxid-port", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
350 #ifdef FEAT_GUI_GNOME | |
351 {"--load-modules", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
352 {"--sm-client-id", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
353 {"--sm-config-prefix", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
354 {"--sm-disable", ARG_FOR_GTK}, | |
355 {"--oaf-ior-fd", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
356 {"--oaf-activate-iid", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
357 {"--oaf-private", ARG_FOR_GTK}, | |
358 {"--enable-sound", ARG_FOR_GTK}, | |
359 {"--disable-sound", ARG_FOR_GTK}, | |
360 {"--espeaker", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
361 {"-?", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
362 {"--help", ARG_FOR_GTK|ARG_NEEDS_GUI|ARG_KEEP}, | |
363 {"--usage", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
364 # if 0 /* conflicts with Vim's own --version argument */ | |
365 {"--version", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
366 # endif | |
367 {"--disable-crash-dialog", ARG_FOR_GTK}, | |
368 #endif | |
369 {NULL, 0} | |
370 }; | |
371 | |
372 static int gui_argc = 0; | |
373 static char **gui_argv = NULL; | |
374 | |
375 static const char *role_argument = NULL; | |
376 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
377 static const char *restart_command = NULL; | |
1898 | 378 static char *abs_restart_command = NULL; |
7 | 379 #endif |
380 static int found_iconic_arg = FALSE; | |
381 | |
382 #ifdef FEAT_GUI_GNOME | |
383 /* | |
384 * Can't use Gnome if --socketid given | |
385 */ | |
386 static int using_gnome = 0; | |
387 #else | |
388 # define using_gnome 0 | |
389 #endif | |
390 | |
391 /* | |
392 * Parse the GUI related command-line arguments. Any arguments used are | |
393 * deleted from argv, and *argc is decremented accordingly. This is called | |
394 * when vim is started, whether or not the GUI has been started. | |
395 */ | |
396 void | |
397 gui_mch_prepare(int *argc, char **argv) | |
398 { | |
399 const cmdline_option_T *option; | |
400 int i = 0; | |
401 int len = 0; | |
402 | |
403 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
404 /* | |
405 * Determine the command used to invoke Vim, to be passed as restart | |
406 * command to the session manager. If argv[0] contains any directory | |
407 * components try building an absolute path, otherwise leave it as is. | |
408 */ | |
409 restart_command = argv[0]; | |
410 | |
411 if (strchr(argv[0], G_DIR_SEPARATOR) != NULL) | |
412 { | |
413 char_u buf[MAXPATHL]; | |
414 | |
415 if (mch_FullName((char_u *)argv[0], buf, (int)sizeof(buf), TRUE) == OK) | |
1898 | 416 { |
417 abs_restart_command = (char *)vim_strsave(buf); | |
418 restart_command = abs_restart_command; | |
419 } | |
7 | 420 } |
421 #endif | |
422 | |
423 /* | |
424 * Move all the entries in argv which are relevant to GTK+ and GNOME | |
425 * into gui_argv. Freed later in gui_mch_init(). | |
426 */ | |
427 gui_argc = 0; | |
428 gui_argv = (char **)alloc((unsigned)((*argc + 1) * sizeof(char *))); | |
429 | |
430 g_return_if_fail(gui_argv != NULL); | |
431 | |
432 gui_argv[gui_argc++] = argv[i++]; | |
433 | |
434 while (i < *argc) | |
435 { | |
436 /* Don't waste CPU cycles on non-option arguments. */ | |
437 if (argv[i][0] != '-' && argv[i][0] != '+') | |
438 { | |
439 ++i; | |
440 continue; | |
441 } | |
442 | |
443 /* Look for argv[i] in cmdline_options[] table. */ | |
444 for (option = &cmdline_options[0]; option->name != NULL; ++option) | |
445 { | |
446 len = strlen(option->name); | |
447 | |
448 if (strncmp(argv[i], option->name, len) == 0) | |
449 { | |
450 if (argv[i][len] == '\0') | |
451 break; | |
452 /* allow --foo=bar style */ | |
453 if (argv[i][len] == '=' && (option->flags & ARG_HAS_VALUE)) | |
454 break; | |
455 #ifdef FEAT_NETBEANS_INTG | |
456 /* darn, -nb has non-standard syntax */ | |
457 if (vim_strchr((char_u *)":=", argv[i][len]) != NULL | |
458 && (option->flags & ARG_INDEX_MASK) == ARG_NETBEANS) | |
459 break; | |
460 #endif | |
461 } | |
462 else if ((option->flags & ARG_COMPAT_LONG) | |
463 && strcmp(argv[i], option->name + 1) == 0) | |
464 { | |
465 /* Replace the standard X arguments "-name" and "-display" | |
466 * with their GNU-style long option counterparts. */ | |
467 argv[i] = (char *)option->name; | |
468 break; | |
469 } | |
470 } | |
471 if (option->name == NULL) /* no match */ | |
472 { | |
473 ++i; | |
474 continue; | |
475 } | |
476 | |
477 if (option->flags & ARG_FOR_GTK) | |
478 { | |
479 /* Move the argument into gui_argv, which | |
480 * will later be passed to gtk_init_check() */ | |
481 gui_argv[gui_argc++] = argv[i]; | |
482 } | |
483 else | |
484 { | |
485 char *value = NULL; | |
486 | |
487 /* Extract the option's value if there is one. | |
488 * Accept both "--foo bar" and "--foo=bar" style. */ | |
489 if (option->flags & ARG_HAS_VALUE) | |
490 { | |
491 if (argv[i][len] == '=') | |
492 value = &argv[i][len + 1]; | |
493 else if (i + 1 < *argc && strcmp(argv[i + 1], "--") != 0) | |
494 value = argv[i + 1]; | |
495 } | |
496 | |
497 /* Check for options handled by Vim itself */ | |
498 switch (option->flags & ARG_INDEX_MASK) | |
499 { | |
500 case ARG_REVERSE: | |
501 found_reverse_arg = TRUE; | |
502 break; | |
503 case ARG_NOREVERSE: | |
504 found_reverse_arg = FALSE; | |
505 break; | |
506 case ARG_FONT: | |
507 font_argument = value; | |
508 break; | |
509 case ARG_GEOMETRY: | |
510 if (value != NULL) | |
511 gui.geom = vim_strsave((char_u *)value); | |
512 break; | |
513 case ARG_BACKGROUND: | |
514 background_argument = value; | |
515 break; | |
516 case ARG_FOREGROUND: | |
517 foreground_argument = value; | |
518 break; | |
519 case ARG_ICONIC: | |
520 found_iconic_arg = TRUE; | |
521 break; | |
522 case ARG_ROLE: | |
523 role_argument = value; /* used later in gui_mch_open() */ | |
524 break; | |
525 #ifdef FEAT_NETBEANS_INTG | |
526 case ARG_NETBEANS: | |
527 gui.dofork = FALSE; /* don't fork() when starting GUI */ | |
528 netbeansArg = argv[i]; | |
529 break; | |
530 #endif | |
531 default: | |
532 break; | |
533 } | |
534 } | |
535 | |
536 /* These arguments make gnome_program_init() print a message and exit. | |
537 * Must start the GUI for this, otherwise ":gui" will exit later! */ | |
538 if (option->flags & ARG_NEEDS_GUI) | |
539 gui.starting = TRUE; | |
540 | |
541 if (option->flags & ARG_KEEP) | |
542 ++i; | |
543 else | |
544 { | |
545 /* Remove the flag from the argument vector. */ | |
546 if (--*argc > i) | |
547 { | |
548 int n_strip = 1; | |
549 | |
550 /* Move the argument's value as well, if there is one. */ | |
551 if ((option->flags & ARG_HAS_VALUE) | |
552 && argv[i][len] != '=' | |
553 && strcmp(argv[i + 1], "--") != 0) | |
554 { | |
555 ++n_strip; | |
556 --*argc; | |
557 if (option->flags & ARG_FOR_GTK) | |
558 gui_argv[gui_argc++] = argv[i + 1]; | |
559 } | |
560 | |
561 if (*argc > i) | |
562 mch_memmove(&argv[i], &argv[i + n_strip], | |
563 (*argc - i) * sizeof(char *)); | |
564 } | |
565 argv[*argc] = NULL; | |
566 } | |
567 } | |
568 | |
569 gui_argv[gui_argc] = NULL; | |
570 } | |
571 | |
359 | 572 #if defined(EXITFREE) || defined(PROTO) |
573 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
574 gui_mch_free_all(void) |
359 | 575 { |
576 vim_free(gui_argv); | |
1898 | 577 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) |
578 vim_free(abs_restart_command); | |
579 #endif | |
359 | 580 } |
581 #endif | |
582 | |
7 | 583 /* |
584 * This should be maybe completely removed. | |
585 * Doesn't seem possible, since check_copy_area() relies on | |
586 * this information. --danielk | |
587 */ | |
588 static gint | |
1884 | 589 visibility_event(GtkWidget *widget UNUSED, |
590 GdkEventVisibility *event, | |
591 gpointer data UNUSED) | |
7 | 592 { |
593 gui.visibility = event->state; | |
594 /* | |
595 * When we do an gdk_window_copy_area(), and the window is partially | |
596 * obscured, we want to receive an event to tell us whether it worked | |
597 * or not. | |
598 */ | |
599 if (gui.text_gc != NULL) | |
600 gdk_gc_set_exposures(gui.text_gc, | |
601 gui.visibility != GDK_VISIBILITY_UNOBSCURED); | |
602 return FALSE; | |
603 } | |
604 | |
605 /* | |
606 * Redraw the corresponding portions of the screen. | |
607 */ | |
608 static gint | |
1884 | 609 expose_event(GtkWidget *widget UNUSED, |
610 GdkEventExpose *event, | |
611 gpointer data UNUSED) | |
7 | 612 { |
613 /* Skip this when the GUI isn't set up yet, will redraw later. */ | |
614 if (gui.starting) | |
615 return FALSE; | |
616 | |
617 out_flush(); /* make sure all output has been processed */ | |
618 gui_redraw(event->area.x, event->area.y, | |
619 event->area.width, event->area.height); | |
620 | |
621 /* Clear the border areas if needed */ | |
622 if (event->area.x < FILL_X(0)) | |
623 gdk_window_clear_area(gui.drawarea->window, 0, 0, FILL_X(0), 0); | |
624 if (event->area.y < FILL_Y(0)) | |
625 gdk_window_clear_area(gui.drawarea->window, 0, 0, 0, FILL_Y(0)); | |
626 if (event->area.x > FILL_X(Columns)) | |
627 gdk_window_clear_area(gui.drawarea->window, | |
628 FILL_X((int)Columns), 0, 0, 0); | |
629 if (event->area.y > FILL_Y(Rows)) | |
630 gdk_window_clear_area(gui.drawarea->window, 0, FILL_Y((int)Rows), 0, 0); | |
631 | |
632 return FALSE; | |
633 } | |
634 | |
635 #ifdef FEAT_CLIENTSERVER | |
636 /* | |
637 * Handle changes to the "Comm" property | |
638 */ | |
639 static gint | |
1884 | 640 property_event(GtkWidget *widget, |
641 GdkEventProperty *event, | |
642 gpointer data UNUSED) | |
7 | 643 { |
644 if (event->type == GDK_PROPERTY_NOTIFY | |
645 && event->state == (int)GDK_PROPERTY_NEW_VALUE | |
646 && GDK_WINDOW_XWINDOW(event->window) == commWindow | |
647 && GET_X_ATOM(event->atom) == commProperty) | |
648 { | |
649 XEvent xev; | |
650 | |
651 /* Translate to XLib */ | |
652 xev.xproperty.type = PropertyNotify; | |
653 xev.xproperty.atom = commProperty; | |
654 xev.xproperty.window = commWindow; | |
655 xev.xproperty.state = PropertyNewValue; | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7098
diff
changeset
|
656 serverEventProc(GDK_WINDOW_XDISPLAY(widget->window), &xev, 0); |
7 | 657 } |
658 return FALSE; | |
659 } | |
660 #endif | |
661 | |
662 | |
663 /**************************************************************************** | |
664 * Focus handlers: | |
665 */ | |
666 | |
667 | |
668 /* | |
669 * This is a simple state machine: | |
670 * BLINK_NONE not blinking at all | |
671 * BLINK_OFF blinking, cursor is not shown | |
672 * BLINK_ON blinking, cursor is shown | |
673 */ | |
674 | |
675 #define BLINK_NONE 0 | |
676 #define BLINK_OFF 1 | |
677 #define BLINK_ON 2 | |
678 | |
679 static int blink_state = BLINK_NONE; | |
680 static long_u blink_waittime = 700; | |
681 static long_u blink_ontime = 400; | |
682 static long_u blink_offtime = 250; | |
683 static guint blink_timer = 0; | |
684 | |
685 void | |
686 gui_mch_set_blinking(long waittime, long on, long off) | |
687 { | |
688 blink_waittime = waittime; | |
689 blink_ontime = on; | |
690 blink_offtime = off; | |
691 } | |
692 | |
693 /* | |
694 * Stop the cursor blinking. Show the cursor if it wasn't shown. | |
695 */ | |
696 void | |
697 gui_mch_stop_blink(void) | |
698 { | |
699 if (blink_timer) | |
700 { | |
701 gtk_timeout_remove(blink_timer); | |
702 blink_timer = 0; | |
703 } | |
704 if (blink_state == BLINK_OFF) | |
705 gui_update_cursor(TRUE, FALSE); | |
706 blink_state = BLINK_NONE; | |
707 } | |
708 | |
709 static gint | |
1884 | 710 blink_cb(gpointer data UNUSED) |
7 | 711 { |
712 if (blink_state == BLINK_ON) | |
713 { | |
714 gui_undraw_cursor(); | |
715 blink_state = BLINK_OFF; | |
716 blink_timer = gtk_timeout_add((guint32)blink_offtime, | |
717 (GtkFunction) blink_cb, NULL); | |
718 } | |
719 else | |
720 { | |
721 gui_update_cursor(TRUE, FALSE); | |
722 blink_state = BLINK_ON; | |
723 blink_timer = gtk_timeout_add((guint32)blink_ontime, | |
724 (GtkFunction) blink_cb, NULL); | |
725 } | |
726 | |
727 return FALSE; /* don't happen again */ | |
728 } | |
729 | |
730 /* | |
731 * Start the cursor blinking. If it was already blinking, this restarts the | |
732 * waiting time and shows the cursor. | |
733 */ | |
734 void | |
735 gui_mch_start_blink(void) | |
736 { | |
737 if (blink_timer) | |
5818 | 738 { |
7 | 739 gtk_timeout_remove(blink_timer); |
5818 | 740 blink_timer = 0; |
741 } | |
7 | 742 /* Only switch blinking on if none of the times is zero */ |
743 if (blink_waittime && blink_ontime && blink_offtime && gui.in_focus) | |
744 { | |
745 blink_timer = gtk_timeout_add((guint32)blink_waittime, | |
746 (GtkFunction) blink_cb, NULL); | |
747 blink_state = BLINK_ON; | |
748 gui_update_cursor(TRUE, FALSE); | |
749 } | |
750 } | |
751 | |
752 static gint | |
1884 | 753 enter_notify_event(GtkWidget *widget UNUSED, |
754 GdkEventCrossing *event UNUSED, | |
755 gpointer data UNUSED) | |
7 | 756 { |
757 if (blink_state == BLINK_NONE) | |
758 gui_mch_start_blink(); | |
759 | |
760 /* make sure keyboard input goes there */ | |
761 if (gtk_socket_id == 0 || !GTK_WIDGET_HAS_FOCUS(gui.drawarea)) | |
762 gtk_widget_grab_focus(gui.drawarea); | |
763 | |
764 return FALSE; | |
765 } | |
766 | |
767 static gint | |
1884 | 768 leave_notify_event(GtkWidget *widget UNUSED, |
769 GdkEventCrossing *event UNUSED, | |
770 gpointer data UNUSED) | |
7 | 771 { |
772 if (blink_state != BLINK_NONE) | |
773 gui_mch_stop_blink(); | |
774 | |
775 return FALSE; | |
776 } | |
777 | |
778 static gint | |
1884 | 779 focus_in_event(GtkWidget *widget, |
780 GdkEventFocus *event UNUSED, | |
781 gpointer data UNUSED) | |
7 | 782 { |
783 gui_focus_change(TRUE); | |
784 | |
785 if (blink_state == BLINK_NONE) | |
786 gui_mch_start_blink(); | |
787 | |
1380 | 788 /* make sure keyboard input goes to the draw area (if this is focus for a |
789 * window) */ | |
791 | 790 if (widget != gui.drawarea) |
856 | 791 gtk_widget_grab_focus(gui.drawarea); |
7 | 792 |
793 return TRUE; | |
794 } | |
795 | |
796 static gint | |
1884 | 797 focus_out_event(GtkWidget *widget UNUSED, |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2301
diff
changeset
|
798 GdkEventFocus *event UNUSED, |
1884 | 799 gpointer data UNUSED) |
7 | 800 { |
801 gui_focus_change(FALSE); | |
802 | |
803 if (blink_state != BLINK_NONE) | |
804 gui_mch_stop_blink(); | |
805 | |
806 return TRUE; | |
807 } | |
808 | |
809 | |
810 /* | |
811 * Translate a GDK key value to UTF-8 independently of the current locale. | |
812 * The output is written to string, which must have room for at least 6 bytes | |
813 * plus the NUL terminator. Returns the length in bytes. | |
814 * | |
815 * This function is used in the GTK+ 2 GUI only. The GTK+ 1 code makes use | |
816 * of GdkEventKey::string instead. But event->string is evil; see here why: | |
817 * http://developer.gnome.org/doc/API/2.0/gdk/gdk-Event-Structures.html#GdkEventKey | |
818 */ | |
819 static int | |
820 keyval_to_string(unsigned int keyval, unsigned int state, char_u *string) | |
821 { | |
822 int len; | |
823 guint32 uc; | |
824 | |
825 uc = gdk_keyval_to_unicode(keyval); | |
826 if (uc != 0) | |
827 { | |
828 /* Check for CTRL-foo */ | |
829 if ((state & GDK_CONTROL_MASK) && uc >= 0x20 && uc < 0x80) | |
830 { | |
831 /* These mappings look arbitrary at the first glance, but in fact | |
832 * resemble quite exactly the behaviour of the GTK+ 1.2 GUI on my | |
833 * machine. The only difference is BS vs. DEL for CTRL-8 (makes | |
834 * more sense and is consistent with usual terminal behaviour). */ | |
835 if (uc >= '@') | |
836 string[0] = uc & 0x1F; | |
837 else if (uc == '2') | |
838 string[0] = NUL; | |
839 else if (uc >= '3' && uc <= '7') | |
840 string[0] = uc ^ 0x28; | |
841 else if (uc == '8') | |
842 string[0] = BS; | |
843 else if (uc == '?') | |
844 string[0] = DEL; | |
845 else | |
846 string[0] = uc; | |
847 len = 1; | |
848 } | |
849 else | |
850 { | |
851 /* Translate a normal key to UTF-8. This doesn't work for dead | |
852 * keys of course, you _have_ to use an input method for that. */ | |
853 len = utf_char2bytes((int)uc, string); | |
854 } | |
855 } | |
856 else | |
857 { | |
858 /* Translate keys which are represented by ASCII control codes in Vim. | |
859 * There are only a few of those; most control keys are translated to | |
860 * special terminal-like control sequences. */ | |
861 len = 1; | |
862 switch (keyval) | |
863 { | |
864 case GDK_Tab: case GDK_KP_Tab: case GDK_ISO_Left_Tab: | |
865 string[0] = TAB; | |
866 break; | |
867 case GDK_Linefeed: | |
868 string[0] = NL; | |
869 break; | |
870 case GDK_Return: case GDK_ISO_Enter: case GDK_3270_Enter: | |
871 string[0] = CAR; | |
872 break; | |
873 case GDK_Escape: | |
874 string[0] = ESC; | |
875 break; | |
876 default: | |
877 len = 0; | |
878 break; | |
879 } | |
880 } | |
881 string[len] = NUL; | |
882 | |
883 return len; | |
884 } | |
885 | |
179 | 886 static int |
887 modifiers_gdk2vim(guint state) | |
888 { | |
889 int modifiers = 0; | |
890 | |
891 if (state & GDK_SHIFT_MASK) | |
892 modifiers |= MOD_MASK_SHIFT; | |
893 if (state & GDK_CONTROL_MASK) | |
894 modifiers |= MOD_MASK_CTRL; | |
895 if (state & GDK_MOD1_MASK) | |
896 modifiers |= MOD_MASK_ALT; | |
2550
7c1f73452ea6
Fix #ifdef for GDK_SUPER_MASK.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
897 #if GTK_CHECK_VERSION(2,10,0) |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
898 if (state & GDK_SUPER_MASK) |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
899 modifiers |= MOD_MASK_META; |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
900 #endif |
179 | 901 if (state & GDK_MOD4_MASK) |
902 modifiers |= MOD_MASK_META; | |
903 | |
904 return modifiers; | |
905 } | |
906 | |
907 static int | |
908 modifiers_gdk2mouse(guint state) | |
909 { | |
910 int modifiers = 0; | |
911 | |
912 if (state & GDK_SHIFT_MASK) | |
913 modifiers |= MOUSE_SHIFT; | |
914 if (state & GDK_CONTROL_MASK) | |
915 modifiers |= MOUSE_CTRL; | |
916 if (state & GDK_MOD1_MASK) | |
917 modifiers |= MOUSE_ALT; | |
918 | |
919 return modifiers; | |
920 } | |
921 | |
7 | 922 /* |
923 * Main keyboard handler: | |
924 */ | |
925 static gint | |
1884 | 926 key_press_event(GtkWidget *widget UNUSED, |
927 GdkEventKey *event, | |
928 gpointer data UNUSED) | |
7 | 929 { |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
930 /* For GTK+ 2 we know for sure how large the string might get. |
7 | 931 * (That is, up to 6 bytes + NUL + CSI escapes + safety measure.) */ |
932 char_u string[32], string2[32]; | |
933 guint key_sym; | |
934 int len; | |
935 int i; | |
936 int modifiers; | |
937 int key; | |
938 guint state; | |
939 char_u *s, *d; | |
940 | |
2923 | 941 gui.event_time = event->time; |
7 | 942 key_sym = event->keyval; |
943 state = event->state; | |
944 | |
945 #ifdef FEAT_XIM | |
946 if (xim_queue_key_press_event(event, TRUE)) | |
947 return TRUE; | |
948 #endif | |
949 | |
950 #ifdef FEAT_HANGULIN | |
951 if (key_sym == GDK_space && (state & GDK_SHIFT_MASK)) | |
952 { | |
953 hangul_input_state_toggle(); | |
954 return TRUE; | |
955 } | |
956 #endif | |
957 | |
958 #ifdef SunXK_F36 | |
959 /* | |
960 * These keys have bogus lookup strings, and trapping them here is | |
961 * easier than trying to XRebindKeysym() on them with every possible | |
962 * combination of modifiers. | |
963 */ | |
964 if (key_sym == SunXK_F36 || key_sym == SunXK_F37) | |
965 len = 0; | |
966 else | |
967 #endif | |
968 { | |
969 len = keyval_to_string(key_sym, state, string2); | |
970 | |
971 /* Careful: convert_input() doesn't handle the NUL character. | |
972 * No need to convert pure ASCII anyway, thus the len > 1 check. */ | |
973 if (len > 1 && input_conv.vc_type != CONV_NONE) | |
974 len = convert_input(string2, len, sizeof(string2)); | |
975 | |
976 s = string2; | |
977 d = string; | |
978 for (i = 0; i < len; ++i) | |
979 { | |
980 *d++ = s[i]; | |
981 if (d[-1] == CSI && d + 2 < string + sizeof(string)) | |
982 { | |
983 /* Turn CSI into K_CSI. */ | |
984 *d++ = KS_EXTRA; | |
985 *d++ = (int)KE_CSI; | |
986 } | |
987 } | |
988 len = d - string; | |
989 } | |
990 | |
991 /* Shift-Tab results in Left_Tab, but we want <S-Tab> */ | |
992 if (key_sym == GDK_ISO_Left_Tab) | |
993 { | |
994 key_sym = GDK_Tab; | |
995 state |= GDK_SHIFT_MASK; | |
996 } | |
997 | |
998 #ifdef FEAT_MENU | |
999 /* If there is a menu and 'wak' is "yes", or 'wak' is "menu" and the key | |
1000 * is a menu shortcut, we ignore everything with the ALT modifier. */ | |
1001 if ((state & GDK_MOD1_MASK) | |
1002 && gui.menu_is_active | |
1003 && (*p_wak == 'y' | |
1004 || (*p_wak == 'm' | |
1005 && len == 1 | |
1006 && gui_is_menu_shortcut(string[0])))) | |
1007 /* For GTK2 we return false to signify that we haven't handled the | |
1008 * keypress, so that gtk will handle the mnemonic or accelerator. */ | |
1009 return FALSE; | |
1010 #endif | |
1011 | |
1012 /* Check for Alt/Meta key (Mod1Mask), but not for a BS, DEL or character | |
1013 * that already has the 8th bit set. | |
1014 * Don't do this for <S-M-Tab>, that should become K_S_TAB with ALT. | |
1015 * Don't do this for double-byte encodings, it turns the char into a lead | |
1016 * byte. */ | |
1017 if (len == 1 | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1018 && ((state & GDK_MOD1_MASK) |
2571
42bdbc2bbb59
Fix #ifdef for GDK_SUPER_MASK. (Stephan Schulz)
Bram Moolenaar <bram@vim.org>
parents:
2550
diff
changeset
|
1019 #if GTK_CHECK_VERSION(2,10,0) |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1020 || (state & GDK_SUPER_MASK) |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1021 #endif |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1022 ) |
7 | 1023 && !(key_sym == GDK_BackSpace || key_sym == GDK_Delete) |
1024 && (string[0] & 0x80) == 0 | |
1025 && !(key_sym == GDK_Tab && (state & GDK_SHIFT_MASK)) | |
1026 && !enc_dbcs | |
1027 ) | |
1028 { | |
1029 string[0] |= 0x80; | |
1030 state &= ~GDK_MOD1_MASK; /* don't use it again */ | |
1031 if (enc_utf8) /* convert to utf-8 */ | |
1032 { | |
1033 string[1] = string[0] & 0xbf; | |
1034 string[0] = ((unsigned)string[0] >> 6) + 0xc0; | |
1035 if (string[1] == CSI) | |
1036 { | |
1037 string[2] = KS_EXTRA; | |
1038 string[3] = (int)KE_CSI; | |
1039 len = 4; | |
1040 } | |
1041 else | |
1042 len = 2; | |
1043 } | |
1044 } | |
1045 | |
1046 /* Check for special keys. Also do this when len == 1 (key has an ASCII | |
1047 * value) to detect backspace, delete and keypad keys. */ | |
1048 if (len == 0 || len == 1) | |
1049 { | |
1050 for (i = 0; special_keys[i].key_sym != 0; i++) | |
1051 { | |
1052 if (special_keys[i].key_sym == key_sym) | |
1053 { | |
1054 string[0] = CSI; | |
1055 string[1] = special_keys[i].code0; | |
1056 string[2] = special_keys[i].code1; | |
1057 len = -3; | |
1058 break; | |
1059 } | |
1060 } | |
1061 } | |
1062 | |
1063 if (len == 0) /* Unrecognized key */ | |
1064 return TRUE; | |
1065 | |
1066 /* Special keys (and a few others) may have modifiers. Also when using a | |
1067 * double-byte encoding (can't set the 8th bit). */ | |
1068 if (len == -3 || key_sym == GDK_space || key_sym == GDK_Tab | |
1069 || key_sym == GDK_Return || key_sym == GDK_Linefeed | |
1070 || key_sym == GDK_Escape || key_sym == GDK_KP_Tab | |
1071 || key_sym == GDK_ISO_Enter || key_sym == GDK_3270_Enter | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1072 || (enc_dbcs && len == 1 && ((state & GDK_MOD1_MASK) |
2571
42bdbc2bbb59
Fix #ifdef for GDK_SUPER_MASK. (Stephan Schulz)
Bram Moolenaar <bram@vim.org>
parents:
2550
diff
changeset
|
1073 #if GTK_CHECK_VERSION(2,10,0) |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1074 || (state & GDK_SUPER_MASK) |
7 | 1075 #endif |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1076 ))) |
7 | 1077 { |
179 | 1078 modifiers = modifiers_gdk2vim(state); |
7 | 1079 |
1080 /* | |
1081 * For some keys a shift modifier is translated into another key | |
1082 * code. | |
1083 */ | |
1084 if (len == -3) | |
1085 key = TO_SPECIAL(string[1], string[2]); | |
1086 else | |
1087 key = string[0]; | |
1088 | |
1089 key = simplify_key(key, &modifiers); | |
1090 if (key == CSI) | |
1091 key = K_CSI; | |
1092 if (IS_SPECIAL(key)) | |
1093 { | |
1094 string[0] = CSI; | |
1095 string[1] = K_SECOND(key); | |
1096 string[2] = K_THIRD(key); | |
1097 len = 3; | |
1098 } | |
1099 else | |
1100 { | |
1101 string[0] = key; | |
1102 len = 1; | |
1103 } | |
1104 | |
1105 if (modifiers != 0) | |
1106 { | |
1107 string2[0] = CSI; | |
1108 string2[1] = KS_MODIFIER; | |
1109 string2[2] = modifiers; | |
1110 add_to_input_buf(string2, 3); | |
1111 } | |
1112 } | |
1113 | |
1114 if (len == 1 && ((string[0] == Ctrl_C && ctrl_c_interrupts) | |
1115 || (string[0] == intr_char && intr_char != Ctrl_C))) | |
1116 { | |
1117 trash_input_buf(); | |
1118 got_int = TRUE; | |
1119 } | |
1120 | |
1121 add_to_input_buf(string, len); | |
1122 | |
1123 /* blank out the pointer if necessary */ | |
1124 if (p_mh) | |
1125 gui_mch_mousehide(TRUE); | |
1126 | |
1127 return TRUE; | |
1128 } | |
1129 | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1130 #if defined(FEAT_XIM) |
7 | 1131 static gboolean |
1884 | 1132 key_release_event(GtkWidget *widget UNUSED, |
1133 GdkEventKey *event, | |
1134 gpointer data UNUSED) | |
7 | 1135 { |
2923 | 1136 gui.event_time = event->time; |
7 | 1137 /* |
1138 * GTK+ 2 input methods may do fancy stuff on key release events too. | |
1139 * With the default IM for instance, you can enter any UCS code point | |
1140 * by holding down CTRL-SHIFT and typing hexadecimal digits. | |
1141 */ | |
1142 return xim_queue_key_press_event(event, FALSE); | |
1143 } | |
1144 #endif | |
1145 | |
1146 | |
1147 /**************************************************************************** | |
1148 * Selection handlers: | |
1149 */ | |
1150 | |
1151 static gint | |
1884 | 1152 selection_clear_event(GtkWidget *widget UNUSED, |
7 | 1153 GdkEventSelection *event, |
1884 | 1154 gpointer user_data UNUSED) |
7 | 1155 { |
1156 if (event->selection == clip_plus.gtk_sel_atom) | |
1157 clip_lose_selection(&clip_plus); | |
1158 else | |
1159 clip_lose_selection(&clip_star); | |
1160 | |
1161 return TRUE; | |
1162 } | |
1163 | |
1164 #define RS_NONE 0 /* selection_received_cb() not called yet */ | |
1165 #define RS_OK 1 /* selection_received_cb() called and OK */ | |
1166 #define RS_FAIL 2 /* selection_received_cb() called and failed */ | |
1167 static int received_selection = RS_NONE; | |
1168 | |
1169 static void | |
1884 | 1170 selection_received_cb(GtkWidget *widget UNUSED, |
7 | 1171 GtkSelectionData *data, |
1884 | 1172 guint time_ UNUSED, |
1173 gpointer user_data UNUSED) | |
7 | 1174 { |
1175 VimClipboard *cbd; | |
1176 char_u *text; | |
1177 char_u *tmpbuf = NULL; | |
1178 guchar *tmpbuf_utf8 = NULL; | |
1179 int len; | |
2896 | 1180 int motion_type = MAUTO; |
7 | 1181 |
1182 if (data->selection == clip_plus.gtk_sel_atom) | |
1183 cbd = &clip_plus; | |
1184 else | |
1185 cbd = &clip_star; | |
1186 | |
1187 text = (char_u *)data->data; | |
1188 len = data->length; | |
1189 | |
1190 if (text == NULL || len <= 0) | |
1191 { | |
1192 received_selection = RS_FAIL; | |
1193 /* clip_free_selection(cbd); ??? */ | |
1194 | |
1195 return; | |
1196 } | |
1197 | |
1198 if (data->type == vim_atom) | |
1199 { | |
1200 motion_type = *text++; | |
1201 --len; | |
1202 } | |
1203 | |
1204 else if (data->type == vimenc_atom) | |
1205 { | |
1206 char_u *enc; | |
1207 vimconv_T conv; | |
1208 | |
1209 motion_type = *text++; | |
1210 --len; | |
1211 | |
1212 enc = text; | |
1213 text += STRLEN(text) + 1; | |
1214 len -= text - enc; | |
1215 | |
1216 /* If the encoding of the text is different from 'encoding', attempt | |
1217 * converting it. */ | |
1218 conv.vc_type = CONV_NONE; | |
1219 convert_setup(&conv, enc, p_enc); | |
1220 if (conv.vc_type != CONV_NONE) | |
1221 { | |
1222 tmpbuf = string_convert(&conv, text, &len); | |
1223 if (tmpbuf != NULL) | |
1224 text = tmpbuf; | |
1225 convert_setup(&conv, NULL, NULL); | |
1226 } | |
1227 } | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1228 |
7 | 1229 /* gtk_selection_data_get_text() handles all the nasty details |
1230 * and targets and encodings etc. This rocks so hard. */ | |
1231 else | |
1232 { | |
1233 tmpbuf_utf8 = gtk_selection_data_get_text(data); | |
1234 if (tmpbuf_utf8 != NULL) | |
1235 { | |
1236 len = STRLEN(tmpbuf_utf8); | |
1237 if (input_conv.vc_type != CONV_NONE) | |
1238 { | |
1239 tmpbuf = string_convert(&input_conv, tmpbuf_utf8, &len); | |
1240 if (tmpbuf != NULL) | |
1241 text = tmpbuf; | |
1242 } | |
1243 else | |
1244 text = tmpbuf_utf8; | |
1245 } | |
1904 | 1246 else if (len >= 2 && text[0] == 0xff && text[1] == 0xfe) |
1247 { | |
1248 vimconv_T conv; | |
1249 | |
1250 /* UTF-16, we get this for HTML */ | |
1251 conv.vc_type = CONV_NONE; | |
1252 convert_setup_ext(&conv, (char_u *)"utf-16le", FALSE, p_enc, TRUE); | |
1253 | |
1254 if (conv.vc_type != CONV_NONE) | |
1255 { | |
1256 text += 2; | |
1257 len -= 2; | |
1258 tmpbuf = string_convert(&conv, text, &len); | |
1259 convert_setup(&conv, NULL, NULL); | |
1260 } | |
1261 if (tmpbuf != NULL) | |
1262 text = tmpbuf; | |
1263 } | |
7 | 1264 } |
1265 | |
4352 | 1266 /* Chop off any trailing NUL bytes. OpenOffice sends these. */ |
2183 | 1267 while (len > 0 && text[len - 1] == NUL) |
1268 --len; | |
1269 | |
7 | 1270 clip_yank_selection(motion_type, text, (long)len, cbd); |
1271 received_selection = RS_OK; | |
1272 vim_free(tmpbuf); | |
1273 g_free(tmpbuf_utf8); | |
1274 } | |
1275 | |
1276 /* | |
1277 * Prepare our selection data for passing it to the external selection | |
1278 * client. | |
1279 */ | |
1280 static void | |
1884 | 1281 selection_get_cb(GtkWidget *widget UNUSED, |
7 | 1282 GtkSelectionData *selection_data, |
1283 guint info, | |
1884 | 1284 guint time_ UNUSED, |
1285 gpointer user_data UNUSED) | |
7 | 1286 { |
1287 char_u *string; | |
1288 char_u *tmpbuf; | |
1289 long_u tmplen; | |
1290 int length; | |
1291 int motion_type; | |
1292 GdkAtom type; | |
1293 VimClipboard *cbd; | |
1294 | |
1295 if (selection_data->selection == clip_plus.gtk_sel_atom) | |
1296 cbd = &clip_plus; | |
1297 else | |
1298 cbd = &clip_star; | |
1299 | |
1300 if (!cbd->owned) | |
1301 return; /* Shouldn't ever happen */ | |
1302 | |
1303 if (info != (guint)TARGET_STRING | |
1904 | 1304 && (!clip_html || info != (guint)TARGET_HTML) |
7 | 1305 && info != (guint)TARGET_UTF8_STRING |
1306 && info != (guint)TARGET_VIMENC | |
1307 && info != (guint)TARGET_VIM | |
1308 && info != (guint)TARGET_COMPOUND_TEXT | |
1309 && info != (guint)TARGET_TEXT) | |
1310 return; | |
1311 | |
1312 /* get the selection from the '*'/'+' register */ | |
1313 clip_get_selection(cbd); | |
1314 | |
1315 motion_type = clip_convert_selection(&string, &tmplen, cbd); | |
1316 if (motion_type < 0 || string == NULL) | |
1317 return; | |
1318 /* Due to int arguments we can't handle more than G_MAXINT. Also | |
1319 * reserve one extra byte for NUL or the motion type; just in case. | |
1320 * (Not that pasting 2G of text is ever going to work, but... ;-) */ | |
1321 length = MIN(tmplen, (long_u)(G_MAXINT - 1)); | |
1322 | |
1323 if (info == (guint)TARGET_VIM) | |
1324 { | |
1325 tmpbuf = alloc((unsigned)length + 1); | |
1326 if (tmpbuf != NULL) | |
1327 { | |
1328 tmpbuf[0] = motion_type; | |
1329 mch_memmove(tmpbuf + 1, string, (size_t)length); | |
1330 } | |
1331 /* For our own format, the first byte contains the motion type */ | |
1332 ++length; | |
1333 vim_free(string); | |
1334 string = tmpbuf; | |
1335 type = vim_atom; | |
1336 } | |
1337 | |
1904 | 1338 else if (info == (guint)TARGET_HTML) |
1339 { | |
1340 vimconv_T conv; | |
1341 | |
1342 /* Since we get utf-16, we probably should set it as well. */ | |
1343 conv.vc_type = CONV_NONE; | |
1344 convert_setup_ext(&conv, p_enc, TRUE, (char_u *)"utf-16le", FALSE); | |
1345 if (conv.vc_type != CONV_NONE) | |
1346 { | |
1347 tmpbuf = string_convert(&conv, string, &length); | |
1348 convert_setup(&conv, NULL, NULL); | |
1349 vim_free(string); | |
1350 string = tmpbuf; | |
1351 } | |
1352 | |
1353 /* Prepend the BOM: "fffe" */ | |
1354 if (string != NULL) | |
1355 { | |
1356 tmpbuf = alloc(length + 2); | |
1357 tmpbuf[0] = 0xff; | |
1358 tmpbuf[1] = 0xfe; | |
1359 mch_memmove(tmpbuf + 2, string, (size_t)length); | |
1360 vim_free(string); | |
1361 string = tmpbuf; | |
1362 length += 2; | |
1363 | |
1364 selection_data->type = selection_data->target; | |
1365 selection_data->format = 16; /* 16 bits per char */ | |
1366 gtk_selection_data_set(selection_data, html_atom, 16, | |
1367 string, length); | |
1368 vim_free(string); | |
1369 } | |
1370 return; | |
1371 } | |
7 | 1372 else if (info == (guint)TARGET_VIMENC) |
1373 { | |
1374 int l = STRLEN(p_enc); | |
1375 | |
1376 /* contents: motion_type 'encoding' NUL text */ | |
1377 tmpbuf = alloc((unsigned)length + l + 2); | |
1378 if (tmpbuf != NULL) | |
1379 { | |
1380 tmpbuf[0] = motion_type; | |
1381 STRCPY(tmpbuf + 1, p_enc); | |
1382 mch_memmove(tmpbuf + l + 2, string, (size_t)length); | |
1383 } | |
1384 length += l + 2; | |
1385 vim_free(string); | |
1386 string = tmpbuf; | |
1387 type = vimenc_atom; | |
1388 } | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1389 |
7 | 1390 /* gtk_selection_data_set_text() handles everything for us. This is |
1391 * so easy and simple and cool, it'd be insane not to use it. */ | |
1392 else | |
1393 { | |
1394 if (output_conv.vc_type != CONV_NONE) | |
1395 { | |
1396 tmpbuf = string_convert(&output_conv, string, &length); | |
1397 vim_free(string); | |
1398 if (tmpbuf == NULL) | |
1399 return; | |
1400 string = tmpbuf; | |
1401 } | |
1402 /* Validate the string to avoid runtime warnings */ | |
1403 if (g_utf8_validate((const char *)string, (gssize)length, NULL)) | |
1404 { | |
1405 gtk_selection_data_set_text(selection_data, | |
1406 (const char *)string, length); | |
1407 } | |
1408 vim_free(string); | |
1409 return; | |
1410 } | |
1411 | |
1412 if (string != NULL) | |
1413 { | |
1414 selection_data->type = selection_data->target; | |
1415 selection_data->format = 8; /* 8 bits per char */ | |
1416 | |
1417 gtk_selection_data_set(selection_data, type, 8, string, length); | |
1418 vim_free(string); | |
1419 } | |
1420 } | |
1421 | |
1422 /* | |
3518 | 1423 * Check if the GUI can be started. Called before gvimrc is sourced and |
1424 * before fork(). | |
1425 * Return OK or FAIL. | |
1426 */ | |
1427 int | |
1428 gui_mch_early_init_check(void) | |
1429 { | |
1430 char_u *p; | |
1431 | |
1432 /* Guess that when $DISPLAY isn't set the GUI can't start. */ | |
1433 p = mch_getenv((char_u *)"DISPLAY"); | |
1434 if (p == NULL || *p == NUL) | |
1435 { | |
1436 gui.dying = TRUE; | |
1437 EMSG(_((char *)e_opendisp)); | |
1438 return FAIL; | |
1439 } | |
1440 return OK; | |
1441 } | |
1442 | |
1443 /* | |
1444 * Check if the GUI can be started. Called before gvimrc is sourced but after | |
1445 * fork(). | |
7 | 1446 * Return OK or FAIL. |
1447 */ | |
1448 int | |
1449 gui_mch_init_check(void) | |
1450 { | |
7679
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1451 #ifdef USE_GRESOURCE |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1452 static int res_registered = FALSE; |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1453 |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1454 if (!res_registered) |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1455 { |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1456 /* Call this function in the GUI process; otherwise, the resources |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1457 * won't be available. Don't call it twice. */ |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1458 res_registered = TRUE; |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1459 gui_gtk_register_resource(); |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1460 } |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1461 #endif |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1462 |
7 | 1463 #ifdef FEAT_GUI_GNOME |
1464 if (gtk_socket_id == 0) | |
1465 using_gnome = 1; | |
1466 #endif | |
1467 | |
4474 | 1468 /* This defaults to argv[0], but we want it to match the name of the |
1469 * shipped gvim.desktop so that Vim's windows can be associated with this | |
1470 * file. */ | |
1471 g_set_prgname("gvim"); | |
1472 | |
7 | 1473 /* Don't use gtk_init() or gnome_init(), it exits on failure. */ |
1474 if (!gtk_init_check(&gui_argc, &gui_argv)) | |
1475 { | |
1476 gui.dying = TRUE; | |
1666 | 1477 EMSG(_((char *)e_opendisp)); |
7 | 1478 return FAIL; |
1479 } | |
1480 | |
1481 return OK; | |
1482 } | |
1483 | |
1484 | |
1485 /**************************************************************************** | |
1486 * Mouse handling callbacks | |
1487 */ | |
1488 | |
1489 | |
1490 static guint mouse_click_timer = 0; | |
1491 static int mouse_timed_out = TRUE; | |
1492 | |
1493 /* | |
1494 * Timer used to recognize multiple clicks of the mouse button | |
1495 */ | |
1496 static gint | |
1497 mouse_click_timer_cb(gpointer data) | |
1498 { | |
1499 /* we don't use this information currently */ | |
1500 int *timed_out = (int *) data; | |
1501 | |
1502 *timed_out = TRUE; | |
1503 return FALSE; /* don't happen again */ | |
1504 } | |
1505 | |
1506 static guint motion_repeat_timer = 0; | |
1507 static int motion_repeat_offset = FALSE; | |
1508 static gint motion_repeat_timer_cb(gpointer); | |
1509 | |
1510 static void | |
1511 process_motion_notify(int x, int y, GdkModifierType state) | |
1512 { | |
1513 int button; | |
1514 int_u vim_modifiers; | |
1515 | |
1516 button = (state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | | |
1517 GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | | |
1518 GDK_BUTTON5_MASK)) | |
1519 ? MOUSE_DRAG : ' '; | |
1520 | |
1521 /* If our pointer is currently hidden, then we should show it. */ | |
1522 gui_mch_mousehide(FALSE); | |
1523 | |
1524 /* Just moving the rodent above the drawing area without any button | |
1525 * being pressed. */ | |
1526 if (button != MOUSE_DRAG) | |
1527 { | |
1528 gui_mouse_moved(x, y); | |
1529 return; | |
1530 } | |
1531 | |
1532 /* translate modifier coding between the main engine and GTK */ | |
179 | 1533 vim_modifiers = modifiers_gdk2mouse(state); |
7 | 1534 |
1226 | 1535 /* inform the editor engine about the occurrence of this event */ |
7 | 1536 gui_send_mouse_event(button, x, y, FALSE, vim_modifiers); |
1537 | |
1538 /* | |
1539 * Auto repeat timer handling. | |
1540 */ | |
1541 if (x < 0 || y < 0 | |
1542 || x >= gui.drawarea->allocation.width | |
1543 || y >= gui.drawarea->allocation.height) | |
1544 { | |
1545 | |
1546 int dx; | |
1547 int dy; | |
1548 int offshoot; | |
1549 int delay = 10; | |
1550 | |
1551 /* Calculate the maximal distance of the cursor from the drawing area. | |
1552 * (offshoot can't become negative here!). | |
1553 */ | |
1554 dx = x < 0 ? -x : x - gui.drawarea->allocation.width; | |
1555 dy = y < 0 ? -y : y - gui.drawarea->allocation.height; | |
1556 | |
1557 offshoot = dx > dy ? dx : dy; | |
1558 | |
1884 | 1559 /* Make a linearly decaying timer delay with a threshold of 5 at a |
7 | 1560 * distance of 127 pixels from the main window. |
1561 * | |
1562 * One could think endlessly about the most ergonomic variant here. | |
1563 * For example it could make sense to calculate the distance from the | |
1564 * drags start instead... | |
1565 * | |
1566 * Maybe a parabolic interpolation would suite us better here too... | |
1567 */ | |
1568 if (offshoot > 127) | |
1569 { | |
1570 /* 5 appears to be somehow near to my perceptual limits :-). */ | |
1571 delay = 5; | |
1572 } | |
1573 else | |
1574 { | |
1575 delay = (130 * (127 - offshoot)) / 127 + 5; | |
1576 } | |
1577 | |
1578 /* shoot again */ | |
1579 if (!motion_repeat_timer) | |
1580 motion_repeat_timer = gtk_timeout_add((guint32)delay, | |
1581 motion_repeat_timer_cb, NULL); | |
1582 } | |
1583 } | |
1584 | |
1585 /* | |
1586 * Timer used to recognize multiple clicks of the mouse button. | |
1587 */ | |
1588 static gint | |
1884 | 1589 motion_repeat_timer_cb(gpointer data UNUSED) |
7 | 1590 { |
1591 int x; | |
1592 int y; | |
1593 GdkModifierType state; | |
1594 | |
1595 gdk_window_get_pointer(gui.drawarea->window, &x, &y, &state); | |
1596 | |
1597 if (!(state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | | |
1598 GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | | |
1599 GDK_BUTTON5_MASK))) | |
1600 { | |
1601 motion_repeat_timer = 0; | |
1602 return FALSE; | |
1603 } | |
1604 | |
1605 /* If there already is a mouse click in the input buffer, wait another | |
1606 * time (otherwise we would create a backlog of clicks) */ | |
1607 if (vim_used_in_input_buf() > 10) | |
1608 return TRUE; | |
1609 | |
1610 motion_repeat_timer = 0; | |
1611 | |
1612 /* | |
1613 * Fake a motion event. | |
1614 * Trick: Pretend the mouse moved to the next character on every other | |
1615 * event, otherwise drag events will be discarded, because they are still | |
1616 * in the same character. | |
1617 */ | |
1618 if (motion_repeat_offset) | |
1619 x += gui.char_width; | |
1620 | |
1621 motion_repeat_offset = !motion_repeat_offset; | |
1622 process_motion_notify(x, y, state); | |
1623 | |
1624 /* Don't happen again. We will get reinstalled in the synthetic event | |
1625 * if needed -- thus repeating should still work. */ | |
1626 return FALSE; | |
1627 } | |
1628 | |
1629 static gint | |
1884 | 1630 motion_notify_event(GtkWidget *widget, |
1631 GdkEventMotion *event, | |
1632 gpointer data UNUSED) | |
7 | 1633 { |
1634 if (event->is_hint) | |
1635 { | |
1636 int x; | |
1637 int y; | |
1638 GdkModifierType state; | |
1639 | |
1640 gdk_window_get_pointer(widget->window, &x, &y, &state); | |
1641 process_motion_notify(x, y, state); | |
1642 } | |
1643 else | |
1644 { | |
1645 process_motion_notify((int)event->x, (int)event->y, | |
1646 (GdkModifierType)event->state); | |
1647 } | |
1648 | |
1649 return TRUE; /* handled */ | |
1650 } | |
1651 | |
1652 | |
1653 /* | |
1654 * Mouse button handling. Note please that we are capturing multiple click's | |
1655 * by our own timeout mechanism instead of the one provided by GTK+ itself. | |
1656 * This is due to the way the generic VIM code is recognizing multiple clicks. | |
1657 */ | |
1658 static gint | |
1884 | 1659 button_press_event(GtkWidget *widget, |
1660 GdkEventButton *event, | |
1661 gpointer data UNUSED) | |
7 | 1662 { |
1663 int button; | |
1664 int repeated_click = FALSE; | |
1665 int x, y; | |
1666 int_u vim_modifiers; | |
1667 | |
2923 | 1668 gui.event_time = event->time; |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2254
diff
changeset
|
1669 |
7 | 1670 /* Make sure we have focus now we've been selected */ |
1671 if (gtk_socket_id != 0 && !GTK_WIDGET_HAS_FOCUS(widget)) | |
1672 gtk_widget_grab_focus(widget); | |
1673 | |
1674 /* | |
1675 * Don't let additional events about multiple clicks send by GTK to us | |
1676 * after the initial button press event confuse us. | |
1677 */ | |
1678 if (event->type != GDK_BUTTON_PRESS) | |
1679 return FALSE; | |
1680 | |
1681 x = event->x; | |
1682 y = event->y; | |
1683 | |
1684 /* Handle multiple clicks */ | |
1685 if (!mouse_timed_out && mouse_click_timer) | |
1686 { | |
1687 gtk_timeout_remove(mouse_click_timer); | |
1688 mouse_click_timer = 0; | |
1689 repeated_click = TRUE; | |
1690 } | |
1691 | |
1692 mouse_timed_out = FALSE; | |
1693 mouse_click_timer = gtk_timeout_add((guint32)p_mouset, | |
1694 mouse_click_timer_cb, &mouse_timed_out); | |
1695 | |
1696 switch (event->button) | |
1697 { | |
7260
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1698 /* Keep in sync with gui_x11.c. |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1699 * Buttons 4-7 are handled in scroll_event() */ |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1700 case 1: button = MOUSE_LEFT; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1701 case 2: button = MOUSE_MIDDLE; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1702 case 3: button = MOUSE_RIGHT; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1703 case 8: button = MOUSE_X1; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1704 case 9: button = MOUSE_X2; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1705 default: |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1706 return FALSE; /* Unknown button */ |
7 | 1707 } |
1708 | |
1709 #ifdef FEAT_XIM | |
1710 /* cancel any preediting */ | |
1711 if (im_is_preediting()) | |
1712 xim_reset(); | |
1713 #endif | |
1714 | |
179 | 1715 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 1716 |
1717 gui_send_mouse_event(button, x, y, repeated_click, vim_modifiers); | |
1718 | |
1719 return TRUE; | |
1720 } | |
1721 | |
1722 /* | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1723 * GTK+ 2 abstracts scrolling via the GdkEventScroll. |
7 | 1724 */ |
1725 static gboolean | |
1884 | 1726 scroll_event(GtkWidget *widget, |
1727 GdkEventScroll *event, | |
1728 gpointer data UNUSED) | |
7 | 1729 { |
1730 int button; | |
179 | 1731 int_u vim_modifiers; |
7 | 1732 |
1733 if (gtk_socket_id != 0 && !GTK_WIDGET_HAS_FOCUS(widget)) | |
1734 gtk_widget_grab_focus(widget); | |
1735 | |
1736 switch (event->direction) | |
1737 { | |
1738 case GDK_SCROLL_UP: | |
1739 button = MOUSE_4; | |
1740 break; | |
1741 case GDK_SCROLL_DOWN: | |
1742 button = MOUSE_5; | |
1743 break; | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1744 case GDK_SCROLL_LEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1745 button = MOUSE_7; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1746 break; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1747 case GDK_SCROLL_RIGHT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1748 button = MOUSE_6; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1749 break; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1750 default: /* This shouldn't happen */ |
7 | 1751 return FALSE; |
1752 } | |
1753 | |
1754 # ifdef FEAT_XIM | |
1755 /* cancel any preediting */ | |
1756 if (im_is_preediting()) | |
1757 xim_reset(); | |
1758 # endif | |
1759 | |
179 | 1760 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 1761 |
1762 gui_send_mouse_event(button, (int)event->x, (int)event->y, | |
1763 FALSE, vim_modifiers); | |
1764 | |
1765 return TRUE; | |
1766 } | |
1767 | |
1768 | |
1769 static gint | |
1884 | 1770 button_release_event(GtkWidget *widget UNUSED, |
1771 GdkEventButton *event, | |
1772 gpointer data UNUSED) | |
7 | 1773 { |
1774 int x, y; | |
1775 int_u vim_modifiers; | |
1776 | |
2923 | 1777 gui.event_time = event->time; |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2254
diff
changeset
|
1778 |
7 | 1779 /* Remove any motion "machine gun" timers used for automatic further |
1780 extension of allocation areas if outside of the applications window | |
1781 area .*/ | |
1782 if (motion_repeat_timer) | |
1783 { | |
1784 gtk_timeout_remove(motion_repeat_timer); | |
1785 motion_repeat_timer = 0; | |
1786 } | |
1787 | |
1788 x = event->x; | |
1789 y = event->y; | |
1790 | |
179 | 1791 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 1792 |
1793 gui_send_mouse_event(MOUSE_RELEASE, x, y, FALSE, vim_modifiers); | |
1794 | |
1795 return TRUE; | |
1796 } | |
1797 | |
1798 | |
1799 #ifdef FEAT_DND | |
1800 /**************************************************************************** | |
1801 * Drag aNd Drop support handlers. | |
1802 */ | |
1803 | |
1804 /* | |
1805 * Count how many items there may be and separate them with a NUL. | |
1806 * Apparently the items are separated with \r\n. This is not documented, | |
1807 * thus be careful not to go past the end. Also allow separation with | |
1808 * NUL characters. | |
1809 */ | |
1810 static int | |
1811 count_and_decode_uri_list(char_u *out, char_u *raw, int len) | |
1812 { | |
1813 int i; | |
1814 char_u *p = out; | |
1815 int count = 0; | |
1816 | |
1817 for (i = 0; i < len; ++i) | |
1818 { | |
1819 if (raw[i] == NUL || raw[i] == '\n' || raw[i] == '\r') | |
1820 { | |
1821 if (p > out && p[-1] != NUL) | |
1822 { | |
1823 ++count; | |
1824 *p++ = NUL; | |
1825 } | |
1826 } | |
1827 else if (raw[i] == '%' && i + 2 < len && hexhex2nr(raw + i + 1) > 0) | |
1828 { | |
1829 *p++ = hexhex2nr(raw + i + 1); | |
1830 i += 2; | |
1831 } | |
1832 else | |
1833 *p++ = raw[i]; | |
1834 } | |
1835 if (p > out && p[-1] != NUL) | |
1836 { | |
1837 *p = NUL; /* last item didn't have \r or \n */ | |
1838 ++count; | |
1839 } | |
1840 return count; | |
1841 } | |
1842 | |
1843 /* | |
1844 * Parse NUL separated "src" strings. Make it an array "outlist" form. On | |
1845 * this process, URI which protocol is not "file:" are removed. Return | |
1846 * length of array (less than "max"). | |
1847 */ | |
1848 static int | |
1849 filter_uri_list(char_u **outlist, int max, char_u *src) | |
1850 { | |
1851 int i, j; | |
1852 | |
1853 for (i = j = 0; i < max; ++i) | |
1854 { | |
1855 outlist[i] = NULL; | |
1856 if (STRNCMP(src, "file:", 5) == 0) | |
1857 { | |
1858 src += 5; | |
1859 if (STRNCMP(src, "//localhost", 11) == 0) | |
1860 src += 11; | |
1861 while (src[0] == '/' && src[1] == '/') | |
1862 ++src; | |
1863 outlist[j++] = vim_strsave(src); | |
1864 } | |
1865 src += STRLEN(src) + 1; | |
1866 } | |
1867 return j; | |
1868 } | |
1869 | |
1870 static char_u ** | |
1871 parse_uri_list(int *count, char_u *data, int len) | |
1872 { | |
1873 int n = 0; | |
1874 char_u *tmp = NULL; | |
1875 char_u **array = NULL;; | |
1876 | |
1877 if (data != NULL && len > 0 && (tmp = (char_u *)alloc(len + 1)) != NULL) | |
1878 { | |
1879 n = count_and_decode_uri_list(tmp, data, len); | |
1880 if (n > 0 && (array = (char_u **)alloc(n * sizeof(char_u *))) != NULL) | |
1881 n = filter_uri_list(array, n, tmp); | |
1882 } | |
1883 vim_free(tmp); | |
1884 *count = n; | |
1885 return array; | |
1886 } | |
1887 | |
1888 static void | |
1889 drag_handle_uri_list(GdkDragContext *context, | |
1890 GtkSelectionData *data, | |
1891 guint time_, | |
1892 GdkModifierType state, | |
1893 gint x, | |
1894 gint y) | |
1895 { | |
1896 char_u **fnames; | |
1897 int nfiles = 0; | |
1898 | |
1899 fnames = parse_uri_list(&nfiles, data->data, data->length); | |
1900 | |
1901 if (fnames != NULL && nfiles > 0) | |
1902 { | |
179 | 1903 int_u modifiers; |
7 | 1904 |
1905 gtk_drag_finish(context, TRUE, FALSE, time_); /* accept */ | |
1906 | |
179 | 1907 modifiers = modifiers_gdk2mouse(state); |
7 | 1908 |
1909 gui_handle_drop(x, y, modifiers, fnames, nfiles); | |
1910 } | |
840 | 1911 else |
1912 vim_free(fnames); | |
7 | 1913 } |
1914 | |
1915 static void | |
1916 drag_handle_text(GdkDragContext *context, | |
1917 GtkSelectionData *data, | |
1918 guint time_, | |
1919 GdkModifierType state) | |
1920 { | |
1921 char_u dropkey[6] = {CSI, KS_MODIFIER, 0, CSI, KS_EXTRA, (char_u)KE_DROP}; | |
1922 char_u *text; | |
1923 int len; | |
1924 char_u *tmpbuf = NULL; | |
1925 | |
1926 text = data->data; | |
1927 len = data->length; | |
1928 | |
1929 if (data->type == utf8_string_atom) | |
1930 { | |
1931 if (input_conv.vc_type != CONV_NONE) | |
1932 tmpbuf = string_convert(&input_conv, text, &len); | |
1933 if (tmpbuf != NULL) | |
1934 text = tmpbuf; | |
1935 } | |
1936 | |
1937 dnd_yank_drag_data(text, (long)len); | |
1938 gtk_drag_finish(context, TRUE, FALSE, time_); /* accept */ | |
1939 vim_free(tmpbuf); | |
1940 | |
179 | 1941 dropkey[2] = modifiers_gdk2vim(state); |
7 | 1942 |
1943 if (dropkey[2] != 0) | |
1944 add_to_input_buf(dropkey, (int)sizeof(dropkey)); | |
1945 else | |
1946 add_to_input_buf(dropkey + 3, (int)(sizeof(dropkey) - 3)); | |
1947 } | |
1948 | |
1949 /* | |
1950 * DND receiver. | |
1951 */ | |
1952 static void | |
1953 drag_data_received_cb(GtkWidget *widget, | |
1954 GdkDragContext *context, | |
1955 gint x, | |
1956 gint y, | |
1957 GtkSelectionData *data, | |
1958 guint info, | |
1959 guint time_, | |
1884 | 1960 gpointer user_data UNUSED) |
7 | 1961 { |
1962 GdkModifierType state; | |
1963 | |
1964 /* Guard against trash */ | |
1965 if (data->data == NULL | |
1966 || data->length <= 0 | |
1967 || data->format != 8 | |
1968 || data->data[data->length] != '\0') | |
1969 { | |
1970 gtk_drag_finish(context, FALSE, FALSE, time_); | |
1971 return; | |
1972 } | |
1973 | |
1974 /* Get the current modifier state for proper distinguishment between | |
1975 * different operations later. */ | |
1976 gdk_window_get_pointer(widget->window, NULL, NULL, &state); | |
1977 | |
1978 /* Not sure about the role of "text/plain" here... */ | |
1979 if (info == (guint)TARGET_TEXT_URI_LIST) | |
1980 drag_handle_uri_list(context, data, time_, state, x, y); | |
1981 else | |
1982 drag_handle_text(context, data, time_, state); | |
1983 | |
1984 } | |
1985 #endif /* FEAT_DND */ | |
1986 | |
1987 | |
1988 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
1989 /* | |
1990 * GnomeClient interact callback. Check for unsaved buffers that cannot | |
1991 * be abandoned and pop up a dialog asking the user for confirmation if | |
1992 * necessary. | |
1993 */ | |
1994 static void | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1995 sm_client_check_changed_any(GnomeClient *client UNUSED, |
7 | 1996 gint key, |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1997 GnomeDialogType type UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1998 gpointer data UNUSED) |
7 | 1999 { |
2000 cmdmod_T save_cmdmod; | |
2001 gboolean shutdown_cancelled; | |
2002 | |
2003 save_cmdmod = cmdmod; | |
2004 | |
2005 # ifdef FEAT_BROWSE | |
2006 cmdmod.browse = TRUE; | |
2007 # endif | |
2008 # if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
2009 cmdmod.confirm = TRUE; | |
2010 # endif | |
2011 /* | |
2012 * If there are changed buffers, present the user with | |
2013 * a dialog if possible, otherwise give an error message. | |
2014 */ | |
7469
15eefe1b0dad
commit https://github.com/vim/vim/commit/027387f70c671f62e3e08e0bdd09ec05b0232735
Christian Brabandt <cb@256bit.org>
parents:
7380
diff
changeset
|
2015 shutdown_cancelled = check_changed_any(FALSE, FALSE); |
7 | 2016 |
2017 exiting = FALSE; | |
2018 cmdmod = save_cmdmod; | |
2019 setcursor(); /* position the cursor */ | |
2020 out_flush(); | |
2021 /* | |
2022 * If the user hit the [Cancel] button the whole shutdown | |
2023 * will be cancelled. Wow, quite powerful feature (: | |
2024 */ | |
2025 gnome_interaction_key_return(key, shutdown_cancelled); | |
2026 } | |
2027 | |
2028 /* | |
2029 * Generate a script that can be used to restore the current editing session. | |
2030 * Save the value of v:this_session before running :mksession in order to make | |
2031 * automagic session save fully transparent. Return TRUE on success. | |
2032 */ | |
2033 static int | |
2034 write_session_file(char_u *filename) | |
2035 { | |
2036 char_u *escaped_filename; | |
2037 char *mksession_cmdline; | |
2038 unsigned int save_ssop_flags; | |
2039 int failed; | |
2040 | |
2041 /* | |
2042 * Build an ex command line to create a script that restores the current | |
2043 * session if executed. Escape the filename to avoid nasty surprises. | |
2044 */ | |
2045 escaped_filename = vim_strsave_escaped(filename, escape_chars); | |
2046 if (escaped_filename == NULL) | |
2047 return FALSE; | |
1296 | 2048 mksession_cmdline = g_strconcat("mksession ", (char *)escaped_filename, |
2049 NULL); | |
7 | 2050 vim_free(escaped_filename); |
1296 | 2051 |
7 | 2052 /* |
2053 * Use a reasonable hardcoded set of 'sessionoptions' flags to avoid | |
2054 * unpredictable effects when the session is saved automatically. Also, | |
2055 * we definitely need SSOP_GLOBALS to be able to restore v:this_session. | |
2056 * Don't use SSOP_BUFFERS to prevent the buffer list from becoming | |
2057 * enormously large if the GNOME session feature is used regularly. | |
2058 */ | |
2059 save_ssop_flags = ssop_flags; | |
2060 ssop_flags = (SSOP_BLANK|SSOP_CURDIR|SSOP_FOLDS|SSOP_GLOBALS | |
1296 | 2061 |SSOP_HELP|SSOP_OPTIONS|SSOP_WINSIZE|SSOP_TABPAGES); |
7 | 2062 |
2063 do_cmdline_cmd((char_u *)"let Save_VV_this_session = v:this_session"); | |
2064 failed = (do_cmdline_cmd((char_u *)mksession_cmdline) == FAIL); | |
2065 do_cmdline_cmd((char_u *)"let v:this_session = Save_VV_this_session"); | |
150 | 2066 do_unlet((char_u *)"Save_VV_this_session", TRUE); |
7 | 2067 |
2068 ssop_flags = save_ssop_flags; | |
2069 g_free(mksession_cmdline); | |
5905 | 2070 |
7 | 2071 /* |
2072 * Reopen the file and append a command to restore v:this_session, | |
2073 * as if this save never happened. This is to avoid conflicts with | |
2074 * the user's own sessions. FIXME: It's probably less hackish to add | |
2075 * a "stealth" flag to 'sessionoptions' -- gotta ask Bram. | |
2076 */ | |
2077 if (!failed) | |
2078 { | |
2079 FILE *fd; | |
2080 | |
2081 fd = open_exfile(filename, TRUE, APPENDBIN); | |
2082 | |
2083 failed = (fd == NULL | |
2084 || put_line(fd, "let v:this_session = Save_VV_this_session") == FAIL | |
2085 || put_line(fd, "unlet Save_VV_this_session") == FAIL); | |
2086 | |
2087 if (fd != NULL && fclose(fd) != 0) | |
2088 failed = TRUE; | |
2089 | |
2090 if (failed) | |
2091 mch_remove(filename); | |
2092 } | |
2093 | |
2094 return !failed; | |
2095 } | |
2096 | |
2097 /* | |
2098 * "save_yourself" signal handler. Initiate an interaction to ask the user | |
2099 * for confirmation if necessary. Save the current editing session and tell | |
2100 * the session manager how to restart Vim. | |
2101 */ | |
2102 static gboolean | |
2103 sm_client_save_yourself(GnomeClient *client, | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2104 gint phase UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2105 GnomeSaveStyle save_style UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2106 gboolean shutdown UNUSED, |
7 | 2107 GnomeInteractStyle interact_style, |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2108 gboolean fast UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2109 gpointer data UNUSED) |
7 | 2110 { |
2111 static const char suffix[] = "-session.vim"; | |
2112 char *session_file; | |
2113 unsigned int len; | |
2114 gboolean success; | |
2115 | |
2116 /* Always request an interaction if possible. check_changed_any() | |
2117 * won't actually show a dialog unless any buffers have been modified. | |
2118 * There doesn't seem to be an obvious way to check that without | |
2119 * automatically firing the dialog. Anyway, it works just fine. */ | |
2120 if (interact_style == GNOME_INTERACT_ANY) | |
2121 gnome_client_request_interaction(client, GNOME_DIALOG_NORMAL, | |
2122 &sm_client_check_changed_any, | |
2123 NULL); | |
2124 out_flush(); | |
2125 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
2126 | |
2127 /* The path is unique for each session save. We do neither know nor care | |
2128 * which session script will actually be used later. This decision is in | |
2129 * the domain of the session manager. */ | |
2130 session_file = gnome_config_get_real_path( | |
2131 gnome_client_get_config_prefix(client)); | |
2132 len = strlen(session_file); | |
2133 | |
2134 if (len > 0 && session_file[len-1] == G_DIR_SEPARATOR) | |
2135 --len; /* get rid of the superfluous trailing '/' */ | |
2136 | |
2137 session_file = g_renew(char, session_file, len + sizeof(suffix)); | |
2138 memcpy(session_file + len, suffix, sizeof(suffix)); | |
2139 | |
2140 success = write_session_file((char_u *)session_file); | |
2141 | |
2142 if (success) | |
2143 { | |
2144 const char *argv[8]; | |
2145 int i; | |
2146 | |
2147 /* Tell the session manager how to wipe out the stored session data. | |
2148 * This isn't as dangerous as it looks, don't worry :) session_file | |
2149 * is a unique absolute filename. Usually it'll be something like | |
2150 * `/home/user/.gnome2/vim-XXXXXX-session.vim'. */ | |
2151 i = 0; | |
2152 argv[i++] = "rm"; | |
2153 argv[i++] = session_file; | |
2154 argv[i] = NULL; | |
2155 | |
2156 gnome_client_set_discard_command(client, i, (char **)argv); | |
2157 | |
2158 /* Tell the session manager how to restore the just saved session. | |
2159 * This is easily done thanks to Vim's -S option. Pass the -f flag | |
2160 * since there's no need to fork -- it might even cause confusion. | |
2161 * Also pass the window role to give the WM something to match on. | |
2162 * The role is set in gui_mch_open(), thus should _never_ be NULL. */ | |
2163 i = 0; | |
2164 argv[i++] = restart_command; | |
2165 argv[i++] = "-f"; | |
2166 argv[i++] = "-g"; | |
2167 argv[i++] = "--role"; | |
2168 argv[i++] = gtk_window_get_role(GTK_WINDOW(gui.mainwin)); | |
2169 argv[i++] = "-S"; | |
2170 argv[i++] = session_file; | |
2171 argv[i] = NULL; | |
2172 | |
2173 gnome_client_set_restart_command(client, i, (char **)argv); | |
2174 gnome_client_set_clone_command(client, 0, NULL); | |
2175 } | |
2176 | |
2177 g_free(session_file); | |
2178 | |
2179 return success; | |
2180 } | |
2181 | |
2182 /* | |
2183 * Called when the session manager wants us to die. There isn't much to save | |
2184 * here since "save_yourself" has been emitted before (unless serious trouble | |
2185 * is happening). | |
2186 */ | |
2187 static void | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2188 sm_client_die(GnomeClient *client UNUSED, gpointer data UNUSED) |
7 | 2189 { |
2190 /* Don't write messages to the GUI anymore */ | |
2191 full_screen = FALSE; | |
2192 | |
1666 | 2193 vim_strncpy(IObuff, (char_u *) |
419 | 2194 _("Vim: Received \"die\" request from session manager\n"), |
1666 | 2195 IOSIZE - 1); |
7 | 2196 preserve_exit(); |
2197 } | |
2198 | |
2199 /* | |
2200 * Connect our signal handlers to be notified on session save and shutdown. | |
2201 */ | |
2202 static void | |
2203 setup_save_yourself(void) | |
2204 { | |
2205 GnomeClient *client; | |
2206 | |
2207 client = gnome_master_client(); | |
2208 | |
2209 if (client != NULL) | |
2210 { | |
2211 /* Must use the deprecated gtk_signal_connect() for compatibility | |
2212 * with GNOME 1. Arrgh, zombies! */ | |
2213 gtk_signal_connect(GTK_OBJECT(client), "save_yourself", | |
2214 GTK_SIGNAL_FUNC(&sm_client_save_yourself), NULL); | |
2215 gtk_signal_connect(GTK_OBJECT(client), "die", | |
2216 GTK_SIGNAL_FUNC(&sm_client_die), NULL); | |
2217 } | |
2218 } | |
2219 | |
2220 #else /* !(FEAT_GUI_GNOME && FEAT_SESSION) */ | |
2221 | |
2222 # ifdef USE_XSMP | |
2223 /* | |
2224 * GTK tells us that XSMP needs attention | |
2225 */ | |
2226 static gboolean | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2227 local_xsmp_handle_requests( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2228 GIOChannel *source UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2229 GIOCondition condition, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2230 gpointer data) |
7 | 2231 { |
2232 if (condition == G_IO_IN) | |
2233 { | |
2234 /* Do stuff; maybe close connection */ | |
2235 if (xsmp_handle_requests() == FAIL) | |
2236 g_io_channel_unref((GIOChannel *)data); | |
2237 return TRUE; | |
2238 } | |
2239 /* Error */ | |
2240 g_io_channel_unref((GIOChannel *)data); | |
2241 xsmp_close(); | |
2242 return TRUE; | |
2243 } | |
2244 # endif /* USE_XSMP */ | |
2245 | |
2246 /* | |
2247 * Setup the WM_PROTOCOLS to indicate we want the WM_SAVE_YOURSELF event. | |
2248 * This is an ugly use of X functions. GTK doesn't offer an alternative. | |
2249 */ | |
2250 static void | |
2251 setup_save_yourself(void) | |
2252 { | |
2253 Atom *existing_atoms = NULL; | |
2254 int count = 0; | |
2255 | |
2256 #ifdef USE_XSMP | |
2257 if (xsmp_icefd != -1) | |
2258 { | |
2259 /* | |
2260 * Use XSMP is preference to legacy WM_SAVE_YOURSELF; | |
2261 * set up GTK IO monitor | |
2262 */ | |
2263 GIOChannel *g_io = g_io_channel_unix_new(xsmp_icefd); | |
2264 | |
2265 g_io_add_watch(g_io, G_IO_IN | G_IO_ERR | G_IO_HUP, | |
2266 local_xsmp_handle_requests, (gpointer)g_io); | |
2267 } | |
2268 else | |
2269 #endif | |
2270 { | |
2271 /* Fall back to old method */ | |
2272 | |
2273 /* first get the existing value */ | |
2274 if (XGetWMProtocols(GDK_WINDOW_XDISPLAY(gui.mainwin->window), | |
2275 GDK_WINDOW_XWINDOW(gui.mainwin->window), | |
2276 &existing_atoms, &count)) | |
2277 { | |
2278 Atom *new_atoms; | |
2279 Atom save_yourself_xatom; | |
2280 int i; | |
2281 | |
2282 save_yourself_xatom = GET_X_ATOM(save_yourself_atom); | |
2283 | |
2284 /* check if WM_SAVE_YOURSELF isn't there yet */ | |
2285 for (i = 0; i < count; ++i) | |
2286 if (existing_atoms[i] == save_yourself_xatom) | |
2287 break; | |
2288 | |
2289 if (i == count) | |
2290 { | |
2291 /* allocate an Atoms array which is one item longer */ | |
2292 new_atoms = (Atom *)alloc((unsigned)((count + 1) | |
2293 * sizeof(Atom))); | |
2294 if (new_atoms != NULL) | |
2295 { | |
2296 memcpy(new_atoms, existing_atoms, count * sizeof(Atom)); | |
2297 new_atoms[count] = save_yourself_xatom; | |
2298 XSetWMProtocols(GDK_WINDOW_XDISPLAY(gui.mainwin->window), | |
2299 GDK_WINDOW_XWINDOW(gui.mainwin->window), | |
2300 new_atoms, count + 1); | |
2301 vim_free(new_atoms); | |
2302 } | |
2303 } | |
2304 XFree(existing_atoms); | |
2305 } | |
2306 } | |
2307 } | |
2308 | |
2309 /* | |
2310 * Installing a global event filter seems to be the only way to catch | |
2311 * client messages of type WM_PROTOCOLS without overriding GDK's own | |
2312 * client message event filter. Well, that's still better than trying | |
2313 * to guess what the GDK filter had done if it had been invoked instead | |
2314 * | |
2315 * GTK2_FIXME: This doesn't seem to work. For some reason we never | |
2316 * receive WM_SAVE_YOURSELF even though everything is set up correctly. | |
2317 * I have the nasty feeling modern session managers just don't send this | |
2318 * deprecated message anymore. Addition: confirmed by several people. | |
2319 * | |
2320 * The GNOME session support is much cooler anyway. Unlike this ugly | |
2321 * WM_SAVE_YOURSELF hack it actually stores the session... And yes, | |
2322 * it should work with KDE as well. | |
2323 */ | |
2324 static GdkFilterReturn | |
1884 | 2325 global_event_filter(GdkXEvent *xev, |
2326 GdkEvent *event UNUSED, | |
2327 gpointer data UNUSED) | |
7 | 2328 { |
2329 XEvent *xevent = (XEvent *)xev; | |
2330 | |
2331 if (xevent != NULL | |
2332 && xevent->type == ClientMessage | |
2333 && xevent->xclient.message_type == GET_X_ATOM(wm_protocols_atom) | |
1884 | 2334 && (long_u)xevent->xclient.data.l[0] |
2335 == GET_X_ATOM(save_yourself_atom)) | |
7 | 2336 { |
2337 out_flush(); | |
2338 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
2339 /* | |
2340 * Set the window's WM_COMMAND property, to let the window manager | |
2341 * know we are done saving ourselves. We don't want to be | |
2342 * restarted, thus set argv to NULL. | |
2343 */ | |
2344 XSetCommand(GDK_WINDOW_XDISPLAY(gui.mainwin->window), | |
2345 GDK_WINDOW_XWINDOW(gui.mainwin->window), | |
2346 NULL, 0); | |
2347 return GDK_FILTER_REMOVE; | |
2348 } | |
2349 | |
2350 return GDK_FILTER_CONTINUE; | |
2351 } | |
2352 #endif /* !(FEAT_GUI_GNOME && FEAT_SESSION) */ | |
2353 | |
2354 | |
2355 /* | |
2356 * Setup the window icon & xcmdsrv comm after the main window has been realized. | |
2357 */ | |
2358 static void | |
1884 | 2359 mainwin_realize(GtkWidget *widget UNUSED, gpointer data UNUSED) |
7 | 2360 { |
2361 /* If you get an error message here, you still need to unpack the runtime | |
2362 * archive! */ | |
2363 #ifdef magick | |
2364 # undef magick | |
2365 #endif | |
2366 /* A bit hackish, but avoids casting later and allows optimization */ | |
2367 # define static static const | |
2368 #define magick vim32x32 | |
2369 #include "../runtime/vim32x32.xpm" | |
2370 #undef magick | |
2371 #define magick vim16x16 | |
2372 #include "../runtime/vim16x16.xpm" | |
2373 #undef magick | |
2374 #define magick vim48x48 | |
2375 #include "../runtime/vim48x48.xpm" | |
2376 #undef magick | |
2377 # undef static | |
2378 | |
2379 /* When started with "--echo-wid" argument, write window ID on stdout. */ | |
2380 if (echo_wid_arg) | |
2381 { | |
2382 printf("WID: %ld\n", (long)GDK_WINDOW_XWINDOW(gui.mainwin->window)); | |
2383 fflush(stdout); | |
2384 } | |
2385 | |
2386 if (vim_strchr(p_go, GO_ICON) != NULL) | |
2387 { | |
2388 /* | |
2389 * Add an icon to the main window. For fun and convenience of the user. | |
2390 */ | |
2391 GList *icons = NULL; | |
2392 | |
2393 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim16x16)); | |
2394 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim32x32)); | |
2395 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim48x48)); | |
2396 | |
2397 gtk_window_set_icon_list(GTK_WINDOW(gui.mainwin), icons); | |
2398 | |
2399 g_list_foreach(icons, (GFunc)&g_object_unref, NULL); | |
2400 g_list_free(icons); | |
2401 } | |
2402 | |
2403 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
2404 /* Register a handler for WM_SAVE_YOURSELF with GDK's low-level X I/F */ | |
2405 gdk_window_add_filter(NULL, &global_event_filter, NULL); | |
2406 #endif | |
2407 /* Setup to indicate to the window manager that we want to catch the | |
2408 * WM_SAVE_YOURSELF event. For GNOME, this connects to the session | |
2409 * manager instead. */ | |
2410 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
2411 if (using_gnome) | |
2412 #endif | |
2413 setup_save_yourself(); | |
2414 | |
2415 #ifdef FEAT_CLIENTSERVER | |
2416 if (serverName == NULL && serverDelayedStartName != NULL) | |
2417 { | |
2418 /* This is a :gui command in a plain vim with no previous server */ | |
2419 commWindow = GDK_WINDOW_XWINDOW(gui.mainwin->window); | |
2420 | |
2421 (void)serverRegisterName(GDK_WINDOW_XDISPLAY(gui.mainwin->window), | |
2422 serverDelayedStartName); | |
2423 } | |
2424 else | |
2425 { | |
2426 /* | |
2427 * Cannot handle "XLib-only" windows with gtk event routines, we'll | |
2428 * have to change the "server" registration to that of the main window | |
2429 * If we have not registered a name yet, remember the window | |
2430 */ | |
2431 serverChangeRegisteredWindow(GDK_WINDOW_XDISPLAY(gui.mainwin->window), | |
2432 GDK_WINDOW_XWINDOW(gui.mainwin->window)); | |
2433 } | |
2434 gtk_widget_add_events(gui.mainwin, GDK_PROPERTY_CHANGE_MASK); | |
2435 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "property_notify_event", | |
2436 GTK_SIGNAL_FUNC(property_event), NULL); | |
2437 #endif | |
2438 } | |
2439 | |
2440 static GdkCursor * | |
2441 create_blank_pointer(void) | |
2442 { | |
2443 GdkWindow *root_window = NULL; | |
2444 GdkPixmap *blank_mask; | |
2445 GdkCursor *cursor; | |
2446 GdkColor color = { 0, 0, 0, 0 }; | |
2447 char blank_data[] = { 0x0 }; | |
2448 | |
2449 #ifdef HAVE_GTK_MULTIHEAD | |
2450 root_window = gtk_widget_get_root_window(gui.mainwin); | |
2451 #endif | |
2452 | |
2453 /* Create a pseudo blank pointer, which is in fact one pixel by one pixel | |
2454 * in size. */ | |
2455 blank_mask = gdk_bitmap_create_from_data(root_window, blank_data, 1, 1); | |
2456 cursor = gdk_cursor_new_from_pixmap(blank_mask, blank_mask, | |
2457 &color, &color, 0, 0); | |
2458 gdk_bitmap_unref(blank_mask); | |
2459 | |
2460 return cursor; | |
2461 } | |
2462 | |
2463 #ifdef HAVE_GTK_MULTIHEAD | |
2464 static void | |
2465 mainwin_screen_changed_cb(GtkWidget *widget, | |
1884 | 2466 GdkScreen *previous_screen UNUSED, |
2467 gpointer data UNUSED) | |
7 | 2468 { |
2469 if (!gtk_widget_has_screen(widget)) | |
2470 return; | |
2471 | |
2472 /* | |
1226 | 2473 * Recreate the invisible mouse cursor. |
7 | 2474 */ |
2475 if (gui.blank_pointer != NULL) | |
2476 gdk_cursor_unref(gui.blank_pointer); | |
2477 | |
2478 gui.blank_pointer = create_blank_pointer(); | |
2479 | |
2480 if (gui.pointer_hidden && gui.drawarea->window != NULL) | |
2481 gdk_window_set_cursor(gui.drawarea->window, gui.blank_pointer); | |
2482 | |
2483 /* | |
2484 * Create a new PangoContext for this screen, and initialize it | |
2485 * with the current font if necessary. | |
2486 */ | |
2487 if (gui.text_context != NULL) | |
2488 g_object_unref(gui.text_context); | |
2489 | |
2490 gui.text_context = gtk_widget_create_pango_context(widget); | |
2491 pango_context_set_base_dir(gui.text_context, PANGO_DIRECTION_LTR); | |
2492 | |
2493 if (gui.norm_font != NULL) | |
2494 { | |
38 | 2495 gui_mch_init_font(p_guifont, FALSE); |
814 | 2496 gui_set_shellsize(FALSE, FALSE, RESIZE_BOTH); |
7 | 2497 } |
2498 } | |
2499 #endif /* HAVE_GTK_MULTIHEAD */ | |
2500 | |
2501 /* | |
2502 * After the drawing area comes up, we calculate all colors and create the | |
2503 * dummy blank cursor. | |
2504 * | |
2505 * Don't try to set any VIM scrollbar sizes anywhere here. I'm relying on the | |
2506 * fact that the main VIM engine doesn't take them into account anywhere. | |
2507 */ | |
2508 static void | |
1884 | 2509 drawarea_realize_cb(GtkWidget *widget, gpointer data UNUSED) |
7 | 2510 { |
2511 GtkWidget *sbar; | |
2512 | |
2513 #ifdef FEAT_XIM | |
2514 xim_init(); | |
2515 #endif | |
2516 gui_mch_new_colors(); | |
2517 gui.text_gc = gdk_gc_new(gui.drawarea->window); | |
2518 | |
2519 gui.blank_pointer = create_blank_pointer(); | |
2520 if (gui.pointer_hidden) | |
2521 gdk_window_set_cursor(widget->window, gui.blank_pointer); | |
2522 | |
2523 /* get the actual size of the scrollbars, if they are realized */ | |
2524 sbar = firstwin->w_scrollbars[SBAR_LEFT].id; | |
2525 if (!sbar || (!gui.which_scrollbars[SBAR_LEFT] | |
2526 && firstwin->w_scrollbars[SBAR_RIGHT].id)) | |
2527 sbar = firstwin->w_scrollbars[SBAR_RIGHT].id; | |
2528 if (sbar && GTK_WIDGET_REALIZED(sbar) && sbar->allocation.width) | |
2529 gui.scrollbar_width = sbar->allocation.width; | |
2530 | |
2531 sbar = gui.bottom_sbar.id; | |
2532 if (sbar && GTK_WIDGET_REALIZED(sbar) && sbar->allocation.height) | |
2533 gui.scrollbar_height = sbar->allocation.height; | |
2534 } | |
2535 | |
2536 /* | |
2537 * Properly clean up on shutdown. | |
2538 */ | |
2539 static void | |
1884 | 2540 drawarea_unrealize_cb(GtkWidget *widget UNUSED, gpointer data UNUSED) |
7 | 2541 { |
2542 /* Don't write messages to the GUI anymore */ | |
2543 full_screen = FALSE; | |
2544 | |
2545 #ifdef FEAT_XIM | |
2546 im_shutdown(); | |
2547 #endif | |
2548 if (gui.ascii_glyphs != NULL) | |
2549 { | |
2550 pango_glyph_string_free(gui.ascii_glyphs); | |
2551 gui.ascii_glyphs = NULL; | |
2552 } | |
2553 if (gui.ascii_font != NULL) | |
2554 { | |
2555 g_object_unref(gui.ascii_font); | |
2556 gui.ascii_font = NULL; | |
2557 } | |
2558 g_object_unref(gui.text_context); | |
2559 gui.text_context = NULL; | |
2560 | |
2561 g_object_unref(gui.text_gc); | |
2562 gui.text_gc = NULL; | |
2563 | |
2564 gdk_cursor_unref(gui.blank_pointer); | |
2565 gui.blank_pointer = NULL; | |
2566 } | |
2567 | |
2568 static void | |
1884 | 2569 drawarea_style_set_cb(GtkWidget *widget UNUSED, |
2570 GtkStyle *previous_style UNUSED, | |
2571 gpointer data UNUSED) | |
7 | 2572 { |
2573 gui_mch_new_colors(); | |
2574 } | |
2575 | |
2576 /* | |
2577 * Callback routine for the "delete_event" signal on the toplevel window. | |
2578 * Tries to vim gracefully, or refuses to exit with changed buffers. | |
2579 */ | |
2580 static gint | |
1884 | 2581 delete_event_cb(GtkWidget *widget UNUSED, |
2582 GdkEventAny *event UNUSED, | |
2583 gpointer data UNUSED) | |
7 | 2584 { |
2585 gui_shell_closed(); | |
2586 return TRUE; | |
2587 } | |
2588 | |
685 | 2589 #if defined(FEAT_MENU) || defined(FEAT_TOOLBAR) || defined(FEAT_GUI_TABLINE) |
2590 static int | |
2591 get_item_dimensions(GtkWidget *widget, GtkOrientation orientation) | |
2592 { | |
2593 GtkOrientation item_orientation = GTK_ORIENTATION_HORIZONTAL; | |
2594 | |
2595 #ifdef FEAT_GUI_GNOME | |
2596 if (using_gnome && widget != NULL) | |
2597 { | |
856 | 2598 GtkWidget *parent; |
685 | 2599 BonoboDockItem *dockitem; |
2600 | |
791 | 2601 parent = gtk_widget_get_parent(widget); |
856 | 2602 if (G_TYPE_FROM_INSTANCE(parent) == BONOBO_TYPE_DOCK_ITEM) |
2603 { | |
2604 /* Only menu & toolbar are dock items. Could tabline be? | |
2605 * Seem to be only the 2 defined in GNOME */ | |
2606 widget = parent; | |
2607 dockitem = BONOBO_DOCK_ITEM(widget); | |
2608 | |
2609 if (dockitem == NULL || dockitem->is_floating) | |
2610 return 0; | |
2611 item_orientation = bonobo_dock_item_get_orientation(dockitem); | |
2612 } | |
685 | 2613 } |
2614 #endif | |
2615 if (widget != NULL | |
2616 && item_orientation == orientation | |
2617 && GTK_WIDGET_REALIZED(widget) | |
2618 && GTK_WIDGET_VISIBLE(widget)) | |
2619 { | |
2620 if (orientation == GTK_ORIENTATION_HORIZONTAL) | |
2621 return widget->allocation.height; | |
2622 else | |
2623 return widget->allocation.width; | |
2624 } | |
2625 return 0; | |
2626 } | |
2627 #endif | |
2628 | |
2629 static int | |
2630 get_menu_tool_width(void) | |
2631 { | |
2632 int width = 0; | |
2633 | |
2634 #ifdef FEAT_GUI_GNOME /* these are never vertical without GNOME */ | |
2635 # ifdef FEAT_MENU | |
2636 width += get_item_dimensions(gui.menubar, GTK_ORIENTATION_VERTICAL); | |
2637 # endif | |
2638 # ifdef FEAT_TOOLBAR | |
2639 width += get_item_dimensions(gui.toolbar, GTK_ORIENTATION_VERTICAL); | |
2640 # endif | |
2641 # ifdef FEAT_GUI_TABLINE | |
782 | 2642 if (gui.tabline != NULL) |
2643 width += get_item_dimensions(gui.tabline, GTK_ORIENTATION_VERTICAL); | |
685 | 2644 # endif |
2645 #endif | |
2646 | |
2647 return width; | |
2648 } | |
2649 | |
2650 static int | |
2651 get_menu_tool_height(void) | |
2652 { | |
2653 int height = 0; | |
2654 | |
2655 #ifdef FEAT_MENU | |
2656 height += get_item_dimensions(gui.menubar, GTK_ORIENTATION_HORIZONTAL); | |
2657 #endif | |
2658 #ifdef FEAT_TOOLBAR | |
2659 height += get_item_dimensions(gui.toolbar, GTK_ORIENTATION_HORIZONTAL); | |
2660 #endif | |
2661 #ifdef FEAT_GUI_TABLINE | |
782 | 2662 if (gui.tabline != NULL) |
2663 height += get_item_dimensions(gui.tabline, GTK_ORIENTATION_HORIZONTAL); | |
685 | 2664 #endif |
2665 | |
2666 return height; | |
2667 } | |
2668 | |
791 | 2669 /* This controls whether we can set the real window hints at |
2670 * start-up when in a GtkPlug. | |
2671 * 0 = normal processing (default) | |
2672 * 1 = init. hints set, no-one's tried to reset since last check | |
2673 * 2 = init. hints set, attempt made to change hints | |
2674 */ | |
2675 static int init_window_hints_state = 0; | |
2676 | |
685 | 2677 static void |
791 | 2678 update_window_manager_hints(int force_width, int force_height) |
685 | 2679 { |
2680 static int old_width = 0; | |
2681 static int old_height = 0; | |
791 | 2682 static int old_min_width = 0; |
2683 static int old_min_height = 0; | |
685 | 2684 static int old_char_width = 0; |
2685 static int old_char_height = 0; | |
2686 | |
2687 int width; | |
2688 int height; | |
791 | 2689 int min_width; |
2690 int min_height; | |
2691 | |
2692 /* At start-up, don't try to set the hints until the initial | |
2693 * values have been used (those that dictate our initial size) | |
1884 | 2694 * Let forced (i.e., correct) values through always. |
791 | 2695 */ |
2696 if (!(force_width && force_height) && init_window_hints_state > 0) | |
2697 { | |
856 | 2698 /* Don't do it! */ |
2699 init_window_hints_state = 2; | |
2700 return; | |
791 | 2701 } |
685 | 2702 |
2703 /* This also needs to be done when the main window isn't there yet, | |
2704 * otherwise the hints don't work. */ | |
2705 width = gui_get_base_width(); | |
2706 height = gui_get_base_height(); | |
2707 # ifdef FEAT_MENU | |
2708 height += tabline_height() * gui.char_height; | |
2709 # endif | |
2710 width += get_menu_tool_width(); | |
2711 height += get_menu_tool_height(); | |
2712 | |
791 | 2713 /* GtkSockets use GtkPlug's [gui,mainwin] min-size hints to determine |
1226 | 2714 * their actual widget size. When we set our size ourselves (e.g., |
791 | 2715 * 'set columns=' or init. -geom) we briefly set the min. to the size |
2716 * we wish to be instead of the legitimate minimum so that we actually | |
2717 * resize correctly. | |
2718 */ | |
2719 if (force_width && force_height) | |
2720 { | |
856 | 2721 min_width = force_width; |
2722 min_height = force_height; | |
791 | 2723 } |
2724 else | |
2725 { | |
856 | 2726 min_width = width + MIN_COLUMNS * gui.char_width; |
2727 min_height = height + MIN_LINES * gui.char_height; | |
791 | 2728 } |
2729 | |
685 | 2730 /* Avoid an expose event when the size didn't change. */ |
2731 if (width != old_width | |
2732 || height != old_height | |
856 | 2733 || min_width != old_min_width |
791 | 2734 || min_height != old_min_height |
685 | 2735 || gui.char_width != old_char_width |
2736 || gui.char_height != old_char_height) | |
2737 { | |
2738 GdkGeometry geometry; | |
2739 GdkWindowHints geometry_mask; | |
2740 | |
2741 geometry.width_inc = gui.char_width; | |
2742 geometry.height_inc = gui.char_height; | |
2743 geometry.base_width = width; | |
2744 geometry.base_height = height; | |
856 | 2745 geometry.min_width = min_width; |
2746 geometry.min_height = min_height; | |
685 | 2747 geometry_mask = GDK_HINT_BASE_SIZE|GDK_HINT_RESIZE_INC |
2748 |GDK_HINT_MIN_SIZE; | |
2749 /* Using gui.formwin as geometry widget doesn't work as expected | |
2750 * with GTK+ 2 -- dunno why. Presumably all the resizing hacks | |
2751 * in Vim confuse GTK+. */ | |
2752 gtk_window_set_geometry_hints(GTK_WINDOW(gui.mainwin), gui.mainwin, | |
2753 &geometry, geometry_mask); | |
856 | 2754 old_width = width; |
2755 old_height = height; | |
2756 old_min_width = min_width; | |
2757 old_min_height = min_height; | |
2758 old_char_width = gui.char_width; | |
2759 old_char_height = gui.char_height; | |
685 | 2760 } |
2761 } | |
2762 | |
7 | 2763 #ifdef FEAT_TOOLBAR |
2764 | |
2765 /* | |
2766 * This extra effort wouldn't be necessary if we only used stock icons in the | |
2767 * toolbar, as we do for all builtin icons. But user-defined toolbar icons | |
2768 * shouldn't be treated differently, thus we do need this. | |
2769 */ | |
2770 static void | |
2771 icon_size_changed_foreach(GtkWidget *widget, gpointer user_data) | |
2772 { | |
2773 if (GTK_IS_IMAGE(widget)) | |
2774 { | |
2775 GtkImage *image = (GtkImage *)widget; | |
2776 | |
2777 /* User-defined icons are stored in a GtkIconSet */ | |
2778 if (gtk_image_get_storage_type(image) == GTK_IMAGE_ICON_SET) | |
2779 { | |
2780 GtkIconSet *icon_set; | |
2781 GtkIconSize icon_size; | |
2782 | |
2783 gtk_image_get_icon_set(image, &icon_set, &icon_size); | |
2784 icon_size = (GtkIconSize)(long)user_data; | |
2785 | |
2786 gtk_icon_set_ref(icon_set); | |
2787 gtk_image_set_from_icon_set(image, icon_set, icon_size); | |
2788 gtk_icon_set_unref(icon_set); | |
2789 } | |
2790 } | |
2791 else if (GTK_IS_CONTAINER(widget)) | |
2792 { | |
2793 gtk_container_foreach((GtkContainer *)widget, | |
2794 &icon_size_changed_foreach, | |
2795 user_data); | |
2796 } | |
2797 } | |
2798 | |
2799 static void | |
2800 set_toolbar_style(GtkToolbar *toolbar) | |
2801 { | |
2802 GtkToolbarStyle style; | |
2803 GtkIconSize size; | |
2804 GtkIconSize oldsize; | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
2805 |
7 | 2806 if ((toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS | TOOLBAR_HORIZ)) |
2807 == (TOOLBAR_TEXT | TOOLBAR_ICONS | TOOLBAR_HORIZ)) | |
2808 style = GTK_TOOLBAR_BOTH_HORIZ; | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
2809 else if ((toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS)) |
7 | 2810 == (TOOLBAR_TEXT | TOOLBAR_ICONS)) |
2811 style = GTK_TOOLBAR_BOTH; | |
2812 else if (toolbar_flags & TOOLBAR_TEXT) | |
2813 style = GTK_TOOLBAR_TEXT; | |
2814 else | |
2815 style = GTK_TOOLBAR_ICONS; | |
2816 | |
2817 gtk_toolbar_set_style(toolbar, style); | |
2818 gtk_toolbar_set_tooltips(toolbar, (toolbar_flags & TOOLBAR_TOOLTIPS) != 0); | |
2819 | |
2820 switch (tbis_flags) | |
2821 { | |
2822 case TBIS_TINY: size = GTK_ICON_SIZE_MENU; break; | |
2823 case TBIS_SMALL: size = GTK_ICON_SIZE_SMALL_TOOLBAR; break; | |
2824 case TBIS_MEDIUM: size = GTK_ICON_SIZE_BUTTON; break; | |
2825 case TBIS_LARGE: size = GTK_ICON_SIZE_LARGE_TOOLBAR; break; | |
2826 default: size = GTK_ICON_SIZE_INVALID; break; | |
2827 } | |
2828 oldsize = gtk_toolbar_get_icon_size(toolbar); | |
2829 | |
2830 if (size == GTK_ICON_SIZE_INVALID) | |
2831 { | |
2832 /* Let global user preferences decide the icon size. */ | |
2833 gtk_toolbar_unset_icon_size(toolbar); | |
2834 size = gtk_toolbar_get_icon_size(toolbar); | |
2835 } | |
2836 if (size != oldsize) | |
2837 { | |
2838 gtk_container_foreach(GTK_CONTAINER(toolbar), | |
2839 &icon_size_changed_foreach, | |
2840 GINT_TO_POINTER((int)size)); | |
2841 } | |
2842 gtk_toolbar_set_icon_size(toolbar, size); | |
2843 } | |
2844 | |
2845 #endif /* FEAT_TOOLBAR */ | |
2846 | |
685 | 2847 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
2848 static int ignore_tabline_evt = FALSE; | |
689 | 2849 static GtkWidget *tabline_menu; |
846 | 2850 static GtkTooltips *tabline_tooltip; |
689 | 2851 static int clicked_page; /* page clicked in tab line */ |
2852 | |
2853 /* | |
2854 * Handle selecting an item in the tab line popup menu. | |
2855 */ | |
2856 static void | |
1884 | 2857 tabline_menu_handler(GtkMenuItem *item UNUSED, gpointer user_data) |
689 | 2858 { |
2859 /* Add the string cmd into input buffer */ | |
824 | 2860 send_tabline_menu_event(clicked_page, (int)(long)user_data); |
689 | 2861 } |
2862 | |
851 | 2863 static void |
2864 add_tabline_menu_item(GtkWidget *menu, char_u *text, int resp) | |
2865 { | |
2866 GtkWidget *item; | |
2867 char_u *utf_text; | |
2868 | |
2869 utf_text = CONVERT_TO_UTF8(text); | |
2870 item = gtk_menu_item_new_with_label((const char *)utf_text); | |
2871 gtk_widget_show(item); | |
2872 CONVERT_TO_UTF8_FREE(utf_text); | |
2873 | |
2874 gtk_container_add(GTK_CONTAINER(menu), item); | |
2875 gtk_signal_connect(GTK_OBJECT(item), "activate", | |
2876 GTK_SIGNAL_FUNC(tabline_menu_handler), | |
1660 | 2877 (gpointer)(long)resp); |
851 | 2878 } |
2879 | |
689 | 2880 /* |
2881 * Create a menu for the tab line. | |
2882 */ | |
2883 static GtkWidget * | |
2884 create_tabline_menu(void) | |
2885 { | |
851 | 2886 GtkWidget *menu; |
689 | 2887 |
2888 menu = gtk_menu_new(); | |
6819 | 2889 if (first_tabpage->tp_next != NULL) |
2890 add_tabline_menu_item(menu, (char_u *)_("Close tab"), | |
2891 TABLINE_MENU_CLOSE); | |
851 | 2892 add_tabline_menu_item(menu, (char_u *)_("New tab"), TABLINE_MENU_NEW); |
2893 add_tabline_menu_item(menu, (char_u *)_("Open Tab..."), TABLINE_MENU_OPEN); | |
689 | 2894 |
2895 return menu; | |
2896 } | |
2897 | |
2898 static gboolean | |
2899 on_tabline_menu(GtkWidget *widget, GdkEvent *event) | |
2900 { | |
2901 /* Was this button press event ? */ | |
2902 if (event->type == GDK_BUTTON_PRESS) | |
2903 { | |
2904 GdkEventButton *bevent = (GdkEventButton *)event; | |
2905 int x = bevent->x; | |
851 | 2906 int y = bevent->y; |
2907 GtkWidget *tabwidget; | |
2908 GdkWindow *tabwin; | |
689 | 2909 |
844 | 2910 /* When ignoring events return TRUE so that the selected page doesn't |
2911 * change. */ | |
2912 if (hold_gui_events | |
2913 # ifdef FEAT_CMDWIN | |
2914 || cmdwin_type != 0 | |
2915 # endif | |
2916 ) | |
2917 return TRUE; | |
2918 | |
851 | 2919 tabwin = gdk_window_at_pointer(&x, &y); |
2920 gdk_window_get_user_data(tabwin, (gpointer)&tabwidget); | |
2921 clicked_page = (int)(long)gtk_object_get_user_data( | |
2922 GTK_OBJECT(tabwidget)); | |
689 | 2923 |
2924 /* If the event was generated for 3rd button popup the menu. */ | |
2925 if (bevent->button == 3) | |
2926 { | |
2927 gtk_menu_popup(GTK_MENU(widget), NULL, NULL, NULL, NULL, | |
2928 bevent->button, bevent->time); | |
2929 /* We handled the event. */ | |
2930 return TRUE; | |
2931 } | |
868 | 2932 else if (bevent->button == 1) |
693 | 2933 { |
868 | 2934 if (clicked_page == 0) |
2935 { | |
1394 | 2936 /* Click after all tabs moves to next tab page. When "x" is |
2937 * small guess it's the left button. */ | |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
2938 send_tabline_event(x < 50 ? -1 : 0); |
868 | 2939 } |
693 | 2940 } |
689 | 2941 } |
844 | 2942 |
689 | 2943 /* We didn't handle the event. */ |
2944 return FALSE; | |
2945 } | |
685 | 2946 |
2947 /* | |
2948 * Handle selecting one of the tabs. | |
2949 */ | |
2950 static void | |
2951 on_select_tab( | |
1884 | 2952 GtkNotebook *notebook UNUSED, |
2953 GtkNotebookPage *page UNUSED, | |
944 | 2954 gint idx, |
1884 | 2955 gpointer data UNUSED) |
685 | 2956 { |
2957 if (!ignore_tabline_evt) | |
693 | 2958 { |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
2959 send_tabline_event(idx + 1); |
693 | 2960 } |
685 | 2961 } |
2962 | |
2963 /* | |
2964 * Show or hide the tabline. | |
2965 */ | |
2966 void | |
2967 gui_mch_show_tabline(int showit) | |
2968 { | |
2969 if (gui.tabline == NULL) | |
2970 return; | |
2971 | |
2972 if (!showit != !gtk_notebook_get_show_tabs(GTK_NOTEBOOK(gui.tabline))) | |
2973 { | |
708 | 2974 /* Note: this may cause a resize event */ |
685 | 2975 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gui.tabline), showit); |
791 | 2976 update_window_manager_hints(0, 0); |
868 | 2977 if (showit) |
2978 GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(gui.tabline), GTK_CAN_FOCUS); | |
2979 } | |
2980 | |
2981 gui_mch_update(); | |
685 | 2982 } |
2983 | |
2984 /* | |
708 | 2985 * Return TRUE when tabline is displayed. |
2986 */ | |
2987 int | |
2988 gui_mch_showing_tabline(void) | |
2989 { | |
2990 return gui.tabline != NULL | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
2991 && gtk_notebook_get_show_tabs(GTK_NOTEBOOK(gui.tabline)); |
708 | 2992 } |
2993 | |
2994 /* | |
685 | 2995 * Update the labels of the tabline. |
2996 */ | |
2997 void | |
2998 gui_mch_update_tabline(void) | |
2999 { | |
3000 GtkWidget *page; | |
846 | 3001 GtkWidget *event_box; |
685 | 3002 GtkWidget *label; |
3003 tabpage_T *tp; | |
3004 int nr = 0; | |
851 | 3005 int tab_num; |
685 | 3006 int curtabidx = 0; |
836 | 3007 char_u *labeltext; |
685 | 3008 |
3009 if (gui.tabline == NULL) | |
3010 return; | |
3011 | |
3012 ignore_tabline_evt = TRUE; | |
3013 | |
3014 /* Add a label for each tab page. They all contain the same text area. */ | |
3015 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr) | |
3016 { | |
3017 if (tp == curtab) | |
3018 curtabidx = nr; | |
3019 | |
851 | 3020 tab_num = nr + 1; |
3021 | |
685 | 3022 page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui.tabline), nr); |
3023 if (page == NULL) | |
3024 { | |
3025 /* Add notebook page */ | |
3026 page = gtk_vbox_new(FALSE, 0); | |
3027 gtk_widget_show(page); | |
846 | 3028 event_box = gtk_event_box_new(); |
3029 gtk_widget_show(event_box); | |
685 | 3030 label = gtk_label_new("-Empty-"); |
851 | 3031 gtk_misc_set_padding(GTK_MISC(label), 2, 2); |
846 | 3032 gtk_container_add(GTK_CONTAINER(event_box), label); |
685 | 3033 gtk_widget_show(label); |
3034 gtk_notebook_insert_page(GTK_NOTEBOOK(gui.tabline), | |
3035 page, | |
846 | 3036 event_box, |
685 | 3037 nr++); |
3038 } | |
3039 | |
846 | 3040 event_box = gtk_notebook_get_tab_label(GTK_NOTEBOOK(gui.tabline), page); |
1660 | 3041 gtk_object_set_user_data(GTK_OBJECT(event_box), |
3042 (gpointer)(long)tab_num); | |
846 | 3043 label = GTK_BIN(event_box)->child; |
839 | 3044 get_tabline_label(tp, FALSE); |
836 | 3045 labeltext = CONVERT_TO_UTF8(NameBuff); |
846 | 3046 gtk_label_set_text(GTK_LABEL(label), (const char *)labeltext); |
836 | 3047 CONVERT_TO_UTF8_FREE(labeltext); |
846 | 3048 |
3049 get_tabline_label(tp, TRUE); | |
3050 labeltext = CONVERT_TO_UTF8(NameBuff); | |
3051 gtk_tooltips_set_tip(GTK_TOOLTIPS(tabline_tooltip), event_box, | |
3052 (const char *)labeltext, NULL); | |
3053 CONVERT_TO_UTF8_FREE(labeltext); | |
685 | 3054 } |
3055 | |
3056 /* Remove any old labels. */ | |
3057 while (gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui.tabline), nr) != NULL) | |
3058 gtk_notebook_remove_page(GTK_NOTEBOOK(gui.tabline), nr); | |
3059 | |
3060 if (gtk_notebook_current_page(GTK_NOTEBOOK(gui.tabline)) != curtabidx) | |
856 | 3061 gtk_notebook_set_page(GTK_NOTEBOOK(gui.tabline), curtabidx); |
685 | 3062 |
851 | 3063 /* Make sure everything is in place before drawing text. */ |
3064 gui_mch_update(); | |
3065 | |
685 | 3066 ignore_tabline_evt = FALSE; |
3067 } | |
3068 | |
3069 /* | |
3070 * Set the current tab to "nr". First tab is 1. | |
3071 */ | |
3072 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
3073 gui_mch_set_curtab(int nr) |
685 | 3074 { |
3075 if (gui.tabline == NULL) | |
3076 return; | |
3077 | |
3078 ignore_tabline_evt = TRUE; | |
3079 if (gtk_notebook_current_page(GTK_NOTEBOOK(gui.tabline)) != nr - 1) | |
856 | 3080 gtk_notebook_set_page(GTK_NOTEBOOK(gui.tabline), nr - 1); |
685 | 3081 ignore_tabline_evt = FALSE; |
3082 } | |
3083 | |
3084 #endif /* FEAT_GUI_TABLINE */ | |
3085 | |
7 | 3086 /* |
2183 | 3087 * Add selection targets for PRIMARY and CLIPBOARD selections. |
3088 */ | |
3089 void | |
3090 gui_gtk_set_selection_targets(void) | |
3091 { | |
3092 int i, j = 0; | |
3093 int n_targets = N_SELECTION_TARGETS; | |
3094 GtkTargetEntry targets[N_SELECTION_TARGETS]; | |
3095 | |
3096 for (i = 0; i < (int)N_SELECTION_TARGETS; ++i) | |
3097 { | |
3518 | 3098 /* OpenOffice tries to use TARGET_HTML and fails when we don't |
2183 | 3099 * return something, instead of trying another target. Therefore only |
3100 * offer TARGET_HTML when it works. */ | |
3101 if (!clip_html && selection_targets[i].info == TARGET_HTML) | |
3102 n_targets--; | |
3103 else | |
3104 targets[j++] = selection_targets[i]; | |
3105 } | |
3106 | |
3107 gtk_selection_clear_targets(gui.drawarea, (GdkAtom)GDK_SELECTION_PRIMARY); | |
3108 gtk_selection_clear_targets(gui.drawarea, (GdkAtom)clip_plus.gtk_sel_atom); | |
3109 gtk_selection_add_targets(gui.drawarea, | |
3110 (GdkAtom)GDK_SELECTION_PRIMARY, | |
3111 targets, n_targets); | |
3112 gtk_selection_add_targets(gui.drawarea, | |
3113 (GdkAtom)clip_plus.gtk_sel_atom, | |
3114 targets, n_targets); | |
3115 } | |
3116 | |
3117 /* | |
3118 * Set up for receiving DND items. | |
3119 */ | |
3120 void | |
3121 gui_gtk_set_dnd_targets(void) | |
3122 { | |
3123 int i, j = 0; | |
3124 int n_targets = N_DND_TARGETS; | |
3125 GtkTargetEntry targets[N_DND_TARGETS]; | |
3126 | |
3127 for (i = 0; i < (int)N_DND_TARGETS; ++i) | |
3128 { | |
3154 | 3129 if (!clip_html && dnd_targets[i].info == TARGET_HTML) |
2183 | 3130 n_targets--; |
3131 else | |
3132 targets[j++] = dnd_targets[i]; | |
3133 } | |
3134 | |
3135 gtk_drag_dest_unset(gui.drawarea); | |
3136 gtk_drag_dest_set(gui.drawarea, | |
3137 GTK_DEST_DEFAULT_ALL, | |
3138 targets, n_targets, | |
2718 | 3139 GDK_ACTION_COPY | GDK_ACTION_MOVE); |
2183 | 3140 } |
3141 | |
3142 /* | |
7 | 3143 * Initialize the GUI. Create all the windows, set up all the callbacks etc. |
3144 * Returns OK for success, FAIL when the GUI can't be started. | |
3145 */ | |
3146 int | |
3147 gui_mch_init(void) | |
3148 { | |
3149 GtkWidget *vbox; | |
3150 | |
3151 #ifdef FEAT_GUI_GNOME | |
3152 /* Initialize the GNOME libraries. gnome_program_init()/gnome_init() | |
3153 * exits on failure, but that's a non-issue because we already called | |
3154 * gtk_init_check() in gui_mch_init_check(). */ | |
3155 if (using_gnome) | |
4045 | 3156 { |
7 | 3157 gnome_program_init(VIMPACKAGE, VIM_VERSION_SHORT, |
3158 LIBGNOMEUI_MODULE, gui_argc, gui_argv, NULL); | |
4045 | 3159 # if defined(FEAT_FLOAT) && defined(LC_NUMERIC) |
5854 | 3160 { |
3161 char *p = setlocale(LC_NUMERIC, NULL); | |
3162 | |
3163 /* Make sure strtod() uses a decimal point, not a comma. Gnome | |
3164 * init may change it. */ | |
3165 if (p == NULL || strcmp(p, "C") != 0) | |
3166 setlocale(LC_NUMERIC, "C"); | |
3167 } | |
4045 | 3168 # endif |
3169 } | |
7 | 3170 #endif |
3171 vim_free(gui_argv); | |
3172 gui_argv = NULL; | |
3173 | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3174 #if GLIB_CHECK_VERSION(2,1,3) |
7 | 3175 /* Set the human-readable application name */ |
3176 g_set_application_name("Vim"); | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3177 #endif |
7 | 3178 /* |
3179 * Force UTF-8 output no matter what the value of 'encoding' is. | |
3180 * did_set_string_option() in option.c prohibits changing 'termencoding' | |
3181 * to something else than UTF-8 if the GUI is in use. | |
3182 */ | |
3183 set_option_value((char_u *)"termencoding", 0L, (char_u *)"utf-8", 0); | |
3184 | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3185 #ifdef FEAT_TOOLBAR |
7 | 3186 gui_gtk_register_stock_icons(); |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3187 #endif |
7 | 3188 /* FIXME: Need to install the classic icons and a gtkrc.classic file. |
3189 * The hard part is deciding install locations and the Makefile magic. */ | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3190 #if 0 |
7 | 3191 gtk_rc_parse("gtkrc"); |
3192 #endif | |
3193 | |
3194 /* Initialize values */ | |
3195 gui.border_width = 2; | |
3196 gui.scrollbar_width = SB_DEFAULT_WIDTH; | |
3197 gui.scrollbar_height = SB_DEFAULT_WIDTH; | |
136 | 3198 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
7 | 3199 gui.fgcolor = g_new0(GdkColor, 1); |
136 | 3200 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
7 | 3201 gui.bgcolor = g_new0(GdkColor, 1); |
207 | 3202 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
3203 gui.spcolor = g_new0(GdkColor, 1); | |
7 | 3204 |
3205 /* Initialise atoms */ | |
1904 | 3206 html_atom = gdk_atom_intern("text/html", FALSE); |
7 | 3207 utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE); |
3208 | |
3209 /* Set default foreground and background colors. */ | |
3210 gui.norm_pixel = gui.def_norm_pixel; | |
3211 gui.back_pixel = gui.def_back_pixel; | |
3212 | |
3213 if (gtk_socket_id != 0) | |
3214 { | |
3215 GtkWidget *plug; | |
3216 | |
3217 /* Use GtkSocket from another app. */ | |
3218 #ifdef HAVE_GTK_MULTIHEAD | |
3219 plug = gtk_plug_new_for_display(gdk_display_get_default(), | |
3220 gtk_socket_id); | |
3221 #else | |
3222 plug = gtk_plug_new(gtk_socket_id); | |
3223 #endif | |
3224 if (plug != NULL && GTK_PLUG(plug)->socket_window != NULL) | |
3225 { | |
3226 gui.mainwin = plug; | |
3227 } | |
3228 else | |
3229 { | |
3230 g_warning("Connection to GTK+ socket (ID %u) failed", | |
3231 (unsigned int)gtk_socket_id); | |
3232 /* Pretend we never wanted it if it failed (get own window) */ | |
3233 gtk_socket_id = 0; | |
3234 } | |
3235 } | |
3236 | |
3237 if (gtk_socket_id == 0) | |
3238 { | |
3239 #ifdef FEAT_GUI_GNOME | |
3240 if (using_gnome) | |
3241 { | |
3242 gui.mainwin = gnome_app_new("Vim", NULL); | |
3243 # ifdef USE_XSMP | |
3244 /* Use the GNOME save-yourself functionality now. */ | |
3245 xsmp_close(); | |
3246 # endif | |
3247 } | |
3248 else | |
3249 #endif | |
3250 gui.mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
3251 } | |
3252 | |
3253 gtk_widget_set_name(gui.mainwin, "vim-main-window"); | |
3254 | |
3255 /* Create the PangoContext used for drawing all text. */ | |
3256 gui.text_context = gtk_widget_create_pango_context(gui.mainwin); | |
3257 pango_context_set_base_dir(gui.text_context, PANGO_DIRECTION_LTR); | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3258 |
7 | 3259 gtk_container_border_width(GTK_CONTAINER(gui.mainwin), 0); |
3260 gtk_widget_add_events(gui.mainwin, GDK_VISIBILITY_NOTIFY_MASK); | |
3261 | |
3262 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "delete_event", | |
3263 GTK_SIGNAL_FUNC(&delete_event_cb), NULL); | |
3264 | |
3265 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "realize", | |
3266 GTK_SIGNAL_FUNC(&mainwin_realize), NULL); | |
3267 #ifdef HAVE_GTK_MULTIHEAD | |
3268 g_signal_connect(G_OBJECT(gui.mainwin), "screen_changed", | |
3269 G_CALLBACK(&mainwin_screen_changed_cb), NULL); | |
3270 #endif | |
3271 gui.accel_group = gtk_accel_group_new(); | |
3272 gtk_window_add_accel_group(GTK_WINDOW(gui.mainwin), gui.accel_group); | |
3273 | |
685 | 3274 /* A vertical box holds the menubar, toolbar and main text window. */ |
7 | 3275 vbox = gtk_vbox_new(FALSE, 0); |
3276 | |
3277 #ifdef FEAT_GUI_GNOME | |
3278 if (using_gnome) | |
3279 { | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3280 # if defined(FEAT_MENU) |
7 | 3281 /* automagically restore menubar/toolbar placement */ |
3282 gnome_app_enable_layout_config(GNOME_APP(gui.mainwin), TRUE); | |
3283 # endif | |
3284 gnome_app_set_contents(GNOME_APP(gui.mainwin), vbox); | |
3285 } | |
3286 else | |
3287 #endif | |
3288 { | |
3289 gtk_container_add(GTK_CONTAINER(gui.mainwin), vbox); | |
3290 gtk_widget_show(vbox); | |
3291 } | |
3292 | |
3293 #ifdef FEAT_MENU | |
3294 /* | |
3295 * Create the menubar and handle | |
3296 */ | |
3297 gui.menubar = gtk_menu_bar_new(); | |
3298 gtk_widget_set_name(gui.menubar, "vim-menubar"); | |
3299 | |
36 | 3300 /* Avoid that GTK takes <F10> away from us. */ |
3301 { | |
3302 GtkSettings *gtk_settings; | |
3303 | |
3304 gtk_settings = gtk_settings_get_for_screen(gdk_screen_get_default()); | |
3305 g_object_set(gtk_settings, "gtk-menu-bar-accel", NULL, NULL); | |
3306 } | |
3307 | |
3308 | |
7 | 3309 # ifdef FEAT_GUI_GNOME |
3310 if (using_gnome) | |
3311 { | |
3312 BonoboDockItem *dockitem; | |
3313 | |
3314 gnome_app_set_menus(GNOME_APP(gui.mainwin), GTK_MENU_BAR(gui.menubar)); | |
3315 dockitem = gnome_app_get_dock_item_by_name(GNOME_APP(gui.mainwin), | |
3316 GNOME_APP_MENUBAR_NAME); | |
798 | 3317 /* We don't want the menu to float. */ |
3318 bonobo_dock_item_set_behavior(dockitem, | |
3319 bonobo_dock_item_get_behavior(dockitem) | |
3320 | BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); | |
7 | 3321 gui.menubar_h = GTK_WIDGET(dockitem); |
3322 } | |
3323 else | |
3324 # endif /* FEAT_GUI_GNOME */ | |
3325 { | |
827 | 3326 /* Always show the menubar, otherwise <F10> doesn't work. It may be |
3327 * disabled in gui_init() later. */ | |
3328 gtk_widget_show(gui.menubar); | |
7 | 3329 gtk_box_pack_start(GTK_BOX(vbox), gui.menubar, FALSE, FALSE, 0); |
3330 } | |
3331 #endif /* FEAT_MENU */ | |
3332 | |
3333 #ifdef FEAT_TOOLBAR | |
3334 /* | |
3335 * Create the toolbar and handle | |
3336 */ | |
3337 /* some aesthetics on the toolbar */ | |
3338 gtk_rc_parse_string( | |
3339 "style \"vim-toolbar-style\" {\n" | |
3340 " GtkToolbar::button_relief = GTK_RELIEF_NONE\n" | |
3341 "}\n" | |
3342 "widget \"*.vim-toolbar\" style \"vim-toolbar-style\"\n"); | |
3343 gui.toolbar = gtk_toolbar_new(); | |
3344 gtk_widget_set_name(gui.toolbar, "vim-toolbar"); | |
3345 set_toolbar_style(GTK_TOOLBAR(gui.toolbar)); | |
3346 | |
3347 # ifdef FEAT_GUI_GNOME | |
3348 if (using_gnome) | |
3349 { | |
3350 BonoboDockItem *dockitem; | |
3351 | |
3352 gnome_app_set_toolbar(GNOME_APP(gui.mainwin), GTK_TOOLBAR(gui.toolbar)); | |
3353 dockitem = gnome_app_get_dock_item_by_name(GNOME_APP(gui.mainwin), | |
3354 GNOME_APP_TOOLBAR_NAME); | |
3355 gui.toolbar_h = GTK_WIDGET(dockitem); | |
795 | 3356 /* When the toolbar is floating it gets stuck. So long as that isn't |
798 | 3357 * fixed let's disallow floating. */ |
795 | 3358 bonobo_dock_item_set_behavior(dockitem, |
798 | 3359 bonobo_dock_item_get_behavior(dockitem) |
3360 | BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); | |
7 | 3361 gtk_container_set_border_width(GTK_CONTAINER(gui.toolbar), 0); |
3362 } | |
3363 else | |
3364 # endif /* FEAT_GUI_GNOME */ | |
3365 { | |
3366 if (vim_strchr(p_go, GO_TOOLBAR) != NULL | |
3367 && (toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS))) | |
3368 gtk_widget_show(gui.toolbar); | |
3369 gtk_box_pack_start(GTK_BOX(vbox), gui.toolbar, FALSE, FALSE, 0); | |
3370 } | |
3371 #endif /* FEAT_TOOLBAR */ | |
3372 | |
685 | 3373 #ifdef FEAT_GUI_TABLINE |
782 | 3374 /* |
3375 * Use a Notebook for the tab pages labels. The labels are hidden by | |
3376 * default. | |
3377 */ | |
791 | 3378 gui.tabline = gtk_notebook_new(); |
3379 gtk_widget_show(gui.tabline); | |
3380 gtk_box_pack_start(GTK_BOX(vbox), gui.tabline, FALSE, FALSE, 0); | |
3381 gtk_notebook_set_show_border(GTK_NOTEBOOK(gui.tabline), FALSE); | |
3382 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gui.tabline), FALSE); | |
841 | 3383 gtk_notebook_set_scrollable(GTK_NOTEBOOK(gui.tabline), TRUE); |
868 | 3384 gtk_notebook_set_tab_border(GTK_NOTEBOOK(gui.tabline), FALSE); |
791 | 3385 |
846 | 3386 tabline_tooltip = gtk_tooltips_new(); |
3387 gtk_tooltips_enable(GTK_TOOLTIPS(tabline_tooltip)); | |
3388 | |
3389 { | |
3390 GtkWidget *page, *label, *event_box; | |
791 | 3391 |
856 | 3392 /* Add the first tab. */ |
846 | 3393 page = gtk_vbox_new(FALSE, 0); |
3394 gtk_widget_show(page); | |
3395 gtk_container_add(GTK_CONTAINER(gui.tabline), page); | |
3396 label = gtk_label_new("-Empty-"); | |
3397 gtk_widget_show(label); | |
3398 event_box = gtk_event_box_new(); | |
3399 gtk_widget_show(event_box); | |
1660 | 3400 gtk_object_set_user_data(GTK_OBJECT(event_box), (gpointer)1L); |
851 | 3401 gtk_misc_set_padding(GTK_MISC(label), 2, 2); |
846 | 3402 gtk_container_add(GTK_CONTAINER(event_box), label); |
3403 gtk_notebook_set_tab_label(GTK_NOTEBOOK(gui.tabline), page, event_box); | |
791 | 3404 } |
865 | 3405 |
791 | 3406 gtk_signal_connect(GTK_OBJECT(gui.tabline), "switch_page", |
856 | 3407 GTK_SIGNAL_FUNC(on_select_tab), NULL); |
791 | 3408 |
3409 /* Create a popup menu for the tab line and connect it. */ | |
3410 tabline_menu = create_tabline_menu(); | |
3411 gtk_signal_connect_object(GTK_OBJECT(gui.tabline), "button_press_event", | |
856 | 3412 GTK_SIGNAL_FUNC(on_tabline_menu), GTK_OBJECT(tabline_menu)); |
685 | 3413 #endif |
3414 | |
7 | 3415 gui.formwin = gtk_form_new(); |
3416 gtk_container_border_width(GTK_CONTAINER(gui.formwin), 0); | |
3417 gtk_widget_set_events(gui.formwin, GDK_EXPOSURE_MASK); | |
3418 | |
3419 gui.drawarea = gtk_drawing_area_new(); | |
3420 | |
3421 /* Determine which events we will filter. */ | |
3422 gtk_widget_set_events(gui.drawarea, | |
3423 GDK_EXPOSURE_MASK | | |
3424 GDK_ENTER_NOTIFY_MASK | | |
3425 GDK_LEAVE_NOTIFY_MASK | | |
3426 GDK_BUTTON_PRESS_MASK | | |
3427 GDK_BUTTON_RELEASE_MASK | | |
3428 GDK_SCROLL_MASK | | |
3429 GDK_KEY_PRESS_MASK | | |
3430 GDK_KEY_RELEASE_MASK | | |
3431 GDK_POINTER_MOTION_MASK | | |
3432 GDK_POINTER_MOTION_HINT_MASK); | |
3433 | |
3434 gtk_widget_show(gui.drawarea); | |
3435 gtk_form_put(GTK_FORM(gui.formwin), gui.drawarea, 0, 0); | |
3436 gtk_widget_show(gui.formwin); | |
3437 gtk_box_pack_start(GTK_BOX(vbox), gui.formwin, TRUE, TRUE, 0); | |
3438 | |
3439 /* For GtkSockets, key-presses must go to the focus widget (drawarea) | |
3440 * and not the window. */ | |
3441 gtk_signal_connect((gtk_socket_id == 0) ? GTK_OBJECT(gui.mainwin) | |
3442 : GTK_OBJECT(gui.drawarea), | |
3443 "key_press_event", | |
3444 GTK_SIGNAL_FUNC(key_press_event), NULL); | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3445 #if defined(FEAT_XIM) |
7 | 3446 /* Also forward key release events for the benefit of GTK+ 2 input |
3447 * modules. Try CTRL-SHIFT-xdigits to enter a Unicode code point. */ | |
3448 g_signal_connect((gtk_socket_id == 0) ? G_OBJECT(gui.mainwin) | |
3449 : G_OBJECT(gui.drawarea), | |
3450 "key_release_event", | |
3451 G_CALLBACK(&key_release_event), NULL); | |
3452 #endif | |
3453 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "realize", | |
3454 GTK_SIGNAL_FUNC(drawarea_realize_cb), NULL); | |
3455 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "unrealize", | |
3456 GTK_SIGNAL_FUNC(drawarea_unrealize_cb), NULL); | |
3457 | |
3458 gtk_signal_connect_after(GTK_OBJECT(gui.drawarea), "style_set", | |
3459 GTK_SIGNAL_FUNC(&drawarea_style_set_cb), NULL); | |
3460 | |
3461 gui.visibility = GDK_VISIBILITY_UNOBSCURED; | |
3462 | |
3463 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
3464 wm_protocols_atom = gdk_atom_intern("WM_PROTOCOLS", FALSE); | |
3465 save_yourself_atom = gdk_atom_intern("WM_SAVE_YOURSELF", FALSE); | |
3466 #endif | |
3467 | |
3468 if (gtk_socket_id != 0) | |
1884 | 3469 /* make sure keyboard input can go to the drawarea */ |
7 | 3470 GTK_WIDGET_SET_FLAGS(gui.drawarea, GTK_CAN_FOCUS); |
3471 | |
3472 /* | |
3473 * Set clipboard specific atoms | |
3474 */ | |
3475 vim_atom = gdk_atom_intern(VIM_ATOM_NAME, FALSE); | |
3476 vimenc_atom = gdk_atom_intern(VIMENC_ATOM_NAME, FALSE); | |
3477 clip_star.gtk_sel_atom = GDK_SELECTION_PRIMARY; | |
3478 clip_plus.gtk_sel_atom = gdk_atom_intern("CLIPBOARD", FALSE); | |
3479 | |
3480 /* | |
3481 * Start out by adding the configured border width into the border offset. | |
3482 */ | |
3483 gui.border_offset = gui.border_width; | |
3484 | |
3485 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "visibility_notify_event", | |
3486 GTK_SIGNAL_FUNC(visibility_event), NULL); | |
3487 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "expose_event", | |
3488 GTK_SIGNAL_FUNC(expose_event), NULL); | |
3489 | |
3490 /* | |
3491 * Only install these enter/leave callbacks when 'p' in 'guioptions'. | |
3492 * Only needed for some window managers. | |
3493 */ | |
3494 if (vim_strchr(p_go, GO_POINTER) != NULL) | |
3495 { | |
3496 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "leave_notify_event", | |
3497 GTK_SIGNAL_FUNC(leave_notify_event), NULL); | |
3498 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "enter_notify_event", | |
3499 GTK_SIGNAL_FUNC(enter_notify_event), NULL); | |
3500 } | |
3501 | |
791 | 3502 /* Real windows can get focus ... GtkPlug, being a mere container can't, |
3503 * only its widgets. Arguably, this could be common code and we not use | |
3504 * the window focus at all, but let's be safe. | |
3505 */ | |
3506 if (gtk_socket_id == 0) | |
3507 { | |
856 | 3508 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "focus_out_event", |
3509 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
3510 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "focus_in_event", | |
3511 GTK_SIGNAL_FUNC(focus_in_event), NULL); | |
791 | 3512 } |
3513 else | |
3514 { | |
856 | 3515 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "focus_out_event", |
3516 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
3517 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "focus_in_event", | |
3518 GTK_SIGNAL_FUNC(focus_in_event), NULL); | |
791 | 3519 #ifdef FEAT_GUI_TABLINE |
856 | 3520 gtk_signal_connect(GTK_OBJECT(gui.tabline), "focus_out_event", |
3521 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
3522 gtk_signal_connect(GTK_OBJECT(gui.tabline), "focus_in_event", | |
3523 GTK_SIGNAL_FUNC(focus_in_event), NULL); | |
791 | 3524 #endif /* FEAT_GUI_TABLINE */ |
3525 } | |
7 | 3526 |
3527 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "motion_notify_event", | |
3528 GTK_SIGNAL_FUNC(motion_notify_event), NULL); | |
3529 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "button_press_event", | |
3530 GTK_SIGNAL_FUNC(button_press_event), NULL); | |
3531 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "button_release_event", | |
3532 GTK_SIGNAL_FUNC(button_release_event), NULL); | |
3533 g_signal_connect(G_OBJECT(gui.drawarea), "scroll_event", | |
3534 G_CALLBACK(&scroll_event), NULL); | |
3535 | |
3536 /* | |
3537 * Add selection handler functions. | |
3538 */ | |
3539 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_clear_event", | |
3540 GTK_SIGNAL_FUNC(selection_clear_event), NULL); | |
3541 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_received", | |
3542 GTK_SIGNAL_FUNC(selection_received_cb), NULL); | |
3543 | |
2183 | 3544 gui_gtk_set_selection_targets(); |
7 | 3545 |
3546 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_get", | |
3547 GTK_SIGNAL_FUNC(selection_get_cb), NULL); | |
3548 | |
3549 /* Pretend we don't have input focus, we will get an event if we do. */ | |
3550 gui.in_focus = FALSE; | |
3551 | |
3552 return OK; | |
3553 } | |
3554 | |
3555 #if (defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) || defined(PROTO) | |
3556 /* | |
3557 * This is called from gui_start() after a fork() has been done. | |
3558 * We have to tell the session manager our new PID. | |
3559 */ | |
3560 void | |
3561 gui_mch_forked(void) | |
3562 { | |
3563 if (using_gnome) | |
3564 { | |
3565 GnomeClient *client; | |
3566 | |
3567 client = gnome_master_client(); | |
3568 | |
3569 if (client != NULL) | |
3570 gnome_client_set_process_id(client, getpid()); | |
3571 } | |
3572 } | |
3573 #endif /* FEAT_GUI_GNOME && FEAT_SESSION */ | |
3574 | |
3575 /* | |
3576 * Called when the foreground or background color has been changed. | |
3577 * This used to change the graphics contexts directly but we are | |
3578 * currently manipulating them where desired. | |
3579 */ | |
3580 void | |
3581 gui_mch_new_colors(void) | |
3582 { | |
3583 if (gui.drawarea != NULL && gui.drawarea->window != NULL) | |
3584 { | |
3585 GdkColor color = { 0, 0, 0, 0 }; | |
3586 | |
3587 color.pixel = gui.back_pixel; | |
3588 gdk_window_set_background(gui.drawarea->window, &color); | |
3589 } | |
3590 } | |
3591 | |
3592 /* | |
3593 * This signal informs us about the need to rearrange our sub-widgets. | |
3594 */ | |
3595 static gint | |
1884 | 3596 form_configure_event(GtkWidget *widget UNUSED, |
3597 GdkEventConfigure *event, | |
3598 gpointer data UNUSED) | |
7 | 3599 { |
791 | 3600 int usable_height = event->height; |
3601 | |
3602 /* When in a GtkPlug, we can't guarantee valid heights (as a round | |
3603 * no. of char-heights), so we have to manually sanitise them. | |
3604 * Widths seem to sort themselves out, don't ask me why. | |
3605 */ | |
3606 if (gtk_socket_id != 0) | |
856 | 3607 usable_height -= (gui.char_height - (gui.char_height/2)); /* sic. */ |
791 | 3608 |
7 | 3609 gtk_form_freeze(GTK_FORM(gui.formwin)); |
791 | 3610 gui_resize_shell(event->width, usable_height); |
7 | 3611 gtk_form_thaw(GTK_FORM(gui.formwin)); |
3612 | |
3613 return TRUE; | |
3614 } | |
3615 | |
3616 /* | |
3617 * Function called when window already closed. | |
3618 * We can't do much more here than to trying to preserve what had been done, | |
3619 * since the window is already inevitably going away. | |
3620 */ | |
3621 static void | |
1884 | 3622 mainwin_destroy_cb(GtkObject *object UNUSED, gpointer data UNUSED) |
7 | 3623 { |
3624 /* Don't write messages to the GUI anymore */ | |
3625 full_screen = FALSE; | |
3626 | |
3627 gui.mainwin = NULL; | |
3628 gui.drawarea = NULL; | |
3629 | |
3630 if (!exiting) /* only do anything if the destroy was unexpected */ | |
3631 { | |
419 | 3632 vim_strncpy(IObuff, |
3633 (char_u *)_("Vim: Main window unexpectedly destroyed\n"), | |
3634 IOSIZE - 1); | |
7 | 3635 preserve_exit(); |
3636 } | |
7380
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
3637 #ifdef USE_GRESOURCE |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
3638 gui_gtk_unregister_resource(); |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
3639 #endif |
7 | 3640 } |
3641 | |
791 | 3642 |
3643 /* | |
3644 * Bit of a hack to ensure we start GtkPlug windows with the correct window | |
3645 * hints (and thus the required size from -geom), but that after that we | |
3646 * put the hints back to normal (the actual minimum size) so we may | |
3647 * subsequently be resized smaller. GtkSocket (the parent end) uses the | |
1226 | 3648 * plug's window 'min hints to set *it's* minimum size, but that's also the |
791 | 3649 * only way we have of making ourselves bigger (by set lines/columns). |
3650 * Thus set hints at start-up to ensure correct init. size, then a | |
3651 * second after the final attempt to reset the real minimum hinst (done by | |
1226 | 3652 * scrollbar init.), actually do the standard hinst and stop the timer. |
791 | 3653 * We'll not let the default hints be set while this timer's active. |
3654 */ | |
3655 static gboolean | |
1884 | 3656 check_startup_plug_hints(gpointer data UNUSED) |
791 | 3657 { |
3658 if (init_window_hints_state == 1) | |
3659 { | |
856 | 3660 /* Safe to use normal hints now */ |
3661 init_window_hints_state = 0; | |
3662 update_window_manager_hints(0, 0); | |
3663 return FALSE; /* stop timer */ | |
791 | 3664 } |
3665 | |
3666 /* Keep on trying */ | |
3667 init_window_hints_state = 1; | |
3668 return TRUE; | |
3669 } | |
3670 | |
7 | 3671 /* |
3672 * Open the GUI window which was created by a call to gui_mch_init(). | |
3673 */ | |
3674 int | |
3675 gui_mch_open(void) | |
3676 { | |
3677 guicolor_T fg_pixel = INVALCOLOR; | |
3678 guicolor_T bg_pixel = INVALCOLOR; | |
1966 | 3679 guint pixel_width; |
3680 guint pixel_height; | |
7 | 3681 |
3682 /* | |
3683 * Allow setting a window role on the command line, or invent one | |
3684 * if none was specified. This is mainly useful for GNOME session | |
3685 * support; allowing the WM to restore window placement. | |
3686 */ | |
3687 if (role_argument != NULL) | |
3688 { | |
3689 gtk_window_set_role(GTK_WINDOW(gui.mainwin), role_argument); | |
3690 } | |
3691 else | |
3692 { | |
3693 char *role; | |
3694 | |
3695 /* Invent a unique-enough ID string for the role */ | |
3696 role = g_strdup_printf("vim-%u-%u-%u", | |
3697 (unsigned)mch_get_pid(), | |
3698 (unsigned)g_random_int(), | |
3699 (unsigned)time(NULL)); | |
3700 | |
3701 gtk_window_set_role(GTK_WINDOW(gui.mainwin), role); | |
3702 g_free(role); | |
3703 } | |
3704 | |
3705 if (gui_win_x != -1 && gui_win_y != -1) | |
3706 gtk_window_move(GTK_WINDOW(gui.mainwin), gui_win_x, gui_win_y); | |
3707 | |
3708 /* Determine user specified geometry, if present. */ | |
3709 if (gui.geom != NULL) | |
3710 { | |
3711 int mask; | |
3712 unsigned int w, h; | |
3713 int x = 0; | |
3714 int y = 0; | |
3715 | |
3716 mask = XParseGeometry((char *)gui.geom, &x, &y, &w, &h); | |
3717 | |
3718 if (mask & WidthValue) | |
3719 Columns = w; | |
3720 if (mask & HeightValue) | |
857 | 3721 { |
1884 | 3722 if (p_window > (long)h - 1 || !option_was_set((char_u *)"window")) |
857 | 3723 p_window = h - 1; |
7 | 3724 Rows = h; |
857 | 3725 } |
5070
cf52d2a8c05c
updated for version 7.3.1278
Bram Moolenaar <bram@vim.org>
parents:
4474
diff
changeset
|
3726 limit_screen_size(); |
1426 | 3727 |
3728 pixel_width = (guint)(gui_get_base_width() + Columns * gui.char_width); | |
3729 pixel_height = (guint)(gui_get_base_height() + Rows * gui.char_height); | |
3730 | |
3731 pixel_width += get_menu_tool_width(); | |
3732 pixel_height += get_menu_tool_height(); | |
3733 | |
7 | 3734 if (mask & (XValue | YValue)) |
1426 | 3735 { |
1757 | 3736 int ww, hh; |
3737 gui_mch_get_screen_dimensions(&ww, &hh); | |
3738 hh += p_ghr + get_menu_tool_height(); | |
3739 ww += get_menu_tool_width(); | |
1426 | 3740 if (mask & XNegative) |
1757 | 3741 x += ww - pixel_width; |
1426 | 3742 if (mask & YNegative) |
1757 | 3743 y += hh - pixel_height; |
7 | 3744 gtk_window_move(GTK_WINDOW(gui.mainwin), x, y); |
1426 | 3745 } |
7 | 3746 vim_free(gui.geom); |
3747 gui.geom = NULL; | |
791 | 3748 |
856 | 3749 /* From now until everyone's stopped trying to set the window hints |
3750 * to their correct minimum values, stop them being set as we need | |
3751 * them to remain at our required size for the parent GtkSocket to | |
3752 * give us the right initial size. | |
3753 */ | |
791 | 3754 if (gtk_socket_id != 0 && (mask & WidthValue || mask & HeightValue)) |
856 | 3755 { |
3756 update_window_manager_hints(pixel_width, pixel_height); | |
3757 init_window_hints_state = 1; | |
3758 g_timeout_add(1000, check_startup_plug_hints, NULL); | |
3759 } | |
7 | 3760 } |
3761 | |
1966 | 3762 pixel_width = (guint)(gui_get_base_width() + Columns * gui.char_width); |
3763 pixel_height = (guint)(gui_get_base_height() + Rows * gui.char_height); | |
3764 /* For GTK2 changing the size of the form widget doesn't cause window | |
3765 * resizing. */ | |
2254
4620acaf4814
One more fix for conceal patch.
Bram Moolenaar <bram@vim.org>
parents:
2248
diff
changeset
|
3766 if (gtk_socket_id == 0) |
1966 | 3767 gtk_window_resize(GTK_WINDOW(gui.mainwin), pixel_width, pixel_height); |
791 | 3768 update_window_manager_hints(0, 0); |
7 | 3769 |
3770 if (foreground_argument != NULL) | |
3771 fg_pixel = gui_get_color((char_u *)foreground_argument); | |
3772 if (fg_pixel == INVALCOLOR) | |
3773 fg_pixel = gui_get_color((char_u *)"Black"); | |
3774 | |
3775 if (background_argument != NULL) | |
3776 bg_pixel = gui_get_color((char_u *)background_argument); | |
3777 if (bg_pixel == INVALCOLOR) | |
3778 bg_pixel = gui_get_color((char_u *)"White"); | |
3779 | |
3780 if (found_reverse_arg) | |
3781 { | |
3782 gui.def_norm_pixel = bg_pixel; | |
3783 gui.def_back_pixel = fg_pixel; | |
3784 } | |
3785 else | |
3786 { | |
3787 gui.def_norm_pixel = fg_pixel; | |
3788 gui.def_back_pixel = bg_pixel; | |
3789 } | |
3790 | |
3791 /* Get the colors from the "Normal" and "Menu" group (set in syntax.c or | |
3792 * in a vimrc file) */ | |
3793 set_normal_colors(); | |
3794 | |
3795 /* Check that none of the colors are the same as the background color */ | |
3796 gui_check_colors(); | |
3797 | |
3798 /* Get the colors for the highlight groups (gui_check_colors() might have | |
3799 * changed them). */ | |
3800 highlight_gui_started(); /* re-init colors and fonts */ | |
3801 | |
3802 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "destroy", | |
3803 GTK_SIGNAL_FUNC(mainwin_destroy_cb), NULL); | |
3804 | |
3805 #ifdef FEAT_HANGULIN | |
3806 hangul_keyboard_set(); | |
3807 #endif | |
3808 | |
3809 /* | |
3810 * Notify the fixed area about the need to resize the contents of the | |
3811 * gui.formwin, which we use for random positioning of the included | |
3812 * components. | |
3813 * | |
3814 * We connect this signal deferred finally after anything is in place, | |
3815 * since this is intended to handle resizements coming from the window | |
3816 * manager upon us and should not interfere with what VIM is requesting | |
3817 * upon startup. | |
3818 */ | |
3819 gtk_signal_connect(GTK_OBJECT(gui.formwin), "configure_event", | |
3820 GTK_SIGNAL_FUNC(form_configure_event), NULL); | |
3821 | |
3822 #ifdef FEAT_DND | |
2183 | 3823 /* Set up for receiving DND items. */ |
3824 gui_gtk_set_dnd_targets(); | |
7 | 3825 |
3826 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "drag_data_received", | |
3827 GTK_SIGNAL_FUNC(drag_data_received_cb), NULL); | |
3828 #endif | |
3829 | |
3830 /* With GTK+ 2, we need to iconify the window before calling show() | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3831 * to avoid mapping the window for a short time. */ |
7 | 3832 if (found_iconic_arg && gtk_socket_id == 0) |
3833 gui_mch_iconify(); | |
3834 | |
3835 { | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3836 #if defined(FEAT_GUI_GNOME) && defined(FEAT_MENU) |
7 | 3837 unsigned long menu_handler = 0; |
3838 # ifdef FEAT_TOOLBAR | |
3839 unsigned long tool_handler = 0; | |
3840 # endif | |
3841 /* | |
3842 * Urgh hackish :/ For some reason BonoboDockLayout always forces a | |
3843 * show when restoring the saved layout configuration. We can't just | |
3844 * hide the widgets again after gtk_widget_show(gui.mainwin) since it's | |
3845 * a toplevel window and thus will be realized immediately. Instead, | |
3846 * connect signal handlers to hide the widgets just after they've been | |
3847 * marked visible, but before the main window is realized. | |
3848 */ | |
3849 if (using_gnome && vim_strchr(p_go, GO_MENUS) == NULL) | |
3850 menu_handler = g_signal_connect_after(gui.menubar_h, "show", | |
3851 G_CALLBACK(>k_widget_hide), | |
3852 NULL); | |
3853 # ifdef FEAT_TOOLBAR | |
3854 if (using_gnome && vim_strchr(p_go, GO_TOOLBAR) == NULL | |
3855 && (toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS))) | |
3856 tool_handler = g_signal_connect_after(gui.toolbar_h, "show", | |
3857 G_CALLBACK(>k_widget_hide), | |
3858 NULL); | |
3859 # endif | |
3860 #endif | |
3861 gtk_widget_show(gui.mainwin); | |
3862 | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3863 #if defined(FEAT_GUI_GNOME) && defined(FEAT_MENU) |
7 | 3864 if (menu_handler != 0) |
3865 g_signal_handler_disconnect(gui.menubar_h, menu_handler); | |
3866 # ifdef FEAT_TOOLBAR | |
3867 if (tool_handler != 0) | |
3868 g_signal_handler_disconnect(gui.toolbar_h, tool_handler); | |
3869 # endif | |
3870 #endif | |
3871 } | |
3872 | |
3873 return OK; | |
3874 } | |
3875 | |
3876 | |
3877 void | |
1884 | 3878 gui_mch_exit(int rc UNUSED) |
7 | 3879 { |
3880 if (gui.mainwin != NULL) | |
3881 gtk_widget_destroy(gui.mainwin); | |
3882 } | |
3883 | |
3884 /* | |
3885 * Get the position of the top left corner of the window. | |
3886 */ | |
3887 int | |
3888 gui_mch_get_winpos(int *x, int *y) | |
3889 { | |
3890 gtk_window_get_position(GTK_WINDOW(gui.mainwin), x, y); | |
3891 return OK; | |
3892 } | |
3893 | |
3894 /* | |
3895 * Set the position of the top left corner of the window to the given | |
3896 * coordinates. | |
3897 */ | |
3898 void | |
3899 gui_mch_set_winpos(int x, int y) | |
3900 { | |
3901 gtk_window_move(GTK_WINDOW(gui.mainwin), x, y); | |
3902 } | |
3903 | |
3904 #if 0 | |
3905 static int resize_idle_installed = FALSE; | |
3906 /* | |
3907 * Idle handler to force resize. Used by gui_mch_set_shellsize() to ensure | |
3908 * the shell size doesn't exceed the window size, i.e. if the window manager | |
3909 * ignored our size request. Usually this happens if the window is maximized. | |
3910 * | |
3911 * FIXME: It'd be nice if we could find a little more orthodox solution. | |
3912 * See also the remark below in gui_mch_set_shellsize(). | |
3913 * | |
3914 * DISABLED: When doing ":set lines+=1" this function would first invoke | |
3915 * gui_resize_shell() with the old size, then the normal callback would | |
3916 * report the new size through form_configure_event(). That caused the window | |
3917 * layout to be messed up. | |
3918 */ | |
3919 static gboolean | |
3920 force_shell_resize_idle(gpointer data) | |
3921 { | |
3922 if (gui.mainwin != NULL | |
3923 && GTK_WIDGET_REALIZED(gui.mainwin) | |
3924 && GTK_WIDGET_VISIBLE(gui.mainwin)) | |
3925 { | |
3926 int width; | |
3927 int height; | |
3928 | |
3929 gtk_window_get_size(GTK_WINDOW(gui.mainwin), &width, &height); | |
3930 | |
3931 width -= get_menu_tool_width(); | |
3932 height -= get_menu_tool_height(); | |
3933 | |
3934 gui_resize_shell(width, height); | |
3935 } | |
3936 | |
3937 resize_idle_installed = FALSE; | |
3938 return FALSE; /* don't call me again */ | |
3939 } | |
3940 #endif | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3941 |
1967 | 3942 /* |
3943 * Return TRUE if the main window is maximized. | |
3944 */ | |
3945 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
3946 gui_mch_maximized(void) |
1967 | 3947 { |
3948 return (gui.mainwin != NULL && gui.mainwin->window != NULL | |
3949 && (gdk_window_get_state(gui.mainwin->window) | |
3950 & GDK_WINDOW_STATE_MAXIMIZED)); | |
3951 } | |
3952 | |
3953 /* | |
3954 * Unmaximize the main window | |
3955 */ | |
3956 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
3957 gui_mch_unmaximize(void) |
1967 | 3958 { |
3959 if (gui.mainwin != NULL) | |
3960 gtk_window_unmaximize(GTK_WINDOW(gui.mainwin)); | |
3961 } | |
3962 | |
7 | 3963 /* |
3014 | 3964 * Called when the font changed while the window is maximized. Compute the |
3965 * new Rows and Columns. This is like resizing the window. | |
3966 */ | |
3967 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
3968 gui_mch_newfont(void) |
3014 | 3969 { |
3970 int w, h; | |
3971 | |
3972 gtk_window_get_size(GTK_WINDOW(gui.mainwin), &w, &h); | |
3973 w -= get_menu_tool_width(); | |
3974 h -= get_menu_tool_height(); | |
3975 gui_resize_shell(w, h); | |
3976 } | |
3977 | |
3978 /* | |
7 | 3979 * Set the windows size. |
3980 */ | |
3981 void | |
3982 gui_mch_set_shellsize(int width, int height, | |
1884 | 3983 int min_width UNUSED, int min_height UNUSED, |
3984 int base_width UNUSED, int base_height UNUSED, | |
3985 int direction UNUSED) | |
7 | 3986 { |
3987 /* give GTK+ a chance to put all widget's into place */ | |
3988 gui_mch_update(); | |
3989 | |
791 | 3990 /* this will cause the proper resizement to happen too */ |
3991 if (gtk_socket_id == 0) | |
856 | 3992 update_window_manager_hints(0, 0); |
791 | 3993 |
7 | 3994 /* With GTK+ 2, changing the size of the form widget doesn't resize |
791 | 3995 * the window. So let's do it the other way around and resize the |
7 | 3996 * main window instead. */ |
3997 width += get_menu_tool_width(); | |
3998 height += get_menu_tool_height(); | |
3999 | |
791 | 4000 if (gtk_socket_id == 0) |
856 | 4001 gtk_window_resize(GTK_WINDOW(gui.mainwin), width, height); |
791 | 4002 else |
856 | 4003 update_window_manager_hints(width, height); |
7 | 4004 |
2183 | 4005 # if 0 |
7 | 4006 if (!resize_idle_installed) |
4007 { | |
4008 g_idle_add_full(GDK_PRIORITY_EVENTS + 10, | |
4009 &force_shell_resize_idle, NULL, NULL); | |
4010 resize_idle_installed = TRUE; | |
4011 } | |
2183 | 4012 # endif |
7 | 4013 /* |
4014 * Wait until all events are processed to prevent a crash because the | |
4015 * real size of the drawing area doesn't reflect Vim's internal ideas. | |
4016 * | |
4017 * This is a bit of a hack, since Vim is a terminal application with a GUI | |
4018 * on top, while the GUI expects to be the boss. | |
4019 */ | |
4020 gui_mch_update(); | |
4021 } | |
4022 | |
4023 | |
4024 /* | |
4025 * The screen size is used to make sure the initial window doesn't get bigger | |
4026 * than the screen. This subtracts some room for menubar, toolbar and window | |
4027 * decorations. | |
4028 */ | |
4029 void | |
4030 gui_mch_get_screen_dimensions(int *screen_w, int *screen_h) | |
4031 { | |
4032 #ifdef HAVE_GTK_MULTIHEAD | |
4033 GdkScreen* screen; | |
4034 | |
4035 if (gui.mainwin != NULL && gtk_widget_has_screen(gui.mainwin)) | |
4036 screen = gtk_widget_get_screen(gui.mainwin); | |
4037 else | |
4038 screen = gdk_screen_get_default(); | |
4039 | |
4040 *screen_w = gdk_screen_get_width(screen); | |
4041 *screen_h = gdk_screen_get_height(screen) - p_ghr; | |
4042 #else | |
4043 *screen_w = gdk_screen_width(); | |
4044 /* Subtract 'guiheadroom' from the height to allow some room for the | |
4045 * window manager (task list and window title bar). */ | |
4046 *screen_h = gdk_screen_height() - p_ghr; | |
4047 #endif | |
4048 | |
4049 /* | |
4050 * FIXME: dirty trick: Because the gui_get_base_height() doesn't include | |
4051 * the toolbar and menubar for GTK, we subtract them from the screen | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
4052 * height, so that the window size can be made to fit on the screen. |
7 | 4053 * This should be completely changed later. |
4054 */ | |
4055 *screen_w -= get_menu_tool_width(); | |
4056 *screen_h -= get_menu_tool_height(); | |
4057 } | |
4058 | |
4059 #if defined(FEAT_TITLE) || defined(PROTO) | |
4060 void | |
1884 | 4061 gui_mch_settitle(char_u *title, char_u *icon UNUSED) |
7 | 4062 { |
4063 if (title != NULL && output_conv.vc_type != CONV_NONE) | |
4064 title = string_convert(&output_conv, title, NULL); | |
4065 | |
4066 gtk_window_set_title(GTK_WINDOW(gui.mainwin), (const char *)title); | |
4067 | |
4068 if (output_conv.vc_type != CONV_NONE) | |
4069 vim_free(title); | |
4070 } | |
4071 #endif /* FEAT_TITLE */ | |
4072 | |
4073 #if defined(FEAT_MENU) || defined(PROTO) | |
4074 void | |
4075 gui_mch_enable_menu(int showit) | |
4076 { | |
4077 GtkWidget *widget; | |
4078 | |
4079 # ifdef FEAT_GUI_GNOME | |
4080 if (using_gnome) | |
4081 widget = gui.menubar_h; | |
4082 else | |
4083 # endif | |
4084 widget = gui.menubar; | |
4085 | |
827 | 4086 /* Do not disable the menu while starting up, otherwise F10 doesn't work. */ |
4087 if (!showit != !GTK_WIDGET_VISIBLE(widget) && !gui.starting) | |
7 | 4088 { |
4089 if (showit) | |
4090 gtk_widget_show(widget); | |
4091 else | |
4092 gtk_widget_hide(widget); | |
4093 | |
791 | 4094 update_window_manager_hints(0, 0); |
7 | 4095 } |
4096 } | |
4097 #endif /* FEAT_MENU */ | |
4098 | |
4099 #if defined(FEAT_TOOLBAR) || defined(PROTO) | |
4100 void | |
4101 gui_mch_show_toolbar(int showit) | |
4102 { | |
4103 GtkWidget *widget; | |
4104 | |
4105 if (gui.toolbar == NULL) | |
4106 return; | |
4107 | |
4108 # ifdef FEAT_GUI_GNOME | |
4109 if (using_gnome) | |
4110 widget = gui.toolbar_h; | |
4111 else | |
4112 # endif | |
4113 widget = gui.toolbar; | |
4114 | |
4115 if (showit) | |
4116 set_toolbar_style(GTK_TOOLBAR(gui.toolbar)); | |
4117 | |
4118 if (!showit != !GTK_WIDGET_VISIBLE(widget)) | |
4119 { | |
4120 if (showit) | |
4121 gtk_widget_show(widget); | |
4122 else | |
4123 gtk_widget_hide(widget); | |
4124 | |
791 | 4125 update_window_manager_hints(0, 0); |
7 | 4126 } |
4127 } | |
4128 #endif /* FEAT_TOOLBAR */ | |
4129 | |
4130 /* | |
4131 * Check if a given font is a CJK font. This is done in a very crude manner. It | |
4132 * just see if U+04E00 for zh and ja and U+AC00 for ko are covered in a given | |
4133 * font. Consequently, this function cannot be used as a general purpose check | |
4134 * for CJK-ness for which fontconfig APIs should be used. This is only used by | |
4135 * gui_mch_init_font() to deal with 'CJK fixed width fonts'. | |
4136 */ | |
4137 static int | |
4138 is_cjk_font(PangoFontDescription *font_desc) | |
4139 { | |
4140 static const char * const cjk_langs[] = | |
4141 {"zh_CN", "zh_TW", "zh_HK", "ja", "ko"}; | |
4142 | |
4143 PangoFont *font; | |
4144 unsigned i; | |
4145 int is_cjk = FALSE; | |
4146 | |
4147 font = pango_context_load_font(gui.text_context, font_desc); | |
4148 | |
4149 if (font == NULL) | |
4150 return FALSE; | |
4151 | |
4152 for (i = 0; !is_cjk && i < G_N_ELEMENTS(cjk_langs); ++i) | |
4153 { | |
4154 PangoCoverage *coverage; | |
4155 gunichar uc; | |
4156 | |
4157 coverage = pango_font_get_coverage( | |
4158 font, pango_language_from_string(cjk_langs[i])); | |
4159 | |
4160 if (coverage != NULL) | |
4161 { | |
4162 uc = (cjk_langs[i][0] == 'k') ? 0xAC00 : 0x4E00; | |
4163 is_cjk = (pango_coverage_get(coverage, uc) == PANGO_COVERAGE_EXACT); | |
4164 pango_coverage_unref(coverage); | |
4165 } | |
4166 } | |
4167 | |
4168 g_object_unref(font); | |
4169 | |
4170 return is_cjk; | |
4171 } | |
4172 | |
445 | 4173 /* |
4174 * Adjust gui.char_height (after 'linespace' was changed). | |
4175 */ | |
7 | 4176 int |
445 | 4177 gui_mch_adjust_charheight(void) |
7 | 4178 { |
4179 PangoFontMetrics *metrics; | |
4180 int ascent; | |
4181 int descent; | |
4182 | |
4183 metrics = pango_context_get_metrics(gui.text_context, gui.norm_font, | |
4184 pango_context_get_language(gui.text_context)); | |
4185 ascent = pango_font_metrics_get_ascent(metrics); | |
4186 descent = pango_font_metrics_get_descent(metrics); | |
4187 | |
4188 pango_font_metrics_unref(metrics); | |
4189 | |
4190 gui.char_height = (ascent + descent + PANGO_SCALE - 1) / PANGO_SCALE | |
445 | 4191 + p_linespace; |
136 | 4192 /* LINTED: avoid warning: bitwise operation on signed value */ |
7 | 4193 gui.char_ascent = PANGO_PIXELS(ascent + p_linespace * PANGO_SCALE / 2); |
4194 | |
4195 /* A not-positive value of char_height may crash Vim. Only happens | |
4196 * if 'linespace' is negative (which does make sense sometimes). */ | |
4197 gui.char_ascent = MAX(gui.char_ascent, 0); | |
4198 gui.char_height = MAX(gui.char_height, gui.char_ascent + 1); | |
4199 | |
4200 return OK; | |
4201 } | |
4202 | |
4203 /* | |
4204 * Put up a font dialog and return the selected font name in allocated memory. | |
4205 * "oldval" is the previous value. Return NULL when cancelled. | |
4206 * This should probably go into gui_gtk.c. Hmm. | |
4207 * FIXME: | |
4208 * The GTK2 font selection dialog has no filtering API. So we could either | |
4209 * a) implement our own (possibly copying the code from somewhere else) or | |
4210 * b) just live with it. | |
4211 */ | |
4212 char_u * | |
4213 gui_mch_font_dialog(char_u *oldval) | |
4214 { | |
4215 GtkWidget *dialog; | |
4216 int response; | |
4217 char_u *fontname = NULL; | |
4218 char_u *oldname; | |
4219 | |
4220 dialog = gtk_font_selection_dialog_new(NULL); | |
4221 | |
4222 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gui.mainwin)); | |
4223 gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE); | |
4224 | |
4225 if (oldval != NULL && oldval[0] != NUL) | |
4226 { | |
4227 if (output_conv.vc_type != CONV_NONE) | |
4228 oldname = string_convert(&output_conv, oldval, NULL); | |
4229 else | |
4230 oldname = oldval; | |
4231 | |
4232 /* Annoying bug in GTK (or Pango): if the font name does not include a | |
4233 * size, zero is used. Use default point size ten. */ | |
4234 if (!vim_isdigit(oldname[STRLEN(oldname) - 1])) | |
4235 { | |
4236 char_u *p = vim_strnsave(oldname, STRLEN(oldname) + 3); | |
4237 | |
4238 if (p != NULL) | |
4239 { | |
4240 STRCPY(p + STRLEN(p), " 10"); | |
4241 if (oldname != oldval) | |
4242 vim_free(oldname); | |
4243 oldname = p; | |
4244 } | |
4245 } | |
4246 | |
4247 gtk_font_selection_dialog_set_font_name( | |
4248 GTK_FONT_SELECTION_DIALOG(dialog), (const char *)oldname); | |
4249 | |
4250 if (oldname != oldval) | |
100 | 4251 vim_free(oldname); |
7 | 4252 } |
1959 | 4253 else |
4254 gtk_font_selection_dialog_set_font_name( | |
4255 GTK_FONT_SELECTION_DIALOG(dialog), DEFAULT_FONT); | |
7 | 4256 |
4257 response = gtk_dialog_run(GTK_DIALOG(dialog)); | |
4258 | |
4259 if (response == GTK_RESPONSE_OK) | |
4260 { | |
4261 char *name; | |
4262 | |
4263 name = gtk_font_selection_dialog_get_font_name( | |
4264 GTK_FONT_SELECTION_DIALOG(dialog)); | |
4265 if (name != NULL) | |
4266 { | |
714 | 4267 char_u *p; |
4268 | |
4269 /* Apparently some font names include a comma, need to escape | |
4270 * that, because in 'guifont' it separates names. */ | |
4271 p = vim_strsave_escaped((char_u *)name, (char_u *)","); | |
4272 g_free(name); | |
840 | 4273 if (p != NULL && input_conv.vc_type != CONV_NONE) |
714 | 4274 { |
4275 fontname = string_convert(&input_conv, p, NULL); | |
4276 vim_free(p); | |
4277 } | |
7 | 4278 else |
714 | 4279 fontname = p; |
7 | 4280 } |
4281 } | |
4282 | |
4283 if (response != GTK_RESPONSE_NONE) | |
4284 gtk_widget_destroy(dialog); | |
4285 | |
4286 return fontname; | |
4287 } | |
4288 | |
4289 /* | |
4290 * Some monospace fonts don't support a bold weight, and fall back | |
4291 * silently to the regular weight. But this is no good since our text | |
4292 * drawing function can emulate bold by overstriking. So let's try | |
4293 * to detect whether bold weight is actually available and emulate it | |
4294 * otherwise. | |
4295 * | |
4296 * Note that we don't need to check for italic style since Xft can | |
4297 * emulate italic on its own, provided you have a proper fontconfig | |
4298 * setup. We wouldn't be able to emulate it in Vim anyway. | |
4299 */ | |
4300 static void | |
4301 get_styled_font_variants(void) | |
4302 { | |
4303 PangoFontDescription *bold_font_desc; | |
4304 PangoFont *plain_font; | |
4305 PangoFont *bold_font; | |
4306 | |
4307 gui.font_can_bold = FALSE; | |
4308 | |
4309 plain_font = pango_context_load_font(gui.text_context, gui.norm_font); | |
4310 | |
4311 if (plain_font == NULL) | |
4312 return; | |
4313 | |
4314 bold_font_desc = pango_font_description_copy_static(gui.norm_font); | |
4315 pango_font_description_set_weight(bold_font_desc, PANGO_WEIGHT_BOLD); | |
4316 | |
4317 bold_font = pango_context_load_font(gui.text_context, bold_font_desc); | |
4318 /* | |
4319 * The comparison relies on the unique handle nature of a PangoFont*, | |
4320 * i.e. it's assumed that a different PangoFont* won't refer to the | |
4321 * same font. Seems to work, and failing here isn't critical anyway. | |
4322 */ | |
4323 if (bold_font != NULL) | |
4324 { | |
4325 gui.font_can_bold = (bold_font != plain_font); | |
4326 g_object_unref(bold_font); | |
4327 } | |
4328 | |
4329 pango_font_description_free(bold_font_desc); | |
4330 g_object_unref(plain_font); | |
4331 } | |
4332 | |
4333 static PangoEngineShape *default_shape_engine = NULL; | |
4334 | |
4335 /* | |
4336 * Create a map from ASCII characters in the range [32,126] to glyphs | |
4337 * of the current font. This is used by gui_gtk2_draw_string() to skip | |
4338 * the itemize and shaping process for the most common case. | |
4339 */ | |
4340 static void | |
4341 ascii_glyph_table_init(void) | |
4342 { | |
4343 char_u ascii_chars[128]; | |
4344 PangoAttrList *attr_list; | |
4345 GList *item_list; | |
4346 int i; | |
4347 | |
4348 if (gui.ascii_glyphs != NULL) | |
4349 pango_glyph_string_free(gui.ascii_glyphs); | |
4350 if (gui.ascii_font != NULL) | |
4351 g_object_unref(gui.ascii_font); | |
4352 | |
4353 gui.ascii_glyphs = NULL; | |
4354 gui.ascii_font = NULL; | |
4355 | |
4356 /* For safety, fill in question marks for the control characters. */ | |
4357 for (i = 0; i < 32; ++i) | |
4358 ascii_chars[i] = '?'; | |
4359 for (; i < 127; ++i) | |
4360 ascii_chars[i] = i; | |
4361 ascii_chars[i] = '?'; | |
4362 | |
4363 attr_list = pango_attr_list_new(); | |
4364 item_list = pango_itemize(gui.text_context, (const char *)ascii_chars, | |
4365 0, sizeof(ascii_chars), attr_list, NULL); | |
4366 | |
4367 if (item_list != NULL && item_list->next == NULL) /* play safe */ | |
4368 { | |
4369 PangoItem *item; | |
4370 int width; | |
4371 | |
4372 item = (PangoItem *)item_list->data; | |
4373 width = gui.char_width * PANGO_SCALE; | |
4374 | |
4375 /* Remember the shape engine used for ASCII. */ | |
4376 default_shape_engine = item->analysis.shape_engine; | |
4377 | |
4378 gui.ascii_font = item->analysis.font; | |
4379 g_object_ref(gui.ascii_font); | |
4380 | |
4381 gui.ascii_glyphs = pango_glyph_string_new(); | |
4382 | |
4383 pango_shape((const char *)ascii_chars, sizeof(ascii_chars), | |
4384 &item->analysis, gui.ascii_glyphs); | |
4385 | |
4386 g_return_if_fail(gui.ascii_glyphs->num_glyphs == sizeof(ascii_chars)); | |
4387 | |
4388 for (i = 0; i < gui.ascii_glyphs->num_glyphs; ++i) | |
4389 { | |
4390 PangoGlyphGeometry *geom; | |
4391 | |
4392 geom = &gui.ascii_glyphs->glyphs[i].geometry; | |
4393 geom->x_offset += MAX(0, width - geom->width) / 2; | |
4394 geom->width = width; | |
4395 } | |
4396 } | |
4397 | |
4398 g_list_foreach(item_list, (GFunc)&pango_item_free, NULL); | |
4399 g_list_free(item_list); | |
4400 pango_attr_list_unref(attr_list); | |
4401 } | |
4402 | |
4403 /* | |
4404 * Initialize Vim to use the font or fontset with the given name. | |
4405 * Return FAIL if the font could not be loaded, OK otherwise. | |
4406 */ | |
4407 int | |
1884 | 4408 gui_mch_init_font(char_u *font_name, int fontset UNUSED) |
7 | 4409 { |
4410 PangoFontDescription *font_desc; | |
4411 PangoLayout *layout; | |
4412 int width; | |
4413 | |
4414 /* If font_name is NULL, this means to use the default, which should | |
4415 * be present on all proper Pango/fontconfig installations. */ | |
4416 if (font_name == NULL) | |
4417 font_name = (char_u *)DEFAULT_FONT; | |
4418 | |
4419 font_desc = gui_mch_get_font(font_name, FALSE); | |
4420 | |
4421 if (font_desc == NULL) | |
4422 return FAIL; | |
4423 | |
4424 gui_mch_free_font(gui.norm_font); | |
4425 gui.norm_font = font_desc; | |
4426 | |
4427 pango_context_set_font_description(gui.text_context, font_desc); | |
4428 | |
4429 layout = pango_layout_new(gui.text_context); | |
4430 pango_layout_set_text(layout, "MW", 2); | |
4431 pango_layout_get_size(layout, &width, NULL); | |
4432 /* | |
4433 * Set char_width to half the width obtained from pango_layout_get_size() | |
4434 * for CJK fixed_width/bi-width fonts. An unpatched version of Xft leads | |
4435 * Pango to use the same width for both non-CJK characters (e.g. Latin | |
4436 * letters and numbers) and CJK characters. This results in 's p a c e d | |
4437 * o u t' rendering when a CJK 'fixed width' font is used. To work around | |
4438 * that, divide the width returned by Pango by 2 if cjk_width is equal to | |
4439 * width for CJK fonts. | |
4440 * | |
4441 * For related bugs, see: | |
4442 * http://bugzilla.gnome.org/show_bug.cgi?id=106618 | |
4443 * http://bugzilla.gnome.org/show_bug.cgi?id=106624 | |
4444 * | |
4445 * With this, for all four of the following cases, Vim works fine: | |
4446 * guifont=CJK_fixed_width_font | |
4447 * guifont=Non_CJK_fixed_font | |
4448 * guifont=Non_CJK_fixed_font,CJK_Fixed_font | |
4449 * guifont=Non_CJK_fixed_font guifontwide=CJK_fixed_font | |
4450 */ | |
4451 if (is_cjk_font(gui.norm_font)) | |
4452 { | |
4453 int cjk_width; | |
4454 | |
4455 /* Measure the text extent of U+4E00 and U+4E8C */ | |
4456 pango_layout_set_text(layout, "\344\270\200\344\272\214", -1); | |
4457 pango_layout_get_size(layout, &cjk_width, NULL); | |
4458 | |
4459 if (width == cjk_width) /* Xft not patched */ | |
4460 width /= 2; | |
4461 } | |
4462 g_object_unref(layout); | |
4463 | |
4464 gui.char_width = (width / 2 + PANGO_SCALE - 1) / PANGO_SCALE; | |
4465 | |
4466 /* A zero width may cause a crash. Happens for semi-invalid fontsets. */ | |
4467 if (gui.char_width <= 0) | |
4468 gui.char_width = 8; | |
4469 | |
445 | 4470 gui_mch_adjust_charheight(); |
7 | 4471 |
4472 /* Set the fontname, which will be used for information purposes */ | |
4473 hl_set_font_name(font_name); | |
4474 | |
4475 get_styled_font_variants(); | |
4476 ascii_glyph_table_init(); | |
4477 | |
4478 /* Avoid unnecessary overhead if 'guifontwide' is equal to 'guifont'. */ | |
4479 if (gui.wide_font != NULL | |
4480 && pango_font_description_equal(gui.norm_font, gui.wide_font)) | |
4481 { | |
4482 pango_font_description_free(gui.wide_font); | |
4483 gui.wide_font = NULL; | |
4484 } | |
4485 | |
1986 | 4486 if (gui_mch_maximized()) |
4487 { | |
4488 /* Update lines and columns in accordance with the new font, keep the | |
4489 * window maximized. */ | |
3014 | 4490 gui_mch_newfont(); |
1986 | 4491 } |
4492 else | |
4493 { | |
4494 /* Preserve the logical dimensions of the screen. */ | |
4495 update_window_manager_hints(0, 0); | |
4496 } | |
7 | 4497 |
4498 return OK; | |
4499 } | |
4500 | |
4501 /* | |
4502 * Get a reference to the font "name". | |
4503 * Return zero for failure. | |
4504 */ | |
4505 GuiFont | |
4506 gui_mch_get_font(char_u *name, int report_error) | |
4507 { | |
4508 PangoFontDescription *font; | |
4509 | |
4510 /* can't do this when GUI is not running */ | |
4511 if (!gui.in_use || name == NULL) | |
4512 return NULL; | |
4513 | |
4514 if (output_conv.vc_type != CONV_NONE) | |
4515 { | |
4516 char_u *buf; | |
4517 | |
4518 buf = string_convert(&output_conv, name, NULL); | |
4519 if (buf != NULL) | |
4520 { | |
4521 font = pango_font_description_from_string((const char *)buf); | |
4522 vim_free(buf); | |
4523 } | |
4524 else | |
4525 font = NULL; | |
4526 } | |
4527 else | |
4528 font = pango_font_description_from_string((const char *)name); | |
4529 | |
4530 if (font != NULL) | |
4531 { | |
4532 PangoFont *real_font; | |
4533 | |
4534 /* pango_context_load_font() bails out if no font size is set */ | |
4535 if (pango_font_description_get_size(font) <= 0) | |
4536 pango_font_description_set_size(font, 10 * PANGO_SCALE); | |
4537 | |
4538 real_font = pango_context_load_font(gui.text_context, font); | |
4539 | |
4540 if (real_font == NULL) | |
4541 { | |
4542 pango_font_description_free(font); | |
4543 font = NULL; | |
4544 } | |
4545 else | |
4546 g_object_unref(real_font); | |
4547 } | |
4548 | |
4549 if (font == NULL) | |
4550 { | |
4551 if (report_error) | |
1666 | 4552 EMSG2(_((char *)e_font), name); |
7 | 4553 return NULL; |
4554 } | |
4555 | |
4556 return font; | |
4557 } | |
4558 | |
39 | 4559 #if defined(FEAT_EVAL) || defined(PROTO) |
38 | 4560 /* |
4561 * Return the name of font "font" in allocated memory. | |
4562 */ | |
4563 char_u * | |
1884 | 4564 gui_mch_get_fontname(GuiFont font, char_u *name UNUSED) |
38 | 4565 { |
4566 if (font != NOFONT) | |
4567 { | |
944 | 4568 char *pangoname = pango_font_description_to_string(font); |
4569 | |
4570 if (pangoname != NULL) | |
38 | 4571 { |
944 | 4572 char_u *s = vim_strsave((char_u *)pangoname); |
4573 | |
4574 g_free(pangoname); | |
38 | 4575 return s; |
4576 } | |
4577 } | |
4578 return NULL; | |
4579 } | |
39 | 4580 #endif |
38 | 4581 |
7 | 4582 /* |
4583 * If a font is not going to be used, free its structure. | |
4584 */ | |
4585 void | |
4586 gui_mch_free_font(GuiFont font) | |
4587 { | |
4588 if (font != NOFONT) | |
4589 pango_font_description_free(font); | |
4590 } | |
4591 | |
4592 /* | |
4593 * Return the Pixel value (color) for the given color name. This routine was | |
4594 * pretty much taken from example code in the Silicon Graphics OSF/Motif | |
4595 * Programmer's Guide. | |
4596 * Return INVALCOLOR for error. | |
4597 */ | |
4598 guicolor_T | |
4599 gui_mch_get_color(char_u *name) | |
4600 { | |
4601 /* A number of colors that some X11 systems don't have */ | |
4602 static const char *const vimnames[][2] = | |
4603 { | |
834 | 4604 {"LightRed", "#FFBBBB"}, |
4605 {"LightGreen", "#88FF88"}, | |
4606 {"LightMagenta","#FFBBFF"}, | |
4607 {"DarkCyan", "#008888"}, | |
4608 {"DarkBlue", "#0000BB"}, | |
4609 {"DarkRed", "#BB0000"}, | |
4610 {"DarkMagenta", "#BB00BB"}, | |
4611 {"DarkGrey", "#BBBBBB"}, | |
4612 {"DarkYellow", "#BBBB00"}, | |
4613 {"Gray10", "#1A1A1A"}, | |
4614 {"Grey10", "#1A1A1A"}, | |
4615 {"Gray20", "#333333"}, | |
4616 {"Grey20", "#333333"}, | |
4617 {"Gray30", "#4D4D4D"}, | |
4618 {"Grey30", "#4D4D4D"}, | |
4619 {"Gray40", "#666666"}, | |
4620 {"Grey40", "#666666"}, | |
4621 {"Gray50", "#7F7F7F"}, | |
4622 {"Grey50", "#7F7F7F"}, | |
4623 {"Gray60", "#999999"}, | |
4624 {"Grey60", "#999999"}, | |
4625 {"Gray70", "#B3B3B3"}, | |
4626 {"Grey70", "#B3B3B3"}, | |
4627 {"Gray80", "#CCCCCC"}, | |
4628 {"Grey80", "#CCCCCC"}, | |
4629 {"Gray90", "#E5E5E5"}, | |
4630 {"Grey90", "#E5E5E5"}, | |
7 | 4631 {NULL, NULL} |
4632 }; | |
4633 | |
4634 if (!gui.in_use) /* can't do this when GUI not running */ | |
4635 return INVALCOLOR; | |
4636 | |
4637 while (name != NULL) | |
4638 { | |
4639 GdkColor color; | |
4640 int parsed; | |
4641 int i; | |
4642 | |
4643 parsed = gdk_color_parse((const char *)name, &color); | |
4644 | |
4645 if (parsed) | |
4646 { | |
4647 gdk_colormap_alloc_color(gtk_widget_get_colormap(gui.drawarea), | |
4648 &color, FALSE, TRUE); | |
4649 return (guicolor_T)color.pixel; | |
4650 } | |
4651 /* add a few builtin names and try again */ | |
4652 for (i = 0; ; ++i) | |
4653 { | |
4654 if (vimnames[i][0] == NULL) | |
4655 { | |
4656 name = NULL; | |
4657 break; | |
4658 } | |
4659 if (STRICMP(name, vimnames[i][0]) == 0) | |
4660 { | |
4661 name = (char_u *)vimnames[i][1]; | |
4662 break; | |
4663 } | |
4664 } | |
4665 } | |
4666 | |
4667 return INVALCOLOR; | |
4668 } | |
4669 | |
4670 /* | |
4671 * Set the current text foreground color. | |
4672 */ | |
4673 void | |
4674 gui_mch_set_fg_color(guicolor_T color) | |
4675 { | |
4676 gui.fgcolor->pixel = (unsigned long)color; | |
4677 } | |
4678 | |
4679 /* | |
4680 * Set the current text background color. | |
4681 */ | |
4682 void | |
4683 gui_mch_set_bg_color(guicolor_T color) | |
4684 { | |
4685 gui.bgcolor->pixel = (unsigned long)color; | |
4686 } | |
4687 | |
207 | 4688 /* |
4689 * Set the current text special color. | |
4690 */ | |
4691 void | |
4692 gui_mch_set_sp_color(guicolor_T color) | |
4693 { | |
4694 gui.spcolor->pixel = (unsigned long)color; | |
4695 } | |
4696 | |
7 | 4697 /* |
4698 * Function-like convenience macro for the sake of efficiency. | |
4699 */ | |
4700 #define INSERT_PANGO_ATTR(Attribute, AttrList, Start, End) \ | |
4701 G_STMT_START{ \ | |
4702 PangoAttribute *tmp_attr_; \ | |
4703 tmp_attr_ = (Attribute); \ | |
4704 tmp_attr_->start_index = (Start); \ | |
4705 tmp_attr_->end_index = (End); \ | |
4706 pango_attr_list_insert((AttrList), tmp_attr_); \ | |
4707 }G_STMT_END | |
4708 | |
4709 static void | |
4710 apply_wide_font_attr(char_u *s, int len, PangoAttrList *attr_list) | |
4711 { | |
4712 char_u *start = NULL; | |
4713 char_u *p; | |
4714 int uc; | |
4715 | |
4716 for (p = s; p < s + len; p += utf_byte2len(*p)) | |
4717 { | |
4718 uc = utf_ptr2char(p); | |
4719 | |
4720 if (start == NULL) | |
4721 { | |
4722 if (uc >= 0x80 && utf_char2cells(uc) == 2) | |
4723 start = p; | |
4724 } | |
4725 else if (uc < 0x80 /* optimization shortcut */ | |
4726 || (utf_char2cells(uc) != 2 && !utf_iscomposing(uc))) | |
4727 { | |
4728 INSERT_PANGO_ATTR(pango_attr_font_desc_new(gui.wide_font), | |
4729 attr_list, start - s, p - s); | |
4730 start = NULL; | |
4731 } | |
4732 } | |
4733 | |
4734 if (start != NULL) | |
4735 INSERT_PANGO_ATTR(pango_attr_font_desc_new(gui.wide_font), | |
4736 attr_list, start - s, len); | |
4737 } | |
4738 | |
4739 static int | |
4740 count_cluster_cells(char_u *s, PangoItem *item, | |
4741 PangoGlyphString* glyphs, int i, | |
4742 int *cluster_width, | |
4743 int *last_glyph_rbearing) | |
4744 { | |
4745 char_u *p; | |
4746 int next; /* glyph start index of next cluster */ | |
4747 int start, end; /* string segment of current cluster */ | |
4748 int width; /* real cluster width in Pango units */ | |
4749 int uc; | |
4750 int cellcount = 0; | |
4751 | |
4752 width = glyphs->glyphs[i].geometry.width; | |
4753 | |
4754 for (next = i + 1; next < glyphs->num_glyphs; ++next) | |
4755 { | |
4756 if (glyphs->glyphs[next].attr.is_cluster_start) | |
4757 break; | |
4758 else if (glyphs->glyphs[next].geometry.width > width) | |
4759 width = glyphs->glyphs[next].geometry.width; | |
4760 } | |
4761 | |
4762 start = item->offset + glyphs->log_clusters[i]; | |
4763 end = item->offset + ((next < glyphs->num_glyphs) ? | |
4764 glyphs->log_clusters[next] : item->length); | |
4765 | |
4766 for (p = s + start; p < s + end; p += utf_byte2len(*p)) | |
4767 { | |
4768 uc = utf_ptr2char(p); | |
4769 if (uc < 0x80) | |
4770 ++cellcount; | |
4771 else if (!utf_iscomposing(uc)) | |
4772 cellcount += utf_char2cells(uc); | |
4773 } | |
4774 | |
4775 if (last_glyph_rbearing != NULL | |
4776 && cellcount > 0 && next == glyphs->num_glyphs) | |
4777 { | |
4778 PangoRectangle ink_rect; | |
4779 /* | |
4780 * If a certain combining mark had to be taken from a non-monospace | |
4781 * font, we have to compensate manually by adapting x_offset according | |
4782 * to the ink extents of the previous glyph. | |
4783 */ | |
4784 pango_font_get_glyph_extents(item->analysis.font, | |
4785 glyphs->glyphs[i].glyph, | |
4786 &ink_rect, NULL); | |
4787 | |
4788 if (PANGO_RBEARING(ink_rect) > 0) | |
4789 *last_glyph_rbearing = PANGO_RBEARING(ink_rect); | |
4790 } | |
4791 | |
4792 if (cellcount > 0) | |
4793 *cluster_width = width; | |
4794 | |
4795 return cellcount; | |
4796 } | |
4797 | |
4798 /* | |
4799 * If there are only combining characters in the cluster, we cannot just | |
4800 * change the width of the previous glyph since there is none. Therefore | |
4801 * some guesswork is needed. | |
4802 * | |
4803 * If ink_rect.x is negative Pango apparently has taken care of the composing | |
4804 * by itself. Actually setting x_offset = 0 should be sufficient then, but due | |
4805 * to problems with composing from different fonts we still need to fine-tune | |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
4806 * x_offset to avoid ugliness. |
7 | 4807 * |
4808 * If ink_rect.x is not negative, force overstriking by pointing x_offset to | |
4809 * the position of the previous glyph. Apparently this happens only with old | |
4810 * X fonts which don't provide the special combining information needed by | |
4811 * Pango. | |
4812 */ | |
4813 static void | |
4814 setup_zero_width_cluster(PangoItem *item, PangoGlyphInfo *glyph, | |
4815 int last_cellcount, int last_cluster_width, | |
4816 int last_glyph_rbearing) | |
4817 { | |
4818 PangoRectangle ink_rect; | |
4819 PangoRectangle logical_rect; | |
4820 int width; | |
4821 | |
4822 width = last_cellcount * gui.char_width * PANGO_SCALE; | |
4823 glyph->geometry.x_offset = -width + MAX(0, width - last_cluster_width) / 2; | |
4824 glyph->geometry.width = 0; | |
4825 | |
4826 pango_font_get_glyph_extents(item->analysis.font, | |
4827 glyph->glyph, | |
4828 &ink_rect, &logical_rect); | |
4829 if (ink_rect.x < 0) | |
4830 { | |
4831 glyph->geometry.x_offset += last_glyph_rbearing; | |
4832 glyph->geometry.y_offset = logical_rect.height | |
4833 - (gui.char_height - p_linespace) * PANGO_SCALE; | |
4834 } | |
2507
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
4835 else |
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
4836 /* If the accent width is smaller than the cluster width, position it |
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
4837 * in the middle. */ |
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
4838 glyph->geometry.x_offset = -width + MAX(0, width - ink_rect.width) / 2; |
7 | 4839 } |
4840 | |
4841 static void | |
4842 draw_glyph_string(int row, int col, int num_cells, int flags, | |
4843 PangoFont *font, PangoGlyphString *glyphs) | |
4844 { | |
4845 if (!(flags & DRAW_TRANSP)) | |
4846 { | |
4847 gdk_gc_set_foreground(gui.text_gc, gui.bgcolor); | |
4848 | |
4849 gdk_draw_rectangle(gui.drawarea->window, | |
4850 gui.text_gc, | |
4851 TRUE, | |
4852 FILL_X(col), | |
4853 FILL_Y(row), | |
4854 num_cells * gui.char_width, | |
4855 gui.char_height); | |
4856 } | |
4857 | |
4858 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | |
4859 | |
4860 gdk_draw_glyphs(gui.drawarea->window, | |
4861 gui.text_gc, | |
4862 font, | |
4863 TEXT_X(col), | |
4864 TEXT_Y(row), | |
4865 glyphs); | |
4866 | |
4867 /* redraw the contents with an offset of 1 to emulate bold */ | |
4868 if ((flags & DRAW_BOLD) && !gui.font_can_bold) | |
4869 gdk_draw_glyphs(gui.drawarea->window, | |
4870 gui.text_gc, | |
4871 font, | |
4872 TEXT_X(col) + 1, | |
4873 TEXT_Y(row), | |
4874 glyphs); | |
4875 } | |
4876 | |
207 | 4877 /* |
4878 * Draw underline and undercurl at the bottom of the character cell. | |
4879 */ | |
4880 static void | |
4881 draw_under(int flags, int row, int col, int cells) | |
4882 { | |
4883 int i; | |
4884 int offset; | |
1884 | 4885 static const int val[8] = {1, 0, 0, 0, 1, 2, 2, 2 }; |
207 | 4886 int y = FILL_Y(row + 1) - 1; |
4887 | |
4888 /* Undercurl: draw curl at the bottom of the character cell. */ | |
4889 if (flags & DRAW_UNDERC) | |
4890 { | |
4891 gdk_gc_set_foreground(gui.text_gc, gui.spcolor); | |
4892 for (i = FILL_X(col); i < FILL_X(col + cells); ++i) | |
4893 { | |
4894 offset = val[i % 8]; | |
4895 gdk_draw_point(gui.drawarea->window, gui.text_gc, i, y - offset); | |
4896 } | |
4897 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | |
4898 } | |
4899 | |
4900 /* Underline: draw a line at the bottom of the character cell. */ | |
4901 if (flags & DRAW_UNDERL) | |
4902 { | |
4903 /* When p_linespace is 0, overwrite the bottom row of pixels. | |
4904 * Otherwise put the line just below the character. */ | |
4905 if (p_linespace > 1) | |
4906 y -= p_linespace - 1; | |
4907 gdk_draw_line(gui.drawarea->window, gui.text_gc, | |
4908 FILL_X(col), y, | |
4909 FILL_X(col + cells) - 1, y); | |
4910 } | |
4911 } | |
4912 | |
7 | 4913 int |
4914 gui_gtk2_draw_string(int row, int col, char_u *s, int len, int flags) | |
4915 { | |
4916 GdkRectangle area; /* area for clip mask */ | |
4917 PangoGlyphString *glyphs; /* glyphs of current item */ | |
4918 int column_offset = 0; /* column offset in cells */ | |
4919 int i; | |
4920 char_u *conv_buf = NULL; /* result of UTF-8 conversion */ | |
4921 char_u *new_conv_buf; | |
4922 int convlen; | |
4923 char_u *sp, *bp; | |
4924 int plen; | |
4925 | |
4926 if (gui.text_context == NULL || gui.drawarea->window == NULL) | |
4927 return len; | |
4928 | |
4929 if (output_conv.vc_type != CONV_NONE) | |
4930 { | |
4931 /* | |
4932 * Convert characters from 'encoding' to 'termencoding', which is set | |
4933 * to UTF-8 by gui_mch_init(). did_set_string_option() in option.c | |
4934 * prohibits changing this to something else than UTF-8 if the GUI is | |
4935 * in use. | |
4936 */ | |
4937 convlen = len; | |
4938 conv_buf = string_convert(&output_conv, s, &convlen); | |
4939 g_return_val_if_fail(conv_buf != NULL, len); | |
4940 | |
4941 /* Correct for differences in char width: some chars are | |
4942 * double-wide in 'encoding' but single-wide in utf-8. Add a space to | |
4943 * compensate for that. */ | |
4944 for (sp = s, bp = conv_buf; sp < s + len && bp < conv_buf + convlen; ) | |
4945 { | |
474 | 4946 plen = utf_ptr2len(bp); |
7 | 4947 if ((*mb_ptr2cells)(sp) == 2 && utf_ptr2cells(bp) == 1) |
4948 { | |
4949 new_conv_buf = alloc(convlen + 2); | |
4950 if (new_conv_buf == NULL) | |
4951 return len; | |
4952 plen += bp - conv_buf; | |
4953 mch_memmove(new_conv_buf, conv_buf, plen); | |
4954 new_conv_buf[plen] = ' '; | |
4955 mch_memmove(new_conv_buf + plen + 1, conv_buf + plen, | |
4956 convlen - plen + 1); | |
4957 vim_free(conv_buf); | |
4958 conv_buf = new_conv_buf; | |
4959 ++convlen; | |
4960 bp = conv_buf + plen; | |
4961 plen = 1; | |
4962 } | |
474 | 4963 sp += (*mb_ptr2len)(sp); |
7 | 4964 bp += plen; |
4965 } | |
4966 s = conv_buf; | |
4967 len = convlen; | |
4968 } | |
4969 | |
4970 /* | |
4971 * Restrict all drawing to the current screen line in order to prevent | |
4972 * fuzzy font lookups from messing up the screen. | |
4973 */ | |
4974 area.x = gui.border_offset; | |
4975 area.y = FILL_Y(row); | |
4976 area.width = gui.num_cols * gui.char_width; | |
4977 area.height = gui.char_height; | |
4978 | |
4979 gdk_gc_set_clip_origin(gui.text_gc, 0, 0); | |
4980 gdk_gc_set_clip_rectangle(gui.text_gc, &area); | |
4981 | |
4982 glyphs = pango_glyph_string_new(); | |
4983 | |
4984 /* | |
4985 * Optimization hack: If possible, skip the itemize and shaping process | |
4986 * for pure ASCII strings. This optimization is particularly effective | |
4987 * because Vim draws space characters to clear parts of the screen. | |
4988 */ | |
4989 if (!(flags & DRAW_ITALIC) | |
4990 && !((flags & DRAW_BOLD) && gui.font_can_bold) | |
4991 && gui.ascii_glyphs != NULL) | |
4992 { | |
4993 char_u *p; | |
4994 | |
4995 for (p = s; p < s + len; ++p) | |
4996 if (*p & 0x80) | |
4997 goto not_ascii; | |
4998 | |
4999 pango_glyph_string_set_size(glyphs, len); | |
5000 | |
5001 for (i = 0; i < len; ++i) | |
5002 { | |
5003 glyphs->glyphs[i] = gui.ascii_glyphs->glyphs[s[i]]; | |
5004 glyphs->log_clusters[i] = i; | |
5005 } | |
5006 | |
5007 draw_glyph_string(row, col, len, flags, gui.ascii_font, glyphs); | |
5008 | |
5009 column_offset = len; | |
5010 } | |
5011 else | |
5012 not_ascii: | |
5013 { | |
5014 PangoAttrList *attr_list; | |
5015 GList *item_list; | |
5016 int cluster_width; | |
5017 int last_glyph_rbearing; | |
5018 int cells = 0; /* cells occupied by current cluster */ | |
5019 | |
26 | 5020 /* Safety check: pango crashes when invoked with invalid utf-8 |
5021 * characters. */ | |
5022 if (!utf_valid_string(s, s + len)) | |
5023 { | |
5024 column_offset = len; | |
5025 goto skipitall; | |
5026 } | |
5027 | |
7 | 5028 /* original width of the current cluster */ |
5029 cluster_width = PANGO_SCALE * gui.char_width; | |
5030 | |
5031 /* right bearing of the last non-composing glyph */ | |
5032 last_glyph_rbearing = PANGO_SCALE * gui.char_width; | |
5033 | |
5034 attr_list = pango_attr_list_new(); | |
5035 | |
5036 /* If 'guifontwide' is set then use that for double-width characters. | |
5037 * Otherwise just go with 'guifont' and let Pango do its thing. */ | |
5038 if (gui.wide_font != NULL) | |
5039 apply_wide_font_attr(s, len, attr_list); | |
5040 | |
5041 if ((flags & DRAW_BOLD) && gui.font_can_bold) | |
5042 INSERT_PANGO_ATTR(pango_attr_weight_new(PANGO_WEIGHT_BOLD), | |
5043 attr_list, 0, len); | |
5044 if (flags & DRAW_ITALIC) | |
5045 INSERT_PANGO_ATTR(pango_attr_style_new(PANGO_STYLE_ITALIC), | |
5046 attr_list, 0, len); | |
5047 /* | |
5048 * Break the text into segments with consistent directional level | |
5049 * and shaping engine. Pure Latin text needs only a single segment, | |
5050 * so there's no need to worry about the loop's efficiency. Better | |
5051 * try to optimize elsewhere, e.g. reducing exposes and stuff :) | |
5052 */ | |
5053 item_list = pango_itemize(gui.text_context, | |
5054 (const char *)s, 0, len, attr_list, NULL); | |
5055 | |
5056 while (item_list != NULL) | |
5057 { | |
5058 PangoItem *item; | |
5059 int item_cells = 0; /* item length in cells */ | |
5060 | |
5061 item = (PangoItem *)item_list->data; | |
5062 item_list = g_list_delete_link(item_list, item_list); | |
5063 /* | |
5064 * Increment the bidirectional embedding level by 1 if it is not | |
5065 * even. An odd number means the output will be RTL, but we don't | |
5066 * want that since Vim handles right-to-left text on its own. It | |
5067 * would probably be sufficient to just set level = 0, but you can | |
5068 * never know :) | |
5069 * | |
5070 * Unfortunately we can't take advantage of Pango's ability to | |
5071 * render both LTR and RTL at the same time. In order to support | |
5072 * that, Vim's main screen engine would have to make use of Pango | |
5073 * functionality. | |
5074 */ | |
5075 item->analysis.level = (item->analysis.level + 1) & (~1U); | |
5076 | |
5077 /* HACK: Overrule the shape engine, we don't want shaping to be | |
5078 * done, because drawing the cursor would change the display. */ | |
5079 item->analysis.shape_engine = default_shape_engine; | |
5080 | |
7098
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
5081 #ifdef HAVE_PANGO_SHAPE_FULL |
7086
3825da022231
commit https://github.com/vim/vim/commit/7e2ec008f5c5152205d0b8a7d88177b374225d8d
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
5082 pango_shape_full((const char *)s + item->offset, item->length, |
3825da022231
commit https://github.com/vim/vim/commit/7e2ec008f5c5152205d0b8a7d88177b374225d8d
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
5083 (const char *)s, len, &item->analysis, glyphs); |
7098
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
5084 #else |
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
5085 pango_shape((const char *)s + item->offset, item->length, |
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
5086 &item->analysis, glyphs); |
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
5087 #endif |
7 | 5088 /* |
5089 * Fixed-width hack: iterate over the array and assign a fixed | |
5090 * width to each glyph, thus overriding the choice made by the | |
5091 * shaping engine. We use utf_char2cells() to determine the | |
5092 * number of cells needed. | |
5093 * | |
5094 * Also perform all kind of dark magic to get composing | |
5095 * characters right (and pretty too of course). | |
5096 */ | |
5097 for (i = 0; i < glyphs->num_glyphs; ++i) | |
5098 { | |
5099 PangoGlyphInfo *glyph; | |
5100 | |
5101 glyph = &glyphs->glyphs[i]; | |
5102 | |
5103 if (glyph->attr.is_cluster_start) | |
5104 { | |
5105 int cellcount; | |
5106 | |
5107 cellcount = count_cluster_cells( | |
5108 s, item, glyphs, i, &cluster_width, | |
5109 (item_list != NULL) ? &last_glyph_rbearing : NULL); | |
5110 | |
5111 if (cellcount > 0) | |
5112 { | |
5113 int width; | |
5114 | |
5115 width = cellcount * gui.char_width * PANGO_SCALE; | |
5116 glyph->geometry.x_offset += | |
5117 MAX(0, width - cluster_width) / 2; | |
5118 glyph->geometry.width = width; | |
5119 } | |
5120 else | |
5121 { | |
5122 /* If there are only combining characters in the | |
5123 * cluster, we cannot just change the width of the | |
5124 * previous glyph since there is none. Therefore | |
5125 * some guesswork is needed. */ | |
5126 setup_zero_width_cluster(item, glyph, cells, | |
5127 cluster_width, | |
5128 last_glyph_rbearing); | |
5129 } | |
5130 | |
5131 item_cells += cellcount; | |
5132 cells = cellcount; | |
5133 } | |
5134 else if (i > 0) | |
5135 { | |
5136 int width; | |
5137 | |
5138 /* There is a previous glyph, so we deal with combining | |
2507
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
5139 * characters the canonical way. |
2517
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
5140 * In some circumstances Pango uses a positive x_offset, |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
5141 * then use the width of the previous glyph for this one |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
5142 * and set the previous width to zero. |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
5143 * Otherwise we get a negative x_offset, Pango has already |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
5144 * positioned the combining char, keep the widths as they |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
5145 * are. |
2507
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
5146 * For both adjust the x_offset to position the glyph in |
2517
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
5147 * the middle. */ |
2507
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
5148 if (glyph->geometry.x_offset >= 0) |
2517
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
5149 { |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
5150 glyphs->glyphs[i].geometry.width = |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
5151 glyphs->glyphs[i - 1].geometry.width; |
2507
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
5152 glyphs->glyphs[i - 1].geometry.width = 0; |
2517
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
5153 } |
7 | 5154 width = cells * gui.char_width * PANGO_SCALE; |
5155 glyph->geometry.x_offset += | |
5156 MAX(0, width - cluster_width) / 2; | |
5157 } | |
5158 else /* i == 0 "cannot happen" */ | |
5159 { | |
5160 glyph->geometry.width = 0; | |
5161 } | |
5162 } | |
5163 | |
5164 /*** Aaaaand action! ***/ | |
5165 draw_glyph_string(row, col + column_offset, item_cells, | |
5166 flags, item->analysis.font, glyphs); | |
5167 | |
5168 pango_item_free(item); | |
5169 | |
5170 column_offset += item_cells; | |
5171 } | |
5172 | |
5173 pango_attr_list_unref(attr_list); | |
5174 } | |
5175 | |
26 | 5176 skipitall: |
207 | 5177 /* Draw underline and undercurl. */ |
5178 draw_under(flags, row, col, column_offset); | |
7 | 5179 |
5180 pango_glyph_string_free(glyphs); | |
5181 vim_free(conv_buf); | |
5182 | |
5183 gdk_gc_set_clip_rectangle(gui.text_gc, NULL); | |
5184 | |
5185 return column_offset; | |
5186 } | |
5187 | |
5188 /* | |
5189 * Return OK if the key with the termcap name "name" is supported. | |
5190 */ | |
5191 int | |
5192 gui_mch_haskey(char_u *name) | |
5193 { | |
5194 int i; | |
5195 | |
5196 for (i = 0; special_keys[i].key_sym != 0; i++) | |
5197 if (name[0] == special_keys[i].code0 | |
5198 && name[1] == special_keys[i].code1) | |
5199 return OK; | |
5200 return FAIL; | |
5201 } | |
5202 | |
4133 | 5203 #if defined(FEAT_TITLE) || defined(FEAT_EVAL) || defined(PROTO) |
7 | 5204 /* |
5205 * Return the text window-id and display. Only required for X-based GUI's | |
5206 */ | |
5207 int | |
5208 gui_get_x11_windis(Window *win, Display **dis) | |
5209 { | |
5210 if (gui.mainwin != NULL && gui.mainwin->window != NULL) | |
5211 { | |
5212 *dis = GDK_WINDOW_XDISPLAY(gui.mainwin->window); | |
5213 *win = GDK_WINDOW_XWINDOW(gui.mainwin->window); | |
5214 return OK; | |
5215 } | |
5216 | |
5217 *dis = NULL; | |
5218 *win = 0; | |
5219 return FAIL; | |
5220 } | |
5221 #endif | |
5222 | |
5223 #if defined(FEAT_CLIENTSERVER) \ | |
5224 || (defined(FEAT_X11) && defined(FEAT_CLIPBOARD)) || defined(PROTO) | |
5225 | |
5226 Display * | |
5227 gui_mch_get_display(void) | |
5228 { | |
5229 if (gui.mainwin != NULL && gui.mainwin->window != NULL) | |
5230 return GDK_WINDOW_XDISPLAY(gui.mainwin->window); | |
5231 else | |
5232 return NULL; | |
5233 } | |
5234 #endif | |
5235 | |
5236 void | |
5237 gui_mch_beep(void) | |
5238 { | |
5239 #ifdef HAVE_GTK_MULTIHEAD | |
5240 GdkDisplay *display; | |
5241 | |
5242 if (gui.mainwin != NULL && GTK_WIDGET_REALIZED(gui.mainwin)) | |
5243 display = gtk_widget_get_display(gui.mainwin); | |
5244 else | |
5245 display = gdk_display_get_default(); | |
5246 | |
5247 if (display != NULL) | |
5248 gdk_display_beep(display); | |
5249 #else | |
5250 gdk_beep(); | |
5251 #endif | |
5252 } | |
5253 | |
5254 void | |
5255 gui_mch_flash(int msec) | |
5256 { | |
5257 GdkGCValues values; | |
5258 GdkGC *invert_gc; | |
5259 | |
5260 if (gui.drawarea->window == NULL) | |
5261 return; | |
5262 | |
5263 values.foreground.pixel = gui.norm_pixel ^ gui.back_pixel; | |
5264 values.background.pixel = gui.norm_pixel ^ gui.back_pixel; | |
5265 values.function = GDK_XOR; | |
5266 invert_gc = gdk_gc_new_with_values(gui.drawarea->window, | |
5267 &values, | |
5268 GDK_GC_FOREGROUND | | |
5269 GDK_GC_BACKGROUND | | |
5270 GDK_GC_FUNCTION); | |
5271 gdk_gc_set_exposures(invert_gc, | |
5272 gui.visibility != GDK_VISIBILITY_UNOBSCURED); | |
5273 /* | |
5274 * Do a visual beep by changing back and forth in some undetermined way, | |
5275 * the foreground and background colors. This is due to the fact that | |
5276 * there can't be really any prediction about the effects of XOR on | |
5277 * arbitrary X11 servers. However this seems to be enough for what we | |
5278 * intend it to do. | |
5279 */ | |
5280 gdk_draw_rectangle(gui.drawarea->window, invert_gc, | |
5281 TRUE, | |
5282 0, 0, | |
5283 FILL_X((int)Columns) + gui.border_offset, | |
5284 FILL_Y((int)Rows) + gui.border_offset); | |
5285 | |
5286 gui_mch_flush(); | |
5287 ui_delay((long)msec, TRUE); /* wait so many msec */ | |
5288 | |
5289 gdk_draw_rectangle(gui.drawarea->window, invert_gc, | |
5290 TRUE, | |
5291 0, 0, | |
5292 FILL_X((int)Columns) + gui.border_offset, | |
5293 FILL_Y((int)Rows) + gui.border_offset); | |
5294 | |
5295 gdk_gc_destroy(invert_gc); | |
5296 } | |
5297 | |
5298 /* | |
5299 * Invert a rectangle from row r, column c, for nr rows and nc columns. | |
5300 */ | |
5301 void | |
5302 gui_mch_invert_rectangle(int r, int c, int nr, int nc) | |
5303 { | |
5304 GdkGCValues values; | |
5305 GdkGC *invert_gc; | |
5306 | |
5307 if (gui.drawarea->window == NULL) | |
5308 return; | |
5309 | |
944 | 5310 values.foreground.pixel = gui.norm_pixel ^ gui.back_pixel; |
5311 values.background.pixel = gui.norm_pixel ^ gui.back_pixel; | |
7 | 5312 values.function = GDK_XOR; |
5313 invert_gc = gdk_gc_new_with_values(gui.drawarea->window, | |
5314 &values, | |
5315 GDK_GC_FOREGROUND | | |
5316 GDK_GC_BACKGROUND | | |
5317 GDK_GC_FUNCTION); | |
944 | 5318 gdk_gc_set_exposures(invert_gc, gui.visibility != |
5319 GDK_VISIBILITY_UNOBSCURED); | |
7 | 5320 gdk_draw_rectangle(gui.drawarea->window, invert_gc, |
5321 TRUE, | |
5322 FILL_X(c), FILL_Y(r), | |
5323 (nc) * gui.char_width, (nr) * gui.char_height); | |
5324 gdk_gc_destroy(invert_gc); | |
5325 } | |
5326 | |
5327 /* | |
5328 * Iconify the GUI window. | |
5329 */ | |
5330 void | |
5331 gui_mch_iconify(void) | |
5332 { | |
5333 gtk_window_iconify(GTK_WINDOW(gui.mainwin)); | |
5334 } | |
5335 | |
5336 #if defined(FEAT_EVAL) || defined(PROTO) | |
5337 /* | |
5338 * Bring the Vim window to the foreground. | |
5339 */ | |
5340 void | |
5341 gui_mch_set_foreground(void) | |
5342 { | |
5343 gtk_window_present(GTK_WINDOW(gui.mainwin)); | |
5344 } | |
5345 #endif | |
5346 | |
5347 /* | |
5348 * Draw a cursor without focus. | |
5349 */ | |
5350 void | |
5351 gui_mch_draw_hollow_cursor(guicolor_T color) | |
5352 { | |
5353 int i = 1; | |
5354 | |
5355 if (gui.drawarea->window == NULL) | |
5356 return; | |
5357 | |
5358 gui_mch_set_fg_color(color); | |
5359 | |
5360 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | |
5361 if (mb_lefthalve(gui.row, gui.col)) | |
5362 i = 2; | |
5363 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, | |
5364 FALSE, | |
5365 FILL_X(gui.col), FILL_Y(gui.row), | |
5366 i * gui.char_width - 1, gui.char_height - 1); | |
5367 } | |
5368 | |
5369 /* | |
5370 * Draw part of a cursor, "w" pixels wide, and "h" pixels high, using | |
5371 * color "color". | |
5372 */ | |
5373 void | |
5374 gui_mch_draw_part_cursor(int w, int h, guicolor_T color) | |
5375 { | |
5376 if (gui.drawarea->window == NULL) | |
5377 return; | |
5378 | |
5379 gui_mch_set_fg_color(color); | |
5380 | |
5381 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | |
5382 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, | |
5383 TRUE, | |
5384 #ifdef FEAT_RIGHTLEFT | |
5385 /* vertical line should be on the right of current point */ | |
5386 CURSOR_BAR_RIGHT ? FILL_X(gui.col + 1) - w : | |
5387 #endif | |
5388 FILL_X(gui.col), | |
5389 FILL_Y(gui.row) + gui.char_height - h, | |
5390 w, h); | |
5391 } | |
5392 | |
5393 | |
5394 /* | |
5395 * Catch up with any queued X11 events. This may put keyboard input into the | |
5396 * input buffer, call resize call-backs, trigger timers etc. If there is | |
5397 * nothing in the X11 event queue (& no timers pending), then we return | |
5398 * immediately. | |
5399 */ | |
5400 void | |
5401 gui_mch_update(void) | |
5402 { | |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
5403 while (g_main_context_pending(NULL) && !vim_is_input_buf_full()) |
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
5404 g_main_context_iteration(NULL, TRUE); |
7 | 5405 } |
5406 | |
5407 static gint | |
5408 input_timer_cb(gpointer data) | |
5409 { | |
5410 int *timed_out = (int *) data; | |
5411 | |
1226 | 5412 /* Just inform the caller about the occurrence of it */ |
7 | 5413 *timed_out = TRUE; |
5414 | |
5415 return FALSE; /* don't happen again */ | |
5416 } | |
5417 | |
5418 #ifdef FEAT_SNIFF | |
5419 /* | |
5420 * Callback function, used when data is available on the SNiFF connection. | |
5421 */ | |
5422 static void | |
5423 sniff_request_cb( | |
7870
fb5ba6fbc843
commit https://github.com/vim/vim/commit/1357caf31f3e447d99baf8dd6a3243e2ab38567f
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
5424 gpointer data UNUSED, |
fb5ba6fbc843
commit https://github.com/vim/vim/commit/1357caf31f3e447d99baf8dd6a3243e2ab38567f
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
5425 gint source_fd UNUSED, |
fb5ba6fbc843
commit https://github.com/vim/vim/commit/1357caf31f3e447d99baf8dd6a3243e2ab38567f
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
5426 GdkInputCondition condition UNUSED) |
7 | 5427 { |
5428 static char_u bytes[3] = {CSI, (int)KS_EXTRA, (int)KE_SNIFF}; | |
5429 | |
5430 add_to_input_buf(bytes, 3); | |
5431 } | |
5432 #endif | |
5433 | |
5434 /* | |
5435 * GUI input routine called by gui_wait_for_chars(). Waits for a character | |
5436 * from the keyboard. | |
5437 * wtime == -1 Wait forever. | |
5438 * wtime == 0 This should never happen. | |
5439 * wtime > 0 Wait wtime milliseconds for a character. | |
5440 * Returns OK if a character was found to be available within the given time, | |
5441 * or FAIL otherwise. | |
5442 */ | |
5443 int | |
5444 gui_mch_wait_for_chars(long wtime) | |
5445 { | |
5446 int focus; | |
5447 guint timer; | |
5448 static int timed_out; | |
5449 #ifdef FEAT_SNIFF | |
5450 static int sniff_on = 0; | |
5451 static gint sniff_input_id = 0; | |
5452 #endif | |
5453 | |
5454 #ifdef FEAT_SNIFF | |
5455 if (sniff_on && !want_sniff_request) | |
5456 { | |
5457 if (sniff_input_id) | |
5458 gdk_input_remove(sniff_input_id); | |
5459 sniff_on = 0; | |
5460 } | |
5461 else if (!sniff_on && want_sniff_request) | |
5462 { | |
5463 /* Add fd_from_sniff to watch for available data in main loop. */ | |
5464 sniff_input_id = gdk_input_add(fd_from_sniff, | |
5465 GDK_INPUT_READ, sniff_request_cb, NULL); | |
5466 sniff_on = 1; | |
5467 } | |
5468 #endif | |
5469 | |
5470 timed_out = FALSE; | |
5471 | |
5472 /* this timeout makes sure that we will return if no characters arrived in | |
5473 * time */ | |
5474 | |
5475 if (wtime > 0) | |
5476 timer = gtk_timeout_add((guint32)wtime, input_timer_cb, &timed_out); | |
5477 else | |
5478 timer = 0; | |
5479 | |
5480 focus = gui.in_focus; | |
5481 | |
5482 do | |
5483 { | |
5484 /* Stop or start blinking when focus changes */ | |
5485 if (gui.in_focus != focus) | |
5486 { | |
5487 if (gui.in_focus) | |
5488 gui_mch_start_blink(); | |
5489 else | |
5490 gui_mch_stop_blink(); | |
5491 focus = gui.in_focus; | |
5492 } | |
5493 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7098
diff
changeset
|
5494 #ifdef MESSAGE_QUEUE |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7098
diff
changeset
|
5495 parse_queued_messages(); |
1624 | 5496 #endif |
5497 | |
7 | 5498 /* |
5499 * Loop in GTK+ processing until a timeout or input occurs. | |
22 | 5500 * Skip this if input is available anyway (can happen in rare |
5501 * situations, sort of race condition). | |
7 | 5502 */ |
22 | 5503 if (!input_available()) |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
5504 g_main_context_iteration(NULL, TRUE); |
7 | 5505 |
5506 /* Got char, return immediately */ | |
5507 if (input_available()) | |
5508 { | |
5509 if (timer != 0 && !timed_out) | |
5510 gtk_timeout_remove(timer); | |
5511 return OK; | |
5512 } | |
5513 } while (wtime < 0 || !timed_out); | |
5514 | |
5515 /* | |
5516 * Flush all eventually pending (drawing) events. | |
5517 */ | |
5518 gui_mch_update(); | |
5519 | |
5520 return FAIL; | |
5521 } | |
5522 | |
5523 | |
5524 /**************************************************************************** | |
5525 * Output drawing routines. | |
5526 ****************************************************************************/ | |
5527 | |
5528 | |
5529 /* Flush any output to the screen */ | |
5530 void | |
5531 gui_mch_flush(void) | |
5532 { | |
5533 #ifdef HAVE_GTK_MULTIHEAD | |
5534 if (gui.mainwin != NULL && GTK_WIDGET_REALIZED(gui.mainwin)) | |
5535 gdk_display_sync(gtk_widget_get_display(gui.mainwin)); | |
5536 #else | |
5537 gdk_flush(); /* historical misnomer: calls XSync(), not XFlush() */ | |
5538 #endif | |
5539 /* This happens to actually do what gui_mch_flush() is supposed to do, | |
5540 * according to the comment above. */ | |
5541 if (gui.drawarea != NULL && gui.drawarea->window != NULL) | |
5542 gdk_window_process_updates(gui.drawarea->window, FALSE); | |
5543 } | |
5544 | |
5545 /* | |
5546 * Clear a rectangular region of the screen from text pos (row1, col1) to | |
5547 * (row2, col2) inclusive. | |
5548 */ | |
5549 void | |
5550 gui_mch_clear_block(int row1, int col1, int row2, int col2) | |
5551 { | |
5552 GdkColor color; | |
5553 | |
5554 if (gui.drawarea->window == NULL) | |
5555 return; | |
5556 | |
5557 color.pixel = gui.back_pixel; | |
5558 | |
5559 gdk_gc_set_foreground(gui.text_gc, &color); | |
5560 | |
5561 /* Clear one extra pixel at the far right, for when bold characters have | |
5562 * spilled over to the window border. */ | |
5563 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, TRUE, | |
5564 FILL_X(col1), FILL_Y(row1), | |
5565 (col2 - col1 + 1) * gui.char_width | |
5566 + (col2 == Columns - 1), | |
5567 (row2 - row1 + 1) * gui.char_height); | |
5568 } | |
5569 | |
5570 void | |
5571 gui_mch_clear_all(void) | |
5572 { | |
5573 if (gui.drawarea->window != NULL) | |
5574 gdk_window_clear(gui.drawarea->window); | |
5575 } | |
5576 | |
5577 /* | |
5578 * Redraw any text revealed by scrolling up/down. | |
5579 */ | |
5580 static void | |
5581 check_copy_area(void) | |
5582 { | |
5583 GdkEvent *event; | |
5584 int expose_count; | |
5585 | |
5586 if (gui.visibility != GDK_VISIBILITY_PARTIAL) | |
5587 return; | |
5588 | |
5589 /* Avoid redrawing the cursor while scrolling or it'll end up where | |
5590 * we don't want it to be. I'm not sure if it's correct to call | |
5591 * gui_dont_update_cursor() at this point but it works as a quick | |
5592 * fix for now. */ | |
5593 gui_dont_update_cursor(); | |
5594 | |
5595 do | |
5596 { | |
5597 /* Wait to check whether the scroll worked or not. */ | |
5598 event = gdk_event_get_graphics_expose(gui.drawarea->window); | |
5599 | |
5600 if (event == NULL) | |
5601 break; /* received NoExpose event */ | |
5602 | |
5603 gui_redraw(event->expose.area.x, event->expose.area.y, | |
5604 event->expose.area.width, event->expose.area.height); | |
5605 | |
5606 expose_count = event->expose.count; | |
5607 gdk_event_free(event); | |
5608 } | |
5609 while (expose_count > 0); /* more events follow */ | |
5610 | |
5611 gui_can_update_cursor(); | |
5612 } | |
5613 | |
5614 /* | |
5615 * Delete the given number of lines from the given row, scrolling up any | |
5616 * text further down within the scroll region. | |
5617 */ | |
5618 void | |
5619 gui_mch_delete_lines(int row, int num_lines) | |
5620 { | |
5621 if (gui.visibility == GDK_VISIBILITY_FULLY_OBSCURED) | |
5622 return; /* Can't see the window */ | |
5623 | |
5624 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | |
5625 gdk_gc_set_background(gui.text_gc, gui.bgcolor); | |
5626 | |
5627 /* copy one extra pixel, for when bold has spilled over */ | |
5628 gdk_window_copy_area(gui.drawarea->window, gui.text_gc, | |
5629 FILL_X(gui.scroll_region_left), FILL_Y(row), | |
5630 gui.drawarea->window, | |
5631 FILL_X(gui.scroll_region_left), | |
5632 FILL_Y(row + num_lines), | |
5633 gui.char_width * (gui.scroll_region_right | |
5634 - gui.scroll_region_left + 1) + 1, | |
5635 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1)); | |
5636 | |
5637 gui_clear_block(gui.scroll_region_bot - num_lines + 1, | |
5638 gui.scroll_region_left, | |
5639 gui.scroll_region_bot, gui.scroll_region_right); | |
5640 check_copy_area(); | |
5641 } | |
5642 | |
5643 /* | |
5644 * Insert the given number of lines before the given row, scrolling down any | |
5645 * following text within the scroll region. | |
5646 */ | |
5647 void | |
5648 gui_mch_insert_lines(int row, int num_lines) | |
5649 { | |
5650 if (gui.visibility == GDK_VISIBILITY_FULLY_OBSCURED) | |
5651 return; /* Can't see the window */ | |
5652 | |
5653 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | |
5654 gdk_gc_set_background(gui.text_gc, gui.bgcolor); | |
5655 | |
5656 /* copy one extra pixel, for when bold has spilled over */ | |
5657 gdk_window_copy_area(gui.drawarea->window, gui.text_gc, | |
5658 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), | |
5659 gui.drawarea->window, | |
5660 FILL_X(gui.scroll_region_left), FILL_Y(row), | |
5661 gui.char_width * (gui.scroll_region_right | |
5662 - gui.scroll_region_left + 1) + 1, | |
5663 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1)); | |
5664 | |
5665 gui_clear_block(row, gui.scroll_region_left, | |
5666 row + num_lines - 1, gui.scroll_region_right); | |
5667 check_copy_area(); | |
5668 } | |
5669 | |
5670 /* | |
5671 * X Selection stuff, for cutting and pasting text to other windows. | |
5672 */ | |
5673 void | |
5674 clip_mch_request_selection(VimClipboard *cbd) | |
5675 { | |
5676 GdkAtom target; | |
5677 unsigned i; | |
1494 | 5678 time_t start; |
7 | 5679 |
5680 for (i = 0; i < N_SELECTION_TARGETS; ++i) | |
5681 { | |
1904 | 5682 if (!clip_html && selection_targets[i].info == TARGET_HTML) |
5683 continue; | |
7 | 5684 received_selection = RS_NONE; |
5685 target = gdk_atom_intern(selection_targets[i].target, FALSE); | |
5686 | |
5687 gtk_selection_convert(gui.drawarea, | |
5688 cbd->gtk_sel_atom, target, | |
5689 (guint32)GDK_CURRENT_TIME); | |
5690 | |
1494 | 5691 /* Hack: Wait up to three seconds for the selection. A hang was |
5692 * noticed here when using the netrw plugin combined with ":gui" | |
5693 * during the FocusGained event. */ | |
5694 start = time(NULL); | |
5695 while (received_selection == RS_NONE && time(NULL) < start + 3) | |
2301
6f63294a1781
Avoid use of the GTK mail_loop() so that the GtkFileChooser can be used.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
5696 g_main_context_iteration(NULL, TRUE); /* wait for selection_received_cb */ |
7 | 5697 |
5698 if (received_selection != RS_FAIL) | |
5699 return; | |
5700 } | |
5701 | |
5702 /* Final fallback position - use the X CUT_BUFFER0 store */ | |
1924 | 5703 yank_cut_buffer0(GDK_WINDOW_XDISPLAY(gui.mainwin->window), cbd); |
7 | 5704 } |
5705 | |
5706 /* | |
5707 * Disown the selection. | |
5708 */ | |
5709 void | |
1884 | 5710 clip_mch_lose_selection(VimClipboard *cbd UNUSED) |
7 | 5711 { |
4209 | 5712 gtk_selection_owner_set(NULL, cbd->gtk_sel_atom, gui.event_time); |
7 | 5713 gui_mch_update(); |
5714 } | |
5715 | |
5716 /* | |
5717 * Own the selection and return OK if it worked. | |
5718 */ | |
5719 int | |
5720 clip_mch_own_selection(VimClipboard *cbd) | |
5721 { | |
5722 int success; | |
5723 | |
5724 success = gtk_selection_owner_set(gui.drawarea, cbd->gtk_sel_atom, | |
2923 | 5725 gui.event_time); |
7 | 5726 gui_mch_update(); |
5727 return (success) ? OK : FAIL; | |
5728 } | |
5729 | |
5730 /* | |
5731 * Send the current selection to the clipboard. Do nothing for X because we | |
5732 * will fill in the selection only when requested by another app. | |
5733 */ | |
5734 void | |
1884 | 5735 clip_mch_set_selection(VimClipboard *cbd UNUSED) |
7 | 5736 { |
5737 } | |
5738 | |
4209 | 5739 int |
5740 clip_gtk_owner_exists(VimClipboard *cbd) | |
5741 { | |
5742 return gdk_selection_owner_get(cbd->gtk_sel_atom) != NULL; | |
5743 } | |
5744 | |
7 | 5745 |
5746 #if defined(FEAT_MENU) || defined(PROTO) | |
5747 /* | |
5748 * Make a menu item appear either active or not active (grey or not grey). | |
5749 */ | |
5750 void | |
5751 gui_mch_menu_grey(vimmenu_T *menu, int grey) | |
5752 { | |
5753 if (menu->id == NULL) | |
5754 return; | |
5755 | |
5756 if (menu_is_separator(menu->name)) | |
5757 grey = TRUE; | |
5758 | |
5759 gui_mch_menu_hidden(menu, FALSE); | |
5760 /* Be clever about bitfields versus true booleans here! */ | |
5761 if (!GTK_WIDGET_SENSITIVE(menu->id) == !grey) | |
5762 { | |
5763 gtk_widget_set_sensitive(menu->id, !grey); | |
5764 gui_mch_update(); | |
5765 } | |
5766 } | |
5767 | |
5768 /* | |
5769 * Make menu item hidden or not hidden. | |
5770 */ | |
5771 void | |
5772 gui_mch_menu_hidden(vimmenu_T *menu, int hidden) | |
5773 { | |
5774 if (menu->id == 0) | |
5775 return; | |
5776 | |
5777 if (hidden) | |
5778 { | |
5779 if (GTK_WIDGET_VISIBLE(menu->id)) | |
5780 { | |
5781 gtk_widget_hide(menu->id); | |
5782 gui_mch_update(); | |
5783 } | |
5784 } | |
5785 else | |
5786 { | |
5787 if (!GTK_WIDGET_VISIBLE(menu->id)) | |
5788 { | |
5789 gtk_widget_show(menu->id); | |
5790 gui_mch_update(); | |
5791 } | |
5792 } | |
5793 } | |
5794 | |
5795 /* | |
5796 * This is called after setting all the menus to grey/hidden or not. | |
5797 */ | |
5798 void | |
5799 gui_mch_draw_menubar(void) | |
5800 { | |
5801 /* just make sure that the visual changes get effect immediately */ | |
5802 gui_mch_update(); | |
5803 } | |
5804 #endif /* FEAT_MENU */ | |
5805 | |
5806 /* | |
5807 * Scrollbar stuff. | |
5808 */ | |
5809 void | |
5810 gui_mch_enable_scrollbar(scrollbar_T *sb, int flag) | |
5811 { | |
5812 if (sb->id == NULL) | |
5813 return; | |
5814 | |
5815 if (flag) | |
5816 gtk_widget_show(sb->id); | |
5817 else | |
5818 gtk_widget_hide(sb->id); | |
5819 | |
791 | 5820 update_window_manager_hints(0, 0); |
7 | 5821 } |
5822 | |
5823 | |
5824 /* | |
5825 * Return the RGB value of a pixel as long. | |
5826 */ | |
5827 long_u | |
5828 gui_mch_get_rgb(guicolor_T pixel) | |
5829 { | |
5830 GdkColor color; | |
5831 gdk_colormap_query_color(gtk_widget_get_colormap(gui.drawarea), | |
5832 (unsigned long)pixel, &color); | |
5833 | |
5834 return (((unsigned)color.red & 0xff00) << 8) | |
5835 | ((unsigned)color.green & 0xff00) | |
5836 | (((unsigned)color.blue & 0xff00) >> 8); | |
5837 } | |
5838 | |
5839 /* | |
88 | 5840 * Get current mouse coordinates in text window. |
7 | 5841 */ |
88 | 5842 void |
5843 gui_mch_getmouse(int *x, int *y) | |
7 | 5844 { |
88 | 5845 gdk_window_get_pointer(gui.drawarea->window, x, y, NULL); |
7 | 5846 } |
5847 | |
5848 void | |
5849 gui_mch_setmouse(int x, int y) | |
5850 { | |
5851 /* Sorry for the Xlib call, but we can't avoid it, since there is no | |
5852 * internal GDK mechanism present to accomplish this. (and for good | |
5853 * reason...) */ | |
5854 XWarpPointer(GDK_WINDOW_XDISPLAY(gui.drawarea->window), | |
5855 (Window)0, GDK_WINDOW_XWINDOW(gui.drawarea->window), | |
5856 0, 0, 0U, 0U, x, y); | |
5857 } | |
5858 | |
5859 | |
5860 #ifdef FEAT_MOUSESHAPE | |
5861 /* The last set mouse pointer shape is remembered, to be used when it goes | |
5862 * from hidden to not hidden. */ | |
5863 static int last_shape = 0; | |
5864 #endif | |
5865 | |
5866 /* | |
5867 * Use the blank mouse pointer or not. | |
5868 * | |
5869 * hide: TRUE = use blank ptr, FALSE = use parent ptr | |
5870 */ | |
5871 void | |
5872 gui_mch_mousehide(int hide) | |
5873 { | |
5874 if (gui.pointer_hidden != hide) | |
5875 { | |
5876 gui.pointer_hidden = hide; | |
5877 if (gui.drawarea->window && gui.blank_pointer != NULL) | |
5878 { | |
5879 if (hide) | |
5880 gdk_window_set_cursor(gui.drawarea->window, gui.blank_pointer); | |
5881 else | |
5882 #ifdef FEAT_MOUSESHAPE | |
5883 mch_set_mouse_shape(last_shape); | |
5884 #else | |
5885 gdk_window_set_cursor(gui.drawarea->window, NULL); | |
5886 #endif | |
5887 } | |
5888 } | |
5889 } | |
5890 | |
5891 #if defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
5892 | |
5893 /* Table for shape IDs. Keep in sync with the mshape_names[] table in | |
5894 * misc2.c! */ | |
5895 static const int mshape_ids[] = | |
5896 { | |
5897 GDK_LEFT_PTR, /* arrow */ | |
5898 GDK_CURSOR_IS_PIXMAP, /* blank */ | |
5899 GDK_XTERM, /* beam */ | |
5900 GDK_SB_V_DOUBLE_ARROW, /* updown */ | |
5901 GDK_SIZING, /* udsizing */ | |
5902 GDK_SB_H_DOUBLE_ARROW, /* leftright */ | |
5903 GDK_SIZING, /* lrsizing */ | |
5904 GDK_WATCH, /* busy */ | |
5905 GDK_X_CURSOR, /* no */ | |
5906 GDK_CROSSHAIR, /* crosshair */ | |
5907 GDK_HAND1, /* hand1 */ | |
5908 GDK_HAND2, /* hand2 */ | |
5909 GDK_PENCIL, /* pencil */ | |
5910 GDK_QUESTION_ARROW, /* question */ | |
5911 GDK_RIGHT_PTR, /* right-arrow */ | |
5912 GDK_CENTER_PTR, /* up-arrow */ | |
5913 GDK_LEFT_PTR /* last one */ | |
5914 }; | |
5915 | |
5916 void | |
5917 mch_set_mouse_shape(int shape) | |
5918 { | |
5919 int id; | |
5920 GdkCursor *c; | |
5921 | |
5922 if (gui.drawarea->window == NULL) | |
5923 return; | |
5924 | |
5925 if (shape == MSHAPE_HIDE || gui.pointer_hidden) | |
5926 gdk_window_set_cursor(gui.drawarea->window, gui.blank_pointer); | |
5927 else | |
5928 { | |
5929 if (shape >= MSHAPE_NUMBERED) | |
5930 { | |
5931 id = shape - MSHAPE_NUMBERED; | |
5932 if (id >= GDK_LAST_CURSOR) | |
5933 id = GDK_LEFT_PTR; | |
5934 else | |
5935 id &= ~1; /* they are always even (why?) */ | |
5936 } | |
1884 | 5937 else if (shape < (int)(sizeof(mshape_ids) / sizeof(int))) |
7 | 5938 id = mshape_ids[shape]; |
842 | 5939 else |
5940 return; | |
7 | 5941 # ifdef HAVE_GTK_MULTIHEAD |
5942 c = gdk_cursor_new_for_display( | |
136 | 5943 gtk_widget_get_display(gui.drawarea), (GdkCursorType)id); |
7 | 5944 # else |
136 | 5945 c = gdk_cursor_new((GdkCursorType)id); |
7 | 5946 # endif |
5947 gdk_window_set_cursor(gui.drawarea->window, c); | |
5948 gdk_cursor_destroy(c); /* Unref, actually. Bloody GTK+ 1. */ | |
5949 } | |
5950 if (shape != MSHAPE_HIDE) | |
5951 last_shape = shape; | |
5952 } | |
5953 #endif /* FEAT_MOUSESHAPE */ | |
5954 | |
5955 | |
5956 #if defined(FEAT_SIGN_ICONS) || defined(PROTO) | |
5957 /* | |
5958 * Signs are currently always 2 chars wide. With GTK+ 2, the image will be | |
5959 * scaled down if the current font is not big enough, or scaled up if the image | |
5960 * size is less than 3/4 of the maximum sign size. With GTK+ 1, the pixmap | |
5961 * will be cut off if the current font is not big enough, or centered if it's | |
5962 * too small. | |
5963 */ | |
5964 # define SIGN_WIDTH (2 * gui.char_width) | |
5965 # define SIGN_HEIGHT (gui.char_height) | |
5966 # define SIGN_ASPECT ((double)SIGN_HEIGHT / (double)SIGN_WIDTH) | |
5967 | |
5968 void | |
5969 gui_mch_drawsign(int row, int col, int typenr) | |
5970 { | |
5971 GdkPixbuf *sign; | |
5972 | |
5973 sign = (GdkPixbuf *)sign_get_image(typenr); | |
5974 | |
5975 if (sign != NULL && gui.drawarea != NULL && gui.drawarea->window != NULL) | |
5976 { | |
5977 int width; | |
5978 int height; | |
5979 int xoffset; | |
5980 int yoffset; | |
5981 int need_scale; | |
5982 | |
5983 width = gdk_pixbuf_get_width(sign); | |
5984 height = gdk_pixbuf_get_height(sign); | |
5985 /* | |
5986 * Decide whether we need to scale. Allow one pixel of border | |
5987 * width to be cut off, in order to avoid excessive scaling for | |
5988 * tiny differences in font size. | |
5983 | 5989 * Do scale to fit the height to avoid gaps because of linespacing. |
7 | 5990 */ |
5991 need_scale = (width > SIGN_WIDTH + 2 | |
5983 | 5992 || height != SIGN_HEIGHT |
7 | 5993 || (width < 3 * SIGN_WIDTH / 4 |
5994 && height < 3 * SIGN_HEIGHT / 4)); | |
5995 if (need_scale) | |
5996 { | |
5983 | 5997 double aspect; |
5998 int w = width; | |
5999 int h = height; | |
7 | 6000 |
6001 /* Keep the original aspect ratio */ | |
6002 aspect = (double)height / (double)width; | |
6003 width = (double)SIGN_WIDTH * SIGN_ASPECT / aspect; | |
6004 width = MIN(width, SIGN_WIDTH); | |
5983 | 6005 if (((double)(MAX(height, SIGN_HEIGHT)) / |
6006 (double)(MIN(height, SIGN_HEIGHT))) < 1.15) | |
6007 { | |
6008 /* Change the aspect ratio by at most 15% to fill the | |
6009 * available space completly. */ | |
6010 height = (double)SIGN_HEIGHT * SIGN_ASPECT / aspect; | |
6011 height = MIN(height, SIGN_HEIGHT); | |
6012 } | |
6013 else | |
6014 height = (double)width * aspect; | |
6015 | |
6016 if (w == width && h == height) | |
6017 { | |
6018 /* no change in dimensions; don't decrease reference counter | |
6019 * (below) */ | |
6020 need_scale = FALSE; | |
6021 } | |
6022 else | |
6023 { | |
6024 /* This doesn't seem to be worth caching, and doing so would | |
6025 * complicate the code quite a bit. */ | |
6026 sign = gdk_pixbuf_scale_simple(sign, width, height, | |
6027 GDK_INTERP_BILINEAR); | |
6028 if (sign == NULL) | |
6029 return; /* out of memory */ | |
6030 } | |
7 | 6031 } |
6032 | |
6033 /* The origin is the upper-left corner of the pixmap. Therefore | |
6034 * these offset may become negative if the pixmap is smaller than | |
6035 * the 2x1 cells reserved for the sign icon. */ | |
6036 xoffset = (width - SIGN_WIDTH) / 2; | |
6037 yoffset = (height - SIGN_HEIGHT) / 2; | |
6038 | |
6039 gdk_gc_set_foreground(gui.text_gc, gui.bgcolor); | |
6040 | |
6041 gdk_draw_rectangle(gui.drawarea->window, | |
6042 gui.text_gc, | |
6043 TRUE, | |
6044 FILL_X(col), | |
6045 FILL_Y(row), | |
6046 SIGN_WIDTH, | |
6047 SIGN_HEIGHT); | |
6048 | |
6049 gdk_pixbuf_render_to_drawable_alpha(sign, | |
6050 gui.drawarea->window, | |
6051 MAX(0, xoffset), | |
6052 MAX(0, yoffset), | |
6053 FILL_X(col) - MIN(0, xoffset), | |
6054 FILL_Y(row) - MIN(0, yoffset), | |
6055 MIN(width, SIGN_WIDTH), | |
6056 MIN(height, SIGN_HEIGHT), | |
6057 GDK_PIXBUF_ALPHA_BILEVEL, | |
6058 127, | |
6059 GDK_RGB_DITHER_NORMAL, | |
6060 0, 0); | |
6061 if (need_scale) | |
6062 g_object_unref(sign); | |
6063 } | |
6064 } | |
6065 | |
6066 void * | |
6067 gui_mch_register_sign(char_u *signfile) | |
6068 { | |
6069 if (signfile[0] != NUL && signfile[0] != '-' && gui.in_use) | |
6070 { | |
6071 GdkPixbuf *sign; | |
6072 GError *error = NULL; | |
6073 char_u *message; | |
6074 | |
6075 sign = gdk_pixbuf_new_from_file((const char *)signfile, &error); | |
6076 | |
6077 if (error == NULL) | |
6078 return sign; | |
6079 | |
6080 message = (char_u *)error->message; | |
6081 | |
6082 if (message != NULL && input_conv.vc_type != CONV_NONE) | |
6083 message = string_convert(&input_conv, message, NULL); | |
6084 | |
6085 if (message != NULL) | |
6086 { | |
6087 /* The error message is already translated and will be more | |
6088 * descriptive than anything we could possibly do ourselves. */ | |
6089 EMSG2("E255: %s", message); | |
6090 | |
6091 if (input_conv.vc_type != CONV_NONE) | |
6092 vim_free(message); | |
6093 } | |
6094 g_error_free(error); | |
6095 } | |
6096 | |
6097 return NULL; | |
6098 } | |
6099 | |
6100 void | |
6101 gui_mch_destroy_sign(void *sign) | |
6102 { | |
6103 if (sign != NULL) | |
6104 g_object_unref(sign); | |
6105 } | |
6106 | |
6107 #endif /* FEAT_SIGN_ICONS */ |