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