]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/toplvcmn.cpp
don't generate wxEVT_CONTEXT_MENU messages for right clicks in the list control header
[wxWidgets.git] / src / common / toplvcmn.cpp
index 1645b2bf973448d6c95e455d10b26523a11ed83e..8441f436ebd1a678027af927f82473ba5362d42e 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        common/toplvcmn.cpp
+// Name:        src/common/toplvcmn.cpp
 // Purpose:     common (for all platforms) wxTopLevelWindow functions
 // Author:      Julian Smart, Vadim Zeitlin
 // Created:     01/02/97
@@ -62,13 +62,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 +94,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;
 }
 
 // ----------------------------------------------------------------------------
@@ -187,6 +217,10 @@ void wxTopLevelWindowBase::DoCentre(int dir)
         rectParent = rectDisplay;
     }
 
+    // centering maximized window on screen is no-op
+    if((rectParent == rectDisplay) && IsMaximized())
+        return;
+
     // the new window rect candidate
     wxRect rect = GetRect().CentreIn(rectParent, dir);
 
@@ -345,4 +379,3 @@ void wxTopLevelWindowBase::RequestUserAttention(int WXUNUSED(flags))
     // it's probably better than do nothing, isn't it?
     Raise();
 }
-