0
|
1 /* Implements a lightweight menubar widget.
|
|
2 Copyright (C) 1992, 1993, 1994 Lucid, Inc.
|
|
3 Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
|
|
4
|
|
5 This file is part of the Lucid Widget Library.
|
|
6
|
|
7 The Lucid Widget Library is free software; you can redistribute it and/or
|
|
8 modify it under the terms of the GNU General Public License as published by
|
|
9 the Free Software Foundation; either version 2, or (at your option)
|
|
10 any later version.
|
|
11
|
|
12 The Lucid Widget Library is distributed in the hope that it will be useful,
|
|
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 GNU General Public License for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with GNU Emacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
20
|
|
21 /* Created by devin@lucid.com */
|
|
22
|
|
23 #include <stdlib.h>
|
|
24 #include <unistd.h>
|
|
25 #include <string.h>
|
|
26 #include <ctype.h>
|
|
27 #include <stdio.h>
|
|
28
|
|
29 #include <sys/types.h>
|
|
30 #include <X11/Xos.h>
|
|
31 #include <X11/IntrinsicP.h>
|
|
32 #include <X11/StringDefs.h>
|
|
33 #include <X11/cursorfont.h>
|
|
34 #include <X11/bitmaps/gray>
|
|
35
|
|
36 #ifdef NEED_MOTIF
|
|
37 #include <Xm/Xm.h>
|
|
38 #endif
|
|
39 #include "xlwmenuP.h"
|
|
40
|
|
41 static char
|
|
42 xlwMenuTranslations [] =
|
|
43 "<BtnDown>: start()\n\
|
|
44 <BtnMotion>: drag()\n\
|
|
45 <BtnUp>: select()\n\
|
|
46 ";
|
|
47
|
|
48 #define offset(field) XtOffset(XlwMenuWidget, field)
|
|
49 static XtResource
|
|
50 xlwMenuResources[] =
|
|
51 {
|
|
52 #ifdef NEED_MOTIF
|
|
53 /* There are three font list resources, so that we can accept either of
|
|
54 the resources *fontList: or *font:, and so that we can tell the
|
|
55 difference between them being specified, and being defaulted to a
|
|
56 font from the XtRString specified here.
|
|
57 */
|
|
58 {XmNfontList, XmCFontList, XmRFontList, sizeof(XmFontList),
|
|
59 offset(menu.font_list), XtRImmediate, (XtPointer)0},
|
|
60 {XtNfont, XtCFont, XmRFontList, sizeof(XmFontList),
|
|
61 offset(menu.font_list_2),XtRImmediate, (XtPointer)0},
|
|
62 {XmNfontList, XmCFontList, XmRFontList, sizeof(XmFontList),
|
|
63 offset(menu.fallback_font_list),
|
|
64 /* We must use an iso8859-1 font here, or people without $LANG set lose.
|
|
65 It's fair to assume that those who do have $LANG set also have the
|
|
66 *fontList resource set, or at least know how to deal with this.
|
|
67 */
|
2
|
68 XtRString, (String) "-*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-1"},
|
0
|
69 #else
|
|
70 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
|
2
|
71 offset(menu.font), XtRString, "XtDefaultFont"},
|
0
|
72 #endif
|
|
73 {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
|
2
|
74 offset(menu.foreground), XtRString, (String) "XtDefaultForeground"},
|
0
|
75 {XtNbuttonForeground, XtCButtonForeground, XtRPixel, sizeof(Pixel),
|
2
|
76 offset(menu.button_foreground), XtRString, (String)"XtDefaultForeground"},
|
0
|
77 {XtNmargin, XtCMargin, XtRDimension, sizeof(Dimension),
|
|
78 offset(menu.margin), XtRImmediate, (XtPointer)2},
|
|
79 {XmNmarginWidth, XmCMarginWidth, XmRHorizontalDimension, sizeof(Dimension),
|
|
80 offset(menu.horizontal_margin), XtRImmediate, (XtPointer)2},
|
|
81 {XmNmarginHeight, XmCMarginHeight, XmRVerticalDimension, sizeof(Dimension),
|
|
82 offset(menu.vertical_margin), XtRImmediate, (XtPointer)1},
|
|
83 {XmNspacing, XmCSpacing, XmRHorizontalDimension, sizeof(Dimension),
|
|
84 offset(menu.column_spacing), XtRImmediate, (XtPointer)4},
|
|
85 {XmNindicatorSize, XmCIndicatorSize, XtRDimension, sizeof(Dimension),
|
|
86 offset(menu.indicator_size), XtRImmediate, (XtPointer)0},
|
|
87 {XmNshadowThickness, XmCShadowThickness, XmRHorizontalDimension,
|
|
88 sizeof (Dimension), offset (menu.shadow_thickness),
|
|
89 XtRImmediate, (XtPointer) 2},
|
|
90 {XmNselectColor, XmCSelectColor, XtRPixel, sizeof (Pixel),
|
|
91 offset (menu.select_color), XtRImmediate, (XtPointer)-1},
|
|
92 {XmNtopShadowColor, XmCTopShadowColor, XtRPixel, sizeof (Pixel),
|
|
93 offset (menu.top_shadow_color), XtRImmediate, (XtPointer)-1},
|
|
94 {XmNbottomShadowColor, XmCBottomShadowColor, XtRPixel, sizeof (Pixel),
|
|
95 offset (menu.bottom_shadow_color), XtRImmediate, (XtPointer)-1},
|
|
96 {XmNtopShadowPixmap, XmCTopShadowPixmap, XtRPixmap, sizeof (Pixmap),
|
|
97 offset (menu.top_shadow_pixmap), XtRImmediate, (XtPointer)None},
|
|
98 {XmNbottomShadowPixmap, XmCBottomShadowPixmap, XtRPixmap, sizeof (Pixmap),
|
|
99 offset (menu.bottom_shadow_pixmap), XtRImmediate, (XtPointer)None},
|
|
100
|
|
101 {XtNopen, XtCCallback, XtRCallback, sizeof(XtPointer),
|
|
102 offset(menu.open), XtRCallback, (XtPointer)NULL},
|
|
103 {XtNselect, XtCCallback, XtRCallback, sizeof(XtPointer),
|
|
104 offset(menu.select), XtRCallback, (XtPointer)NULL},
|
|
105 {XtNmenu, XtCMenu, XtRPointer, sizeof(XtPointer),
|
|
106 offset(menu.contents), XtRImmediate, (XtPointer)NULL},
|
|
107 {XtNcursor, XtCCursor, XtRCursor, sizeof(Cursor),
|
|
108 offset(menu.cursor_shape), XtRString, (XtPointer)"right_ptr"},
|
|
109 {XtNhorizontal, XtCHorizontal, XtRInt, sizeof(int),
|
|
110 offset(menu.horizontal), XtRImmediate, (XtPointer)True},
|
|
111 {XtNuseBackingStore, XtCUseBackingStore, XtRBoolean, sizeof (Boolean),
|
|
112 offset (menu.use_backing_store), XtRImmediate, (XtPointer)False},
|
|
113 {XtNbounceDown, XtCBounceDown, XtRBoolean, sizeof (Boolean),
|
|
114 offset (menu.bounce_down), XtRImmediate, (XtPointer)True},
|
|
115 {XtNresourceLabels, XtCResourceLabels, XtRBoolean, sizeof (Boolean),
|
|
116 offset (menu.lookup_labels), XtRImmediate, (XtPointer)False},
|
|
117 };
|
|
118 #undef offset
|
|
119
|
|
120 static Boolean XlwMenuSetValues (Widget current, Widget request, Widget new,
|
|
121 ArgList args, Cardinal *num_args);
|
|
122 static void XlwMenuRealize (Widget w, Mask *valueMask,
|
|
123 XSetWindowAttributes *attributes);
|
|
124 static void XlwMenuRedisplay (Widget w, XEvent *ev, Region region);
|
|
125 static void XlwMenuResize (Widget w);
|
|
126 static void XlwMenuInitialize (Widget request, Widget new, ArgList args,
|
|
127 Cardinal *num_args);
|
|
128 static void XlwMenuDestroy (Widget w);
|
|
129 static void XlwMenuClassInitialize (void);
|
|
130 static void Start (Widget w, XEvent *ev, String *params, Cardinal *num_params);
|
|
131 static void Drag (Widget w, XEvent *ev, String *params, Cardinal *num_params);
|
|
132 static void Select (Widget w, XEvent *ev, String *params,
|
|
133 Cardinal *num_params);
|
|
134
|
|
135 #ifdef NEED_MOTIF
|
|
136 static XFontStruct *default_font_of_font_list (XmFontList);
|
|
137 #endif
|
|
138
|
|
139 static XtActionsRec
|
|
140 xlwMenuActionsList [] =
|
|
141 {
|
2
|
142 {(String) "start", Start},
|
|
143 {(String) "drag", Drag},
|
|
144 {(String) "select", Select},
|
0
|
145 };
|
|
146
|
|
147 #define SuperClass ((CoreWidgetClass)&coreClassRec)
|
|
148
|
|
149 XlwMenuClassRec xlwMenuClassRec =
|
|
150 {
|
|
151 { /* CoreClass fields initialization */
|
|
152 (WidgetClass) SuperClass, /* superclass */
|
2
|
153 (String) "XlwMenu", /* class_name */
|
0
|
154 sizeof(XlwMenuRec), /* size */
|
|
155 XlwMenuClassInitialize, /* class_initialize */
|
|
156 NULL, /* class_part_initialize */
|
|
157 FALSE, /* class_inited */
|
|
158 XlwMenuInitialize, /* initialize */
|
|
159 NULL, /* initialize_hook */
|
|
160 XlwMenuRealize, /* realize */
|
|
161 xlwMenuActionsList, /* actions */
|
|
162 XtNumber(xlwMenuActionsList), /* num_actions */
|
|
163 xlwMenuResources, /* resources */
|
|
164 XtNumber(xlwMenuResources), /* resource_count */
|
|
165 NULLQUARK, /* xrm_class */
|
|
166 TRUE, /* compress_motion */
|
|
167 TRUE, /* compress_exposure */
|
|
168 TRUE, /* compress_enterleave */
|
|
169 FALSE, /* visible_interest */
|
|
170 XlwMenuDestroy, /* destroy */
|
|
171 XlwMenuResize, /* resize */
|
|
172 XlwMenuRedisplay, /* expose */
|
|
173 XlwMenuSetValues, /* set_values */
|
|
174 NULL, /* set_values_hook */
|
|
175 XtInheritSetValuesAlmost, /* set_values_almost */
|
|
176 NULL, /* get_values_hook */
|
|
177 NULL, /* #### - should this be set for grabs? accept_focus */
|
|
178 XtVersion, /* version */
|
|
179 NULL, /* callback_private */
|
|
180 xlwMenuTranslations, /* tm_table */
|
|
181 XtInheritQueryGeometry, /* query_geometry */
|
|
182 XtInheritDisplayAccelerator, /* display_accelerator */
|
|
183 NULL /* extension */
|
|
184 }, /* XlwMenuClass fields initialization */
|
|
185 {
|
|
186 0 /* dummy */
|
|
187 },
|
|
188 };
|
|
189
|
|
190 WidgetClass xlwMenuWidgetClass = (WidgetClass) &xlwMenuClassRec;
|
|
191
|
|
192 /* Utilities */
|
|
193 #if 0 /* Apparently not used anywhere */
|
|
194
|
|
195 static char *
|
|
196 safe_strdup (char *s)
|
|
197 {
|
|
198 char *result;
|
|
199 if (! s) return 0;
|
|
200 result = (char *) malloc (strlen (s) + 1);
|
|
201 if (! result)
|
|
202 return 0;
|
|
203 strcpy (result, s);
|
|
204 return result;
|
|
205 }
|
|
206
|
|
207 #endif /* 0 */
|
|
208
|
|
209 /* Replacement for XAllocColor() that tries to return the nearest
|
|
210 available color if the colormap is full. From FSF Emacs. */
|
|
211
|
|
212 static int
|
|
213 allocate_nearest_color (Display *display, Colormap screen_colormap,
|
|
214 XColor *color_def)
|
|
215 {
|
|
216 int status;
|
|
217
|
|
218 status = XAllocColor (display, screen_colormap, color_def);
|
|
219 if (!status)
|
|
220 {
|
|
221 /* If we got to this point, the colormap is full, so we're
|
|
222 going to try and get the next closest color.
|
|
223 The algorithm used is a least-squares matching, which is
|
|
224 what X uses for closest color matching with StaticColor visuals. */
|
|
225
|
|
226 XColor *cells;
|
|
227 int no_cells;
|
|
228 int nearest;
|
|
229 long nearest_delta, trial_delta;
|
|
230 int x;
|
|
231
|
|
232 no_cells = XDisplayCells (display, XDefaultScreen (display));
|
|
233 /* Don't use alloca here because lwlib doesn't have the
|
|
234 necessary configuration information that src does. */
|
|
235 cells = (XColor *) malloc (sizeof (XColor) * no_cells);
|
|
236
|
|
237 for (x = 0; x < no_cells; x++)
|
|
238 cells[x].pixel = x;
|
|
239
|
|
240 XQueryColors (display, screen_colormap, cells, no_cells);
|
|
241 nearest = 0;
|
|
242 /* I'm assuming CSE so I'm not going to condense this. */
|
|
243 nearest_delta = ((((color_def->red >> 8) - (cells[0].red >> 8))
|
|
244 * ((color_def->red >> 8) - (cells[0].red >> 8)))
|
|
245 +
|
|
246 (((color_def->green >> 8) - (cells[0].green >> 8))
|
|
247 * ((color_def->green >> 8) - (cells[0].green >> 8)))
|
|
248 +
|
|
249 (((color_def->blue >> 8) - (cells[0].blue >> 8))
|
|
250 * ((color_def->blue >> 8) - (cells[0].blue >> 8))));
|
|
251 for (x = 1; x < no_cells; x++)
|
|
252 {
|
|
253 trial_delta = ((((color_def->red >> 8) - (cells[x].red >> 8))
|
|
254 * ((color_def->red >> 8) - (cells[x].red >> 8)))
|
|
255 +
|
|
256 (((color_def->green >> 8) - (cells[x].green >> 8))
|
|
257 * ((color_def->green >> 8) - (cells[x].green >> 8)))
|
|
258 +
|
|
259 (((color_def->blue >> 8) - (cells[x].blue >> 8))
|
|
260 * ((color_def->blue >> 8) - (cells[x].blue >> 8))));
|
|
261 if (trial_delta < nearest_delta)
|
|
262 {
|
|
263 nearest = x;
|
|
264 nearest_delta = trial_delta;
|
|
265 }
|
|
266 }
|
|
267 color_def->red = cells[nearest].red;
|
|
268 color_def->green = cells[nearest].green;
|
|
269 color_def->blue = cells[nearest].blue;
|
|
270 status = XAllocColor (display, screen_colormap, color_def);
|
|
271
|
|
272 free (cells);
|
|
273 }
|
|
274
|
|
275 return status;
|
|
276 }
|
|
277
|
|
278 static void
|
|
279 push_new_stack (XlwMenuWidget mw, widget_value *val)
|
|
280 {
|
|
281 if (!mw->menu.new_stack)
|
|
282 {
|
|
283 mw->menu.new_stack_length = 10;
|
|
284 mw->menu.new_stack =
|
|
285 (widget_value**)XtCalloc (mw->menu.new_stack_length,
|
|
286 sizeof (widget_value*));
|
|
287 }
|
|
288 else if (mw->menu.new_depth == mw->menu.new_stack_length)
|
|
289 {
|
|
290 mw->menu.new_stack_length *= 2;
|
|
291 mw->menu.new_stack =
|
|
292 (widget_value**)XtRealloc ((char*)mw->menu.new_stack,
|
|
293 mw->menu.new_stack_length *
|
|
294 sizeof (widget_value*));
|
|
295 }
|
|
296 mw->menu.new_stack [mw->menu.new_depth++] = val;
|
|
297 }
|
|
298
|
|
299 static void
|
|
300 pop_new_stack_if_no_contents (XlwMenuWidget mw)
|
|
301 {
|
|
302 if (mw->menu.new_depth)
|
|
303 {
|
|
304 if (!mw->menu.new_stack [mw->menu.new_depth - 1]->contents)
|
|
305 {
|
|
306 mw->menu.new_depth -= 1;
|
|
307 }
|
|
308 }
|
|
309 }
|
|
310
|
|
311 static void
|
|
312 make_old_stack_space (XlwMenuWidget mw, int n)
|
|
313 {
|
|
314 if (!mw->menu.old_stack)
|
|
315 {
|
|
316 mw->menu.old_stack_length = 10;
|
|
317 mw->menu.old_stack =
|
|
318 (widget_value**)XtCalloc (mw->menu.old_stack_length,
|
|
319 sizeof (widget_value*));
|
|
320 }
|
|
321 else if (mw->menu.old_stack_length < n)
|
|
322 {
|
|
323 mw->menu.old_stack_length *= 2;
|
|
324 mw->menu.old_stack =
|
|
325 (widget_value**)XtRealloc ((char*)mw->menu.old_stack,
|
|
326 mw->menu.old_stack_length *
|
|
327 sizeof (widget_value*));
|
|
328 }
|
|
329 }
|
|
330
|
|
331 static Boolean
|
|
332 close_to_reference_time(Widget w, Time reference_time, XEvent *ev)
|
|
333 {
|
|
334 return (reference_time &&
|
|
335 (ev->xbutton.time - reference_time
|
|
336 < XtGetMultiClickTime (XtDisplay (w))));
|
|
337 }
|
|
338
|
|
339 /* Size code */
|
|
340 static int
|
|
341 string_width (XlwMenuWidget mw,
|
|
342 #ifdef NEED_MOTIF
|
|
343 XmString s
|
|
344 #else
|
|
345 char *s
|
|
346 #endif
|
|
347 )
|
|
348 {
|
|
349 #ifdef NEED_MOTIF
|
|
350 Dimension width, height;
|
|
351 XmStringExtent (mw->menu.font_list, s, &width, &height);
|
|
352 return width;
|
|
353 #else
|
|
354 XCharStruct xcs;
|
|
355 int drop;
|
|
356 XTextExtents (mw->menu.font, s, strlen (s), &drop, &drop, &drop, &xcs);
|
|
357 return xcs.width;
|
|
358 #endif
|
|
359 }
|
|
360
|
|
361 static void
|
|
362 massage_resource_name (CONST char *in, char *out)
|
|
363 {
|
|
364 /* Turn a random string into something suitable for using as a resource.
|
|
365 For example:
|
|
366
|
|
367 "Kill Buffer" -> "killBuffer"
|
|
368 "Find File..." -> "findFile"
|
|
369 "Search and Replace..." -> "searchAndReplace"
|
2
|
370 "C++ Mode Commands" -> "cppModeCommands"
|
0
|
371 */
|
|
372
|
|
373 # define GOOD_CHAR(c) (((c) >= 'a' && (c) <= 'z') || \
|
|
374 ((c) >= 'A' && (c) <= 'Z') || \
|
|
375 ((c) >= '0' && (c) <= '9') || \
|
|
376 ((c) == '_') || \
|
|
377 ((c) > 0240))
|
|
378 int firstp = 1;
|
|
379 while (*in)
|
|
380 {
|
|
381 if (GOOD_CHAR ((unsigned char) *in))
|
|
382 {
|
|
383 if (firstp)
|
|
384 *out = tolower (*in);
|
|
385 else
|
|
386 *out = toupper (*in);
|
|
387 firstp = 0;
|
|
388 in++;
|
|
389 out++;
|
|
390 while (GOOD_CHAR ((unsigned char) *in))
|
|
391 {
|
|
392 *out = *in;
|
|
393 in++;
|
|
394 out++;
|
|
395 }
|
|
396 }
|
2
|
397 else if ((unsigned char)*in == '+')
|
|
398 {
|
|
399 /* for char '+' convert to 'P', e.g for C++ to cPP */
|
|
400 *out = 'P';
|
|
401 in++;
|
|
402 out++;
|
|
403 }
|
0
|
404 else
|
|
405 {
|
|
406 /* A bogus char between words; skip it. */
|
|
407 in++;
|
|
408 }
|
|
409 }
|
2
|
410
|
|
411 /* Add the following define to --cflags to generate a translation
|
|
412 file for menu localizations */
|
|
413 #ifdef PRINT_XLWMENU_RESOURCE_CONVERSIONS
|
|
414 printf("Emacs*XlwMenu.%s.labelString:\t%s\n", outpointer, inpointer);
|
|
415 #endif
|
0
|
416 *out = 0;
|
|
417 #undef GOOD_CHAR
|
|
418 }
|
|
419
|
|
420 static XtResource
|
|
421 nameResource[] =
|
|
422 {
|
2
|
423 { (String) "labelString", (String) "LabelString", XtRString, sizeof(String),
|
0
|
424 0, XtRImmediate, 0 }
|
|
425 };
|
|
426
|
|
427 /*
|
|
428 * This function looks through string searching for parameter
|
|
429 * inserts of the form:
|
|
430 * %[padding]1
|
|
431 * padding is space (' ') or dash ('-') characters meaning
|
|
432 * padding to the left or right of the inserted parameter.
|
|
433 * In essence all %1 strings are replaced by value in the return
|
|
434 * value (which the caller is expected to free).
|
|
435 * %% means insert one % (like printf).
|
|
436 * %1 means insert value.
|
|
437 * %-1 means insert value followed by one space. The latter is
|
|
438 * not inserted if value is a zero length string.
|
|
439 */
|
|
440 static char*
|
|
441 parameterize_string (CONST char *string, CONST char *value)
|
|
442 {
|
|
443 char *percent;
|
|
444 char *result;
|
|
445 unsigned done = 0;
|
|
446 unsigned ntimes;
|
|
447
|
|
448 if (!string)
|
|
449 {
|
|
450 result = XtMalloc(1);
|
|
451 result[0] = '\0';
|
|
452 return (result);
|
|
453 }
|
|
454
|
|
455 if (!value)
|
|
456 value = "";
|
|
457
|
|
458 for (ntimes = 1, result = (char *) string; (percent = strchr(result, '%'));
|
|
459 ntimes++)
|
|
460 result = &percent[1];
|
|
461
|
|
462 result = XtMalloc((ntimes * strlen(value)) + strlen(string) + 4);
|
|
463 result[0] = '\0';
|
|
464
|
|
465 while ((percent = strchr(string, '%')))
|
|
466 {
|
|
467 unsigned left_pad;
|
|
468 unsigned right_pad;
|
|
469 char *p;
|
|
470
|
|
471 if (percent[1] == '%')
|
|
472 { /* it's a real % */
|
|
473 strncat(result, string, 1 + percent - string); /* incl % */
|
|
474 string = &percent[2]; /* after the second '%' */
|
|
475 continue; /* with the while() loop */
|
|
476 }
|
|
477
|
|
478 left_pad = 0;
|
|
479 right_pad = 0;
|
|
480
|
|
481 for (p = &percent[1]; /* test *p inside the loop */ ; p++)
|
|
482 {
|
|
483 if (*p == ' ')
|
|
484 { /* left pad */
|
|
485 left_pad++;
|
|
486 }
|
|
487 else if (*p == '-')
|
|
488 { /* right pad */
|
|
489 right_pad++;
|
|
490 }
|
|
491 else if (*p == '1')
|
|
492 { /* param and terminator */
|
|
493 strncat(result, string, percent - string);
|
|
494 if (value[0] != '\0')
|
|
495 {
|
|
496 unsigned i;
|
|
497 for (i = 0; i < left_pad; i++)
|
|
498 strcat(result, " ");
|
|
499 strcat(result, value);
|
|
500 for (i = 0; i < right_pad; i++)
|
|
501 strcat(result, " ");
|
|
502 }
|
|
503 string = &p[1]; /* after the '1' */
|
|
504 done++; /* no need to do old way */
|
|
505 break; /* out of for() loop */
|
|
506 }
|
|
507 else
|
|
508 { /* bogus, copy the format as is */
|
|
509 /* out of for() loop */
|
|
510 strncat(result, string, 1 + p - string);
|
|
511 string= (*p ? &p[1] : p);
|
|
512 break;
|
|
513 }
|
|
514 }
|
|
515 }
|
|
516
|
|
517 /*
|
|
518 * Copy the tail of the string
|
|
519 */
|
|
520 strcat(result, string);
|
|
521
|
|
522 /*
|
|
523 * If we have not processed a % string, and we have a value, tail it.
|
|
524 */
|
|
525 if (!done && value[0] != '\0')
|
|
526 {
|
|
527 strcat(result, " ");
|
|
528 strcat(result, value);
|
|
529 }
|
|
530
|
|
531 return result;
|
|
532 }
|
|
533
|
|
534 #ifdef NEED_MOTIF
|
|
535
|
|
536 static XmString
|
|
537 resource_widget_value (XlwMenuWidget mw, widget_value *val)
|
|
538 {
|
|
539 if (!val->toolkit_data)
|
|
540 {
|
|
541 char *resourced_name = NULL;
|
|
542 char *converted_name, *str;
|
|
543 XmString complete_name;
|
|
544 char massaged_name [1024];
|
|
545
|
|
546 if (mw->menu.lookup_labels)
|
|
547 {
|
|
548 /* Convert value style name into resource style name.
|
|
549 eg: "Free Willy" becomes "freeWilly" */
|
|
550 massage_resource_name (val->name, massaged_name);
|
|
551
|
|
552 /* If we have a value (parameter) see if we can find a "Named"
|
|
553 resource. */
|
|
554 if (val->value)
|
|
555 {
|
|
556 char named_name[1024];
|
|
557 sprintf(named_name, "%sNamed", massaged_name);
|
|
558 XtGetSubresources ((Widget) mw,
|
|
559 (XtPointer) &resourced_name,
|
|
560 named_name, named_name,
|
|
561 nameResource, 1, NULL, 0);
|
|
562 }
|
|
563
|
|
564 /* If nothing yet, try to load from the massaged name. */
|
|
565 if (!resourced_name)
|
|
566 {
|
|
567 XtGetSubresources ((Widget) mw,
|
|
568 (XtPointer) &resourced_name,
|
|
569 massaged_name, massaged_name,
|
|
570 nameResource, 1, NULL, 0);
|
|
571 }
|
|
572 } /* if (mw->menu.lookup_labels) */
|
|
573
|
|
574 /* Still nothing yet, use the name as the value. */
|
|
575 if (!resourced_name)
|
|
576 resourced_name = val->name;
|
|
577
|
|
578 /* Parameterize the string. */
|
|
579 converted_name = parameterize_string(resourced_name, val->value);
|
|
580
|
|
581 /* nuke newline characters to prevent menubar screwups */
|
|
582 for ( str = converted_name ; *str ; str++ )
|
|
583 {
|
|
584 if (str[0] == '\n') str[0] = ' ';
|
|
585 }
|
|
586
|
|
587 /* Improve OSF's bottom line. */
|
|
588 #if (XmVersion >= 1002)
|
|
589 complete_name = XmStringCreateLocalized (converted_name);
|
|
590 #else
|
|
591 complete_name = XmStringCreateLtoR (converted_name,
|
|
592 XmSTRING_DEFAULT_CHARSET);
|
|
593 #endif
|
|
594 XtFree (converted_name);
|
|
595
|
|
596 val->toolkit_data = complete_name;
|
|
597 val->free_toolkit_data = True;
|
|
598 }
|
|
599 return ((XmString) val->toolkit_data);
|
|
600 }
|
|
601
|
|
602 /* Unused */
|
|
603 #if 0
|
|
604 /*
|
|
605 * These two routines should be a seperate file..djw
|
|
606 */
|
|
607 static char *
|
|
608 xlw_create_localized_string (Widget w,
|
|
609 char *name,
|
|
610 char **args,
|
|
611 unsigned nargs)
|
|
612 {
|
|
613 char *string = NULL;
|
|
614 char *arg = NULL;
|
|
615
|
|
616 if (nargs > 0)
|
|
617 arg = args[0];
|
|
618
|
|
619 XtGetSubresources (w,
|
|
620 (XtPointer)&string,
|
|
621 name,
|
|
622 name,
|
|
623 nameResource, 1,
|
|
624 NULL, 0
|
|
625 );
|
|
626
|
|
627 if (!string)
|
|
628 string = name;
|
|
629
|
|
630 return parameterize_string (string, arg);
|
|
631 }
|
|
632
|
|
633 static XmString
|
|
634 xlw_create_localized_xmstring (Widget w,
|
|
635 char *name,
|
|
636 char **args,
|
|
637 unsigned nargs)
|
|
638 {
|
|
639 char * string = xlw_create_localized_string (w, name, args, nargs);
|
|
640 XmString xm_string = XmStringCreateLtoR (string, XmSTRING_DEFAULT_CHARSET);
|
|
641 XtFree(string);
|
|
642 return xm_string;
|
|
643 }
|
|
644 #endif /* 0 */
|
|
645
|
|
646 #else /* !Motif */
|
|
647
|
|
648 static char*
|
|
649 resource_widget_value (XlwMenuWidget mw, widget_value *val)
|
|
650 {
|
|
651 if (!val->toolkit_data)
|
|
652 {
|
|
653 char *resourced_name = NULL;
|
|
654 char *complete_name;
|
|
655 char massaged_name [1024];
|
|
656
|
|
657 if (mw->menu.lookup_labels)
|
|
658 {
|
|
659 massage_resource_name (val->name, massaged_name);
|
|
660
|
|
661 XtGetSubresources ((Widget) mw,
|
|
662 (XtPointer) &resourced_name,
|
|
663 massaged_name, massaged_name,
|
|
664 nameResource, 1, NULL, 0);
|
|
665 }
|
|
666 if (!resourced_name)
|
|
667 resourced_name = val->name;
|
|
668
|
|
669 complete_name = parameterize_string(resourced_name, val->value);
|
|
670
|
|
671 val->toolkit_data = complete_name;
|
|
672 /* nuke newline characters to prevent menubar screwups */
|
|
673 for ( ; *complete_name ; complete_name++ )
|
|
674 {
|
|
675 if (complete_name[0] == '\n')
|
|
676 complete_name[0] = ' ';
|
|
677 }
|
|
678 val->free_toolkit_data = True;
|
|
679 }
|
|
680 return (char*)val->toolkit_data;
|
|
681 }
|
|
682
|
|
683 #endif /* !Motif */
|
|
684
|
|
685 /*
|
|
686 * Code for drawing strings.
|
|
687 */
|
|
688 static void
|
|
689 string_draw(
|
|
690 XlwMenuWidget mw,
|
|
691 Window window,
|
|
692 int x, int y,
|
|
693 GC gc,
|
|
694 #ifdef NEED_MOTIF
|
|
695 XmString string
|
|
696 #else
|
|
697 char *string
|
|
698 #endif
|
|
699 ) {
|
|
700 #ifdef NEED_MOTIF
|
|
701 XmStringDraw (XtDisplay (mw), window,
|
|
702 mw->menu.font_list,
|
|
703 string, gc,
|
|
704 x, y,
|
|
705 1000, /* ???? width */
|
|
706 XmALIGNMENT_BEGINNING,
|
|
707 0, /* ???? layout_direction */
|
|
708 0);
|
|
709 #else
|
|
710 XDrawString (XtDisplay (mw), window, gc,
|
|
711 x, y + mw->menu.font_ascent, string, strlen (string));
|
|
712
|
|
713 #endif
|
|
714 }
|
|
715
|
|
716 static void
|
|
717 binding_draw (XlwMenuWidget mw, Window w, int x, int y, GC gc, char *value)
|
|
718 {
|
|
719 #ifdef NEED_MOTIF
|
|
720 XmString xm_value = XmStringCreateLtoR(value, XmSTRING_DEFAULT_CHARSET);
|
|
721 string_draw (mw, w, x, y, gc, xm_value);
|
|
722 XmStringFree (xm_value);
|
|
723 #else
|
|
724 string_draw (mw, w, x, y, gc, value);
|
|
725 #endif
|
|
726 }
|
|
727
|
|
728 /*
|
|
729 * Low level code for drawing 3-D edges.
|
|
730 */
|
|
731 static void
|
|
732 shadow_rectangle_draw (
|
|
733 Display *dpy,
|
|
734 Window window,
|
|
735 GC top_gc,
|
|
736 GC bottom_gc,
|
|
737 int x, int y, unsigned width, unsigned height,
|
|
738 unsigned thickness
|
|
739 )
|
|
740 {
|
|
741 XPoint points [4];
|
|
742
|
|
743 if (!thickness)
|
|
744 return;
|
|
745
|
|
746 points [0].x = x;
|
|
747 points [0].y = y;
|
|
748 points [1].x = x + width;
|
|
749 points [1].y = y;
|
|
750 points [2].x = x + width - thickness;
|
|
751 points [2].y = y + thickness;
|
|
752 points [3].x = x;
|
|
753 points [3].y = y + thickness;
|
|
754 XFillPolygon (dpy, window, top_gc, points, 4, Convex, CoordModeOrigin);
|
|
755 points [0].x = x;
|
|
756 points [0].y = y + thickness;
|
|
757 points [1].x = x;
|
|
758 points [1].y = y + height;
|
|
759 points [2].x = x + thickness;
|
|
760 points [2].y = y + height - thickness;
|
|
761 points [3].x = x + thickness;
|
|
762 points [3].y = y + thickness;
|
|
763 XFillPolygon (dpy, window, top_gc, points, 4, Convex, CoordModeOrigin);
|
|
764 points [0].x = x + width;
|
|
765 points [0].y = y;
|
|
766 points [1].x = x + width - thickness;
|
|
767 points [1].y = y + thickness;
|
|
768 points [2].x = x + width - thickness;
|
|
769 points [2].y = y + height - thickness;
|
|
770 points [3].x = x + width;
|
|
771 points [3].y = y + height - thickness;
|
|
772 XFillPolygon (dpy, window, bottom_gc, points, 4, Convex, CoordModeOrigin);
|
|
773 points [0].x = x;
|
|
774 points [0].y = y + height;
|
|
775 points [1].x = x + width;
|
|
776 points [1].y = y + height;
|
|
777 points [2].x = x + width;
|
|
778 points [2].y = y + height - thickness;
|
|
779 points [3].x = x + thickness;
|
|
780 points [3].y = y + height - thickness;
|
|
781 XFillPolygon (dpy, window, bottom_gc, points, 4, Convex, CoordModeOrigin);
|
|
782 }
|
|
783
|
|
784 typedef enum e_shadow_type
|
|
785 {
|
|
786 /* these are Motif compliant */
|
|
787 SHADOW_BACKGROUND,
|
|
788 SHADOW_OUT,
|
|
789 SHADOW_IN,
|
|
790 SHADOW_ETCHED_OUT,
|
|
791 SHADOW_ETCHED_IN,
|
|
792 SHADOW_ETCHED_OUT_DASH,
|
|
793 SHADOW_ETCHED_IN_DASH,
|
|
794 SHADOW_SINGLE_LINE,
|
|
795 SHADOW_DOUBLE_LINE,
|
|
796 SHADOW_SINGLE_DASHED_LINE,
|
|
797 SHADOW_DOUBLE_DASHED_LINE,
|
|
798 SHADOW_NO_LINE,
|
|
799 /* these are all non-Motif */
|
|
800 SHADOW_DOUBLE_ETCHED_OUT,
|
|
801 SHADOW_DOUBLE_ETCHED_IN,
|
|
802 SHADOW_DOUBLE_ETCHED_OUT_DASH,
|
|
803 SHADOW_DOUBLE_ETCHED_IN_DASH
|
|
804 } shadow_type;
|
|
805
|
|
806 static void
|
|
807 shadow_draw (XlwMenuWidget mw,
|
|
808 Window window,
|
|
809 int x, int y, unsigned width, unsigned height,
|
|
810 shadow_type type
|
|
811 )
|
|
812 {
|
|
813 Display *dpy = XtDisplay (mw);
|
|
814 GC top_gc;
|
|
815 GC bottom_gc;
|
|
816 int thickness = mw->menu.shadow_thickness;
|
|
817 #if 0
|
|
818 XPoint points [4];
|
|
819 #endif /* 0 */
|
|
820 Boolean etched = False;
|
|
821
|
|
822 switch (type)
|
|
823 {
|
|
824 case SHADOW_BACKGROUND:
|
|
825 top_gc = bottom_gc = mw->menu.background_gc;
|
|
826 break;
|
|
827 case SHADOW_ETCHED_IN:
|
|
828 top_gc = mw->menu.shadow_bottom_gc;
|
|
829 bottom_gc = mw->menu.shadow_top_gc;
|
|
830 etched = True;
|
|
831 break;
|
|
832 case SHADOW_ETCHED_OUT:
|
|
833 top_gc = mw->menu.shadow_top_gc;
|
|
834 bottom_gc = mw->menu.shadow_bottom_gc;
|
|
835 etched = True;
|
|
836 break;
|
|
837 case SHADOW_IN:
|
|
838 top_gc = mw->menu.shadow_bottom_gc;
|
|
839 bottom_gc = mw->menu.shadow_top_gc;
|
|
840 break;
|
|
841 case SHADOW_OUT:
|
|
842 default:
|
|
843 top_gc = mw->menu.shadow_top_gc;
|
|
844 bottom_gc = mw->menu.shadow_bottom_gc;
|
|
845 break;
|
|
846 }
|
|
847
|
|
848 if (etched)
|
|
849 {
|
|
850 unsigned half = thickness/2;
|
|
851 shadow_rectangle_draw (
|
|
852 dpy,
|
|
853 window,
|
|
854 top_gc,
|
|
855 top_gc,
|
|
856 x, y,
|
|
857 width - half, height - half,
|
|
858 thickness - half
|
|
859 );
|
|
860 shadow_rectangle_draw (
|
|
861 dpy,
|
|
862 window,
|
|
863 bottom_gc,
|
|
864 bottom_gc,
|
|
865 x + half, y + half,
|
|
866 width - half , height - half,
|
|
867 half
|
|
868 );
|
|
869 }
|
|
870 else
|
|
871 {
|
|
872 shadow_rectangle_draw (
|
|
873 dpy,
|
|
874 window,
|
|
875 top_gc,
|
|
876 bottom_gc,
|
|
877 x, y,
|
|
878 width, height,
|
|
879 thickness
|
|
880 );
|
|
881 }
|
|
882 }
|
|
883
|
|
884 static void
|
|
885 arrow_decoration_draw (
|
|
886 XlwMenuWidget mw,
|
|
887 Window window,
|
|
888 int x, int y,
|
|
889 unsigned width,
|
|
890 Boolean raised
|
|
891 )
|
|
892 {
|
|
893 Display *dpy = XtDisplay (mw);
|
|
894 GC top_gc;
|
|
895 GC bottom_gc;
|
|
896 GC select_gc;
|
|
897 int thickness = mw->menu.shadow_thickness;
|
|
898 XPoint points [4];
|
|
899 int half_width;
|
|
900 int length = (int)((double)width * 0.87);
|
|
901 int thick_med = (int)((double)thickness * 1.73);
|
|
902
|
|
903 if (width & 0x1)
|
|
904 half_width = width/2 + 1;
|
|
905 else
|
|
906 half_width = width/2;
|
|
907
|
|
908 select_gc = mw->menu.background_gc;
|
|
909
|
|
910 if (raised)
|
|
911 {
|
|
912 top_gc = mw->menu.shadow_bottom_gc;
|
|
913 bottom_gc = mw->menu.shadow_top_gc;
|
|
914 }
|
|
915 else
|
|
916 {
|
|
917 top_gc = mw->menu.shadow_top_gc;
|
|
918 bottom_gc = mw->menu.shadow_bottom_gc;
|
|
919 }
|
|
920
|
|
921 /*
|
|
922 * Fill internal area, we do this first so that the borders
|
|
923 * have a nice sharp edge.
|
|
924 */
|
|
925 points [0].x = x + thickness;
|
|
926 points [0].y = y + thickness;
|
|
927 points [1].x = x + length - thickness;
|
|
928 points [1].y = y + half_width;
|
|
929 points [2].x = x + length - thickness;
|
|
930 points [2].y = y + half_width + thickness;
|
|
931 points [3].x = x + thickness;
|
|
932 points [3].y = y + width - thickness;
|
|
933
|
|
934 XFillPolygon (
|
|
935 dpy,
|
|
936 window,
|
|
937 select_gc,
|
|
938 points,
|
|
939 4,
|
|
940 Convex,
|
|
941 CoordModeOrigin
|
|
942 );
|
|
943
|
|
944 /* left border */
|
|
945 points [0].x = x;
|
|
946 points [0].y = y;
|
|
947 points [1].x = x + thickness;
|
|
948 points [1].y = y + thick_med;
|
|
949 points [2].x = x + thickness;
|
|
950 points [2].y = y + width - thick_med;
|
|
951 points [3].x = x;
|
|
952 points [3].y = y + width;
|
|
953
|
|
954 XFillPolygon (dpy, window, top_gc, points, 4, Convex, CoordModeOrigin);
|
|
955
|
|
956 /* top border */
|
|
957 points [0].x = x;
|
|
958 points [0].y = y + width;
|
|
959 points [1].x = x + length;
|
|
960 points [1].y = y + half_width;
|
|
961 points [2].x = x + length - (thickness + thickness);
|
|
962 points [2].y = y + half_width;
|
|
963 points [3].x = x + thickness;
|
|
964 points [3].y = y + width - thick_med;
|
|
965
|
|
966 XFillPolygon (dpy, window, bottom_gc, points, 4, Convex, CoordModeOrigin);
|
|
967
|
|
968 /* bottom shadow */
|
|
969 points [0].x = x;
|
|
970 points [0].y = y;
|
|
971 points [1].x = x + length;
|
|
972 points [1].y = y + half_width;
|
|
973 points [2].x = x + length - (thickness + thickness);
|
|
974 points [2].y = y + half_width;
|
|
975 points [3].x = x + thickness;
|
|
976 points [3].y = y + thick_med;
|
|
977
|
|
978 XFillPolygon (dpy, window, top_gc, points, 4, Convex, CoordModeOrigin);
|
|
979 }
|
|
980
|
|
981 static void
|
|
982 toggle_decoration_draw (
|
|
983 XlwMenuWidget mw,
|
|
984 Window window,
|
|
985 int x, int y,
|
|
986 unsigned width,
|
|
987 Boolean set
|
|
988 )
|
|
989 {
|
|
990 Display *dpy = XtDisplay (mw);
|
|
991 int thickness = mw->menu.shadow_thickness;
|
|
992 shadow_type type;
|
|
993 GC select_gc = mw->menu.select_gc;
|
|
994
|
|
995 if (set)
|
|
996 type = SHADOW_IN;
|
|
997 else
|
|
998 type = SHADOW_OUT;
|
|
999
|
|
1000 /*
|
|
1001 * Fill internal area.
|
|
1002 */
|
|
1003 if (set)
|
|
1004 XFillRectangle (
|
|
1005 dpy,
|
|
1006 window,
|
|
1007 select_gc,
|
|
1008 x + thickness,
|
|
1009 y + thickness,
|
|
1010 width - (2*thickness),
|
|
1011 width - (2*thickness)
|
|
1012 );
|
|
1013
|
|
1014 shadow_draw(mw, window, x, y, width, width, type);
|
|
1015 }
|
|
1016
|
|
1017 static void
|
|
1018 radio_decoration_draw (
|
|
1019 XlwMenuWidget mw,
|
|
1020 Window window,
|
|
1021 int x, int y,
|
|
1022 unsigned width,
|
|
1023 Boolean enabled
|
|
1024 )
|
|
1025 {
|
|
1026 Display *dpy = XtDisplay (mw);
|
|
1027 GC top_gc;
|
|
1028 GC bottom_gc;
|
|
1029 GC select_gc = mw->menu.select_gc;
|
|
1030 int thickness = mw->menu.shadow_thickness;
|
|
1031 XPoint points[6];
|
|
1032 int half_width;
|
|
1033 #if 0
|
|
1034 int npoints;
|
|
1035 #endif /* 0 */
|
|
1036
|
|
1037 if (width & 0x1)
|
|
1038 width++;
|
|
1039
|
|
1040 half_width = width/2;
|
|
1041
|
|
1042 if (enabled)
|
|
1043 {
|
|
1044 top_gc = mw->menu.shadow_bottom_gc;
|
|
1045 bottom_gc = mw->menu.shadow_top_gc;
|
|
1046 }
|
|
1047 else
|
|
1048 {
|
|
1049 top_gc = mw->menu.shadow_top_gc;
|
|
1050 bottom_gc = mw->menu.shadow_bottom_gc;
|
|
1051 }
|
|
1052
|
|
1053 #if 1
|
|
1054 /*
|
|
1055 * Draw the bottom first, just incase the regions overlap.
|
|
1056 * The top should cast the longer shadow.
|
|
1057 */
|
|
1058 points [0].x = x; /* left corner */
|
|
1059 points [0].y = y + half_width;
|
|
1060 points [1].x = x + half_width; /* bottom corner */
|
|
1061 points [1].y = y + width;
|
|
1062 points [2].x = x + half_width; /* bottom inside corner */
|
|
1063 points [2].y = y + width - thickness;
|
|
1064 points [3].x = x + thickness; /* left inside corner */
|
|
1065 points [3].y = y + half_width;
|
|
1066
|
|
1067 XFillPolygon (dpy, window, bottom_gc, points, 4, Convex, CoordModeOrigin);
|
|
1068
|
|
1069 points [0].x = x + half_width; /* bottom corner */
|
|
1070 points [0].y = y + width;
|
|
1071 points [1].x = x + width; /* right corner */
|
|
1072 points [1].y = y + half_width;
|
|
1073 points [2].x = x + width - thickness; /* right inside corner */
|
|
1074 points [2].y = y + half_width;
|
|
1075 points [3].x = x + half_width; /* bottom inside corner */
|
|
1076 points [3].y = y + width - thickness;
|
|
1077
|
|
1078 XFillPolygon (dpy, window, bottom_gc, points, 4, Convex, CoordModeOrigin);
|
|
1079
|
|
1080 points [0].x = x; /* left corner */
|
|
1081 points [0].y = y + half_width;
|
|
1082 points [1].x = x + half_width; /* top corner */
|
|
1083 points [1].y = y;
|
|
1084 points [2].x = x + half_width; /* top inside corner */
|
|
1085 points [2].y = y + thickness;
|
|
1086 points [3].x = x + thickness; /* left inside corner */
|
|
1087 points [3].y = y + half_width;
|
|
1088
|
|
1089 XFillPolygon (dpy, window, top_gc, points, 4, Convex, CoordModeOrigin);
|
|
1090
|
|
1091 points [0].x = x + half_width; /* top corner */
|
|
1092 points [0].y = y;
|
|
1093 points [1].x = x + width; /* right corner */
|
|
1094 points [1].y = y + half_width;
|
|
1095 points [2].x = x + width - thickness; /* right inside corner */
|
|
1096 points [2].y = y + half_width;
|
|
1097 points [3].x = x + half_width; /* top inside corner */
|
|
1098 points [3].y = y + thickness;
|
|
1099
|
|
1100 XFillPolygon (dpy, window, top_gc, points, 4, Convex, CoordModeOrigin);
|
|
1101 #else
|
|
1102 /*
|
|
1103 * Draw the bottom first, just incase the regions overlap.
|
|
1104 * The top should cast the longer shadow.
|
|
1105 */
|
|
1106 npoints = 0;
|
|
1107 points [npoints].x = x; /* left corner */
|
|
1108 points [npoints++].y = y + half_width;
|
|
1109 points [npoints].x = x + half_width; /* bottom corner */
|
|
1110 points [npoints++].y = y + width;
|
|
1111 points [npoints].x = x + width; /* right corner */
|
|
1112 points [npoints++].y = y + half_width;
|
|
1113 points [npoints].x = x + width - thickness; /* right inside corner */
|
|
1114 points [npoints++].y = y + half_width;
|
|
1115 points [npoints].x = x + half_width; /* bottom inside corner */
|
|
1116 points [npoints++].y = y + width - thickness;
|
|
1117 points [npoints].x = x + thickness; /* left inside corner */
|
|
1118 points [npoints++].y = y + half_width;
|
|
1119
|
|
1120 XFillPolygon (dpy, window, bottom_gc,
|
|
1121 points, npoints, Nonconvex, CoordModeOrigin);
|
|
1122
|
|
1123 npoints = 0;
|
|
1124
|
|
1125 points [npoints].x = x; /* left corner */
|
|
1126 points [npoints++].y = y + half_width;
|
|
1127 points [npoints].x = x + half_width; /* top corner */
|
|
1128 points [npoints++].y = y;
|
|
1129 points [npoints].x = x + width; /* right corner */
|
|
1130 points [npoints++].y = y + half_width;
|
|
1131 points [npoints].x = x + width - thickness; /* right inside corner */
|
|
1132 points [npoints++].y = y + half_width;
|
|
1133 points [npoints].x = x + half_width; /* top inside corner */
|
|
1134 points [npoints++].y = y + thickness;
|
|
1135 points [npoints].x = x + thickness; /* left inside corner */
|
|
1136 points [npoints++].y = y + half_width;
|
|
1137
|
|
1138 XFillPolygon (dpy, window, top_gc, points, npoints, Nonconvex,
|
|
1139 CoordModeOrigin);
|
|
1140 #endif
|
|
1141
|
|
1142
|
|
1143 /*
|
|
1144 * Fill internal area.
|
|
1145 */
|
|
1146 if (enabled)
|
|
1147 {
|
|
1148 points [0].x = x + thickness;
|
|
1149 points [0].y = y + half_width;
|
|
1150 points [1].x = x + half_width;
|
|
1151 points [1].y = y + thickness;
|
|
1152 points [2].x = x + width - thickness;
|
|
1153 points [2].y = y + half_width;
|
|
1154 points [3].x = x + half_width;
|
|
1155 points [3].y = y + width - thickness;
|
|
1156 XFillPolygon (dpy,
|
|
1157 window,
|
|
1158 select_gc,
|
|
1159 points,
|
|
1160 4,
|
|
1161 Convex,
|
|
1162 CoordModeOrigin
|
|
1163 );
|
|
1164 }
|
|
1165 }
|
|
1166
|
|
1167 static void
|
|
1168 separator_decoration_draw (
|
|
1169 XlwMenuWidget mw,
|
|
1170 Window window,
|
|
1171 int x, int y,
|
|
1172 unsigned width,
|
|
1173 Boolean vertical,
|
|
1174 shadow_type type
|
|
1175 )
|
|
1176 {
|
|
1177 Display *dpy = XtDisplay (mw);
|
|
1178 GC top_gc;
|
|
1179 GC bottom_gc;
|
|
1180 unsigned offset = 0;
|
|
1181 unsigned num_separators = 1;
|
|
1182 unsigned top_line_thickness = 0;
|
|
1183 unsigned bottom_line_thickness = 0;
|
|
1184 Boolean dashed = False;
|
|
1185 int i;
|
|
1186
|
|
1187 switch (type)
|
|
1188 {
|
|
1189 case SHADOW_NO_LINE: /* nothing to do */
|
|
1190 return;
|
|
1191 case SHADOW_DOUBLE_LINE:
|
|
1192 num_separators = 2;
|
|
1193 case SHADOW_SINGLE_LINE:
|
|
1194 top_gc = bottom_gc = mw->menu.foreground_gc;
|
|
1195 top_line_thickness = 1;
|
|
1196 break;
|
|
1197 case SHADOW_DOUBLE_DASHED_LINE:
|
|
1198 num_separators = 2;
|
|
1199 case SHADOW_SINGLE_DASHED_LINE:
|
|
1200 top_gc = bottom_gc = mw->menu.foreground_gc;
|
|
1201 top_line_thickness = 1;
|
|
1202 dashed = True;
|
|
1203 break;
|
|
1204 case SHADOW_DOUBLE_ETCHED_OUT_DASH:
|
|
1205 num_separators = 2;
|
|
1206 case SHADOW_ETCHED_OUT_DASH:
|
|
1207 top_gc = mw->menu.shadow_top_gc;
|
|
1208 bottom_gc = mw->menu.shadow_bottom_gc;
|
|
1209 top_line_thickness = mw->menu.shadow_thickness/2;
|
|
1210 bottom_line_thickness = mw->menu.shadow_thickness - top_line_thickness;
|
|
1211 dashed = True;
|
|
1212 break;
|
|
1213 case SHADOW_DOUBLE_ETCHED_IN_DASH:
|
|
1214 num_separators = 2;
|
|
1215 case SHADOW_ETCHED_IN_DASH:
|
|
1216 top_gc = mw->menu.shadow_bottom_gc;
|
|
1217 bottom_gc = mw->menu.shadow_top_gc;
|
|
1218 top_line_thickness = mw->menu.shadow_thickness/2;
|
|
1219 bottom_line_thickness = mw->menu.shadow_thickness - top_line_thickness;
|
|
1220 dashed = True;
|
|
1221 break;
|
|
1222 case SHADOW_DOUBLE_ETCHED_OUT:
|
|
1223 num_separators = 2;
|
|
1224 case SHADOW_ETCHED_OUT:
|
|
1225 top_gc = mw->menu.shadow_top_gc;
|
|
1226 bottom_gc = mw->menu.shadow_bottom_gc;
|
|
1227 top_line_thickness = mw->menu.shadow_thickness/2;
|
|
1228 bottom_line_thickness = mw->menu.shadow_thickness - top_line_thickness;
|
|
1229 break;
|
|
1230 case SHADOW_DOUBLE_ETCHED_IN:
|
|
1231 num_separators = 2;
|
|
1232 case SHADOW_ETCHED_IN:
|
|
1233 default:
|
|
1234 top_gc = mw->menu.shadow_bottom_gc;
|
|
1235 bottom_gc = mw->menu.shadow_top_gc;
|
|
1236 top_line_thickness = mw->menu.shadow_thickness/2;
|
|
1237 bottom_line_thickness = mw->menu.shadow_thickness - top_line_thickness;
|
|
1238 break;
|
|
1239 }
|
|
1240
|
|
1241 if (dashed)
|
|
1242 {
|
|
1243 XGCValues values;
|
|
1244 values.line_style = LineOnOffDash;
|
|
1245 if (top_line_thickness > 0)
|
|
1246 XChangeGC (dpy, top_gc, GCLineStyle, &values);
|
|
1247 if (bottom_line_thickness > 0 && bottom_gc != top_gc)
|
|
1248 XChangeGC (dpy, bottom_gc, GCLineStyle, &values);
|
|
1249 }
|
|
1250
|
|
1251 while (num_separators--)
|
|
1252 {
|
|
1253 for (i = 0; i < top_line_thickness; i++)
|
|
1254 XDrawLine (dpy, window, top_gc, x, y + i, x + width, y + i);
|
|
1255
|
|
1256 for (i = 0; i < bottom_line_thickness; i++)
|
|
1257 XDrawLine (
|
|
1258 dpy, window, bottom_gc,
|
|
1259 x, y + top_line_thickness + offset + i,
|
|
1260 x + width, y + top_line_thickness + offset + i
|
|
1261 );
|
|
1262 y += (top_line_thickness + offset + bottom_line_thickness + 1);
|
|
1263 }
|
|
1264
|
|
1265 if (dashed)
|
|
1266 {
|
|
1267 XGCValues values;
|
|
1268 values.line_style = LineSolid;
|
|
1269 if (top_line_thickness > 0)
|
|
1270 XChangeGC (dpy, top_gc, GCLineStyle, &values);
|
|
1271 if (bottom_line_thickness > 0 && bottom_gc != top_gc)
|
|
1272 XChangeGC (dpy, bottom_gc, GCLineStyle, &values);
|
|
1273 }
|
|
1274 }
|
|
1275
|
|
1276 #define SLOPPY_TYPES 0 /* 0=off, 1=error check, 2=easy to please */
|
|
1277 #if SLOPPY_TYPES
|
|
1278 #if SLOPPY_TYPES < 2
|
|
1279
|
|
1280 static char *wv_types[] =
|
|
1281 {
|
|
1282 "UNSPECIFIED",
|
|
1283 "BUTTON",
|
|
1284 "TOGGLE",
|
|
1285 "RADIO",
|
|
1286 "TEXT",
|
|
1287 "SEPARATOR",
|
|
1288 "CASCADE",
|
|
1289 "PUSHRIGHT",
|
|
1290 "INCREMENTAL"
|
|
1291 };
|
|
1292
|
|
1293 static void
|
|
1294 print_widget_value (widget_value *wv, int just_one, int depth)
|
|
1295 {
|
|
1296 char d [200];
|
|
1297 int i;
|
|
1298 for (i = 0; i < depth; i++) d[i] = ' ';
|
|
1299 d[depth]=0;
|
|
1300 if (!wv)
|
|
1301 {
|
|
1302 printf ("%s(null widget value pointer)\n", d);
|
|
1303 return;
|
|
1304 }
|
|
1305 printf ("%stype: %s\n", d, wv_types [wv->type]);
|
|
1306 #if 0
|
|
1307 printf ("%sname: %s\n", d, (wv->name ? wv->name : "(null)"));
|
|
1308 #else
|
|
1309 if (wv->name) printf ("%sname: %s\n", d, wv->name);
|
|
1310 #endif
|
|
1311 if (wv->value) printf ("%svalue: %s\n", d, wv->value);
|
|
1312 if (wv->key) printf ("%skey: %s\n", d, wv->key);
|
|
1313 printf ("%senabled: %d\n", d, wv->enabled);
|
|
1314 if (wv->contents)
|
|
1315 {
|
|
1316 printf ("\n%scontents: \n", d);
|
|
1317 print_widget_value (wv->contents, 0, depth + 5);
|
|
1318 }
|
|
1319 if (!just_one && wv->next)
|
|
1320 {
|
|
1321 printf ("\n");
|
|
1322 print_widget_value (wv->next, 0, depth);
|
|
1323 }
|
|
1324 }
|
|
1325 #endif
|
|
1326
|
|
1327 static Boolean
|
|
1328 all_dashes_p (char *s)
|
|
1329 {
|
|
1330 char *p;
|
|
1331 if (!s || s[0] == '\0')
|
|
1332 return False;
|
|
1333 for (p = s; *p == '-'; p++);
|
|
1334
|
|
1335 if (*p == '!' || *p == '\0')
|
|
1336 return True;
|
|
1337 return False;
|
|
1338 }
|
|
1339 #endif
|
|
1340
|
|
1341 static widget_value_type
|
|
1342 menu_item_type (widget_value *val)
|
|
1343 {
|
|
1344 if (val->type != UNSPECIFIED_TYPE)
|
|
1345 return val->type;
|
|
1346 else
|
|
1347 {
|
|
1348 #if SLOPPY_TYPES
|
|
1349 if (all_dashes_p(val->name))
|
|
1350 return SEPARATOR_TYPE;
|
|
1351 else if (val->name && val->name[0] == '\0') /* push right */
|
|
1352 return PUSHRIGHT_TYPE;
|
|
1353 else if (val->contents) /* cascade */
|
|
1354 return CASCADE_TYPE;
|
|
1355 else if (val->call_data) /* push button */
|
|
1356 return BUTTON_TYPE;
|
|
1357 else
|
|
1358 return TEXT_TYPE;
|
|
1359 #else
|
|
1360 abort();
|
|
1361 #endif
|
|
1362 }
|
|
1363 }
|
|
1364
|
|
1365 static void
|
|
1366 label_button_size (
|
|
1367 XlwMenuWidget mw,
|
|
1368 widget_value *val,
|
|
1369 Boolean in_menubar,
|
|
1370 unsigned *toggle_width,
|
|
1371 unsigned *label_width,
|
|
1372 unsigned *bindings_width,
|
|
1373 unsigned *height
|
|
1374 )
|
|
1375 {
|
|
1376 *height = (mw->menu.font_ascent + mw->menu.font_descent +
|
|
1377 2 * mw->menu.vertical_margin +
|
|
1378 2 * mw->menu.shadow_thickness);
|
|
1379 /* no left column decoration */
|
|
1380 *toggle_width = mw->menu.horizontal_margin + mw->menu.shadow_thickness;;
|
|
1381
|
|
1382 *label_width = string_width (mw, resource_widget_value (mw, val));
|
|
1383 *bindings_width = mw->menu.horizontal_margin + mw->menu.shadow_thickness;
|
|
1384 }
|
|
1385
|
|
1386 static void
|
|
1387 label_button_draw (
|
|
1388 XlwMenuWidget mw,
|
|
1389 widget_value *val,
|
|
1390 Boolean in_menubar,
|
|
1391 Boolean highlighted,
|
|
1392 Window window,
|
|
1393 int x, int y,
|
|
1394 unsigned width,
|
|
1395 unsigned height,
|
|
1396 unsigned label_offset,
|
|
1397 unsigned binding_tab
|
|
1398 )
|
|
1399 {
|
|
1400 int y_offset = mw->menu.shadow_thickness + mw->menu.vertical_margin;
|
|
1401
|
|
1402 if (!label_offset)
|
|
1403 label_offset = mw->menu.shadow_thickness + mw->menu.horizontal_margin;
|
|
1404
|
|
1405 /*
|
|
1406 * Draw the label string.
|
|
1407 */
|
|
1408 string_draw (
|
|
1409 mw,
|
|
1410 window,
|
|
1411 x + label_offset, y + y_offset,
|
|
1412 mw->menu.foreground_gc,
|
|
1413 resource_widget_value (mw, val)
|
|
1414 );
|
|
1415 }
|
|
1416
|
|
1417 static void
|
|
1418 push_button_size (
|
|
1419 XlwMenuWidget mw,
|
|
1420 widget_value *val,
|
|
1421 Boolean in_menubar,
|
|
1422 unsigned *toggle_width,
|
|
1423 unsigned *label_width,
|
|
1424 unsigned *bindings_width,
|
|
1425 unsigned *height
|
|
1426 )
|
|
1427 {
|
|
1428 /* inherit */
|
|
1429 label_button_size (
|
|
1430 mw, val, in_menubar,
|
|
1431 toggle_width, label_width, bindings_width,
|
|
1432 height
|
|
1433 );
|
|
1434
|
|
1435 /* key bindings to display? */
|
|
1436 if (!in_menubar && val->key)
|
|
1437 {
|
|
1438 int w;
|
|
1439 #ifdef NEED_MOTIF
|
|
1440 XmString key = XmStringCreateLtoR (val->key, XmSTRING_DEFAULT_CHARSET);
|
|
1441 w = string_width(mw, key);
|
|
1442 XmStringFree (key);
|
|
1443 #else
|
|
1444 char *key = val->key;
|
|
1445 w = string_width (mw, key);
|
|
1446 #endif
|
|
1447 *bindings_width += w + mw->menu.column_spacing;
|
|
1448 }
|
|
1449 }
|
|
1450
|
|
1451 static void
|
|
1452 push_button_draw (
|
|
1453 XlwMenuWidget mw,
|
|
1454 widget_value *val,
|
|
1455 Boolean in_menubar,
|
|
1456 Boolean highlighted,
|
|
1457 Window window,
|
|
1458 int x, int y,
|
|
1459 unsigned width, unsigned height,
|
|
1460 unsigned label_offset,
|
|
1461 unsigned binding_offset
|
|
1462 )
|
|
1463 {
|
|
1464 int y_offset = mw->menu.shadow_thickness + mw->menu.vertical_margin;
|
|
1465 GC gc;
|
|
1466 shadow_type type;
|
|
1467 Boolean menu_pb = in_menubar && (menu_item_type (val) == BUTTON_TYPE);
|
|
1468
|
|
1469 /*
|
|
1470 * Draw the label string.
|
|
1471 */
|
|
1472 if (!label_offset)
|
|
1473 label_offset = mw->menu.shadow_thickness + mw->menu.horizontal_margin;
|
|
1474
|
|
1475 if (menu_pb)
|
|
1476 {
|
|
1477 if (val->enabled)
|
|
1478 gc = mw->menu.button_gc;
|
|
1479 else
|
|
1480 gc = mw->menu.inactive_button_gc;
|
|
1481 }
|
|
1482 else
|
|
1483 {
|
|
1484 if (val->enabled)
|
|
1485 gc = mw->menu.foreground_gc;
|
|
1486 else
|
|
1487 gc = mw->menu.inactive_gc;
|
|
1488 }
|
|
1489
|
|
1490 string_draw (
|
|
1491 mw,
|
|
1492 window,
|
|
1493 x + label_offset, y + y_offset,
|
|
1494 gc,
|
|
1495 resource_widget_value(mw, val)
|
|
1496 );
|
|
1497
|
|
1498 /*
|
|
1499 * Draw the keybindings
|
|
1500 */
|
|
1501 if (val->key)
|
|
1502 {
|
|
1503 if (!binding_offset)
|
|
1504 {
|
|
1505 unsigned s_width = string_width (mw, resource_widget_value(mw, val));
|
|
1506 binding_offset = label_offset + s_width + mw->menu.shadow_thickness;
|
|
1507 }
|
|
1508 binding_draw (mw, window,
|
|
1509 x + binding_offset + mw->menu.column_spacing,
|
|
1510 y + y_offset, gc, val->key);
|
|
1511 }
|
|
1512
|
|
1513 /*
|
|
1514 * Draw the shadow
|
|
1515 */
|
|
1516 if (menu_pb)
|
|
1517 {
|
|
1518 if (highlighted)
|
|
1519 type = SHADOW_OUT;
|
|
1520 else
|
|
1521 type = (val->selected ? SHADOW_ETCHED_OUT : SHADOW_ETCHED_IN);
|
|
1522 }
|
|
1523 else
|
|
1524 {
|
|
1525 if (highlighted)
|
|
1526 type = SHADOW_OUT;
|
|
1527 else
|
|
1528 type = SHADOW_BACKGROUND;
|
|
1529 }
|
|
1530
|
|
1531 shadow_draw (mw, window, x, y, width, height, type);
|
|
1532 }
|
|
1533
|
|
1534 static unsigned int
|
|
1535 arrow_decoration_height (XlwMenuWidget mw)
|
|
1536 {
|
|
1537 unsigned int result =
|
|
1538 (mw->menu.font_ascent + mw->menu.font_descent) / (unsigned int)2;
|
|
1539
|
|
1540 result += 2 * mw->menu.shadow_thickness;
|
|
1541
|
|
1542 if (result > (mw->menu.font_ascent + mw->menu.font_descent))
|
|
1543 result = mw->menu.font_ascent + mw->menu.font_descent;
|
|
1544
|
|
1545 return result;
|
|
1546 }
|
|
1547
|
|
1548 static void
|
|
1549 cascade_button_size (
|
|
1550 XlwMenuWidget mw,
|
|
1551 widget_value *val,
|
|
1552 Boolean in_menubar,
|
|
1553 unsigned *toggle_width,
|
|
1554 unsigned *label_width,
|
|
1555 unsigned *arrow_width,
|
|
1556 unsigned *height
|
|
1557 )
|
|
1558 {
|
|
1559 /* inherit */
|
|
1560 label_button_size (
|
|
1561 mw, val, in_menubar,
|
|
1562 toggle_width, label_width, arrow_width,
|
|
1563 height
|
|
1564 );
|
|
1565 /* we have a pull aside arrow */
|
|
1566 if (!in_menubar)
|
|
1567 {
|
|
1568 *arrow_width += arrow_decoration_height(mw) + mw->menu.column_spacing;
|
|
1569 }
|
|
1570 }
|
|
1571
|
|
1572 static void
|
|
1573 cascade_button_draw (
|
|
1574 XlwMenuWidget mw,
|
|
1575 widget_value *val,
|
|
1576 Boolean in_menubar,
|
|
1577 Boolean highlighted,
|
|
1578 Window window,
|
|
1579 int x, int y,
|
|
1580 unsigned width, unsigned height,
|
|
1581 unsigned label_offset,
|
|
1582 unsigned binding_offset
|
|
1583 )
|
|
1584 {
|
|
1585 shadow_type type;
|
|
1586
|
|
1587 /*
|
|
1588 * Draw the label string.
|
|
1589 */
|
|
1590 label_button_draw (mw, val, in_menubar, highlighted,
|
|
1591 window, x, y, width, height, label_offset,
|
|
1592 binding_offset);
|
|
1593
|
|
1594 /*
|
|
1595 * Draw the pull aside arrow
|
|
1596 */
|
|
1597 if (!in_menubar && val->contents)
|
|
1598 {
|
|
1599 int y_offset;
|
|
1600 unsigned arrow_height = arrow_decoration_height (mw);
|
|
1601
|
|
1602 y_offset = mw->menu.shadow_thickness + mw->menu.vertical_margin +
|
|
1603 (mw->menu.font_ascent+mw->menu.font_descent - arrow_height)/2;
|
|
1604
|
|
1605 if (!binding_offset)
|
|
1606 {
|
|
1607 unsigned s_width = string_width(mw, resource_widget_value (mw, val));
|
|
1608
|
|
1609 if (!label_offset)
|
|
1610 label_offset = mw->menu.shadow_thickness +
|
|
1611 mw->menu.horizontal_margin;
|
|
1612
|
|
1613 binding_offset = label_offset + s_width + mw->menu.shadow_thickness;
|
|
1614 }
|
|
1615
|
|
1616 arrow_decoration_draw (
|
|
1617 mw,
|
|
1618 window,
|
|
1619 x + binding_offset + mw->menu.column_spacing,
|
|
1620 y + y_offset,
|
|
1621 arrow_height,
|
|
1622 highlighted
|
|
1623 );
|
|
1624 }
|
|
1625
|
|
1626 /*
|
|
1627 * Draw the shadow
|
|
1628 */
|
|
1629 if (highlighted)
|
|
1630 type = SHADOW_OUT;
|
|
1631 else
|
|
1632 type = SHADOW_BACKGROUND;
|
|
1633
|
|
1634 shadow_draw(mw, window, x, y, width, height, type);
|
|
1635 }
|
|
1636
|
|
1637 static unsigned
|
|
1638 toggle_decoration_height(XlwMenuWidget mw)
|
|
1639 {
|
|
1640 unsigned rv;
|
|
1641 if (mw->menu.indicator_size > 0)
|
|
1642 rv = mw->menu.indicator_size;
|
|
1643 else
|
|
1644 rv = mw->menu.font_ascent;
|
|
1645
|
|
1646 if (rv > (mw->menu.font_ascent+mw->menu.font_descent))
|
|
1647 rv = mw->menu.font_ascent+mw->menu.font_descent;
|
|
1648
|
|
1649 return rv;
|
|
1650 }
|
|
1651
|
|
1652 static void
|
|
1653 toggle_button_size (
|
|
1654 XlwMenuWidget mw,
|
|
1655 widget_value *val,
|
|
1656 Boolean in_menubar,
|
|
1657 unsigned *toggle_width,
|
|
1658 unsigned *label_width,
|
|
1659 unsigned *bindings_width,
|
|
1660 unsigned *height
|
|
1661 )
|
|
1662 {
|
|
1663 /* inherit */
|
|
1664 push_button_size (
|
|
1665 mw, val, in_menubar,
|
|
1666 toggle_width, label_width, bindings_width,
|
|
1667 height
|
|
1668 );
|
|
1669 /* we have a toggle */
|
|
1670 *toggle_width += toggle_decoration_height(mw) + mw->menu.column_spacing;
|
|
1671 }
|
|
1672
|
|
1673 static void
|
|
1674 toggle_button_draw (
|
|
1675 XlwMenuWidget mw,
|
|
1676 widget_value *val,
|
|
1677 Boolean in_menubar,
|
|
1678 Boolean highlighted,
|
|
1679 Window window,
|
|
1680 int x, int y,
|
|
1681 unsigned width, unsigned height,
|
|
1682 unsigned label_tab,
|
|
1683 unsigned binding_tab
|
|
1684 )
|
|
1685 {
|
|
1686 int x_offset;
|
|
1687 int y_offset;
|
|
1688 unsigned t_height = toggle_decoration_height(mw);
|
|
1689
|
|
1690 /*
|
|
1691 * Draw a toggle.
|
|
1692 */
|
|
1693 x_offset = mw->menu.shadow_thickness + mw->menu.horizontal_margin;
|
|
1694 y_offset = mw->menu.shadow_thickness + mw->menu.vertical_margin;
|
|
1695 y_offset += (mw->menu.font_ascent + mw->menu.font_descent - t_height)/2;
|
|
1696
|
|
1697 toggle_decoration_draw (mw, window, x + x_offset, y + y_offset,
|
|
1698 t_height, val->selected);
|
|
1699
|
|
1700 /*
|
|
1701 * Draw the pushbutton parts.
|
|
1702 */
|
|
1703 push_button_draw (mw, val, in_menubar, highlighted, window, x, y, width,
|
|
1704 height, label_tab, binding_tab);
|
|
1705 }
|
|
1706
|
|
1707 static unsigned
|
|
1708 radio_decoration_height(XlwMenuWidget mw)
|
|
1709 {
|
|
1710 return toggle_decoration_height(mw);
|
|
1711 }
|
|
1712
|
|
1713 static void
|
|
1714 radio_button_draw (
|
|
1715 XlwMenuWidget mw,
|
|
1716 widget_value *val,
|
|
1717 Boolean in_menubar,
|
|
1718 Boolean highlighted,
|
|
1719 Window window,
|
|
1720 int x, int y,
|
|
1721 unsigned width, unsigned height,
|
|
1722 unsigned label_tab,
|
|
1723 unsigned binding_tab
|
|
1724 )
|
|
1725 {
|
|
1726 int x_offset;
|
|
1727 int y_offset;
|
|
1728 unsigned r_height = radio_decoration_height(mw);
|
|
1729
|
|
1730 /*
|
|
1731 * Draw a toggle.
|
|
1732 */
|
|
1733 x_offset = mw->menu.shadow_thickness + mw->menu.horizontal_margin;
|
|
1734 y_offset = mw->menu.shadow_thickness + mw->menu.vertical_margin;
|
|
1735 y_offset += (mw->menu.font_ascent + mw->menu.font_descent - r_height)/2;
|
|
1736
|
|
1737 radio_decoration_draw (mw, window, x + x_offset, y + y_offset, r_height,
|
|
1738 val->selected);
|
|
1739
|
|
1740 /*
|
|
1741 * Draw the pushbutton parts.
|
|
1742 */
|
|
1743 push_button_draw (mw, val, in_menubar, highlighted, window, x, y, width,
|
|
1744 height, label_tab, binding_tab);
|
|
1745 }
|
|
1746
|
|
1747 static struct _shadow_names
|
|
1748 {
|
|
1749 CONST char * name;
|
|
1750 shadow_type type;
|
|
1751 } shadow_names[] =
|
|
1752 {
|
|
1753 /* Motif */
|
|
1754 { "singleLine", SHADOW_SINGLE_LINE },
|
|
1755 { "doubleLine", SHADOW_DOUBLE_LINE },
|
|
1756 { "singleDashedLine", SHADOW_SINGLE_DASHED_LINE },
|
|
1757 { "doubleDashedLine", SHADOW_DOUBLE_DASHED_LINE },
|
|
1758 { "noLine", SHADOW_NO_LINE },
|
|
1759 { "shadowEtchedIn", SHADOW_ETCHED_IN },
|
|
1760 { "shadowEtchedOut", SHADOW_ETCHED_OUT },
|
|
1761 { "shadowEtchedInDash", SHADOW_ETCHED_IN_DASH },
|
|
1762 { "shadowEtchedOutDash", SHADOW_ETCHED_OUT_DASH },
|
|
1763 /* non-Motif */
|
|
1764 { "shadowDoubleEtchedIn", SHADOW_DOUBLE_ETCHED_IN },
|
|
1765 { "shadowDoubleEtchedOut", SHADOW_DOUBLE_ETCHED_OUT },
|
|
1766 { "shadowDoubleEtchedInDash", SHADOW_DOUBLE_ETCHED_IN_DASH },
|
|
1767 { "shadowDoubleEtchedOutDash", SHADOW_DOUBLE_ETCHED_OUT_DASH }
|
|
1768 };
|
|
1769
|
|
1770 static shadow_type
|
|
1771 separator_type (char *name)
|
|
1772 {
|
|
1773 int i;
|
|
1774
|
|
1775 if (name)
|
|
1776 {
|
|
1777 for (i = 0; i < XtNumber(shadow_names); i++ )
|
|
1778 {
|
|
1779 if (strcmp (name, shadow_names[i].name) == 0)
|
|
1780 return shadow_names[i].type;
|
|
1781 }
|
|
1782 }
|
|
1783 return SHADOW_BACKGROUND;
|
|
1784 }
|
|
1785
|
|
1786 static unsigned
|
|
1787 separator_decoration_height (XlwMenuWidget mw, widget_value *val)
|
|
1788 {
|
|
1789
|
|
1790 switch (separator_type(val->value))
|
|
1791 {
|
|
1792 case SHADOW_NO_LINE:
|
|
1793 case SHADOW_SINGLE_LINE:
|
|
1794 case SHADOW_SINGLE_DASHED_LINE:
|
|
1795 return 1;
|
|
1796 case SHADOW_DOUBLE_LINE:
|
|
1797 case SHADOW_DOUBLE_DASHED_LINE:
|
|
1798 return 3;
|
|
1799 case SHADOW_DOUBLE_ETCHED_OUT:
|
|
1800 case SHADOW_DOUBLE_ETCHED_IN:
|
|
1801 case SHADOW_DOUBLE_ETCHED_OUT_DASH:
|
|
1802 case SHADOW_DOUBLE_ETCHED_IN_DASH:
|
|
1803 return (1 + 2 * mw->menu.shadow_thickness);
|
|
1804 case SHADOW_ETCHED_OUT:
|
|
1805 case SHADOW_ETCHED_IN:
|
|
1806 default:
|
|
1807 return mw->menu.shadow_thickness;
|
|
1808 }
|
|
1809 }
|
|
1810
|
|
1811 static void
|
|
1812 separator_size (XlwMenuWidget mw,
|
|
1813 widget_value *val,
|
|
1814 Boolean in_menubar,
|
|
1815 unsigned *toggle_width,
|
|
1816 unsigned *label_width,
|
|
1817 unsigned *rest_width,
|
|
1818 unsigned *height
|
|
1819 )
|
|
1820 {
|
|
1821 *height = separator_decoration_height (mw, val);
|
|
1822 *label_width = 1;
|
|
1823 *toggle_width = *rest_width = 0;
|
|
1824 }
|
|
1825
|
|
1826 static void
|
|
1827 separator_draw (XlwMenuWidget mw,
|
|
1828 widget_value *val,
|
|
1829 Boolean in_menubar,
|
|
1830 Boolean highlighted,
|
|
1831 Window window,
|
|
1832 int x, int y,
|
|
1833 unsigned width, unsigned height,
|
|
1834 unsigned label_tab,
|
|
1835 unsigned binding_tab
|
|
1836 )
|
|
1837 {
|
|
1838 unsigned sep_width;
|
|
1839
|
|
1840 if (in_menubar)
|
|
1841 sep_width = height;
|
|
1842 else
|
|
1843 sep_width = width;
|
|
1844
|
|
1845 separator_decoration_draw (mw,
|
|
1846 window,
|
|
1847 x,
|
|
1848 y,
|
|
1849 sep_width,
|
|
1850 in_menubar,
|
|
1851 separator_type(val->value)
|
|
1852 );
|
|
1853 }
|
|
1854
|
|
1855 static void
|
|
1856 pushright_size (XlwMenuWidget mw,
|
|
1857 widget_value *val,
|
|
1858 Boolean in_menubar,
|
|
1859 unsigned *toggle_width,
|
|
1860 unsigned *label_width,
|
|
1861 unsigned *rest_width,
|
|
1862 unsigned *height
|
|
1863 )
|
|
1864 {
|
|
1865 *height = *label_width = *toggle_width = *rest_width = 0;
|
|
1866 }
|
|
1867
|
|
1868 static void
|
|
1869 size_menu_item (XlwMenuWidget mw,
|
|
1870 widget_value *val,
|
|
1871 int horizontal,
|
|
1872 unsigned *toggle_width,
|
|
1873 unsigned *label_width,
|
|
1874 unsigned *rest_width,
|
|
1875 unsigned *height
|
|
1876 )
|
|
1877 {
|
|
1878
|
|
1879 void (*function_ptr) (
|
|
1880 XlwMenuWidget _mw,
|
|
1881 widget_value *_val,
|
|
1882 Boolean _in_menubar,
|
|
1883 unsigned *_toggle_width,
|
|
1884 unsigned *_label_width,
|
|
1885 unsigned *_rest_width,
|
|
1886 unsigned *_height
|
|
1887 );
|
|
1888 switch (menu_item_type (val))
|
|
1889 {
|
|
1890 case TOGGLE_TYPE:
|
|
1891 case RADIO_TYPE:
|
|
1892 function_ptr = toggle_button_size;
|
|
1893 break;
|
|
1894 case SEPARATOR_TYPE:
|
|
1895 function_ptr = separator_size;
|
|
1896 break;
|
|
1897 case INCREMENTAL_TYPE:
|
|
1898 case CASCADE_TYPE:
|
|
1899 function_ptr = cascade_button_size;
|
|
1900 break;
|
|
1901 case BUTTON_TYPE:
|
|
1902 function_ptr = push_button_size;
|
|
1903 break;
|
|
1904 case PUSHRIGHT_TYPE:
|
|
1905 function_ptr = pushright_size;
|
|
1906 break;
|
|
1907 case TEXT_TYPE:
|
|
1908 default:
|
|
1909 function_ptr = label_button_size;
|
|
1910 break;
|
|
1911 }
|
|
1912
|
|
1913 (*function_ptr) (
|
|
1914 mw,
|
|
1915 val,
|
|
1916 horizontal,
|
|
1917 toggle_width,
|
|
1918 label_width,
|
|
1919 rest_width,
|
|
1920 height
|
|
1921 );
|
|
1922 }
|
|
1923
|
|
1924 static void
|
|
1925 display_menu_item (
|
|
1926 XlwMenuWidget mw,
|
|
1927 widget_value *val,
|
|
1928 window_state *ws,
|
|
1929 XPoint *where,
|
|
1930 Boolean highlighted,
|
|
1931 Boolean horizontal,
|
|
1932 Boolean just_compute
|
|
1933 )
|
|
1934 {
|
|
1935
|
|
1936 int x = where->x /* + mw->menu.shadow_thickness */ ;
|
|
1937 int y = where->y /* + mw->menu.shadow_thickness */ ;
|
|
1938 unsigned toggle_width;
|
|
1939 unsigned label_width;
|
|
1940 unsigned binding_width;
|
|
1941 unsigned width;
|
|
1942 unsigned height;
|
|
1943 unsigned label_tab;
|
|
1944 unsigned binding_tab;
|
|
1945 void (*function_ptr) (
|
|
1946 XlwMenuWidget _mw,
|
|
1947 widget_value *_val,
|
|
1948 Boolean _in_menubar,
|
|
1949 Boolean _highlighted,
|
|
1950 Window _window,
|
|
1951 int _x, int _y,
|
|
1952 unsigned _width, unsigned _height,
|
|
1953 unsigned _label_tab,
|
|
1954 unsigned _binding_tab
|
|
1955 );
|
|
1956
|
|
1957 size_menu_item (
|
|
1958 mw, val, horizontal,
|
|
1959 &toggle_width, &label_width, &binding_width, &height
|
|
1960 );
|
|
1961
|
|
1962 if (horizontal)
|
|
1963 {
|
|
1964 width = toggle_width + label_width + binding_width;
|
|
1965 height = ws->height - 2 * mw->menu.shadow_thickness;
|
|
1966 }
|
|
1967 else
|
|
1968 {
|
|
1969 width = ws->width - 2 * mw->menu.shadow_thickness;
|
|
1970 toggle_width = ws->toggle_width;
|
|
1971 label_width = ws->label_width;
|
|
1972 }
|
|
1973
|
|
1974 where->x += width;
|
|
1975 where->y += height;
|
|
1976
|
|
1977 if (just_compute)
|
|
1978 return;
|
|
1979
|
|
1980 label_tab = toggle_width;
|
|
1981 binding_tab = toggle_width + label_width;
|
|
1982
|
|
1983 switch (menu_item_type (val))
|
|
1984 {
|
|
1985 case TOGGLE_TYPE:
|
|
1986 function_ptr = toggle_button_draw;
|
|
1987 break;
|
|
1988 case RADIO_TYPE:
|
|
1989 function_ptr = radio_button_draw;
|
|
1990 break;
|
|
1991 case SEPARATOR_TYPE:
|
|
1992 function_ptr = separator_draw;
|
|
1993 break;
|
|
1994 case INCREMENTAL_TYPE:
|
|
1995 case CASCADE_TYPE:
|
|
1996 function_ptr = cascade_button_draw;
|
|
1997 break;
|
|
1998 case BUTTON_TYPE:
|
|
1999 function_ptr = push_button_draw;
|
|
2000 break;
|
|
2001 case TEXT_TYPE:
|
|
2002 function_ptr = label_button_draw;
|
|
2003 break;
|
|
2004 default: /* do no drawing */
|
|
2005 return;
|
|
2006 }
|
|
2007
|
|
2008 (*function_ptr) (
|
|
2009 mw,
|
|
2010 val,
|
|
2011 horizontal,
|
|
2012 highlighted,
|
|
2013 ws->window,
|
|
2014 x, y,
|
|
2015 width, height,
|
|
2016 label_tab,
|
|
2017 binding_tab
|
|
2018 );
|
|
2019 }
|
|
2020
|
|
2021 static void
|
|
2022 size_menu (XlwMenuWidget mw, int level)
|
|
2023 {
|
|
2024 unsigned toggle_width;
|
|
2025 unsigned label_width;
|
|
2026 unsigned rest_width;
|
|
2027 unsigned height;
|
|
2028 unsigned max_toggle_width = 0;
|
|
2029 unsigned max_label_width = 0;
|
|
2030 unsigned max_rest_width = 0;
|
|
2031 unsigned max_height = 0;
|
|
2032 int horizontal_p = mw->menu.horizontal && (level == 0);
|
|
2033 widget_value* val;
|
|
2034 window_state* ws;
|
|
2035
|
|
2036 if (level >= mw->menu.old_depth)
|
|
2037 abort ();
|
|
2038
|
|
2039 ws = &mw->menu.windows [level];
|
|
2040
|
|
2041 for (val = mw->menu.old_stack [level]->contents; val; val = val->next)
|
|
2042 {
|
|
2043 size_menu_item (
|
|
2044 mw,
|
|
2045 val,
|
|
2046 horizontal_p,
|
|
2047 &toggle_width,
|
|
2048 &label_width,
|
|
2049 &rest_width,
|
|
2050 &height
|
|
2051 );
|
|
2052 if (horizontal_p)
|
|
2053 {
|
|
2054 max_label_width += toggle_width + label_width + rest_width;
|
|
2055 if (height > max_height)
|
|
2056 max_height = height;
|
|
2057 }
|
|
2058 else
|
|
2059 {
|
|
2060 if (toggle_width > max_toggle_width)
|
|
2061 max_toggle_width = toggle_width;
|
|
2062 if (label_width > max_label_width)
|
|
2063 max_label_width = label_width;
|
|
2064 if (rest_width > max_rest_width)
|
|
2065 max_rest_width = rest_width;
|
|
2066 max_height += height;
|
|
2067 }
|
|
2068 }
|
|
2069
|
|
2070 ws->height = max_height;
|
|
2071 ws->width = max_label_width + max_rest_width + max_toggle_width;
|
|
2072 ws->toggle_width = max_toggle_width;
|
|
2073 ws->label_width = max_label_width;
|
|
2074
|
|
2075 ws->width += 2 * mw->menu.shadow_thickness;
|
|
2076 ws->height += 2 * mw->menu.shadow_thickness;
|
|
2077 }
|
|
2078
|
|
2079 static void
|
|
2080 display_menu (XlwMenuWidget mw, int level, Boolean just_compute_p,
|
|
2081 XPoint *highlighted_pos, XPoint *hit, widget_value **hit_return,
|
|
2082 widget_value *this, widget_value *that)
|
|
2083 {
|
|
2084 widget_value *val;
|
|
2085 widget_value *following_item;
|
|
2086 window_state *ws;
|
|
2087 XPoint where;
|
|
2088 int horizontal_p = mw->menu.horizontal && (level == 0);
|
|
2089 int highlighted_p;
|
|
2090 int just_compute_this_one_p;
|
|
2091
|
|
2092 if (level >= mw->menu.old_depth)
|
|
2093 abort ();
|
|
2094
|
|
2095 if (level < mw->menu.old_depth - 1)
|
|
2096 following_item = mw->menu.old_stack [level + 1];
|
|
2097 else
|
|
2098 following_item = NULL;
|
|
2099
|
|
2100 #if SLOPPY_TYPES == 1
|
|
2101 puts("===================================================================");
|
|
2102 print_widget_value (following_item, 1, 0);
|
|
2103 #endif
|
|
2104 if (following_item
|
|
2105 && following_item->type == CASCADE_TYPE
|
|
2106 && following_item->contents
|
|
2107 && following_item->contents->type == INCREMENTAL_TYPE)
|
|
2108 {
|
|
2109 /* okay, we're now doing a lisp callback to incrementally generate
|
|
2110 more of the menu. */
|
|
2111 XtCallCallbackList ((Widget)mw,
|
|
2112 mw->menu.open,
|
|
2113 (XtPointer)following_item->contents);
|
|
2114 #if SLOPPY_TYPES == 1
|
|
2115 puts("==== NEW ==== NEW ==== NEW ==== NEW ==== NEW ==== NEW ==== NEW ====");
|
|
2116 print_widget_value(following_item, 1, 0);
|
|
2117 #endif
|
|
2118 }
|
|
2119
|
|
2120 if (hit)
|
|
2121 *hit_return = NULL;
|
|
2122
|
|
2123 where.x = mw->menu.shadow_thickness;
|
|
2124 where.y = mw->menu.shadow_thickness;
|
|
2125
|
|
2126 ws = &mw->menu.windows [level];
|
|
2127 for (val = mw->menu.old_stack [level]->contents; val; val = val->next)
|
|
2128 {
|
|
2129 XPoint start;
|
|
2130
|
|
2131 highlighted_p = (val == following_item);
|
|
2132 /* If this is the partition (the dummy item which says that menus
|
|
2133 after this should be flushright) then figure out how big the
|
|
2134 following items are. This means we walk down the tail of the
|
|
2135 list twice, but that's no big deal - it's short.
|
|
2136 */
|
|
2137 if (horizontal_p && (menu_item_type (val) == PUSHRIGHT_TYPE))
|
|
2138 {
|
|
2139 widget_value *rest;
|
|
2140 XPoint flushright_size;
|
|
2141 int new_x;
|
|
2142 flushright_size.x = 0;
|
|
2143 flushright_size.y = 0;
|
|
2144 for (rest = val; rest; rest = rest->next)
|
|
2145 display_menu_item (mw, rest, ws, &flushright_size,
|
|
2146 highlighted_p, horizontal_p, True);
|
|
2147 new_x = ws->width - (flushright_size.x + mw->menu.shadow_thickness);
|
|
2148 if (new_x > where.x)
|
|
2149 where.x = new_x;
|
|
2150 /* We know what we need; don't draw this item. */
|
|
2151 continue;
|
|
2152 }
|
|
2153
|
|
2154 if (highlighted_p && highlighted_pos)
|
|
2155 {
|
|
2156 if (horizontal_p)
|
|
2157 highlighted_pos->x = where.x;
|
|
2158 else
|
|
2159 highlighted_pos->y = where.y;
|
|
2160 }
|
|
2161
|
|
2162 just_compute_this_one_p =
|
|
2163 just_compute_p || ((this || that) && val != this && val != that);
|
|
2164
|
|
2165 start.x = where.x;
|
|
2166 start.y = where.y;
|
|
2167 display_menu_item (mw, val, ws, &where, highlighted_p, horizontal_p,
|
|
2168 just_compute_this_one_p);
|
|
2169
|
|
2170 if (highlighted_p && highlighted_pos)
|
|
2171 {
|
|
2172 if (horizontal_p)
|
|
2173 highlighted_pos->y = ws->height;
|
|
2174 else
|
|
2175 highlighted_pos->x = ws->width;
|
|
2176 }
|
|
2177
|
|
2178 if (hit && !*hit_return && (val->type != SEPARATOR_TYPE))
|
|
2179 {
|
|
2180 if (horizontal_p && hit->x > start.x && hit->x < where.x)
|
|
2181 *hit_return = val;
|
|
2182 else if (!horizontal_p && hit->y > start.y && hit->y < where.y)
|
|
2183 *hit_return = val;
|
|
2184 }
|
|
2185
|
|
2186 if (horizontal_p)
|
|
2187 where.y = mw->menu.shadow_thickness;
|
|
2188 else
|
|
2189 where.x = mw->menu.shadow_thickness;
|
|
2190 }
|
|
2191
|
|
2192 /* Draw slab edges around menu */
|
|
2193 if (!just_compute_p)
|
|
2194 shadow_draw(mw, ws->window, 0, 0, ws->width, ws->height, SHADOW_OUT);
|
|
2195 }
|
|
2196
|
|
2197 /* Motion code */
|
|
2198 static void
|
|
2199 set_new_state (XlwMenuWidget mw, widget_value *val, int level)
|
|
2200 {
|
|
2201 int i;
|
|
2202
|
|
2203 mw->menu.new_depth = 0;
|
|
2204 for (i = 0; i < level; i++)
|
|
2205 push_new_stack (mw, mw->menu.old_stack [i]);
|
|
2206 if (val)
|
|
2207 push_new_stack (mw, val);
|
|
2208 }
|
|
2209
|
|
2210 static void
|
|
2211 make_windows_if_needed (XlwMenuWidget mw, int n)
|
|
2212 {
|
|
2213 int i;
|
|
2214 int start_at;
|
|
2215 XSetWindowAttributes xswa;
|
|
2216 int mask;
|
|
2217 #define ROOT_PARENT
|
|
2218 #ifdef ROOT_PARENT
|
|
2219 Window root = RootWindowOfScreen (DefaultScreenOfDisplay (XtDisplay (mw)));
|
|
2220 #endif
|
|
2221 window_state *windows;
|
|
2222
|
|
2223 if (mw->menu.windows_length >= n)
|
|
2224 return;
|
|
2225
|
|
2226 xswa.save_under = True;
|
|
2227 xswa.override_redirect = True;
|
|
2228 xswa.background_pixel = mw->core.background_pixel;
|
|
2229 xswa.border_pixel = mw->core.border_pixel;
|
|
2230 xswa.event_mask = (ExposureMask | ButtonMotionMask
|
|
2231 | ButtonReleaseMask | ButtonPressMask);
|
|
2232 xswa.cursor = mw->menu.cursor_shape;
|
|
2233 mask = CWSaveUnder | CWOverrideRedirect | CWBackPixel | CWBorderPixel
|
|
2234 | CWEventMask | CWCursor;
|
|
2235
|
|
2236 if (mw->menu.use_backing_store)
|
|
2237 {
|
|
2238 xswa.backing_store = Always;
|
|
2239 mask |= CWBackingStore;
|
|
2240 }
|
|
2241
|
|
2242 if (!mw->menu.windows)
|
|
2243 {
|
|
2244 mw->menu.windows =
|
|
2245 (window_state *) XtMalloc (n * sizeof (window_state));
|
|
2246 start_at = 0;
|
|
2247 }
|
|
2248 else
|
|
2249 {
|
|
2250 mw->menu.windows =
|
|
2251 (window_state *) XtRealloc ((char*)mw->menu.windows,
|
|
2252 n * sizeof (window_state));
|
|
2253 start_at = mw->menu.windows_length;
|
|
2254 }
|
|
2255 mw->menu.windows_length = n;
|
|
2256
|
|
2257 windows = mw->menu.windows;
|
|
2258
|
|
2259 for (i = start_at; i < n; i++)
|
|
2260 {
|
|
2261 windows [i].x = 0;
|
|
2262 windows [i].y = 0;
|
|
2263 windows [i].width = 1;
|
|
2264 windows [i].height = 1;
|
|
2265 windows [i].window =
|
|
2266 XCreateWindow (XtDisplay (mw),
|
|
2267 #ifdef ROOT_PARENT
|
|
2268 root,
|
|
2269 #else
|
|
2270 ((i > 0)
|
|
2271 ? windows[0].window
|
|
2272 : XtWindow (XtParent (mw))),
|
|
2273 #endif
|
|
2274 0, 0, 1, 1,
|
|
2275 0, 0, CopyFromParent, CopyFromParent, mask, &xswa);
|
|
2276 }
|
|
2277 }
|
|
2278
|
|
2279 /* Make the window fit in the screen */
|
|
2280 static void
|
|
2281 fit_to_screen (XlwMenuWidget mw, window_state *ws, window_state *previous_ws,
|
|
2282 Boolean horizontal_p)
|
|
2283 {
|
|
2284 int screen_width = WidthOfScreen (XtScreen (mw));
|
|
2285 int screen_height = HeightOfScreen (XtScreen (mw));
|
|
2286
|
|
2287 if (ws->x < 0)
|
|
2288 ws->x = 0;
|
|
2289 else if ((int) (ws->x + ws->width) > screen_width)
|
|
2290 {
|
|
2291 if (!horizontal_p)
|
|
2292 ws->x = previous_ws->x - ws->width;
|
|
2293 else
|
|
2294 {
|
|
2295 ws->x = screen_width - ws->width;
|
|
2296
|
|
2297 /* This check is to make sure we cut off the right side
|
|
2298 instead of the left side if the menu is wider than the
|
|
2299 screen. */
|
|
2300 if (ws->x < 0)
|
|
2301 ws->x = 0;
|
|
2302 }
|
|
2303 }
|
|
2304 if (ws->y < 0)
|
|
2305 ws->y = 0;
|
|
2306 else if ((int) (ws->y + ws->height) > screen_height)
|
|
2307 {
|
|
2308 if (horizontal_p)
|
|
2309 {
|
|
2310 /* A pulldown must either be entirely above or below the menubar.
|
|
2311 If we're here, the pulldown doesn't fit below the menubar, so
|
|
2312 let's determine if it will fit above the menubar.
|
|
2313 Only put it above if there is more room above than below.
|
|
2314 Note shadow_thickness offset to allow for slab surround.
|
|
2315 */
|
|
2316 if (ws->y > (screen_height / 2))
|
|
2317 ws->y = previous_ws->y - ws->height + mw->menu.shadow_thickness;
|
|
2318 }
|
|
2319 else
|
|
2320 {
|
|
2321 ws->y = screen_height - ws->height;
|
|
2322 /* if it's taller than the screen, display the topmost part
|
|
2323 that will fit, beginning at the top of the screen. */
|
|
2324 if (ws->y < 0)
|
|
2325 ws->y = 0;
|
|
2326 }
|
|
2327 }
|
|
2328 }
|
|
2329
|
|
2330 /* Updates old_stack from new_stack and redisplays. */
|
|
2331 static void
|
|
2332 remap_menubar (XlwMenuWidget mw)
|
|
2333 {
|
|
2334 int i;
|
|
2335 int last_same;
|
|
2336 XPoint selection_position;
|
|
2337 int old_depth = mw->menu.old_depth;
|
|
2338 int new_depth = mw->menu.new_depth;
|
|
2339 widget_value **old_stack;
|
|
2340 widget_value **new_stack;
|
|
2341 window_state *windows;
|
|
2342 widget_value *old_selection;
|
|
2343 widget_value *new_selection;
|
|
2344
|
|
2345 /* Check that enough windows and old_stack are ready. */
|
|
2346 make_windows_if_needed (mw, new_depth);
|
|
2347 make_old_stack_space (mw, new_depth);
|
|
2348 windows = mw->menu.windows;
|
|
2349 old_stack = mw->menu.old_stack;
|
|
2350 new_stack = mw->menu.new_stack;
|
|
2351
|
|
2352 /* compute the last identical different entry */
|
|
2353 for (i = 1; i < old_depth && i < new_depth; i++)
|
|
2354 if (old_stack [i] != new_stack [i])
|
|
2355 break;
|
|
2356 last_same = i - 1;
|
|
2357
|
|
2358 /* Memorize the previously selected item to be able to refresh it */
|
|
2359 old_selection = last_same + 1 < old_depth ? old_stack [last_same + 1] : NULL;
|
|
2360 if (old_selection && !old_selection->enabled)
|
|
2361 old_selection = NULL;
|
|
2362 new_selection = last_same + 1 < new_depth ? new_stack [last_same + 1] : NULL;
|
|
2363 if (new_selection && !new_selection->enabled)
|
|
2364 new_selection = NULL;
|
|
2365
|
|
2366 /* updates old_state from new_state. It has to be done now because
|
|
2367 display_menu (called below) uses the old_stack to know what to display. */
|
|
2368 for (i = last_same + 1; i < new_depth; i++)
|
|
2369 old_stack [i] = new_stack [i];
|
|
2370 mw->menu.old_depth = new_depth;
|
|
2371
|
|
2372 /* refresh the last seletion */
|
|
2373 selection_position.x = 0;
|
|
2374 selection_position.y = 0;
|
|
2375 display_menu (mw, last_same, new_selection == old_selection,
|
|
2376 &selection_position, NULL, NULL, old_selection, new_selection);
|
|
2377
|
|
2378 /* Now popup the new menus */
|
|
2379 for (i = last_same + 1; i < new_depth && new_stack [i]->contents; i++)
|
|
2380 {
|
|
2381 window_state *previous_ws = &windows [i - 1];
|
|
2382 window_state *ws = &windows [i];
|
|
2383
|
|
2384 ws->x = previous_ws->x + selection_position.x;
|
|
2385 ws->y = previous_ws->y + selection_position.y;
|
|
2386
|
|
2387 /* take into account the slab around the new menu */
|
|
2388 ws->y -= mw->menu.shadow_thickness;
|
|
2389
|
|
2390 size_menu (mw, i);
|
|
2391
|
|
2392 fit_to_screen (mw, ws, previous_ws, mw->menu.horizontal && i == 1);
|
|
2393
|
|
2394 XClearWindow (XtDisplay (mw), ws->window);
|
|
2395 XMoveResizeWindow (XtDisplay (mw), ws->window, ws->x, ws->y,
|
|
2396 ws->width, ws->height);
|
|
2397 XMapRaised (XtDisplay (mw), ws->window);
|
|
2398 display_menu (mw, i, False, &selection_position, NULL, NULL, NULL, NULL);
|
|
2399 }
|
|
2400
|
|
2401 /* unmap the menus that popped down */
|
|
2402 for (i = new_depth - 1; i < old_depth; i++)
|
|
2403 if (i >= new_depth || !new_stack [i]->contents)
|
|
2404 XUnmapWindow (XtDisplay (mw), windows [i].window);
|
|
2405 }
|
|
2406
|
|
2407 static Boolean
|
|
2408 motion_event_is_in_menu (XlwMenuWidget mw, XMotionEvent *ev, int level,
|
|
2409 XPoint *relative_pos)
|
|
2410 {
|
|
2411 window_state *ws = &mw->menu.windows [level];
|
|
2412 int x = level == 0 ? ws->x : ws->x + mw->menu.shadow_thickness;
|
|
2413 int y = level == 0 ? ws->y : ws->y + mw->menu.shadow_thickness;
|
|
2414 relative_pos->x = ev->x_root - x;
|
|
2415 relative_pos->y = ev->y_root - y;
|
|
2416 return (x < ev->x_root && ev->x_root < (int) (x + ws->width)
|
|
2417 && y < ev->y_root && ev->y_root < (int) (y + ws->height));
|
|
2418 }
|
|
2419
|
|
2420 static Boolean
|
|
2421 map_event_to_widget_value (XlwMenuWidget mw, XMotionEvent *ev,
|
|
2422 widget_value **val_ptr, int *level,
|
|
2423 Boolean *inside_menu)
|
|
2424 {
|
|
2425 int i;
|
|
2426 XPoint relative_pos;
|
|
2427 window_state* ws;
|
|
2428
|
|
2429 *val_ptr = NULL;
|
|
2430 *inside_menu = False;
|
|
2431
|
|
2432 /* Find the window */
|
|
2433 for (i = mw->menu.old_depth - 1; i >= 0; i--)
|
|
2434 {
|
|
2435 ws = &mw->menu.windows [i];
|
|
2436 if (ws && motion_event_is_in_menu (mw, ev, i, &relative_pos))
|
|
2437 {
|
|
2438 *inside_menu = True; /* special logic for menubar below... */
|
|
2439 if ((ev->type == ButtonPress) ||
|
|
2440 (ev->state != 0))
|
|
2441 {
|
|
2442 display_menu (mw, i, True, NULL, &relative_pos,
|
|
2443 val_ptr, NULL, NULL);
|
|
2444 if (*val_ptr)
|
|
2445 {
|
|
2446 *level = i + 1;
|
|
2447 *inside_menu = True;
|
|
2448 return True;
|
|
2449 }
|
|
2450 else if (mw->menu.horizontal || i == 0)
|
|
2451 {
|
|
2452 /* if we're clicking on empty part of the menubar, then
|
|
2453 unpost the stay-up menu */
|
|
2454 *inside_menu = False;
|
|
2455 }
|
|
2456 }
|
|
2457 }
|
|
2458 }
|
|
2459 return False;
|
|
2460 }
|
|
2461
|
|
2462 /* Procedures */
|
|
2463 static void
|
|
2464 make_drawing_gcs (XlwMenuWidget mw)
|
|
2465 {
|
|
2466 XGCValues xgcv;
|
|
2467 unsigned long flags = (GCFont | GCForeground | GCBackground);
|
|
2468
|
|
2469 #ifdef NEED_MOTIF
|
|
2470 xgcv.font = default_font_of_font_list (mw->menu.font_list)->fid;
|
|
2471 #else
|
|
2472 xgcv.font = mw->menu.font->fid;
|
|
2473 #endif
|
|
2474
|
|
2475 xgcv.foreground = mw->core.background_pixel;
|
|
2476 xgcv.background = mw->menu.foreground;
|
|
2477 mw->menu.background_gc = XtGetGC ((Widget)mw, flags, &xgcv);
|
|
2478
|
|
2479 xgcv.foreground = mw->menu.foreground;
|
|
2480 xgcv.background = mw->core.background_pixel;
|
|
2481 mw->menu.foreground_gc = XtGetGC ((Widget)mw, flags, &xgcv);
|
|
2482
|
|
2483 if (mw->menu.select_color != (Pixel)-1)
|
|
2484 {
|
|
2485 xgcv.foreground = mw->menu.select_color;
|
|
2486 }
|
|
2487 else
|
|
2488 {
|
|
2489 Display *dpy = XtDisplay(mw);
|
|
2490 if (CellsOfScreen(DefaultScreenOfDisplay(dpy)) <= 2)
|
|
2491 { /* mono */
|
|
2492 xgcv.foreground = mw->menu.foreground;
|
|
2493 }
|
|
2494 else
|
|
2495 { /* color */
|
|
2496 XColor xcolor;
|
|
2497 Colormap cmap = DefaultColormapOfScreen (XtScreen ((Widget) mw));
|
|
2498 xcolor.pixel = mw->core.background_pixel;
|
|
2499 XQueryColor (dpy, cmap, &xcolor);
|
|
2500 xcolor.red *= 0.85;
|
|
2501 xcolor.green *= 0.85;
|
|
2502 xcolor.blue *= 0.85;
|
|
2503 if (allocate_nearest_color (dpy, cmap, &xcolor))
|
|
2504 xgcv.foreground = xcolor.pixel;
|
|
2505 }
|
|
2506 }
|
|
2507 xgcv.background = mw->core.background_pixel;
|
|
2508 mw->menu.select_gc = XtGetGC ((Widget)mw, flags, &xgcv);
|
|
2509
|
|
2510 xgcv.foreground = mw->menu.foreground;
|
|
2511 xgcv.background = mw->core.background_pixel;
|
|
2512 xgcv.fill_style = FillStippled;
|
|
2513 xgcv.stipple = mw->menu.gray_pixmap;
|
|
2514 mw->menu.inactive_gc = XtGetGC ((Widget)mw,
|
|
2515 (flags | GCFillStyle | GCStipple),
|
|
2516 &xgcv);
|
|
2517
|
|
2518 xgcv.foreground = mw->menu.button_foreground;
|
|
2519 xgcv.background = mw->core.background_pixel;
|
|
2520 mw->menu.button_gc = XtGetGC ((Widget)mw, flags, &xgcv);
|
|
2521
|
|
2522 xgcv.fill_style = FillStippled;
|
|
2523 xgcv.stipple = mw->menu.gray_pixmap;
|
|
2524 mw->menu.inactive_button_gc = XtGetGC ((Widget)mw,
|
|
2525 (flags | GCFillStyle | GCStipple),
|
|
2526 &xgcv);
|
|
2527 }
|
|
2528
|
|
2529 static void
|
|
2530 release_drawing_gcs (XlwMenuWidget mw)
|
|
2531 {
|
|
2532 XtReleaseGC ((Widget) mw, mw->menu.foreground_gc);
|
|
2533 XtReleaseGC ((Widget) mw, mw->menu.button_gc);
|
|
2534 XtReleaseGC ((Widget) mw, mw->menu.inactive_gc);
|
|
2535 XtReleaseGC ((Widget) mw, mw->menu.inactive_button_gc);
|
|
2536 XtReleaseGC ((Widget) mw, mw->menu.background_gc);
|
|
2537 XtReleaseGC ((Widget) mw, mw->menu.select_gc);
|
|
2538 /* let's get some segvs if we try to use these... */
|
|
2539 mw->menu.foreground_gc = (GC) -1;
|
|
2540 mw->menu.button_gc = (GC) -1;
|
|
2541 mw->menu.inactive_gc = (GC) -1;
|
|
2542 mw->menu.inactive_button_gc = (GC) -1;
|
|
2543 mw->menu.background_gc = (GC) -1;
|
|
2544 mw->menu.select_gc = (GC) -1;
|
|
2545 }
|
|
2546
|
|
2547 #define MINL(x,y) ((((unsigned long) (x)) < ((unsigned long) (y))) \
|
|
2548 ? ((unsigned long) (x)) : ((unsigned long) (y)))
|
|
2549
|
|
2550 static void
|
|
2551 make_shadow_gcs (XlwMenuWidget mw)
|
|
2552 {
|
|
2553 XGCValues xgcv;
|
|
2554 unsigned long pm = 0;
|
|
2555 Display *dpy = XtDisplay ((Widget) mw);
|
|
2556 Colormap cmap = DefaultColormapOfScreen (XtScreen ((Widget) mw));
|
|
2557 XColor topc, botc;
|
|
2558 int top_frobbed = 0, bottom_frobbed = 0;
|
|
2559
|
|
2560 if (mw->menu.top_shadow_color == -1)
|
|
2561 mw->menu.top_shadow_color = mw->core.background_pixel;
|
|
2562 if (mw->menu.bottom_shadow_color == -1)
|
|
2563 mw->menu.bottom_shadow_color = mw->menu.foreground;
|
|
2564
|
|
2565 if (mw->menu.top_shadow_color == mw->core.background_pixel ||
|
|
2566 mw->menu.top_shadow_color == mw->menu.foreground)
|
|
2567 {
|
|
2568 topc.pixel = mw->core.background_pixel;
|
|
2569 XQueryColor (dpy, cmap, &topc);
|
|
2570 /* don't overflow/wrap! */
|
|
2571 topc.red = MINL (65535, topc.red * 1.2);
|
|
2572 topc.green = MINL (65535, topc.green * 1.2);
|
|
2573 topc.blue = MINL (65535, topc.blue * 1.2);
|
|
2574 if (allocate_nearest_color (dpy, cmap, &topc))
|
|
2575 {
|
|
2576 if (topc.pixel == mw->core.background_pixel)
|
|
2577 {
|
|
2578 XFreeColors( dpy, cmap, &topc.pixel, 1, 0);
|
|
2579 topc.red = MINL (65535, topc.red + 0x8000);
|
|
2580 topc.green = MINL (65535, topc.green + 0x8000);
|
|
2581 topc.blue = MINL (65535, topc.blue + 0x8000);
|
|
2582 if (allocate_nearest_color (dpy, cmap, &topc))
|
|
2583 {
|
|
2584 mw->menu.top_shadow_color = topc.pixel;
|
|
2585 }
|
|
2586 }
|
|
2587 else
|
|
2588 {
|
|
2589 mw->menu.top_shadow_color = topc.pixel;
|
|
2590 }
|
|
2591
|
|
2592 top_frobbed = 1;
|
|
2593 }
|
|
2594 }
|
|
2595 if (mw->menu.bottom_shadow_color == mw->menu.foreground ||
|
|
2596 mw->menu.bottom_shadow_color == mw->core.background_pixel)
|
|
2597 {
|
|
2598 botc.pixel = mw->core.background_pixel;
|
|
2599 XQueryColor (dpy, cmap, &botc);
|
|
2600 botc.red *= 0.6;
|
|
2601 botc.green *= 0.6;
|
|
2602 botc.blue *= 0.6;
|
|
2603 if (allocate_nearest_color (dpy, cmap, &botc))
|
|
2604 {
|
|
2605 if (botc.pixel == mw->core.background_pixel)
|
|
2606 {
|
|
2607 XFreeColors (dpy, cmap, &botc.pixel, 1, 0);
|
|
2608 botc.red = MINL (65535, botc.red + 0x4000);
|
|
2609 botc.green = MINL (65535, botc.green + 0x4000);
|
|
2610 botc.blue = MINL (65535, botc.blue + 0x4000);
|
|
2611 if (allocate_nearest_color (dpy, cmap, &botc))
|
|
2612 {
|
|
2613 mw->menu.bottom_shadow_color = botc.pixel;
|
|
2614 }
|
|
2615 }
|
|
2616 else
|
|
2617 {
|
|
2618 mw->menu.bottom_shadow_color = botc.pixel;
|
|
2619 }
|
|
2620
|
|
2621 bottom_frobbed = 1;
|
|
2622 }
|
|
2623 }
|
|
2624
|
|
2625 if (top_frobbed && bottom_frobbed)
|
|
2626 {
|
|
2627 int top_avg = ((topc.red / 3) + (topc.green / 3) + (topc.blue / 3));
|
|
2628 int bot_avg = ((botc.red / 3) + (botc.green / 3) + (botc.blue / 3));
|
|
2629 if (bot_avg > top_avg)
|
|
2630 {
|
|
2631 Pixel tmp = mw->menu.top_shadow_color;
|
|
2632 mw->menu.top_shadow_color = mw->menu.bottom_shadow_color;
|
|
2633 mw->menu.bottom_shadow_color = tmp;
|
|
2634 }
|
|
2635 else if (topc.pixel == botc.pixel)
|
|
2636 {
|
|
2637 if (botc.pixel == mw->menu.foreground)
|
|
2638 mw->menu.top_shadow_color = mw->core.background_pixel;
|
|
2639 else
|
|
2640 mw->menu.bottom_shadow_color = mw->menu.foreground;
|
|
2641 }
|
|
2642 }
|
|
2643
|
|
2644 if (!mw->menu.top_shadow_pixmap &&
|
|
2645 mw->menu.top_shadow_color == mw->core.background_pixel)
|
|
2646 {
|
|
2647 mw->menu.top_shadow_pixmap = mw->menu.gray_pixmap;
|
|
2648 mw->menu.top_shadow_color = mw->menu.foreground;
|
|
2649 }
|
|
2650 if (!mw->menu.bottom_shadow_pixmap &&
|
|
2651 mw->menu.bottom_shadow_color == mw->core.background_pixel)
|
|
2652 {
|
|
2653 mw->menu.bottom_shadow_pixmap = mw->menu.gray_pixmap;
|
|
2654 mw->menu.bottom_shadow_color = mw->menu.foreground;
|
|
2655 }
|
|
2656
|
|
2657 xgcv.fill_style = FillOpaqueStippled;
|
|
2658 xgcv.foreground = mw->menu.top_shadow_color;
|
|
2659 xgcv.background = mw->core.background_pixel;
|
|
2660 xgcv.stipple = mw->menu.top_shadow_pixmap;
|
|
2661 pm = (xgcv.stipple ? GCStipple|GCFillStyle : 0);
|
|
2662 mw->menu.shadow_top_gc =
|
|
2663 XtGetGC((Widget)mw, GCForeground|GCBackground|pm, &xgcv);
|
|
2664
|
|
2665 xgcv.foreground = mw->menu.bottom_shadow_color;
|
|
2666 xgcv.stipple = mw->menu.bottom_shadow_pixmap;
|
|
2667 pm = (xgcv.stipple ? GCStipple|GCFillStyle : 0);
|
|
2668 mw->menu.shadow_bottom_gc =
|
|
2669 XtGetGC ((Widget)mw, GCForeground|GCBackground|pm, &xgcv);
|
|
2670 }
|
|
2671
|
|
2672
|
|
2673 static void
|
|
2674 release_shadow_gcs (XlwMenuWidget mw)
|
|
2675 {
|
|
2676 XtReleaseGC ((Widget) mw, mw->menu.shadow_top_gc);
|
|
2677 XtReleaseGC ((Widget) mw, mw->menu.shadow_bottom_gc);
|
|
2678 }
|
|
2679
|
|
2680
|
|
2681 static void
|
|
2682 extract_font_extents (XlwMenuWidget mw)
|
|
2683 {
|
|
2684 #ifdef NEED_MOTIF
|
|
2685 /* Find the maximal ascent/descent of the fonts in the font list
|
|
2686 so that all menu items can be the same height... */
|
|
2687 mw->menu.font_ascent = 0;
|
|
2688 mw->menu.font_descent = 0;
|
|
2689
|
|
2690 {
|
|
2691 XmFontContext context;
|
|
2692 #if (XmVersion >= 1002)
|
|
2693 XmFontListEntry fontentry;
|
|
2694 #else
|
|
2695 XmStringCharSet charset;
|
|
2696 #endif
|
|
2697 XFontStruct *font;
|
|
2698
|
|
2699 if (! XmFontListInitFontContext (&context, mw->menu.font_list))
|
|
2700 abort ();
|
|
2701 #if (XmVersion >= 1002)
|
|
2702 /* There is a BUG in the 1.2 version of XmFontListGetNextFont() (or more
|
|
2703 specifically, in _XmGetFirstFont()) that can cause a null pointer to be
|
|
2704 passed to XFontsOfFontSet. Use XmFontListNextEntry(), which is the
|
|
2705 newer equivalent, instead. Also, it supports font sets, and the
|
|
2706 older function doesn't. */
|
|
2707 while ((fontentry = XmFontListNextEntry (context)))
|
|
2708 {
|
|
2709 char *one_of_them;
|
|
2710 XmFontType rettype;
|
|
2711
|
|
2712 one_of_them = XmFontListEntryGetFont (fontentry, &rettype);
|
|
2713 if (rettype == XmFONT_IS_FONTSET)
|
|
2714 {
|
|
2715 XFontSet fontset = (XFontSet) one_of_them;
|
|
2716 XFontStruct **fontstruct_list;
|
|
2717 char **fontname_list;
|
|
2718 int fontcount = XFontsOfFontSet (fontset, &fontstruct_list,
|
|
2719 &fontname_list);
|
|
2720 while (--fontcount >= 0)
|
|
2721 {
|
|
2722 font = fontstruct_list[fontcount];
|
|
2723 if (font->ascent > (int) mw->menu.font_ascent)
|
|
2724 mw->menu.font_ascent = font->ascent;
|
|
2725 if (font->descent > (int) mw->menu.font_descent)
|
|
2726 mw->menu.font_descent = font->descent;
|
|
2727 }
|
|
2728 }
|
|
2729 else /* XmFONT_IS_FONT */
|
|
2730 {
|
|
2731 font = (XFontStruct *) one_of_them;
|
|
2732 if (font->ascent > (int) mw->menu.font_ascent)
|
|
2733 mw->menu.font_ascent = font->ascent;
|
|
2734 if (font->descent > (int) mw->menu.font_descent)
|
|
2735 mw->menu.font_descent = font->descent;
|
|
2736 }
|
|
2737 }
|
|
2738 #else /* motif 1.1 */
|
|
2739 while (XmFontListGetNextFont (context, &charset, &font))
|
|
2740 {
|
|
2741 if (font->ascent > (int) mw->menu.font_ascent)
|
|
2742 mw->menu.font_ascent = font->ascent;
|
|
2743 if (font->descent > (int) mw->menu.font_descent)
|
|
2744 mw->menu.font_descent = font->descent;
|
|
2745 XtFree (charset);
|
|
2746 }
|
|
2747 #endif /* Motif version */
|
|
2748 XmFontListFreeFontContext (context);
|
|
2749 }
|
|
2750 #else /* Not Motif */
|
|
2751 mw->menu.font_ascent = mw->menu.font->ascent;
|
|
2752 mw->menu.font_descent = mw->menu.font->descent;
|
|
2753 #endif /* NEED_MOTIF */
|
|
2754 }
|
|
2755
|
|
2756 #ifdef NEED_MOTIF
|
|
2757 static XFontStruct *
|
|
2758 default_font_of_font_list (XmFontList font_list)
|
|
2759 {
|
|
2760 XFontStruct *font = 0;
|
|
2761 # if 0
|
|
2762 /* Xm/Label.c does this: */
|
|
2763 _XmFontListGetDefaultFont (font_list, &font);
|
|
2764 # else /* !0 */
|
|
2765 {
|
|
2766 XmFontContext context;
|
|
2767 #if (XmVersion >= 1002)
|
|
2768 XmFontListEntry fontentry;
|
|
2769 XmFontType rettype;
|
|
2770 char *one_of_them;
|
|
2771 #else
|
|
2772 XmStringCharSet charset;
|
|
2773 #endif
|
|
2774
|
|
2775 if (! XmFontListInitFontContext (&context, font_list))
|
|
2776 abort ();
|
|
2777 #if (XmVersion >= 1002)
|
|
2778 /* There is a BUG in the 1.2 version of XmFontListGetNextFont() (or more
|
|
2779 specifically, in _XmGetFirstFont()) that can cause a null pointer to be
|
|
2780 passed to XFontsOfFontSet. Use XmFontListNextEntry(), which is the
|
|
2781 newer equivalent, instead. */
|
|
2782 fontentry = XmFontListNextEntry (context);
|
|
2783 one_of_them = XmFontListEntryGetFont (fontentry, &rettype);
|
|
2784 if (rettype == XmFONT_IS_FONTSET)
|
|
2785 {
|
|
2786 XFontSet fontset = (XFontSet) one_of_them;
|
|
2787 XFontStruct **fontstruct_list;
|
|
2788 char **fontname_list;
|
|
2789 (void) XFontsOfFontSet (fontset, &fontstruct_list, &fontname_list);
|
|
2790 font = fontstruct_list[0];
|
|
2791 }
|
|
2792 else /* XmFONT_IS_FONT */
|
|
2793 {
|
|
2794 font = (XFontStruct *) one_of_them;
|
|
2795 }
|
|
2796 #else
|
|
2797 if (! XmFontListGetNextFont (context, &charset, &font))
|
|
2798 abort ();
|
|
2799 XtFree (charset);
|
|
2800 #endif
|
|
2801 XmFontListFreeFontContext (context);
|
|
2802 }
|
|
2803 # endif /* !0 */
|
|
2804
|
|
2805 if (! font) abort ();
|
|
2806 return font;
|
|
2807 }
|
|
2808 #endif /* NEED_MOTIF */
|
|
2809
|
|
2810 static void
|
|
2811 XlwMenuInitialize (Widget request, Widget new, ArgList args,
|
|
2812 Cardinal *num_args)
|
|
2813 {
|
|
2814 /* Get the GCs and the widget size */
|
|
2815 XlwMenuWidget mw = (XlwMenuWidget)new;
|
|
2816
|
|
2817 XSetWindowAttributes xswa;
|
|
2818 int mask;
|
|
2819
|
|
2820 Window window = RootWindowOfScreen (DefaultScreenOfDisplay (XtDisplay (mw)));
|
|
2821 Display *display = XtDisplay (mw);
|
|
2822
|
|
2823 /* mw->menu.cursor = XCreateFontCursor (display, mw->menu.cursor_shape); */
|
|
2824 mw->menu.cursor = mw->menu.cursor_shape;
|
|
2825
|
|
2826 mw->menu.gray_pixmap = XCreatePixmapFromBitmapData (display, window,
|
|
2827 (char *) gray_bits,
|
|
2828 gray_width,
|
|
2829 gray_height, 1, 0, 1);
|
|
2830
|
|
2831 #ifdef NEED_MOTIF
|
|
2832 /* The menu.font_list slot came from the *fontList resource (Motif standard.)
|
|
2833 The menu.font_list_2 slot came from the *font resource, for backward
|
|
2834 compatibility with older versions of this code, and consistency with the
|
|
2835 rest of emacs. If both font and fontList are specified, we use font.
|
|
2836 If only one is specified, we use that. If neither are specified, we
|
|
2837 use the "fallback" value. What a kludge!!!
|
|
2838
|
|
2839 Note that this has the bug that a more general wildcard like "*fontList:"
|
|
2840 will override a more specific resource like "Emacs*menubar.font:". But
|
|
2841 I can't think of a way around that.
|
|
2842 */
|
|
2843 if (mw->menu.font_list) /* if *fontList is specified, use that */
|
|
2844 ;
|
|
2845 else if (mw->menu.font_list_2) /* else if *font is specified, use that */
|
|
2846 mw->menu.font_list = mw->menu.font_list_2;
|
|
2847 else /* otherwise use default */
|
|
2848 mw->menu.font_list = mw->menu.fallback_font_list;
|
|
2849 #endif
|
|
2850
|
|
2851 make_drawing_gcs (mw);
|
|
2852 make_shadow_gcs (mw);
|
|
2853 extract_font_extents (mw);
|
|
2854
|
|
2855 xswa.background_pixel = mw->core.background_pixel;
|
|
2856 xswa.border_pixel = mw->core.border_pixel;
|
|
2857 mask = CWBackPixel | CWBorderPixel;
|
|
2858
|
|
2859 mw->menu.popped_up = False;
|
|
2860 mw->menu.pointer_grabbed = False;
|
|
2861 mw->menu.next_release_must_exit = False;
|
|
2862
|
|
2863 mw->menu.old_depth = 1;
|
|
2864 mw->menu.old_stack = (widget_value**)XtMalloc (sizeof (widget_value*));
|
|
2865 mw->menu.old_stack_length = 1;
|
|
2866 mw->menu.old_stack [0] = mw->menu.contents;
|
|
2867
|
|
2868 mw->menu.new_depth = 0;
|
|
2869 mw->menu.new_stack = 0;
|
|
2870 mw->menu.new_stack_length = 0;
|
|
2871 push_new_stack (mw, mw->menu.contents);
|
|
2872
|
|
2873 mw->menu.windows = (window_state*)XtMalloc (sizeof (window_state));
|
|
2874 mw->menu.windows_length = 1;
|
|
2875 mw->menu.windows [0].x = 0;
|
|
2876 mw->menu.windows [0].y = 0;
|
|
2877 mw->menu.windows [0].width = 0;
|
|
2878 mw->menu.windows [0].height = 0;
|
|
2879 size_menu (mw, 0);
|
|
2880
|
|
2881 mw->core.width = mw->menu.windows [0].width;
|
|
2882 mw->core.height = mw->menu.windows [0].height;
|
|
2883 }
|
|
2884
|
|
2885 static void
|
|
2886 XlwMenuClassInitialize (void)
|
|
2887 {
|
|
2888 }
|
|
2889
|
|
2890 static void
|
|
2891 XlwMenuRealize (Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
|
|
2892 {
|
|
2893 XlwMenuWidget mw = (XlwMenuWidget)w;
|
|
2894 XSetWindowAttributes xswa;
|
|
2895 int mask;
|
|
2896
|
|
2897 (*xlwMenuWidgetClass->core_class.superclass->core_class.realize)
|
|
2898 (w, valueMask, attributes);
|
|
2899
|
|
2900 xswa.save_under = True;
|
|
2901 xswa.cursor = mw->menu.cursor_shape;
|
|
2902 mask = CWSaveUnder | CWCursor;
|
|
2903 if (mw->menu.use_backing_store)
|
|
2904 {
|
|
2905 xswa.backing_store = Always;
|
|
2906 mask |= CWBackingStore;
|
|
2907 }
|
|
2908 XChangeWindowAttributes (XtDisplay (w), XtWindow (w), mask, &xswa);
|
|
2909
|
|
2910 mw->menu.windows [0].window = XtWindow (w);
|
|
2911 mw->menu.windows [0].x = w->core.x;
|
|
2912 mw->menu.windows [0].y = w->core.y;
|
|
2913 mw->menu.windows [0].width = w->core.width;
|
|
2914 mw->menu.windows [0].height = w->core.height;
|
|
2915 }
|
|
2916
|
|
2917 /* Only the toplevel menubar/popup is a widget so it's the only one that
|
|
2918 receives expose events through Xt. So we repaint all the other panes
|
|
2919 when receiving an Expose event. */
|
|
2920 static void
|
|
2921 XlwMenuRedisplay (Widget w, XEvent *ev, Region region)
|
|
2922 {
|
|
2923 XlwMenuWidget mw = (XlwMenuWidget)w;
|
|
2924 int i;
|
|
2925
|
|
2926 if (mw->core.being_destroyed) return;
|
|
2927
|
|
2928 for (i = 0; i < mw->menu.old_depth; i++)
|
|
2929 display_menu (mw, i, False, NULL, NULL, NULL, NULL, NULL);
|
|
2930 set_new_state (mw, NULL, mw->menu.old_depth); /* #### - ??? */
|
|
2931 remap_menubar (mw); /* #### - do these two lines do anything? */
|
|
2932 }
|
|
2933
|
|
2934 static void
|
|
2935 XlwMenuDestroy (Widget w)
|
|
2936 {
|
|
2937 int i;
|
|
2938 XlwMenuWidget mw = (XlwMenuWidget) w;
|
|
2939
|
|
2940 if (mw->menu.pointer_grabbed)
|
|
2941 {
|
|
2942 XtUngrabPointer (w, CurrentTime);
|
|
2943 mw->menu.pointer_grabbed = False;
|
|
2944 }
|
|
2945
|
|
2946 release_drawing_gcs (mw);
|
|
2947 release_shadow_gcs (mw);
|
|
2948
|
|
2949 /* this doesn't come from the resource db but is created explicitly
|
|
2950 so we must free it ourselves. */
|
|
2951 XFreePixmap (XtDisplay (mw), mw->menu.gray_pixmap);
|
|
2952 mw->menu.gray_pixmap = (Pixmap) -1;
|
|
2953
|
|
2954 /* Don't free mw->menu.contents because that comes from our creator.
|
|
2955 The `*_stack' elements are just pointers into `contents' so leave
|
|
2956 that alone too. But free the stacks themselves. */
|
|
2957 if (mw->menu.old_stack) XtFree ((char *) mw->menu.old_stack);
|
|
2958 if (mw->menu.new_stack) XtFree ((char *) mw->menu.new_stack);
|
|
2959
|
|
2960 /* Remember, you can't free anything that came from the resource
|
|
2961 database. This includes:
|
|
2962 mw->menu.cursor
|
|
2963 mw->menu.top_shadow_pixmap
|
|
2964 mw->menu.bottom_shadow_pixmap
|
|
2965 mw->menu.font
|
|
2966 mw->menu.font_set
|
|
2967 Also the color cells of top_shadow_color, bottom_shadow_color,
|
|
2968 foreground, and button_foreground will never be freed until this
|
|
2969 client exits. Nice, eh?
|
|
2970 */
|
|
2971
|
|
2972 /* start from 1 because the one in slot 0 is w->core.window */
|
|
2973 for (i = 1; i < mw->menu.windows_length; i++)
|
|
2974 XDestroyWindow (XtDisplay (mw), mw->menu.windows [i].window);
|
|
2975 if (mw->menu.windows)
|
|
2976 XtFree ((char *) mw->menu.windows);
|
|
2977 }
|
|
2978
|
|
2979 static Boolean
|
|
2980 XlwMenuSetValues (Widget current, Widget request, Widget new, ArgList args,
|
|
2981 Cardinal *num_args)
|
|
2982 {
|
|
2983 XlwMenuWidget oldmw = (XlwMenuWidget)current;
|
|
2984 XlwMenuWidget newmw = (XlwMenuWidget)new;
|
|
2985 Boolean redisplay = False;
|
|
2986 int i;
|
|
2987
|
|
2988 if (newmw->menu.contents
|
|
2989 && newmw->menu.contents->contents
|
|
2990 && newmw->menu.contents->contents->change >= VISIBLE_CHANGE)
|
|
2991 redisplay = True;
|
|
2992
|
|
2993 if (newmw->core.background_pixel != oldmw->core.background_pixel
|
|
2994 || newmw->menu.foreground != oldmw->menu.foreground
|
|
2995 /* For the XEditResource protocol, which may want to change the font. */
|
|
2996 #ifdef NEED_MOTIF
|
|
2997 || newmw->menu.font_list != oldmw->menu.font_list
|
|
2998 || newmw->menu.font_list_2 != oldmw->menu.font_list_2
|
|
2999 || newmw->menu.fallback_font_list != oldmw->menu.fallback_font_list
|
|
3000 #else
|
|
3001 || newmw->menu.font != oldmw->menu.font
|
|
3002 #endif
|
|
3003 )
|
|
3004 {
|
|
3005 release_drawing_gcs (newmw);
|
|
3006 make_drawing_gcs (newmw);
|
|
3007 redisplay = True;
|
|
3008
|
|
3009 for (i = 0; i < oldmw->menu.windows_length; i++)
|
|
3010 {
|
|
3011 XSetWindowBackground (XtDisplay (oldmw),
|
|
3012 oldmw->menu.windows [i].window,
|
|
3013 newmw->core.background_pixel);
|
|
3014 /* clear windows and generate expose events */
|
|
3015 XClearArea (XtDisplay (oldmw), oldmw->menu.windows[i].window,
|
|
3016 0, 0, 0, 0, True);
|
|
3017 }
|
|
3018 }
|
|
3019
|
|
3020 return redisplay;
|
|
3021 }
|
|
3022
|
|
3023 static void
|
|
3024 XlwMenuResize (Widget w)
|
|
3025 {
|
|
3026 XlwMenuWidget mw = (XlwMenuWidget)w;
|
|
3027
|
|
3028 mw->menu.windows [0].width = mw->core.width;
|
|
3029 mw->menu.windows [0].height = mw->core.height;
|
|
3030 }
|
|
3031
|
|
3032 /* Action procedures */
|
|
3033 static void
|
|
3034 handle_single_motion_event (XlwMenuWidget mw, XMotionEvent *ev,
|
|
3035 Boolean select_p)
|
|
3036 {
|
|
3037 widget_value *val;
|
|
3038 Boolean stay_up;
|
|
3039 int level;
|
|
3040
|
|
3041 if (!map_event_to_widget_value (mw, ev, &val, &level, &stay_up))
|
|
3042 {
|
|
3043 /* we wind up here when: (a) the event is in the menubar, (b) the
|
|
3044 event isn't in the menubar or any of the panes, (c) the event is on
|
|
3045 a disabled menu item */
|
|
3046 pop_new_stack_if_no_contents (mw);
|
|
3047 if (select_p && !stay_up) {
|
|
3048 /* pop down all menus and exit */
|
|
3049 mw->menu.next_release_must_exit = True;
|
|
3050 set_new_state(mw, (val = NULL), 1);
|
|
3051 }
|
|
3052 }
|
|
3053 else
|
|
3054 {
|
|
3055 /* we wind up here when: (a) the event pops up a pull_right menu,
|
|
3056 (b) a menu item that is not disabled is highlighted */
|
|
3057 if (select_p && mw->menu.bounce_down
|
|
3058 && close_to_reference_time((Widget)mw,
|
|
3059 mw->menu.menu_bounce_time,
|
|
3060 (XEvent *)ev))
|
|
3061 {
|
|
3062 /* motion can cause more than one event. Don't bounce right back
|
|
3063 up if we've just bounced down. */
|
|
3064 val = NULL;
|
|
3065 }
|
|
3066 else if (select_p && mw->menu.bounce_down &&
|
|
3067 mw->menu.last_selected_val &&
|
|
3068 (mw->menu.last_selected_val == val))
|
|
3069 {
|
|
3070 val = NULL; /* assigned to mw->last_selected_val below */
|
|
3071 mw->menu.menu_bounce_time = ev->time;
|
|
3072 /* popdown last menu if we're selecting the same menu item as we did
|
|
3073 last time and the XlwMenu.bounceDown resource is set, if the
|
|
3074 item is on the menubar itself, then exit. */
|
|
3075 if (level == (mw->menu.popped_up ? 0 : 1))
|
|
3076 mw->menu.next_release_must_exit = True;
|
|
3077 }
|
|
3078 else
|
|
3079 mw->menu.menu_bounce_time = 0;
|
|
3080 set_new_state (mw, val, level);
|
|
3081 }
|
|
3082 mw->menu.last_selected_val = val;
|
|
3083 remap_menubar (mw);
|
|
3084
|
|
3085 /* Sync with the display. Makes it feel better on X terms. */
|
|
3086 XFlush (XtDisplay (mw));
|
|
3087 }
|
|
3088
|
|
3089 static void
|
|
3090 handle_motion_event (XlwMenuWidget mw, XMotionEvent *ev,
|
|
3091 Boolean select_p)
|
|
3092 {
|
|
3093 int x = ev->x_root;
|
|
3094 int y = ev->y_root;
|
|
3095 int state = ev->state;
|
|
3096 XMotionEvent *event= ev, dummy;
|
|
3097
|
|
3098 /* allow motion events to be generated again */
|
|
3099 dummy.window = ev->window;
|
|
3100 if (ev->is_hint
|
|
3101 && XQueryPointer (XtDisplay (mw), dummy.window,
|
|
3102 &dummy.root, &dummy.subwindow,
|
|
3103 &dummy.x_root, &dummy.y_root,
|
|
3104 &dummy.x, &dummy.y,
|
|
3105 &dummy.state)
|
|
3106 && dummy.state == state
|
|
3107 && (dummy.x_root != x || dummy.y_root != y))
|
|
3108 {
|
|
3109 /* don't handle the event twice or that breaks bounce_down. --Stig */
|
|
3110 dummy.type = ev->type;
|
|
3111 event = &dummy;
|
|
3112 }
|
|
3113
|
|
3114 handle_single_motion_event (mw, event, select_p);
|
|
3115 }
|
|
3116
|
|
3117 static void
|
|
3118 Start (Widget w, XEvent *ev, String *params, Cardinal *num_params)
|
|
3119 {
|
|
3120 XlwMenuWidget mw = (XlwMenuWidget)w;
|
|
3121
|
|
3122 if (!mw->menu.pointer_grabbed)
|
|
3123 {
|
|
3124 mw->menu.menu_post_time = ev->xbutton.time;
|
|
3125 mw->menu.menu_bounce_time = 0;
|
|
3126 mw->menu.next_release_must_exit = True;
|
|
3127 mw->menu.last_selected_val = NULL;
|
|
3128
|
|
3129 XtCallCallbackList ((Widget)mw, mw->menu.open, NULL);
|
|
3130
|
|
3131 /* notes the absolute position of the menubar window */
|
|
3132 mw->menu.windows [0].x = ev->xmotion.x_root - ev->xmotion.x;
|
|
3133 mw->menu.windows [0].y = ev->xmotion.y_root - ev->xmotion.y;
|
|
3134
|
|
3135 XtGrabPointer ((Widget)mw, False,
|
|
3136 (ButtonMotionMask | ButtonReleaseMask | ButtonPressMask),
|
|
3137 GrabModeAsync, GrabModeAsync,
|
|
3138 None, mw->menu.cursor_shape,
|
|
3139 ((XButtonPressedEvent*)ev)->time);
|
|
3140 mw->menu.pointer_grabbed = True;
|
|
3141 }
|
|
3142
|
|
3143 /* handles the down like a move, slots are mostly compatible */
|
|
3144 handle_motion_event (mw, &ev->xmotion, True);
|
|
3145 }
|
|
3146
|
|
3147 static void
|
|
3148 Drag (Widget w, XEvent *ev, String *params, Cardinal *num_params)
|
|
3149 {
|
|
3150 XlwMenuWidget mw = (XlwMenuWidget)w;
|
|
3151 handle_motion_event (mw, &ev->xmotion, False);
|
|
3152 }
|
|
3153
|
|
3154 static void
|
|
3155 Select (Widget w, XEvent *ev, String *params, Cardinal *num_params)
|
|
3156 {
|
|
3157 XlwMenuWidget mw = (XlwMenuWidget)w;
|
|
3158 widget_value *selected_item = mw->menu.old_stack [mw->menu.old_depth - 1];
|
|
3159
|
|
3160 /* If user releases the button quickly, without selecting anything,
|
|
3161 after the initial down-click that brought the menu up,
|
|
3162 do nothing. */
|
|
3163 if ((selected_item == 0 || selected_item->call_data == 0)
|
|
3164 && (!mw->menu.next_release_must_exit
|
|
3165 || close_to_reference_time(w, mw->menu.menu_post_time, ev)))
|
|
3166 {
|
|
3167 mw->menu.next_release_must_exit = False;
|
|
3168 return;
|
|
3169 }
|
|
3170
|
|
3171 /* pop down everything */
|
|
3172 mw->menu.new_depth = 1;
|
|
3173 remap_menubar (mw);
|
|
3174
|
|
3175 /* Destroy() only gets called for popup menus. Menubar widgets aren't
|
|
3176 destroyed when their menu panes get nuked. */
|
|
3177 if (mw->menu.pointer_grabbed)
|
|
3178 {
|
|
3179 XtUngrabPointer ((Widget)w, ev->xmotion.time);
|
|
3180 mw->menu.pointer_grabbed = False;
|
|
3181 }
|
|
3182
|
|
3183 if (mw->menu.popped_up)
|
|
3184 {
|
|
3185 mw->menu.popped_up = False;
|
|
3186 XtPopdown (XtParent (mw));
|
|
3187 }
|
|
3188
|
|
3189 /* callback */
|
|
3190 XtCallCallbackList ((Widget)mw, mw->menu.select, (XtPointer)selected_item);
|
|
3191 }
|
|
3192
|
|
3193
|
|
3194 /* Special code to pop-up a menu */
|
|
3195 void
|
|
3196 xlw_pop_up_menu (XlwMenuWidget mw, XButtonPressedEvent *event)
|
|
3197 {
|
|
3198 int x = event->x_root;
|
|
3199 int y = event->y_root;
|
|
3200 int w;
|
|
3201 int h;
|
|
3202 int borderwidth = mw->menu.shadow_thickness;
|
|
3203 Screen* screen = XtScreen (mw);
|
|
3204
|
|
3205 mw->menu.menu_post_time = event->time;
|
|
3206 mw->menu.menu_bounce_time = 0;
|
|
3207 mw->menu.next_release_must_exit = True;
|
|
3208 mw->menu.last_selected_val = NULL;
|
|
3209
|
|
3210 XtCallCallbackList ((Widget)mw, mw->menu.open, NULL);
|
|
3211
|
|
3212 size_menu (mw, 0);
|
|
3213
|
|
3214 w = mw->menu.windows [0].width;
|
|
3215 h = mw->menu.windows [0].height;
|
|
3216
|
|
3217 x -= borderwidth;
|
|
3218 y -= borderwidth;
|
|
3219 if (x < borderwidth)
|
|
3220 x = borderwidth;
|
|
3221 if (x + w + 2 * borderwidth > WidthOfScreen (screen))
|
|
3222 x = WidthOfScreen (screen) - w - 2 * borderwidth;
|
|
3223 if (y < borderwidth)
|
|
3224 y = borderwidth;
|
|
3225 if (y + h + 2 * borderwidth> HeightOfScreen (screen))
|
|
3226 y = HeightOfScreen (screen) - h - 2 * borderwidth;
|
|
3227
|
|
3228 mw->menu.popped_up = True;
|
|
3229 XtConfigureWidget (XtParent (mw), x, y, w, h,
|
|
3230 XtParent (mw)->core.border_width);
|
|
3231 XtPopup (XtParent (mw), XtGrabExclusive);
|
|
3232 display_menu (mw, 0, False, NULL, NULL, NULL, NULL, NULL);
|
|
3233 if (!mw->menu.pointer_grabbed)
|
|
3234 {
|
|
3235 XtGrabPointer ((Widget)mw, False,
|
|
3236 (ButtonMotionMask | ButtonReleaseMask | ButtonPressMask),
|
|
3237 GrabModeAsync, GrabModeAsync,
|
|
3238 None, mw->menu.cursor_shape, event->time);
|
|
3239 mw->menu.pointer_grabbed = True;
|
|
3240 }
|
|
3241
|
|
3242 mw->menu.windows [0].x = x + borderwidth;
|
|
3243 mw->menu.windows [0].y = y + borderwidth;
|
|
3244
|
|
3245 handle_motion_event (mw, (XMotionEvent *) event, True);
|
|
3246 }
|
|
3247
|
|
3248 /* #### unused */
|
|
3249 #if 0
|
|
3250 /*
|
|
3251 * This is a horrible function which should not be needed.
|
|
3252 * use it to put the resize method back the way the XlwMenu
|
|
3253 * class initializer put it. Motif screws with this when
|
|
3254 * the XlwMenu class gets instantiated.
|
|
3255 */
|
|
3256 void
|
|
3257 xlw_unmunge_class_resize (Widget w)
|
|
3258 {
|
|
3259 if (w->core.widget_class->core_class.resize != XlwMenuResize)
|
|
3260 w->core.widget_class->core_class.resize = XlwMenuResize;
|
|
3261 }
|
|
3262 #endif /* 0 */
|
|
3263
|