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