X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a58a6614646ea85d5cceb26f88e61a4a5a460149..cb73e6001f891ae46b12a1e4ca39b93649cb6099:/src/cocoa/frame.mm diff --git a/src/cocoa/frame.mm b/src/cocoa/frame.mm index 3ab4609843..4f3d12062f 100644 --- a/src/cocoa/frame.mm +++ b/src/cocoa/frame.mm @@ -15,9 +15,13 @@ #include "wx/app.h" #include "wx/log.h" #include "wx/statusbr.h" +#include "wx/toolbar.h" + +#include "wx/cocoa/autorelease.h" #import #import +#import // wxFrame @@ -28,6 +32,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow) void wxFrame::Init() { + m_frameNSView = nil; } bool wxFrame::Create(wxWindow *parent, @@ -45,6 +50,7 @@ bool wxFrame::Create(wxWindow *parent, wxFrame::~wxFrame() { + [m_frameNSView release]; } void wxFrame::Cocoa_wxMenuItemAction(wxMenuItem& item) @@ -73,54 +79,152 @@ void wxFrame::DetachMenuBar() bool wxFrame::Show(bool show) { + wxAutoNSAutoreleasePool pool; bool ret = wxFrameBase::Show(show); if(show && GetMenuBar()) [wxTheApp->GetNSApplication() setMenu:GetMenuBar()->GetNSMenu() ]; return ret; } -void wxFrame::Cocoa_FrameChanged(void) +wxPoint wxFrame::GetClientAreaOrigin() const { - PositionStatusBar(); - wxFrameBase::Cocoa_FrameChanged(); + return wxPoint(0,0); } -wxPoint wxFrame::GetClientAreaOrigin() const +void wxFrame::CocoaSetWxWindowSize(int width, int height) { - return wxPoint(0,0); + if(m_frameStatusBar) + height += m_frameStatusBar->GetSize().y; + if(m_frameToolBar) + height += m_frameToolBar->GetSize().y; + wxTopLevelWindow::CocoaSetWxWindowSize(width,height); +} + +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::DoGetClientSize(int *width, int *height) const +void wxFrame::UpdateFrameNSView() { - wxFrameBase::DoGetClientSize(width,height); - if(height) + if(!m_frameNSView) { - if(m_frameStatusBar && m_frameStatusBar->IsShown()) - *height -= m_frameStatusBar->GetSize().y; + 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::DoSetClientSize(int width, int height) +void wxFrame::SetStatusBar(wxStatusBar *statusbar) { - if(m_frameStatusBar && m_frameStatusBar->IsShown()) - height += m_frameStatusBar->GetSize().y; - wxFrameBase::DoSetClientSize(width,height); + if(m_frameStatusBar) + { + [m_frameStatusBar->GetNSViewForSuperview() removeFromSuperview]; + [m_frameStatusBar->GetNSViewForSuperview() setAutoresizingMask: NSViewMinYMargin]; + if(m_frameStatusBar->GetParent()) + m_frameStatusBar->GetParent()->CocoaAddChild(m_frameToolBar); + } + m_frameStatusBar = statusbar; + if(m_frameStatusBar) + { + m_frameStatusBar->CocoaRemoveFromParent(); + } + UpdateFrameNSView(); } -void wxFrame::PositionStatusBar() +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: NSViewMinYMargin]; + 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() +{ }