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