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