Add wxCheckListBox::GetCheckedItems() helper.

This method is similar to wxListBox::GetSelections() and allows to retrieve
all checked items at once.

Closes #14969.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73422 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2013-01-21 11:18:55 +00:00
parent 0444602e46
commit ae72623b64
5 changed files with 39 additions and 1 deletions

View File

@@ -607,6 +607,7 @@ All (GUI):
- Fix wrong tab order in wxAuiNotebook after dragging (Mark Barber). - Fix wrong tab order in wxAuiNotebook after dragging (Mark Barber).
- Fix bug in generic wxDataViewCtrl column dragging (jobuz). - Fix bug in generic wxDataViewCtrl column dragging (jobuz).
- Add wxMask::GetBitmap() for wxMSW, wxGTK and wxOSX - Add wxMask::GetBitmap() for wxMSW, wxGTK and wxOSX
- Add wxCheckListBox::GetCheckedItems() (hartwigw).
wxGTK: wxGTK:

View File

@@ -37,6 +37,8 @@ public:
virtual bool IsChecked(unsigned int item) const = 0; virtual bool IsChecked(unsigned int item) const = 0;
virtual void Check(unsigned int item, bool check = true) = 0; virtual void Check(unsigned int item, bool check = true) = 0;
virtual unsigned int GetCheckedItems(wxArrayInt& checkedItems) const;
wxDECLARE_NO_COPY_CLASS(wxCheckListBoxBase); wxDECLARE_NO_COPY_CLASS(wxCheckListBoxBase);
}; };

View File

@@ -151,6 +151,19 @@ public:
Index of item whose check status is to be returned. Index of item whose check status is to be returned.
*/ */
bool IsChecked(unsigned int item) const; bool IsChecked(unsigned int item) const;
/**
Return the indices of the checked items.
@param checkedItems
A reference to the array that is filled with the indices of the
checked items.
@return The number of checked items.
@see Check(), IsChecked()
@since 2.9.5
*/
unsigned int GetCheckedItems(wxArrayInt& checkedItems) const;
}; };

View File

@@ -99,4 +99,22 @@ wxCONSTRUCTOR_4( wxCheckListBox, wxWindow*, Parent, wxWindowID, Id, \
wxPoint, Position, wxSize, Size ) wxPoint, Position, wxSize, Size )
// ============================================================================
// implementation
// ============================================================================
unsigned int wxCheckListBoxBase::GetCheckedItems(wxArrayInt& checkedItems) const
{
unsigned int const numberOfItems = GetCount();
checkedItems.clear();
for ( unsigned int i = 0; i < numberOfItems; ++i )
{
if ( IsChecked(i) )
checkedItems.push_back(i);
}
return checkedItems.size();
}
#endif #endif

View File

@@ -67,6 +67,7 @@ void CheckListBoxTestCase::Check()
{ {
EventCounter toggled(m_check, wxEVT_COMMAND_CHECKLISTBOX_TOGGLED); EventCounter toggled(m_check, wxEVT_COMMAND_CHECKLISTBOX_TOGGLED);
wxArrayInt checkedItems;
wxArrayString testitems; wxArrayString testitems;
testitems.Add("item 0"); testitems.Add("item 0");
testitems.Add("item 1"); testitems.Add("item 1");
@@ -84,6 +85,9 @@ void CheckListBoxTestCase::Check()
CPPUNIT_ASSERT_EQUAL(true, m_check->IsChecked(0)); CPPUNIT_ASSERT_EQUAL(true, m_check->IsChecked(0));
CPPUNIT_ASSERT_EQUAL(false, m_check->IsChecked(1)); CPPUNIT_ASSERT_EQUAL(false, m_check->IsChecked(1));
CPPUNIT_ASSERT_EQUAL(1, m_check->GetCheckedItems(checkedItems));
CPPUNIT_ASSERT_EQUAL(0, checkedItems[0]);
//Make sure a double check of an items doesn't deselect it //Make sure a double check of an items doesn't deselect it
m_check->Check(0); m_check->Check(0);