aboutsummaryrefslogtreecommitdiffstats
path: root/src/nsmenu.m
diff options
context:
space:
mode:
Diffstat (limited to 'src/nsmenu.m')
-rw-r--r--src/nsmenu.m66
1 files changed, 42 insertions, 24 deletions
diff --git a/src/nsmenu.m b/src/nsmenu.m
index 464be89c524..f9cd511efe9 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 frame: f];
370 } 370 }
371 371
372 } 372 }
@@ -504,23 +504,11 @@ void
504x_activate_menubar (struct frame *f) 504x_activate_menubar (struct frame *f)
505{ 505{
506#ifdef NS_IMPL_COCOA 506#ifdef NS_IMPL_COCOA
507 NSArray *a = [[NSApp mainMenu] itemArray]; 507#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
508 /* Update each submenu separately so ns_update_menubar doesn't reset 508 ns_update_menubar (f, true, nil);
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 (); 509 ns_check_pending_open_menu ();
523#endif 510#endif
511#endif
524} 512}
525 513
526 514
@@ -541,6 +529,7 @@ x_activate_menubar (struct frame *f)
541/* override designated initializer */ 529/* override designated initializer */
542- initWithTitle: (NSString *)title 530- initWithTitle: (NSString *)title
543{ 531{
532 frame = 0;
544 if ((self = [super initWithTitle: title])) 533 if ((self = [super initWithTitle: title]))
545 [self setAutoenablesItems: NO]; 534 [self setAutoenablesItems: NO];
546 return self; 535 return self;
@@ -576,17 +565,36 @@ extern NSString *NSMenuDidBeginTrackingNotification;
576 /* Update menu in menuNeedsUpdate only while tracking menus. */ 565 /* Update menu in menuNeedsUpdate only while tracking menus. */
577 trackingMenu = ([notification name] == NSMenuDidBeginTrackingNotification 566 trackingMenu = ([notification name] == NSMenuDidBeginTrackingNotification
578 ? 1 : 0); 567 ? 1 : 0);
568#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
569 if (! trackingMenu) ns_check_menu_open (nil);
570#endif
579} 571}
580 572
581#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 573#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
582- (void)menuWillOpen:(NSMenu *)menu 574- (void)menuWillOpen:(NSMenu *)menu
583{ 575{
584 ns_check_menu_open (menu); 576 ++trackingMenu;
585}
586#endif
587 577
578#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
579 // On 10.6 we get repeated calls, only the one for NSSystemDefined is "real".
580 if ([[NSApp currentEvent] type] != NSSystemDefined) return;
588#endif 581#endif
589 582
583 /* When dragging from one menu to another, we get willOpen followed by didClose,
584 i.e. trackingMenu == 3 in willOpen and then 2 after didClose.
585 We have updated all menus, so avoid doing it when trackingMenu == 3. */
586 if (trackingMenu == 2)
587 ns_check_menu_open (menu);
588}
589
590- (void)menuDidClose:(NSMenu *)menu
591{
592 --trackingMenu;
593}
594#endif /* OSX >= 10.5 */
595
596#endif /* NS_IMPL_COCOA */
597
590/* delegate method called when a submenu is being opened: run a 'deep' call 598/* delegate method called when a submenu is being opened: run a 'deep' call
591 to set_frame_menubar */ 599 to set_frame_menubar */
592- (void)menuNeedsUpdate: (NSMenu *)menu 600- (void)menuNeedsUpdate: (NSMenu *)menu
@@ -722,6 +730,11 @@ extern NSString *NSMenuDidBeginTrackingNotification;
722 730
723- (void)fillWithWidgetValue: (void *)wvptr 731- (void)fillWithWidgetValue: (void *)wvptr
724{ 732{
733 [self fillWithWidgetValue: wvptr frame: (struct frame *)nil];
734}
735
736- (void)fillWithWidgetValue: (void *)wvptr frame: (struct frame *)f
737{
725 widget_value *wv = (widget_value *)wvptr; 738 widget_value *wv = (widget_value *)wvptr;
726 739
727 /* clear existing contents */ 740 /* clear existing contents */
@@ -735,7 +748,12 @@ extern NSString *NSMenuDidBeginTrackingNotification;
735 748
736 if (wv->contents) 749 if (wv->contents)
737 { 750 {
738 EmacsMenu *submenu = [[EmacsMenu alloc] initWithTitle: [item title]]; 751 EmacsMenu *submenu;
752
753 if (f)
754 submenu = [[EmacsMenu alloc] initWithTitle: [item title] frame:f];
755 else
756 submenu = [[EmacsMenu alloc] initWithTitle: [item title]];
739 757
740 [self setSubmenu: submenu forItem: item]; 758 [self setSubmenu: submenu forItem: item];
741 [submenu fillWithWidgetValue: wv->contents]; 759 [submenu fillWithWidgetValue: wv->contents];
@@ -1665,7 +1683,7 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
1665 } 1683 }
1666 1684
1667 if (buttons > 0) 1685 if (buttons > 0)
1668 button_values = (Lisp_Object *) xmalloc (buttons * sizeof (*button_values)); 1686 button_values = xmalloc (buttons * sizeof *button_values);
1669 1687
1670 for (; XTYPE (list) == Lisp_Cons; list = XCDR (list)) 1688 for (; XTYPE (list) == Lisp_Cons; list = XCDR (list))
1671 { 1689 {
@@ -1849,11 +1867,11 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
1849 while (popup_activated_flag) 1867 while (popup_activated_flag)
1850 { 1868 {
1851 NSTimer *tmo = nil; 1869 NSTimer *tmo = nil;
1852 EMACS_TIME next_time = timer_check (); 1870 struct timespec next_time = timer_check ();
1853 1871
1854 if (EMACS_TIME_VALID_P (next_time)) 1872 if (timespec_valid_p (next_time))
1855 { 1873 {
1856 double time = EMACS_TIME_TO_DOUBLE (next_time); 1874 double time = timespectod (next_time);
1857 tmo = [NSTimer timerWithTimeInterval: time 1875 tmo = [NSTimer timerWithTimeInterval: time
1858 target: self 1876 target: self
1859 selector: @selector (timeout_handler:) 1877 selector: @selector (timeout_handler:)