2008年7月6日星期日

wxWidgets: 用來找尋 tree Index (在同一個 level 下)

/**
* Find the tree item index in the same depth
*
* @param pTree tree pinter
* @param rootid parent tree item id
* @param itemid tree item id
*
* @return return item index if success otherwise return -1
*/
int find_treeItem_index(wxTreeCtrl *pTree, wxTreeItemId rootid, wxTreeItemId itemid)
{
wxTreeItemIdValue cookie;
wxTreeItemId id;
int cnt=-1;

// for the first child
id = pTree->GetFirstChild(rootid, cookie);

if(!id.IsOk()) {
return -1;
} else {
cnt++;
}

while(id != itemid) {
id = pTree->GetNextChild(rootid, cookie);

if(!id.IsOk()) {
break;
}

cnt++;
}

if(!id.IsOk()) {
cnt = -1;
}

return cnt;
}

沒有留言: