428
|
1 /* Generic GUI code. (menubars, scrollbars, toolbars, dialogs)
|
|
2 Copyright (C) 1995 Board of Trustees, University of Illinois.
|
793
|
3 Copyright (C) 1995, 1996, 2000, 2001, 2002 Ben Wing.
|
428
|
4 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
5 Copyright (C) 1998 Free Software Foundation, Inc.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: Not in FSF. */
|
|
25
|
793
|
26 /* This file Mule-ized by Ben Wing, 3-24-02. */
|
442
|
27
|
428
|
28 #include <config.h>
|
|
29 #include "lisp.h"
|
872
|
30
|
442
|
31 #include "buffer.h"
|
428
|
32 #include "bytecode.h"
|
872
|
33 #include "elhash.h"
|
|
34 #include "gui.h"
|
|
35 #include "menubar.h"
|
428
|
36
|
442
|
37 Lisp_Object Qmenu_no_selection_hook;
|
|
38 Lisp_Object Vmenu_no_selection_hook;
|
428
|
39
|
|
40 static Lisp_Object parse_gui_item_tree_list (Lisp_Object list);
|
454
|
41 Lisp_Object find_keyword_in_vector (Lisp_Object vector, Lisp_Object keyword);
|
428
|
42
|
563
|
43 Lisp_Object Qgui_error;
|
|
44
|
428
|
45 #ifdef HAVE_POPUPS
|
|
46
|
|
47 /* count of menus/dboxes currently up */
|
|
48 int popup_up_p;
|
|
49
|
|
50 DEFUN ("popup-up-p", Fpopup_up_p, 0, 0, 0, /*
|
|
51 Return t if a popup menu or dialog box is up, nil otherwise.
|
|
52 See `popup-menu' and `popup-dialog-box'.
|
|
53 */
|
|
54 ())
|
|
55 {
|
|
56 return popup_up_p ? Qt : Qnil;
|
|
57 }
|
|
58 #endif /* HAVE_POPUPS */
|
|
59
|
|
60 int
|
867
|
61 separator_string_p (const Ibyte *s)
|
428
|
62 {
|
867
|
63 const Ibyte *p;
|
|
64 Ibyte first;
|
428
|
65
|
|
66 if (!s || s[0] == '\0')
|
|
67 return 0;
|
|
68 first = s[0];
|
|
69 if (first != '-' && first != '=')
|
|
70 return 0;
|
|
71 for (p = s; *p == first; p++)
|
|
72 ;
|
|
73
|
|
74 return (*p == '!' || *p == ':' || *p == '\0');
|
|
75 }
|
|
76
|
|
77 /* Massage DATA to find the correct function and argument. Used by
|
|
78 popup_selection_callback() and the msw code. */
|
|
79 void
|
|
80 get_gui_callback (Lisp_Object data, Lisp_Object *fn, Lisp_Object *arg)
|
|
81 {
|
442
|
82 if (EQ (data, Qquit))
|
|
83 {
|
|
84 *fn = Qeval;
|
|
85 *arg = list3 (Qsignal, list2 (Qquote, Qquit), Qnil);
|
|
86 Vquit_flag = Qt;
|
|
87 }
|
|
88 else if (SYMBOLP (data)
|
|
89 || (COMPILED_FUNCTIONP (data)
|
|
90 && XCOMPILED_FUNCTION (data)->flags.interactivep)
|
|
91 || (CONSP (data) && (EQ (XCAR (data), Qlambda))
|
|
92 && !NILP (Fassq (Qinteractive, Fcdr (Fcdr (data))))))
|
428
|
93 {
|
|
94 *fn = Qcall_interactively;
|
|
95 *arg = data;
|
|
96 }
|
|
97 else if (CONSP (data))
|
|
98 {
|
|
99 *fn = Qeval;
|
|
100 *arg = data;
|
|
101 }
|
|
102 else
|
|
103 {
|
|
104 *fn = Qeval;
|
|
105 *arg = list3 (Qsignal,
|
|
106 list2 (Qquote, Qerror),
|
771
|
107 list2 (Qquote, list2 (build_msg_string
|
428
|
108 ("illegal callback"),
|
|
109 data)));
|
|
110 }
|
|
111 }
|
|
112
|
|
113 /*
|
|
114 * Add a value VAL associated with keyword KEY into PGUI_ITEM
|
|
115 * structure. If KEY is not a keyword, or is an unknown keyword, then
|
|
116 * error is signaled.
|
|
117 */
|
454
|
118 int
|
428
|
119 gui_item_add_keyval_pair (Lisp_Object gui_item,
|
440
|
120 Lisp_Object key, Lisp_Object val,
|
578
|
121 Error_Behavior errb)
|
428
|
122 {
|
442
|
123 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);
|
454
|
124 int retval = 0;
|
428
|
125
|
|
126 if (!KEYWORDP (key))
|
563
|
127 sferror_2 ("Non-keyword in gui item", key, pgui_item->name);
|
428
|
128
|
454
|
129 if (EQ (key, Q_descriptor))
|
|
130 {
|
|
131 if (!EQ (pgui_item->name, val))
|
|
132 {
|
|
133 retval = 1;
|
|
134 pgui_item->name = val;
|
|
135 }
|
|
136 }
|
793
|
137 #define FROB(slot) \
|
454
|
138 else if (EQ (key, Q_##slot)) \
|
|
139 { \
|
793
|
140 if (!EQ (pgui_item->slot, val)) \
|
454
|
141 { \
|
|
142 retval = 1; \
|
793
|
143 pgui_item->slot = val; \
|
454
|
144 } \
|
|
145 }
|
|
146 FROB (suffix)
|
|
147 FROB (active)
|
|
148 FROB (included)
|
|
149 FROB (config)
|
|
150 FROB (filter)
|
|
151 FROB (style)
|
|
152 FROB (selected)
|
|
153 FROB (keys)
|
|
154 FROB (callback)
|
|
155 FROB (callback_ex)
|
|
156 FROB (value)
|
|
157 #undef FROB
|
440
|
158 else if (EQ (key, Q_key_sequence)) ; /* ignored for FSF compatibility */
|
428
|
159 else if (EQ (key, Q_label)) ; /* ignored for 21.0 implement in 21.2 */
|
|
160 else if (EQ (key, Q_accelerator))
|
|
161 {
|
454
|
162 if (!EQ (pgui_item->accelerator, val))
|
|
163 {
|
|
164 retval = 1;
|
|
165 if (SYMBOLP (val) || CHARP (val))
|
|
166 pgui_item->accelerator = val;
|
|
167 else if (ERRB_EQ (errb, ERROR_ME))
|
563
|
168 invalid_argument ("Bad keyboard accelerator", val);
|
454
|
169 }
|
428
|
170 }
|
|
171 else if (ERRB_EQ (errb, ERROR_ME))
|
793
|
172 invalid_argument_2 ("Unknown keyword in gui item", key, pgui_item->name);
|
454
|
173 return retval;
|
428
|
174 }
|
|
175
|
|
176 void
|
|
177 gui_item_init (Lisp_Object gui_item)
|
|
178 {
|
440
|
179 Lisp_Gui_Item *lp = XGUI_ITEM (gui_item);
|
428
|
180
|
|
181 lp->name = Qnil;
|
|
182 lp->callback = Qnil;
|
442
|
183 lp->callback_ex = Qnil;
|
428
|
184 lp->suffix = Qnil;
|
|
185 lp->active = Qt;
|
|
186 lp->included = Qt;
|
|
187 lp->config = Qnil;
|
|
188 lp->filter = Qnil;
|
|
189 lp->style = Qnil;
|
|
190 lp->selected = Qnil;
|
|
191 lp->keys = Qnil;
|
|
192 lp->accelerator = Qnil;
|
442
|
193 lp->value = Qnil;
|
428
|
194 }
|
|
195
|
|
196 Lisp_Object
|
|
197 allocate_gui_item (void)
|
|
198 {
|
440
|
199 Lisp_Gui_Item *lp = alloc_lcrecord_type (Lisp_Gui_Item, &lrecord_gui_item);
|
428
|
200 Lisp_Object val;
|
|
201
|
793
|
202 val = wrap_gui_item (lp);
|
428
|
203
|
|
204 gui_item_init (val);
|
|
205
|
|
206 return val;
|
|
207 }
|
|
208
|
|
209 /*
|
|
210 * ITEM is a lisp vector, describing a menu item or a button. The
|
|
211 * function extracts the description of the item into the PGUI_ITEM
|
|
212 * structure.
|
|
213 */
|
|
214 static Lisp_Object
|
|
215 make_gui_item_from_keywords_internal (Lisp_Object item,
|
578
|
216 Error_Behavior errb)
|
428
|
217 {
|
|
218 int length, plist_p, start;
|
|
219 Lisp_Object *contents;
|
|
220 Lisp_Object gui_item = allocate_gui_item ();
|
442
|
221 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);
|
428
|
222
|
|
223 CHECK_VECTOR (item);
|
|
224 length = XVECTOR_LENGTH (item);
|
|
225 contents = XVECTOR_DATA (item);
|
|
226
|
|
227 if (length < 1)
|
563
|
228 sferror ("GUI item descriptors must be at least 1 elts long", item);
|
428
|
229
|
|
230 /* length 1: [ "name" ]
|
|
231 length 2: [ "name" callback ]
|
|
232 length 3: [ "name" callback active-p ]
|
|
233 or [ "name" keyword value ]
|
|
234 length 4: [ "name" callback active-p suffix ]
|
|
235 or [ "name" callback keyword value ]
|
|
236 length 5+: [ "name" callback [ keyword value ]+ ]
|
|
237 or [ "name" [ keyword value ]+ ]
|
|
238 */
|
|
239 plist_p = (length > 2 && (KEYWORDP (contents [1])
|
|
240 || KEYWORDP (contents [2])));
|
|
241
|
|
242 pgui_item->name = contents [0];
|
|
243 if (length > 1 && !KEYWORDP (contents [1]))
|
|
244 {
|
|
245 pgui_item->callback = contents [1];
|
|
246 start = 2;
|
|
247 }
|
440
|
248 else
|
428
|
249 start =1;
|
|
250
|
|
251 if (!plist_p && length > 2)
|
|
252 /* the old way */
|
|
253 {
|
|
254 pgui_item->active = contents [2];
|
|
255 if (length == 4)
|
|
256 pgui_item->suffix = contents [3];
|
|
257 }
|
|
258 else
|
|
259 /* the new way */
|
|
260 {
|
|
261 int i;
|
|
262 if ((length - start) & 1)
|
563
|
263 sferror (
|
428
|
264 "GUI item descriptor has an odd number of keywords and values",
|
793
|
265 item);
|
428
|
266
|
|
267 for (i = start; i < length;)
|
|
268 {
|
|
269 Lisp_Object key = contents [i++];
|
|
270 Lisp_Object val = contents [i++];
|
|
271 gui_item_add_keyval_pair (gui_item, key, val, errb);
|
|
272 }
|
|
273 }
|
|
274 return gui_item;
|
|
275 }
|
|
276
|
454
|
277 /* This will only work with descriptors in the new format. */
|
|
278 Lisp_Object
|
|
279 widget_gui_parse_item_keywords (Lisp_Object item)
|
|
280 {
|
|
281 int i, length;
|
|
282 Lisp_Object *contents;
|
|
283 Lisp_Object gui_item = allocate_gui_item ();
|
|
284 Lisp_Object desc = find_keyword_in_vector (item, Q_descriptor);
|
|
285
|
|
286 CHECK_VECTOR (item);
|
|
287 length = XVECTOR_LENGTH (item);
|
|
288 contents = XVECTOR_DATA (item);
|
|
289
|
|
290 if (!NILP (desc) && !STRINGP (desc) && !VECTORP (desc))
|
563
|
291 sferror ("Invalid GUI item descriptor", item);
|
454
|
292
|
|
293 if (length & 1)
|
|
294 {
|
|
295 if (!SYMBOLP (contents [0]))
|
563
|
296 sferror ("Invalid GUI item descriptor", item);
|
454
|
297 contents++; /* Ignore the leading symbol. */
|
|
298 length--;
|
|
299 }
|
|
300
|
|
301 for (i = 0; i < length;)
|
|
302 {
|
|
303 Lisp_Object key = contents [i++];
|
|
304 Lisp_Object val = contents [i++];
|
|
305 gui_item_add_keyval_pair (gui_item, key, val, ERROR_ME_NOT);
|
|
306 }
|
|
307
|
|
308 return gui_item;
|
|
309 }
|
|
310
|
|
311 /* Update a gui item from a partial descriptor. */
|
|
312 int
|
|
313 update_gui_item_keywords (Lisp_Object gui_item, Lisp_Object item)
|
|
314 {
|
|
315 int i, length, retval = 0;
|
|
316 Lisp_Object *contents;
|
|
317
|
|
318 CHECK_VECTOR (item);
|
|
319 length = XVECTOR_LENGTH (item);
|
|
320 contents = XVECTOR_DATA (item);
|
|
321
|
|
322 if (length & 1)
|
|
323 {
|
|
324 if (!SYMBOLP (contents [0]))
|
563
|
325 sferror ("Invalid GUI item descriptor", item);
|
454
|
326 contents++; /* Ignore the leading symbol. */
|
|
327 length--;
|
|
328 }
|
|
329
|
|
330 for (i = 0; i < length;)
|
|
331 {
|
|
332 Lisp_Object key = contents [i++];
|
|
333 Lisp_Object val = contents [i++];
|
793
|
334 if (gui_item_add_keyval_pair (gui_item, key, val, ERROR_ME_DEBUG_WARN))
|
454
|
335 retval = 1;
|
|
336 }
|
|
337 return retval;
|
|
338 }
|
|
339
|
428
|
340 Lisp_Object
|
|
341 gui_parse_item_keywords (Lisp_Object item)
|
|
342 {
|
|
343 return make_gui_item_from_keywords_internal (item, ERROR_ME);
|
|
344 }
|
|
345
|
|
346 Lisp_Object
|
|
347 gui_parse_item_keywords_no_errors (Lisp_Object item)
|
|
348 {
|
793
|
349 return make_gui_item_from_keywords_internal (item, ERROR_ME_DEBUG_WARN);
|
428
|
350 }
|
|
351
|
|
352 /* convert a gui item into plist properties */
|
|
353 void
|
|
354 gui_add_item_keywords_to_plist (Lisp_Object plist, Lisp_Object gui_item)
|
|
355 {
|
442
|
356 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);
|
440
|
357
|
428
|
358 if (!NILP (pgui_item->callback))
|
|
359 Fplist_put (plist, Q_callback, pgui_item->callback);
|
442
|
360 if (!NILP (pgui_item->callback_ex))
|
|
361 Fplist_put (plist, Q_callback_ex, pgui_item->callback_ex);
|
428
|
362 if (!NILP (pgui_item->suffix))
|
|
363 Fplist_put (plist, Q_suffix, pgui_item->suffix);
|
|
364 if (!NILP (pgui_item->active))
|
|
365 Fplist_put (plist, Q_active, pgui_item->active);
|
|
366 if (!NILP (pgui_item->included))
|
|
367 Fplist_put (plist, Q_included, pgui_item->included);
|
|
368 if (!NILP (pgui_item->config))
|
|
369 Fplist_put (plist, Q_config, pgui_item->config);
|
|
370 if (!NILP (pgui_item->filter))
|
|
371 Fplist_put (plist, Q_filter, pgui_item->filter);
|
|
372 if (!NILP (pgui_item->style))
|
|
373 Fplist_put (plist, Q_style, pgui_item->style);
|
|
374 if (!NILP (pgui_item->selected))
|
|
375 Fplist_put (plist, Q_selected, pgui_item->selected);
|
|
376 if (!NILP (pgui_item->keys))
|
|
377 Fplist_put (plist, Q_keys, pgui_item->keys);
|
|
378 if (!NILP (pgui_item->accelerator))
|
|
379 Fplist_put (plist, Q_accelerator, pgui_item->accelerator);
|
442
|
380 if (!NILP (pgui_item->value))
|
|
381 Fplist_put (plist, Q_value, pgui_item->value);
|
428
|
382 }
|
|
383
|
|
384 /*
|
|
385 * Decide whether a GUI item is active by evaluating its :active form
|
|
386 * if any
|
|
387 */
|
|
388 int
|
|
389 gui_item_active_p (Lisp_Object gui_item)
|
|
390 {
|
|
391 /* This function can call lisp */
|
|
392
|
|
393 /* Shortcut to avoid evaluating Qt each time */
|
|
394 return (EQ (XGUI_ITEM (gui_item)->active, Qt)
|
|
395 || !NILP (Feval (XGUI_ITEM (gui_item)->active)));
|
|
396 }
|
|
397
|
|
398 /* set menu accelerator key to first underlined character in menu name */
|
|
399 Lisp_Object
|
|
400 gui_item_accelerator (Lisp_Object gui_item)
|
|
401 {
|
442
|
402 Lisp_Gui_Item *pgui = XGUI_ITEM (gui_item);
|
440
|
403
|
428
|
404 if (!NILP (pgui->accelerator))
|
|
405 return pgui->accelerator;
|
|
406
|
|
407 else
|
442
|
408 return gui_name_accelerator (pgui->name);
|
428
|
409 }
|
|
410
|
|
411 Lisp_Object
|
|
412 gui_name_accelerator (Lisp_Object nm)
|
|
413 {
|
867
|
414 Ibyte *name = XSTRING_DATA (nm);
|
428
|
415
|
442
|
416 while (*name)
|
|
417 {
|
|
418 if (*name == '%')
|
428
|
419 {
|
442
|
420 ++name;
|
|
421 if (!(*name))
|
|
422 return Qnil;
|
|
423 if (*name == '_' && *(name + 1))
|
|
424 {
|
867
|
425 Ichar accelerator = itext_ichar (name + 1);
|
771
|
426 return make_char (DOWNCASE (0, accelerator));
|
442
|
427 }
|
428
|
428 }
|
867
|
429 INC_IBYTEPTR (name);
|
428
|
430 }
|
867
|
431 return make_char (DOWNCASE (0, itext_ichar (XSTRING_DATA (nm))));
|
428
|
432 }
|
|
433
|
|
434 /*
|
|
435 * Decide whether a GUI item is selected by evaluating its :selected form
|
|
436 * if any
|
|
437 */
|
|
438 int
|
|
439 gui_item_selected_p (Lisp_Object gui_item)
|
|
440 {
|
|
441 /* This function can call lisp */
|
|
442
|
|
443 /* Shortcut to avoid evaluating Qt each time */
|
|
444 return (EQ (XGUI_ITEM (gui_item)->selected, Qt)
|
|
445 || !NILP (Feval (XGUI_ITEM (gui_item)->selected)));
|
|
446 }
|
|
447
|
442
|
448 Lisp_Object
|
|
449 gui_item_list_find_selected (Lisp_Object gui_item_list)
|
|
450 {
|
|
451 /* This function can GC. */
|
|
452 Lisp_Object rest;
|
|
453 LIST_LOOP (rest, gui_item_list)
|
|
454 {
|
|
455 if (gui_item_selected_p (XCAR (rest)))
|
|
456 return XCAR (rest);
|
|
457 }
|
|
458 return XCAR (gui_item_list);
|
|
459 }
|
|
460
|
428
|
461 /*
|
|
462 * Decide whether a GUI item is included by evaluating its :included
|
|
463 * form if given, and testing its :config form against supplied CONFLIST
|
|
464 * configuration variable
|
|
465 */
|
|
466 int
|
|
467 gui_item_included_p (Lisp_Object gui_item, Lisp_Object conflist)
|
|
468 {
|
|
469 /* This function can call lisp */
|
442
|
470 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);
|
428
|
471
|
|
472 /* Evaluate :included first. Shortcut to avoid evaluating Qt each time */
|
|
473 if (!EQ (pgui_item->included, Qt)
|
|
474 && NILP (Feval (pgui_item->included)))
|
|
475 return 0;
|
|
476
|
|
477 /* Do :config if conflist is given */
|
|
478 if (!NILP (conflist) && !NILP (pgui_item->config)
|
|
479 && NILP (Fmemq (pgui_item->config, conflist)))
|
|
480 return 0;
|
|
481
|
|
482 return 1;
|
|
483 }
|
|
484
|
|
485 /*
|
771
|
486 * Format "left flush" display portion of an item.
|
428
|
487 */
|
771
|
488 Lisp_Object
|
|
489 gui_item_display_flush_left (Lisp_Object gui_item)
|
428
|
490 {
|
|
491 /* This function can call lisp */
|
442
|
492 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);
|
771
|
493 Lisp_Object retval;
|
428
|
494
|
|
495 CHECK_STRING (pgui_item->name);
|
771
|
496 retval = pgui_item->name;
|
428
|
497
|
|
498 if (!NILP (pgui_item->suffix))
|
|
499 {
|
|
500 Lisp_Object suffix = pgui_item->suffix;
|
|
501 /* Shortcut to avoid evaluating suffix each time */
|
|
502 if (!STRINGP (suffix))
|
|
503 {
|
|
504 suffix = Feval (suffix);
|
|
505 CHECK_STRING (suffix);
|
|
506 }
|
|
507
|
771
|
508 retval = concat3 (pgui_item->name, build_string (" "), suffix);
|
428
|
509 }
|
771
|
510
|
|
511 return retval;
|
428
|
512 }
|
|
513
|
|
514 /*
|
771
|
515 * Format "right flush" display portion of an item into BUF.
|
428
|
516 */
|
771
|
517 Lisp_Object
|
|
518 gui_item_display_flush_right (Lisp_Object gui_item)
|
428
|
519 {
|
442
|
520 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);
|
428
|
521
|
|
522 #ifdef HAVE_MENUBARS
|
|
523 /* Have keys? */
|
|
524 if (!menubar_show_keybindings)
|
771
|
525 return Qnil;
|
428
|
526 #endif
|
|
527
|
|
528 /* Try :keys first */
|
|
529 if (!NILP (pgui_item->keys))
|
|
530 {
|
|
531 CHECK_STRING (pgui_item->keys);
|
771
|
532 return pgui_item->keys;
|
428
|
533 }
|
|
534
|
|
535 /* See if we can derive keys out of callback symbol */
|
|
536 if (SYMBOLP (pgui_item->callback))
|
|
537 {
|
793
|
538 DECLARE_EISTRING_MALLOC (buf);
|
|
539 Lisp_Object str;
|
|
540
|
|
541 where_is_to_char (pgui_item->callback, buf);
|
|
542 str = eimake_string (buf);
|
|
543 eifree (buf);
|
|
544 return str;
|
428
|
545 }
|
|
546
|
|
547 /* No keys - no right flush display */
|
771
|
548 return Qnil;
|
428
|
549 }
|
|
550
|
1204
|
551 static const struct memory_description gui_item_description [] = {
|
934
|
552 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, name) },
|
|
553 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, callback) },
|
|
554 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, callback_ex) },
|
|
555 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, suffix) },
|
|
556 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, active) },
|
|
557 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, included) },
|
|
558 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, config) },
|
|
559 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, filter) },
|
|
560 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, style) },
|
|
561 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, selected) },
|
|
562 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, keys) },
|
|
563 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, accelerator) },
|
|
564 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, value) },
|
|
565 { XD_END }
|
|
566 };
|
|
567
|
428
|
568 static Lisp_Object
|
|
569 mark_gui_item (Lisp_Object obj)
|
|
570 {
|
440
|
571 Lisp_Gui_Item *p = XGUI_ITEM (obj);
|
428
|
572
|
|
573 mark_object (p->name);
|
|
574 mark_object (p->callback);
|
442
|
575 mark_object (p->callback_ex);
|
428
|
576 mark_object (p->config);
|
|
577 mark_object (p->suffix);
|
|
578 mark_object (p->active);
|
|
579 mark_object (p->included);
|
|
580 mark_object (p->config);
|
|
581 mark_object (p->filter);
|
|
582 mark_object (p->style);
|
|
583 mark_object (p->selected);
|
|
584 mark_object (p->keys);
|
|
585 mark_object (p->accelerator);
|
442
|
586 mark_object (p->value);
|
428
|
587
|
|
588 return Qnil;
|
|
589 }
|
|
590
|
665
|
591 static Hashcode
|
428
|
592 gui_item_hash (Lisp_Object obj, int depth)
|
|
593 {
|
440
|
594 Lisp_Gui_Item *p = XGUI_ITEM (obj);
|
428
|
595
|
442
|
596 return HASH2 (HASH6 (internal_hash (p->name, depth + 1),
|
428
|
597 internal_hash (p->callback, depth + 1),
|
442
|
598 internal_hash (p->callback_ex, depth + 1),
|
428
|
599 internal_hash (p->suffix, depth + 1),
|
|
600 internal_hash (p->active, depth + 1),
|
|
601 internal_hash (p->included, depth + 1)),
|
442
|
602 HASH6 (internal_hash (p->config, depth + 1),
|
428
|
603 internal_hash (p->filter, depth + 1),
|
|
604 internal_hash (p->style, depth + 1),
|
|
605 internal_hash (p->selected, depth + 1),
|
442
|
606 internal_hash (p->keys, depth + 1),
|
|
607 internal_hash (p->value, depth + 1)));
|
428
|
608 }
|
|
609
|
|
610 int
|
|
611 gui_item_id_hash (Lisp_Object hashtable, Lisp_Object gitem, int slot)
|
|
612 {
|
|
613 int hashid = gui_item_hash (gitem, 0);
|
|
614 int id = GUI_ITEM_ID_BITS (hashid, slot);
|
853
|
615 while (!UNBOUNDP (Fgethash (make_int (id), hashtable, Qunbound)))
|
428
|
616 {
|
|
617 id = GUI_ITEM_ID_BITS (id + 1, slot);
|
|
618 }
|
|
619 return id;
|
|
620 }
|
|
621
|
442
|
622 int
|
|
623 gui_item_equal_sans_selected (Lisp_Object obj1, Lisp_Object obj2, int depth)
|
428
|
624 {
|
440
|
625 Lisp_Gui_Item *p1 = XGUI_ITEM (obj1);
|
|
626 Lisp_Gui_Item *p2 = XGUI_ITEM (obj2);
|
428
|
627
|
|
628 if (!(internal_equal (p1->name, p2->name, depth + 1)
|
|
629 &&
|
|
630 internal_equal (p1->callback, p2->callback, depth + 1)
|
|
631 &&
|
442
|
632 internal_equal (p1->callback_ex, p2->callback_ex, depth + 1)
|
|
633 &&
|
428
|
634 EQ (p1->suffix, p2->suffix)
|
|
635 &&
|
|
636 EQ (p1->active, p2->active)
|
|
637 &&
|
|
638 EQ (p1->included, p2->included)
|
|
639 &&
|
|
640 EQ (p1->config, p2->config)
|
|
641 &&
|
|
642 EQ (p1->filter, p2->filter)
|
|
643 &&
|
|
644 EQ (p1->style, p2->style)
|
|
645 &&
|
|
646 EQ (p1->accelerator, p2->accelerator)
|
|
647 &&
|
442
|
648 EQ (p1->keys, p2->keys)
|
|
649 &&
|
|
650 EQ (p1->value, p2->value)))
|
|
651 return 0;
|
|
652 return 1;
|
|
653 }
|
|
654
|
|
655 static int
|
|
656 gui_item_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
|
|
657 {
|
|
658 Lisp_Gui_Item *p1 = XGUI_ITEM (obj1);
|
|
659 Lisp_Gui_Item *p2 = XGUI_ITEM (obj2);
|
|
660
|
|
661 if (!(gui_item_equal_sans_selected (obj1, obj2, depth)
|
|
662 &&
|
|
663 EQ (p1->selected, p2->selected)))
|
428
|
664 return 0;
|
|
665 return 1;
|
|
666 }
|
|
667
|
|
668 static void
|
|
669 print_gui_item (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
670 {
|
440
|
671 Lisp_Gui_Item *g = XGUI_ITEM (obj);
|
428
|
672
|
|
673 if (print_readably)
|
563
|
674 printing_unreadable_object ("#<gui-item 0x%x>", g->header.uid);
|
428
|
675
|
793
|
676 write_fmt_string (printcharfun, "#<gui-item 0x%x>", g->header.uid);
|
428
|
677 }
|
|
678
|
454
|
679 Lisp_Object
|
442
|
680 copy_gui_item (Lisp_Object gui_item)
|
|
681 {
|
|
682 Lisp_Object ret = allocate_gui_item ();
|
|
683 Lisp_Gui_Item *lp, *g = XGUI_ITEM (gui_item);
|
|
684
|
|
685 lp = XGUI_ITEM (ret);
|
|
686 lp->name = g->name;
|
|
687 lp->callback = g->callback;
|
|
688 lp->callback_ex = g->callback_ex;
|
|
689 lp->suffix = g->suffix;
|
|
690 lp->active = g->active;
|
|
691 lp->included = g->included;
|
|
692 lp->config = g->config;
|
|
693 lp->filter = g->filter;
|
|
694 lp->style = g->style;
|
|
695 lp->selected = g->selected;
|
|
696 lp->keys = g->keys;
|
|
697 lp->accelerator = g->accelerator;
|
|
698 lp->value = g->value;
|
|
699
|
|
700 return ret;
|
|
701 }
|
|
702
|
|
703 Lisp_Object
|
|
704 copy_gui_item_tree (Lisp_Object arg)
|
|
705 {
|
|
706 if (CONSP (arg))
|
|
707 {
|
|
708 Lisp_Object rest = arg = Fcopy_sequence (arg);
|
|
709 while (CONSP (rest))
|
|
710 {
|
|
711 XCAR (rest) = copy_gui_item_tree (XCAR (rest));
|
|
712 rest = XCDR (rest);
|
|
713 }
|
|
714 return arg;
|
|
715 }
|
|
716 else if (GUI_ITEMP (arg))
|
|
717 return copy_gui_item (arg);
|
|
718 else
|
|
719 return arg;
|
|
720 }
|
|
721
|
428
|
722 /* parse a glyph descriptor into a tree of gui items.
|
|
723
|
|
724 The gui_item slot of an image instance can be a single item or an
|
|
725 arbitrarily nested hierarchy of item lists. */
|
|
726
|
442
|
727 static Lisp_Object
|
|
728 parse_gui_item_tree_item (Lisp_Object entry)
|
428
|
729 {
|
|
730 Lisp_Object ret = entry;
|
442
|
731 struct gcpro gcpro1;
|
|
732
|
|
733 GCPRO1 (ret);
|
|
734
|
428
|
735 if (VECTORP (entry))
|
|
736 {
|
442
|
737 ret = gui_parse_item_keywords_no_errors (entry);
|
428
|
738 }
|
|
739 else if (STRINGP (entry))
|
|
740 {
|
|
741 CHECK_STRING (entry);
|
|
742 }
|
|
743 else
|
563
|
744 sferror ("item must be a vector or a string", entry);
|
428
|
745
|
442
|
746 RETURN_UNGCPRO (ret);
|
428
|
747 }
|
|
748
|
442
|
749 Lisp_Object
|
|
750 parse_gui_item_tree_children (Lisp_Object list)
|
428
|
751 {
|
442
|
752 Lisp_Object rest, ret = Qnil, sub = Qnil;
|
|
753 struct gcpro gcpro1, gcpro2;
|
|
754
|
|
755 GCPRO2 (ret, sub);
|
428
|
756 CHECK_CONS (list);
|
|
757 /* recursively add items to the tree view */
|
|
758 LIST_LOOP (rest, list)
|
|
759 {
|
|
760 if (CONSP (XCAR (rest)))
|
|
761 sub = parse_gui_item_tree_list (XCAR (rest));
|
|
762 else
|
|
763 sub = parse_gui_item_tree_item (XCAR (rest));
|
440
|
764
|
428
|
765 ret = Fcons (sub, ret);
|
|
766 }
|
|
767 /* make the order the same as the items we have parsed */
|
442
|
768 RETURN_UNGCPRO (Fnreverse (ret));
|
428
|
769 }
|
|
770
|
442
|
771 static Lisp_Object
|
|
772 parse_gui_item_tree_list (Lisp_Object list)
|
428
|
773 {
|
|
774 Lisp_Object ret;
|
442
|
775 struct gcpro gcpro1;
|
428
|
776 CHECK_CONS (list);
|
|
777 /* first one can never be a list */
|
|
778 ret = parse_gui_item_tree_item (XCAR (list));
|
442
|
779 GCPRO1 (ret);
|
|
780 ret = Fcons (ret, parse_gui_item_tree_children (XCDR (list)));
|
|
781 RETURN_UNGCPRO (ret);
|
|
782 }
|
|
783
|
|
784 static void
|
793
|
785 finalize_gui_item (void *header, int for_disksave)
|
442
|
786 {
|
428
|
787 }
|
|
788
|
934
|
789 DEFINE_LRECORD_IMPLEMENTATION ("gui-item", gui_item,
|
|
790 0, /*dumpable-flag*/
|
|
791 mark_gui_item, print_gui_item,
|
|
792 finalize_gui_item, gui_item_equal,
|
|
793 gui_item_hash,
|
|
794 gui_item_description,
|
|
795 Lisp_Gui_Item);
|
563
|
796
|
|
797 DOESNT_RETURN
|
793
|
798 gui_error (const Char_ASCII *reason, Lisp_Object frob)
|
563
|
799 {
|
|
800 signal_error (Qgui_error, reason, frob);
|
|
801 }
|
|
802
|
569
|
803 DOESNT_RETURN
|
793
|
804 gui_error_2 (const Char_ASCII *reason, Lisp_Object frob0, Lisp_Object frob1)
|
569
|
805 {
|
|
806 signal_error_2 (Qgui_error, reason, frob0, frob1);
|
|
807 }
|
|
808
|
428
|
809 void
|
|
810 syms_of_gui (void)
|
|
811 {
|
442
|
812 INIT_LRECORD_IMPLEMENTATION (gui_item);
|
428
|
813
|
442
|
814 DEFSYMBOL (Qmenu_no_selection_hook);
|
428
|
815
|
563
|
816 DEFERROR_STANDARD (Qgui_error, Qio_error);
|
|
817
|
428
|
818 #ifdef HAVE_POPUPS
|
|
819 DEFSUBR (Fpopup_up_p);
|
|
820 #endif
|
|
821 }
|
|
822
|
|
823 void
|
|
824 vars_of_gui (void)
|
|
825 {
|
442
|
826 DEFVAR_LISP ("menu-no-selection-hook", &Vmenu_no_selection_hook /*
|
|
827 Function or functions to call when a menu or dialog box is dismissed
|
|
828 without a selection having been made.
|
|
829 */ );
|
|
830 Vmenu_no_selection_hook = Qnil;
|
428
|
831 }
|