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