]> git.saurik.com Git - wxWidgets.git/commitdiff
Invalidate wxListBox best size immediately without waiting for idle time.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 8 May 2010 10:28:01 +0000 (10:28 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 8 May 2010 10:28:01 +0000 (10:28 +0000)
Since r53743 the listbox best size was only invalidated during idle time but
this meant that it could be laid out using incorrect old best size. So while
we still defer (expensive) horizontal extent calculation until later, do
invalidate the best size immediately to ensure the listbox is laid out
correctly.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64246 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/listbox.h
src/msw/listbox.cpp

index 4a78e165a22cb97f30b47d44e55f785cce425f6c..54a53b1c58872800c72daa96a4cc8a9a0cee3ffe 100644 (file)
@@ -145,6 +145,8 @@ public:
     // returns true if the platform should explicitly apply a theme border
     virtual bool CanApplyThemeBorder() const { return false; }
 
+    virtual void OnInternalIdle();
+
 protected:
     virtual wxSize DoGetBestClientSize() const;
 
@@ -164,8 +166,8 @@ protected:
     // this can't be called DoHitTest() because wxWindow already has this method
     virtual int DoHitTestList(const wxPoint& point) const;
 
-    bool m_updateHorizontalExtent;
-    virtual void OnInternalIdle();
+    // free memory (common part of Clear() and dtor)
+    void Free();
 
     unsigned int m_noItems;
 
@@ -175,6 +177,14 @@ protected:
 #endif
 
 private:
+    // call this when items are added to or deleted from the listbox or an
+    // items text changes
+    void MSWOnItemsChanged();
+
+    // flag indicating whether the max horizontal extent should be updated,
+    // i.e. if we need to call SetHorizontalExtent() from OnInternalIdle()
+    bool m_updateHorizontalExtent;
+
     DECLARE_DYNAMIC_CLASS_NO_COPY(wxListBox)
 };
 
index 78d76fdfabcd4c679d343f1b584f83feb25b9416..d36f5ab109782dbbae02df8e7f6a7a33bb3e9c7e 100644 (file)
@@ -186,7 +186,6 @@ bool wxListBox::Create(wxWindow *parent,
     }
 
     // now we can compute our best size correctly, so do it again
-    InvalidateBestSize();
     SetInitialSize(size);
 
     return true;
@@ -269,6 +268,22 @@ void wxListBox::OnInternalIdle()
     }
 }
 
+void wxListBox::MSWOnItemsChanged()
+{
+    // we need to do two things when items change: update their max horizontal
+    // extent so that horizontal scrollbar could be shown or hidden as
+    // appropriate and also invlaidate the best size
+    //
+    // updating the max extent is slow (it's an O(N) operation) and so we defer
+    // it until the idle time but the best size should be invalidated
+    // immediately doing it in idle time is too late -- layout using incorrect
+    // old best size will have been already done by then
+
+    m_updateHorizontalExtent = true;
+
+    InvalidateBestSize();
+}
+
 // ----------------------------------------------------------------------------
 // implementation of wxListBoxBase methods
 // ----------------------------------------------------------------------------
@@ -297,8 +312,7 @@ void wxListBox::DoDeleteOneItem(unsigned int n)
     SendMessage(GetHwnd(), LB_DELETESTRING, n, 0);
     m_noItems--;
 
-    // SetHorizontalExtent(wxEmptyString); can be slow
-    m_updateHorizontalExtent = true;
+    MSWOnItemsChanged();
 
     UpdateOldSelections();
 }
@@ -328,7 +342,7 @@ void wxListBox::DoClear()
     ListBox_ResetContent(GetHwnd());
 
     m_noItems = 0;
-    m_updateHorizontalExtent = true;
+    MSWOnItemsChanged();
 
     UpdateOldSelections();
 }
@@ -486,7 +500,7 @@ int wxListBox::DoInsertItems(const wxArrayStringsAdapter & items,
         AssignNewItemClientData(n, clientData, i, type);
     }
 
-    m_updateHorizontalExtent = true;
+    MSWOnItemsChanged();
 
     UpdateOldSelections();
 
@@ -537,7 +551,7 @@ void wxListBox::SetString(unsigned int n, const wxString& s)
     if ( wasSelected )
         Select(n);
 
-    m_updateHorizontalExtent = true;
+    MSWOnItemsChanged();
 }
 
 unsigned int wxListBox::GetCount() const
@@ -551,9 +565,6 @@ unsigned int wxListBox::GetCount() const
 
 void wxListBox::SetHorizontalExtent(const wxString& s)
 {
-    // in any case, our best size could have changed
-    InvalidateBestSize();
-
     // the rest is only necessary if we want a horizontal scrollbar
     if ( !HasFlag(wxHSCROLL) )
         return;