blob: 84d6acdeda9e82899ce14b82f41ede4cdf079994 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* 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
Bram Moolenaare2ac10d2005-03-07 23:26:06 +000015/*
16 * Common code, invoked when the mouse is resting for a moment.
17 */
Bram Moolenaare2ac10d2005-03-07 23:26:06 +000018 void
19general_beval_cb(beval, state)
20 BalloonEval *beval;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +000021 int state UNUSED;
Bram Moolenaare2ac10d2005-03-07 23:26:06 +000022{
Bram Moolenaar56be9502010-06-06 14:20:26 +020023#ifdef FEAT_EVAL
Bram Moolenaare2ac10d2005-03-07 23:26:06 +000024 win_T *wp;
25 int col;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000026 int use_sandbox;
Bram Moolenaare2ac10d2005-03-07 23:26:06 +000027 linenr_T lnum;
28 char_u *text;
29 static char_u *result = NULL;
30 long winnr = 0;
Bram Moolenaarb3656ed2006-03-20 21:59:49 +000031 char_u *bexpr;
32 buf_T *save_curbuf;
Bram Moolenaar56be9502010-06-06 14:20:26 +020033# ifdef FEAT_WINDOWS
Bram Moolenaare2ac10d2005-03-07 23:26:06 +000034 win_T *cw;
Bram Moolenaar56be9502010-06-06 14:20:26 +020035# endif
Bram Moolenaar33aec762006-01-22 23:30:12 +000036#endif
Bram Moolenaar54a709e2006-05-04 21:57:11 +000037 static int recursive = FALSE;
Bram Moolenaare2ac10d2005-03-07 23:26:06 +000038
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
Bram Moolenaar54a709e2006-05-04 21:57:11 +000044 /* 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
Bram Moolenaare2ac10d2005-03-07 23:26:06 +000050#ifdef FEAT_EVAL
Bram Moolenaarb3656ed2006-03-20 21:59:49 +000051 if (get_beval_info(balloonEval, TRUE, &wp, &lnum, &text, &col) == OK)
Bram Moolenaare2ac10d2005-03-07 23:26:06 +000052 {
Bram Moolenaarb3656ed2006-03-20 21:59:49 +000053 bexpr = (*wp->w_buffer->b_p_bexpr == NUL) ? p_bexpr
54 : wp->w_buffer->b_p_bexpr;
55 if (*bexpr != NUL)
56 {
Bram Moolenaar33aec762006-01-22 23:30:12 +000057# ifdef FEAT_WINDOWS
Bram Moolenaarb3656ed2006-03-20 21:59:49 +000058 /* Convert window pointer to number. */
59 for (cw = firstwin; cw != wp; cw = cw->w_next)
60 ++winnr;
Bram Moolenaar33aec762006-01-22 23:30:12 +000061# endif
Bram Moolenaare2ac10d2005-03-07 23:26:06 +000062
Bram Moolenaarb3656ed2006-03-20 21:59:49 +000063 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);
Bram Moolenaare2ac10d2005-03-07 23:26:06 +000069
Bram Moolenaarb3656ed2006-03-20 21:59:49 +000070 /*
71 * Temporarily change the curbuf, so that we can determine whether
Bram Moolenaarbae0c162007-05-10 19:30:25 +000072 * the buffer-local balloonexpr option was set insecurely.
Bram Moolenaarb3656ed2006-03-20 21:59:49 +000073 */
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;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000082
Bram Moolenaarb3656ed2006-03-20 21:59:49 +000083 vim_free(result);
84 result = eval_to_string(bexpr, NULL, TRUE);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000085
Bram Moolenaarb3656ed2006-03-20 21:59:49 +000086 if (use_sandbox)
87 --sandbox;
88 --textlock;
Bram Moolenaare2ac10d2005-03-07 23:26:06 +000089
Bram Moolenaarb3656ed2006-03-20 21:59:49 +000090 set_vim_var_string(VV_BEVAL_TEXT, NULL, -1);
91 if (result != NULL && result[0] != NUL)
92 {
93 gui_mch_post_balloon(beval, result);
Bram Moolenaar54a709e2006-05-04 21:57:11 +000094 recursive = FALSE;
Bram Moolenaarb3656ed2006-03-20 21:59:49 +000095 return;
96 }
Bram Moolenaare2ac10d2005-03-07 23:26:06 +000097 }
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
Bram Moolenaar54a709e2006-05-04 21:57:11 +0000108
109 recursive = FALSE;
Bram Moolenaare2ac10d2005-03-07 23:26:06 +0000110}
111
112/* on Win32 only get_beval_info() is required */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000113#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>
Bram Moolenaar238a5642006-02-21 22:12:05 +0000130# ifdef FEAT_GUI_NEXTAW
131# include <X11/neXtaw/Label.h>
132# else
133# include <X11/Xaw/Label.h>
134# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000135# endif
136#endif
137
138#include "gui_beval.h"
139
140#ifndef FEAT_GUI_GTK
141extern 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 */
148static BalloonEval *current_beval = NULL;
149#endif
150
151#ifdef FEAT_GUI_GTK
152static void addEventHandler __ARGS((GtkWidget *, BalloonEval *));
153static void removeEventHandler __ARGS((BalloonEval *));
154static gint target_event_cb __ARGS((GtkWidget *, GdkEvent *, gpointer));
155static gint mainwin_event_cb __ARGS((GtkWidget *, GdkEvent *, gpointer));
156static void pointer_event __ARGS((BalloonEval *, int, int, unsigned));
157static void key_event __ARGS((BalloonEval *, unsigned, int));
158static gint timeout_cb __ARGS((gpointer));
159static gint balloon_expose_event_cb __ARGS((GtkWidget *, GdkEventExpose *, gpointer));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000160#else
161static void addEventHandler __ARGS((Widget, BalloonEval *));
162static void removeEventHandler __ARGS((BalloonEval *));
163static void pointerEventEH __ARGS((Widget, XtPointer, XEvent *, Boolean *));
164static void pointerEvent __ARGS((BalloonEval *, XEvent *));
165static void timerRoutine __ARGS((XtPointer, XtIntervalId *));
166#endif
167static void cancelBalloon __ARGS((BalloonEval *));
168static void requestBalloon __ARGS((BalloonEval *));
169static void drawBalloon __ARGS((BalloonEval *));
170static void undrawBalloon __ARGS((BalloonEval *beval));
171static 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 *
184gui_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/*
Bram Moolenaarbae0c162007-05-10 19:30:25 +0000251 * Destroy a balloon-eval and free its associated memory.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000252 */
253 void
254gui_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
270gui_mch_enable_beval_area(beval)
271 BalloonEval *beval;
272{
273 if (beval != NULL)
274 addEventHandler(beval->target, beval);
275}
276
277 void
278gui_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 *
293gui_mch_currently_showing_beval()
294{
295 return current_beval;
296}
297#endif
298#endif /* !FEAT_GUI_W32 */
299
Bram Moolenaare2ac10d2005-03-07 23:26:06 +0000300#if defined(FEAT_SUN_WORKSHOP) || defined(FEAT_NETBEANS_INTG) \
301 || defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000302/*
303 * Get the text and position to be evaluated for "beval".
Bram Moolenaare2ac10d2005-03-07 23:26:06 +0000304 * If "getword" is true the returned text is not the whole line but the
305 * relevant word in allocated memory.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000306 * Returns OK or FAIL.
307 */
308 int
Bram Moolenaare2ac10d2005-03-07 23:26:06 +0000309get_beval_info(beval, getword, winp, lnump, textp, colp)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310 BalloonEval *beval;
Bram Moolenaare2ac10d2005-03-07 23:26:06 +0000311 int getword;
312 win_T **winp;
313 linenr_T *lnump;
314 char_u **textp;
315 int *colp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000316{
317 win_T *wp;
318 int row, col;
319 char_u *lbuf;
320 linenr_T lnum;
321
Bram Moolenaare2ac10d2005-03-07 23:26:06 +0000322 *textp = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000323 row = Y_2_ROW(beval->y);
324 col = X_2_COL(beval->x);
Bram Moolenaar33aec762006-01-22 23:30:12 +0000325#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +0000326 wp = mouse_find_win(&row, &col);
Bram Moolenaar33aec762006-01-22 23:30:12 +0000327#else
328 wp = firstwin;
329#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000330 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. */
Bram Moolenaare2ac10d2005-03-07 23:26:06 +0000341 if (getword)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000342 {
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
Bram Moolenaarb6101cf2012-10-21 00:58:39 +0200362 col = vcol2col(wp, lnum, col);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000363
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);
Bram Moolenaarb6101cf2012-10-21 00:58:39 +0200380 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);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000384 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 }
Bram Moolenaare2ac10d2005-03-07 23:26:06 +0000399
400 *winp = wp;
401 *lnump = lnum;
402 *textp = lbuf;
403 *colp = col;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000404 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
419gui_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
438gui_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
451addEventHandler(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
478removeEventHandler(BalloonEval *beval)
479{
Bram Moolenaar33570922005-01-25 22:26:29 +0000480 /* LINTED: avoid warning: dubious operation on enum */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000481 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 {
Bram Moolenaar33570922005-01-25 22:26:29 +0000488 /* LINTED: avoid warning: dubious operation on enum */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000489 gtk_signal_disconnect_by_func((GtkObject*)(gui.mainwin),
490 GTK_SIGNAL_FUNC(mainwin_event_cb),
491 beval);
492 }
493}
494
495 static gint
496target_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:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000536 case GDK_SCROLL:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000537 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
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552 static gint
Bram Moolenaarb85cb212009-05-17 14:24:23 +0000553mainwin_event_cb(GtkWidget *widget UNUSED, GdkEvent *event, gpointer data)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000554{
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
573pointer_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
617key_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:
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000636 /* 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);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000640 break;
641 }
642 }
643 else
644 cancelBalloon(beval);
645}
646
647 static gint
648timeout_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
Bram Moolenaar071d4272004-06-13 20:20:40 +0000663 static gint
Bram Moolenaarb85cb212009-05-17 14:24:23 +0000664balloon_expose_event_cb(GtkWidget *widget,
665 GdkEventExpose *event,
666 gpointer data UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000667{
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
Bram Moolenaar071d4272004-06-13 20:20:40 +0000676#else /* !FEAT_GUI_GTK */
677
678 static void
679addEventHandler(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
692removeEventHandler(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 */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000707 static void
708pointerEventEH(w, client_data, event, unused)
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +0000709 Widget w UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000710 XtPointer client_data;
711 XEvent *event;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +0000712 Boolean *unused UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000713{
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
Bram Moolenaarbae0c162007-05-10 19:30:25 +0000721 * interested in occurs.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722 */
723
724 static void
725pointerEvent(beval, event)
726 BalloonEval *beval;
727 XEvent *event;
728{
729 Position distance; /* a measure of how much the ponter moved */
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
Bram Moolenaar071d4272004-06-13 20:20:40 +0000857 static void
858timerRoutine(dx, id)
859 XtPointer dx;
Bram Moolenaar4bdbbf72009-05-21 21:27:43 +0000860 XtIntervalId *id UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000861{
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
877requestBalloon(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
Bram Moolenaar071d4272004-06-13 20:20:40 +0000894/*
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 */
Bram Moolenaar182c5be2010-06-25 05:37:59 +0200900# define IS_NONPRINTABLE(c) (((c) < 0x20 && (c) != TAB && (c) != NL) \
Bram Moolenaar071d4272004-06-13 20:20:40 +0000901 || (c) == DEL)
902 static void
Bram Moolenaar89d40322006-08-29 15:30:07 +0000903set_printable_label_text(GtkLabel *label, char_u *text)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000904{
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 {
Bram Moolenaar89d40322006-08-29 15:30:07 +0000917 convbuf = string_convert(&output_conv, text, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 if (convbuf != NULL)
Bram Moolenaar89d40322006-08-29 15:30:07 +0000919 text = convbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000920 }
921
922 /* First let's see how much we need to allocate */
923 len = 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +0000924 for (p = text; *p != NUL; p += charlen)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000925 {
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 {
Bram Moolenaar0fa313a2005-08-10 21:07:57 +0000933 charlen = utf_ptr2len(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000934 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;
Bram Moolenaar89d40322006-08-29 15:30:07 +0000969 p = text;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000970 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 {
Bram Moolenaar0fa313a2005-08-10 21:07:57 +0000979 charlen = utf_ptr2len(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000980 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}
Bram Moolenaar182c5be2010-06-25 05:37:59 +02001038# undef IS_NONPRINTABLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039
1040/*
1041 * Draw a balloon.
1042 */
1043 static void
1044drawBalloon(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;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055 PangoLayout *layout;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001056# 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
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 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));
Bram Moolenaar182c5be2010-06-25 05:37:59 +02001077# ifdef PANGO_WRAP_WORD_CHAR
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078 pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
Bram Moolenaar182c5be2010-06-25 05:37:59 +02001079# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001080 pango_layout_set_wrap(layout, PANGO_WRAP_WORD);
Bram Moolenaar182c5be2010-06-25 05:37:59 +02001081# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001082 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);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001090
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
1118undrawBalloon(BalloonEval *beval)
1119{
1120 if (beval->balloonShell != NULL)
1121 gtk_widget_hide(beval->balloonShell);
1122 beval->showState = ShS_NEUTRAL;
1123}
1124
1125 static void
1126cancelBalloon(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
1141createBalloonEvalWindow(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);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001152 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
1169drawBalloon(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
Bram Moolenaar8281f442009-03-18 11:22:25 +00001241 /* 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 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001258
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
1271undrawBalloon(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
1282cancelBalloon(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
1299createBalloonEvalWindow(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 */