Mercurial > vim
annotate src/gui_beval.c @ 12865:ebb4f6c93598 v8.0.1309
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
commit https://github.com/vim/vim/commit/51b0f3701ecb440aa72ab6017c1df6940c0e0f6f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Nov 18 18:52:04 2017 +0100
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Problem: Cannot use 'balloonexpr' in a terminal.
Solution: Add 'balloonevalterm' and add code to handle mouse movements in a
terminal. Initial implementation for Unix with GUI.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 18 Nov 2017 19:00:06 +0100 |
parents | 972ea22c946f |
children | 1a450ce6980c |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9630
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * Visual Workshop integration by Gordon Prieur | |
5 * | |
6 * Do ":help uganda" in Vim to read copying and usage conditions. | |
7 * Do ":help credits" in Vim to see a list of people who contributed. | |
8 * See README.txt for an overview of the Vim source code. | |
9 */ | |
10 | |
11 #include "vim.h" | |
12 | |
13 #if defined(FEAT_BEVAL) || defined(PROTO) | |
14 | |
192 | 15 /* |
16 * Common code, invoked when the mouse is resting for a moment. | |
17 */ | |
18 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
19 general_beval_cb(BalloonEval *beval, int state UNUSED) |
192 | 20 { |
2251
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
1887
diff
changeset
|
21 #ifdef FEAT_EVAL |
192 | 22 win_T *wp; |
23 int col; | |
634 | 24 int use_sandbox; |
192 | 25 linenr_T lnum; |
26 char_u *text; | |
27 static char_u *result = NULL; | |
28 long winnr = 0; | |
791 | 29 char_u *bexpr; |
30 buf_T *save_curbuf; | |
6297 | 31 size_t len; |
192 | 32 win_T *cw; |
640 | 33 #endif |
865 | 34 static int recursive = FALSE; |
192 | 35 |
36 /* Don't do anything when 'ballooneval' is off, messages scrolled the | |
37 * windows up or we have no beval area. */ | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
38 if (!((gui.in_use && p_beval) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
39 # ifdef FEAT_BEVALTERM |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
40 || (!gui.in_use && p_bevalterm) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
41 # endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
42 ) || beval == NULL || msg_scrolled > 0) |
192 | 43 return; |
44 | |
865 | 45 /* Don't do this recursively. Happens when the expression evaluation |
46 * takes a long time and invokes something that checks for CTRL-C typed. */ | |
47 if (recursive) | |
48 return; | |
49 recursive = TRUE; | |
50 | |
192 | 51 #ifdef FEAT_EVAL |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
52 if (get_beval_info(beval, TRUE, &wp, &lnum, &text, &col) == OK) |
192 | 53 { |
791 | 54 bexpr = (*wp->w_buffer->b_p_bexpr == NUL) ? p_bexpr |
55 : wp->w_buffer->b_p_bexpr; | |
56 if (*bexpr != NUL) | |
57 { | |
58 /* Convert window pointer to number. */ | |
59 for (cw = firstwin; cw != wp; cw = cw->w_next) | |
60 ++winnr; | |
192 | 61 |
791 | 62 set_vim_var_nr(VV_BEVAL_BUFNR, (long)wp->w_buffer->b_fnum); |
63 set_vim_var_nr(VV_BEVAL_WINNR, winnr); | |
9217
9495e43a800d
commit https://github.com/vim/vim/commit/c9721bdc63378cc6123e775ffe43e9cba30322b3
Christian Brabandt <cb@256bit.org>
parents:
8926
diff
changeset
|
64 set_vim_var_nr(VV_BEVAL_WINID, wp->w_id); |
791 | 65 set_vim_var_nr(VV_BEVAL_LNUM, (long)lnum); |
66 set_vim_var_nr(VV_BEVAL_COL, (long)(col + 1)); | |
67 set_vim_var_string(VV_BEVAL_TEXT, text, -1); | |
68 vim_free(text); | |
634 | 69 |
791 | 70 /* |
71 * Temporarily change the curbuf, so that we can determine whether | |
1228 | 72 * the buffer-local balloonexpr option was set insecurely. |
791 | 73 */ |
74 save_curbuf = curbuf; | |
75 curbuf = wp->w_buffer; | |
76 use_sandbox = was_set_insecurely((char_u *)"balloonexpr", | |
77 *curbuf->b_p_bexpr == NUL ? 0 : OPT_LOCAL); | |
78 curbuf = save_curbuf; | |
79 if (use_sandbox) | |
80 ++sandbox; | |
81 ++textlock; | |
634 | 82 |
791 | 83 vim_free(result); |
84 result = eval_to_string(bexpr, NULL, TRUE); | |
85 | |
6297 | 86 /* Remove one trailing newline, it is added when the result was a |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
87 * list and it's hardly ever useful. If the user really wants a |
6297 | 88 * trailing newline he can add two and one remains. */ |
89 if (result != NULL) | |
90 { | |
91 len = STRLEN(result); | |
92 if (len > 0 && result[len - 1] == NL) | |
93 result[len - 1] = NUL; | |
94 } | |
95 | |
791 | 96 if (use_sandbox) |
97 --sandbox; | |
98 --textlock; | |
192 | 99 |
791 | 100 set_vim_var_string(VV_BEVAL_TEXT, NULL, -1); |
101 if (result != NULL && result[0] != NUL) | |
102 { | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
103 post_balloon(beval, result); |
865 | 104 recursive = FALSE; |
791 | 105 return; |
106 } | |
192 | 107 } |
108 } | |
109 #endif | |
110 #ifdef FEAT_NETBEANS_INTG | |
111 if (bevalServers & BEVAL_NETBEANS) | |
112 netbeans_beval_cb(beval, state); | |
113 #endif | |
114 #ifdef FEAT_SUN_WORKSHOP | |
115 if (bevalServers & BEVAL_WORKSHOP) | |
116 workshop_beval_cb(beval, state); | |
117 #endif | |
865 | 118 |
119 recursive = FALSE; | |
192 | 120 } |
121 | |
122 /* on Win32 only get_beval_info() is required */ | |
7 | 123 #if !defined(FEAT_GUI_W32) || defined(PROTO) |
124 | |
125 #ifdef FEAT_GUI_GTK | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
126 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
127 # include <gdk/gdkkeysyms-compat.h> |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
128 # else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
129 # include <gdk/gdkkeysyms.h> |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
130 # endif |
7 | 131 # include <gtk/gtk.h> |
132 #else | |
133 # include <X11/keysym.h> | |
134 # ifdef FEAT_GUI_MOTIF | |
135 # include <Xm/PushB.h> | |
136 # include <Xm/Separator.h> | |
137 # include <Xm/List.h> | |
138 # include <Xm/Label.h> | |
139 # include <Xm/AtomMgr.h> | |
140 # include <Xm/Protocols.h> | |
141 # else | |
142 /* Assume Athena */ | |
143 # include <X11/Shell.h> | |
680 | 144 # ifdef FEAT_GUI_NEXTAW |
145 # include <X11/neXtaw/Label.h> | |
146 # else | |
147 # include <X11/Xaw/Label.h> | |
148 # endif | |
7 | 149 # endif |
150 #endif | |
151 | |
152 #include "gui_beval.h" | |
153 | |
154 #ifndef FEAT_GUI_GTK | |
155 extern Widget vimShell; | |
156 | |
157 /* | |
158 * Currently, we assume that there can be only one BalloonEval showing | |
159 * on-screen at any given moment. This variable will hold the currently | |
160 * showing BalloonEval or NULL if none is showing. | |
161 */ | |
162 static BalloonEval *current_beval = NULL; | |
163 #endif | |
164 | |
165 #ifdef FEAT_GUI_GTK | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6297
diff
changeset
|
166 static void addEventHandler(GtkWidget *, BalloonEval *); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6297
diff
changeset
|
167 static void removeEventHandler(BalloonEval *); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6297
diff
changeset
|
168 static gint target_event_cb(GtkWidget *, GdkEvent *, gpointer); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6297
diff
changeset
|
169 static gint mainwin_event_cb(GtkWidget *, GdkEvent *, gpointer); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6297
diff
changeset
|
170 static void pointer_event(BalloonEval *, int, int, unsigned); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6297
diff
changeset
|
171 static void key_event(BalloonEval *, unsigned, int); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
172 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
173 static gboolean timeout_cb(gpointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
174 # else |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6297
diff
changeset
|
175 static gint timeout_cb(gpointer); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
176 # endif |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
177 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
178 static gboolean balloon_draw_event_cb (GtkWidget *, cairo_t *, gpointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
179 # else |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
180 static gint balloon_expose_event_cb (GtkWidget *, GdkEventExpose *, gpointer); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
181 # endif |
7 | 182 #else |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6297
diff
changeset
|
183 static void addEventHandler(Widget, BalloonEval *); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6297
diff
changeset
|
184 static void removeEventHandler(BalloonEval *); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6297
diff
changeset
|
185 static void pointerEventEH(Widget, XtPointer, XEvent *, Boolean *); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6297
diff
changeset
|
186 static void pointerEvent(BalloonEval *, XEvent *); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6297
diff
changeset
|
187 static void timerRoutine(XtPointer, XtIntervalId *); |
7 | 188 #endif |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6297
diff
changeset
|
189 static void cancelBalloon(BalloonEval *); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6297
diff
changeset
|
190 static void requestBalloon(BalloonEval *); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6297
diff
changeset
|
191 static void drawBalloon(BalloonEval *); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6297
diff
changeset
|
192 static void undrawBalloon(BalloonEval *beval); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
6297
diff
changeset
|
193 static void createBalloonEvalWindow(BalloonEval *); |
7 | 194 |
195 | |
196 | |
197 /* | |
198 * Create a balloon-evaluation area for a Widget. | |
199 * There can be either a "mesg" for a fixed string or "mesgCB" to generate a | |
200 * message by calling this callback function. | |
201 * When "mesg" is not NULL it must remain valid for as long as the balloon is | |
202 * used. It is not freed here. | |
203 * Returns a pointer to the resulting object (NULL when out of memory). | |
204 */ | |
205 BalloonEval * | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
206 gui_mch_create_beval_area( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
207 void *target, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
208 char_u *mesg, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
209 void (*mesgCB)(BalloonEval *, int), |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
210 void *clientData) |
7 | 211 { |
212 #ifndef FEAT_GUI_GTK | |
213 char *display_name; /* get from gui.dpy */ | |
214 int screen_num; | |
215 char *p; | |
216 #endif | |
217 BalloonEval *beval; | |
218 | |
219 if (mesg != NULL && mesgCB != NULL) | |
220 { | |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10176
diff
changeset
|
221 IEMSG(_("E232: Cannot create BalloonEval with both message and callback")); |
7 | 222 return NULL; |
223 } | |
224 | |
225 beval = (BalloonEval *)alloc(sizeof(BalloonEval)); | |
226 if (beval != NULL) | |
227 { | |
228 #ifdef FEAT_GUI_GTK | |
229 beval->target = GTK_WIDGET(target); | |
230 beval->balloonShell = NULL; | |
231 beval->timerID = 0; | |
232 #else | |
233 beval->target = (Widget)target; | |
234 beval->balloonShell = NULL; | |
235 beval->timerID = (XtIntervalId)NULL; | |
236 beval->appContext = XtWidgetToApplicationContext((Widget)target); | |
237 #endif | |
238 beval->showState = ShS_NEUTRAL; | |
239 beval->x = 0; | |
240 beval->y = 0; | |
241 beval->msg = mesg; | |
242 beval->msgCB = mesgCB; | |
243 beval->clientData = clientData; | |
244 | |
245 /* | |
246 * Set up event handler which will keep its eyes on the pointer, | |
247 * and when the pointer rests in a certain spot for a given time | |
248 * interval, show the beval. | |
249 */ | |
250 addEventHandler(beval->target, beval); | |
251 createBalloonEvalWindow(beval); | |
252 | |
253 #ifndef FEAT_GUI_GTK | |
254 /* | |
255 * Now create and save the screen width and height. Used in drawing. | |
256 */ | |
257 display_name = DisplayString(gui.dpy); | |
258 p = strrchr(display_name, '.'); | |
259 if (p != NULL) | |
260 screen_num = atoi(++p); | |
261 else | |
262 screen_num = 0; | |
263 beval->screen_width = DisplayWidth(gui.dpy, screen_num); | |
264 beval->screen_height = DisplayHeight(gui.dpy, screen_num); | |
265 #endif | |
266 } | |
267 | |
268 return beval; | |
269 } | |
270 | |
271 #if defined(FEAT_BEVAL_TIP) || defined(PROTO) | |
272 /* | |
1228 | 273 * Destroy a balloon-eval and free its associated memory. |
7 | 274 */ |
275 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
276 gui_mch_destroy_beval_area(BalloonEval *beval) |
7 | 277 { |
278 cancelBalloon(beval); | |
279 removeEventHandler(beval); | |
280 /* Children will automatically be destroyed */ | |
281 # ifdef FEAT_GUI_GTK | |
282 gtk_widget_destroy(beval->balloonShell); | |
283 # else | |
284 XtDestroyWidget(beval->balloonShell); | |
285 # endif | |
286 vim_free(beval); | |
287 } | |
288 #endif | |
289 | |
290 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
291 gui_mch_enable_beval_area(BalloonEval *beval) |
7 | 292 { |
293 if (beval != NULL) | |
294 addEventHandler(beval->target, beval); | |
295 } | |
296 | |
297 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
298 gui_mch_disable_beval_area(BalloonEval *beval) |
7 | 299 { |
300 if (beval != NULL) | |
301 removeEventHandler(beval); | |
302 } | |
303 | |
304 #if defined(FEAT_BEVAL_TIP) || defined(PROTO) | |
305 /* | |
306 * This function returns the BalloonEval * associated with the currently | |
307 * displayed tooltip. Returns NULL if there is no tooltip currently showing. | |
308 * | |
309 * Assumption: Only one tooltip can be shown at a time. | |
310 */ | |
311 BalloonEval * | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
312 gui_mch_currently_showing_beval(void) |
7 | 313 { |
314 return current_beval; | |
315 } | |
316 #endif | |
317 #endif /* !FEAT_GUI_W32 */ | |
318 | |
192 | 319 #if defined(FEAT_SUN_WORKSHOP) || defined(FEAT_NETBEANS_INTG) \ |
320 || defined(FEAT_EVAL) || defined(PROTO) | |
7 | 321 /* |
322 * Get the text and position to be evaluated for "beval". | |
192 | 323 * If "getword" is true the returned text is not the whole line but the |
324 * relevant word in allocated memory. | |
7 | 325 * Returns OK or FAIL. |
326 */ | |
327 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
328 get_beval_info( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
329 BalloonEval *beval, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
330 int getword, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
331 win_T **winp, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
332 linenr_T *lnump, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
333 char_u **textp, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
334 int *colp) |
7 | 335 { |
336 win_T *wp; | |
337 int row, col; | |
338 char_u *lbuf; | |
339 linenr_T lnum; | |
340 | |
192 | 341 *textp = NULL; |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
342 # ifdef FEAT_BEVALTERM |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
343 if (!gui.in_use) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
344 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
345 row = mouse_row; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
346 col = mouse_col; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
347 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
348 else |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
349 # endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
350 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
351 row = Y_2_ROW(beval->y); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
352 col = X_2_COL(beval->x); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
353 } |
7 | 354 wp = mouse_find_win(&row, &col); |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
355 if (wp != NULL && row < wp->w_height && col < wp->w_width) |
7 | 356 { |
357 /* Found a window and the cursor is in the text. Now find the line | |
358 * number. */ | |
359 if (!mouse_comp_pos(wp, &row, &col, &lnum)) | |
360 { | |
361 /* Not past end of the file. */ | |
362 lbuf = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
363 if (col <= win_linetabsize(wp, lbuf, (colnr_T)MAXCOL)) | |
364 { | |
365 /* Not past end of line. */ | |
192 | 366 if (getword) |
7 | 367 { |
368 /* For Netbeans we get the relevant part of the line | |
369 * instead of the whole line. */ | |
370 int len; | |
371 pos_T *spos = NULL, *epos = NULL; | |
372 | |
373 if (VIsual_active) | |
374 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10390
diff
changeset
|
375 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 376 { |
377 spos = &VIsual; | |
378 epos = &curwin->w_cursor; | |
379 } | |
380 else | |
381 { | |
382 spos = &curwin->w_cursor; | |
383 epos = &VIsual; | |
384 } | |
385 } | |
386 | |
3877 | 387 col = vcol2col(wp, lnum, col); |
7 | 388 |
389 if (VIsual_active | |
390 && wp->w_buffer == curwin->w_buffer | |
391 && (lnum == spos->lnum | |
392 ? col >= (int)spos->col | |
393 : lnum > spos->lnum) | |
394 && (lnum == epos->lnum | |
395 ? col <= (int)epos->col | |
396 : lnum < epos->lnum)) | |
397 { | |
398 /* Visual mode and pointing to the line with the | |
399 * Visual selection: return selected text, with a | |
400 * maximum of one line. */ | |
401 if (spos->lnum != epos->lnum || spos->col == epos->col) | |
402 return FAIL; | |
403 | |
404 lbuf = ml_get_buf(curwin->w_buffer, VIsual.lnum, FALSE); | |
3877 | 405 len = epos->col - spos->col; |
406 if (*p_sel != 'e') | |
407 len += MB_PTR2LEN(lbuf + epos->col); | |
408 lbuf = vim_strnsave(lbuf + spos->col, len); | |
7 | 409 lnum = spos->lnum; |
410 col = spos->col; | |
411 } | |
412 else | |
413 { | |
414 /* Find the word under the cursor. */ | |
415 ++emsg_off; | |
416 len = find_ident_at_pos(wp, lnum, (colnr_T)col, &lbuf, | |
417 FIND_IDENT + FIND_STRING + FIND_EVAL); | |
418 --emsg_off; | |
419 if (len == 0) | |
420 return FAIL; | |
421 lbuf = vim_strnsave(lbuf, len); | |
422 } | |
423 } | |
192 | 424 |
425 *winp = wp; | |
426 *lnump = lnum; | |
427 *textp = lbuf; | |
428 *colp = col; | |
7 | 429 beval->ts = wp->w_buffer->b_p_ts; |
430 return OK; | |
431 } | |
432 } | |
433 } | |
434 | |
435 return FAIL; | |
436 } | |
437 | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
438 /* |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
439 * Show a balloon with "mesg". |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
440 */ |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
441 void |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
442 post_balloon(BalloonEval *beval, char_u *mesg) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
443 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
444 # ifdef FEAT_BEVALTERM |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
445 if (!gui.in_use) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
446 ui_post_balloon(mesg); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
447 else |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
448 # endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
449 gui_mch_post_balloon(beval, mesg); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
450 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
451 |
7 | 452 # if !defined(FEAT_GUI_W32) || defined(PROTO) |
453 | |
454 /* | |
455 * Show a balloon with "mesg". | |
456 */ | |
457 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
458 gui_mch_post_balloon(BalloonEval *beval, char_u *mesg) |
7 | 459 { |
460 beval->msg = mesg; | |
461 if (mesg != NULL) | |
462 drawBalloon(beval); | |
463 else | |
464 undrawBalloon(beval); | |
465 } | |
466 # endif /* FEAT_GUI_W32 */ | |
467 #endif /* FEAT_SUN_WORKSHOP || FEAT_NETBEANS_INTG || PROTO */ | |
468 | |
469 #if !defined(FEAT_GUI_W32) || defined(PROTO) | |
470 #if defined(FEAT_BEVAL_TIP) || defined(PROTO) | |
471 /* | |
472 * Hide the given balloon. | |
473 */ | |
474 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
475 gui_mch_unpost_balloon(BalloonEval *beval) |
7 | 476 { |
477 undrawBalloon(beval); | |
478 } | |
479 #endif | |
480 | |
481 #ifdef FEAT_GUI_GTK | |
482 static void | |
483 addEventHandler(GtkWidget *target, BalloonEval *beval) | |
484 { | |
485 /* | |
486 * Connect to the generic "event" signal instead of the individual | |
487 * signals for each event type, because the former is emitted earlier. | |
488 * This allows us to catch events independently of the signal handlers | |
489 * in gui_gtk_x11.c. | |
490 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
491 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
492 g_signal_connect(G_OBJECT(target), "event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
493 G_CALLBACK(target_event_cb), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
494 beval); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
495 # else |
7 | 496 /* Should use GTK_OBJECT() here, but that causes a lint warning... */ |
497 gtk_signal_connect((GtkObject*)(target), "event", | |
498 GTK_SIGNAL_FUNC(target_event_cb), | |
499 beval); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
500 # endif |
7 | 501 /* |
502 * Nasty: Key press events go to the main window thus the drawing area | |
503 * will never see them. This means we have to connect to the main window | |
504 * as well in order to catch those events. | |
505 */ | |
506 if (gtk_socket_id == 0 && gui.mainwin != NULL | |
507 && gtk_widget_is_ancestor(target, gui.mainwin)) | |
508 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
509 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
510 g_signal_connect(G_OBJECT(gui.mainwin), "event", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
511 G_CALLBACK(mainwin_event_cb), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
512 beval); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
513 # else |
7 | 514 gtk_signal_connect((GtkObject*)(gui.mainwin), "event", |
515 GTK_SIGNAL_FUNC(mainwin_event_cb), | |
516 beval); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
517 # endif |
7 | 518 } |
519 } | |
520 | |
521 static void | |
522 removeEventHandler(BalloonEval *beval) | |
523 { | |
137 | 524 /* LINTED: avoid warning: dubious operation on enum */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
525 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
526 g_signal_handlers_disconnect_by_func(G_OBJECT(beval->target), |
10176
51888fb2599f
commit https://github.com/vim/vim/commit/d47d83745ff450232328ca7a4b8b00b31bad22fc
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
527 FUNC2GENERIC(target_event_cb), |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
528 beval); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
529 # else |
7 | 530 gtk_signal_disconnect_by_func((GtkObject*)(beval->target), |
531 GTK_SIGNAL_FUNC(target_event_cb), | |
532 beval); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
533 # endif |
7 | 534 |
535 if (gtk_socket_id == 0 && gui.mainwin != NULL | |
536 && gtk_widget_is_ancestor(beval->target, gui.mainwin)) | |
537 { | |
137 | 538 /* LINTED: avoid warning: dubious operation on enum */ |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
539 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
540 g_signal_handlers_disconnect_by_func(G_OBJECT(gui.mainwin), |
10176
51888fb2599f
commit https://github.com/vim/vim/commit/d47d83745ff450232328ca7a4b8b00b31bad22fc
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
541 FUNC2GENERIC(mainwin_event_cb), |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
542 beval); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
543 # else |
7 | 544 gtk_signal_disconnect_by_func((GtkObject*)(gui.mainwin), |
545 GTK_SIGNAL_FUNC(mainwin_event_cb), | |
546 beval); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
547 # endif |
7 | 548 } |
549 } | |
550 | |
551 static gint | |
552 target_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data) | |
553 { | |
554 BalloonEval *beval = (BalloonEval *)data; | |
555 | |
556 switch (event->type) | |
557 { | |
558 case GDK_ENTER_NOTIFY: | |
559 pointer_event(beval, (int)event->crossing.x, | |
560 (int)event->crossing.y, | |
561 event->crossing.state); | |
562 break; | |
563 case GDK_MOTION_NOTIFY: | |
564 if (event->motion.is_hint) | |
565 { | |
566 int x; | |
567 int y; | |
568 GdkModifierType state; | |
569 /* | |
570 * GDK_POINTER_MOTION_HINT_MASK is set, thus we cannot obtain | |
571 * the coordinates from the GdkEventMotion struct directly. | |
572 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
573 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
574 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
575 GdkWindow * const win = gtk_widget_get_window(widget); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
576 GdkDisplay * const dpy = gdk_window_get_display(win); |
8926
fc69eed19ba7
commit https://github.com/vim/vim/commit/30e12d259ee78272359f9da2655d0593a4f6a626
Christian Brabandt <cb@256bit.org>
parents:
8218
diff
changeset
|
577 # if GTK_CHECK_VERSION(3,20,0) |
fc69eed19ba7
commit https://github.com/vim/vim/commit/30e12d259ee78272359f9da2655d0593a4f6a626
Christian Brabandt <cb@256bit.org>
parents:
8218
diff
changeset
|
578 GdkSeat * const seat = gdk_display_get_default_seat(dpy); |
fc69eed19ba7
commit https://github.com/vim/vim/commit/30e12d259ee78272359f9da2655d0593a4f6a626
Christian Brabandt <cb@256bit.org>
parents:
8218
diff
changeset
|
579 GdkDevice * const dev = gdk_seat_get_pointer(seat); |
fc69eed19ba7
commit https://github.com/vim/vim/commit/30e12d259ee78272359f9da2655d0593a4f6a626
Christian Brabandt <cb@256bit.org>
parents:
8218
diff
changeset
|
580 # else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
581 GdkDeviceManager * const mngr = gdk_display_get_device_manager(dpy); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
582 GdkDevice * const dev = gdk_device_manager_get_client_pointer(mngr); |
8926
fc69eed19ba7
commit https://github.com/vim/vim/commit/30e12d259ee78272359f9da2655d0593a4f6a626
Christian Brabandt <cb@256bit.org>
parents:
8218
diff
changeset
|
583 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
584 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:
7821
diff
changeset
|
585 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
586 # else |
7 | 587 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:
7821
diff
changeset
|
588 # endif |
7 | 589 pointer_event(beval, x, y, (unsigned int)state); |
590 } | |
591 else | |
592 { | |
593 pointer_event(beval, (int)event->motion.x, | |
594 (int)event->motion.y, | |
595 event->motion.state); | |
596 } | |
597 break; | |
598 case GDK_LEAVE_NOTIFY: | |
599 /* | |
600 * Ignore LeaveNotify events that are not "normal". | |
601 * Apparently we also get it when somebody else grabs focus. | |
602 */ | |
603 if (event->crossing.mode == GDK_CROSSING_NORMAL) | |
604 cancelBalloon(beval); | |
605 break; | |
606 case GDK_BUTTON_PRESS: | |
607 case GDK_SCROLL: | |
608 cancelBalloon(beval); | |
609 break; | |
610 case GDK_KEY_PRESS: | |
611 key_event(beval, event->key.keyval, TRUE); | |
612 break; | |
613 case GDK_KEY_RELEASE: | |
614 key_event(beval, event->key.keyval, FALSE); | |
615 break; | |
616 default: | |
617 break; | |
618 } | |
619 | |
620 return FALSE; /* continue emission */ | |
621 } | |
622 | |
623 static gint | |
1884 | 624 mainwin_event_cb(GtkWidget *widget UNUSED, GdkEvent *event, gpointer data) |
7 | 625 { |
626 BalloonEval *beval = (BalloonEval *)data; | |
627 | |
628 switch (event->type) | |
629 { | |
630 case GDK_KEY_PRESS: | |
631 key_event(beval, event->key.keyval, TRUE); | |
632 break; | |
633 case GDK_KEY_RELEASE: | |
634 key_event(beval, event->key.keyval, FALSE); | |
635 break; | |
636 default: | |
637 break; | |
638 } | |
639 | |
640 return FALSE; /* continue emission */ | |
641 } | |
642 | |
643 static void | |
644 pointer_event(BalloonEval *beval, int x, int y, unsigned state) | |
645 { | |
646 int distance; | |
647 | |
648 distance = ABS(x - beval->x) + ABS(y - beval->y); | |
649 | |
650 if (distance > 4) | |
651 { | |
652 /* | |
653 * Moved out of the balloon location: cancel it. | |
654 * Remember button state | |
655 */ | |
656 beval->state = state; | |
657 cancelBalloon(beval); | |
658 | |
659 /* Mouse buttons are pressed - no balloon now */ | |
660 if (!(state & ((int)GDK_BUTTON1_MASK | (int)GDK_BUTTON2_MASK | |
661 | (int)GDK_BUTTON3_MASK))) | |
662 { | |
663 beval->x = x; | |
664 beval->y = y; | |
665 | |
666 if (state & (int)GDK_MOD1_MASK) | |
667 { | |
668 /* | |
669 * Alt is pressed -- enter super-evaluate-mode, | |
670 * where there is no time delay | |
671 */ | |
672 if (beval->msgCB != NULL) | |
673 { | |
674 beval->showState = ShS_PENDING; | |
675 (*beval->msgCB)(beval, state); | |
676 } | |
677 } | |
678 else | |
679 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
680 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
681 beval->timerID = g_timeout_add((guint)p_bdlay, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
682 &timeout_cb, beval); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
683 # else |
7 | 684 beval->timerID = gtk_timeout_add((guint32)p_bdlay, |
685 &timeout_cb, beval); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
686 # endif |
7 | 687 } |
688 } | |
689 } | |
690 } | |
691 | |
692 static void | |
693 key_event(BalloonEval *beval, unsigned keyval, int is_keypress) | |
694 { | |
695 if (beval->showState == ShS_SHOWING && beval->msgCB != NULL) | |
696 { | |
697 switch (keyval) | |
698 { | |
699 case GDK_Shift_L: | |
700 case GDK_Shift_R: | |
701 beval->showState = ShS_UPDATE_PENDING; | |
702 (*beval->msgCB)(beval, (is_keypress) | |
703 ? (int)GDK_SHIFT_MASK : 0); | |
704 break; | |
705 case GDK_Control_L: | |
706 case GDK_Control_R: | |
707 beval->showState = ShS_UPDATE_PENDING; | |
708 (*beval->msgCB)(beval, (is_keypress) | |
709 ? (int)GDK_CONTROL_MASK : 0); | |
710 break; | |
711 default: | |
667 | 712 /* Don't do this for key release, we apparently get these with |
713 * focus changes in some GTK version. */ | |
714 if (is_keypress) | |
715 cancelBalloon(beval); | |
7 | 716 break; |
717 } | |
718 } | |
719 else | |
720 cancelBalloon(beval); | |
721 } | |
722 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
723 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
724 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
725 # else |
7 | 726 static gint |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
727 # endif |
7 | 728 timeout_cb(gpointer data) |
729 { | |
730 BalloonEval *beval = (BalloonEval *)data; | |
731 | |
732 beval->timerID = 0; | |
733 /* | |
734 * If the timer event happens then the mouse has stopped long enough for | |
735 * a request to be started. The request will only send to the debugger if | |
736 * there the mouse is pointing at real data. | |
737 */ | |
738 requestBalloon(beval); | |
739 | |
740 return FALSE; /* don't call me again */ | |
741 } | |
742 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
743 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
744 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
745 balloon_draw_event_cb(GtkWidget *widget, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
746 cairo_t *cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
747 gpointer data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
748 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
749 GtkStyleContext *context = NULL; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
750 gint width = -1, height = -1; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
751 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
752 if (widget == NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
753 return TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
754 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
755 context = gtk_widget_get_style_context(widget); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
756 width = gtk_widget_get_allocated_width(widget); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
757 height = gtk_widget_get_allocated_height(widget); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
758 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
759 gtk_style_context_save(context); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
760 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
761 gtk_style_context_add_class(context, "tooltip"); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
762 gtk_style_context_set_state(context, GTK_STATE_FLAG_NORMAL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
763 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
764 cairo_save(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
765 gtk_render_frame(context, cr, 0, 0, width, height); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
766 gtk_render_background(context, cr, 0, 0, width, height); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
767 cairo_restore(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
768 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
769 gtk_style_context_restore(context); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
770 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
771 return FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
772 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
773 # else |
7 | 774 static gint |
1884 | 775 balloon_expose_event_cb(GtkWidget *widget, |
776 GdkEventExpose *event, | |
777 gpointer data UNUSED) | |
7 | 778 { |
779 gtk_paint_flat_box(widget->style, widget->window, | |
780 GTK_STATE_NORMAL, GTK_SHADOW_OUT, | |
781 &event->area, widget, "tooltip", | |
782 0, 0, -1, -1); | |
783 | |
784 return FALSE; /* continue emission */ | |
785 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
786 # endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 787 |
788 #else /* !FEAT_GUI_GTK */ | |
789 | |
790 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
791 addEventHandler(Widget target, BalloonEval *beval) |
7 | 792 { |
793 XtAddEventHandler(target, | |
794 PointerMotionMask | EnterWindowMask | | |
795 LeaveWindowMask | ButtonPressMask | KeyPressMask | | |
796 KeyReleaseMask, | |
797 False, | |
798 pointerEventEH, (XtPointer)beval); | |
799 } | |
800 | |
801 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
802 removeEventHandler(BalloonEval *beval) |
7 | 803 { |
804 XtRemoveEventHandler(beval->target, | |
805 PointerMotionMask | EnterWindowMask | | |
806 LeaveWindowMask | ButtonPressMask | KeyPressMask | | |
807 KeyReleaseMask, | |
808 False, | |
809 pointerEventEH, (XtPointer)beval); | |
810 } | |
811 | |
812 | |
813 /* | |
814 * The X event handler. All it does is call the real event handler. | |
815 */ | |
816 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
817 pointerEventEH( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
818 Widget w UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
819 XtPointer client_data, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
820 XEvent *event, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
821 Boolean *unused UNUSED) |
7 | 822 { |
823 BalloonEval *beval = (BalloonEval *)client_data; | |
824 pointerEvent(beval, event); | |
825 } | |
826 | |
827 | |
828 /* | |
829 * The real event handler. Called by pointerEventEH() whenever an event we are | |
1228 | 830 * interested in occurs. |
7 | 831 */ |
832 | |
833 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
834 pointerEvent(BalloonEval *beval, XEvent *event) |
7 | 835 { |
4352 | 836 Position distance; /* a measure of how much the pointer moved */ |
7 | 837 Position delta; /* used to compute distance */ |
838 | |
839 switch (event->type) | |
840 { | |
841 case EnterNotify: | |
842 case MotionNotify: | |
843 delta = event->xmotion.x - beval->x; | |
844 if (delta < 0) | |
845 delta = -delta; | |
846 distance = delta; | |
847 delta = event->xmotion.y - beval->y; | |
848 if (delta < 0) | |
849 delta = -delta; | |
850 distance += delta; | |
851 if (distance > 4) | |
852 { | |
853 /* | |
854 * Moved out of the balloon location: cancel it. | |
855 * Remember button state | |
856 */ | |
857 beval->state = event->xmotion.state; | |
858 if (beval->state & (Button1Mask|Button2Mask|Button3Mask)) | |
859 { | |
860 /* Mouse buttons are pressed - no balloon now */ | |
861 cancelBalloon(beval); | |
862 } | |
863 else if (beval->state & (Mod1Mask|Mod2Mask|Mod3Mask)) | |
864 { | |
865 /* | |
866 * Alt is pressed -- enter super-evaluate-mode, | |
867 * where there is no time delay | |
868 */ | |
869 beval->x = event->xmotion.x; | |
870 beval->y = event->xmotion.y; | |
871 beval->x_root = event->xmotion.x_root; | |
872 beval->y_root = event->xmotion.y_root; | |
873 cancelBalloon(beval); | |
874 if (beval->msgCB != NULL) | |
875 { | |
876 beval->showState = ShS_PENDING; | |
877 (*beval->msgCB)(beval, beval->state); | |
878 } | |
879 } | |
880 else | |
881 { | |
882 beval->x = event->xmotion.x; | |
883 beval->y = event->xmotion.y; | |
884 beval->x_root = event->xmotion.x_root; | |
885 beval->y_root = event->xmotion.y_root; | |
886 cancelBalloon(beval); | |
887 beval->timerID = XtAppAddTimeOut( beval->appContext, | |
888 (long_u)p_bdlay, timerRoutine, beval); | |
889 } | |
890 } | |
891 break; | |
892 | |
893 /* | |
894 * Motif and Athena version: Keystrokes will be caught by the | |
895 * "textArea" widget, and handled in gui_x11_key_hit_cb(). | |
896 */ | |
897 case KeyPress: | |
898 if (beval->showState == ShS_SHOWING && beval->msgCB != NULL) | |
899 { | |
900 Modifiers modifier; | |
901 KeySym keysym; | |
902 | |
903 XtTranslateKeycode(gui.dpy, | |
904 event->xkey.keycode, event->xkey.state, | |
905 &modifier, &keysym); | |
906 if (keysym == XK_Shift_L || keysym == XK_Shift_R) | |
907 { | |
908 beval->showState = ShS_UPDATE_PENDING; | |
909 (*beval->msgCB)(beval, ShiftMask); | |
910 } | |
911 else if (keysym == XK_Control_L || keysym == XK_Control_R) | |
912 { | |
913 beval->showState = ShS_UPDATE_PENDING; | |
914 (*beval->msgCB)(beval, ControlMask); | |
915 } | |
916 else | |
917 cancelBalloon(beval); | |
918 } | |
919 else | |
920 cancelBalloon(beval); | |
921 break; | |
922 | |
923 case KeyRelease: | |
924 if (beval->showState == ShS_SHOWING && beval->msgCB != NULL) | |
925 { | |
926 Modifiers modifier; | |
927 KeySym keysym; | |
928 | |
929 XtTranslateKeycode(gui.dpy, event->xkey.keycode, | |
930 event->xkey.state, &modifier, &keysym); | |
931 if ((keysym == XK_Shift_L) || (keysym == XK_Shift_R)) { | |
932 beval->showState = ShS_UPDATE_PENDING; | |
933 (*beval->msgCB)(beval, 0); | |
934 } | |
935 else if ((keysym == XK_Control_L) || (keysym == XK_Control_R)) | |
936 { | |
937 beval->showState = ShS_UPDATE_PENDING; | |
938 (*beval->msgCB)(beval, 0); | |
939 } | |
940 else | |
941 cancelBalloon(beval); | |
942 } | |
943 else | |
944 cancelBalloon(beval); | |
945 break; | |
946 | |
947 case LeaveNotify: | |
948 /* Ignore LeaveNotify events that are not "normal". | |
949 * Apparently we also get it when somebody else grabs focus. | |
950 * Happens for me every two seconds (some clipboard tool?) */ | |
951 if (event->xcrossing.mode == NotifyNormal) | |
952 cancelBalloon(beval); | |
953 break; | |
954 | |
955 case ButtonPress: | |
956 cancelBalloon(beval); | |
957 break; | |
958 | |
959 default: | |
960 break; | |
961 } | |
962 } | |
963 | |
964 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
965 timerRoutine(XtPointer dx, XtIntervalId *id UNUSED) |
7 | 966 { |
967 BalloonEval *beval = (BalloonEval *)dx; | |
968 | |
969 beval->timerID = (XtIntervalId)NULL; | |
970 | |
971 /* | |
972 * If the timer event happens then the mouse has stopped long enough for | |
973 * a request to be started. The request will only send to the debugger if | |
974 * there the mouse is pointing at real data. | |
975 */ | |
976 requestBalloon(beval); | |
977 } | |
978 | |
979 #endif /* !FEAT_GUI_GTK */ | |
980 | |
981 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
982 requestBalloon(BalloonEval *beval) |
7 | 983 { |
984 if (beval->showState != ShS_PENDING) | |
985 { | |
986 /* Determine the beval to display */ | |
987 if (beval->msgCB != NULL) | |
988 { | |
989 beval->showState = ShS_PENDING; | |
990 (*beval->msgCB)(beval, beval->state); | |
991 } | |
992 else if (beval->msg != NULL) | |
993 drawBalloon(beval); | |
994 } | |
995 } | |
996 | |
997 #ifdef FEAT_GUI_GTK | |
998 /* | |
999 * Convert the string to UTF-8 if 'encoding' is not "utf-8". | |
1000 * Replace any non-printable characters and invalid bytes sequences with | |
1001 * "^X" or "<xx>" escapes, and apply SpecialKey highlighting to them. | |
1002 * TAB and NL are passed through unscathed. | |
1003 */ | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1004 # define IS_NONPRINTABLE(c) (((c) < 0x20 && (c) != TAB && (c) != NL) \ |
7 | 1005 || (c) == DEL) |
1006 static void | |
944 | 1007 set_printable_label_text(GtkLabel *label, char_u *text) |
7 | 1008 { |
1009 char_u *convbuf = NULL; | |
1010 char_u *buf; | |
1011 char_u *p; | |
1012 char_u *pdest; | |
1013 unsigned int len; | |
1014 int charlen; | |
1015 int uc; | |
1016 PangoAttrList *attr_list; | |
1017 | |
1018 /* Convert to UTF-8 if it isn't already */ | |
1019 if (output_conv.vc_type != CONV_NONE) | |
1020 { | |
944 | 1021 convbuf = string_convert(&output_conv, text, NULL); |
7 | 1022 if (convbuf != NULL) |
944 | 1023 text = convbuf; |
7 | 1024 } |
1025 | |
1026 /* First let's see how much we need to allocate */ | |
1027 len = 0; | |
944 | 1028 for (p = text; *p != NUL; p += charlen) |
7 | 1029 { |
1030 if ((*p & 0x80) == 0) /* be quick for ASCII */ | |
1031 { | |
1032 charlen = 1; | |
1033 len += IS_NONPRINTABLE(*p) ? 2 : 1; /* nonprintable: ^X */ | |
1034 } | |
1035 else | |
1036 { | |
474 | 1037 charlen = utf_ptr2len(p); |
7 | 1038 uc = utf_ptr2char(p); |
1039 | |
1040 if (charlen != utf_char2len(uc)) | |
1041 charlen = 1; /* reject overlong sequences */ | |
1042 | |
1043 if (charlen == 1 || uc < 0xa0) /* illegal byte or */ | |
1044 len += 4; /* control char: <xx> */ | |
1045 else if (!utf_printable(uc)) | |
1046 /* Note: we assume here that utf_printable() doesn't | |
1047 * care about characters outside the BMP. */ | |
1048 len += 6; /* nonprintable: <xxxx> */ | |
1049 else | |
1050 len += charlen; | |
1051 } | |
1052 } | |
1053 | |
1054 attr_list = pango_attr_list_new(); | |
1055 buf = alloc(len + 1); | |
1056 | |
1057 /* Now go for the real work */ | |
1058 if (buf != NULL) | |
1059 { | |
1060 attrentry_T *aep; | |
1061 PangoAttribute *attr; | |
1062 guicolor_T pixel; | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1063 #if GTK_CHECK_VERSION(3,0,0) |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1064 GdkRGBA color = { 0.0, 0.0, 0.0, 1.0 }; |
9630
0c098fb3994c
commit https://github.com/vim/vim/commit/870b749ce1db1cec80f0f3766064a031688e6a46
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
1065 # if PANGO_VERSION_CHECK(1,38,0) |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1066 PangoAttribute *attr_alpha; |
9630
0c098fb3994c
commit https://github.com/vim/vim/commit/870b749ce1db1cec80f0f3766064a031688e6a46
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
1067 # endif |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1068 #else |
7 | 1069 GdkColor color = { 0, 0, 0, 0 }; |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1070 #endif |
7 | 1071 |
1072 /* Look up the RGB values of the SpecialKey foreground color. */ | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
1073 aep = syn_gui_attr2entry(HL_ATTR(HLF_8)); |
7 | 1074 pixel = (aep != NULL) ? aep->ae_u.gui.fg_color : INVALCOLOR; |
1075 if (pixel != INVALCOLOR) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1076 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1077 { |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1078 color.red = ((pixel & 0xff0000) >> 16) / 255.0; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1079 color.green = ((pixel & 0xff00) >> 8) / 255.0; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1080 color.blue = (pixel & 0xff) / 255.0; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1081 color.alpha = 1.0; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1082 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1083 # else |
7 | 1084 gdk_colormap_query_color(gtk_widget_get_colormap(gui.drawarea), |
1085 (unsigned long)pixel, &color); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1086 # endif |
7 | 1087 |
1088 pdest = buf; | |
944 | 1089 p = text; |
7 | 1090 while (*p != NUL) |
1091 { | |
1092 /* Be quick for ASCII */ | |
1093 if ((*p & 0x80) == 0 && !IS_NONPRINTABLE(*p)) | |
1094 { | |
1095 *pdest++ = *p++; | |
1096 } | |
1097 else | |
1098 { | |
474 | 1099 charlen = utf_ptr2len(p); |
7 | 1100 uc = utf_ptr2char(p); |
1101 | |
1102 if (charlen != utf_char2len(uc)) | |
1103 charlen = 1; /* reject overlong sequences */ | |
1104 | |
1105 if (charlen == 1 || uc < 0xa0 || !utf_printable(uc)) | |
1106 { | |
1107 int outlen; | |
1108 | |
1109 /* Careful: we can't just use transchar_byte() here, | |
1110 * since 'encoding' is not necessarily set to "utf-8". */ | |
1111 if (*p & 0x80 && charlen == 1) | |
1112 { | |
1113 transchar_hex(pdest, *p); /* <xx> */ | |
1114 outlen = 4; | |
1115 } | |
1116 else if (uc >= 0x80) | |
1117 { | |
1118 /* Note: we assume here that utf_printable() doesn't | |
1119 * care about characters outside the BMP. */ | |
1120 transchar_hex(pdest, uc); /* <xx> or <xxxx> */ | |
1121 outlen = (uc < 0x100) ? 4 : 6; | |
1122 } | |
1123 else | |
1124 { | |
1125 transchar_nonprint(pdest, *p); /* ^X */ | |
1126 outlen = 2; | |
1127 } | |
1128 if (pixel != INVALCOLOR) | |
1129 { | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1130 #if GTK_CHECK_VERSION(3,0,0) |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1131 # define DOUBLE2UINT16(val) ((guint16)((val) * 65535 + 0.5)) |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1132 attr = pango_attr_foreground_new( |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1133 DOUBLE2UINT16(color.red), |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1134 DOUBLE2UINT16(color.green), |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1135 DOUBLE2UINT16(color.blue)); |
9630
0c098fb3994c
commit https://github.com/vim/vim/commit/870b749ce1db1cec80f0f3766064a031688e6a46
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
1136 # if PANGO_VERSION_CHECK(1,38,0) |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1137 attr_alpha = pango_attr_foreground_alpha_new( |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1138 DOUBLE2UINT16(color.alpha)); |
9630
0c098fb3994c
commit https://github.com/vim/vim/commit/870b749ce1db1cec80f0f3766064a031688e6a46
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
1139 # endif |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1140 # undef DOUBLE2UINT16 |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1141 #else |
7 | 1142 attr = pango_attr_foreground_new( |
1143 color.red, color.green, color.blue); | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1144 #endif |
7 | 1145 attr->start_index = pdest - buf; |
1146 attr->end_index = pdest - buf + outlen; | |
1147 pango_attr_list_insert(attr_list, attr); | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1148 #if GTK_CHECK_VERSION(3,0,0) |
9630
0c098fb3994c
commit https://github.com/vim/vim/commit/870b749ce1db1cec80f0f3766064a031688e6a46
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
1149 # if PANGO_VERSION_CHECK(1,38,0) |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1150 attr_alpha->start_index = pdest - buf; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1151 attr_alpha->end_index = pdest - buf + outlen; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1152 pango_attr_list_insert(attr_list, attr_alpha); |
9630
0c098fb3994c
commit https://github.com/vim/vim/commit/870b749ce1db1cec80f0f3766064a031688e6a46
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
1153 # endif |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1154 #endif |
7 | 1155 } |
1156 pdest += outlen; | |
1157 p += charlen; | |
1158 } | |
1159 else | |
1160 { | |
1161 do | |
1162 *pdest++ = *p++; | |
1163 while (--charlen != 0); | |
1164 } | |
1165 } | |
1166 } | |
1167 *pdest = NUL; | |
1168 } | |
1169 | |
1170 vim_free(convbuf); | |
1171 | |
1172 gtk_label_set_text(label, (const char *)buf); | |
1173 vim_free(buf); | |
1174 | |
1175 gtk_label_set_attributes(label, attr_list); | |
1176 pango_attr_list_unref(attr_list); | |
1177 } | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1178 # undef IS_NONPRINTABLE |
7 | 1179 |
1180 /* | |
1181 * Draw a balloon. | |
1182 */ | |
1183 static void | |
1184 drawBalloon(BalloonEval *beval) | |
1185 { | |
1186 if (beval->msg != NULL) | |
1187 { | |
1188 GtkRequisition requisition; | |
1189 int screen_w; | |
1190 int screen_h; | |
1191 int x; | |
1192 int y; | |
1193 int x_offset = EVAL_OFFSET_X; | |
1194 int y_offset = EVAL_OFFSET_Y; | |
1195 PangoLayout *layout; | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1196 |
12409
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
1197 # if !GTK_CHECK_VERSION(3,22,2) |
7 | 1198 GdkScreen *screen; |
1199 | |
1200 screen = gtk_widget_get_screen(beval->target); | |
1201 gtk_window_set_screen(GTK_WINDOW(beval->balloonShell), screen); | |
1202 # endif | |
12409
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
1203 gui_gtk_get_screen_size_of_win(beval->balloonShell, |
2c020bc30f62
patch 8.0.1084: GTK build has compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
11474
diff
changeset
|
1204 &screen_w, &screen_h); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1205 # if !GTK_CHECK_VERSION(3,0,0) |
7 | 1206 gtk_widget_ensure_style(beval->balloonShell); |
1207 gtk_widget_ensure_style(beval->balloonLabel); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1208 # endif |
7 | 1209 |
1210 set_printable_label_text(GTK_LABEL(beval->balloonLabel), beval->msg); | |
1211 /* | |
1212 * Dirty trick: Enable wrapping mode on the label's layout behind its | |
1213 * back. This way GtkLabel won't try to constrain the wrap width to a | |
1214 * builtin maximum value of about 65 Latin characters. | |
1215 */ | |
1216 layout = gtk_label_get_layout(GTK_LABEL(beval->balloonLabel)); | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1217 # ifdef PANGO_WRAP_WORD_CHAR |
7 | 1218 pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1219 # else |
7 | 1220 pango_layout_set_wrap(layout, PANGO_WRAP_WORD); |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1221 # endif |
7 | 1222 pango_layout_set_width(layout, |
1223 /* try to come up with some reasonable width */ | |
1224 PANGO_SCALE * CLAMP(gui.num_cols * gui.char_width, | |
1225 screen_w / 2, | |
1226 MAX(20, screen_w - 20))); | |
1227 | |
1228 /* Calculate the balloon's width and height. */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1229 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1230 gtk_widget_get_preferred_size(beval->balloonShell, &requisition, NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1231 # else |
7 | 1232 gtk_widget_size_request(beval->balloonShell, &requisition); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1233 # endif |
7 | 1234 |
1235 /* Compute position of the balloon area */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1236 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1237 gdk_window_get_origin(gtk_widget_get_window(beval->target), &x, &y); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1238 # else |
7 | 1239 gdk_window_get_origin(beval->target->window, &x, &y); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1240 # endif |
7 | 1241 x += beval->x; |
1242 y += beval->y; | |
1243 | |
1244 /* Get out of the way of the mouse pointer */ | |
1245 if (x + x_offset + requisition.width > screen_w) | |
1246 y_offset += 15; | |
1247 if (y + y_offset + requisition.height > screen_h) | |
1248 y_offset = -requisition.height - EVAL_OFFSET_Y; | |
1249 | |
1250 /* Sanitize values */ | |
1251 x = CLAMP(x + x_offset, 0, MAX(0, screen_w - requisition.width)); | |
1252 y = CLAMP(y + y_offset, 0, MAX(0, screen_h - requisition.height)); | |
1253 | |
1254 /* Show the balloon */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1255 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1256 gtk_window_move(GTK_WINDOW(beval->balloonShell), x, y); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1257 # else |
7 | 1258 gtk_widget_set_uposition(beval->balloonShell, x, y); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1259 # endif |
7 | 1260 gtk_widget_show(beval->balloonShell); |
1261 | |
1262 beval->showState = ShS_SHOWING; | |
1263 } | |
1264 } | |
1265 | |
1266 /* | |
1267 * Undraw a balloon. | |
1268 */ | |
1269 static void | |
1270 undrawBalloon(BalloonEval *beval) | |
1271 { | |
1272 if (beval->balloonShell != NULL) | |
1273 gtk_widget_hide(beval->balloonShell); | |
1274 beval->showState = ShS_NEUTRAL; | |
1275 } | |
1276 | |
1277 static void | |
1278 cancelBalloon(BalloonEval *beval) | |
1279 { | |
1280 if (beval->showState == ShS_SHOWING | |
1281 || beval->showState == ShS_UPDATE_PENDING) | |
1282 undrawBalloon(beval); | |
1283 | |
1284 if (beval->timerID != 0) | |
1285 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1286 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1287 g_source_remove(beval->timerID); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1288 # else |
7 | 1289 gtk_timeout_remove(beval->timerID); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1290 # endif |
7 | 1291 beval->timerID = 0; |
1292 } | |
1293 beval->showState = ShS_NEUTRAL; | |
1294 } | |
1295 | |
1296 static void | |
1297 createBalloonEvalWindow(BalloonEval *beval) | |
1298 { | |
1299 beval->balloonShell = gtk_window_new(GTK_WINDOW_POPUP); | |
1300 | |
1301 gtk_widget_set_app_paintable(beval->balloonShell, TRUE); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1302 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1303 gtk_window_set_resizable(GTK_WINDOW(beval->balloonShell), FALSE); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1304 # else |
7 | 1305 gtk_window_set_policy(GTK_WINDOW(beval->balloonShell), FALSE, FALSE, TRUE); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1306 # endif |
7 | 1307 gtk_widget_set_name(beval->balloonShell, "gtk-tooltips"); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1308 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1309 gtk_container_set_border_width(GTK_CONTAINER(beval->balloonShell), 4); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1310 # else |
7 | 1311 gtk_container_border_width(GTK_CONTAINER(beval->balloonShell), 4); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1312 # endif |
7 | 1313 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1314 # if GTK_CHECK_VERSION(3,0,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1315 g_signal_connect(G_OBJECT(beval->balloonShell), "draw", |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1316 G_CALLBACK(balloon_draw_event_cb), NULL); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1317 # else |
7 | 1318 gtk_signal_connect((GtkObject*)(beval->balloonShell), "expose_event", |
1319 GTK_SIGNAL_FUNC(balloon_expose_event_cb), NULL); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1320 # endif |
7 | 1321 beval->balloonLabel = gtk_label_new(NULL); |
1322 | |
1323 gtk_label_set_line_wrap(GTK_LABEL(beval->balloonLabel), FALSE); | |
1324 gtk_label_set_justify(GTK_LABEL(beval->balloonLabel), GTK_JUSTIFY_LEFT); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1325 # if GTK_CHECK_VERSION(3,16,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1326 gtk_label_set_xalign(GTK_LABEL(beval->balloonLabel), 0.5); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1327 gtk_label_set_yalign(GTK_LABEL(beval->balloonLabel), 0.5); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1328 # elif GTK_CHECK_VERSION(3,14,0) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1329 GValue align_val = G_VALUE_INIT; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1330 g_value_init(&align_val, G_TYPE_FLOAT); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1331 g_value_set_float(&align_val, 0.5); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1332 g_object_set_property(G_OBJECT(beval->balloonLabel), "xalign", &align_val); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1333 g_object_set_property(G_OBJECT(beval->balloonLabel), "yalign", &align_val); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1334 g_value_unset(&align_val); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1335 # else |
7 | 1336 gtk_misc_set_alignment(GTK_MISC(beval->balloonLabel), 0.5f, 0.5f); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1337 # endif |
7 | 1338 gtk_widget_set_name(beval->balloonLabel, "vim-balloon-label"); |
1339 gtk_widget_show(beval->balloonLabel); | |
1340 | |
1341 gtk_container_add(GTK_CONTAINER(beval->balloonShell), beval->balloonLabel); | |
1342 } | |
1343 | |
1344 #else /* !FEAT_GUI_GTK */ | |
1345 | |
1346 /* | |
1347 * Draw a balloon. | |
1348 */ | |
1349 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1350 drawBalloon(BalloonEval *beval) |
7 | 1351 { |
1352 Dimension w; | |
1353 Dimension h; | |
1354 Position tx; | |
1355 Position ty; | |
1356 | |
1357 if (beval->msg != NULL) | |
1358 { | |
1359 /* Show the Balloon */ | |
1360 | |
1361 /* Calculate the label's width and height */ | |
1362 #ifdef FEAT_GUI_MOTIF | |
1363 XmString s; | |
1364 | |
1365 /* For the callback function we parse NL characters to create a | |
1366 * multi-line label. This doesn't work for all languages, but | |
1367 * XmStringCreateLocalized() doesn't do multi-line labels... */ | |
1368 if (beval->msgCB != NULL) | |
1369 s = XmStringCreateLtoR((char *)beval->msg, XmFONTLIST_DEFAULT_TAG); | |
1370 else | |
1371 s = XmStringCreateLocalized((char *)beval->msg); | |
1372 { | |
1373 XmFontList fl; | |
1374 | |
1375 fl = gui_motif_fontset2fontlist(&gui.tooltip_fontset); | |
6003 | 1376 if (fl == NULL) |
7 | 1377 { |
6003 | 1378 XmStringFree(s); |
1379 return; | |
7 | 1380 } |
6003 | 1381 XmStringExtent(fl, s, &w, &h); |
1382 XmFontListFree(fl); | |
7 | 1383 } |
1384 w += gui.border_offset << 1; | |
1385 h += gui.border_offset << 1; | |
1386 XtVaSetValues(beval->balloonLabel, XmNlabelString, s, NULL); | |
1387 XmStringFree(s); | |
1388 #else /* Athena */ | |
1389 /* Assume XtNinternational == True */ | |
1390 XFontSet fset; | |
1391 XFontSetExtents *ext; | |
1392 | |
1393 XtVaGetValues(beval->balloonLabel, XtNfontSet, &fset, NULL); | |
1394 ext = XExtentsOfFontSet(fset); | |
1395 h = ext->max_ink_extent.height; | |
1396 w = XmbTextEscapement(fset, | |
1397 (char *)beval->msg, | |
1398 (int)STRLEN(beval->msg)); | |
1399 w += gui.border_offset << 1; | |
1400 h += gui.border_offset << 1; | |
1401 XtVaSetValues(beval->balloonLabel, XtNlabel, beval->msg, NULL); | |
1402 #endif | |
1403 | |
1404 /* Compute position of the balloon area */ | |
1405 tx = beval->x_root + EVAL_OFFSET_X; | |
1406 ty = beval->y_root + EVAL_OFFSET_Y; | |
1407 if ((tx + w) > beval->screen_width) | |
1408 tx = beval->screen_width - w; | |
1409 if ((ty + h) > beval->screen_height) | |
1410 ty = beval->screen_height - h; | |
1411 #ifdef FEAT_GUI_MOTIF | |
1412 XtVaSetValues(beval->balloonShell, | |
1413 XmNx, tx, | |
1414 XmNy, ty, | |
1415 NULL); | |
1416 #else | |
1417 /* Athena */ | |
1418 XtVaSetValues(beval->balloonShell, | |
1419 XtNx, tx, | |
1420 XtNy, ty, | |
1421 NULL); | |
1422 #endif | |
1844 | 1423 /* Set tooltip colors */ |
1424 { | |
1425 Arg args[2]; | |
1426 | |
1427 #ifdef FEAT_GUI_MOTIF | |
1428 args[0].name = XmNbackground; | |
1429 args[0].value = gui.tooltip_bg_pixel; | |
1430 args[1].name = XmNforeground; | |
1431 args[1].value = gui.tooltip_fg_pixel; | |
1432 #else /* Athena */ | |
1433 args[0].name = XtNbackground; | |
1434 args[0].value = gui.tooltip_bg_pixel; | |
1435 args[1].name = XtNforeground; | |
1436 args[1].value = gui.tooltip_fg_pixel; | |
1437 #endif | |
1438 XtSetValues(beval->balloonLabel, &args[0], XtNumber(args)); | |
1439 } | |
7 | 1440 |
1441 XtPopup(beval->balloonShell, XtGrabNone); | |
1442 | |
1443 beval->showState = ShS_SHOWING; | |
1444 | |
1445 current_beval = beval; | |
1446 } | |
1447 } | |
1448 | |
1449 /* | |
1450 * Undraw a balloon. | |
1451 */ | |
1452 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1453 undrawBalloon(BalloonEval *beval) |
7 | 1454 { |
1455 if (beval->balloonShell != (Widget)0) | |
1456 XtPopdown(beval->balloonShell); | |
1457 beval->showState = ShS_NEUTRAL; | |
1458 | |
1459 current_beval = NULL; | |
1460 } | |
1461 | |
1462 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1463 cancelBalloon(BalloonEval *beval) |
7 | 1464 { |
1465 if (beval->showState == ShS_SHOWING | |
1466 || beval->showState == ShS_UPDATE_PENDING) | |
1467 undrawBalloon(beval); | |
1468 | |
1469 if (beval->timerID != (XtIntervalId)NULL) | |
1470 { | |
1471 XtRemoveTimeOut(beval->timerID); | |
1472 beval->timerID = (XtIntervalId)NULL; | |
1473 } | |
1474 beval->showState = ShS_NEUTRAL; | |
1475 } | |
1476 | |
1477 | |
1478 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1479 createBalloonEvalWindow(BalloonEval *beval) |
7 | 1480 { |
1481 Arg args[12]; | |
1482 int n; | |
1483 | |
1484 n = 0; | |
1485 #ifdef FEAT_GUI_MOTIF | |
1486 XtSetArg(args[n], XmNallowShellResize, True); n++; | |
1487 beval->balloonShell = XtAppCreateShell("balloonEval", "BalloonEval", | |
1488 overrideShellWidgetClass, gui.dpy, args, n); | |
1489 #else | |
1490 /* Athena */ | |
1491 XtSetArg(args[n], XtNallowShellResize, True); n++; | |
1492 beval->balloonShell = XtAppCreateShell("balloonEval", "BalloonEval", | |
1493 overrideShellWidgetClass, gui.dpy, args, n); | |
1494 #endif | |
1495 | |
1496 n = 0; | |
1497 #ifdef FEAT_GUI_MOTIF | |
1498 { | |
1499 XmFontList fl; | |
1500 | |
1501 fl = gui_motif_fontset2fontlist(&gui.tooltip_fontset); | |
1502 XtSetArg(args[n], XmNforeground, gui.tooltip_fg_pixel); n++; | |
1503 XtSetArg(args[n], XmNbackground, gui.tooltip_bg_pixel); n++; | |
1504 XtSetArg(args[n], XmNfontList, fl); n++; | |
1505 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++; | |
1506 beval->balloonLabel = XtCreateManagedWidget("balloonLabel", | |
1507 xmLabelWidgetClass, beval->balloonShell, args, n); | |
1508 } | |
1509 #else /* FEAT_GUI_ATHENA */ | |
1510 XtSetArg(args[n], XtNforeground, gui.tooltip_fg_pixel); n++; | |
1511 XtSetArg(args[n], XtNbackground, gui.tooltip_bg_pixel); n++; | |
1512 XtSetArg(args[n], XtNinternational, True); n++; | |
1513 XtSetArg(args[n], XtNfontSet, gui.tooltip_fontset); n++; | |
1514 beval->balloonLabel = XtCreateManagedWidget("balloonLabel", | |
1515 labelWidgetClass, beval->balloonShell, args, n); | |
1516 #endif | |
1517 } | |
1518 | |
1519 #endif /* !FEAT_GUI_GTK */ | |
1520 #endif /* !FEAT_GUI_W32 */ | |
1521 | |
1522 #endif /* FEAT_BEVAL */ |