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