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