X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1544ba0edc8d1791d1d3a79bb0451831d0408051..316bba0c7207ceff140d0d8271962ad7c001ba8a:/src/msw/listbox.cpp diff --git a/src/msw/listbox.cpp b/src/msw/listbox.cpp index 78d76fdfab..d36f5ab109 100644 --- a/src/msw/listbox.cpp +++ b/src/msw/listbox.cpp @@ -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;