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