For any people who are looking for a checked list component for wxWidgets– you might find this article revealing.
I’ve been using wxWidgets for a couple of months and I have to say it’s awesome. But, when I looked in the docs for a checked list control, I was not very excited to find that it does not exist in the 2.8.10 release. After doing some googling, I found the wiki page that gives some hints on using a subclass of wxListCtrl as a checked list control.
The wiki will tell you get the .cpp and the .h from the webupdate component page. The specific files I used can be downloaded from these locations:
- download the latest wxcheckedlistctrl.php revision from this page: http://wxcode.svn.sourceforge.net/viewvc/wxcode/trunk/wxCode/components/webupdate/src/checkedlistctrl.cpp?view=log
- download the latest revision for wxcheckedlistctrl.h from: http://wxcode.svn.sourceforge.net/viewvc/wxcode/trunk/wxCode/components/webupdate/include/wx/checkedlistctrl.h?view=log
- download the bitmap images from: http://wxcode.svn.sourceforge.net/viewvc/wxcode/trunk/wxCode/components/webupdate/include/wx/checked.xpm?view=log
- http://wxcode.svn.sourceforge.net/viewvc/wxcode/trunk/wxCode/components/webupdate/include/wx/checked_dis.xpm?view=log
- http://wxcode.svn.sourceforge.net/viewvc/wxcode/trunk/wxCode/components/webupdate/include/wx/unchecked.xpm?view=log
- http://wxcode.svn.sourceforge.net/viewvc/wxcode/trunk/wxCode/components/webupdate/include/wx/unchecked_dis.xpm?view=log
then edit the wxcheckedlistctrl.h to point to the right xpm images for the control. Include the .h and .cpp files in your project. I had to write a few additional hacks to the .h file but I got it to work just fine. There are a couple of methods not implemented in the implementation file. Today I spent quite a while trying to sort the items in the list using the SortItems method, then found out that It wasn’t implemented. Below, is the SortItems method for wxCheckedListCtrl as written by me, each row should have a unique value set by SetItemData(..)
bool SortItems(wxListCtrlCompare c, long le)
{
long ic = GetItemCount();
long *b_CE = new long[ic*2]; // first half is checked.. 2nd is enabled
long chc = 0, enc = 0;
for(long l=0;l<ic;++l)
{
if(IsChecked(l))
b_CE[chc++] = GetItemData(l);
if(IsEnabled(l))
b_CE[ic+(enc++)] = GetItemData(l);
}
if(!wxListCtrl::SortItems(c, le))
{
delete [] b_CE;
return false;
}
CheckAll(false);
EnableAll(false);
for(long l=0;l<ic;++l)
{
for(long l2=0;l2<chc;l2++)
if(b_CE[l2] == GetItemData(l))
Check(l, true);
for(long l2=0;l2<enc;l2++)
if(b_CE[ic+l2] == GetItemData(l))
Enable(l, true);
}
delete [] b_CE;
// wxASSERT_MSG(0, wxT("Not implemented yet ! sorry... ")); return FALSE;
return true;
}
My name is Amado Martinez. I'm a 23 year old programmer living in Reynosa, Mexico. I specialize in website systems. I'm not a frequent blogger, but I hope that you find my web development tips helpful and perhaps even AWESOME! Thanks for visiting :)
Add One