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 {
|
440
|
200 Lisp_Gui_Item *lp = alloc_lcrecord_type (Lisp_Gui_Item, &lrecord_gui_item);
|
428
|
201 Lisp_Object val;
|
|
202
|
793
|
203 val = wrap_gui_item (lp);
|
428
|
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",
|
793
|
266 item);
|
428
|
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++];
|
793
|
335 if (gui_item_add_keyval_pair (gui_item, key, val, ERROR_ME_DEBUG_WARN))
|
454
|
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 {
|
793
|
350 return make_gui_item_from_keywords_internal (item, ERROR_ME_DEBUG_WARN);
|
428
|
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
|
1318
|
385 static int
|
|
386 gui_item_value (Lisp_Object form, int in_redisplay)
|
|
387 {
|
|
388 /* This function can call Lisp. */
|
|
389
|
|
390 #ifndef ERROR_CHECK_DISPLAY
|
|
391 /* Shortcut to avoid evaluating Qt/Qnil each time; but don't do it when
|
|
392 error-checking so we catch unprotected eval within redisplay quicker */
|
|
393 if (NILP (form))
|
|
394 return 0;
|
|
395 if (EQ (form, Qt))
|
|
396 return 1;
|
|
397 #endif
|
|
398 if (in_redisplay)
|
|
399 return !NILP (eval_within_redisplay (form));
|
|
400 else
|
|
401 return !NILP (Feval (form));
|
|
402 }
|
|
403
|
428
|
404 /*
|
|
405 * Decide whether a GUI item is active by evaluating its :active form
|
|
406 * if any
|
|
407 */
|
|
408 int
|
1318
|
409 gui_item_active_p (Lisp_Object gui_item, int in_redisplay)
|
428
|
410 {
|
1318
|
411 return gui_item_value (XGUI_ITEM (gui_item)->active, in_redisplay);
|
428
|
412 }
|
|
413
|
|
414 /* set menu accelerator key to first underlined character in menu name */
|
|
415 Lisp_Object
|
|
416 gui_item_accelerator (Lisp_Object gui_item)
|
|
417 {
|
442
|
418 Lisp_Gui_Item *pgui = XGUI_ITEM (gui_item);
|
440
|
419
|
428
|
420 if (!NILP (pgui->accelerator))
|
|
421 return pgui->accelerator;
|
|
422
|
|
423 else
|
442
|
424 return gui_name_accelerator (pgui->name);
|
428
|
425 }
|
|
426
|
|
427 Lisp_Object
|
|
428 gui_name_accelerator (Lisp_Object nm)
|
|
429 {
|
867
|
430 Ibyte *name = XSTRING_DATA (nm);
|
428
|
431
|
442
|
432 while (*name)
|
|
433 {
|
|
434 if (*name == '%')
|
428
|
435 {
|
442
|
436 ++name;
|
|
437 if (!(*name))
|
|
438 return Qnil;
|
|
439 if (*name == '_' && *(name + 1))
|
|
440 {
|
867
|
441 Ichar accelerator = itext_ichar (name + 1);
|
771
|
442 return make_char (DOWNCASE (0, accelerator));
|
442
|
443 }
|
428
|
444 }
|
867
|
445 INC_IBYTEPTR (name);
|
428
|
446 }
|
867
|
447 return make_char (DOWNCASE (0, itext_ichar (XSTRING_DATA (nm))));
|
428
|
448 }
|
|
449
|
|
450 /*
|
|
451 * Decide whether a GUI item is selected by evaluating its :selected form
|
|
452 * if any
|
|
453 */
|
|
454 int
|
1318
|
455 gui_item_selected_p (Lisp_Object gui_item, int in_redisplay)
|
428
|
456 {
|
1318
|
457 return gui_item_value (XGUI_ITEM (gui_item)->selected, in_redisplay);
|
428
|
458 }
|
|
459
|
442
|
460 Lisp_Object
|
|
461 gui_item_list_find_selected (Lisp_Object gui_item_list)
|
|
462 {
|
1318
|
463 /* This function can call Lisp but cannot GC because it is called within
|
|
464 redisplay, and redisplay disables GC. */
|
442
|
465 Lisp_Object rest;
|
|
466 LIST_LOOP (rest, gui_item_list)
|
|
467 {
|
1318
|
468 if (gui_item_selected_p (XCAR (rest), 1))
|
442
|
469 return XCAR (rest);
|
|
470 }
|
|
471 return XCAR (gui_item_list);
|
|
472 }
|
|
473
|
428
|
474 /*
|
|
475 * Decide whether a GUI item is included by evaluating its :included
|
|
476 * form if given, and testing its :config form against supplied CONFLIST
|
|
477 * configuration variable
|
|
478 */
|
|
479 int
|
|
480 gui_item_included_p (Lisp_Object gui_item, Lisp_Object conflist)
|
|
481 {
|
|
482 /* This function can call lisp */
|
442
|
483 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);
|
428
|
484
|
|
485 /* Evaluate :included first. Shortcut to avoid evaluating Qt each time */
|
1318
|
486 if (!gui_item_value (pgui_item->included, 0))
|
428
|
487 return 0;
|
|
488
|
|
489 /* Do :config if conflist is given */
|
|
490 if (!NILP (conflist) && !NILP (pgui_item->config)
|
|
491 && NILP (Fmemq (pgui_item->config, conflist)))
|
|
492 return 0;
|
|
493
|
|
494 return 1;
|
|
495 }
|
|
496
|
|
497 /*
|
771
|
498 * Format "left flush" display portion of an item.
|
428
|
499 */
|
771
|
500 Lisp_Object
|
|
501 gui_item_display_flush_left (Lisp_Object gui_item)
|
428
|
502 {
|
|
503 /* This function can call lisp */
|
442
|
504 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);
|
771
|
505 Lisp_Object retval;
|
428
|
506
|
|
507 CHECK_STRING (pgui_item->name);
|
771
|
508 retval = pgui_item->name;
|
428
|
509
|
|
510 if (!NILP (pgui_item->suffix))
|
|
511 {
|
|
512 Lisp_Object suffix = pgui_item->suffix;
|
|
513 /* Shortcut to avoid evaluating suffix each time */
|
|
514 if (!STRINGP (suffix))
|
|
515 {
|
|
516 suffix = Feval (suffix);
|
|
517 CHECK_STRING (suffix);
|
|
518 }
|
|
519
|
771
|
520 retval = concat3 (pgui_item->name, build_string (" "), suffix);
|
428
|
521 }
|
771
|
522
|
|
523 return retval;
|
428
|
524 }
|
|
525
|
|
526 /*
|
771
|
527 * Format "right flush" display portion of an item into BUF.
|
428
|
528 */
|
771
|
529 Lisp_Object
|
|
530 gui_item_display_flush_right (Lisp_Object gui_item)
|
428
|
531 {
|
442
|
532 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);
|
428
|
533
|
|
534 #ifdef HAVE_MENUBARS
|
|
535 /* Have keys? */
|
|
536 if (!menubar_show_keybindings)
|
771
|
537 return Qnil;
|
428
|
538 #endif
|
|
539
|
|
540 /* Try :keys first */
|
|
541 if (!NILP (pgui_item->keys))
|
|
542 {
|
|
543 CHECK_STRING (pgui_item->keys);
|
771
|
544 return pgui_item->keys;
|
428
|
545 }
|
|
546
|
|
547 /* See if we can derive keys out of callback symbol */
|
|
548 if (SYMBOLP (pgui_item->callback))
|
|
549 {
|
793
|
550 DECLARE_EISTRING_MALLOC (buf);
|
|
551 Lisp_Object str;
|
|
552
|
|
553 where_is_to_char (pgui_item->callback, buf);
|
|
554 str = eimake_string (buf);
|
|
555 eifree (buf);
|
|
556 return str;
|
428
|
557 }
|
|
558
|
|
559 /* No keys - no right flush display */
|
771
|
560 return Qnil;
|
428
|
561 }
|
|
562
|
1204
|
563 static const struct memory_description gui_item_description [] = {
|
934
|
564 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, name) },
|
|
565 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, callback) },
|
|
566 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, callback_ex) },
|
|
567 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, suffix) },
|
|
568 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, active) },
|
|
569 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, included) },
|
|
570 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, config) },
|
|
571 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, filter) },
|
|
572 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, style) },
|
|
573 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, selected) },
|
|
574 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, keys) },
|
|
575 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, accelerator) },
|
|
576 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, value) },
|
|
577 { XD_END }
|
|
578 };
|
|
579
|
428
|
580 static Lisp_Object
|
|
581 mark_gui_item (Lisp_Object obj)
|
|
582 {
|
440
|
583 Lisp_Gui_Item *p = XGUI_ITEM (obj);
|
428
|
584
|
|
585 mark_object (p->name);
|
|
586 mark_object (p->callback);
|
442
|
587 mark_object (p->callback_ex);
|
428
|
588 mark_object (p->config);
|
|
589 mark_object (p->suffix);
|
|
590 mark_object (p->active);
|
|
591 mark_object (p->included);
|
|
592 mark_object (p->config);
|
|
593 mark_object (p->filter);
|
|
594 mark_object (p->style);
|
|
595 mark_object (p->selected);
|
|
596 mark_object (p->keys);
|
|
597 mark_object (p->accelerator);
|
442
|
598 mark_object (p->value);
|
428
|
599
|
|
600 return Qnil;
|
|
601 }
|
|
602
|
665
|
603 static Hashcode
|
428
|
604 gui_item_hash (Lisp_Object obj, int depth)
|
|
605 {
|
440
|
606 Lisp_Gui_Item *p = XGUI_ITEM (obj);
|
428
|
607
|
442
|
608 return HASH2 (HASH6 (internal_hash (p->name, depth + 1),
|
428
|
609 internal_hash (p->callback, depth + 1),
|
442
|
610 internal_hash (p->callback_ex, depth + 1),
|
428
|
611 internal_hash (p->suffix, depth + 1),
|
|
612 internal_hash (p->active, depth + 1),
|
|
613 internal_hash (p->included, depth + 1)),
|
442
|
614 HASH6 (internal_hash (p->config, depth + 1),
|
428
|
615 internal_hash (p->filter, depth + 1),
|
|
616 internal_hash (p->style, depth + 1),
|
|
617 internal_hash (p->selected, depth + 1),
|
442
|
618 internal_hash (p->keys, depth + 1),
|
|
619 internal_hash (p->value, depth + 1)));
|
428
|
620 }
|
|
621
|
|
622 int
|
|
623 gui_item_id_hash (Lisp_Object hashtable, Lisp_Object gitem, int slot)
|
|
624 {
|
|
625 int hashid = gui_item_hash (gitem, 0);
|
|
626 int id = GUI_ITEM_ID_BITS (hashid, slot);
|
853
|
627 while (!UNBOUNDP (Fgethash (make_int (id), hashtable, Qunbound)))
|
428
|
628 {
|
|
629 id = GUI_ITEM_ID_BITS (id + 1, slot);
|
|
630 }
|
|
631 return id;
|
|
632 }
|
|
633
|
1318
|
634 static int
|
|
635 gui_value_equal (Lisp_Object a, Lisp_Object b, int depth, int in_redisplay)
|
|
636 {
|
|
637 if (in_redisplay)
|
|
638 return internal_equal_trapping_problems
|
|
639 (Qredisplay, "Error calling function within redisplay", 0, 0,
|
|
640 /* say they're not equal in case of error; code calling
|
|
641 gui_item_equal_sans_selected() in redisplay does extra stuff
|
|
642 only when equal */
|
|
643 0, a, b, depth);
|
|
644 else
|
|
645 return internal_equal (a, b, depth);
|
|
646 }
|
|
647
|
442
|
648 int
|
1318
|
649 gui_item_equal_sans_selected (Lisp_Object obj1, Lisp_Object obj2, int depth,
|
|
650 int in_redisplay)
|
428
|
651 {
|
440
|
652 Lisp_Gui_Item *p1 = XGUI_ITEM (obj1);
|
|
653 Lisp_Gui_Item *p2 = XGUI_ITEM (obj2);
|
428
|
654
|
1318
|
655 if (!(gui_value_equal (p1->name, p2->name, depth + 1, in_redisplay)
|
428
|
656 &&
|
1318
|
657 gui_value_equal (p1->callback, p2->callback, depth + 1, in_redisplay)
|
428
|
658 &&
|
1318
|
659 gui_value_equal (p1->callback_ex, p2->callback_ex, depth + 1,
|
|
660 in_redisplay)
|
442
|
661 &&
|
428
|
662 EQ (p1->suffix, p2->suffix)
|
|
663 &&
|
|
664 EQ (p1->active, p2->active)
|
|
665 &&
|
|
666 EQ (p1->included, p2->included)
|
|
667 &&
|
|
668 EQ (p1->config, p2->config)
|
|
669 &&
|
|
670 EQ (p1->filter, p2->filter)
|
|
671 &&
|
|
672 EQ (p1->style, p2->style)
|
|
673 &&
|
|
674 EQ (p1->accelerator, p2->accelerator)
|
|
675 &&
|
442
|
676 EQ (p1->keys, p2->keys)
|
|
677 &&
|
|
678 EQ (p1->value, p2->value)))
|
|
679 return 0;
|
|
680 return 1;
|
|
681 }
|
|
682
|
|
683 static int
|
|
684 gui_item_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
|
|
685 {
|
|
686 Lisp_Gui_Item *p1 = XGUI_ITEM (obj1);
|
|
687 Lisp_Gui_Item *p2 = XGUI_ITEM (obj2);
|
|
688
|
1318
|
689 if (!(gui_item_equal_sans_selected (obj1, obj2, depth, 0) &&
|
442
|
690 EQ (p1->selected, p2->selected)))
|
428
|
691 return 0;
|
|
692 return 1;
|
|
693 }
|
|
694
|
|
695 static void
|
|
696 print_gui_item (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
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
|
793
|
812 finalize_gui_item (void *header, int 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
|
793
|
825 gui_error (const Char_ASCII *reason, Lisp_Object frob)
|
563
|
826 {
|
|
827 signal_error (Qgui_error, reason, frob);
|
|
828 }
|
|
829
|
569
|
830 DOESNT_RETURN
|
793
|
831 gui_error_2 (const Char_ASCII *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 }
|