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