From 0bba37f51ded370ee79e26916c4c94ce5dc1f44e Mon Sep 17 00:00:00 2001 From: David Elliott Date: Mon, 22 Nov 2004 20:10:53 +0000 Subject: [PATCH] Fix centering of top-level children of wxMDIParentFrame on Mac git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30706 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/mac/carbon/mdi.h | 2 ++ include/wx/toplevel.h | 3 +++ src/common/toplvcmn.cpp | 6 ++++++ src/common/wincmn.cpp | 17 ++++++++++++----- src/mac/carbon/mdi.cpp | 9 +++++++++ 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/include/wx/mac/carbon/mdi.h b/include/wx/mac/carbon/mdi.h index bde585e045..eb55fff2a1 100644 --- a/include/wx/mac/carbon/mdi.h +++ b/include/wx/mac/carbon/mdi.h @@ -68,6 +68,8 @@ public: // Get the client window inline wxMDIClientWindow *GetClientWindow() const { return m_clientWindow; }; + // Get rect to be used to center top-level children + virtual void GetRectForTopLevelChildren(int *x, int *y, int *w, int *h); // Create the client window class (don't Create the window, // just return a new class) diff --git a/include/wx/toplevel.h b/include/wx/toplevel.h index e2201ae8fd..b14af59160 100644 --- a/include/wx/toplevel.h +++ b/include/wx/toplevel.h @@ -196,6 +196,9 @@ public: void OnCloseWindow(wxCloseEvent& event); void OnSize(wxSizeEvent& WXUNUSED(event)) { DoLayout(); } + // Get rect to be used to center top-level children + virtual void GetRectForTopLevelChildren(int *x, int *y, int *w, int *h); + // this should go away, but for now it's called from docview.cpp, // so should be there for all platforms void OnActivate(wxActivateEvent &WXUNUSED(event)) { } diff --git a/src/common/toplvcmn.cpp b/src/common/toplvcmn.cpp index e23349fb52..0146f40ab4 100644 --- a/src/common/toplvcmn.cpp +++ b/src/common/toplvcmn.cpp @@ -109,6 +109,12 @@ bool wxTopLevelWindowBase::IsLastBeforeExit() const // wxTopLevelWindow geometry // ---------------------------------------------------------------------------- +void wxTopLevelWindowBase::GetRectForTopLevelChildren(int *x, int *y, int *w, int *h) +{ + GetPosition(x,y); + GetSize(w,h); +} + wxSize wxTopLevelWindowBase::GetMaxSize() const { wxSize size( GetMaxWidth(), GetMaxHeight() ); diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index f906802a0f..546182a212 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -388,6 +388,7 @@ void wxWindowBase::Centre(int direction) int widthParent, heightParent; wxWindow *parent = NULL; + wxTopLevelWindow *winTop = NULL; if ( !(direction & wxCENTRE_ON_SCREEN) ) { @@ -409,9 +410,10 @@ void wxWindowBase::Centre(int direction) // Windows, for example, this places it completely off the screen if ( parent ) { - wxTopLevelWindow *winTop = wxDynamicCast(parent, wxTopLevelWindow); + winTop = wxDynamicCast(parent, wxTopLevelWindow); if ( winTop && winTop->IsIconized() ) { + winTop = NULL; parent = NULL; } } @@ -434,11 +436,16 @@ void wxWindowBase::Centre(int direction) { if ( IsTopLevel() ) { - // centre on the parent - parent->GetSize(&widthParent, &heightParent); + if(winTop) + winTop->GetRectForTopLevelChildren(&posParent.x, &posParent.y, &widthParent, &heightParent); + else + { + // centre on the parent + parent->GetSize(&widthParent, &heightParent); - // adjust to the parents position - posParent = parent->GetPosition(); + // adjust to the parents position + posParent = parent->GetPosition(); + } } else { diff --git a/src/mac/carbon/mdi.cpp b/src/mac/carbon/mdi.cpp index a5672eebec..0c80890f18 100644 --- a/src/mac/carbon/mdi.cpp +++ b/src/mac/carbon/mdi.cpp @@ -117,6 +117,15 @@ void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar) wxFrame::SetMenuBar( menu_bar ) ; } +void wxMDIParentFrame::GetRectForTopLevelChildren(int *x, int *y, int *w, int *h) +{ + if(x) + *x = 0; + if(y) + *y = 0; + wxDisplaySize(w,h); +} + void wxMDIParentFrame::MacActivate(long timestamp, bool activating) { wxLogDebug(wxT("MDI PARENT=%p MacActivate(0x%08lx,%s)"),this,timestamp,activating?wxT("ACTIV"):wxT("deact"));