X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/448cbf1d4ef247bacd87dadb38e0bce895ead4d1..3ca4086b22723db16d7e0fc23aa9021b4785096a:/src/cocoa/frame.mm diff --git a/src/cocoa/frame.mm b/src/cocoa/frame.mm index 7c0387a644..7ed2c50c8f 100644 --- a/src/cocoa/frame.mm +++ b/src/cocoa/frame.mm @@ -9,15 +9,18 @@ // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// -#include "wx/frame.h" -#include "wx/menu.h" -#include "wx/menuitem.h" -#include "wx/app.h" -#include "wx/log.h" -#include "wx/statusbr.h" -#include "wx/toolbar.h" +#include "wx/wxprec.h" +#ifndef WX_PRECOMP + #include "wx/log.h" + #include "wx/app.h" + #include "wx/frame.h" + #include "wx/menu.h" + #include "wx/toolbar.h" + #include "wx/statusbr.h" +#endif // WX_PRECOMP #include "wx/cocoa/autorelease.h" +#include "wx/cocoa/mbarman.h" #import #import @@ -53,37 +56,36 @@ wxFrame::~wxFrame() [m_frameNSView release]; } -void wxFrame::Cocoa_wxMenuItemAction(wxMenuItem& item) -{ - Command(item.GetId()); -} - 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 @@ -91,21 +93,22 @@ wxPoint wxFrame::GetClientAreaOrigin() const return wxPoint(0,0); } -void wxFrame::DoGetClientSize(int *width, int *height) const +void wxFrame::CocoaSetWxWindowSize(int width, int height) { - wxFrameBase::DoGetClientSize(width,height); - if(height) - { - if(m_frameStatusBar && m_frameStatusBar->IsShown()) - *height -= m_frameStatusBar->GetSize().y; - } + if(m_frameStatusBar) + height += m_frameStatusBar->GetSize().y; +#if wxUSE_TOOLBAR + if(m_frameToolBar) + height += m_frameToolBar->GetSize().y; +#endif //wxUSE_TOOLBAR + wxTopLevelWindow::CocoaSetWxWindowSize(width,height); } -void wxFrame::DoSetClientSize(int width, int height) +WX_NSView wxFrame::GetNonClientNSView() { - if(m_frameStatusBar && m_frameStatusBar->IsShown()) - height += m_frameStatusBar->GetSize().y; - wxFrameBase::DoSetClientSize(width,height); + if(m_frameNSView) + return m_frameNSView; + return GetNSViewForSuperview(); } void wxFrame::CocoaReplaceView(WX_NSView oldView, WX_NSView newView) @@ -129,11 +132,14 @@ void wxFrame::UpdateFrameNSView() } NSRect frameRect = [m_frameNSView frame]; float tbarheight = 0.0; +#if wxUSE_TOOLBAR if(m_frameToolBar) { 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; @@ -143,6 +149,7 @@ void wxFrame::UpdateFrameNSView() [tbarNSView setAutoresizingMask: NSViewWidthSizable|NSViewMinYMargin]; tbarheight = tbarRect.size.height; } +#endif //wxUSE_TOOLBAR float sbarheight = 0.0; if(m_frameStatusBar) { @@ -158,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; @@ -176,9 +183,9 @@ void wxFrame::SetStatusBar(wxStatusBar *statusbar) if(m_frameStatusBar) { [m_frameStatusBar->GetNSViewForSuperview() removeFromSuperview]; - [m_frameStatusBar->GetNSViewForSuperview() setAutoresizingMask: NSViewNotSizable]; + [m_frameStatusBar->GetNSViewForSuperview() setAutoresizingMask: NSViewMinYMargin]; if(m_frameStatusBar->GetParent()) - m_frameStatusBar->GetParent()->CocoaAddChild(m_frameToolBar); + m_frameStatusBar->GetParent()->CocoaAddChild(m_frameStatusBar); } m_frameStatusBar = statusbar; if(m_frameStatusBar) @@ -193,6 +200,7 @@ wxStatusBar* wxFrame::CreateStatusBar(int number, wxWindowID winid, const wxString& name) { + wxAutoNSAutoreleasePool pool; wxFrameBase::CreateStatusBar(number,style,winid,name); if(m_frameStatusBar) { @@ -202,12 +210,14 @@ wxStatusBar* wxFrame::CreateStatusBar(int number, return m_frameStatusBar; } +#if wxUSE_TOOLBAR void wxFrame::SetToolBar(wxToolBar *toolbar) { if(m_frameToolBar) { + m_frameToolBar->SetOwningFrame(NULL); [m_frameToolBar->GetNSViewForSuperview() removeFromSuperview]; - [m_frameToolBar->GetNSViewForSuperview() setAutoresizingMask: NSViewNotSizable]; + [m_frameToolBar->GetNSViewForSuperview() setAutoresizingMask: NSViewMinYMargin]; if(m_frameToolBar->GetParent()) m_frameToolBar->GetParent()->CocoaAddChild(m_frameToolBar); } @@ -215,6 +225,7 @@ void wxFrame::SetToolBar(wxToolBar *toolbar) if(m_frameToolBar) { m_frameToolBar->CocoaRemoveFromParent(); + m_frameToolBar->SetOwningFrame(this); } UpdateFrameNSView(); } @@ -223,14 +234,17 @@ 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; } +#endif // wxUSE_TOOLBAR void wxFrame::PositionStatusBar() {