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