+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);
+
+ DoResetBrokenStateImages(idParent, cookie, state);
+}
+
+void MyTreeCtrl::LogEvent(const wxChar *name, const wxTreeEvent& event)
+{
+ wxTreeItemId item = event.GetItem();
+ wxString text;
+ if ( item.IsOk() )
+ text << _T('"') << GetItemText(item).c_str() << _T('"');
+ else
+ text = _T("invalid item");
+ wxLogMessage(wxT("%s(%s)"), name, text.c_str());
+}