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