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