2011-05-15 15:55:49 +00:00
|
|
|
/*
|
2024-05-19 01:00:20 +00:00
|
|
|
* PROJECT: ReactOS shell32
|
|
|
|
* LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
|
|
|
|
* PURPOSE: SHBrowseForFolderA/W functions
|
|
|
|
* COPYRIGHT: Copyright 1999 Juergen Schmied
|
|
|
|
* Copyright 2024 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2011-05-15 15:55:49 +00:00
|
|
|
* FIXME:
|
|
|
|
* - many memory leaks
|
|
|
|
* - many flags unimplemented
|
|
|
|
*/
|
|
|
|
|
2024-05-19 01:00:20 +00:00
|
|
|
#include "precomp.h"
|
2014-11-04 20:10:43 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
#include <ui/layout.h> // Resizable window
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(shell);
|
|
|
|
|
2020-03-18 20:57:10 +00:00
|
|
|
#define SHV_CHANGE_NOTIFY (WM_USER + 0x1111)
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
typedef struct tagbrowse_info
|
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
HWND hWnd;
|
|
|
|
HWND hwndTreeView;
|
|
|
|
LPBROWSEINFOW lpBrowseInfo;
|
|
|
|
LPITEMIDLIST pidlRet;
|
|
|
|
LAYOUT_DATA* layout; // Filled by LayoutInit, used by LayoutUpdate
|
|
|
|
SIZE szMin;
|
|
|
|
ULONG hNotify; // Change notification handle
|
2011-05-15 15:55:49 +00:00
|
|
|
} browse_info;
|
|
|
|
|
|
|
|
typedef struct tagTV_ITEMDATA
|
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
LPSHELLFOLDER lpsfParent; // IShellFolder of the parent
|
|
|
|
LPITEMIDLIST lpi; // PIDL relative to parent
|
|
|
|
LPITEMIDLIST lpifq; // Fully qualified PIDL
|
|
|
|
IEnumIDList *pEnumIL; // Children iterator
|
2011-05-15 15:55:49 +00:00
|
|
|
} TV_ITEMDATA, *LPTV_ITEMDATA;
|
|
|
|
|
2011-10-08 17:33:21 +00:00
|
|
|
static const LAYOUT_INFO g_layout_info[] =
|
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
{ IDC_BROWSE_FOR_FOLDER_TITLE, BF_TOP | BF_LEFT | BF_RIGHT },
|
|
|
|
{ IDC_BROWSE_FOR_FOLDER_STATUS, BF_TOP | BF_LEFT | BF_RIGHT },
|
|
|
|
{ IDC_BROWSE_FOR_FOLDER_TREEVIEW, BF_TOP | BF_BOTTOM | BF_LEFT | BF_RIGHT },
|
|
|
|
{ IDC_BROWSE_FOR_FOLDER_FOLDER_TEXT, BF_TOP | BF_LEFT | BF_RIGHT },
|
|
|
|
{ IDC_BROWSE_FOR_FOLDER_NEW_FOLDER, BF_BOTTOM | BF_LEFT },
|
|
|
|
{ IDOK, BF_BOTTOM | BF_RIGHT },
|
|
|
|
{ IDCANCEL, BF_BOTTOM | BF_RIGHT },
|
2011-10-08 17:33:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define LAYOUT_INFO_COUNT (sizeof(g_layout_info)/sizeof(g_layout_info[0]))
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
#define SUPPORTEDFLAGS (BIF_STATUSTEXT | BIF_BROWSEFORCOMPUTER | BIF_RETURNFSANCESTORS | \
|
|
|
|
BIF_RETURNONLYFSDIRS | BIF_NONEWFOLDERBUTTON | BIF_NEWDIALOGSTYLE | \
|
2011-05-15 15:55:49 +00:00
|
|
|
BIF_BROWSEINCLUDEFILES)
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static void
|
|
|
|
FillTreeView(browse_info*, LPSHELLFOLDER, LPITEMIDLIST, HTREEITEM, IEnumIDList*);
|
|
|
|
|
|
|
|
static HTREEITEM
|
|
|
|
InsertTreeViewItem(
|
|
|
|
browse_info *info,
|
|
|
|
IShellFolder *lpsf,
|
|
|
|
LPCITEMIDLIST pidl,
|
|
|
|
LPCITEMIDLIST pidlParent,
|
|
|
|
IEnumIDList *pEnumIL,
|
|
|
|
HTREEITEM hParent);
|
|
|
|
|
|
|
|
static inline DWORD
|
|
|
|
BrowseFlagsToSHCONTF(UINT ulFlags)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
return SHCONTF_FOLDERS | (ulFlags & BIF_BROWSEINCLUDEFILES ? SHCONTF_NONFOLDERS : 0);
|
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static void
|
|
|
|
browsefolder_callback(LPBROWSEINFOW lpBrowseInfo, HWND hWnd, UINT msg, LPARAM param)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2011-09-08 22:43:43 +00:00
|
|
|
if (!lpBrowseInfo->lpfn)
|
|
|
|
return;
|
2024-05-23 03:03:44 +00:00
|
|
|
lpBrowseInfo->lpfn(hWnd, msg, param, lpBrowseInfo->lParam);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
2024-05-18 11:42:22 +00:00
|
|
|
static LPTV_ITEMDATA
|
|
|
|
BrsFolder_GetDataFromItem(browse_info *info, HTREEITEM hItem)
|
2011-10-08 17:33:21 +00:00
|
|
|
{
|
2024-05-18 11:42:22 +00:00
|
|
|
TVITEMW item = { TVIF_HANDLE | TVIF_PARAM };
|
|
|
|
item.hItem = hItem;
|
|
|
|
if (!TreeView_GetItem(info->hwndTreeView, &item))
|
|
|
|
ERR("TreeView_GetItem failed\n");
|
|
|
|
return (LPTV_ITEMDATA)item.lParam;
|
2011-10-08 17:33:21 +00:00
|
|
|
}
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* InitializeTreeView [Internal]
|
|
|
|
*
|
|
|
|
* Called from WM_INITDIALOG handler.
|
2024-05-23 03:03:44 +00:00
|
|
|
*
|
2011-05-15 15:55:49 +00:00
|
|
|
* PARAMS
|
|
|
|
* hwndParent [I] The BrowseForFolder dialog
|
|
|
|
* root [I] ITEMIDLIST of the root shell folder
|
|
|
|
*/
|
2024-05-23 03:03:44 +00:00
|
|
|
static void
|
|
|
|
InitializeTreeView(browse_info *info)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
LPITEMIDLIST pidlParent, pidlChild;
|
|
|
|
HIMAGELIST hImageList;
|
|
|
|
HRESULT hr;
|
2014-11-04 20:10:43 +00:00
|
|
|
IShellFolder *lpsfParent, *lpsfRoot;
|
2024-05-23 03:03:44 +00:00
|
|
|
IEnumIDList *pEnumChildren = NULL;
|
2011-05-15 15:55:49 +00:00
|
|
|
HTREEITEM item;
|
|
|
|
DWORD flags;
|
|
|
|
LPCITEMIDLIST root = info->lpBrowseInfo->pidlRoot;
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
TRACE("%p\n", info);
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
Shell_GetImageLists(NULL, &hImageList);
|
|
|
|
|
|
|
|
if (hImageList)
|
2024-05-18 11:42:22 +00:00
|
|
|
TreeView_SetImageList(info->hwndTreeView, hImageList, 0);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
/* We want to call InsertTreeViewItem down the code, in order to insert
|
2024-05-23 03:03:44 +00:00
|
|
|
* the root item of the treeview. Due to InsertTreeViewItem's signature,
|
2011-05-15 15:55:49 +00:00
|
|
|
* we need the following to do this:
|
|
|
|
*
|
2024-05-23 03:03:44 +00:00
|
|
|
* + An ITEMIDLIST corresponding to _the parent_ of root.
|
|
|
|
* + An ITEMIDLIST, which is a relative path from root's parent to root
|
2011-05-15 15:55:49 +00:00
|
|
|
* (containing a single SHITEMID).
|
|
|
|
* + An IShellFolder interface pointer of root's parent folder.
|
|
|
|
*
|
|
|
|
* If root is 'Desktop', then root's parent is also 'Desktop'.
|
|
|
|
*/
|
|
|
|
|
|
|
|
pidlParent = ILClone(root);
|
|
|
|
ILRemoveLastID(pidlParent);
|
|
|
|
pidlChild = ILClone(ILFindLastID(root));
|
2024-05-23 03:03:44 +00:00
|
|
|
|
|
|
|
if (_ILIsDesktop(pidlParent))
|
|
|
|
{
|
2011-05-15 15:55:49 +00:00
|
|
|
hr = SHGetDesktopFolder(&lpsfParent);
|
2024-05-23 03:03:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-04 20:10:43 +00:00
|
|
|
IShellFolder *lpsfDesktop;
|
2011-05-15 15:55:49 +00:00
|
|
|
hr = SHGetDesktopFolder(&lpsfDesktop);
|
2024-05-23 03:03:44 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2011-05-15 15:55:49 +00:00
|
|
|
WARN("SHGetDesktopFolder failed! hr = %08x\n", hr);
|
2011-10-08 17:33:21 +00:00
|
|
|
ILFree(pidlChild);
|
|
|
|
ILFree(pidlParent);
|
2011-05-15 15:55:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-05-23 03:03:44 +00:00
|
|
|
hr = lpsfDesktop->BindToObject(pidlParent, NULL, IID_PPV_ARG(IShellFolder, &lpsfParent));
|
2024-05-19 01:00:20 +00:00
|
|
|
lpsfDesktop->Release();
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2011-05-15 15:55:49 +00:00
|
|
|
WARN("Could not bind to parent shell folder! hr = %08x\n", hr);
|
2011-10-08 17:33:21 +00:00
|
|
|
ILFree(pidlChild);
|
|
|
|
ILFree(pidlParent);
|
2011-05-15 15:55:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
if (!_ILIsEmpty(pidlChild))
|
|
|
|
{
|
|
|
|
hr = lpsfParent->BindToObject(pidlChild, NULL, IID_PPV_ARG(IShellFolder, &lpsfRoot));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-15 15:55:49 +00:00
|
|
|
lpsfRoot = lpsfParent;
|
2024-05-19 01:00:20 +00:00
|
|
|
hr = lpsfParent->AddRef();
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2011-05-15 15:55:49 +00:00
|
|
|
WARN("Could not bind to root shell folder! hr = %08x\n", hr);
|
2024-05-19 01:00:20 +00:00
|
|
|
lpsfParent->Release();
|
2011-10-08 17:33:21 +00:00
|
|
|
ILFree(pidlChild);
|
|
|
|
ILFree(pidlParent);
|
2011-05-15 15:55:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
flags = BrowseFlagsToSHCONTF(info->lpBrowseInfo->ulFlags);
|
|
|
|
hr = lpsfRoot->EnumObjects(info->hWnd, flags, &pEnumChildren);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2011-05-15 15:55:49 +00:00
|
|
|
WARN("Could not get child iterator! hr = %08x\n", hr);
|
2024-05-19 01:00:20 +00:00
|
|
|
lpsfParent->Release();
|
|
|
|
lpsfRoot->Release();
|
2011-10-08 17:33:21 +00:00
|
|
|
ILFree(pidlChild);
|
|
|
|
ILFree(pidlParent);
|
2011-05-15 15:55:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-05-18 11:42:22 +00:00
|
|
|
TreeView_DeleteItem(info->hwndTreeView, TVI_ROOT);
|
2024-05-23 03:03:44 +00:00
|
|
|
item = InsertTreeViewItem(info, lpsfParent, pidlChild,
|
|
|
|
pidlParent, pEnumChildren, TVI_ROOT);
|
2024-05-18 11:42:22 +00:00
|
|
|
TreeView_Expand(info->hwndTreeView, item, TVE_EXPAND);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-10-08 17:33:21 +00:00
|
|
|
ILFree(pidlChild);
|
|
|
|
ILFree(pidlParent);
|
2024-05-19 01:00:20 +00:00
|
|
|
lpsfRoot->Release();
|
|
|
|
lpsfParent->Release();
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static int
|
|
|
|
GetIcon(LPCITEMIDLIST lpi, UINT uFlags)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
SHFILEINFOW sfi;
|
2024-05-23 03:03:44 +00:00
|
|
|
SHGetFileInfoW((LPCWSTR)lpi, 0, &sfi, sizeof(SHFILEINFOW), uFlags);
|
2011-05-15 15:55:49 +00:00
|
|
|
return sfi.iIcon;
|
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static void
|
|
|
|
GetNormalAndSelectedIcons(LPITEMIDLIST lpifq, LPTVITEMW lpTV_ITEM)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
LPITEMIDLIST pidlDesktop = NULL;
|
|
|
|
DWORD flags;
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
TRACE("%p %p\n", lpifq, lpTV_ITEM);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
if (!lpifq)
|
|
|
|
{
|
|
|
|
pidlDesktop = _ILCreateDesktop();
|
|
|
|
lpifq = pidlDesktop;
|
|
|
|
}
|
|
|
|
|
|
|
|
flags = SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON;
|
2024-05-23 03:03:44 +00:00
|
|
|
lpTV_ITEM->iImage = GetIcon(lpifq, flags);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
flags = SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_OPENICON;
|
2024-05-23 03:03:44 +00:00
|
|
|
lpTV_ITEM->iSelectedImage = GetIcon(lpifq, flags);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
if (pidlDesktop)
|
2024-05-23 03:03:44 +00:00
|
|
|
ILFree(pidlDesktop);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* GetName [Internal]
|
|
|
|
*
|
2014-11-05 17:04:42 +00:00
|
|
|
* Query a shell folder for the display name of one of its children
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpsf [I] IShellFolder interface of the folder to be queried.
|
|
|
|
* lpi [I] ITEMIDLIST of the child, relative to parent
|
|
|
|
* dwFlags [I] as in IShellFolder::GetDisplayNameOf
|
|
|
|
* lpFriendlyName [O] The desired display name in unicode
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
2024-05-23 03:03:44 +00:00
|
|
|
static BOOL
|
|
|
|
GetName(
|
|
|
|
LPSHELLFOLDER lpsf,
|
|
|
|
LPCITEMIDLIST lpi,
|
|
|
|
DWORD dwFlags,
|
|
|
|
LPWSTR lpFriendlyName)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
BOOL bSuccess = TRUE;
|
|
|
|
STRRET str;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
TRACE("%p %p %x %p\n", lpsf, lpi, dwFlags, lpFriendlyName);
|
|
|
|
if (SUCCEEDED(lpsf->GetDisplayNameOf(lpi, dwFlags, &str)))
|
|
|
|
bSuccess = StrRetToStrNW(lpFriendlyName, MAX_PATH, &str, lpi);
|
|
|
|
else
|
|
|
|
bSuccess = FALSE;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
TRACE("-- %s\n", debugstr_w(lpFriendlyName));
|
|
|
|
return bSuccess;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* InsertTreeViewItem [Internal]
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* info [I] data for the dialog
|
2024-05-23 03:03:44 +00:00
|
|
|
* lpsf [I] IShellFolder interface of the item's parent shell folder
|
2011-05-15 15:55:49 +00:00
|
|
|
* pidl [I] ITEMIDLIST of the child to insert, relative to parent
|
|
|
|
* pidlParent [I] ITEMIDLIST of the parent shell folder
|
|
|
|
* pEnumIL [I] Iterator for the children of the item to be inserted
|
|
|
|
* hParent [I] The treeview-item that represents the parent shell folder
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Handle to the created and inserted treeview-item
|
|
|
|
* Failure: NULL
|
|
|
|
*/
|
2024-05-23 03:03:44 +00:00
|
|
|
static HTREEITEM
|
|
|
|
InsertTreeViewItem(
|
|
|
|
browse_info *info,
|
|
|
|
IShellFolder *lpsf,
|
|
|
|
LPCITEMIDLIST pidl,
|
|
|
|
LPCITEMIDLIST pidlParent,
|
|
|
|
IEnumIDList *pEnumIL,
|
2011-05-15 15:55:49 +00:00
|
|
|
HTREEITEM hParent)
|
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
TVITEMW tvi;
|
|
|
|
TVINSERTSTRUCTW tvins;
|
|
|
|
WCHAR szBuff[MAX_PATH];
|
|
|
|
LPTV_ITEMDATA lptvid = NULL;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
tvi.cChildren= pEnumIL ? 1 : 0;
|
|
|
|
tvi.mask |= TVIF_CHILDREN;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
if (!GetName(lpsf, pidl, SHGDN_NORMAL, szBuff))
|
|
|
|
return NULL;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
lptvid = (LPTV_ITEMDATA)SHAlloc(sizeof(TV_ITEMDATA));
|
|
|
|
if (!lptvid)
|
|
|
|
return NULL;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
tvi.pszText = szBuff;
|
|
|
|
tvi.cchTextMax = MAX_PATH;
|
|
|
|
tvi.lParam = (LPARAM)lptvid;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
lpsf->AddRef();
|
|
|
|
lptvid->lpsfParent = lpsf;
|
|
|
|
lptvid->lpi = ILClone(pidl);
|
|
|
|
lptvid->lpifq = pidlParent ? ILCombine(pidlParent, pidl) : ILClone(pidl);
|
|
|
|
lptvid->pEnumIL = pEnumIL;
|
|
|
|
GetNormalAndSelectedIcons(lptvid->lpifq, &tvi);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
tvins.item = tvi;
|
|
|
|
tvins.hInsertAfter = NULL;
|
|
|
|
tvins.hParent = hParent;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
return TreeView_InsertItem(info->hwndTreeView, &tvins);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* FillTreeView [Internal]
|
|
|
|
*
|
2024-05-23 03:03:44 +00:00
|
|
|
* For each child (given by lpe) of the parent shell folder, which is given by
|
2011-05-15 15:55:49 +00:00
|
|
|
* lpsf and whose PIDL is pidl, insert a treeview-item right under hParent
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* info [I] data for the dialog
|
|
|
|
* lpsf [I] IShellFolder interface of the parent shell folder
|
|
|
|
* pidl [I] ITEMIDLIST of the parent shell folder
|
|
|
|
* hParent [I] The treeview item that represents the parent shell folder
|
|
|
|
* lpe [I] An iterator for the children of the parent shell folder
|
|
|
|
*/
|
2024-05-23 03:03:44 +00:00
|
|
|
static void
|
|
|
|
FillTreeView(
|
|
|
|
browse_info *info,
|
|
|
|
IShellFolder *lpsf,
|
|
|
|
LPITEMIDLIST pidl,
|
|
|
|
HTREEITEM hParent,
|
|
|
|
IEnumIDList *lpe)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
LPITEMIDLIST pidlTemp = 0;
|
|
|
|
ULONG ulFetched;
|
|
|
|
HRESULT hr;
|
|
|
|
HWND hwnd = GetParent(info->hwndTreeView);
|
|
|
|
|
|
|
|
TRACE("%p %p %p %p\n", lpsf, pidl, hParent, lpe);
|
|
|
|
|
|
|
|
// No IEnumIDList -> No children
|
|
|
|
if (!lpe)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SetCapture(hwnd);
|
|
|
|
SetCursor(LoadCursorA(NULL, (LPSTR)IDC_WAIT));
|
|
|
|
|
|
|
|
while (S_OK == lpe->Next(1, &pidlTemp, &ulFetched))
|
|
|
|
{
|
|
|
|
ULONG ulAttrs = SFGAO_HASSUBFOLDER | SFGAO_FOLDER;
|
|
|
|
IEnumIDList *pEnumIL = NULL;
|
|
|
|
IShellFolder *pSFChild = NULL;
|
|
|
|
lpsf->GetAttributesOf(1, (LPCITEMIDLIST *)&pidlTemp, &ulAttrs);
|
|
|
|
if (ulAttrs & SFGAO_FOLDER)
|
|
|
|
{
|
|
|
|
hr = lpsf->BindToObject(pidlTemp, NULL, IID_PPV_ARG(IShellFolder, &pSFChild));
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
DWORD flags = BrowseFlagsToSHCONTF(info->lpBrowseInfo->ulFlags);
|
|
|
|
hr = pSFChild->EnumObjects(hwnd, flags, &pEnumIL);
|
|
|
|
if (hr == S_OK)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
if ((pEnumIL->Skip(1) != S_OK) ||
|
|
|
|
FAILED(pEnumIL->Reset()))
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
pEnumIL->Release();
|
|
|
|
pEnumIL = NULL;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-23 03:03:44 +00:00
|
|
|
pSFChild->Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-27 15:00:46 +00:00
|
|
|
if (ulAttrs != (ulAttrs & SFGAO_FOLDER))
|
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
if (!InsertTreeViewItem(info, lpsf, pidlTemp, pidl, pEnumIL, hParent))
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
SHFree(pidlTemp); // Finally, free the pidl that the shell gave us...
|
|
|
|
pidlTemp = NULL;
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
done:
|
2024-05-23 03:03:44 +00:00
|
|
|
ReleaseCapture();
|
|
|
|
SetCursor(LoadCursorW(NULL, (LPWSTR)IDC_ARROW));
|
2011-05-15 15:55:49 +00:00
|
|
|
SHFree(pidlTemp);
|
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static inline BOOL
|
|
|
|
PIDLIsType(LPCITEMIDLIST pidl, PIDLTYPE type)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
LPPIDLDATA data = _ILGetDataPointer(pidl);
|
|
|
|
if (!data)
|
|
|
|
return FALSE;
|
|
|
|
return (data->type == type);
|
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static void
|
|
|
|
BrsFolder_CheckValidSelection(browse_info *info, LPTV_ITEMDATA lptvid)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
LPBROWSEINFOW lpBrowseInfo = info->lpBrowseInfo;
|
|
|
|
LPCITEMIDLIST pidl = lptvid->lpi;
|
|
|
|
BOOL bEnabled = TRUE;
|
|
|
|
DWORD dwAttributes;
|
|
|
|
HRESULT r;
|
|
|
|
|
|
|
|
if ((lpBrowseInfo->ulFlags & BIF_BROWSEFORCOMPUTER) &&
|
|
|
|
!PIDLIsType(pidl, PT_COMP))
|
|
|
|
bEnabled = FALSE;
|
|
|
|
if (lpBrowseInfo->ulFlags & BIF_RETURNFSANCESTORS)
|
|
|
|
{
|
|
|
|
dwAttributes = SFGAO_FILESYSANCESTOR | SFGAO_FILESYSTEM;
|
2024-05-23 03:03:44 +00:00
|
|
|
r = lptvid->lpsfParent->GetAttributesOf(1, (LPCITEMIDLIST *)&lptvid->lpi, &dwAttributes);
|
|
|
|
if (FAILED(r) || !(dwAttributes & (SFGAO_FILESYSANCESTOR | SFGAO_FILESYSTEM)))
|
2011-05-15 15:55:49 +00:00
|
|
|
bEnabled = FALSE;
|
|
|
|
}
|
2011-10-08 17:33:21 +00:00
|
|
|
|
|
|
|
dwAttributes = SFGAO_FOLDER | SFGAO_FILESYSTEM;
|
2024-05-23 03:03:44 +00:00
|
|
|
r = lptvid->lpsfParent->GetAttributesOf(1, (LPCITEMIDLIST *)&lptvid->lpi, &dwAttributes);
|
2011-10-08 17:33:21 +00:00
|
|
|
if (FAILED(r) ||
|
2024-05-23 03:03:44 +00:00
|
|
|
((dwAttributes & (SFGAO_FOLDER | SFGAO_FILESYSTEM)) != (SFGAO_FOLDER | SFGAO_FILESYSTEM)))
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2011-10-08 17:33:21 +00:00
|
|
|
if (lpBrowseInfo->ulFlags & BIF_RETURNONLYFSDIRS)
|
2011-05-15 15:55:49 +00:00
|
|
|
bEnabled = FALSE;
|
2012-01-17 21:28:17 +00:00
|
|
|
EnableWindow(GetDlgItem(info->hWnd, IDC_BROWSE_FOR_FOLDER_NEW_FOLDER), FALSE);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
2011-10-08 17:33:21 +00:00
|
|
|
else
|
2024-05-23 03:03:44 +00:00
|
|
|
{
|
2012-01-17 21:28:17 +00:00
|
|
|
EnableWindow(GetDlgItem(info->hWnd, IDC_BROWSE_FOR_FOLDER_NEW_FOLDER), TRUE);
|
2024-05-23 03:03:44 +00:00
|
|
|
}
|
2011-10-08 17:33:21 +00:00
|
|
|
|
|
|
|
SendMessageW(info->hWnd, BFFM_ENABLEOK, 0, bEnabled);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static LRESULT
|
|
|
|
BrsFolder_Treeview_Delete(browse_info *info, NMTREEVIEWW *pnmtv)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
LPTV_ITEMDATA lptvid = (LPTV_ITEMDATA)pnmtv->itemOld.lParam;
|
|
|
|
|
|
|
|
TRACE("TVN_DELETEITEMA/W %p\n", lptvid);
|
|
|
|
|
2024-05-19 01:00:20 +00:00
|
|
|
lptvid->lpsfParent->Release();
|
2011-05-15 15:55:49 +00:00
|
|
|
if (lptvid->pEnumIL)
|
2024-05-19 01:00:20 +00:00
|
|
|
lptvid->pEnumIL->Release();
|
2011-05-15 15:55:49 +00:00
|
|
|
SHFree(lptvid->lpi);
|
|
|
|
SHFree(lptvid->lpifq);
|
|
|
|
SHFree(lptvid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static LRESULT
|
|
|
|
BrsFolder_Treeview_Expand(browse_info *info, NMTREEVIEWW *pnmtv)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2014-11-04 20:13:22 +00:00
|
|
|
IShellFolder *lpsf2 = NULL;
|
2024-05-23 03:03:44 +00:00
|
|
|
LPTV_ITEMDATA lptvid = (LPTV_ITEMDATA)pnmtv->itemNew.lParam;
|
2011-05-15 15:55:49 +00:00
|
|
|
HRESULT r;
|
|
|
|
|
|
|
|
TRACE("TVN_ITEMEXPANDINGA/W\n");
|
|
|
|
|
|
|
|
if ((pnmtv->itemNew.state & TVIS_EXPANDEDONCE))
|
|
|
|
return 0;
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
if (!_ILIsEmpty(lptvid->lpi))
|
|
|
|
{
|
|
|
|
r = lptvid->lpsfParent->BindToObject(lptvid->lpi, NULL, IID_PPV_ARG(IShellFolder, &lpsf2));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-15 15:55:49 +00:00
|
|
|
lpsf2 = lptvid->lpsfParent;
|
2024-05-19 01:00:20 +00:00
|
|
|
lpsf2->AddRef();
|
2014-11-06 19:14:58 +00:00
|
|
|
r = S_OK;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(r))
|
2011-10-08 17:33:21 +00:00
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
FillTreeView(info, lpsf2, lptvid->lpifq, pnmtv->itemNew.hItem, lptvid->pEnumIL);
|
2024-05-19 01:00:20 +00:00
|
|
|
lpsf2->Release();
|
2011-10-08 17:33:21 +00:00
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
// My Computer is already sorted and trying to do a simple text
|
|
|
|
// sort will only mess things up
|
2011-05-15 15:55:49 +00:00
|
|
|
if (!_ILIsMyComputer(lptvid->lpi))
|
2024-05-18 11:42:22 +00:00
|
|
|
TreeView_SortChildren(info->hwndTreeView, pnmtv->itemNew.hItem, FALSE);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static HRESULT
|
|
|
|
BrsFolder_Treeview_Changed(browse_info *info, NMTREEVIEWW *pnmtv)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
LPTV_ITEMDATA lptvid = (LPTV_ITEMDATA) pnmtv->itemNew.lParam;
|
2011-10-08 17:33:21 +00:00
|
|
|
WCHAR name[MAX_PATH];
|
|
|
|
|
|
|
|
ILFree(info->pidlRet);
|
|
|
|
info->pidlRet = ILClone(lptvid->lpifq);
|
|
|
|
|
|
|
|
if (GetName(lptvid->lpsfParent, lptvid->lpi, SHGDN_NORMAL, name))
|
2024-05-23 03:03:44 +00:00
|
|
|
SetWindowTextW(GetDlgItem(info->hWnd, IDC_BROWSE_FOR_FOLDER_FOLDER_TEXT), name);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
browsefolder_callback(info->lpBrowseInfo, info->hWnd, BFFM_SELCHANGED,
|
|
|
|
(LPARAM)info->pidlRet);
|
|
|
|
BrsFolder_CheckValidSelection(info, lptvid);
|
2014-11-04 20:13:22 +00:00
|
|
|
return S_OK;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static LRESULT
|
|
|
|
BrsFolder_Treeview_Rename(browse_info *info, NMTVDISPINFOW *pnmtv)
|
2011-10-08 17:33:21 +00:00
|
|
|
{
|
|
|
|
LPTV_ITEMDATA item_data;
|
|
|
|
WCHAR old_path[MAX_PATH], new_path[MAX_PATH], *p;
|
|
|
|
NMTREEVIEWW nmtv;
|
|
|
|
TVITEMW item;
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
if (!pnmtv->item.pszText)
|
2011-10-08 17:33:21 +00:00
|
|
|
return 0;
|
|
|
|
|
2024-05-18 11:42:22 +00:00
|
|
|
item.hItem = TreeView_GetSelection(info->hwndTreeView);
|
|
|
|
item_data = BrsFolder_GetDataFromItem(info, item.hItem);
|
2011-10-08 17:33:21 +00:00
|
|
|
|
|
|
|
SHGetPathFromIDListW(item_data->lpifq, old_path);
|
2024-05-23 03:03:44 +00:00
|
|
|
if (!(p = strrchrW(old_path, '\\')))
|
2011-10-08 17:33:21 +00:00
|
|
|
return 0;
|
2024-05-23 03:03:44 +00:00
|
|
|
p = new_path + (p - old_path + 1);
|
|
|
|
memcpy(new_path, old_path, (p-new_path) * sizeof(WCHAR));
|
2011-10-08 17:33:21 +00:00
|
|
|
strcpyW(p, pnmtv->item.pszText);
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
if (!MoveFileW(old_path, new_path))
|
2011-10-08 17:33:21 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
SHFree(item_data->lpifq);
|
|
|
|
SHFree(item_data->lpi);
|
|
|
|
item_data->lpifq = SHSimpleIDListFromPathW(new_path);
|
2024-05-23 03:03:44 +00:00
|
|
|
item_data->lpsfParent->ParseDisplayName(NULL, NULL, pnmtv->item.pszText, NULL,
|
|
|
|
&item_data->lpi, NULL);
|
2011-10-08 17:33:21 +00:00
|
|
|
|
2024-05-18 11:42:22 +00:00
|
|
|
item.mask = TVIF_HANDLE | TVIF_TEXT;
|
2011-10-08 17:33:21 +00:00
|
|
|
item.pszText = pnmtv->item.pszText;
|
2024-05-18 11:42:22 +00:00
|
|
|
TreeView_SetItem(info->hwndTreeView, &item);
|
2011-10-08 17:33:21 +00:00
|
|
|
|
|
|
|
nmtv.itemNew.lParam = item.lParam;
|
|
|
|
BrsFolder_Treeview_Changed(info, &nmtv);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static HRESULT
|
|
|
|
BrsFolder_Rename(browse_info *info, HTREEITEM hItem)
|
2020-03-18 20:57:10 +00:00
|
|
|
{
|
2024-05-18 11:42:22 +00:00
|
|
|
TreeView_SelectItem(info->hwndTreeView, hItem);
|
|
|
|
TreeView_EditLabel(info->hwndTreeView, hItem);
|
2020-03-18 20:57:10 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-04-26 13:06:19 +00:00
|
|
|
static void
|
|
|
|
BrsFolder_Delete(browse_info *info, HTREEITEM selected_item)
|
|
|
|
{
|
|
|
|
TV_ITEMDATA *item_data;
|
|
|
|
SHFILEOPSTRUCTW fileop = { info->hwndTreeView };
|
|
|
|
WCHAR szzFrom[MAX_PATH + 1];
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
// Get item_data
|
2024-05-18 11:42:22 +00:00
|
|
|
item_data = BrsFolder_GetDataFromItem(info, selected_item);
|
2020-04-26 13:06:19 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
// Get the path
|
2020-04-26 13:06:19 +00:00
|
|
|
if (!SHGetPathFromIDListW(item_data->lpifq, szzFrom))
|
|
|
|
{
|
|
|
|
ERR("SHGetPathFromIDListW failed\n");
|
|
|
|
return;
|
|
|
|
}
|
2024-05-23 03:03:44 +00:00
|
|
|
szzFrom[lstrlenW(szzFrom) + 1] = UNICODE_NULL; // Double NULL-terminated
|
2020-04-26 13:06:19 +00:00
|
|
|
fileop.pFrom = szzFrom;
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
// Delete folder
|
2020-04-26 13:06:19 +00:00
|
|
|
fileop.fFlags = FOF_ALLOWUNDO;
|
|
|
|
fileop.wFunc = FO_DELETE;
|
|
|
|
SHFileOperationW(&fileop);
|
|
|
|
}
|
2024-05-18 11:42:22 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static LRESULT
|
|
|
|
BrsFolder_Treeview_Keydown(browse_info *info, LPNMTVKEYDOWN keydown)
|
2020-03-18 20:57:10 +00:00
|
|
|
{
|
|
|
|
HTREEITEM selected_item;
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
// Old dialog doesn't support those advanced features
|
2021-03-14 09:35:40 +00:00
|
|
|
if (!(info->lpBrowseInfo->ulFlags & BIF_USENEWUI))
|
2020-03-18 20:57:10 +00:00
|
|
|
return 0;
|
|
|
|
|
2024-05-18 11:42:22 +00:00
|
|
|
selected_item = TreeView_GetSelection(info->hwndTreeView);
|
2020-03-18 20:57:10 +00:00
|
|
|
|
|
|
|
switch (keydown->wVKey)
|
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
case VK_F2:
|
|
|
|
BrsFolder_Rename(info, selected_item);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VK_DELETE:
|
|
|
|
BrsFolder_Delete(info, selected_item);
|
|
|
|
break;
|
2020-03-18 20:57:10 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static LRESULT
|
|
|
|
BrsFolder_OnNotify(browse_info *info, UINT CtlID, LPNMHDR lpnmh)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
NMTREEVIEWW *pnmtv = (NMTREEVIEWW *)lpnmh;
|
|
|
|
|
|
|
|
TRACE("%p %x %p msg=%x\n", info, CtlID, lpnmh, pnmtv->hdr.code);
|
|
|
|
|
2012-01-17 21:28:17 +00:00
|
|
|
if (pnmtv->hdr.idFrom != IDC_BROWSE_FOR_FOLDER_TREEVIEW)
|
2011-05-15 15:55:49 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (pnmtv->hdr.code)
|
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
case TVN_DELETEITEMA:
|
|
|
|
case TVN_DELETEITEMW:
|
|
|
|
return BrsFolder_Treeview_Delete(info, pnmtv);
|
|
|
|
|
|
|
|
case TVN_ITEMEXPANDINGA:
|
|
|
|
case TVN_ITEMEXPANDINGW:
|
|
|
|
return BrsFolder_Treeview_Expand(info, pnmtv);
|
|
|
|
|
|
|
|
case TVN_SELCHANGEDA:
|
|
|
|
case TVN_SELCHANGEDW:
|
|
|
|
return BrsFolder_Treeview_Changed(info, pnmtv);
|
|
|
|
|
|
|
|
case TVN_ENDLABELEDITA:
|
|
|
|
case TVN_ENDLABELEDITW:
|
|
|
|
return BrsFolder_Treeview_Rename(info, (LPNMTVDISPINFOW)pnmtv);
|
|
|
|
|
|
|
|
case TVN_KEYDOWN:
|
|
|
|
return BrsFolder_Treeview_Keydown(info, (LPNMTVKEYDOWN)pnmtv);
|
|
|
|
|
|
|
|
default:
|
|
|
|
WARN("unhandled (%d)\n", pnmtv->hdr.code);
|
|
|
|
break;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static BOOL
|
|
|
|
BrsFolder_OnCreate(HWND hWnd, browse_info *info)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2020-03-18 20:57:10 +00:00
|
|
|
LPITEMIDLIST computer_pidl;
|
|
|
|
SHChangeNotifyEntry ntreg;
|
2011-05-15 15:55:49 +00:00
|
|
|
LPBROWSEINFOW lpBrowseInfo = info->lpBrowseInfo;
|
|
|
|
|
|
|
|
info->hWnd = hWnd;
|
2024-05-23 03:03:44 +00:00
|
|
|
SetPropW(hWnd, L"__WINE_BRSFOLDERDLG_INFO", info);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
if (lpBrowseInfo->ulFlags & BIF_NEWDIALOGSTYLE)
|
|
|
|
FIXME("flags BIF_NEWDIALOGSTYLE partially implemented\n");
|
|
|
|
if (lpBrowseInfo->ulFlags & ~SUPPORTEDFLAGS)
|
2024-05-23 03:03:44 +00:00
|
|
|
FIXME("flags %x not implemented\n", lpBrowseInfo->ulFlags & ~SUPPORTEDFLAGS);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2021-03-14 09:35:40 +00:00
|
|
|
if (lpBrowseInfo->ulFlags & BIF_USENEWUI)
|
2011-10-08 17:33:21 +00:00
|
|
|
{
|
|
|
|
RECT rcWnd;
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
// Resize the treeview if there's not editbox
|
|
|
|
if ((lpBrowseInfo->ulFlags & BIF_NEWDIALOGSTYLE) &&
|
|
|
|
!(lpBrowseInfo->ulFlags & BIF_EDITBOX))
|
2021-03-14 22:13:03 +00:00
|
|
|
{
|
|
|
|
RECT rcEdit, rcTreeView;
|
|
|
|
INT cy;
|
|
|
|
GetWindowRect(GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_FOLDER_TEXT), &rcEdit);
|
|
|
|
GetWindowRect(GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_TREEVIEW), &rcTreeView);
|
|
|
|
cy = rcTreeView.top - rcEdit.top;
|
|
|
|
MapWindowPoints(NULL, hWnd, (LPPOINT)&rcTreeView, sizeof(RECT) / sizeof(POINT));
|
|
|
|
rcTreeView.top -= cy;
|
|
|
|
MoveWindow(GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_TREEVIEW),
|
|
|
|
rcTreeView.left, rcTreeView.top,
|
|
|
|
rcTreeView.right - rcTreeView.left,
|
|
|
|
rcTreeView.bottom - rcTreeView.top, TRUE);
|
|
|
|
}
|
2024-05-23 03:03:44 +00:00
|
|
|
|
2021-03-14 09:35:40 +00:00
|
|
|
if (lpBrowseInfo->ulFlags & BIF_NEWDIALOGSTYLE)
|
|
|
|
info->layout = LayoutInit(hWnd, g_layout_info, LAYOUT_INFO_COUNT);
|
|
|
|
else
|
|
|
|
info->layout = NULL;
|
2011-10-08 17:33:21 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
// TODO: Windows allows shrinking the windows a bit
|
2011-10-08 17:33:21 +00:00
|
|
|
GetWindowRect(hWnd, &rcWnd);
|
|
|
|
info->szMin.cx = rcWnd.right - rcWnd.left;
|
|
|
|
info->szMin.cy = rcWnd.bottom - rcWnd.top;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info->layout = NULL;
|
|
|
|
}
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
if (lpBrowseInfo->lpszTitle)
|
2024-05-23 03:03:44 +00:00
|
|
|
SetWindowTextW(GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_TITLE), lpBrowseInfo->lpszTitle);
|
2011-05-15 15:55:49 +00:00
|
|
|
else
|
2024-05-23 03:03:44 +00:00
|
|
|
ShowWindow(GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_TITLE), SW_HIDE);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
if (!(lpBrowseInfo->ulFlags & BIF_STATUSTEXT) ||
|
|
|
|
(lpBrowseInfo->ulFlags & BIF_USENEWUI))
|
|
|
|
{
|
|
|
|
ShowWindow(GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_STATUS), SW_HIDE);
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
// Hide "Make New Folder" Button?
|
|
|
|
if ((lpBrowseInfo->ulFlags & BIF_NONEWFOLDERBUTTON) ||
|
|
|
|
!(lpBrowseInfo->ulFlags & BIF_NEWDIALOGSTYLE))
|
|
|
|
{
|
|
|
|
ShowWindow(GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_NEW_FOLDER), SW_HIDE);
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
// Hide the editbox?
|
2011-05-15 15:55:49 +00:00
|
|
|
if (!(lpBrowseInfo->ulFlags & BIF_EDITBOX))
|
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
ShowWindow(GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_FOLDER), SW_HIDE);
|
|
|
|
ShowWindow(GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_FOLDER_TEXT), SW_HIDE);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
info->hwndTreeView = GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_TREEVIEW);
|
2011-05-15 15:55:49 +00:00
|
|
|
if (info->hwndTreeView)
|
2024-05-23 03:03:44 +00:00
|
|
|
InitializeTreeView(info);
|
2011-05-15 15:55:49 +00:00
|
|
|
else
|
|
|
|
ERR("treeview control missing!\n");
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
// Register for change notifications
|
2020-03-18 20:57:10 +00:00
|
|
|
SHGetFolderLocation(NULL, CSIDL_DESKTOP, NULL, 0, &computer_pidl);
|
|
|
|
|
|
|
|
ntreg.pidl = computer_pidl;
|
|
|
|
ntreg.fRecursive = TRUE;
|
|
|
|
|
|
|
|
info->hNotify = SHChangeNotifyRegister(hWnd, SHCNRF_InterruptLevel, SHCNE_ALLEVENTS, SHV_CHANGE_NOTIFY, 1, &ntreg);
|
|
|
|
|
2021-03-14 22:13:03 +00:00
|
|
|
SetFocus(info->hwndTreeView);
|
2024-05-23 03:03:44 +00:00
|
|
|
browsefolder_callback(info->lpBrowseInfo, hWnd, BFFM_INITIALIZED, 0);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2021-03-15 07:30:32 +00:00
|
|
|
SHAutoComplete(GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_FOLDER_TEXT),
|
|
|
|
(SHACF_FILESYS_ONLY | SHACF_URLHISTORY | SHACF_FILESYSTEM));
|
|
|
|
return TRUE;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static HRESULT
|
|
|
|
BrsFolder_NewFolder(browse_info *info)
|
2011-10-08 17:33:21 +00:00
|
|
|
{
|
|
|
|
DWORD flags = BrowseFlagsToSHCONTF(info->lpBrowseInfo->ulFlags);
|
2014-11-04 20:10:43 +00:00
|
|
|
IShellFolder *desktop, *cur;
|
2015-09-02 13:14:46 +00:00
|
|
|
WCHAR wszNewFolder[25];
|
2017-11-03 10:09:30 +00:00
|
|
|
WCHAR path[MAX_PATH];
|
2011-10-08 17:33:21 +00:00
|
|
|
WCHAR name[MAX_PATH];
|
2024-05-18 11:42:22 +00:00
|
|
|
HTREEITEM hParent, hAdded;
|
2011-10-08 17:33:21 +00:00
|
|
|
LPTV_ITEMDATA item_data;
|
|
|
|
LPITEMIDLIST new_item;
|
|
|
|
TVITEMW item;
|
|
|
|
HRESULT hr;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
hr = SHGetDesktopFolder(&desktop);
|
2024-05-23 03:03:44 +00:00
|
|
|
if (FAILED(hr))
|
2011-10-08 17:33:21 +00:00
|
|
|
return hr;
|
|
|
|
|
2017-11-05 10:09:42 +00:00
|
|
|
if (info->pidlRet)
|
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
hr = desktop->BindToObject(info->pidlRet, NULL, IID_PPV_ARG(IShellFolder, &cur));
|
2024-05-19 01:00:20 +00:00
|
|
|
desktop->Release();
|
2024-05-23 03:03:44 +00:00
|
|
|
if (FAILED(hr))
|
2017-11-05 10:09:42 +00:00
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = SHGetPathFromIDListW(info->pidlRet, path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cur = desktop;
|
|
|
|
hr = SHGetFolderPathW(NULL, CSIDL_DESKTOPDIRECTORY, NULL, SHGFP_TYPE_CURRENT, path);
|
|
|
|
}
|
2024-05-23 03:03:44 +00:00
|
|
|
if (FAILED(hr))
|
2015-09-02 13:14:46 +00:00
|
|
|
return hr;
|
|
|
|
|
|
|
|
if (!LoadStringW(shell32_hInstance, IDS_NEWFOLDER, wszNewFolder, _countof(wszNewFolder)))
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
if (!PathYetAnotherMakeUniqueName(name, path, NULL, wszNewFolder))
|
|
|
|
return E_FAIL;
|
2017-11-05 10:09:42 +00:00
|
|
|
|
|
|
|
len = strlenW(path);
|
2024-05-23 03:03:44 +00:00
|
|
|
if (len < MAX_PATH && name[len] == L'\\')
|
2017-11-05 10:09:42 +00:00
|
|
|
len++;
|
2011-10-08 17:33:21 +00:00
|
|
|
|
|
|
|
hr = E_FAIL;
|
2024-05-23 03:03:44 +00:00
|
|
|
if (!CreateDirectoryW(name, NULL))
|
2011-10-08 17:33:21 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
// Update parent of newly created directory
|
2024-05-18 11:42:22 +00:00
|
|
|
hParent = TreeView_GetSelection(info->hwndTreeView);
|
2024-05-23 03:03:44 +00:00
|
|
|
if (!hParent)
|
2011-10-08 17:33:21 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2024-05-18 11:42:22 +00:00
|
|
|
TreeView_Expand(info->hwndTreeView, hParent, TVE_EXPAND);
|
2011-10-08 17:33:21 +00:00
|
|
|
|
|
|
|
memset(&item, 0, sizeof(TVITEMW));
|
2024-05-23 03:03:44 +00:00
|
|
|
item.mask = TVIF_PARAM | TVIF_STATE;
|
2024-05-18 11:42:22 +00:00
|
|
|
item.hItem = hParent;
|
|
|
|
TreeView_GetItem(info->hwndTreeView, &item);
|
2011-10-08 17:33:21 +00:00
|
|
|
item_data = (LPTV_ITEMDATA)item.lParam;
|
2024-05-23 03:03:44 +00:00
|
|
|
if (!item_data)
|
2011-10-08 17:33:21 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
if (item_data->pEnumIL)
|
2024-05-19 01:00:20 +00:00
|
|
|
item_data->pEnumIL->Release();
|
|
|
|
hr = cur->EnumObjects(info->hwndTreeView, flags, &item_data->pEnumIL);
|
2024-05-23 03:03:44 +00:00
|
|
|
if (FAILED(hr))
|
2011-10-08 17:33:21 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
// Update treeview
|
|
|
|
if (!(item.state & TVIS_EXPANDEDONCE))
|
|
|
|
{
|
2011-10-08 17:33:21 +00:00
|
|
|
item.mask = TVIF_STATE;
|
|
|
|
item.state = TVIS_EXPANDEDONCE;
|
|
|
|
item.stateMask = TVIS_EXPANDEDONCE;
|
2024-05-18 11:42:22 +00:00
|
|
|
TreeView_SetItem(info->hwndTreeView, &item);
|
2011-10-08 17:33:21 +00:00
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
hr = cur->ParseDisplayName(NULL, NULL, name + len, NULL, &new_item, NULL);
|
|
|
|
if (FAILED(hr))
|
2011-10-08 17:33:21 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2024-05-18 11:42:22 +00:00
|
|
|
hAdded = InsertTreeViewItem(info, cur, new_item, item_data->lpifq, NULL, hParent);
|
2024-05-19 01:00:20 +00:00
|
|
|
cur->Release();
|
2011-10-08 17:33:21 +00:00
|
|
|
SHFree(new_item);
|
|
|
|
|
2024-05-18 11:42:22 +00:00
|
|
|
TreeView_SortChildren(info->hwndTreeView, hParent, FALSE);
|
|
|
|
return BrsFolder_Rename(info, hAdded);
|
2011-10-08 17:33:21 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static BOOL
|
|
|
|
BrsFolder_OnCommand(browse_info *info, UINT id)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
LPBROWSEINFOW lpBrowseInfo = info->lpBrowseInfo;
|
2020-08-20 02:35:14 +00:00
|
|
|
WCHAR szPath[MAX_PATH];
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
switch (id)
|
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
case IDOK:
|
2020-08-20 02:35:14 +00:00
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
// Get the text
|
|
|
|
GetDlgItemTextW(info->hWnd, IDC_BROWSE_FOR_FOLDER_FOLDER_TEXT, szPath, _countof(szPath));
|
|
|
|
StrTrimW(szPath, L" \t");
|
|
|
|
|
|
|
|
// The original pidl is owned by the treeview and will be free'd.
|
|
|
|
if (!PathIsRelativeW(szPath) && PathIsDirectoryW(szPath))
|
|
|
|
{
|
|
|
|
// It's valid path
|
|
|
|
info->pidlRet = ILCreateFromPathW(szPath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info->pidlRet = ILClone(info->pidlRet);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->pidlRet == NULL) // A null pidl would mean a cancel
|
|
|
|
info->pidlRet = _ILCreateDesktop();
|
|
|
|
|
|
|
|
pdump(info->pidlRet);
|
|
|
|
|
|
|
|
if (lpBrowseInfo->pszDisplayName)
|
|
|
|
{
|
|
|
|
SHFILEINFOW fileInfo = { NULL };
|
|
|
|
lpBrowseInfo->pszDisplayName[0] = UNICODE_NULL;
|
|
|
|
if (SHGetFileInfoW((LPCWSTR)info->pidlRet, 0, &fileInfo, sizeof(fileInfo),
|
|
|
|
SHGFI_PIDL | SHGFI_DISPLAYNAME))
|
|
|
|
{
|
|
|
|
lstrcpynW(lpBrowseInfo->pszDisplayName, fileInfo.szDisplayName, MAX_PATH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EndDialog(info->hWnd, 1);
|
|
|
|
return TRUE;
|
2020-08-20 02:35:14 +00:00
|
|
|
}
|
2024-05-23 03:03:44 +00:00
|
|
|
case IDCANCEL:
|
2020-08-20 02:35:14 +00:00
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
EndDialog(info->hWnd, 0);
|
|
|
|
return TRUE;
|
2020-08-20 02:35:14 +00:00
|
|
|
}
|
2024-05-23 03:03:44 +00:00
|
|
|
case IDC_BROWSE_FOR_FOLDER_NEW_FOLDER:
|
2024-02-28 04:23:27 +00:00
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
BrsFolder_NewFolder(info);
|
|
|
|
return TRUE;
|
2024-02-28 04:23:27 +00:00
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static BOOL
|
|
|
|
BrsFolder_OnSetExpanded(browse_info *info, LPVOID selection, BOOL is_str, HTREEITEM *pItem)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2024-05-19 01:00:20 +00:00
|
|
|
LPITEMIDLIST pidlSelection = (LPITEMIDLIST)selection;
|
2011-05-15 15:55:49 +00:00
|
|
|
LPCITEMIDLIST pidlCurrent, pidlRoot;
|
|
|
|
TVITEMEXW item;
|
|
|
|
BOOL bResult = FALSE;
|
|
|
|
|
2011-10-08 17:33:21 +00:00
|
|
|
memset(&item, 0, sizeof(item));
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
// If 'selection' is a string, convert to a Shell ID List.
|
|
|
|
if (is_str)
|
|
|
|
{
|
2014-11-04 20:10:43 +00:00
|
|
|
IShellFolder *psfDesktop;
|
2011-05-15 15:55:49 +00:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = SHGetDesktopFolder(&psfDesktop);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto done;
|
|
|
|
|
2024-05-19 01:00:20 +00:00
|
|
|
hr = psfDesktop->ParseDisplayName(NULL, NULL, (LPWSTR)selection, NULL, &pidlSelection, NULL);
|
|
|
|
psfDesktop->Release();
|
2024-05-23 03:03:44 +00:00
|
|
|
if (FAILED(hr))
|
2011-05-15 15:55:49 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2024-05-23 03:03:44 +00:00
|
|
|
|
2020-08-20 02:35:14 +00:00
|
|
|
if (_ILIsDesktop(pidlSelection))
|
|
|
|
{
|
|
|
|
item.hItem = TVI_ROOT;
|
|
|
|
bResult = TRUE;
|
|
|
|
goto done;
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
// Move pidlCurrent behind the SHITEMIDs in pidlSelection, which are the root of
|
|
|
|
// the sub-tree currently displayed.
|
2011-05-15 15:55:49 +00:00
|
|
|
pidlRoot = info->lpBrowseInfo->pidlRoot;
|
|
|
|
pidlCurrent = pidlSelection;
|
2024-05-23 03:03:44 +00:00
|
|
|
while (!_ILIsEmpty(pidlRoot) && _ILIsEqualSimple(pidlRoot, pidlCurrent))
|
|
|
|
{
|
2011-05-15 15:55:49 +00:00
|
|
|
pidlRoot = ILGetNext(pidlRoot);
|
|
|
|
pidlCurrent = ILGetNext(pidlCurrent);
|
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
// The given ID List is not part of the SHBrowseForFolder's current sub-tree.
|
2011-05-15 15:55:49 +00:00
|
|
|
if (!_ILIsEmpty(pidlRoot))
|
|
|
|
goto done;
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
// Initialize item to point to the first child of the root folder.
|
2011-05-15 15:55:49 +00:00
|
|
|
item.mask = TVIF_PARAM;
|
2024-05-18 11:42:22 +00:00
|
|
|
item.hItem = TreeView_GetRoot(info->hwndTreeView);
|
2011-10-08 17:33:21 +00:00
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
if (item.hItem)
|
2024-05-18 11:42:22 +00:00
|
|
|
item.hItem = TreeView_GetChild(info->hwndTreeView, item.hItem);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
// Walk the tree along the nodes corresponding to the remaining ITEMIDLIST
|
|
|
|
while (item.hItem && !_ILIsEmpty(pidlCurrent))
|
|
|
|
{
|
2011-05-15 15:55:49 +00:00
|
|
|
LPTV_ITEMDATA pItemData;
|
|
|
|
|
2024-05-18 11:42:22 +00:00
|
|
|
TreeView_GetItem(info->hwndTreeView, &item);
|
2011-05-15 15:55:49 +00:00
|
|
|
pItemData = (LPTV_ITEMDATA)item.lParam;
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
if (_ILIsEqualSimple(pItemData->lpi, pidlCurrent))
|
|
|
|
{
|
2011-05-15 15:55:49 +00:00
|
|
|
pidlCurrent = ILGetNext(pidlCurrent);
|
2024-05-23 03:03:44 +00:00
|
|
|
if (!_ILIsEmpty(pidlCurrent))
|
|
|
|
{
|
|
|
|
// Only expand current node and move on to its first child,
|
|
|
|
// if we didn't already reach the last SHITEMID
|
2024-05-18 11:42:22 +00:00
|
|
|
TreeView_Expand(info->hwndTreeView, item.hItem, TVE_EXPAND);
|
|
|
|
item.hItem = TreeView_GetChild(info->hwndTreeView, item.hItem);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
2024-05-23 03:03:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-18 11:42:22 +00:00
|
|
|
item.hItem = TreeView_GetNextSibling(info->hwndTreeView, item.hItem);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
if (_ILIsEmpty(pidlCurrent) && item.hItem)
|
2011-05-15 15:55:49 +00:00
|
|
|
bResult = TRUE;
|
|
|
|
|
|
|
|
done:
|
2014-11-05 17:04:42 +00:00
|
|
|
if (pidlSelection && pidlSelection != selection)
|
2011-05-15 15:55:49 +00:00
|
|
|
ILFree(pidlSelection);
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
if (pItem)
|
2011-05-15 15:55:49 +00:00
|
|
|
*pItem = item.hItem;
|
2024-05-23 03:03:44 +00:00
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
return bResult;
|
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static BOOL
|
|
|
|
BrsFolder_OnSetSelectionW(browse_info *info, LPVOID selection, BOOL is_str)
|
|
|
|
{
|
2011-05-15 15:55:49 +00:00
|
|
|
HTREEITEM hItem;
|
|
|
|
BOOL bResult;
|
|
|
|
|
2011-10-08 17:33:21 +00:00
|
|
|
if (!selection) return FALSE;
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
bResult = BrsFolder_OnSetExpanded(info, selection, is_str, &hItem);
|
|
|
|
if (bResult)
|
2024-05-18 11:42:22 +00:00
|
|
|
TreeView_SelectItem(info->hwndTreeView, hItem);
|
2011-05-15 15:55:49 +00:00
|
|
|
return bResult;
|
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static BOOL
|
|
|
|
BrsFolder_OnSetSelectionA(browse_info *info, LPVOID selection, BOOL is_str)
|
|
|
|
{
|
2011-05-15 15:55:49 +00:00
|
|
|
LPWSTR selectionW = NULL;
|
|
|
|
BOOL result = FALSE;
|
|
|
|
int length;
|
2024-05-23 03:03:44 +00:00
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
if (!is_str)
|
|
|
|
return BrsFolder_OnSetSelectionW(info, selection, is_str);
|
|
|
|
|
2024-05-19 01:00:20 +00:00
|
|
|
if ((length = MultiByteToWideChar(CP_ACP, 0, (LPSTR)selection, -1, NULL, 0)) &&
|
|
|
|
(selectionW = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, length * sizeof(WCHAR))) &&
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, (LPSTR)selection, -1, selectionW, length))
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
result = BrsFolder_OnSetSelectionW(info, selectionW, is_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, selectionW);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static INT
|
|
|
|
BrsFolder_OnDestroy(browse_info *info)
|
2011-10-08 17:33:21 +00:00
|
|
|
{
|
|
|
|
if (info->layout)
|
|
|
|
{
|
2020-10-21 13:25:16 +00:00
|
|
|
LayoutDestroy(info->layout);
|
2011-10-08 17:33:21 +00:00
|
|
|
info->layout = NULL;
|
|
|
|
}
|
|
|
|
|
2020-03-18 20:57:10 +00:00
|
|
|
SHChangeNotifyDeregister(info->hNotify);
|
|
|
|
|
2011-10-08 17:33:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
// Find a treeview node by recursively walking the treeview
|
|
|
|
static HTREEITEM
|
|
|
|
BrsFolder_FindItemByPidl(browse_info *info, LPCITEMIDLIST pidl, HTREEITEM hItem)
|
2020-03-18 20:57:10 +00:00
|
|
|
{
|
|
|
|
TV_ITEMDATA *item_data;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2024-05-18 11:42:22 +00:00
|
|
|
item_data = BrsFolder_GetDataFromItem(info, hItem);
|
2020-03-18 20:57:10 +00:00
|
|
|
|
2024-05-19 01:00:20 +00:00
|
|
|
hr = item_data->lpsfParent->CompareIDs(0, item_data->lpifq, pidl);
|
2024-05-23 03:03:44 +00:00
|
|
|
if (SUCCEEDED(hr) && !HRESULT_CODE(hr))
|
2020-03-18 20:57:10 +00:00
|
|
|
return hItem;
|
|
|
|
|
2024-05-18 11:42:22 +00:00
|
|
|
hItem = TreeView_GetChild(info->hwndTreeView, hItem);
|
2020-03-18 20:57:10 +00:00
|
|
|
|
|
|
|
while (hItem)
|
|
|
|
{
|
|
|
|
HTREEITEM newItem = BrsFolder_FindItemByPidl(info, pidl, hItem);
|
|
|
|
if (newItem)
|
|
|
|
return newItem;
|
2024-05-18 11:42:22 +00:00
|
|
|
hItem = TreeView_GetNextSibling(info->hwndTreeView, hItem);
|
2020-03-18 20:57:10 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
static LRESULT
|
|
|
|
BrsFolder_OnChange(browse_info *info, const LPCITEMIDLIST *pidls, LONG event)
|
2020-03-18 20:57:10 +00:00
|
|
|
{
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p, %p, 0x%08x)\n", info, pidls[0], pidls[1], event);
|
|
|
|
|
|
|
|
switch (event)
|
|
|
|
{
|
|
|
|
case SHCNE_RMDIR:
|
|
|
|
case SHCNE_DELETE:
|
|
|
|
{
|
2024-05-18 11:42:22 +00:00
|
|
|
HTREEITEM hRoot = TreeView_GetRoot(info->hwndTreeView);
|
|
|
|
HTREEITEM hItem = BrsFolder_FindItemByPidl(info, pidls[0], hRoot);
|
|
|
|
if (hItem)
|
|
|
|
TreeView_DeleteItem(info->hwndTreeView, hItem);
|
2020-03-18 20:57:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
/*************************************************************************
|
|
|
|
* BrsFolderDlgProc32 (not an exported API function)
|
|
|
|
*/
|
2024-05-23 03:03:44 +00:00
|
|
|
static INT_PTR CALLBACK
|
|
|
|
BrsFolderDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
browse_info *info;
|
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
TRACE("hwnd=%p msg=%04x 0x%08lx 0x%08lx\n", hWnd, msg, wParam, lParam);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
if (msg == WM_INITDIALOG)
|
2024-05-23 03:03:44 +00:00
|
|
|
return BrsFolder_OnCreate(hWnd, (browse_info *)lParam);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-19 01:00:20 +00:00
|
|
|
info = (browse_info*)GetPropW(hWnd, L"__WINE_BRSFOLDERDLG_INFO");
|
|
|
|
if (!info)
|
|
|
|
return 0;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
switch (msg)
|
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
case WM_NOTIFY:
|
|
|
|
return BrsFolder_OnNotify(info, (UINT)wParam, (LPNMHDR)lParam);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
case WM_COMMAND:
|
|
|
|
return BrsFolder_OnCommand(info, wParam);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
case WM_GETMINMAXINFO:
|
|
|
|
((LPMINMAXINFO)lParam)->ptMinTrackSize.x = info->szMin.cx;
|
|
|
|
((LPMINMAXINFO)lParam)->ptMinTrackSize.y = info->szMin.cy;
|
|
|
|
return 0;
|
2011-10-08 17:33:21 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
case WM_SIZE:
|
|
|
|
if (info->layout) // New style dialogs
|
|
|
|
LayoutUpdate(hWnd, info->layout, g_layout_info, LAYOUT_INFO_COUNT);
|
|
|
|
return 0;
|
2011-10-08 17:33:21 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
case BFFM_SETSTATUSTEXTA:
|
|
|
|
TRACE("Set status %s\n", debugstr_a((LPSTR)lParam));
|
|
|
|
SetWindowTextA(GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_STATUS), (LPSTR)lParam);
|
|
|
|
break;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
case BFFM_SETSTATUSTEXTW:
|
|
|
|
TRACE("Set status %s\n", debugstr_w((LPWSTR)lParam));
|
|
|
|
SetWindowTextW(GetDlgItem(hWnd, IDC_BROWSE_FOR_FOLDER_STATUS), (LPWSTR)lParam);
|
|
|
|
break;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
case BFFM_ENABLEOK:
|
|
|
|
TRACE("Enable %ld\n", lParam);
|
|
|
|
EnableWindow(GetDlgItem(hWnd, 1), lParam != 0);
|
|
|
|
break;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
case BFFM_SETOKTEXT: // Unicode only
|
|
|
|
TRACE("Set OK text %s\n", debugstr_w((LPWSTR)lParam));
|
|
|
|
SetWindowTextW(GetDlgItem(hWnd, 1), (LPWSTR)lParam);
|
|
|
|
break;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
case BFFM_SETSELECTIONA:
|
|
|
|
return BrsFolder_OnSetSelectionA(info, (LPVOID)lParam, (BOOL)wParam);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
case BFFM_SETSELECTIONW:
|
|
|
|
return BrsFolder_OnSetSelectionW(info, (LPVOID)lParam, (BOOL)wParam);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
case BFFM_SETEXPANDED: // Unicode only
|
|
|
|
return BrsFolder_OnSetExpanded(info, (LPVOID)lParam, (BOOL)wParam, NULL);
|
2011-10-08 17:33:21 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
case SHV_CHANGE_NOTIFY:
|
|
|
|
return BrsFolder_OnChange(info, (const LPCITEMIDLIST*)wParam, (LONG)lParam);
|
2020-03-18 20:57:10 +00:00
|
|
|
|
2024-05-23 03:03:44 +00:00
|
|
|
case WM_DESTROY:
|
|
|
|
return BrsFolder_OnDestroy(info);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SHBrowseForFolderA [SHELL32.@]
|
|
|
|
* SHBrowseForFolder [SHELL32.@]
|
|
|
|
*/
|
2024-05-19 01:00:20 +00:00
|
|
|
EXTERN_C
|
2024-05-23 03:03:44 +00:00
|
|
|
LPITEMIDLIST WINAPI
|
|
|
|
SHBrowseForFolderA(LPBROWSEINFOA lpbi)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
BROWSEINFOW bi;
|
|
|
|
LPITEMIDLIST lpid;
|
|
|
|
INT len;
|
|
|
|
LPWSTR title;
|
|
|
|
|
|
|
|
TRACE("%p\n", lpbi);
|
|
|
|
|
|
|
|
bi.hwndOwner = lpbi->hwndOwner;
|
|
|
|
bi.pidlRoot = lpbi->pidlRoot;
|
|
|
|
if (lpbi->pszDisplayName)
|
2024-05-19 01:00:20 +00:00
|
|
|
bi.pszDisplayName = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
|
2011-05-15 15:55:49 +00:00
|
|
|
else
|
|
|
|
bi.pszDisplayName = NULL;
|
|
|
|
|
|
|
|
if (lpbi->lpszTitle)
|
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, lpbi->lpszTitle, -1, NULL, 0);
|
|
|
|
title = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpbi->lpszTitle, -1, title, len);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
title = NULL;
|
|
|
|
|
|
|
|
bi.lpszTitle = title;
|
|
|
|
bi.ulFlags = lpbi->ulFlags;
|
|
|
|
bi.lpfn = lpbi->lpfn;
|
|
|
|
bi.lParam = lpbi->lParam;
|
|
|
|
bi.iImage = lpbi->iImage;
|
2024-05-23 03:03:44 +00:00
|
|
|
lpid = SHBrowseForFolderW(&bi);
|
2011-05-15 15:55:49 +00:00
|
|
|
if (bi.pszDisplayName)
|
|
|
|
{
|
2024-05-23 03:03:44 +00:00
|
|
|
WideCharToMultiByte(CP_ACP, 0, bi.pszDisplayName, -1,
|
|
|
|
lpbi->pszDisplayName, MAX_PATH, 0, NULL);
|
|
|
|
HeapFree(GetProcessHeap(), 0, bi.pszDisplayName);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, title);
|
|
|
|
lpbi->iImage = bi.iImage;
|
|
|
|
return lpid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SHBrowseForFolderW [SHELL32.@]
|
|
|
|
*/
|
2024-05-19 01:00:20 +00:00
|
|
|
EXTERN_C
|
2024-05-23 03:03:44 +00:00
|
|
|
LPITEMIDLIST WINAPI
|
|
|
|
SHBrowseForFolderW(LPBROWSEINFOW lpbi)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2024-05-19 01:00:20 +00:00
|
|
|
browse_info info = { NULL };
|
2011-05-15 15:55:49 +00:00
|
|
|
info.lpBrowseInfo = lpbi;
|
2024-05-18 11:42:22 +00:00
|
|
|
|
2024-05-19 01:00:20 +00:00
|
|
|
HRESULT hr = OleInitialize(NULL);
|
2024-05-18 11:42:22 +00:00
|
|
|
|
2024-05-19 01:00:20 +00:00
|
|
|
INT id = ((lpbi->ulFlags & BIF_USENEWUI) ? IDD_BROWSE_FOR_FOLDER_NEW : IDD_BROWSE_FOR_FOLDER);
|
|
|
|
INT_PTR ret = DialogBoxParamW(shell32_hInstance, MAKEINTRESOURCEW(id), lpbi->hwndOwner,
|
|
|
|
BrsFolderDlgProc, (LPARAM)&info);
|
2024-05-18 11:42:22 +00:00
|
|
|
if (SUCCEEDED(hr))
|
2011-05-15 15:55:49 +00:00
|
|
|
OleUninitialize();
|
2024-05-18 11:42:22 +00:00
|
|
|
|
2024-05-19 01:00:20 +00:00
|
|
|
if (!ret)
|
2011-10-08 17:33:21 +00:00
|
|
|
{
|
|
|
|
ILFree(info.pidlRet);
|
2011-05-15 15:55:49 +00:00
|
|
|
return NULL;
|
2011-10-08 17:33:21 +00:00
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
return info.pidlRet;
|
|
|
|
}
|