X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1f0c8f31f407ecfce909060464c0ea655221cdab..bb996f289574defb0ae4339ae8e46ff3cf6fa54c:/src/osx/carbon/frame.cpp diff --git a/src/osx/carbon/frame.cpp b/src/osx/carbon/frame.cpp index fb6b170ae8..09cd082182 100644 --- a/src/osx/carbon/frame.cpp +++ b/src/osx/carbon/frame.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/frame.cpp +// Name: src/osx/carbon/frame.cpp // Purpose: wxFrame // Author: Stefan Csomor // Modified by: @@ -24,18 +24,13 @@ #include "wx/menuitem.h" #endif // WX_PRECOMP -#include "wx/osx/uma.h" +#include "wx/osx/private.h" BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) EVT_ACTIVATE(wxFrame::OnActivate) - // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) -// EVT_IDLE(wxFrame::OnIdle) -// EVT_CLOSE(wxFrame::OnCloseWindow) END_EVENT_TABLE() -IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow) - #define WX_MAC_STATUSBAR_HEIGHT 18 // ---------------------------------------------------------------------------- @@ -55,7 +50,6 @@ bool wxFrame::Create(wxWindow *parent, long style, const wxString& name) { - if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) ) return false; @@ -64,7 +58,8 @@ bool wxFrame::Create(wxWindow *parent, wxFrame::~wxFrame() { - m_isBeingDeleted = true; + SendDestroyEvent(); + DeleteAllBars(); } @@ -80,13 +75,13 @@ wxPoint wxFrame::GetClientAreaOrigin() const int w, h; toolbar->GetSize(&w, &h); - if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) + if ( toolbar->HasFlag(wxTB_LEFT) ) { pt.x += w; } - else + else if ( toolbar->HasFlag(wxTB_TOP) ) { -#if !wxMAC_USE_NATIVE_TOOLBAR +#if !wxOSX_USE_NATIVE_TOOLBAR pt.y += h; #endif } @@ -101,7 +96,10 @@ bool wxFrame::Enable(bool enable) if ( !wxWindow::Enable(enable) ) return false; - if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() ) +#if wxUSE_MENUS + // we should always enable/disable the menubar, even if we are not current, otherwise + // we might miss some state change later (happened eg in the docview sample after PrintPreview) + if ( m_frameMenuBar /*&& m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar()*/) { int iMaxMenu = m_frameMenuBar->GetMenuCount(); for ( int i = 0 ; i < iMaxMenu ; ++ i ) @@ -109,7 +107,7 @@ bool wxFrame::Enable(bool enable) m_frameMenuBar->EnableTop( i , enable ) ; } } - +#endif return true; } @@ -152,7 +150,7 @@ void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) wxSysColourChangedEvent event2; event2.SetEventObject( m_frameStatusBar ); - m_frameStatusBar->ProcessEvent(event2); + m_frameStatusBar->GetEventHandler()->ProcessEvent(event2); } #endif // wxUSE_STATUSBAR @@ -198,6 +196,7 @@ void wxFrame::OnActivate(wxActivateEvent& event) wxSetFocusToChild(parent, &m_winLastFocused); +#if wxUSE_MENUS if (m_frameMenuBar != NULL) { m_frameMenuBar->MacInstallMenuBar(); @@ -212,20 +211,25 @@ void wxFrame::OnActivate(wxActivateEvent& event) tlf->GetMenuBar()->MacInstallMenuBar(); } } +#endif } } +#if wxUSE_MENUS void wxFrame::DetachMenuBar() { - if ( m_frameMenuBar ) - m_frameMenuBar->UnsetInvokingWindow(); - wxFrameBase::DetachMenuBar(); } void wxFrame::AttachMenuBar( wxMenuBar *menuBar ) { - wxFrame* tlf = wxDynamicCast( wxFindWinFromMacWindow( FrontNonFloatingWindow() ) , wxFrame ); +#if wxOSX_USE_CARBON + wxFrame* tlf = wxDynamicCast( wxNonOwnedWindow::GetFromWXWindow( (WXWindow) FrontNonFloatingWindow() ) , wxFrame ); +#elif wxOSX_USE_COCOA + wxFrame* tlf = wxDynamicCast( wxNonOwnedWindow::GetFromWXWindow( wxOSXGetMainWindow() ) , wxFrame ); +#else + wxFrame* tlf = wxDynamicCast( wxTheApp->GetTopWindow(), wxFrame ); +#endif bool makeCurrent = false; // if this is already the current menubar or we are the frontmost window @@ -239,11 +243,11 @@ void wxFrame::AttachMenuBar( wxMenuBar *menuBar ) if (m_frameMenuBar) { - m_frameMenuBar->SetInvokingWindow( this ); if (makeCurrent) m_frameMenuBar->MacInstallMenuBar(); } } +#endif void wxFrame::DoGetClientSize(int *x, int *y) const { @@ -261,14 +265,19 @@ void wxFrame::DoGetClientSize(int *x, int *y) const int w, h; toolbar->GetSize(&w, &h); - if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) + if ( toolbar->IsVertical() ) { if ( x ) *x -= w; } + else if ( toolbar->HasFlag( wxTB_BOTTOM ) ) + { + if ( y ) + *y -= h; + } else { -#if !wxMAC_USE_NATIVE_TOOLBAR +#if !wxOSX_USE_NATIVE_TOOLBAR if ( y ) *y -= h; #endif @@ -318,17 +327,20 @@ void wxFrame::SetToolBar(wxToolBar *toolbar) if ( m_frameToolBar == toolbar ) return ; -#if wxMAC_USE_NATIVE_TOOLBAR +#ifndef __WXOSX_IPHONE__ +#if wxOSX_USE_NATIVE_TOOLBAR if ( m_frameToolBar ) m_frameToolBar->MacInstallNativeToolbar( false ) ; #endif - +#endif m_frameToolBar = toolbar ; -#if wxMAC_USE_NATIVE_TOOLBAR +#ifndef __WXOSX_IPHONE__ +#if wxOSX_USE_NATIVE_TOOLBAR if ( toolbar ) toolbar->MacInstallNativeToolbar( true ) ; #endif +#endif } wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) @@ -343,44 +355,55 @@ void wxFrame::PositionToolBar() { int cw, ch; - GetSize( &cw , &ch ) ; - + wxTopLevelWindow::DoGetClientSize( &cw , &ch ); + int statusX = 0 ; int statusY = 0 ; #if wxUSE_STATUSBAR if (GetStatusBar() && GetStatusBar()->IsShown()) { - GetStatusBar()->GetClientSize(&statusX, &statusY); + GetStatusBar()->GetSize(&statusX, &statusY); ch -= statusY; } #endif +#ifdef __WXOSX_IPHONE__ + // TODO integrate this in a better way, on iphone the status bar is not a child of the content view + // but the toolbar is + ch -= 20; +#endif + if (GetToolBar()) { int tx, ty, tw, th; tx = ty = 0 ; GetToolBar()->GetSize(&tw, &th); - if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) + if (GetToolBar()->HasFlag(wxTB_LEFT)) + { + // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS + // means, pretend we don't have toolbar/status bar, so we + // have the original client size. + GetToolBar()->SetSize(tx , ty , tw, ch , wxSIZE_NO_ADJUSTMENTS ); + } + else if (GetToolBar()->HasFlag(wxTB_RIGHT)) { // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS // means, pretend we don't have toolbar/status bar, so we // have the original client size. + tx = cw - tw; GetToolBar()->SetSize(tx , ty , tw, ch , wxSIZE_NO_ADJUSTMENTS ); } - else if (GetToolBar()->GetWindowStyleFlag() & wxTB_BOTTOM) + else if (GetToolBar()->HasFlag(wxTB_BOTTOM)) { - //FIXME: this positions the tool bar almost correctly, but still it doesn't work right yet, - //as 1) the space for the 'old' top toolbar is still taken up, and 2) the toolbar - //doesn't extend it's width to the width of the frame. tx = 0; - ty = ch - (th + statusY); + ty = ch - th; GetToolBar()->SetSize(tx, ty, cw, th, wxSIZE_NO_ADJUSTMENTS ); } else { -#if !wxMAC_USE_NATIVE_TOOLBAR +#if !wxOSX_USE_NATIVE_TOOLBAR // Use the 'real' position GetToolBar()->SetSize(tx , ty , cw , th, wxSIZE_NO_ADJUSTMENTS ); #endif