diff options
| author | YAMAMOTO Mitsuharu | 2007-01-05 08:30:05 +0000 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2007-01-05 08:30:05 +0000 |
| commit | 0aea47c1ee664c4282ae14fb558ff8278659b12c (patch) | |
| tree | deda39dcc403540331fd1fa3963d22ae3a963274 /src | |
| parent | 3bfd2d469042762e29fc0e9b5fc616fcf2bb0b54 (diff) | |
| download | emacs-0aea47c1ee664c4282ae14fb558ff8278659b12c.tar.gz emacs-0aea47c1ee664c4282ae14fb558ff8278659b12c.zip | |
(Vshow_help_function) [TARGET_API_MAC_CARBON]: Add extern.
(restore_show_help_function, menu_target_item_handler)
[TARGET_API_MAC_CARBON]: New functions.
(install_menu_target_item_handler): New function.
(add_menu_item) [TARGET_API_MAC_CARBON]: Set help string as menu
item property.
Diffstat (limited to 'src')
| -rw-r--r-- | src/macmenu.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/macmenu.c b/src/macmenu.c index 14bfe92cb25..9981250979a 100644 --- a/src/macmenu.c +++ b/src/macmenu.c | |||
| @@ -1450,6 +1450,80 @@ update_submenu_strings (first_wv) | |||
| 1450 | } | 1450 | } |
| 1451 | 1451 | ||
| 1452 | 1452 | ||
| 1453 | #if TARGET_API_MAC_CARBON | ||
| 1454 | extern Lisp_Object Vshow_help_function; | ||
| 1455 | |||
| 1456 | static Lisp_Object | ||
| 1457 | restore_show_help_function (old_show_help_function) | ||
| 1458 | Lisp_Object old_show_help_function; | ||
| 1459 | { | ||
| 1460 | Vshow_help_function = old_show_help_function; | ||
| 1461 | |||
| 1462 | return Qnil; | ||
| 1463 | } | ||
| 1464 | |||
| 1465 | static pascal OSStatus | ||
| 1466 | menu_target_item_handler (next_handler, event, data) | ||
| 1467 | EventHandlerCallRef next_handler; | ||
| 1468 | EventRef event; | ||
| 1469 | void *data; | ||
| 1470 | { | ||
| 1471 | OSStatus err, result; | ||
| 1472 | MenuRef menu; | ||
| 1473 | MenuItemIndex menu_item; | ||
| 1474 | Lisp_Object help; | ||
| 1475 | GrafPtr port; | ||
| 1476 | int specpdl_count = SPECPDL_INDEX (); | ||
| 1477 | |||
| 1478 | result = CallNextEventHandler (next_handler, event); | ||
| 1479 | |||
| 1480 | err = GetEventParameter (event, kEventParamDirectObject, typeMenuRef, | ||
| 1481 | NULL, sizeof (MenuRef), NULL, &menu); | ||
| 1482 | if (err == noErr) | ||
| 1483 | err = GetEventParameter (event, kEventParamMenuItemIndex, | ||
| 1484 | typeMenuItemIndex, NULL, | ||
| 1485 | sizeof (MenuItemIndex), NULL, &menu_item); | ||
| 1486 | if (err == noErr) | ||
| 1487 | err = GetMenuItemProperty (menu, menu_item, | ||
| 1488 | MAC_EMACS_CREATOR_CODE, 'help', | ||
| 1489 | sizeof (Lisp_Object), NULL, &help); | ||
| 1490 | if (err != noErr) | ||
| 1491 | help = Qnil; | ||
| 1492 | |||
| 1493 | /* Temporarily bind Vshow_help_function to Qnil because we don't | ||
| 1494 | want tooltips during menu tracking. */ | ||
| 1495 | record_unwind_protect (restore_show_help_function, Vshow_help_function); | ||
| 1496 | Vshow_help_function = Qnil; | ||
| 1497 | GetPort (&port); | ||
| 1498 | show_help_echo (help, Qnil, Qnil, Qnil, 1); | ||
| 1499 | SetPort (port); | ||
| 1500 | unbind_to (specpdl_count, Qnil); | ||
| 1501 | |||
| 1502 | return err == noErr ? noErr : result; | ||
| 1503 | } | ||
| 1504 | #endif | ||
| 1505 | |||
| 1506 | OSStatus | ||
| 1507 | install_menu_target_item_handler (window) | ||
| 1508 | WindowPtr window; | ||
| 1509 | { | ||
| 1510 | OSStatus err = noErr; | ||
| 1511 | #if TARGET_API_MAC_CARBON | ||
| 1512 | static const EventTypeSpec specs[] = | ||
| 1513 | {{kEventClassMenu, kEventMenuTargetItem}}; | ||
| 1514 | static EventHandlerUPP menu_target_item_handlerUPP = NULL; | ||
| 1515 | |||
| 1516 | if (menu_target_item_handlerUPP == NULL) | ||
| 1517 | menu_target_item_handlerUPP = | ||
| 1518 | NewEventHandlerUPP (menu_target_item_handler); | ||
| 1519 | |||
| 1520 | err = InstallWindowEventHandler (window, menu_target_item_handlerUPP, | ||
| 1521 | GetEventTypeCount (specs), specs, | ||
| 1522 | NULL, NULL); | ||
| 1523 | #endif | ||
| 1524 | return err; | ||
| 1525 | } | ||
| 1526 | |||
| 1453 | /* Event handler function that pops down a menu on C-g. We can only pop | 1527 | /* Event handler function that pops down a menu on C-g. We can only pop |
| 1454 | down menus if CancelMenuTracking is present (OSX 10.3 or later). */ | 1528 | down menus if CancelMenuTracking is present (OSX 10.3 or later). */ |
| 1455 | 1529 | ||
| @@ -2485,6 +2559,10 @@ add_menu_item (menu, pos, wv) | |||
| 2485 | EnableMenuItem (menu, pos); | 2559 | EnableMenuItem (menu, pos); |
| 2486 | else | 2560 | else |
| 2487 | DisableMenuItem (menu, pos); | 2561 | DisableMenuItem (menu, pos); |
| 2562 | |||
| 2563 | if (STRINGP (wv->help)) | ||
| 2564 | SetMenuItemProperty (menu, pos, MAC_EMACS_CREATOR_CODE, 'help', | ||
| 2565 | sizeof (Lisp_Object), &wv->help); | ||
| 2488 | #else /* ! TARGET_API_MAC_CARBON */ | 2566 | #else /* ! TARGET_API_MAC_CARBON */ |
| 2489 | item_name[sizeof (item_name) - 1] = '\0'; | 2567 | item_name[sizeof (item_name) - 1] = '\0'; |
| 2490 | strncpy (item_name, wv->name, sizeof (item_name) - 1); | 2568 | strncpy (item_name, wv->name, sizeof (item_name) - 1); |