428
|
1 /* Balloon Help
|
|
2 Copyright (c) 1997 Douglas Keller
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Synched up with: Not in FSF. */
|
|
22
|
771
|
23 /* !!#### Needs to be Mule-ized. */
|
|
24
|
428
|
25 /*
|
|
26 * Balloon Help
|
|
27 *
|
|
28 * Version: 1.337 (Sun Apr 13 04:52:10 1997)
|
|
29 *
|
|
30 * Written by Douglas Keller <dkeller@vnet.ibm.com>
|
|
31 *
|
|
32 *
|
|
33 */
|
|
34
|
|
35 #include <config.h>
|
|
36 #include <string.h>
|
|
37 #include <stdlib.h>
|
|
38 #include <stdio.h>
|
|
39 #include <assert.h>
|
|
40
|
|
41 #include <X11/Xlib.h>
|
|
42 #include <X11/Xutil.h>
|
|
43 #include <X11/extensions/shape.h>
|
|
44
|
|
45 #include "xintrinsic.h"
|
|
46
|
|
47 #include "balloon_help.h"
|
|
48
|
442
|
49 #ifndef max
|
428
|
50 #define max(x,y) (x>y?x:y)
|
|
51 #endif
|
|
52
|
|
53 #undef bool
|
|
54 #define bool int
|
|
55
|
|
56 #define MARGIN_WIDTH 4
|
|
57 #define POINTER_OFFSET 8
|
|
58 #define BORDER_WIDTH 2
|
|
59 #define BORDER_WIDTH_HALF 1
|
|
60
|
|
61 #define CONE_HEIGHT 20
|
|
62 #define CONE_WIDTH 50
|
|
63
|
|
64 #define SHAPE_CONE_TOP (1<<0)
|
|
65 #define SHAPE_CONE_LEFT (1<<1)
|
|
66 #define SHAPE_CONE_TOP_LEFT (SHAPE_CONE_TOP | SHAPE_CONE_LEFT)
|
|
67 #define SHAPE_CONE_TOP_RIGHT (SHAPE_CONE_TOP)
|
|
68 #define SHAPE_CONE_BOTTOM_LEFT (SHAPE_CONE_LEFT)
|
|
69 #define SHAPE_CONE_BOTTOM_RIGHT (0)
|
|
70 #define SHAPE_CONE_FREE (-1)
|
|
71
|
|
72
|
|
73 static Display* b_dpy;
|
|
74
|
|
75 static XFontStruct* b_fontStruct;
|
|
76 static GC b_gc;
|
|
77
|
|
78 static GC b_shineGC;
|
|
79 static GC b_shadowGC;
|
|
80
|
|
81 static Window b_win;
|
|
82 static bool b_winMapped;
|
|
83
|
|
84 static Pixmap b_mask;
|
|
85 static int b_maskWidth, b_maskHeight;
|
|
86 static GC b_maskGC;
|
|
87
|
442
|
88 static const char* b_text;
|
428
|
89 static int b_width, b_height;
|
|
90
|
|
91 static XtIntervalId b_timer;
|
|
92 static unsigned long b_delay;
|
|
93
|
|
94 static int b_screenWidth, b_screenHeight;
|
|
95
|
|
96 static int b_lastShape;
|
|
97
|
|
98 /*============================================================================
|
|
99
|
|
100 ============================================================================*/
|
|
101
|
|
102 static GC
|
|
103 create_gc (Display* dpy, Window win, unsigned long fg, unsigned long bg,
|
|
104 XFontStruct* fontStruct)
|
|
105 {
|
|
106 XGCValues gcv;
|
|
107 unsigned long mask;
|
|
108
|
|
109 gcv.foreground = fg;
|
|
110 gcv.background = bg;
|
|
111 gcv.font = fontStruct->fid;
|
|
112 gcv.join_style = JoinMiter;
|
|
113 gcv.line_width = BORDER_WIDTH;
|
|
114
|
|
115 mask = GCFont | GCBackground | GCForeground | GCJoinStyle | GCLineWidth;
|
|
116
|
|
117 return XCreateGC (dpy, win, mask, &gcv);
|
|
118 }
|
|
119
|
|
120 static void
|
|
121 destroy_gc (Display* dpy, GC gc)
|
|
122 {
|
|
123 if (gc)
|
|
124 {
|
|
125 XFreeGC (dpy, gc);
|
|
126 }
|
|
127 }
|
|
128
|
|
129 /*============================================================================
|
|
130
|
|
131 ============================================================================*/
|
|
132
|
|
133 static Window
|
|
134 create_window (Display* dpy, unsigned long bg)
|
|
135 {
|
|
136 Window win;
|
|
137 XSetWindowAttributes attr;
|
|
138 unsigned long attr_mask;
|
|
139
|
|
140 attr_mask = CWOverrideRedirect | CWBackPixel | CWSaveUnder;
|
|
141 attr.override_redirect = True;
|
|
142 attr.background_pixel = bg;
|
|
143 attr.save_under = True;
|
|
144
|
|
145 win =
|
|
146 XCreateWindow (dpy,
|
|
147 DefaultRootWindow (dpy),
|
|
148 0, 0, 1, 1,
|
|
149 0,
|
|
150 CopyFromParent, InputOutput, CopyFromParent,
|
|
151 attr_mask, &attr);
|
|
152
|
|
153 XSelectInput (dpy, win,
|
|
154 SubstructureRedirectMask |
|
|
155 SubstructureNotifyMask |
|
|
156 ExposureMask |
|
|
157 EnterWindowMask |
|
|
158 LeaveWindowMask);
|
|
159 return win;
|
|
160 }
|
|
161
|
|
162 static void
|
|
163 destroy_window (Display* dpy, Window win)
|
|
164 {
|
|
165 if (win)
|
|
166 {
|
|
167 XDestroyWindow (dpy, win);
|
|
168 }
|
|
169 }
|
|
170
|
|
171 /*============================================================================
|
|
172
|
|
173 ============================================================================*/
|
|
174
|
|
175 static void
|
|
176 get_pointer_xy (Display* dpy, int* x_return, int* y_return)
|
|
177 {
|
|
178 int dummy;
|
|
179 unsigned int mask;
|
|
180 Window dummy_win;
|
|
181
|
|
182 XQueryPointer (dpy, RootWindow(dpy, DefaultScreen(dpy)), &dummy_win, &dummy_win,
|
|
183 x_return, y_return, &dummy, &dummy, &mask);
|
|
184 }
|
|
185
|
|
186 /*============================================================================
|
|
187
|
|
188 ============================================================================*/
|
|
189
|
|
190 static void
|
|
191 create_pixmap_mask (int width, int height)
|
|
192 {
|
|
193 b_maskWidth = width;
|
|
194 b_maskHeight = height;
|
|
195 b_mask = XCreatePixmap (b_dpy, b_win, width, height, 1);
|
|
196 }
|
|
197
|
|
198 static void
|
|
199 destroy_pixmap_mask(void)
|
|
200 {
|
|
201 XFreePixmap (b_dpy, b_mask);
|
|
202 }
|
|
203
|
|
204 static void
|
|
205 grow_pixmap_mask (int width, int height)
|
|
206 {
|
|
207 if (width > b_maskWidth || height > b_maskHeight)
|
|
208 {
|
|
209 destroy_pixmap_mask ();
|
|
210 create_pixmap_mask (width, height);
|
|
211 }
|
|
212 }
|
|
213
|
|
214 /*============================================================================
|
|
215
|
|
216 ============================================================================*/
|
|
217
|
|
218 static void
|
442
|
219 text_extent (XFontStruct* fontStruct, const char* text, int len,
|
428
|
220 int* width, int* height)
|
|
221 {
|
|
222 XCharStruct extent;
|
|
223 int dummy;
|
|
224
|
|
225 XTextExtents (fontStruct, text, len, &dummy, &dummy, &dummy, &extent);
|
|
226
|
|
227 *width = extent.width;
|
|
228 *height = fontStruct->ascent + fontStruct->descent;
|
|
229 }
|
|
230
|
|
231 static void
|
442
|
232 get_text_size (Display* dpy, XFontStruct* fontStruct, const char* text,
|
428
|
233 int* max_width, int* max_height)
|
|
234 {
|
|
235 int width;
|
|
236 int height;
|
442
|
237 const char* start;
|
|
238 const char* end;
|
428
|
239
|
|
240 *max_width = *max_height = 0;
|
|
241
|
|
242 start = text;
|
|
243 while ((end = strchr(start, '\n')))
|
|
244 {
|
|
245 text_extent (fontStruct, start, end - start, &width, &height);
|
|
246 *max_width = max (width, *max_width);
|
|
247 *max_height += height;
|
|
248
|
|
249 start = end + 1;
|
|
250 }
|
|
251 text_extent (fontStruct, start, strlen (start), &width, &height);
|
|
252 *max_width = max (width, *max_width);
|
|
253 *max_height += height;
|
|
254
|
|
255 /* Min width */
|
|
256 *max_width = max (*max_width, CONE_WIDTH / 2 * 3);
|
|
257
|
|
258 }
|
|
259
|
|
260 static void
|
|
261 draw_text (Display* dpy, Window win, GC gc, XFontStruct* fontStruct,
|
442
|
262 int x, int y, const char* text)
|
428
|
263 {
|
442
|
264 const char* start;
|
|
265 const char* end;
|
428
|
266 int font_height;
|
|
267
|
|
268 y += fontStruct->ascent;
|
|
269
|
|
270 font_height = fontStruct->ascent + fontStruct->descent;
|
|
271
|
|
272 start = text;
|
|
273 while ((end = strchr(start, '\n')))
|
|
274 {
|
|
275 XDrawString (dpy, win, gc, x, y, start, end - start);
|
|
276
|
|
277 start = end + 1;
|
|
278 y += font_height;
|
|
279 }
|
|
280 XDrawString (dpy, win, gc, x, y, start, strlen (start));
|
|
281 }
|
|
282
|
|
283 /*============================================================================
|
|
284
|
|
285 ============================================================================*/
|
|
286
|
|
287 static int
|
|
288 get_shape (int last_shape, int x, int y, int width, int height,
|
|
289 int screen_width, int screen_height)
|
|
290 {
|
|
291 /* Can we use last_shape? */
|
|
292 if (((last_shape == SHAPE_CONE_TOP_LEFT) &&
|
|
293 (x + width < screen_width) && (y + height < screen_height)) ||
|
|
294 ((last_shape == SHAPE_CONE_TOP_RIGHT) &&
|
|
295 (x - width > 0) && (y + height < screen_height)) ||
|
|
296 ((last_shape == SHAPE_CONE_BOTTOM_LEFT) &&
|
|
297 (x + width < screen_width) && (y - height > 0)) ||
|
|
298 ((last_shape == SHAPE_CONE_BOTTOM_RIGHT) &&
|
|
299 (x - width > 0) && (y - height > 0)))
|
|
300 return last_shape;
|
|
301
|
|
302 /* Try to pick a shape that will not get changed,
|
|
303 e.g. if top left quadrant, top_left */
|
|
304 return (x < screen_width / 2) ?
|
|
305 (y < screen_height / 2 ? SHAPE_CONE_TOP_LEFT: SHAPE_CONE_BOTTOM_LEFT) :
|
|
306 (y < screen_height / 2 ? SHAPE_CONE_TOP_RIGHT: SHAPE_CONE_BOTTOM_RIGHT);
|
|
307 }
|
|
308
|
|
309 static void
|
|
310 make_mask (int shape, int x, int y, int width, int height)
|
|
311 {
|
|
312 XPoint cone[ 3 ];
|
|
313
|
|
314 grow_pixmap_mask (width, height);
|
|
315
|
|
316 /* Clear mask */
|
|
317 XSetForeground (b_dpy, b_maskGC, 0);
|
|
318 XFillRectangle (b_dpy, b_mask, b_maskGC,
|
|
319 0, 0, width, height);
|
|
320
|
|
321 /* Enable text area */
|
|
322 XSetForeground (b_dpy, b_maskGC, 1);
|
|
323 XFillRectangle (b_dpy, b_mask, b_maskGC, 0,
|
|
324 shape & SHAPE_CONE_TOP ? CONE_HEIGHT : 0, width, height - CONE_HEIGHT);
|
|
325
|
|
326 /* Enable for cone area */
|
|
327 cone[0].x = (shape & SHAPE_CONE_LEFT) ? CONE_WIDTH / 2 : width - (CONE_WIDTH / 2);
|
|
328 cone[0].y = (shape & SHAPE_CONE_TOP) ? CONE_HEIGHT : height - CONE_HEIGHT;
|
|
329 cone[1].x = (shape & SHAPE_CONE_LEFT) ? 0 : width;
|
|
330 cone[1].y = (shape & SHAPE_CONE_TOP) ? 0 : height;
|
|
331 cone[2].x = (shape & SHAPE_CONE_LEFT) ? CONE_WIDTH : width - CONE_WIDTH;
|
|
332 cone[2].y = (shape & SHAPE_CONE_TOP) ? CONE_HEIGHT : height - CONE_HEIGHT;
|
|
333
|
|
334 XFillPolygon (b_dpy, b_mask, b_maskGC, cone, 3, Nonconvex, CoordModeOrigin);
|
|
335
|
|
336 }
|
|
337
|
|
338 static void
|
|
339 show_help (XtPointer data, XtIntervalId* id)
|
|
340 {
|
|
341 int x, y;
|
|
342 int shape;
|
|
343 XPoint border[ 3 ];
|
|
344
|
|
345 if (id == NULL || ((id && b_timer) && b_text))
|
|
346 {
|
|
347 b_timer = None;
|
|
348
|
|
349 /* size */
|
|
350 get_text_size (b_dpy, b_fontStruct, b_text, &b_width, &b_height);
|
|
351 b_width += 2 * MARGIN_WIDTH + 2 * BORDER_WIDTH;
|
|
352 b_height += 2 * MARGIN_WIDTH + 2 * BORDER_WIDTH + CONE_HEIGHT;
|
|
353
|
|
354 /* origin */
|
|
355 get_pointer_xy (b_dpy, &x, &y);
|
|
356
|
|
357 /* guess at shape */
|
|
358 shape = get_shape(b_lastShape, x, y, b_width, b_height,
|
|
359 b_screenWidth, b_screenHeight);
|
|
360
|
|
361 x += (shape & SHAPE_CONE_LEFT) ? POINTER_OFFSET : -POINTER_OFFSET;
|
|
362 y += (shape & SHAPE_CONE_TOP) ? POINTER_OFFSET : -POINTER_OFFSET;
|
|
363
|
|
364 /* make sure it is still ok with offset */
|
|
365 shape = get_shape (shape, x, y, b_width, b_height, b_screenWidth, b_screenHeight);
|
|
366
|
|
367 b_lastShape = shape;
|
|
368
|
|
369 make_mask (shape, x, y, b_width, b_height);
|
|
370
|
|
371 XShapeCombineMask (b_dpy, b_win, ShapeBounding, 0, 0, b_mask, ShapeSet);
|
|
372
|
|
373 XMoveResizeWindow(b_dpy, b_win,
|
|
374 (shape & SHAPE_CONE_LEFT) ? x : x - b_width,
|
|
375 (shape & SHAPE_CONE_TOP) ? y : y - b_height,
|
|
376 b_width, b_height);
|
|
377
|
|
378 XClearWindow (b_dpy, b_win);
|
|
379
|
|
380 XMapRaised (b_dpy, b_win);
|
|
381 b_winMapped = True;
|
|
382
|
|
383 draw_text (b_dpy, b_win, b_gc, b_fontStruct,
|
|
384 BORDER_WIDTH + MARGIN_WIDTH,
|
|
385 BORDER_WIDTH + MARGIN_WIDTH + ((shape & SHAPE_CONE_TOP) ? CONE_HEIGHT : 0),
|
|
386 b_text);
|
|
387
|
|
388 /* 3d border */
|
|
389 /* shine- top left */
|
|
390 border[0].x = 0 + BORDER_WIDTH_HALF;
|
|
391 border[0].y = ((shape & SHAPE_CONE_TOP) ? b_height : b_height - CONE_HEIGHT) - BORDER_WIDTH_HALF;
|
|
392 border[1].x = 0 + BORDER_WIDTH_HALF;
|
|
393 border[1].y = ((shape & SHAPE_CONE_TOP) ? CONE_HEIGHT : 0) + BORDER_WIDTH_HALF;
|
|
394 border[2].x = b_width - BORDER_WIDTH_HALF;
|
|
395 border[2].y = border[1].y;
|
|
396 XDrawLines (b_dpy, b_win, b_shineGC, border, 3, CoordModeOrigin);
|
|
397
|
|
398 /* shadow- bottom right */
|
|
399 border[0].x = 0 + BORDER_WIDTH_HALF;
|
|
400 border[0].y = ((shape & SHAPE_CONE_TOP) ? b_height : b_height - CONE_HEIGHT) - BORDER_WIDTH_HALF;
|
|
401 border[1].x = b_width - BORDER_WIDTH_HALF;
|
|
402 border[1].y = border[0].y;
|
|
403 border[2].x = b_width - BORDER_WIDTH_HALF;
|
|
404 border[2].y = ((shape & SHAPE_CONE_TOP) ? CONE_HEIGHT : 0) + BORDER_WIDTH_HALF;
|
|
405 XDrawLines (b_dpy, b_win, b_shadowGC, border, 3, CoordModeOrigin);
|
|
406
|
|
407 /* cone */
|
|
408 if (SHAPE_CONE_TOP_LEFT == shape)
|
|
409 {
|
|
410 XClearArea (b_dpy, b_win,
|
|
411 CONE_WIDTH / 2 + BORDER_WIDTH,
|
|
412 CONE_HEIGHT,
|
|
413 CONE_WIDTH / 2 - BORDER_WIDTH,
|
|
414 BORDER_WIDTH, False);
|
|
415 XDrawLine (b_dpy, b_win, b_shadowGC,
|
|
416 0,
|
|
417 0,
|
|
418 CONE_WIDTH / 2 + BORDER_WIDTH_HALF,
|
|
419 CONE_HEIGHT);
|
|
420 XDrawLine (b_dpy, b_win, b_shineGC,
|
|
421 0,
|
|
422 0,
|
|
423 CONE_WIDTH - BORDER_WIDTH_HALF,
|
|
424 CONE_HEIGHT);
|
|
425 }
|
|
426 else if (SHAPE_CONE_TOP_RIGHT == shape)
|
|
427 {
|
|
428 XClearArea (b_dpy, b_win,
|
|
429 b_width - CONE_WIDTH + BORDER_WIDTH,
|
|
430 CONE_HEIGHT,
|
|
431 CONE_WIDTH / 2 - BORDER_WIDTH,
|
|
432 BORDER_WIDTH, False);
|
|
433 XDrawLine (b_dpy, b_win, b_shadowGC,
|
|
434 b_width,
|
|
435 0,
|
|
436 b_width - CONE_WIDTH / 2 - BORDER_WIDTH_HALF,
|
|
437 CONE_HEIGHT);
|
|
438 XDrawLine (b_dpy, b_win, b_shineGC,
|
|
439 b_width,
|
|
440 0,
|
|
441 b_width - CONE_WIDTH + BORDER_WIDTH_HALF,
|
|
442 CONE_HEIGHT);
|
|
443 }
|
|
444 else if (SHAPE_CONE_BOTTOM_LEFT == shape)
|
|
445 {
|
|
446 XClearArea (b_dpy, b_win,
|
|
447 CONE_WIDTH / 2 + BORDER_WIDTH,
|
|
448 b_height - CONE_HEIGHT - BORDER_WIDTH,
|
|
449 CONE_WIDTH / 2 - BORDER_WIDTH,
|
|
450 BORDER_WIDTH, False);
|
|
451 XDrawLine (b_dpy, b_win, b_shadowGC,
|
|
452 0,
|
|
453 b_height - 1,
|
|
454 CONE_WIDTH,
|
|
455 b_height - 1 - CONE_HEIGHT);
|
|
456 XDrawLine (b_dpy, b_win, b_shineGC,
|
|
457 0,
|
|
458 b_height - 1,
|
|
459 CONE_WIDTH / 2 + BORDER_WIDTH,
|
|
460 b_height - 1 - CONE_HEIGHT);
|
|
461 }
|
|
462 else if (SHAPE_CONE_BOTTOM_RIGHT == shape)
|
|
463 {
|
|
464 XClearArea (b_dpy, b_win,
|
|
465 b_width - 1 - CONE_WIDTH + BORDER_WIDTH,
|
|
466 b_height - CONE_HEIGHT - BORDER_WIDTH,
|
|
467 CONE_WIDTH / 2 - BORDER_WIDTH - 1,
|
|
468 BORDER_WIDTH, False);
|
|
469 XDrawLine (b_dpy, b_win, b_shadowGC,
|
|
470 b_width - 1,
|
|
471 b_height - 1,
|
|
472 b_width - 1 - CONE_WIDTH,
|
|
473 b_height - 1 - CONE_HEIGHT);
|
|
474 XDrawLine (b_dpy, b_win, b_shineGC,
|
|
475 b_width - 1,
|
|
476 b_height - 1,
|
|
477 b_width - 1 - CONE_WIDTH / 2 - BORDER_WIDTH,
|
|
478 b_height - 1 - CONE_HEIGHT);
|
|
479 }
|
|
480 }
|
|
481
|
|
482 }
|
|
483
|
|
484 /*============================================================================
|
|
485
|
|
486 ============================================================================*/
|
|
487
|
|
488 static void
|
|
489 balloon_help_destroy (void)
|
|
490 {
|
|
491 assert (b_dpy != NULL);
|
|
492 b_dpy = NULL;
|
|
493
|
|
494 destroy_window (b_dpy, b_win);
|
|
495 destroy_gc (b_dpy, b_gc);
|
|
496
|
|
497 destroy_gc (b_dpy, b_shineGC);
|
|
498 destroy_gc (b_dpy, b_shadowGC);
|
|
499
|
|
500 destroy_pixmap_mask ();
|
|
501 destroy_gc (b_dpy, b_maskGC);
|
|
502
|
|
503 if (b_timer) XtRemoveTimeOut (b_timer);
|
|
504 }
|
|
505
|
|
506 void
|
|
507 balloon_help_create (Display* dpy,
|
|
508 Pixel fg, Pixel bg, Pixel shine, Pixel shadow,
|
|
509 XFontStruct* font)
|
|
510 {
|
|
511 if (b_dpy) balloon_help_destroy ();
|
|
512
|
|
513 b_dpy = dpy;
|
|
514
|
|
515 b_fontStruct = font;
|
|
516
|
|
517 b_win = create_window (dpy, bg);
|
|
518 b_gc = create_gc (dpy, b_win, fg, bg, b_fontStruct);
|
|
519
|
|
520 b_shineGC = create_gc (dpy, b_win, shine, bg, b_fontStruct);
|
|
521 b_shadowGC = create_gc (dpy, b_win, shadow, bg, b_fontStruct);
|
|
522
|
|
523 create_pixmap_mask (1, 1);
|
|
524 b_maskGC = create_gc (dpy, b_mask, bg, fg, b_fontStruct);
|
|
525
|
|
526 b_winMapped = False;
|
|
527 b_timer = None;
|
|
528 b_delay = 500;
|
|
529
|
|
530 b_screenWidth = DisplayWidth (b_dpy, DefaultScreen(b_dpy));
|
|
531 b_screenHeight = DisplayHeight (b_dpy, DefaultScreen(b_dpy));
|
|
532
|
|
533 b_lastShape = SHAPE_CONE_FREE;
|
|
534 }
|
|
535
|
|
536 void
|
|
537 balloon_help_set_delay (unsigned long milliseconds)
|
|
538 {
|
|
539 b_delay = milliseconds;
|
|
540 }
|
|
541
|
|
542 void
|
442
|
543 balloon_help_show (const char* text)
|
428
|
544 {
|
|
545 assert (b_dpy != NULL);
|
|
546
|
|
547 /* We don't copy the text */
|
|
548 b_text = text;
|
|
549 b_lastShape = SHAPE_CONE_FREE;
|
|
550
|
|
551 if (b_winMapped)
|
|
552 {
|
|
553 /* If help is already being shown, don't delay just update */
|
|
554 show_help (NULL, NULL);
|
|
555 }
|
|
556 else
|
|
557 {
|
|
558 b_timer =
|
|
559 XtAppAddTimeOut (XtDisplayToApplicationContext(b_dpy),
|
|
560 b_delay, show_help, NULL);
|
|
561 }
|
|
562 }
|
|
563
|
|
564 void
|
|
565 balloon_help_hide (void)
|
|
566 {
|
|
567 assert (b_dpy != NULL);
|
|
568
|
|
569 b_text = NULL;
|
|
570 XUnmapWindow (b_dpy, b_win);
|
|
571 b_winMapped = False;
|
|
572 if (b_timer)
|
|
573 {
|
|
574 XtRemoveTimeOut (b_timer);
|
|
575 b_timer = None;
|
|
576 }
|
|
577 }
|
|
578
|
|
579 void
|
|
580 balloon_help_move_to_pointer (void)
|
|
581 {
|
|
582 assert (b_dpy != NULL);
|
|
583
|
|
584 if (b_winMapped)
|
|
585 {
|
|
586 int x, y;
|
|
587 int shape = b_lastShape;
|
|
588
|
|
589 get_pointer_xy (b_dpy, &x, &y);
|
|
590
|
|
591 x += (shape & SHAPE_CONE_LEFT) ? POINTER_OFFSET : -POINTER_OFFSET;
|
|
592 y += (shape & SHAPE_CONE_TOP) ? POINTER_OFFSET : -POINTER_OFFSET;
|
|
593
|
|
594 shape = get_shape (shape, x, y, b_width, b_height, b_screenWidth, b_screenHeight);
|
|
595
|
|
596 if (shape == b_lastShape)
|
|
597 {
|
|
598 XMoveWindow (b_dpy, b_win,
|
|
599 shape & SHAPE_CONE_LEFT ? x : x - b_width,
|
|
600 shape & SHAPE_CONE_TOP ? y : y - b_height);
|
|
601 }
|
|
602 else
|
|
603 {
|
|
604 /* text would be off screen, rebuild with new shape */
|
|
605 b_lastShape = SHAPE_CONE_FREE;
|
|
606 show_help (NULL, NULL);
|
|
607 }
|
|
608 }
|
|
609 }
|