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