]> git.saurik.com Git - wxWidgets.git/commitdiff
made Freeze/Thaw recursively (un)freeze child windows too
authorVáclav Slavík <vslavik@fastmail.fm>
Mon, 3 Mar 2008 11:30:07 +0000 (11:30 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Mon, 3 Mar 2008 11:30:07 +0000 (11:30 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52283 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/generic/listctrl.h
include/wx/msw/toplevel.h
include/wx/window.h
src/common/wincmn.cpp
src/generic/listctrl.cpp
src/msw/toplevel.cpp

index 1dedb608c686de625b5b12c57b2dcdfccee7301d..b3dcb0260b129f7c7aa06d0b81d99a973abbd1f2 100644 (file)
@@ -215,9 +215,6 @@ protected:
 
     virtual wxSize DoGetBestSize() const;
 
-    virtual void DoFreeze();
-    virtual void DoThaw();
-
     // return the text for the given column of the given item
     virtual wxString OnGetItemText(long item, long column) const;
 
index d3422813f09ef5f9673c5d093768456702d5335e..1434359e8551370a4502b8388326b25c9a0d5112 100644 (file)
@@ -75,8 +75,6 @@ public:
     virtual bool SetTransparent(wxByte alpha);
     virtual bool CanSetTransparent();
 
-    virtual void AddChild( wxWindowBase *child );
-
 
     // implementation from now on
     // --------------------------
index 33d33ce50d8e3690bb7344ecbbae5ae3e9c9ef57..3b39c5b321494a86c1944432cf91408603b1f846 100644 (file)
@@ -888,16 +888,10 @@ public:
     virtual void ClearBackground();
 
         // freeze the window: don't redraw it until it is thawed
-    void Freeze() { if ( !m_freezeCount++ ) DoFreeze(); }
+    void Freeze();
 
         // thaw the window: redraw it after it had been frozen
-    void Thaw()
-    {
-        wxASSERT_MSG( m_freezeCount, "Thaw() without matching Freeze()" );
-
-        if ( !--m_freezeCount )
-            DoThaw();
-    }
+    void Thaw();
 
         // return true if window had been frozen and not unthawed yet
     bool IsFrozen() const { return m_freezeCount != 0; }
index 6b80b11927c3b27eeb92660e8f6b8c64e4450c1b..838be57cc7ec464be1a302cc96b3afe7cbd65cf5 100644 (file)
@@ -928,6 +928,52 @@ bool wxWindowBase::IsTopLevel() const
     return false;
 }
 
+// ----------------------------------------------------------------------------
+// Freeze/Thaw
+// ----------------------------------------------------------------------------
+
+void wxWindowBase::Freeze()
+{
+    if ( !m_freezeCount++ )
+    {
+        // physically freeze this window:
+        DoFreeze();
+
+        // and recursively freeze all children:
+        for ( wxWindowList::iterator i = GetChildren().begin();
+              i != GetChildren().end(); ++i )
+        {
+            wxWindow *child = *i;
+            if ( child->IsTopLevel() )
+                continue;
+
+            child->Freeze();
+        }
+    }
+}
+
+void wxWindowBase::Thaw()
+{
+    wxASSERT_MSG( m_freezeCount, "Thaw() without matching Freeze()" );
+
+    if ( !--m_freezeCount )
+    {
+        // recursively thaw all children:
+        for ( wxWindowList::iterator i = GetChildren().begin();
+              i != GetChildren().end(); ++i )
+        {
+            wxWindow *child = *i;
+            if ( child->IsTopLevel() )
+                continue;
+
+            child->Thaw();
+        }
+
+        // physically thaw this window:
+        DoThaw();
+    }
+}
+
 // ----------------------------------------------------------------------------
 // reparenting the window
 // ----------------------------------------------------------------------------
@@ -943,12 +989,22 @@ void wxWindowBase::AddChild(wxWindowBase *child)
 
     GetChildren().Append((wxWindow*)child);
     child->SetParent(this);
+
+    // adding a child while frozen will assert when thawn, so freeze it as if
+    // it had been already present when we were frozen
+    if ( IsFrozen() && !child->IsTopLevel() )
+        child->Freeze();
 }
 
 void wxWindowBase::RemoveChild(wxWindowBase *child)
 {
     wxCHECK_RET( child, wxT("can't remove a NULL child") );
 
+    // removing a child while frozen may result in permanently frozen window
+    // if used e.g. from Reparent(), so thaw it
+    if ( IsFrozen() && !child->IsTopLevel() )
+        child->Thaw();
+
     GetChildren().DeleteObject((wxWindow *)child);
     child->SetParent(NULL);
 }
index f6bb4d3199b3cbb4437d2f6e0e9da9abe6975f70..bf34d03800fcd1a09a26ed4e99f6aa842cfe3876 100644 (file)
@@ -5901,14 +5901,4 @@ void wxGenericListCtrl::Refresh(bool eraseBackground, const wxRect *rect)
     }
 }
 
-void wxGenericListCtrl::DoFreeze()
-{
-    m_mainWin->Freeze();
-}
-
-void wxGenericListCtrl::DoThaw()
-{
-    m_mainWin->Thaw();
-}
-
 #endif // wxUSE_LISTCTRL
index 65dfa445868cf258d7ccc5a6f6ea015fd3815155..f87a9827358e98aedce67319b35455759fd780bf 100644 (file)
@@ -1175,49 +1175,14 @@ bool wxTopLevelWindowMSW::CanSetTransparent()
 
 void wxTopLevelWindowMSW::DoFreeze()
 {
-    if ( IsShown() )
-    {
-        for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
-              node;
-              node = node->GetNext() )
-        {
-            wxWindow *child = node->GetData();
-            if ( child->IsTopLevel() )
-                continue;
-
-            child->Freeze();
-        }
-    }
+    // do nothing: freezing toplevel window causes paint and mouse events
+    // to go through it any TLWs under it, so the best we can do is to freeze
+    // all children -- and wxWindowBase::Freeze() does that
 }
 
 void wxTopLevelWindowMSW::DoThaw()
 {
-    if ( IsShown() )
-    {
-        for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
-              node;
-              node = node->GetNext() )
-        {
-            wxWindow *child = node->GetData();
-            if ( child->IsTopLevel() )
-                continue;
-
-            child->Thaw();
-        }
-    }
-}
-
-
-void wxTopLevelWindowMSW::AddChild(wxWindowBase *child)
-{
-    // adding a child while frozen will assert when thawn, so freeze it as if
-    // it had been already present when we were frozen
-    if ( child && !child->IsTopLevel() && IsFrozen() )
-    {
-        child->Freeze();
-    }
-
-    wxTopLevelWindowBase::AddChild(child);
+    // intentionally empty -- see DoFreeze()
 }