comparison src/gui.c @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 8de8e3f6228a
children d7a9135ec789
comparison
equal deleted inserted replaced
441:72a7cfa4a488 442:abe6d1db359e
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */ 22 Boston, MA 02111-1307, USA. */
23 23
24 /* Synched up with: Not in FSF. */ 24 /* Synched up with: Not in FSF. */
25 25
26 /* This file not quite Mule-ized yet but will be when merged with my
27 Mule workspace. --ben */
28
26 #include <config.h> 29 #include <config.h>
27 #include "lisp.h" 30 #include "lisp.h"
28 #include "gui.h" 31 #include "gui.h"
29 #include "elhash.h" 32 #include "elhash.h"
33 #include "buffer.h"
30 #include "bytecode.h" 34 #include "bytecode.h"
31 35
32 Lisp_Object Q_active, Q_suffix, Q_keys, Q_style, Q_selected; 36 Lisp_Object Qmenu_no_selection_hook;
33 Lisp_Object Q_filter, Q_config, Q_included, Q_key_sequence; 37 Lisp_Object Vmenu_no_selection_hook;
34 Lisp_Object Q_accelerator, Q_label, Q_callback;
35 Lisp_Object Qtoggle, Qradio;
36 38
37 static Lisp_Object parse_gui_item_tree_list (Lisp_Object list); 39 static Lisp_Object parse_gui_item_tree_list (Lisp_Object list);
38 40
39 #ifdef HAVE_POPUPS 41 #ifdef HAVE_POPUPS
40 42
50 return popup_up_p ? Qt : Qnil; 52 return popup_up_p ? Qt : Qnil;
51 } 53 }
52 #endif /* HAVE_POPUPS */ 54 #endif /* HAVE_POPUPS */
53 55
54 int 56 int
55 separator_string_p (CONST char *s) 57 separator_string_p (const Bufbyte *s)
56 { 58 {
57 CONST char *p; 59 const Bufbyte *p;
58 char first; 60 Bufbyte first;
59 61
60 if (!s || s[0] == '\0') 62 if (!s || s[0] == '\0')
61 return 0; 63 return 0;
62 first = s[0]; 64 first = s[0];
63 if (first != '-' && first != '=') 65 if (first != '-' && first != '=')
71 /* Massage DATA to find the correct function and argument. Used by 73 /* Massage DATA to find the correct function and argument. Used by
72 popup_selection_callback() and the msw code. */ 74 popup_selection_callback() and the msw code. */
73 void 75 void
74 get_gui_callback (Lisp_Object data, Lisp_Object *fn, Lisp_Object *arg) 76 get_gui_callback (Lisp_Object data, Lisp_Object *fn, Lisp_Object *arg)
75 { 77 {
76 if (SYMBOLP (data) 78 if (EQ (data, Qquit))
77 || (COMPILED_FUNCTIONP (data) 79 {
78 && XCOMPILED_FUNCTION (data)->flags.interactivep) 80 *fn = Qeval;
79 || (CONSP (data) && (EQ (XCAR (data), Qlambda)) 81 *arg = list3 (Qsignal, list2 (Qquote, Qquit), Qnil);
80 && !NILP (Fassq (Qinteractive, Fcdr (Fcdr (data)))))) 82 Vquit_flag = Qt;
83 }
84 else if (SYMBOLP (data)
85 || (COMPILED_FUNCTIONP (data)
86 && XCOMPILED_FUNCTION (data)->flags.interactivep)
87 || (CONSP (data) && (EQ (XCAR (data), Qlambda))
88 && !NILP (Fassq (Qinteractive, Fcdr (Fcdr (data))))))
81 { 89 {
82 *fn = Qcall_interactively; 90 *fn = Qcall_interactively;
83 *arg = data; 91 *arg = data;
84 } 92 }
85 else if (CONSP (data)) 93 else if (CONSP (data))
106 void 114 void
107 gui_item_add_keyval_pair (Lisp_Object gui_item, 115 gui_item_add_keyval_pair (Lisp_Object gui_item,
108 Lisp_Object key, Lisp_Object val, 116 Lisp_Object key, Lisp_Object val,
109 Error_behavior errb) 117 Error_behavior errb)
110 { 118 {
111 Lisp_Gui_Item* pgui_item = XGUI_ITEM (gui_item); 119 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);
112 120
113 if (!KEYWORDP (key)) 121 if (!KEYWORDP (key))
114 signal_simple_error_2 ("Non-keyword in gui item", key, pgui_item->name); 122 syntax_error_2 ("Non-keyword in gui item", key, pgui_item->name);
115 123
116 if (EQ (key, Q_suffix)) pgui_item->suffix = val; 124 if (EQ (key, Q_suffix)) pgui_item->suffix = val;
117 else if (EQ (key, Q_active)) pgui_item->active = val; 125 else if (EQ (key, Q_active)) pgui_item->active = val;
118 else if (EQ (key, Q_included)) pgui_item->included = val; 126 else if (EQ (key, Q_included)) pgui_item->included = val;
119 else if (EQ (key, Q_config)) pgui_item->config = val; 127 else if (EQ (key, Q_config)) pgui_item->config = val;
120 else if (EQ (key, Q_filter)) pgui_item->filter = val; 128 else if (EQ (key, Q_filter)) pgui_item->filter = val;
121 else if (EQ (key, Q_style)) pgui_item->style = val; 129 else if (EQ (key, Q_style)) pgui_item->style = val;
122 else if (EQ (key, Q_selected)) pgui_item->selected = val; 130 else if (EQ (key, Q_selected)) pgui_item->selected = val;
123 else if (EQ (key, Q_keys)) pgui_item->keys = val; 131 else if (EQ (key, Q_keys)) pgui_item->keys = val;
124 else if (EQ (key, Q_callback)) pgui_item->callback = val; 132 else if (EQ (key, Q_callback)) pgui_item->callback = val;
133 else if (EQ (key, Q_callback_ex)) pgui_item->callback_ex = val;
134 else if (EQ (key, Q_value)) pgui_item->value = val;
125 else if (EQ (key, Q_key_sequence)) ; /* ignored for FSF compatibility */ 135 else if (EQ (key, Q_key_sequence)) ; /* ignored for FSF compatibility */
126 else if (EQ (key, Q_label)) ; /* ignored for 21.0 implement in 21.2 */ 136 else if (EQ (key, Q_label)) ; /* ignored for 21.0 implement in 21.2 */
127 else if (EQ (key, Q_accelerator)) 137 else if (EQ (key, Q_accelerator))
128 { 138 {
129 if (SYMBOLP (val) || CHARP (val)) 139 if (SYMBOLP (val) || CHARP (val))
130 pgui_item->accelerator = val; 140 pgui_item->accelerator = val;
131 else if (ERRB_EQ (errb, ERROR_ME)) 141 else if (ERRB_EQ (errb, ERROR_ME))
132 signal_simple_error ("Bad keyboard accelerator", val); 142 syntax_error ("Bad keyboard accelerator", val);
133 } 143 }
134 else if (ERRB_EQ (errb, ERROR_ME)) 144 else if (ERRB_EQ (errb, ERROR_ME))
135 signal_simple_error_2 ("Unknown keyword in gui item", key, pgui_item->name); 145 syntax_error_2 ("Unknown keyword in gui item", key,
146 pgui_item->name);
136 } 147 }
137 148
138 void 149 void
139 gui_item_init (Lisp_Object gui_item) 150 gui_item_init (Lisp_Object gui_item)
140 { 151 {
141 Lisp_Gui_Item *lp = XGUI_ITEM (gui_item); 152 Lisp_Gui_Item *lp = XGUI_ITEM (gui_item);
142 153
143 lp->name = Qnil; 154 lp->name = Qnil;
144 lp->callback = Qnil; 155 lp->callback = Qnil;
156 lp->callback_ex = Qnil;
145 lp->suffix = Qnil; 157 lp->suffix = Qnil;
146 lp->active = Qt; 158 lp->active = Qt;
147 lp->included = Qt; 159 lp->included = Qt;
148 lp->config = Qnil; 160 lp->config = Qnil;
149 lp->filter = Qnil; 161 lp->filter = Qnil;
150 lp->style = Qnil; 162 lp->style = Qnil;
151 lp->selected = Qnil; 163 lp->selected = Qnil;
152 lp->keys = Qnil; 164 lp->keys = Qnil;
153 lp->accelerator = Qnil; 165 lp->accelerator = Qnil;
166 lp->value = Qnil;
154 } 167 }
155 168
156 Lisp_Object 169 Lisp_Object
157 allocate_gui_item (void) 170 allocate_gui_item (void)
158 { 171 {
177 Error_behavior errb) 190 Error_behavior errb)
178 { 191 {
179 int length, plist_p, start; 192 int length, plist_p, start;
180 Lisp_Object *contents; 193 Lisp_Object *contents;
181 Lisp_Object gui_item = allocate_gui_item (); 194 Lisp_Object gui_item = allocate_gui_item ();
182 Lisp_Gui_Item* pgui_item = XGUI_ITEM (gui_item); 195 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);
183 196
184 CHECK_VECTOR (item); 197 CHECK_VECTOR (item);
185 length = XVECTOR_LENGTH (item); 198 length = XVECTOR_LENGTH (item);
186 contents = XVECTOR_DATA (item); 199 contents = XVECTOR_DATA (item);
187 200
188 if (length < 1) 201 if (length < 1)
189 signal_simple_error ("GUI item descriptors must be at least 1 elts long", item); 202 syntax_error ("GUI item descriptors must be at least 1 elts long", item);
190 203
191 /* length 1: [ "name" ] 204 /* length 1: [ "name" ]
192 length 2: [ "name" callback ] 205 length 2: [ "name" callback ]
193 length 3: [ "name" callback active-p ] 206 length 3: [ "name" callback active-p ]
194 or [ "name" keyword value ] 207 or [ "name" keyword value ]
219 else 232 else
220 /* the new way */ 233 /* the new way */
221 { 234 {
222 int i; 235 int i;
223 if ((length - start) & 1) 236 if ((length - start) & 1)
224 signal_simple_error ( 237 syntax_error (
225 "GUI item descriptor has an odd number of keywords and values", 238 "GUI item descriptor has an odd number of keywords and values",
226 item); 239 item);
227 240
228 for (i = start; i < length;) 241 for (i = start; i < length;)
229 { 242 {
249 262
250 /* convert a gui item into plist properties */ 263 /* convert a gui item into plist properties */
251 void 264 void
252 gui_add_item_keywords_to_plist (Lisp_Object plist, Lisp_Object gui_item) 265 gui_add_item_keywords_to_plist (Lisp_Object plist, Lisp_Object gui_item)
253 { 266 {
254 Lisp_Gui_Item* pgui_item = XGUI_ITEM (gui_item); 267 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);
255 268
256 if (!NILP (pgui_item->callback)) 269 if (!NILP (pgui_item->callback))
257 Fplist_put (plist, Q_callback, pgui_item->callback); 270 Fplist_put (plist, Q_callback, pgui_item->callback);
271 if (!NILP (pgui_item->callback_ex))
272 Fplist_put (plist, Q_callback_ex, pgui_item->callback_ex);
258 if (!NILP (pgui_item->suffix)) 273 if (!NILP (pgui_item->suffix))
259 Fplist_put (plist, Q_suffix, pgui_item->suffix); 274 Fplist_put (plist, Q_suffix, pgui_item->suffix);
260 if (!NILP (pgui_item->active)) 275 if (!NILP (pgui_item->active))
261 Fplist_put (plist, Q_active, pgui_item->active); 276 Fplist_put (plist, Q_active, pgui_item->active);
262 if (!NILP (pgui_item->included)) 277 if (!NILP (pgui_item->included))
271 Fplist_put (plist, Q_selected, pgui_item->selected); 286 Fplist_put (plist, Q_selected, pgui_item->selected);
272 if (!NILP (pgui_item->keys)) 287 if (!NILP (pgui_item->keys))
273 Fplist_put (plist, Q_keys, pgui_item->keys); 288 Fplist_put (plist, Q_keys, pgui_item->keys);
274 if (!NILP (pgui_item->accelerator)) 289 if (!NILP (pgui_item->accelerator))
275 Fplist_put (plist, Q_accelerator, pgui_item->accelerator); 290 Fplist_put (plist, Q_accelerator, pgui_item->accelerator);
291 if (!NILP (pgui_item->value))
292 Fplist_put (plist, Q_value, pgui_item->value);
276 } 293 }
277 294
278 /* 295 /*
279 * Decide whether a GUI item is active by evaluating its :active form 296 * Decide whether a GUI item is active by evaluating its :active form
280 * if any 297 * if any
291 308
292 /* set menu accelerator key to first underlined character in menu name */ 309 /* set menu accelerator key to first underlined character in menu name */
293 Lisp_Object 310 Lisp_Object
294 gui_item_accelerator (Lisp_Object gui_item) 311 gui_item_accelerator (Lisp_Object gui_item)
295 { 312 {
296 Lisp_Gui_Item* pgui = XGUI_ITEM (gui_item); 313 Lisp_Gui_Item *pgui = XGUI_ITEM (gui_item);
297 314
298 if (!NILP (pgui->accelerator)) 315 if (!NILP (pgui->accelerator))
299 return pgui->accelerator; 316 return pgui->accelerator;
300 317
301 else 318 else
302 return pgui->name; 319 return gui_name_accelerator (pgui->name);
303 } 320 }
304 321
305 Lisp_Object 322 Lisp_Object
306 gui_name_accelerator (Lisp_Object nm) 323 gui_name_accelerator (Lisp_Object nm)
307 { 324 {
308 /* !!#### This function has not been Mule-ized */ 325 Bufbyte *name = XSTRING_DATA (nm);
309 char* name = (char*)XSTRING_DATA (nm); 326
310 327 while (*name)
311 while (*name) { 328 {
312 if (*name=='%') { 329 if (*name == '%')
313 ++name;
314 if (!(*name))
315 return Qnil;
316 if (*name=='_' && *(name+1))
317 { 330 {
318 int accelerator = (int) (unsigned char) (*(name+1)); 331 ++name;
319 return make_char (tolower (accelerator)); 332 if (!(*name))
333 return Qnil;
334 if (*name == '_' && *(name + 1))
335 {
336 Emchar accelerator = charptr_emchar (name + 1);
337 /* #### bogus current_buffer dependency */
338 return make_char (DOWNCASE (current_buffer, accelerator));
339 }
320 } 340 }
321 } 341 INC_CHARPTR (name);
322 ++name; 342 }
323 } 343 return make_char (DOWNCASE (current_buffer,
324 return Qnil; 344 charptr_emchar (XSTRING_DATA (nm))));
325 } 345 }
326 346
327 /* 347 /*
328 * Decide whether a GUI item is selected by evaluating its :selected form 348 * Decide whether a GUI item is selected by evaluating its :selected form
329 * if any 349 * if any
334 /* This function can call lisp */ 354 /* This function can call lisp */
335 355
336 /* Shortcut to avoid evaluating Qt each time */ 356 /* Shortcut to avoid evaluating Qt each time */
337 return (EQ (XGUI_ITEM (gui_item)->selected, Qt) 357 return (EQ (XGUI_ITEM (gui_item)->selected, Qt)
338 || !NILP (Feval (XGUI_ITEM (gui_item)->selected))); 358 || !NILP (Feval (XGUI_ITEM (gui_item)->selected)));
359 }
360
361 Lisp_Object
362 gui_item_list_find_selected (Lisp_Object gui_item_list)
363 {
364 /* This function can GC. */
365 Lisp_Object rest;
366 LIST_LOOP (rest, gui_item_list)
367 {
368 if (gui_item_selected_p (XCAR (rest)))
369 return XCAR (rest);
370 }
371 return XCAR (gui_item_list);
339 } 372 }
340 373
341 /* 374 /*
342 * Decide whether a GUI item is included by evaluating its :included 375 * Decide whether a GUI item is included by evaluating its :included
343 * form if given, and testing its :config form against supplied CONFLIST 376 * form if given, and testing its :config form against supplied CONFLIST
345 */ 378 */
346 int 379 int
347 gui_item_included_p (Lisp_Object gui_item, Lisp_Object conflist) 380 gui_item_included_p (Lisp_Object gui_item, Lisp_Object conflist)
348 { 381 {
349 /* This function can call lisp */ 382 /* This function can call lisp */
350 Lisp_Gui_Item* pgui_item = XGUI_ITEM (gui_item); 383 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);
351 384
352 /* Evaluate :included first. Shortcut to avoid evaluating Qt each time */ 385 /* Evaluate :included first. Shortcut to avoid evaluating Qt each time */
353 if (!EQ (pgui_item->included, Qt) 386 if (!EQ (pgui_item->included, Qt)
354 && NILP (Feval (pgui_item->included))) 387 && NILP (Feval (pgui_item->included)))
355 return 0; 388 return 0;
363 } 396 }
364 397
365 static DOESNT_RETURN 398 static DOESNT_RETURN
366 signal_too_long_error (Lisp_Object name) 399 signal_too_long_error (Lisp_Object name)
367 { 400 {
368 signal_simple_error ("GUI item produces too long displayable string", name); 401 syntax_error ("GUI item produces too long displayable string", name);
369 } 402 }
370 403
371 #ifdef HAVE_WINDOW_SYSTEM 404 #ifdef HAVE_WINDOW_SYSTEM
372 /* 405 /*
373 * Format "left flush" display portion of an item into BUF, guarded by 406 * Format "left flush" display portion of an item into BUF, guarded by
377 * signaled. 410 * signaled.
378 * Return value is the offset to the terminating null character into the 411 * Return value is the offset to the terminating null character into the
379 * buffer. 412 * buffer.
380 */ 413 */
381 unsigned int 414 unsigned int
382 gui_item_display_flush_left (Lisp_Object gui_item, 415 gui_item_display_flush_left (Lisp_Object gui_item,
383 char* buf, Bytecount buf_len) 416 char *buf, Bytecount buf_len)
384 { 417 {
385 /* This function can call lisp */ 418 /* This function can call lisp */
386 char *p = buf; 419 char *p = buf;
387 Bytecount len; 420 Bytecount len;
388 Lisp_Gui_Item* pgui_item = XGUI_ITEM (gui_item); 421 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);
389 422
390 /* Copy item name first */ 423 /* Copy item name first */
391 CHECK_STRING (pgui_item->name); 424 CHECK_STRING (pgui_item->name);
392 len = XSTRING_LENGTH (pgui_item->name); 425 len = XSTRING_LENGTH (pgui_item->name);
393 if (len > buf_len) 426 if (len > buf_len)
427 * Return value is the offset to the terminating null character into the 460 * Return value is the offset to the terminating null character into the
428 * buffer. 461 * buffer.
429 */ 462 */
430 unsigned int 463 unsigned int
431 gui_item_display_flush_right (Lisp_Object gui_item, 464 gui_item_display_flush_right (Lisp_Object gui_item,
432 char* buf, Bytecount buf_len) 465 char *buf, Bytecount buf_len)
433 { 466 {
434 Lisp_Gui_Item* pgui_item = XGUI_ITEM (gui_item); 467 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);
435 *buf = 0; 468 *buf = 0;
436 469
437 #ifdef HAVE_MENUBARS 470 #ifdef HAVE_MENUBARS
438 /* Have keys? */ 471 /* Have keys? */
439 if (!menubar_show_keybindings) 472 if (!menubar_show_keybindings)
442 475
443 /* Try :keys first */ 476 /* Try :keys first */
444 if (!NILP (pgui_item->keys)) 477 if (!NILP (pgui_item->keys))
445 { 478 {
446 CHECK_STRING (pgui_item->keys); 479 CHECK_STRING (pgui_item->keys);
447 if (XSTRING_LENGTH (pgui_item->keys) > buf_len) 480 if (XSTRING_LENGTH (pgui_item->keys) + 1 > buf_len)
448 signal_too_long_error (pgui_item->name); 481 signal_too_long_error (pgui_item->name);
449 strcpy (buf, (CONST char *) XSTRING_DATA (pgui_item->keys)); 482 memcpy (buf, XSTRING_DATA (pgui_item->keys),
483 XSTRING_LENGTH (pgui_item->keys) + 1);
450 return XSTRING_LENGTH (pgui_item->keys); 484 return XSTRING_LENGTH (pgui_item->keys);
451 } 485 }
452 486
453 /* See if we can derive keys out of callback symbol */ 487 /* See if we can derive keys out of callback symbol */
454 if (SYMBOLP (pgui_item->callback)) 488 if (SYMBOLP (pgui_item->callback))
455 { 489 {
456 char buf2 [1024]; 490 char buf2[1024]; /* #### */
457 Bytecount len; 491 Bytecount len;
458 492
459 where_is_to_char (pgui_item->callback, buf2); 493 where_is_to_char (pgui_item->callback, buf2);
460 len = strlen (buf2); 494 len = strlen (buf2);
461 if (len > buf_len) 495 if (len > buf_len)
474 { 508 {
475 Lisp_Gui_Item *p = XGUI_ITEM (obj); 509 Lisp_Gui_Item *p = XGUI_ITEM (obj);
476 510
477 mark_object (p->name); 511 mark_object (p->name);
478 mark_object (p->callback); 512 mark_object (p->callback);
513 mark_object (p->callback_ex);
479 mark_object (p->config); 514 mark_object (p->config);
480 mark_object (p->suffix); 515 mark_object (p->suffix);
481 mark_object (p->active); 516 mark_object (p->active);
482 mark_object (p->included); 517 mark_object (p->included);
483 mark_object (p->config); 518 mark_object (p->config);
484 mark_object (p->filter); 519 mark_object (p->filter);
485 mark_object (p->style); 520 mark_object (p->style);
486 mark_object (p->selected); 521 mark_object (p->selected);
487 mark_object (p->keys); 522 mark_object (p->keys);
488 mark_object (p->accelerator); 523 mark_object (p->accelerator);
524 mark_object (p->value);
489 525
490 return Qnil; 526 return Qnil;
491 } 527 }
492 528
493 static unsigned long 529 static unsigned long
494 gui_item_hash (Lisp_Object obj, int depth) 530 gui_item_hash (Lisp_Object obj, int depth)
495 { 531 {
496 Lisp_Gui_Item *p = XGUI_ITEM (obj); 532 Lisp_Gui_Item *p = XGUI_ITEM (obj);
497 533
498 return HASH2 (HASH5 (internal_hash (p->name, depth + 1), 534 return HASH2 (HASH6 (internal_hash (p->name, depth + 1),
499 internal_hash (p->callback, depth + 1), 535 internal_hash (p->callback, depth + 1),
536 internal_hash (p->callback_ex, depth + 1),
500 internal_hash (p->suffix, depth + 1), 537 internal_hash (p->suffix, depth + 1),
501 internal_hash (p->active, depth + 1), 538 internal_hash (p->active, depth + 1),
502 internal_hash (p->included, depth + 1)), 539 internal_hash (p->included, depth + 1)),
503 HASH5 (internal_hash (p->config, depth + 1), 540 HASH6 (internal_hash (p->config, depth + 1),
504 internal_hash (p->filter, depth + 1), 541 internal_hash (p->filter, depth + 1),
505 internal_hash (p->style, depth + 1), 542 internal_hash (p->style, depth + 1),
506 internal_hash (p->selected, depth + 1), 543 internal_hash (p->selected, depth + 1),
507 internal_hash (p->keys, depth + 1))); 544 internal_hash (p->keys, depth + 1),
545 internal_hash (p->value, depth + 1)));
508 } 546 }
509 547
510 int 548 int
511 gui_item_id_hash (Lisp_Object hashtable, Lisp_Object gitem, int slot) 549 gui_item_id_hash (Lisp_Object hashtable, Lisp_Object gitem, int slot)
512 { 550 {
518 id = GUI_ITEM_ID_BITS (id + 1, slot); 556 id = GUI_ITEM_ID_BITS (id + 1, slot);
519 } 557 }
520 return id; 558 return id;
521 } 559 }
522 560
561 int
562 gui_item_equal_sans_selected (Lisp_Object obj1, Lisp_Object obj2, int depth)
563 {
564 Lisp_Gui_Item *p1 = XGUI_ITEM (obj1);
565 Lisp_Gui_Item *p2 = XGUI_ITEM (obj2);
566
567 if (!(internal_equal (p1->name, p2->name, depth + 1)
568 &&
569 internal_equal (p1->callback, p2->callback, depth + 1)
570 &&
571 internal_equal (p1->callback_ex, p2->callback_ex, depth + 1)
572 &&
573 EQ (p1->suffix, p2->suffix)
574 &&
575 EQ (p1->active, p2->active)
576 &&
577 EQ (p1->included, p2->included)
578 &&
579 EQ (p1->config, p2->config)
580 &&
581 EQ (p1->filter, p2->filter)
582 &&
583 EQ (p1->style, p2->style)
584 &&
585 EQ (p1->accelerator, p2->accelerator)
586 &&
587 EQ (p1->keys, p2->keys)
588 &&
589 EQ (p1->value, p2->value)))
590 return 0;
591 return 1;
592 }
593
523 static int 594 static int
524 gui_item_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) 595 gui_item_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
525 { 596 {
526 Lisp_Gui_Item *p1 = XGUI_ITEM (obj1); 597 Lisp_Gui_Item *p1 = XGUI_ITEM (obj1);
527 Lisp_Gui_Item *p2 = XGUI_ITEM (obj2); 598 Lisp_Gui_Item *p2 = XGUI_ITEM (obj2);
528 599
529 if (!(internal_equal (p1->name, p2->name, depth + 1) 600 if (!(gui_item_equal_sans_selected (obj1, obj2, depth)
530 && 601 &&
531 internal_equal (p1->callback, p2->callback, depth + 1) 602 EQ (p1->selected, p2->selected)))
532 &&
533 EQ (p1->suffix, p2->suffix)
534 &&
535 EQ (p1->active, p2->active)
536 &&
537 EQ (p1->included, p2->included)
538 &&
539 EQ (p1->config, p2->config)
540 &&
541 EQ (p1->filter, p2->filter)
542 &&
543 EQ (p1->style, p2->style)
544 &&
545 EQ (p1->selected, p2->selected)
546 &&
547 EQ (p1->accelerator, p2->accelerator)
548 &&
549 EQ (p1->keys, p2->keys)))
550 return 0; 603 return 0;
551 return 1; 604 return 1;
552 } 605 }
553 606
554 static void 607 static void
563 write_c_string ("#<gui-item ", printcharfun); 616 write_c_string ("#<gui-item ", printcharfun);
564 sprintf (buf, "0x%x>", g->header.uid); 617 sprintf (buf, "0x%x>", g->header.uid);
565 write_c_string (buf, printcharfun); 618 write_c_string (buf, printcharfun);
566 } 619 }
567 620
621 static Lisp_Object
622 copy_gui_item (Lisp_Object gui_item)
623 {
624 Lisp_Object ret = allocate_gui_item ();
625 Lisp_Gui_Item *lp, *g = XGUI_ITEM (gui_item);
626
627 lp = XGUI_ITEM (ret);
628 lp->name = g->name;
629 lp->callback = g->callback;
630 lp->callback_ex = g->callback_ex;
631 lp->suffix = g->suffix;
632 lp->active = g->active;
633 lp->included = g->included;
634 lp->config = g->config;
635 lp->filter = g->filter;
636 lp->style = g->style;
637 lp->selected = g->selected;
638 lp->keys = g->keys;
639 lp->accelerator = g->accelerator;
640 lp->value = g->value;
641
642 return ret;
643 }
644
645 Lisp_Object
646 copy_gui_item_tree (Lisp_Object arg)
647 {
648 if (CONSP (arg))
649 {
650 Lisp_Object rest = arg = Fcopy_sequence (arg);
651 while (CONSP (rest))
652 {
653 XCAR (rest) = copy_gui_item_tree (XCAR (rest));
654 rest = XCDR (rest);
655 }
656 return arg;
657 }
658 else if (GUI_ITEMP (arg))
659 return copy_gui_item (arg);
660 else
661 return arg;
662 }
663
568 /* parse a glyph descriptor into a tree of gui items. 664 /* parse a glyph descriptor into a tree of gui items.
569 665
570 The gui_item slot of an image instance can be a single item or an 666 The gui_item slot of an image instance can be a single item or an
571 arbitrarily nested hierarchy of item lists. */ 667 arbitrarily nested hierarchy of item lists. */
572 668
573 static Lisp_Object parse_gui_item_tree_item (Lisp_Object entry) 669 static Lisp_Object
670 parse_gui_item_tree_item (Lisp_Object entry)
574 { 671 {
575 Lisp_Object ret = entry; 672 Lisp_Object ret = entry;
673 struct gcpro gcpro1;
674
675 GCPRO1 (ret);
676
576 if (VECTORP (entry)) 677 if (VECTORP (entry))
577 { 678 {
578 ret = gui_parse_item_keywords_no_errors (entry); 679 ret = gui_parse_item_keywords_no_errors (entry);
579 } 680 }
580 else if (STRINGP (entry)) 681 else if (STRINGP (entry))
581 { 682 {
582 CHECK_STRING (entry); 683 CHECK_STRING (entry);
583 } 684 }
584 else 685 else
585 signal_simple_error ("item must be a vector or a string", entry); 686 syntax_error ("item must be a vector or a string", entry);
586 687
587 return ret; 688 RETURN_UNGCPRO (ret);
588 } 689 }
589 690
590 Lisp_Object parse_gui_item_tree_children (Lisp_Object list) 691 Lisp_Object
591 { 692 parse_gui_item_tree_children (Lisp_Object list)
592 Lisp_Object rest, ret = Qnil; 693 {
694 Lisp_Object rest, ret = Qnil, sub = Qnil;
695 struct gcpro gcpro1, gcpro2;
696
697 GCPRO2 (ret, sub);
593 CHECK_CONS (list); 698 CHECK_CONS (list);
594 /* recursively add items to the tree view */ 699 /* recursively add items to the tree view */
595 LIST_LOOP (rest, list) 700 LIST_LOOP (rest, list)
596 { 701 {
597 Lisp_Object sub;
598 if (CONSP (XCAR (rest))) 702 if (CONSP (XCAR (rest)))
599 sub = parse_gui_item_tree_list (XCAR (rest)); 703 sub = parse_gui_item_tree_list (XCAR (rest));
600 else 704 else
601 sub = parse_gui_item_tree_item (XCAR (rest)); 705 sub = parse_gui_item_tree_item (XCAR (rest));
602 706
603 ret = Fcons (sub, ret); 707 ret = Fcons (sub, ret);
604 } 708 }
605 /* make the order the same as the items we have parsed */ 709 /* make the order the same as the items we have parsed */
606 return Fnreverse (ret); 710 RETURN_UNGCPRO (Fnreverse (ret));
607 } 711 }
608 712
609 static Lisp_Object parse_gui_item_tree_list (Lisp_Object list) 713 static Lisp_Object
714 parse_gui_item_tree_list (Lisp_Object list)
610 { 715 {
611 Lisp_Object ret; 716 Lisp_Object ret;
717 struct gcpro gcpro1;
612 CHECK_CONS (list); 718 CHECK_CONS (list);
613 /* first one can never be a list */ 719 /* first one can never be a list */
614 ret = parse_gui_item_tree_item (XCAR (list)); 720 ret = parse_gui_item_tree_item (XCAR (list));
615 return Fcons (ret, parse_gui_item_tree_children (XCDR (list))); 721 GCPRO1 (ret);
722 ret = Fcons (ret, parse_gui_item_tree_children (XCDR (list)));
723 RETURN_UNGCPRO (ret);
724 }
725
726 static void
727 finalize_gui_item (void* header, int for_disksave)
728 {
616 } 729 }
617 730
618 DEFINE_LRECORD_IMPLEMENTATION ("gui-item", gui_item, 731 DEFINE_LRECORD_IMPLEMENTATION ("gui-item", gui_item,
619 mark_gui_item, print_gui_item, 732 mark_gui_item, print_gui_item,
620 0, gui_item_equal, 733 finalize_gui_item, gui_item_equal,
621 gui_item_hash, 734 gui_item_hash,
622 0, 735 0,
623 Lisp_Gui_Item); 736 Lisp_Gui_Item);
624 737
625 void 738 void
626 syms_of_gui (void) 739 syms_of_gui (void)
627 { 740 {
628 defkeyword (&Q_active, ":active"); 741 INIT_LRECORD_IMPLEMENTATION (gui_item);
629 defkeyword (&Q_suffix, ":suffix"); 742
630 defkeyword (&Q_keys, ":keys"); 743 DEFSYMBOL (Qmenu_no_selection_hook);
631 defkeyword (&Q_key_sequence,":key-sequence");
632 defkeyword (&Q_style, ":style");
633 defkeyword (&Q_selected, ":selected");
634 defkeyword (&Q_filter, ":filter");
635 defkeyword (&Q_config, ":config");
636 defkeyword (&Q_included, ":included");
637 defkeyword (&Q_accelerator, ":accelerator");
638 defkeyword (&Q_label, ":label");
639 defkeyword (&Q_callback, ":callback");
640
641 defsymbol (&Qtoggle, "toggle");
642 defsymbol (&Qradio, "radio");
643 744
644 #ifdef HAVE_POPUPS 745 #ifdef HAVE_POPUPS
645 DEFSUBR (Fpopup_up_p); 746 DEFSUBR (Fpopup_up_p);
646 #endif 747 #endif
647 } 748 }
648 749
649 void 750 void
650 vars_of_gui (void) 751 vars_of_gui (void)
651 { 752 {
652 } 753 DEFVAR_LISP ("menu-no-selection-hook", &Vmenu_no_selection_hook /*
754 Function or functions to call when a menu or dialog box is dismissed
755 without a selection having been made.
756 */ );
757 Vmenu_no_selection_hook = Qnil;
758 }