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