DOSFS_ToDosFCBFormat: fail if extension longer than 3 characters.
[wine/gsoc-2012-control.git] / dlls / shell32 / brsfolder.c
blob00f26f5569efce1fcfca4dea6e7311c9cc136fd4
1 #include <stdlib.h>
2 #include <string.h>
4 #include "winerror.h"
5 #include "heap.h"
6 #include "dlgs.h"
7 #include "win.h"
8 #include "sysmetrics.h"
9 #include "debugtools.h"
10 #include "winreg.h"
11 #include "authors.h"
12 #include "winnls.h"
13 #include "commctrl.h"
14 #include "spy.h"
16 #include "wine/obj_base.h"
17 #include "wine/obj_enumidlist.h"
18 #include "wine/obj_shellfolder.h"
19 #include "wine/undocshell.h"
21 #include "pidl.h"
22 #include "shell32_main.h"
23 #include "shellapi.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;
38 IShellFolder * lpsf;
39 HRESULT hr;
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);
57 if (SUCCEEDED(hr))
58 { IShellFolder_Release(lpsf);
62 static int GetIcon(LPITEMIDLIST lpi, UINT uFlags)
63 { SHFILEINFOA sfi;
64 SHGetFileInfoA((LPCSTR)lpi,0,&sfi, sizeof(SHFILEINFOA), uFlags);
65 return sfi.iIcon;
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);
74 return;
77 typedef struct tagID
79 LPSHELLFOLDER lpsfParent;
80 LPITEMIDLIST lpi;
81 LPITEMIDLIST lpifq;
82 } TV_ITEMDATA, *LPTV_ITEMDATA;
84 static BOOL GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi, DWORD dwFlags, LPSTR lpFriendlyName)
86 BOOL bSuccess=TRUE;
87 STRRET str;
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)))
94 bSuccess = FALSE;
97 else
98 bSuccess = FALSE;
100 TRACE("-- %s\n",lpFriendlyName);
101 return bSuccess;
104 static void FillTreeView(IShellFolder * lpsf, LPITEMIDLIST pidl, HTREEITEM hParent)
106 TVITEMA tvi;
107 TVINSERTSTRUCTA tvins;
108 HTREEITEM hPrev = 0;
109 LPENUMIDLIST lpe=0;
110 LPITEMIDLIST pidlTemp=0;
111 LPTV_ITEMDATA lptvid=0;
112 ULONG ulFetched;
113 HRESULT hr;
114 char szBuff[256];
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);
123 if (SUCCEEDED(hr))
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)
132 { tvi.cChildren=1;
133 tvi.mask |= TVIF_CHILDREN;
136 if (!( lptvid = (LPTV_ITEMDATA)SHAlloc(sizeof(TV_ITEMDATA))))
137 goto Done;
139 if (!GetName(lpsf, pidlTemp, SHGDN_NORMAL, szBuff))
140 goto Done;
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... */
161 pidlTemp=0;
165 Done:
166 ReleaseCapture();
167 SetCursor(LoadCursorA(0, IDC_ARROWA));
169 if (lpe)
170 IEnumIDList_Release(lpe);
171 if (pidlTemp )
172 SHFree(pidlTemp);
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)
185 { case IDD_TREEVIEW:
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);
191 SHFree(lptvid->lpi);
192 SHFree(lptvid->lpifq);
193 SHFree(lptvid);
195 break;
197 case TVN_ITEMEXPANDINGA:
198 { FIXME("TVN_ITEMEXPANDINGA\n");
199 if ((pnmtv->itemNew.state & TVIS_EXPANDEDONCE))
200 break;
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);
208 break;
209 case TVN_SELCHANGEDA:
210 lptvid=(LPTV_ITEMDATA)pnmtv->itemNew.lParam;
211 pidlRet = lptvid->lpifq;
212 break;
214 default:
215 FIXME("unhandled\n");
216 break;
218 break;
220 default:
221 break;
224 return 0;
228 /*************************************************************************
229 * BrsFolderDlgProc32 (not an exported API function)
231 static BOOL WINAPI BrsFolderDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
232 LPARAM lParam )
233 { TRACE("hwnd=%i msg=%i 0x%08x 0x%08lx\n", hWnd, msg, wParam, lParam );
235 switch(msg)
236 { case WM_INITDIALOG:
237 pidlRet = NULL;
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);
249 return 1;
251 case WM_NOTIFY:
252 MsgNotify( hWnd, (UINT)wParam, (LPNMHDR)lParam);
253 break;
255 case WM_COMMAND:
256 switch (wParam)
257 { case IDOK:
258 pdump ( pidlRet );
259 SHGetPathFromIDListA(pidlRet, lpBrowseInfo->pszDisplayName);
260 EndDialog(hWnd, (DWORD) ILClone(pidlRet));
261 return TRUE;
263 case IDCANCEL:
264 EndDialog(hWnd, 0);
265 return TRUE;
267 break;
269 return 0;
272 /*************************************************************************
273 * SHBrowseForFolderA [SHELL32.209]
276 LPITEMIDLIST WINAPI SHBrowseForFolderA (LPBROWSEINFOA lpbi)
278 TRACE("(%lx,%s) empty stub!\n", (DWORD)lpbi, lpbi->lpszTitle);
280 return (LPITEMIDLIST) DialogBoxParamA( shell32_hInstance,
281 "SHBRSFORFOLDER_MSGBOX", 0,
282 BrsFolderDlgProc, (INT)lpbi );