emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

scratch/ns/refactor ee6db19 5/9: Move NS port toolbar handling to the wi


From: Alan Third
Subject: scratch/ns/refactor ee6db19 5/9: Move NS port toolbar handling to the window
Date: Fri, 25 Jun 2021 13:16:57 -0400 (EDT)

branch: scratch/ns/refactor
commit ee6db19012faf2193f121c383d2385471e646920
Author: Alan Third <alan@idiocy.org>
Commit: Alan Third <alan@idiocy.org>

    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.
---
 src/nsmenu.m | 16 +++---------
 src/nsterm.h |  4 ---
 src/nsterm.m | 84 +++++++++++++++++++++++++++---------------------------------
 3 files changed, 42 insertions(+), 62 deletions(-)

diff --git a/src/nsmenu.m b/src/nsmenu.m
index 1b03fe9..673c042 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 fd51681..032d483 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 19e5d3c..c0d0a12 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1109,7 +1109,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];
   }
@@ -1851,9 +1851,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];
 
@@ -6177,7 +6174,6 @@ not_in_argv (NSString *arg)
               name:NSViewFrameDidChangeNotification
             object:nil];
 
-  [toolbar release];
   if (fs_state == FULLSCREEN_BOTH)
     [nonfs_window release];
   [super dealloc];
@@ -7260,34 +7256,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:]");
@@ -7339,10 +7307,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
@@ -7622,7 +7586,7 @@ not_in_argv (NSString *arg)
           [NSApp setPresentationOptions: options];
         }
 #endif
-      [toolbar setVisible:tbar_visible];
+      [[[self window]toolbar] setVisible:tbar_visible];
     }
 }
 
@@ -7665,12 +7629,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];
@@ -7969,12 +7933,6 @@ not_in_argv (NSString *arg)
 }
 
 
-- (EmacsToolbar *)toolbar
-{
-  return toolbar;
-}
-
-
 /* This gets called on toolbar button click.  */
 - (instancetype)toolbarClicked: (id)item
 {
@@ -8526,6 +8484,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.  */
@@ -8539,6 +8501,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]);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]