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