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