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