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