9 #include "sysmetrics.h"
10 #include "debugtools.h"
17 #include "wine/obj_base.h"
18 #include "wine/obj_enumidlist.h"
19 #include "wine/obj_shellfolder.h"
20 #include "wine/undocshell.h"
23 #include "shell32_main.h"
26 DEFAULT_DEBUG_CHANNEL(shell)
28 #define IDD_TREEVIEW 99
30 static HWND hwndTreeView;
31 static LPBROWSEINFOA lpBrowseInfo;
32 static LPITEMIDLIST pidlRet;
34 static void FillTreeView(LPSHELLFOLDER lpsf, LPITEMIDLIST lpifq, HTREEITEM hParent);
36 static void InitializeTreeView(HWND hwndParent)
38 HIMAGELIST hImageList;
42 hwndTreeView = GetDlgItem (hwndParent, IDD_TREEVIEW);
43 Shell_GetImageList(NULL, &hImageList);
45 TRACE("dlg=%x tree=%x\n", hwndParent, hwndTreeView );
47 if (hImageList && hwndTreeView)
48 { TreeView_SetImageList(hwndTreeView, hImageList, 0);
51 hr = SHGetDesktopFolder(&lpsf);
53 if (SUCCEEDED(hr) && hwndTreeView)
54 { TreeView_DeleteAllItems(hwndTreeView);
55 FillTreeView(lpsf, NULL, TVI_ROOT);
59 { IShellFolder_Release(lpsf);
63 static int GetIcon(LPITEMIDLIST lpi, UINT uFlags)
65 SHGetFileInfoA((LPCSTR)lpi,0,&sfi, sizeof(SHFILEINFOA), uFlags);
69 static void GetNormalAndSelectedIcons(LPITEMIDLIST lpifq,LPTVITEMA lpTV_ITEM)
70 { TRACE("%p %p\n",lpifq, lpTV_ITEM);
72 lpTV_ITEM->iImage = GetIcon(lpifq, SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
73 lpTV_ITEM->iSelectedImage = GetIcon(lpifq, SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_OPENICON);
80 LPSHELLFOLDER lpsfParent;
83 } TV_ITEMDATA, *LPTV_ITEMDATA;
85 static BOOL GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi, DWORD dwFlags, LPSTR lpFriendlyName)
90 TRACE("%p %p %lx %p\n", lpsf, lpi, dwFlags, lpFriendlyName);
91 if (SUCCEEDED(IShellFolder_GetDisplayNameOf(lpsf, lpi, dwFlags, &str)))
93 if(FAILED(StrRetToStrNA (lpFriendlyName, MAX_PATH, &str, lpi)))
101 TRACE("-- %s\n",lpFriendlyName);
105 static void FillTreeView(IShellFolder * lpsf, LPITEMIDLIST pidl, HTREEITEM hParent)
108 TVINSERTSTRUCTA tvins;
111 LPITEMIDLIST pidlTemp=0;
112 LPTV_ITEMDATA lptvid=0;
116 HWND hwnd=GetParent(hwndTreeView);
118 TRACE("%p %p %x\n",lpsf, pidl, (INT)hParent);
119 SetCapture(GetParent(hwndTreeView));
120 SetCursor(LoadCursorA(0, IDC_WAITA));
122 hr=IShellFolder_EnumObjects(lpsf,hwnd, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS,&lpe);
125 { while (NOERROR == IEnumIDList_Next(lpe,1,&pidlTemp,&ulFetched))
126 { ULONG ulAttrs = SFGAO_HASSUBFOLDER | SFGAO_FOLDER;
127 IShellFolder_GetAttributesOf(lpsf, 1, &pidlTemp, &ulAttrs);
128 if (ulAttrs & (SFGAO_HASSUBFOLDER | SFGAO_FOLDER))
129 { if (ulAttrs & SFGAO_FOLDER)
130 { tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
132 if (ulAttrs & SFGAO_HASSUBFOLDER)
134 tvi.mask |= TVIF_CHILDREN;
137 if (!( lptvid = (LPTV_ITEMDATA)SHAlloc(sizeof(TV_ITEMDATA))))
140 if (!GetName(lpsf, pidlTemp, SHGDN_NORMAL, szBuff))
143 tvi.pszText = szBuff;
144 tvi.cchTextMax = MAX_PATH;
145 tvi.lParam = (LPARAM)lptvid;
147 IShellFolder_AddRef(lpsf);
148 lptvid->lpsfParent = lpsf;
149 lptvid->lpi = ILClone(pidlTemp);
150 lptvid->lpifq = ILCombine(pidl, pidlTemp);
151 GetNormalAndSelectedIcons(lptvid->lpifq, &tvi);
153 tvins.DUMMYUNIONNAME.item = tvi;
154 tvins.hInsertAfter = hPrev;
155 tvins.hParent = hParent;
157 hPrev = (HTREEITEM)TreeView_InsertItemA (hwndTreeView, &tvins);
161 SHFree(pidlTemp); /* Finally, free the pidl that the shell gave us... */
168 SetCursor(LoadCursorA(0, IDC_ARROWA));
171 IEnumIDList_Release(lpe);
176 static LRESULT MsgNotify(HWND hWnd, UINT CtlID, LPNMHDR lpnmh)
178 NMTREEVIEWA *pnmtv = (NMTREEVIEWA *)lpnmh;
179 LPTV_ITEMDATA lptvid; /* Long pointer to TreeView item data */
180 IShellFolder * lpsf2=0;
183 TRACE("%x %x %p msg=%x\n", hWnd, CtlID, lpnmh, pnmtv->hdr.code);
185 switch (pnmtv->hdr.idFrom)
187 switch (pnmtv->hdr.code)
188 { case TVN_DELETEITEM:
189 { FIXME("TVN_DELETEITEM\n");
190 lptvid=(LPTV_ITEMDATA)pnmtv->itemOld.lParam;
191 IShellFolder_Release(lptvid->lpsfParent);
193 SHFree(lptvid->lpifq);
198 case TVN_ITEMEXPANDING:
199 { FIXME("TVN_ITEMEXPANDING\n");
200 if ((pnmtv->itemNew.state & TVIS_EXPANDEDONCE))
203 lptvid=(LPTV_ITEMDATA)pnmtv->itemNew.lParam;
204 if (SUCCEEDED(IShellFolder_BindToObject(lptvid->lpsfParent, lptvid->lpi,0,(REFIID)&IID_IShellFolder,(LPVOID *)&lpsf2)))
205 { FillTreeView( lpsf2, lptvid->lpifq, pnmtv->itemNew.hItem );
207 TreeView_SortChildren(hwndTreeView, pnmtv->itemNew.hItem, FALSE);
211 lptvid=(LPTV_ITEMDATA)pnmtv->itemNew.lParam;
212 pidlRet = lptvid->lpifq;
216 FIXME("unhandled\n");
229 /*************************************************************************
230 * BrsFolderDlgProc32 (not an exported API function)
232 static BOOL WINAPI BrsFolderDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
234 { TRACE("hwnd=%i msg=%i 0x%08x 0x%08lx\n", hWnd, msg, wParam, lParam );
237 { case WM_INITDIALOG:
239 lpBrowseInfo = (LPBROWSEINFOA) lParam;
240 if (lpBrowseInfo->lpfn)
241 FIXME("Callbacks not implemented\n");
242 if (lpBrowseInfo->ulFlags)
243 FIXME("flag %x not implemented\n", lpBrowseInfo->ulFlags);
244 if (lpBrowseInfo->lpszTitle)
245 FIXME("title %s not displayed\n", lpBrowseInfo->lpszTitle);
246 if ( lpBrowseInfo->pidlRoot )
247 FIXME("root is desktop\n");
249 InitializeTreeView ( hWnd);
253 MsgNotify( hWnd, (UINT)wParam, (LPNMHDR)lParam);
260 SHGetPathFromIDListA(pidlRet, lpBrowseInfo->pszDisplayName);
261 EndDialog(hWnd, (DWORD) ILClone(pidlRet));
273 /*************************************************************************
274 * SHBrowseForFolderA [SHELL32.209]
277 LPITEMIDLIST WINAPI SHBrowseForFolderA (LPBROWSEINFOA lpbi)
279 TRACE("(%lx,%s) empty stub!\n", (DWORD)lpbi, lpbi->lpszTitle);
281 return (LPITEMIDLIST) DialogBoxParamA( shell32_hInstance,
282 "SHBRSFORFOLDER_MSGBOX", 0,
283 BrsFolderDlgProc, (INT)lpbi );