Revert tree-restructure attempt: r66583, r66582, r66581, r66578, sauf ntdll changes...
[reactos.git] / reactos / dll / win32 / shell32 / wine / brsfolder.c
1 /*
2 * Copyright 1999 Juergen Schmied
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 *
18 * FIXME:
19 * - many memory leaks
20 * - many flags unimplemented
21 * - implement editbox
22 */
23
24 #define WIN32_NO_STATUS
25 #define _INC_WINDOWS
26 #define COBJMACROS
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
29
30 #include <windef.h>
31 #include <winbase.h>
32 #include <shlobj.h>
33 #include <undocshell.h>
34 #include <shellapi.h>
35 #include <wine/debug.h>
36 #include <wine/unicode.h>
37
38 #include "pidl.h"
39 #include "shell32_main.h"
40 #include "shresdef.h"
41 #include "shellfolder.h"
42
43 WINE_DEFAULT_DEBUG_CHANNEL(shell);
44
45 /* original margins and control size */
46 typedef struct tagLAYOUT_DATA
47 {
48 LONG left, width, right;
49 LONG top, height, bottom;
50 } LAYOUT_DATA;
51
52 typedef struct tagbrowse_info
53 {
54 HWND hWnd;
55 HWND hwndTreeView;
56 LPBROWSEINFOW lpBrowseInfo;
57 LPITEMIDLIST pidlRet;
58 LAYOUT_DATA *layout; /* filled by LayoutInit, used by LayoutUpdate */
59 SIZE szMin;
60 } browse_info;
61
62 typedef struct tagTV_ITEMDATA
63 {
64 LPSHELLFOLDER lpsfParent; /* IShellFolder of the parent */
65 LPITEMIDLIST lpi; /* PIDL relative to parent */
66 LPITEMIDLIST lpifq; /* Fully qualified PIDL */
67 IEnumIDList* pEnumIL; /* Children iterator */
68 } TV_ITEMDATA, *LPTV_ITEMDATA;
69
70 typedef struct tagLAYOUT_INFO
71 {
72 int iItemId; /* control id */
73 DWORD dwAnchor; /* BF_* flags specifying which margins should remain constant */
74 } LAYOUT_INFO;
75
76 static const LAYOUT_INFO g_layout_info[] =
77 {
78 {IDC_BROWSE_FOR_FOLDER_TITLE, BF_TOP|BF_LEFT|BF_RIGHT},
79 {IDC_BROWSE_FOR_FOLDER_STATUS, BF_TOP|BF_LEFT|BF_RIGHT},
80 {IDC_BROWSE_FOR_FOLDER_FOLDER, BF_TOP|BF_LEFT|BF_RIGHT},
81 {IDC_BROWSE_FOR_FOLDER_TREEVIEW, BF_TOP|BF_BOTTOM|BF_LEFT|BF_RIGHT},
82 {IDC_BROWSE_FOR_FOLDER_FOLDER, BF_BOTTOM|BF_LEFT},
83 {IDC_BROWSE_FOR_FOLDER_FOLDER_TEXT, BF_BOTTOM|BF_LEFT|BF_RIGHT},
84 {IDC_BROWSE_FOR_FOLDER_NEW_FOLDER, BF_BOTTOM|BF_LEFT},
85 {IDOK, BF_BOTTOM|BF_RIGHT},
86 {IDCANCEL, BF_BOTTOM|BF_RIGHT}
87 };
88
89 #define LAYOUT_INFO_COUNT (sizeof(g_layout_info)/sizeof(g_layout_info[0]))
90
91 #define SUPPORTEDFLAGS (BIF_STATUSTEXT | \
92 BIF_BROWSEFORCOMPUTER | \
93 BIF_RETURNFSANCESTORS | \
94 BIF_RETURNONLYFSDIRS | \
95 BIF_NONEWFOLDERBUTTON | \
96 BIF_NEWDIALOGSTYLE | \
97 BIF_BROWSEINCLUDEFILES)
98
99 static void FillTreeView(browse_info*, LPSHELLFOLDER,
100 LPITEMIDLIST, HTREEITEM, IEnumIDList*);
101 static HTREEITEM InsertTreeViewItem( browse_info*, IShellFolder *,
102 LPCITEMIDLIST, LPCITEMIDLIST, IEnumIDList*, HTREEITEM);
103
104 static const WCHAR szBrowseFolderInfo[] = {
105 '_','_','W','I','N','E','_',
106 'B','R','S','F','O','L','D','E','R','D','L','G','_',
107 'I','N','F','O',0
108 };
109
110 static inline DWORD BrowseFlagsToSHCONTF(UINT ulFlags)
111 {
112 return SHCONTF_FOLDERS | (ulFlags & BIF_BROWSEINCLUDEFILES ? SHCONTF_NONFOLDERS : 0);
113 }
114
115 static void browsefolder_callback( LPBROWSEINFOW lpBrowseInfo, HWND hWnd,
116 UINT msg, LPARAM param )
117 {
118 if (!lpBrowseInfo->lpfn)
119 return;
120 lpBrowseInfo->lpfn( hWnd, msg, param, lpBrowseInfo->lParam );
121 }
122
123 static LAYOUT_DATA *LayoutInit(HWND hwnd, const LAYOUT_INFO *layout_info, int layout_count)
124 {
125 LAYOUT_DATA *data;
126 RECT rcWnd;
127 int i;
128
129 GetClientRect(hwnd, &rcWnd);
130 data = SHAlloc(sizeof(LAYOUT_DATA)*layout_count);
131 for (i = 0; i < layout_count; i++)
132 {
133 RECT r;
134 HWND hItem = GetDlgItem(hwnd, layout_info[i].iItemId);
135
136 if (hItem == NULL)
137 ERR("Item %d not found\n", i);
138 GetWindowRect(hItem, &r);
139 MapWindowPoints(HWND_DESKTOP, hwnd, (LPPOINT)&r, 2);
140
141 data[i].left = r.left;
142 data[i].right = rcWnd.right - r.right;
143 data[i].width = r.right - r.left;
144
145 data[i].top = r.top;
146 data[i].bottom = rcWnd.bottom - r.bottom;
147 data[i].height = r.bottom - r.top;
148 }
149 return data;
150 }
151
152 static void LayoutUpdate(HWND hwnd, LAYOUT_DATA *data, const LAYOUT_INFO *layout_info, int layout_count)
153 {
154 RECT rcWnd;
155 int i;
156
157 GetClientRect(hwnd, &rcWnd);
158 for (i = 0; i < layout_count; i++)
159 {
160 RECT r;
161 HWND hItem = GetDlgItem(hwnd, layout_info[i].iItemId);
162
163 GetWindowRect(hItem, &r);
164 MapWindowPoints(HWND_DESKTOP, hwnd, (LPPOINT)&r, 2);
165
166 if (layout_info[i].dwAnchor & BF_RIGHT)
167 {
168 r.right = rcWnd.right - data[i].right;
169 if (!(layout_info[i].dwAnchor & BF_LEFT))
170 r.left = r.right - data[i].width;
171 }
172
173 if (layout_info[i].dwAnchor & BF_BOTTOM)
174 {
175 r.bottom = rcWnd.bottom - data[i].bottom;
176 if (!(layout_info[i].dwAnchor & BF_TOP))
177 r.top = r.bottom - data[i].height;
178 }
179
180 SetWindowPos(hItem, NULL, r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_NOZORDER);
181 }
182 }
183
184
185 /******************************************************************************
186 * InitializeTreeView [Internal]
187 *
188 * Called from WM_INITDIALOG handler.
189 *
190 * PARAMS
191 * hwndParent [I] The BrowseForFolder dialog
192 * root [I] ITEMIDLIST of the root shell folder
193 */
194 static void InitializeTreeView( browse_info *info )
195 {
196 LPITEMIDLIST pidlParent, pidlChild;
197 HIMAGELIST hImageList;
198 HRESULT hr;
199 IShellFolder *lpsfParent, *lpsfRoot;
200 IEnumIDList * pEnumChildren = NULL;
201 HTREEITEM item;
202 DWORD flags;
203 LPCITEMIDLIST root = info->lpBrowseInfo->pidlRoot;
204
205 TRACE("%p\n", info );
206
207 Shell_GetImageLists(NULL, &hImageList);
208
209 if (hImageList)
210 SendMessageW( info->hwndTreeView, TVM_SETIMAGELIST, 0, (LPARAM)hImageList );
211
212 /* We want to call InsertTreeViewItem down the code, in order to insert
213 * the root item of the treeview. Due to InsertTreeViewItem's signature,
214 * we need the following to do this:
215 *
216 * + An ITEMIDLIST corresponding to _the parent_ of root.
217 * + An ITEMIDLIST, which is a relative path from root's parent to root
218 * (containing a single SHITEMID).
219 * + An IShellFolder interface pointer of root's parent folder.
220 *
221 * If root is 'Desktop', then root's parent is also 'Desktop'.
222 */
223
224 pidlParent = ILClone(root);
225 ILRemoveLastID(pidlParent);
226 pidlChild = ILClone(ILFindLastID(root));
227
228 if (_ILIsDesktop(pidlParent)) {
229 hr = SHGetDesktopFolder(&lpsfParent);
230 } else {
231 IShellFolder *lpsfDesktop;
232 hr = SHGetDesktopFolder(&lpsfDesktop);
233 if (FAILED(hr)) {
234 WARN("SHGetDesktopFolder failed! hr = %08x\n", hr);
235 ILFree(pidlChild);
236 ILFree(pidlParent);
237 return;
238 }
239 hr = IShellFolder_BindToObject(lpsfDesktop, pidlParent, 0, &IID_IShellFolder, (LPVOID*)&lpsfParent);
240 IShellFolder_Release(lpsfDesktop);
241 }
242
243 if (FAILED(hr)) {
244 WARN("Could not bind to parent shell folder! hr = %08x\n", hr);
245 ILFree(pidlChild);
246 ILFree(pidlParent);
247 return;
248 }
249
250 if (!_ILIsEmpty(pidlChild)) {
251 hr = IShellFolder_BindToObject(lpsfParent, pidlChild, 0, &IID_IShellFolder, (LPVOID*)&lpsfRoot);
252 } else {
253 lpsfRoot = lpsfParent;
254 hr = IShellFolder_AddRef(lpsfParent);
255 }
256
257 if (FAILED(hr)) {
258 WARN("Could not bind to root shell folder! hr = %08x\n", hr);
259 IShellFolder_Release(lpsfParent);
260 ILFree(pidlChild);
261 ILFree(pidlParent);
262 return;
263 }
264
265 flags = BrowseFlagsToSHCONTF( info->lpBrowseInfo->ulFlags );
266 hr = IShellFolder_EnumObjects( lpsfRoot, info->hWnd, flags, &pEnumChildren );
267 if (FAILED(hr)) {
268 WARN("Could not get child iterator! hr = %08x\n", hr);
269 IShellFolder_Release(lpsfParent);
270 IShellFolder_Release(lpsfRoot);
271 ILFree(pidlChild);
272 ILFree(pidlParent);
273 return;
274 }
275
276 SendMessageW( info->hwndTreeView, TVM_DELETEITEM, 0, (LPARAM)TVI_ROOT );
277 item = InsertTreeViewItem( info, lpsfParent, pidlChild,
278 pidlParent, pEnumChildren, TVI_ROOT );
279 SendMessageW( info->hwndTreeView, TVM_EXPAND, TVE_EXPAND, (LPARAM)item );
280
281 ILFree(pidlChild);
282 ILFree(pidlParent);
283 IShellFolder_Release(lpsfRoot);
284 IShellFolder_Release(lpsfParent);
285 }
286
287 static int GetIcon(LPCITEMIDLIST lpi, UINT uFlags)
288 {
289 SHFILEINFOW sfi;
290 SHGetFileInfoW((LPCWSTR)lpi, 0 ,&sfi, sizeof(SHFILEINFOW), uFlags);
291 return sfi.iIcon;
292 }
293
294 static void GetNormalAndSelectedIcons(LPITEMIDLIST lpifq, LPTVITEMW lpTV_ITEM)
295 {
296 LPITEMIDLIST pidlDesktop = NULL;
297 DWORD flags;
298
299 TRACE("%p %p\n",lpifq, lpTV_ITEM);
300
301 if (!lpifq)
302 {
303 pidlDesktop = _ILCreateDesktop();
304 lpifq = pidlDesktop;
305 }
306
307 flags = SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON;
308 lpTV_ITEM->iImage = GetIcon( lpifq, flags );
309
310 flags = SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_OPENICON;
311 lpTV_ITEM->iSelectedImage = GetIcon( lpifq, flags );
312
313 if (pidlDesktop)
314 ILFree( pidlDesktop );
315 }
316
317 /******************************************************************************
318 * GetName [Internal]
319 *
320 * Query a shell folder for the display name of one of its children
321 *
322 * PARAMS
323 * lpsf [I] IShellFolder interface of the folder to be queried.
324 * lpi [I] ITEMIDLIST of the child, relative to parent
325 * dwFlags [I] as in IShellFolder::GetDisplayNameOf
326 * lpFriendlyName [O] The desired display name in unicode
327 *
328 * RETURNS
329 * Success: TRUE
330 * Failure: FALSE
331 */
332 static BOOL GetName(LPSHELLFOLDER lpsf, LPCITEMIDLIST lpi, DWORD dwFlags, LPWSTR lpFriendlyName)
333 {
334 BOOL bSuccess=TRUE;
335 STRRET str;
336
337 TRACE("%p %p %x %p\n", lpsf, lpi, dwFlags, lpFriendlyName);
338 if (SUCCEEDED(IShellFolder_GetDisplayNameOf(lpsf, lpi, dwFlags, &str)))
339 bSuccess = StrRetToStrNW(lpFriendlyName, MAX_PATH, &str, lpi);
340 else
341 bSuccess = FALSE;
342
343 TRACE("-- %s\n", debugstr_w(lpFriendlyName));
344 return bSuccess;
345 }
346
347 /******************************************************************************
348 * InsertTreeViewItem [Internal]
349 *
350 * PARAMS
351 * info [I] data for the dialog
352 * lpsf [I] IShellFolder interface of the item's parent shell folder
353 * pidl [I] ITEMIDLIST of the child to insert, relative to parent
354 * pidlParent [I] ITEMIDLIST of the parent shell folder
355 * pEnumIL [I] Iterator for the children of the item to be inserted
356 * hParent [I] The treeview-item that represents the parent shell folder
357 *
358 * RETURNS
359 * Success: Handle to the created and inserted treeview-item
360 * Failure: NULL
361 */
362 static HTREEITEM InsertTreeViewItem( browse_info *info, IShellFolder * lpsf,
363 LPCITEMIDLIST pidl, LPCITEMIDLIST pidlParent, IEnumIDList* pEnumIL,
364 HTREEITEM hParent)
365 {
366 TVITEMW tvi;
367 TVINSERTSTRUCTW tvins;
368 WCHAR szBuff[MAX_PATH];
369 LPTV_ITEMDATA lptvid=0;
370
371 tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
372
373 tvi.cChildren= pEnumIL ? 1 : 0;
374 tvi.mask |= TVIF_CHILDREN;
375
376 if (!GetName(lpsf, pidl, SHGDN_NORMAL, szBuff))
377 return NULL;
378
379 lptvid = SHAlloc( sizeof(TV_ITEMDATA) );
380 if (!lptvid)
381 return NULL;
382
383 tvi.pszText = szBuff;
384 tvi.cchTextMax = MAX_PATH;
385 tvi.lParam = (LPARAM)lptvid;
386
387 IShellFolder_AddRef(lpsf);
388 lptvid->lpsfParent = lpsf;
389 lptvid->lpi = ILClone(pidl);
390 lptvid->lpifq = pidlParent ? ILCombine(pidlParent, pidl) : ILClone(pidl);
391 lptvid->pEnumIL = pEnumIL;
392 GetNormalAndSelectedIcons(lptvid->lpifq, &tvi);
393
394 tvins.u.item = tvi;
395 tvins.hInsertAfter = NULL;
396 tvins.hParent = hParent;
397
398 return TreeView_InsertItem( info->hwndTreeView, &tvins );
399 }
400
401 /******************************************************************************
402 * FillTreeView [Internal]
403 *
404 * For each child (given by lpe) of the parent shell folder, which is given by
405 * lpsf and whose PIDL is pidl, insert a treeview-item right under hParent
406 *
407 * PARAMS
408 * info [I] data for the dialog
409 * lpsf [I] IShellFolder interface of the parent shell folder
410 * pidl [I] ITEMIDLIST of the parent shell folder
411 * hParent [I] The treeview item that represents the parent shell folder
412 * lpe [I] An iterator for the children of the parent shell folder
413 */
414 static void FillTreeView( browse_info *info, IShellFolder * lpsf,
415 LPITEMIDLIST pidl, HTREEITEM hParent, IEnumIDList* lpe)
416 {
417 LPITEMIDLIST pidlTemp = 0;
418 ULONG ulFetched;
419 HRESULT hr;
420 HWND hwnd = GetParent( info->hwndTreeView );
421
422 TRACE("%p %p %p %p\n",lpsf, pidl, hParent, lpe);
423
424 /* No IEnumIDList -> No children */
425 if (!lpe) return;
426
427 SetCapture( hwnd );
428 SetCursor( LoadCursorA( 0, (LPSTR)IDC_WAIT ) );
429
430 while (S_OK == IEnumIDList_Next(lpe,1,&pidlTemp,&ulFetched))
431 {
432 ULONG ulAttrs = SFGAO_HASSUBFOLDER | SFGAO_FOLDER;
433 IEnumIDList* pEnumIL = NULL;
434 IShellFolder* pSFChild = NULL;
435 IShellFolder_GetAttributesOf(lpsf, 1, (LPCITEMIDLIST*)&pidlTemp, &ulAttrs);
436 if (ulAttrs & SFGAO_FOLDER)
437 {
438 hr = IShellFolder_BindToObject(lpsf,pidlTemp,NULL,&IID_IShellFolder,(LPVOID*)&pSFChild);
439 if (SUCCEEDED(hr))
440 {
441 DWORD flags = BrowseFlagsToSHCONTF(info->lpBrowseInfo->ulFlags);
442 hr = IShellFolder_EnumObjects(pSFChild, hwnd, flags, &pEnumIL);
443 if (hr == S_OK)
444 {
445 if ((IEnumIDList_Skip(pEnumIL, 1) != S_OK) ||
446 FAILED(IEnumIDList_Reset(pEnumIL)))
447 {
448 IEnumIDList_Release(pEnumIL);
449 pEnumIL = NULL;
450 }
451 }
452 IShellFolder_Release(pSFChild);
453 }
454 }
455
456 if (!InsertTreeViewItem(info, lpsf, pidlTemp, pidl, pEnumIL, hParent))
457 goto done;
458 SHFree(pidlTemp); /* Finally, free the pidl that the shell gave us... */
459 pidlTemp=NULL;
460 }
461
462 done:
463 ReleaseCapture();
464 SetCursor(LoadCursorW(0, (LPWSTR)IDC_ARROW));
465 SHFree(pidlTemp);
466 }
467
468 static inline BOOL PIDLIsType(LPCITEMIDLIST pidl, PIDLTYPE type)
469 {
470 LPPIDLDATA data = _ILGetDataPointer(pidl);
471 if (!data)
472 return FALSE;
473 return (data->type == type);
474 }
475
476 static void BrsFolder_CheckValidSelection( browse_info *info, LPTV_ITEMDATA lptvid )
477 {
478 LPBROWSEINFOW lpBrowseInfo = info->lpBrowseInfo;
479 LPCITEMIDLIST pidl = lptvid->lpi;
480 BOOL bEnabled = TRUE;
481 DWORD dwAttributes;
482 HRESULT r;
483
484 if ((lpBrowseInfo->ulFlags & BIF_BROWSEFORCOMPUTER) &&
485 !PIDLIsType(pidl, PT_COMP))
486 bEnabled = FALSE;
487 if (lpBrowseInfo->ulFlags & BIF_RETURNFSANCESTORS)
488 {
489 dwAttributes = SFGAO_FILESYSANCESTOR | SFGAO_FILESYSTEM;
490 r = IShellFolder_GetAttributesOf(lptvid->lpsfParent, 1,
491 (LPCITEMIDLIST*)&lptvid->lpi, &dwAttributes);
492 if (FAILED(r) || !(dwAttributes & (SFGAO_FILESYSANCESTOR|SFGAO_FILESYSTEM)))
493 bEnabled = FALSE;
494 }
495
496 dwAttributes = SFGAO_FOLDER | SFGAO_FILESYSTEM;
497 r = IShellFolder_GetAttributesOf(lptvid->lpsfParent, 1,
498 (LPCITEMIDLIST*)&lptvid->lpi, &dwAttributes);
499 if (FAILED(r) ||
500 ((dwAttributes & (SFGAO_FOLDER|SFGAO_FILESYSTEM)) != (SFGAO_FOLDER|SFGAO_FILESYSTEM)))
501 {
502 if (lpBrowseInfo->ulFlags & BIF_RETURNONLYFSDIRS)
503 bEnabled = FALSE;
504 EnableWindow(GetDlgItem(info->hWnd, IDC_BROWSE_FOR_FOLDER_NEW_FOLDER), FALSE);
505 }
506 else
507 EnableWindow(GetDlgItem(info->hWnd, IDC_BROWSE_FOR_FOLDER_NEW_FOLDER), TRUE);
508
509 SendMessageW(info->hWnd, BFFM_ENABLEOK, 0, bEnabled);
510 }
511
512 static LRESULT BrsFolder_Treeview_Delete( browse_info *info, NMTREEVIEWW *pnmtv )
513 {
514 LPTV_ITEMDATA lptvid = (LPTV_ITEMDATA)pnmtv->itemOld.lParam;
515
516 TRACE("TVN_DELETEITEMA/W %p\n", lptvid);
517
518 IShellFolder_Release(lptvid->lpsfParent);
519 if (lptvid->pEnumIL)
520 IEnumIDList_Release(lptvid->pEnumIL);
521 SHFree(lptvid->lpi);
522 SHFree(lptvid->lpifq);
523 SHFree(lptvid);
524 return 0;
525 }
526
527 static LRESULT BrsFolder_Treeview_Expand( browse_info *info, NMTREEVIEWW *pnmtv )
528 {
529 IShellFolder *lpsf2 = NULL;
530 LPTV_ITEMDATA lptvid = (LPTV_ITEMDATA) pnmtv->itemNew.lParam;
531 HRESULT r;
532
533 TRACE("TVN_ITEMEXPANDINGA/W\n");
534
535 if ((pnmtv->itemNew.state & TVIS_EXPANDEDONCE))
536 return 0;
537
538 if (!_ILIsEmpty(lptvid->lpi)) {
539 r = IShellFolder_BindToObject( lptvid->lpsfParent, lptvid->lpi, 0,
540 &IID_IShellFolder, (void**)&lpsf2 );
541 } else {
542 lpsf2 = lptvid->lpsfParent;
543 IShellFolder_AddRef(lpsf2);
544 r = S_OK;
545 }
546
547 if (SUCCEEDED(r))
548 {
549 FillTreeView( info, lpsf2, lptvid->lpifq, pnmtv->itemNew.hItem, lptvid->pEnumIL);
550 IShellFolder_Release( lpsf2 );
551 }
552
553 /* My Computer is already sorted and trying to do a simple text
554 * sort will only mess things up */
555 if (!_ILIsMyComputer(lptvid->lpi))
556 SendMessageW( info->hwndTreeView, TVM_SORTCHILDREN,
557 FALSE, (LPARAM)pnmtv->itemNew.hItem );
558
559 return 0;
560 }
561
562 static HRESULT BrsFolder_Treeview_Changed( browse_info *info, NMTREEVIEWW *pnmtv )
563 {
564 LPTV_ITEMDATA lptvid = (LPTV_ITEMDATA) pnmtv->itemNew.lParam;
565 WCHAR name[MAX_PATH];
566
567 ILFree(info->pidlRet);
568 info->pidlRet = ILClone(lptvid->lpifq);
569
570 if (GetName(lptvid->lpsfParent, lptvid->lpi, SHGDN_NORMAL, name))
571 SetWindowTextW( GetDlgItem(info->hWnd, IDC_BROWSE_FOR_FOLDER_FOLDER_TEXT), name );
572
573 browsefolder_callback( info->lpBrowseInfo, info->hWnd, BFFM_SELCHANGED,
574 (LPARAM)info->pidlRet );
575 BrsFolder_CheckValidSelection( info, lptvid );
576 return S_OK;
577 }
578
579 static LRESULT BrsFolder_Treeview_Rename(browse_info *info, NMTVDISPINFOW *pnmtv)
580 {
581 LPTV_ITEMDATA item_data;
582 WCHAR old_path[MAX_PATH], new_path[MAX_PATH], *p;
583 NMTREEVIEWW nmtv;
584 TVITEMW item;
585
586 if(!pnmtv->item.pszText)
587 return 0;
588
589 item.mask = TVIF_HANDLE|TVIF_PARAM;
590 item.hItem = (HTREEITEM)SendMessageW(info->hwndTreeView, TVM_GETNEXTITEM, TVGN_CARET, 0);
591 SendMessageW(info->hwndTreeView, TVM_GETITEMW, 0, (LPARAM)&item);
592 item_data = (LPTV_ITEMDATA)item.lParam;
593
594 SHGetPathFromIDListW(item_data->lpifq, old_path);
595 if(!(p = strrchrW(old_path, '\\')))
596 return 0;
597 p = new_path+(p-old_path+1);
598 memcpy(new_path, old_path, (p-new_path)*sizeof(WCHAR));
599 strcpyW(p, pnmtv->item.pszText);
600
601 if(!MoveFileW(old_path, new_path))
602 return 0;
603
604 SHFree(item_data->lpifq);
605 SHFree(item_data->lpi);
606 item_data->lpifq = SHSimpleIDListFromPathW(new_path);
607 IShellFolder_ParseDisplayName(item_data->lpsfParent, NULL, NULL,
608 pnmtv->item.pszText, NULL, &item_data->lpi, NULL);
609
610 item.mask = TVIF_HANDLE|TVIF_TEXT;
611 item.pszText = pnmtv->item.pszText;
612 SendMessageW(info->hwndTreeView, TVM_SETITEMW, 0, (LPARAM)&item);
613
614 nmtv.itemNew.lParam = item.lParam;
615 BrsFolder_Treeview_Changed(info, &nmtv);
616 return 0;
617 }
618
619 static LRESULT BrsFolder_OnNotify( browse_info *info, UINT CtlID, LPNMHDR lpnmh )
620 {
621 NMTREEVIEWW *pnmtv = (NMTREEVIEWW *)lpnmh;
622
623 TRACE("%p %x %p msg=%x\n", info, CtlID, lpnmh, pnmtv->hdr.code);
624
625 if (pnmtv->hdr.idFrom != IDC_BROWSE_FOR_FOLDER_TREEVIEW)
626 return 0;
627
628 switch (pnmtv->hdr.code)
629 {
630 case TVN_DELETEITEMA:
631 case TVN_DELETEITEMW:
632 return BrsFolder_Treeview_Delete( info, pnmtv );
633
634 case TVN_ITEMEXPANDINGA:
635 case TVN_ITEMEXPANDINGW:
636 return BrsFolder_Treeview_Expand( info, pnmtv );
637
638 case TVN_SELCHANGEDA:
639 case TVN_SELCHANGEDW:
640 return BrsFolder_Treeview_Changed( info, pnmtv );
641
642 case TVN_ENDLABELEDITA:
643 case TVN_ENDLABELEDITW:
644 return BrsFolder_Treeview_Rename( info, (LPNMTVDISPINFOW)pnmtv );
645
646 default:
647 WARN("unhandled (%d)\n", pnmtv->hdr.code);
648 break;
649 }
650
651 return 0;
652 }
653
654
655 static BOOL BrsFolder_OnCreate( HWND hWnd, browse_info *info )
656 {
657 LPBROWSEINFOW lpBrowseInfo = info->lpBrowseInfo;
658
659 info->hWnd = hWnd;
660 SetPropW( hWnd, szBrowseFolderInfo, info );
661
662 if (lpBrowseInfo->ulFlags & BIF_NEWDIALOGSTYLE)
663 FIXME("flags BIF_NEWDIALOGSTYLE partially implemented\n");
664 if (lpBrowseInfo->ulFlags & ~SUPPORTEDFLAGS)
665 FIXME("flags %x not implemented\n", lpBrowseInfo->ulFlags & ~SUPPORTEDFLAGS);
666
667 if (lpBrowseInfo->ulFlags & BIF_NEWDIALOGSTYLE)
668 {
669 RECT rcWnd;
670
671 info->layout = LayoutInit(hWnd, g_layout_info, LAYOUT_INFO_COUNT);
672
673 /* TODO: Windows allows shrinking the windows a bit */
674 GetWindowRect(hWnd, &rcWnd);
675 info->szMin.cx = rcWnd.right - rcWnd.left;
676 info->szMin.cy = rcWnd.bottom - rcWnd.top;
677 }
678 else
679 {
680 info->layout = NULL;
681 }
682
683 if (lpBrowseInfo->lpszTitle)
684 SetWindowTextW( GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_TITLE), lpBrowseInfo->lpszTitle );
685 else
686 ShowWindow( GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_TITLE), SW_HIDE );
687
688 if (!(lpBrowseInfo->ulFlags & BIF_STATUSTEXT)
689 || (lpBrowseInfo->ulFlags & BIF_NEWDIALOGSTYLE))
690 ShowWindow( GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_STATUS), SW_HIDE );
691
692 /* Hide "Make New Folder" Button? */
693 if ((lpBrowseInfo->ulFlags & BIF_NONEWFOLDERBUTTON)
694 || !(lpBrowseInfo->ulFlags & BIF_NEWDIALOGSTYLE))
695 ShowWindow( GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_NEW_FOLDER), SW_HIDE );
696
697 /* Hide the editbox? */
698 if (!(lpBrowseInfo->ulFlags & BIF_EDITBOX))
699 {
700 ShowWindow( GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_FOLDER), SW_HIDE );
701 ShowWindow( GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_FOLDER_TEXT), SW_HIDE );
702 }
703
704 info->hwndTreeView = GetDlgItem( hWnd, IDC_BROWSE_FOR_FOLDER_TREEVIEW );
705 if (info->hwndTreeView)
706 {
707 InitializeTreeView( info );
708
709 /* Resize the treeview if there's not editbox */
710 if ((lpBrowseInfo->ulFlags & BIF_NEWDIALOGSTYLE)
711 && !(lpBrowseInfo->ulFlags & BIF_EDITBOX))
712 {
713 RECT rc;
714 GetClientRect(info->hwndTreeView, &rc);
715 SetWindowPos(info->hwndTreeView, HWND_TOP, 0, 0,
716 rc.right, rc.bottom + 40, SWP_NOMOVE);
717 }
718 }
719 else
720 ERR("treeview control missing!\n");
721
722 browsefolder_callback( info->lpBrowseInfo, hWnd, BFFM_INITIALIZED, 0 );
723
724 return TRUE;
725 }
726
727 static HRESULT BrsFolder_Rename(browse_info *info, HTREEITEM rename)
728 {
729 SendMessageW(info->hwndTreeView, TVM_SELECTITEM, TVGN_CARET, (LPARAM)rename);
730 SendMessageW(info->hwndTreeView, TVM_EDITLABELW, 0, (LPARAM)rename);
731 return S_OK;
732 }
733
734 static HRESULT BrsFolder_NewFolder(browse_info *info)
735 {
736 DWORD flags = BrowseFlagsToSHCONTF(info->lpBrowseInfo->ulFlags);
737 IShellFolder *desktop, *cur;
738 ISFHelper *sfhelper;
739 WCHAR name[MAX_PATH];
740 HTREEITEM parent, added;
741 LPTV_ITEMDATA item_data;
742 LPITEMIDLIST new_item;
743 TVITEMW item;
744 HRESULT hr;
745 int len;
746
747 if(!info->pidlRet) {
748 ERR("Make new folder button should be disabled\n");
749 return E_FAIL;
750 }
751
752 /* Create new directory */
753 hr = SHGetDesktopFolder(&desktop);
754 if(FAILED(hr))
755 return hr;
756 hr = IShellFolder_BindToObject(desktop, info->pidlRet, 0, &IID_IShellFolder, (void**)&cur);
757 IShellFolder_Release(desktop);
758 if(FAILED(hr))
759 return hr;
760
761 hr = IShellFolder_QueryInterface(cur, &IID_ISFHelper, (void**)&sfhelper);
762 if(FAILED(hr))
763 return hr;
764
765 hr = SHGetPathFromIDListW(info->pidlRet, name);
766 if(FAILED(hr))
767 goto cleanup;
768
769 len = strlenW(name);
770 if(len<MAX_PATH)
771 name[len++] = '\\';
772 hr = ISFHelper_GetUniqueName(sfhelper, &name[len], MAX_PATH-len);
773 ISFHelper_Release(sfhelper);
774 if(FAILED(hr))
775 goto cleanup;
776
777 hr = E_FAIL;
778 if(!CreateDirectoryW(name, NULL))
779 goto cleanup;
780
781 /* Update parent of newly created directory */
782 parent = (HTREEITEM)SendMessageW(info->hwndTreeView, TVM_GETNEXTITEM, TVGN_CARET, 0);
783 if(!parent)
784 goto cleanup;
785
786 SendMessageW(info->hwndTreeView, TVM_EXPAND, TVE_EXPAND, (LPARAM)parent);
787
788 memset(&item, 0, sizeof(TVITEMW));
789 item.mask = TVIF_PARAM|TVIF_STATE;
790 item.hItem = parent;
791 SendMessageW(info->hwndTreeView, TVM_GETITEMW, 0, (LPARAM)&item);
792 item_data = (LPTV_ITEMDATA)item.lParam;
793 if(!item_data)
794 goto cleanup;
795
796 if(item_data->pEnumIL)
797 IEnumIDList_Release(item_data->pEnumIL);
798 hr = IShellFolder_EnumObjects(cur, info->hwndTreeView, flags, &item_data->pEnumIL);
799 if(FAILED(hr))
800 goto cleanup;
801
802 /* Update treeview */
803 if(!(item.state&TVIS_EXPANDEDONCE)) {
804 item.mask = TVIF_STATE;
805 item.state = TVIS_EXPANDEDONCE;
806 item.stateMask = TVIS_EXPANDEDONCE;
807 SendMessageW(info->hwndTreeView, TVM_SETITEMW, 0, (LPARAM)&item);
808 }
809
810 hr = IShellFolder_ParseDisplayName(cur, NULL, NULL, name+len, NULL, &new_item, NULL);
811 if(FAILED(hr))
812 goto cleanup;
813
814 added = InsertTreeViewItem(info, cur, new_item, item_data->lpifq, NULL, parent);
815 IShellFolder_Release(cur);
816 SHFree(new_item);
817
818 SendMessageW(info->hwndTreeView, TVM_SORTCHILDREN, FALSE, (LPARAM)parent);
819 return BrsFolder_Rename(info, added);
820
821 cleanup:
822 return hr;
823 }
824
825 static BOOL BrsFolder_OnCommand( browse_info *info, UINT id )
826 {
827 LPBROWSEINFOW lpBrowseInfo = info->lpBrowseInfo;
828
829 switch (id)
830 {
831 case IDOK:
832 #ifdef __REACTOS__
833 /* The original pidl is owned by the treeview and will be free'd. */
834 info->pidlRet = ILClone(info->pidlRet);
835 #endif
836 if (info->pidlRet == NULL) /* A null pidl would mean a cancel */
837 info->pidlRet = _ILCreateDesktop();
838 pdump( info->pidlRet );
839 if (lpBrowseInfo->pszDisplayName)
840 SHGetPathFromIDListW( info->pidlRet, lpBrowseInfo->pszDisplayName );
841 EndDialog( info->hWnd, 1 );
842 return TRUE;
843
844 case IDCANCEL:
845 EndDialog( info->hWnd, 0 );
846 return TRUE;
847
848 case IDC_BROWSE_FOR_FOLDER_NEW_FOLDER:
849 BrsFolder_NewFolder(info);
850 return TRUE;
851 }
852 return FALSE;
853 }
854
855 static BOOL BrsFolder_OnSetExpanded(browse_info *info, LPVOID selection,
856 BOOL is_str, HTREEITEM *pItem)
857 {
858 LPITEMIDLIST pidlSelection = selection;
859 LPCITEMIDLIST pidlCurrent, pidlRoot;
860 TVITEMEXW item;
861 BOOL bResult = FALSE;
862
863 memset(&item, 0, sizeof(item));
864
865 /* If 'selection' is a string, convert to a Shell ID List. */
866 if (is_str) {
867 IShellFolder *psfDesktop;
868 HRESULT hr;
869
870 hr = SHGetDesktopFolder(&psfDesktop);
871 if (FAILED(hr))
872 goto done;
873
874 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL,
875 selection, NULL, &pidlSelection, NULL);
876 IShellFolder_Release(psfDesktop);
877 if (FAILED(hr))
878 goto done;
879 }
880
881 /* Move pidlCurrent behind the SHITEMIDs in pidlSelection, which are the root of
882 * the sub-tree currently displayed. */
883 pidlRoot = info->lpBrowseInfo->pidlRoot;
884 pidlCurrent = pidlSelection;
885 while (!_ILIsEmpty(pidlRoot) && _ILIsEqualSimple(pidlRoot, pidlCurrent)) {
886 pidlRoot = ILGetNext(pidlRoot);
887 pidlCurrent = ILGetNext(pidlCurrent);
888 }
889
890 /* The given ID List is not part of the SHBrowseForFolder's current sub-tree. */
891 if (!_ILIsEmpty(pidlRoot))
892 goto done;
893
894 /* Initialize item to point to the first child of the root folder. */
895 item.mask = TVIF_PARAM;
896 item.hItem = (HTREEITEM)SendMessageW(info->hwndTreeView, TVM_GETNEXTITEM, TVGN_ROOT, 0);
897
898 if (item.hItem)
899 item.hItem = (HTREEITEM)SendMessageW(info->hwndTreeView, TVM_GETNEXTITEM, TVGN_CHILD,
900 (LPARAM)item.hItem);
901
902 /* Walk the tree along the nodes corresponding to the remaining ITEMIDLIST */
903 while (item.hItem && !_ILIsEmpty(pidlCurrent)) {
904 LPTV_ITEMDATA pItemData;
905
906 SendMessageW(info->hwndTreeView, TVM_GETITEMW, 0, (LPARAM)&item);
907 pItemData = (LPTV_ITEMDATA)item.lParam;
908
909 if (_ILIsEqualSimple(pItemData->lpi, pidlCurrent)) {
910 pidlCurrent = ILGetNext(pidlCurrent);
911 if (!_ILIsEmpty(pidlCurrent)) {
912 /* Only expand current node and move on to its first child,
913 * if we didn't already reach the last SHITEMID */
914 SendMessageW(info->hwndTreeView, TVM_EXPAND, TVE_EXPAND, (LPARAM)item.hItem);
915 item.hItem = (HTREEITEM)SendMessageW(info->hwndTreeView, TVM_GETNEXTITEM, TVGN_CHILD,
916 (LPARAM)item.hItem);
917 }
918 } else {
919 item.hItem = (HTREEITEM)SendMessageW(info->hwndTreeView, TVM_GETNEXTITEM, TVGN_NEXT,
920 (LPARAM)item.hItem);
921 }
922 }
923
924 if (_ILIsEmpty(pidlCurrent) && item.hItem)
925 bResult = TRUE;
926
927 done:
928 if (pidlSelection && pidlSelection != selection)
929 ILFree(pidlSelection);
930
931 if (pItem)
932 *pItem = item.hItem;
933
934 return bResult;
935 }
936
937 static BOOL BrsFolder_OnSetSelectionW(browse_info *info, LPVOID selection, BOOL is_str) {
938 HTREEITEM hItem;
939 BOOL bResult;
940
941 if (!selection) return FALSE;
942
943 bResult = BrsFolder_OnSetExpanded(info, selection, is_str, &hItem);
944 if (bResult)
945 SendMessageW(info->hwndTreeView, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hItem );
946 return bResult;
947 }
948
949 static BOOL BrsFolder_OnSetSelectionA(browse_info *info, LPVOID selection, BOOL is_str) {
950 LPWSTR selectionW = NULL;
951 BOOL result = FALSE;
952 int length;
953
954 if (!is_str)
955 return BrsFolder_OnSetSelectionW(info, selection, is_str);
956
957 if ((length = MultiByteToWideChar(CP_ACP, 0, selection, -1, NULL, 0)) &&
958 (selectionW = HeapAlloc(GetProcessHeap(), 0, length * sizeof(WCHAR))) &&
959 MultiByteToWideChar(CP_ACP, 0, selection, -1, selectionW, length))
960 {
961 result = BrsFolder_OnSetSelectionW(info, selectionW, is_str);
962 }
963
964 HeapFree(GetProcessHeap(), 0, selectionW);
965 return result;
966 }
967
968 static LRESULT BrsFolder_OnWindowPosChanging(browse_info *info, WINDOWPOS *pos)
969 {
970 if ((info->lpBrowseInfo->ulFlags & BIF_NEWDIALOGSTYLE) && !(pos->flags & SWP_NOSIZE))
971 {
972 if (pos->cx < info->szMin.cx)
973 pos->cx = info->szMin.cx;
974 if (pos->cy < info->szMin.cy)
975 pos->cy = info->szMin.cy;
976 }
977 return 0;
978 }
979
980 static INT BrsFolder_OnDestroy(browse_info *info)
981 {
982 if (info->layout)
983 {
984 SHFree(info->layout);
985 info->layout = NULL;
986 }
987
988 return 0;
989 }
990
991 /*************************************************************************
992 * BrsFolderDlgProc32 (not an exported API function)
993 */
994 static INT_PTR CALLBACK BrsFolderDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
995 LPARAM lParam )
996 {
997 browse_info *info;
998
999 TRACE("hwnd=%p msg=%04x 0x%08lx 0x%08lx\n", hWnd, msg, wParam, lParam );
1000
1001 if (msg == WM_INITDIALOG)
1002 return BrsFolder_OnCreate( hWnd, (browse_info*) lParam );
1003
1004 info = GetPropW( hWnd, szBrowseFolderInfo );
1005
1006 switch (msg)
1007 {
1008 case WM_NOTIFY:
1009 return BrsFolder_OnNotify( info, (UINT)wParam, (LPNMHDR)lParam);
1010
1011 case WM_COMMAND:
1012 return BrsFolder_OnCommand( info, wParam );
1013
1014 case WM_WINDOWPOSCHANGING:
1015 return BrsFolder_OnWindowPosChanging( info, (WINDOWPOS *)lParam);
1016
1017 case WM_SIZE:
1018 if (info->layout) /* new style dialogs */
1019 LayoutUpdate(hWnd, info->layout, g_layout_info, LAYOUT_INFO_COUNT);
1020 return 0;
1021
1022 case BFFM_SETSTATUSTEXTA:
1023 TRACE("Set status %s\n", debugstr_a((LPSTR)lParam));
1024 SetWindowTextA(GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_STATUS), (LPSTR)lParam);
1025 break;
1026
1027 case BFFM_SETSTATUSTEXTW:
1028 TRACE("Set status %s\n", debugstr_w((LPWSTR)lParam));
1029 SetWindowTextW(GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_STATUS), (LPWSTR)lParam);
1030 break;
1031
1032 case BFFM_ENABLEOK:
1033 TRACE("Enable %ld\n", lParam);
1034 EnableWindow(GetDlgItem(hWnd, 1), lParam != 0);
1035 break;
1036
1037 case BFFM_SETOKTEXT: /* unicode only */
1038 TRACE("Set OK text %s\n", debugstr_w((LPWSTR)lParam));
1039 SetWindowTextW(GetDlgItem(hWnd, 1), (LPWSTR)lParam);
1040 break;
1041
1042 case BFFM_SETSELECTIONA:
1043 return BrsFolder_OnSetSelectionA(info, (LPVOID)lParam, (BOOL)wParam);
1044
1045 case BFFM_SETSELECTIONW:
1046 return BrsFolder_OnSetSelectionW(info, (LPVOID)lParam, (BOOL)wParam);
1047
1048 case BFFM_SETEXPANDED: /* unicode only */
1049 return BrsFolder_OnSetExpanded(info, (LPVOID)lParam, (BOOL)wParam, NULL);
1050
1051 case WM_DESTROY:
1052 return BrsFolder_OnDestroy(info);
1053 }
1054 return FALSE;
1055 }
1056
1057 #ifndef __REACTOS__
1058 static const WCHAR swBrowseTemplateName[] = {
1059 'S','H','B','R','S','F','O','R','F','O','L','D','E','R','_','M','S','G','B','O','X',0};
1060 static const WCHAR swNewBrowseTemplateName[] = {
1061 'S','H','N','E','W','B','R','S','F','O','R','F','O','L','D','E','R','_','M','S','G','B','O','X',0};
1062 #endif
1063
1064 /*************************************************************************
1065 * SHBrowseForFolderA [SHELL32.@]
1066 * SHBrowseForFolder [SHELL32.@]
1067 */
1068 LPITEMIDLIST WINAPI SHBrowseForFolderA (LPBROWSEINFOA lpbi)
1069 {
1070 BROWSEINFOW bi;
1071 LPITEMIDLIST lpid;
1072 INT len;
1073 LPWSTR title;
1074
1075 TRACE("%p\n", lpbi);
1076
1077 bi.hwndOwner = lpbi->hwndOwner;
1078 bi.pidlRoot = lpbi->pidlRoot;
1079 if (lpbi->pszDisplayName)
1080 bi.pszDisplayName = HeapAlloc( GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR) );
1081 else
1082 bi.pszDisplayName = NULL;
1083
1084 if (lpbi->lpszTitle)
1085 {
1086 len = MultiByteToWideChar( CP_ACP, 0, lpbi->lpszTitle, -1, NULL, 0 );
1087 title = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1088 MultiByteToWideChar( CP_ACP, 0, lpbi->lpszTitle, -1, title, len );
1089 }
1090 else
1091 title = NULL;
1092
1093 bi.lpszTitle = title;
1094 bi.ulFlags = lpbi->ulFlags;
1095 bi.lpfn = lpbi->lpfn;
1096 bi.lParam = lpbi->lParam;
1097 bi.iImage = lpbi->iImage;
1098 lpid = SHBrowseForFolderW( &bi );
1099 if (bi.pszDisplayName)
1100 {
1101 WideCharToMultiByte( CP_ACP, 0, bi.pszDisplayName, -1,
1102 lpbi->pszDisplayName, MAX_PATH, 0, NULL);
1103 HeapFree( GetProcessHeap(), 0, bi.pszDisplayName );
1104 }
1105 HeapFree(GetProcessHeap(), 0, title);
1106 lpbi->iImage = bi.iImage;
1107 return lpid;
1108 }
1109
1110
1111 /*************************************************************************
1112 * SHBrowseForFolderW [SHELL32.@]
1113 *
1114 * NOTES
1115 * crashes when passed a null pointer
1116 */
1117 LPITEMIDLIST WINAPI SHBrowseForFolderW (LPBROWSEINFOW lpbi)
1118 {
1119 browse_info info;
1120 DWORD r;
1121 HRESULT hr;
1122 #ifdef __REACTOS__
1123 WORD wDlgId;
1124 #else
1125 const WCHAR * templateName;
1126 INITCOMMONCONTROLSEX icex;
1127 #endif
1128
1129 info.hWnd = 0;
1130 info.pidlRet = NULL;
1131 info.lpBrowseInfo = lpbi;
1132 info.hwndTreeView = NULL;
1133
1134 #ifndef __REACTOS__
1135 icex.dwSize = sizeof( icex );
1136 icex.dwICC = ICC_TREEVIEW_CLASSES;
1137 InitCommonControlsEx( &icex );
1138 #endif
1139
1140 hr = OleInitialize(NULL);
1141
1142 if (lpbi->ulFlags & BIF_NEWDIALOGSTYLE)
1143 wDlgId = IDD_BROWSE_FOR_FOLDER_NEW;
1144 else
1145 wDlgId = IDD_BROWSE_FOR_FOLDER;
1146 r = DialogBoxParamW( shell32_hInstance, MAKEINTRESOURCEW(wDlgId), lpbi->hwndOwner,
1147 BrsFolderDlgProc, (LPARAM)&info );
1148 if (SUCCEEDED(hr))
1149 OleUninitialize();
1150 if (!r)
1151 {
1152 ILFree(info.pidlRet);
1153 return NULL;
1154 }
1155
1156 return info.pidlRet;
1157 }