]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/toplvcmn.cpp
don't remove the tools we hadn't added to the toolbar (replaces patch 1660201)
[wxWidgets.git] / src / common / toplvcmn.cpp
index bf2742a04ede00e8df7414473762532a728109d5..433e3a6aae7b2e7fec5560771a20ac7264b5197c 100644 (file)
@@ -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
@@ -38,6 +39,7 @@
 BEGIN_EVENT_TABLE(wxTopLevelWindowBase, wxWindow)
     EVT_CLOSE(wxTopLevelWindowBase::OnCloseWindow)
     EVT_SIZE(wxTopLevelWindowBase::OnSize)
+    EVT_WINDOW_DESTROY(wxTopLevelWindowBase::OnChildDestroy)
 END_EVENT_TABLE()
 
 // ============================================================================
@@ -54,6 +56,8 @@ wxTopLevelWindowBase::wxTopLevelWindowBase()
 {
     // Unlike windows, top level windows are created hidden by default.
     m_isShown = false;
+    m_winDefault = NULL;
+    m_winTmpDefault = NULL;
 }
 
 wxTopLevelWindowBase::~wxTopLevelWindowBase()
@@ -137,26 +141,37 @@ bool wxTopLevelWindowBase::IsLastBeforeExit() const
 // wxTopLevelWindow geometry
 // ----------------------------------------------------------------------------
 
-void wxTopLevelWindowBase::GetRectForTopLevelChildren(int *x, int *y, int *w, int *h)
+void wxTopLevelWindowBase::SetMinSize(const wxSize& minSize)
 {
-    GetPosition(x,y);
-    GetSize(w,h);
+    SetSizeHints( minSize.x, minSize.y, GetMaxWidth(), GetMaxHeight() );    
 }
 
-wxSize wxTopLevelWindowBase::GetMaxSize() const
+void wxTopLevelWindowBase::SetMaxSize(const wxSize& maxSize)
 {
-    wxSize  size( GetMaxWidth(), GetMaxHeight() );
-    int     w, h;
-
-    wxClientDisplayRect( 0, 0, &w, &h );
-
-    if( size.GetWidth() == wxDefaultCoord )
-        size.SetWidth( w );
+    SetSizeHints( GetMinWidth(), GetMinHeight(), maxSize.x, maxSize.y );
+}
 
-    if( size.GetHeight() == wxDefaultCoord )
-        size.SetHeight( h );
+// set the min/max size of the window
+void wxTopLevelWindowBase::DoSetSizeHints(int minW, int minH,
+                                  int maxW, int maxH,
+                                  int WXUNUSED(incW), int WXUNUSED(incH))
+{
+    // setting min width greater than max width leads to infinite loops under
+    // X11 and generally doesn't make any sense, so don't allow it
+    wxCHECK_RET( (minW == wxDefaultCoord || maxW == wxDefaultCoord || minW <= maxW) &&
+                    (minH == wxDefaultCoord || maxH == wxDefaultCoord || minH <= maxH),
+                 _T("min width/height must be less than max width/height!") );
+
+    m_minWidth = minW;
+    m_maxWidth = maxW;
+    m_minHeight = minH;
+    m_maxHeight = maxH;
+}
 
-    return size;
+void wxTopLevelWindowBase::GetRectForTopLevelChildren(int *x, int *y, int *w, int *h)
+{
+    GetPosition(x,y);
+    GetSize(w,h);
 }
 
 /* static */
@@ -207,8 +222,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;
@@ -217,7 +232,7 @@ void wxTopLevelWindowBase::DoCentre(int dir)
 
     if ( rectParent.IsEmpty() )
     {
-        // we were explicitely asked to centre this window on the entire screen
+        // we were explicitly asked to centre this window on the entire screen
         // or if we have no parent anyhow and so can't centre on it
         rectParent = rectDisplay;
     }
@@ -232,15 +247,15 @@ 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
+            // move the window just enough for the bottom right corner to
+            // become visible
             int dx = rectDisplay.GetRight() - rect.GetRight();
             int dy = rectDisplay.GetBottom() - rect.GetBottom();
-            rect.Offset(dx, dy);
+            rect.Offset(dx < 0 ? dx : 0, dy < 0 ? dy : 0);
         }
         //else: the window top left and bottom right corner are both visible,
         //      although the window might still be not entirely on screen (with
@@ -344,15 +359,7 @@ void wxTopLevelWindowBase::DoLayout()
             int clientW, clientH;
             DoGetClientSize(&clientW, &clientH);
 
-            // for whatever reasons, wxGTK wants to have a small offset - it
-            // probably looks better with it?
-#ifdef __WXGTK__
-            static const int ofs = 1;
-#else
-            static const int ofs = 0;
-#endif
-
-            child->SetSize(ofs, ofs, clientW - 2*ofs, clientH - 2*ofs);
+            child->SetSize(0, 0, clientW, clientH);
         }
     }
 }
@@ -363,6 +370,17 @@ void wxTopLevelWindowBase::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
     Destroy();
 }
 
+void wxTopLevelWindowBase::OnChildDestroy(wxWindowDestroyEvent& event)
+{
+    event.Skip();
+
+    wxWindow * const win = event.GetWindow();
+    if ( win == m_winDefault )
+        m_winDefault = NULL;
+    if ( win == m_winTmpDefault )
+        m_winTmpDefault = NULL;
+}
+
 bool wxTopLevelWindowBase::SendIconizeEvent(bool iconized)
 {
     wxIconizeEvent event(GetId(), iconized);
@@ -392,3 +410,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);
+}