Allow using wxRearrangeList::Check() to change state programmatically.
Previous this resulted in an assert and broken behaviour as it didn't update the internally stored state. Do update it now and remove the assert as it isn't possible to distinguish between user code calling Check() and wxGTK doing it itself from wxCheckListBox implementation. Closes #15940. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75786 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
8942262811
commit
9d05d9a009
@ -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:
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
||||
if ( (m_order[n] >= 0) != IsChecked(n) )
|
||||
m_order[n] = ~m_order[n];
|
||||
|
||||
wxASSERT_MSG( (m_order[n] >= 0) == IsChecked(n),
|
||||
"discrepancy between internal state and GUI" );
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
Loading…
Reference in New Issue
Block a user