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