]> git.saurik.com Git - wxWidgets.git/commitdiff
Implemented toolbar/statusbar positioning
authorDavid Elliott <dfe@tgwbd.org>
Thu, 14 Aug 2003 20:34:07 +0000 (20:34 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Thu, 14 Aug 2003 20:34:07 +0000 (20:34 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22890 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/cocoa/frame.h
include/wx/cocoa/toplevel.h
src/cocoa/frame.mm
src/cocoa/toplevel.mm

index d20f4ed16f111f5f2c728cb34ed7b7a0d506fe28..02e19ed615d0626125d4648bf7eeeb90a8fade81 100644 (file)
@@ -53,6 +53,13 @@ protected:
 // ------------------------------------------------------------------------
 protected:
     virtual void Cocoa_wxMenuItemAction(wxMenuItem& item);
+
+    // Helper function to position status/tool bars
+    void UpdateFrameNSView();
+
+    virtual void CocoaReplaceView(WX_NSView oldView, WX_NSView newView);
+    // frameNSView is used whenever a statusbar/generic toolbar are present
+    WX_NSView m_frameNSView;
 // ------------------------------------------------------------------------
 // Implementation
 // ------------------------------------------------------------------------
@@ -70,9 +77,21 @@ public:
     // if the frame has a toolbar) in client coordinates
     virtual wxPoint GetClientAreaOrigin() const;
 
+    // create the main status bar by calling OnCreateStatusBar()
+    virtual wxStatusBar* CreateStatusBar(int number = 1,
+                                         long style = wxST_SIZEGRIP,
+                                         wxWindowID winid = 0,
+                                         const wxString& name =
+                                            wxStatusLineNameStr);
+    // sets the main status bar
+    void SetStatusBar(wxStatusBar *statBar);
+    // create main toolbar bycalling OnCreateToolBar()
+    virtual wxToolBar* CreateToolBar(long style = -1,
+                                     wxWindowID winid = -1,
+                                     const wxString& name = wxToolBarNameStr);
+    // sets the main tool bar
+    virtual void SetToolBar(wxToolBar *toolbar);
 protected:
-    // Catch the Cocoa size event
-    virtual void Cocoa_FrameChanged(void);
     void PositionStatusBar();
     // override base class virtuals
     virtual void DoGetClientSize(int *width, int *height) const;
index 9af31a2e519560590d4c6cb0b2012b4fe24cbaec..c23c18ff46e4e8acc99ece1b337d4620b98e7b90 100644 (file)
@@ -66,6 +66,7 @@ protected:
     void SetNSWindow(WX_NSWindow cocoaNSWindow);
     WX_NSWindow m_cocoaNSWindow;
     static wxCocoaNSWindowHash sm_cocoaHash;
+    virtual void CocoaReplaceView(WX_NSView oldView, WX_NSView newView);
 
 // ------------------------------------------------------------------------
 // Implementation
index 4024b2534c0f4b8c6d3aeebff90de15400ad98ff..7c0387a644f91a7251d6e05c115fcf40957eff79 100644 (file)
 #include "wx/app.h"
 #include "wx/log.h"
 #include "wx/statusbr.h"
+#include "wx/toolbar.h"
 
 #include "wx/cocoa/autorelease.h"
 
 #import <AppKit/NSWindow.h>
 #import <AppKit/NSApplication.h>
+#import <AppKit/NSView.h>
 
 // wxFrame
 
@@ -30,6 +32,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
 
 void wxFrame::Init()
 {
+    m_frameNSView = nil;
 }
 
 bool wxFrame::Create(wxWindow *parent,
@@ -47,6 +50,7 @@ bool wxFrame::Create(wxWindow *parent,
 
 wxFrame::~wxFrame()
 {
+    [m_frameNSView release];
 }
 
 void wxFrame::Cocoa_wxMenuItemAction(wxMenuItem& item)
@@ -82,12 +86,6 @@ bool wxFrame::Show(bool show)
     return ret;
 }
 
-void wxFrame::Cocoa_FrameChanged(void)
-{
-    PositionStatusBar();
-    wxFrameBase::Cocoa_FrameChanged();
-}
-
 wxPoint wxFrame::GetClientAreaOrigin() const
 {
     return wxPoint(0,0);
@@ -110,20 +108,131 @@ void wxFrame::DoSetClientSize(int width, int height)
     wxFrameBase::DoSetClientSize(width,height);
 }
 
-void wxFrame::PositionStatusBar()
+void wxFrame::CocoaReplaceView(WX_NSView oldView, WX_NSView newView)
+{
+    // If we have the additional toolbar/statbar view, then the
+    // default replaceSubview will work. Otherwise, the old view
+    // should be the content view and should be replaced that way
+    if(m_frameNSView)
+        wxWindow::CocoaReplaceView(oldView, newView);
+    else
+        wxTopLevelWindow::CocoaReplaceView(oldView, newView);
+}
+
+void wxFrame::UpdateFrameNSView()
+{
+    if(!m_frameNSView)
+    {
+        m_frameNSView = [[NSView alloc] initWithFrame:[[m_cocoaNSWindow contentView] frame]];
+        [m_cocoaNSWindow setContentView: m_frameNSView];
+        [m_frameNSView addSubview:m_cocoaNSView];
+    }
+    NSRect frameRect = [m_frameNSView frame];
+    float tbarheight = 0.0;
+    if(m_frameToolBar)
+    {
+        NSView *tbarNSView = m_frameToolBar->GetNSViewForSuperview();
+        if(![tbarNSView superview])
+            [m_frameNSView addSubview: tbarNSView];
+        NSRect tbarRect = [tbarNSView frame];
+        tbarRect.size.width = frameRect.size.width;
+        tbarRect.origin.x = 0.0;
+        tbarRect.origin.y = frameRect.size.height - tbarRect.size.height;
+        [tbarNSView setFrame:tbarRect];
+        // width expands, bottom margin expands
+        [tbarNSView setAutoresizingMask: NSViewWidthSizable|NSViewMinYMargin];
+        tbarheight = tbarRect.size.height;
+    }
+    float sbarheight = 0.0;
+    if(m_frameStatusBar)
+    {
+        NSView *sbarNSView = m_frameStatusBar->GetNSViewForSuperview();
+        if(![sbarNSView superview])
+            [m_frameNSView addSubview: sbarNSView];
+        NSRect sbarRect = [sbarNSView frame];
+        sbarRect.size.width = frameRect.size.width;
+        sbarRect.origin.x = 0.0;
+        sbarRect.origin.y = 0.0;
+        [sbarNSView setFrame:sbarRect];
+        // width expands, top margin expands
+        [sbarNSView setAutoresizingMask: NSViewWidthSizable|NSViewMaxYMargin];
+        sbarheight = sbarRect.size.height;
+    }
+    wxLogDebug("frame height=%f, tbar=%f, sbar=%f",frameRect.size.height,tbarheight,sbarheight);
+    NSRect innerRect = [m_cocoaNSView frame];
+    innerRect.size.height = frameRect.size.height - tbarheight - sbarheight;
+    innerRect.origin.y = sbarheight;
+    [m_cocoaNSView setFrame:innerRect];
+    [m_cocoaNSView setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
+    // Don't let the frame get smaller than the toolbar+statusbar height
+    NSRect frameMinRect = [NSWindow frameRectForContentRect:
+            NSMakeRect(0.0,0.0,0.0,tbarheight+sbarheight)
+        styleMask: [m_cocoaNSWindow styleMask]];
+    [m_cocoaNSWindow setMinSize:frameMinRect.size];
+}
+
+void wxFrame::SetStatusBar(wxStatusBar *statusbar)
+{
+    if(m_frameStatusBar)
+    {
+        [m_frameStatusBar->GetNSViewForSuperview() removeFromSuperview];
+        [m_frameStatusBar->GetNSViewForSuperview() setAutoresizingMask: NSViewNotSizable];
+        if(m_frameStatusBar->GetParent())
+            m_frameStatusBar->GetParent()->CocoaAddChild(m_frameToolBar);
+    }
+    m_frameStatusBar = statusbar;
+    if(m_frameStatusBar)
+    {
+        m_frameStatusBar->CocoaRemoveFromParent();
+    }
+    UpdateFrameNSView();
+}
+
+wxStatusBar* wxFrame::CreateStatusBar(int number,
+                                          long style,
+                                          wxWindowID winid,
+                                          const wxString& name)
 {
-    if( !m_frameStatusBar || !m_frameStatusBar->IsShown() )
-        return;
+    wxFrameBase::CreateStatusBar(number,style,winid,name);
+    if(m_frameStatusBar)
+    {
+        m_frameStatusBar->CocoaRemoveFromParent();
+    }
+    UpdateFrameNSView();
+    return m_frameStatusBar;
+}
 
-    // Get the client size.  Since it excludes the StatusBar area we want
-    // the top of the status bar to be directly under it (thus located at h)
-    // The width of the statusbar should then match the client width
-    int w, h;
-    GetClientSize(&w, &h);
+void wxFrame::SetToolBar(wxToolBar *toolbar)
+{
+    if(m_frameToolBar)
+    {
+        [m_frameToolBar->GetNSViewForSuperview() removeFromSuperview];
+        [m_frameToolBar->GetNSViewForSuperview() setAutoresizingMask: NSViewNotSizable];
+        if(m_frameToolBar->GetParent())
+            m_frameToolBar->GetParent()->CocoaAddChild(m_frameToolBar);
+    }
+    m_frameToolBar = toolbar;
+    if(m_frameToolBar)
+    {
+        m_frameToolBar->CocoaRemoveFromParent();
+    }
+    UpdateFrameNSView();
+}
 
-    int sh;
-    m_frameStatusBar->GetSize(NULL, &sh);
+wxToolBar* wxFrame::CreateToolBar(long style,
+                                      wxWindowID winid,
+                                      const wxString& name)
+{
+    wxFrameBase::CreateToolBar(style,winid,name);
+    if(m_frameToolBar)
+    {
+        m_frameToolBar->CocoaRemoveFromParent();
+    }
+    UpdateFrameNSView();
+    return m_frameToolBar;
+}
 
-    m_frameStatusBar->SetSize(0, h, w, sh);
+void wxFrame::PositionStatusBar()
+{
 }
 
index 4c138ca8f05bc8d186e63a8ae63f38633c90276e..068d4bd7242e1f57c045440992a113a516fab1f2 100644 (file)
@@ -122,6 +122,12 @@ void wxTopLevelWindowCocoa::SetNSWindow(WX_NSWindow cocoaNSWindow)
     if(need_debug) wxLogDebug("wxTopLevelWindowCocoa=%p::SetNSWindow [cocoaNSWindow=%p retainCount]=%d",this,cocoaNSWindow,[cocoaNSWindow retainCount]);
 }
 
+void wxTopLevelWindowCocoa::CocoaReplaceView(WX_NSView oldView, WX_NSView newView)
+{
+    if([m_cocoaNSWindow contentView] == oldView)
+        [m_cocoaNSWindow setContentView:newView];
+}
+
 void wxTopLevelWindowCocoa::Cocoa_wxMenuItemAction(wxMenuItem& item)
 {
 }