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