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