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