Mercurial > vim
annotate src/gui_beval.c @ 11103:3335c3c75611 v8.0.0439
patch 8.0.0439: ":%argdel" gives an error for an empty arglist
commit https://github.com/vim/vim/commit/69a92fb5aecdf2f9d5f6947790b18991b22d0e4c
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Mar 9 15:58:30 2017 +0100
patch 8.0.0439: ":%argdel" gives an error for an empty arglist
Problem: Using ":%argdel" while the argument list is already empty gives an
error. (Pavol Juhas)
Solution: Don't give an error. (closes #1546)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 09 Mar 2017 16:00:05 +0100 |
parents | 6c8a4d21b873 |
children | 778c10516955 |
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; |
2251
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
1887
diff
changeset
|
32 # ifdef FEAT_WINDOWS |
192 | 33 win_T *cw; |
2251
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
1887
diff
changeset
|
34 # endif |
640 | 35 #endif |
865 | 36 static int recursive = FALSE; |
192 | 37 |
38 /* Don't do anything when 'ballooneval' is off, messages scrolled the | |
39 * windows up or we have no beval area. */ | |
40 if (!p_beval || balloonEval == NULL || msg_scrolled > 0) | |
41 return; | |
42 | |
865 | 43 /* Don't do this recursively. Happens when the expression evaluation |
44 * takes a long time and invokes something that checks for CTRL-C typed. */ | |
45 if (recursive) | |
46 return; | |
47 recursive = TRUE; | |
48 | |
192 | 49 #ifdef FEAT_EVAL |
791 | 50 if (get_beval_info(balloonEval, TRUE, &wp, &lnum, &text, &col) == OK) |
192 | 51 { |
791 | 52 bexpr = (*wp->w_buffer->b_p_bexpr == NUL) ? p_bexpr |
53 : wp->w_buffer->b_p_bexpr; | |
54 if (*bexpr != NUL) | |
55 { | |
640 | 56 # ifdef FEAT_WINDOWS |
791 | 57 /* Convert window pointer to number. */ |
58 for (cw = firstwin; cw != wp; cw = cw->w_next) | |
59 ++winnr; | |
640 | 60 # endif |
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 |
87 * list and it's hardly every useful. If the user really wants a | |
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 { | |
103 gui_mch_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; |
7 | 342 row = Y_2_ROW(beval->y); |
343 col = X_2_COL(beval->x); | |
640 | 344 #ifdef FEAT_WINDOWS |
7 | 345 wp = mouse_find_win(&row, &col); |
640 | 346 #else |
347 wp = firstwin; | |
348 #endif | |
7 | 349 if (wp != NULL && row < wp->w_height && col < W_WIDTH(wp)) |
350 { | |
351 /* Found a window and the cursor is in the text. Now find the line | |
352 * number. */ | |
353 if (!mouse_comp_pos(wp, &row, &col, &lnum)) | |
354 { | |
355 /* Not past end of the file. */ | |
356 lbuf = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
357 if (col <= win_linetabsize(wp, lbuf, (colnr_T)MAXCOL)) | |
358 { | |
359 /* Not past end of line. */ | |
192 | 360 if (getword) |
7 | 361 { |
362 /* For Netbeans we get the relevant part of the line | |
363 * instead of the whole line. */ | |
364 int len; | |
365 pos_T *spos = NULL, *epos = NULL; | |
366 | |
367 if (VIsual_active) | |
368 { | |
369 if (lt(VIsual, curwin->w_cursor)) | |
370 { | |
371 spos = &VIsual; | |
372 epos = &curwin->w_cursor; | |
373 } | |
374 else | |
375 { | |
376 spos = &curwin->w_cursor; | |
377 epos = &VIsual; | |
378 } | |
379 } | |
380 | |
3877 | 381 col = vcol2col(wp, lnum, col); |
7 | 382 |
383 if (VIsual_active | |
384 && wp->w_buffer == curwin->w_buffer | |
385 && (lnum == spos->lnum | |
386 ? col >= (int)spos->col | |
387 : lnum > spos->lnum) | |
388 && (lnum == epos->lnum | |
389 ? col <= (int)epos->col | |
390 : lnum < epos->lnum)) | |
391 { | |
392 /* Visual mode and pointing to the line with the | |
393 * Visual selection: return selected text, with a | |
394 * maximum of one line. */ | |
395 if (spos->lnum != epos->lnum || spos->col == epos->col) | |
396 return FAIL; | |
397 | |
398 lbuf = ml_get_buf(curwin->w_buffer, VIsual.lnum, FALSE); | |
3877 | 399 len = epos->col - spos->col; |
400 if (*p_sel != 'e') | |
401 len += MB_PTR2LEN(lbuf + epos->col); | |
402 lbuf = vim_strnsave(lbuf + spos->col, len); | |
7 | 403 lnum = spos->lnum; |
404 col = spos->col; | |
405 } | |
406 else | |
407 { | |
408 /* Find the word under the cursor. */ | |
409 ++emsg_off; | |
410 len = find_ident_at_pos(wp, lnum, (colnr_T)col, &lbuf, | |
411 FIND_IDENT + FIND_STRING + FIND_EVAL); | |
412 --emsg_off; | |
413 if (len == 0) | |
414 return FAIL; | |
415 lbuf = vim_strnsave(lbuf, len); | |
416 } | |
417 } | |
192 | 418 |
419 *winp = wp; | |
420 *lnump = lnum; | |
421 *textp = lbuf; | |
422 *colp = col; | |
7 | 423 beval->ts = wp->w_buffer->b_p_ts; |
424 return OK; | |
425 } | |
426 } | |
427 } | |
428 | |
429 return FAIL; | |
430 } | |
431 | |
432 # if !defined(FEAT_GUI_W32) || defined(PROTO) | |
433 | |
434 /* | |
435 * Show a balloon with "mesg". | |
436 */ | |
437 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
438 gui_mch_post_balloon(BalloonEval *beval, char_u *mesg) |
7 | 439 { |
440 beval->msg = mesg; | |
441 if (mesg != NULL) | |
442 drawBalloon(beval); | |
443 else | |
444 undrawBalloon(beval); | |
445 } | |
446 # endif /* FEAT_GUI_W32 */ | |
447 #endif /* FEAT_SUN_WORKSHOP || FEAT_NETBEANS_INTG || PROTO */ | |
448 | |
449 #if !defined(FEAT_GUI_W32) || defined(PROTO) | |
450 #if defined(FEAT_BEVAL_TIP) || defined(PROTO) | |
451 /* | |
452 * Hide the given balloon. | |
453 */ | |
454 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
455 gui_mch_unpost_balloon(BalloonEval *beval) |
7 | 456 { |
457 undrawBalloon(beval); | |
458 } | |
459 #endif | |
460 | |
461 #ifdef FEAT_GUI_GTK | |
462 /* | |
463 * We can unconditionally use ANSI-style prototypes here since | |
464 * GTK+ requires an ANSI C compiler anyway. | |
465 */ | |
466 static void | |
467 addEventHandler(GtkWidget *target, BalloonEval *beval) | |
468 { | |
469 /* | |
470 * Connect to the generic "event" signal instead of the individual | |
471 * signals for each event type, because the former is emitted earlier. | |
472 * This allows us to catch events independently of the signal handlers | |
473 * in gui_gtk_x11.c. | |
474 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
475 # 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
|
476 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
|
477 G_CALLBACK(target_event_cb), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
478 beval); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
479 # else |
7 | 480 /* Should use GTK_OBJECT() here, but that causes a lint warning... */ |
481 gtk_signal_connect((GtkObject*)(target), "event", | |
482 GTK_SIGNAL_FUNC(target_event_cb), | |
483 beval); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
484 # endif |
7 | 485 /* |
486 * Nasty: Key press events go to the main window thus the drawing area | |
487 * will never see them. This means we have to connect to the main window | |
488 * as well in order to catch those events. | |
489 */ | |
490 if (gtk_socket_id == 0 && gui.mainwin != NULL | |
491 && gtk_widget_is_ancestor(target, gui.mainwin)) | |
492 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
493 # 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
|
494 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
|
495 G_CALLBACK(mainwin_event_cb), |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
496 beval); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
497 # else |
7 | 498 gtk_signal_connect((GtkObject*)(gui.mainwin), "event", |
499 GTK_SIGNAL_FUNC(mainwin_event_cb), | |
500 beval); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
501 # endif |
7 | 502 } |
503 } | |
504 | |
505 static void | |
506 removeEventHandler(BalloonEval *beval) | |
507 { | |
137 | 508 /* 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
|
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_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
|
511 FUNC2GENERIC(target_event_cb), |
8218
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_disconnect_by_func((GtkObject*)(beval->target), |
515 GTK_SIGNAL_FUNC(target_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 if (gtk_socket_id == 0 && gui.mainwin != NULL | |
520 && gtk_widget_is_ancestor(beval->target, gui.mainwin)) | |
521 { | |
137 | 522 /* 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
|
523 # 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
|
524 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
|
525 FUNC2GENERIC(mainwin_event_cb), |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
526 beval); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
527 # else |
7 | 528 gtk_signal_disconnect_by_func((GtkObject*)(gui.mainwin), |
529 GTK_SIGNAL_FUNC(mainwin_event_cb), | |
530 beval); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
531 # endif |
7 | 532 } |
533 } | |
534 | |
535 static gint | |
536 target_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data) | |
537 { | |
538 BalloonEval *beval = (BalloonEval *)data; | |
539 | |
540 switch (event->type) | |
541 { | |
542 case GDK_ENTER_NOTIFY: | |
543 pointer_event(beval, (int)event->crossing.x, | |
544 (int)event->crossing.y, | |
545 event->crossing.state); | |
546 break; | |
547 case GDK_MOTION_NOTIFY: | |
548 if (event->motion.is_hint) | |
549 { | |
550 int x; | |
551 int y; | |
552 GdkModifierType state; | |
553 /* | |
554 * GDK_POINTER_MOTION_HINT_MASK is set, thus we cannot obtain | |
555 * the coordinates from the GdkEventMotion struct directly. | |
556 */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
557 # 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
|
558 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
559 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
|
560 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
|
561 # 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
|
562 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
|
563 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
|
564 # else |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
565 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
|
566 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
|
567 # endif |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
568 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
|
569 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
570 # else |
7 | 571 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
|
572 # endif |
7 | 573 pointer_event(beval, x, y, (unsigned int)state); |
574 } | |
575 else | |
576 { | |
577 pointer_event(beval, (int)event->motion.x, | |
578 (int)event->motion.y, | |
579 event->motion.state); | |
580 } | |
581 break; | |
582 case GDK_LEAVE_NOTIFY: | |
583 /* | |
584 * Ignore LeaveNotify events that are not "normal". | |
585 * Apparently we also get it when somebody else grabs focus. | |
586 */ | |
587 if (event->crossing.mode == GDK_CROSSING_NORMAL) | |
588 cancelBalloon(beval); | |
589 break; | |
590 case GDK_BUTTON_PRESS: | |
591 case GDK_SCROLL: | |
592 cancelBalloon(beval); | |
593 break; | |
594 case GDK_KEY_PRESS: | |
595 key_event(beval, event->key.keyval, TRUE); | |
596 break; | |
597 case GDK_KEY_RELEASE: | |
598 key_event(beval, event->key.keyval, FALSE); | |
599 break; | |
600 default: | |
601 break; | |
602 } | |
603 | |
604 return FALSE; /* continue emission */ | |
605 } | |
606 | |
607 static gint | |
1884 | 608 mainwin_event_cb(GtkWidget *widget UNUSED, GdkEvent *event, gpointer data) |
7 | 609 { |
610 BalloonEval *beval = (BalloonEval *)data; | |
611 | |
612 switch (event->type) | |
613 { | |
614 case GDK_KEY_PRESS: | |
615 key_event(beval, event->key.keyval, TRUE); | |
616 break; | |
617 case GDK_KEY_RELEASE: | |
618 key_event(beval, event->key.keyval, FALSE); | |
619 break; | |
620 default: | |
621 break; | |
622 } | |
623 | |
624 return FALSE; /* continue emission */ | |
625 } | |
626 | |
627 static void | |
628 pointer_event(BalloonEval *beval, int x, int y, unsigned state) | |
629 { | |
630 int distance; | |
631 | |
632 distance = ABS(x - beval->x) + ABS(y - beval->y); | |
633 | |
634 if (distance > 4) | |
635 { | |
636 /* | |
637 * Moved out of the balloon location: cancel it. | |
638 * Remember button state | |
639 */ | |
640 beval->state = state; | |
641 cancelBalloon(beval); | |
642 | |
643 /* Mouse buttons are pressed - no balloon now */ | |
644 if (!(state & ((int)GDK_BUTTON1_MASK | (int)GDK_BUTTON2_MASK | |
645 | (int)GDK_BUTTON3_MASK))) | |
646 { | |
647 beval->x = x; | |
648 beval->y = y; | |
649 | |
650 if (state & (int)GDK_MOD1_MASK) | |
651 { | |
652 /* | |
653 * Alt is pressed -- enter super-evaluate-mode, | |
654 * where there is no time delay | |
655 */ | |
656 if (beval->msgCB != NULL) | |
657 { | |
658 beval->showState = ShS_PENDING; | |
659 (*beval->msgCB)(beval, state); | |
660 } | |
661 } | |
662 else | |
663 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
664 # 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
|
665 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
|
666 &timeout_cb, beval); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
667 # else |
7 | 668 beval->timerID = gtk_timeout_add((guint32)p_bdlay, |
669 &timeout_cb, beval); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
670 # endif |
7 | 671 } |
672 } | |
673 } | |
674 } | |
675 | |
676 static void | |
677 key_event(BalloonEval *beval, unsigned keyval, int is_keypress) | |
678 { | |
679 if (beval->showState == ShS_SHOWING && beval->msgCB != NULL) | |
680 { | |
681 switch (keyval) | |
682 { | |
683 case GDK_Shift_L: | |
684 case GDK_Shift_R: | |
685 beval->showState = ShS_UPDATE_PENDING; | |
686 (*beval->msgCB)(beval, (is_keypress) | |
687 ? (int)GDK_SHIFT_MASK : 0); | |
688 break; | |
689 case GDK_Control_L: | |
690 case GDK_Control_R: | |
691 beval->showState = ShS_UPDATE_PENDING; | |
692 (*beval->msgCB)(beval, (is_keypress) | |
693 ? (int)GDK_CONTROL_MASK : 0); | |
694 break; | |
695 default: | |
667 | 696 /* Don't do this for key release, we apparently get these with |
697 * focus changes in some GTK version. */ | |
698 if (is_keypress) | |
699 cancelBalloon(beval); | |
7 | 700 break; |
701 } | |
702 } | |
703 else | |
704 cancelBalloon(beval); | |
705 } | |
706 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
707 # 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
|
708 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
709 # else |
7 | 710 static gint |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
711 # endif |
7 | 712 timeout_cb(gpointer data) |
713 { | |
714 BalloonEval *beval = (BalloonEval *)data; | |
715 | |
716 beval->timerID = 0; | |
717 /* | |
718 * If the timer event happens then the mouse has stopped long enough for | |
719 * a request to be started. The request will only send to the debugger if | |
720 * there the mouse is pointing at real data. | |
721 */ | |
722 requestBalloon(beval); | |
723 | |
724 return FALSE; /* don't call me again */ | |
725 } | |
726 | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
727 # 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
|
728 static gboolean |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
729 balloon_draw_event_cb(GtkWidget *widget, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
730 cairo_t *cr, |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
731 gpointer data UNUSED) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
732 { |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
733 GtkStyleContext *context = NULL; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
734 gint width = -1, height = -1; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
735 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
736 if (widget == NULL) |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
737 return TRUE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
738 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
739 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
|
740 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
|
741 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
|
742 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
743 gtk_style_context_save(context); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
744 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
745 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
|
746 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
|
747 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
748 cairo_save(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
749 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
|
750 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
|
751 cairo_restore(cr); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
752 |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
753 gtk_style_context_restore(context); |
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 return FALSE; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
756 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
757 # else |
7 | 758 static gint |
1884 | 759 balloon_expose_event_cb(GtkWidget *widget, |
760 GdkEventExpose *event, | |
761 gpointer data UNUSED) | |
7 | 762 { |
763 gtk_paint_flat_box(widget->style, widget->window, | |
764 GTK_STATE_NORMAL, GTK_SHADOW_OUT, | |
765 &event->area, widget, "tooltip", | |
766 0, 0, -1, -1); | |
767 | |
768 return FALSE; /* continue emission */ | |
769 } | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
770 # endif /* !GTK_CHECK_VERSION(3,0,0) */ |
7 | 771 |
772 #else /* !FEAT_GUI_GTK */ | |
773 | |
774 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
775 addEventHandler(Widget target, BalloonEval *beval) |
7 | 776 { |
777 XtAddEventHandler(target, | |
778 PointerMotionMask | EnterWindowMask | | |
779 LeaveWindowMask | ButtonPressMask | KeyPressMask | | |
780 KeyReleaseMask, | |
781 False, | |
782 pointerEventEH, (XtPointer)beval); | |
783 } | |
784 | |
785 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
786 removeEventHandler(BalloonEval *beval) |
7 | 787 { |
788 XtRemoveEventHandler(beval->target, | |
789 PointerMotionMask | EnterWindowMask | | |
790 LeaveWindowMask | ButtonPressMask | KeyPressMask | | |
791 KeyReleaseMask, | |
792 False, | |
793 pointerEventEH, (XtPointer)beval); | |
794 } | |
795 | |
796 | |
797 /* | |
798 * The X event handler. All it does is call the real event handler. | |
799 */ | |
800 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
801 pointerEventEH( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
802 Widget w UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
803 XtPointer client_data, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
804 XEvent *event, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
805 Boolean *unused UNUSED) |
7 | 806 { |
807 BalloonEval *beval = (BalloonEval *)client_data; | |
808 pointerEvent(beval, event); | |
809 } | |
810 | |
811 | |
812 /* | |
813 * The real event handler. Called by pointerEventEH() whenever an event we are | |
1228 | 814 * interested in occurs. |
7 | 815 */ |
816 | |
817 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
818 pointerEvent(BalloonEval *beval, XEvent *event) |
7 | 819 { |
4352 | 820 Position distance; /* a measure of how much the pointer moved */ |
7 | 821 Position delta; /* used to compute distance */ |
822 | |
823 switch (event->type) | |
824 { | |
825 case EnterNotify: | |
826 case MotionNotify: | |
827 delta = event->xmotion.x - beval->x; | |
828 if (delta < 0) | |
829 delta = -delta; | |
830 distance = delta; | |
831 delta = event->xmotion.y - beval->y; | |
832 if (delta < 0) | |
833 delta = -delta; | |
834 distance += delta; | |
835 if (distance > 4) | |
836 { | |
837 /* | |
838 * Moved out of the balloon location: cancel it. | |
839 * Remember button state | |
840 */ | |
841 beval->state = event->xmotion.state; | |
842 if (beval->state & (Button1Mask|Button2Mask|Button3Mask)) | |
843 { | |
844 /* Mouse buttons are pressed - no balloon now */ | |
845 cancelBalloon(beval); | |
846 } | |
847 else if (beval->state & (Mod1Mask|Mod2Mask|Mod3Mask)) | |
848 { | |
849 /* | |
850 * Alt is pressed -- enter super-evaluate-mode, | |
851 * where there is no time delay | |
852 */ | |
853 beval->x = event->xmotion.x; | |
854 beval->y = event->xmotion.y; | |
855 beval->x_root = event->xmotion.x_root; | |
856 beval->y_root = event->xmotion.y_root; | |
857 cancelBalloon(beval); | |
858 if (beval->msgCB != NULL) | |
859 { | |
860 beval->showState = ShS_PENDING; | |
861 (*beval->msgCB)(beval, beval->state); | |
862 } | |
863 } | |
864 else | |
865 { | |
866 beval->x = event->xmotion.x; | |
867 beval->y = event->xmotion.y; | |
868 beval->x_root = event->xmotion.x_root; | |
869 beval->y_root = event->xmotion.y_root; | |
870 cancelBalloon(beval); | |
871 beval->timerID = XtAppAddTimeOut( beval->appContext, | |
872 (long_u)p_bdlay, timerRoutine, beval); | |
873 } | |
874 } | |
875 break; | |
876 | |
877 /* | |
878 * Motif and Athena version: Keystrokes will be caught by the | |
879 * "textArea" widget, and handled in gui_x11_key_hit_cb(). | |
880 */ | |
881 case KeyPress: | |
882 if (beval->showState == ShS_SHOWING && beval->msgCB != NULL) | |
883 { | |
884 Modifiers modifier; | |
885 KeySym keysym; | |
886 | |
887 XtTranslateKeycode(gui.dpy, | |
888 event->xkey.keycode, event->xkey.state, | |
889 &modifier, &keysym); | |
890 if (keysym == XK_Shift_L || keysym == XK_Shift_R) | |
891 { | |
892 beval->showState = ShS_UPDATE_PENDING; | |
893 (*beval->msgCB)(beval, ShiftMask); | |
894 } | |
895 else if (keysym == XK_Control_L || keysym == XK_Control_R) | |
896 { | |
897 beval->showState = ShS_UPDATE_PENDING; | |
898 (*beval->msgCB)(beval, ControlMask); | |
899 } | |
900 else | |
901 cancelBalloon(beval); | |
902 } | |
903 else | |
904 cancelBalloon(beval); | |
905 break; | |
906 | |
907 case KeyRelease: | |
908 if (beval->showState == ShS_SHOWING && beval->msgCB != NULL) | |
909 { | |
910 Modifiers modifier; | |
911 KeySym keysym; | |
912 | |
913 XtTranslateKeycode(gui.dpy, event->xkey.keycode, | |
914 event->xkey.state, &modifier, &keysym); | |
915 if ((keysym == XK_Shift_L) || (keysym == XK_Shift_R)) { | |
916 beval->showState = ShS_UPDATE_PENDING; | |
917 (*beval->msgCB)(beval, 0); | |
918 } | |
919 else if ((keysym == XK_Control_L) || (keysym == XK_Control_R)) | |
920 { | |
921 beval->showState = ShS_UPDATE_PENDING; | |
922 (*beval->msgCB)(beval, 0); | |
923 } | |
924 else | |
925 cancelBalloon(beval); | |
926 } | |
927 else | |
928 cancelBalloon(beval); | |
929 break; | |
930 | |
931 case LeaveNotify: | |
932 /* Ignore LeaveNotify events that are not "normal". | |
933 * Apparently we also get it when somebody else grabs focus. | |
934 * Happens for me every two seconds (some clipboard tool?) */ | |
935 if (event->xcrossing.mode == NotifyNormal) | |
936 cancelBalloon(beval); | |
937 break; | |
938 | |
939 case ButtonPress: | |
940 cancelBalloon(beval); | |
941 break; | |
942 | |
943 default: | |
944 break; | |
945 } | |
946 } | |
947 | |
948 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
949 timerRoutine(XtPointer dx, XtIntervalId *id UNUSED) |
7 | 950 { |
951 BalloonEval *beval = (BalloonEval *)dx; | |
952 | |
953 beval->timerID = (XtIntervalId)NULL; | |
954 | |
955 /* | |
956 * If the timer event happens then the mouse has stopped long enough for | |
957 * a request to be started. The request will only send to the debugger if | |
958 * there the mouse is pointing at real data. | |
959 */ | |
960 requestBalloon(beval); | |
961 } | |
962 | |
963 #endif /* !FEAT_GUI_GTK */ | |
964 | |
965 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
966 requestBalloon(BalloonEval *beval) |
7 | 967 { |
968 if (beval->showState != ShS_PENDING) | |
969 { | |
970 /* Determine the beval to display */ | |
971 if (beval->msgCB != NULL) | |
972 { | |
973 beval->showState = ShS_PENDING; | |
974 (*beval->msgCB)(beval, beval->state); | |
975 } | |
976 else if (beval->msg != NULL) | |
977 drawBalloon(beval); | |
978 } | |
979 } | |
980 | |
981 #ifdef FEAT_GUI_GTK | |
982 /* | |
983 * Convert the string to UTF-8 if 'encoding' is not "utf-8". | |
984 * Replace any non-printable characters and invalid bytes sequences with | |
985 * "^X" or "<xx>" escapes, and apply SpecialKey highlighting to them. | |
986 * TAB and NL are passed through unscathed. | |
987 */ | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
988 # define IS_NONPRINTABLE(c) (((c) < 0x20 && (c) != TAB && (c) != NL) \ |
7 | 989 || (c) == DEL) |
990 static void | |
944 | 991 set_printable_label_text(GtkLabel *label, char_u *text) |
7 | 992 { |
993 char_u *convbuf = NULL; | |
994 char_u *buf; | |
995 char_u *p; | |
996 char_u *pdest; | |
997 unsigned int len; | |
998 int charlen; | |
999 int uc; | |
1000 PangoAttrList *attr_list; | |
1001 | |
1002 /* Convert to UTF-8 if it isn't already */ | |
1003 if (output_conv.vc_type != CONV_NONE) | |
1004 { | |
944 | 1005 convbuf = string_convert(&output_conv, text, NULL); |
7 | 1006 if (convbuf != NULL) |
944 | 1007 text = convbuf; |
7 | 1008 } |
1009 | |
1010 /* First let's see how much we need to allocate */ | |
1011 len = 0; | |
944 | 1012 for (p = text; *p != NUL; p += charlen) |
7 | 1013 { |
1014 if ((*p & 0x80) == 0) /* be quick for ASCII */ | |
1015 { | |
1016 charlen = 1; | |
1017 len += IS_NONPRINTABLE(*p) ? 2 : 1; /* nonprintable: ^X */ | |
1018 } | |
1019 else | |
1020 { | |
474 | 1021 charlen = utf_ptr2len(p); |
7 | 1022 uc = utf_ptr2char(p); |
1023 | |
1024 if (charlen != utf_char2len(uc)) | |
1025 charlen = 1; /* reject overlong sequences */ | |
1026 | |
1027 if (charlen == 1 || uc < 0xa0) /* illegal byte or */ | |
1028 len += 4; /* control char: <xx> */ | |
1029 else if (!utf_printable(uc)) | |
1030 /* Note: we assume here that utf_printable() doesn't | |
1031 * care about characters outside the BMP. */ | |
1032 len += 6; /* nonprintable: <xxxx> */ | |
1033 else | |
1034 len += charlen; | |
1035 } | |
1036 } | |
1037 | |
1038 attr_list = pango_attr_list_new(); | |
1039 buf = alloc(len + 1); | |
1040 | |
1041 /* Now go for the real work */ | |
1042 if (buf != NULL) | |
1043 { | |
1044 attrentry_T *aep; | |
1045 PangoAttribute *attr; | |
1046 guicolor_T pixel; | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1047 #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
|
1048 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
|
1049 # 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
|
1050 PangoAttribute *attr_alpha; |
9630
0c098fb3994c
commit https://github.com/vim/vim/commit/870b749ce1db1cec80f0f3766064a031688e6a46
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
1051 # endif |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1052 #else |
7 | 1053 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
|
1054 #endif |
7 | 1055 |
1056 /* Look up the RGB values of the SpecialKey foreground color. */ | |
1057 aep = syn_gui_attr2entry(hl_attr(HLF_8)); | |
1058 pixel = (aep != NULL) ? aep->ae_u.gui.fg_color : INVALCOLOR; | |
1059 if (pixel != INVALCOLOR) | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1060 # 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
|
1061 { |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1062 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
|
1063 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
|
1064 color.blue = (pixel & 0xff) / 255.0; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1065 color.alpha = 1.0; |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1066 } |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1067 # else |
7 | 1068 gdk_colormap_query_color(gtk_widget_get_colormap(gui.drawarea), |
1069 (unsigned long)pixel, &color); | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1070 # endif |
7 | 1071 |
1072 pdest = buf; | |
944 | 1073 p = text; |
7 | 1074 while (*p != NUL) |
1075 { | |
1076 /* Be quick for ASCII */ | |
1077 if ((*p & 0x80) == 0 && !IS_NONPRINTABLE(*p)) | |
1078 { | |
1079 *pdest++ = *p++; | |
1080 } | |
1081 else | |
1082 { | |
474 | 1083 charlen = utf_ptr2len(p); |
7 | 1084 uc = utf_ptr2char(p); |
1085 | |
1086 if (charlen != utf_char2len(uc)) | |
1087 charlen = 1; /* reject overlong sequences */ | |
1088 | |
1089 if (charlen == 1 || uc < 0xa0 || !utf_printable(uc)) | |
1090 { | |
1091 int outlen; | |
1092 | |
1093 /* Careful: we can't just use transchar_byte() here, | |
1094 * since 'encoding' is not necessarily set to "utf-8". */ | |
1095 if (*p & 0x80 && charlen == 1) | |
1096 { | |
1097 transchar_hex(pdest, *p); /* <xx> */ | |
1098 outlen = 4; | |
1099 } | |
1100 else if (uc >= 0x80) | |
1101 { | |
1102 /* Note: we assume here that utf_printable() doesn't | |
1103 * care about characters outside the BMP. */ | |
1104 transchar_hex(pdest, uc); /* <xx> or <xxxx> */ | |
1105 outlen = (uc < 0x100) ? 4 : 6; | |
1106 } | |
1107 else | |
1108 { | |
1109 transchar_nonprint(pdest, *p); /* ^X */ | |
1110 outlen = 2; | |
1111 } | |
1112 if (pixel != INVALCOLOR) | |
1113 { | |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1114 #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
|
1115 # 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
|
1116 attr = pango_attr_foreground_new( |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1117 DOUBLE2UINT16(color.red), |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1118 DOUBLE2UINT16(color.green), |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1119 DOUBLE2UINT16(color.blue)); |
9630
0c098fb3994c
commit https://github.com/vim/vim/commit/870b749ce1db1cec80f0f3766064a031688e6a46
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
1120 # 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
|
1121 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
|
1122 DOUBLE2UINT16(color.alpha)); |
9630
0c098fb3994c
commit https://github.com/vim/vim/commit/870b749ce1db1cec80f0f3766064a031688e6a46
Christian Brabandt <cb@256bit.org>
parents:
9624
diff
changeset
|
1123 # endif |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1124 # undef DOUBLE2UINT16 |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1125 #else |
7 | 1126 attr = pango_attr_foreground_new( |
1127 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
|
1128 #endif |
7 | 1129 attr->start_index = pdest - buf; |
1130 attr->end_index = pdest - buf + outlen; | |
1131 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
|
1132 #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
|
1133 # 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
|
1134 attr_alpha->start_index = pdest - buf; |
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1135 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
|
1136 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
|
1137 # endif |
9624
d63b85fe3dc7
commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e
Christian Brabandt <cb@256bit.org>
parents:
9217
diff
changeset
|
1138 #endif |
7 | 1139 } |
1140 pdest += outlen; | |
1141 p += charlen; | |
1142 } | |
1143 else | |
1144 { | |
1145 do | |
1146 *pdest++ = *p++; | |
1147 while (--charlen != 0); | |
1148 } | |
1149 } | |
1150 } | |
1151 *pdest = NUL; | |
1152 } | |
1153 | |
1154 vim_free(convbuf); | |
1155 | |
1156 gtk_label_set_text(label, (const char *)buf); | |
1157 vim_free(buf); | |
1158 | |
1159 gtk_label_set_attributes(label, attr_list); | |
1160 pango_attr_list_unref(attr_list); | |
1161 } | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1162 # undef IS_NONPRINTABLE |
7 | 1163 |
1164 /* | |
1165 * Draw a balloon. | |
1166 */ | |
1167 static void | |
1168 drawBalloon(BalloonEval *beval) | |
1169 { | |
1170 if (beval->msg != NULL) | |
1171 { | |
1172 GtkRequisition requisition; | |
1173 int screen_w; | |
1174 int screen_h; | |
1175 int x; | |
1176 int y; | |
1177 int x_offset = EVAL_OFFSET_X; | |
1178 int y_offset = EVAL_OFFSET_Y; | |
1179 PangoLayout *layout; | |
1180 # ifdef HAVE_GTK_MULTIHEAD | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1181 # if GTK_CHECK_VERSION(3,22,2) |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1182 GdkRectangle rect; |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1183 GdkMonitor * const mon = gdk_display_get_monitor_at_window( |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1184 gtk_widget_get_display(beval->balloonShell), |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1185 gtk_widget_get_window(beval->balloonShell)); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1186 gdk_monitor_get_geometry(mon, &rect); |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1187 |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1188 screen_w = rect.width; |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1189 screen_h = rect.height; |
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1190 # else |
7 | 1191 GdkScreen *screen; |
1192 | |
1193 screen = gtk_widget_get_screen(beval->target); | |
1194 gtk_window_set_screen(GTK_WINDOW(beval->balloonShell), screen); | |
1195 screen_w = gdk_screen_get_width(screen); | |
1196 screen_h = gdk_screen_get_height(screen); | |
10390
6c8a4d21b873
commit https://github.com/vim/vim/commit/a859f04b4db651860c07db3587f29906517c552b
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1197 # endif |
7 | 1198 # else |
1199 screen_w = gdk_screen_width(); | |
1200 screen_h = gdk_screen_height(); | |
1201 # endif | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1202 # if !GTK_CHECK_VERSION(3,0,0) |
7 | 1203 gtk_widget_ensure_style(beval->balloonShell); |
1204 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
|
1205 # endif |
7 | 1206 |
1207 set_printable_label_text(GTK_LABEL(beval->balloonLabel), beval->msg); | |
1208 /* | |
1209 * Dirty trick: Enable wrapping mode on the label's layout behind its | |
1210 * back. This way GtkLabel won't try to constrain the wrap width to a | |
1211 * builtin maximum value of about 65 Latin characters. | |
1212 */ | |
1213 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
|
1214 # ifdef PANGO_WRAP_WORD_CHAR |
7 | 1215 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
|
1216 # else |
7 | 1217 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
|
1218 # endif |
7 | 1219 pango_layout_set_width(layout, |
1220 /* try to come up with some reasonable width */ | |
1221 PANGO_SCALE * CLAMP(gui.num_cols * gui.char_width, | |
1222 screen_w / 2, | |
1223 MAX(20, screen_w - 20))); | |
1224 | |
1225 /* 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
|
1226 # 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
|
1227 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
|
1228 # else |
7 | 1229 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
|
1230 # endif |
7 | 1231 |
1232 /* 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
|
1233 # 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
|
1234 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
|
1235 # else |
7 | 1236 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
|
1237 # endif |
7 | 1238 x += beval->x; |
1239 y += beval->y; | |
1240 | |
1241 /* Get out of the way of the mouse pointer */ | |
1242 if (x + x_offset + requisition.width > screen_w) | |
1243 y_offset += 15; | |
1244 if (y + y_offset + requisition.height > screen_h) | |
1245 y_offset = -requisition.height - EVAL_OFFSET_Y; | |
1246 | |
1247 /* Sanitize values */ | |
1248 x = CLAMP(x + x_offset, 0, MAX(0, screen_w - requisition.width)); | |
1249 y = CLAMP(y + y_offset, 0, MAX(0, screen_h - requisition.height)); | |
1250 | |
1251 /* Show the balloon */ | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1252 # 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
|
1253 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
|
1254 # else |
7 | 1255 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
|
1256 # endif |
7 | 1257 gtk_widget_show(beval->balloonShell); |
1258 | |
1259 beval->showState = ShS_SHOWING; | |
1260 } | |
1261 } | |
1262 | |
1263 /* | |
1264 * Undraw a balloon. | |
1265 */ | |
1266 static void | |
1267 undrawBalloon(BalloonEval *beval) | |
1268 { | |
1269 if (beval->balloonShell != NULL) | |
1270 gtk_widget_hide(beval->balloonShell); | |
1271 beval->showState = ShS_NEUTRAL; | |
1272 } | |
1273 | |
1274 static void | |
1275 cancelBalloon(BalloonEval *beval) | |
1276 { | |
1277 if (beval->showState == ShS_SHOWING | |
1278 || beval->showState == ShS_UPDATE_PENDING) | |
1279 undrawBalloon(beval); | |
1280 | |
1281 if (beval->timerID != 0) | |
1282 { | |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1283 # 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
|
1284 g_source_remove(beval->timerID); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1285 # else |
7 | 1286 gtk_timeout_remove(beval->timerID); |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1287 # endif |
7 | 1288 beval->timerID = 0; |
1289 } | |
1290 beval->showState = ShS_NEUTRAL; | |
1291 } | |
1292 | |
1293 static void | |
1294 createBalloonEvalWindow(BalloonEval *beval) | |
1295 { | |
1296 beval->balloonShell = gtk_window_new(GTK_WINDOW_POPUP); | |
1297 | |
1298 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
|
1299 # 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
|
1300 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
|
1301 # else |
7 | 1302 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
|
1303 # endif |
7 | 1304 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
|
1305 # 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
|
1306 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
|
1307 # else |
7 | 1308 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
|
1309 # endif |
7 | 1310 |
8218
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1311 # 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
|
1312 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
|
1313 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
|
1314 # else |
7 | 1315 gtk_signal_connect((GtkObject*)(beval->balloonShell), "expose_event", |
1316 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
|
1317 # endif |
7 | 1318 beval->balloonLabel = gtk_label_new(NULL); |
1319 | |
1320 gtk_label_set_line_wrap(GTK_LABEL(beval->balloonLabel), FALSE); | |
1321 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
|
1322 # 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
|
1323 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
|
1324 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
|
1325 # 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
|
1326 GValue align_val = G_VALUE_INIT; |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1327 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
|
1328 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
|
1329 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
|
1330 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
|
1331 g_value_unset(&align_val); |
3456e2ebebd4
commit https://github.com/vim/vim/commit/9892189d2e7ab94b750f99e6da4cbfc3c8014517
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
1332 # else |
7 | 1333 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
|
1334 # endif |
7 | 1335 gtk_widget_set_name(beval->balloonLabel, "vim-balloon-label"); |
1336 gtk_widget_show(beval->balloonLabel); | |
1337 | |
1338 gtk_container_add(GTK_CONTAINER(beval->balloonShell), beval->balloonLabel); | |
1339 } | |
1340 | |
1341 #else /* !FEAT_GUI_GTK */ | |
1342 | |
1343 /* | |
1344 * Draw a balloon. | |
1345 */ | |
1346 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1347 drawBalloon(BalloonEval *beval) |
7 | 1348 { |
1349 Dimension w; | |
1350 Dimension h; | |
1351 Position tx; | |
1352 Position ty; | |
1353 | |
1354 if (beval->msg != NULL) | |
1355 { | |
1356 /* Show the Balloon */ | |
1357 | |
1358 /* Calculate the label's width and height */ | |
1359 #ifdef FEAT_GUI_MOTIF | |
1360 XmString s; | |
1361 | |
1362 /* For the callback function we parse NL characters to create a | |
1363 * multi-line label. This doesn't work for all languages, but | |
1364 * XmStringCreateLocalized() doesn't do multi-line labels... */ | |
1365 if (beval->msgCB != NULL) | |
1366 s = XmStringCreateLtoR((char *)beval->msg, XmFONTLIST_DEFAULT_TAG); | |
1367 else | |
1368 s = XmStringCreateLocalized((char *)beval->msg); | |
1369 { | |
1370 XmFontList fl; | |
1371 | |
1372 fl = gui_motif_fontset2fontlist(&gui.tooltip_fontset); | |
6003 | 1373 if (fl == NULL) |
7 | 1374 { |
6003 | 1375 XmStringFree(s); |
1376 return; | |
7 | 1377 } |
6003 | 1378 XmStringExtent(fl, s, &w, &h); |
1379 XmFontListFree(fl); | |
7 | 1380 } |
1381 w += gui.border_offset << 1; | |
1382 h += gui.border_offset << 1; | |
1383 XtVaSetValues(beval->balloonLabel, XmNlabelString, s, NULL); | |
1384 XmStringFree(s); | |
1385 #else /* Athena */ | |
1386 /* Assume XtNinternational == True */ | |
1387 XFontSet fset; | |
1388 XFontSetExtents *ext; | |
1389 | |
1390 XtVaGetValues(beval->balloonLabel, XtNfontSet, &fset, NULL); | |
1391 ext = XExtentsOfFontSet(fset); | |
1392 h = ext->max_ink_extent.height; | |
1393 w = XmbTextEscapement(fset, | |
1394 (char *)beval->msg, | |
1395 (int)STRLEN(beval->msg)); | |
1396 w += gui.border_offset << 1; | |
1397 h += gui.border_offset << 1; | |
1398 XtVaSetValues(beval->balloonLabel, XtNlabel, beval->msg, NULL); | |
1399 #endif | |
1400 | |
1401 /* Compute position of the balloon area */ | |
1402 tx = beval->x_root + EVAL_OFFSET_X; | |
1403 ty = beval->y_root + EVAL_OFFSET_Y; | |
1404 if ((tx + w) > beval->screen_width) | |
1405 tx = beval->screen_width - w; | |
1406 if ((ty + h) > beval->screen_height) | |
1407 ty = beval->screen_height - h; | |
1408 #ifdef FEAT_GUI_MOTIF | |
1409 XtVaSetValues(beval->balloonShell, | |
1410 XmNx, tx, | |
1411 XmNy, ty, | |
1412 NULL); | |
1413 #else | |
1414 /* Athena */ | |
1415 XtVaSetValues(beval->balloonShell, | |
1416 XtNx, tx, | |
1417 XtNy, ty, | |
1418 NULL); | |
1419 #endif | |
1844 | 1420 /* Set tooltip colors */ |
1421 { | |
1422 Arg args[2]; | |
1423 | |
1424 #ifdef FEAT_GUI_MOTIF | |
1425 args[0].name = XmNbackground; | |
1426 args[0].value = gui.tooltip_bg_pixel; | |
1427 args[1].name = XmNforeground; | |
1428 args[1].value = gui.tooltip_fg_pixel; | |
1429 #else /* Athena */ | |
1430 args[0].name = XtNbackground; | |
1431 args[0].value = gui.tooltip_bg_pixel; | |
1432 args[1].name = XtNforeground; | |
1433 args[1].value = gui.tooltip_fg_pixel; | |
1434 #endif | |
1435 XtSetValues(beval->balloonLabel, &args[0], XtNumber(args)); | |
1436 } | |
7 | 1437 |
1438 XtPopup(beval->balloonShell, XtGrabNone); | |
1439 | |
1440 beval->showState = ShS_SHOWING; | |
1441 | |
1442 current_beval = beval; | |
1443 } | |
1444 } | |
1445 | |
1446 /* | |
1447 * Undraw a balloon. | |
1448 */ | |
1449 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1450 undrawBalloon(BalloonEval *beval) |
7 | 1451 { |
1452 if (beval->balloonShell != (Widget)0) | |
1453 XtPopdown(beval->balloonShell); | |
1454 beval->showState = ShS_NEUTRAL; | |
1455 | |
1456 current_beval = NULL; | |
1457 } | |
1458 | |
1459 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1460 cancelBalloon(BalloonEval *beval) |
7 | 1461 { |
1462 if (beval->showState == ShS_SHOWING | |
1463 || beval->showState == ShS_UPDATE_PENDING) | |
1464 undrawBalloon(beval); | |
1465 | |
1466 if (beval->timerID != (XtIntervalId)NULL) | |
1467 { | |
1468 XtRemoveTimeOut(beval->timerID); | |
1469 beval->timerID = (XtIntervalId)NULL; | |
1470 } | |
1471 beval->showState = ShS_NEUTRAL; | |
1472 } | |
1473 | |
1474 | |
1475 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1476 createBalloonEvalWindow(BalloonEval *beval) |
7 | 1477 { |
1478 Arg args[12]; | |
1479 int n; | |
1480 | |
1481 n = 0; | |
1482 #ifdef FEAT_GUI_MOTIF | |
1483 XtSetArg(args[n], XmNallowShellResize, True); n++; | |
1484 beval->balloonShell = XtAppCreateShell("balloonEval", "BalloonEval", | |
1485 overrideShellWidgetClass, gui.dpy, args, n); | |
1486 #else | |
1487 /* Athena */ | |
1488 XtSetArg(args[n], XtNallowShellResize, True); n++; | |
1489 beval->balloonShell = XtAppCreateShell("balloonEval", "BalloonEval", | |
1490 overrideShellWidgetClass, gui.dpy, args, n); | |
1491 #endif | |
1492 | |
1493 n = 0; | |
1494 #ifdef FEAT_GUI_MOTIF | |
1495 { | |
1496 XmFontList fl; | |
1497 | |
1498 fl = gui_motif_fontset2fontlist(&gui.tooltip_fontset); | |
1499 XtSetArg(args[n], XmNforeground, gui.tooltip_fg_pixel); n++; | |
1500 XtSetArg(args[n], XmNbackground, gui.tooltip_bg_pixel); n++; | |
1501 XtSetArg(args[n], XmNfontList, fl); n++; | |
1502 XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++; | |
1503 beval->balloonLabel = XtCreateManagedWidget("balloonLabel", | |
1504 xmLabelWidgetClass, beval->balloonShell, args, n); | |
1505 } | |
1506 #else /* FEAT_GUI_ATHENA */ | |
1507 XtSetArg(args[n], XtNforeground, gui.tooltip_fg_pixel); n++; | |
1508 XtSetArg(args[n], XtNbackground, gui.tooltip_bg_pixel); n++; | |
1509 XtSetArg(args[n], XtNinternational, True); n++; | |
1510 XtSetArg(args[n], XtNfontSet, gui.tooltip_fontset); n++; | |
1511 beval->balloonLabel = XtCreateManagedWidget("balloonLabel", | |
1512 labelWidgetClass, beval->balloonShell, args, n); | |
1513 #endif | |
1514 } | |
1515 | |
1516 #endif /* !FEAT_GUI_GTK */ | |
1517 #endif /* !FEAT_GUI_W32 */ | |
1518 | |
1519 #endif /* FEAT_BEVAL */ |