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