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