X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/cf7a0de6e75d2c510e69ab77bc70279cba7c48ba..8131fcfd622dd2b7fccf09b0f6a1c3f4747619a7:/src/nsmenu.m diff --git a/src/nsmenu.m b/src/nsmenu.m index 22635dca0a..5af813ac75 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m @@ -366,7 +366,7 @@ ns_update_menubar (struct frame *f, bool deep_p, EmacsMenu *submenu) } else { - [menu fillWithWidgetValue: first_wv->contents]; + [menu fillWithWidgetValue: first_wv->contents frame: f]; } } @@ -504,23 +504,11 @@ void x_activate_menubar (struct frame *f) { #ifdef NS_IMPL_COCOA - NSArray *a = [[NSApp mainMenu] itemArray]; - /* Update each submenu separately so ns_update_menubar doesn't reset - the delegate. */ - int i = 0; - while (i < [a count]) - { - EmacsMenu *menu = (EmacsMenu *)[[a objectAtIndex:i] submenu]; - const char *title = [[menu title] UTF8String]; - if (strcmp (title, ns_get_pending_menu_title ()) == 0) - { - ns_update_menubar (f, true, menu); - break; - } - ++i; - } +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 + ns_update_menubar (f, true, nil); ns_check_pending_open_menu (); #endif +#endif } @@ -541,6 +529,7 @@ x_activate_menubar (struct frame *f) /* override designated initializer */ - initWithTitle: (NSString *)title { + frame = 0; if ((self = [super initWithTitle: title])) [self setAutoenablesItems: NO]; return self; @@ -576,17 +565,36 @@ extern NSString *NSMenuDidBeginTrackingNotification; /* Update menu in menuNeedsUpdate only while tracking menus. */ trackingMenu = ([notification name] == NSMenuDidBeginTrackingNotification ? 1 : 0); +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 + if (! trackingMenu) ns_check_menu_open (nil); +#endif } #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 - (void)menuWillOpen:(NSMenu *)menu { - ns_check_menu_open (menu); -} -#endif + ++trackingMenu; +#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 + // On 10.6 we get repeated calls, only the one for NSSystemDefined is "real". + if ([[NSApp currentEvent] type] != NSSystemDefined) return; #endif + /* When dragging from one menu to another, we get willOpen followed by didClose, + i.e. trackingMenu == 3 in willOpen and then 2 after didClose. + We have updated all menus, so avoid doing it when trackingMenu == 3. */ + if (trackingMenu == 2) + ns_check_menu_open (menu); +} + +- (void)menuDidClose:(NSMenu *)menu +{ + --trackingMenu; +} +#endif /* OSX >= 10.5 */ + +#endif /* NS_IMPL_COCOA */ + /* delegate method called when a submenu is being opened: run a 'deep' call to set_frame_menubar */ - (void)menuNeedsUpdate: (NSMenu *)menu @@ -721,6 +729,11 @@ extern NSString *NSMenuDidBeginTrackingNotification; - (void)fillWithWidgetValue: (void *)wvptr +{ + [self fillWithWidgetValue: wvptr frame:nil]; +} + +- (void)fillWithWidgetValue: (void *)wvptr frame: (struct frame *)f { widget_value *wv = (widget_value *)wvptr; @@ -735,7 +748,12 @@ extern NSString *NSMenuDidBeginTrackingNotification; if (wv->contents) { - EmacsMenu *submenu = [[EmacsMenu alloc] initWithTitle: [item title]]; + EmacsMenu *submenu; + + if (f) + submenu = [[EmacsMenu alloc] initWithTitle: [item title] frame:f]; + else + submenu = [[EmacsMenu alloc] initWithTitle: [item title]]; [self setSubmenu: submenu forItem: item]; [submenu fillWithWidgetValue: wv->contents]; @@ -806,7 +824,7 @@ extern NSString *NSMenuDidBeginTrackingNotification; ========================================================================== */ Lisp_Object -ns_menu_show (FRAME_PTR f, int x, int y, bool for_click, bool keymaps, +ns_menu_show (struct frame *f, int x, int y, bool for_click, bool keymaps, Lisp_Object title, const char **error) { EmacsMenu *pmenu; @@ -1028,7 +1046,7 @@ ns_menu_show (FRAME_PTR f, int x, int y, bool for_click, bool keymaps, ========================================================================== */ void -free_frame_tool_bar (FRAME_PTR f) +free_frame_tool_bar (struct frame *f) /* -------------------------------------------------------------------------- Under NS we just hide the toolbar until it might be needed again. -------------------------------------------------------------------------- */ @@ -1040,7 +1058,7 @@ free_frame_tool_bar (FRAME_PTR f) } void -update_frame_tool_bar (FRAME_PTR f) +update_frame_tool_bar (struct frame *f) /* -------------------------------------------------------------------------- Update toolbar contents -------------------------------------------------------------------------- */ @@ -1410,10 +1428,10 @@ struct Popdown_data EmacsDialogPanel *dialog; }; -static Lisp_Object -pop_down_menu (Lisp_Object arg) +static void +pop_down_menu (void *arg) { - struct Popdown_data *unwind_data = XSAVE_POINTER (arg, 0); + struct Popdown_data *unwind_data = arg; block_input (); if (popup_activated_flag) @@ -1427,8 +1445,6 @@ pop_down_menu (Lisp_Object arg) xfree (unwind_data); unblock_input (); - - return Qnil; } @@ -1492,7 +1508,7 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header) if (NILP (Fcar (Fcdr (contents)))) /* No buttons specified, add an "Ok" button so users can pop down the dialog. */ - contents = Fcons (title, Fcons (Fcons (build_string ("Ok"), Qt), Qnil)); + contents = list2 (title, Fcons (build_string ("Ok"), Qt)); block_input (); pool = [[NSAutoreleasePool alloc] init]; @@ -1506,7 +1522,7 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header) unwind_data->pool = pool; unwind_data->dialog = dialog; - record_unwind_protect (pop_down_menu, make_save_pointer (unwind_data)); + record_unwind_protect_ptr (pop_down_menu, unwind_data); popup_activated_flag = 1; tem = [dialog runDialogAt: p]; unbind_to (specpdl_count, Qnil); /* calls pop_down_menu */ @@ -1667,7 +1683,7 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header) } if (buttons > 0) - button_values = (Lisp_Object *) xmalloc (buttons * sizeof (*button_values)); + button_values = xmalloc (buttons * sizeof *button_values); for (; XTYPE (list) == Lisp_Cons; list = XCDR (list)) {