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