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