| 16307 | |
| 16308 | |
| 16309 | HTREEITEM GetNextTreeItem(HWND aTreeHwnd, HTREEITEM aItem) |
| 16310 | // Helper function for others below. |
| 16311 | // If aItem is NULL, caller wants topmost ROOT item returned. |
| 16312 | // Otherwise, the next child, sibling, or parent's sibling is returned in a manner that allows the caller |
| 16313 | // to traverse every item in the tree easily. |
| 16314 | { |
| 16315 | if (!aItem) |
| 16316 | return TreeView_GetRoot(aTreeHwnd); |
| 16317 | // Otherwise, do depth-first recursion. Must be done in the following order to allow full traversal: |
| 16318 | // Children first. |
| 16319 | // Then siblings. |
| 16320 | // Then parent's sibling(s). |
| 16321 | HTREEITEM hitem; |
| 16322 | if (hitem = TreeView_GetChild(aTreeHwnd, aItem)) |
| 16323 | return hitem; |
| 16324 | if (hitem = TreeView_GetNextSibling(aTreeHwnd, aItem)) |
| 16325 | return hitem; |
| 16326 | // The last stage is trickier than the above: parent's next sibling, or if none, its parent's parent's sibling, etc. |
| 16327 | for (HTREEITEM hparent = aItem;;) |
| 16328 | { |
| 16329 | if ( !(hparent = TreeView_GetParent(aTreeHwnd, hparent)) ) // No parent, so this is a root-level item. |
| 16330 | return NULL; // There is no next item. |
| 16331 | // Now it's known there is a parent. It's not necessary to check that parent's children because that |
| 16332 | // would have been done by a prior iteration in the script. |
| 16333 | if (hitem = TreeView_GetNextSibling(aTreeHwnd, hparent)) |
| 16334 | return hitem; |
| 16335 | // Otherwise, parent has no sibling, but does its parent (and so on)? Continue looping to find out. |
| 16336 | } |
| 16337 | } |
| 16338 | |
| 16339 | |
| 16340 | |