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