diff options
| author | YAMAMOTO Mitsuharu | 2007-06-07 08:44:33 +0000 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2007-06-07 08:44:33 +0000 |
| commit | b52ee0bd9a59abc2c164144c8f1c83d38d2f06ce (patch) | |
| tree | ddb4a33beb7e29eefc86062411627ac2e19fa350 /src | |
| parent | 1f23bcb73b4079ab2bd7f0d5cc481744686b4fe7 (diff) | |
| download | emacs-b52ee0bd9a59abc2c164144c8f1c83d38d2f06ce.tar.gz emacs-b52ee0bd9a59abc2c164144c8f1c83d38d2f06ce.zip | |
[TARGET_API_MAC_CARBON] (menu_target_item_handler):
Don't call next handler.
[TARGET_API_MAC_CARBON] (install_menu_target_item_handler):
Remove argument. Install handler to application.
(set_frame_menubar): Don't change deep_p.
(mac_menu_show): Use FRAME_OUTER_TO_INNER_DIFF_X and
FRAME_OUTER_TO_INNER_DIFF_Y.
(DIALOG_BUTTON_COMMAND_ID_OFFSET, DIALOG_BUTTON_COMMAND_ID_P)
(DIALOG_BUTTON_COMMAND_ID_VALUE, DIALOG_BUTTON_MAKE_COMMAND_ID)
[HAVE_DIALOGS]: New macros.
[HAVE_DIALOGS] (mac_handle_dialog_event, create_and_show_dialog):
Use them.
(fill_menubar) [TARGET_API_MAC_CARBON]: Use CFString.
Diffstat (limited to 'src')
| -rw-r--r-- | src/macmenu.c | 115 |
1 files changed, 72 insertions, 43 deletions
diff --git a/src/macmenu.c b/src/macmenu.c index 098457a3f36..5e6ad6f7d10 100644 --- a/src/macmenu.c +++ b/src/macmenu.c | |||
| @@ -1595,15 +1595,13 @@ menu_target_item_handler (next_handler, event, data) | |||
| 1595 | EventRef event; | 1595 | EventRef event; |
| 1596 | void *data; | 1596 | void *data; |
| 1597 | { | 1597 | { |
| 1598 | OSStatus err, result; | 1598 | OSStatus err; |
| 1599 | MenuRef menu; | 1599 | MenuRef menu; |
| 1600 | MenuItemIndex menu_item; | 1600 | MenuItemIndex menu_item; |
| 1601 | Lisp_Object help; | 1601 | Lisp_Object help; |
| 1602 | GrafPtr port; | 1602 | GrafPtr port; |
| 1603 | int specpdl_count = SPECPDL_INDEX (); | 1603 | int specpdl_count = SPECPDL_INDEX (); |
| 1604 | 1604 | ||
| 1605 | result = CallNextEventHandler (next_handler, event); | ||
| 1606 | |||
| 1607 | err = GetEventParameter (event, kEventParamDirectObject, typeMenuRef, | 1605 | err = GetEventParameter (event, kEventParamDirectObject, typeMenuRef, |
| 1608 | NULL, sizeof (MenuRef), NULL, &menu); | 1606 | NULL, sizeof (MenuRef), NULL, &menu); |
| 1609 | if (err == noErr) | 1607 | if (err == noErr) |
| @@ -1626,30 +1624,21 @@ menu_target_item_handler (next_handler, event, data) | |||
| 1626 | SetPort (port); | 1624 | SetPort (port); |
| 1627 | unbind_to (specpdl_count, Qnil); | 1625 | unbind_to (specpdl_count, Qnil); |
| 1628 | 1626 | ||
| 1629 | return err == noErr ? noErr : result; | 1627 | return err == noErr ? noErr : eventNotHandledErr; |
| 1630 | } | 1628 | } |
| 1631 | #endif | ||
| 1632 | 1629 | ||
| 1633 | OSStatus | 1630 | OSStatus |
| 1634 | install_menu_target_item_handler (window) | 1631 | install_menu_target_item_handler () |
| 1635 | WindowRef window; | ||
| 1636 | { | 1632 | { |
| 1637 | OSStatus err = noErr; | ||
| 1638 | #if TARGET_API_MAC_CARBON | ||
| 1639 | static const EventTypeSpec specs[] = | 1633 | static const EventTypeSpec specs[] = |
| 1640 | {{kEventClassMenu, kEventMenuTargetItem}}; | 1634 | {{kEventClassMenu, kEventMenuTargetItem}}; |
| 1641 | static EventHandlerUPP menu_target_item_handlerUPP = NULL; | ||
| 1642 | 1635 | ||
| 1643 | if (menu_target_item_handlerUPP == NULL) | 1636 | return InstallApplicationEventHandler (NewEventHandlerUPP |
| 1644 | menu_target_item_handlerUPP = | 1637 | (menu_target_item_handler), |
| 1645 | NewEventHandlerUPP (menu_target_item_handler); | 1638 | GetEventTypeCount (specs), |
| 1646 | 1639 | specs, NULL, NULL); | |
| 1647 | err = InstallWindowEventHandler (window, menu_target_item_handlerUPP, | ||
| 1648 | GetEventTypeCount (specs), specs, | ||
| 1649 | NULL, NULL); | ||
| 1650 | #endif | ||
| 1651 | return err; | ||
| 1652 | } | 1640 | } |
| 1641 | #endif /* TARGET_API_MAC_CARBON */ | ||
| 1653 | 1642 | ||
| 1654 | /* Event handler function that pops down a menu on C-g. We can only pop | 1643 | /* Event handler function that pops down a menu on C-g. We can only pop |
| 1655 | down menus if CancelMenuTracking is present (OSX 10.3 or later). */ | 1644 | down menus if CancelMenuTracking is present (OSX 10.3 or later). */ |
| @@ -1738,10 +1727,13 @@ set_frame_menubar (f, first_time, deep_p) | |||
| 1738 | 1727 | ||
| 1739 | XSETFRAME (Vmenu_updating_frame, f); | 1728 | XSETFRAME (Vmenu_updating_frame, f); |
| 1740 | 1729 | ||
| 1730 | /* This seems to be unnecessary for Carbon. */ | ||
| 1731 | #if 0 | ||
| 1741 | if (! menubar_widget) | 1732 | if (! menubar_widget) |
| 1742 | deep_p = 1; | 1733 | deep_p = 1; |
| 1743 | else if (pending_menu_activation && !deep_p) | 1734 | else if (pending_menu_activation && !deep_p) |
| 1744 | deep_p = 1; | 1735 | deep_p = 1; |
| 1736 | #endif | ||
| 1745 | 1737 | ||
| 1746 | if (deep_p) | 1738 | if (deep_p) |
| 1747 | { | 1739 | { |
| @@ -2025,7 +2017,6 @@ mac_menu_show (f, x, y, for_click, keymaps, title, error) | |||
| 2025 | int menu_item_choice; | 2017 | int menu_item_choice; |
| 2026 | UInt32 menu_item_selection; | 2018 | UInt32 menu_item_selection; |
| 2027 | MenuRef menu; | 2019 | MenuRef menu; |
| 2028 | Point pos; | ||
| 2029 | widget_value *wv, *save_wv = 0, *first_wv = 0, *prev_wv = 0; | 2020 | widget_value *wv, *save_wv = 0, *first_wv = 0, *prev_wv = 0; |
| 2030 | widget_value **submenu_stack | 2021 | widget_value **submenu_stack |
| 2031 | = (widget_value **) alloca (menu_items_used * sizeof (widget_value *)); | 2022 | = (widget_value **) alloca (menu_items_used * sizeof (widget_value *)); |
| @@ -2231,11 +2222,8 @@ mac_menu_show (f, x, y, for_click, keymaps, title, error) | |||
| 2231 | free_menubar_widget_value_tree (first_wv); | 2222 | free_menubar_widget_value_tree (first_wv); |
| 2232 | 2223 | ||
| 2233 | /* Adjust coordinates to be root-window-relative. */ | 2224 | /* Adjust coordinates to be root-window-relative. */ |
| 2234 | pos.h = x; | 2225 | x += f->left_pos + FRAME_OUTER_TO_INNER_DIFF_X (f); |
| 2235 | pos.v = y; | 2226 | y += f->top_pos + FRAME_OUTER_TO_INNER_DIFF_Y (f); |
| 2236 | |||
| 2237 | SetPortWindowPort (FRAME_MAC_WINDOW (f)); | ||
| 2238 | LocalToGlobal (&pos); | ||
| 2239 | 2227 | ||
| 2240 | /* No selection has been chosen yet. */ | 2228 | /* No selection has been chosen yet. */ |
| 2241 | menu_item_selection = 0; | 2229 | menu_item_selection = 0; |
| @@ -2248,7 +2236,7 @@ mac_menu_show (f, x, y, for_click, keymaps, title, error) | |||
| 2248 | 2236 | ||
| 2249 | /* Display the menu. */ | 2237 | /* Display the menu. */ |
| 2250 | popup_activated_flag = 1; | 2238 | popup_activated_flag = 1; |
| 2251 | menu_item_choice = PopUpMenuSelect (menu, pos.v, pos.h, 0); | 2239 | menu_item_choice = PopUpMenuSelect (menu, y, x, 0); |
| 2252 | popup_activated_flag = 0; | 2240 | popup_activated_flag = 0; |
| 2253 | 2241 | ||
| 2254 | /* Get the refcon to find the correct item */ | 2242 | /* Get the refcon to find the correct item */ |
| @@ -2330,6 +2318,14 @@ mac_menu_show (f, x, y, for_click, keymaps, title, error) | |||
| 2330 | 2318 | ||
| 2331 | #if TARGET_API_MAC_CARBON | 2319 | #if TARGET_API_MAC_CARBON |
| 2332 | 2320 | ||
| 2321 | #define DIALOG_BUTTON_COMMAND_ID_OFFSET 'Bt\0\0' | ||
| 2322 | #define DIALOG_BUTTON_COMMAND_ID_P(id) \ | ||
| 2323 | (((id) & ~0xffff) == DIALOG_BUTTON_COMMAND_ID_OFFSET) | ||
| 2324 | #define DIALOG_BUTTON_COMMAND_ID_VALUE(id) \ | ||
| 2325 | ((id) - DIALOG_BUTTON_COMMAND_ID_OFFSET) | ||
| 2326 | #define DIALOG_BUTTON_MAKE_COMMAND_ID(value) \ | ||
| 2327 | ((value) + DIALOG_BUTTON_COMMAND_ID_OFFSET) | ||
| 2328 | |||
| 2333 | static pascal OSStatus | 2329 | static pascal OSStatus |
| 2334 | mac_handle_dialog_event (next_handler, event, data) | 2330 | mac_handle_dialog_event (next_handler, event, data) |
| 2335 | EventHandlerCallRef next_handler; | 2331 | EventHandlerCallRef next_handler; |
| @@ -2349,7 +2345,7 @@ mac_handle_dialog_event (next_handler, event, data) | |||
| 2349 | typeHICommand, NULL, sizeof (HICommand), | 2345 | typeHICommand, NULL, sizeof (HICommand), |
| 2350 | NULL, &command); | 2346 | NULL, &command); |
| 2351 | if (err == noErr) | 2347 | if (err == noErr) |
| 2352 | if ((command.commandID & ~0xffff) == 'Bt\0\0') | 2348 | if (DIALOG_BUTTON_COMMAND_ID_P (command.commandID)) |
| 2353 | { | 2349 | { |
| 2354 | SetWRefCon (window, command.commandID); | 2350 | SetWRefCon (window, command.commandID); |
| 2355 | err = QuitAppModalLoopForWindow (window); | 2351 | err = QuitAppModalLoopForWindow (window); |
| @@ -2402,7 +2398,10 @@ mac_handle_dialog_event (next_handler, event, data) | |||
| 2402 | break; | 2398 | break; |
| 2403 | } | 2399 | } |
| 2404 | 2400 | ||
| 2405 | return err == noErr ? noErr : result; | 2401 | if (err == noErr) |
| 2402 | result = noErr; | ||
| 2403 | |||
| 2404 | return result; | ||
| 2406 | } | 2405 | } |
| 2407 | break; | 2406 | break; |
| 2408 | 2407 | ||
| @@ -2518,14 +2517,16 @@ create_and_show_dialog (f, first_wv) | |||
| 2518 | } | 2517 | } |
| 2519 | if (err == noErr) | 2518 | if (err == noErr) |
| 2520 | { | 2519 | { |
| 2520 | UInt32 command_id; | ||
| 2521 | |||
| 2521 | OffsetRect (&rects[i], -rects[i].left, -rects[i].top); | 2522 | OffsetRect (&rects[i], -rects[i].left, -rects[i].top); |
| 2522 | if (rects[i].right < DIALOG_BUTTON_MIN_WIDTH) | 2523 | if (rects[i].right < DIALOG_BUTTON_MIN_WIDTH) |
| 2523 | rects[i].right = DIALOG_BUTTON_MIN_WIDTH; | 2524 | rects[i].right = DIALOG_BUTTON_MIN_WIDTH; |
| 2524 | else if (rects[i].right > DIALOG_MAX_INNER_WIDTH) | 2525 | else if (rects[i].right > DIALOG_MAX_INNER_WIDTH) |
| 2525 | rects[i].right = DIALOG_MAX_INNER_WIDTH; | 2526 | rects[i].right = DIALOG_MAX_INNER_WIDTH; |
| 2526 | 2527 | ||
| 2527 | err = SetControlCommandID (buttons[i], | 2528 | command_id = DIALOG_BUTTON_MAKE_COMMAND_ID ((int) wv->call_data); |
| 2528 | 'Bt\0\0' + (int) wv->call_data); | 2529 | err = SetControlCommandID (buttons[i], command_id); |
| 2529 | } | 2530 | } |
| 2530 | if (err != noErr) | 2531 | if (err != noErr) |
| 2531 | break; | 2532 | break; |
| @@ -2702,8 +2703,8 @@ create_and_show_dialog (f, first_wv) | |||
| 2702 | { | 2703 | { |
| 2703 | UInt32 command_id = GetWRefCon (window); | 2704 | UInt32 command_id = GetWRefCon (window); |
| 2704 | 2705 | ||
| 2705 | if ((command_id & ~0xffff) == 'Bt\0\0') | 2706 | if (DIALOG_BUTTON_COMMAND_ID_P (command_id)) |
| 2706 | result = command_id - 'Bt\0\0'; | 2707 | result = DIALOG_BUTTON_COMMAND_ID_VALUE (command_id); |
| 2707 | } | 2708 | } |
| 2708 | 2709 | ||
| 2709 | if (window) | 2710 | if (window) |
| @@ -3139,8 +3140,6 @@ fill_menubar (wv, deep_p) | |||
| 3139 | int deep_p; | 3140 | int deep_p; |
| 3140 | { | 3141 | { |
| 3141 | int id, submenu_id; | 3142 | int id, submenu_id; |
| 3142 | MenuRef menu; | ||
| 3143 | Str255 title; | ||
| 3144 | #if !TARGET_API_MAC_CARBON | 3143 | #if !TARGET_API_MAC_CARBON |
| 3145 | int title_changed_p = 0; | 3144 | int title_changed_p = 0; |
| 3146 | #endif | 3145 | #endif |
| @@ -3162,19 +3161,36 @@ fill_menubar (wv, deep_p) | |||
| 3162 | wv != NULL && id < min_menu_id[MAC_MENU_MENU_BAR + 1]; | 3161 | wv != NULL && id < min_menu_id[MAC_MENU_MENU_BAR + 1]; |
| 3163 | wv = wv->next, id++) | 3162 | wv = wv->next, id++) |
| 3164 | { | 3163 | { |
| 3164 | OSStatus err = noErr; | ||
| 3165 | MenuRef menu; | ||
| 3166 | #if TARGET_API_MAC_CARBON | ||
| 3167 | CFStringRef title; | ||
| 3168 | |||
| 3169 | title = CFStringCreateWithCString (NULL, wv->name, | ||
| 3170 | kCFStringEncodingMacRoman); | ||
| 3171 | #else | ||
| 3172 | Str255 title; | ||
| 3173 | |||
| 3165 | strncpy (title, wv->name, 255); | 3174 | strncpy (title, wv->name, 255); |
| 3166 | title[255] = '\0'; | 3175 | title[255] = '\0'; |
| 3167 | c2pstr (title); | 3176 | c2pstr (title); |
| 3177 | #endif | ||
| 3168 | 3178 | ||
| 3169 | menu = GetMenuRef (id); | 3179 | menu = GetMenuRef (id); |
| 3170 | if (menu) | 3180 | if (menu) |
| 3171 | { | 3181 | { |
| 3172 | #if TARGET_API_MAC_CARBON | 3182 | #if TARGET_API_MAC_CARBON |
| 3173 | Str255 old_title; | 3183 | CFStringRef old_title; |
| 3174 | 3184 | ||
| 3175 | GetMenuTitle (menu, old_title); | 3185 | err = CopyMenuTitleAsCFString (menu, &old_title); |
| 3176 | if (!EqualString (title, old_title, false, false)) | 3186 | if (err == noErr) |
| 3177 | SetMenuTitle (menu, title); | 3187 | { |
| 3188 | if (CFStringCompare (title, old_title, 0) != kCFCompareEqualTo) | ||
| 3189 | err = SetMenuTitleWithCFString (menu, title); | ||
| 3190 | CFRelease (old_title); | ||
| 3191 | } | ||
| 3192 | else | ||
| 3193 | err = SetMenuTitleWithCFString (menu, title); | ||
| 3178 | #else /* !TARGET_API_MAC_CARBON */ | 3194 | #else /* !TARGET_API_MAC_CARBON */ |
| 3179 | if (!EqualString (title, (*menu)->menuData, false, false)) | 3195 | if (!EqualString (title, (*menu)->menuData, false, false)) |
| 3180 | { | 3196 | { |
| @@ -3188,16 +3204,29 @@ fill_menubar (wv, deep_p) | |||
| 3188 | } | 3204 | } |
| 3189 | else | 3205 | else |
| 3190 | { | 3206 | { |
| 3207 | #if TARGET_API_MAC_CARBON | ||
| 3208 | err = CreateNewMenu (id, 0, &menu); | ||
| 3209 | if (err == noErr) | ||
| 3210 | err = SetMenuTitleWithCFString (menu, title); | ||
| 3211 | #else | ||
| 3191 | menu = NewMenu (id, title); | 3212 | menu = NewMenu (id, title); |
| 3192 | InsertMenu (menu, 0); | 3213 | #endif |
| 3214 | if (err == noErr) | ||
| 3215 | { | ||
| 3216 | InsertMenu (menu, 0); | ||
| 3193 | #if !TARGET_API_MAC_CARBON | 3217 | #if !TARGET_API_MAC_CARBON |
| 3194 | title_changed_p = 1; | 3218 | title_changed_p = 1; |
| 3195 | #endif | 3219 | #endif |
| 3220 | } | ||
| 3196 | } | 3221 | } |
| 3222 | #if TARGET_API_MAC_CARBON | ||
| 3223 | CFRelease (title); | ||
| 3224 | #endif | ||
| 3197 | 3225 | ||
| 3198 | if (wv->contents) | 3226 | if (err == noErr) |
| 3199 | submenu_id = fill_menu (menu, wv->contents, MAC_MENU_MENU_BAR_SUB, | 3227 | if (wv->contents) |
| 3200 | submenu_id); | 3228 | submenu_id = fill_menu (menu, wv->contents, MAC_MENU_MENU_BAR_SUB, |
| 3229 | submenu_id); | ||
| 3201 | } | 3230 | } |
| 3202 | 3231 | ||
| 3203 | if (id < min_menu_id[MAC_MENU_MENU_BAR + 1] && GetMenuRef (id)) | 3232 | if (id < min_menu_id[MAC_MENU_MENU_BAR + 1] && GetMenuRef (id)) |