Mercurial > vim
annotate src/gui_gtk_x11.c @ 8495:8877ea0a27ec v7.4.1538
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Mar 12 12:40:58 2016 +0100
patch 7.4.1538
Problem: Selection with the mouse does not work in command line mode.
Solution: Use cairo functions. (Kazunobu Kuriyama)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 12 Mar 2016 12:45:04 +0100 |
parents | 42020d59a432 |
children | 9f5bd031530d |
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> | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
22 * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
23 * Support for GTK+ 3 was added by: |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
24 * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
25 * 2016 Kazunobu Kuriyama <kazunobu.kuriyama@gmail.com> |
7 | 26 */ |
27 | |
28 #include "vim.h" | |
7380
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
29 #ifdef USE_GRESOURCE |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
30 #include "auto/gui_gtk_gresources.h" |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
31 #endif |
1666 | 32 |
7 | 33 #ifdef FEAT_GUI_GNOME |
34 /* Gnome redefines _() and N_(). Grrr... */ | |
35 # ifdef _ | |
36 # undef _ | |
37 # endif | |
38 # ifdef N_ | |
39 # undef N_ | |
40 # endif | |
41 # ifdef textdomain | |
42 # undef textdomain | |
43 # endif | |
44 # ifdef bindtextdomain | |
45 # undef bindtextdomain | |
46 # endif | |
1286 | 47 # ifdef bind_textdomain_codeset |
48 # undef bind_textdomain_codeset | |
1226 | 49 # endif |
7 | 50 # if defined(FEAT_GETTEXT) && !defined(ENABLE_NLS) |
51 # define ENABLE_NLS /* so the texts in the dialog boxes are translated */ | |
52 # endif | |
53 # include <gnome.h> | |
54 # include "version.h" | |
798 | 55 /* missing prototype in bonobo-dock-item.h */ |
56 extern void bonobo_dock_item_set_behavior(BonoboDockItem *dock_item, BonoboDockItemBehavior beh); | |
7 | 57 #endif |
58 | |
59 #if !defined(FEAT_GUI_GTK) && defined(PROTO) | |
60 /* When generating prototypes we don't want syntax errors. */ | |
61 # define GdkAtom int | |
62 # define GdkEventExpose int | |
63 # define GdkEventFocus int | |
64 # define GdkEventVisibility int | |
65 # define GdkEventProperty int | |
66 # define GtkContainer int | |
67 # define GtkTargetEntry int | |
68 # define GtkType int | |
69 # define GtkWidget int | |
70 # define gint int | |
71 # define gpointer int | |
72 # define guint int | |
73 # define GdkEventKey int | |
74 # define GdkEventSelection int | |
75 # define GtkSelectionData int | |
76 # define GdkEventMotion int | |
77 # define GdkEventButton int | |
78 # define GdkDragContext int | |
79 # define GdkEventConfigure int | |
80 # define GdkEventClient int | |
81 #else | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
82 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
83 # include <gdk/gdkkeysyms-compat.h> |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
84 # include <gtk/gtkx.h> |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
85 # else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
86 # include <gdk/gdkkeysyms.h> |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
87 # endif |
7 | 88 # include <gdk/gdk.h> |
89 # ifdef WIN3264 | |
90 # include <gdk/gdkwin32.h> | |
91 # else | |
92 # include <gdk/gdkx.h> | |
93 # endif | |
94 # include <gtk/gtk.h> | |
95 # include "gui_gtk_f.h" | |
96 #endif | |
97 | |
98 #ifdef HAVE_X11_SUNKEYSYM_H | |
99 # include <X11/Sunkeysym.h> | |
2714 | 100 #endif |
101 | |
7 | 102 /* |
103 * Easy-to-use macro for multihead support. | |
104 */ | |
105 #ifdef HAVE_GTK_MULTIHEAD | |
106 # define GET_X_ATOM(atom) gdk_x11_atom_to_xatom_for_display( \ | |
107 gtk_widget_get_display(gui.mainwin), atom) | |
108 #else | |
109 # define GET_X_ATOM(atom) ((Atom)(atom)) | |
110 #endif | |
111 | |
112 /* Selection type distinguishers */ | |
113 enum | |
114 { | |
115 TARGET_TYPE_NONE, | |
116 TARGET_UTF8_STRING, | |
117 TARGET_STRING, | |
118 TARGET_COMPOUND_TEXT, | |
1904 | 119 TARGET_HTML, |
7 | 120 TARGET_TEXT, |
121 TARGET_TEXT_URI_LIST, | |
122 TARGET_TEXT_PLAIN, | |
123 TARGET_VIM, | |
124 TARGET_VIMENC | |
125 }; | |
126 | |
127 /* | |
128 * Table of selection targets supported by Vim. | |
129 * Note: Order matters, preferred types should come first. | |
130 */ | |
131 static const GtkTargetEntry selection_targets[] = | |
132 { | |
133 {VIMENC_ATOM_NAME, 0, TARGET_VIMENC}, | |
134 {VIM_ATOM_NAME, 0, TARGET_VIM}, | |
1904 | 135 {"text/html", 0, TARGET_HTML}, |
7 | 136 {"UTF8_STRING", 0, TARGET_UTF8_STRING}, |
137 {"COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT}, | |
138 {"TEXT", 0, TARGET_TEXT}, | |
139 {"STRING", 0, TARGET_STRING} | |
140 }; | |
141 #define N_SELECTION_TARGETS (sizeof(selection_targets) / sizeof(selection_targets[0])) | |
142 | |
143 #ifdef FEAT_DND | |
144 /* | |
145 * Table of DnD targets supported by Vim. | |
146 * Note: Order matters, preferred types should come first. | |
147 */ | |
148 static const GtkTargetEntry dnd_targets[] = | |
149 { | |
150 {"text/uri-list", 0, TARGET_TEXT_URI_LIST}, | |
1904 | 151 {"text/html", 0, TARGET_HTML}, |
7 | 152 {"UTF8_STRING", 0, TARGET_UTF8_STRING}, |
153 {"STRING", 0, TARGET_STRING}, | |
154 {"text/plain", 0, TARGET_TEXT_PLAIN} | |
155 }; | |
156 # define N_DND_TARGETS (sizeof(dnd_targets) / sizeof(dnd_targets[0])) | |
157 #endif | |
158 | |
159 | |
160 /* | |
161 * "Monospace" is a standard font alias that should be present | |
162 * on all proper Pango/fontconfig installations. | |
163 */ | |
164 # define DEFAULT_FONT "Monospace 10" | |
165 | |
166 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
167 /* | |
168 * Atoms used to communicate save-yourself from the X11 session manager. There | |
169 * is no need to move them into the GUI struct, since they should be constant. | |
170 */ | |
171 static GdkAtom wm_protocols_atom = GDK_NONE; | |
172 static GdkAtom save_yourself_atom = GDK_NONE; | |
173 #endif | |
174 | |
175 /* | |
176 * Atoms used to control/reference X11 selections. | |
177 */ | |
1904 | 178 static GdkAtom html_atom = GDK_NONE; |
7 | 179 static GdkAtom utf8_string_atom = GDK_NONE; |
180 static GdkAtom vim_atom = GDK_NONE; /* Vim's own special selection format */ | |
181 static GdkAtom vimenc_atom = GDK_NONE; /* Vim's extended selection format */ | |
182 | |
183 /* | |
184 * Keycodes recognized by vim. | |
185 * NOTE: when changing this, the table in gui_x11.c probably needs the same | |
186 * change! | |
187 */ | |
188 static struct special_key | |
189 { | |
190 guint key_sym; | |
191 char_u code0; | |
192 char_u code1; | |
193 } | |
194 const special_keys[] = | |
195 { | |
196 {GDK_Up, 'k', 'u'}, | |
197 {GDK_Down, 'k', 'd'}, | |
198 {GDK_Left, 'k', 'l'}, | |
199 {GDK_Right, 'k', 'r'}, | |
200 {GDK_F1, 'k', '1'}, | |
201 {GDK_F2, 'k', '2'}, | |
202 {GDK_F3, 'k', '3'}, | |
203 {GDK_F4, 'k', '4'}, | |
204 {GDK_F5, 'k', '5'}, | |
205 {GDK_F6, 'k', '6'}, | |
206 {GDK_F7, 'k', '7'}, | |
207 {GDK_F8, 'k', '8'}, | |
208 {GDK_F9, 'k', '9'}, | |
209 {GDK_F10, 'k', ';'}, | |
210 {GDK_F11, 'F', '1'}, | |
211 {GDK_F12, 'F', '2'}, | |
212 {GDK_F13, 'F', '3'}, | |
213 {GDK_F14, 'F', '4'}, | |
214 {GDK_F15, 'F', '5'}, | |
215 {GDK_F16, 'F', '6'}, | |
216 {GDK_F17, 'F', '7'}, | |
217 {GDK_F18, 'F', '8'}, | |
218 {GDK_F19, 'F', '9'}, | |
219 {GDK_F20, 'F', 'A'}, | |
220 {GDK_F21, 'F', 'B'}, | |
221 {GDK_Pause, 'F', 'B'}, /* Pause == F21 according to netbeans.txt */ | |
222 {GDK_F22, 'F', 'C'}, | |
223 {GDK_F23, 'F', 'D'}, | |
224 {GDK_F24, 'F', 'E'}, | |
225 {GDK_F25, 'F', 'F'}, | |
226 {GDK_F26, 'F', 'G'}, | |
227 {GDK_F27, 'F', 'H'}, | |
228 {GDK_F28, 'F', 'I'}, | |
229 {GDK_F29, 'F', 'J'}, | |
230 {GDK_F30, 'F', 'K'}, | |
231 {GDK_F31, 'F', 'L'}, | |
232 {GDK_F32, 'F', 'M'}, | |
233 {GDK_F33, 'F', 'N'}, | |
234 {GDK_F34, 'F', 'O'}, | |
235 {GDK_F35, 'F', 'P'}, | |
236 #ifdef SunXK_F36 | |
237 {SunXK_F36, 'F', 'Q'}, | |
238 {SunXK_F37, 'F', 'R'}, | |
239 #endif | |
240 {GDK_Help, '%', '1'}, | |
241 {GDK_Undo, '&', '8'}, | |
242 {GDK_BackSpace, 'k', 'b'}, | |
243 {GDK_Insert, 'k', 'I'}, | |
244 {GDK_Delete, 'k', 'D'}, | |
245 {GDK_3270_BackTab, 'k', 'B'}, | |
246 {GDK_Clear, 'k', 'C'}, | |
247 {GDK_Home, 'k', 'h'}, | |
248 {GDK_End, '@', '7'}, | |
249 {GDK_Prior, 'k', 'P'}, | |
250 {GDK_Next, 'k', 'N'}, | |
251 {GDK_Print, '%', '9'}, | |
252 /* Keypad keys: */ | |
253 {GDK_KP_Left, 'k', 'l'}, | |
254 {GDK_KP_Right, 'k', 'r'}, | |
255 {GDK_KP_Up, 'k', 'u'}, | |
256 {GDK_KP_Down, 'k', 'd'}, | |
257 {GDK_KP_Insert, KS_EXTRA, (char_u)KE_KINS}, | |
258 {GDK_KP_Delete, KS_EXTRA, (char_u)KE_KDEL}, | |
259 {GDK_KP_Home, 'K', '1'}, | |
260 {GDK_KP_End, 'K', '4'}, | |
261 {GDK_KP_Prior, 'K', '3'}, /* page up */ | |
262 {GDK_KP_Next, 'K', '5'}, /* page down */ | |
263 | |
264 {GDK_KP_Add, 'K', '6'}, | |
265 {GDK_KP_Subtract, 'K', '7'}, | |
266 {GDK_KP_Divide, 'K', '8'}, | |
267 {GDK_KP_Multiply, 'K', '9'}, | |
268 {GDK_KP_Enter, 'K', 'A'}, | |
269 {GDK_KP_Decimal, 'K', 'B'}, | |
270 | |
271 {GDK_KP_0, 'K', 'C'}, | |
272 {GDK_KP_1, 'K', 'D'}, | |
273 {GDK_KP_2, 'K', 'E'}, | |
274 {GDK_KP_3, 'K', 'F'}, | |
275 {GDK_KP_4, 'K', 'G'}, | |
276 {GDK_KP_5, 'K', 'H'}, | |
277 {GDK_KP_6, 'K', 'I'}, | |
278 {GDK_KP_7, 'K', 'J'}, | |
279 {GDK_KP_8, 'K', 'K'}, | |
280 {GDK_KP_9, 'K', 'L'}, | |
281 | |
282 /* End of list marker: */ | |
283 {0, 0, 0} | |
284 }; | |
285 | |
286 /* | |
287 * Flags for command line options table below. | |
288 */ | |
289 #define ARG_FONT 1 | |
290 #define ARG_GEOMETRY 2 | |
291 #define ARG_REVERSE 3 | |
292 #define ARG_NOREVERSE 4 | |
293 #define ARG_BACKGROUND 5 | |
294 #define ARG_FOREGROUND 6 | |
295 #define ARG_ICONIC 7 | |
296 #define ARG_ROLE 8 | |
297 #define ARG_NETBEANS 9 | |
298 #define ARG_XRM 10 /* ignored */ | |
299 #define ARG_MENUFONT 11 /* ignored */ | |
300 #define ARG_INDEX_MASK 0x00ff | |
301 #define ARG_HAS_VALUE 0x0100 /* a value is expected after the argument */ | |
302 #define ARG_NEEDS_GUI 0x0200 /* need to initialize the GUI for this */ | |
303 #define ARG_FOR_GTK 0x0400 /* argument is handled by GTK+ or GNOME */ | |
304 #define ARG_COMPAT_LONG 0x0800 /* accept -foo but substitute with --foo */ | |
305 #define ARG_KEEP 0x1000 /* don't remove argument from argv[] */ | |
306 | |
307 /* | |
308 * This table holds all the X GUI command line options allowed. This includes | |
309 * the standard ones so that we can skip them when Vim is started without the | |
310 * GUI (but the GUI might start up later). | |
311 * | |
312 * When changing this, also update doc/gui_x11.txt and the usage message!!! | |
313 */ | |
314 typedef struct | |
315 { | |
316 const char *name; | |
317 unsigned int flags; | |
318 } | |
319 cmdline_option_T; | |
320 | |
321 static const cmdline_option_T cmdline_options[] = | |
322 { | |
323 /* We handle these options ourselves */ | |
324 {"-fn", ARG_FONT|ARG_HAS_VALUE}, | |
325 {"-font", ARG_FONT|ARG_HAS_VALUE}, | |
326 {"-geom", ARG_GEOMETRY|ARG_HAS_VALUE}, | |
327 {"-geometry", ARG_GEOMETRY|ARG_HAS_VALUE}, | |
328 {"-rv", ARG_REVERSE}, | |
329 {"-reverse", ARG_REVERSE}, | |
330 {"+rv", ARG_NOREVERSE}, | |
331 {"+reverse", ARG_NOREVERSE}, | |
332 {"-bg", ARG_BACKGROUND|ARG_HAS_VALUE}, | |
333 {"-background", ARG_BACKGROUND|ARG_HAS_VALUE}, | |
334 {"-fg", ARG_FOREGROUND|ARG_HAS_VALUE}, | |
335 {"-foreground", ARG_FOREGROUND|ARG_HAS_VALUE}, | |
336 {"-iconic", ARG_ICONIC}, | |
337 {"--role", ARG_ROLE|ARG_HAS_VALUE}, | |
338 #ifdef FEAT_NETBEANS_INTG | |
339 {"-nb", ARG_NETBEANS}, /* non-standard value format */ | |
340 {"-xrm", ARG_XRM|ARG_HAS_VALUE}, /* not implemented */ | |
341 {"-mf", ARG_MENUFONT|ARG_HAS_VALUE}, /* not implemented */ | |
342 {"-menufont", ARG_MENUFONT|ARG_HAS_VALUE}, /* not implemented */ | |
343 #endif | |
344 /* Arguments handled by GTK (and GNOME) internally. */ | |
345 {"--g-fatal-warnings", ARG_FOR_GTK}, | |
346 {"--gdk-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
347 {"--gdk-no-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
348 {"--gtk-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
349 {"--gtk-no-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
350 {"--gtk-module", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
351 {"--sync", ARG_FOR_GTK}, | |
352 {"--display", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
353 {"--name", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
354 {"--class", ARG_FOR_GTK|ARG_HAS_VALUE|ARG_COMPAT_LONG}, | |
355 {"--screen", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
356 {"--gxid-host", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
357 {"--gxid-port", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
358 #ifdef FEAT_GUI_GNOME | |
359 {"--load-modules", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
360 {"--sm-client-id", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
361 {"--sm-config-prefix", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
362 {"--sm-disable", ARG_FOR_GTK}, | |
363 {"--oaf-ior-fd", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
364 {"--oaf-activate-iid", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
365 {"--oaf-private", ARG_FOR_GTK}, | |
366 {"--enable-sound", ARG_FOR_GTK}, | |
367 {"--disable-sound", ARG_FOR_GTK}, | |
368 {"--espeaker", ARG_FOR_GTK|ARG_HAS_VALUE}, | |
369 {"-?", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
370 {"--help", ARG_FOR_GTK|ARG_NEEDS_GUI|ARG_KEEP}, | |
371 {"--usage", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
372 # if 0 /* conflicts with Vim's own --version argument */ | |
373 {"--version", ARG_FOR_GTK|ARG_NEEDS_GUI}, | |
374 # endif | |
375 {"--disable-crash-dialog", ARG_FOR_GTK}, | |
376 #endif | |
377 {NULL, 0} | |
378 }; | |
379 | |
380 static int gui_argc = 0; | |
381 static char **gui_argv = NULL; | |
382 | |
383 static const char *role_argument = NULL; | |
384 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
385 static const char *restart_command = NULL; | |
1898 | 386 static char *abs_restart_command = NULL; |
7 | 387 #endif |
388 static int found_iconic_arg = FALSE; | |
389 | |
390 #ifdef FEAT_GUI_GNOME | |
391 /* | |
392 * Can't use Gnome if --socketid given | |
393 */ | |
394 static int using_gnome = 0; | |
395 #else | |
396 # define using_gnome 0 | |
397 #endif | |
398 | |
399 /* | |
400 * Parse the GUI related command-line arguments. Any arguments used are | |
401 * deleted from argv, and *argc is decremented accordingly. This is called | |
402 * when vim is started, whether or not the GUI has been started. | |
403 */ | |
404 void | |
405 gui_mch_prepare(int *argc, char **argv) | |
406 { | |
407 const cmdline_option_T *option; | |
408 int i = 0; | |
409 int len = 0; | |
410 | |
411 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
412 /* | |
413 * Determine the command used to invoke Vim, to be passed as restart | |
414 * command to the session manager. If argv[0] contains any directory | |
415 * components try building an absolute path, otherwise leave it as is. | |
416 */ | |
417 restart_command = argv[0]; | |
418 | |
419 if (strchr(argv[0], G_DIR_SEPARATOR) != NULL) | |
420 { | |
421 char_u buf[MAXPATHL]; | |
422 | |
423 if (mch_FullName((char_u *)argv[0], buf, (int)sizeof(buf), TRUE) == OK) | |
1898 | 424 { |
425 abs_restart_command = (char *)vim_strsave(buf); | |
426 restart_command = abs_restart_command; | |
427 } | |
7 | 428 } |
429 #endif | |
430 | |
431 /* | |
432 * Move all the entries in argv which are relevant to GTK+ and GNOME | |
433 * into gui_argv. Freed later in gui_mch_init(). | |
434 */ | |
435 gui_argc = 0; | |
436 gui_argv = (char **)alloc((unsigned)((*argc + 1) * sizeof(char *))); | |
437 | |
438 g_return_if_fail(gui_argv != NULL); | |
439 | |
440 gui_argv[gui_argc++] = argv[i++]; | |
441 | |
442 while (i < *argc) | |
443 { | |
444 /* Don't waste CPU cycles on non-option arguments. */ | |
445 if (argv[i][0] != '-' && argv[i][0] != '+') | |
446 { | |
447 ++i; | |
448 continue; | |
449 } | |
450 | |
451 /* Look for argv[i] in cmdline_options[] table. */ | |
452 for (option = &cmdline_options[0]; option->name != NULL; ++option) | |
453 { | |
454 len = strlen(option->name); | |
455 | |
456 if (strncmp(argv[i], option->name, len) == 0) | |
457 { | |
458 if (argv[i][len] == '\0') | |
459 break; | |
460 /* allow --foo=bar style */ | |
461 if (argv[i][len] == '=' && (option->flags & ARG_HAS_VALUE)) | |
462 break; | |
463 #ifdef FEAT_NETBEANS_INTG | |
464 /* darn, -nb has non-standard syntax */ | |
465 if (vim_strchr((char_u *)":=", argv[i][len]) != NULL | |
466 && (option->flags & ARG_INDEX_MASK) == ARG_NETBEANS) | |
467 break; | |
468 #endif | |
469 } | |
470 else if ((option->flags & ARG_COMPAT_LONG) | |
471 && strcmp(argv[i], option->name + 1) == 0) | |
472 { | |
473 /* Replace the standard X arguments "-name" and "-display" | |
474 * with their GNU-style long option counterparts. */ | |
475 argv[i] = (char *)option->name; | |
476 break; | |
477 } | |
478 } | |
479 if (option->name == NULL) /* no match */ | |
480 { | |
481 ++i; | |
482 continue; | |
483 } | |
484 | |
485 if (option->flags & ARG_FOR_GTK) | |
486 { | |
487 /* Move the argument into gui_argv, which | |
488 * will later be passed to gtk_init_check() */ | |
489 gui_argv[gui_argc++] = argv[i]; | |
490 } | |
491 else | |
492 { | |
493 char *value = NULL; | |
494 | |
495 /* Extract the option's value if there is one. | |
496 * Accept both "--foo bar" and "--foo=bar" style. */ | |
497 if (option->flags & ARG_HAS_VALUE) | |
498 { | |
499 if (argv[i][len] == '=') | |
500 value = &argv[i][len + 1]; | |
501 else if (i + 1 < *argc && strcmp(argv[i + 1], "--") != 0) | |
502 value = argv[i + 1]; | |
503 } | |
504 | |
505 /* Check for options handled by Vim itself */ | |
506 switch (option->flags & ARG_INDEX_MASK) | |
507 { | |
508 case ARG_REVERSE: | |
509 found_reverse_arg = TRUE; | |
510 break; | |
511 case ARG_NOREVERSE: | |
512 found_reverse_arg = FALSE; | |
513 break; | |
514 case ARG_FONT: | |
515 font_argument = value; | |
516 break; | |
517 case ARG_GEOMETRY: | |
518 if (value != NULL) | |
519 gui.geom = vim_strsave((char_u *)value); | |
520 break; | |
521 case ARG_BACKGROUND: | |
522 background_argument = value; | |
523 break; | |
524 case ARG_FOREGROUND: | |
525 foreground_argument = value; | |
526 break; | |
527 case ARG_ICONIC: | |
528 found_iconic_arg = TRUE; | |
529 break; | |
530 case ARG_ROLE: | |
531 role_argument = value; /* used later in gui_mch_open() */ | |
532 break; | |
533 #ifdef FEAT_NETBEANS_INTG | |
534 case ARG_NETBEANS: | |
535 gui.dofork = FALSE; /* don't fork() when starting GUI */ | |
536 netbeansArg = argv[i]; | |
537 break; | |
538 #endif | |
539 default: | |
540 break; | |
541 } | |
542 } | |
543 | |
544 /* These arguments make gnome_program_init() print a message and exit. | |
545 * Must start the GUI for this, otherwise ":gui" will exit later! */ | |
546 if (option->flags & ARG_NEEDS_GUI) | |
547 gui.starting = TRUE; | |
548 | |
549 if (option->flags & ARG_KEEP) | |
550 ++i; | |
551 else | |
552 { | |
553 /* Remove the flag from the argument vector. */ | |
554 if (--*argc > i) | |
555 { | |
556 int n_strip = 1; | |
557 | |
558 /* Move the argument's value as well, if there is one. */ | |
559 if ((option->flags & ARG_HAS_VALUE) | |
560 && argv[i][len] != '=' | |
561 && strcmp(argv[i + 1], "--") != 0) | |
562 { | |
563 ++n_strip; | |
564 --*argc; | |
565 if (option->flags & ARG_FOR_GTK) | |
566 gui_argv[gui_argc++] = argv[i + 1]; | |
567 } | |
568 | |
569 if (*argc > i) | |
570 mch_memmove(&argv[i], &argv[i + n_strip], | |
571 (*argc - i) * sizeof(char *)); | |
572 } | |
573 argv[*argc] = NULL; | |
574 } | |
575 } | |
576 | |
577 gui_argv[gui_argc] = NULL; | |
578 } | |
579 | |
359 | 580 #if defined(EXITFREE) || defined(PROTO) |
581 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
582 gui_mch_free_all(void) |
359 | 583 { |
584 vim_free(gui_argv); | |
1898 | 585 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) |
586 vim_free(abs_restart_command); | |
587 #endif | |
359 | 588 } |
589 #endif | |
590 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
591 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 592 /* |
593 * This should be maybe completely removed. | |
594 * Doesn't seem possible, since check_copy_area() relies on | |
595 * this information. --danielk | |
596 */ | |
597 static gint | |
1884 | 598 visibility_event(GtkWidget *widget UNUSED, |
599 GdkEventVisibility *event, | |
600 gpointer data UNUSED) | |
7 | 601 { |
602 gui.visibility = event->state; | |
603 /* | |
604 * When we do an gdk_window_copy_area(), and the window is partially | |
605 * obscured, we want to receive an event to tell us whether it worked | |
606 * or not. | |
607 */ | |
608 if (gui.text_gc != NULL) | |
609 gdk_gc_set_exposures(gui.text_gc, | |
610 gui.visibility != GDK_VISIBILITY_UNOBSCURED); | |
611 return FALSE; | |
612 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
613 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 614 |
615 /* | |
616 * Redraw the corresponding portions of the screen. | |
617 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
618 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
619 static gboolean is_key_pressed = FALSE; |
8412
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
620 static gboolean blink_mode = TRUE; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
621 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
622 static gboolean gui_gtk_is_blink_on(void); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
623 static void gui_gtk_window_clear(GdkWindow *win); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
624 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
625 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
626 gui_gtk3_redraw(int x, int y, int width, int height) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
627 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
628 gui_redraw_block(Y_2_ROW(y), X_2_COL(x), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
629 Y_2_ROW(y + height - 1), X_2_COL(x + width - 1), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
630 GUI_MON_NOCLEAR); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
631 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
632 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
633 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
634 gui_gtk3_update_cursor(cairo_t *cr) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
635 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
636 if (gui.row == gui.cursor_row) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
637 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
638 gui.by_signal = TRUE; |
8495
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
639 if (State & CMDLINE) |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
640 gui_update_cursor(TRUE, FALSE); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
641 else |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
642 gui_update_cursor(TRUE, TRUE); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
643 gui.by_signal = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
644 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
645 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
646 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
647 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
648 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
649 gui_gtk3_should_draw_cursor(void) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
650 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
651 unsigned int cond = 0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
652 cond |= gui_gtk_is_blink_on(); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
653 cond |= is_key_pressed; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
654 cond |= gui.in_focus == FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
655 return cond; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
656 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
657 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
658 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
659 draw_event(GtkWidget *widget, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
660 cairo_t *cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
661 gpointer user_data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
662 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
663 /* Skip this when the GUI isn't set up yet, will redraw later. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
664 if (gui.starting) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
665 return FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
666 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
667 out_flush(); /* make sure all output has been processed */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
668 /* for GTK+ 3, may induce other draw events. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
669 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
670 cairo_set_source_surface(cr, gui.surface, 0, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
671 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
672 /* Draw the window without the cursor. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
673 gui.by_signal = TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
674 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
675 cairo_rectangle_list_t *list = NULL; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
676 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
677 gui_gtk_window_clear(gtk_widget_get_window(widget)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
678 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
679 list = cairo_copy_clip_rectangle_list(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
680 if (list->status != CAIRO_STATUS_CLIP_NOT_REPRESENTABLE) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
681 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
682 int i; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
683 for (i = 0; i < list->num_rectangles; i++) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
684 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
685 const cairo_rectangle_t rect = list->rectangles[i]; |
8412
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
686 if (blink_mode) |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
687 gui_gtk3_redraw(rect.x, rect.y, rect.width, rect.height); |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
688 else |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
689 gui_redraw(rect.x, rect.y, rect.width, rect.height); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
690 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
691 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
692 cairo_rectangle_list_destroy(list); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
693 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
694 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
695 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
696 gui.by_signal = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
697 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
698 /* Add the cursor to the window if necessary.*/ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
699 if (gui_gtk3_should_draw_cursor()) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
700 gui_gtk3_update_cursor(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
701 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
702 return FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
703 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
704 #else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 705 static gint |
1884 | 706 expose_event(GtkWidget *widget UNUSED, |
707 GdkEventExpose *event, | |
708 gpointer data UNUSED) | |
7 | 709 { |
710 /* Skip this when the GUI isn't set up yet, will redraw later. */ | |
711 if (gui.starting) | |
712 return FALSE; | |
713 | |
714 out_flush(); /* make sure all output has been processed */ | |
715 gui_redraw(event->area.x, event->area.y, | |
716 event->area.width, event->area.height); | |
717 | |
718 /* Clear the border areas if needed */ | |
719 if (event->area.x < FILL_X(0)) | |
720 gdk_window_clear_area(gui.drawarea->window, 0, 0, FILL_X(0), 0); | |
721 if (event->area.y < FILL_Y(0)) | |
722 gdk_window_clear_area(gui.drawarea->window, 0, 0, 0, FILL_Y(0)); | |
723 if (event->area.x > FILL_X(Columns)) | |
724 gdk_window_clear_area(gui.drawarea->window, | |
725 FILL_X((int)Columns), 0, 0, 0); | |
726 if (event->area.y > FILL_Y(Rows)) | |
727 gdk_window_clear_area(gui.drawarea->window, 0, FILL_Y((int)Rows), 0, 0); | |
728 | |
729 return FALSE; | |
730 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
731 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 732 |
733 #ifdef FEAT_CLIENTSERVER | |
734 /* | |
735 * Handle changes to the "Comm" property | |
736 */ | |
737 static gint | |
1884 | 738 property_event(GtkWidget *widget, |
739 GdkEventProperty *event, | |
740 gpointer data UNUSED) | |
7 | 741 { |
742 if (event->type == GDK_PROPERTY_NOTIFY | |
743 && event->state == (int)GDK_PROPERTY_NEW_VALUE | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
744 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
745 && GDK_WINDOW_XID(event->window) == commWindow |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
746 # else |
7 | 747 && GDK_WINDOW_XWINDOW(event->window) == commWindow |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
748 # endif |
7 | 749 && GET_X_ATOM(event->atom) == commProperty) |
750 { | |
751 XEvent xev; | |
752 | |
753 /* Translate to XLib */ | |
754 xev.xproperty.type = PropertyNotify; | |
755 xev.xproperty.atom = commProperty; | |
756 xev.xproperty.window = commWindow; | |
757 xev.xproperty.state = PropertyNewValue; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
758 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
759 serverEventProc(GDK_WINDOW_XDISPLAY(gtk_widget_get_window(widget)), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
760 &xev, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
761 # else |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7098
diff
changeset
|
762 serverEventProc(GDK_WINDOW_XDISPLAY(widget->window), &xev, 0); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
763 # endif |
7 | 764 } |
765 return FALSE; | |
766 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
767 #endif /* defined(FEAT_CLIENTSERVER) */ |
7 | 768 |
769 | |
770 /**************************************************************************** | |
771 * Focus handlers: | |
772 */ | |
773 | |
774 | |
775 /* | |
776 * This is a simple state machine: | |
777 * BLINK_NONE not blinking at all | |
778 * BLINK_OFF blinking, cursor is not shown | |
779 * BLINK_ON blinking, cursor is shown | |
780 */ | |
781 | |
782 #define BLINK_NONE 0 | |
783 #define BLINK_OFF 1 | |
784 #define BLINK_ON 2 | |
785 | |
786 static int blink_state = BLINK_NONE; | |
787 static long_u blink_waittime = 700; | |
788 static long_u blink_ontime = 400; | |
789 static long_u blink_offtime = 250; | |
790 static guint blink_timer = 0; | |
791 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
792 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
793 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
794 gui_gtk_is_blink_on(void) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
795 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
796 return blink_state == BLINK_ON; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
797 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
798 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
799 |
7 | 800 void |
801 gui_mch_set_blinking(long waittime, long on, long off) | |
802 { | |
8412
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
803 #if GTK_CHECK_VERSION(3,0,0) |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
804 if (waittime == 0 || on == 0 || off == 0) |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
805 { |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
806 blink_mode = FALSE; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
807 |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
808 blink_waittime = 700; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
809 blink_ontime = 400; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
810 blink_offtime = 250; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
811 } |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
812 else |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
813 { |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
814 blink_mode = TRUE; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
815 |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
816 blink_waittime = waittime; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
817 blink_ontime = on; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
818 blink_offtime = off; |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
819 } |
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
820 #else |
7 | 821 blink_waittime = waittime; |
822 blink_ontime = on; | |
823 blink_offtime = off; | |
8412
7ee2b87ba896
commit https://github.com/vim/vim/commit/0ecbe33718b06a3771fd2c65b331c8c9504657d7
Christian Brabandt <cb@256bit.org>
parents:
8397
diff
changeset
|
824 #endif |
7 | 825 } |
826 | |
827 /* | |
828 * Stop the cursor blinking. Show the cursor if it wasn't shown. | |
829 */ | |
830 void | |
831 gui_mch_stop_blink(void) | |
832 { | |
833 if (blink_timer) | |
834 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
835 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
836 g_source_remove(blink_timer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
837 #else |
7 | 838 gtk_timeout_remove(blink_timer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
839 #endif |
7 | 840 blink_timer = 0; |
841 } | |
842 if (blink_state == BLINK_OFF) | |
843 gui_update_cursor(TRUE, FALSE); | |
844 blink_state = BLINK_NONE; | |
845 } | |
846 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
847 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
848 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
849 #else |
7 | 850 static gint |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
851 #endif |
1884 | 852 blink_cb(gpointer data UNUSED) |
7 | 853 { |
854 if (blink_state == BLINK_ON) | |
855 { | |
856 gui_undraw_cursor(); | |
857 blink_state = BLINK_OFF; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
858 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
859 blink_timer = g_timeout_add((guint)blink_offtime, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
860 (GSourceFunc) blink_cb, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
861 #else |
7 | 862 blink_timer = gtk_timeout_add((guint32)blink_offtime, |
863 (GtkFunction) blink_cb, NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
864 #endif |
7 | 865 } |
866 else | |
867 { | |
868 gui_update_cursor(TRUE, FALSE); | |
869 blink_state = BLINK_ON; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
870 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
871 blink_timer = g_timeout_add((guint)blink_ontime, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
872 (GSourceFunc) blink_cb, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
873 #else |
7 | 874 blink_timer = gtk_timeout_add((guint32)blink_ontime, |
875 (GtkFunction) blink_cb, NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
876 #endif |
7 | 877 } |
878 | |
879 return FALSE; /* don't happen again */ | |
880 } | |
881 | |
882 /* | |
883 * Start the cursor blinking. If it was already blinking, this restarts the | |
884 * waiting time and shows the cursor. | |
885 */ | |
886 void | |
887 gui_mch_start_blink(void) | |
888 { | |
889 if (blink_timer) | |
5818 | 890 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
891 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
892 g_source_remove(blink_timer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
893 #else |
7 | 894 gtk_timeout_remove(blink_timer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
895 #endif |
5818 | 896 blink_timer = 0; |
897 } | |
7 | 898 /* Only switch blinking on if none of the times is zero */ |
899 if (blink_waittime && blink_ontime && blink_offtime && gui.in_focus) | |
900 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
901 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
902 blink_timer = g_timeout_add((guint)blink_waittime, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
903 (GSourceFunc) blink_cb, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
904 #else |
7 | 905 blink_timer = gtk_timeout_add((guint32)blink_waittime, |
906 (GtkFunction) blink_cb, NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
907 #endif |
7 | 908 blink_state = BLINK_ON; |
909 gui_update_cursor(TRUE, FALSE); | |
910 } | |
911 } | |
912 | |
913 static gint | |
1884 | 914 enter_notify_event(GtkWidget *widget UNUSED, |
915 GdkEventCrossing *event UNUSED, | |
916 gpointer data UNUSED) | |
7 | 917 { |
918 if (blink_state == BLINK_NONE) | |
919 gui_mch_start_blink(); | |
920 | |
921 /* make sure keyboard input goes there */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
922 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
923 if (gtk_socket_id == 0 || !gtk_widget_has_focus(gui.drawarea)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
924 #else |
7 | 925 if (gtk_socket_id == 0 || !GTK_WIDGET_HAS_FOCUS(gui.drawarea)) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
926 #endif |
7 | 927 gtk_widget_grab_focus(gui.drawarea); |
928 | |
929 return FALSE; | |
930 } | |
931 | |
932 static gint | |
1884 | 933 leave_notify_event(GtkWidget *widget UNUSED, |
934 GdkEventCrossing *event UNUSED, | |
935 gpointer data UNUSED) | |
7 | 936 { |
937 if (blink_state != BLINK_NONE) | |
938 gui_mch_stop_blink(); | |
939 | |
940 return FALSE; | |
941 } | |
942 | |
943 static gint | |
1884 | 944 focus_in_event(GtkWidget *widget, |
945 GdkEventFocus *event UNUSED, | |
946 gpointer data UNUSED) | |
7 | 947 { |
948 gui_focus_change(TRUE); | |
949 | |
950 if (blink_state == BLINK_NONE) | |
951 gui_mch_start_blink(); | |
952 | |
1380 | 953 /* make sure keyboard input goes to the draw area (if this is focus for a |
954 * window) */ | |
791 | 955 if (widget != gui.drawarea) |
856 | 956 gtk_widget_grab_focus(gui.drawarea); |
7 | 957 |
958 return TRUE; | |
959 } | |
960 | |
961 static gint | |
1884 | 962 focus_out_event(GtkWidget *widget UNUSED, |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2301
diff
changeset
|
963 GdkEventFocus *event UNUSED, |
1884 | 964 gpointer data UNUSED) |
7 | 965 { |
966 gui_focus_change(FALSE); | |
967 | |
968 if (blink_state != BLINK_NONE) | |
969 gui_mch_stop_blink(); | |
970 | |
971 return TRUE; | |
972 } | |
973 | |
974 | |
975 /* | |
976 * Translate a GDK key value to UTF-8 independently of the current locale. | |
977 * The output is written to string, which must have room for at least 6 bytes | |
978 * plus the NUL terminator. Returns the length in bytes. | |
979 * | |
980 * This function is used in the GTK+ 2 GUI only. The GTK+ 1 code makes use | |
981 * of GdkEventKey::string instead. But event->string is evil; see here why: | |
982 * http://developer.gnome.org/doc/API/2.0/gdk/gdk-Event-Structures.html#GdkEventKey | |
983 */ | |
984 static int | |
985 keyval_to_string(unsigned int keyval, unsigned int state, char_u *string) | |
986 { | |
987 int len; | |
988 guint32 uc; | |
989 | |
990 uc = gdk_keyval_to_unicode(keyval); | |
991 if (uc != 0) | |
992 { | |
993 /* Check for CTRL-foo */ | |
994 if ((state & GDK_CONTROL_MASK) && uc >= 0x20 && uc < 0x80) | |
995 { | |
996 /* These mappings look arbitrary at the first glance, but in fact | |
997 * resemble quite exactly the behaviour of the GTK+ 1.2 GUI on my | |
998 * machine. The only difference is BS vs. DEL for CTRL-8 (makes | |
999 * more sense and is consistent with usual terminal behaviour). */ | |
1000 if (uc >= '@') | |
1001 string[0] = uc & 0x1F; | |
1002 else if (uc == '2') | |
1003 string[0] = NUL; | |
1004 else if (uc >= '3' && uc <= '7') | |
1005 string[0] = uc ^ 0x28; | |
1006 else if (uc == '8') | |
1007 string[0] = BS; | |
1008 else if (uc == '?') | |
1009 string[0] = DEL; | |
1010 else | |
1011 string[0] = uc; | |
1012 len = 1; | |
1013 } | |
1014 else | |
1015 { | |
1016 /* Translate a normal key to UTF-8. This doesn't work for dead | |
1017 * keys of course, you _have_ to use an input method for that. */ | |
1018 len = utf_char2bytes((int)uc, string); | |
1019 } | |
1020 } | |
1021 else | |
1022 { | |
1023 /* Translate keys which are represented by ASCII control codes in Vim. | |
1024 * There are only a few of those; most control keys are translated to | |
1025 * special terminal-like control sequences. */ | |
1026 len = 1; | |
1027 switch (keyval) | |
1028 { | |
1029 case GDK_Tab: case GDK_KP_Tab: case GDK_ISO_Left_Tab: | |
1030 string[0] = TAB; | |
1031 break; | |
1032 case GDK_Linefeed: | |
1033 string[0] = NL; | |
1034 break; | |
1035 case GDK_Return: case GDK_ISO_Enter: case GDK_3270_Enter: | |
1036 string[0] = CAR; | |
1037 break; | |
1038 case GDK_Escape: | |
1039 string[0] = ESC; | |
1040 break; | |
1041 default: | |
1042 len = 0; | |
1043 break; | |
1044 } | |
1045 } | |
1046 string[len] = NUL; | |
1047 | |
1048 return len; | |
1049 } | |
1050 | |
179 | 1051 static int |
1052 modifiers_gdk2vim(guint state) | |
1053 { | |
1054 int modifiers = 0; | |
1055 | |
1056 if (state & GDK_SHIFT_MASK) | |
1057 modifiers |= MOD_MASK_SHIFT; | |
1058 if (state & GDK_CONTROL_MASK) | |
1059 modifiers |= MOD_MASK_CTRL; | |
1060 if (state & GDK_MOD1_MASK) | |
1061 modifiers |= MOD_MASK_ALT; | |
2550
7c1f73452ea6
Fix #ifdef for GDK_SUPER_MASK.
Bram Moolenaar <bram@vim.org>
parents:
2520
diff
changeset
|
1062 #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
|
1063 if (state & GDK_SUPER_MASK) |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1064 modifiers |= MOD_MASK_META; |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1065 #endif |
179 | 1066 if (state & GDK_MOD4_MASK) |
1067 modifiers |= MOD_MASK_META; | |
1068 | |
1069 return modifiers; | |
1070 } | |
1071 | |
1072 static int | |
1073 modifiers_gdk2mouse(guint state) | |
1074 { | |
1075 int modifiers = 0; | |
1076 | |
1077 if (state & GDK_SHIFT_MASK) | |
1078 modifiers |= MOUSE_SHIFT; | |
1079 if (state & GDK_CONTROL_MASK) | |
1080 modifiers |= MOUSE_CTRL; | |
1081 if (state & GDK_MOD1_MASK) | |
1082 modifiers |= MOUSE_ALT; | |
1083 | |
1084 return modifiers; | |
1085 } | |
1086 | |
7 | 1087 /* |
1088 * Main keyboard handler: | |
1089 */ | |
1090 static gint | |
1884 | 1091 key_press_event(GtkWidget *widget UNUSED, |
1092 GdkEventKey *event, | |
1093 gpointer data UNUSED) | |
7 | 1094 { |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1095 /* For GTK+ 2 we know for sure how large the string might get. |
7 | 1096 * (That is, up to 6 bytes + NUL + CSI escapes + safety measure.) */ |
1097 char_u string[32], string2[32]; | |
1098 guint key_sym; | |
1099 int len; | |
1100 int i; | |
1101 int modifiers; | |
1102 int key; | |
1103 guint state; | |
1104 char_u *s, *d; | |
1105 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1106 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1107 is_key_pressed = TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1108 gui_mch_stop_blink(); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1109 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1110 |
2923 | 1111 gui.event_time = event->time; |
7 | 1112 key_sym = event->keyval; |
1113 state = event->state; | |
1114 | |
1115 #ifdef FEAT_XIM | |
1116 if (xim_queue_key_press_event(event, TRUE)) | |
1117 return TRUE; | |
1118 #endif | |
1119 | |
1120 #ifdef FEAT_HANGULIN | |
1121 if (key_sym == GDK_space && (state & GDK_SHIFT_MASK)) | |
1122 { | |
1123 hangul_input_state_toggle(); | |
1124 return TRUE; | |
1125 } | |
1126 #endif | |
1127 | |
1128 #ifdef SunXK_F36 | |
1129 /* | |
1130 * These keys have bogus lookup strings, and trapping them here is | |
1131 * easier than trying to XRebindKeysym() on them with every possible | |
1132 * combination of modifiers. | |
1133 */ | |
1134 if (key_sym == SunXK_F36 || key_sym == SunXK_F37) | |
1135 len = 0; | |
1136 else | |
1137 #endif | |
1138 { | |
1139 len = keyval_to_string(key_sym, state, string2); | |
1140 | |
1141 /* Careful: convert_input() doesn't handle the NUL character. | |
1142 * No need to convert pure ASCII anyway, thus the len > 1 check. */ | |
1143 if (len > 1 && input_conv.vc_type != CONV_NONE) | |
1144 len = convert_input(string2, len, sizeof(string2)); | |
1145 | |
1146 s = string2; | |
1147 d = string; | |
1148 for (i = 0; i < len; ++i) | |
1149 { | |
1150 *d++ = s[i]; | |
1151 if (d[-1] == CSI && d + 2 < string + sizeof(string)) | |
1152 { | |
1153 /* Turn CSI into K_CSI. */ | |
1154 *d++ = KS_EXTRA; | |
1155 *d++ = (int)KE_CSI; | |
1156 } | |
1157 } | |
1158 len = d - string; | |
1159 } | |
1160 | |
1161 /* Shift-Tab results in Left_Tab, but we want <S-Tab> */ | |
1162 if (key_sym == GDK_ISO_Left_Tab) | |
1163 { | |
1164 key_sym = GDK_Tab; | |
1165 state |= GDK_SHIFT_MASK; | |
1166 } | |
1167 | |
1168 #ifdef FEAT_MENU | |
1169 /* If there is a menu and 'wak' is "yes", or 'wak' is "menu" and the key | |
1170 * is a menu shortcut, we ignore everything with the ALT modifier. */ | |
1171 if ((state & GDK_MOD1_MASK) | |
1172 && gui.menu_is_active | |
1173 && (*p_wak == 'y' | |
1174 || (*p_wak == 'm' | |
1175 && len == 1 | |
1176 && gui_is_menu_shortcut(string[0])))) | |
1177 /* For GTK2 we return false to signify that we haven't handled the | |
1178 * keypress, so that gtk will handle the mnemonic or accelerator. */ | |
1179 return FALSE; | |
1180 #endif | |
1181 | |
1182 /* Check for Alt/Meta key (Mod1Mask), but not for a BS, DEL or character | |
1183 * that already has the 8th bit set. | |
1184 * Don't do this for <S-M-Tab>, that should become K_S_TAB with ALT. | |
1185 * Don't do this for double-byte encodings, it turns the char into a lead | |
1186 * byte. */ | |
1187 if (len == 1 | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1188 && ((state & GDK_MOD1_MASK) |
2571
42bdbc2bbb59
Fix #ifdef for GDK_SUPER_MASK. (Stephan Schulz)
Bram Moolenaar <bram@vim.org>
parents:
2550
diff
changeset
|
1189 #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
|
1190 || (state & GDK_SUPER_MASK) |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1191 #endif |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1192 ) |
7 | 1193 && !(key_sym == GDK_BackSpace || key_sym == GDK_Delete) |
1194 && (string[0] & 0x80) == 0 | |
1195 && !(key_sym == GDK_Tab && (state & GDK_SHIFT_MASK)) | |
1196 && !enc_dbcs | |
1197 ) | |
1198 { | |
1199 string[0] |= 0x80; | |
1200 state &= ~GDK_MOD1_MASK; /* don't use it again */ | |
1201 if (enc_utf8) /* convert to utf-8 */ | |
1202 { | |
1203 string[1] = string[0] & 0xbf; | |
1204 string[0] = ((unsigned)string[0] >> 6) + 0xc0; | |
1205 if (string[1] == CSI) | |
1206 { | |
1207 string[2] = KS_EXTRA; | |
1208 string[3] = (int)KE_CSI; | |
1209 len = 4; | |
1210 } | |
1211 else | |
1212 len = 2; | |
1213 } | |
1214 } | |
1215 | |
1216 /* Check for special keys. Also do this when len == 1 (key has an ASCII | |
1217 * value) to detect backspace, delete and keypad keys. */ | |
1218 if (len == 0 || len == 1) | |
1219 { | |
1220 for (i = 0; special_keys[i].key_sym != 0; i++) | |
1221 { | |
1222 if (special_keys[i].key_sym == key_sym) | |
1223 { | |
1224 string[0] = CSI; | |
1225 string[1] = special_keys[i].code0; | |
1226 string[2] = special_keys[i].code1; | |
1227 len = -3; | |
1228 break; | |
1229 } | |
1230 } | |
1231 } | |
1232 | |
1233 if (len == 0) /* Unrecognized key */ | |
1234 return TRUE; | |
1235 | |
1236 /* Special keys (and a few others) may have modifiers. Also when using a | |
1237 * double-byte encoding (can't set the 8th bit). */ | |
1238 if (len == -3 || key_sym == GDK_space || key_sym == GDK_Tab | |
1239 || key_sym == GDK_Return || key_sym == GDK_Linefeed | |
1240 || key_sym == GDK_Escape || key_sym == GDK_KP_Tab | |
1241 || 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
|
1242 || (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
|
1243 #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
|
1244 || (state & GDK_SUPER_MASK) |
7 | 1245 #endif |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1246 ))) |
7 | 1247 { |
179 | 1248 modifiers = modifiers_gdk2vim(state); |
7 | 1249 |
1250 /* | |
1251 * For some keys a shift modifier is translated into another key | |
1252 * code. | |
1253 */ | |
1254 if (len == -3) | |
1255 key = TO_SPECIAL(string[1], string[2]); | |
1256 else | |
1257 key = string[0]; | |
1258 | |
1259 key = simplify_key(key, &modifiers); | |
1260 if (key == CSI) | |
1261 key = K_CSI; | |
1262 if (IS_SPECIAL(key)) | |
1263 { | |
1264 string[0] = CSI; | |
1265 string[1] = K_SECOND(key); | |
1266 string[2] = K_THIRD(key); | |
1267 len = 3; | |
1268 } | |
1269 else | |
1270 { | |
1271 string[0] = key; | |
1272 len = 1; | |
1273 } | |
1274 | |
1275 if (modifiers != 0) | |
1276 { | |
1277 string2[0] = CSI; | |
1278 string2[1] = KS_MODIFIER; | |
1279 string2[2] = modifiers; | |
1280 add_to_input_buf(string2, 3); | |
1281 } | |
1282 } | |
1283 | |
1284 if (len == 1 && ((string[0] == Ctrl_C && ctrl_c_interrupts) | |
1285 || (string[0] == intr_char && intr_char != Ctrl_C))) | |
1286 { | |
1287 trash_input_buf(); | |
1288 got_int = TRUE; | |
1289 } | |
1290 | |
1291 add_to_input_buf(string, len); | |
1292 | |
1293 /* blank out the pointer if necessary */ | |
1294 if (p_mh) | |
1295 gui_mch_mousehide(TRUE); | |
1296 | |
1297 return TRUE; | |
1298 } | |
1299 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1300 #if defined(FEAT_XIM) || GTK_CHECK_VERSION(3,0,0) |
7 | 1301 static gboolean |
1884 | 1302 key_release_event(GtkWidget *widget UNUSED, |
1303 GdkEventKey *event, | |
1304 gpointer data UNUSED) | |
7 | 1305 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1306 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1307 is_key_pressed = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1308 gui_mch_start_blink(); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1309 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1310 # if defined(FEAT_XIM) |
2923 | 1311 gui.event_time = event->time; |
7 | 1312 /* |
1313 * GTK+ 2 input methods may do fancy stuff on key release events too. | |
1314 * With the default IM for instance, you can enter any UCS code point | |
1315 * by holding down CTRL-SHIFT and typing hexadecimal digits. | |
1316 */ | |
1317 return xim_queue_key_press_event(event, FALSE); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1318 # else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1319 return TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1320 # endif |
7 | 1321 } |
1322 #endif | |
1323 | |
1324 | |
1325 /**************************************************************************** | |
1326 * Selection handlers: | |
1327 */ | |
1328 | |
1329 static gint | |
1884 | 1330 selection_clear_event(GtkWidget *widget UNUSED, |
7 | 1331 GdkEventSelection *event, |
1884 | 1332 gpointer user_data UNUSED) |
7 | 1333 { |
1334 if (event->selection == clip_plus.gtk_sel_atom) | |
1335 clip_lose_selection(&clip_plus); | |
1336 else | |
1337 clip_lose_selection(&clip_star); | |
1338 | |
1339 return TRUE; | |
1340 } | |
1341 | |
1342 #define RS_NONE 0 /* selection_received_cb() not called yet */ | |
1343 #define RS_OK 1 /* selection_received_cb() called and OK */ | |
1344 #define RS_FAIL 2 /* selection_received_cb() called and failed */ | |
1345 static int received_selection = RS_NONE; | |
1346 | |
1347 static void | |
1884 | 1348 selection_received_cb(GtkWidget *widget UNUSED, |
7 | 1349 GtkSelectionData *data, |
1884 | 1350 guint time_ UNUSED, |
1351 gpointer user_data UNUSED) | |
7 | 1352 { |
1353 VimClipboard *cbd; | |
1354 char_u *text; | |
1355 char_u *tmpbuf = NULL; | |
1356 guchar *tmpbuf_utf8 = NULL; | |
1357 int len; | |
2896 | 1358 int motion_type = MAUTO; |
7 | 1359 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1360 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1361 if (gtk_selection_data_get_selection(data) == clip_plus.gtk_sel_atom) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1362 #else |
7 | 1363 if (data->selection == clip_plus.gtk_sel_atom) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1364 #endif |
7 | 1365 cbd = &clip_plus; |
1366 else | |
1367 cbd = &clip_star; | |
1368 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1369 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1370 text = (char_u *)gtk_selection_data_get_data(data); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1371 len = gtk_selection_data_get_length(data); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1372 #else |
7 | 1373 text = (char_u *)data->data; |
1374 len = data->length; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1375 #endif |
7 | 1376 |
1377 if (text == NULL || len <= 0) | |
1378 { | |
1379 received_selection = RS_FAIL; | |
1380 /* clip_free_selection(cbd); ??? */ | |
1381 | |
1382 return; | |
1383 } | |
1384 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1385 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1386 if (gtk_selection_data_get_data_type(data) == vim_atom) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1387 #else |
7 | 1388 if (data->type == vim_atom) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1389 #endif |
7 | 1390 { |
1391 motion_type = *text++; | |
1392 --len; | |
1393 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1394 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1395 else if (gtk_selection_data_get_data_type(data) == vimenc_atom) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1396 #else |
7 | 1397 else if (data->type == vimenc_atom) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1398 #endif |
7 | 1399 { |
1400 char_u *enc; | |
1401 vimconv_T conv; | |
1402 | |
1403 motion_type = *text++; | |
1404 --len; | |
1405 | |
1406 enc = text; | |
1407 text += STRLEN(text) + 1; | |
1408 len -= text - enc; | |
1409 | |
1410 /* If the encoding of the text is different from 'encoding', attempt | |
1411 * converting it. */ | |
1412 conv.vc_type = CONV_NONE; | |
1413 convert_setup(&conv, enc, p_enc); | |
1414 if (conv.vc_type != CONV_NONE) | |
1415 { | |
1416 tmpbuf = string_convert(&conv, text, &len); | |
1417 if (tmpbuf != NULL) | |
1418 text = tmpbuf; | |
1419 convert_setup(&conv, NULL, NULL); | |
1420 } | |
1421 } | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1422 |
7 | 1423 /* gtk_selection_data_get_text() handles all the nasty details |
1424 * and targets and encodings etc. This rocks so hard. */ | |
1425 else | |
1426 { | |
1427 tmpbuf_utf8 = gtk_selection_data_get_text(data); | |
1428 if (tmpbuf_utf8 != NULL) | |
1429 { | |
1430 len = STRLEN(tmpbuf_utf8); | |
1431 if (input_conv.vc_type != CONV_NONE) | |
1432 { | |
1433 tmpbuf = string_convert(&input_conv, tmpbuf_utf8, &len); | |
1434 if (tmpbuf != NULL) | |
1435 text = tmpbuf; | |
1436 } | |
1437 else | |
1438 text = tmpbuf_utf8; | |
1439 } | |
1904 | 1440 else if (len >= 2 && text[0] == 0xff && text[1] == 0xfe) |
1441 { | |
1442 vimconv_T conv; | |
1443 | |
1444 /* UTF-16, we get this for HTML */ | |
1445 conv.vc_type = CONV_NONE; | |
1446 convert_setup_ext(&conv, (char_u *)"utf-16le", FALSE, p_enc, TRUE); | |
1447 | |
1448 if (conv.vc_type != CONV_NONE) | |
1449 { | |
1450 text += 2; | |
1451 len -= 2; | |
1452 tmpbuf = string_convert(&conv, text, &len); | |
1453 convert_setup(&conv, NULL, NULL); | |
1454 } | |
1455 if (tmpbuf != NULL) | |
1456 text = tmpbuf; | |
1457 } | |
7 | 1458 } |
1459 | |
4352 | 1460 /* Chop off any trailing NUL bytes. OpenOffice sends these. */ |
2183 | 1461 while (len > 0 && text[len - 1] == NUL) |
1462 --len; | |
1463 | |
7 | 1464 clip_yank_selection(motion_type, text, (long)len, cbd); |
1465 received_selection = RS_OK; | |
1466 vim_free(tmpbuf); | |
1467 g_free(tmpbuf_utf8); | |
1468 } | |
1469 | |
1470 /* | |
1471 * Prepare our selection data for passing it to the external selection | |
1472 * client. | |
1473 */ | |
1474 static void | |
1884 | 1475 selection_get_cb(GtkWidget *widget UNUSED, |
7 | 1476 GtkSelectionData *selection_data, |
1477 guint info, | |
1884 | 1478 guint time_ UNUSED, |
1479 gpointer user_data UNUSED) | |
7 | 1480 { |
1481 char_u *string; | |
1482 char_u *tmpbuf; | |
1483 long_u tmplen; | |
1484 int length; | |
1485 int motion_type; | |
1486 GdkAtom type; | |
1487 VimClipboard *cbd; | |
1488 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1489 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1490 if (gtk_selection_data_get_selection(selection_data) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1491 == clip_plus.gtk_sel_atom) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1492 #else |
7 | 1493 if (selection_data->selection == clip_plus.gtk_sel_atom) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1494 #endif |
7 | 1495 cbd = &clip_plus; |
1496 else | |
1497 cbd = &clip_star; | |
1498 | |
1499 if (!cbd->owned) | |
1500 return; /* Shouldn't ever happen */ | |
1501 | |
1502 if (info != (guint)TARGET_STRING | |
1904 | 1503 && (!clip_html || info != (guint)TARGET_HTML) |
7 | 1504 && info != (guint)TARGET_UTF8_STRING |
1505 && info != (guint)TARGET_VIMENC | |
1506 && info != (guint)TARGET_VIM | |
1507 && info != (guint)TARGET_COMPOUND_TEXT | |
1508 && info != (guint)TARGET_TEXT) | |
1509 return; | |
1510 | |
1511 /* get the selection from the '*'/'+' register */ | |
1512 clip_get_selection(cbd); | |
1513 | |
1514 motion_type = clip_convert_selection(&string, &tmplen, cbd); | |
1515 if (motion_type < 0 || string == NULL) | |
1516 return; | |
1517 /* Due to int arguments we can't handle more than G_MAXINT. Also | |
1518 * reserve one extra byte for NUL or the motion type; just in case. | |
1519 * (Not that pasting 2G of text is ever going to work, but... ;-) */ | |
1520 length = MIN(tmplen, (long_u)(G_MAXINT - 1)); | |
1521 | |
1522 if (info == (guint)TARGET_VIM) | |
1523 { | |
1524 tmpbuf = alloc((unsigned)length + 1); | |
1525 if (tmpbuf != NULL) | |
1526 { | |
1527 tmpbuf[0] = motion_type; | |
1528 mch_memmove(tmpbuf + 1, string, (size_t)length); | |
1529 } | |
1530 /* For our own format, the first byte contains the motion type */ | |
1531 ++length; | |
1532 vim_free(string); | |
1533 string = tmpbuf; | |
1534 type = vim_atom; | |
1535 } | |
1536 | |
1904 | 1537 else if (info == (guint)TARGET_HTML) |
1538 { | |
1539 vimconv_T conv; | |
1540 | |
1541 /* Since we get utf-16, we probably should set it as well. */ | |
1542 conv.vc_type = CONV_NONE; | |
1543 convert_setup_ext(&conv, p_enc, TRUE, (char_u *)"utf-16le", FALSE); | |
1544 if (conv.vc_type != CONV_NONE) | |
1545 { | |
1546 tmpbuf = string_convert(&conv, string, &length); | |
1547 convert_setup(&conv, NULL, NULL); | |
1548 vim_free(string); | |
1549 string = tmpbuf; | |
1550 } | |
1551 | |
1552 /* Prepend the BOM: "fffe" */ | |
1553 if (string != NULL) | |
1554 { | |
1555 tmpbuf = alloc(length + 2); | |
1556 tmpbuf[0] = 0xff; | |
1557 tmpbuf[1] = 0xfe; | |
1558 mch_memmove(tmpbuf + 2, string, (size_t)length); | |
1559 vim_free(string); | |
1560 string = tmpbuf; | |
1561 length += 2; | |
1562 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1563 #if !GTK_CHECK_VERSION(3,0,0) |
8301
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
1564 /* Looks redundant even for GTK2 because these values are |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1565 * overwritten by gtk_selection_data_set() that follows. */ |
1904 | 1566 selection_data->type = selection_data->target; |
1567 selection_data->format = 16; /* 16 bits per char */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1568 #endif |
1904 | 1569 gtk_selection_data_set(selection_data, html_atom, 16, |
1570 string, length); | |
1571 vim_free(string); | |
1572 } | |
1573 return; | |
1574 } | |
7 | 1575 else if (info == (guint)TARGET_VIMENC) |
1576 { | |
1577 int l = STRLEN(p_enc); | |
1578 | |
1579 /* contents: motion_type 'encoding' NUL text */ | |
1580 tmpbuf = alloc((unsigned)length + l + 2); | |
1581 if (tmpbuf != NULL) | |
1582 { | |
1583 tmpbuf[0] = motion_type; | |
1584 STRCPY(tmpbuf + 1, p_enc); | |
1585 mch_memmove(tmpbuf + l + 2, string, (size_t)length); | |
1586 } | |
1587 length += l + 2; | |
1588 vim_free(string); | |
1589 string = tmpbuf; | |
1590 type = vimenc_atom; | |
1591 } | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
1592 |
7 | 1593 /* gtk_selection_data_set_text() handles everything for us. This is |
1594 * so easy and simple and cool, it'd be insane not to use it. */ | |
1595 else | |
1596 { | |
1597 if (output_conv.vc_type != CONV_NONE) | |
1598 { | |
1599 tmpbuf = string_convert(&output_conv, string, &length); | |
1600 vim_free(string); | |
1601 if (tmpbuf == NULL) | |
1602 return; | |
1603 string = tmpbuf; | |
1604 } | |
1605 /* Validate the string to avoid runtime warnings */ | |
1606 if (g_utf8_validate((const char *)string, (gssize)length, NULL)) | |
1607 { | |
1608 gtk_selection_data_set_text(selection_data, | |
1609 (const char *)string, length); | |
1610 } | |
1611 vim_free(string); | |
1612 return; | |
1613 } | |
1614 | |
1615 if (string != NULL) | |
1616 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1617 #if !GTK_CHECK_VERSION(3,0,0) |
8301
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
1618 /* Looks redundant even for GTK2 because these values are |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1619 * overwritten by gtk_selection_data_set() that follows. */ |
7 | 1620 selection_data->type = selection_data->target; |
1621 selection_data->format = 8; /* 8 bits per char */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1622 #endif |
7 | 1623 gtk_selection_data_set(selection_data, type, 8, string, length); |
1624 vim_free(string); | |
1625 } | |
1626 } | |
1627 | |
1628 /* | |
3518 | 1629 * Check if the GUI can be started. Called before gvimrc is sourced and |
1630 * before fork(). | |
1631 * Return OK or FAIL. | |
1632 */ | |
1633 int | |
1634 gui_mch_early_init_check(void) | |
1635 { | |
1636 char_u *p; | |
1637 | |
1638 /* Guess that when $DISPLAY isn't set the GUI can't start. */ | |
1639 p = mch_getenv((char_u *)"DISPLAY"); | |
1640 if (p == NULL || *p == NUL) | |
1641 { | |
1642 gui.dying = TRUE; | |
1643 EMSG(_((char *)e_opendisp)); | |
1644 return FAIL; | |
1645 } | |
1646 return OK; | |
1647 } | |
1648 | |
1649 /* | |
1650 * Check if the GUI can be started. Called before gvimrc is sourced but after | |
1651 * fork(). | |
7 | 1652 * Return OK or FAIL. |
1653 */ | |
1654 int | |
1655 gui_mch_init_check(void) | |
1656 { | |
7679
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1657 #ifdef USE_GRESOURCE |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1658 static int res_registered = FALSE; |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1659 |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1660 if (!res_registered) |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1661 { |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1662 /* 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
|
1663 * 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
|
1664 res_registered = TRUE; |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1665 gui_gtk_register_resource(); |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1666 } |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1667 #endif |
c80284cfe1b8
commit https://github.com/vim/vim/commit/3a466a87180d677b898687ef72d09f14a397794e
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
1668 |
7 | 1669 #ifdef FEAT_GUI_GNOME |
1670 if (gtk_socket_id == 0) | |
1671 using_gnome = 1; | |
1672 #endif | |
1673 | |
4474 | 1674 /* This defaults to argv[0], but we want it to match the name of the |
1675 * shipped gvim.desktop so that Vim's windows can be associated with this | |
1676 * file. */ | |
1677 g_set_prgname("gvim"); | |
1678 | |
7 | 1679 /* Don't use gtk_init() or gnome_init(), it exits on failure. */ |
1680 if (!gtk_init_check(&gui_argc, &gui_argv)) | |
1681 { | |
1682 gui.dying = TRUE; | |
1666 | 1683 EMSG(_((char *)e_opendisp)); |
7 | 1684 return FAIL; |
1685 } | |
1686 | |
1687 return OK; | |
1688 } | |
1689 | |
1690 | |
1691 /**************************************************************************** | |
1692 * Mouse handling callbacks | |
1693 */ | |
1694 | |
1695 | |
1696 static guint mouse_click_timer = 0; | |
1697 static int mouse_timed_out = TRUE; | |
1698 | |
1699 /* | |
1700 * Timer used to recognize multiple clicks of the mouse button | |
1701 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1702 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1703 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1704 #else |
7 | 1705 static gint |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1706 #endif |
7 | 1707 mouse_click_timer_cb(gpointer data) |
1708 { | |
1709 /* we don't use this information currently */ | |
1710 int *timed_out = (int *) data; | |
1711 | |
1712 *timed_out = TRUE; | |
1713 return FALSE; /* don't happen again */ | |
1714 } | |
1715 | |
1716 static guint motion_repeat_timer = 0; | |
1717 static int motion_repeat_offset = FALSE; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1718 #ifdef GTK_DEST_DEFAULT_ALL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1719 static gboolean motion_repeat_timer_cb(gpointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1720 #else |
7 | 1721 static gint motion_repeat_timer_cb(gpointer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1722 #endif |
7 | 1723 |
1724 static void | |
1725 process_motion_notify(int x, int y, GdkModifierType state) | |
1726 { | |
1727 int button; | |
1728 int_u vim_modifiers; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1729 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1730 GtkAllocation allocation; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1731 #endif |
7 | 1732 |
1733 button = (state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | | |
1734 GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | | |
1735 GDK_BUTTON5_MASK)) | |
1736 ? MOUSE_DRAG : ' '; | |
1737 | |
1738 /* If our pointer is currently hidden, then we should show it. */ | |
1739 gui_mch_mousehide(FALSE); | |
1740 | |
1741 /* Just moving the rodent above the drawing area without any button | |
1742 * being pressed. */ | |
1743 if (button != MOUSE_DRAG) | |
1744 { | |
1745 gui_mouse_moved(x, y); | |
1746 return; | |
1747 } | |
1748 | |
1749 /* translate modifier coding between the main engine and GTK */ | |
179 | 1750 vim_modifiers = modifiers_gdk2mouse(state); |
7 | 1751 |
1226 | 1752 /* inform the editor engine about the occurrence of this event */ |
7 | 1753 gui_send_mouse_event(button, x, y, FALSE, vim_modifiers); |
1754 | |
1755 /* | |
1756 * Auto repeat timer handling. | |
1757 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1758 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1759 gtk_widget_get_allocation(gui.drawarea, &allocation); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1760 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1761 if (x < 0 || y < 0 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1762 || x >= allocation.width |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1763 || y >= allocation.height) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1764 #else |
7 | 1765 if (x < 0 || y < 0 |
1766 || x >= gui.drawarea->allocation.width | |
1767 || y >= gui.drawarea->allocation.height) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1768 #endif |
7 | 1769 { |
1770 | |
1771 int dx; | |
1772 int dy; | |
1773 int offshoot; | |
1774 int delay = 10; | |
1775 | |
1776 /* Calculate the maximal distance of the cursor from the drawing area. | |
1777 * (offshoot can't become negative here!). | |
1778 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1779 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1780 dx = x < 0 ? -x : x - allocation.width; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1781 dy = y < 0 ? -y : y - allocation.height; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1782 #else |
7 | 1783 dx = x < 0 ? -x : x - gui.drawarea->allocation.width; |
1784 dy = y < 0 ? -y : y - gui.drawarea->allocation.height; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1785 #endif |
7 | 1786 |
1787 offshoot = dx > dy ? dx : dy; | |
1788 | |
1884 | 1789 /* Make a linearly decaying timer delay with a threshold of 5 at a |
7 | 1790 * distance of 127 pixels from the main window. |
1791 * | |
1792 * One could think endlessly about the most ergonomic variant here. | |
1793 * For example it could make sense to calculate the distance from the | |
1794 * drags start instead... | |
1795 * | |
1796 * Maybe a parabolic interpolation would suite us better here too... | |
1797 */ | |
1798 if (offshoot > 127) | |
1799 { | |
1800 /* 5 appears to be somehow near to my perceptual limits :-). */ | |
1801 delay = 5; | |
1802 } | |
1803 else | |
1804 { | |
1805 delay = (130 * (127 - offshoot)) / 127 + 5; | |
1806 } | |
1807 | |
1808 /* shoot again */ | |
1809 if (!motion_repeat_timer) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1810 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1811 motion_repeat_timer = g_timeout_add((guint)delay, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1812 motion_repeat_timer_cb, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1813 #else |
7 | 1814 motion_repeat_timer = gtk_timeout_add((guint32)delay, |
1815 motion_repeat_timer_cb, NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1816 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1817 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1818 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1819 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1820 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1821 static GdkDevice * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1822 gui_gtk_get_pointer_device(GtkWidget *widget) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1823 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1824 GdkWindow * const win = gtk_widget_get_window(widget); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1825 GdkDisplay * const dpy = gdk_window_get_display(win); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1826 GdkDeviceManager * const mngr = gdk_display_get_device_manager(dpy); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1827 return gdk_device_manager_get_client_pointer(mngr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1828 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1829 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1830 static GdkWindow * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1831 gui_gtk_get_pointer(GtkWidget *widget, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1832 gint *x, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1833 gint *y, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1834 GdkModifierType *state) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1835 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1836 GdkWindow * const win = gtk_widget_get_window(widget); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1837 GdkDevice * const dev = gui_gtk_get_pointer_device(widget); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1838 return gdk_window_get_device_position(win, dev , x, y, state); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1839 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1840 |
8397
1e58a938aafc
commit https://github.com/vim/vim/commit/2369c15407cf9a730a396ebf9709abb280c5ce48
Christian Brabandt <cb@256bit.org>
parents:
8301
diff
changeset
|
1841 # if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1842 static GdkWindow * |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1843 gui_gtk_window_at_position(GtkWidget *widget, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1844 gint *x, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1845 gint *y) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1846 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1847 GdkDevice * const dev = gui_gtk_get_pointer_device(widget); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1848 return gdk_device_get_window_at_position(dev, x, y); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1849 } |
8397
1e58a938aafc
commit https://github.com/vim/vim/commit/2369c15407cf9a730a396ebf9709abb280c5ce48
Christian Brabandt <cb@256bit.org>
parents:
8301
diff
changeset
|
1850 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1851 #endif |
7 | 1852 |
1853 /* | |
1854 * Timer used to recognize multiple clicks of the mouse button. | |
1855 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1856 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1857 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1858 #else |
7 | 1859 static gint |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1860 #endif |
1884 | 1861 motion_repeat_timer_cb(gpointer data UNUSED) |
7 | 1862 { |
1863 int x; | |
1864 int y; | |
1865 GdkModifierType state; | |
1866 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1867 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1868 gui_gtk_get_pointer(gui.drawarea, &x, &y, &state); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1869 #else |
7 | 1870 gdk_window_get_pointer(gui.drawarea->window, &x, &y, &state); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1871 #endif |
7 | 1872 |
1873 if (!(state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | | |
1874 GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | | |
1875 GDK_BUTTON5_MASK))) | |
1876 { | |
1877 motion_repeat_timer = 0; | |
1878 return FALSE; | |
1879 } | |
1880 | |
1881 /* If there already is a mouse click in the input buffer, wait another | |
1882 * time (otherwise we would create a backlog of clicks) */ | |
1883 if (vim_used_in_input_buf() > 10) | |
1884 return TRUE; | |
1885 | |
1886 motion_repeat_timer = 0; | |
1887 | |
1888 /* | |
1889 * Fake a motion event. | |
1890 * Trick: Pretend the mouse moved to the next character on every other | |
1891 * event, otherwise drag events will be discarded, because they are still | |
1892 * in the same character. | |
1893 */ | |
1894 if (motion_repeat_offset) | |
1895 x += gui.char_width; | |
1896 | |
1897 motion_repeat_offset = !motion_repeat_offset; | |
1898 process_motion_notify(x, y, state); | |
1899 | |
1900 /* Don't happen again. We will get reinstalled in the synthetic event | |
1901 * if needed -- thus repeating should still work. */ | |
1902 return FALSE; | |
1903 } | |
1904 | |
1905 static gint | |
1884 | 1906 motion_notify_event(GtkWidget *widget, |
1907 GdkEventMotion *event, | |
1908 gpointer data UNUSED) | |
7 | 1909 { |
1910 if (event->is_hint) | |
1911 { | |
1912 int x; | |
1913 int y; | |
1914 GdkModifierType state; | |
1915 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1916 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1917 gui_gtk_get_pointer(widget, &x, &y, &state); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1918 #else |
7 | 1919 gdk_window_get_pointer(widget->window, &x, &y, &state); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1920 #endif |
7 | 1921 process_motion_notify(x, y, state); |
1922 } | |
1923 else | |
1924 { | |
1925 process_motion_notify((int)event->x, (int)event->y, | |
1926 (GdkModifierType)event->state); | |
1927 } | |
1928 | |
1929 return TRUE; /* handled */ | |
1930 } | |
1931 | |
1932 | |
1933 /* | |
1934 * Mouse button handling. Note please that we are capturing multiple click's | |
1935 * by our own timeout mechanism instead of the one provided by GTK+ itself. | |
1936 * This is due to the way the generic VIM code is recognizing multiple clicks. | |
1937 */ | |
1938 static gint | |
1884 | 1939 button_press_event(GtkWidget *widget, |
1940 GdkEventButton *event, | |
1941 gpointer data UNUSED) | |
7 | 1942 { |
1943 int button; | |
1944 int repeated_click = FALSE; | |
1945 int x, y; | |
1946 int_u vim_modifiers; | |
1947 | |
2923 | 1948 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
|
1949 |
7 | 1950 /* Make sure we have focus now we've been selected */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1951 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1952 if (gtk_socket_id != 0 && !gtk_widget_has_focus(widget)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1953 #else |
7 | 1954 if (gtk_socket_id != 0 && !GTK_WIDGET_HAS_FOCUS(widget)) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1955 #endif |
7 | 1956 gtk_widget_grab_focus(widget); |
1957 | |
1958 /* | |
1959 * Don't let additional events about multiple clicks send by GTK to us | |
1960 * after the initial button press event confuse us. | |
1961 */ | |
1962 if (event->type != GDK_BUTTON_PRESS) | |
1963 return FALSE; | |
1964 | |
1965 x = event->x; | |
1966 y = event->y; | |
1967 | |
1968 /* Handle multiple clicks */ | |
1969 if (!mouse_timed_out && mouse_click_timer) | |
1970 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1971 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1972 g_source_remove(mouse_click_timer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1973 #else |
7 | 1974 gtk_timeout_remove(mouse_click_timer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1975 #endif |
7 | 1976 mouse_click_timer = 0; |
1977 repeated_click = TRUE; | |
1978 } | |
1979 | |
1980 mouse_timed_out = FALSE; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1981 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1982 mouse_click_timer = g_timeout_add((guint)p_mouset, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1983 mouse_click_timer_cb, &mouse_timed_out); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1984 #else |
7 | 1985 mouse_click_timer = gtk_timeout_add((guint32)p_mouset, |
1986 mouse_click_timer_cb, &mouse_timed_out); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
1987 #endif |
7 | 1988 |
1989 switch (event->button) | |
1990 { | |
7260
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1991 /* 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
|
1992 * 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
|
1993 case 1: button = MOUSE_LEFT; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1994 case 2: button = MOUSE_MIDDLE; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1995 case 3: button = MOUSE_RIGHT; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1996 case 8: button = MOUSE_X1; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1997 case 9: button = MOUSE_X2; break; |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1998 default: |
8ba562cb3e07
commit https://github.com/vim/vim/commit/88e484bf1b0afb5f2dec44f19335729578ace66a
Christian Brabandt <cb@256bit.org>
parents:
7109
diff
changeset
|
1999 return FALSE; /* Unknown button */ |
7 | 2000 } |
2001 | |
2002 #ifdef FEAT_XIM | |
2003 /* cancel any preediting */ | |
2004 if (im_is_preediting()) | |
2005 xim_reset(); | |
2006 #endif | |
2007 | |
179 | 2008 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 2009 |
2010 gui_send_mouse_event(button, x, y, repeated_click, vim_modifiers); | |
2011 | |
2012 return TRUE; | |
2013 } | |
2014 | |
2015 /* | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
2016 * GTK+ 2 abstracts scrolling via the GdkEventScroll. |
7 | 2017 */ |
2018 static gboolean | |
1884 | 2019 scroll_event(GtkWidget *widget, |
2020 GdkEventScroll *event, | |
2021 gpointer data UNUSED) | |
7 | 2022 { |
2023 int button; | |
179 | 2024 int_u vim_modifiers; |
7 | 2025 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2026 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2027 if (gtk_socket_id != 0 && !gtk_widget_has_focus(widget)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2028 #else |
7 | 2029 if (gtk_socket_id != 0 && !GTK_WIDGET_HAS_FOCUS(widget)) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2030 #endif |
7 | 2031 gtk_widget_grab_focus(widget); |
2032 | |
2033 switch (event->direction) | |
2034 { | |
2035 case GDK_SCROLL_UP: | |
2036 button = MOUSE_4; | |
2037 break; | |
2038 case GDK_SCROLL_DOWN: | |
2039 button = MOUSE_5; | |
2040 break; | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2041 case GDK_SCROLL_LEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2042 button = MOUSE_7; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2043 break; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2044 case GDK_SCROLL_RIGHT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2045 button = MOUSE_6; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2046 break; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2047 default: /* This shouldn't happen */ |
7 | 2048 return FALSE; |
2049 } | |
2050 | |
2051 # ifdef FEAT_XIM | |
2052 /* cancel any preediting */ | |
2053 if (im_is_preediting()) | |
2054 xim_reset(); | |
2055 # endif | |
2056 | |
179 | 2057 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 2058 |
2059 gui_send_mouse_event(button, (int)event->x, (int)event->y, | |
2060 FALSE, vim_modifiers); | |
2061 | |
2062 return TRUE; | |
2063 } | |
2064 | |
2065 | |
2066 static gint | |
1884 | 2067 button_release_event(GtkWidget *widget UNUSED, |
2068 GdkEventButton *event, | |
2069 gpointer data UNUSED) | |
7 | 2070 { |
2071 int x, y; | |
2072 int_u vim_modifiers; | |
2073 | |
2923 | 2074 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
|
2075 |
7 | 2076 /* Remove any motion "machine gun" timers used for automatic further |
2077 extension of allocation areas if outside of the applications window | |
2078 area .*/ | |
2079 if (motion_repeat_timer) | |
2080 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2081 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2082 g_source_remove(motion_repeat_timer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2083 #else |
7 | 2084 gtk_timeout_remove(motion_repeat_timer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2085 #endif |
7 | 2086 motion_repeat_timer = 0; |
2087 } | |
2088 | |
2089 x = event->x; | |
2090 y = event->y; | |
2091 | |
179 | 2092 vim_modifiers = modifiers_gdk2mouse(event->state); |
7 | 2093 |
2094 gui_send_mouse_event(MOUSE_RELEASE, x, y, FALSE, vim_modifiers); | |
2095 | |
2096 return TRUE; | |
2097 } | |
2098 | |
2099 | |
2100 #ifdef FEAT_DND | |
2101 /**************************************************************************** | |
2102 * Drag aNd Drop support handlers. | |
2103 */ | |
2104 | |
2105 /* | |
2106 * Count how many items there may be and separate them with a NUL. | |
2107 * Apparently the items are separated with \r\n. This is not documented, | |
2108 * thus be careful not to go past the end. Also allow separation with | |
2109 * NUL characters. | |
2110 */ | |
2111 static int | |
2112 count_and_decode_uri_list(char_u *out, char_u *raw, int len) | |
2113 { | |
2114 int i; | |
2115 char_u *p = out; | |
2116 int count = 0; | |
2117 | |
2118 for (i = 0; i < len; ++i) | |
2119 { | |
2120 if (raw[i] == NUL || raw[i] == '\n' || raw[i] == '\r') | |
2121 { | |
2122 if (p > out && p[-1] != NUL) | |
2123 { | |
2124 ++count; | |
2125 *p++ = NUL; | |
2126 } | |
2127 } | |
2128 else if (raw[i] == '%' && i + 2 < len && hexhex2nr(raw + i + 1) > 0) | |
2129 { | |
2130 *p++ = hexhex2nr(raw + i + 1); | |
2131 i += 2; | |
2132 } | |
2133 else | |
2134 *p++ = raw[i]; | |
2135 } | |
2136 if (p > out && p[-1] != NUL) | |
2137 { | |
2138 *p = NUL; /* last item didn't have \r or \n */ | |
2139 ++count; | |
2140 } | |
2141 return count; | |
2142 } | |
2143 | |
2144 /* | |
2145 * Parse NUL separated "src" strings. Make it an array "outlist" form. On | |
2146 * this process, URI which protocol is not "file:" are removed. Return | |
2147 * length of array (less than "max"). | |
2148 */ | |
2149 static int | |
2150 filter_uri_list(char_u **outlist, int max, char_u *src) | |
2151 { | |
2152 int i, j; | |
2153 | |
2154 for (i = j = 0; i < max; ++i) | |
2155 { | |
2156 outlist[i] = NULL; | |
2157 if (STRNCMP(src, "file:", 5) == 0) | |
2158 { | |
2159 src += 5; | |
2160 if (STRNCMP(src, "//localhost", 11) == 0) | |
2161 src += 11; | |
2162 while (src[0] == '/' && src[1] == '/') | |
2163 ++src; | |
2164 outlist[j++] = vim_strsave(src); | |
2165 } | |
2166 src += STRLEN(src) + 1; | |
2167 } | |
2168 return j; | |
2169 } | |
2170 | |
2171 static char_u ** | |
2172 parse_uri_list(int *count, char_u *data, int len) | |
2173 { | |
2174 int n = 0; | |
2175 char_u *tmp = NULL; | |
2176 char_u **array = NULL;; | |
2177 | |
2178 if (data != NULL && len > 0 && (tmp = (char_u *)alloc(len + 1)) != NULL) | |
2179 { | |
2180 n = count_and_decode_uri_list(tmp, data, len); | |
2181 if (n > 0 && (array = (char_u **)alloc(n * sizeof(char_u *))) != NULL) | |
2182 n = filter_uri_list(array, n, tmp); | |
2183 } | |
2184 vim_free(tmp); | |
2185 *count = n; | |
2186 return array; | |
2187 } | |
2188 | |
2189 static void | |
2190 drag_handle_uri_list(GdkDragContext *context, | |
2191 GtkSelectionData *data, | |
2192 guint time_, | |
2193 GdkModifierType state, | |
2194 gint x, | |
2195 gint y) | |
2196 { | |
2197 char_u **fnames; | |
2198 int nfiles = 0; | |
2199 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2200 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2201 fnames = parse_uri_list(&nfiles, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2202 (char_u *)gtk_selection_data_get_data(data), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2203 gtk_selection_data_get_length(data)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2204 # else |
7 | 2205 fnames = parse_uri_list(&nfiles, data->data, data->length); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2206 # endif |
7 | 2207 |
2208 if (fnames != NULL && nfiles > 0) | |
2209 { | |
179 | 2210 int_u modifiers; |
7 | 2211 |
2212 gtk_drag_finish(context, TRUE, FALSE, time_); /* accept */ | |
2213 | |
179 | 2214 modifiers = modifiers_gdk2mouse(state); |
7 | 2215 |
2216 gui_handle_drop(x, y, modifiers, fnames, nfiles); | |
2217 } | |
840 | 2218 else |
2219 vim_free(fnames); | |
7 | 2220 } |
2221 | |
2222 static void | |
2223 drag_handle_text(GdkDragContext *context, | |
2224 GtkSelectionData *data, | |
2225 guint time_, | |
2226 GdkModifierType state) | |
2227 { | |
2228 char_u dropkey[6] = {CSI, KS_MODIFIER, 0, CSI, KS_EXTRA, (char_u)KE_DROP}; | |
2229 char_u *text; | |
2230 int len; | |
2231 char_u *tmpbuf = NULL; | |
2232 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2233 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2234 text = (char_u *)gtk_selection_data_get_data(data); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2235 len = gtk_selection_data_get_length(data); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2236 # else |
7 | 2237 text = data->data; |
2238 len = data->length; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2239 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2240 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2241 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2242 if (gtk_selection_data_get_data_type(data) == utf8_string_atom) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2243 # else |
7 | 2244 if (data->type == utf8_string_atom) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2245 # endif |
7 | 2246 { |
2247 if (input_conv.vc_type != CONV_NONE) | |
2248 tmpbuf = string_convert(&input_conv, text, &len); | |
2249 if (tmpbuf != NULL) | |
2250 text = tmpbuf; | |
2251 } | |
2252 | |
2253 dnd_yank_drag_data(text, (long)len); | |
2254 gtk_drag_finish(context, TRUE, FALSE, time_); /* accept */ | |
2255 vim_free(tmpbuf); | |
2256 | |
179 | 2257 dropkey[2] = modifiers_gdk2vim(state); |
7 | 2258 |
2259 if (dropkey[2] != 0) | |
2260 add_to_input_buf(dropkey, (int)sizeof(dropkey)); | |
2261 else | |
2262 add_to_input_buf(dropkey + 3, (int)(sizeof(dropkey) - 3)); | |
2263 } | |
2264 | |
2265 /* | |
2266 * DND receiver. | |
2267 */ | |
2268 static void | |
2269 drag_data_received_cb(GtkWidget *widget, | |
2270 GdkDragContext *context, | |
2271 gint x, | |
2272 gint y, | |
2273 GtkSelectionData *data, | |
2274 guint info, | |
2275 guint time_, | |
1884 | 2276 gpointer user_data UNUSED) |
7 | 2277 { |
2278 GdkModifierType state; | |
2279 | |
2280 /* Guard against trash */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2281 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2282 const guchar * const data_data = gtk_selection_data_get_data(data); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2283 const gint data_length = gtk_selection_data_get_length(data); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2284 const gint data_format = gtk_selection_data_get_format(data); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2285 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2286 if (data_data == NULL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2287 || data_length <= 0 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2288 || data_format != 8 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2289 || data_data[data_length] != '\0') |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2290 # else |
7 | 2291 if (data->data == NULL |
2292 || data->length <= 0 | |
2293 || data->format != 8 | |
2294 || data->data[data->length] != '\0') | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2295 # endif |
7 | 2296 { |
2297 gtk_drag_finish(context, FALSE, FALSE, time_); | |
2298 return; | |
2299 } | |
2300 | |
2301 /* Get the current modifier state for proper distinguishment between | |
2302 * different operations later. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2303 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2304 gui_gtk_get_pointer(widget, NULL, NULL, &state); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2305 # else |
7 | 2306 gdk_window_get_pointer(widget->window, NULL, NULL, &state); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2307 # endif |
7 | 2308 |
2309 /* Not sure about the role of "text/plain" here... */ | |
2310 if (info == (guint)TARGET_TEXT_URI_LIST) | |
2311 drag_handle_uri_list(context, data, time_, state, x, y); | |
2312 else | |
2313 drag_handle_text(context, data, time_, state); | |
2314 | |
2315 } | |
2316 #endif /* FEAT_DND */ | |
2317 | |
2318 | |
2319 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
2320 /* | |
2321 * GnomeClient interact callback. Check for unsaved buffers that cannot | |
2322 * be abandoned and pop up a dialog asking the user for confirmation if | |
2323 * necessary. | |
2324 */ | |
2325 static void | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2326 sm_client_check_changed_any(GnomeClient *client UNUSED, |
7 | 2327 gint key, |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2328 GnomeDialogType type UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2329 gpointer data UNUSED) |
7 | 2330 { |
2331 cmdmod_T save_cmdmod; | |
2332 gboolean shutdown_cancelled; | |
2333 | |
2334 save_cmdmod = cmdmod; | |
2335 | |
2336 # ifdef FEAT_BROWSE | |
2337 cmdmod.browse = TRUE; | |
2338 # endif | |
2339 # if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
2340 cmdmod.confirm = TRUE; | |
2341 # endif | |
2342 /* | |
2343 * If there are changed buffers, present the user with | |
2344 * a dialog if possible, otherwise give an error message. | |
2345 */ | |
7469
15eefe1b0dad
commit https://github.com/vim/vim/commit/027387f70c671f62e3e08e0bdd09ec05b0232735
Christian Brabandt <cb@256bit.org>
parents:
7380
diff
changeset
|
2346 shutdown_cancelled = check_changed_any(FALSE, FALSE); |
7 | 2347 |
2348 exiting = FALSE; | |
2349 cmdmod = save_cmdmod; | |
2350 setcursor(); /* position the cursor */ | |
2351 out_flush(); | |
2352 /* | |
2353 * If the user hit the [Cancel] button the whole shutdown | |
2354 * will be cancelled. Wow, quite powerful feature (: | |
2355 */ | |
2356 gnome_interaction_key_return(key, shutdown_cancelled); | |
2357 } | |
2358 | |
2359 /* | |
2360 * Generate a script that can be used to restore the current editing session. | |
2361 * Save the value of v:this_session before running :mksession in order to make | |
2362 * automagic session save fully transparent. Return TRUE on success. | |
2363 */ | |
2364 static int | |
2365 write_session_file(char_u *filename) | |
2366 { | |
2367 char_u *escaped_filename; | |
2368 char *mksession_cmdline; | |
2369 unsigned int save_ssop_flags; | |
2370 int failed; | |
2371 | |
2372 /* | |
2373 * Build an ex command line to create a script that restores the current | |
2374 * session if executed. Escape the filename to avoid nasty surprises. | |
2375 */ | |
2376 escaped_filename = vim_strsave_escaped(filename, escape_chars); | |
2377 if (escaped_filename == NULL) | |
2378 return FALSE; | |
1296 | 2379 mksession_cmdline = g_strconcat("mksession ", (char *)escaped_filename, |
2380 NULL); | |
7 | 2381 vim_free(escaped_filename); |
1296 | 2382 |
7 | 2383 /* |
2384 * Use a reasonable hardcoded set of 'sessionoptions' flags to avoid | |
2385 * unpredictable effects when the session is saved automatically. Also, | |
2386 * we definitely need SSOP_GLOBALS to be able to restore v:this_session. | |
2387 * Don't use SSOP_BUFFERS to prevent the buffer list from becoming | |
2388 * enormously large if the GNOME session feature is used regularly. | |
2389 */ | |
2390 save_ssop_flags = ssop_flags; | |
2391 ssop_flags = (SSOP_BLANK|SSOP_CURDIR|SSOP_FOLDS|SSOP_GLOBALS | |
1296 | 2392 |SSOP_HELP|SSOP_OPTIONS|SSOP_WINSIZE|SSOP_TABPAGES); |
7 | 2393 |
2394 do_cmdline_cmd((char_u *)"let Save_VV_this_session = v:this_session"); | |
2395 failed = (do_cmdline_cmd((char_u *)mksession_cmdline) == FAIL); | |
2396 do_cmdline_cmd((char_u *)"let v:this_session = Save_VV_this_session"); | |
150 | 2397 do_unlet((char_u *)"Save_VV_this_session", TRUE); |
7 | 2398 |
2399 ssop_flags = save_ssop_flags; | |
2400 g_free(mksession_cmdline); | |
5905 | 2401 |
7 | 2402 /* |
2403 * Reopen the file and append a command to restore v:this_session, | |
2404 * as if this save never happened. This is to avoid conflicts with | |
2405 * the user's own sessions. FIXME: It's probably less hackish to add | |
2406 * a "stealth" flag to 'sessionoptions' -- gotta ask Bram. | |
2407 */ | |
2408 if (!failed) | |
2409 { | |
2410 FILE *fd; | |
2411 | |
2412 fd = open_exfile(filename, TRUE, APPENDBIN); | |
2413 | |
2414 failed = (fd == NULL | |
2415 || put_line(fd, "let v:this_session = Save_VV_this_session") == FAIL | |
2416 || put_line(fd, "unlet Save_VV_this_session") == FAIL); | |
2417 | |
2418 if (fd != NULL && fclose(fd) != 0) | |
2419 failed = TRUE; | |
2420 | |
2421 if (failed) | |
2422 mch_remove(filename); | |
2423 } | |
2424 | |
2425 return !failed; | |
2426 } | |
2427 | |
2428 /* | |
2429 * "save_yourself" signal handler. Initiate an interaction to ask the user | |
2430 * for confirmation if necessary. Save the current editing session and tell | |
2431 * the session manager how to restart Vim. | |
2432 */ | |
2433 static gboolean | |
2434 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
|
2435 gint phase UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2436 GnomeSaveStyle save_style UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2437 gboolean shutdown UNUSED, |
7 | 2438 GnomeInteractStyle interact_style, |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2439 gboolean fast UNUSED, |
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2440 gpointer data UNUSED) |
7 | 2441 { |
2442 static const char suffix[] = "-session.vim"; | |
2443 char *session_file; | |
2444 unsigned int len; | |
2445 gboolean success; | |
2446 | |
2447 /* Always request an interaction if possible. check_changed_any() | |
2448 * won't actually show a dialog unless any buffers have been modified. | |
2449 * There doesn't seem to be an obvious way to check that without | |
2450 * automatically firing the dialog. Anyway, it works just fine. */ | |
2451 if (interact_style == GNOME_INTERACT_ANY) | |
2452 gnome_client_request_interaction(client, GNOME_DIALOG_NORMAL, | |
2453 &sm_client_check_changed_any, | |
2454 NULL); | |
2455 out_flush(); | |
2456 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
2457 | |
2458 /* The path is unique for each session save. We do neither know nor care | |
2459 * which session script will actually be used later. This decision is in | |
2460 * the domain of the session manager. */ | |
2461 session_file = gnome_config_get_real_path( | |
2462 gnome_client_get_config_prefix(client)); | |
2463 len = strlen(session_file); | |
2464 | |
2465 if (len > 0 && session_file[len-1] == G_DIR_SEPARATOR) | |
2466 --len; /* get rid of the superfluous trailing '/' */ | |
2467 | |
2468 session_file = g_renew(char, session_file, len + sizeof(suffix)); | |
2469 memcpy(session_file + len, suffix, sizeof(suffix)); | |
2470 | |
2471 success = write_session_file((char_u *)session_file); | |
2472 | |
2473 if (success) | |
2474 { | |
2475 const char *argv[8]; | |
2476 int i; | |
2477 | |
2478 /* Tell the session manager how to wipe out the stored session data. | |
2479 * This isn't as dangerous as it looks, don't worry :) session_file | |
2480 * is a unique absolute filename. Usually it'll be something like | |
2481 * `/home/user/.gnome2/vim-XXXXXX-session.vim'. */ | |
2482 i = 0; | |
2483 argv[i++] = "rm"; | |
2484 argv[i++] = session_file; | |
2485 argv[i] = NULL; | |
2486 | |
2487 gnome_client_set_discard_command(client, i, (char **)argv); | |
2488 | |
2489 /* Tell the session manager how to restore the just saved session. | |
2490 * This is easily done thanks to Vim's -S option. Pass the -f flag | |
2491 * since there's no need to fork -- it might even cause confusion. | |
2492 * Also pass the window role to give the WM something to match on. | |
2493 * The role is set in gui_mch_open(), thus should _never_ be NULL. */ | |
2494 i = 0; | |
2495 argv[i++] = restart_command; | |
2496 argv[i++] = "-f"; | |
2497 argv[i++] = "-g"; | |
2498 argv[i++] = "--role"; | |
2499 argv[i++] = gtk_window_get_role(GTK_WINDOW(gui.mainwin)); | |
2500 argv[i++] = "-S"; | |
2501 argv[i++] = session_file; | |
2502 argv[i] = NULL; | |
2503 | |
2504 gnome_client_set_restart_command(client, i, (char **)argv); | |
2505 gnome_client_set_clone_command(client, 0, NULL); | |
2506 } | |
2507 | |
2508 g_free(session_file); | |
2509 | |
2510 return success; | |
2511 } | |
2512 | |
2513 /* | |
2514 * Called when the session manager wants us to die. There isn't much to save | |
2515 * here since "save_yourself" has been emitted before (unless serious trouble | |
2516 * is happening). | |
2517 */ | |
2518 static void | |
2188
722e390945d7
Avoid warnings for unused arguments when compiling with Gnome.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
2519 sm_client_die(GnomeClient *client UNUSED, gpointer data UNUSED) |
7 | 2520 { |
2521 /* Don't write messages to the GUI anymore */ | |
2522 full_screen = FALSE; | |
2523 | |
1666 | 2524 vim_strncpy(IObuff, (char_u *) |
419 | 2525 _("Vim: Received \"die\" request from session manager\n"), |
1666 | 2526 IOSIZE - 1); |
7 | 2527 preserve_exit(); |
2528 } | |
2529 | |
2530 /* | |
2531 * Connect our signal handlers to be notified on session save and shutdown. | |
2532 */ | |
2533 static void | |
2534 setup_save_yourself(void) | |
2535 { | |
2536 GnomeClient *client; | |
2537 | |
2538 client = gnome_master_client(); | |
2539 | |
2540 if (client != NULL) | |
2541 { | |
2542 /* Must use the deprecated gtk_signal_connect() for compatibility | |
2543 * with GNOME 1. Arrgh, zombies! */ | |
2544 gtk_signal_connect(GTK_OBJECT(client), "save_yourself", | |
2545 GTK_SIGNAL_FUNC(&sm_client_save_yourself), NULL); | |
2546 gtk_signal_connect(GTK_OBJECT(client), "die", | |
2547 GTK_SIGNAL_FUNC(&sm_client_die), NULL); | |
2548 } | |
2549 } | |
2550 | |
2551 #else /* !(FEAT_GUI_GNOME && FEAT_SESSION) */ | |
2552 | |
2553 # ifdef USE_XSMP | |
2554 /* | |
2555 * GTK tells us that XSMP needs attention | |
2556 */ | |
2557 static gboolean | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2558 local_xsmp_handle_requests( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2559 GIOChannel *source UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2560 GIOCondition condition, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
2561 gpointer data) |
7 | 2562 { |
2563 if (condition == G_IO_IN) | |
2564 { | |
2565 /* Do stuff; maybe close connection */ | |
2566 if (xsmp_handle_requests() == FAIL) | |
2567 g_io_channel_unref((GIOChannel *)data); | |
2568 return TRUE; | |
2569 } | |
2570 /* Error */ | |
2571 g_io_channel_unref((GIOChannel *)data); | |
2572 xsmp_close(); | |
2573 return TRUE; | |
2574 } | |
2575 # endif /* USE_XSMP */ | |
2576 | |
2577 /* | |
2578 * Setup the WM_PROTOCOLS to indicate we want the WM_SAVE_YOURSELF event. | |
2579 * This is an ugly use of X functions. GTK doesn't offer an alternative. | |
2580 */ | |
2581 static void | |
2582 setup_save_yourself(void) | |
2583 { | |
2584 Atom *existing_atoms = NULL; | |
2585 int count = 0; | |
2586 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2587 # ifdef USE_XSMP |
7 | 2588 if (xsmp_icefd != -1) |
2589 { | |
2590 /* | |
2591 * Use XSMP is preference to legacy WM_SAVE_YOURSELF; | |
2592 * set up GTK IO monitor | |
2593 */ | |
2594 GIOChannel *g_io = g_io_channel_unix_new(xsmp_icefd); | |
2595 | |
2596 g_io_add_watch(g_io, G_IO_IN | G_IO_ERR | G_IO_HUP, | |
2597 local_xsmp_handle_requests, (gpointer)g_io); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2598 g_io_channel_unref(g_io); |
7 | 2599 } |
2600 else | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2601 # endif |
7 | 2602 { |
2603 /* Fall back to old method */ | |
2604 | |
2605 /* first get the existing value */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2606 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2607 GdkWindow * const mainwin_win = gtk_widget_get_window(gui.mainwin); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2608 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2609 if (XGetWMProtocols(GDK_WINDOW_XDISPLAY(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2610 GDK_WINDOW_XID(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2611 &existing_atoms, &count)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2612 # else |
7 | 2613 if (XGetWMProtocols(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
2614 GDK_WINDOW_XWINDOW(gui.mainwin->window), | |
2615 &existing_atoms, &count)) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2616 # endif |
7 | 2617 { |
2618 Atom *new_atoms; | |
2619 Atom save_yourself_xatom; | |
2620 int i; | |
2621 | |
2622 save_yourself_xatom = GET_X_ATOM(save_yourself_atom); | |
2623 | |
2624 /* check if WM_SAVE_YOURSELF isn't there yet */ | |
2625 for (i = 0; i < count; ++i) | |
2626 if (existing_atoms[i] == save_yourself_xatom) | |
2627 break; | |
2628 | |
2629 if (i == count) | |
2630 { | |
2631 /* allocate an Atoms array which is one item longer */ | |
2632 new_atoms = (Atom *)alloc((unsigned)((count + 1) | |
2633 * sizeof(Atom))); | |
2634 if (new_atoms != NULL) | |
2635 { | |
2636 memcpy(new_atoms, existing_atoms, count * sizeof(Atom)); | |
2637 new_atoms[count] = save_yourself_xatom; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2638 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2639 XSetWMProtocols(GDK_WINDOW_XDISPLAY(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2640 GDK_WINDOW_XID(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2641 # else |
7 | 2642 XSetWMProtocols(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
2643 GDK_WINDOW_XWINDOW(gui.mainwin->window), | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2644 # endif |
7 | 2645 new_atoms, count + 1); |
2646 vim_free(new_atoms); | |
2647 } | |
2648 } | |
2649 XFree(existing_atoms); | |
2650 } | |
2651 } | |
2652 } | |
2653 | |
2654 /* | |
2655 * Installing a global event filter seems to be the only way to catch | |
2656 * client messages of type WM_PROTOCOLS without overriding GDK's own | |
2657 * client message event filter. Well, that's still better than trying | |
2658 * to guess what the GDK filter had done if it had been invoked instead | |
2659 * | |
2660 * GTK2_FIXME: This doesn't seem to work. For some reason we never | |
2661 * receive WM_SAVE_YOURSELF even though everything is set up correctly. | |
2662 * I have the nasty feeling modern session managers just don't send this | |
2663 * deprecated message anymore. Addition: confirmed by several people. | |
2664 * | |
2665 * The GNOME session support is much cooler anyway. Unlike this ugly | |
2666 * WM_SAVE_YOURSELF hack it actually stores the session... And yes, | |
2667 * it should work with KDE as well. | |
2668 */ | |
2669 static GdkFilterReturn | |
1884 | 2670 global_event_filter(GdkXEvent *xev, |
2671 GdkEvent *event UNUSED, | |
2672 gpointer data UNUSED) | |
7 | 2673 { |
2674 XEvent *xevent = (XEvent *)xev; | |
2675 | |
2676 if (xevent != NULL | |
2677 && xevent->type == ClientMessage | |
2678 && xevent->xclient.message_type == GET_X_ATOM(wm_protocols_atom) | |
1884 | 2679 && (long_u)xevent->xclient.data.l[0] |
2680 == GET_X_ATOM(save_yourself_atom)) | |
7 | 2681 { |
2682 out_flush(); | |
2683 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
2684 /* | |
2685 * Set the window's WM_COMMAND property, to let the window manager | |
2686 * know we are done saving ourselves. We don't want to be | |
2687 * restarted, thus set argv to NULL. | |
2688 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2689 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2690 XSetCommand(GDK_WINDOW_XDISPLAY(gtk_widget_get_window(gui.mainwin)), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2691 GDK_WINDOW_XID(gtk_widget_get_window(gui.mainwin)), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2692 # else |
7 | 2693 XSetCommand(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
2694 GDK_WINDOW_XWINDOW(gui.mainwin->window), | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2695 # endif |
7 | 2696 NULL, 0); |
2697 return GDK_FILTER_REMOVE; | |
2698 } | |
2699 | |
2700 return GDK_FILTER_CONTINUE; | |
2701 } | |
2702 #endif /* !(FEAT_GUI_GNOME && FEAT_SESSION) */ | |
2703 | |
2704 | |
2705 /* | |
2706 * Setup the window icon & xcmdsrv comm after the main window has been realized. | |
2707 */ | |
2708 static void | |
1884 | 2709 mainwin_realize(GtkWidget *widget UNUSED, gpointer data UNUSED) |
7 | 2710 { |
2711 /* If you get an error message here, you still need to unpack the runtime | |
2712 * archive! */ | |
2713 #ifdef magick | |
2714 # undef magick | |
2715 #endif | |
2716 /* A bit hackish, but avoids casting later and allows optimization */ | |
2717 # define static static const | |
2718 #define magick vim32x32 | |
2719 #include "../runtime/vim32x32.xpm" | |
2720 #undef magick | |
2721 #define magick vim16x16 | |
2722 #include "../runtime/vim16x16.xpm" | |
2723 #undef magick | |
2724 #define magick vim48x48 | |
2725 #include "../runtime/vim48x48.xpm" | |
2726 #undef magick | |
2727 # undef static | |
2728 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2729 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2730 GdkWindow * const mainwin_win = gtk_widget_get_window(gui.mainwin); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2731 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2732 |
7 | 2733 /* When started with "--echo-wid" argument, write window ID on stdout. */ |
2734 if (echo_wid_arg) | |
2735 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2736 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2737 printf("WID: %ld\n", (long)GDK_WINDOW_XID(mainwin_win)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2738 #else |
7 | 2739 printf("WID: %ld\n", (long)GDK_WINDOW_XWINDOW(gui.mainwin->window)); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2740 #endif |
7 | 2741 fflush(stdout); |
2742 } | |
2743 | |
2744 if (vim_strchr(p_go, GO_ICON) != NULL) | |
2745 { | |
2746 /* | |
2747 * Add an icon to the main window. For fun and convenience of the user. | |
2748 */ | |
2749 GList *icons = NULL; | |
2750 | |
2751 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim16x16)); | |
2752 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim32x32)); | |
2753 icons = g_list_prepend(icons, gdk_pixbuf_new_from_xpm_data(vim48x48)); | |
2754 | |
2755 gtk_window_set_icon_list(GTK_WINDOW(gui.mainwin), icons); | |
2756 | |
2757 g_list_foreach(icons, (GFunc)&g_object_unref, NULL); | |
2758 g_list_free(icons); | |
2759 } | |
2760 | |
2761 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
2762 /* Register a handler for WM_SAVE_YOURSELF with GDK's low-level X I/F */ | |
2763 gdk_window_add_filter(NULL, &global_event_filter, NULL); | |
2764 #endif | |
2765 /* Setup to indicate to the window manager that we want to catch the | |
2766 * WM_SAVE_YOURSELF event. For GNOME, this connects to the session | |
2767 * manager instead. */ | |
2768 #if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
2769 if (using_gnome) | |
2770 #endif | |
2771 setup_save_yourself(); | |
2772 | |
2773 #ifdef FEAT_CLIENTSERVER | |
2774 if (serverName == NULL && serverDelayedStartName != NULL) | |
2775 { | |
2776 /* This is a :gui command in a plain vim with no previous server */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2777 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2778 commWindow = GDK_WINDOW_XID(mainwin_win); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2779 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2780 (void)serverRegisterName(GDK_WINDOW_XDISPLAY(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2781 serverDelayedStartName); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2782 # else |
7 | 2783 commWindow = GDK_WINDOW_XWINDOW(gui.mainwin->window); |
2784 | |
2785 (void)serverRegisterName(GDK_WINDOW_XDISPLAY(gui.mainwin->window), | |
2786 serverDelayedStartName); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2787 # endif |
7 | 2788 } |
2789 else | |
2790 { | |
2791 /* | |
2792 * Cannot handle "XLib-only" windows with gtk event routines, we'll | |
2793 * have to change the "server" registration to that of the main window | |
2794 * If we have not registered a name yet, remember the window | |
2795 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2796 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2797 serverChangeRegisteredWindow(GDK_WINDOW_XDISPLAY(mainwin_win), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2798 GDK_WINDOW_XID(mainwin_win)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2799 # else |
7 | 2800 serverChangeRegisteredWindow(GDK_WINDOW_XDISPLAY(gui.mainwin->window), |
2801 GDK_WINDOW_XWINDOW(gui.mainwin->window)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2802 # endif |
7 | 2803 } |
2804 gtk_widget_add_events(gui.mainwin, GDK_PROPERTY_CHANGE_MASK); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2805 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2806 g_signal_connect(G_OBJECT(gui.mainwin), "property-notify-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2807 G_CALLBACK(property_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2808 # else |
7 | 2809 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "property_notify_event", |
2810 GTK_SIGNAL_FUNC(property_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2811 # endif |
7 | 2812 #endif |
2813 } | |
2814 | |
2815 static GdkCursor * | |
2816 create_blank_pointer(void) | |
2817 { | |
2818 GdkWindow *root_window = NULL; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2819 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2820 GdkPixbuf *blank_mask; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2821 #else |
7 | 2822 GdkPixmap *blank_mask; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2823 #endif |
7 | 2824 GdkCursor *cursor; |
2825 GdkColor color = { 0, 0, 0, 0 }; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2826 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 2827 char blank_data[] = { 0x0 }; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2828 #endif |
7 | 2829 |
2830 #ifdef HAVE_GTK_MULTIHEAD | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2831 # if GTK_CHECK_VERSION(3,12,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2832 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2833 GdkWindow * const win = gtk_widget_get_window(gui.mainwin); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2834 GdkScreen * const scrn = gdk_window_get_screen(win); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2835 root_window = gdk_screen_get_root_window(scrn); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2836 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2837 # else |
7 | 2838 root_window = gtk_widget_get_root_window(gui.mainwin); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2839 # endif |
7 | 2840 #endif |
2841 | |
2842 /* Create a pseudo blank pointer, which is in fact one pixel by one pixel | |
2843 * in size. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2844 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2845 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2846 cairo_surface_t *surf; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2847 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2848 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2849 surf = cairo_image_surface_create(CAIRO_FORMAT_A1, 1, 1); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2850 cr = cairo_create(surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2851 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2852 cairo_set_source_rgb(cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2853 color.red / 65535.0, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2854 color.green / 65535.0, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2855 color.blue / 65535.0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2856 cairo_rectangle(cr, 0, 0, 1, 1); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2857 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2858 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2859 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2860 blank_mask = gdk_pixbuf_get_from_surface(surf, 0, 0, 1, 1); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2861 cairo_surface_destroy(surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2862 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2863 cursor = gdk_cursor_new_from_pixbuf(gdk_window_get_display(root_window), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2864 blank_mask, 0, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2865 g_object_unref(blank_mask); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2866 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2867 #else |
7 | 2868 blank_mask = gdk_bitmap_create_from_data(root_window, blank_data, 1, 1); |
2869 cursor = gdk_cursor_new_from_pixmap(blank_mask, blank_mask, | |
2870 &color, &color, 0, 0); | |
2871 gdk_bitmap_unref(blank_mask); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2872 #endif |
7 | 2873 |
2874 return cursor; | |
2875 } | |
2876 | |
2877 #ifdef HAVE_GTK_MULTIHEAD | |
2878 static void | |
2879 mainwin_screen_changed_cb(GtkWidget *widget, | |
1884 | 2880 GdkScreen *previous_screen UNUSED, |
2881 gpointer data UNUSED) | |
7 | 2882 { |
2883 if (!gtk_widget_has_screen(widget)) | |
2884 return; | |
2885 | |
2886 /* | |
1226 | 2887 * Recreate the invisible mouse cursor. |
7 | 2888 */ |
2889 if (gui.blank_pointer != NULL) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2890 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2891 g_object_unref(G_OBJECT(gui.blank_pointer)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2892 # else |
7 | 2893 gdk_cursor_unref(gui.blank_pointer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2894 # endif |
7 | 2895 |
2896 gui.blank_pointer = create_blank_pointer(); | |
2897 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2898 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2899 if (gui.pointer_hidden && gtk_widget_get_window(gui.drawarea) != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2900 gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2901 gui.blank_pointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2902 # else |
7 | 2903 if (gui.pointer_hidden && gui.drawarea->window != NULL) |
2904 gdk_window_set_cursor(gui.drawarea->window, gui.blank_pointer); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2905 # endif |
7 | 2906 |
2907 /* | |
2908 * Create a new PangoContext for this screen, and initialize it | |
2909 * with the current font if necessary. | |
2910 */ | |
2911 if (gui.text_context != NULL) | |
2912 g_object_unref(gui.text_context); | |
2913 | |
2914 gui.text_context = gtk_widget_create_pango_context(widget); | |
2915 pango_context_set_base_dir(gui.text_context, PANGO_DIRECTION_LTR); | |
2916 | |
2917 if (gui.norm_font != NULL) | |
2918 { | |
38 | 2919 gui_mch_init_font(p_guifont, FALSE); |
814 | 2920 gui_set_shellsize(FALSE, FALSE, RESIZE_BOTH); |
7 | 2921 } |
2922 } | |
2923 #endif /* HAVE_GTK_MULTIHEAD */ | |
2924 | |
2925 /* | |
2926 * After the drawing area comes up, we calculate all colors and create the | |
2927 * dummy blank cursor. | |
2928 * | |
2929 * Don't try to set any VIM scrollbar sizes anywhere here. I'm relying on the | |
2930 * fact that the main VIM engine doesn't take them into account anywhere. | |
2931 */ | |
2932 static void | |
1884 | 2933 drawarea_realize_cb(GtkWidget *widget, gpointer data UNUSED) |
7 | 2934 { |
2935 GtkWidget *sbar; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2936 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2937 GtkAllocation allocation; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2938 #endif |
7 | 2939 |
2940 #ifdef FEAT_XIM | |
2941 xim_init(); | |
2942 #endif | |
2943 gui_mch_new_colors(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2944 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2945 gui.surface = gdk_window_create_similar_surface( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2946 gtk_widget_get_window(widget), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2947 CAIRO_CONTENT_COLOR_ALPHA, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2948 gtk_widget_get_allocated_width(widget), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2949 gtk_widget_get_allocated_height(widget)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2950 #else |
7 | 2951 gui.text_gc = gdk_gc_new(gui.drawarea->window); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2952 #endif |
7 | 2953 |
2954 gui.blank_pointer = create_blank_pointer(); | |
2955 if (gui.pointer_hidden) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2956 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2957 gdk_window_set_cursor(gtk_widget_get_window(widget), gui.blank_pointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2958 #else |
7 | 2959 gdk_window_set_cursor(widget->window, gui.blank_pointer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2960 #endif |
7 | 2961 |
2962 /* get the actual size of the scrollbars, if they are realized */ | |
2963 sbar = firstwin->w_scrollbars[SBAR_LEFT].id; | |
2964 if (!sbar || (!gui.which_scrollbars[SBAR_LEFT] | |
2965 && firstwin->w_scrollbars[SBAR_RIGHT].id)) | |
2966 sbar = firstwin->w_scrollbars[SBAR_RIGHT].id; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2967 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2968 gtk_widget_get_allocation(sbar, &allocation); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2969 if (sbar && gtk_widget_get_realized(sbar) && allocation.width) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2970 gui.scrollbar_width = allocation.width; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2971 #else |
7 | 2972 if (sbar && GTK_WIDGET_REALIZED(sbar) && sbar->allocation.width) |
2973 gui.scrollbar_width = sbar->allocation.width; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2974 #endif |
7 | 2975 |
2976 sbar = gui.bottom_sbar.id; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2977 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2978 if (sbar && gtk_widget_get_realized(sbar) && allocation.height) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2979 gui.scrollbar_height = allocation.height; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2980 #else |
7 | 2981 if (sbar && GTK_WIDGET_REALIZED(sbar) && sbar->allocation.height) |
2982 gui.scrollbar_height = sbar->allocation.height; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
2983 #endif |
7 | 2984 } |
2985 | |
2986 /* | |
2987 * Properly clean up on shutdown. | |
2988 */ | |
2989 static void | |
1884 | 2990 drawarea_unrealize_cb(GtkWidget *widget UNUSED, gpointer data UNUSED) |
7 | 2991 { |
2992 /* Don't write messages to the GUI anymore */ | |
2993 full_screen = FALSE; | |
2994 | |
2995 #ifdef FEAT_XIM | |
2996 im_shutdown(); | |
2997 #endif | |
2998 if (gui.ascii_glyphs != NULL) | |
2999 { | |
3000 pango_glyph_string_free(gui.ascii_glyphs); | |
3001 gui.ascii_glyphs = NULL; | |
3002 } | |
3003 if (gui.ascii_font != NULL) | |
3004 { | |
3005 g_object_unref(gui.ascii_font); | |
3006 gui.ascii_font = NULL; | |
3007 } | |
3008 g_object_unref(gui.text_context); | |
3009 gui.text_context = NULL; | |
3010 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3011 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3012 if (gui.surface != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3013 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3014 cairo_surface_destroy(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3015 gui.surface = NULL; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3016 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3017 #else |
7 | 3018 g_object_unref(gui.text_gc); |
3019 gui.text_gc = NULL; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3020 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3021 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3022 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3023 g_object_unref(G_OBJECT(gui.blank_pointer)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3024 #else |
7 | 3025 gdk_cursor_unref(gui.blank_pointer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3026 #endif |
7 | 3027 gui.blank_pointer = NULL; |
3028 } | |
3029 | |
3030 static void | |
1884 | 3031 drawarea_style_set_cb(GtkWidget *widget UNUSED, |
3032 GtkStyle *previous_style UNUSED, | |
3033 gpointer data UNUSED) | |
7 | 3034 { |
3035 gui_mch_new_colors(); | |
3036 } | |
3037 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3038 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3039 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3040 drawarea_configure_event_cb(GtkWidget *widget, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3041 GdkEventConfigure *event, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3042 gpointer data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3043 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3044 static int cur_width = 0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3045 static int cur_height = 0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3046 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3047 g_return_val_if_fail(event |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3048 && event->width >= 1 && event->height >= 1, TRUE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3049 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3050 if (event->width == cur_width && event->height == cur_height) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3051 return TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3052 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3053 cur_width = event->width; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3054 cur_height = event->height; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3055 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3056 if (gui.surface != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3057 cairo_surface_destroy(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3058 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3059 gui.surface = gdk_window_create_similar_surface( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3060 gtk_widget_get_window(widget), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3061 CAIRO_CONTENT_COLOR_ALPHA, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3062 event->width, event->height); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3063 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3064 gtk_widget_queue_draw(widget); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3065 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3066 return TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3067 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3068 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3069 |
7 | 3070 /* |
3071 * Callback routine for the "delete_event" signal on the toplevel window. | |
3072 * Tries to vim gracefully, or refuses to exit with changed buffers. | |
3073 */ | |
3074 static gint | |
1884 | 3075 delete_event_cb(GtkWidget *widget UNUSED, |
3076 GdkEventAny *event UNUSED, | |
3077 gpointer data UNUSED) | |
7 | 3078 { |
3079 gui_shell_closed(); | |
3080 return TRUE; | |
3081 } | |
3082 | |
685 | 3083 #if defined(FEAT_MENU) || defined(FEAT_TOOLBAR) || defined(FEAT_GUI_TABLINE) |
3084 static int | |
3085 get_item_dimensions(GtkWidget *widget, GtkOrientation orientation) | |
3086 { | |
3087 GtkOrientation item_orientation = GTK_ORIENTATION_HORIZONTAL; | |
3088 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3089 # ifdef FEAT_GUI_GNOME |
685 | 3090 if (using_gnome && widget != NULL) |
3091 { | |
856 | 3092 GtkWidget *parent; |
685 | 3093 BonoboDockItem *dockitem; |
3094 | |
791 | 3095 parent = gtk_widget_get_parent(widget); |
856 | 3096 if (G_TYPE_FROM_INSTANCE(parent) == BONOBO_TYPE_DOCK_ITEM) |
3097 { | |
3098 /* Only menu & toolbar are dock items. Could tabline be? | |
3099 * Seem to be only the 2 defined in GNOME */ | |
3100 widget = parent; | |
3101 dockitem = BONOBO_DOCK_ITEM(widget); | |
3102 | |
3103 if (dockitem == NULL || dockitem->is_floating) | |
3104 return 0; | |
3105 item_orientation = bonobo_dock_item_get_orientation(dockitem); | |
3106 } | |
685 | 3107 } |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3108 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3109 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3110 if (widget != NULL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3111 && item_orientation == orientation |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3112 && gtk_widget_get_realized(widget) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3113 && gtk_widget_get_visible(widget)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3114 # else |
685 | 3115 if (widget != NULL |
3116 && item_orientation == orientation | |
3117 && GTK_WIDGET_REALIZED(widget) | |
3118 && GTK_WIDGET_VISIBLE(widget)) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3119 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3120 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3121 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3122 GtkAllocation allocation; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3123 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3124 gtk_widget_get_allocation(widget, &allocation); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3125 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3126 if (orientation == GTK_ORIENTATION_HORIZONTAL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3127 return allocation.height; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3128 else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3129 return allocation.width; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3130 # else |
685 | 3131 if (orientation == GTK_ORIENTATION_HORIZONTAL) |
3132 return widget->allocation.height; | |
3133 else | |
3134 return widget->allocation.width; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3135 # endif |
685 | 3136 } |
3137 return 0; | |
3138 } | |
3139 #endif | |
3140 | |
3141 static int | |
3142 get_menu_tool_width(void) | |
3143 { | |
3144 int width = 0; | |
3145 | |
3146 #ifdef FEAT_GUI_GNOME /* these are never vertical without GNOME */ | |
3147 # ifdef FEAT_MENU | |
3148 width += get_item_dimensions(gui.menubar, GTK_ORIENTATION_VERTICAL); | |
3149 # endif | |
3150 # ifdef FEAT_TOOLBAR | |
3151 width += get_item_dimensions(gui.toolbar, GTK_ORIENTATION_VERTICAL); | |
3152 # endif | |
3153 # ifdef FEAT_GUI_TABLINE | |
782 | 3154 if (gui.tabline != NULL) |
3155 width += get_item_dimensions(gui.tabline, GTK_ORIENTATION_VERTICAL); | |
685 | 3156 # endif |
3157 #endif | |
3158 | |
3159 return width; | |
3160 } | |
3161 | |
3162 static int | |
3163 get_menu_tool_height(void) | |
3164 { | |
3165 int height = 0; | |
3166 | |
3167 #ifdef FEAT_MENU | |
3168 height += get_item_dimensions(gui.menubar, GTK_ORIENTATION_HORIZONTAL); | |
3169 #endif | |
3170 #ifdef FEAT_TOOLBAR | |
3171 height += get_item_dimensions(gui.toolbar, GTK_ORIENTATION_HORIZONTAL); | |
3172 #endif | |
3173 #ifdef FEAT_GUI_TABLINE | |
782 | 3174 if (gui.tabline != NULL) |
3175 height += get_item_dimensions(gui.tabline, GTK_ORIENTATION_HORIZONTAL); | |
685 | 3176 #endif |
3177 | |
3178 return height; | |
3179 } | |
3180 | |
791 | 3181 /* This controls whether we can set the real window hints at |
3182 * start-up when in a GtkPlug. | |
3183 * 0 = normal processing (default) | |
3184 * 1 = init. hints set, no-one's tried to reset since last check | |
3185 * 2 = init. hints set, attempt made to change hints | |
3186 */ | |
3187 static int init_window_hints_state = 0; | |
3188 | |
685 | 3189 static void |
791 | 3190 update_window_manager_hints(int force_width, int force_height) |
685 | 3191 { |
3192 static int old_width = 0; | |
3193 static int old_height = 0; | |
791 | 3194 static int old_min_width = 0; |
3195 static int old_min_height = 0; | |
685 | 3196 static int old_char_width = 0; |
3197 static int old_char_height = 0; | |
3198 | |
3199 int width; | |
3200 int height; | |
791 | 3201 int min_width; |
3202 int min_height; | |
3203 | |
3204 /* At start-up, don't try to set the hints until the initial | |
3205 * values have been used (those that dictate our initial size) | |
1884 | 3206 * Let forced (i.e., correct) values through always. |
791 | 3207 */ |
3208 if (!(force_width && force_height) && init_window_hints_state > 0) | |
3209 { | |
856 | 3210 /* Don't do it! */ |
3211 init_window_hints_state = 2; | |
3212 return; | |
791 | 3213 } |
685 | 3214 |
3215 /* This also needs to be done when the main window isn't there yet, | |
3216 * otherwise the hints don't work. */ | |
3217 width = gui_get_base_width(); | |
3218 height = gui_get_base_height(); | |
3219 # ifdef FEAT_MENU | |
3220 height += tabline_height() * gui.char_height; | |
3221 # endif | |
3222 width += get_menu_tool_width(); | |
3223 height += get_menu_tool_height(); | |
3224 | |
791 | 3225 /* GtkSockets use GtkPlug's [gui,mainwin] min-size hints to determine |
1226 | 3226 * their actual widget size. When we set our size ourselves (e.g., |
791 | 3227 * 'set columns=' or init. -geom) we briefly set the min. to the size |
3228 * we wish to be instead of the legitimate minimum so that we actually | |
3229 * resize correctly. | |
3230 */ | |
3231 if (force_width && force_height) | |
3232 { | |
856 | 3233 min_width = force_width; |
3234 min_height = force_height; | |
791 | 3235 } |
3236 else | |
3237 { | |
856 | 3238 min_width = width + MIN_COLUMNS * gui.char_width; |
3239 min_height = height + MIN_LINES * gui.char_height; | |
791 | 3240 } |
3241 | |
685 | 3242 /* Avoid an expose event when the size didn't change. */ |
3243 if (width != old_width | |
3244 || height != old_height | |
856 | 3245 || min_width != old_min_width |
791 | 3246 || min_height != old_min_height |
685 | 3247 || gui.char_width != old_char_width |
3248 || gui.char_height != old_char_height) | |
3249 { | |
3250 GdkGeometry geometry; | |
3251 GdkWindowHints geometry_mask; | |
3252 | |
3253 geometry.width_inc = gui.char_width; | |
3254 geometry.height_inc = gui.char_height; | |
3255 geometry.base_width = width; | |
3256 geometry.base_height = height; | |
856 | 3257 geometry.min_width = min_width; |
3258 geometry.min_height = min_height; | |
685 | 3259 geometry_mask = GDK_HINT_BASE_SIZE|GDK_HINT_RESIZE_INC |
3260 |GDK_HINT_MIN_SIZE; | |
3261 /* Using gui.formwin as geometry widget doesn't work as expected | |
3262 * with GTK+ 2 -- dunno why. Presumably all the resizing hacks | |
3263 * in Vim confuse GTK+. */ | |
3264 gtk_window_set_geometry_hints(GTK_WINDOW(gui.mainwin), gui.mainwin, | |
3265 &geometry, geometry_mask); | |
856 | 3266 old_width = width; |
3267 old_height = height; | |
3268 old_min_width = min_width; | |
3269 old_min_height = min_height; | |
3270 old_char_width = gui.char_width; | |
3271 old_char_height = gui.char_height; | |
685 | 3272 } |
3273 } | |
3274 | |
7 | 3275 #ifdef FEAT_TOOLBAR |
3276 | |
3277 /* | |
3278 * This extra effort wouldn't be necessary if we only used stock icons in the | |
3279 * toolbar, as we do for all builtin icons. But user-defined toolbar icons | |
3280 * shouldn't be treated differently, thus we do need this. | |
3281 */ | |
3282 static void | |
3283 icon_size_changed_foreach(GtkWidget *widget, gpointer user_data) | |
3284 { | |
3285 if (GTK_IS_IMAGE(widget)) | |
3286 { | |
3287 GtkImage *image = (GtkImage *)widget; | |
3288 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3289 # if GTK_CHECK_VERSION(3,10,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3290 if (gtk_image_get_storage_type(image) == GTK_IMAGE_ICON_NAME) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3291 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3292 const GtkIconSize icon_size = GPOINTER_TO_INT(user_data); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3293 const gchar *icon_name; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3294 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3295 gtk_image_get_icon_name(image, &icon_name, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3296 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3297 gtk_image_set_from_icon_name(image, icon_name, icon_size); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3298 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3299 # else |
7 | 3300 /* User-defined icons are stored in a GtkIconSet */ |
3301 if (gtk_image_get_storage_type(image) == GTK_IMAGE_ICON_SET) | |
3302 { | |
3303 GtkIconSet *icon_set; | |
3304 GtkIconSize icon_size; | |
3305 | |
3306 gtk_image_get_icon_set(image, &icon_set, &icon_size); | |
3307 icon_size = (GtkIconSize)(long)user_data; | |
3308 | |
3309 gtk_icon_set_ref(icon_set); | |
3310 gtk_image_set_from_icon_set(image, icon_set, icon_size); | |
3311 gtk_icon_set_unref(icon_set); | |
3312 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3313 # endif |
7 | 3314 } |
3315 else if (GTK_IS_CONTAINER(widget)) | |
3316 { | |
3317 gtk_container_foreach((GtkContainer *)widget, | |
3318 &icon_size_changed_foreach, | |
3319 user_data); | |
3320 } | |
3321 } | |
3322 | |
3323 static void | |
3324 set_toolbar_style(GtkToolbar *toolbar) | |
3325 { | |
3326 GtkToolbarStyle style; | |
3327 GtkIconSize size; | |
3328 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
|
3329 |
7 | 3330 if ((toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS | TOOLBAR_HORIZ)) |
3331 == (TOOLBAR_TEXT | TOOLBAR_ICONS | TOOLBAR_HORIZ)) | |
3332 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
|
3333 else if ((toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS)) |
7 | 3334 == (TOOLBAR_TEXT | TOOLBAR_ICONS)) |
3335 style = GTK_TOOLBAR_BOTH; | |
3336 else if (toolbar_flags & TOOLBAR_TEXT) | |
3337 style = GTK_TOOLBAR_TEXT; | |
3338 else | |
3339 style = GTK_TOOLBAR_ICONS; | |
3340 | |
3341 gtk_toolbar_set_style(toolbar, style); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3342 # if !GTK_CHECK_VERSION(3,0,0) |
7 | 3343 gtk_toolbar_set_tooltips(toolbar, (toolbar_flags & TOOLBAR_TOOLTIPS) != 0); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3344 # endif |
7 | 3345 |
3346 switch (tbis_flags) | |
3347 { | |
3348 case TBIS_TINY: size = GTK_ICON_SIZE_MENU; break; | |
3349 case TBIS_SMALL: size = GTK_ICON_SIZE_SMALL_TOOLBAR; break; | |
3350 case TBIS_MEDIUM: size = GTK_ICON_SIZE_BUTTON; break; | |
3351 case TBIS_LARGE: size = GTK_ICON_SIZE_LARGE_TOOLBAR; break; | |
8469
42020d59a432
commit https://github.com/vim/vim/commit/beb003b303cde1e55634aae9f810535684b76211
Christian Brabandt <cb@256bit.org>
parents:
8412
diff
changeset
|
3352 case TBIS_HUGE: size = GTK_ICON_SIZE_DND; break; |
42020d59a432
commit https://github.com/vim/vim/commit/beb003b303cde1e55634aae9f810535684b76211
Christian Brabandt <cb@256bit.org>
parents:
8412
diff
changeset
|
3353 case TBIS_GIANT: size = GTK_ICON_SIZE_DIALOG; break; |
7 | 3354 default: size = GTK_ICON_SIZE_INVALID; break; |
3355 } | |
3356 oldsize = gtk_toolbar_get_icon_size(toolbar); | |
3357 | |
3358 if (size == GTK_ICON_SIZE_INVALID) | |
3359 { | |
3360 /* Let global user preferences decide the icon size. */ | |
3361 gtk_toolbar_unset_icon_size(toolbar); | |
3362 size = gtk_toolbar_get_icon_size(toolbar); | |
3363 } | |
3364 if (size != oldsize) | |
3365 { | |
3366 gtk_container_foreach(GTK_CONTAINER(toolbar), | |
3367 &icon_size_changed_foreach, | |
3368 GINT_TO_POINTER((int)size)); | |
3369 } | |
3370 gtk_toolbar_set_icon_size(toolbar, size); | |
3371 } | |
3372 | |
3373 #endif /* FEAT_TOOLBAR */ | |
3374 | |
685 | 3375 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
3376 static int ignore_tabline_evt = FALSE; | |
689 | 3377 static GtkWidget *tabline_menu; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3378 # if !GTK_CHECK_VERSION(3,0,0) |
846 | 3379 static GtkTooltips *tabline_tooltip; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3380 # endif |
689 | 3381 static int clicked_page; /* page clicked in tab line */ |
3382 | |
3383 /* | |
3384 * Handle selecting an item in the tab line popup menu. | |
3385 */ | |
3386 static void | |
1884 | 3387 tabline_menu_handler(GtkMenuItem *item UNUSED, gpointer user_data) |
689 | 3388 { |
3389 /* Add the string cmd into input buffer */ | |
824 | 3390 send_tabline_menu_event(clicked_page, (int)(long)user_data); |
689 | 3391 } |
3392 | |
851 | 3393 static void |
3394 add_tabline_menu_item(GtkWidget *menu, char_u *text, int resp) | |
3395 { | |
3396 GtkWidget *item; | |
3397 char_u *utf_text; | |
3398 | |
3399 utf_text = CONVERT_TO_UTF8(text); | |
3400 item = gtk_menu_item_new_with_label((const char *)utf_text); | |
3401 gtk_widget_show(item); | |
3402 CONVERT_TO_UTF8_FREE(utf_text); | |
3403 | |
3404 gtk_container_add(GTK_CONTAINER(menu), item); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3405 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3406 g_signal_connect(G_OBJECT(item), "activate", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3407 G_CALLBACK(tabline_menu_handler), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3408 GINT_TO_POINTER(resp)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3409 # else |
851 | 3410 gtk_signal_connect(GTK_OBJECT(item), "activate", |
3411 GTK_SIGNAL_FUNC(tabline_menu_handler), | |
1660 | 3412 (gpointer)(long)resp); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3413 # endif |
851 | 3414 } |
3415 | |
689 | 3416 /* |
3417 * Create a menu for the tab line. | |
3418 */ | |
3419 static GtkWidget * | |
3420 create_tabline_menu(void) | |
3421 { | |
851 | 3422 GtkWidget *menu; |
689 | 3423 |
3424 menu = gtk_menu_new(); | |
6819 | 3425 if (first_tabpage->tp_next != NULL) |
3426 add_tabline_menu_item(menu, (char_u *)_("Close tab"), | |
3427 TABLINE_MENU_CLOSE); | |
851 | 3428 add_tabline_menu_item(menu, (char_u *)_("New tab"), TABLINE_MENU_NEW); |
3429 add_tabline_menu_item(menu, (char_u *)_("Open Tab..."), TABLINE_MENU_OPEN); | |
689 | 3430 |
3431 return menu; | |
3432 } | |
3433 | |
3434 static gboolean | |
3435 on_tabline_menu(GtkWidget *widget, GdkEvent *event) | |
3436 { | |
3437 /* Was this button press event ? */ | |
3438 if (event->type == GDK_BUTTON_PRESS) | |
3439 { | |
3440 GdkEventButton *bevent = (GdkEventButton *)event; | |
3441 int x = bevent->x; | |
851 | 3442 int y = bevent->y; |
3443 GtkWidget *tabwidget; | |
3444 GdkWindow *tabwin; | |
689 | 3445 |
844 | 3446 /* When ignoring events return TRUE so that the selected page doesn't |
3447 * change. */ | |
3448 if (hold_gui_events | |
3449 # ifdef FEAT_CMDWIN | |
3450 || cmdwin_type != 0 | |
3451 # endif | |
3452 ) | |
3453 return TRUE; | |
3454 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3455 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3456 tabwin = gui_gtk_window_at_position(gui.mainwin, &x, &y); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3457 # else |
851 | 3458 tabwin = gdk_window_at_pointer(&x, &y); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3459 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3460 |
851 | 3461 gdk_window_get_user_data(tabwin, (gpointer)&tabwidget); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3462 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3463 clicked_page = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(tabwidget), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3464 "tab_num")); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3465 # else |
851 | 3466 clicked_page = (int)(long)gtk_object_get_user_data( |
3467 GTK_OBJECT(tabwidget)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3468 # endif |
689 | 3469 |
3470 /* If the event was generated for 3rd button popup the menu. */ | |
3471 if (bevent->button == 3) | |
3472 { | |
3473 gtk_menu_popup(GTK_MENU(widget), NULL, NULL, NULL, NULL, | |
3474 bevent->button, bevent->time); | |
3475 /* We handled the event. */ | |
3476 return TRUE; | |
3477 } | |
868 | 3478 else if (bevent->button == 1) |
693 | 3479 { |
868 | 3480 if (clicked_page == 0) |
3481 { | |
1394 | 3482 /* Click after all tabs moves to next tab page. When "x" is |
3483 * 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
|
3484 send_tabline_event(x < 50 ? -1 : 0); |
868 | 3485 } |
693 | 3486 } |
689 | 3487 } |
844 | 3488 |
689 | 3489 /* We didn't handle the event. */ |
3490 return FALSE; | |
3491 } | |
685 | 3492 |
3493 /* | |
3494 * Handle selecting one of the tabs. | |
3495 */ | |
3496 static void | |
3497 on_select_tab( | |
1884 | 3498 GtkNotebook *notebook UNUSED, |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3499 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3500 gpointer *page UNUSED, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3501 # else |
1884 | 3502 GtkNotebookPage *page UNUSED, |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3503 # endif |
944 | 3504 gint idx, |
1884 | 3505 gpointer data UNUSED) |
685 | 3506 { |
3507 if (!ignore_tabline_evt) | |
693 | 3508 { |
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
|
3509 send_tabline_event(idx + 1); |
693 | 3510 } |
685 | 3511 } |
3512 | |
3513 /* | |
3514 * Show or hide the tabline. | |
3515 */ | |
3516 void | |
3517 gui_mch_show_tabline(int showit) | |
3518 { | |
3519 if (gui.tabline == NULL) | |
3520 return; | |
3521 | |
3522 if (!showit != !gtk_notebook_get_show_tabs(GTK_NOTEBOOK(gui.tabline))) | |
3523 { | |
708 | 3524 /* Note: this may cause a resize event */ |
685 | 3525 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gui.tabline), showit); |
791 | 3526 update_window_manager_hints(0, 0); |
868 | 3527 if (showit) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3528 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3529 gtk_widget_set_can_focus(GTK_WIDGET(gui.tabline), FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3530 # else |
868 | 3531 GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(gui.tabline), GTK_CAN_FOCUS); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3532 # endif |
868 | 3533 } |
3534 | |
3535 gui_mch_update(); | |
685 | 3536 } |
3537 | |
3538 /* | |
708 | 3539 * Return TRUE when tabline is displayed. |
3540 */ | |
3541 int | |
3542 gui_mch_showing_tabline(void) | |
3543 { | |
3544 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
|
3545 && gtk_notebook_get_show_tabs(GTK_NOTEBOOK(gui.tabline)); |
708 | 3546 } |
3547 | |
3548 /* | |
685 | 3549 * Update the labels of the tabline. |
3550 */ | |
3551 void | |
3552 gui_mch_update_tabline(void) | |
3553 { | |
3554 GtkWidget *page; | |
846 | 3555 GtkWidget *event_box; |
685 | 3556 GtkWidget *label; |
3557 tabpage_T *tp; | |
3558 int nr = 0; | |
851 | 3559 int tab_num; |
685 | 3560 int curtabidx = 0; |
836 | 3561 char_u *labeltext; |
685 | 3562 |
3563 if (gui.tabline == NULL) | |
3564 return; | |
3565 | |
3566 ignore_tabline_evt = TRUE; | |
3567 | |
3568 /* Add a label for each tab page. They all contain the same text area. */ | |
3569 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr) | |
3570 { | |
3571 if (tp == curtab) | |
3572 curtabidx = nr; | |
3573 | |
851 | 3574 tab_num = nr + 1; |
3575 | |
685 | 3576 page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui.tabline), nr); |
3577 if (page == NULL) | |
3578 { | |
3579 /* Add notebook page */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3580 # if GTK_CHECK_VERSION(3,2,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3581 page = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3582 gtk_box_set_homogeneous(GTK_BOX(page), FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3583 # else |
685 | 3584 page = gtk_vbox_new(FALSE, 0); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3585 # endif |
685 | 3586 gtk_widget_show(page); |
846 | 3587 event_box = gtk_event_box_new(); |
3588 gtk_widget_show(event_box); | |
685 | 3589 label = gtk_label_new("-Empty-"); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3590 # if !GTK_CHECK_VERSION(3,14,0) |
851 | 3591 gtk_misc_set_padding(GTK_MISC(label), 2, 2); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3592 # endif |
846 | 3593 gtk_container_add(GTK_CONTAINER(event_box), label); |
685 | 3594 gtk_widget_show(label); |
3595 gtk_notebook_insert_page(GTK_NOTEBOOK(gui.tabline), | |
3596 page, | |
846 | 3597 event_box, |
685 | 3598 nr++); |
3599 } | |
3600 | |
846 | 3601 event_box = gtk_notebook_get_tab_label(GTK_NOTEBOOK(gui.tabline), page); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3602 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3603 g_object_set_data(G_OBJECT(event_box), "tab_num", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3604 GINT_TO_POINTER(tab_num)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3605 # else |
1660 | 3606 gtk_object_set_user_data(GTK_OBJECT(event_box), |
3607 (gpointer)(long)tab_num); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3608 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3609 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3610 label = gtk_bin_get_child(GTK_BIN(event_box)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3611 # else |
846 | 3612 label = GTK_BIN(event_box)->child; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3613 # endif |
839 | 3614 get_tabline_label(tp, FALSE); |
836 | 3615 labeltext = CONVERT_TO_UTF8(NameBuff); |
846 | 3616 gtk_label_set_text(GTK_LABEL(label), (const char *)labeltext); |
836 | 3617 CONVERT_TO_UTF8_FREE(labeltext); |
846 | 3618 |
3619 get_tabline_label(tp, TRUE); | |
3620 labeltext = CONVERT_TO_UTF8(NameBuff); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3621 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3622 gtk_widget_set_tooltip_text(event_box, (const gchar *)labeltext); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3623 # else |
846 | 3624 gtk_tooltips_set_tip(GTK_TOOLTIPS(tabline_tooltip), event_box, |
3625 (const char *)labeltext, NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3626 # endif |
846 | 3627 CONVERT_TO_UTF8_FREE(labeltext); |
685 | 3628 } |
3629 | |
3630 /* Remove any old labels. */ | |
3631 while (gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui.tabline), nr) != NULL) | |
3632 gtk_notebook_remove_page(GTK_NOTEBOOK(gui.tabline), nr); | |
3633 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3634 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3635 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(gui.tabline)) != curtabidx) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3636 gtk_notebook_set_current_page(GTK_NOTEBOOK(gui.tabline), curtabidx); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3637 # else |
685 | 3638 if (gtk_notebook_current_page(GTK_NOTEBOOK(gui.tabline)) != curtabidx) |
856 | 3639 gtk_notebook_set_page(GTK_NOTEBOOK(gui.tabline), curtabidx); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3640 # endif |
685 | 3641 |
851 | 3642 /* Make sure everything is in place before drawing text. */ |
3643 gui_mch_update(); | |
3644 | |
685 | 3645 ignore_tabline_evt = FALSE; |
3646 } | |
3647 | |
3648 /* | |
3649 * Set the current tab to "nr". First tab is 1. | |
3650 */ | |
3651 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
3652 gui_mch_set_curtab(int nr) |
685 | 3653 { |
3654 if (gui.tabline == NULL) | |
3655 return; | |
3656 | |
3657 ignore_tabline_evt = TRUE; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3658 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3659 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(gui.tabline)) != nr - 1) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3660 gtk_notebook_set_current_page(GTK_NOTEBOOK(gui.tabline), nr - 1); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3661 # else |
685 | 3662 if (gtk_notebook_current_page(GTK_NOTEBOOK(gui.tabline)) != nr - 1) |
856 | 3663 gtk_notebook_set_page(GTK_NOTEBOOK(gui.tabline), nr - 1); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3664 # endif |
685 | 3665 ignore_tabline_evt = FALSE; |
3666 } | |
3667 | |
3668 #endif /* FEAT_GUI_TABLINE */ | |
3669 | |
7 | 3670 /* |
2183 | 3671 * Add selection targets for PRIMARY and CLIPBOARD selections. |
3672 */ | |
3673 void | |
3674 gui_gtk_set_selection_targets(void) | |
3675 { | |
3676 int i, j = 0; | |
3677 int n_targets = N_SELECTION_TARGETS; | |
3678 GtkTargetEntry targets[N_SELECTION_TARGETS]; | |
3679 | |
3680 for (i = 0; i < (int)N_SELECTION_TARGETS; ++i) | |
3681 { | |
3518 | 3682 /* OpenOffice tries to use TARGET_HTML and fails when we don't |
2183 | 3683 * return something, instead of trying another target. Therefore only |
3684 * offer TARGET_HTML when it works. */ | |
3685 if (!clip_html && selection_targets[i].info == TARGET_HTML) | |
3686 n_targets--; | |
3687 else | |
3688 targets[j++] = selection_targets[i]; | |
3689 } | |
3690 | |
3691 gtk_selection_clear_targets(gui.drawarea, (GdkAtom)GDK_SELECTION_PRIMARY); | |
3692 gtk_selection_clear_targets(gui.drawarea, (GdkAtom)clip_plus.gtk_sel_atom); | |
3693 gtk_selection_add_targets(gui.drawarea, | |
3694 (GdkAtom)GDK_SELECTION_PRIMARY, | |
3695 targets, n_targets); | |
3696 gtk_selection_add_targets(gui.drawarea, | |
3697 (GdkAtom)clip_plus.gtk_sel_atom, | |
3698 targets, n_targets); | |
3699 } | |
3700 | |
3701 /* | |
3702 * Set up for receiving DND items. | |
3703 */ | |
3704 void | |
3705 gui_gtk_set_dnd_targets(void) | |
3706 { | |
3707 int i, j = 0; | |
3708 int n_targets = N_DND_TARGETS; | |
3709 GtkTargetEntry targets[N_DND_TARGETS]; | |
3710 | |
3711 for (i = 0; i < (int)N_DND_TARGETS; ++i) | |
3712 { | |
3154 | 3713 if (!clip_html && dnd_targets[i].info == TARGET_HTML) |
2183 | 3714 n_targets--; |
3715 else | |
3716 targets[j++] = dnd_targets[i]; | |
3717 } | |
3718 | |
3719 gtk_drag_dest_unset(gui.drawarea); | |
3720 gtk_drag_dest_set(gui.drawarea, | |
3721 GTK_DEST_DEFAULT_ALL, | |
3722 targets, n_targets, | |
2718 | 3723 GDK_ACTION_COPY | GDK_ACTION_MOVE); |
2183 | 3724 } |
3725 | |
3726 /* | |
7 | 3727 * Initialize the GUI. Create all the windows, set up all the callbacks etc. |
3728 * Returns OK for success, FAIL when the GUI can't be started. | |
3729 */ | |
3730 int | |
3731 gui_mch_init(void) | |
3732 { | |
3733 GtkWidget *vbox; | |
3734 | |
3735 #ifdef FEAT_GUI_GNOME | |
3736 /* Initialize the GNOME libraries. gnome_program_init()/gnome_init() | |
3737 * exits on failure, but that's a non-issue because we already called | |
3738 * gtk_init_check() in gui_mch_init_check(). */ | |
3739 if (using_gnome) | |
4045 | 3740 { |
7 | 3741 gnome_program_init(VIMPACKAGE, VIM_VERSION_SHORT, |
3742 LIBGNOMEUI_MODULE, gui_argc, gui_argv, NULL); | |
4045 | 3743 # if defined(FEAT_FLOAT) && defined(LC_NUMERIC) |
5854 | 3744 { |
3745 char *p = setlocale(LC_NUMERIC, NULL); | |
3746 | |
3747 /* Make sure strtod() uses a decimal point, not a comma. Gnome | |
3748 * init may change it. */ | |
3749 if (p == NULL || strcmp(p, "C") != 0) | |
3750 setlocale(LC_NUMERIC, "C"); | |
3751 } | |
4045 | 3752 # endif |
3753 } | |
7 | 3754 #endif |
3755 vim_free(gui_argv); | |
3756 gui_argv = NULL; | |
3757 | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3758 #if GLIB_CHECK_VERSION(2,1,3) |
7 | 3759 /* Set the human-readable application name */ |
3760 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
|
3761 #endif |
7 | 3762 /* |
3763 * Force UTF-8 output no matter what the value of 'encoding' is. | |
3764 * did_set_string_option() in option.c prohibits changing 'termencoding' | |
3765 * to something else than UTF-8 if the GUI is in use. | |
3766 */ | |
3767 set_option_value((char_u *)"termencoding", 0L, (char_u *)"utf-8", 0); | |
3768 | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3769 #ifdef FEAT_TOOLBAR |
7 | 3770 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
|
3771 #endif |
7 | 3772 /* FIXME: Need to install the classic icons and a gtkrc.classic file. |
3773 * The hard part is deciding install locations and the Makefile magic. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3774 #if !GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3775 # if 0 |
7 | 3776 gtk_rc_parse("gtkrc"); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3777 # endif |
7 | 3778 #endif |
3779 | |
3780 /* Initialize values */ | |
3781 gui.border_width = 2; | |
3782 gui.scrollbar_width = SB_DEFAULT_WIDTH; | |
3783 gui.scrollbar_height = SB_DEFAULT_WIDTH; | |
136 | 3784 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
7 | 3785 gui.fgcolor = g_new0(GdkColor, 1); |
136 | 3786 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
7 | 3787 gui.bgcolor = g_new0(GdkColor, 1); |
207 | 3788 /* LINTED: avoid warning: conversion to 'unsigned long' */ |
3789 gui.spcolor = g_new0(GdkColor, 1); | |
7 | 3790 |
3791 /* Initialise atoms */ | |
1904 | 3792 html_atom = gdk_atom_intern("text/html", FALSE); |
7 | 3793 utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE); |
3794 | |
3795 /* Set default foreground and background colors. */ | |
3796 gui.norm_pixel = gui.def_norm_pixel; | |
3797 gui.back_pixel = gui.def_back_pixel; | |
3798 | |
3799 if (gtk_socket_id != 0) | |
3800 { | |
3801 GtkWidget *plug; | |
3802 | |
3803 /* Use GtkSocket from another app. */ | |
3804 #ifdef HAVE_GTK_MULTIHEAD | |
3805 plug = gtk_plug_new_for_display(gdk_display_get_default(), | |
3806 gtk_socket_id); | |
3807 #else | |
3808 plug = gtk_plug_new(gtk_socket_id); | |
3809 #endif | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3810 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3811 if (plug != NULL && gtk_plug_get_socket_window(GTK_PLUG(plug)) != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3812 #else |
7 | 3813 if (plug != NULL && GTK_PLUG(plug)->socket_window != NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3814 #endif |
7 | 3815 { |
3816 gui.mainwin = plug; | |
3817 } | |
3818 else | |
3819 { | |
3820 g_warning("Connection to GTK+ socket (ID %u) failed", | |
3821 (unsigned int)gtk_socket_id); | |
3822 /* Pretend we never wanted it if it failed (get own window) */ | |
3823 gtk_socket_id = 0; | |
3824 } | |
3825 } | |
3826 | |
3827 if (gtk_socket_id == 0) | |
3828 { | |
3829 #ifdef FEAT_GUI_GNOME | |
3830 if (using_gnome) | |
3831 { | |
3832 gui.mainwin = gnome_app_new("Vim", NULL); | |
3833 # ifdef USE_XSMP | |
3834 /* Use the GNOME save-yourself functionality now. */ | |
3835 xsmp_close(); | |
3836 # endif | |
3837 } | |
3838 else | |
3839 #endif | |
3840 gui.mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
3841 } | |
3842 | |
3843 gtk_widget_set_name(gui.mainwin, "vim-main-window"); | |
3844 | |
3845 /* Create the PangoContext used for drawing all text. */ | |
3846 gui.text_context = gtk_widget_create_pango_context(gui.mainwin); | |
3847 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
|
3848 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3849 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3850 gtk_container_set_border_width(GTK_CONTAINER(gui.mainwin), 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3851 #else |
7 | 3852 gtk_container_border_width(GTK_CONTAINER(gui.mainwin), 0); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3853 #endif |
7 | 3854 gtk_widget_add_events(gui.mainwin, GDK_VISIBILITY_NOTIFY_MASK); |
3855 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3856 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3857 g_signal_connect(G_OBJECT(gui.mainwin), "delete-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3858 G_CALLBACK(&delete_event_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3859 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3860 g_signal_connect(G_OBJECT(gui.mainwin), "realize", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3861 G_CALLBACK(&mainwin_realize), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3862 #else |
7 | 3863 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "delete_event", |
3864 GTK_SIGNAL_FUNC(&delete_event_cb), NULL); | |
3865 | |
3866 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "realize", | |
3867 GTK_SIGNAL_FUNC(&mainwin_realize), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3868 #endif |
7 | 3869 #ifdef HAVE_GTK_MULTIHEAD |
3870 g_signal_connect(G_OBJECT(gui.mainwin), "screen_changed", | |
3871 G_CALLBACK(&mainwin_screen_changed_cb), NULL); | |
3872 #endif | |
3873 gui.accel_group = gtk_accel_group_new(); | |
3874 gtk_window_add_accel_group(GTK_WINDOW(gui.mainwin), gui.accel_group); | |
3875 | |
685 | 3876 /* A vertical box holds the menubar, toolbar and main text window. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3877 #if GTK_CHECK_VERSION(3,2,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3878 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3879 gtk_box_set_homogeneous(GTK_BOX(vbox), FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3880 #else |
7 | 3881 vbox = gtk_vbox_new(FALSE, 0); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3882 #endif |
7 | 3883 |
3884 #ifdef FEAT_GUI_GNOME | |
3885 if (using_gnome) | |
3886 { | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3887 # if defined(FEAT_MENU) |
7 | 3888 /* automagically restore menubar/toolbar placement */ |
3889 gnome_app_enable_layout_config(GNOME_APP(gui.mainwin), TRUE); | |
3890 # endif | |
3891 gnome_app_set_contents(GNOME_APP(gui.mainwin), vbox); | |
3892 } | |
3893 else | |
3894 #endif | |
3895 { | |
3896 gtk_container_add(GTK_CONTAINER(gui.mainwin), vbox); | |
3897 gtk_widget_show(vbox); | |
3898 } | |
3899 | |
3900 #ifdef FEAT_MENU | |
3901 /* | |
3902 * Create the menubar and handle | |
3903 */ | |
3904 gui.menubar = gtk_menu_bar_new(); | |
3905 gtk_widget_set_name(gui.menubar, "vim-menubar"); | |
3906 | |
36 | 3907 /* Avoid that GTK takes <F10> away from us. */ |
3908 { | |
3909 GtkSettings *gtk_settings; | |
3910 | |
3911 gtk_settings = gtk_settings_get_for_screen(gdk_screen_get_default()); | |
3912 g_object_set(gtk_settings, "gtk-menu-bar-accel", NULL, NULL); | |
3913 } | |
3914 | |
3915 | |
7 | 3916 # ifdef FEAT_GUI_GNOME |
3917 if (using_gnome) | |
3918 { | |
3919 BonoboDockItem *dockitem; | |
3920 | |
3921 gnome_app_set_menus(GNOME_APP(gui.mainwin), GTK_MENU_BAR(gui.menubar)); | |
3922 dockitem = gnome_app_get_dock_item_by_name(GNOME_APP(gui.mainwin), | |
3923 GNOME_APP_MENUBAR_NAME); | |
798 | 3924 /* We don't want the menu to float. */ |
3925 bonobo_dock_item_set_behavior(dockitem, | |
3926 bonobo_dock_item_get_behavior(dockitem) | |
3927 | BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); | |
7 | 3928 gui.menubar_h = GTK_WIDGET(dockitem); |
3929 } | |
3930 else | |
3931 # endif /* FEAT_GUI_GNOME */ | |
3932 { | |
827 | 3933 /* Always show the menubar, otherwise <F10> doesn't work. It may be |
3934 * disabled in gui_init() later. */ | |
3935 gtk_widget_show(gui.menubar); | |
7 | 3936 gtk_box_pack_start(GTK_BOX(vbox), gui.menubar, FALSE, FALSE, 0); |
3937 } | |
3938 #endif /* FEAT_MENU */ | |
3939 | |
3940 #ifdef FEAT_TOOLBAR | |
3941 /* | |
3942 * Create the toolbar and handle | |
3943 */ | |
3944 /* some aesthetics on the toolbar */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3945 # ifdef USE_GTK3 |
8301
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
3946 /* TODO: Add GTK+ 3 code here using GtkCssProvider if necessary. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3947 /* N.B. Since the default value of GtkToolbar::button-relief is |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3948 * GTK_RELIEF_NONE, there's no need to specify that, probably. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3949 # else |
7 | 3950 gtk_rc_parse_string( |
3951 "style \"vim-toolbar-style\" {\n" | |
3952 " GtkToolbar::button_relief = GTK_RELIEF_NONE\n" | |
3953 "}\n" | |
3954 "widget \"*.vim-toolbar\" style \"vim-toolbar-style\"\n"); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3955 # endif |
7 | 3956 gui.toolbar = gtk_toolbar_new(); |
3957 gtk_widget_set_name(gui.toolbar, "vim-toolbar"); | |
3958 set_toolbar_style(GTK_TOOLBAR(gui.toolbar)); | |
3959 | |
3960 # ifdef FEAT_GUI_GNOME | |
3961 if (using_gnome) | |
3962 { | |
3963 BonoboDockItem *dockitem; | |
3964 | |
3965 gnome_app_set_toolbar(GNOME_APP(gui.mainwin), GTK_TOOLBAR(gui.toolbar)); | |
3966 dockitem = gnome_app_get_dock_item_by_name(GNOME_APP(gui.mainwin), | |
3967 GNOME_APP_TOOLBAR_NAME); | |
3968 gui.toolbar_h = GTK_WIDGET(dockitem); | |
795 | 3969 /* When the toolbar is floating it gets stuck. So long as that isn't |
798 | 3970 * fixed let's disallow floating. */ |
795 | 3971 bonobo_dock_item_set_behavior(dockitem, |
798 | 3972 bonobo_dock_item_get_behavior(dockitem) |
3973 | BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); | |
7 | 3974 gtk_container_set_border_width(GTK_CONTAINER(gui.toolbar), 0); |
3975 } | |
3976 else | |
3977 # endif /* FEAT_GUI_GNOME */ | |
3978 { | |
3979 if (vim_strchr(p_go, GO_TOOLBAR) != NULL | |
3980 && (toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS))) | |
3981 gtk_widget_show(gui.toolbar); | |
3982 gtk_box_pack_start(GTK_BOX(vbox), gui.toolbar, FALSE, FALSE, 0); | |
3983 } | |
3984 #endif /* FEAT_TOOLBAR */ | |
3985 | |
685 | 3986 #ifdef FEAT_GUI_TABLINE |
782 | 3987 /* |
3988 * Use a Notebook for the tab pages labels. The labels are hidden by | |
3989 * default. | |
3990 */ | |
791 | 3991 gui.tabline = gtk_notebook_new(); |
3992 gtk_widget_show(gui.tabline); | |
3993 gtk_box_pack_start(GTK_BOX(vbox), gui.tabline, FALSE, FALSE, 0); | |
3994 gtk_notebook_set_show_border(GTK_NOTEBOOK(gui.tabline), FALSE); | |
3995 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gui.tabline), FALSE); | |
841 | 3996 gtk_notebook_set_scrollable(GTK_NOTEBOOK(gui.tabline), TRUE); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3997 # if !GTK_CHECK_VERSION(3,0,0) |
868 | 3998 gtk_notebook_set_tab_border(GTK_NOTEBOOK(gui.tabline), FALSE); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
3999 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4000 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4001 # if !GTK_CHECK_VERSION(3,0,0) |
846 | 4002 tabline_tooltip = gtk_tooltips_new(); |
4003 gtk_tooltips_enable(GTK_TOOLTIPS(tabline_tooltip)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4004 # endif |
846 | 4005 |
4006 { | |
4007 GtkWidget *page, *label, *event_box; | |
791 | 4008 |
856 | 4009 /* Add the first tab. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4010 # if GTK_CHECK_VERSION(3,2,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4011 page = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4012 gtk_box_set_homogeneous(GTK_BOX(page), FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4013 # else |
846 | 4014 page = gtk_vbox_new(FALSE, 0); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4015 # endif |
846 | 4016 gtk_widget_show(page); |
4017 gtk_container_add(GTK_CONTAINER(gui.tabline), page); | |
4018 label = gtk_label_new("-Empty-"); | |
4019 gtk_widget_show(label); | |
4020 event_box = gtk_event_box_new(); | |
4021 gtk_widget_show(event_box); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4022 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4023 g_object_set_data(G_OBJECT(event_box), "tab_num", GINT_TO_POINTER(1L)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4024 # else |
1660 | 4025 gtk_object_set_user_data(GTK_OBJECT(event_box), (gpointer)1L); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4026 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4027 # if !GTK_CHECK_VERSION(3,14,0) |
851 | 4028 gtk_misc_set_padding(GTK_MISC(label), 2, 2); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4029 # endif |
846 | 4030 gtk_container_add(GTK_CONTAINER(event_box), label); |
4031 gtk_notebook_set_tab_label(GTK_NOTEBOOK(gui.tabline), page, event_box); | |
791 | 4032 } |
865 | 4033 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4034 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4035 g_signal_connect(G_OBJECT(gui.tabline), "switch-page", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4036 G_CALLBACK(on_select_tab), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4037 # else |
791 | 4038 gtk_signal_connect(GTK_OBJECT(gui.tabline), "switch_page", |
856 | 4039 GTK_SIGNAL_FUNC(on_select_tab), NULL); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4040 # endif |
791 | 4041 |
4042 /* Create a popup menu for the tab line and connect it. */ | |
4043 tabline_menu = create_tabline_menu(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4044 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4045 g_signal_connect_swapped(G_OBJECT(gui.tabline), "button-press-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4046 G_CALLBACK(on_tabline_menu), G_OBJECT(tabline_menu)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4047 # else |
791 | 4048 gtk_signal_connect_object(GTK_OBJECT(gui.tabline), "button_press_event", |
856 | 4049 GTK_SIGNAL_FUNC(on_tabline_menu), GTK_OBJECT(tabline_menu)); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4050 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4051 #endif /* FEAT_GUI_TABLINE */ |
685 | 4052 |
7 | 4053 gui.formwin = gtk_form_new(); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4054 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4055 gtk_container_set_border_width(GTK_CONTAINER(gui.formwin), 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4056 #else |
7 | 4057 gtk_container_border_width(GTK_CONTAINER(gui.formwin), 0); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4058 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4059 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 4060 gtk_widget_set_events(gui.formwin, GDK_EXPOSURE_MASK); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4061 #endif |
7 | 4062 |
4063 gui.drawarea = gtk_drawing_area_new(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4064 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4065 gui.surface = NULL; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4066 gui.by_signal = FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4067 #endif |
7 | 4068 |
4069 /* Determine which events we will filter. */ | |
4070 gtk_widget_set_events(gui.drawarea, | |
4071 GDK_EXPOSURE_MASK | | |
4072 GDK_ENTER_NOTIFY_MASK | | |
4073 GDK_LEAVE_NOTIFY_MASK | | |
4074 GDK_BUTTON_PRESS_MASK | | |
4075 GDK_BUTTON_RELEASE_MASK | | |
4076 GDK_SCROLL_MASK | | |
4077 GDK_KEY_PRESS_MASK | | |
4078 GDK_KEY_RELEASE_MASK | | |
4079 GDK_POINTER_MOTION_MASK | | |
4080 GDK_POINTER_MOTION_HINT_MASK); | |
4081 | |
4082 gtk_widget_show(gui.drawarea); | |
4083 gtk_form_put(GTK_FORM(gui.formwin), gui.drawarea, 0, 0); | |
4084 gtk_widget_show(gui.formwin); | |
4085 gtk_box_pack_start(GTK_BOX(vbox), gui.formwin, TRUE, TRUE, 0); | |
4086 | |
4087 /* For GtkSockets, key-presses must go to the focus widget (drawarea) | |
4088 * and not the window. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4089 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4090 g_signal_connect((gtk_socket_id == 0) ? G_OBJECT(gui.mainwin) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4091 : G_OBJECT(gui.drawarea), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4092 "key-press-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4093 G_CALLBACK(key_press_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4094 #else |
7 | 4095 gtk_signal_connect((gtk_socket_id == 0) ? GTK_OBJECT(gui.mainwin) |
4096 : GTK_OBJECT(gui.drawarea), | |
4097 "key_press_event", | |
4098 GTK_SIGNAL_FUNC(key_press_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4099 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4100 #if defined(FEAT_XIM) || GTK_CHECK_VERSION(3,0,0) |
7 | 4101 /* Also forward key release events for the benefit of GTK+ 2 input |
4102 * modules. Try CTRL-SHIFT-xdigits to enter a Unicode code point. */ | |
4103 g_signal_connect((gtk_socket_id == 0) ? G_OBJECT(gui.mainwin) | |
4104 : G_OBJECT(gui.drawarea), | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4105 "key-release-event", |
7 | 4106 G_CALLBACK(&key_release_event), NULL); |
4107 #endif | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4108 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4109 g_signal_connect(G_OBJECT(gui.drawarea), "realize", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4110 G_CALLBACK(drawarea_realize_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4111 g_signal_connect(G_OBJECT(gui.drawarea), "unrealize", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4112 G_CALLBACK(drawarea_unrealize_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4113 g_signal_connect(G_OBJECT(gui.drawarea), "configure-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4114 G_CALLBACK(drawarea_configure_event_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4115 g_signal_connect_after(G_OBJECT(gui.drawarea), "style-set", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4116 G_CALLBACK(&drawarea_style_set_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4117 #else |
7 | 4118 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "realize", |
4119 GTK_SIGNAL_FUNC(drawarea_realize_cb), NULL); | |
4120 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "unrealize", | |
4121 GTK_SIGNAL_FUNC(drawarea_unrealize_cb), NULL); | |
4122 | |
4123 gtk_signal_connect_after(GTK_OBJECT(gui.drawarea), "style_set", | |
4124 GTK_SIGNAL_FUNC(&drawarea_style_set_cb), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4125 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4126 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4127 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 4128 gui.visibility = GDK_VISIBILITY_UNOBSCURED; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4129 #endif |
7 | 4130 |
4131 #if !(defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) | |
4132 wm_protocols_atom = gdk_atom_intern("WM_PROTOCOLS", FALSE); | |
4133 save_yourself_atom = gdk_atom_intern("WM_SAVE_YOURSELF", FALSE); | |
4134 #endif | |
4135 | |
4136 if (gtk_socket_id != 0) | |
1884 | 4137 /* make sure keyboard input can go to the drawarea */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4138 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4139 gtk_widget_set_can_focus(gui.drawarea, TRUE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4140 #else |
7 | 4141 GTK_WIDGET_SET_FLAGS(gui.drawarea, GTK_CAN_FOCUS); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4142 #endif |
7 | 4143 |
4144 /* | |
4145 * Set clipboard specific atoms | |
4146 */ | |
4147 vim_atom = gdk_atom_intern(VIM_ATOM_NAME, FALSE); | |
4148 vimenc_atom = gdk_atom_intern(VIMENC_ATOM_NAME, FALSE); | |
4149 clip_star.gtk_sel_atom = GDK_SELECTION_PRIMARY; | |
4150 clip_plus.gtk_sel_atom = gdk_atom_intern("CLIPBOARD", FALSE); | |
4151 | |
4152 /* | |
4153 * Start out by adding the configured border width into the border offset. | |
4154 */ | |
4155 gui.border_offset = gui.border_width; | |
4156 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4157 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4158 g_signal_connect(G_OBJECT(gui.drawarea), "draw", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4159 G_CALLBACK(draw_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4160 #else |
7 | 4161 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "visibility_notify_event", |
4162 GTK_SIGNAL_FUNC(visibility_event), NULL); | |
4163 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "expose_event", | |
4164 GTK_SIGNAL_FUNC(expose_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4165 #endif |
7 | 4166 |
4167 /* | |
4168 * Only install these enter/leave callbacks when 'p' in 'guioptions'. | |
4169 * Only needed for some window managers. | |
4170 */ | |
4171 if (vim_strchr(p_go, GO_POINTER) != NULL) | |
4172 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4173 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4174 g_signal_connect(G_OBJECT(gui.drawarea), "leave-notify-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4175 G_CALLBACK(leave_notify_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4176 g_signal_connect(G_OBJECT(gui.drawarea), "enter-notify-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4177 G_CALLBACK(enter_notify_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4178 #else |
7 | 4179 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "leave_notify_event", |
4180 GTK_SIGNAL_FUNC(leave_notify_event), NULL); | |
4181 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "enter_notify_event", | |
4182 GTK_SIGNAL_FUNC(enter_notify_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4183 #endif |
7 | 4184 } |
4185 | |
791 | 4186 /* Real windows can get focus ... GtkPlug, being a mere container can't, |
4187 * only its widgets. Arguably, this could be common code and we not use | |
4188 * the window focus at all, but let's be safe. | |
4189 */ | |
4190 if (gtk_socket_id == 0) | |
4191 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4192 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4193 g_signal_connect(G_OBJECT(gui.mainwin), "focus-out-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4194 G_CALLBACK(focus_out_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4195 g_signal_connect(G_OBJECT(gui.mainwin), "focus-in-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4196 G_CALLBACK(focus_in_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4197 #else |
856 | 4198 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "focus_out_event", |
4199 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
4200 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "focus_in_event", | |
4201 GTK_SIGNAL_FUNC(focus_in_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4202 #endif |
791 | 4203 } |
4204 else | |
4205 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4206 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4207 g_signal_connect(G_OBJECT(gui.drawarea), "focus-out-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4208 G_CALLBACK(focus_out_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4209 g_signal_connect(G_OBJECT(gui.drawarea), "focus-in-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4210 G_CALLBACK(focus_in_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4211 #else |
856 | 4212 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "focus_out_event", |
4213 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
4214 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "focus_in_event", | |
4215 GTK_SIGNAL_FUNC(focus_in_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4216 #endif |
791 | 4217 #ifdef FEAT_GUI_TABLINE |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4218 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4219 g_signal_connect(G_OBJECT(gui.tabline), "focus-out-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4220 G_CALLBACK(focus_out_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4221 g_signal_connect(G_OBJECT(gui.tabline), "focus-in-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4222 G_CALLBACK(focus_in_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4223 # else |
856 | 4224 gtk_signal_connect(GTK_OBJECT(gui.tabline), "focus_out_event", |
4225 GTK_SIGNAL_FUNC(focus_out_event), NULL); | |
4226 gtk_signal_connect(GTK_OBJECT(gui.tabline), "focus_in_event", | |
4227 GTK_SIGNAL_FUNC(focus_in_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4228 # endif |
791 | 4229 #endif /* FEAT_GUI_TABLINE */ |
4230 } | |
7 | 4231 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4232 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4233 g_signal_connect(G_OBJECT(gui.drawarea), "motion-notify-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4234 G_CALLBACK(motion_notify_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4235 g_signal_connect(G_OBJECT(gui.drawarea), "button-press-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4236 G_CALLBACK(button_press_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4237 g_signal_connect(G_OBJECT(gui.drawarea), "button-release-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4238 G_CALLBACK(button_release_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4239 g_signal_connect(G_OBJECT(gui.drawarea), "scroll-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4240 G_CALLBACK(&scroll_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4241 #else |
7 | 4242 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "motion_notify_event", |
4243 GTK_SIGNAL_FUNC(motion_notify_event), NULL); | |
4244 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "button_press_event", | |
4245 GTK_SIGNAL_FUNC(button_press_event), NULL); | |
4246 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "button_release_event", | |
4247 GTK_SIGNAL_FUNC(button_release_event), NULL); | |
4248 g_signal_connect(G_OBJECT(gui.drawarea), "scroll_event", | |
4249 G_CALLBACK(&scroll_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4250 #endif |
7 | 4251 |
4252 /* | |
4253 * Add selection handler functions. | |
4254 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4255 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4256 g_signal_connect(G_OBJECT(gui.drawarea), "selection-clear-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4257 G_CALLBACK(selection_clear_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4258 g_signal_connect(G_OBJECT(gui.drawarea), "selection-received", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4259 G_CALLBACK(selection_received_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4260 #else |
7 | 4261 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_clear_event", |
4262 GTK_SIGNAL_FUNC(selection_clear_event), NULL); | |
4263 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_received", | |
4264 GTK_SIGNAL_FUNC(selection_received_cb), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4265 #endif |
7 | 4266 |
2183 | 4267 gui_gtk_set_selection_targets(); |
7 | 4268 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4269 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4270 g_signal_connect(G_OBJECT(gui.drawarea), "selection-get", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4271 G_CALLBACK(selection_get_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4272 #else |
7 | 4273 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "selection_get", |
4274 GTK_SIGNAL_FUNC(selection_get_cb), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4275 #endif |
7 | 4276 |
4277 /* Pretend we don't have input focus, we will get an event if we do. */ | |
4278 gui.in_focus = FALSE; | |
4279 | |
4280 return OK; | |
4281 } | |
4282 | |
4283 #if (defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)) || defined(PROTO) | |
4284 /* | |
4285 * This is called from gui_start() after a fork() has been done. | |
4286 * We have to tell the session manager our new PID. | |
4287 */ | |
4288 void | |
4289 gui_mch_forked(void) | |
4290 { | |
4291 if (using_gnome) | |
4292 { | |
4293 GnomeClient *client; | |
4294 | |
4295 client = gnome_master_client(); | |
4296 | |
4297 if (client != NULL) | |
4298 gnome_client_set_process_id(client, getpid()); | |
4299 } | |
4300 } | |
4301 #endif /* FEAT_GUI_GNOME && FEAT_SESSION */ | |
4302 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4303 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4304 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4305 gui_gtk_get_rgb_from_pixel(guint32 pixel, GdkRGBA *result) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4306 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4307 GdkVisual * const visual = gtk_widget_get_visual(gui.drawarea); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4308 guint32 r_mask, g_mask, b_mask; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4309 gint r_shift, g_shift, b_shift; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4310 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4311 if (visual == NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4312 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4313 result->red = 0.0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4314 result->green = 0.0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4315 result->blue = 0.0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4316 result->alpha = 0.0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4317 return; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4318 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4319 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4320 gdk_visual_get_red_pixel_details(visual, &r_mask, &r_shift, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4321 gdk_visual_get_green_pixel_details(visual, &g_mask, &g_shift, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4322 gdk_visual_get_blue_pixel_details(visual, &b_mask, &b_shift, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4323 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4324 result->red = ((pixel & r_mask) >> r_shift) / 255.0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4325 result->green = ((pixel & g_mask) >> g_shift) / 255.0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4326 result->blue = ((pixel & b_mask) >> b_shift) / 255.0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4327 result->alpha = 1.0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4328 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4329 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4330 /* Convert a GdRGBA into a pixel value using drawarea's visual */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4331 static guint32 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4332 gui_gtk_get_pixel_from_rgb(const GdkRGBA *rgba) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4333 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4334 GdkVisual * const visual = gtk_widget_get_visual(gui.drawarea); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4335 guint32 r_mask, g_mask, b_mask; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4336 gint r_shift, g_shift, b_shift; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4337 guint32 r, g, b; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4338 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4339 if (visual == NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4340 return 0; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4341 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4342 gdk_visual_get_red_pixel_details(visual, &r_mask, &r_shift, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4343 gdk_visual_get_green_pixel_details(visual, &g_mask, &g_shift, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4344 gdk_visual_get_blue_pixel_details(visual, &b_mask, &b_shift, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4345 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4346 r = rgba->red * 65535; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4347 g = rgba->green * 65535; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4348 b = rgba->blue * 65535; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4349 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4350 return ((r << r_shift) & r_mask) | |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4351 ((g << g_shift) & g_mask) | |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4352 ((b << b_shift) & b_mask); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4353 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4354 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4355 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4356 set_cairo_source_rgb_from_pixel(cairo_t *cr, guint32 pixel) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4357 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4358 GdkRGBA result; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4359 gui_gtk_get_rgb_from_pixel(pixel, &result); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4360 cairo_set_source_rgb(cr, result.red, result.green, result.blue); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4361 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4362 #endif /* GTK_CHECK_VERSION(3,0,0) */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4363 |
7 | 4364 /* |
4365 * Called when the foreground or background color has been changed. | |
4366 * This used to change the graphics contexts directly but we are | |
4367 * currently manipulating them where desired. | |
4368 */ | |
4369 void | |
4370 gui_mch_new_colors(void) | |
4371 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4372 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4373 GdkWindow * const da_win = gtk_widget_get_window(gui.drawarea); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4374 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4375 if (gui.drawarea != NULL && gtk_widget_get_window(gui.drawarea) != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4376 #else |
7 | 4377 if (gui.drawarea != NULL && gui.drawarea->window != NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4378 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4379 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4380 #if GTK_CHECK_VERSION(3,4,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4381 GdkRGBA color; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4382 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4383 gui_gtk_get_rgb_from_pixel(gui.back_pixel, &color); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4384 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4385 cairo_pattern_t * const pat = cairo_pattern_create_rgba( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4386 color.red, color.green, color.blue, color.alpha); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4387 if (pat != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4388 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4389 gdk_window_set_background_pattern(da_win, pat); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4390 cairo_pattern_destroy(pat); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4391 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4392 else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4393 gdk_window_set_background_rgba(da_win, &color); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4394 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4395 #else /* !GTK_CHECK_VERSION(3,4,0) */ |
7 | 4396 GdkColor color = { 0, 0, 0, 0 }; |
4397 | |
4398 color.pixel = gui.back_pixel; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4399 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4400 gdk_window_set_background(da_win, &color); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4401 # else |
7 | 4402 gdk_window_set_background(gui.drawarea->window, &color); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4403 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4404 #endif /* !GTK_CHECK_VERSION(3,4,0) */ |
7 | 4405 } |
4406 } | |
4407 | |
4408 /* | |
4409 * This signal informs us about the need to rearrange our sub-widgets. | |
4410 */ | |
4411 static gint | |
1884 | 4412 form_configure_event(GtkWidget *widget UNUSED, |
4413 GdkEventConfigure *event, | |
4414 gpointer data UNUSED) | |
7 | 4415 { |
791 | 4416 int usable_height = event->height; |
4417 | |
4418 /* When in a GtkPlug, we can't guarantee valid heights (as a round | |
4419 * no. of char-heights), so we have to manually sanitise them. | |
4420 * Widths seem to sort themselves out, don't ask me why. | |
4421 */ | |
4422 if (gtk_socket_id != 0) | |
856 | 4423 usable_height -= (gui.char_height - (gui.char_height/2)); /* sic. */ |
791 | 4424 |
7 | 4425 gtk_form_freeze(GTK_FORM(gui.formwin)); |
791 | 4426 gui_resize_shell(event->width, usable_height); |
7 | 4427 gtk_form_thaw(GTK_FORM(gui.formwin)); |
4428 | |
4429 return TRUE; | |
4430 } | |
4431 | |
4432 /* | |
4433 * Function called when window already closed. | |
4434 * We can't do much more here than to trying to preserve what had been done, | |
4435 * since the window is already inevitably going away. | |
4436 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4437 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4438 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4439 mainwin_destroy_cb(GObject *object UNUSED, gpointer data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4440 #else |
7 | 4441 static void |
1884 | 4442 mainwin_destroy_cb(GtkObject *object UNUSED, gpointer data UNUSED) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4443 #endif |
7 | 4444 { |
4445 /* Don't write messages to the GUI anymore */ | |
4446 full_screen = FALSE; | |
4447 | |
4448 gui.mainwin = NULL; | |
4449 gui.drawarea = NULL; | |
4450 | |
4451 if (!exiting) /* only do anything if the destroy was unexpected */ | |
4452 { | |
419 | 4453 vim_strncpy(IObuff, |
4454 (char_u *)_("Vim: Main window unexpectedly destroyed\n"), | |
4455 IOSIZE - 1); | |
7 | 4456 preserve_exit(); |
4457 } | |
7380
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
4458 #ifdef USE_GRESOURCE |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
4459 gui_gtk_unregister_resource(); |
055a0b587a3e
commit https://github.com/vim/vim/commit/36e294c00c784b9ddd05a4fdbea2e331ab2b1ca8
Christian Brabandt <cb@256bit.org>
parents:
7260
diff
changeset
|
4460 #endif |
7 | 4461 } |
4462 | |
791 | 4463 |
4464 /* | |
4465 * Bit of a hack to ensure we start GtkPlug windows with the correct window | |
4466 * hints (and thus the required size from -geom), but that after that we | |
4467 * put the hints back to normal (the actual minimum size) so we may | |
4468 * subsequently be resized smaller. GtkSocket (the parent end) uses the | |
1226 | 4469 * plug's window 'min hints to set *it's* minimum size, but that's also the |
791 | 4470 * only way we have of making ourselves bigger (by set lines/columns). |
4471 * Thus set hints at start-up to ensure correct init. size, then a | |
8301
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4472 * second after the final attempt to reset the real minimum hints (done by |
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
4473 * scrollbar init.), actually do the standard hints and stop the timer. |
791 | 4474 * We'll not let the default hints be set while this timer's active. |
4475 */ | |
4476 static gboolean | |
1884 | 4477 check_startup_plug_hints(gpointer data UNUSED) |
791 | 4478 { |
4479 if (init_window_hints_state == 1) | |
4480 { | |
856 | 4481 /* Safe to use normal hints now */ |
4482 init_window_hints_state = 0; | |
4483 update_window_manager_hints(0, 0); | |
4484 return FALSE; /* stop timer */ | |
791 | 4485 } |
4486 | |
4487 /* Keep on trying */ | |
4488 init_window_hints_state = 1; | |
4489 return TRUE; | |
4490 } | |
4491 | |
7 | 4492 /* |
4493 * Open the GUI window which was created by a call to gui_mch_init(). | |
4494 */ | |
4495 int | |
4496 gui_mch_open(void) | |
4497 { | |
4498 guicolor_T fg_pixel = INVALCOLOR; | |
4499 guicolor_T bg_pixel = INVALCOLOR; | |
1966 | 4500 guint pixel_width; |
4501 guint pixel_height; | |
7 | 4502 |
4503 /* | |
4504 * Allow setting a window role on the command line, or invent one | |
4505 * if none was specified. This is mainly useful for GNOME session | |
4506 * support; allowing the WM to restore window placement. | |
4507 */ | |
4508 if (role_argument != NULL) | |
4509 { | |
4510 gtk_window_set_role(GTK_WINDOW(gui.mainwin), role_argument); | |
4511 } | |
4512 else | |
4513 { | |
4514 char *role; | |
4515 | |
4516 /* Invent a unique-enough ID string for the role */ | |
4517 role = g_strdup_printf("vim-%u-%u-%u", | |
4518 (unsigned)mch_get_pid(), | |
4519 (unsigned)g_random_int(), | |
4520 (unsigned)time(NULL)); | |
4521 | |
4522 gtk_window_set_role(GTK_WINDOW(gui.mainwin), role); | |
4523 g_free(role); | |
4524 } | |
4525 | |
4526 if (gui_win_x != -1 && gui_win_y != -1) | |
4527 gtk_window_move(GTK_WINDOW(gui.mainwin), gui_win_x, gui_win_y); | |
4528 | |
4529 /* Determine user specified geometry, if present. */ | |
4530 if (gui.geom != NULL) | |
4531 { | |
4532 int mask; | |
4533 unsigned int w, h; | |
4534 int x = 0; | |
4535 int y = 0; | |
4536 | |
4537 mask = XParseGeometry((char *)gui.geom, &x, &y, &w, &h); | |
4538 | |
4539 if (mask & WidthValue) | |
4540 Columns = w; | |
4541 if (mask & HeightValue) | |
857 | 4542 { |
1884 | 4543 if (p_window > (long)h - 1 || !option_was_set((char_u *)"window")) |
857 | 4544 p_window = h - 1; |
7 | 4545 Rows = h; |
857 | 4546 } |
5070
cf52d2a8c05c
updated for version 7.3.1278
Bram Moolenaar <bram@vim.org>
parents:
4474
diff
changeset
|
4547 limit_screen_size(); |
1426 | 4548 |
4549 pixel_width = (guint)(gui_get_base_width() + Columns * gui.char_width); | |
4550 pixel_height = (guint)(gui_get_base_height() + Rows * gui.char_height); | |
4551 | |
4552 pixel_width += get_menu_tool_width(); | |
4553 pixel_height += get_menu_tool_height(); | |
4554 | |
7 | 4555 if (mask & (XValue | YValue)) |
1426 | 4556 { |
1757 | 4557 int ww, hh; |
4558 gui_mch_get_screen_dimensions(&ww, &hh); | |
4559 hh += p_ghr + get_menu_tool_height(); | |
4560 ww += get_menu_tool_width(); | |
1426 | 4561 if (mask & XNegative) |
1757 | 4562 x += ww - pixel_width; |
1426 | 4563 if (mask & YNegative) |
1757 | 4564 y += hh - pixel_height; |
7 | 4565 gtk_window_move(GTK_WINDOW(gui.mainwin), x, y); |
1426 | 4566 } |
7 | 4567 vim_free(gui.geom); |
4568 gui.geom = NULL; | |
791 | 4569 |
856 | 4570 /* From now until everyone's stopped trying to set the window hints |
4571 * to their correct minimum values, stop them being set as we need | |
4572 * them to remain at our required size for the parent GtkSocket to | |
4573 * give us the right initial size. | |
4574 */ | |
791 | 4575 if (gtk_socket_id != 0 && (mask & WidthValue || mask & HeightValue)) |
856 | 4576 { |
4577 update_window_manager_hints(pixel_width, pixel_height); | |
4578 init_window_hints_state = 1; | |
4579 g_timeout_add(1000, check_startup_plug_hints, NULL); | |
4580 } | |
7 | 4581 } |
4582 | |
1966 | 4583 pixel_width = (guint)(gui_get_base_width() + Columns * gui.char_width); |
4584 pixel_height = (guint)(gui_get_base_height() + Rows * gui.char_height); | |
4585 /* For GTK2 changing the size of the form widget doesn't cause window | |
4586 * resizing. */ | |
2254
4620acaf4814
One more fix for conceal patch.
Bram Moolenaar <bram@vim.org>
parents:
2248
diff
changeset
|
4587 if (gtk_socket_id == 0) |
1966 | 4588 gtk_window_resize(GTK_WINDOW(gui.mainwin), pixel_width, pixel_height); |
791 | 4589 update_window_manager_hints(0, 0); |
7 | 4590 |
4591 if (foreground_argument != NULL) | |
4592 fg_pixel = gui_get_color((char_u *)foreground_argument); | |
4593 if (fg_pixel == INVALCOLOR) | |
4594 fg_pixel = gui_get_color((char_u *)"Black"); | |
4595 | |
4596 if (background_argument != NULL) | |
4597 bg_pixel = gui_get_color((char_u *)background_argument); | |
4598 if (bg_pixel == INVALCOLOR) | |
4599 bg_pixel = gui_get_color((char_u *)"White"); | |
4600 | |
4601 if (found_reverse_arg) | |
4602 { | |
4603 gui.def_norm_pixel = bg_pixel; | |
4604 gui.def_back_pixel = fg_pixel; | |
4605 } | |
4606 else | |
4607 { | |
4608 gui.def_norm_pixel = fg_pixel; | |
4609 gui.def_back_pixel = bg_pixel; | |
4610 } | |
4611 | |
4612 /* Get the colors from the "Normal" and "Menu" group (set in syntax.c or | |
4613 * in a vimrc file) */ | |
4614 set_normal_colors(); | |
4615 | |
4616 /* Check that none of the colors are the same as the background color */ | |
4617 gui_check_colors(); | |
4618 | |
4619 /* Get the colors for the highlight groups (gui_check_colors() might have | |
4620 * changed them). */ | |
4621 highlight_gui_started(); /* re-init colors and fonts */ | |
4622 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4623 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4624 g_signal_connect(G_OBJECT(gui.mainwin), "destroy", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4625 G_CALLBACK(mainwin_destroy_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4626 #else |
7 | 4627 gtk_signal_connect(GTK_OBJECT(gui.mainwin), "destroy", |
4628 GTK_SIGNAL_FUNC(mainwin_destroy_cb), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4629 #endif |
7 | 4630 |
4631 #ifdef FEAT_HANGULIN | |
4632 hangul_keyboard_set(); | |
4633 #endif | |
4634 | |
4635 /* | |
4636 * Notify the fixed area about the need to resize the contents of the | |
4637 * gui.formwin, which we use for random positioning of the included | |
4638 * components. | |
4639 * | |
4640 * We connect this signal deferred finally after anything is in place, | |
4641 * since this is intended to handle resizements coming from the window | |
4642 * manager upon us and should not interfere with what VIM is requesting | |
4643 * upon startup. | |
4644 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4645 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4646 g_signal_connect(G_OBJECT(gui.formwin), "configure-event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4647 G_CALLBACK(form_configure_event), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4648 #else |
7 | 4649 gtk_signal_connect(GTK_OBJECT(gui.formwin), "configure_event", |
4650 GTK_SIGNAL_FUNC(form_configure_event), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4651 #endif |
7 | 4652 |
4653 #ifdef FEAT_DND | |
2183 | 4654 /* Set up for receiving DND items. */ |
4655 gui_gtk_set_dnd_targets(); | |
7 | 4656 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4657 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4658 g_signal_connect(G_OBJECT(gui.drawarea), "drag-data-received", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4659 G_CALLBACK(drag_data_received_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4660 # else |
7 | 4661 gtk_signal_connect(GTK_OBJECT(gui.drawarea), "drag_data_received", |
4662 GTK_SIGNAL_FUNC(drag_data_received_cb), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4663 # endif |
7 | 4664 #endif |
4665 | |
4666 /* 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
|
4667 * to avoid mapping the window for a short time. */ |
7 | 4668 if (found_iconic_arg && gtk_socket_id == 0) |
4669 gui_mch_iconify(); | |
4670 | |
4671 { | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
4672 #if defined(FEAT_GUI_GNOME) && defined(FEAT_MENU) |
7 | 4673 unsigned long menu_handler = 0; |
4674 # ifdef FEAT_TOOLBAR | |
4675 unsigned long tool_handler = 0; | |
4676 # endif | |
4677 /* | |
4678 * Urgh hackish :/ For some reason BonoboDockLayout always forces a | |
4679 * show when restoring the saved layout configuration. We can't just | |
4680 * hide the widgets again after gtk_widget_show(gui.mainwin) since it's | |
4681 * a toplevel window and thus will be realized immediately. Instead, | |
4682 * connect signal handlers to hide the widgets just after they've been | |
4683 * marked visible, but before the main window is realized. | |
4684 */ | |
4685 if (using_gnome && vim_strchr(p_go, GO_MENUS) == NULL) | |
4686 menu_handler = g_signal_connect_after(gui.menubar_h, "show", | |
4687 G_CALLBACK(>k_widget_hide), | |
4688 NULL); | |
4689 # ifdef FEAT_TOOLBAR | |
4690 if (using_gnome && vim_strchr(p_go, GO_TOOLBAR) == NULL | |
4691 && (toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS))) | |
4692 tool_handler = g_signal_connect_after(gui.toolbar_h, "show", | |
4693 G_CALLBACK(>k_widget_hide), | |
4694 NULL); | |
4695 # endif | |
4696 #endif | |
4697 gtk_widget_show(gui.mainwin); | |
4698 | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
4699 #if defined(FEAT_GUI_GNOME) && defined(FEAT_MENU) |
7 | 4700 if (menu_handler != 0) |
4701 g_signal_handler_disconnect(gui.menubar_h, menu_handler); | |
4702 # ifdef FEAT_TOOLBAR | |
4703 if (tool_handler != 0) | |
4704 g_signal_handler_disconnect(gui.toolbar_h, tool_handler); | |
4705 # endif | |
4706 #endif | |
4707 } | |
4708 | |
4709 return OK; | |
4710 } | |
4711 | |
4712 | |
4713 void | |
1884 | 4714 gui_mch_exit(int rc UNUSED) |
7 | 4715 { |
4716 if (gui.mainwin != NULL) | |
4717 gtk_widget_destroy(gui.mainwin); | |
4718 } | |
4719 | |
4720 /* | |
4721 * Get the position of the top left corner of the window. | |
4722 */ | |
4723 int | |
4724 gui_mch_get_winpos(int *x, int *y) | |
4725 { | |
4726 gtk_window_get_position(GTK_WINDOW(gui.mainwin), x, y); | |
4727 return OK; | |
4728 } | |
4729 | |
4730 /* | |
4731 * Set the position of the top left corner of the window to the given | |
4732 * coordinates. | |
4733 */ | |
4734 void | |
4735 gui_mch_set_winpos(int x, int y) | |
4736 { | |
4737 gtk_window_move(GTK_WINDOW(gui.mainwin), x, y); | |
4738 } | |
4739 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4740 #if !GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4741 # if 0 |
7 | 4742 static int resize_idle_installed = FALSE; |
4743 /* | |
4744 * Idle handler to force resize. Used by gui_mch_set_shellsize() to ensure | |
4745 * the shell size doesn't exceed the window size, i.e. if the window manager | |
4746 * ignored our size request. Usually this happens if the window is maximized. | |
4747 * | |
4748 * FIXME: It'd be nice if we could find a little more orthodox solution. | |
4749 * See also the remark below in gui_mch_set_shellsize(). | |
4750 * | |
4751 * DISABLED: When doing ":set lines+=1" this function would first invoke | |
4752 * gui_resize_shell() with the old size, then the normal callback would | |
4753 * report the new size through form_configure_event(). That caused the window | |
4754 * layout to be messed up. | |
4755 */ | |
4756 static gboolean | |
4757 force_shell_resize_idle(gpointer data) | |
4758 { | |
4759 if (gui.mainwin != NULL | |
4760 && GTK_WIDGET_REALIZED(gui.mainwin) | |
4761 && GTK_WIDGET_VISIBLE(gui.mainwin)) | |
4762 { | |
4763 int width; | |
4764 int height; | |
4765 | |
4766 gtk_window_get_size(GTK_WINDOW(gui.mainwin), &width, &height); | |
4767 | |
4768 width -= get_menu_tool_width(); | |
4769 height -= get_menu_tool_height(); | |
4770 | |
4771 gui_resize_shell(width, height); | |
4772 } | |
4773 | |
4774 resize_idle_installed = FALSE; | |
4775 return FALSE; /* don't call me again */ | |
4776 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4777 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4778 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
4779 |
1967 | 4780 /* |
4781 * Return TRUE if the main window is maximized. | |
4782 */ | |
4783 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
4784 gui_mch_maximized(void) |
1967 | 4785 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4786 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4787 return (gui.mainwin != NULL && gtk_widget_get_window(gui.mainwin) != NULL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4788 && (gdk_window_get_state(gtk_widget_get_window(gui.mainwin)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4789 & GDK_WINDOW_STATE_MAXIMIZED)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4790 #else |
1967 | 4791 return (gui.mainwin != NULL && gui.mainwin->window != NULL |
4792 && (gdk_window_get_state(gui.mainwin->window) | |
4793 & GDK_WINDOW_STATE_MAXIMIZED)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4794 #endif |
1967 | 4795 } |
4796 | |
4797 /* | |
4798 * Unmaximize the main window | |
4799 */ | |
4800 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
4801 gui_mch_unmaximize(void) |
1967 | 4802 { |
4803 if (gui.mainwin != NULL) | |
4804 gtk_window_unmaximize(GTK_WINDOW(gui.mainwin)); | |
4805 } | |
4806 | |
7 | 4807 /* |
3014 | 4808 * Called when the font changed while the window is maximized. Compute the |
4809 * new Rows and Columns. This is like resizing the window. | |
4810 */ | |
4811 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7679
diff
changeset
|
4812 gui_mch_newfont(void) |
3014 | 4813 { |
4814 int w, h; | |
4815 | |
4816 gtk_window_get_size(GTK_WINDOW(gui.mainwin), &w, &h); | |
4817 w -= get_menu_tool_width(); | |
4818 h -= get_menu_tool_height(); | |
4819 gui_resize_shell(w, h); | |
4820 } | |
4821 | |
4822 /* | |
7 | 4823 * Set the windows size. |
4824 */ | |
4825 void | |
4826 gui_mch_set_shellsize(int width, int height, | |
1884 | 4827 int min_width UNUSED, int min_height UNUSED, |
4828 int base_width UNUSED, int base_height UNUSED, | |
4829 int direction UNUSED) | |
7 | 4830 { |
4831 /* give GTK+ a chance to put all widget's into place */ | |
4832 gui_mch_update(); | |
4833 | |
791 | 4834 /* this will cause the proper resizement to happen too */ |
4835 if (gtk_socket_id == 0) | |
856 | 4836 update_window_manager_hints(0, 0); |
791 | 4837 |
7 | 4838 /* With GTK+ 2, changing the size of the form widget doesn't resize |
791 | 4839 * the window. So let's do it the other way around and resize the |
7 | 4840 * main window instead. */ |
4841 width += get_menu_tool_width(); | |
4842 height += get_menu_tool_height(); | |
4843 | |
791 | 4844 if (gtk_socket_id == 0) |
856 | 4845 gtk_window_resize(GTK_WINDOW(gui.mainwin), width, height); |
791 | 4846 else |
856 | 4847 update_window_manager_hints(width, height); |
7 | 4848 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4849 # if !GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4850 # if 0 |
7 | 4851 if (!resize_idle_installed) |
4852 { | |
4853 g_idle_add_full(GDK_PRIORITY_EVENTS + 10, | |
4854 &force_shell_resize_idle, NULL, NULL); | |
4855 resize_idle_installed = TRUE; | |
4856 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4857 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4858 # endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 4859 /* |
4860 * Wait until all events are processed to prevent a crash because the | |
4861 * real size of the drawing area doesn't reflect Vim's internal ideas. | |
4862 * | |
4863 * This is a bit of a hack, since Vim is a terminal application with a GUI | |
4864 * on top, while the GUI expects to be the boss. | |
4865 */ | |
4866 gui_mch_update(); | |
4867 } | |
4868 | |
4869 | |
4870 /* | |
4871 * The screen size is used to make sure the initial window doesn't get bigger | |
4872 * than the screen. This subtracts some room for menubar, toolbar and window | |
4873 * decorations. | |
4874 */ | |
4875 void | |
4876 gui_mch_get_screen_dimensions(int *screen_w, int *screen_h) | |
4877 { | |
4878 #ifdef HAVE_GTK_MULTIHEAD | |
4879 GdkScreen* screen; | |
4880 | |
4881 if (gui.mainwin != NULL && gtk_widget_has_screen(gui.mainwin)) | |
4882 screen = gtk_widget_get_screen(gui.mainwin); | |
4883 else | |
4884 screen = gdk_screen_get_default(); | |
4885 | |
4886 *screen_w = gdk_screen_get_width(screen); | |
4887 *screen_h = gdk_screen_get_height(screen) - p_ghr; | |
4888 #else | |
4889 *screen_w = gdk_screen_width(); | |
4890 /* Subtract 'guiheadroom' from the height to allow some room for the | |
4891 * window manager (task list and window title bar). */ | |
4892 *screen_h = gdk_screen_height() - p_ghr; | |
4893 #endif | |
4894 | |
4895 /* | |
4896 * FIXME: dirty trick: Because the gui_get_base_height() doesn't include | |
4897 * 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
|
4898 * height, so that the window size can be made to fit on the screen. |
7 | 4899 * This should be completely changed later. |
4900 */ | |
4901 *screen_w -= get_menu_tool_width(); | |
4902 *screen_h -= get_menu_tool_height(); | |
4903 } | |
4904 | |
4905 #if defined(FEAT_TITLE) || defined(PROTO) | |
4906 void | |
1884 | 4907 gui_mch_settitle(char_u *title, char_u *icon UNUSED) |
7 | 4908 { |
4909 if (title != NULL && output_conv.vc_type != CONV_NONE) | |
4910 title = string_convert(&output_conv, title, NULL); | |
4911 | |
4912 gtk_window_set_title(GTK_WINDOW(gui.mainwin), (const char *)title); | |
4913 | |
4914 if (output_conv.vc_type != CONV_NONE) | |
4915 vim_free(title); | |
4916 } | |
4917 #endif /* FEAT_TITLE */ | |
4918 | |
4919 #if defined(FEAT_MENU) || defined(PROTO) | |
4920 void | |
4921 gui_mch_enable_menu(int showit) | |
4922 { | |
4923 GtkWidget *widget; | |
4924 | |
4925 # ifdef FEAT_GUI_GNOME | |
4926 if (using_gnome) | |
4927 widget = gui.menubar_h; | |
4928 else | |
4929 # endif | |
4930 widget = gui.menubar; | |
4931 | |
827 | 4932 /* Do not disable the menu while starting up, otherwise F10 doesn't work. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4933 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4934 if (!showit != !gtk_widget_get_visible(widget) && !gui.starting) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4935 # else |
827 | 4936 if (!showit != !GTK_WIDGET_VISIBLE(widget) && !gui.starting) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4937 # endif |
7 | 4938 { |
4939 if (showit) | |
4940 gtk_widget_show(widget); | |
4941 else | |
4942 gtk_widget_hide(widget); | |
4943 | |
791 | 4944 update_window_manager_hints(0, 0); |
7 | 4945 } |
4946 } | |
4947 #endif /* FEAT_MENU */ | |
4948 | |
4949 #if defined(FEAT_TOOLBAR) || defined(PROTO) | |
4950 void | |
4951 gui_mch_show_toolbar(int showit) | |
4952 { | |
4953 GtkWidget *widget; | |
4954 | |
4955 if (gui.toolbar == NULL) | |
4956 return; | |
4957 | |
4958 # ifdef FEAT_GUI_GNOME | |
4959 if (using_gnome) | |
4960 widget = gui.toolbar_h; | |
4961 else | |
4962 # endif | |
4963 widget = gui.toolbar; | |
4964 | |
4965 if (showit) | |
4966 set_toolbar_style(GTK_TOOLBAR(gui.toolbar)); | |
4967 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4968 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4969 if (!showit != !gtk_widget_get_visible(widget)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4970 # else |
7 | 4971 if (!showit != !GTK_WIDGET_VISIBLE(widget)) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
4972 # endif |
7 | 4973 { |
4974 if (showit) | |
4975 gtk_widget_show(widget); | |
4976 else | |
4977 gtk_widget_hide(widget); | |
4978 | |
791 | 4979 update_window_manager_hints(0, 0); |
7 | 4980 } |
4981 } | |
4982 #endif /* FEAT_TOOLBAR */ | |
4983 | |
4984 /* | |
4985 * Check if a given font is a CJK font. This is done in a very crude manner. It | |
4986 * just see if U+04E00 for zh and ja and U+AC00 for ko are covered in a given | |
4987 * font. Consequently, this function cannot be used as a general purpose check | |
4988 * for CJK-ness for which fontconfig APIs should be used. This is only used by | |
4989 * gui_mch_init_font() to deal with 'CJK fixed width fonts'. | |
4990 */ | |
4991 static int | |
4992 is_cjk_font(PangoFontDescription *font_desc) | |
4993 { | |
4994 static const char * const cjk_langs[] = | |
4995 {"zh_CN", "zh_TW", "zh_HK", "ja", "ko"}; | |
4996 | |
4997 PangoFont *font; | |
4998 unsigned i; | |
4999 int is_cjk = FALSE; | |
5000 | |
5001 font = pango_context_load_font(gui.text_context, font_desc); | |
5002 | |
5003 if (font == NULL) | |
5004 return FALSE; | |
5005 | |
5006 for (i = 0; !is_cjk && i < G_N_ELEMENTS(cjk_langs); ++i) | |
5007 { | |
5008 PangoCoverage *coverage; | |
5009 gunichar uc; | |
5010 | |
5011 coverage = pango_font_get_coverage( | |
5012 font, pango_language_from_string(cjk_langs[i])); | |
5013 | |
5014 if (coverage != NULL) | |
5015 { | |
5016 uc = (cjk_langs[i][0] == 'k') ? 0xAC00 : 0x4E00; | |
5017 is_cjk = (pango_coverage_get(coverage, uc) == PANGO_COVERAGE_EXACT); | |
5018 pango_coverage_unref(coverage); | |
5019 } | |
5020 } | |
5021 | |
5022 g_object_unref(font); | |
5023 | |
5024 return is_cjk; | |
5025 } | |
5026 | |
445 | 5027 /* |
5028 * Adjust gui.char_height (after 'linespace' was changed). | |
5029 */ | |
7 | 5030 int |
445 | 5031 gui_mch_adjust_charheight(void) |
7 | 5032 { |
5033 PangoFontMetrics *metrics; | |
5034 int ascent; | |
5035 int descent; | |
5036 | |
5037 metrics = pango_context_get_metrics(gui.text_context, gui.norm_font, | |
5038 pango_context_get_language(gui.text_context)); | |
5039 ascent = pango_font_metrics_get_ascent(metrics); | |
5040 descent = pango_font_metrics_get_descent(metrics); | |
5041 | |
5042 pango_font_metrics_unref(metrics); | |
5043 | |
5044 gui.char_height = (ascent + descent + PANGO_SCALE - 1) / PANGO_SCALE | |
445 | 5045 + p_linespace; |
136 | 5046 /* LINTED: avoid warning: bitwise operation on signed value */ |
7 | 5047 gui.char_ascent = PANGO_PIXELS(ascent + p_linespace * PANGO_SCALE / 2); |
5048 | |
5049 /* A not-positive value of char_height may crash Vim. Only happens | |
5050 * if 'linespace' is negative (which does make sense sometimes). */ | |
5051 gui.char_ascent = MAX(gui.char_ascent, 0); | |
5052 gui.char_height = MAX(gui.char_height, gui.char_ascent + 1); | |
5053 | |
5054 return OK; | |
5055 } | |
5056 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5057 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5058 /* Callback function used in gui_mch_font_dialog() */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5059 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5060 font_filter(const PangoFontFamily *family, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5061 const PangoFontFace *face UNUSED, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5062 gpointer data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5063 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5064 return pango_font_family_is_monospace((PangoFontFamily *)family); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5065 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5066 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5067 |
7 | 5068 /* |
5069 * Put up a font dialog and return the selected font name in allocated memory. | |
5070 * "oldval" is the previous value. Return NULL when cancelled. | |
5071 * This should probably go into gui_gtk.c. Hmm. | |
5072 * FIXME: | |
5073 * The GTK2 font selection dialog has no filtering API. So we could either | |
5074 * a) implement our own (possibly copying the code from somewhere else) or | |
5075 * b) just live with it. | |
5076 */ | |
5077 char_u * | |
5078 gui_mch_font_dialog(char_u *oldval) | |
5079 { | |
5080 GtkWidget *dialog; | |
5081 int response; | |
5082 char_u *fontname = NULL; | |
5083 char_u *oldname; | |
5084 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5085 #if GTK_CHECK_VERSION(3,2,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5086 dialog = gtk_font_chooser_dialog_new(NULL, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5087 gtk_font_chooser_set_filter_func(GTK_FONT_CHOOSER(dialog), font_filter, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5088 NULL, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5089 #else |
7 | 5090 dialog = gtk_font_selection_dialog_new(NULL); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5091 #endif |
7 | 5092 |
5093 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gui.mainwin)); | |
5094 gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE); | |
5095 | |
5096 if (oldval != NULL && oldval[0] != NUL) | |
5097 { | |
5098 if (output_conv.vc_type != CONV_NONE) | |
5099 oldname = string_convert(&output_conv, oldval, NULL); | |
5100 else | |
5101 oldname = oldval; | |
5102 | |
5103 /* Annoying bug in GTK (or Pango): if the font name does not include a | |
5104 * size, zero is used. Use default point size ten. */ | |
5105 if (!vim_isdigit(oldname[STRLEN(oldname) - 1])) | |
5106 { | |
5107 char_u *p = vim_strnsave(oldname, STRLEN(oldname) + 3); | |
5108 | |
5109 if (p != NULL) | |
5110 { | |
5111 STRCPY(p + STRLEN(p), " 10"); | |
5112 if (oldname != oldval) | |
5113 vim_free(oldname); | |
5114 oldname = p; | |
5115 } | |
5116 } | |
5117 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5118 #if GTK_CHECK_VERSION(3,2,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5119 gtk_font_chooser_set_font( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5120 GTK_FONT_CHOOSER(dialog), (const gchar *)oldname); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5121 #else |
7 | 5122 gtk_font_selection_dialog_set_font_name( |
5123 GTK_FONT_SELECTION_DIALOG(dialog), (const char *)oldname); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5124 #endif |
7 | 5125 |
5126 if (oldname != oldval) | |
100 | 5127 vim_free(oldname); |
7 | 5128 } |
1959 | 5129 else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5130 #if GTK_CHECK_VERSION(3,2,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5131 gtk_font_chooser_set_font( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5132 GTK_FONT_CHOOSER(dialog), DEFAULT_FONT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5133 #else |
1959 | 5134 gtk_font_selection_dialog_set_font_name( |
5135 GTK_FONT_SELECTION_DIALOG(dialog), DEFAULT_FONT); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5136 #endif |
7 | 5137 |
5138 response = gtk_dialog_run(GTK_DIALOG(dialog)); | |
5139 | |
5140 if (response == GTK_RESPONSE_OK) | |
5141 { | |
5142 char *name; | |
5143 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5144 #if GTK_CHECK_VERSION(3,2,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5145 name = gtk_font_chooser_get_font(GTK_FONT_CHOOSER(dialog)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5146 #else |
7 | 5147 name = gtk_font_selection_dialog_get_font_name( |
5148 GTK_FONT_SELECTION_DIALOG(dialog)); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5149 #endif |
7 | 5150 if (name != NULL) |
5151 { | |
714 | 5152 char_u *p; |
5153 | |
5154 /* Apparently some font names include a comma, need to escape | |
5155 * that, because in 'guifont' it separates names. */ | |
5156 p = vim_strsave_escaped((char_u *)name, (char_u *)","); | |
5157 g_free(name); | |
840 | 5158 if (p != NULL && input_conv.vc_type != CONV_NONE) |
714 | 5159 { |
5160 fontname = string_convert(&input_conv, p, NULL); | |
5161 vim_free(p); | |
5162 } | |
7 | 5163 else |
714 | 5164 fontname = p; |
7 | 5165 } |
5166 } | |
5167 | |
5168 if (response != GTK_RESPONSE_NONE) | |
5169 gtk_widget_destroy(dialog); | |
5170 | |
5171 return fontname; | |
5172 } | |
5173 | |
5174 /* | |
5175 * Some monospace fonts don't support a bold weight, and fall back | |
5176 * silently to the regular weight. But this is no good since our text | |
5177 * drawing function can emulate bold by overstriking. So let's try | |
5178 * to detect whether bold weight is actually available and emulate it | |
5179 * otherwise. | |
5180 * | |
5181 * Note that we don't need to check for italic style since Xft can | |
5182 * emulate italic on its own, provided you have a proper fontconfig | |
5183 * setup. We wouldn't be able to emulate it in Vim anyway. | |
5184 */ | |
5185 static void | |
5186 get_styled_font_variants(void) | |
5187 { | |
5188 PangoFontDescription *bold_font_desc; | |
5189 PangoFont *plain_font; | |
5190 PangoFont *bold_font; | |
5191 | |
5192 gui.font_can_bold = FALSE; | |
5193 | |
5194 plain_font = pango_context_load_font(gui.text_context, gui.norm_font); | |
5195 | |
5196 if (plain_font == NULL) | |
5197 return; | |
5198 | |
5199 bold_font_desc = pango_font_description_copy_static(gui.norm_font); | |
5200 pango_font_description_set_weight(bold_font_desc, PANGO_WEIGHT_BOLD); | |
5201 | |
5202 bold_font = pango_context_load_font(gui.text_context, bold_font_desc); | |
5203 /* | |
5204 * The comparison relies on the unique handle nature of a PangoFont*, | |
5205 * i.e. it's assumed that a different PangoFont* won't refer to the | |
5206 * same font. Seems to work, and failing here isn't critical anyway. | |
5207 */ | |
5208 if (bold_font != NULL) | |
5209 { | |
5210 gui.font_can_bold = (bold_font != plain_font); | |
5211 g_object_unref(bold_font); | |
5212 } | |
5213 | |
5214 pango_font_description_free(bold_font_desc); | |
5215 g_object_unref(plain_font); | |
5216 } | |
5217 | |
5218 static PangoEngineShape *default_shape_engine = NULL; | |
5219 | |
5220 /* | |
5221 * Create a map from ASCII characters in the range [32,126] to glyphs | |
5222 * of the current font. This is used by gui_gtk2_draw_string() to skip | |
5223 * the itemize and shaping process for the most common case. | |
5224 */ | |
5225 static void | |
5226 ascii_glyph_table_init(void) | |
5227 { | |
5228 char_u ascii_chars[128]; | |
5229 PangoAttrList *attr_list; | |
5230 GList *item_list; | |
5231 int i; | |
5232 | |
5233 if (gui.ascii_glyphs != NULL) | |
5234 pango_glyph_string_free(gui.ascii_glyphs); | |
5235 if (gui.ascii_font != NULL) | |
5236 g_object_unref(gui.ascii_font); | |
5237 | |
5238 gui.ascii_glyphs = NULL; | |
5239 gui.ascii_font = NULL; | |
5240 | |
5241 /* For safety, fill in question marks for the control characters. */ | |
5242 for (i = 0; i < 32; ++i) | |
5243 ascii_chars[i] = '?'; | |
5244 for (; i < 127; ++i) | |
5245 ascii_chars[i] = i; | |
5246 ascii_chars[i] = '?'; | |
5247 | |
5248 attr_list = pango_attr_list_new(); | |
5249 item_list = pango_itemize(gui.text_context, (const char *)ascii_chars, | |
5250 0, sizeof(ascii_chars), attr_list, NULL); | |
5251 | |
5252 if (item_list != NULL && item_list->next == NULL) /* play safe */ | |
5253 { | |
5254 PangoItem *item; | |
5255 int width; | |
5256 | |
5257 item = (PangoItem *)item_list->data; | |
5258 width = gui.char_width * PANGO_SCALE; | |
5259 | |
5260 /* Remember the shape engine used for ASCII. */ | |
5261 default_shape_engine = item->analysis.shape_engine; | |
5262 | |
5263 gui.ascii_font = item->analysis.font; | |
5264 g_object_ref(gui.ascii_font); | |
5265 | |
5266 gui.ascii_glyphs = pango_glyph_string_new(); | |
5267 | |
5268 pango_shape((const char *)ascii_chars, sizeof(ascii_chars), | |
5269 &item->analysis, gui.ascii_glyphs); | |
5270 | |
5271 g_return_if_fail(gui.ascii_glyphs->num_glyphs == sizeof(ascii_chars)); | |
5272 | |
5273 for (i = 0; i < gui.ascii_glyphs->num_glyphs; ++i) | |
5274 { | |
5275 PangoGlyphGeometry *geom; | |
5276 | |
5277 geom = &gui.ascii_glyphs->glyphs[i].geometry; | |
5278 geom->x_offset += MAX(0, width - geom->width) / 2; | |
5279 geom->width = width; | |
5280 } | |
5281 } | |
5282 | |
5283 g_list_foreach(item_list, (GFunc)&pango_item_free, NULL); | |
5284 g_list_free(item_list); | |
5285 pango_attr_list_unref(attr_list); | |
5286 } | |
5287 | |
5288 /* | |
5289 * Initialize Vim to use the font or fontset with the given name. | |
5290 * Return FAIL if the font could not be loaded, OK otherwise. | |
5291 */ | |
5292 int | |
1884 | 5293 gui_mch_init_font(char_u *font_name, int fontset UNUSED) |
7 | 5294 { |
5295 PangoFontDescription *font_desc; | |
5296 PangoLayout *layout; | |
5297 int width; | |
5298 | |
5299 /* If font_name is NULL, this means to use the default, which should | |
5300 * be present on all proper Pango/fontconfig installations. */ | |
5301 if (font_name == NULL) | |
5302 font_name = (char_u *)DEFAULT_FONT; | |
5303 | |
5304 font_desc = gui_mch_get_font(font_name, FALSE); | |
5305 | |
5306 if (font_desc == NULL) | |
5307 return FAIL; | |
5308 | |
5309 gui_mch_free_font(gui.norm_font); | |
5310 gui.norm_font = font_desc; | |
5311 | |
5312 pango_context_set_font_description(gui.text_context, font_desc); | |
5313 | |
5314 layout = pango_layout_new(gui.text_context); | |
5315 pango_layout_set_text(layout, "MW", 2); | |
5316 pango_layout_get_size(layout, &width, NULL); | |
5317 /* | |
5318 * Set char_width to half the width obtained from pango_layout_get_size() | |
5319 * for CJK fixed_width/bi-width fonts. An unpatched version of Xft leads | |
5320 * Pango to use the same width for both non-CJK characters (e.g. Latin | |
5321 * letters and numbers) and CJK characters. This results in 's p a c e d | |
5322 * o u t' rendering when a CJK 'fixed width' font is used. To work around | |
5323 * that, divide the width returned by Pango by 2 if cjk_width is equal to | |
5324 * width for CJK fonts. | |
5325 * | |
5326 * For related bugs, see: | |
5327 * http://bugzilla.gnome.org/show_bug.cgi?id=106618 | |
5328 * http://bugzilla.gnome.org/show_bug.cgi?id=106624 | |
5329 * | |
5330 * With this, for all four of the following cases, Vim works fine: | |
5331 * guifont=CJK_fixed_width_font | |
5332 * guifont=Non_CJK_fixed_font | |
5333 * guifont=Non_CJK_fixed_font,CJK_Fixed_font | |
5334 * guifont=Non_CJK_fixed_font guifontwide=CJK_fixed_font | |
5335 */ | |
5336 if (is_cjk_font(gui.norm_font)) | |
5337 { | |
5338 int cjk_width; | |
5339 | |
5340 /* Measure the text extent of U+4E00 and U+4E8C */ | |
5341 pango_layout_set_text(layout, "\344\270\200\344\272\214", -1); | |
5342 pango_layout_get_size(layout, &cjk_width, NULL); | |
5343 | |
5344 if (width == cjk_width) /* Xft not patched */ | |
5345 width /= 2; | |
5346 } | |
5347 g_object_unref(layout); | |
5348 | |
5349 gui.char_width = (width / 2 + PANGO_SCALE - 1) / PANGO_SCALE; | |
5350 | |
5351 /* A zero width may cause a crash. Happens for semi-invalid fontsets. */ | |
5352 if (gui.char_width <= 0) | |
5353 gui.char_width = 8; | |
5354 | |
445 | 5355 gui_mch_adjust_charheight(); |
7 | 5356 |
5357 /* Set the fontname, which will be used for information purposes */ | |
5358 hl_set_font_name(font_name); | |
5359 | |
5360 get_styled_font_variants(); | |
5361 ascii_glyph_table_init(); | |
5362 | |
5363 /* Avoid unnecessary overhead if 'guifontwide' is equal to 'guifont'. */ | |
5364 if (gui.wide_font != NULL | |
5365 && pango_font_description_equal(gui.norm_font, gui.wide_font)) | |
5366 { | |
5367 pango_font_description_free(gui.wide_font); | |
5368 gui.wide_font = NULL; | |
5369 } | |
5370 | |
1986 | 5371 if (gui_mch_maximized()) |
5372 { | |
5373 /* Update lines and columns in accordance with the new font, keep the | |
5374 * window maximized. */ | |
3014 | 5375 gui_mch_newfont(); |
1986 | 5376 } |
5377 else | |
5378 { | |
5379 /* Preserve the logical dimensions of the screen. */ | |
5380 update_window_manager_hints(0, 0); | |
5381 } | |
7 | 5382 |
5383 return OK; | |
5384 } | |
5385 | |
5386 /* | |
5387 * Get a reference to the font "name". | |
5388 * Return zero for failure. | |
5389 */ | |
5390 GuiFont | |
5391 gui_mch_get_font(char_u *name, int report_error) | |
5392 { | |
5393 PangoFontDescription *font; | |
5394 | |
5395 /* can't do this when GUI is not running */ | |
5396 if (!gui.in_use || name == NULL) | |
5397 return NULL; | |
5398 | |
5399 if (output_conv.vc_type != CONV_NONE) | |
5400 { | |
5401 char_u *buf; | |
5402 | |
5403 buf = string_convert(&output_conv, name, NULL); | |
5404 if (buf != NULL) | |
5405 { | |
5406 font = pango_font_description_from_string((const char *)buf); | |
5407 vim_free(buf); | |
5408 } | |
5409 else | |
5410 font = NULL; | |
5411 } | |
5412 else | |
5413 font = pango_font_description_from_string((const char *)name); | |
5414 | |
5415 if (font != NULL) | |
5416 { | |
5417 PangoFont *real_font; | |
5418 | |
5419 /* pango_context_load_font() bails out if no font size is set */ | |
5420 if (pango_font_description_get_size(font) <= 0) | |
5421 pango_font_description_set_size(font, 10 * PANGO_SCALE); | |
5422 | |
5423 real_font = pango_context_load_font(gui.text_context, font); | |
5424 | |
5425 if (real_font == NULL) | |
5426 { | |
5427 pango_font_description_free(font); | |
5428 font = NULL; | |
5429 } | |
5430 else | |
5431 g_object_unref(real_font); | |
5432 } | |
5433 | |
5434 if (font == NULL) | |
5435 { | |
5436 if (report_error) | |
1666 | 5437 EMSG2(_((char *)e_font), name); |
7 | 5438 return NULL; |
5439 } | |
5440 | |
5441 return font; | |
5442 } | |
5443 | |
39 | 5444 #if defined(FEAT_EVAL) || defined(PROTO) |
38 | 5445 /* |
5446 * Return the name of font "font" in allocated memory. | |
5447 */ | |
5448 char_u * | |
1884 | 5449 gui_mch_get_fontname(GuiFont font, char_u *name UNUSED) |
38 | 5450 { |
5451 if (font != NOFONT) | |
5452 { | |
944 | 5453 char *pangoname = pango_font_description_to_string(font); |
5454 | |
5455 if (pangoname != NULL) | |
38 | 5456 { |
944 | 5457 char_u *s = vim_strsave((char_u *)pangoname); |
5458 | |
5459 g_free(pangoname); | |
38 | 5460 return s; |
5461 } | |
5462 } | |
5463 return NULL; | |
5464 } | |
39 | 5465 #endif |
38 | 5466 |
7 | 5467 /* |
5468 * If a font is not going to be used, free its structure. | |
5469 */ | |
5470 void | |
5471 gui_mch_free_font(GuiFont font) | |
5472 { | |
5473 if (font != NOFONT) | |
5474 pango_font_description_free(font); | |
5475 } | |
5476 | |
5477 /* | |
5478 * Return the Pixel value (color) for the given color name. This routine was | |
5479 * pretty much taken from example code in the Silicon Graphics OSF/Motif | |
5480 * Programmer's Guide. | |
5481 * Return INVALCOLOR for error. | |
5482 */ | |
5483 guicolor_T | |
5484 gui_mch_get_color(char_u *name) | |
5485 { | |
5486 /* A number of colors that some X11 systems don't have */ | |
5487 static const char *const vimnames[][2] = | |
5488 { | |
834 | 5489 {"LightRed", "#FFBBBB"}, |
5490 {"LightGreen", "#88FF88"}, | |
5491 {"LightMagenta","#FFBBFF"}, | |
5492 {"DarkCyan", "#008888"}, | |
5493 {"DarkBlue", "#0000BB"}, | |
5494 {"DarkRed", "#BB0000"}, | |
5495 {"DarkMagenta", "#BB00BB"}, | |
5496 {"DarkGrey", "#BBBBBB"}, | |
5497 {"DarkYellow", "#BBBB00"}, | |
5498 {"Gray10", "#1A1A1A"}, | |
5499 {"Grey10", "#1A1A1A"}, | |
5500 {"Gray20", "#333333"}, | |
5501 {"Grey20", "#333333"}, | |
5502 {"Gray30", "#4D4D4D"}, | |
5503 {"Grey30", "#4D4D4D"}, | |
5504 {"Gray40", "#666666"}, | |
5505 {"Grey40", "#666666"}, | |
5506 {"Gray50", "#7F7F7F"}, | |
5507 {"Grey50", "#7F7F7F"}, | |
5508 {"Gray60", "#999999"}, | |
5509 {"Grey60", "#999999"}, | |
5510 {"Gray70", "#B3B3B3"}, | |
5511 {"Grey70", "#B3B3B3"}, | |
5512 {"Gray80", "#CCCCCC"}, | |
5513 {"Grey80", "#CCCCCC"}, | |
5514 {"Gray90", "#E5E5E5"}, | |
5515 {"Grey90", "#E5E5E5"}, | |
7 | 5516 {NULL, NULL} |
5517 }; | |
5518 | |
5519 if (!gui.in_use) /* can't do this when GUI not running */ | |
5520 return INVALCOLOR; | |
5521 | |
5522 while (name != NULL) | |
5523 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5524 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5525 GdkRGBA color; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5526 #else |
7 | 5527 GdkColor color; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5528 #endif |
7 | 5529 int parsed; |
5530 int i; | |
5531 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5532 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5533 parsed = gdk_rgba_parse(&color, (const gchar *)name); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5534 #else |
7 | 5535 parsed = gdk_color_parse((const char *)name, &color); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5536 #endif |
7 | 5537 |
5538 if (parsed) | |
5539 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5540 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5541 return (guicolor_T)gui_gtk_get_pixel_from_rgb(&color); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5542 #else |
7 | 5543 gdk_colormap_alloc_color(gtk_widget_get_colormap(gui.drawarea), |
5544 &color, FALSE, TRUE); | |
5545 return (guicolor_T)color.pixel; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5546 #endif |
7 | 5547 } |
5548 /* add a few builtin names and try again */ | |
5549 for (i = 0; ; ++i) | |
5550 { | |
5551 if (vimnames[i][0] == NULL) | |
5552 { | |
5553 name = NULL; | |
5554 break; | |
5555 } | |
5556 if (STRICMP(name, vimnames[i][0]) == 0) | |
5557 { | |
5558 name = (char_u *)vimnames[i][1]; | |
5559 break; | |
5560 } | |
5561 } | |
5562 } | |
5563 | |
5564 return INVALCOLOR; | |
5565 } | |
5566 | |
5567 /* | |
5568 * Set the current text foreground color. | |
5569 */ | |
5570 void | |
5571 gui_mch_set_fg_color(guicolor_T color) | |
5572 { | |
5573 gui.fgcolor->pixel = (unsigned long)color; | |
5574 } | |
5575 | |
5576 /* | |
5577 * Set the current text background color. | |
5578 */ | |
5579 void | |
5580 gui_mch_set_bg_color(guicolor_T color) | |
5581 { | |
5582 gui.bgcolor->pixel = (unsigned long)color; | |
5583 } | |
5584 | |
207 | 5585 /* |
5586 * Set the current text special color. | |
5587 */ | |
5588 void | |
5589 gui_mch_set_sp_color(guicolor_T color) | |
5590 { | |
5591 gui.spcolor->pixel = (unsigned long)color; | |
5592 } | |
5593 | |
7 | 5594 /* |
5595 * Function-like convenience macro for the sake of efficiency. | |
5596 */ | |
5597 #define INSERT_PANGO_ATTR(Attribute, AttrList, Start, End) \ | |
5598 G_STMT_START{ \ | |
5599 PangoAttribute *tmp_attr_; \ | |
5600 tmp_attr_ = (Attribute); \ | |
5601 tmp_attr_->start_index = (Start); \ | |
5602 tmp_attr_->end_index = (End); \ | |
5603 pango_attr_list_insert((AttrList), tmp_attr_); \ | |
5604 }G_STMT_END | |
5605 | |
5606 static void | |
5607 apply_wide_font_attr(char_u *s, int len, PangoAttrList *attr_list) | |
5608 { | |
5609 char_u *start = NULL; | |
5610 char_u *p; | |
5611 int uc; | |
5612 | |
5613 for (p = s; p < s + len; p += utf_byte2len(*p)) | |
5614 { | |
5615 uc = utf_ptr2char(p); | |
5616 | |
5617 if (start == NULL) | |
5618 { | |
5619 if (uc >= 0x80 && utf_char2cells(uc) == 2) | |
5620 start = p; | |
5621 } | |
5622 else if (uc < 0x80 /* optimization shortcut */ | |
5623 || (utf_char2cells(uc) != 2 && !utf_iscomposing(uc))) | |
5624 { | |
5625 INSERT_PANGO_ATTR(pango_attr_font_desc_new(gui.wide_font), | |
5626 attr_list, start - s, p - s); | |
5627 start = NULL; | |
5628 } | |
5629 } | |
5630 | |
5631 if (start != NULL) | |
5632 INSERT_PANGO_ATTR(pango_attr_font_desc_new(gui.wide_font), | |
5633 attr_list, start - s, len); | |
5634 } | |
5635 | |
5636 static int | |
5637 count_cluster_cells(char_u *s, PangoItem *item, | |
5638 PangoGlyphString* glyphs, int i, | |
5639 int *cluster_width, | |
5640 int *last_glyph_rbearing) | |
5641 { | |
5642 char_u *p; | |
5643 int next; /* glyph start index of next cluster */ | |
5644 int start, end; /* string segment of current cluster */ | |
5645 int width; /* real cluster width in Pango units */ | |
5646 int uc; | |
5647 int cellcount = 0; | |
5648 | |
5649 width = glyphs->glyphs[i].geometry.width; | |
5650 | |
5651 for (next = i + 1; next < glyphs->num_glyphs; ++next) | |
5652 { | |
5653 if (glyphs->glyphs[next].attr.is_cluster_start) | |
5654 break; | |
5655 else if (glyphs->glyphs[next].geometry.width > width) | |
5656 width = glyphs->glyphs[next].geometry.width; | |
5657 } | |
5658 | |
5659 start = item->offset + glyphs->log_clusters[i]; | |
5660 end = item->offset + ((next < glyphs->num_glyphs) ? | |
5661 glyphs->log_clusters[next] : item->length); | |
5662 | |
5663 for (p = s + start; p < s + end; p += utf_byte2len(*p)) | |
5664 { | |
5665 uc = utf_ptr2char(p); | |
5666 if (uc < 0x80) | |
5667 ++cellcount; | |
5668 else if (!utf_iscomposing(uc)) | |
5669 cellcount += utf_char2cells(uc); | |
5670 } | |
5671 | |
5672 if (last_glyph_rbearing != NULL | |
5673 && cellcount > 0 && next == glyphs->num_glyphs) | |
5674 { | |
5675 PangoRectangle ink_rect; | |
5676 /* | |
5677 * If a certain combining mark had to be taken from a non-monospace | |
5678 * font, we have to compensate manually by adapting x_offset according | |
5679 * to the ink extents of the previous glyph. | |
5680 */ | |
5681 pango_font_get_glyph_extents(item->analysis.font, | |
5682 glyphs->glyphs[i].glyph, | |
5683 &ink_rect, NULL); | |
5684 | |
5685 if (PANGO_RBEARING(ink_rect) > 0) | |
5686 *last_glyph_rbearing = PANGO_RBEARING(ink_rect); | |
5687 } | |
5688 | |
5689 if (cellcount > 0) | |
5690 *cluster_width = width; | |
5691 | |
5692 return cellcount; | |
5693 } | |
5694 | |
5695 /* | |
5696 * If there are only combining characters in the cluster, we cannot just | |
5697 * change the width of the previous glyph since there is none. Therefore | |
5698 * some guesswork is needed. | |
5699 * | |
5700 * If ink_rect.x is negative Pango apparently has taken care of the composing | |
5701 * by itself. Actually setting x_offset = 0 should be sufficient then, but due | |
5702 * 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
|
5703 * x_offset to avoid ugliness. |
7 | 5704 * |
5705 * If ink_rect.x is not negative, force overstriking by pointing x_offset to | |
5706 * the position of the previous glyph. Apparently this happens only with old | |
5707 * X fonts which don't provide the special combining information needed by | |
5708 * Pango. | |
5709 */ | |
5710 static void | |
5711 setup_zero_width_cluster(PangoItem *item, PangoGlyphInfo *glyph, | |
5712 int last_cellcount, int last_cluster_width, | |
5713 int last_glyph_rbearing) | |
5714 { | |
5715 PangoRectangle ink_rect; | |
5716 PangoRectangle logical_rect; | |
5717 int width; | |
5718 | |
5719 width = last_cellcount * gui.char_width * PANGO_SCALE; | |
5720 glyph->geometry.x_offset = -width + MAX(0, width - last_cluster_width) / 2; | |
5721 glyph->geometry.width = 0; | |
5722 | |
5723 pango_font_get_glyph_extents(item->analysis.font, | |
5724 glyph->glyph, | |
5725 &ink_rect, &logical_rect); | |
5726 if (ink_rect.x < 0) | |
5727 { | |
5728 glyph->geometry.x_offset += last_glyph_rbearing; | |
5729 glyph->geometry.y_offset = logical_rect.height | |
5730 - (gui.char_height - p_linespace) * PANGO_SCALE; | |
5731 } | |
2507
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
5732 else |
2070b63605a7
Fix: with newer GTK versions accented characters were drawn too much to the
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
5733 /* 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
|
5734 * 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
|
5735 glyph->geometry.x_offset = -width + MAX(0, width - ink_rect.width) / 2; |
7 | 5736 } |
5737 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5738 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5739 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5740 draw_glyph_string(int row, int col, int num_cells, int flags, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5741 PangoFont *font, PangoGlyphString *glyphs, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5742 cairo_t *cr) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5743 #else |
7 | 5744 static void |
5745 draw_glyph_string(int row, int col, int num_cells, int flags, | |
5746 PangoFont *font, PangoGlyphString *glyphs) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5747 #endif |
7 | 5748 { |
5749 if (!(flags & DRAW_TRANSP)) | |
5750 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5751 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5752 set_cairo_source_rgb_from_pixel(cr, gui.bgcolor->pixel); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5753 cairo_rectangle(cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5754 FILL_X(col), FILL_Y(row), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5755 num_cells * gui.char_width, gui.char_height); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5756 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5757 #else |
7 | 5758 gdk_gc_set_foreground(gui.text_gc, gui.bgcolor); |
5759 | |
5760 gdk_draw_rectangle(gui.drawarea->window, | |
5761 gui.text_gc, | |
5762 TRUE, | |
5763 FILL_X(col), | |
5764 FILL_Y(row), | |
5765 num_cells * gui.char_width, | |
5766 gui.char_height); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5767 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5768 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5769 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5770 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5771 set_cairo_source_rgb_from_pixel(cr, gui.fgcolor->pixel); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5772 cairo_move_to(cr, TEXT_X(col), TEXT_Y(row)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5773 pango_cairo_show_glyph_string(cr, font, glyphs); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5774 #else |
7 | 5775 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
5776 | |
5777 gdk_draw_glyphs(gui.drawarea->window, | |
5778 gui.text_gc, | |
5779 font, | |
5780 TEXT_X(col), | |
5781 TEXT_Y(row), | |
5782 glyphs); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5783 #endif |
7 | 5784 |
5785 /* redraw the contents with an offset of 1 to emulate bold */ | |
5786 if ((flags & DRAW_BOLD) && !gui.font_can_bold) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5787 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5788 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5789 set_cairo_source_rgb_from_pixel(cr, gui.fgcolor->pixel); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5790 cairo_move_to(cr, TEXT_X(col) + 1, TEXT_Y(row)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5791 pango_cairo_show_glyph_string(cr, font, glyphs); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5792 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5793 #else |
7 | 5794 gdk_draw_glyphs(gui.drawarea->window, |
5795 gui.text_gc, | |
5796 font, | |
5797 TEXT_X(col) + 1, | |
5798 TEXT_Y(row), | |
5799 glyphs); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5800 #endif |
7 | 5801 } |
5802 | |
207 | 5803 /* |
5804 * Draw underline and undercurl at the bottom of the character cell. | |
5805 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5806 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5807 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5808 draw_under(int flags, int row, int col, int cells, cairo_t *cr) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5809 #else |
207 | 5810 static void |
5811 draw_under(int flags, int row, int col, int cells) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5812 #endif |
207 | 5813 { |
5814 int i; | |
5815 int offset; | |
1884 | 5816 static const int val[8] = {1, 0, 0, 0, 1, 2, 2, 2 }; |
207 | 5817 int y = FILL_Y(row + 1) - 1; |
5818 | |
5819 /* Undercurl: draw curl at the bottom of the character cell. */ | |
5820 if (flags & DRAW_UNDERC) | |
5821 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5822 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5823 cairo_set_line_width(cr, 1.0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5824 cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5825 set_cairo_source_rgb_from_pixel(cr, gui.spcolor->pixel); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5826 for (i = FILL_X(col); i < FILL_X(col + cells); ++i) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5827 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5828 offset = val[i % 8]; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5829 cairo_line_to(cr, i, y - offset + 0.5); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5830 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5831 cairo_stroke(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5832 #else |
207 | 5833 gdk_gc_set_foreground(gui.text_gc, gui.spcolor); |
5834 for (i = FILL_X(col); i < FILL_X(col + cells); ++i) | |
5835 { | |
5836 offset = val[i % 8]; | |
5837 gdk_draw_point(gui.drawarea->window, gui.text_gc, i, y - offset); | |
5838 } | |
5839 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5840 #endif |
207 | 5841 } |
5842 | |
5843 /* Underline: draw a line at the bottom of the character cell. */ | |
5844 if (flags & DRAW_UNDERL) | |
5845 { | |
5846 /* When p_linespace is 0, overwrite the bottom row of pixels. | |
5847 * Otherwise put the line just below the character. */ | |
5848 if (p_linespace > 1) | |
5849 y -= p_linespace - 1; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5850 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5851 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5852 cairo_set_line_width(cr, 1.0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5853 cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5854 set_cairo_source_rgb_from_pixel(cr, gui.fgcolor->pixel); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5855 cairo_move_to(cr, FILL_X(col), y + 0.5); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5856 cairo_line_to(cr, FILL_X(col + cells), y + 0.5); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5857 cairo_stroke(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5858 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5859 #else |
207 | 5860 gdk_draw_line(gui.drawarea->window, gui.text_gc, |
5861 FILL_X(col), y, | |
5862 FILL_X(col + cells) - 1, y); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5863 #endif |
207 | 5864 } |
5865 } | |
5866 | |
7 | 5867 int |
5868 gui_gtk2_draw_string(int row, int col, char_u *s, int len, int flags) | |
5869 { | |
5870 GdkRectangle area; /* area for clip mask */ | |
5871 PangoGlyphString *glyphs; /* glyphs of current item */ | |
5872 int column_offset = 0; /* column offset in cells */ | |
5873 int i; | |
5874 char_u *conv_buf = NULL; /* result of UTF-8 conversion */ | |
5875 char_u *new_conv_buf; | |
5876 int convlen; | |
5877 char_u *sp, *bp; | |
5878 int plen; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5879 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5880 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5881 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5882 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5883 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5884 if (gui.text_context == NULL || gtk_widget_get_window(gui.drawarea) == NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5885 #else |
7 | 5886 if (gui.text_context == NULL || gui.drawarea->window == NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5887 #endif |
7 | 5888 return len; |
5889 | |
5890 if (output_conv.vc_type != CONV_NONE) | |
5891 { | |
5892 /* | |
5893 * Convert characters from 'encoding' to 'termencoding', which is set | |
5894 * to UTF-8 by gui_mch_init(). did_set_string_option() in option.c | |
5895 * prohibits changing this to something else than UTF-8 if the GUI is | |
5896 * in use. | |
5897 */ | |
5898 convlen = len; | |
5899 conv_buf = string_convert(&output_conv, s, &convlen); | |
5900 g_return_val_if_fail(conv_buf != NULL, len); | |
5901 | |
5902 /* Correct for differences in char width: some chars are | |
5903 * double-wide in 'encoding' but single-wide in utf-8. Add a space to | |
5904 * compensate for that. */ | |
5905 for (sp = s, bp = conv_buf; sp < s + len && bp < conv_buf + convlen; ) | |
5906 { | |
474 | 5907 plen = utf_ptr2len(bp); |
7 | 5908 if ((*mb_ptr2cells)(sp) == 2 && utf_ptr2cells(bp) == 1) |
5909 { | |
5910 new_conv_buf = alloc(convlen + 2); | |
5911 if (new_conv_buf == NULL) | |
5912 return len; | |
5913 plen += bp - conv_buf; | |
5914 mch_memmove(new_conv_buf, conv_buf, plen); | |
5915 new_conv_buf[plen] = ' '; | |
5916 mch_memmove(new_conv_buf + plen + 1, conv_buf + plen, | |
5917 convlen - plen + 1); | |
5918 vim_free(conv_buf); | |
5919 conv_buf = new_conv_buf; | |
5920 ++convlen; | |
5921 bp = conv_buf + plen; | |
5922 plen = 1; | |
5923 } | |
474 | 5924 sp += (*mb_ptr2len)(sp); |
7 | 5925 bp += plen; |
5926 } | |
5927 s = conv_buf; | |
5928 len = convlen; | |
5929 } | |
5930 | |
5931 /* | |
5932 * Restrict all drawing to the current screen line in order to prevent | |
5933 * fuzzy font lookups from messing up the screen. | |
5934 */ | |
5935 area.x = gui.border_offset; | |
5936 area.y = FILL_Y(row); | |
5937 area.width = gui.num_cols * gui.char_width; | |
5938 area.height = gui.char_height; | |
5939 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5940 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5941 cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5942 cairo_rectangle(cr, area.x, area.y, area.width, area.height); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5943 cairo_clip(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5944 #else |
7 | 5945 gdk_gc_set_clip_origin(gui.text_gc, 0, 0); |
5946 gdk_gc_set_clip_rectangle(gui.text_gc, &area); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5947 #endif |
7 | 5948 |
5949 glyphs = pango_glyph_string_new(); | |
5950 | |
5951 /* | |
5952 * Optimization hack: If possible, skip the itemize and shaping process | |
5953 * for pure ASCII strings. This optimization is particularly effective | |
5954 * because Vim draws space characters to clear parts of the screen. | |
5955 */ | |
5956 if (!(flags & DRAW_ITALIC) | |
5957 && !((flags & DRAW_BOLD) && gui.font_can_bold) | |
5958 && gui.ascii_glyphs != NULL) | |
5959 { | |
5960 char_u *p; | |
5961 | |
5962 for (p = s; p < s + len; ++p) | |
5963 if (*p & 0x80) | |
5964 goto not_ascii; | |
5965 | |
5966 pango_glyph_string_set_size(glyphs, len); | |
5967 | |
5968 for (i = 0; i < len; ++i) | |
5969 { | |
5970 glyphs->glyphs[i] = gui.ascii_glyphs->glyphs[s[i]]; | |
5971 glyphs->log_clusters[i] = i; | |
5972 } | |
5973 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5974 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5975 draw_glyph_string(row, col, len, flags, gui.ascii_font, glyphs, cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5976 #else |
7 | 5977 draw_glyph_string(row, col, len, flags, gui.ascii_font, glyphs); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
5978 #endif |
7 | 5979 |
5980 column_offset = len; | |
5981 } | |
5982 else | |
5983 not_ascii: | |
5984 { | |
5985 PangoAttrList *attr_list; | |
5986 GList *item_list; | |
5987 int cluster_width; | |
5988 int last_glyph_rbearing; | |
5989 int cells = 0; /* cells occupied by current cluster */ | |
5990 | |
26 | 5991 /* Safety check: pango crashes when invoked with invalid utf-8 |
5992 * characters. */ | |
5993 if (!utf_valid_string(s, s + len)) | |
5994 { | |
5995 column_offset = len; | |
5996 goto skipitall; | |
5997 } | |
5998 | |
7 | 5999 /* original width of the current cluster */ |
6000 cluster_width = PANGO_SCALE * gui.char_width; | |
6001 | |
6002 /* right bearing of the last non-composing glyph */ | |
6003 last_glyph_rbearing = PANGO_SCALE * gui.char_width; | |
6004 | |
6005 attr_list = pango_attr_list_new(); | |
6006 | |
6007 /* If 'guifontwide' is set then use that for double-width characters. | |
6008 * Otherwise just go with 'guifont' and let Pango do its thing. */ | |
6009 if (gui.wide_font != NULL) | |
6010 apply_wide_font_attr(s, len, attr_list); | |
6011 | |
6012 if ((flags & DRAW_BOLD) && gui.font_can_bold) | |
6013 INSERT_PANGO_ATTR(pango_attr_weight_new(PANGO_WEIGHT_BOLD), | |
6014 attr_list, 0, len); | |
6015 if (flags & DRAW_ITALIC) | |
6016 INSERT_PANGO_ATTR(pango_attr_style_new(PANGO_STYLE_ITALIC), | |
6017 attr_list, 0, len); | |
6018 /* | |
6019 * Break the text into segments with consistent directional level | |
6020 * and shaping engine. Pure Latin text needs only a single segment, | |
6021 * so there's no need to worry about the loop's efficiency. Better | |
6022 * try to optimize elsewhere, e.g. reducing exposes and stuff :) | |
6023 */ | |
6024 item_list = pango_itemize(gui.text_context, | |
6025 (const char *)s, 0, len, attr_list, NULL); | |
6026 | |
6027 while (item_list != NULL) | |
6028 { | |
6029 PangoItem *item; | |
6030 int item_cells = 0; /* item length in cells */ | |
6031 | |
6032 item = (PangoItem *)item_list->data; | |
6033 item_list = g_list_delete_link(item_list, item_list); | |
6034 /* | |
6035 * Increment the bidirectional embedding level by 1 if it is not | |
6036 * even. An odd number means the output will be RTL, but we don't | |
6037 * want that since Vim handles right-to-left text on its own. It | |
6038 * would probably be sufficient to just set level = 0, but you can | |
6039 * never know :) | |
6040 * | |
6041 * Unfortunately we can't take advantage of Pango's ability to | |
6042 * render both LTR and RTL at the same time. In order to support | |
6043 * that, Vim's main screen engine would have to make use of Pango | |
6044 * functionality. | |
6045 */ | |
6046 item->analysis.level = (item->analysis.level + 1) & (~1U); | |
6047 | |
6048 /* HACK: Overrule the shape engine, we don't want shaping to be | |
6049 * done, because drawing the cursor would change the display. */ | |
6050 item->analysis.shape_engine = default_shape_engine; | |
6051 | |
7098
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
6052 #ifdef HAVE_PANGO_SHAPE_FULL |
7086
3825da022231
commit https://github.com/vim/vim/commit/7e2ec008f5c5152205d0b8a7d88177b374225d8d
Christian Brabandt <cb@256bit.org>
parents:
6819
diff
changeset
|
6053 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
|
6054 (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
|
6055 #else |
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
6056 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
|
6057 &item->analysis, glyphs); |
70b56e5eccb2
commit https://github.com/vim/vim/commit/3cbe0c01ad71875bd662edb629f9e792a734f292
Christian Brabandt <cb@256bit.org>
parents:
7086
diff
changeset
|
6058 #endif |
7 | 6059 /* |
6060 * Fixed-width hack: iterate over the array and assign a fixed | |
6061 * width to each glyph, thus overriding the choice made by the | |
6062 * shaping engine. We use utf_char2cells() to determine the | |
6063 * number of cells needed. | |
6064 * | |
6065 * Also perform all kind of dark magic to get composing | |
6066 * characters right (and pretty too of course). | |
6067 */ | |
6068 for (i = 0; i < glyphs->num_glyphs; ++i) | |
6069 { | |
6070 PangoGlyphInfo *glyph; | |
6071 | |
6072 glyph = &glyphs->glyphs[i]; | |
6073 | |
6074 if (glyph->attr.is_cluster_start) | |
6075 { | |
6076 int cellcount; | |
6077 | |
6078 cellcount = count_cluster_cells( | |
6079 s, item, glyphs, i, &cluster_width, | |
6080 (item_list != NULL) ? &last_glyph_rbearing : NULL); | |
6081 | |
6082 if (cellcount > 0) | |
6083 { | |
6084 int width; | |
6085 | |
6086 width = cellcount * gui.char_width * PANGO_SCALE; | |
6087 glyph->geometry.x_offset += | |
6088 MAX(0, width - cluster_width) / 2; | |
6089 glyph->geometry.width = width; | |
6090 } | |
6091 else | |
6092 { | |
6093 /* If there are only combining characters in the | |
6094 * cluster, we cannot just change the width of the | |
6095 * previous glyph since there is none. Therefore | |
6096 * some guesswork is needed. */ | |
6097 setup_zero_width_cluster(item, glyph, cells, | |
6098 cluster_width, | |
6099 last_glyph_rbearing); | |
6100 } | |
6101 | |
6102 item_cells += cellcount; | |
6103 cells = cellcount; | |
6104 } | |
6105 else if (i > 0) | |
6106 { | |
6107 int width; | |
6108 | |
6109 /* 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
|
6110 * characters the canonical way. |
2517
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6111 * 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
|
6112 * 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
|
6113 * and set the previous width to zero. |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6114 * 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
|
6115 * 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
|
6116 * 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
|
6117 * 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
|
6118 * 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
|
6119 if (glyph->geometry.x_offset >= 0) |
2517
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6120 { |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6121 glyphs->glyphs[i].geometry.width = |
fe5709686d05
Improve positioning of combining characters in GTK.
Bram Moolenaar <bram@vim.org>
parents:
2507
diff
changeset
|
6122 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
|
6123 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
|
6124 } |
7 | 6125 width = cells * gui.char_width * PANGO_SCALE; |
6126 glyph->geometry.x_offset += | |
6127 MAX(0, width - cluster_width) / 2; | |
6128 } | |
6129 else /* i == 0 "cannot happen" */ | |
6130 { | |
6131 glyph->geometry.width = 0; | |
6132 } | |
6133 } | |
6134 | |
6135 /*** Aaaaand action! ***/ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6136 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6137 draw_glyph_string(row, col + column_offset, item_cells, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6138 flags, item->analysis.font, glyphs, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6139 cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6140 #else |
7 | 6141 draw_glyph_string(row, col + column_offset, item_cells, |
6142 flags, item->analysis.font, glyphs); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6143 #endif |
7 | 6144 |
6145 pango_item_free(item); | |
6146 | |
6147 column_offset += item_cells; | |
6148 } | |
6149 | |
6150 pango_attr_list_unref(attr_list); | |
6151 } | |
6152 | |
26 | 6153 skipitall: |
207 | 6154 /* Draw underline and undercurl. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6155 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6156 draw_under(flags, row, col, column_offset, cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6157 #else |
207 | 6158 draw_under(flags, row, col, column_offset); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6159 #endif |
7 | 6160 |
6161 pango_glyph_string_free(glyphs); | |
6162 vim_free(conv_buf); | |
6163 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6164 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6165 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6166 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6167 gdk_window_invalidate_rect(gtk_widget_get_window(gui.drawarea), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6168 &area, FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6169 #else |
7 | 6170 gdk_gc_set_clip_rectangle(gui.text_gc, NULL); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6171 #endif |
7 | 6172 |
6173 return column_offset; | |
6174 } | |
6175 | |
6176 /* | |
6177 * Return OK if the key with the termcap name "name" is supported. | |
6178 */ | |
6179 int | |
6180 gui_mch_haskey(char_u *name) | |
6181 { | |
6182 int i; | |
6183 | |
6184 for (i = 0; special_keys[i].key_sym != 0; i++) | |
6185 if (name[0] == special_keys[i].code0 | |
6186 && name[1] == special_keys[i].code1) | |
6187 return OK; | |
6188 return FAIL; | |
6189 } | |
6190 | |
4133 | 6191 #if defined(FEAT_TITLE) || defined(FEAT_EVAL) || defined(PROTO) |
7 | 6192 /* |
6193 * Return the text window-id and display. Only required for X-based GUI's | |
6194 */ | |
6195 int | |
6196 gui_get_x11_windis(Window *win, Display **dis) | |
6197 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6198 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6199 if (gui.mainwin != NULL && gtk_widget_get_window(gui.mainwin) != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6200 #else |
7 | 6201 if (gui.mainwin != NULL && gui.mainwin->window != NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6202 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6203 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6204 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6205 *dis = GDK_WINDOW_XDISPLAY(gtk_widget_get_window(gui.mainwin)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6206 *win = GDK_WINDOW_XID(gtk_widget_get_window(gui.mainwin)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6207 #else |
7 | 6208 *dis = GDK_WINDOW_XDISPLAY(gui.mainwin->window); |
6209 *win = GDK_WINDOW_XWINDOW(gui.mainwin->window); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6210 #endif |
7 | 6211 return OK; |
6212 } | |
6213 | |
6214 *dis = NULL; | |
6215 *win = 0; | |
6216 return FAIL; | |
6217 } | |
6218 #endif | |
6219 | |
6220 #if defined(FEAT_CLIENTSERVER) \ | |
6221 || (defined(FEAT_X11) && defined(FEAT_CLIPBOARD)) || defined(PROTO) | |
6222 | |
6223 Display * | |
6224 gui_mch_get_display(void) | |
6225 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6226 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6227 if (gui.mainwin != NULL && gtk_widget_get_window(gui.mainwin) != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6228 return GDK_WINDOW_XDISPLAY(gtk_widget_get_window(gui.mainwin)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6229 #else |
7 | 6230 if (gui.mainwin != NULL && gui.mainwin->window != NULL) |
6231 return GDK_WINDOW_XDISPLAY(gui.mainwin->window); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6232 #endif |
7 | 6233 else |
6234 return NULL; | |
6235 } | |
6236 #endif | |
6237 | |
6238 void | |
6239 gui_mch_beep(void) | |
6240 { | |
6241 #ifdef HAVE_GTK_MULTIHEAD | |
6242 GdkDisplay *display; | |
6243 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6244 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6245 if (gui.mainwin != NULL && gtk_widget_get_realized(gui.mainwin)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6246 # else |
7 | 6247 if (gui.mainwin != NULL && GTK_WIDGET_REALIZED(gui.mainwin)) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6248 # endif |
7 | 6249 display = gtk_widget_get_display(gui.mainwin); |
6250 else | |
6251 display = gdk_display_get_default(); | |
6252 | |
6253 if (display != NULL) | |
6254 gdk_display_beep(display); | |
6255 #else | |
6256 gdk_beep(); | |
6257 #endif | |
6258 } | |
6259 | |
6260 void | |
6261 gui_mch_flash(int msec) | |
6262 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6263 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6264 /* TODO Replace GdkGC with Cairo */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6265 (void)msec; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6266 #else |
7 | 6267 GdkGCValues values; |
6268 GdkGC *invert_gc; | |
6269 | |
6270 if (gui.drawarea->window == NULL) | |
6271 return; | |
6272 | |
6273 values.foreground.pixel = gui.norm_pixel ^ gui.back_pixel; | |
6274 values.background.pixel = gui.norm_pixel ^ gui.back_pixel; | |
6275 values.function = GDK_XOR; | |
6276 invert_gc = gdk_gc_new_with_values(gui.drawarea->window, | |
6277 &values, | |
6278 GDK_GC_FOREGROUND | | |
6279 GDK_GC_BACKGROUND | | |
6280 GDK_GC_FUNCTION); | |
6281 gdk_gc_set_exposures(invert_gc, | |
6282 gui.visibility != GDK_VISIBILITY_UNOBSCURED); | |
6283 /* | |
6284 * Do a visual beep by changing back and forth in some undetermined way, | |
6285 * the foreground and background colors. This is due to the fact that | |
6286 * there can't be really any prediction about the effects of XOR on | |
6287 * arbitrary X11 servers. However this seems to be enough for what we | |
6288 * intend it to do. | |
6289 */ | |
6290 gdk_draw_rectangle(gui.drawarea->window, invert_gc, | |
6291 TRUE, | |
6292 0, 0, | |
6293 FILL_X((int)Columns) + gui.border_offset, | |
6294 FILL_Y((int)Rows) + gui.border_offset); | |
6295 | |
6296 gui_mch_flush(); | |
6297 ui_delay((long)msec, TRUE); /* wait so many msec */ | |
6298 | |
6299 gdk_draw_rectangle(gui.drawarea->window, invert_gc, | |
6300 TRUE, | |
6301 0, 0, | |
6302 FILL_X((int)Columns) + gui.border_offset, | |
6303 FILL_Y((int)Rows) + gui.border_offset); | |
6304 | |
6305 gdk_gc_destroy(invert_gc); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6306 #endif |
7 | 6307 } |
6308 | |
6309 /* | |
6310 * Invert a rectangle from row r, column c, for nr rows and nc columns. | |
6311 */ | |
6312 void | |
6313 gui_mch_invert_rectangle(int r, int c, int nr, int nc) | |
6314 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6315 #if GTK_CHECK_VERSION(3,0,0) |
8495
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6316 const GdkRectangle rect = { |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6317 FILL_X(c), FILL_Y(r), nc * gui.char_width, nr * gui.char_height |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6318 }; |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6319 cairo_t * const cr = cairo_create(gui.surface); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6320 |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6321 set_cairo_source_rgb_from_pixel(cr, gui.norm_pixel ^ gui.back_pixel); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6322 # if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1,9,2) |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6323 cairo_set_operator(cr, CAIRO_OPERATOR_DIFFERENCE); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6324 # else |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6325 /* Give an implementation for older cairo versions if necessary. */ |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6326 # endif |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6327 gdk_cairo_rectangle(cr, &rect); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6328 cairo_fill(cr); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6329 |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6330 cairo_destroy(cr); |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6331 |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6332 if (!gui.by_signal) |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6333 gtk_widget_queue_draw_area(gui.drawarea, rect.x, rect.y, |
8877ea0a27ec
commit https://github.com/vim/vim/commit/4fc563b397949ce23190045112fa08c0776a56e6
Christian Brabandt <cb@256bit.org>
parents:
8469
diff
changeset
|
6334 rect.width, rect.height); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6335 #else |
7 | 6336 GdkGCValues values; |
6337 GdkGC *invert_gc; | |
6338 | |
6339 if (gui.drawarea->window == NULL) | |
6340 return; | |
6341 | |
944 | 6342 values.foreground.pixel = gui.norm_pixel ^ gui.back_pixel; |
6343 values.background.pixel = gui.norm_pixel ^ gui.back_pixel; | |
7 | 6344 values.function = GDK_XOR; |
6345 invert_gc = gdk_gc_new_with_values(gui.drawarea->window, | |
6346 &values, | |
6347 GDK_GC_FOREGROUND | | |
6348 GDK_GC_BACKGROUND | | |
6349 GDK_GC_FUNCTION); | |
944 | 6350 gdk_gc_set_exposures(invert_gc, gui.visibility != |
6351 GDK_VISIBILITY_UNOBSCURED); | |
7 | 6352 gdk_draw_rectangle(gui.drawarea->window, invert_gc, |
6353 TRUE, | |
6354 FILL_X(c), FILL_Y(r), | |
6355 (nc) * gui.char_width, (nr) * gui.char_height); | |
6356 gdk_gc_destroy(invert_gc); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6357 #endif |
7 | 6358 } |
6359 | |
6360 /* | |
6361 * Iconify the GUI window. | |
6362 */ | |
6363 void | |
6364 gui_mch_iconify(void) | |
6365 { | |
6366 gtk_window_iconify(GTK_WINDOW(gui.mainwin)); | |
6367 } | |
6368 | |
6369 #if defined(FEAT_EVAL) || defined(PROTO) | |
6370 /* | |
6371 * Bring the Vim window to the foreground. | |
6372 */ | |
6373 void | |
6374 gui_mch_set_foreground(void) | |
6375 { | |
6376 gtk_window_present(GTK_WINDOW(gui.mainwin)); | |
6377 } | |
6378 #endif | |
6379 | |
6380 /* | |
6381 * Draw a cursor without focus. | |
6382 */ | |
6383 void | |
6384 gui_mch_draw_hollow_cursor(guicolor_T color) | |
6385 { | |
6386 int i = 1; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6387 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6388 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6389 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6390 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6391 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6392 if (gtk_widget_get_window(gui.drawarea) == NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6393 #else |
7 | 6394 if (gui.drawarea->window == NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6395 #endif |
7 | 6396 return; |
6397 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6398 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6399 cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6400 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6401 |
7 | 6402 gui_mch_set_fg_color(color); |
6403 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6404 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6405 set_cairo_source_rgb_from_pixel(cr, gui.fgcolor->pixel); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6406 #else |
7 | 6407 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6408 #endif |
7 | 6409 if (mb_lefthalve(gui.row, gui.col)) |
6410 i = 2; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6411 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6412 cairo_set_line_width(cr, 1.0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6413 cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6414 cairo_rectangle(cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6415 FILL_X(gui.col) + 0.5, FILL_Y(gui.row) + 0.5, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6416 i * gui.char_width - 1, gui.char_height - 1); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6417 cairo_stroke(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6418 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6419 #else |
7 | 6420 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, |
6421 FALSE, | |
6422 FILL_X(gui.col), FILL_Y(gui.row), | |
6423 i * gui.char_width - 1, gui.char_height - 1); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6424 #endif |
7 | 6425 } |
6426 | |
6427 /* | |
6428 * Draw part of a cursor, "w" pixels wide, and "h" pixels high, using | |
6429 * color "color". | |
6430 */ | |
6431 void | |
6432 gui_mch_draw_part_cursor(int w, int h, guicolor_T color) | |
6433 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6434 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6435 if (gtk_widget_get_window(gui.drawarea) == NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6436 #else |
7 | 6437 if (gui.drawarea->window == NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6438 #endif |
7 | 6439 return; |
6440 | |
6441 gui_mch_set_fg_color(color); | |
6442 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6443 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6444 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6445 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6446 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6447 cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6448 set_cairo_source_rgb_from_pixel(cr, gui.fgcolor->pixel); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6449 cairo_rectangle(cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6450 # ifdef FEAT_RIGHTLEFT |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6451 /* vertical line should be on the right of current point */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6452 CURSOR_BAR_RIGHT ? FILL_X(gui.col + 1) - w : |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6453 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6454 FILL_X(gui.col), FILL_Y(gui.row) + gui.char_height - h, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6455 w, h); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6456 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6457 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6458 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6459 #else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6460 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
6461 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, | |
6462 TRUE, | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6463 # ifdef FEAT_RIGHTLEFT |
7 | 6464 /* vertical line should be on the right of current point */ |
6465 CURSOR_BAR_RIGHT ? FILL_X(gui.col + 1) - w : | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6466 # endif |
7 | 6467 FILL_X(gui.col), |
6468 FILL_Y(gui.row) + gui.char_height - h, | |
6469 w, h); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6470 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6471 } |
6472 | |
6473 | |
6474 /* | |
6475 * Catch up with any queued X11 events. This may put keyboard input into the | |
6476 * input buffer, call resize call-backs, trigger timers etc. If there is | |
6477 * nothing in the X11 event queue (& no timers pending), then we return | |
6478 * immediately. | |
6479 */ | |
6480 void | |
6481 gui_mch_update(void) | |
6482 { | |
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
|
6483 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
|
6484 g_main_context_iteration(NULL, TRUE); |
7 | 6485 } |
6486 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6487 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6488 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6489 #else |
7 | 6490 static gint |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6491 #endif |
7 | 6492 input_timer_cb(gpointer data) |
6493 { | |
6494 int *timed_out = (int *) data; | |
6495 | |
1226 | 6496 /* Just inform the caller about the occurrence of it */ |
7 | 6497 *timed_out = TRUE; |
6498 | |
6499 return FALSE; /* don't happen again */ | |
6500 } | |
6501 | |
6502 /* | |
6503 * GUI input routine called by gui_wait_for_chars(). Waits for a character | |
6504 * from the keyboard. | |
6505 * wtime == -1 Wait forever. | |
6506 * wtime == 0 This should never happen. | |
6507 * wtime > 0 Wait wtime milliseconds for a character. | |
6508 * Returns OK if a character was found to be available within the given time, | |
6509 * or FAIL otherwise. | |
6510 */ | |
6511 int | |
6512 gui_mch_wait_for_chars(long wtime) | |
6513 { | |
6514 int focus; | |
6515 guint timer; | |
6516 static int timed_out; | |
6517 | |
6518 timed_out = FALSE; | |
6519 | |
6520 /* this timeout makes sure that we will return if no characters arrived in | |
6521 * time */ | |
6522 | |
6523 if (wtime > 0) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6524 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6525 timer = g_timeout_add((guint)wtime, input_timer_cb, &timed_out); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6526 #else |
7 | 6527 timer = gtk_timeout_add((guint32)wtime, input_timer_cb, &timed_out); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6528 #endif |
7 | 6529 else |
6530 timer = 0; | |
6531 | |
6532 focus = gui.in_focus; | |
6533 | |
6534 do | |
6535 { | |
6536 /* Stop or start blinking when focus changes */ | |
6537 if (gui.in_focus != focus) | |
6538 { | |
6539 if (gui.in_focus) | |
6540 gui_mch_start_blink(); | |
6541 else | |
6542 gui_mch_stop_blink(); | |
6543 focus = gui.in_focus; | |
6544 } | |
6545 | |
7109
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7098
diff
changeset
|
6546 #ifdef MESSAGE_QUEUE |
fa95595fbc52
commit https://github.com/vim/vim/commit/93c88e0f6a4a8f7634ed84721daf4af46fc0d5db
Christian Brabandt <cb@256bit.org>
parents:
7098
diff
changeset
|
6547 parse_queued_messages(); |
1624 | 6548 #endif |
6549 | |
7 | 6550 /* |
6551 * Loop in GTK+ processing until a timeout or input occurs. | |
22 | 6552 * Skip this if input is available anyway (can happen in rare |
6553 * situations, sort of race condition). | |
7 | 6554 */ |
22 | 6555 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
|
6556 g_main_context_iteration(NULL, TRUE); |
7 | 6557 |
6558 /* Got char, return immediately */ | |
6559 if (input_available()) | |
6560 { | |
6561 if (timer != 0 && !timed_out) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6562 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6563 g_source_remove(timer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6564 #else |
7 | 6565 gtk_timeout_remove(timer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6566 #endif |
7 | 6567 return OK; |
6568 } | |
6569 } while (wtime < 0 || !timed_out); | |
6570 | |
6571 /* | |
6572 * Flush all eventually pending (drawing) events. | |
6573 */ | |
6574 gui_mch_update(); | |
6575 | |
6576 return FAIL; | |
6577 } | |
6578 | |
6579 | |
6580 /**************************************************************************** | |
6581 * Output drawing routines. | |
6582 ****************************************************************************/ | |
6583 | |
6584 | |
6585 /* Flush any output to the screen */ | |
6586 void | |
6587 gui_mch_flush(void) | |
6588 { | |
6589 #ifdef HAVE_GTK_MULTIHEAD | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6590 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6591 if (gui.mainwin != NULL && gtk_widget_get_realized(gui.mainwin)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6592 # else |
7 | 6593 if (gui.mainwin != NULL && GTK_WIDGET_REALIZED(gui.mainwin)) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6594 # endif |
7 | 6595 gdk_display_sync(gtk_widget_get_display(gui.mainwin)); |
6596 #else | |
6597 gdk_flush(); /* historical misnomer: calls XSync(), not XFlush() */ | |
6598 #endif | |
6599 /* This happens to actually do what gui_mch_flush() is supposed to do, | |
6600 * according to the comment above. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6601 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6602 if (gui.drawarea != NULL && gtk_widget_get_window(gui.drawarea) != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6603 gdk_window_process_updates(gtk_widget_get_window(gui.drawarea), FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6604 #else |
7 | 6605 if (gui.drawarea != NULL && gui.drawarea->window != NULL) |
6606 gdk_window_process_updates(gui.drawarea->window, FALSE); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6607 #endif |
7 | 6608 } |
6609 | |
6610 /* | |
6611 * Clear a rectangular region of the screen from text pos (row1, col1) to | |
6612 * (row2, col2) inclusive. | |
6613 */ | |
6614 void | |
6615 gui_mch_clear_block(int row1, int col1, int row2, int col2) | |
6616 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6617 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6618 if (gtk_widget_get_window(gui.drawarea) == NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6619 return; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6620 #else |
7 | 6621 GdkColor color; |
6622 | |
6623 if (gui.drawarea->window == NULL) | |
6624 return; | |
6625 | |
6626 color.pixel = gui.back_pixel; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6627 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6628 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6629 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6630 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6631 /* Add one pixel to the far right column in case a double-stroked |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6632 * bold glyph may sit there. */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6633 const GdkRectangle rect = { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6634 FILL_X(col1), FILL_Y(row1), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6635 (col2 - col1 + 1) * gui.char_width + (col2 == Columns - 1), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6636 (row2 - row1 + 1) * gui.char_height |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6637 }; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6638 GdkWindow * const win = gtk_widget_get_window(gui.drawarea); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6639 cairo_t * const cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6640 cairo_pattern_t * const pat = gdk_window_get_background_pattern(win); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6641 if (pat != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6642 cairo_set_source(cr, pat); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6643 else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6644 set_cairo_source_rgb_from_pixel(cr, gui.back_pixel); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6645 gdk_cairo_rectangle(cr, &rect); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6646 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6647 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6648 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6649 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6650 gdk_window_invalidate_rect(win, &rect, FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6651 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6652 #else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6653 gdk_gc_set_foreground(gui.text_gc, &color); |
6654 | |
6655 /* Clear one extra pixel at the far right, for when bold characters have | |
6656 * spilled over to the window border. */ | |
6657 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, TRUE, | |
6658 FILL_X(col1), FILL_Y(row1), | |
6659 (col2 - col1 + 1) * gui.char_width | |
6660 + (col2 == Columns - 1), | |
6661 (row2 - row1 + 1) * gui.char_height); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6662 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6663 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6664 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6665 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6666 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6667 gui_gtk_window_clear(GdkWindow *win) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6668 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6669 const GdkRectangle rect = { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6670 0, 0, gdk_window_get_width(win), gdk_window_get_height(win) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6671 }; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6672 cairo_t * const cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6673 cairo_pattern_t * const pat = gdk_window_get_background_pattern(win); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6674 if (pat != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6675 cairo_set_source(cr, pat); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6676 else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6677 set_cairo_source_rgb_from_pixel(cr, gui.back_pixel); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6678 gdk_cairo_rectangle(cr, &rect); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6679 cairo_fill(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6680 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6681 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6682 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6683 gdk_window_invalidate_rect(win, &rect, FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6684 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6685 #endif |
7 | 6686 |
6687 void | |
6688 gui_mch_clear_all(void) | |
6689 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6690 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6691 if (gtk_widget_get_window(gui.drawarea) != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6692 gui_gtk_window_clear(gtk_widget_get_window(gui.drawarea)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6693 #else |
7 | 6694 if (gui.drawarea->window != NULL) |
6695 gdk_window_clear(gui.drawarea->window); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6696 #endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6697 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6698 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6699 #if !GTK_CHECK_VERSION(3,0,0) |
7 | 6700 /* |
6701 * Redraw any text revealed by scrolling up/down. | |
6702 */ | |
6703 static void | |
6704 check_copy_area(void) | |
6705 { | |
6706 GdkEvent *event; | |
6707 int expose_count; | |
6708 | |
6709 if (gui.visibility != GDK_VISIBILITY_PARTIAL) | |
6710 return; | |
6711 | |
6712 /* Avoid redrawing the cursor while scrolling or it'll end up where | |
6713 * we don't want it to be. I'm not sure if it's correct to call | |
6714 * gui_dont_update_cursor() at this point but it works as a quick | |
6715 * fix for now. */ | |
6716 gui_dont_update_cursor(); | |
6717 | |
6718 do | |
6719 { | |
6720 /* Wait to check whether the scroll worked or not. */ | |
6721 event = gdk_event_get_graphics_expose(gui.drawarea->window); | |
6722 | |
6723 if (event == NULL) | |
6724 break; /* received NoExpose event */ | |
6725 | |
6726 gui_redraw(event->expose.area.x, event->expose.area.y, | |
6727 event->expose.area.width, event->expose.area.height); | |
6728 | |
6729 expose_count = event->expose.count; | |
6730 gdk_event_free(event); | |
6731 } | |
6732 while (expose_count > 0); /* more events follow */ | |
6733 | |
6734 gui_can_update_cursor(); | |
6735 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6736 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6737 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6738 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6739 static void |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6740 gui_gtk_surface_copy_rect(int dest_x, int dest_y, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6741 int src_x, int src_y, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6742 int width, int height) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6743 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6744 cairo_t * const cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6745 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6746 cairo_rectangle(cr, dest_x, dest_y, width, height); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6747 cairo_clip(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6748 cairo_push_group(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6749 cairo_set_source_surface(cr, gui.surface, dest_x - src_x, dest_y - src_y); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6750 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6751 cairo_pop_group_to_source(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6752 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6753 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6754 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6755 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6756 #endif |
7 | 6757 |
6758 /* | |
6759 * Delete the given number of lines from the given row, scrolling up any | |
6760 * text further down within the scroll region. | |
6761 */ | |
6762 void | |
6763 gui_mch_delete_lines(int row, int num_lines) | |
6764 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6765 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6766 const int ncols = gui.scroll_region_right - gui.scroll_region_left + 1; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6767 const int nrows = gui.scroll_region_bot - row + 1; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6768 const int src_nrows = nrows - num_lines; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6769 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6770 gui_gtk_surface_copy_rect( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6771 FILL_X(gui.scroll_region_left), FILL_Y(row), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6772 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6773 gui.char_width * ncols + 1, gui.char_height * src_nrows); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6774 gui_clear_block( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6775 gui.scroll_region_bot - num_lines + 1, gui.scroll_region_left, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6776 gui.scroll_region_bot, gui.scroll_region_right); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6777 gui_gtk3_redraw( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6778 FILL_X(gui.scroll_region_left), FILL_Y(row), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6779 gui.char_width * ncols + 1, gui.char_height * nrows); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6780 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6781 gtk_widget_queue_draw_area(gui.drawarea, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6782 FILL_X(gui.scroll_region_left), FILL_Y(row), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6783 gui.char_width * ncols + 1, gui.char_height * nrows); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6784 #else |
7 | 6785 if (gui.visibility == GDK_VISIBILITY_FULLY_OBSCURED) |
6786 return; /* Can't see the window */ | |
6787 | |
6788 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | |
6789 gdk_gc_set_background(gui.text_gc, gui.bgcolor); | |
6790 | |
6791 /* copy one extra pixel, for when bold has spilled over */ | |
6792 gdk_window_copy_area(gui.drawarea->window, gui.text_gc, | |
6793 FILL_X(gui.scroll_region_left), FILL_Y(row), | |
6794 gui.drawarea->window, | |
6795 FILL_X(gui.scroll_region_left), | |
6796 FILL_Y(row + num_lines), | |
6797 gui.char_width * (gui.scroll_region_right | |
6798 - gui.scroll_region_left + 1) + 1, | |
6799 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1)); | |
6800 | |
6801 gui_clear_block(gui.scroll_region_bot - num_lines + 1, | |
6802 gui.scroll_region_left, | |
6803 gui.scroll_region_bot, gui.scroll_region_right); | |
6804 check_copy_area(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6805 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6806 } |
6807 | |
6808 /* | |
6809 * Insert the given number of lines before the given row, scrolling down any | |
6810 * following text within the scroll region. | |
6811 */ | |
6812 void | |
6813 gui_mch_insert_lines(int row, int num_lines) | |
6814 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6815 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6816 const int ncols = gui.scroll_region_right - gui.scroll_region_left + 1; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6817 const int nrows = gui.scroll_region_bot - row + 1; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6818 const int src_nrows = nrows - num_lines; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6819 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6820 gui_gtk_surface_copy_rect( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6821 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6822 FILL_X(gui.scroll_region_left), FILL_Y(row), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6823 gui.char_width * ncols + 1, gui.char_height * src_nrows); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6824 gui_mch_clear_block( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6825 row, gui.scroll_region_left, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6826 row + num_lines - 1, gui.scroll_region_right); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6827 gui_gtk3_redraw( |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6828 FILL_X(gui.scroll_region_left), FILL_Y(row), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6829 gui.char_width * ncols + 1, gui.char_height * nrows); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6830 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6831 gtk_widget_queue_draw_area(gui.drawarea, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6832 FILL_X(gui.scroll_region_left), FILL_Y(row), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6833 gui.char_width * ncols + 1, gui.char_height * nrows); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6834 #else |
7 | 6835 if (gui.visibility == GDK_VISIBILITY_FULLY_OBSCURED) |
6836 return; /* Can't see the window */ | |
6837 | |
6838 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | |
6839 gdk_gc_set_background(gui.text_gc, gui.bgcolor); | |
6840 | |
6841 /* copy one extra pixel, for when bold has spilled over */ | |
6842 gdk_window_copy_area(gui.drawarea->window, gui.text_gc, | |
6843 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), | |
6844 gui.drawarea->window, | |
6845 FILL_X(gui.scroll_region_left), FILL_Y(row), | |
6846 gui.char_width * (gui.scroll_region_right | |
6847 - gui.scroll_region_left + 1) + 1, | |
6848 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1)); | |
6849 | |
6850 gui_clear_block(row, gui.scroll_region_left, | |
6851 row + num_lines - 1, gui.scroll_region_right); | |
6852 check_copy_area(); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6853 #endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 6854 } |
6855 | |
6856 /* | |
6857 * X Selection stuff, for cutting and pasting text to other windows. | |
6858 */ | |
6859 void | |
6860 clip_mch_request_selection(VimClipboard *cbd) | |
6861 { | |
6862 GdkAtom target; | |
6863 unsigned i; | |
1494 | 6864 time_t start; |
7 | 6865 |
6866 for (i = 0; i < N_SELECTION_TARGETS; ++i) | |
6867 { | |
1904 | 6868 if (!clip_html && selection_targets[i].info == TARGET_HTML) |
6869 continue; | |
7 | 6870 received_selection = RS_NONE; |
6871 target = gdk_atom_intern(selection_targets[i].target, FALSE); | |
6872 | |
6873 gtk_selection_convert(gui.drawarea, | |
6874 cbd->gtk_sel_atom, target, | |
6875 (guint32)GDK_CURRENT_TIME); | |
6876 | |
1494 | 6877 /* Hack: Wait up to three seconds for the selection. A hang was |
6878 * noticed here when using the netrw plugin combined with ":gui" | |
6879 * during the FocusGained event. */ | |
6880 start = time(NULL); | |
6881 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
|
6882 g_main_context_iteration(NULL, TRUE); /* wait for selection_received_cb */ |
7 | 6883 |
6884 if (received_selection != RS_FAIL) | |
6885 return; | |
6886 } | |
6887 | |
6888 /* Final fallback position - use the X CUT_BUFFER0 store */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6889 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6890 yank_cut_buffer0(GDK_WINDOW_XDISPLAY(gtk_widget_get_window(gui.mainwin)), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6891 cbd); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6892 #else |
1924 | 6893 yank_cut_buffer0(GDK_WINDOW_XDISPLAY(gui.mainwin->window), cbd); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6894 #endif |
7 | 6895 } |
6896 | |
6897 /* | |
6898 * Disown the selection. | |
6899 */ | |
6900 void | |
1884 | 6901 clip_mch_lose_selection(VimClipboard *cbd UNUSED) |
7 | 6902 { |
4209 | 6903 gtk_selection_owner_set(NULL, cbd->gtk_sel_atom, gui.event_time); |
7 | 6904 gui_mch_update(); |
6905 } | |
6906 | |
6907 /* | |
6908 * Own the selection and return OK if it worked. | |
6909 */ | |
6910 int | |
6911 clip_mch_own_selection(VimClipboard *cbd) | |
6912 { | |
6913 int success; | |
6914 | |
6915 success = gtk_selection_owner_set(gui.drawarea, cbd->gtk_sel_atom, | |
2923 | 6916 gui.event_time); |
7 | 6917 gui_mch_update(); |
6918 return (success) ? OK : FAIL; | |
6919 } | |
6920 | |
6921 /* | |
6922 * Send the current selection to the clipboard. Do nothing for X because we | |
6923 * will fill in the selection only when requested by another app. | |
6924 */ | |
6925 void | |
1884 | 6926 clip_mch_set_selection(VimClipboard *cbd UNUSED) |
7 | 6927 { |
6928 } | |
6929 | |
4209 | 6930 int |
6931 clip_gtk_owner_exists(VimClipboard *cbd) | |
6932 { | |
6933 return gdk_selection_owner_get(cbd->gtk_sel_atom) != NULL; | |
6934 } | |
6935 | |
7 | 6936 |
6937 #if defined(FEAT_MENU) || defined(PROTO) | |
6938 /* | |
6939 * Make a menu item appear either active or not active (grey or not grey). | |
6940 */ | |
6941 void | |
6942 gui_mch_menu_grey(vimmenu_T *menu, int grey) | |
6943 { | |
6944 if (menu->id == NULL) | |
6945 return; | |
6946 | |
6947 if (menu_is_separator(menu->name)) | |
6948 grey = TRUE; | |
6949 | |
6950 gui_mch_menu_hidden(menu, FALSE); | |
6951 /* Be clever about bitfields versus true booleans here! */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6952 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6953 if (!gtk_widget_get_sensitive(menu->id) == !grey) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6954 # else |
7 | 6955 if (!GTK_WIDGET_SENSITIVE(menu->id) == !grey) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6956 # endif |
7 | 6957 { |
6958 gtk_widget_set_sensitive(menu->id, !grey); | |
6959 gui_mch_update(); | |
6960 } | |
6961 } | |
6962 | |
6963 /* | |
6964 * Make menu item hidden or not hidden. | |
6965 */ | |
6966 void | |
6967 gui_mch_menu_hidden(vimmenu_T *menu, int hidden) | |
6968 { | |
6969 if (menu->id == 0) | |
6970 return; | |
6971 | |
6972 if (hidden) | |
6973 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6974 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6975 if (gtk_widget_get_visible(menu->id)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6976 # else |
7 | 6977 if (GTK_WIDGET_VISIBLE(menu->id)) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6978 # endif |
7 | 6979 { |
6980 gtk_widget_hide(menu->id); | |
6981 gui_mch_update(); | |
6982 } | |
6983 } | |
6984 else | |
6985 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6986 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6987 if (!gtk_widget_get_visible(menu->id)) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6988 # else |
7 | 6989 if (!GTK_WIDGET_VISIBLE(menu->id)) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
6990 # endif |
7 | 6991 { |
6992 gtk_widget_show(menu->id); | |
6993 gui_mch_update(); | |
6994 } | |
6995 } | |
6996 } | |
6997 | |
6998 /* | |
6999 * This is called after setting all the menus to grey/hidden or not. | |
7000 */ | |
7001 void | |
7002 gui_mch_draw_menubar(void) | |
7003 { | |
7004 /* just make sure that the visual changes get effect immediately */ | |
7005 gui_mch_update(); | |
7006 } | |
7007 #endif /* FEAT_MENU */ | |
7008 | |
7009 /* | |
7010 * Scrollbar stuff. | |
7011 */ | |
7012 void | |
7013 gui_mch_enable_scrollbar(scrollbar_T *sb, int flag) | |
7014 { | |
7015 if (sb->id == NULL) | |
7016 return; | |
7017 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7018 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7019 gtk_widget_set_visible(sb->id, flag); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7020 #else |
7 | 7021 if (flag) |
7022 gtk_widget_show(sb->id); | |
7023 else | |
7024 gtk_widget_hide(sb->id); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7025 #endif |
7 | 7026 |
791 | 7027 update_window_manager_hints(0, 0); |
7 | 7028 } |
7029 | |
7030 | |
7031 /* | |
7032 * Return the RGB value of a pixel as long. | |
7033 */ | |
7034 long_u | |
7035 gui_mch_get_rgb(guicolor_T pixel) | |
7036 { | |
7037 GdkColor color; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7038 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7039 GdkRGBA rgba; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7040 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7041 gui_gtk_get_rgb_from_pixel(pixel, &rgba); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7042 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7043 color.red = rgba.red * 65535; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7044 color.green = rgba.green * 65535; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7045 color.blue = rgba.blue * 65535; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7046 #else |
7 | 7047 gdk_colormap_query_color(gtk_widget_get_colormap(gui.drawarea), |
7048 (unsigned long)pixel, &color); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7049 #endif |
7 | 7050 |
7051 return (((unsigned)color.red & 0xff00) << 8) | |
7052 | ((unsigned)color.green & 0xff00) | |
7053 | (((unsigned)color.blue & 0xff00) >> 8); | |
7054 } | |
7055 | |
7056 /* | |
88 | 7057 * Get current mouse coordinates in text window. |
7 | 7058 */ |
88 | 7059 void |
7060 gui_mch_getmouse(int *x, int *y) | |
7 | 7061 { |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7062 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7063 gui_gtk_get_pointer(gui.drawarea, x, y, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7064 #else |
88 | 7065 gdk_window_get_pointer(gui.drawarea->window, x, y, NULL); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7066 #endif |
7 | 7067 } |
7068 | |
7069 void | |
7070 gui_mch_setmouse(int x, int y) | |
7071 { | |
7072 /* Sorry for the Xlib call, but we can't avoid it, since there is no | |
7073 * internal GDK mechanism present to accomplish this. (and for good | |
7074 * reason...) */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7075 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7076 XWarpPointer(GDK_WINDOW_XDISPLAY(gtk_widget_get_window(gui.drawarea)), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7077 (Window)0, GDK_WINDOW_XID(gtk_widget_get_window(gui.drawarea)), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7078 0, 0, 0U, 0U, x, y); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7079 #else |
7 | 7080 XWarpPointer(GDK_WINDOW_XDISPLAY(gui.drawarea->window), |
7081 (Window)0, GDK_WINDOW_XWINDOW(gui.drawarea->window), | |
7082 0, 0, 0U, 0U, x, y); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7083 #endif |
7 | 7084 } |
7085 | |
7086 | |
7087 #ifdef FEAT_MOUSESHAPE | |
7088 /* The last set mouse pointer shape is remembered, to be used when it goes | |
7089 * from hidden to not hidden. */ | |
7090 static int last_shape = 0; | |
7091 #endif | |
7092 | |
7093 /* | |
7094 * Use the blank mouse pointer or not. | |
7095 * | |
7096 * hide: TRUE = use blank ptr, FALSE = use parent ptr | |
7097 */ | |
7098 void | |
7099 gui_mch_mousehide(int hide) | |
7100 { | |
7101 if (gui.pointer_hidden != hide) | |
7102 { | |
7103 gui.pointer_hidden = hide; | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7104 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7105 if (gtk_widget_get_window(gui.drawarea) && gui.blank_pointer != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7106 #else |
7 | 7107 if (gui.drawarea->window && gui.blank_pointer != NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7108 #endif |
7 | 7109 { |
7110 if (hide) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7111 #if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7112 gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7113 gui.blank_pointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7114 #else |
7 | 7115 gdk_window_set_cursor(gui.drawarea->window, gui.blank_pointer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7116 #endif |
7 | 7117 else |
7118 #ifdef FEAT_MOUSESHAPE | |
7119 mch_set_mouse_shape(last_shape); | |
8301
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7120 #elif GTK_CHECK_VERSION(3,0,0) |
6a4c11fa1aa3
commit https://github.com/vim/vim/commit/3f2a5d8dfbe2998b4d3d369c0275e2366c92666b
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
7121 gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), NULL); |
7 | 7122 #else |
7123 gdk_window_set_cursor(gui.drawarea->window, NULL); | |
7124 #endif | |
7125 } | |
7126 } | |
7127 } | |
7128 | |
7129 #if defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7130 | |
7131 /* Table for shape IDs. Keep in sync with the mshape_names[] table in | |
7132 * misc2.c! */ | |
7133 static const int mshape_ids[] = | |
7134 { | |
7135 GDK_LEFT_PTR, /* arrow */ | |
7136 GDK_CURSOR_IS_PIXMAP, /* blank */ | |
7137 GDK_XTERM, /* beam */ | |
7138 GDK_SB_V_DOUBLE_ARROW, /* updown */ | |
7139 GDK_SIZING, /* udsizing */ | |
7140 GDK_SB_H_DOUBLE_ARROW, /* leftright */ | |
7141 GDK_SIZING, /* lrsizing */ | |
7142 GDK_WATCH, /* busy */ | |
7143 GDK_X_CURSOR, /* no */ | |
7144 GDK_CROSSHAIR, /* crosshair */ | |
7145 GDK_HAND1, /* hand1 */ | |
7146 GDK_HAND2, /* hand2 */ | |
7147 GDK_PENCIL, /* pencil */ | |
7148 GDK_QUESTION_ARROW, /* question */ | |
7149 GDK_RIGHT_PTR, /* right-arrow */ | |
7150 GDK_CENTER_PTR, /* up-arrow */ | |
7151 GDK_LEFT_PTR /* last one */ | |
7152 }; | |
7153 | |
7154 void | |
7155 mch_set_mouse_shape(int shape) | |
7156 { | |
7157 int id; | |
7158 GdkCursor *c; | |
7159 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7160 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7161 if (gtk_widget_get_window(gui.drawarea) == NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7162 # else |
7 | 7163 if (gui.drawarea->window == NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7164 # endif |
7 | 7165 return; |
7166 | |
7167 if (shape == MSHAPE_HIDE || gui.pointer_hidden) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7168 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7169 gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7170 gui.blank_pointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7171 # else |
7 | 7172 gdk_window_set_cursor(gui.drawarea->window, gui.blank_pointer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7173 # endif |
7 | 7174 else |
7175 { | |
7176 if (shape >= MSHAPE_NUMBERED) | |
7177 { | |
7178 id = shape - MSHAPE_NUMBERED; | |
7179 if (id >= GDK_LAST_CURSOR) | |
7180 id = GDK_LEFT_PTR; | |
7181 else | |
7182 id &= ~1; /* they are always even (why?) */ | |
7183 } | |
1884 | 7184 else if (shape < (int)(sizeof(mshape_ids) / sizeof(int))) |
7 | 7185 id = mshape_ids[shape]; |
842 | 7186 else |
7187 return; | |
7 | 7188 # ifdef HAVE_GTK_MULTIHEAD |
7189 c = gdk_cursor_new_for_display( | |
136 | 7190 gtk_widget_get_display(gui.drawarea), (GdkCursorType)id); |
7 | 7191 # else |
136 | 7192 c = gdk_cursor_new((GdkCursorType)id); |
7 | 7193 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7194 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7195 gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), c); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7196 # else |
7 | 7197 gdk_window_set_cursor(gui.drawarea->window, c); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7198 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7199 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7200 g_object_unref(G_OBJECT(c)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7201 # else |
7 | 7202 gdk_cursor_destroy(c); /* Unref, actually. Bloody GTK+ 1. */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7203 # endif |
7 | 7204 } |
7205 if (shape != MSHAPE_HIDE) | |
7206 last_shape = shape; | |
7207 } | |
7208 #endif /* FEAT_MOUSESHAPE */ | |
7209 | |
7210 | |
7211 #if defined(FEAT_SIGN_ICONS) || defined(PROTO) | |
7212 /* | |
7213 * Signs are currently always 2 chars wide. With GTK+ 2, the image will be | |
7214 * scaled down if the current font is not big enough, or scaled up if the image | |
7215 * size is less than 3/4 of the maximum sign size. With GTK+ 1, the pixmap | |
7216 * will be cut off if the current font is not big enough, or centered if it's | |
7217 * too small. | |
7218 */ | |
7219 # define SIGN_WIDTH (2 * gui.char_width) | |
7220 # define SIGN_HEIGHT (gui.char_height) | |
7221 # define SIGN_ASPECT ((double)SIGN_HEIGHT / (double)SIGN_WIDTH) | |
7222 | |
7223 void | |
7224 gui_mch_drawsign(int row, int col, int typenr) | |
7225 { | |
7226 GdkPixbuf *sign; | |
7227 | |
7228 sign = (GdkPixbuf *)sign_get_image(typenr); | |
7229 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7230 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7231 if (sign != NULL && gui.drawarea != NULL |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7232 && gtk_widget_get_window(gui.drawarea) != NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7233 # else |
7 | 7234 if (sign != NULL && gui.drawarea != NULL && gui.drawarea->window != NULL) |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7235 # endif |
7 | 7236 { |
7237 int width; | |
7238 int height; | |
7239 int xoffset; | |
7240 int yoffset; | |
7241 int need_scale; | |
7242 | |
7243 width = gdk_pixbuf_get_width(sign); | |
7244 height = gdk_pixbuf_get_height(sign); | |
7245 /* | |
7246 * Decide whether we need to scale. Allow one pixel of border | |
7247 * width to be cut off, in order to avoid excessive scaling for | |
7248 * tiny differences in font size. | |
5983 | 7249 * Do scale to fit the height to avoid gaps because of linespacing. |
7 | 7250 */ |
7251 need_scale = (width > SIGN_WIDTH + 2 | |
5983 | 7252 || height != SIGN_HEIGHT |
7 | 7253 || (width < 3 * SIGN_WIDTH / 4 |
7254 && height < 3 * SIGN_HEIGHT / 4)); | |
7255 if (need_scale) | |
7256 { | |
5983 | 7257 double aspect; |
7258 int w = width; | |
7259 int h = height; | |
7 | 7260 |
7261 /* Keep the original aspect ratio */ | |
7262 aspect = (double)height / (double)width; | |
7263 width = (double)SIGN_WIDTH * SIGN_ASPECT / aspect; | |
7264 width = MIN(width, SIGN_WIDTH); | |
5983 | 7265 if (((double)(MAX(height, SIGN_HEIGHT)) / |
7266 (double)(MIN(height, SIGN_HEIGHT))) < 1.15) | |
7267 { | |
7268 /* Change the aspect ratio by at most 15% to fill the | |
7269 * available space completly. */ | |
7270 height = (double)SIGN_HEIGHT * SIGN_ASPECT / aspect; | |
7271 height = MIN(height, SIGN_HEIGHT); | |
7272 } | |
7273 else | |
7274 height = (double)width * aspect; | |
7275 | |
7276 if (w == width && h == height) | |
7277 { | |
7278 /* no change in dimensions; don't decrease reference counter | |
7279 * (below) */ | |
7280 need_scale = FALSE; | |
7281 } | |
7282 else | |
7283 { | |
7284 /* This doesn't seem to be worth caching, and doing so would | |
7285 * complicate the code quite a bit. */ | |
7286 sign = gdk_pixbuf_scale_simple(sign, width, height, | |
7287 GDK_INTERP_BILINEAR); | |
7288 if (sign == NULL) | |
7289 return; /* out of memory */ | |
7290 } | |
7 | 7291 } |
7292 | |
7293 /* The origin is the upper-left corner of the pixmap. Therefore | |
7294 * these offset may become negative if the pixmap is smaller than | |
7295 * the 2x1 cells reserved for the sign icon. */ | |
7296 xoffset = (width - SIGN_WIDTH) / 2; | |
7297 yoffset = (height - SIGN_HEIGHT) / 2; | |
7298 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7299 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7300 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7301 cairo_t *cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7302 cairo_surface_t *bg_surf; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7303 cairo_t *bg_cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7304 cairo_surface_t *sign_surf; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7305 cairo_t *sign_cr; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7306 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7307 cr = cairo_create(gui.surface); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7308 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7309 bg_surf = cairo_surface_create_similar(gui.surface, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7310 cairo_surface_get_content(gui.surface), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7311 SIGN_WIDTH, SIGN_HEIGHT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7312 bg_cr = cairo_create(bg_surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7313 set_cairo_source_rgb_from_pixel(bg_cr, gui.bgcolor->pixel); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7314 cairo_paint(bg_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7315 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7316 sign_surf = cairo_surface_create_similar(gui.surface, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7317 cairo_surface_get_content(gui.surface), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7318 SIGN_WIDTH, SIGN_HEIGHT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7319 sign_cr = cairo_create(sign_surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7320 gdk_cairo_set_source_pixbuf(sign_cr, sign, -xoffset, -yoffset); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7321 cairo_paint(sign_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7322 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7323 cairo_set_operator(sign_cr, CAIRO_OPERATOR_DEST_OVER); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7324 cairo_set_source_surface(sign_cr, bg_surf, 0, 0); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7325 cairo_paint(sign_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7326 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7327 cairo_set_source_surface(cr, sign_surf, FILL_X(col), FILL_Y(row)); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7328 cairo_paint(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7329 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7330 cairo_destroy(sign_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7331 cairo_surface_destroy(sign_surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7332 cairo_destroy(bg_cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7333 cairo_surface_destroy(bg_surf); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7334 cairo_destroy(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7335 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7336 if (!gui.by_signal) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7337 gtk_widget_queue_draw_area(gui.drawarea, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7338 FILL_X(col), FILL_Y(col), width, height); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7339 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7340 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7341 # else /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 7342 gdk_gc_set_foreground(gui.text_gc, gui.bgcolor); |
7343 | |
7344 gdk_draw_rectangle(gui.drawarea->window, | |
7345 gui.text_gc, | |
7346 TRUE, | |
7347 FILL_X(col), | |
7348 FILL_Y(row), | |
7349 SIGN_WIDTH, | |
7350 SIGN_HEIGHT); | |
7351 | |
7352 gdk_pixbuf_render_to_drawable_alpha(sign, | |
7353 gui.drawarea->window, | |
7354 MAX(0, xoffset), | |
7355 MAX(0, yoffset), | |
7356 FILL_X(col) - MIN(0, xoffset), | |
7357 FILL_Y(row) - MIN(0, yoffset), | |
7358 MIN(width, SIGN_WIDTH), | |
7359 MIN(height, SIGN_HEIGHT), | |
7360 GDK_PIXBUF_ALPHA_BILEVEL, | |
7361 127, | |
7362 GDK_RGB_DITHER_NORMAL, | |
7363 0, 0); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7870
diff
changeset
|
7364 # endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 7365 if (need_scale) |
7366 g_object_unref(sign); | |
7367 } | |
7368 } | |
7369 | |
7370 void * | |
7371 gui_mch_register_sign(char_u *signfile) | |
7372 { | |
7373 if (signfile[0] != NUL && signfile[0] != '-' && gui.in_use) | |
7374 { | |
7375 GdkPixbuf *sign; | |
7376 GError *error = NULL; | |
7377 char_u *message; | |
7378 | |
7379 sign = gdk_pixbuf_new_from_file((const char *)signfile, &error); | |
7380 | |
7381 if (error == NULL) | |
7382 return sign; | |
7383 | |
7384 message = (char_u *)error->message; | |
7385 | |
7386 if (message != NULL && input_conv.vc_type != CONV_NONE) | |
7387 message = string_convert(&input_conv, message, NULL); | |
7388 | |
7389 if (message != NULL) | |
7390 { | |
7391 /* The error message is already translated and will be more | |
7392 * descriptive than anything we could possibly do ourselves. */ | |
7393 EMSG2("E255: %s", message); | |
7394 | |
7395 if (input_conv.vc_type != CONV_NONE) | |
7396 vim_free(message); | |
7397 } | |
7398 g_error_free(error); | |
7399 } | |
7400 | |
7401 return NULL; | |
7402 } | |
7403 | |
7404 void | |
7405 gui_mch_destroy_sign(void *sign) | |
7406 { | |
7407 if (sign != NULL) | |
7408 g_object_unref(sign); | |
7409 } | |
7410 | |
7411 #endif /* FEAT_SIGN_ICONS */ |