more convenient API for wxGenericValidator + wxLB_SINGLE
For a single-selection wxListBox, using an int to transfer data to/from wxGenericValidator is more convenient than wxArrayInt.
This commit is contained in:
parent
ed02e03585
commit
cfc5bc6ff2
2 changed files with 57 additions and 0 deletions
|
|
@ -21,6 +21,9 @@
|
|||
For example, wxButton and wxTextCtrl transfer data to and from a
|
||||
wxString variable; wxListBox uses a wxArrayInt; wxCheckBox uses a boolean.
|
||||
|
||||
@since 3.2.5
|
||||
A wxLB_SINGLE wxListBox can also use an int.
|
||||
|
||||
For more information, please see @ref overview_validator.
|
||||
|
||||
@library{wxcore}
|
||||
|
|
|
|||
|
|
@ -377,6 +377,17 @@ bool wxGenericValidator::TransferToWindow()
|
|||
|
||||
return true;
|
||||
}
|
||||
else if (m_pInt)
|
||||
{
|
||||
wxCHECK_MSG(
|
||||
!(pControl->GetWindowStyle() & (wxLB_MULTIPLE || wxLB_EXTENDED)),
|
||||
false,
|
||||
"multi-select control requires wxArrayInt"
|
||||
);
|
||||
pControl->Check(*m_pInt);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
} else
|
||||
|
|
@ -398,6 +409,17 @@ bool wxGenericValidator::TransferToWindow()
|
|||
for ( i = 0 ; i < count; i++ )
|
||||
pControl->SetSelection(m_pArrayInt->Item(i));
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (m_pInt)
|
||||
{
|
||||
wxCHECK_MSG(
|
||||
!(pControl->GetWindowStyle() & (wxLB_MULTIPLE || wxLB_EXTENDED)),
|
||||
false,
|
||||
"multi-select control requires wxArrayInt"
|
||||
);
|
||||
pControl->SetSelection(*m_pInt);
|
||||
|
||||
return true;
|
||||
}
|
||||
} else
|
||||
|
|
@ -654,6 +676,26 @@ bool wxGenericValidator::TransferFromWindow()
|
|||
|
||||
return true;
|
||||
}
|
||||
else if (m_pInt)
|
||||
{
|
||||
wxCHECK_MSG(
|
||||
!(pControl->GetWindowStyle()& (wxLB_MULTIPLE || wxLB_EXTENDED)),
|
||||
false,
|
||||
"multi-select control requires wxArrayInt"
|
||||
);
|
||||
|
||||
size_t i,
|
||||
count = pControl->GetCount();
|
||||
for ( i = 0; i < count; i++ )
|
||||
{
|
||||
if (pControl->IsChecked(i))
|
||||
{
|
||||
*m_pInt = i;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
} else
|
||||
|
|
@ -676,6 +718,18 @@ bool wxGenericValidator::TransferFromWindow()
|
|||
m_pArrayInt->Add(i);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (m_pInt)
|
||||
{
|
||||
wxCHECK_MSG(
|
||||
!(pControl->GetWindowStyle() & (wxLB_MULTIPLE || wxLB_EXTENDED)),
|
||||
false,
|
||||
"multi-select control requires wxArrayInt"
|
||||
);
|
||||
|
||||
*m_pInt = pControl->GetSelection();
|
||||
|
||||
return true;
|
||||
}
|
||||
} else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue