Mercurial > hg > xemacs-beta
comparison src/gui.c @ 404:2f8bb876ab1d r21-2-32
Import from CVS: tag r21-2-32
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:16:07 +0200 |
parents | a86b2b5e0111 |
children | b8cc9ab3f761 |
comparison
equal
deleted
inserted
replaced
403:9f011ab08d48 | 404:2f8bb876ab1d |
---|---|
25 | 25 |
26 #include <config.h> | 26 #include <config.h> |
27 #include "lisp.h" | 27 #include "lisp.h" |
28 #include "gui.h" | 28 #include "gui.h" |
29 #include "elhash.h" | 29 #include "elhash.h" |
30 #include "buffer.h" | |
30 #include "bytecode.h" | 31 #include "bytecode.h" |
31 | 32 |
32 Lisp_Object Q_active, Q_suffix, Q_keys, Q_style, Q_selected; | 33 Lisp_Object Q_active, Q_suffix, Q_keys, Q_style, Q_selected; |
33 Lisp_Object Q_filter, Q_config, Q_included, Q_key_sequence; | 34 Lisp_Object Q_filter, Q_config, Q_included, Q_key_sequence; |
34 Lisp_Object Q_accelerator, Q_label, Q_callback; | 35 Lisp_Object Q_accelerator, Q_label, Q_callback; |
106 void | 107 void |
107 gui_item_add_keyval_pair (Lisp_Object gui_item, | 108 gui_item_add_keyval_pair (Lisp_Object gui_item, |
108 Lisp_Object key, Lisp_Object val, | 109 Lisp_Object key, Lisp_Object val, |
109 Error_behavior errb) | 110 Error_behavior errb) |
110 { | 111 { |
111 Lisp_Gui_Item* pgui_item = XGUI_ITEM (gui_item); | 112 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item); |
112 | 113 |
113 if (!KEYWORDP (key)) | 114 if (!KEYWORDP (key)) |
114 signal_simple_error_2 ("Non-keyword in gui item", key, pgui_item->name); | 115 signal_simple_error_2 ("Non-keyword in gui item", key, pgui_item->name); |
115 | 116 |
116 if (EQ (key, Q_suffix)) pgui_item->suffix = val; | 117 if (EQ (key, Q_suffix)) pgui_item->suffix = val; |
130 pgui_item->accelerator = val; | 131 pgui_item->accelerator = val; |
131 else if (ERRB_EQ (errb, ERROR_ME)) | 132 else if (ERRB_EQ (errb, ERROR_ME)) |
132 signal_simple_error ("Bad keyboard accelerator", val); | 133 signal_simple_error ("Bad keyboard accelerator", val); |
133 } | 134 } |
134 else if (ERRB_EQ (errb, ERROR_ME)) | 135 else if (ERRB_EQ (errb, ERROR_ME)) |
135 signal_simple_error_2 ("Unknown keyword in gui item", key, pgui_item->name); | 136 signal_simple_error_2 ("Unknown keyword in gui item", key, |
137 pgui_item->name); | |
136 } | 138 } |
137 | 139 |
138 void | 140 void |
139 gui_item_init (Lisp_Object gui_item) | 141 gui_item_init (Lisp_Object gui_item) |
140 { | 142 { |
177 Error_behavior errb) | 179 Error_behavior errb) |
178 { | 180 { |
179 int length, plist_p, start; | 181 int length, plist_p, start; |
180 Lisp_Object *contents; | 182 Lisp_Object *contents; |
181 Lisp_Object gui_item = allocate_gui_item (); | 183 Lisp_Object gui_item = allocate_gui_item (); |
182 Lisp_Gui_Item* pgui_item = XGUI_ITEM (gui_item); | 184 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item); |
183 | 185 |
184 CHECK_VECTOR (item); | 186 CHECK_VECTOR (item); |
185 length = XVECTOR_LENGTH (item); | 187 length = XVECTOR_LENGTH (item); |
186 contents = XVECTOR_DATA (item); | 188 contents = XVECTOR_DATA (item); |
187 | 189 |
249 | 251 |
250 /* convert a gui item into plist properties */ | 252 /* convert a gui item into plist properties */ |
251 void | 253 void |
252 gui_add_item_keywords_to_plist (Lisp_Object plist, Lisp_Object gui_item) | 254 gui_add_item_keywords_to_plist (Lisp_Object plist, Lisp_Object gui_item) |
253 { | 255 { |
254 Lisp_Gui_Item* pgui_item = XGUI_ITEM (gui_item); | 256 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item); |
255 | 257 |
256 if (!NILP (pgui_item->callback)) | 258 if (!NILP (pgui_item->callback)) |
257 Fplist_put (plist, Q_callback, pgui_item->callback); | 259 Fplist_put (plist, Q_callback, pgui_item->callback); |
258 if (!NILP (pgui_item->suffix)) | 260 if (!NILP (pgui_item->suffix)) |
259 Fplist_put (plist, Q_suffix, pgui_item->suffix); | 261 Fplist_put (plist, Q_suffix, pgui_item->suffix); |
291 | 293 |
292 /* set menu accelerator key to first underlined character in menu name */ | 294 /* set menu accelerator key to first underlined character in menu name */ |
293 Lisp_Object | 295 Lisp_Object |
294 gui_item_accelerator (Lisp_Object gui_item) | 296 gui_item_accelerator (Lisp_Object gui_item) |
295 { | 297 { |
296 Lisp_Gui_Item* pgui = XGUI_ITEM (gui_item); | 298 Lisp_Gui_Item *pgui = XGUI_ITEM (gui_item); |
297 | 299 |
298 if (!NILP (pgui->accelerator)) | 300 if (!NILP (pgui->accelerator)) |
299 return pgui->accelerator; | 301 return pgui->accelerator; |
300 | 302 |
301 else | 303 else |
303 } | 305 } |
304 | 306 |
305 Lisp_Object | 307 Lisp_Object |
306 gui_name_accelerator (Lisp_Object nm) | 308 gui_name_accelerator (Lisp_Object nm) |
307 { | 309 { |
308 /* !!#### This function has not been Mule-ized */ | 310 Bufbyte *name = XSTRING_DATA (nm); |
309 char* name = (char*)XSTRING_DATA (nm); | 311 |
310 | 312 while (*name) |
311 while (*name) { | 313 { |
312 if (*name=='%') { | 314 if (*name == '%') |
313 ++name; | |
314 if (!(*name)) | |
315 return Qnil; | |
316 if (*name=='_' && *(name+1)) | |
317 { | 315 { |
318 int accelerator = (int) (unsigned char) (*(name+1)); | 316 ++name; |
319 return make_char (tolower (accelerator)); | 317 if (!(*name)) |
318 return Qnil; | |
319 if (*name == '_' && *(name + 1)) | |
320 { | |
321 Emchar accelerator = charptr_emchar (name + 1); | |
322 /* #### bogus current_buffer dependency */ | |
323 return make_char (DOWNCASE (current_buffer, accelerator)); | |
324 } | |
320 } | 325 } |
321 } | 326 INC_CHARPTR (name); |
322 ++name; | 327 } |
323 } | 328 return make_char (DOWNCASE (current_buffer, |
324 return Qnil; | 329 charptr_emchar (XSTRING_DATA (nm)))); |
325 } | 330 } |
326 | 331 |
327 /* | 332 /* |
328 * Decide whether a GUI item is selected by evaluating its :selected form | 333 * Decide whether a GUI item is selected by evaluating its :selected form |
329 * if any | 334 * if any |
345 */ | 350 */ |
346 int | 351 int |
347 gui_item_included_p (Lisp_Object gui_item, Lisp_Object conflist) | 352 gui_item_included_p (Lisp_Object gui_item, Lisp_Object conflist) |
348 { | 353 { |
349 /* This function can call lisp */ | 354 /* This function can call lisp */ |
350 Lisp_Gui_Item* pgui_item = XGUI_ITEM (gui_item); | 355 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item); |
351 | 356 |
352 /* Evaluate :included first. Shortcut to avoid evaluating Qt each time */ | 357 /* Evaluate :included first. Shortcut to avoid evaluating Qt each time */ |
353 if (!EQ (pgui_item->included, Qt) | 358 if (!EQ (pgui_item->included, Qt) |
354 && NILP (Feval (pgui_item->included))) | 359 && NILP (Feval (pgui_item->included))) |
355 return 0; | 360 return 0; |
377 * signaled. | 382 * signaled. |
378 * Return value is the offset to the terminating null character into the | 383 * Return value is the offset to the terminating null character into the |
379 * buffer. | 384 * buffer. |
380 */ | 385 */ |
381 unsigned int | 386 unsigned int |
382 gui_item_display_flush_left (Lisp_Object gui_item, | 387 gui_item_display_flush_left (Lisp_Object gui_item, |
383 char* buf, Bytecount buf_len) | 388 char *buf, Bytecount buf_len) |
384 { | 389 { |
385 /* This function can call lisp */ | 390 /* This function can call lisp */ |
386 char *p = buf; | 391 char *p = buf; |
387 Bytecount len; | 392 Bytecount len; |
388 Lisp_Gui_Item* pgui_item = XGUI_ITEM (gui_item); | 393 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item); |
389 | 394 |
390 /* Copy item name first */ | 395 /* Copy item name first */ |
391 CHECK_STRING (pgui_item->name); | 396 CHECK_STRING (pgui_item->name); |
392 len = XSTRING_LENGTH (pgui_item->name); | 397 len = XSTRING_LENGTH (pgui_item->name); |
393 if (len > buf_len) | 398 if (len > buf_len) |
427 * Return value is the offset to the terminating null character into the | 432 * Return value is the offset to the terminating null character into the |
428 * buffer. | 433 * buffer. |
429 */ | 434 */ |
430 unsigned int | 435 unsigned int |
431 gui_item_display_flush_right (Lisp_Object gui_item, | 436 gui_item_display_flush_right (Lisp_Object gui_item, |
432 char* buf, Bytecount buf_len) | 437 char *buf, Bytecount buf_len) |
433 { | 438 { |
434 Lisp_Gui_Item* pgui_item = XGUI_ITEM (gui_item); | 439 Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item); |
435 *buf = 0; | 440 *buf = 0; |
436 | 441 |
437 #ifdef HAVE_MENUBARS | 442 #ifdef HAVE_MENUBARS |
438 /* Have keys? */ | 443 /* Have keys? */ |
439 if (!menubar_show_keybindings) | 444 if (!menubar_show_keybindings) |
442 | 447 |
443 /* Try :keys first */ | 448 /* Try :keys first */ |
444 if (!NILP (pgui_item->keys)) | 449 if (!NILP (pgui_item->keys)) |
445 { | 450 { |
446 CHECK_STRING (pgui_item->keys); | 451 CHECK_STRING (pgui_item->keys); |
447 if (XSTRING_LENGTH (pgui_item->keys) > buf_len) | 452 if (XSTRING_LENGTH (pgui_item->keys) + 1 > buf_len) |
448 signal_too_long_error (pgui_item->name); | 453 signal_too_long_error (pgui_item->name); |
449 strcpy (buf, (const char *) XSTRING_DATA (pgui_item->keys)); | 454 memcpy (buf, XSTRING_DATA (pgui_item->keys), |
455 XSTRING_LENGTH (pgui_item->keys) + 1); | |
450 return XSTRING_LENGTH (pgui_item->keys); | 456 return XSTRING_LENGTH (pgui_item->keys); |
451 } | 457 } |
452 | 458 |
453 /* See if we can derive keys out of callback symbol */ | 459 /* See if we can derive keys out of callback symbol */ |
454 if (SYMBOLP (pgui_item->callback)) | 460 if (SYMBOLP (pgui_item->callback)) |
455 { | 461 { |
456 char buf2 [1024]; | 462 char buf2[1024]; /* #### */ |
457 Bytecount len; | 463 Bytecount len; |
458 | 464 |
459 where_is_to_char (pgui_item->callback, buf2); | 465 where_is_to_char (pgui_item->callback, buf2); |
460 len = strlen (buf2); | 466 len = strlen (buf2); |
461 if (len > buf_len) | 467 if (len > buf_len) |
489 | 495 |
490 return Qnil; | 496 return Qnil; |
491 } | 497 } |
492 | 498 |
493 static unsigned long | 499 static unsigned long |
494 gui_item_hash (Lisp_Object obj, int depth) | 500 gui_item_hash_internal (Lisp_Object obj, int depth) |
495 { | 501 { |
496 Lisp_Gui_Item *p = XGUI_ITEM (obj); | 502 Lisp_Gui_Item *p = XGUI_ITEM (obj); |
497 | 503 |
498 return HASH2 (HASH5 (internal_hash (p->name, depth + 1), | 504 return HASH2 (HASH5 (internal_hash (p->name, depth + 1), |
499 internal_hash (p->callback, depth + 1), | 505 internal_hash (p->callback, depth + 1), |
505 internal_hash (p->style, depth + 1), | 511 internal_hash (p->style, depth + 1), |
506 internal_hash (p->selected, depth + 1), | 512 internal_hash (p->selected, depth + 1), |
507 internal_hash (p->keys, depth + 1))); | 513 internal_hash (p->keys, depth + 1))); |
508 } | 514 } |
509 | 515 |
516 static unsigned long | |
517 gui_item_hash (Lisp_Object obj, int depth) | |
518 { | |
519 Lisp_Gui_Item *p = XGUI_ITEM (obj); | |
520 | |
521 /* Note that this evaluates the active and selected slots so that | |
522 the hash changes when the result of these changes. */ | |
523 return HASH2 (HASH5 (internal_hash (p->name, depth + 1), | |
524 internal_hash (p->callback, depth + 1), | |
525 internal_hash (p->suffix, depth + 1), | |
526 gui_item_active_p (obj), | |
527 internal_hash (p->included, depth + 1)), | |
528 HASH5 (internal_hash (p->config, depth + 1), | |
529 internal_hash (p->filter, depth + 1), | |
530 internal_hash (p->style, depth + 1), | |
531 gui_item_selected_p (obj), | |
532 internal_hash (p->keys, depth + 1))); | |
533 } | |
534 | |
510 int | 535 int |
511 gui_item_id_hash (Lisp_Object hashtable, Lisp_Object gitem, int slot) | 536 gui_item_id_hash (Lisp_Object hashtable, Lisp_Object gitem, int slot) |
512 { | 537 { |
513 int hashid = gui_item_hash (gitem, 0); | 538 int hashid = gui_item_hash_internal (gitem, 0); |
514 int id = GUI_ITEM_ID_BITS (hashid, slot); | 539 int id = GUI_ITEM_ID_BITS (hashid, slot); |
515 while (!NILP (Fgethash (make_int (id), | 540 while (!NILP (Fgethash (make_int (id), |
516 hashtable, Qnil))) | 541 hashtable, Qnil))) |
517 { | 542 { |
518 id = GUI_ITEM_ID_BITS (id + 1, slot); | 543 id = GUI_ITEM_ID_BITS (id + 1, slot); |
568 /* parse a glyph descriptor into a tree of gui items. | 593 /* parse a glyph descriptor into a tree of gui items. |
569 | 594 |
570 The gui_item slot of an image instance can be a single item or an | 595 The gui_item slot of an image instance can be a single item or an |
571 arbitrarily nested hierarchy of item lists. */ | 596 arbitrarily nested hierarchy of item lists. */ |
572 | 597 |
573 static Lisp_Object parse_gui_item_tree_item (Lisp_Object entry) | 598 static Lisp_Object |
599 parse_gui_item_tree_item (Lisp_Object entry) | |
574 { | 600 { |
575 Lisp_Object ret = entry; | 601 Lisp_Object ret = entry; |
602 struct gcpro gcpro1; | |
603 | |
604 GCPRO1 (ret); | |
605 | |
576 if (VECTORP (entry)) | 606 if (VECTORP (entry)) |
577 { | 607 { |
578 ret = gui_parse_item_keywords_no_errors (entry); | 608 ret = gui_parse_item_keywords_no_errors (entry); |
579 } | 609 } |
580 else if (STRINGP (entry)) | 610 else if (STRINGP (entry)) |
581 { | 611 { |
582 CHECK_STRING (entry); | 612 CHECK_STRING (entry); |
583 } | 613 } |
584 else | 614 else |
585 signal_simple_error ("item must be a vector or a string", entry); | 615 signal_simple_error ("item must be a vector or a string", entry); |
586 | 616 |
587 return ret; | 617 RETURN_UNGCPRO (ret); |
588 } | 618 } |
589 | 619 |
590 Lisp_Object parse_gui_item_tree_children (Lisp_Object list) | 620 Lisp_Object |
591 { | 621 parse_gui_item_tree_children (Lisp_Object list) |
592 Lisp_Object rest, ret = Qnil; | 622 { |
623 Lisp_Object rest, ret = Qnil, sub = Qnil; | |
624 struct gcpro gcpro1, gcpro2; | |
625 | |
626 GCPRO2 (ret, sub); | |
593 CHECK_CONS (list); | 627 CHECK_CONS (list); |
594 /* recursively add items to the tree view */ | 628 /* recursively add items to the tree view */ |
595 LIST_LOOP (rest, list) | 629 LIST_LOOP (rest, list) |
596 { | 630 { |
597 Lisp_Object sub; | |
598 if (CONSP (XCAR (rest))) | 631 if (CONSP (XCAR (rest))) |
599 sub = parse_gui_item_tree_list (XCAR (rest)); | 632 sub = parse_gui_item_tree_list (XCAR (rest)); |
600 else | 633 else |
601 sub = parse_gui_item_tree_item (XCAR (rest)); | 634 sub = parse_gui_item_tree_item (XCAR (rest)); |
602 | 635 |
603 ret = Fcons (sub, ret); | 636 ret = Fcons (sub, ret); |
604 } | 637 } |
605 /* make the order the same as the items we have parsed */ | 638 /* make the order the same as the items we have parsed */ |
606 return Fnreverse (ret); | 639 RETURN_UNGCPRO (Fnreverse (ret)); |
607 } | 640 } |
608 | 641 |
609 static Lisp_Object parse_gui_item_tree_list (Lisp_Object list) | 642 static Lisp_Object |
643 parse_gui_item_tree_list (Lisp_Object list) | |
610 { | 644 { |
611 Lisp_Object ret; | 645 Lisp_Object ret; |
646 struct gcpro gcpro1; | |
612 CHECK_CONS (list); | 647 CHECK_CONS (list); |
613 /* first one can never be a list */ | 648 /* first one can never be a list */ |
614 ret = parse_gui_item_tree_item (XCAR (list)); | 649 ret = parse_gui_item_tree_item (XCAR (list)); |
615 return Fcons (ret, parse_gui_item_tree_children (XCDR (list))); | 650 GCPRO1 (ret); |
651 ret = Fcons (ret, parse_gui_item_tree_children (XCDR (list))); | |
652 RETURN_UNGCPRO (ret); | |
653 } | |
654 | |
655 static void | |
656 finalize_gui_item (void* header, int for_disksave) | |
657 { | |
616 } | 658 } |
617 | 659 |
618 DEFINE_LRECORD_IMPLEMENTATION ("gui-item", gui_item, | 660 DEFINE_LRECORD_IMPLEMENTATION ("gui-item", gui_item, |
619 mark_gui_item, print_gui_item, | 661 mark_gui_item, print_gui_item, |
620 0, gui_item_equal, | 662 finalize_gui_item, gui_item_equal, |
621 gui_item_hash, | 663 gui_item_hash, |
622 0, | 664 0, |
623 Lisp_Gui_Item); | 665 Lisp_Gui_Item); |
624 | 666 |
625 void | 667 void |