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