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