+ int image = GetItemImage(item) == TreeCtrlIcon_Folder
+ ? TreeCtrlIcon_File
+ : TreeCtrlIcon_Folder;
+ SetItemImage(item, image, wxTreeItemIcon_Normal);
+
+ image = GetItemImage(item, wxTreeItemIcon_Selected) == TreeCtrlIcon_FolderSelected
+ ? TreeCtrlIcon_FileSelected
+ : TreeCtrlIcon_FolderSelected;
+ SetItemImage(item, image, wxTreeItemIcon_Selected);
+}
+
+void MyTreeCtrl::DoToggleState(const wxTreeItemId& item)
+{
+ if ( m_alternateStates )
+ {
+ // sets random state unlike current
+ int state = GetItemState(item);
+ int nState;
+
+ srand (time(NULL));
+ do {
+ nState = rand() % GetStateImageList()->GetImageCount();
+ } while (nState == state);
+
+ SetItemState(item, nState);
+ }
+ else
+ {
+ // we have only 2 checkbox states, so next state will be reversed
+ SetItemState(item, wxTREE_ITEMSTATE_NEXT);
+ }
+}
+
+void MyTreeCtrl::DoResetBrokenStateImages(const wxTreeItemId& idParent,
+ wxTreeItemIdValue cookie, int state)
+{
+ wxTreeItemId id;
+
+ if ( !cookie )
+ id = GetFirstChild(idParent, cookie);
+ else
+ id = GetNextChild(idParent, cookie);
+
+ if ( !id.IsOk() )
+ return;
+
+ int curState = GetItemState(id);
+ if ( curState != wxTREE_ITEMSTATE_NONE && curState > state )
+ SetItemState(id, state);
+
+ if (ItemHasChildren(id))
+ DoResetBrokenStateImages(id, 0, state);