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
// returns true if the platform should explicitly apply a theme border
virtual bool CanApplyThemeBorder() const { return false; }
// 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;
protected:
virtual wxSize DoGetBestClientSize() const;
// this can't be called DoHitTest() because wxWindow already has this method
virtual int DoHitTestList(const wxPoint& point) const;
// 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();
+ // 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)
};
DECLARE_DYNAMIC_CLASS_NO_COPY(wxListBox)
};
}
// now we can compute our best size correctly, so do it again
}
// now we can compute our best size correctly, so do it again
SetInitialSize(size);
return true;
SetInitialSize(size);
return true;
+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
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// implementation of wxListBoxBase methods
// ----------------------------------------------------------------------------
SendMessage(GetHwnd(), LB_DELETESTRING, n, 0);
m_noItems--;
SendMessage(GetHwnd(), LB_DELETESTRING, n, 0);
m_noItems--;
- // SetHorizontalExtent(wxEmptyString); can be slow
- m_updateHorizontalExtent = true;
ListBox_ResetContent(GetHwnd());
m_noItems = 0;
ListBox_ResetContent(GetHwnd());
m_noItems = 0;
- m_updateHorizontalExtent = true;
AssignNewItemClientData(n, clientData, i, type);
}
AssignNewItemClientData(n, clientData, i, type);
}
- m_updateHorizontalExtent = true;
if ( wasSelected )
Select(n);
if ( wasSelected )
Select(n);
- m_updateHorizontalExtent = true;
}
unsigned int wxListBox::GetCount() const
}
unsigned int wxListBox::GetCount() const
void wxListBox::SetHorizontalExtent(const wxString& s)
{
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;
// the rest is only necessary if we want a horizontal scrollbar
if ( !HasFlag(wxHSCROLL) )
return;