diff options
| author | Jan Djärv | 2013-08-11 16:57:12 +0200 |
|---|---|---|
| committer | Jan Djärv | 2013-08-11 16:57:12 +0200 |
| commit | d2d699ac519599385b2865627db065c0fbfd38f3 (patch) | |
| tree | 9f21ec7de67b36c79ef5f41259e7d33e90e26b7f /src | |
| parent | 7ec326db1dfe07523c8e22fb98f8aed6c8f2ae7e (diff) | |
| download | emacs-d2d699ac519599385b2865627db065c0fbfd38f3.tar.gz emacs-d2d699ac519599385b2865627db065c0fbfd38f3.zip | |
* nsmenu.m (ns_update_menubar): Call fillWithWidgetValue:setDelegate.
(x_activate_menubar): Update the whole menu.
(trackingNotification:): Call ns_check_menu_open if tracking ends.
(menuWillOpen:): Increment trackingMenu. For OSX <= 10.6, exit if
current event is not NSSystemDefined.
Call ns_check_menu_open only if trackingMenu is 2.
(menuDidClose:): New method, decrease trackingMenu.
(fillWithWidgetValue:setDelegate:): New method.
(fillWithWidgetValue:): Call the above.
* nsterm.h (EmacsMenu): Add fillWithWidgetValue:setDelegate:
* nsterm.m (menu_pending_title, ns_get_pending_menu_title): Remove.
(ns_check_menu_open): Handle menu == nil. Remove assignment to
menu_pending_title.
Fixes: debbugs:15001
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 18 | ||||
| -rw-r--r-- | src/nsmenu.m | 49 | ||||
| -rw-r--r-- | src/nsterm.h | 1 | ||||
| -rw-r--r-- | src/nsterm.m | 19 |
4 files changed, 57 insertions, 30 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index e114db5c8d4..58806f4e0b1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,21 @@ | |||
| 1 | 2013-08-11 Jan Djärv <jan.h.d@swipnet.se> | ||
| 2 | |||
| 3 | * nsterm.m (menu_pending_title, ns_get_pending_menu_title): Remove. | ||
| 4 | (ns_check_menu_open): Handle menu == nil. Remove assignment to | ||
| 5 | menu_pending_title. | ||
| 6 | |||
| 7 | * nsmenu.m (ns_update_menubar): Call fillWithWidgetValue:setDelegate. | ||
| 8 | (x_activate_menubar): Update the whole menu. | ||
| 9 | (trackingNotification:): Call ns_check_menu_open if tracking ends. | ||
| 10 | (menuWillOpen:): Increment trackingMenu. For OSX <= 10.6, exit if | ||
| 11 | current event is not NSSystemDefined (Bug#15001). | ||
| 12 | Call ns_check_menu_open only if trackingMenu is 2. | ||
| 13 | (menuDidClose:): New method, decrease trackingMenu. | ||
| 14 | (fillWithWidgetValue:setDelegate:): New method. | ||
| 15 | (fillWithWidgetValue:): Call the above. | ||
| 16 | |||
| 17 | * nsterm.h (EmacsMenu): Add fillWithWidgetValue:setDelegate: | ||
| 18 | |||
| 1 | 2013-08-11 Paul Eggert <eggert@cs.ucla.edu> | 19 | 2013-08-11 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 20 | ||
| 3 | Omit some unnecessary casts. | 21 | Omit some unnecessary casts. |
diff --git a/src/nsmenu.m b/src/nsmenu.m index 5b3c21424e9..1ae2a34ab92 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m | |||
| @@ -366,7 +366,7 @@ ns_update_menubar (struct frame *f, bool deep_p, EmacsMenu *submenu) | |||
| 366 | } | 366 | } |
| 367 | else | 367 | else |
| 368 | { | 368 | { |
| 369 | [menu fillWithWidgetValue: first_wv->contents]; | 369 | [menu fillWithWidgetValue: first_wv->contents setDelegate:YES]; |
| 370 | } | 370 | } |
| 371 | 371 | ||
| 372 | } | 372 | } |
| @@ -504,21 +504,7 @@ void | |||
| 504 | x_activate_menubar (struct frame *f) | 504 | x_activate_menubar (struct frame *f) |
| 505 | { | 505 | { |
| 506 | #ifdef NS_IMPL_COCOA | 506 | #ifdef NS_IMPL_COCOA |
| 507 | NSArray *a = [[NSApp mainMenu] itemArray]; | 507 | ns_update_menubar (f, true, nil); |
| 508 | /* Update each submenu separately so ns_update_menubar doesn't reset | ||
| 509 | the delegate. */ | ||
| 510 | int i = 0; | ||
| 511 | while (i < [a count]) | ||
| 512 | { | ||
| 513 | EmacsMenu *menu = (EmacsMenu *)[[a objectAtIndex:i] submenu]; | ||
| 514 | const char *title = [[menu title] UTF8String]; | ||
| 515 | if (strcmp (title, ns_get_pending_menu_title ()) == 0) | ||
| 516 | { | ||
| 517 | ns_update_menubar (f, true, menu); | ||
| 518 | break; | ||
| 519 | } | ||
| 520 | ++i; | ||
| 521 | } | ||
| 522 | ns_check_pending_open_menu (); | 508 | ns_check_pending_open_menu (); |
| 523 | #endif | 509 | #endif |
| 524 | } | 510 | } |
| @@ -576,17 +562,34 @@ extern NSString *NSMenuDidBeginTrackingNotification; | |||
| 576 | /* Update menu in menuNeedsUpdate only while tracking menus. */ | 562 | /* Update menu in menuNeedsUpdate only while tracking menus. */ |
| 577 | trackingMenu = ([notification name] == NSMenuDidBeginTrackingNotification | 563 | trackingMenu = ([notification name] == NSMenuDidBeginTrackingNotification |
| 578 | ? 1 : 0); | 564 | ? 1 : 0); |
| 565 | if (! trackingMenu) ns_check_menu_open (nil); | ||
| 579 | } | 566 | } |
| 580 | 567 | ||
| 581 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 | 568 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 |
| 582 | - (void)menuWillOpen:(NSMenu *)menu | 569 | - (void)menuWillOpen:(NSMenu *)menu |
| 583 | { | 570 | { |
| 584 | ns_check_menu_open (menu); | 571 | ++trackingMenu; |
| 585 | } | ||
| 586 | #endif | ||
| 587 | 572 | ||
| 573 | #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_6 | ||
| 574 | // On 10.6 we get repeated calls, only the one for NSSystemDefined is "real". | ||
| 575 | if ([[NSApp currentEvent] type] != NSSystemDefined) return; | ||
| 588 | #endif | 576 | #endif |
| 589 | 577 | ||
| 578 | /* When dragging from one menu to another, we get willOpen followed by didClose, | ||
| 579 | i.e. trackingMenu == 3 in willOpen and then 2 after didClose. | ||
| 580 | We have updated all menus, so avoid doing it when trackingMenu == 3. */ | ||
| 581 | if (trackingMenu == 2) | ||
| 582 | ns_check_menu_open (menu); | ||
| 583 | } | ||
| 584 | |||
| 585 | - (void)menuDidClose:(NSMenu *)menu | ||
| 586 | { | ||
| 587 | --trackingMenu; | ||
| 588 | } | ||
| 589 | #endif /* OSX >= 10.5 */ | ||
| 590 | |||
| 591 | #endif /* NS_IMPL_COCOA */ | ||
| 592 | |||
| 590 | /* delegate method called when a submenu is being opened: run a 'deep' call | 593 | /* delegate method called when a submenu is being opened: run a 'deep' call |
| 591 | to set_frame_menubar */ | 594 | to set_frame_menubar */ |
| 592 | - (void)menuNeedsUpdate: (NSMenu *)menu | 595 | - (void)menuNeedsUpdate: (NSMenu *)menu |
| @@ -722,6 +725,11 @@ extern NSString *NSMenuDidBeginTrackingNotification; | |||
| 722 | 725 | ||
| 723 | - (void)fillWithWidgetValue: (void *)wvptr | 726 | - (void)fillWithWidgetValue: (void *)wvptr |
| 724 | { | 727 | { |
| 728 | [self fillWithWidgetValue: wvptr setDelegate:NO]; | ||
| 729 | } | ||
| 730 | |||
| 731 | - (void)fillWithWidgetValue: (void *)wvptr setDelegate: (BOOL)set | ||
| 732 | { | ||
| 725 | widget_value *wv = (widget_value *)wvptr; | 733 | widget_value *wv = (widget_value *)wvptr; |
| 726 | 734 | ||
| 727 | /* clear existing contents */ | 735 | /* clear existing contents */ |
| @@ -737,6 +745,9 @@ extern NSString *NSMenuDidBeginTrackingNotification; | |||
| 737 | { | 745 | { |
| 738 | EmacsMenu *submenu = [[EmacsMenu alloc] initWithTitle: [item title]]; | 746 | EmacsMenu *submenu = [[EmacsMenu alloc] initWithTitle: [item title]]; |
| 739 | 747 | ||
| 748 | #ifdef NS_IMPL_COCOA | ||
| 749 | if (set) [submenu setDelegate: submenu]; | ||
| 750 | #endif | ||
| 740 | [self setSubmenu: submenu forItem: item]; | 751 | [self setSubmenu: submenu forItem: item]; |
| 741 | [submenu fillWithWidgetValue: wv->contents]; | 752 | [submenu fillWithWidgetValue: wv->contents]; |
| 742 | [submenu release]; | 753 | [submenu release]; |
diff --git a/src/nsterm.h b/src/nsterm.h index 1303a475547..cf8e26d14a6 100644 --- a/src/nsterm.h +++ b/src/nsterm.h | |||
| @@ -196,6 +196,7 @@ typedef float EmacsCGFloat; | |||
| 196 | - (NSString *)parseKeyEquiv: (const char *)key; | 196 | - (NSString *)parseKeyEquiv: (const char *)key; |
| 197 | - (NSMenuItem *)addItemWithWidgetValue: (void *)wvptr; | 197 | - (NSMenuItem *)addItemWithWidgetValue: (void *)wvptr; |
| 198 | - (void)fillWithWidgetValue: (void *)wvptr; | 198 | - (void)fillWithWidgetValue: (void *)wvptr; |
| 199 | - (void)fillWithWidgetValue: (void *)wvptr setDelegate: (BOOL)set; | ||
| 199 | - (EmacsMenu *)addSubmenuWithTitle: (const char *)title forFrame: (struct frame *)f; | 200 | - (EmacsMenu *)addSubmenuWithTitle: (const char *)title forFrame: (struct frame *)f; |
| 200 | - (void) clear; | 201 | - (void) clear; |
| 201 | - (Lisp_Object)runMenuAt: (NSPoint)p forFrame: (struct frame *)f | 202 | - (Lisp_Object)runMenuAt: (NSPoint)p forFrame: (struct frame *)f |
diff --git a/src/nsterm.m b/src/nsterm.m index d391d39fdaa..e519244ac99 100644 --- a/src/nsterm.m +++ b/src/nsterm.m | |||
| @@ -250,9 +250,6 @@ static int menu_will_open_state = MENU_NONE; | |||
| 250 | 250 | ||
| 251 | /* Saved position for menu click. */ | 251 | /* Saved position for menu click. */ |
| 252 | static CGPoint menu_mouse_point; | 252 | static CGPoint menu_mouse_point; |
| 253 | |||
| 254 | /* Title for the menu to open. */ | ||
| 255 | static char *menu_pending_title = 0; | ||
| 256 | #endif | 253 | #endif |
| 257 | 254 | ||
| 258 | /* Convert modifiers in a NeXTstep event to emacs style modifiers. */ | 255 | /* Convert modifiers in a NeXTstep event to emacs style modifiers. */ |
| @@ -3397,12 +3394,6 @@ check_native_fs () | |||
| 3397 | /* GNUStep and OSX <= 10.4 does not have cancelTracking. */ | 3394 | /* GNUStep and OSX <= 10.4 does not have cancelTracking. */ |
| 3398 | #if defined (NS_IMPL_COCOA) && \ | 3395 | #if defined (NS_IMPL_COCOA) && \ |
| 3399 | MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 | 3396 | MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 |
| 3400 | const char * | ||
| 3401 | ns_get_pending_menu_title () | ||
| 3402 | { | ||
| 3403 | return menu_pending_title; | ||
| 3404 | } | ||
| 3405 | |||
| 3406 | /* Check if menu open should be cancelled or continued as normal. */ | 3397 | /* Check if menu open should be cancelled or continued as normal. */ |
| 3407 | void | 3398 | void |
| 3408 | ns_check_menu_open (NSMenu *menu) | 3399 | ns_check_menu_open (NSMenu *menu) |
| @@ -3411,6 +3402,14 @@ ns_check_menu_open (NSMenu *menu) | |||
| 3411 | NSArray *a = [[NSApp mainMenu] itemArray]; | 3402 | NSArray *a = [[NSApp mainMenu] itemArray]; |
| 3412 | int i; | 3403 | int i; |
| 3413 | BOOL found = NO; | 3404 | BOOL found = NO; |
| 3405 | |||
| 3406 | if (menu == nil) // Menu tracking ended. | ||
| 3407 | { | ||
| 3408 | if (menu_will_open_state == MENU_OPENING) | ||
| 3409 | menu_will_open_state = MENU_NONE; | ||
| 3410 | return; | ||
| 3411 | } | ||
| 3412 | |||
| 3414 | for (i = 0; ! found && i < [a count]; i++) | 3413 | for (i = 0; ! found && i < [a count]; i++) |
| 3415 | found = menu == [[a objectAtIndex:i] submenu]; | 3414 | found = menu == [[a objectAtIndex:i] submenu]; |
| 3416 | if (found) | 3415 | if (found) |
| @@ -3428,8 +3427,6 @@ ns_check_menu_open (NSMenu *menu) | |||
| 3428 | CGEventRef ourEvent = CGEventCreate (NULL); | 3427 | CGEventRef ourEvent = CGEventCreate (NULL); |
| 3429 | menu_mouse_point = CGEventGetLocation (ourEvent); | 3428 | menu_mouse_point = CGEventGetLocation (ourEvent); |
| 3430 | CFRelease (ourEvent); | 3429 | CFRelease (ourEvent); |
| 3431 | xfree (menu_pending_title); | ||
| 3432 | menu_pending_title = xstrdup ([[menu title] UTF8String]); | ||
| 3433 | } | 3430 | } |
| 3434 | else if (menu_will_open_state == MENU_OPENING) | 3431 | else if (menu_will_open_state == MENU_OPENING) |
| 3435 | { | 3432 | { |