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