📄 brsfolder.c
字号:
if (FAILED(r) ||
((dwAttributes & (SFGAO_FOLDER|SFGAO_FILESYSTEM)) != (SFGAO_FOLDER|SFGAO_FILESYSTEM)))
{
bEnabled = FALSE;
}
}
SendMessageW(info->hWnd, BFFM_ENABLEOK, 0, (LPARAM)bEnabled);
}
static LRESULT BrsFolder_Treeview_Delete( browse_info *info, NMTREEVIEWW *pnmtv )
{
LPTV_ITEMDATA lptvid = (LPTV_ITEMDATA)pnmtv->itemOld.lParam;
TRACE("TVN_DELETEITEMA/W %p\n", lptvid);
IShellFolder_Release(lptvid->lpsfParent);
if (lptvid->pEnumIL)
IEnumIDList_Release(lptvid->pEnumIL);
SHFree(lptvid->lpi);
SHFree(lptvid->lpifq);
SHFree(lptvid);
return 0;
}
static LRESULT BrsFolder_Treeview_Expand( browse_info *info, NMTREEVIEWW *pnmtv )
{
IShellFolder *lpsf2 = NULL;
LPTV_ITEMDATA lptvid = (LPTV_ITEMDATA) pnmtv->itemNew.lParam;
HRESULT r;
TRACE("TVN_ITEMEXPANDINGA/W\n");
if ((pnmtv->itemNew.state & TVIS_EXPANDEDONCE))
return 0;
if (lptvid->lpi && lptvid->lpi->mkid.cb) {
r = IShellFolder_BindToObject( lptvid->lpsfParent, lptvid->lpi, 0,
(REFIID)&IID_IShellFolder, (LPVOID *)&lpsf2 );
} else {
lpsf2 = lptvid->lpsfParent;
r = IShellFolder_AddRef(lpsf2);
}
if (SUCCEEDED(r))
FillTreeView( info, lpsf2, lptvid->lpifq, pnmtv->itemNew.hItem, lptvid->pEnumIL);
/* My Computer is already sorted and trying to do a simple text
* sort will only mess things up */
if (!_ILIsMyComputer(lptvid->lpi))
SendMessageW( info->hwndTreeView, TVM_SORTCHILDREN,
FALSE, (LPARAM)pnmtv->itemNew.hItem );
return 0;
}
static HRESULT BrsFolder_Treeview_Changed( browse_info *info, NMTREEVIEWW *pnmtv )
{
LPTV_ITEMDATA lptvid = (LPTV_ITEMDATA) pnmtv->itemNew.lParam;
lptvid = (LPTV_ITEMDATA) pnmtv->itemNew.lParam;
info->pidlRet = lptvid->lpifq;
browsefolder_callback( info->lpBrowseInfo, info->hWnd, BFFM_SELCHANGED,
(LPARAM)info->pidlRet );
BrsFolder_CheckValidSelection( info, lptvid );
return 0;
}
static LRESULT BrsFolder_OnNotify( browse_info *info, UINT CtlID, LPNMHDR lpnmh )
{
NMTREEVIEWW *pnmtv = (NMTREEVIEWW *)lpnmh;
TRACE("%p %x %p msg=%x\n", info, CtlID, lpnmh, pnmtv->hdr.code);
if (pnmtv->hdr.idFrom != IDD_TREEVIEW)
return 0;
switch (pnmtv->hdr.code)
{
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 );
default:
WARN("unhandled (%d)\n", pnmtv->hdr.code);
break;
}
return 0;
}
static BOOL BrsFolder_OnCreate( HWND hWnd, browse_info *info )
{
LPBROWSEINFOW lpBrowseInfo = info->lpBrowseInfo;
info->hWnd = hWnd;
SetPropW( hWnd, szBrowseFolderInfo, info );
if (lpBrowseInfo->ulFlags & ~SUPPORTEDFLAGS)
FIXME("flags %x not implemented\n", lpBrowseInfo->ulFlags & ~SUPPORTEDFLAGS);
if (lpBrowseInfo->lpszTitle)
SetWindowTextW( GetDlgItem(hWnd, IDD_TITLE), lpBrowseInfo->lpszTitle );
else
ShowWindow( GetDlgItem(hWnd, IDD_TITLE), SW_HIDE );
if (!(lpBrowseInfo->ulFlags & BIF_STATUSTEXT))
ShowWindow( GetDlgItem(hWnd, IDD_STATUS), SW_HIDE );
info->hwndTreeView = GetDlgItem( hWnd, IDD_TREEVIEW );
if (info->hwndTreeView)
InitializeTreeView( info );
else
ERR("treeview control missing!\n");
browsefolder_callback( info->lpBrowseInfo, hWnd, BFFM_INITIALIZED, 0 );
return TRUE;
}
static BOOL BrsFolder_OnCommand( browse_info *info, UINT id )
{
LPBROWSEINFOW lpBrowseInfo = info->lpBrowseInfo;
switch (id)
{
case IDOK:
info->pidlRet = ILClone(info->pidlRet); /* The original pidl will be free'd. */
pdump( info->pidlRet );
if (lpBrowseInfo->pszDisplayName)
SHGetPathFromIDListW( info->pidlRet, lpBrowseInfo->pszDisplayName );
EndDialog( info->hWnd, 1 );
return TRUE;
case IDCANCEL:
EndDialog( info->hWnd, 0 );
return TRUE;
}
return FALSE;
}
static BOOL BrsFolder_OnSetExpanded(browse_info *info, LPVOID selection,
BOOL is_str, HTREEITEM *pItem)
{
LPITEMIDLIST pidlSelection = (LPITEMIDLIST)selection;
LPCITEMIDLIST pidlCurrent, pidlRoot;
TVITEMEXW item;
BOOL bResult = FALSE;
/* If 'selection' is a string, convert to a Shell ID List. */
if (is_str) {
IShellFolder *psfDesktop;
HRESULT hr;
hr = SHGetDesktopFolder(&psfDesktop);
if (FAILED(hr))
goto done;
hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL,
(LPOLESTR)selection, NULL, &pidlSelection, NULL);
IShellFolder_Release(psfDesktop);
if (FAILED(hr))
goto done;
}
/* Move pidlCurrent behind the SHITEMIDs in pidlSelection, which are the root of
* the sub-tree currently displayed. */
pidlRoot = info->lpBrowseInfo->pidlRoot;
pidlCurrent = pidlSelection;
while (!_ILIsEmpty(pidlRoot) && _ILIsEqualSimple(pidlRoot, pidlCurrent)) {
pidlRoot = ILGetNext(pidlRoot);
pidlCurrent = ILGetNext(pidlCurrent);
}
/* The given ID List is not part of the SHBrowseForFolder's current sub-tree. */
if (!_ILIsEmpty(pidlRoot))
goto done;
/* Initialize item to point to the first child of the root folder. */
memset(&item, 0, sizeof(item));
item.mask = TVIF_PARAM;
item.hItem = TreeView_GetRoot(info->hwndTreeView);
if (item.hItem)
item.hItem = TreeView_GetChild(info->hwndTreeView, item.hItem);
/* Walk the tree along the nodes corresponding to the remaining ITEMIDLIST */
while (item.hItem && !_ILIsEmpty(pidlCurrent)) {
LPTV_ITEMDATA pItemData;
SendMessageW(info->hwndTreeView, TVM_GETITEMW, 0, (LPARAM)&item);
pItemData = (LPTV_ITEMDATA)item.lParam;
if (_ILIsEqualSimple(pItemData->lpi, pidlCurrent)) {
pidlCurrent = ILGetNext(pidlCurrent);
if (!_ILIsEmpty(pidlCurrent)) {
/* Only expand current node and move on to it's first child,
* if we didn't already reach the last SHITEMID */
SendMessageW(info->hwndTreeView, TVM_EXPAND, TVE_EXPAND, (LPARAM)item.hItem);
item.hItem = TreeView_GetChild(info->hwndTreeView, item.hItem);
}
} else {
item.hItem = TreeView_GetNextSibling(info->hwndTreeView, item.hItem);
}
}
if (_ILIsEmpty(pidlCurrent) && item.hItem)
bResult = TRUE;
done:
if (pidlSelection && pidlSelection != (LPITEMIDLIST)selection)
ILFree(pidlSelection);
if (pItem)
*pItem = item.hItem;
return bResult;
}
static BOOL BrsFolder_OnSetSelectionW(browse_info *info, LPVOID selection, BOOL is_str) {
HTREEITEM hItem;
BOOL bResult;
bResult = BrsFolder_OnSetExpanded(info, selection, is_str, &hItem);
if (bResult)
SendMessageW(info->hwndTreeView, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hItem );
return bResult;
}
static BOOL BrsFolder_OnSetSelectionA(browse_info *info, LPVOID selection, BOOL is_str) {
LPWSTR selectionW = NULL;
BOOL result = FALSE;
int length;
if (!is_str)
return BrsFolder_OnSetSelectionW(info, selection, is_str);
if ((length = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)selection, -1, NULL, 0)) &&
(selectionW = HeapAlloc(GetProcessHeap(), 0, length * sizeof(WCHAR))) &&
MultiByteToWideChar(CP_ACP, 0, (LPCSTR)selection, -1, selectionW, length))
{
result = BrsFolder_OnSetSelectionW(info, selectionW, is_str);
}
HeapFree(GetProcessHeap(), 0, selectionW);
return result;
}
/*************************************************************************
* BrsFolderDlgProc32 (not an exported API function)
*/
static INT_PTR CALLBACK BrsFolderDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
LPARAM lParam )
{
browse_info *info;
TRACE("hwnd=%p msg=%04x 0x%08x 0x%08lx\n", hWnd, msg, wParam, lParam );
if (msg == WM_INITDIALOG)
return BrsFolder_OnCreate( hWnd, (browse_info*) lParam );
info = (browse_info*) GetPropW( hWnd, szBrowseFolderInfo );
switch (msg)
{
case WM_NOTIFY:
return BrsFolder_OnNotify( info, (UINT)wParam, (LPNMHDR)lParam);
case WM_COMMAND:
return BrsFolder_OnCommand( info, wParam );
case BFFM_SETSTATUSTEXTA:
TRACE("Set status %s\n", debugstr_a((LPSTR)lParam));
SetWindowTextA(GetDlgItem(hWnd, IDD_STATUS), (LPSTR)lParam);
break;
case BFFM_SETSTATUSTEXTW:
TRACE("Set status %s\n", debugstr_w((LPWSTR)lParam));
SetWindowTextW(GetDlgItem(hWnd, IDD_STATUS), (LPWSTR)lParam);
break;
case BFFM_ENABLEOK:
TRACE("Enable %ld\n", lParam);
EnableWindow(GetDlgItem(hWnd, 1), (lParam)?TRUE:FALSE);
break;
case BFFM_SETOKTEXT: /* unicode only */
TRACE("Set OK text %s\n", debugstr_w((LPWSTR)wParam));
SetWindowTextW(GetDlgItem(hWnd, 1), (LPWSTR)wParam);
break;
case BFFM_SETSELECTIONA:
return BrsFolder_OnSetSelectionA(info, (LPVOID)lParam, (BOOL)wParam);
case BFFM_SETSELECTIONW:
return BrsFolder_OnSetSelectionW(info, (LPVOID)lParam, (BOOL)wParam);
case BFFM_SETEXPANDED: /* unicode only */
return BrsFolder_OnSetExpanded(info, (LPVOID)lParam, (BOOL)wParam, NULL);
}
return FALSE;
}
static const WCHAR swBrowseTemplateName[] = {
'S','H','B','R','S','F','O','R','F','O','L','D','E','R','_','M','S','G','B','O','X',0};
/*************************************************************************
* SHBrowseForFolderA [SHELL32.@]
* SHBrowseForFolder [SHELL32.@]
*/
LPITEMIDLIST WINAPI SHBrowseForFolderA (LPBROWSEINFOA lpbi)
{
BROWSEINFOW bi;
LPITEMIDLIST lpid;
INT len;
LPWSTR title;
TRACE("%p\n", lpbi);
bi.hwndOwner = lpbi->hwndOwner;
bi.pidlRoot = lpbi->pidlRoot;
if (lpbi->pszDisplayName)
{
bi.pszDisplayName = HeapAlloc( GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR) );
MultiByteToWideChar( CP_ACP, 0, lpbi->pszDisplayName, -1, bi.pszDisplayName, MAX_PATH );
}
else
bi.pszDisplayName = NULL;
if (lpbi->lpszTitle)
{
len = MultiByteToWideChar( CP_ACP, 0, lpbi->lpszTitle, -1, NULL, 0 );
title = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
MultiByteToWideChar( CP_ACP, 0, lpbi->lpszTitle, -1, title, len );
}
else
title = NULL;
bi.lpszTitle = title;
bi.ulFlags = lpbi->ulFlags;
bi.lpfn = lpbi->lpfn;
bi.lParam = lpbi->lParam;
bi.iImage = lpbi->iImage;
lpid = SHBrowseForFolderW( &bi );
if (bi.pszDisplayName)
{
WideCharToMultiByte( CP_ACP, 0, bi.pszDisplayName, -1,
lpbi->pszDisplayName, MAX_PATH, 0, NULL);
HeapFree( GetProcessHeap(), 0, bi.pszDisplayName );
}
HeapFree(GetProcessHeap(), 0, title);
lpbi->iImage = bi.iImage;
return lpid;
}
/*************************************************************************
* SHBrowseForFolderW [SHELL32.@]
*
* NOTES
* crashes when passed a null pointer
*/
LPITEMIDLIST WINAPI SHBrowseForFolderW (LPBROWSEINFOW lpbi)
{
browse_info info;
DWORD r;
HRESULT hr;
info.hWnd = 0;
info.pidlRet = NULL;
info.lpBrowseInfo = lpbi;
info.hwndTreeView = NULL;
hr = OleInitialize(NULL);
r = DialogBoxParamW( shell32_hInstance, swBrowseTemplateName, lpbi->hwndOwner,
BrsFolderDlgProc, (LPARAM)&info );
if (SUCCEEDED(hr))
OleUninitialize();
if (!r)
return NULL;
return info.pidlRet;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -