X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cca1624d2a0b06280494e0d3be857819a331f344..0b1cc7bffb94ebfb4bc988b9a7320b96ea0cfcda:/src/common/toplvcmn.cpp diff --git a/src/common/toplvcmn.cpp b/src/common/toplvcmn.cpp index d99000e5e2..aa07d2f096 100644 --- a/src/common/toplvcmn.cpp +++ b/src/common/toplvcmn.cpp @@ -23,8 +23,9 @@ #pragma hdrstop #endif +#include "wx/toplevel.h" + #ifndef WX_PRECOMP - #include "wx/toplevel.h" #include "wx/dcclient.h" #include "wx/app.h" #endif // WX_PRECOMP @@ -54,6 +55,8 @@ wxTopLevelWindowBase::wxTopLevelWindowBase() { // Unlike windows, top level windows are created hidden by default. m_isShown = false; + m_winDefault = NULL; + m_winTmpDefault = NULL; } wxTopLevelWindowBase::~wxTopLevelWindowBase() @@ -62,13 +65,11 @@ wxTopLevelWindowBase::~wxTopLevelWindowBase() if ( wxTheApp && wxTheApp->GetTopWindow() == this ) wxTheApp->SetTopWindow(NULL); - bool shouldExit = IsLastBeforeExit(); - wxTopLevelWindows.DeleteObject(this); - if ( shouldExit ) + if ( IsLastBeforeExit() ) { - // then do it + // no other (important) windows left, quit the app wxTheApp->ExitMainLoop(); } } @@ -96,11 +97,43 @@ bool wxTopLevelWindowBase::Destroy() bool wxTopLevelWindowBase::IsLastBeforeExit() const { - // we exit the application if there are no more top level windows left - // normally but wxApp can prevent this from happening - return wxTopLevelWindows.GetCount() == 1 && - wxTopLevelWindows.GetFirst()->GetData() == (wxWindow *)this && - wxTheApp && wxTheApp->GetExitOnFrameDelete(); + // first of all, automatically exiting the app on last window close can be + // completely disabled at wxTheApp level + if ( !wxTheApp || !wxTheApp->GetExitOnFrameDelete() ) + return false; + + wxWindowList::const_iterator i; + const wxWindowList::const_iterator end = wxTopLevelWindows.end(); + + // then decide whether we should exit at all + for ( i = wxTopLevelWindows.begin(); i != end; ++i ) + { + wxTopLevelWindow * const win = wx_static_cast(wxTopLevelWindow *, *i); + if ( win->ShouldPreventAppExit() ) + { + // there remains at least one important TLW, don't exit + return false; + } + } + + // if yes, close all the other windows: this could still fail + for ( i = wxTopLevelWindows.begin(); i != end; ++i ) + { + // don't close twice the windows which are already marked for deletion + wxTopLevelWindow * const win = wx_static_cast(wxTopLevelWindow *, *i); + if ( !wxPendingDelete.Member(win) && !win->Close() ) + { + // one of the windows refused to close, don't exit + // + // NB: of course, by now some other windows could have been already + // closed but there is really nothing we can do about it as we + // have no way just to ask the window if it can close without + // forcing it to do it + return false; + } + } + + return true; } // ---------------------------------------------------------------------------- @@ -155,6 +188,11 @@ wxSize wxTopLevelWindowBase::GetDefaultSize() void wxTopLevelWindowBase::DoCentre(int dir) { + // on some platforms centering top level windows is impossible + // because they are always maximized by guidelines or limitations + if(IsAlwaysMaximized()) + return; + // we need the display rect anyhow so store it first int nDisplay = wxDisplay::GetFromWindow(this); wxDisplay dpy(nDisplay == wxNOT_FOUND ? 0 : nDisplay); @@ -172,8 +210,8 @@ void wxTopLevelWindowBase::DoCentre(int dir) // parent frame under Mac but could happen elsewhere too if the frame // was hidden/moved away for some reason), don't use it as otherwise // this window wouldn't be visible at all - if ( !rectDisplay.Inside(rectParent.GetTopLeft()) && - !rectParent.Inside(rectParent.GetBottomRight()) ) + if ( !rectDisplay.Contains(rectParent.GetTopLeft()) && + !rectParent.Contains(rectParent.GetBottomRight()) ) { // this is enough to make IsEmpty() test below pass rectParent.width = 0; @@ -197,9 +235,9 @@ void wxTopLevelWindowBase::DoCentre(int dir) // we don't want to place the window off screen if Centre() is called as // this is (almost?) never wanted and it would be very difficult to prevent // it from happening from the user code if we didn't check for it here - if ( rectDisplay.Inside(rect.GetTopLeft()) ) + if ( rectDisplay.Contains(rect.GetTopLeft()) ) { - if ( !rectDisplay.Inside(rect.GetBottomRight()) ) + if ( !rectDisplay.Contains(rect.GetBottomRight()) ) { // check if we can move the window so that the bottom right corner // is visible without hiding the top left one @@ -256,6 +294,14 @@ void wxTopLevelWindowBase::DoClientToScreen(int *x, int *y) const wxWindow::DoClientToScreen(x, y); } +bool wxTopLevelWindowBase::IsAlwaysMaximized() const +{ +#if defined(__SMARTPHONE__) || defined(__POCKETPC__) + return true; +#else + return false; +#endif +} // ---------------------------------------------------------------------------- // event handlers @@ -295,7 +341,7 @@ void wxTopLevelWindowBase::DoLayout() } // do we have any children at all? - if ( child ) + if ( child && child->IsShown() ) { // exactly one child - set it's size to fill the whole frame int clientW, clientH; @@ -304,12 +350,18 @@ void wxTopLevelWindowBase::DoLayout() // for whatever reasons, wxGTK wants to have a small offset - it // probably looks better with it? #ifdef __WXGTK__ - static const int ofs = 1; + const int ofs = 1; + clientW -= 2 * ofs; + clientH -= 2 * ofs; + if (clientW < 0) + clientW = 0; + if (clientH < 0) + clientH = 0; #else - static const int ofs = 0; + const int ofs = 0; #endif - child->SetSize(ofs, ofs, clientW - 2*ofs, clientH - 2*ofs); + child->SetSize(ofs, ofs, clientW, clientH); } } } @@ -349,3 +401,14 @@ void wxTopLevelWindowBase::RequestUserAttention(int WXUNUSED(flags)) // it's probably better than do nothing, isn't it? Raise(); } + +void wxTopLevelWindowBase::RemoveChild(wxWindowBase *child) +{ + if ( child == m_winDefault ) + m_winDefault = NULL; + + if ( child == m_winTmpDefault ) + m_winTmpDefault = NULL; + + wxWindow::RemoveChild(child); +}