From: Alan Third Date: Sat, 12 Jun 2021 11:52:15 +0000 (+0100) Subject: Move NS port toolbar handling to the window X-Git-Tag: emacs-28.0.90~1633 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0b5cf4850990ff7b32264d2a174843fe72203cd0;p=emacs.git Move NS port toolbar handling to the window * src/nsmenu.m (free_frame_tool_bar): (update_frame_tool_bar): Remove wait_for_tool_bar and get the toolbar from the window. * src/nsterm.h (EmacsView): Remove toolbar and wait_for_tool_bar. * src/nsterm.m (ns_update_begin): ([EmacsView windowDidEnterFullScreen]): ([EmacsView windowDidExitFullScreen]): Get the toolbar from the window, not the view. ([EmacsView dealloc]): Remove toolbar from view. ([EmacsView createToolbar:]): Move method to EmacsWindow. ([EmacsView initFrameFromEmacs:]): Don't create toolbar here any more. ([EmacsView toolbar]): Remove method. ([EmacsWindow initWithEmacsFrame:fullscreen:screen:]): Create toolbar here. ([EmacsWindow createToolbar:]): Moved from EmacsView. ([EmacsWindow dealloc]): Make sure we clean up the toolbar after closing the window. --- diff --git a/src/nsmenu.m b/src/nsmenu.m index 1b03fe91a8b..673c0423d04 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m @@ -991,12 +991,11 @@ free_frame_tool_bar (struct frame *f) NSTRACE ("free_frame_tool_bar"); block_input (); - view->wait_for_tool_bar = NO; /* Note: This triggers an animation, which calls windowDidResize repeatedly. */ f->output_data.ns->in_animation = 1; - [[view toolbar] setVisible: NO]; + [[[view window] toolbar] setVisible: NO]; f->output_data.ns->in_animation = 0; unblock_input (); @@ -1009,12 +1008,12 @@ update_frame_tool_bar (struct frame *f) -------------------------------------------------------------------------- */ { int i, k = 0; - EmacsView *view = FRAME_NS_VIEW (f); - EmacsToolbar *toolbar = [view toolbar]; + NSWindow *window = [FRAME_NS_VIEW (f) window]; + EmacsToolbar *toolbar = (EmacsToolbar *)[window toolbar]; NSTRACE ("update_frame_tool_bar"); - if (view == nil || toolbar == nil) return; + if (window == nil || toolbar == nil) return; block_input (); #ifdef NS_IMPL_COCOA @@ -1120,13 +1119,6 @@ update_frame_tool_bar (struct frame *f) [newDict release]; } #endif - - if (view->wait_for_tool_bar && FRAME_TOOLBAR_HEIGHT (f) > 0) - { - view->wait_for_tool_bar = NO; - [view setNeedsDisplay: YES]; - } - unblock_input (); } diff --git a/src/nsterm.h b/src/nsterm.h index 40206cc4ded..f7ab8236b4c 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -453,9 +453,7 @@ typedef id instancetype; @public struct frame *emacsframe; int scrollbarsNeedingUpdate; - EmacsToolbar *toolbar; NSRect ns_userRect; - BOOL wait_for_tool_bar; } /* AppKit-side interface */ @@ -469,9 +467,7 @@ typedef id instancetype; /* Emacs-side interface */ - (instancetype) initFrameFromEmacs: (struct frame *) f; -- (void) createToolbar: (struct frame *)f; - (void) setWindowClosing: (BOOL)closing; -- (EmacsToolbar *) toolbar; - (void) deleteWorkingText; - (void) handleFS; - (void) setFSValue: (int)value; diff --git a/src/nsterm.m b/src/nsterm.m index b8b306e685a..ba334d5fe90 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -1026,7 +1026,7 @@ ns_update_begin (struct frame *f) { // Fix reappearing tool bar in fullscreen for Mac OS X 10.7 BOOL tbar_visible = FRAME_EXTERNAL_TOOL_BAR (f) ? YES : NO; - NSToolbar *toolbar = [FRAME_NS_VIEW (f) toolbar]; + NSToolbar *toolbar = [[FRAME_NS_VIEW (f) window] toolbar]; if (! tbar_visible != ! [toolbar isVisible]) [toolbar setVisible: tbar_visible]; } @@ -1745,9 +1745,6 @@ ns_set_undecorated (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu newWindow = [[EmacsWindow alloc] initWithEmacsFrame:f]; - if (!FRAME_UNDECORATED (f)) - [view createToolbar: f]; - if ([oldWindow isKeyWindow]) [newWindow makeKeyAndOrderFront:NSApp]; @@ -6074,7 +6071,6 @@ not_in_argv (NSString *arg) name:NSViewFrameDidChangeNotification object:nil]; - [toolbar release]; if (fs_state == FULLSCREEN_BOTH) [nonfs_window release]; [super dealloc]; @@ -7155,34 +7151,6 @@ not_in_argv (NSString *arg) } -- (void)createToolbar: (struct frame *)f -{ - EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f); - NSWindow *window = [view window]; - - toolbar = [[EmacsToolbar alloc] initForView: self withIdentifier: - [NSString stringWithFormat: @"Emacs Frame %d", - ns_window_num]]; - [toolbar setVisible: NO]; - [window setToolbar: toolbar]; - - /* Don't set frame garbaged until tool bar is up to date? - This avoids an extra clear and redraw (flicker) at frame creation. */ - if (FRAME_EXTERNAL_TOOL_BAR (f)) wait_for_tool_bar = YES; - else wait_for_tool_bar = NO; - - -#ifdef NS_IMPL_COCOA - { - NSButton *toggleButton; - toggleButton = [window standardWindowButton: NSWindowToolbarButton]; - [toggleButton setTarget: self]; - [toggleButton setAction: @selector (toggleToolbar: )]; - } -#endif -} - - - (instancetype) initFrameFromEmacs: (struct frame *)f { NSTRACE ("[EmacsView initFrameFromEmacs:]"); @@ -7234,10 +7202,6 @@ not_in_argv (NSString *arg) if (ns_drag_types) [self registerForDraggedTypes: ns_drag_types]; - /* toolbar support */ - if (! FRAME_UNDECORATED (f)) - [self createToolbar: f]; - #if !defined (NS_IMPL_COCOA) \ || MAC_OS_X_VERSION_MIN_REQUIRED <= 1090 #if MAC_OS_X_VERSION_MAX_ALLOWED > 1090 @@ -7517,7 +7481,7 @@ not_in_argv (NSString *arg) [NSApp setPresentationOptions: options]; } #endif - [toolbar setVisible:tbar_visible]; + [[[self window]toolbar] setVisible:tbar_visible]; } } @@ -7560,12 +7524,12 @@ not_in_argv (NSString *arg) #endif if (FRAME_EXTERNAL_TOOL_BAR (emacsframe)) { - [toolbar setVisible:YES]; + [[[self window] toolbar] setVisible:YES]; update_frame_tool_bar (emacsframe); [[self window] display]; } else - [toolbar setVisible:NO]; + [[[self window] toolbar] setVisible:NO]; if (next_maximized != -1) [[self window] performZoom:self]; @@ -7864,12 +7828,6 @@ not_in_argv (NSString *arg) } -- (EmacsToolbar *)toolbar -{ - return toolbar; -} - - /* This gets called on toolbar button click. */ - (instancetype)toolbarClicked: (id)item { @@ -8421,6 +8379,10 @@ not_in_argv (NSString *arg) if ([col alphaComponent] != (EmacsCGFloat) 1.0) [self setOpaque:NO]; + /* toolbar support */ + if (! FRAME_UNDECORATED (f)) + [self createToolbar:f]; + /* macOS Sierra automatically enables tabbed windows. We can't allow this to be enabled until it's available on a Free system. Currently it only happens by accident and is buggy anyway. */ @@ -8434,6 +8396,36 @@ not_in_argv (NSString *arg) } +- (void)createToolbar: (struct frame *)f +{ + EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f); + + EmacsToolbar *toolbar = [[EmacsToolbar alloc] + initForView:view + withIdentifier:[NSString stringWithLispString:f->name]]; + [self setToolbar:toolbar]; + + update_frame_tool_bar (f); + +#ifdef NS_IMPL_COCOA + { + NSButton *toggleButton; + toggleButton = [self standardWindowButton:NSWindowToolbarButton]; + [toggleButton setTarget:view]; + [toggleButton setAction:@selector (toggleToolbar:)]; + } +#endif +} + +- (void)dealloc +{ + NSTRACE ("[EmacsWindow dealloc]"); + + /* We need to release the toolbar ourselves. */ + [[self toolbar] release]; + [super dealloc]; +} + - (NSInteger) borderWidth { return NSWidth ([self frame]) - NSWidth ([[self contentView] frame]);