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