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