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