X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2fc2d511d0f095ab5de3713cff6042832f886d15..3a7c125370cf6fd2b66eb06ba031efcfd5c5b9b0:/src/cocoa/frame.mm diff --git a/src/cocoa/frame.mm b/src/cocoa/frame.mm index 3c40bc0f66..7ed2c50c8f 100644 --- a/src/cocoa/frame.mm +++ b/src/cocoa/frame.mm @@ -20,6 +20,7 @@ #endif // WX_PRECOMP #include "wx/cocoa/autorelease.h" +#include "wx/cocoa/mbarman.h" #import #import @@ -58,29 +59,33 @@ wxFrame::~wxFrame() void wxFrame::AttachMenuBar(wxMenuBar *mbar) { wxFrameBase::AttachMenuBar(mbar); - if(m_frameMenuBar) - { - wxLogDebug("Attached menu"); - [m_cocoaNSWindow setMenu:m_frameMenuBar->GetNSMenu()]; - } + wxMenuBarManager::GetInstance()->UpdateMenuBar(); } void wxFrame::DetachMenuBar() { - if(m_frameMenuBar) + wxFrameBase::DetachMenuBar(); + wxMenuBarManager::GetInstance()->UpdateMenuBar(); +} + +void wxFrame::SetMenuBar(wxMenuBar *menubar) +{ + if ( menubar == GetMenuBar() ) { - [m_cocoaNSWindow setMenu:nil]; + // nothing to do + return; } + wxFrameBase::DetachMenuBar(); + wxFrameBase::AttachMenuBar(menubar); + wxMenuBarManager::GetInstance()->UpdateMenuBar(); } -bool wxFrame::Show(bool show) +wxMenuBar* wxFrame::GetAppMenuBar(wxCocoaNSWindow *win) { - wxAutoNSAutoreleasePool pool; - bool ret = wxFrameBase::Show(show); - if(show && GetMenuBar()) - [wxTheApp->GetNSApplication() setMenu:GetMenuBar()->GetNSMenu() ]; - return ret; + if(GetMenuBar()) + return GetMenuBar(); + return wxFrameBase::GetAppMenuBar(win); } wxPoint wxFrame::GetClientAreaOrigin() const @@ -99,6 +104,13 @@ void wxFrame::CocoaSetWxWindowSize(int width, int height) wxTopLevelWindow::CocoaSetWxWindowSize(width,height); } +WX_NSView wxFrame::GetNonClientNSView() +{ + if(m_frameNSView) + return m_frameNSView; + return GetNSViewForSuperview(); +} + void wxFrame::CocoaReplaceView(WX_NSView oldView, WX_NSView newView) { // If we have the additional toolbar/statbar view, then the @@ -126,6 +138,8 @@ void wxFrame::UpdateFrameNSView() NSView *tbarNSView = m_frameToolBar->GetNSViewForSuperview(); if(![tbarNSView superview]) [m_frameNSView addSubview: tbarNSView]; + // Do this after addSubView so that SetSize can work + m_frameToolBar->SetSize(m_frameToolBar->DoGetBestSize()); NSRect tbarRect = [tbarNSView frame]; tbarRect.size.width = frameRect.size.width; tbarRect.origin.x = 0.0; @@ -151,7 +165,7 @@ void wxFrame::UpdateFrameNSView() [sbarNSView setAutoresizingMask: NSViewWidthSizable|NSViewMaxYMargin]; sbarheight = sbarRect.size.height; } - wxLogDebug("frame height=%f, tbar=%f, sbar=%f",frameRect.size.height,tbarheight,sbarheight); + wxLogTrace(wxTRACE_COCOA,wxT("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; @@ -186,6 +200,7 @@ wxStatusBar* wxFrame::CreateStatusBar(int number, wxWindowID winid, const wxString& name) { + wxAutoNSAutoreleasePool pool; wxFrameBase::CreateStatusBar(number,style,winid,name); if(m_frameStatusBar) { @@ -200,6 +215,7 @@ void wxFrame::SetToolBar(wxToolBar *toolbar) { if(m_frameToolBar) { + m_frameToolBar->SetOwningFrame(NULL); [m_frameToolBar->GetNSViewForSuperview() removeFromSuperview]; [m_frameToolBar->GetNSViewForSuperview() setAutoresizingMask: NSViewMinYMargin]; if(m_frameToolBar->GetParent()) @@ -209,6 +225,7 @@ void wxFrame::SetToolBar(wxToolBar *toolbar) if(m_frameToolBar) { m_frameToolBar->CocoaRemoveFromParent(); + m_frameToolBar->SetOwningFrame(this); } UpdateFrameNSView(); } @@ -217,10 +234,12 @@ wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID winid, const wxString& name) { + wxAutoNSAutoreleasePool pool; wxFrameBase::CreateToolBar(style,winid,name); if(m_frameToolBar) { m_frameToolBar->CocoaRemoveFromParent(); + m_frameToolBar->SetOwningFrame(this); } UpdateFrameNSView(); return m_frameToolBar;