2 * Copyright 1999 Juergen Schmied
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * - view with root unequal desktop
21 * - show only filesystem objects
27 #include "wine/debug.h"
28 #include "undocshell.h"
31 #include "shell32_main.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
37 static HWND hwndTreeView
;
38 static LPBROWSEINFOA lpBrowseInfo
;
39 static LPITEMIDLIST pidlRet
;
41 static void FillTreeView(LPSHELLFOLDER lpsf
, LPITEMIDLIST lpifq
, HTREEITEM hParent
);
43 static void InitializeTreeView(HWND hwndParent
, LPCITEMIDLIST root
)
45 HIMAGELIST hImageList
;
49 hwndTreeView
= GetDlgItem (hwndParent
, IDD_TREEVIEW
);
50 Shell_GetImageList(NULL
, &hImageList
);
52 TRACE("dlg=%x tree=%x\n", hwndParent
, hwndTreeView
);
54 if (hImageList
&& hwndTreeView
)
55 { TreeView_SetImageList(hwndTreeView
, hImageList
, 0);
58 /* so far, this method doesn't work (still missing the upper level), keep the old way */
60 if (_ILIsDesktop (root
)) {
61 hr
= SHGetDesktopFolder(&lpsf
);
63 IShellFolder
* lpsfdesktop
;
65 hr
= SHGetDesktopFolder(&lpsfdesktop
);
67 hr
= IShellFolder_BindToObject(lpsfdesktop
, root
, 0,(REFIID
)&IID_IShellFolder
,(LPVOID
*)&lpsf
);
68 IShellFolder_Release(lpsfdesktop
);
72 hr
= SHGetDesktopFolder(&lpsf
);
75 if (SUCCEEDED(hr
) && hwndTreeView
)
76 { TreeView_DeleteAllItems(hwndTreeView
);
77 FillTreeView(lpsf
, NULL
, TVI_ROOT
);
81 { IShellFolder_Release(lpsf
);
86 static int GetIcon(LPITEMIDLIST lpi
, UINT uFlags
)
88 SHGetFileInfoA((LPCSTR
)lpi
,0,&sfi
, sizeof(SHFILEINFOA
), uFlags
);
92 static void GetNormalAndSelectedIcons(LPITEMIDLIST lpifq
,LPTVITEMA lpTV_ITEM
)
93 { TRACE("%p %p\n",lpifq
, lpTV_ITEM
);
95 lpTV_ITEM
->iImage
= GetIcon(lpifq
, SHGFI_PIDL
| SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
);
96 lpTV_ITEM
->iSelectedImage
= GetIcon(lpifq
, SHGFI_PIDL
| SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
| SHGFI_OPENICON
);
103 LPSHELLFOLDER lpsfParent
;
106 } TV_ITEMDATA
, *LPTV_ITEMDATA
;
108 static BOOL
GetName(LPSHELLFOLDER lpsf
, LPITEMIDLIST lpi
, DWORD dwFlags
, LPSTR lpFriendlyName
)
113 TRACE("%p %p %lx %p\n", lpsf
, lpi
, dwFlags
, lpFriendlyName
);
114 if (SUCCEEDED(IShellFolder_GetDisplayNameOf(lpsf
, lpi
, dwFlags
, &str
)))
116 if(FAILED(StrRetToStrNA (lpFriendlyName
, MAX_PATH
, &str
, lpi
)))
124 TRACE("-- %s\n",lpFriendlyName
);
128 static void FillTreeView(IShellFolder
* lpsf
, LPITEMIDLIST pidl
, HTREEITEM hParent
)
131 TVINSERTSTRUCTA tvins
;
134 LPITEMIDLIST pidlTemp
=0;
135 LPTV_ITEMDATA lptvid
=0;
139 HWND hwnd
=GetParent(hwndTreeView
);
141 TRACE("%p %p %x\n",lpsf
, pidl
, (INT
)hParent
);
142 SetCapture(GetParent(hwndTreeView
));
143 SetCursor(LoadCursorA(0, IDC_WAITA
));
145 hr
=IShellFolder_EnumObjects(lpsf
,hwnd
, SHCONTF_FOLDERS
| SHCONTF_NONFOLDERS
,&lpe
);
148 { while (NOERROR
== IEnumIDList_Next(lpe
,1,&pidlTemp
,&ulFetched
))
149 { ULONG ulAttrs
= SFGAO_HASSUBFOLDER
| SFGAO_FOLDER
;
150 IShellFolder_GetAttributesOf(lpsf
, 1, &pidlTemp
, &ulAttrs
);
151 if (ulAttrs
& (SFGAO_HASSUBFOLDER
| SFGAO_FOLDER
))
152 { if (ulAttrs
& SFGAO_FOLDER
)
153 { tvi
.mask
= TVIF_TEXT
| TVIF_IMAGE
| TVIF_SELECTEDIMAGE
| TVIF_PARAM
;
155 if (ulAttrs
& SFGAO_HASSUBFOLDER
)
157 tvi
.mask
|= TVIF_CHILDREN
;
160 if (!( lptvid
= (LPTV_ITEMDATA
)SHAlloc(sizeof(TV_ITEMDATA
))))
163 if (!GetName(lpsf
, pidlTemp
, SHGDN_NORMAL
, szBuff
))
166 tvi
.pszText
= szBuff
;
167 tvi
.cchTextMax
= MAX_PATH
;
168 tvi
.lParam
= (LPARAM
)lptvid
;
170 IShellFolder_AddRef(lpsf
);
171 lptvid
->lpsfParent
= lpsf
;
172 lptvid
->lpi
= ILClone(pidlTemp
);
173 lptvid
->lpifq
= ILCombine(pidl
, pidlTemp
);
174 GetNormalAndSelectedIcons(lptvid
->lpifq
, &tvi
);
176 tvins
.DUMMYUNIONNAME
.item
= tvi
;
177 tvins
.hInsertAfter
= hPrev
;
178 tvins
.hParent
= hParent
;
180 hPrev
= (HTREEITEM
)TreeView_InsertItemA (hwndTreeView
, &tvins
);
184 SHFree(pidlTemp
); /* Finally, free the pidl that the shell gave us... */
191 SetCursor(LoadCursorA(0, IDC_ARROWA
));
194 IEnumIDList_Release(lpe
);
199 static LRESULT
MsgNotify(HWND hWnd
, UINT CtlID
, LPNMHDR lpnmh
)
201 NMTREEVIEWA
*pnmtv
= (NMTREEVIEWA
*)lpnmh
;
202 LPTV_ITEMDATA lptvid
; /* Long pointer to TreeView item data */
203 IShellFolder
* lpsf2
=0;
206 TRACE("%x %x %p msg=%x\n", hWnd
, CtlID
, lpnmh
, pnmtv
->hdr
.code
);
208 switch (pnmtv
->hdr
.idFrom
)
210 switch (pnmtv
->hdr
.code
)
211 { case TVN_DELETEITEMA
: case TVN_DELETEITEMW
:
212 { FIXME("TVN_DELETEITEMA/W\n");
213 lptvid
=(LPTV_ITEMDATA
)pnmtv
->itemOld
.lParam
;
214 IShellFolder_Release(lptvid
->lpsfParent
);
216 SHFree(lptvid
->lpifq
);
221 case TVN_ITEMEXPANDINGA
: case TVN_ITEMEXPANDINGW
:
222 { FIXME("TVN_ITEMEXPANDINGA/W\n");
223 if ((pnmtv
->itemNew
.state
& TVIS_EXPANDEDONCE
))
226 lptvid
=(LPTV_ITEMDATA
)pnmtv
->itemNew
.lParam
;
227 if (SUCCEEDED(IShellFolder_BindToObject(lptvid
->lpsfParent
, lptvid
->lpi
,0,(REFIID
)&IID_IShellFolder
,(LPVOID
*)&lpsf2
)))
228 { FillTreeView( lpsf2
, lptvid
->lpifq
, pnmtv
->itemNew
.hItem
);
230 TreeView_SortChildren(hwndTreeView
, pnmtv
->itemNew
.hItem
, FALSE
);
233 case TVN_SELCHANGEDA
: case TVN_SELCHANGEDW
:
234 lptvid
=(LPTV_ITEMDATA
)pnmtv
->itemNew
.lParam
;
235 pidlRet
= lptvid
->lpifq
;
236 if (lpBrowseInfo
->lpfn
)
237 (lpBrowseInfo
->lpfn
)(hWnd
, BFFM_SELCHANGED
, (LPARAM
)pidlRet
, lpBrowseInfo
->lParam
);
241 FIXME("unhandled (%d)\n", pnmtv
->hdr
.code
);
254 /*************************************************************************
255 * BrsFolderDlgProc32 (not an exported API function)
257 static INT_PTR CALLBACK
BrsFolderDlgProc( HWND hWnd
, UINT msg
, WPARAM wParam
,
260 TRACE("hwnd=%08x msg=%04x 0x%08x 0x%08lx\n", hWnd
, msg
, wParam
, lParam
);
263 { case WM_INITDIALOG
:
265 lpBrowseInfo
= (LPBROWSEINFOA
) lParam
;
266 if (lpBrowseInfo
->ulFlags
& ~(BIF_STATUSTEXT
))
267 FIXME("flags %x not implemented\n", lpBrowseInfo
->ulFlags
& ~(BIF_STATUSTEXT
));
268 if (lpBrowseInfo
->lpszTitle
) {
269 SetWindowTextA(GetDlgItem(hWnd
, IDD_TITLE
), lpBrowseInfo
->lpszTitle
);
271 ShowWindow(GetDlgItem(hWnd
, IDD_TITLE
), SW_HIDE
);
273 if (!(lpBrowseInfo
->ulFlags
& BIF_STATUSTEXT
))
274 ShowWindow(GetDlgItem(hWnd
, IDD_STATUS
), SW_HIDE
);
276 if ( lpBrowseInfo
->pidlRoot
)
277 FIXME("root is desktop\n");
279 InitializeTreeView( hWnd
, lpBrowseInfo
->pidlRoot
);
281 if (lpBrowseInfo
->lpfn
) {
282 (lpBrowseInfo
->lpfn
)(hWnd
, BFFM_INITIALIZED
, 0, lpBrowseInfo
->lParam
);
283 (lpBrowseInfo
->lpfn
)(hWnd
, BFFM_SELCHANGED
, 0/*FIXME*/, lpBrowseInfo
->lParam
);
289 MsgNotify( hWnd
, (UINT
)wParam
, (LPNMHDR
)lParam
);
296 SHGetPathFromIDListA(pidlRet
, lpBrowseInfo
->pszDisplayName
);
297 EndDialog(hWnd
, (DWORD
) ILClone(pidlRet
));
305 case BFFM_SETSTATUSTEXTA
:
306 TRACE("Set status %s\n", debugstr_a((LPSTR
)lParam
));
307 SetWindowTextA(GetDlgItem(hWnd
, IDD_STATUS
), (LPSTR
)lParam
);
309 case BFFM_SETSTATUSTEXTW
:
310 TRACE("Set status %s\n", debugstr_w((LPWSTR
)lParam
));
311 SetWindowTextW(GetDlgItem(hWnd
, IDD_STATUS
), (LPWSTR
)lParam
);
314 TRACE("Enable %ld\n", lParam
);
315 EnableWindow(GetDlgItem(hWnd
, 1), (lParam
)?TRUE
:FALSE
);
317 case BFFM_SETSELECTIONA
:
319 TRACE("Set selection %s\n", debugstr_a((LPSTR
)lParam
));
321 TRACE("Set selection %p\n", (void*)lParam
);
323 case BFFM_SETSELECTIONW
:
325 TRACE("Set selection %s\n", debugstr_w((LPWSTR
)lParam
));
327 TRACE("Set selection %p\n", (void*)lParam
);
333 /*************************************************************************
334 * SHBrowseForFolderA [SHELL32.@]
335 * SHBrowseForFolder [SHELL32.@]
338 LPITEMIDLIST WINAPI
SHBrowseForFolderA (LPBROWSEINFOA lpbi
)
340 TRACE("(%p{lpszTitle=%s,owner=%i})\n",
341 lpbi
, debugstr_a(lpbi
->lpszTitle
), lpbi
->hwndOwner
);
343 return (LPITEMIDLIST
) DialogBoxParamA( shell32_hInstance
,
344 "SHBRSFORFOLDER_MSGBOX",
346 BrsFolderDlgProc
, (INT
)lpbi
);
349 /*************************************************************************
350 * SHBrowseForFolderW [SHELL32.@]
352 LPITEMIDLIST WINAPI
SHBrowseForFolderW (LPBROWSEINFOW lpbi
)
354 char szDisplayName
[MAX_PATH
], szTitle
[MAX_PATH
];
357 TRACE("((%p->{lpszTitle=%s,owner=%i})\n", lpbi
,
358 lpbi
? debugstr_w(lpbi
->lpszTitle
): NULL
, lpbi
? lpbi
->hwndOwner
: 0);
363 bi
.hwndOwner
= lpbi
->hwndOwner
;
364 bi
.pidlRoot
= lpbi
->pidlRoot
;
365 if (lpbi
->pszDisplayName
)
367 WideCharToMultiByte(CP_ACP
, 0, lpbi
->pszDisplayName
, -1, szDisplayName
, MAX_PATH
, 0, NULL
);
368 bi
.pszDisplayName
= szDisplayName
;
371 bi
.pszDisplayName
= NULL
;
375 WideCharToMultiByte(CP_ACP
, 0, lpbi
->lpszTitle
, -1, szTitle
, MAX_PATH
, 0, NULL
);
376 bi
.lpszTitle
= szTitle
;
381 bi
.ulFlags
= lpbi
->ulFlags
;
382 bi
.lpfn
= lpbi
->lpfn
;
383 bi
.lParam
= lpbi
->lParam
;
384 bi
.iImage
= lpbi
->iImage
;
385 return (LPITEMIDLIST
) DialogBoxParamA(shell32_hInstance
,
386 "SHBRSFORFOLDER_MSGBOX", lpbi
->hwndOwner
,
387 BrsFolderDlgProc
, (INT
)lpbi
);