8 #include "sysmetrics.h"
9 #include "debugtools.h"
16 #include "wine/obj_base.h"
17 #include "wine/obj_enumidlist.h"
18 #include "wine/obj_shellfolder.h"
19 #include "wine/undocshell.h"
22 #include "shell32_main.h"
25 DEFAULT_DEBUG_CHANNEL(shell)
27 #define IDD_TREEVIEW 99
29 static HWND hwndTreeView;
30 static LPBROWSEINFOA lpBrowseInfo;
31 static LPITEMIDLIST pidlRet;
33 static void FillTreeView(LPSHELLFOLDER lpsf, LPITEMIDLIST lpifq, HTREEITEM hParent);
35 static void InitializeTreeView(HWND hwndParent)
37 HIMAGELIST hImageList;
41 hwndTreeView = GetDlgItem (hwndParent, IDD_TREEVIEW);
42 Shell_GetImageList(NULL, &hImageList);
44 TRACE("dlg=%x tree=%x\n", hwndParent, hwndTreeView );
46 if (hImageList && hwndTreeView)
47 { TreeView_SetImageList(hwndTreeView, hImageList, 0);
50 hr = SHGetDesktopFolder(&lpsf);
52 if (SUCCEEDED(hr) && hwndTreeView)
53 { TreeView_DeleteAllItems(hwndTreeView);
54 FillTreeView(lpsf, NULL, TVI_ROOT);
58 { IShellFolder_Release(lpsf);
62 static int GetIcon(LPITEMIDLIST lpi, UINT uFlags)
64 SHGetFileInfoA((LPCSTR)lpi,0,&sfi, sizeof(SHFILEINFOA), uFlags);
68 static void GetNormalAndSelectedIcons(LPITEMIDLIST lpifq,LPTVITEMA lpTV_ITEM)
69 { TRACE("%p %p\n",lpifq, lpTV_ITEM);
71 lpTV_ITEM->iImage = GetIcon(lpifq, SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
72 lpTV_ITEM->iSelectedImage = GetIcon(lpifq, SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_OPENICON);
79 LPSHELLFOLDER lpsfParent;
82 } TV_ITEMDATA, *LPTV_ITEMDATA;
84 static BOOL GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi, DWORD dwFlags, LPSTR lpFriendlyName)
89 TRACE("%p %p %lx %p\n", lpsf, lpi, dwFlags, lpFriendlyName);
90 if (SUCCEEDED(IShellFolder_GetDisplayNameOf(lpsf, lpi, dwFlags, &str)))
92 if(FAILED(StrRetToStrNA (lpFriendlyName, MAX_PATH, &str, lpi)))
100 TRACE("-- %s\n",lpFriendlyName);
104 static void FillTreeView(IShellFolder * lpsf, LPITEMIDLIST pidl, HTREEITEM hParent)
107 TVINSERTSTRUCTA tvins;
110 LPITEMIDLIST pidlTemp=0;
111 LPTV_ITEMDATA lptvid=0;
115 HWND hwnd=GetParent(hwndTreeView);
117 TRACE("%p %p %x\n",lpsf, pidl, (INT)hParent);
118 SetCapture(GetParent(hwndTreeView));
119 SetCursor(LoadCursorA(0, IDC_WAITA));
121 hr=IShellFolder_EnumObjects(lpsf,hwnd, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS,&lpe);
124 { while (NOERROR == IEnumIDList_Next(lpe,1,&pidlTemp,&ulFetched))
125 { ULONG ulAttrs = SFGAO_HASSUBFOLDER | SFGAO_FOLDER;
126 IShellFolder_GetAttributesOf(lpsf, 1, &pidlTemp, &ulAttrs);
127 if (ulAttrs & (SFGAO_HASSUBFOLDER | SFGAO_FOLDER))
128 { if (ulAttrs & SFGAO_FOLDER)
129 { tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
131 if (ulAttrs & SFGAO_HASSUBFOLDER)
133 tvi.mask |= TVIF_CHILDREN;
136 if (!( lptvid = (LPTV_ITEMDATA)SHAlloc(sizeof(TV_ITEMDATA))))
139 if (!GetName(lpsf, pidlTemp, SHGDN_NORMAL, szBuff))
142 tvi.pszText = szBuff;
143 tvi.cchTextMax = MAX_PATH;
144 tvi.lParam = (LPARAM)lptvid;
146 IShellFolder_AddRef(lpsf);
147 lptvid->lpsfParent = lpsf;
148 lptvid->lpi = ILClone(pidlTemp);
149 lptvid->lpifq = ILCombine(pidl, pidlTemp);
150 GetNormalAndSelectedIcons(lptvid->lpifq, &tvi);
152 tvins.DUMMYUNIONNAME.item = tvi;
153 tvins.hInsertAfter = hPrev;
154 tvins.hParent = hParent;
156 hPrev = (HTREEITEM)TreeView_InsertItemA (hwndTreeView, &tvins);
160 SHFree(pidlTemp); /* Finally, free the pidl that the shell gave us... */
167 SetCursor(LoadCursorA(0, IDC_ARROWA));
170 IEnumIDList_Release(lpe);
175 static LRESULT MsgNotify(HWND hWnd, UINT CtlID, LPNMHDR lpnmh)
177 NMTREEVIEWA *pnmtv = (NMTREEVIEWA *)lpnmh;
178 LPTV_ITEMDATA lptvid; /* Long pointer to TreeView item data */
179 IShellFolder * lpsf2=0;
182 TRACE("%x %x %p msg=%x\n", hWnd, CtlID, lpnmh, pnmtv->hdr.code);
184 switch (pnmtv->hdr.idFrom)
186 switch (pnmtv->hdr.code)
187 { case TVN_DELETEITEMA:
188 { FIXME("TVN_DELETEITEMA\n");
189 lptvid=(LPTV_ITEMDATA)pnmtv->itemOld.lParam;
190 IShellFolder_Release(lptvid->lpsfParent);
192 SHFree(lptvid->lpifq);
197 case TVN_ITEMEXPANDINGA:
198 { FIXME("TVN_ITEMEXPANDINGA\n");
199 if ((pnmtv->itemNew.state & TVIS_EXPANDEDONCE))
202 lptvid=(LPTV_ITEMDATA)pnmtv->itemNew.lParam;
203 if (SUCCEEDED(IShellFolder_BindToObject(lptvid->lpsfParent, lptvid->lpi,0,(REFIID)&IID_IShellFolder,(LPVOID *)&lpsf2)))
204 { FillTreeView( lpsf2, lptvid->lpifq, pnmtv->itemNew.hItem );
206 TreeView_SortChildren(hwndTreeView, pnmtv->itemNew.hItem, FALSE);
209 case TVN_SELCHANGEDA:
210 lptvid=(LPTV_ITEMDATA)pnmtv->itemNew.lParam;
211 pidlRet = lptvid->lpifq;
215 FIXME("unhandled\n");
228 /*************************************************************************
229 * BrsFolderDlgProc32 (not an exported API function)
231 static BOOL WINAPI BrsFolderDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
233 { TRACE("hwnd=%i msg=%i 0x%08x 0x%08lx\n", hWnd, msg, wParam, lParam );
236 { case WM_INITDIALOG:
238 lpBrowseInfo = (LPBROWSEINFOA) lParam;
239 if (lpBrowseInfo->lpfn)
240 FIXME("Callbacks not implemented\n");
241 if (lpBrowseInfo->ulFlags)
242 FIXME("flag %x not implemented\n", lpBrowseInfo->ulFlags);
243 if (lpBrowseInfo->lpszTitle)
244 FIXME("title %s not displayed\n", lpBrowseInfo->lpszTitle);
245 if ( lpBrowseInfo->pidlRoot )
246 FIXME("root is desktop\n");
248 InitializeTreeView ( hWnd);
252 MsgNotify( hWnd, (UINT)wParam, (LPNMHDR)lParam);
259 SHGetPathFromIDListA(pidlRet, lpBrowseInfo->pszDisplayName);
260 EndDialog(hWnd, (DWORD) ILClone(pidlRet));
272 /*************************************************************************
273 * SHBrowseForFolderA [SHELL32.209]
276 LPITEMIDLIST WINAPI SHBrowseForFolderA (LPBROWSEINFOA lpbi)
278 TRACE("(%p{lpszTitle=%s})\n", lpbi, debugstr_a(lpbi->lpszTitle));
280 return (LPITEMIDLIST) DialogBoxParamA( shell32_hInstance,
281 "SHBRSFORFOLDER_MSGBOX", lpbi->hwndOwner,
282 BrsFolderDlgProc, (INT)lpbi );