diff --git a/docs/changes.txt b/docs/changes.txt index 5874f7b657..82e7e63731 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -29,6 +29,7 @@ All (GUI): - Add wxHtmlWindow::SetDefaultHTMLCursor() (Jeff A. Marr). - Add default ctor and Create() to wxContextHelpButton (Hanmac). - Send events when toggling wxPropertyGrid nodes from keyboard (Armel Asselin). +- Fix wxRearrangeList::Check() which asserted and misbehaved before. wxGTK: diff --git a/include/wx/rearrangectrl.h b/include/wx/rearrangectrl.h index b54b04fa11..e334ca247e 100644 --- a/include/wx/rearrangectrl.h +++ b/include/wx/rearrangectrl.h @@ -95,6 +95,10 @@ public: bool MoveCurrentUp(); bool MoveCurrentDown(); + + // Override this to keep our m_order array in sync with the real item state. + virtual void Check(unsigned int item, bool check = true); + private: // swap two items at the given positions in the listbox void Swap(int pos1, int pos2); diff --git a/src/common/rearrangectrl.cpp b/src/common/rearrangectrl.cpp index a6865f9036..ebea20dc4c 100644 --- a/src/common/rearrangectrl.cpp +++ b/src/common/rearrangectrl.cpp @@ -78,7 +78,11 @@ bool wxRearrangeList::Create(wxWindow *parent, for ( n = 0; n < count; n++ ) { if ( order[n] >= 0 ) - Check(n); + { + // Be careful to call the base class version here and not our own + // which would also update m_order itself. + wxCheckListBox::Check(n); + } } m_order = order; @@ -137,8 +141,8 @@ void wxRearrangeList::Swap(int pos1, int pos2) // then the checked state const bool checkedTmp = IsChecked(pos1); - Check(pos1, IsChecked(pos2)); - Check(pos2, checkedTmp); + wxCheckListBox::Check(pos1, IsChecked(pos2)); + wxCheckListBox::Check(pos2, checkedTmp); // and finally the client data, if necessary switch ( GetClientDataType() ) @@ -165,15 +169,23 @@ void wxRearrangeList::Swap(int pos1, int pos2) } } +void wxRearrangeList::Check(unsigned int item, bool check) +{ + if ( check == IsChecked(item) ) + return; + + wxCheckListBox::Check(item, check); + + m_order[item] = ~m_order[item]; +} + void wxRearrangeList::OnCheck(wxCommandEvent& event) { // update the internal state to match the new item state const int n = event.GetInt(); - m_order[n] = ~m_order[n]; - - wxASSERT_MSG( (m_order[n] >= 0) == IsChecked(n), - "discrepancy between internal state and GUI" ); + if ( (m_order[n] >= 0) != IsChecked(n) ) + m_order[n] = ~m_order[n]; } // ============================================================================