void CImpactCtrl::DeleteResults(HTREEITEM hRoot) { while(hRoot != NULL) { DeleteResults(m_ImpactTree.GetChildItem(hRoot)); HTREEITEM hItem = m_ImpactTree.GetNextSiblingItem(hRoot); m_ImpactTree.DeleteItem(hRoot); hRoot = hItem; } }
LRESULT CImpactCtrl::OnItemStateChanged(WPARAM wparm, LPARAM lparm) { HTREEITEM hItem = (HTREEITEM)lparm; HTREEITEM hParent = m_ImpactTree.GetParentItem(hItem); CImpactAction* pAction = (CImpactAction*)m_ImpactTree.GetItemData(hItem); if(pAction != NULL) { if(!pAction->IsExecuted()) { // if action has not been executed yet - run it CImpactItem* pItem = (CImpactItem*)m_ImpactTree.GetItemData(m_ImpactTree.GetParentItem(hItem)); if(pAction->ActionPerformed(pItem->GetEntity())) { CResultsTree* pResults = pAction->GetResults(); if(pResults!=NULL) { DisplayActionResults(hItem,pResults->children()); // if we can repeat the action - add it to the tree again if(pAction->DoRepeat()) { CImpactItem* pImpactItem = (CImpactItem*)m_ImpactTree.GetItemData(hParent); CImpactActionsSet* pSet = pImpactItem->GetActions(); TActionsList& actionsList = pSet->GetActions(); // duplicate the action CObject* pObject = pAction->GetRuntimeClass()->CreateObject(); ASSERT( pObject->IsKindOf(pAction->GetRuntimeClass()) ); CImpactAction* pNewAction = (CImpactAction*)pObject; pNewAction->SetCtrl(pAction->GetCtrl()); if(pAction->HasHash()) pNewAction->SetHash(pAction->GetHash()); pAction->SetDuplicated(true); actionsList.InsertAfter(actionsList.Find(pAction),pNewAction); AddAction(hParent,hItem,pNewAction); } m_ImpactTree.Expand(hItem,TVE_EXPAND); } } else { m_ImpactTree.SetItemState(hItem, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK); } } else { // otherwise - clean all results DeleteResults(m_ImpactTree.GetChildItem(hItem)); pAction->SetExecuted(false); // if it's a duplicate - remove it if(pAction->IsDuplicated()) { CImpactItem* pImpactItem = (CImpactItem*)m_ImpactTree.GetItemData(hParent); CImpactActionsSet* pSet = pImpactItem->GetActions(); TActionsList& actionsList = pSet->GetActions(); actionsList.RemoveAt(actionsList.Find(pAction)); m_ImpactTree.DeleteItem(hItem); pAction->Undo(); delete pAction; } } } CRect rcRect; m_ImpactTree.GetItemRect(hItem,rcRect,FALSE); m_ImpactTree.InvalidateRect(rcRect) ; m_ImpactTree.UpdateWindow(); return 0; }
extern "C" int __declspec(dllexport) Unload(void) { if (hTimer) KillTimer(NULL, hTimer); for (int i = 0; i < acc_num; i++) DeleteResults(acc[i].results.next); free(acc); UnhookEvent(hMirandaStarted); UnhookEvent(hOptionsInitial); return 0; }