Mercurial > vim
comparison src/gui_xmebw.c @ 48:00c35ea0c2b3
updated for version 7.0028
author | vimboss |
---|---|
date | Sun, 02 Jan 2005 11:31:05 +0000 |
parents | |
children | 2983cde45542 |
comparison
equal
deleted
inserted
replaced
47:eff3887963cc | 48:00c35ea0c2b3 |
---|---|
1 /* vi:set ts=8 sts=4 sw=4: | |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 /* | |
10 * | |
11 * (C) 2002,2005 by Marcin Dalecki <martin@dalecki.de> | |
12 * | |
13 * MARCIN DALECKI ASSUMES NO RESPONSIBILITY FOR THE USE OR INABILITY TO USE ANY | |
14 * OF THIS SOFTWARE . THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY | |
15 * KIND, AND MARCIN DALECKI EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES, | |
16 * INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
17 * FITNESS FOR A PARTICULAR PURPOSE. | |
18 */ | |
19 | |
20 /* | |
21 * Enhanced Motif PushButton widget with move over behaviour. | |
22 */ | |
23 | |
24 #include <ctype.h> | |
25 #include <stdio.h> | |
26 #include <assert.h> | |
27 | |
28 #include <Xm/XmP.h> | |
29 #include <Xm/DrawP.h> | |
30 #ifndef LESSTIF_VERSION | |
31 # include <Xm/TraitP.h> | |
32 # include <Xm/Manager.h> | |
33 # include <Xm/UnhighlightT.h> | |
34 # include <Xm/XpmP.h> | |
35 #else | |
36 # include <X11/xpm.h> | |
37 #endif | |
38 #include <Xm/ManagerP.h> | |
39 #include <Xm/Display.h> | |
40 #include <Xm/DisplayP.h> | |
41 | |
42 #include <X11/Shell.h> | |
43 #include <X11/ShellP.h> | |
44 | |
45 #include "gui_xmebwp.h" | |
46 | |
47 /* Provide some missing wrappers, which are missed from the LessTif | |
48 * implementation. | |
49 * | |
50 * We neither use XmeGetPixmapData or _XmGetPixmapData, since with LessTif the | |
51 * pixmap will not appear in it's caches properly. We cache the interresting | |
52 * values in XmEnhancedButtonPart instead ourself. | |
53 */ | |
54 #ifdef LESSTIF_VERSION | |
55 # ifndef Lab_IsMenupane | |
56 # define Lab_IsMenupane(w) (Lab_MenuType(w) == (int)XmMENU_POPUP || \ | |
57 Lab_MenuType(w) == (int)XmMENU_PULLDOWN) | |
58 # endif | |
59 # define XmeClearBorder _XmClearBorder | |
60 # define XmeDrawShadows _XmDrawShadows | |
61 # define XmeDrawHighlight(a, b, c, d, e, f, g, h) \ | |
62 _XmDrawHighlight(a, b, c, d, e, f, g, h, LineSolid) | |
63 #endif | |
64 | |
65 /* | |
66 * Motif internals we have to cheat around with. | |
67 */ | |
68 | |
69 /* Hopefully this will never change... */ | |
70 #ifndef XmFOCUS_IGNORE | |
71 # define XmFOCUS_IGNORE 1<<1 | |
72 #endif | |
73 | |
74 extern Boolean _XmGetInDragMode(Widget widget); | |
75 extern void _XmPrimitiveEnter(Widget wid, | |
76 XEvent * event, | |
77 String * params, Cardinal * num_params); | |
78 extern void _XmPrimitiveLeave(Widget wid, | |
79 XEvent * event, | |
80 String * params, Cardinal * num_params); | |
81 extern void _XmSetFocusFlag(Widget w, unsigned int mask, Boolean value); | |
82 extern void _XmCalcLabelDimensions(Widget wid); | |
83 | |
84 /* | |
85 * Declaration of class methods. | |
86 */ | |
87 static void Destroy(Widget w); | |
88 static void Initialize(Widget rq, Widget eb, ArgList args, Cardinal *n); | |
89 static Boolean SetValues(Widget current, Widget request, Widget new, ArgList args, Cardinal *n); | |
90 static void Redisplay(Widget, XEvent *, Region); | |
91 | |
92 /* | |
93 * Declaration of action methods. | |
94 */ | |
95 static void Enter(Widget, XEvent *, String *, Cardinal *); | |
96 static void Leave(Widget, XEvent *, String *, Cardinal *); | |
97 static void BorderHighlight(Widget); | |
98 static void BorderUnhighlight(Widget); | |
99 | |
100 /* | |
101 * 4 x 4 stipple for desensitized widgets | |
102 */ | |
103 #define stipple_width 4 | |
104 #define stipple_height 4 | |
105 static char stipple_bits[] = { 0x0a, 0x05, 0x0a, 0x05 }; | |
106 #define STIPPLE_BITMAP xmEnhancedButtonClassRec.enhancedbutton_class.stipple_bitmap | |
107 | |
108 /* | |
109 * Override actions. | |
110 */ | |
111 static XtActionsRec actionsList[] = | |
112 { | |
113 {"Enter", Enter}, | |
114 {"Leave", Leave}, | |
115 }; | |
116 | |
117 static XtResource resources[] = | |
118 { | |
119 { | |
120 XmNpixmapData, XmCPixmap, XmRString, sizeof(String), | |
121 XtOffsetOf(XmEnhancedButtonRec, enhancedbutton.pixmap_data), | |
122 XmRImmediate, (XtPointer) NULL | |
123 }, { | |
124 XmNpixmapFile, XmCPixmap, XmRString, sizeof(String), | |
125 XtOffsetOf(XmEnhancedButtonRec, enhancedbutton.pixmap_file), | |
126 XmRImmediate, (XtPointer) NULL | |
127 }, { | |
128 XmNspacing, XmCSpacing, XmRHorizontalDimension, sizeof(Dimension), | |
129 XtOffsetOf(XmEnhancedButtonRec, enhancedbutton.spacing), | |
130 XmRImmediate, (XtPointer) 2 | |
131 }, | |
132 { | |
133 XmNlabelLocation, XmCLocation, XmRInt, sizeof(int), | |
134 XtOffsetOf(XmEnhancedButtonRec, enhancedbutton.label_location), | |
135 XtRImmediate, (XtPointer) XmRIGHT | |
136 } | |
137 }; | |
138 | |
139 XmEnhancedButtonClassRec xmEnhancedButtonClassRec = | |
140 { | |
141 { | |
142 /* core_class fields */ | |
143 /* superclass */ (WidgetClass) & xmPushButtonClassRec, | |
144 /* class_name */ "XmEnhancedButton", | |
145 /* widget_size */ sizeof(XmEnhancedButtonRec), | |
146 /* class_initialize */ NULL, | |
147 /* class_part_initialize */ NULL, | |
148 /* class_inited */ False, | |
149 /* initialize */ Initialize, | |
150 /* initialize_hook */ NULL, | |
151 /* realize */ XtInheritRealize, | |
152 /* actions */ actionsList, | |
153 /* num_actions */ XtNumber(actionsList), | |
154 /* resources */ resources, | |
155 /* num_resources */ XtNumber(resources), | |
156 /* xrm_class */ NULLQUARK, | |
157 /* compress_motion */ True, | |
158 /* compress_exposure */ XtExposeCompressMaximal, | |
159 /* compress_enterleave */ True, | |
160 /* visible_interest */ False, | |
161 /* destroy */ Destroy, | |
162 /* resize */ XtInheritResize, | |
163 /* expose */ Redisplay, | |
164 /* set_values */ SetValues, | |
165 /* set_values_hook */ NULL, | |
166 /* set_values_almost */ XtInheritSetValuesAlmost, | |
167 /* get_values_hook */ NULL, | |
168 /* accept_focus */ XtInheritAcceptFocus, | |
169 /* version */ XtVersion, | |
170 /* callback_private */ NULL, | |
171 /* tm_table */ NULL, | |
172 /* query_geometry */ NULL, | |
173 /* display_accelerator */ XtInheritDisplayAccelerator, | |
174 /* extension */ NULL | |
175 }, | |
176 | |
177 /* primitive_class fields */ | |
178 { | |
179 /* border highlight */ BorderHighlight, | |
180 /* border_unhighlight */ BorderUnhighlight, | |
181 /* translations */ XtInheritTranslations, | |
182 /* arm and activate */ XmInheritArmAndActivate, | |
183 /* synthetic resources */ NULL, | |
184 /* number of syn res */ 0, | |
185 /* extension */ NULL, | |
186 }, | |
187 | |
188 /* label_class fields */ | |
189 { | |
190 /* setOverrideCallback */ XmInheritSetOverrideCallback, | |
191 /* menuProcs */ XmInheritMenuProc, | |
192 /* translations */ XtInheritTranslations, | |
193 /* extension */ NULL, | |
194 }, | |
195 | |
196 /* pushbutton_class record */ | |
197 { | |
198 /* extension */ (XtPointer) NULL, | |
199 }, | |
200 | |
201 /* enhancedbutton_class fields */ | |
202 { | |
203 /* stipple_bitmap */ None | |
204 } | |
205 }; | |
206 | |
207 | |
208 WidgetClass xmEnhancedButtonWidgetClass = | |
209 (WidgetClass)&xmEnhancedButtonClassRec; | |
210 | |
211 | |
212 /* | |
213 * Create a slightly fainter pixmap to be shown on button entry. | |
214 */ | |
215 static unsigned short | |
216 bump_color(unsigned short value) | |
217 { | |
218 int tmp = 2 * (((int) value - 65535) / 3) + 65535; | |
219 | |
220 return tmp; | |
221 } | |
222 | |
223 /*ARGSUSED*/ | |
224 static int | |
225 alloc_color(Display *display, | |
226 Colormap colormap, | |
227 char *colorname, | |
228 XColor *xcolor, | |
229 void *closure) | |
230 { | |
231 int status; | |
232 | |
233 if (colorname) | |
234 if (!XParseColor(display, colormap, colorname, xcolor)) | |
235 return -1; | |
236 | |
237 xcolor->red = bump_color(xcolor->red); | |
238 xcolor->green = bump_color(xcolor->green); | |
239 xcolor->blue = bump_color(xcolor->blue); | |
240 | |
241 status = XAllocColor(display, colormap, xcolor); | |
242 return status != 0 ? 1 : 0; | |
243 } | |
244 | |
245 /* XPM */ | |
246 static char * blank_xpm[] = | |
247 { | |
248 /* width height ncolors cpp [x_hot y_hot] */ | |
249 "12 12 4 1 0 0", | |
250 /* colors */ | |
251 " s iconColor1 m black c #000000", | |
252 ". s none m none c none", | |
253 "X s topShadowColor m none c #DCDEE5", | |
254 "o s bottomShadowColor m black c #5D6069", | |
255 /* pixels */ | |
256 " ..", | |
257 " XXXXXXXX ..", | |
258 " X....... o.", | |
259 " X....... o.", | |
260 " X....... o.", | |
261 " X....... o.", | |
262 " X....... o.", | |
263 " X....... o.", | |
264 " X....... o.", | |
265 " o.", | |
266 "..ooooooooo.", | |
267 "............"}; | |
268 | |
269 /* | |
270 * Set the pixmap. | |
271 */ | |
272 static void | |
273 set_pixmap(XmEnhancedButtonWidget eb) | |
274 { | |
275 XpmAttributes attr; | |
276 Pixmap sen_pix; | |
277 Window root; | |
278 static XpmColorSymbol color[8] = { | |
279 {"none", "none", 0}, | |
280 {"None", "none", 0}, | |
281 {"background", NULL, 0}, | |
282 {"foreground", NULL, 0}, | |
283 {"bottomShadowColor", NULL, 0}, | |
284 {"topShadowColor", NULL, 0}, | |
285 {"highlightColor", NULL, 0}, | |
286 {"armColor", NULL, 0} | |
287 }; | |
288 int scr; | |
289 Display *dpy = XtDisplay(eb); | |
290 int x; | |
291 int y; | |
292 unsigned int height, width, border, depth; | |
293 int status; | |
294 Pixmap mask; | |
295 Pixmap pix = None; | |
296 Pixmap arm_pix = None; | |
297 Pixmap ins_pix = None; | |
298 Pixmap high_pix = None; | |
299 char **data = (char **) eb->enhancedbutton.pixmap_data; | |
300 int shift; | |
301 GC gc; | |
302 | |
303 /* Make sure there is a default value for the pixmap. | |
304 */ | |
305 if (!data) | |
306 return; | |
307 | |
308 gc = XtGetGC((Widget)eb, (XtGCMask)0, NULL); | |
309 | |
310 scr = DefaultScreen(dpy); | |
311 root = RootWindow(dpy, scr); | |
312 | |
313 eb->label.pixmap = None; | |
314 eb->enhancedbutton.pixmap_depth = 0; | |
315 eb->enhancedbutton.pixmap_width = 0; | |
316 eb->enhancedbutton.pixmap_height = 0; | |
317 eb->enhancedbutton.normal_pixmap = None; | |
318 eb->enhancedbutton.armed_pixmap = None; | |
319 eb->enhancedbutton.highlight_pixmap = None; | |
320 eb->enhancedbutton.insensitive_pixmap = None; | |
321 | |
322 /* Setup color subsititution table. */ | |
323 color[0].pixel = eb->core.background_pixel; | |
324 color[1].pixel = eb->core.background_pixel; | |
325 color[2].pixel = eb->core.background_pixel; | |
326 color[3].pixel = eb->primitive.foreground; | |
327 color[4].pixel = eb->core.background_pixel; | |
328 color[5].pixel = eb->primitive.top_shadow_color; | |
329 color[6].pixel = eb->primitive.highlight_color; | |
330 color[7].pixel = eb->pushbutton.arm_color; | |
331 | |
332 /* Create the "sensitive" pixmap. */ | |
333 attr.valuemask = XpmColorSymbols | XpmCloseness; | |
334 attr.closeness = 65535; /* accuracy isn't crucial */ | |
335 attr.colorsymbols = color; | |
336 attr.numsymbols = XtNumber(color); | |
337 | |
338 status = XpmCreatePixmapFromData(dpy, root, data, &pix, &mask, &attr); | |
339 | |
340 /* If somethin failed, we will fill in the default pixmap. */ | |
341 if (status != XpmSuccess) | |
342 status = XpmCreatePixmapFromData(dpy, root, blank_xpm, &pix, | |
343 &mask, &attr); | |
344 | |
345 XpmFreeAttributes(&attr); | |
346 | |
347 XGetGeometry(dpy, pix, &root, &x, &y, &width, &height, &border, &depth); | |
348 | |
349 if (eb->enhancedbutton.label_location == XmTOP | |
350 || eb->enhancedbutton.label_location == XmBOTTOM) | |
351 shift = eb->primitive.shadow_thickness / 2; | |
352 else | |
353 shift = eb->primitive.shadow_thickness / 2; | |
354 | |
355 if (shift < 1) | |
356 shift = 1; | |
357 | |
358 sen_pix = XCreatePixmap(dpy, root, width + shift, height + shift, depth); | |
359 | |
360 XSetForeground(dpy, gc, eb->core.background_pixel); | |
361 XFillRectangle(dpy, sen_pix, gc, 0, 0, width + shift, height + shift); | |
362 XSetClipMask(dpy, gc, mask); | |
363 XSetClipOrigin(dpy, gc, shift, shift); | |
364 XCopyArea(dpy, pix, sen_pix, gc, 0, 0, width, height, shift, shift); | |
365 | |
366 /* Create the "highlight" pixmap. */ | |
367 color[4].pixel = eb->primitive.bottom_shadow_color; | |
368 attr.valuemask = XpmColorSymbols | XpmCloseness | XpmAllocColor; | |
369 attr.closeness = 65535; /* accuracy isn't crucial */ | |
370 attr.colorsymbols = color; | |
371 attr.numsymbols = XtNumber(color); | |
372 attr.alloc_color = alloc_color; | |
373 | |
374 status = XpmCreatePixmapFromData(dpy, root, data, &pix, NULL, &attr); | |
375 XpmFreeAttributes(&attr); | |
376 | |
377 high_pix = XCreatePixmap(dpy, root, width + shift, height + shift, depth); | |
378 | |
379 #if 1 | |
380 XSetForeground(dpy, gc, eb->core.background_pixel); | |
381 #else | |
382 XSetForeground(dpy, gc, eb->primitive.top_shadow_color); | |
383 #endif | |
384 XSetClipMask(dpy, gc, None); | |
385 XFillRectangle(dpy, high_pix, gc, 0, 0, width + shift, height + shift); | |
386 XSetClipMask(dpy, gc, mask); | |
387 XSetClipOrigin(dpy, gc, 0, 0); | |
388 XCopyArea(dpy, pix, high_pix, gc, 0, 0, width, height, 0, 0); | |
389 | |
390 arm_pix = XCreatePixmap(dpy, pix, width + shift, height + shift, depth); | |
391 | |
392 if (eb->pushbutton.fill_on_arm) | |
393 XSetForeground(dpy, gc, eb->pushbutton.arm_color); | |
394 else | |
395 XSetForeground(dpy, gc, eb->core.background_pixel); | |
396 XSetClipOrigin(dpy, gc, shift, shift); | |
397 XSetClipMask(dpy, gc, None); | |
398 XFillRectangle(dpy, arm_pix, gc, 0, 0, width + shift, height + shift); | |
399 XSetClipMask(dpy, gc, mask); | |
400 XSetClipOrigin(dpy, gc, 2 * shift, 2 * shift); | |
401 XCopyArea(dpy, pix, arm_pix, gc, 0, 0, width, height, 2 * shift, 2 * shift); | |
402 | |
403 XFreePixmap(dpy, pix); | |
404 XFreePixmap(dpy, mask); | |
405 | |
406 /* Create the "insensitive" pixmap. */ | |
407 attr.valuemask = XpmColorSymbols | XpmCloseness | XpmColorKey; | |
408 attr.closeness = 65535; /* accuracy isn't crucial */ | |
409 attr.colorsymbols = color; | |
410 attr.numsymbols = sizeof(color) / sizeof(color[0]); | |
411 attr.color_key = XPM_MONO; | |
412 status = XpmCreatePixmapFromData(dpy, root, data, &pix, &mask, &attr); | |
413 | |
414 /* Need to create new Pixmaps with the mask applied. */ | |
415 | |
416 ins_pix = XCreatePixmap(dpy, root, width + shift, height + shift, depth); | |
417 | |
418 XSetForeground(dpy, gc, eb->core.background_pixel); | |
419 XSetClipOrigin(dpy, gc, 0, 0); | |
420 XSetClipMask(dpy, gc, None); | |
421 XFillRectangle(dpy, ins_pix, gc, 0, 0, width + shift, height + shift); | |
422 XSetClipMask(dpy, gc, mask); | |
423 XSetForeground(dpy, gc, eb->primitive.top_shadow_color); | |
424 XSetClipOrigin(dpy, gc, 2 * shift, 2 * shift); | |
425 XFillRectangle(dpy, ins_pix, gc, 2 * shift, 2 * shift, width, height); | |
426 XSetForeground(dpy, gc, eb->primitive.bottom_shadow_color); | |
427 XSetClipOrigin(dpy, gc, shift, shift); | |
428 XFillRectangle(dpy, ins_pix, gc, 0, 0, width + shift, height + shift); | |
429 XtReleaseGC((Widget) eb, gc); | |
430 | |
431 XpmFreeAttributes(&attr); | |
432 | |
433 eb->enhancedbutton.pixmap_depth = depth; | |
434 eb->enhancedbutton.pixmap_width = width; | |
435 eb->enhancedbutton.pixmap_height = height; | |
436 eb->enhancedbutton.normal_pixmap = sen_pix; | |
437 eb->enhancedbutton.highlight_pixmap = high_pix; | |
438 eb->enhancedbutton.insensitive_pixmap = ins_pix; | |
439 eb->enhancedbutton.armed_pixmap = arm_pix; | |
440 | |
441 eb->enhancedbutton.doing_setvalues = True; | |
442 eb->enhancedbutton.doing_setvalues = False; | |
443 | |
444 XFreePixmap(dpy, pix); | |
445 XFreePixmap(dpy, mask); | |
446 } | |
447 | |
448 #define BUTTON_MASK ( \ | |
449 Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask \ | |
450 ) | |
451 | |
452 static void | |
453 draw_shadows(XmEnhancedButtonWidget eb) | |
454 { | |
455 GC top_gc; | |
456 GC bottom_gc; | |
457 Boolean etched_in; | |
458 | |
459 if (!eb->primitive.shadow_thickness) | |
460 return; | |
461 | |
462 if ((eb->core.width <= 2 * eb->primitive.highlight_thickness) | |
463 || (eb->core.height <= 2 * eb->primitive.highlight_thickness)) | |
464 return; | |
465 | |
466 #ifndef LESSTIF_VERSION | |
467 { | |
468 XmDisplay dpy; | |
469 | |
470 dpy = (XmDisplay) XmGetXmDisplay(XtDisplay(eb)); | |
471 etched_in = dpy->display.enable_etched_in_menu; | |
472 } | |
473 #else | |
474 etched_in = False; | |
475 #endif | |
476 if (!etched_in ^ eb->pushbutton.armed) | |
477 { | |
478 top_gc = eb->primitive.top_shadow_GC; | |
479 bottom_gc = eb->primitive.bottom_shadow_GC; | |
480 } | |
481 else | |
482 { | |
483 top_gc = eb->primitive.bottom_shadow_GC; | |
484 bottom_gc = eb->primitive.top_shadow_GC; | |
485 } | |
486 | |
487 XmeDrawShadows(XtDisplay(eb), XtWindow(eb), | |
488 top_gc, | |
489 bottom_gc, | |
490 eb->primitive.highlight_thickness, | |
491 eb->primitive.highlight_thickness, | |
492 eb->core.width - 2 * eb->primitive.highlight_thickness, | |
493 eb->core.height - 2 * eb->primitive.highlight_thickness, | |
494 eb->primitive.shadow_thickness, | |
495 (unsigned)(etched_in ? XmSHADOW_IN : XmSHADOW_OUT)); | |
496 } | |
497 | |
498 static void | |
499 draw_highlight(XmEnhancedButtonWidget eb) | |
500 { | |
501 eb->primitive.highlighted = True; | |
502 eb->primitive.highlight_drawn = True; | |
503 | |
504 if (!XtWidth(eb) || !XtHeight(eb) || !eb->primitive.highlight_thickness) | |
505 return; | |
506 | |
507 XmeDrawHighlight(XtDisplay(eb), XtWindow(eb), | |
508 eb->primitive.highlight_GC, 0, 0, | |
509 XtWidth(eb), XtHeight(eb), | |
510 eb->primitive.highlight_thickness); | |
511 } | |
512 | |
513 static void | |
514 draw_unhighlight(XmEnhancedButtonWidget eb) | |
515 { | |
516 GC manager_background_GC; | |
517 | |
518 eb->primitive.highlighted = False; | |
519 eb->primitive.highlight_drawn = False; | |
520 | |
521 if (!XtWidth(eb) || !XtHeight(eb) || !eb->primitive.highlight_thickness) | |
522 return; | |
523 | |
524 if (XmIsManager(eb->core.parent)) | |
525 { | |
526 #ifndef LESSTIF_VERSION | |
527 XmSpecifyUnhighlightTrait UnhighlightT; | |
528 | |
529 if (((UnhighlightT = (XmSpecifyUnhighlightTrait) XmeTraitGet((XtPointer) | |
530 XtClass(eb->core.parent), XmQTspecifyUnhighlight)) | |
531 != NULL) && (UnhighlightT->getUnhighlightGC != NULL)) | |
532 { | |
533 /* if unhighlight trait in parent use specified GC... */ | |
534 manager_background_GC = | |
535 UnhighlightT->getUnhighlightGC(eb->core.parent, (Widget) eb); | |
536 } | |
537 else | |
538 { | |
539 /* ...otherwise, use parent's background GC */ | |
540 manager_background_GC = ((XmManagerWidget) | |
541 (eb->core.parent))->manager.background_GC; | |
542 } | |
543 #else | |
544 manager_background_GC = ((XmManagerWidget) | |
545 (eb->core.parent))->manager.background_GC; | |
546 #endif | |
547 XmeDrawHighlight(XtDisplay(eb), XtWindow(eb), | |
548 manager_background_GC, | |
549 0, 0, XtWidth(eb), XtHeight(eb), | |
550 eb->primitive.highlight_thickness); | |
551 if (!eb->pushbutton.armed && eb->primitive.shadow_thickness) | |
552 XmeClearBorder(XtDisplay(eb), XtWindow(eb), | |
553 eb->primitive.highlight_thickness, | |
554 eb->primitive.highlight_thickness, | |
555 eb->core.width - 2 * eb->primitive.highlight_thickness, | |
556 eb->core.height - 2 * eb->primitive.highlight_thickness, | |
557 eb->primitive.shadow_thickness); | |
558 } | |
559 else | |
560 XmeClearBorder(XtDisplay(eb), XtWindow(eb), 0, 0, XtWidth(eb), | |
561 XtHeight(eb), eb->primitive.highlight_thickness); | |
562 } | |
563 | |
564 /*ARGSUSED*/ | |
565 static void | |
566 draw_pixmap(XmEnhancedButtonWidget eb, XEvent *event, Region region) | |
567 { | |
568 Pixmap pix; | |
569 GC gc = eb->label.normal_GC; | |
570 int depth; | |
571 Cardinal width; | |
572 Cardinal height; | |
573 Cardinal w; | |
574 Cardinal h; | |
575 int x; | |
576 int y; | |
577 | |
578 if (!XtIsSensitive((Widget) eb)) | |
579 pix = eb->enhancedbutton.insensitive_pixmap; | |
580 else | |
581 { | |
582 if (eb->primitive.highlighted && !eb->pushbutton.armed) | |
583 pix = eb->enhancedbutton.highlight_pixmap; | |
584 else if (eb->pushbutton.armed) | |
585 pix = eb->enhancedbutton.armed_pixmap; | |
586 else | |
587 pix = eb->enhancedbutton.normal_pixmap; | |
588 } | |
589 | |
590 if (pix == None || !eb->enhancedbutton.pixmap_data) | |
591 return; | |
592 | |
593 depth = eb->enhancedbutton.pixmap_depth; | |
594 w = eb->enhancedbutton.pixmap_width; | |
595 h = eb->enhancedbutton.pixmap_height; | |
596 | |
597 gc = eb->label.normal_GC; | |
598 x = eb->primitive.highlight_thickness | |
599 + eb->primitive.shadow_thickness | |
600 + eb->label.margin_width; | |
601 y = eb->primitive.highlight_thickness | |
602 + eb->primitive.shadow_thickness | |
603 + eb->label.margin_height; | |
604 width = eb->core.width - 2 * x; | |
605 if (w < width) | |
606 width = w; | |
607 height = eb->core.height - 2 * y; | |
608 if (h < height) | |
609 height = h; | |
610 if (depth == eb->core.depth) | |
611 XCopyArea(XtDisplay(eb), pix, XtWindow(eb), gc, 0, 0, | |
612 width, height, x, y); | |
613 else if (depth == 1) | |
614 XCopyPlane(XtDisplay(eb), pix, XtWindow(eb), gc, 0, 0, | |
615 width, height, x, y, (unsigned long)1); | |
616 } | |
617 | |
618 /* | |
619 * Draw the label contained in the pushbutton. | |
620 */ | |
621 static void | |
622 draw_label(XmEnhancedButtonWidget eb, XEvent *event, Region region) | |
623 { | |
624 GC tmp_gc = NULL; | |
625 Boolean replaceGC = False; | |
626 Boolean deadjusted = False; | |
627 #ifndef LESSTIF_VERSION | |
628 XmDisplay dpy = (XmDisplay)XmGetXmDisplay(XtDisplay(eb)); | |
629 Boolean etched_in = dpy->display.enable_etched_in_menu; | |
630 #else | |
631 Boolean etched_in = False; | |
632 #endif | |
633 | |
634 if (eb->pushbutton.armed | |
635 && ((!Lab_IsMenupane(eb) && eb->pushbutton.fill_on_arm) | |
636 || (Lab_IsMenupane(eb) && etched_in))) | |
637 { | |
638 if (eb->label.label_type == (int)XmSTRING | |
639 && eb->pushbutton.arm_color == eb->primitive.foreground) | |
640 { | |
641 tmp_gc = eb->label.normal_GC; | |
642 eb->label.normal_GC = eb->pushbutton.background_gc; | |
643 replaceGC = True; | |
644 } | |
645 } | |
646 | |
647 /* | |
648 * If the button contains a labeled pixmap, we will take it instead of our | |
649 * own pixmap. | |
650 */ | |
651 | |
652 if (eb->label.label_type == (int)XmPIXMAP) | |
653 { | |
654 if (eb->pushbutton.armed) | |
655 { | |
656 if (eb->pushbutton.arm_pixmap != XmUNSPECIFIED_PIXMAP) | |
657 eb->label.pixmap = eb->pushbutton.arm_pixmap; | |
658 else | |
659 eb->label.pixmap = eb->pushbutton.unarm_pixmap; | |
660 } | |
661 else | |
662 /* pushbutton is not armed */ | |
663 eb->label.pixmap = eb->pushbutton.unarm_pixmap; | |
664 } | |
665 | |
666 /* | |
667 * Temporarily remove the Xm3D_ENHANCE_PIXEL hack ("adjustment") from the | |
668 * margin values, so we don't confuse Label. | |
669 */ | |
670 if (eb->pushbutton.default_button_shadow_thickness > 0) | |
671 { | |
672 deadjusted = True; | |
673 Lab_MarginLeft(eb) -= Xm3D_ENHANCE_PIXEL; | |
674 Lab_MarginRight(eb) -= Xm3D_ENHANCE_PIXEL; | |
675 Lab_MarginTop(eb) -= Xm3D_ENHANCE_PIXEL; | |
676 Lab_MarginBottom(eb) -= Xm3D_ENHANCE_PIXEL; | |
677 } | |
678 | |
679 { | |
680 XtExposeProc expose; | |
681 | |
682 XtProcessLock(); | |
683 expose = xmLabelClassRec.core_class.expose; | |
684 XtProcessUnlock(); | |
685 (*expose)((Widget) eb, event, region); | |
686 } | |
687 | |
688 if (deadjusted) | |
689 { | |
690 Lab_MarginLeft(eb) += Xm3D_ENHANCE_PIXEL; | |
691 Lab_MarginRight(eb) += Xm3D_ENHANCE_PIXEL; | |
692 Lab_MarginTop(eb) += Xm3D_ENHANCE_PIXEL; | |
693 Lab_MarginBottom(eb) += Xm3D_ENHANCE_PIXEL; | |
694 } | |
695 | |
696 if (replaceGC) | |
697 eb->label.normal_GC = tmp_gc; | |
698 } | |
699 | |
700 /*ARGSUSED*/ | |
701 static void | |
702 Enter(Widget wid, XEvent *event, String *params, Cardinal *num_params) | |
703 { | |
704 XmEnhancedButtonWidget eb = (XmEnhancedButtonWidget) wid; | |
705 XmPushButtonCallbackStruct call_value; | |
706 | |
707 if (Lab_IsMenupane(eb)) | |
708 { | |
709 if ((((ShellWidget) XtParent(XtParent(eb)))->shell.popped_up) | |
710 && _XmGetInDragMode((Widget) eb)) | |
711 { | |
712 #ifndef LESSTIF_VERSION | |
713 XmDisplay dpy = (XmDisplay) XmGetXmDisplay(XtDisplay(wid)); | |
714 Boolean etched_in = dpy->display.enable_etched_in_menu; | |
715 #else | |
716 Boolean etched_in = False; | |
717 #endif | |
718 | |
719 if (eb->pushbutton.armed) | |
720 return; | |
721 | |
722 /* ...so KHelp event is delivered correctly. */ | |
723 _XmSetFocusFlag(XtParent(XtParent(eb)), XmFOCUS_IGNORE, TRUE); | |
724 XtSetKeyboardFocus(XtParent(XtParent(eb)), (Widget) eb); | |
725 _XmSetFocusFlag(XtParent(XtParent(eb)), XmFOCUS_IGNORE, FALSE); | |
726 | |
727 eb->pushbutton.armed = TRUE; | |
728 | |
729 ((XmManagerWidget) XtParent(wid))->manager.active_child = wid; | |
730 | |
731 /* etched in menu button */ | |
732 if (etched_in && !XmIsTearOffButton(eb)) | |
733 { | |
734 XFillRectangle(XtDisplay(eb), XtWindow(eb), | |
735 eb->pushbutton.fill_gc, | |
736 0, 0, eb->core.width, eb->core.height); | |
737 draw_label(eb, event, NULL); | |
738 draw_pixmap(eb, event, NULL); | |
739 } | |
740 | |
741 if ((eb->core.width > 2 * eb->primitive.highlight_thickness) | |
742 && (eb->core.height > | |
743 2 * eb->primitive.highlight_thickness)) | |
744 { | |
745 XmeDrawShadows(XtDisplay(eb), XtWindow(eb), | |
746 eb->primitive.top_shadow_GC, | |
747 eb->primitive.bottom_shadow_GC, | |
748 eb->primitive.highlight_thickness, | |
749 eb->primitive.highlight_thickness, | |
750 eb->core.width - 2 * eb->primitive.highlight_thickness, | |
751 eb->core.height - 2 * eb->primitive.highlight_thickness, | |
752 eb->primitive.shadow_thickness, | |
753 (unsigned)(etched_in ? XmSHADOW_IN : XmSHADOW_OUT)); | |
754 } | |
755 | |
756 if (eb->pushbutton.arm_callback) | |
757 { | |
758 XFlush(XtDisplay(eb)); | |
759 | |
760 call_value.reason = (int)XmCR_ARM; | |
761 call_value.event = event; | |
762 XtCallCallbackList((Widget) eb, | |
763 eb->pushbutton.arm_callback, | |
764 &call_value); | |
765 } | |
766 } | |
767 } | |
768 else | |
769 { | |
770 XtExposeProc expose; | |
771 | |
772 _XmPrimitiveEnter((Widget) eb, event, NULL, NULL); | |
773 if (eb->pushbutton.armed == TRUE) | |
774 { | |
775 XtProcessLock(); | |
776 expose = XtClass(eb)->core_class.expose; | |
777 XtProcessUnlock(); | |
778 (*expose) (wid, event, (Region) NULL); | |
779 } | |
780 | |
781 draw_highlight(eb); | |
782 draw_shadows(eb); | |
783 draw_pixmap(eb, event, NULL); | |
784 } | |
785 } | |
786 | |
787 /*ARGSUSED*/ | |
788 static void | |
789 Leave(Widget wid, XEvent *event, String *params, Cardinal *num_params) | |
790 { | |
791 XmEnhancedButtonWidget eb = (XmEnhancedButtonWidget)wid; | |
792 XmPushButtonCallbackStruct call_value; | |
793 | |
794 if (Lab_IsMenupane(eb)) | |
795 { | |
796 #ifndef LESSTIF_VERSION | |
797 XmDisplay dpy = (XmDisplay) XmGetXmDisplay(XtDisplay(wid)); | |
798 Boolean etched_in = dpy->display.enable_etched_in_menu; | |
799 #else | |
800 Boolean etched_in = False; | |
801 #endif | |
802 | |
803 if (_XmGetInDragMode((Widget)eb) | |
804 && eb->pushbutton.armed | |
805 && ( /* !ActiveTearOff || */ | |
806 event->xcrossing.mode == NotifyNormal)) | |
807 { | |
808 eb->pushbutton.armed = FALSE; | |
809 | |
810 ((XmManagerWidget) XtParent(wid))->manager.active_child = NULL; | |
811 | |
812 if (etched_in && !XmIsTearOffButton(eb)) | |
813 { | |
814 XFillRectangle(XtDisplay(eb), XtWindow(eb), | |
815 eb->pushbutton.background_gc, | |
816 0, 0, eb->core.width, eb->core.height); | |
817 draw_label(eb, event, NULL); | |
818 draw_pixmap(eb, event, NULL); | |
819 } | |
820 else | |
821 XmeClearBorder | |
822 (XtDisplay(eb), XtWindow(eb), | |
823 eb->primitive.highlight_thickness, | |
824 eb->primitive.highlight_thickness, | |
825 eb->core.width - | |
826 2 * eb->primitive.highlight_thickness, | |
827 eb->core.height - | |
828 2 * eb->primitive.highlight_thickness, | |
829 eb->primitive.shadow_thickness); | |
830 | |
831 if (eb->pushbutton.disarm_callback) | |
832 { | |
833 XFlush(XtDisplay(eb)); | |
834 | |
835 call_value.reason = (int)XmCR_DISARM; | |
836 call_value.event = event; | |
837 XtCallCallbackList((Widget) eb, | |
838 eb->pushbutton.disarm_callback, | |
839 &call_value); | |
840 } | |
841 } | |
842 } | |
843 else | |
844 { | |
845 _XmPrimitiveLeave((Widget) eb, event, NULL, NULL); | |
846 | |
847 if (eb->pushbutton.armed == TRUE) | |
848 { | |
849 XtExposeProc expose; | |
850 eb->pushbutton.armed = FALSE; | |
851 XtProcessLock(); | |
852 expose = XtClass(eb)->core_class.expose; | |
853 XtProcessUnlock(); | |
854 (*expose) (wid, event, (Region)NULL); | |
855 draw_unhighlight(eb); | |
856 draw_pixmap(eb, event, NULL); | |
857 eb->pushbutton.armed = TRUE; | |
858 } | |
859 else | |
860 { | |
861 draw_unhighlight(eb); | |
862 draw_pixmap(eb, event, NULL); | |
863 } | |
864 } | |
865 } | |
866 | |
867 #define IsNull(p) ((p) == XmUNSPECIFIED_PIXMAP) | |
868 | |
869 static void | |
870 set_size(XmEnhancedButtonWidget newtb) | |
871 { | |
872 unsigned int w = 0; | |
873 unsigned int h = 0; | |
874 | |
875 _XmCalcLabelDimensions((Widget) newtb); | |
876 | |
877 /* Find out how big the pixmap is */ | |
878 if (newtb->enhancedbutton.pixmap_data | |
879 && !IsNull(newtb->label.pixmap) | |
880 && !IsNull(newtb->enhancedbutton.normal_pixmap)) | |
881 { | |
882 w = newtb->enhancedbutton.pixmap_width; | |
883 h = newtb->enhancedbutton.pixmap_height; | |
884 } | |
885 | |
886 /* | |
887 * Plase note that we manipulate the width only in case of push buttons not | |
888 * used in the context of a menu pane. | |
889 */ | |
890 if (Lab_IsMenupane(newtb)) | |
891 { | |
892 newtb->label.margin_left = w + 2 * (newtb->primitive.shadow_thickness | |
893 + newtb->primitive.highlight_thickness) | |
894 + newtb->label.margin_width; | |
895 } | |
896 else | |
897 { | |
898 newtb->label.margin_left = w; | |
899 newtb->core.width = w + 2 * (newtb->primitive.shadow_thickness | |
900 + newtb->primitive.highlight_thickness | |
901 + newtb->label.margin_width) | |
902 + newtb->label.TextRect.width; | |
903 | |
904 if (newtb->label.TextRect.width > 0) | |
905 { | |
906 newtb->label.margin_left += newtb->label.margin_width | |
907 + newtb->primitive.shadow_thickness; | |
908 newtb->core.width += newtb->label.margin_width | |
909 + newtb->primitive.shadow_thickness; | |
910 } | |
911 } | |
912 if (newtb->label.TextRect.height < h) | |
913 { | |
914 newtb->core.height = h + 2 * (newtb->primitive.shadow_thickness | |
915 + newtb->primitive.highlight_thickness | |
916 + newtb->label.margin_height); | |
917 } | |
918 else | |
919 { | |
920 /* FIXME: We should calculate an drawing offset for the pixmap here to | |
921 * adjust it. */ | |
922 } | |
923 | |
924 #if 0 | |
925 printf("%d %d %d %d %d %d - %d %d\n", newtb->enhancedbutton.normal_pixmap, | |
926 h, newtb->core.height, | |
927 newtb->primitive.shadow_thickness, | |
928 newtb->primitive.highlight_thickness, | |
929 newtb->label.margin_height, | |
930 newtb->core.width, | |
931 newtb->core.height); | |
932 #endif | |
933 | |
934 /* Invoke Label's Resize procedure. */ | |
935 { | |
936 XtWidgetProc resize; | |
937 XtProcessLock(); | |
938 resize = xmLabelClassRec.core_class.resize; | |
939 XtProcessUnlock(); | |
940 | |
941 (* resize) ((Widget) newtb); | |
942 } | |
943 } | |
944 | |
945 /*ARGSUSED*/ | |
946 static void | |
947 Initialize(Widget rq, Widget ebw, ArgList args, Cardinal *n) | |
948 { | |
949 XmEnhancedButtonWidget request = (XmEnhancedButtonWidget)rq; | |
950 XmEnhancedButtonWidget eb = (XmEnhancedButtonWidget)ebw; | |
951 XtWidgetProc resize; | |
952 | |
953 XtProcessLock(); | |
954 resize = xmLabelClassRec.core_class.resize; | |
955 XtProcessUnlock(); | |
956 | |
957 /* Create a bitmap for stippling (Drawable resources are cheap). */ | |
958 if (STIPPLE_BITMAP == None) | |
959 { | |
960 Display *dpy = XtDisplay((Widget) request); | |
961 Window rootW = DefaultRootWindow(dpy); | |
962 | |
963 STIPPLE_BITMAP = XCreateBitmapFromData(dpy, rootW, stipple_bits, | |
964 stipple_width, stipple_height); | |
965 } | |
966 eb->enhancedbutton.doing_setvalues = False; | |
967 | |
968 /* First see what type of extended label this is. | |
969 */ | |
970 if (eb->enhancedbutton.pixmap_data) | |
971 { | |
972 XmString str; | |
973 set_pixmap(eb); | |
974 | |
975 /* FIXME: this is not the perfect way to deal with menues, which do not | |
976 * have any string set right now. */ | |
977 str = XmStringCreateLocalized(""); | |
978 XtVaSetValues((Widget) eb, XmNlabelString, str, NULL); | |
979 XmStringFree(str); | |
980 } | |
981 eb->label.pixmap = eb->enhancedbutton.normal_pixmap; | |
982 | |
983 if (request->core.width == 0) | |
984 eb->core.width = 0; | |
985 if (request->core.height == 0) | |
986 eb->core.height = 0; | |
987 set_size(eb); | |
988 | |
989 (* resize)((Widget)eb); | |
990 } | |
991 | |
992 static void | |
993 free_pixmaps(XmEnhancedButtonWidget eb) | |
994 { | |
995 /* | |
996 * Clear the old pixmaps. | |
997 */ | |
998 Pixmap norm_pix = eb->enhancedbutton.normal_pixmap; | |
999 Pixmap arm_pix = eb->enhancedbutton.armed_pixmap; | |
1000 Pixmap insen_pix = eb->enhancedbutton.insensitive_pixmap; | |
1001 Pixmap high_pix = eb->enhancedbutton.highlight_pixmap; | |
1002 | |
1003 if (norm_pix != None && norm_pix != XmUNSPECIFIED_PIXMAP) | |
1004 XFreePixmap(XtDisplay(eb), norm_pix); | |
1005 | |
1006 if (arm_pix != None && arm_pix != XmUNSPECIFIED_PIXMAP) | |
1007 XFreePixmap(XtDisplay(eb), arm_pix); | |
1008 | |
1009 if (insen_pix != None && insen_pix != XmUNSPECIFIED_PIXMAP) | |
1010 XFreePixmap(XtDisplay(eb), insen_pix); | |
1011 | |
1012 if (high_pix != None && high_pix != XmUNSPECIFIED_PIXMAP) | |
1013 XFreePixmap(XtDisplay(eb), high_pix); | |
1014 } | |
1015 | |
1016 static void | |
1017 Destroy(Widget w) | |
1018 { | |
1019 if (!XmIsEnhancedButton(w)) | |
1020 return; | |
1021 | |
1022 free_pixmaps((XmEnhancedButtonWidget)w); | |
1023 } | |
1024 | |
1025 /*ARGSUSED*/ | |
1026 static Boolean | |
1027 SetValues(Widget current, Widget request, Widget new, ArgList args, Cardinal *n) | |
1028 { | |
1029 XmEnhancedButtonWidget cur = (XmEnhancedButtonWidget) current; | |
1030 XmEnhancedButtonWidget eb = (XmEnhancedButtonWidget) new; | |
1031 Boolean redraw = False; | |
1032 Boolean change = True; | |
1033 Display *dpy = XtDisplay(current); | |
1034 | |
1035 #define NOT_EQUAL(field) (cur->field != eb->field) | |
1036 | |
1037 /* | |
1038 * Make sure that lost sensitivity is causing the border to vanish as well. | |
1039 */ | |
1040 if (NOT_EQUAL(core.sensitive) && !Lab_IsMenupane(current)) | |
1041 { | |
1042 if (cur->core.sensitive == True) | |
1043 { | |
1044 draw_unhighlight(eb); | |
1045 } | |
1046 else | |
1047 { | |
1048 int r_x; | |
1049 int r_y; | |
1050 unsigned int r_height; | |
1051 unsigned int r_width; | |
1052 unsigned int r_border; | |
1053 unsigned int r_depth; | |
1054 int root_x; | |
1055 int root_y; | |
1056 int win_x; | |
1057 int win_y; | |
1058 Window root; | |
1059 Window root_q; | |
1060 Window child; | |
1061 unsigned int mask; | |
1062 | |
1063 /* | |
1064 * Aritificially let the highlight appear if the mouse is over us. | |
1065 */ | |
1066 /* Best way to get the root window of object: */ | |
1067 XGetGeometry(dpy, XtWindow(cur), &root, &r_x, &r_y, &r_width, | |
1068 &r_height, &r_border, &r_depth); | |
1069 XQueryPointer(XtDisplay(cur), XtWindow(cur), &root_q, &child, | |
1070 &root_x, &root_y, &win_x, &win_y, &mask); | |
1071 | |
1072 if (root == root_q) | |
1073 { | |
1074 if ((win_x < 0) || (win_y < 0)) | |
1075 return False; | |
1076 | |
1077 if ((win_x > r_width) || (win_y > r_height)) | |
1078 return False; | |
1079 draw_highlight(eb); | |
1080 draw_shadows(eb); | |
1081 } | |
1082 } | |
1083 | |
1084 return True; | |
1085 } | |
1086 | |
1087 /* | |
1088 * Check for changed ExtLabelString. | |
1089 */ | |
1090 if (NOT_EQUAL(primitive.shadow_thickness)) | |
1091 { | |
1092 redraw = True; | |
1093 /* Don't change the pixmaps */ | |
1094 change = False; | |
1095 } | |
1096 | |
1097 if (NOT_EQUAL(primitive.foreground)) | |
1098 redraw = True; | |
1099 if (NOT_EQUAL(core.background_pixel)) | |
1100 redraw = True; | |
1101 if (NOT_EQUAL(pushbutton.fill_on_arm)) | |
1102 redraw = True; | |
1103 if (NOT_EQUAL(enhancedbutton.spacing)) | |
1104 redraw = True; | |
1105 if (NOT_EQUAL(enhancedbutton.label_location)) | |
1106 { | |
1107 redraw = True; | |
1108 change = False; | |
1109 } | |
1110 if (NOT_EQUAL(label._label)) | |
1111 { | |
1112 redraw = True; | |
1113 set_size(eb); | |
1114 } | |
1115 | |
1116 if (redraw == True) | |
1117 { | |
1118 if (change) | |
1119 set_pixmap(eb); | |
1120 if (eb->primitive.highlighted) | |
1121 eb->label.pixmap = eb->enhancedbutton.highlight_pixmap; | |
1122 else | |
1123 eb->label.pixmap = eb->enhancedbutton.normal_pixmap; | |
1124 if (change) | |
1125 set_size(eb); | |
1126 redraw = False; | |
1127 } | |
1128 | |
1129 return redraw; | |
1130 } | |
1131 | |
1132 static void | |
1133 Redisplay(Widget w, XEvent *event, Region region) | |
1134 { | |
1135 XmEnhancedButtonWidget eb = (XmEnhancedButtonWidget) w; | |
1136 #ifndef LESSTIF_VERSION | |
1137 XmDisplay dpy; | |
1138 XtEnum default_button_emphasis; | |
1139 #endif | |
1140 XRectangle box; | |
1141 int dx; | |
1142 int adjust; | |
1143 short fill = 0; | |
1144 | |
1145 if (!XtIsRealized((Widget)eb)) | |
1146 return; | |
1147 | |
1148 #ifndef LESSTIF_VERSION | |
1149 dpy = (XmDisplay)XmGetXmDisplay(XtDisplay(eb)); | |
1150 default_button_emphasis = dpy->display.default_button_emphasis; | |
1151 #endif | |
1152 | |
1153 /* | |
1154 * Compute the area allocated to the label of the pushbutton; fill in the | |
1155 * dimensions in the box. | |
1156 */ | |
1157 | |
1158 if ((eb->pushbutton.arm_color == eb->primitive.top_shadow_color) | |
1159 || (eb->pushbutton.arm_color == eb->primitive.bottom_shadow_color)) | |
1160 fill = 1; | |
1161 | |
1162 if (eb->pushbutton.compatible) | |
1163 adjust = eb->pushbutton.show_as_default; | |
1164 else | |
1165 adjust = eb->pushbutton.default_button_shadow_thickness; | |
1166 | |
1167 if (adjust > 0) | |
1168 { | |
1169 adjust = adjust + eb->primitive.shadow_thickness; | |
1170 adjust = (adjust << 1); | |
1171 dx = eb->primitive.highlight_thickness + adjust + fill; | |
1172 } | |
1173 else | |
1174 dx = (eb->primitive.highlight_thickness | |
1175 + eb->primitive.shadow_thickness + fill); | |
1176 | |
1177 box.x = dx; | |
1178 box.y = dx; | |
1179 adjust = (dx << 1); | |
1180 box.width = eb->core.width - adjust; | |
1181 box.height = eb->core.height - adjust; | |
1182 | |
1183 /* | |
1184 * Redraw the background. | |
1185 */ | |
1186 if (!Lab_IsMenupane(eb)) | |
1187 { | |
1188 GC gc; | |
1189 | |
1190 /* Don't shade if the button contains a label with a pixmap, since | |
1191 * there is no variant of the label available with the needed | |
1192 * background. | |
1193 */ | |
1194 if (eb->pushbutton.armed && eb->pushbutton.fill_on_arm) | |
1195 { | |
1196 if (eb->label.label_type == (int)XmPIXMAP) | |
1197 { | |
1198 if (eb->pushbutton.arm_pixmap != XmUNSPECIFIED_PIXMAP) | |
1199 gc = eb->pushbutton.fill_gc; | |
1200 else | |
1201 gc = eb->pushbutton.background_gc; | |
1202 } | |
1203 else | |
1204 gc = eb->pushbutton.fill_gc; | |
1205 } | |
1206 else | |
1207 gc = eb->pushbutton.background_gc; | |
1208 /* really need to fill with background if not armed ? */ | |
1209 if (gc) | |
1210 XFillRectangle(XtDisplay(eb), XtWindow(eb), gc, | |
1211 box.x, box.y, box.width, box.height); | |
1212 } | |
1213 | |
1214 draw_label(eb, event, region); | |
1215 | |
1216 if (Lab_IsMenupane(eb)) | |
1217 { | |
1218 if (eb->pushbutton.armed) | |
1219 (*(((XmPushButtonWidgetClass)XtClass(eb)) | |
1220 ->primitive_class.border_highlight))(w); | |
1221 draw_pixmap(eb, event, region); | |
1222 } | |
1223 else | |
1224 { | |
1225 int adjust = 0; | |
1226 | |
1227 #ifndef LESSTIF_VERSION | |
1228 /* | |
1229 * NOTE: PushButton has two types of shadows: primitive-shadow and | |
1230 * default-button-shadow. If pushbutton is in a menu only primitive | |
1231 * shadows are drawn. | |
1232 */ | |
1233 switch (default_button_emphasis) | |
1234 { | |
1235 case XmEXTERNAL_HIGHLIGHT: | |
1236 adjust = (eb->primitive.highlight_thickness - | |
1237 (eb->pushbutton.default_button_shadow_thickness ? | |
1238 Xm3D_ENHANCE_PIXEL : 0)); | |
1239 break; | |
1240 | |
1241 case XmINTERNAL_HIGHLIGHT: | |
1242 adjust = 0; | |
1243 break; | |
1244 | |
1245 default: | |
1246 assert(FALSE); | |
1247 return; | |
1248 } | |
1249 #endif | |
1250 | |
1251 /* | |
1252 * Clear the area not occupied by label with parents background color. | |
1253 * Label will invoke BorderUnhighlight() on the highlight_thickness | |
1254 * area, which is redundant when XmEXTERNAL_HIGHLIGHT default button | |
1255 * shadow emphasis is used. | |
1256 */ | |
1257 if (box.x > adjust) | |
1258 { | |
1259 int borderwidth =box.x - adjust; | |
1260 int rectwidth = eb->core.width - 2 * adjust; | |
1261 int rectheight = eb->core.height - 2 * adjust; | |
1262 | |
1263 if (XmIsManager(XtParent(eb))) | |
1264 { | |
1265 XmeDrawHighlight(XtDisplay(eb), XtWindow(eb), | |
1266 XmParentBackgroundGC(eb), | |
1267 adjust, adjust, rectwidth, rectheight, borderwidth); | |
1268 } | |
1269 else | |
1270 { | |
1271 XmeClearBorder(XtDisplay(eb), XtWindow(eb), | |
1272 adjust, adjust, rectwidth, rectheight, borderwidth); | |
1273 } | |
1274 | |
1275 #ifndef LESSTIF_VERSION | |
1276 switch (default_button_emphasis) | |
1277 { | |
1278 case XmINTERNAL_HIGHLIGHT: | |
1279 /* The call above erases the border highlighting. */ | |
1280 if (eb->primitive.highlight_drawn) | |
1281 (*(((XmPushButtonWidgetClass) XtClass (eb)) | |
1282 ->primitive_class.border_highlight)) ((Widget) eb) ; | |
1283 break; | |
1284 | |
1285 default: | |
1286 break; | |
1287 } | |
1288 #endif | |
1289 } | |
1290 | |
1291 if (eb->pushbutton.default_button_shadow_thickness) | |
1292 { | |
1293 if (eb->pushbutton.show_as_default) | |
1294 { | |
1295 /* | |
1296 * - get the topShadowColor and bottomShadowColor from the | |
1297 * parent; use those colors to construct top and bottom gc; | |
1298 * use these GCs to draw the shadows of the button. | |
1299 * | |
1300 * - Should not be called if pushbutton is in a row column or | |
1301 * in a menu. | |
1302 * | |
1303 * - Should be called only if a defaultbuttonshadow is to be | |
1304 * drawn. | |
1305 */ | |
1306 GC top_gc; | |
1307 GC bottom_gc; | |
1308 int default_button_shadow_thickness; | |
1309 int x, y, width, height, delta; | |
1310 Widget parent; | |
1311 | |
1312 if (eb->pushbutton.compatible | |
1313 && (eb->pushbutton.show_as_default == 0)) | |
1314 return; | |
1315 | |
1316 if (!eb->pushbutton.compatible | |
1317 && (eb->pushbutton.default_button_shadow_thickness | |
1318 == 0)) | |
1319 return; | |
1320 | |
1321 delta = eb->primitive.highlight_thickness; | |
1322 | |
1323 /* | |
1324 * May need more complex computation for getting the GCs. | |
1325 */ | |
1326 parent = XtParent(eb); | |
1327 if (XmIsManager(parent)) | |
1328 { | |
1329 /* Use the parent's GC so monochrome works. */ | |
1330 bottom_gc = XmParentTopShadowGC(eb); | |
1331 top_gc = XmParentBottomShadowGC(eb); | |
1332 } | |
1333 else | |
1334 { | |
1335 /* Use your own pixel for drawing. */ | |
1336 bottom_gc = eb->primitive.top_shadow_GC; | |
1337 top_gc = eb->primitive.bottom_shadow_GC; | |
1338 } | |
1339 | |
1340 if ((bottom_gc == None) || (top_gc == None)) | |
1341 return; | |
1342 | |
1343 | |
1344 if (eb->pushbutton.compatible) | |
1345 default_button_shadow_thickness = | |
1346 eb->pushbutton.show_as_default; | |
1347 else | |
1348 default_button_shadow_thickness = | |
1349 eb->pushbutton.default_button_shadow_thickness; | |
1350 | |
1351 #ifndef LESSTIF_VERSION | |
1352 /* | |
1353 * Compute location of bounding box to contain the | |
1354 * defaultButtonShadow. | |
1355 */ | |
1356 switch (default_button_emphasis) | |
1357 { | |
1358 case XmEXTERNAL_HIGHLIGHT: | |
1359 delta = eb->primitive.highlight_thickness; | |
1360 break; | |
1361 | |
1362 case XmINTERNAL_HIGHLIGHT: | |
1363 delta = Xm3D_ENHANCE_PIXEL; | |
1364 break; | |
1365 | |
1366 default: | |
1367 assert(FALSE); | |
1368 return; | |
1369 } | |
1370 #endif | |
1371 | |
1372 x = y = delta; | |
1373 width = eb->core.width - 2 * delta; | |
1374 height = eb->core.height - 2 * delta; | |
1375 | |
1376 if ((width > 0) && (height > 0)) | |
1377 XmeDrawShadows(XtDisplay(eb), XtWindow(eb), | |
1378 top_gc, bottom_gc, x, y, width, height, | |
1379 default_button_shadow_thickness, | |
1380 (unsigned)XmSHADOW_OUT); | |
1381 } | |
1382 } | |
1383 | |
1384 if (eb->primitive.highlight_drawn) | |
1385 draw_shadows(eb); | |
1386 draw_pixmap(eb, event, region); | |
1387 } | |
1388 } | |
1389 | |
1390 static void | |
1391 BorderHighlight(Widget w) | |
1392 { | |
1393 XmEnhancedButtonWidget eb = (XmEnhancedButtonWidget)w; | |
1394 | |
1395 (*(xmPushButtonClassRec.primitive_class.border_highlight))(w); | |
1396 draw_pixmap(eb, NULL, NULL); | |
1397 } | |
1398 | |
1399 static void | |
1400 BorderUnhighlight(Widget w) | |
1401 { | |
1402 XmEnhancedButtonWidget eb = (XmEnhancedButtonWidget)w; | |
1403 | |
1404 (*(xmPushButtonClassRec.primitive_class.border_unhighlight))(w); | |
1405 draw_pixmap(eb, NULL, NULL); | |
1406 } |