+/**
+ * Navigate to a given PIDL in the treeview, and return matching tree item handle
+ * - dest: The absolute PIDL we should navigate in the treeview
+ * - item: Handle of the tree item matching the PIDL
+ * - bExpand: expand collapsed nodes in order to find the right element
+ * - bInsert: insert the element at the right place if we don't find it
+ * - bSelect: select the item after we found it
+ */
+BOOL CExplorerBand::NavigateToPIDL(LPITEMIDLIST dest, HTREEITEM *item, BOOL bExpand, BOOL bInsert,
+ BOOL bSelect)
+{
+ HTREEITEM current;
+ HTREEITEM tmp;
+ HTREEITEM parent;
+ BOOL found;
+ NodeInfo *nodeData;
+ LPITEMIDLIST relativeChild;
+ TVITEM tvItem;
+
+ if (!item)
+ return FALSE;
+
+ found = FALSE;
+ current = hRoot;
+ parent = NULL;
+ while(!found)
+ {
+ nodeData = GetNodeInfo(current);
+ if (!nodeData)
+ {
+ ERR("Something has gone wrong, no data associated to node !\n");
+ *item = NULL;
+ return FALSE;
+ }
+ // If we found our node, give it back
+ if (!pDesktop->CompareIDs(0, nodeData->absolutePidl, dest))
+ {
+ if (bSelect)
+ TreeView_SelectItem(m_hWnd, current);
+ *item = current;
+ return TRUE;
+ }
+
+ // Check if we are a parent of the requested item
+ relativeChild = ILFindChild(nodeData->absolutePidl, dest);
+ if (relativeChild != 0)
+ {
+ // Notify treeview we have children
+ tvItem.mask = TVIF_CHILDREN;
+ tvItem.hItem = current;
+ tvItem.cChildren = 1;
+ TreeView_SetItem(m_hWnd, &tvItem);
+
+ // If we can expand and the node isn't expanded yet, do it
+ if (bExpand)
+ {
+ if (!nodeData->expanded)
+ InsertSubitems(current, nodeData);
+ TreeView_Expand(m_hWnd, current, TVE_EXPAND);
+ }
+
+ // Try to get a child
+ tmp = TreeView_GetChild(m_hWnd, current);
+ if (tmp)
+ {
+ // We have a child, let's continue with it
+ parent = current;
+ current = tmp;
+ continue;
+ }
+
+ if (bInsert && nodeData->expanded)
+ {
+ // Happens when we have to create a subchild inside a child
+ current = InsertItem(current, dest, relativeChild, TRUE);
+ }
+ // We end up here, without any children, so we found nothing
+ // Tell the parent node it has children
+ ZeroMemory(&tvItem, sizeof(tvItem));
+ *item = NULL;
+ return FALSE;
+ }
+
+ // Find sibling
+ tmp = TreeView_GetNextSibling(m_hWnd, current);
+ if (tmp)
+ {
+ current = tmp;
+ continue;
+ }
+ if (bInsert)
+ {
+ current = InsertItem(parent, dest, ILFindLastID(dest), TRUE);
+ *item = current;
+ return TRUE;
+ }
+ *item = NULL;
+ return FALSE;
+ }
+ return FALSE;
+}
+
+BOOL CExplorerBand::NavigateToCurrentFolder()
+{
+ LPITEMIDLIST explorerPidl;
+ CComPtr<IBrowserService> pBrowserService;
+ HRESULT hr;
+ HTREEITEM dummy;
+ BOOL result;
+ explorerPidl = NULL;
+
+ hr = IUnknown_QueryService(pSite, SID_STopLevelBrowser, IID_PPV_ARG(IBrowserService, &pBrowserService));
+ if (!SUCCEEDED(hr))
+ {
+ ERR("Can't get IBrowserService !\n");
+ return FALSE;
+ }
+
+ hr = pBrowserService->GetPidl(&explorerPidl);
+ if (!SUCCEEDED(hr) || !explorerPidl)
+ {
+ ERR("Unable to get browser PIDL !\n");
+ return FALSE;
+ }
+ bNavigating = TRUE;
+ /* find PIDL into our explorer */
+ result = NavigateToPIDL(explorerPidl, &dummy, TRUE, FALSE, TRUE);
+ bNavigating = FALSE;
+ return result;
+}
+