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