aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Third2021-06-12 12:52:15 +0100
committerAlan Third2021-07-24 16:35:46 +0100
commit6f4f66d0da005786b9d0fe8b47c43f14e8cd4d5e (patch)
tree4c9ed9a542af49f6cb21ad2ef8d8a0451e084f84
parent8d0fb516f58fd5ddff5cbc03d00c5ec55be390c7 (diff)
downloademacs-6f4f66d0da005786b9d0fe8b47c43f14e8cd4d5e.tar.gz
emacs-6f4f66d0da005786b9d0fe8b47c43f14e8cd4d5e.zip
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.
-rw-r--r--src/nsmenu.m16
-rw-r--r--src/nsterm.h4
-rw-r--r--src/nsterm.m84
3 files changed, 42 insertions, 62 deletions
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)
991 NSTRACE ("free_frame_tool_bar"); 991 NSTRACE ("free_frame_tool_bar");
992 992
993 block_input (); 993 block_input ();
994 view->wait_for_tool_bar = NO;
995 994
996 /* Note: This triggers an animation, which calls windowDidResize 995 /* Note: This triggers an animation, which calls windowDidResize
997 repeatedly. */ 996 repeatedly. */
998 f->output_data.ns->in_animation = 1; 997 f->output_data.ns->in_animation = 1;
999 [[view toolbar] setVisible: NO]; 998 [[[view window] toolbar] setVisible: NO];
1000 f->output_data.ns->in_animation = 0; 999 f->output_data.ns->in_animation = 0;
1001 1000
1002 unblock_input (); 1001 unblock_input ();
@@ -1009,12 +1008,12 @@ update_frame_tool_bar (struct frame *f)
1009 -------------------------------------------------------------------------- */ 1008 -------------------------------------------------------------------------- */
1010{ 1009{
1011 int i, k = 0; 1010 int i, k = 0;
1012 EmacsView *view = FRAME_NS_VIEW (f); 1011 NSWindow *window = [FRAME_NS_VIEW (f) window];
1013 EmacsToolbar *toolbar = [view toolbar]; 1012 EmacsToolbar *toolbar = (EmacsToolbar *)[window toolbar];
1014 1013
1015 NSTRACE ("update_frame_tool_bar"); 1014 NSTRACE ("update_frame_tool_bar");
1016 1015
1017 if (view == nil || toolbar == nil) return; 1016 if (window == nil || toolbar == nil) return;
1018 block_input (); 1017 block_input ();
1019 1018
1020#ifdef NS_IMPL_COCOA 1019#ifdef NS_IMPL_COCOA
@@ -1120,13 +1119,6 @@ update_frame_tool_bar (struct frame *f)
1120 [newDict release]; 1119 [newDict release];
1121 } 1120 }
1122#endif 1121#endif
1123
1124 if (view->wait_for_tool_bar && FRAME_TOOLBAR_HEIGHT (f) > 0)
1125 {
1126 view->wait_for_tool_bar = NO;
1127 [view setNeedsDisplay: YES];
1128 }
1129
1130 unblock_input (); 1122 unblock_input ();
1131} 1123}
1132 1124
diff --git a/src/nsterm.h b/src/nsterm.h
index b99bea7567a..28155cdc0cb 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -453,9 +453,7 @@ typedef id instancetype;
453@public 453@public
454 struct frame *emacsframe; 454 struct frame *emacsframe;
455 int scrollbarsNeedingUpdate; 455 int scrollbarsNeedingUpdate;
456 EmacsToolbar *toolbar;
457 NSRect ns_userRect; 456 NSRect ns_userRect;
458 BOOL wait_for_tool_bar;
459 } 457 }
460 458
461/* AppKit-side interface */ 459/* AppKit-side interface */
@@ -469,9 +467,7 @@ typedef id instancetype;
469 467
470/* Emacs-side interface */ 468/* Emacs-side interface */
471- (instancetype) initFrameFromEmacs: (struct frame *) f; 469- (instancetype) initFrameFromEmacs: (struct frame *) f;
472- (void) createToolbar: (struct frame *)f;
473- (void) setWindowClosing: (BOOL)closing; 470- (void) setWindowClosing: (BOOL)closing;
474- (EmacsToolbar *) toolbar;
475- (void) deleteWorkingText; 471- (void) deleteWorkingText;
476- (void) handleFS; 472- (void) handleFS;
477- (void) setFSValue: (int)value; 473- (void) setFSValue: (int)value;
diff --git a/src/nsterm.m b/src/nsterm.m
index cc1ddd5efdd..8aa8ff821fd 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1026,7 +1026,7 @@ ns_update_begin (struct frame *f)
1026 { 1026 {
1027 // Fix reappearing tool bar in fullscreen for Mac OS X 10.7 1027 // Fix reappearing tool bar in fullscreen for Mac OS X 10.7
1028 BOOL tbar_visible = FRAME_EXTERNAL_TOOL_BAR (f) ? YES : NO; 1028 BOOL tbar_visible = FRAME_EXTERNAL_TOOL_BAR (f) ? YES : NO;
1029 NSToolbar *toolbar = [FRAME_NS_VIEW (f) toolbar]; 1029 NSToolbar *toolbar = [[FRAME_NS_VIEW (f) window] toolbar];
1030 if (! tbar_visible != ! [toolbar isVisible]) 1030 if (! tbar_visible != ! [toolbar isVisible])
1031 [toolbar setVisible: tbar_visible]; 1031 [toolbar setVisible: tbar_visible];
1032 } 1032 }
@@ -1768,9 +1768,6 @@ ns_set_undecorated (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu
1768 1768
1769 newWindow = [[EmacsWindow alloc] initWithEmacsFrame:f]; 1769 newWindow = [[EmacsWindow alloc] initWithEmacsFrame:f];
1770 1770
1771 if (!FRAME_UNDECORATED (f))
1772 [view createToolbar: f];
1773
1774 if ([oldWindow isKeyWindow]) 1771 if ([oldWindow isKeyWindow])
1775 [newWindow makeKeyAndOrderFront:NSApp]; 1772 [newWindow makeKeyAndOrderFront:NSApp];
1776 1773
@@ -6094,7 +6091,6 @@ not_in_argv (NSString *arg)
6094 name:NSViewFrameDidChangeNotification 6091 name:NSViewFrameDidChangeNotification
6095 object:nil]; 6092 object:nil];
6096 6093
6097 [toolbar release];
6098 if (fs_state == FULLSCREEN_BOTH) 6094 if (fs_state == FULLSCREEN_BOTH)
6099 [nonfs_window release]; 6095 [nonfs_window release];
6100 [super dealloc]; 6096 [super dealloc];
@@ -7175,34 +7171,6 @@ not_in_argv (NSString *arg)
7175} 7171}
7176 7172
7177 7173
7178- (void)createToolbar: (struct frame *)f
7179{
7180 EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f);
7181 NSWindow *window = [view window];
7182
7183 toolbar = [[EmacsToolbar alloc] initForView: self withIdentifier:
7184 [NSString stringWithFormat: @"Emacs Frame %d",
7185 ns_window_num]];
7186 [toolbar setVisible: NO];
7187 [window setToolbar: toolbar];
7188
7189 /* Don't set frame garbaged until tool bar is up to date?
7190 This avoids an extra clear and redraw (flicker) at frame creation. */
7191 if (FRAME_EXTERNAL_TOOL_BAR (f)) wait_for_tool_bar = YES;
7192 else wait_for_tool_bar = NO;
7193
7194
7195#ifdef NS_IMPL_COCOA
7196 {
7197 NSButton *toggleButton;
7198 toggleButton = [window standardWindowButton: NSWindowToolbarButton];
7199 [toggleButton setTarget: self];
7200 [toggleButton setAction: @selector (toggleToolbar: )];
7201 }
7202#endif
7203}
7204
7205
7206- (instancetype) initFrameFromEmacs: (struct frame *)f 7174- (instancetype) initFrameFromEmacs: (struct frame *)f
7207{ 7175{
7208 NSTRACE ("[EmacsView initFrameFromEmacs:]"); 7176 NSTRACE ("[EmacsView initFrameFromEmacs:]");
@@ -7254,10 +7222,6 @@ not_in_argv (NSString *arg)
7254 if (ns_drag_types) 7222 if (ns_drag_types)
7255 [self registerForDraggedTypes: ns_drag_types]; 7223 [self registerForDraggedTypes: ns_drag_types];
7256 7224
7257 /* toolbar support */
7258 if (! FRAME_UNDECORATED (f))
7259 [self createToolbar: f];
7260
7261#if !defined (NS_IMPL_COCOA) \ 7225#if !defined (NS_IMPL_COCOA) \
7262 || MAC_OS_X_VERSION_MIN_REQUIRED <= 1090 7226 || MAC_OS_X_VERSION_MIN_REQUIRED <= 1090
7263#if MAC_OS_X_VERSION_MAX_ALLOWED > 1090 7227#if MAC_OS_X_VERSION_MAX_ALLOWED > 1090
@@ -7537,7 +7501,7 @@ not_in_argv (NSString *arg)
7537 [NSApp setPresentationOptions: options]; 7501 [NSApp setPresentationOptions: options];
7538 } 7502 }
7539#endif 7503#endif
7540 [toolbar setVisible:tbar_visible]; 7504 [[[self window]toolbar] setVisible:tbar_visible];
7541 } 7505 }
7542} 7506}
7543 7507
@@ -7580,12 +7544,12 @@ not_in_argv (NSString *arg)
7580#endif 7544#endif
7581 if (FRAME_EXTERNAL_TOOL_BAR (emacsframe)) 7545 if (FRAME_EXTERNAL_TOOL_BAR (emacsframe))
7582 { 7546 {
7583 [toolbar setVisible:YES]; 7547 [[[self window] toolbar] setVisible:YES];
7584 update_frame_tool_bar (emacsframe); 7548 update_frame_tool_bar (emacsframe);
7585 [[self window] display]; 7549 [[self window] display];
7586 } 7550 }
7587 else 7551 else
7588 [toolbar setVisible:NO]; 7552 [[[self window] toolbar] setVisible:NO];
7589 7553
7590 if (next_maximized != -1) 7554 if (next_maximized != -1)
7591 [[self window] performZoom:self]; 7555 [[self window] performZoom:self];
@@ -7884,12 +7848,6 @@ not_in_argv (NSString *arg)
7884} 7848}
7885 7849
7886 7850
7887- (EmacsToolbar *)toolbar
7888{
7889 return toolbar;
7890}
7891
7892
7893/* This gets called on toolbar button click. */ 7851/* This gets called on toolbar button click. */
7894- (instancetype)toolbarClicked: (id)item 7852- (instancetype)toolbarClicked: (id)item
7895{ 7853{
@@ -8441,6 +8399,10 @@ not_in_argv (NSString *arg)
8441 if ([col alphaComponent] != (EmacsCGFloat) 1.0) 8399 if ([col alphaComponent] != (EmacsCGFloat) 1.0)
8442 [self setOpaque:NO]; 8400 [self setOpaque:NO];
8443 8401
8402 /* toolbar support */
8403 if (! FRAME_UNDECORATED (f))
8404 [self createToolbar:f];
8405
8444 /* macOS Sierra automatically enables tabbed windows. We can't 8406 /* macOS Sierra automatically enables tabbed windows. We can't
8445 allow this to be enabled until it's available on a Free system. 8407 allow this to be enabled until it's available on a Free system.
8446 Currently it only happens by accident and is buggy anyway. */ 8408 Currently it only happens by accident and is buggy anyway. */
@@ -8454,6 +8416,36 @@ not_in_argv (NSString *arg)
8454} 8416}
8455 8417
8456 8418
8419- (void)createToolbar: (struct frame *)f
8420{
8421 EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f);
8422
8423 EmacsToolbar *toolbar = [[EmacsToolbar alloc]
8424 initForView:view
8425 withIdentifier:[NSString stringWithLispString:f->name]];
8426 [self setToolbar:toolbar];
8427
8428 update_frame_tool_bar (f);
8429
8430#ifdef NS_IMPL_COCOA
8431 {
8432 NSButton *toggleButton;
8433 toggleButton = [self standardWindowButton:NSWindowToolbarButton];
8434 [toggleButton setTarget:view];
8435 [toggleButton setAction:@selector (toggleToolbar:)];
8436 }
8437#endif
8438}
8439
8440- (void)dealloc
8441{
8442 NSTRACE ("[EmacsWindow dealloc]");
8443
8444 /* We need to release the toolbar ourselves. */
8445 [[self toolbar] release];
8446 [super dealloc];
8447}
8448
8457- (NSInteger) borderWidth 8449- (NSInteger) borderWidth
8458{ 8450{
8459 return NSWidth ([self frame]) - NSWidth ([[self contentView] frame]); 8451 return NSWidth ([self frame]) - NSWidth ([[self contentView] frame]);