428
|
1 /* Generic GUI code. (menubars, scrollbars, toolbars, dialogs)
|
|
2 Copyright (C) 1995 Board of Trustees, University of Illinois.
|
793
|
3 Copyright (C) 1995, 1996, 2000, 2001, 2002 Ben Wing.
|
428
|
4 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
5 Copyright (C) 1998 Free Software Foundation, Inc.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: Not in FSF. */
|
|
25
|
793
|
26 /* This file Mule-ized by Ben Wing, 3-24-02. */
|
442
|
27
|
428
|
28 #include <config.h>
|
|
29 #include "lisp.h"
|
872
|
30
|
442
|
31 #include "buffer.h"
|
428
|
32 #include "bytecode.h"
|
872
|
33 #include "elhash.h"
|
|
34 #include "gui.h"
|
|
35 #include "menubar.h"
|
428
|
36
|
442
|
37 Lisp_Object Qmenu_no_selection_hook;
|
|
38 Lisp_Object Vmenu_no_selection_hook;
|
428
|
39
|
|
40 static Lisp_Object parse_gui_item_tree_list (Lisp_Object list);
|
454
|
41 Lisp_Object find_keyword_in_vector (Lisp_Object vector, Lisp_Object keyword);
|
428
|
42
|
563
|
43 Lisp_Object Qgui_error;
|
|
44
|
428
|
45 #ifdef HAVE_POPUPS
|
|
46
|
|
47 /* count of menus/dboxes currently up */
|
|
48 int popup_up_p;
|
|
49
|
|
50 DEFUN ("popup-up-p", Fpopup_up_p, 0, 0, 0, /*
|
|
51 Return t if a popup menu or dialog box is up, nil otherwise.
|
|
52 See `popup-menu' and `popup-dialog-box'.
|
|
53 */
|
|
54 ())
|
|
55 {
|
|
56 return popup_up_p ? Qt : Qnil;
|
|
57 }
|
|
58 #endif /* HAVE_POPUPS */
|
|
59
|
|
60 int
|
867
|
61 separator_string_p (const Ibyte *s)
|
428
|
62 {
|
867
|
63 const Ibyte *p;
|
|
64 Ibyte first;
|
428
|
65
|
|
66 if (!s || s[0] == '\0')
|
|
67 return 0;
|
|
68 first = s[0];
|
|
69 if (first != '-' && first != '=')
|
|
70 return 0;
|
|
71 for (p = s; *p == first; p++)
|
|
72 ;
|
|
73
|
|
74 return (*p == '!' || *p == ':' || *p == '\0');
|
|
75 }
|
|
76
|
|
77 /* Massage DATA to find the correct function and argument. Used by
|
|
78 popup_selection_callback() and the msw code. */
|
|
79 void
|
|
80 get_gui_callback (Lisp_Object data, Lisp_Object *fn, Lisp_Object *arg)
|
|
81 {
|
442
|
82 if (EQ (data, Qquit))
|
|
83 {
|
|
84 *fn = Qeval;
|
|
85 *arg = list3 (Qsignal, list2 (Qquote, Qquit), Qnil);
|
|
86 Vquit_flag = Qt;
|
|
87 }
|
|
88 else if (SYMBOLP (data)
|
|
89 || (COMPILED_FUNCTIONP (data)
|
|
90 && XCOMPILED_FUNCTION (data)->flags.interactivep)
|
|
91 || (CONSP (data) && (EQ (XCAR (data), Qlambda))
|
|
92 && !NILP (Fassq (Qinteractive, Fcdr (Fcdr (data))))))
|
428
|
93 {
|
|
94 *fn = Qcall_interactively;
|
|
95 *arg = data;
|
|
96 }
|
|
97 else if (CONSP (data))
|
|
98 {
|
|
99 *fn = Qeval;
|
|
100 *arg = data;
|
|
101 }
|
|
102 else
|
|
103 {
|
|
104 *fn = Qeval;
|
|
105 *arg = list3 (Qsignal,
|
|
106 list2 (Qquote, Qerror),
|
771
|
107 list2 (Qquote, list2 (build_msg_string
|
428
|
108 ("illegal callback"),
|
|
109 data)));
|
|
110 }
|
|
111 }
|
|
112
|
|
113 /*
|
|
114 * Add a value VAL associated with keyword KEY into PGUI_ITEM
|
|
115 * structure. If KEY is not a keyword, or is an unknown keyword, then
|
|
116 * error is signaled.
|
|
117 */
|
454
|
118 int
|
428
|
119 gui_item_add_keyval_pair (Lisp_Object gui_item,
|
440
|
120 Lisp_Object key, Lisp_Object val,
|
578
|
121 Error_Behavior errb)
|
428
|
122 {
|
442
|
123 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);
|
454
|
124 int retval = 0;
|
428
|
125
|
|
126 if (!KEYWORDP (key))
|
563
|
127 sferror_2 ("Non-keyword in gui item", key, pgui_item->name);
|
428
|
128
|
454
|
129 if (EQ (key, Q_descriptor))
|
|
130 {
|
|
131 if (!EQ (pgui_item->name, val))
|
|
132 {
|
|
133 retval = 1;
|
|
134 pgui_item->name = val;
|
|
135 }
|
|
136 }
|
793
|
137 #define FROB(slot) \
|
454
|
138 else if (EQ (key, Q_##slot)) \
|
|
139 { \
|
793
|
140 if (!EQ (pgui_item->slot, val)) \
|
454
|
141 { \
|
|
142 retval = 1; \
|
793
|
143 pgui_item->slot = val; \
|
454
|
144 } \
|
|
145 }
|
|
146 FROB (suffix)
|
|
147 FROB (active)
|
|
148 FROB (included)
|
|
149 FROB (config)
|
|
150 FROB (filter)
|
|
151 FROB (style)
|
|
152 FROB (selected)
|
|
153 FROB (keys)
|
|
154 FROB (callback)
|
|
155 FROB (callback_ex)
|
|
156 FROB (value)
|
|
157 #undef FROB
|
440
|
158 else if (EQ (key, Q_key_sequence)) ; /* ignored for FSF compatibility */
|
428
|
159 else if (EQ (key, Q_label)) ; /* ignored for 21.0 implement in 21.2 */
|
|
160 else if (EQ (key, Q_accelerator))
|
|
161 {
|
454
|
162 if (!EQ (pgui_item->accelerator, val))
|
|
163 {
|
|
164 retval = 1;
|
|
165 if (SYMBOLP (val) || CHARP (val))
|
|
166 pgui_item->accelerator = val;
|
|
167 else if (ERRB_EQ (errb, ERROR_ME))
|
563
|
168 invalid_argument ("Bad keyboard accelerator", val);
|
454
|
169 }
|
428
|
170 }
|
|
171 else if (ERRB_EQ (errb, ERROR_ME))
|
793
|
172 invalid_argument_2 ("Unknown keyword in gui item", key, pgui_item->name);
|
454
|
173 return retval;
|
428
|
174 }
|
|
175
|
|
176 void
|
|
177 gui_item_init (Lisp_Object gui_item)
|
|
178 {
|
440
|
179 Lisp_Gui_Item *lp = XGUI_ITEM (gui_item);
|
428
|
180
|
|
181 lp->name = Qnil;
|
|
182 lp->callback = Qnil;
|
442
|
183 lp->callback_ex = Qnil;
|
428
|
184 lp->suffix = Qnil;
|
|
185 lp->active = Qt;
|
|
186 lp->included = Qt;
|
|
187 lp->config = Qnil;
|
|
188 lp->filter = Qnil;
|
|
189 lp->style = Qnil;
|
|
190 lp->selected = Qnil;
|
|
191 lp->keys = Qnil;
|
|
192 lp->accelerator = Qnil;
|
442
|
193 lp->value = Qnil;
|
428
|
194 }
|
|
195
|
|
196 Lisp_Object
|
|
197 allocate_gui_item (void)
|
|
198 {
|
440
|
199 Lisp_Gui_Item *lp = alloc_lcrecord_type (Lisp_Gui_Item, &lrecord_gui_item);
|
428
|
200 Lisp_Object val;
|
|
201
|
|
202 zero_lcrecord (lp);
|
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
|
|
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 {
|
867
|
415 Ibyte *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 {
|
867
|
426 Ichar accelerator = itext_ichar (name + 1);
|
771
|
427 return make_char (DOWNCASE (0, accelerator));
|
442
|
428 }
|
428
|
429 }
|
867
|
430 INC_IBYTEPTR (name);
|
428
|
431 }
|
867
|
432 return make_char (DOWNCASE (0, itext_ichar (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 {
|
793
|
539 DECLARE_EISTRING_MALLOC (buf);
|
|
540 Lisp_Object str;
|
|
541
|
|
542 where_is_to_char (pgui_item->callback, buf);
|
|
543 str = eimake_string (buf);
|
|
544 eifree (buf);
|
|
545 return str;
|
428
|
546 }
|
|
547
|
|
548 /* No keys - no right flush display */
|
771
|
549 return Qnil;
|
428
|
550 }
|
|
551
|
934
|
552 #ifdef USE_KKCC
|
|
553 static const struct lrecord_description gui_item_description [] = {
|
|
554 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, name) },
|
|
555 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, callback) },
|
|
556 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, callback_ex) },
|
|
557 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, suffix) },
|
|
558 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, active) },
|
|
559 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, included) },
|
|
560 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, config) },
|
|
561 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, filter) },
|
|
562 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, style) },
|
|
563 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, selected) },
|
|
564 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, keys) },
|
|
565 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, accelerator) },
|
|
566 { XD_LISP_OBJECT, offsetof (struct Lisp_Gui_Item, value) },
|
|
567 { XD_END }
|
|
568 };
|
|
569 #endif /* USE_KKCC */
|
|
570
|
428
|
571 static Lisp_Object
|
|
572 mark_gui_item (Lisp_Object obj)
|
|
573 {
|
440
|
574 Lisp_Gui_Item *p = XGUI_ITEM (obj);
|
428
|
575
|
|
576 mark_object (p->name);
|
|
577 mark_object (p->callback);
|
442
|
578 mark_object (p->callback_ex);
|
428
|
579 mark_object (p->config);
|
|
580 mark_object (p->suffix);
|
|
581 mark_object (p->active);
|
|
582 mark_object (p->included);
|
|
583 mark_object (p->config);
|
|
584 mark_object (p->filter);
|
|
585 mark_object (p->style);
|
|
586 mark_object (p->selected);
|
|
587 mark_object (p->keys);
|
|
588 mark_object (p->accelerator);
|
442
|
589 mark_object (p->value);
|
428
|
590
|
|
591 return Qnil;
|
|
592 }
|
|
593
|
665
|
594 static Hashcode
|
428
|
595 gui_item_hash (Lisp_Object obj, int depth)
|
|
596 {
|
440
|
597 Lisp_Gui_Item *p = XGUI_ITEM (obj);
|
428
|
598
|
442
|
599 return HASH2 (HASH6 (internal_hash (p->name, depth + 1),
|
428
|
600 internal_hash (p->callback, depth + 1),
|
442
|
601 internal_hash (p->callback_ex, depth + 1),
|
428
|
602 internal_hash (p->suffix, depth + 1),
|
|
603 internal_hash (p->active, depth + 1),
|
|
604 internal_hash (p->included, depth + 1)),
|
442
|
605 HASH6 (internal_hash (p->config, depth + 1),
|
428
|
606 internal_hash (p->filter, depth + 1),
|
|
607 internal_hash (p->style, depth + 1),
|
|
608 internal_hash (p->selected, depth + 1),
|
442
|
609 internal_hash (p->keys, depth + 1),
|
|
610 internal_hash (p->value, depth + 1)));
|
428
|
611 }
|
|
612
|
|
613 int
|
|
614 gui_item_id_hash (Lisp_Object hashtable, Lisp_Object gitem, int slot)
|
|
615 {
|
|
616 int hashid = gui_item_hash (gitem, 0);
|
|
617 int id = GUI_ITEM_ID_BITS (hashid, slot);
|
853
|
618 while (!UNBOUNDP (Fgethash (make_int (id), hashtable, Qunbound)))
|
428
|
619 {
|
|
620 id = GUI_ITEM_ID_BITS (id + 1, slot);
|
|
621 }
|
|
622 return id;
|
|
623 }
|
|
624
|
442
|
625 int
|
|
626 gui_item_equal_sans_selected (Lisp_Object obj1, Lisp_Object obj2, int depth)
|
428
|
627 {
|
440
|
628 Lisp_Gui_Item *p1 = XGUI_ITEM (obj1);
|
|
629 Lisp_Gui_Item *p2 = XGUI_ITEM (obj2);
|
428
|
630
|
|
631 if (!(internal_equal (p1->name, p2->name, depth + 1)
|
|
632 &&
|
|
633 internal_equal (p1->callback, p2->callback, depth + 1)
|
|
634 &&
|
442
|
635 internal_equal (p1->callback_ex, p2->callback_ex, depth + 1)
|
|
636 &&
|
428
|
637 EQ (p1->suffix, p2->suffix)
|
|
638 &&
|
|
639 EQ (p1->active, p2->active)
|
|
640 &&
|
|
641 EQ (p1->included, p2->included)
|
|
642 &&
|
|
643 EQ (p1->config, p2->config)
|
|
644 &&
|
|
645 EQ (p1->filter, p2->filter)
|
|
646 &&
|
|
647 EQ (p1->style, p2->style)
|
|
648 &&
|
|
649 EQ (p1->accelerator, p2->accelerator)
|
|
650 &&
|
442
|
651 EQ (p1->keys, p2->keys)
|
|
652 &&
|
|
653 EQ (p1->value, p2->value)))
|
|
654 return 0;
|
|
655 return 1;
|
|
656 }
|
|
657
|
|
658 static int
|
|
659 gui_item_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
|
|
660 {
|
|
661 Lisp_Gui_Item *p1 = XGUI_ITEM (obj1);
|
|
662 Lisp_Gui_Item *p2 = XGUI_ITEM (obj2);
|
|
663
|
|
664 if (!(gui_item_equal_sans_selected (obj1, obj2, depth)
|
|
665 &&
|
|
666 EQ (p1->selected, p2->selected)))
|
428
|
667 return 0;
|
|
668 return 1;
|
|
669 }
|
|
670
|
|
671 static void
|
|
672 print_gui_item (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
673 {
|
440
|
674 Lisp_Gui_Item *g = XGUI_ITEM (obj);
|
428
|
675
|
|
676 if (print_readably)
|
563
|
677 printing_unreadable_object ("#<gui-item 0x%x>", g->header.uid);
|
428
|
678
|
793
|
679 write_fmt_string (printcharfun, "#<gui-item 0x%x>", g->header.uid);
|
428
|
680 }
|
|
681
|
454
|
682 Lisp_Object
|
442
|
683 copy_gui_item (Lisp_Object gui_item)
|
|
684 {
|
|
685 Lisp_Object ret = allocate_gui_item ();
|
|
686 Lisp_Gui_Item *lp, *g = XGUI_ITEM (gui_item);
|
|
687
|
|
688 lp = XGUI_ITEM (ret);
|
|
689 lp->name = g->name;
|
|
690 lp->callback = g->callback;
|
|
691 lp->callback_ex = g->callback_ex;
|
|
692 lp->suffix = g->suffix;
|
|
693 lp->active = g->active;
|
|
694 lp->included = g->included;
|
|
695 lp->config = g->config;
|
|
696 lp->filter = g->filter;
|
|
697 lp->style = g->style;
|
|
698 lp->selected = g->selected;
|
|
699 lp->keys = g->keys;
|
|
700 lp->accelerator = g->accelerator;
|
|
701 lp->value = g->value;
|
|
702
|
|
703 return ret;
|
|
704 }
|
|
705
|
|
706 Lisp_Object
|
|
707 copy_gui_item_tree (Lisp_Object arg)
|
|
708 {
|
|
709 if (CONSP (arg))
|
|
710 {
|
|
711 Lisp_Object rest = arg = Fcopy_sequence (arg);
|
|
712 while (CONSP (rest))
|
|
713 {
|
|
714 XCAR (rest) = copy_gui_item_tree (XCAR (rest));
|
|
715 rest = XCDR (rest);
|
|
716 }
|
|
717 return arg;
|
|
718 }
|
|
719 else if (GUI_ITEMP (arg))
|
|
720 return copy_gui_item (arg);
|
|
721 else
|
|
722 return arg;
|
|
723 }
|
|
724
|
428
|
725 /* parse a glyph descriptor into a tree of gui items.
|
|
726
|
|
727 The gui_item slot of an image instance can be a single item or an
|
|
728 arbitrarily nested hierarchy of item lists. */
|
|
729
|
442
|
730 static Lisp_Object
|
|
731 parse_gui_item_tree_item (Lisp_Object entry)
|
428
|
732 {
|
|
733 Lisp_Object ret = entry;
|
442
|
734 struct gcpro gcpro1;
|
|
735
|
|
736 GCPRO1 (ret);
|
|
737
|
428
|
738 if (VECTORP (entry))
|
|
739 {
|
442
|
740 ret = gui_parse_item_keywords_no_errors (entry);
|
428
|
741 }
|
|
742 else if (STRINGP (entry))
|
|
743 {
|
|
744 CHECK_STRING (entry);
|
|
745 }
|
|
746 else
|
563
|
747 sferror ("item must be a vector or a string", entry);
|
428
|
748
|
442
|
749 RETURN_UNGCPRO (ret);
|
428
|
750 }
|
|
751
|
442
|
752 Lisp_Object
|
|
753 parse_gui_item_tree_children (Lisp_Object list)
|
428
|
754 {
|
442
|
755 Lisp_Object rest, ret = Qnil, sub = Qnil;
|
|
756 struct gcpro gcpro1, gcpro2;
|
|
757
|
|
758 GCPRO2 (ret, sub);
|
428
|
759 CHECK_CONS (list);
|
|
760 /* recursively add items to the tree view */
|
|
761 LIST_LOOP (rest, list)
|
|
762 {
|
|
763 if (CONSP (XCAR (rest)))
|
|
764 sub = parse_gui_item_tree_list (XCAR (rest));
|
|
765 else
|
|
766 sub = parse_gui_item_tree_item (XCAR (rest));
|
440
|
767
|
428
|
768 ret = Fcons (sub, ret);
|
|
769 }
|
|
770 /* make the order the same as the items we have parsed */
|
442
|
771 RETURN_UNGCPRO (Fnreverse (ret));
|
428
|
772 }
|
|
773
|
442
|
774 static Lisp_Object
|
|
775 parse_gui_item_tree_list (Lisp_Object list)
|
428
|
776 {
|
|
777 Lisp_Object ret;
|
442
|
778 struct gcpro gcpro1;
|
428
|
779 CHECK_CONS (list);
|
|
780 /* first one can never be a list */
|
|
781 ret = parse_gui_item_tree_item (XCAR (list));
|
442
|
782 GCPRO1 (ret);
|
|
783 ret = Fcons (ret, parse_gui_item_tree_children (XCDR (list)));
|
|
784 RETURN_UNGCPRO (ret);
|
|
785 }
|
|
786
|
|
787 static void
|
793
|
788 finalize_gui_item (void *header, int for_disksave)
|
442
|
789 {
|
428
|
790 }
|
|
791
|
934
|
792 #ifdef USE_KKCC
|
|
793 DEFINE_LRECORD_IMPLEMENTATION ("gui-item", gui_item,
|
|
794 0, /*dumpable-flag*/
|
|
795 mark_gui_item, print_gui_item,
|
|
796 finalize_gui_item, gui_item_equal,
|
|
797 gui_item_hash,
|
|
798 gui_item_description,
|
|
799 Lisp_Gui_Item);
|
|
800 #else /* not USE_KKCC */
|
428
|
801 DEFINE_LRECORD_IMPLEMENTATION ("gui-item", gui_item,
|
|
802 mark_gui_item, print_gui_item,
|
442
|
803 finalize_gui_item, gui_item_equal,
|
428
|
804 gui_item_hash,
|
|
805 0,
|
440
|
806 Lisp_Gui_Item);
|
934
|
807 #endif /* not USE_KKCC */
|
563
|
808
|
|
809 DOESNT_RETURN
|
793
|
810 gui_error (const Char_ASCII *reason, Lisp_Object frob)
|
563
|
811 {
|
|
812 signal_error (Qgui_error, reason, frob);
|
|
813 }
|
|
814
|
569
|
815 DOESNT_RETURN
|
793
|
816 gui_error_2 (const Char_ASCII *reason, Lisp_Object frob0, Lisp_Object frob1)
|
569
|
817 {
|
|
818 signal_error_2 (Qgui_error, reason, frob0, frob1);
|
|
819 }
|
|
820
|
428
|
821 void
|
|
822 syms_of_gui (void)
|
|
823 {
|
442
|
824 INIT_LRECORD_IMPLEMENTATION (gui_item);
|
428
|
825
|
442
|
826 DEFSYMBOL (Qmenu_no_selection_hook);
|
428
|
827
|
563
|
828 DEFERROR_STANDARD (Qgui_error, Qio_error);
|
|
829
|
428
|
830 #ifdef HAVE_POPUPS
|
|
831 DEFSUBR (Fpopup_up_p);
|
|
832 #endif
|
|
833 }
|
|
834
|
|
835 void
|
|
836 vars_of_gui (void)
|
|
837 {
|
442
|
838 DEFVAR_LISP ("menu-no-selection-hook", &Vmenu_no_selection_hook /*
|
|
839 Function or functions to call when a menu or dialog box is dismissed
|
|
840 without a selection having been made.
|
|
841 */ );
|
|
842 Vmenu_no_selection_hook = Qnil;
|
428
|
843 }
|