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