comparison src/menubar-msw.c @ 363:972bbb6d6ca2 r21-1-11

Import from CVS: tag r21-1-11
author cvs
date Mon, 13 Aug 2007 10:59:28 +0200
parents fbbf69b4e8a7
children a4f53d9b3154
comparison
equal deleted inserted replaced
362:1e474c183006 363:972bbb6d6ca2
275 { 275 {
276 /* Submenu */ 276 /* Submenu */
277 HMENU submenu; 277 HMENU submenu;
278 struct gui_item gui_item; 278 struct gui_item gui_item;
279 struct gcpro gcpro1; 279 struct gcpro gcpro1;
280 struct gcpro ngcpro1;
280 281
281 gui_item_init (&gui_item); 282 gui_item_init (&gui_item);
282 GCPRO_GUI_ITEM (&gui_item); 283 GCPRO_GUI_ITEM (&gui_item);
284 NGCPRO1 (path);
283 285
284 menu_parse_submenu_keywords (item, &gui_item); 286 menu_parse_submenu_keywords (item, &gui_item);
285 287
286 if (!STRINGP (gui_item.name)) 288 if (!STRINGP (gui_item.name))
287 signal_simple_error ("Menu name (first element) must be a string", item); 289 signal_simple_error ("Menu name (first element) must be a string", item);
288 290
289 if (!gui_item_included_p (&gui_item, Vmenubar_configuration)) 291 if (!gui_item_included_p (&gui_item, Vmenubar_configuration))
290 return; 292 {
293 NUNGCPRO;
294 UNGCPRO;
295 return;
296 }
291 297
292 if (!gui_item_active_p (&gui_item)) 298 if (!gui_item_active_p (&gui_item))
293 item_info.fState = MFS_GRAYED; 299 item_info.fState = MFS_GRAYED;
294 /* Temptation is to put 'else' right here. Although, the 300 /* Temptation is to put 'else' right here. Although, the
295 displayed item won't have an arrow indicating that it is a 301 displayed item won't have an arrow indicating that it is a
317 } 323 }
318 324
319 /* Fputhash GCPRO'es PATH */ 325 /* Fputhash GCPRO'es PATH */
320 Fputhash (hmenu_to_lisp_object (submenu), path, hash_tab); 326 Fputhash (hmenu_to_lisp_object (submenu), path, hash_tab);
321 } 327 }
328 NUNGCPRO;
322 UNGCPRO; /* gui_item */ 329 UNGCPRO; /* gui_item */
323 } 330 }
324 else if (VECTORP (item)) 331 else if (VECTORP (item))
325 { 332 {
326 /* An ordinary item */ 333 /* An ordinary item */
391 Lisp_Object item_desc; 398 Lisp_Object item_desc;
392 int deep_p, flush_right; 399 int deep_p, flush_right;
393 struct gcpro gcpro1; 400 struct gcpro gcpro1;
394 unsigned long checksum; 401 unsigned long checksum;
395 struct gui_item gui_item; 402 struct gui_item gui_item;
403 struct gcpro ngcpro1;
396 404
397 gui_item_init (&gui_item); 405 gui_item_init (&gui_item);
398 GCPRO_GUI_ITEM (&gui_item); 406 GCPRO_GUI_ITEM (&gui_item);
407 NGCPRO1 (desc);
399 408
400 /* We are sometimes called with the menubar unchanged, and with changed 409 /* We are sometimes called with the menubar unchanged, and with changed
401 right flush. We have to update the menubar in ths case, 410 right flush. We have to update the menubar in ths case,
402 so account for the compliance setting in the hash value */ 411 so account for the compliance setting in the hash value */
403 checksum = REPLACE_ME_WITH_GLOBAL_VARIABLE_WHICH_CONTROLS_RIHGT_FLUSH; 412 checksum = REPLACE_ME_WITH_GLOBAL_VARIABLE_WHICH_CONTROLS_RIHGT_FLUSH;
456 0, XSTRING_DATA(gui_item.name)); 465 0, XSTRING_DATA(gui_item.name));
457 InsertMenu (menu, 1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL); 466 InsertMenu (menu, 1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
458 SetMenuDefaultItem (menu, 0, MF_BYPOSITION); 467 SetMenuDefaultItem (menu, 0, MF_BYPOSITION);
459 } 468 }
460 } 469 }
470 NUNGCPRO;
461 UNGCPRO; /* gui_item */ 471 UNGCPRO; /* gui_item */
462 return checksum; 472 return checksum;
463 } 473 }
464 474
465 static void 475 static void
481 HMENU menubar = GetMenu (FRAME_MSWINDOWS_HANDLE (f)); 491 HMENU menubar = GetMenu (FRAME_MSWINDOWS_HANDLE (f));
482 struct window *w = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f)); 492 struct window *w = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f));
483 Lisp_Object desc = (!NILP (w->menubar_visible_p) 493 Lisp_Object desc = (!NILP (w->menubar_visible_p)
484 ? symbol_value_in_buffer (Qcurrent_menubar, w->buffer) 494 ? symbol_value_in_buffer (Qcurrent_menubar, w->buffer)
485 : Qnil); 495 : Qnil);
496 struct gcpro gcpro1;
497
498 GCPRO1 (desc); /* it's safest to do this, just in case some filter
499 or something changes the value of current-menubar */
486 500
487 top_level_menu = menubar; 501 top_level_menu = menubar;
488 502
489 if (NILP (desc) && menubar != NULL) 503 if (NILP (desc) && menubar != NULL)
490 { 504 {
491 /* Menubar has gone */ 505 /* Menubar has gone */
492 FRAME_MSWINDOWS_MENU_HASHTABLE(f) = Qnil; 506 FRAME_MSWINDOWS_MENU_HASHTABLE(f) = Qnil;
493 SetMenu (FRAME_MSWINDOWS_HANDLE (f), NULL); 507 SetMenu (FRAME_MSWINDOWS_HANDLE (f), NULL);
494 DestroyMenu (menubar); 508 DestroyMenu (menubar);
495 DrawMenuBar (FRAME_MSWINDOWS_HANDLE (f)); 509 DrawMenuBar (FRAME_MSWINDOWS_HANDLE (f));
510 UNGCPRO;
496 return; 511 return;
497 } 512 }
498 513
499 if (!NILP (desc) && menubar == NULL) 514 if (!NILP (desc) && menubar == NULL)
500 { 515 {
504 } 519 }
505 520
506 if (NILP (desc)) 521 if (NILP (desc))
507 { 522 {
508 /* We did not have the bar and are not going to */ 523 /* We did not have the bar and are not going to */
524 UNGCPRO;
509 return; 525 return;
510 } 526 }
511 527
512 /* Now we bail out if the menubar has not changed */ 528 /* Now we bail out if the menubar has not changed */
513 if (FRAME_MSWINDOWS_MENU_CHECKSUM(f) == checksum_menu (desc)) 529 if (FRAME_MSWINDOWS_MENU_CHECKSUM(f) == checksum_menu (desc))
514 return; 530 {
531 UNGCPRO;
532 return;
533 }
515 534
516 populate: 535 populate:
517 /* Come with empty hash table */ 536 /* Come with empty hash table */
518 if (NILP (FRAME_MSWINDOWS_MENU_HASHTABLE(f))) 537 if (NILP (FRAME_MSWINDOWS_MENU_HASHTABLE(f)))
519 FRAME_MSWINDOWS_MENU_HASHTABLE(f) = Fmake_hashtable (make_int (50), Qequal); 538 FRAME_MSWINDOWS_MENU_HASHTABLE(f) = Fmake_hashtable (make_int (50), Qequal);
526 FRAME_MSWINDOWS_MENU_HASHTABLE(f), 1); 545 FRAME_MSWINDOWS_MENU_HASHTABLE(f), 1);
527 SetMenu (FRAME_MSWINDOWS_HANDLE (f), menubar); 546 SetMenu (FRAME_MSWINDOWS_HANDLE (f), menubar);
528 DrawMenuBar (FRAME_MSWINDOWS_HANDLE (f)); 547 DrawMenuBar (FRAME_MSWINDOWS_HANDLE (f));
529 548
530 FRAME_MSWINDOWS_MENU_CHECKSUM(f) = checksum_menu (desc); 549 FRAME_MSWINDOWS_MENU_CHECKSUM(f) = checksum_menu (desc);
550
551 UNGCPRO;
531 } 552 }
532 553
533 static void 554 static void
534 prune_menubar (struct frame *f) 555 prune_menubar (struct frame *f)
535 { 556 {
536 HMENU menubar = GetMenu (FRAME_MSWINDOWS_HANDLE (f)); 557 HMENU menubar = GetMenu (FRAME_MSWINDOWS_HANDLE (f));
537 Lisp_Object desc = current_frame_menubar (f); 558 Lisp_Object desc = current_frame_menubar (f);
559 struct gcpro gcpro1;
560
538 if (menubar == NULL) 561 if (menubar == NULL)
539 return; 562 return;
540 563
541 /* #### If a filter function has set desc to Qnil, this abort() 564 /* #### If a filter function has set desc to Qnil, this abort()
542 triggers. To resolve, we must prevent filters explicitely from 565 triggers. To resolve, we must prevent filters explicitely from
544 Is copy-tree on the whole menu too expensive? */ 567 Is copy-tree on the whole menu too expensive? */
545 if (NILP(desc)) 568 if (NILP(desc))
546 /* abort(); */ 569 /* abort(); */
547 return; 570 return;
548 571
572 GCPRO1 (desc); /* just to be safe -- see above */
549 /* We do the trick by removing all items and re-populating top level */ 573 /* We do the trick by removing all items and re-populating top level */
550 empty_menu (menubar, 0); 574 empty_menu (menubar, 0);
551 575
552 assert (HASHTABLEP (FRAME_MSWINDOWS_MENU_HASHTABLE(f))); 576 assert (HASHTABLEP (FRAME_MSWINDOWS_MENU_HASHTABLE(f)));
553 Fclrhash (FRAME_MSWINDOWS_MENU_HASHTABLE(f)); 577 Fclrhash (FRAME_MSWINDOWS_MENU_HASHTABLE(f));
554 578
555 Fputhash (hmenu_to_lisp_object (menubar), Qnil, 579 Fputhash (hmenu_to_lisp_object (menubar), Qnil,
556 FRAME_MSWINDOWS_MENU_HASHTABLE(f)); 580 FRAME_MSWINDOWS_MENU_HASHTABLE(f));
557 populate_menu (menubar, Qnil, desc, 581 populate_menu (menubar, Qnil, desc,
558 FRAME_MSWINDOWS_MENU_HASHTABLE(f), 1); 582 FRAME_MSWINDOWS_MENU_HASHTABLE(f), 1);
583 UNGCPRO;
559 } 584 }
560 585
561 /* 586 /*
562 * This is called when cleanup is possible. It is better not to 587 * This is called when cleanup is possible. It is better not to
563 * clean things up at all than do it too earaly! 588 * clean things up at all than do it too earaly!
734 struct frame *f = selected_frame (); 759 struct frame *f = selected_frame ();
735 struct Lisp_Event *eev = NULL; 760 struct Lisp_Event *eev = NULL;
736 HMENU menu; 761 HMENU menu;
737 POINT pt; 762 POINT pt;
738 int ok; 763 int ok;
764 struct gcpro gcpro1;
765
766 GCPRO1 (menu_desc); /* to be safe -- see above */
739 767
740 if (!NILP (event)) 768 if (!NILP (event))
741 { 769 {
742 CHECK_LIVE_EVENT (event); 770 CHECK_LIVE_EVENT (event);
743 eev = XEVENT (event); 771 eev = XEVENT (event);
794 if (!ok) { 822 if (!ok) {
795 menu_cleanup (f); 823 menu_cleanup (f);
796 signal_simple_error ("Cannot track popup menu while in menu", 824 signal_simple_error ("Cannot track popup menu while in menu",
797 menu_desc); 825 menu_desc);
798 } 826 }
827 UNGCPRO;
799 } 828 }
800 829
801 830
802 /*------------------------------------------------------------------------*/ 831 /*------------------------------------------------------------------------*/
803 /* Initialization */ 832 /* Initialization */