2002-03-10 00:29:33 +01:00
|
|
|
/*
|
|
|
|
* Copyright 1999 Juergen Schmied
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-07-24 03:56:03 +02:00
|
|
|
*
|
|
|
|
* FIXME:
|
|
|
|
* - many memory leaks
|
2003-06-06 20:09:38 +02:00
|
|
|
* - many flags unimplemented
|
2007-06-07 23:55:09 +02:00
|
|
|
* - implement editbox
|
2002-03-10 00:29:33 +01:00
|
|
|
*/
|
|
|
|
|
1999-01-26 11:30:55 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#define COBJMACROS
|
2003-01-07 21:36:20 +01:00
|
|
|
#define NONAMELESSUNION
|
2004-10-07 05:06:48 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2001-08-16 20:49:56 +02:00
|
|
|
#include "undocshell.h"
|
2017-04-25 10:04:59 +02:00
|
|
|
#include "commoncontrols.h"
|
1999-01-26 11:30:55 +01:00
|
|
|
#include "pidl.h"
|
|
|
|
#include "shell32_main.h"
|
1999-04-22 12:11:04 +02:00
|
|
|
#include "shellapi.h"
|
2000-08-25 23:33:23 +02:00
|
|
|
#include "shresdef.h"
|
2011-07-03 13:55:39 +02:00
|
|
|
#include "shellfolder.h"
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(shell);
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2018-09-14 22:01:41 +02:00
|
|
|
#define SHV_CHANGE_NOTIFY (WM_USER + 0x1111)
|
|
|
|
|
2008-07-07 12:05:02 +02:00
|
|
|
/* original margins and control size */
|
|
|
|
typedef struct tagLAYOUT_DATA
|
|
|
|
{
|
|
|
|
LONG left, width, right;
|
|
|
|
LONG top, height, bottom;
|
|
|
|
} LAYOUT_DATA;
|
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
typedef struct tagbrowse_info
|
|
|
|
{
|
|
|
|
HWND hWnd;
|
|
|
|
HWND hwndTreeView;
|
|
|
|
LPBROWSEINFOW lpBrowseInfo;
|
|
|
|
LPITEMIDLIST pidlRet;
|
2008-07-07 12:05:02 +02:00
|
|
|
LAYOUT_DATA *layout; /* filled by LayoutInit, used by LayoutUpdate */
|
|
|
|
SIZE szMin;
|
2018-09-14 22:01:41 +02:00
|
|
|
ULONG hNotify; /* change notification handle */
|
2005-05-04 11:48:15 +02:00
|
|
|
} browse_info;
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
typedef struct tagTV_ITEMDATA
|
2005-04-28 20:26:58 +02:00
|
|
|
{
|
|
|
|
LPSHELLFOLDER lpsfParent; /* IShellFolder of the parent */
|
2008-01-16 12:20:50 +01:00
|
|
|
LPITEMIDLIST lpi; /* PIDL relative to parent */
|
2005-04-28 20:26:58 +02:00
|
|
|
LPITEMIDLIST lpifq; /* Fully qualified PIDL */
|
|
|
|
IEnumIDList* pEnumIL; /* Children iterator */
|
|
|
|
} TV_ITEMDATA, *LPTV_ITEMDATA;
|
|
|
|
|
2008-07-07 12:05:02 +02:00
|
|
|
typedef struct tagLAYOUT_INFO
|
|
|
|
{
|
|
|
|
int iItemId; /* control id */
|
|
|
|
DWORD dwAnchor; /* BF_* flags specifying which margins should remain constant */
|
|
|
|
} LAYOUT_INFO;
|
|
|
|
|
|
|
|
static const LAYOUT_INFO g_layout_info[] =
|
|
|
|
{
|
|
|
|
{IDD_TITLE, BF_TOP|BF_LEFT|BF_RIGHT},
|
|
|
|
{IDD_STATUS, BF_TOP|BF_LEFT|BF_RIGHT},
|
|
|
|
{IDD_FOLDER, BF_TOP|BF_LEFT|BF_RIGHT},
|
|
|
|
{IDD_TREEVIEW, BF_TOP|BF_BOTTOM|BF_LEFT|BF_RIGHT},
|
2009-01-28 20:54:30 +01:00
|
|
|
{IDD_FOLDER, BF_BOTTOM|BF_LEFT},
|
2008-07-07 12:05:02 +02:00
|
|
|
{IDD_FOLDERTEXT, BF_BOTTOM|BF_LEFT|BF_RIGHT},
|
|
|
|
{IDD_MAKENEWFOLDER, BF_BOTTOM|BF_LEFT},
|
|
|
|
{IDOK, BF_BOTTOM|BF_RIGHT},
|
|
|
|
{IDCANCEL, BF_BOTTOM|BF_RIGHT}
|
|
|
|
};
|
|
|
|
|
2003-06-06 20:09:38 +02:00
|
|
|
#define SUPPORTEDFLAGS (BIF_STATUSTEXT | \
|
|
|
|
BIF_BROWSEFORCOMPUTER | \
|
|
|
|
BIF_RETURNFSANCESTORS | \
|
|
|
|
BIF_RETURNONLYFSDIRS | \
|
2007-06-07 23:55:09 +02:00
|
|
|
BIF_NONEWFOLDERBUTTON | \
|
|
|
|
BIF_NEWDIALOGSTYLE | \
|
2003-06-06 20:09:38 +02:00
|
|
|
BIF_BROWSEINCLUDEFILES)
|
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
static void FillTreeView(browse_info*, LPSHELLFOLDER,
|
|
|
|
LPITEMIDLIST, HTREEITEM, IEnumIDList*);
|
|
|
|
static HTREEITEM InsertTreeViewItem( browse_info*, IShellFolder *,
|
|
|
|
LPCITEMIDLIST, LPCITEMIDLIST, IEnumIDList*, HTREEITEM);
|
|
|
|
|
2006-06-12 13:44:21 +02:00
|
|
|
static const WCHAR szBrowseFolderInfo[] = {
|
2005-05-04 11:48:15 +02:00
|
|
|
'_','_','W','I','N','E','_',
|
|
|
|
'B','R','S','F','O','L','D','E','R','D','L','G','_',
|
|
|
|
'I','N','F','O',0
|
|
|
|
};
|
|
|
|
|
2003-06-06 20:09:38 +02:00
|
|
|
static inline DWORD BrowseFlagsToSHCONTF(UINT ulFlags)
|
|
|
|
{
|
|
|
|
return SHCONTF_FOLDERS | (ulFlags & BIF_BROWSEINCLUDEFILES ? SHCONTF_NONFOLDERS : 0);
|
|
|
|
}
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
static void browsefolder_callback( LPBROWSEINFOW lpBrowseInfo, HWND hWnd,
|
|
|
|
UINT msg, LPARAM param )
|
|
|
|
{
|
|
|
|
if (!lpBrowseInfo->lpfn)
|
|
|
|
return;
|
2005-06-27 20:46:47 +02:00
|
|
|
lpBrowseInfo->lpfn( hWnd, msg, param, lpBrowseInfo->lParam );
|
2005-05-04 11:48:15 +02:00
|
|
|
}
|
|
|
|
|
2008-07-07 12:05:02 +02:00
|
|
|
static LAYOUT_DATA *LayoutInit(HWND hwnd, const LAYOUT_INFO *layout_info, int layout_count)
|
|
|
|
{
|
|
|
|
LAYOUT_DATA *data;
|
|
|
|
RECT rcWnd;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
GetClientRect(hwnd, &rcWnd);
|
|
|
|
data = SHAlloc(sizeof(LAYOUT_DATA)*layout_count);
|
|
|
|
for (i = 0; i < layout_count; i++)
|
|
|
|
{
|
|
|
|
RECT r;
|
|
|
|
HWND hItem = GetDlgItem(hwnd, layout_info[i].iItemId);
|
|
|
|
|
|
|
|
if (hItem == NULL)
|
|
|
|
ERR("Item %d not found\n", i);
|
|
|
|
GetWindowRect(hItem, &r);
|
|
|
|
MapWindowPoints(HWND_DESKTOP, hwnd, (LPPOINT)&r, 2);
|
|
|
|
|
|
|
|
data[i].left = r.left;
|
|
|
|
data[i].right = rcWnd.right - r.right;
|
|
|
|
data[i].width = r.right - r.left;
|
|
|
|
|
|
|
|
data[i].top = r.top;
|
|
|
|
data[i].bottom = rcWnd.bottom - r.bottom;
|
|
|
|
data[i].height = r.bottom - r.top;
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void LayoutUpdate(HWND hwnd, LAYOUT_DATA *data, const LAYOUT_INFO *layout_info, int layout_count)
|
|
|
|
{
|
|
|
|
RECT rcWnd;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
GetClientRect(hwnd, &rcWnd);
|
|
|
|
for (i = 0; i < layout_count; i++)
|
|
|
|
{
|
|
|
|
RECT r;
|
|
|
|
HWND hItem = GetDlgItem(hwnd, layout_info[i].iItemId);
|
|
|
|
|
|
|
|
GetWindowRect(hItem, &r);
|
|
|
|
MapWindowPoints(HWND_DESKTOP, hwnd, (LPPOINT)&r, 2);
|
|
|
|
|
|
|
|
if (layout_info[i].dwAnchor & BF_RIGHT)
|
|
|
|
{
|
|
|
|
r.right = rcWnd.right - data[i].right;
|
|
|
|
if (!(layout_info[i].dwAnchor & BF_LEFT))
|
|
|
|
r.left = r.right - data[i].width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout_info[i].dwAnchor & BF_BOTTOM)
|
|
|
|
{
|
|
|
|
r.bottom = rcWnd.bottom - data[i].bottom;
|
|
|
|
if (!(layout_info[i].dwAnchor & BF_TOP))
|
|
|
|
r.top = r.bottom - data[i].height;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetWindowPos(hItem, NULL, r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_NOZORDER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-01 12:45:32 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* InitializeTreeView [Internal]
|
|
|
|
*
|
|
|
|
* Called from WM_INITDIALOG handler.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hwndParent [I] The BrowseForFolder dialog
|
|
|
|
* root [I] ITEMIDLIST of the root shell folder
|
|
|
|
*/
|
2005-05-04 11:48:15 +02:00
|
|
|
static void InitializeTreeView( browse_info *info )
|
1999-01-26 11:30:55 +01:00
|
|
|
{
|
2005-03-01 12:45:32 +01:00
|
|
|
LPITEMIDLIST pidlParent, pidlChild;
|
|
|
|
HIMAGELIST hImageList;
|
|
|
|
HRESULT hr;
|
|
|
|
IShellFolder *lpsfParent, *lpsfRoot;
|
|
|
|
IEnumIDList * pEnumChildren = NULL;
|
2005-05-04 11:48:15 +02:00
|
|
|
HTREEITEM item;
|
|
|
|
DWORD flags;
|
|
|
|
LPCITEMIDLIST root = info->lpBrowseInfo->pidlRoot;
|
2005-03-01 12:45:32 +01:00
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
TRACE("%p\n", info );
|
2005-03-01 12:45:32 +01:00
|
|
|
|
2010-07-20 10:11:49 +02:00
|
|
|
Shell_GetImageLists(NULL, &hImageList);
|
2005-03-01 12:45:32 +01:00
|
|
|
|
|
|
|
if (hImageList)
|
2006-03-03 04:28:14 +01:00
|
|
|
SendMessageW( info->hwndTreeView, TVM_SETIMAGELIST, 0, (LPARAM)hImageList );
|
2005-03-01 12:45:32 +01:00
|
|
|
|
|
|
|
/* We want to call InsertTreeViewItem down the code, in order to insert
|
|
|
|
* the root item of the treeview. Due to InsertTreeViewItem's signature,
|
|
|
|
* we need the following to do this:
|
|
|
|
*
|
|
|
|
* + An ITEMIDLIST corresponding to _the parent_ of root.
|
|
|
|
* + An ITEMIDLIST, which is a relative path from root's parent to root
|
|
|
|
* (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));
|
|
|
|
|
|
|
|
if (_ILIsDesktop(pidlParent)) {
|
|
|
|
hr = SHGetDesktopFolder(&lpsfParent);
|
|
|
|
} else {
|
|
|
|
IShellFolder *lpsfDesktop;
|
|
|
|
hr = SHGetDesktopFolder(&lpsfDesktop);
|
2008-10-08 01:32:38 +02:00
|
|
|
if (FAILED(hr)) {
|
2006-10-07 20:18:14 +02:00
|
|
|
WARN("SHGetDesktopFolder failed! hr = %08x\n", hr);
|
2011-01-19 23:41:18 +01:00
|
|
|
ILFree(pidlChild);
|
2011-01-22 01:07:40 +01:00
|
|
|
ILFree(pidlParent);
|
2005-03-01 12:45:32 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
hr = IShellFolder_BindToObject(lpsfDesktop, pidlParent, 0, &IID_IShellFolder, (LPVOID*)&lpsfParent);
|
|
|
|
IShellFolder_Release(lpsfDesktop);
|
|
|
|
}
|
2008-10-08 01:32:38 +02:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2006-10-07 20:18:14 +02:00
|
|
|
WARN("Could not bind to parent shell folder! hr = %08x\n", hr);
|
2011-01-19 23:41:18 +01:00
|
|
|
ILFree(pidlChild);
|
2011-01-22 01:07:40 +01:00
|
|
|
ILFree(pidlParent);
|
2005-03-01 12:45:32 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-02 14:33:40 +02:00
|
|
|
if (!_ILIsEmpty(pidlChild)) {
|
2005-03-01 12:45:32 +01:00
|
|
|
hr = IShellFolder_BindToObject(lpsfParent, pidlChild, 0, &IID_IShellFolder, (LPVOID*)&lpsfRoot);
|
|
|
|
} else {
|
|
|
|
lpsfRoot = lpsfParent;
|
|
|
|
hr = IShellFolder_AddRef(lpsfParent);
|
|
|
|
}
|
2008-10-08 01:32:38 +02:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2006-10-07 20:18:14 +02:00
|
|
|
WARN("Could not bind to root shell folder! hr = %08x\n", hr);
|
2005-03-01 12:45:32 +01:00
|
|
|
IShellFolder_Release(lpsfParent);
|
2011-01-19 23:41:18 +01:00
|
|
|
ILFree(pidlChild);
|
2011-01-22 01:07:40 +01:00
|
|
|
ILFree(pidlParent);
|
2005-03-01 12:45:32 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
flags = BrowseFlagsToSHCONTF( info->lpBrowseInfo->ulFlags );
|
|
|
|
hr = IShellFolder_EnumObjects( lpsfRoot, info->hWnd, flags, &pEnumChildren );
|
2008-10-08 01:32:38 +02:00
|
|
|
if (FAILED(hr)) {
|
2006-10-07 20:18:14 +02:00
|
|
|
WARN("Could not get child iterator! hr = %08x\n", hr);
|
2005-03-01 12:45:32 +01:00
|
|
|
IShellFolder_Release(lpsfParent);
|
|
|
|
IShellFolder_Release(lpsfRoot);
|
2011-01-19 23:41:18 +01:00
|
|
|
ILFree(pidlChild);
|
2011-01-22 01:07:40 +01:00
|
|
|
ILFree(pidlParent);
|
2005-03-01 12:45:32 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-03-03 04:28:14 +01:00
|
|
|
SendMessageW( info->hwndTreeView, TVM_DELETEITEM, 0, (LPARAM)TVI_ROOT );
|
2005-05-04 11:48:15 +02:00
|
|
|
item = InsertTreeViewItem( info, lpsfParent, pidlChild,
|
|
|
|
pidlParent, pEnumChildren, TVI_ROOT );
|
2006-03-03 04:28:14 +01:00
|
|
|
SendMessageW( info->hwndTreeView, TVM_EXPAND, TVE_EXPAND, (LPARAM)item );
|
2005-03-01 12:45:32 +01:00
|
|
|
|
2011-01-19 23:41:18 +01:00
|
|
|
ILFree(pidlChild);
|
2011-01-22 01:07:40 +01:00
|
|
|
ILFree(pidlParent);
|
2005-03-01 12:45:32 +01:00
|
|
|
IShellFolder_Release(lpsfRoot);
|
|
|
|
IShellFolder_Release(lpsfParent);
|
1999-01-26 11:30:55 +01:00
|
|
|
}
|
|
|
|
|
2007-09-11 00:09:58 +02:00
|
|
|
static int GetIcon(LPCITEMIDLIST lpi, UINT uFlags)
|
2003-06-06 20:09:38 +02:00
|
|
|
{
|
2005-05-04 11:48:15 +02:00
|
|
|
SHFILEINFOW sfi;
|
2017-04-25 10:04:59 +02:00
|
|
|
IImageList *list;
|
|
|
|
|
|
|
|
list = (IImageList *)SHGetFileInfoW((LPCWSTR)lpi, 0 ,&sfi, sizeof(SHFILEINFOW), uFlags);
|
|
|
|
if (list) IImageList_Release(list);
|
2005-05-04 11:48:15 +02:00
|
|
|
return sfi.iIcon;
|
1999-01-26 11:30:55 +01:00
|
|
|
}
|
|
|
|
|
2002-12-13 01:30:30 +01:00
|
|
|
static void GetNormalAndSelectedIcons(LPITEMIDLIST lpifq, LPTVITEMW lpTV_ITEM)
|
2003-06-06 20:09:38 +02:00
|
|
|
{
|
2005-05-04 11:48:15 +02:00
|
|
|
LPITEMIDLIST pidlDesktop = NULL;
|
|
|
|
DWORD flags;
|
2003-06-06 20:09:38 +02:00
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
TRACE("%p %p\n",lpifq, lpTV_ITEM);
|
2003-06-06 20:09:38 +02:00
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
if (!lpifq)
|
|
|
|
{
|
|
|
|
pidlDesktop = _ILCreateDesktop();
|
|
|
|
lpifq = pidlDesktop;
|
|
|
|
}
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
flags = SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON;
|
|
|
|
lpTV_ITEM->iImage = GetIcon( lpifq, flags );
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
flags = SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_OPENICON;
|
|
|
|
lpTV_ITEM->iSelectedImage = GetIcon( lpifq, flags );
|
2003-06-06 20:09:38 +02:00
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
if (pidlDesktop)
|
|
|
|
ILFree( pidlDesktop );
|
1999-01-26 11:30:55 +01:00
|
|
|
}
|
|
|
|
|
2005-03-01 12:45:32 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* GetName [Internal]
|
|
|
|
*
|
2014-02-07 22:42:49 +01:00
|
|
|
* Query a shell folder for the display name of one of its children
|
2005-03-01 12:45:32 +01: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
|
|
|
|
*/
|
2003-09-02 03:01:06 +02:00
|
|
|
static BOOL GetName(LPSHELLFOLDER lpsf, LPCITEMIDLIST lpi, DWORD dwFlags, LPWSTR lpFriendlyName)
|
1999-01-26 11:30:55 +01:00
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL bSuccess=TRUE;
|
1999-01-26 11:30:55 +01:00
|
|
|
STRRET str;
|
|
|
|
|
2006-10-07 20:18:14 +02:00
|
|
|
TRACE("%p %p %x %p\n", lpsf, lpi, dwFlags, lpFriendlyName);
|
1999-03-14 13:16:21 +01:00
|
|
|
if (SUCCEEDED(IShellFolder_GetDisplayNameOf(lpsf, lpi, dwFlags, &str)))
|
2006-01-20 20:17:07 +01:00
|
|
|
bSuccess = StrRetToStrNW(lpFriendlyName, MAX_PATH, &str, lpi);
|
1999-01-26 11:30:55 +01:00
|
|
|
else
|
|
|
|
bSuccess = FALSE;
|
|
|
|
|
2002-12-13 01:30:30 +01:00
|
|
|
TRACE("-- %s\n", debugstr_w(lpFriendlyName));
|
1999-01-26 11:30:55 +01:00
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
2005-03-01 12:45:32 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* InsertTreeViewItem [Internal]
|
|
|
|
*
|
|
|
|
* PARAMS
|
2005-05-04 11:48:15 +02:00
|
|
|
* info [I] data for the dialog
|
2005-03-01 12:45:32 +01:00
|
|
|
* lpsf [I] IShellFolder interface of the item's parent shell folder
|
2008-01-16 12:20:50 +01:00
|
|
|
* pidl [I] ITEMIDLIST of the child to insert, relative to parent
|
2005-03-01 12:45:32 +01:00
|
|
|
* 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
|
|
|
|
*/
|
2005-05-04 11:48:15 +02:00
|
|
|
static HTREEITEM InsertTreeViewItem( browse_info *info, IShellFolder * lpsf,
|
|
|
|
LPCITEMIDLIST pidl, LPCITEMIDLIST pidlParent, IEnumIDList* pEnumIL,
|
|
|
|
HTREEITEM hParent)
|
1999-01-26 11:30:55 +01:00
|
|
|
{
|
2002-12-13 01:30:30 +01:00
|
|
|
TVITEMW tvi;
|
|
|
|
TVINSERTSTRUCTW tvins;
|
|
|
|
WCHAR szBuff[MAX_PATH];
|
2003-06-06 20:09:38 +02:00
|
|
|
LPTV_ITEMDATA lptvid=0;
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2003-06-06 20:09:38 +02:00
|
|
|
tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2003-06-06 20:09:38 +02:00
|
|
|
tvi.cChildren= pEnumIL ? 1 : 0;
|
|
|
|
tvi.mask |= TVIF_CHILDREN;
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2012-10-28 16:17:01 +01:00
|
|
|
if (!GetName(lpsf, pidl, SHGDN_NORMAL, szBuff))
|
2003-06-06 20:09:38 +02:00
|
|
|
return NULL;
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2012-10-28 16:17:01 +01:00
|
|
|
lptvid = SHAlloc( sizeof(TV_ITEMDATA) );
|
|
|
|
if (!lptvid)
|
2003-06-06 20:09:38 +02:00
|
|
|
return NULL;
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2003-06-06 20:09:38 +02:00
|
|
|
tvi.pszText = szBuff;
|
|
|
|
tvi.cchTextMax = MAX_PATH;
|
|
|
|
tvi.lParam = (LPARAM)lptvid;
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2003-06-06 20:09:38 +02:00
|
|
|
IShellFolder_AddRef(lpsf);
|
|
|
|
lptvid->lpsfParent = lpsf;
|
|
|
|
lptvid->lpi = ILClone(pidl);
|
|
|
|
lptvid->lpifq = pidlParent ? ILCombine(pidlParent, pidl) : ILClone(pidl);
|
|
|
|
lptvid->pEnumIL = pEnumIL;
|
|
|
|
GetNormalAndSelectedIcons(lptvid->lpifq, &tvi);
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2004-01-07 01:47:35 +01:00
|
|
|
tvins.u.item = tvi;
|
2003-06-06 20:09:38 +02:00
|
|
|
tvins.hInsertAfter = NULL;
|
|
|
|
tvins.hParent = hParent;
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2008-01-19 17:54:24 +01:00
|
|
|
return TreeView_InsertItemW( info->hwndTreeView, &tvins );
|
2003-06-06 20:09:38 +02:00
|
|
|
}
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2005-03-01 12:45:32 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* FillTreeView [Internal]
|
|
|
|
*
|
|
|
|
* For each child (given by lpe) of the parent shell folder, which is given by
|
|
|
|
* lpsf and whose PIDL is pidl, insert a treeview-item right under hParent
|
|
|
|
*
|
|
|
|
* PARAMS
|
2005-05-04 11:48:15 +02:00
|
|
|
* info [I] data for the dialog
|
2005-03-01 12:45:32 +01:00
|
|
|
* 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
|
|
|
|
*/
|
2005-05-04 11:48:15 +02:00
|
|
|
static void FillTreeView( browse_info *info, IShellFolder * lpsf,
|
|
|
|
LPITEMIDLIST pidl, HTREEITEM hParent, IEnumIDList* lpe)
|
2003-06-06 20:09:38 +02:00
|
|
|
{
|
2003-09-02 03:01:06 +02:00
|
|
|
LPITEMIDLIST pidlTemp = 0;
|
2003-06-06 20:09:38 +02:00
|
|
|
ULONG ulFetched;
|
|
|
|
HRESULT hr;
|
2005-05-04 11:48:15 +02:00
|
|
|
HWND hwnd = GetParent( info->hwndTreeView );
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2005-09-02 13:32:17 +02:00
|
|
|
TRACE("%p %p %p %p\n",lpsf, pidl, hParent, lpe);
|
2005-03-01 12:45:32 +01:00
|
|
|
|
|
|
|
/* No IEnumIDList -> No children */
|
|
|
|
if (!lpe) return;
|
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
SetCapture( hwnd );
|
|
|
|
SetCursor( LoadCursorA( 0, (LPSTR)IDC_WAIT ) );
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2011-01-19 23:35:25 +01:00
|
|
|
while (S_OK == IEnumIDList_Next(lpe,1,&pidlTemp,&ulFetched))
|
2003-06-06 20:09:38 +02:00
|
|
|
{
|
|
|
|
ULONG ulAttrs = SFGAO_HASSUBFOLDER | SFGAO_FOLDER;
|
|
|
|
IEnumIDList* pEnumIL = NULL;
|
|
|
|
IShellFolder* pSFChild = NULL;
|
2003-09-02 03:01:06 +02:00
|
|
|
IShellFolder_GetAttributesOf(lpsf, 1, (LPCITEMIDLIST*)&pidlTemp, &ulAttrs);
|
2003-06-06 20:09:38 +02:00
|
|
|
if (ulAttrs & SFGAO_FOLDER)
|
|
|
|
{
|
|
|
|
hr = IShellFolder_BindToObject(lpsf,pidlTemp,NULL,&IID_IShellFolder,(LPVOID*)&pSFChild);
|
|
|
|
if (SUCCEEDED(hr))
|
2003-07-02 02:37:16 +02:00
|
|
|
{
|
2005-05-04 11:48:15 +02:00
|
|
|
DWORD flags = BrowseFlagsToSHCONTF(info->lpBrowseInfo->ulFlags);
|
|
|
|
hr = IShellFolder_EnumObjects(pSFChild, hwnd, flags, &pEnumIL);
|
2005-04-22 21:07:00 +02:00
|
|
|
if (hr == S_OK)
|
2003-07-02 02:37:16 +02:00
|
|
|
{
|
2005-05-04 11:48:15 +02:00
|
|
|
if ((IEnumIDList_Skip(pEnumIL, 1) != S_OK) ||
|
|
|
|
FAILED(IEnumIDList_Reset(pEnumIL)))
|
2003-07-02 02:37:16 +02:00
|
|
|
{
|
|
|
|
IEnumIDList_Release(pEnumIL);
|
|
|
|
pEnumIL = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IShellFolder_Release(pSFChild);
|
|
|
|
}
|
1999-01-26 11:30:55 +01:00
|
|
|
}
|
2003-06-06 20:09:38 +02:00
|
|
|
|
2012-11-21 22:17:03 +01:00
|
|
|
if (!InsertTreeViewItem(info, lpsf, pidlTemp, pidl, pEnumIL, hParent))
|
2005-05-04 11:48:15 +02:00
|
|
|
goto done;
|
1999-04-22 18:27:50 +02:00
|
|
|
SHFree(pidlTemp); /* Finally, free the pidl that the shell gave us... */
|
2003-06-06 20:09:38 +02:00
|
|
|
pidlTemp=NULL;
|
1999-01-26 11:30:55 +01:00
|
|
|
}
|
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
done:
|
1999-01-26 11:30:55 +01:00
|
|
|
ReleaseCapture();
|
2003-09-10 05:56:47 +02:00
|
|
|
SetCursor(LoadCursorW(0, (LPWSTR)IDC_ARROW));
|
2006-10-07 03:06:26 +02:00
|
|
|
SHFree(pidlTemp);
|
1999-01-26 11:30:55 +01:00
|
|
|
}
|
|
|
|
|
2003-06-06 20:09:38 +02:00
|
|
|
static inline BOOL PIDLIsType(LPCITEMIDLIST pidl, PIDLTYPE type)
|
|
|
|
{
|
|
|
|
LPPIDLDATA data = _ILGetDataPointer(pidl);
|
|
|
|
if (!data)
|
|
|
|
return FALSE;
|
|
|
|
return (data->type == type);
|
|
|
|
}
|
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
static void BrsFolder_CheckValidSelection( browse_info *info, LPTV_ITEMDATA lptvid )
|
2003-06-06 20:09:38 +02:00
|
|
|
{
|
2005-05-04 11:48:15 +02:00
|
|
|
LPBROWSEINFOW lpBrowseInfo = info->lpBrowseInfo;
|
2003-06-06 20:09:38 +02:00
|
|
|
LPCITEMIDLIST pidl = lptvid->lpi;
|
|
|
|
BOOL bEnabled = TRUE;
|
|
|
|
DWORD dwAttributes;
|
2005-04-28 20:26:58 +02:00
|
|
|
HRESULT r;
|
|
|
|
|
2003-06-06 20:09:38 +02:00
|
|
|
if ((lpBrowseInfo->ulFlags & BIF_BROWSEFORCOMPUTER) &&
|
|
|
|
!PIDLIsType(pidl, PT_COMP))
|
|
|
|
bEnabled = FALSE;
|
|
|
|
if (lpBrowseInfo->ulFlags & BIF_RETURNFSANCESTORS)
|
|
|
|
{
|
|
|
|
dwAttributes = SFGAO_FILESYSANCESTOR | SFGAO_FILESYSTEM;
|
2005-04-28 20:26:58 +02:00
|
|
|
r = IShellFolder_GetAttributesOf(lptvid->lpsfParent, 1,
|
|
|
|
(LPCITEMIDLIST*)&lptvid->lpi, &dwAttributes);
|
2005-11-07 21:11:27 +01:00
|
|
|
if (FAILED(r) || !(dwAttributes & (SFGAO_FILESYSANCESTOR|SFGAO_FILESYSTEM)))
|
2003-06-06 20:09:38 +02:00
|
|
|
bEnabled = FALSE;
|
|
|
|
}
|
2011-07-03 13:55:39 +02:00
|
|
|
|
|
|
|
dwAttributes = SFGAO_FOLDER | SFGAO_FILESYSTEM;
|
|
|
|
r = IShellFolder_GetAttributesOf(lptvid->lpsfParent, 1,
|
|
|
|
(LPCITEMIDLIST*)&lptvid->lpi, &dwAttributes);
|
|
|
|
if (FAILED(r) ||
|
2005-11-07 21:11:27 +01:00
|
|
|
((dwAttributes & (SFGAO_FOLDER|SFGAO_FILESYSTEM)) != (SFGAO_FOLDER|SFGAO_FILESYSTEM)))
|
2011-07-03 13:55:39 +02:00
|
|
|
{
|
|
|
|
if (lpBrowseInfo->ulFlags & BIF_RETURNONLYFSDIRS)
|
2003-06-06 20:09:38 +02:00
|
|
|
bEnabled = FALSE;
|
2011-07-03 13:55:39 +02:00
|
|
|
EnableWindow(GetDlgItem(info->hWnd, IDD_MAKENEWFOLDER), FALSE);
|
2003-06-06 20:09:38 +02:00
|
|
|
}
|
2011-07-03 13:55:39 +02:00
|
|
|
else
|
|
|
|
EnableWindow(GetDlgItem(info->hWnd, IDD_MAKENEWFOLDER), TRUE);
|
|
|
|
|
2009-12-27 23:53:28 +01:00
|
|
|
SendMessageW(info->hWnd, BFFM_ENABLEOK, 0, bEnabled);
|
2003-06-06 20:09:38 +02:00
|
|
|
}
|
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
static LRESULT BrsFolder_Treeview_Delete( browse_info *info, NMTREEVIEWW *pnmtv )
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2005-04-28 20:26:58 +02:00
|
|
|
LPTV_ITEMDATA lptvid = (LPTV_ITEMDATA)pnmtv->itemOld.lParam;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-04-28 20:26:58 +02:00
|
|
|
TRACE("TVN_DELETEITEMA/W %p\n", lptvid);
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2005-04-28 20:26:58 +02:00
|
|
|
IShellFolder_Release(lptvid->lpsfParent);
|
|
|
|
if (lptvid->pEnumIL)
|
|
|
|
IEnumIDList_Release(lptvid->pEnumIL);
|
|
|
|
SHFree(lptvid->lpi);
|
|
|
|
SHFree(lptvid->lpifq);
|
|
|
|
SHFree(lptvid);
|
|
|
|
return 0;
|
|
|
|
}
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
static LRESULT BrsFolder_Treeview_Expand( browse_info *info, NMTREEVIEWW *pnmtv )
|
2005-04-28 20:26:58 +02:00
|
|
|
{
|
|
|
|
IShellFolder *lpsf2 = NULL;
|
|
|
|
LPTV_ITEMDATA lptvid = (LPTV_ITEMDATA) pnmtv->itemNew.lParam;
|
|
|
|
HRESULT r;
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2005-04-28 20:26:58 +02:00
|
|
|
TRACE("TVN_ITEMEXPANDINGA/W\n");
|
|
|
|
|
|
|
|
if ((pnmtv->itemNew.state & TVIS_EXPANDEDONCE))
|
|
|
|
return 0;
|
|
|
|
|
2010-08-02 14:33:40 +02:00
|
|
|
if (!_ILIsEmpty(lptvid->lpi)) {
|
2005-06-06 12:04:15 +02:00
|
|
|
r = IShellFolder_BindToObject( lptvid->lpsfParent, lptvid->lpi, 0,
|
2011-01-19 23:35:25 +01:00
|
|
|
&IID_IShellFolder, (void**)&lpsf2 );
|
2005-06-06 12:04:15 +02:00
|
|
|
} else {
|
|
|
|
lpsf2 = lptvid->lpsfParent;
|
2011-01-19 23:35:25 +01:00
|
|
|
IShellFolder_AddRef(lpsf2);
|
|
|
|
r = S_OK;
|
2005-06-06 12:04:15 +02:00
|
|
|
}
|
|
|
|
|
2005-04-28 20:26:58 +02:00
|
|
|
if (SUCCEEDED(r))
|
2011-01-19 23:35:25 +01:00
|
|
|
{
|
2005-05-04 11:48:15 +02:00
|
|
|
FillTreeView( info, lpsf2, lptvid->lpifq, pnmtv->itemNew.hItem, lptvid->pEnumIL);
|
2011-01-19 23:35:25 +01:00
|
|
|
IShellFolder_Release( lpsf2 );
|
|
|
|
}
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2005-04-28 20:26:58 +02:00
|
|
|
/* My Computer is already sorted and trying to do a simple text
|
|
|
|
* sort will only mess things up */
|
|
|
|
if (!_ILIsMyComputer(lptvid->lpi))
|
2006-03-03 04:28:14 +01:00
|
|
|
SendMessageW( info->hwndTreeView, TVM_SORTCHILDREN,
|
|
|
|
FALSE, (LPARAM)pnmtv->itemNew.hItem );
|
2005-04-28 20:26:58 +02:00
|
|
|
|
|
|
|
return 0;
|
1999-01-26 11:30:55 +01:00
|
|
|
}
|
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
static HRESULT BrsFolder_Treeview_Changed( browse_info *info, NMTREEVIEWW *pnmtv )
|
2005-04-28 20:26:58 +02:00
|
|
|
{
|
|
|
|
LPTV_ITEMDATA lptvid = (LPTV_ITEMDATA) pnmtv->itemNew.lParam;
|
2011-07-03 13:55:27 +02:00
|
|
|
WCHAR name[MAX_PATH];
|
2005-04-28 20:26:58 +02:00
|
|
|
|
2011-05-03 13:07:02 +02:00
|
|
|
ILFree(info->pidlRet);
|
|
|
|
info->pidlRet = ILClone(lptvid->lpifq);
|
2011-07-03 13:55:27 +02:00
|
|
|
|
|
|
|
if (GetName(lptvid->lpsfParent, lptvid->lpi, SHGDN_NORMAL, name))
|
|
|
|
SetWindowTextW( GetDlgItem(info->hWnd, IDD_FOLDERTEXT), name );
|
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
browsefolder_callback( info->lpBrowseInfo, info->hWnd, BFFM_SELCHANGED,
|
|
|
|
(LPARAM)info->pidlRet );
|
|
|
|
BrsFolder_CheckValidSelection( info, lptvid );
|
2012-06-20 09:11:27 +02:00
|
|
|
return S_OK;
|
2005-04-28 20:26:58 +02:00
|
|
|
}
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2011-07-03 14:42:26 +02:00
|
|
|
static LRESULT BrsFolder_Treeview_Rename(browse_info *info, NMTVDISPINFOW *pnmtv)
|
|
|
|
{
|
|
|
|
LPTV_ITEMDATA item_data;
|
|
|
|
WCHAR old_path[MAX_PATH], new_path[MAX_PATH], *p;
|
|
|
|
NMTREEVIEWW nmtv;
|
|
|
|
TVITEMW item;
|
|
|
|
|
|
|
|
if(!pnmtv->item.pszText)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
item.mask = TVIF_HANDLE|TVIF_PARAM;
|
|
|
|
item.hItem = (HTREEITEM)SendMessageW(info->hwndTreeView, TVM_GETNEXTITEM, TVGN_CARET, 0);
|
|
|
|
SendMessageW(info->hwndTreeView, TVM_GETITEMW, 0, (LPARAM)&item);
|
|
|
|
item_data = (LPTV_ITEMDATA)item.lParam;
|
|
|
|
|
|
|
|
SHGetPathFromIDListW(item_data->lpifq, old_path);
|
|
|
|
if(!(p = strrchrW(old_path, '\\')))
|
|
|
|
return 0;
|
|
|
|
p = new_path+(p-old_path+1);
|
|
|
|
memcpy(new_path, old_path, (p-new_path)*sizeof(WCHAR));
|
|
|
|
strcpyW(p, pnmtv->item.pszText);
|
|
|
|
|
|
|
|
if(!MoveFileW(old_path, new_path))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
SHFree(item_data->lpifq);
|
|
|
|
SHFree(item_data->lpi);
|
|
|
|
item_data->lpifq = SHSimpleIDListFromPathW(new_path);
|
|
|
|
IShellFolder_ParseDisplayName(item_data->lpsfParent, NULL, NULL,
|
|
|
|
pnmtv->item.pszText, NULL, &item_data->lpi, NULL);
|
|
|
|
|
|
|
|
item.mask = TVIF_HANDLE|TVIF_TEXT;
|
|
|
|
item.pszText = pnmtv->item.pszText;
|
|
|
|
SendMessageW(info->hwndTreeView, TVM_SETITEMW, 0, (LPARAM)&item);
|
|
|
|
|
|
|
|
nmtv.itemNew.lParam = item.lParam;
|
|
|
|
BrsFolder_Treeview_Changed(info, &nmtv);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-14 22:01:40 +02:00
|
|
|
static HRESULT BrsFolder_Rename(browse_info *info, HTREEITEM rename)
|
|
|
|
{
|
|
|
|
SendMessageW(info->hwndTreeView, TVM_SELECTITEM, TVGN_CARET, (LPARAM)rename);
|
|
|
|
SendMessageW(info->hwndTreeView, TVM_EDITLABELW, 0, (LPARAM)rename);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT BrsFolder_Treeview_Keydown(browse_info *info, LPNMTVKEYDOWN keydown)
|
|
|
|
{
|
|
|
|
HTREEITEM selected_item;
|
|
|
|
|
|
|
|
/* Old dialog doesn't support those advanced features */
|
|
|
|
if (!(info->lpBrowseInfo->ulFlags & BIF_NEWDIALOGSTYLE))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
selected_item = (HTREEITEM)SendMessageW(info->hwndTreeView, TVM_GETNEXTITEM, TVGN_CARET, 0);
|
|
|
|
|
|
|
|
switch (keydown->wVKey)
|
|
|
|
{
|
|
|
|
case VK_F2:
|
|
|
|
BrsFolder_Rename(info, selected_item);
|
|
|
|
break;
|
2018-09-14 22:01:41 +02:00
|
|
|
case VK_DELETE:
|
|
|
|
{
|
|
|
|
const ITEMIDLIST *item_id;
|
|
|
|
ISFHelper *psfhlp;
|
|
|
|
HRESULT hr;
|
|
|
|
TVITEMW item;
|
|
|
|
TV_ITEMDATA *item_data;
|
|
|
|
|
|
|
|
item.mask = TVIF_PARAM;
|
|
|
|
item.hItem = selected_item;
|
|
|
|
SendMessageW(info->hwndTreeView, TVM_GETITEMW, 0, (LPARAM)&item);
|
|
|
|
item_data = (TV_ITEMDATA *)item.lParam;
|
|
|
|
item_id = item_data->lpi;
|
|
|
|
|
|
|
|
hr = IShellFolder_QueryInterface(item_data->lpsfParent, &IID_ISFHelper, (void**)&psfhlp);
|
|
|
|
if(FAILED(hr))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* perform the item deletion - tree view gets updated over shell notification */
|
|
|
|
ISFHelper_DeleteItems(psfhlp, 1, &item_id);
|
|
|
|
ISFHelper_Release(psfhlp);
|
|
|
|
}
|
|
|
|
break;
|
2018-09-14 22:01:40 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
static LRESULT BrsFolder_OnNotify( browse_info *info, UINT CtlID, LPNMHDR lpnmh )
|
2002-08-14 23:03:55 +02:00
|
|
|
{
|
2005-04-28 20:26:58 +02:00
|
|
|
NMTREEVIEWW *pnmtv = (NMTREEVIEWW *)lpnmh;
|
2000-08-25 23:33:23 +02:00
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
TRACE("%p %x %p msg=%x\n", info, CtlID, lpnmh, pnmtv->hdr.code);
|
2000-08-25 23:33:23 +02:00
|
|
|
|
2005-04-28 20:26:58 +02:00
|
|
|
if (pnmtv->hdr.idFrom != IDD_TREEVIEW)
|
|
|
|
return 0;
|
2000-08-25 23:33:23 +02:00
|
|
|
|
2005-04-28 20:26:58 +02:00
|
|
|
switch (pnmtv->hdr.code)
|
|
|
|
{
|
|
|
|
case TVN_DELETEITEMA:
|
|
|
|
case TVN_DELETEITEMW:
|
2005-05-04 11:48:15 +02:00
|
|
|
return BrsFolder_Treeview_Delete( info, pnmtv );
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2005-04-28 20:26:58 +02:00
|
|
|
case TVN_ITEMEXPANDINGA:
|
|
|
|
case TVN_ITEMEXPANDINGW:
|
2005-05-04 11:48:15 +02:00
|
|
|
return BrsFolder_Treeview_Expand( info, pnmtv );
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-04-28 20:26:58 +02:00
|
|
|
case TVN_SELCHANGEDA:
|
|
|
|
case TVN_SELCHANGEDW:
|
2005-05-04 11:48:15 +02:00
|
|
|
return BrsFolder_Treeview_Changed( info, pnmtv );
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2011-07-03 14:42:26 +02:00
|
|
|
case TVN_ENDLABELEDITA:
|
|
|
|
case TVN_ENDLABELEDITW:
|
|
|
|
return BrsFolder_Treeview_Rename( info, (LPNMTVDISPINFOW)pnmtv );
|
|
|
|
|
2018-09-14 22:01:40 +02:00
|
|
|
case TVN_KEYDOWN:
|
|
|
|
return BrsFolder_Treeview_Keydown( info, (LPNMTVKEYDOWN)pnmtv );
|
|
|
|
|
2005-04-28 20:26:58 +02:00
|
|
|
default:
|
|
|
|
WARN("unhandled (%d)\n", pnmtv->hdr.code);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
static BOOL BrsFolder_OnCreate( HWND hWnd, browse_info *info )
|
2005-04-28 20:26:58 +02:00
|
|
|
{
|
2018-09-14 22:01:41 +02:00
|
|
|
LPITEMIDLIST computer_pidl;
|
|
|
|
SHChangeNotifyEntry ntreg;
|
2005-05-04 11:48:15 +02:00
|
|
|
LPBROWSEINFOW lpBrowseInfo = info->lpBrowseInfo;
|
|
|
|
|
|
|
|
info->hWnd = hWnd;
|
|
|
|
SetPropW( hWnd, szBrowseFolderInfo, info );
|
2005-04-28 20:26:58 +02:00
|
|
|
|
2007-06-07 23:55:09 +02:00
|
|
|
if (lpBrowseInfo->ulFlags & BIF_NEWDIALOGSTYLE)
|
|
|
|
FIXME("flags BIF_NEWDIALOGSTYLE partially implemented\n");
|
2005-04-28 20:26:58 +02:00
|
|
|
if (lpBrowseInfo->ulFlags & ~SUPPORTEDFLAGS)
|
|
|
|
FIXME("flags %x not implemented\n", lpBrowseInfo->ulFlags & ~SUPPORTEDFLAGS);
|
|
|
|
|
2008-07-07 12:05:02 +02:00
|
|
|
if (lpBrowseInfo->ulFlags & BIF_NEWDIALOGSTYLE)
|
|
|
|
{
|
|
|
|
RECT rcWnd;
|
|
|
|
|
2018-03-19 08:11:27 +01:00
|
|
|
info->layout = LayoutInit(hWnd, g_layout_info, ARRAY_SIZE(g_layout_info));
|
2008-07-07 12:05:02 +02:00
|
|
|
|
|
|
|
/* TODO: Windows allows shrinking the windows a bit */
|
|
|
|
GetWindowRect(hWnd, &rcWnd);
|
|
|
|
info->szMin.cx = rcWnd.right - rcWnd.left;
|
|
|
|
info->szMin.cy = rcWnd.bottom - rcWnd.top;
|
|
|
|
}
|
2008-07-09 02:49:13 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
info->layout = NULL;
|
|
|
|
}
|
2008-07-07 12:05:02 +02:00
|
|
|
|
2005-04-28 20:26:58 +02:00
|
|
|
if (lpBrowseInfo->lpszTitle)
|
|
|
|
SetWindowTextW( GetDlgItem(hWnd, IDD_TITLE), lpBrowseInfo->lpszTitle );
|
|
|
|
else
|
|
|
|
ShowWindow( GetDlgItem(hWnd, IDD_TITLE), SW_HIDE );
|
|
|
|
|
2007-06-07 23:55:09 +02:00
|
|
|
if (!(lpBrowseInfo->ulFlags & BIF_STATUSTEXT)
|
|
|
|
|| (lpBrowseInfo->ulFlags & BIF_NEWDIALOGSTYLE))
|
2005-04-28 20:26:58 +02:00
|
|
|
ShowWindow( GetDlgItem(hWnd, IDD_STATUS), SW_HIDE );
|
|
|
|
|
2007-06-07 23:55:09 +02:00
|
|
|
/* Hide "Make New Folder" Button? */
|
|
|
|
if ((lpBrowseInfo->ulFlags & BIF_NONEWFOLDERBUTTON)
|
|
|
|
|| !(lpBrowseInfo->ulFlags & BIF_NEWDIALOGSTYLE))
|
|
|
|
ShowWindow( GetDlgItem(hWnd, IDD_MAKENEWFOLDER), SW_HIDE );
|
|
|
|
|
|
|
|
/* Hide the editbox? */
|
|
|
|
if (!(lpBrowseInfo->ulFlags & BIF_EDITBOX))
|
|
|
|
{
|
|
|
|
ShowWindow( GetDlgItem(hWnd, IDD_FOLDER), SW_HIDE );
|
|
|
|
ShowWindow( GetDlgItem(hWnd, IDD_FOLDERTEXT), SW_HIDE );
|
|
|
|
}
|
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
info->hwndTreeView = GetDlgItem( hWnd, IDD_TREEVIEW );
|
|
|
|
if (info->hwndTreeView)
|
2007-06-07 23:55:09 +02:00
|
|
|
{
|
2005-05-04 11:48:15 +02:00
|
|
|
InitializeTreeView( info );
|
2007-06-07 23:55:09 +02:00
|
|
|
|
|
|
|
/* Resize the treeview if there's not editbox */
|
|
|
|
if ((lpBrowseInfo->ulFlags & BIF_NEWDIALOGSTYLE)
|
|
|
|
&& !(lpBrowseInfo->ulFlags & BIF_EDITBOX))
|
|
|
|
{
|
|
|
|
RECT rc;
|
|
|
|
GetClientRect(info->hwndTreeView, &rc);
|
|
|
|
SetWindowPos(info->hwndTreeView, HWND_TOP, 0, 0,
|
|
|
|
rc.right, rc.bottom + 40, SWP_NOMOVE);
|
|
|
|
}
|
|
|
|
}
|
2005-05-04 11:48:15 +02:00
|
|
|
else
|
|
|
|
ERR("treeview control missing!\n");
|
2005-04-28 20:26:58 +02:00
|
|
|
|
2018-09-14 22:01:41 +02:00
|
|
|
/* Register for change notifications */
|
|
|
|
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);
|
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
browsefolder_callback( info->lpBrowseInfo, hWnd, BFFM_INITIALIZED, 0 );
|
2005-04-28 20:26:58 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-07-03 13:55:39 +02:00
|
|
|
static HRESULT BrsFolder_NewFolder(browse_info *info)
|
|
|
|
{
|
|
|
|
DWORD flags = BrowseFlagsToSHCONTF(info->lpBrowseInfo->ulFlags);
|
|
|
|
IShellFolder *desktop, *cur;
|
|
|
|
ISFHelper *sfhelper;
|
|
|
|
WCHAR name[MAX_PATH];
|
|
|
|
HTREEITEM parent, added;
|
|
|
|
LPTV_ITEMDATA item_data;
|
|
|
|
LPITEMIDLIST new_item;
|
|
|
|
TVITEMW item;
|
|
|
|
HRESULT hr;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if(!info->pidlRet) {
|
|
|
|
ERR("Make new folder button should be disabled\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create new directory */
|
|
|
|
hr = SHGetDesktopFolder(&desktop);
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
hr = IShellFolder_BindToObject(desktop, info->pidlRet, 0, &IID_IShellFolder, (void**)&cur);
|
|
|
|
IShellFolder_Release(desktop);
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = IShellFolder_QueryInterface(cur, &IID_ISFHelper, (void**)&sfhelper);
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2015-10-20 15:44:49 +02:00
|
|
|
if(!SHGetPathFromIDListW(info->pidlRet, name)) {
|
|
|
|
hr = E_FAIL;
|
2011-07-03 13:55:39 +02:00
|
|
|
goto cleanup;
|
2015-10-20 15:44:49 +02:00
|
|
|
}
|
2011-07-03 13:55:39 +02:00
|
|
|
|
|
|
|
len = strlenW(name);
|
|
|
|
if(len<MAX_PATH)
|
|
|
|
name[len++] = '\\';
|
|
|
|
hr = ISFHelper_GetUniqueName(sfhelper, &name[len], MAX_PATH-len);
|
|
|
|
ISFHelper_Release(sfhelper);
|
|
|
|
if(FAILED(hr))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
hr = E_FAIL;
|
|
|
|
if(!CreateDirectoryW(name, NULL))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Update parent of newly created directory */
|
|
|
|
parent = (HTREEITEM)SendMessageW(info->hwndTreeView, TVM_GETNEXTITEM, TVGN_CARET, 0);
|
|
|
|
if(!parent)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
SendMessageW(info->hwndTreeView, TVM_EXPAND, TVE_EXPAND, (LPARAM)parent);
|
|
|
|
|
|
|
|
memset(&item, 0, sizeof(TVITEMW));
|
|
|
|
item.mask = TVIF_PARAM|TVIF_STATE;
|
|
|
|
item.hItem = parent;
|
|
|
|
SendMessageW(info->hwndTreeView, TVM_GETITEMW, 0, (LPARAM)&item);
|
|
|
|
item_data = (LPTV_ITEMDATA)item.lParam;
|
|
|
|
if(!item_data)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if(item_data->pEnumIL)
|
|
|
|
IEnumIDList_Release(item_data->pEnumIL);
|
|
|
|
hr = IShellFolder_EnumObjects(cur, info->hwndTreeView, flags, &item_data->pEnumIL);
|
|
|
|
if(FAILED(hr))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Update treeview */
|
|
|
|
if(!(item.state&TVIS_EXPANDEDONCE)) {
|
|
|
|
item.mask = TVIF_STATE;
|
|
|
|
item.state = TVIS_EXPANDEDONCE;
|
|
|
|
item.stateMask = TVIS_EXPANDEDONCE;
|
|
|
|
SendMessageW(info->hwndTreeView, TVM_SETITEMW, 0, (LPARAM)&item);
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IShellFolder_ParseDisplayName(cur, NULL, NULL, name+len, NULL, &new_item, NULL);
|
|
|
|
if(FAILED(hr))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
added = InsertTreeViewItem(info, cur, new_item, item_data->lpifq, NULL, parent);
|
|
|
|
IShellFolder_Release(cur);
|
|
|
|
SHFree(new_item);
|
|
|
|
|
|
|
|
SendMessageW(info->hwndTreeView, TVM_SORTCHILDREN, FALSE, (LPARAM)parent);
|
|
|
|
return BrsFolder_Rename(info, added);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
static BOOL BrsFolder_OnCommand( browse_info *info, UINT id )
|
2005-04-28 20:26:58 +02:00
|
|
|
{
|
2005-05-04 11:48:15 +02:00
|
|
|
LPBROWSEINFOW lpBrowseInfo = info->lpBrowseInfo;
|
|
|
|
|
2005-04-28 20:26:58 +02:00
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case IDOK:
|
2007-02-09 16:53:24 +01:00
|
|
|
if (info->pidlRet == NULL) /* A null pidl would mean a cancel */
|
|
|
|
info->pidlRet = _ILCreateDesktop();
|
2005-05-04 11:48:15 +02:00
|
|
|
pdump( info->pidlRet );
|
2005-04-28 20:26:58 +02:00
|
|
|
if (lpBrowseInfo->pszDisplayName)
|
2005-05-04 11:48:15 +02:00
|
|
|
SHGetPathFromIDListW( info->pidlRet, lpBrowseInfo->pszDisplayName );
|
|
|
|
EndDialog( info->hWnd, 1 );
|
2005-04-28 20:26:58 +02:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case IDCANCEL:
|
2005-05-04 11:48:15 +02:00
|
|
|
EndDialog( info->hWnd, 0 );
|
2005-04-28 20:26:58 +02:00
|
|
|
return TRUE;
|
2007-06-07 23:55:09 +02:00
|
|
|
|
|
|
|
case IDD_MAKENEWFOLDER:
|
2011-07-03 13:55:39 +02:00
|
|
|
BrsFolder_NewFolder(info);
|
2007-06-07 23:55:09 +02:00
|
|
|
return TRUE;
|
2005-04-28 20:26:58 +02:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-05-09 22:24:58 +02:00
|
|
|
static BOOL BrsFolder_OnSetExpanded(browse_info *info, LPVOID selection,
|
|
|
|
BOOL is_str, HTREEITEM *pItem)
|
|
|
|
{
|
2009-02-18 22:46:39 +01:00
|
|
|
LPITEMIDLIST pidlSelection = selection;
|
2006-05-09 22:24:58 +02:00
|
|
|
LPCITEMIDLIST pidlCurrent, pidlRoot;
|
|
|
|
TVITEMEXW item;
|
|
|
|
BOOL bResult = FALSE;
|
2011-07-07 23:40:34 +02:00
|
|
|
|
|
|
|
memset(&item, 0, sizeof(item));
|
|
|
|
|
2006-05-09 22:24:58 +02:00
|
|
|
/* 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,
|
2009-02-18 22:46:39 +01:00
|
|
|
selection, NULL, &pidlSelection, NULL);
|
2006-05-09 22:24:58 +02:00
|
|
|
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. */
|
|
|
|
item.mask = TVIF_PARAM;
|
2009-05-13 21:54:37 +02:00
|
|
|
item.hItem = (HTREEITEM)SendMessageW(info->hwndTreeView, TVM_GETNEXTITEM, TVGN_ROOT, 0);
|
|
|
|
|
|
|
|
if (item.hItem)
|
|
|
|
item.hItem = (HTREEITEM)SendMessageW(info->hwndTreeView, TVM_GETNEXTITEM, TVGN_CHILD,
|
|
|
|
(LPARAM)item.hItem);
|
2006-05-09 22:24:58 +02:00
|
|
|
|
|
|
|
/* Walk the tree along the nodes corresponding to the remaining ITEMIDLIST */
|
|
|
|
while (item.hItem && !_ILIsEmpty(pidlCurrent)) {
|
|
|
|
LPTV_ITEMDATA pItemData;
|
|
|
|
|
2006-07-13 15:50:20 +02:00
|
|
|
SendMessageW(info->hwndTreeView, TVM_GETITEMW, 0, (LPARAM)&item);
|
2006-05-09 22:24:58 +02:00
|
|
|
pItemData = (LPTV_ITEMDATA)item.lParam;
|
|
|
|
|
|
|
|
if (_ILIsEqualSimple(pItemData->lpi, pidlCurrent)) {
|
|
|
|
pidlCurrent = ILGetNext(pidlCurrent);
|
|
|
|
if (!_ILIsEmpty(pidlCurrent)) {
|
2014-02-07 22:42:49 +01:00
|
|
|
/* Only expand current node and move on to its first child,
|
2006-05-09 22:24:58 +02:00
|
|
|
* if we didn't already reach the last SHITEMID */
|
2006-07-13 15:50:20 +02:00
|
|
|
SendMessageW(info->hwndTreeView, TVM_EXPAND, TVE_EXPAND, (LPARAM)item.hItem);
|
2009-05-13 21:54:37 +02:00
|
|
|
item.hItem = (HTREEITEM)SendMessageW(info->hwndTreeView, TVM_GETNEXTITEM, TVGN_CHILD,
|
|
|
|
(LPARAM)item.hItem);
|
2006-05-09 22:24:58 +02:00
|
|
|
}
|
|
|
|
} else {
|
2009-05-13 21:54:37 +02:00
|
|
|
item.hItem = (HTREEITEM)SendMessageW(info->hwndTreeView, TVM_GETNEXTITEM, TVGN_NEXT,
|
|
|
|
(LPARAM)item.hItem);
|
2006-05-09 22:24:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_ILIsEmpty(pidlCurrent) && item.hItem)
|
|
|
|
bResult = TRUE;
|
|
|
|
|
|
|
|
done:
|
2009-02-18 22:46:39 +01:00
|
|
|
if (pidlSelection && pidlSelection != selection)
|
2006-05-09 22:24:58 +02:00
|
|
|
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;
|
|
|
|
|
2011-04-28 22:31:31 +02:00
|
|
|
if (!selection) return FALSE;
|
|
|
|
|
2006-05-09 22:24:58 +02:00
|
|
|
bResult = BrsFolder_OnSetExpanded(info, selection, is_str, &hItem);
|
|
|
|
if (bResult)
|
2006-07-13 15:50:20 +02:00
|
|
|
SendMessageW(info->hwndTreeView, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hItem );
|
2006-05-09 22:24:58 +02:00
|
|
|
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);
|
2009-02-18 22:46:39 +01:00
|
|
|
|
|
|
|
if ((length = MultiByteToWideChar(CP_ACP, 0, selection, -1, NULL, 0)) &&
|
2018-02-22 08:43:28 +01:00
|
|
|
(selectionW = heap_alloc(length * sizeof(WCHAR))) &&
|
2009-02-18 22:46:39 +01:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, selection, -1, selectionW, length))
|
2006-05-09 22:24:58 +02:00
|
|
|
{
|
|
|
|
result = BrsFolder_OnSetSelectionW(info, selectionW, is_str);
|
|
|
|
}
|
|
|
|
|
2018-02-22 08:43:28 +01:00
|
|
|
heap_free(selectionW);
|
2006-05-09 22:24:58 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-01-10 19:54:34 +01:00
|
|
|
static LRESULT BrsFolder_OnWindowPosChanging(browse_info *info, WINDOWPOS *pos)
|
2008-07-07 12:05:02 +02:00
|
|
|
{
|
|
|
|
if ((info->lpBrowseInfo->ulFlags & BIF_NEWDIALOGSTYLE) && !(pos->flags & SWP_NOSIZE))
|
|
|
|
{
|
|
|
|
if (pos->cx < info->szMin.cx)
|
|
|
|
pos->cx = info->szMin.cx;
|
|
|
|
if (pos->cy < info->szMin.cy)
|
|
|
|
pos->cy = info->szMin.cy;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-29 20:54:29 +01:00
|
|
|
static INT BrsFolder_OnDestroy(browse_info *info)
|
|
|
|
{
|
|
|
|
if (info->layout)
|
|
|
|
{
|
|
|
|
SHFree(info->layout);
|
|
|
|
info->layout = NULL;
|
|
|
|
}
|
|
|
|
|
2018-09-14 22:01:41 +02:00
|
|
|
SHChangeNotifyDeregister(info->hNotify);
|
|
|
|
|
2009-01-29 20:54:29 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-14 22:01:41 +02:00
|
|
|
/* Find a treeview node by recursively walking the treeview */
|
|
|
|
static HTREEITEM BrsFolder_FindItemByPidl(browse_info *info, LPCITEMIDLIST pidl, HTREEITEM hItem)
|
|
|
|
{
|
|
|
|
TV_ITEMW item;
|
|
|
|
TV_ITEMDATA *item_data;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
item.mask = TVIF_HANDLE | TVIF_PARAM;
|
|
|
|
item.hItem = hItem;
|
|
|
|
SendMessageW(info->hwndTreeView, TVM_GETITEMW, 0, (LPARAM)&item);
|
|
|
|
item_data = (TV_ITEMDATA *)item.lParam;
|
|
|
|
|
|
|
|
hr = IShellFolder_CompareIDs(item_data->lpsfParent, 0, item_data->lpifq, pidl);
|
|
|
|
if(SUCCEEDED(hr) && !HRESULT_CODE(hr))
|
|
|
|
return hItem;
|
|
|
|
|
|
|
|
hItem = (HTREEITEM)SendMessageW(info->hwndTreeView, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem);
|
|
|
|
|
|
|
|
while (hItem)
|
|
|
|
{
|
|
|
|
HTREEITEM newItem = BrsFolder_FindItemByPidl(info, pidl, hItem);
|
|
|
|
if (newItem)
|
|
|
|
return newItem;
|
|
|
|
hItem = (HTREEITEM)SendMessageW(info->hwndTreeView, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)hItem);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT BrsFolder_OnChange(browse_info *info, const LPCITEMIDLIST *pidls, LONG event)
|
|
|
|
{
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p, %p, 0x%08x)\n", info, pidls[0], pidls[1], event);
|
|
|
|
|
|
|
|
switch (event)
|
|
|
|
{
|
|
|
|
case SHCNE_RMDIR:
|
|
|
|
case SHCNE_DELETE:
|
|
|
|
{
|
|
|
|
HTREEITEM handle_root = (HTREEITEM)SendMessageW(info->hwndTreeView, TVM_GETNEXTITEM, TVGN_ROOT, 0);
|
|
|
|
HTREEITEM handle_item = BrsFolder_FindItemByPidl(info, pidls[0], handle_root);
|
|
|
|
|
|
|
|
if (handle_item)
|
|
|
|
SendMessageW(info->hwndTreeView, TVM_DELETEITEM, 0, (LPARAM)handle_item);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-04-28 20:26:58 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* BrsFolderDlgProc32 (not an exported API function)
|
|
|
|
*/
|
|
|
|
static INT_PTR CALLBACK BrsFolderDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
|
|
|
|
LPARAM lParam )
|
|
|
|
{
|
2005-05-04 11:48:15 +02:00
|
|
|
browse_info *info;
|
|
|
|
|
2007-05-24 16:41:17 +02:00
|
|
|
TRACE("hwnd=%p msg=%04x 0x%08lx 0x%08lx\n", hWnd, msg, wParam, lParam );
|
2005-04-28 20:26:58 +02:00
|
|
|
|
|
|
|
if (msg == WM_INITDIALOG)
|
2005-05-04 11:48:15 +02:00
|
|
|
return BrsFolder_OnCreate( hWnd, (browse_info*) lParam );
|
|
|
|
|
2008-11-05 23:00:50 +01:00
|
|
|
info = GetPropW( hWnd, szBrowseFolderInfo );
|
2005-04-28 20:26:58 +02:00
|
|
|
|
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case WM_NOTIFY:
|
2005-05-04 11:48:15 +02:00
|
|
|
return BrsFolder_OnNotify( info, (UINT)wParam, (LPNMHDR)lParam);
|
2005-04-28 20:26:58 +02:00
|
|
|
|
|
|
|
case WM_COMMAND:
|
2005-05-04 11:48:15 +02:00
|
|
|
return BrsFolder_OnCommand( info, wParam );
|
2005-04-28 20:26:58 +02:00
|
|
|
|
2008-07-07 12:05:02 +02:00
|
|
|
case WM_WINDOWPOSCHANGING:
|
|
|
|
return BrsFolder_OnWindowPosChanging( info, (WINDOWPOS *)lParam);
|
|
|
|
|
|
|
|
case WM_SIZE:
|
|
|
|
if (info->layout) /* new style dialogs */
|
2018-03-19 08:11:27 +01:00
|
|
|
LayoutUpdate(hWnd, info->layout, g_layout_info, ARRAY_SIZE(g_layout_info));
|
2008-07-07 12:05:02 +02:00
|
|
|
return 0;
|
|
|
|
|
2005-04-28 20:26:58 +02:00
|
|
|
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);
|
2012-08-13 11:42:29 +02:00
|
|
|
EnableWindow(GetDlgItem(hWnd, 1), lParam != 0);
|
2005-04-28 20:26:58 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BFFM_SETOKTEXT: /* unicode only */
|
2013-11-22 10:35:44 +01:00
|
|
|
TRACE("Set OK text %s\n", debugstr_w((LPWSTR)lParam));
|
|
|
|
SetWindowTextW(GetDlgItem(hWnd, 1), (LPWSTR)lParam);
|
2005-04-28 20:26:58 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BFFM_SETSELECTIONA:
|
2006-05-09 22:24:58 +02:00
|
|
|
return BrsFolder_OnSetSelectionA(info, (LPVOID)lParam, (BOOL)wParam);
|
2005-04-28 20:26:58 +02:00
|
|
|
|
|
|
|
case BFFM_SETSELECTIONW:
|
2006-05-09 22:24:58 +02:00
|
|
|
return BrsFolder_OnSetSelectionW(info, (LPVOID)lParam, (BOOL)wParam);
|
2005-04-28 20:26:58 +02:00
|
|
|
|
|
|
|
case BFFM_SETEXPANDED: /* unicode only */
|
2006-05-09 22:24:58 +02:00
|
|
|
return BrsFolder_OnSetExpanded(info, (LPVOID)lParam, (BOOL)wParam, NULL);
|
2009-01-29 20:54:29 +01:00
|
|
|
|
2018-09-14 22:01:41 +02:00
|
|
|
case SHV_CHANGE_NOTIFY:
|
|
|
|
return BrsFolder_OnChange(info, (const LPCITEMIDLIST*)wParam, (LONG)lParam);
|
|
|
|
|
2009-01-29 20:54:29 +01:00
|
|
|
case WM_DESTROY:
|
|
|
|
return BrsFolder_OnDestroy(info);
|
2005-04-28 20:26:58 +02:00
|
|
|
}
|
|
|
|
return FALSE;
|
1999-01-26 11:30:55 +01:00
|
|
|
}
|
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
static const WCHAR swBrowseTemplateName[] = {
|
2005-04-28 20:26:58 +02:00
|
|
|
'S','H','B','R','S','F','O','R','F','O','L','D','E','R','_','M','S','G','B','O','X',0};
|
2007-06-07 23:55:09 +02:00
|
|
|
static const WCHAR swNewBrowseTemplateName[] = {
|
|
|
|
'S','H','N','E','W','B','R','S','F','O','R','F','O','L','D','E','R','_','M','S','G','B','O','X',0};
|
2002-12-13 01:30:30 +01:00
|
|
|
|
1999-01-26 11:30:55 +01:00
|
|
|
/*************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SHBrowseForFolderA [SHELL32.@]
|
2001-07-11 20:56:41 +02:00
|
|
|
* SHBrowseForFolder [SHELL32.@]
|
1999-01-26 11:30:55 +01:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
LPITEMIDLIST WINAPI SHBrowseForFolderA (LPBROWSEINFOA lpbi)
|
1999-01-26 11:30:55 +01:00
|
|
|
{
|
2005-05-04 11:48:15 +02:00
|
|
|
BROWSEINFOW bi;
|
|
|
|
LPITEMIDLIST lpid;
|
|
|
|
INT len;
|
2006-09-29 00:13:35 +02:00
|
|
|
LPWSTR title;
|
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
TRACE("%p\n", lpbi);
|
2002-12-13 01:30:30 +01:00
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
bi.hwndOwner = lpbi->hwndOwner;
|
|
|
|
bi.pidlRoot = lpbi->pidlRoot;
|
|
|
|
if (lpbi->pszDisplayName)
|
2018-02-22 08:43:28 +01:00
|
|
|
bi.pszDisplayName = heap_alloc( MAX_PATH * sizeof(WCHAR) );
|
2005-05-04 11:48:15 +02:00
|
|
|
else
|
|
|
|
bi.pszDisplayName = NULL;
|
1999-01-26 11:30:55 +01:00
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
if (lpbi->lpszTitle)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, lpbi->lpszTitle, -1, NULL, 0 );
|
2018-02-22 08:43:28 +01:00
|
|
|
title = heap_alloc( len * sizeof(WCHAR) );
|
2006-09-29 00:13:35 +02:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpbi->lpszTitle, -1, title, len );
|
2005-05-04 11:48:15 +02:00
|
|
|
}
|
|
|
|
else
|
2006-09-29 00:13:35 +02:00
|
|
|
title = NULL;
|
2005-05-04 11:48:15 +02:00
|
|
|
|
2006-09-29 00:13:35 +02:00
|
|
|
bi.lpszTitle = title;
|
2005-05-04 11:48:15 +02:00
|
|
|
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);
|
2018-02-22 08:43:28 +01:00
|
|
|
heap_free( bi.pszDisplayName );
|
2005-05-04 11:48:15 +02:00
|
|
|
}
|
2018-02-22 08:43:28 +01:00
|
|
|
heap_free(title);
|
2005-05-04 11:48:15 +02:00
|
|
|
lpbi->iImage = bi.iImage;
|
|
|
|
return lpid;
|
1999-01-26 11:30:55 +01:00
|
|
|
}
|
2002-07-19 02:26:02 +02:00
|
|
|
|
2002-12-13 01:30:30 +01:00
|
|
|
|
2002-07-19 02:26:02 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* SHBrowseForFolderW [SHELL32.@]
|
2005-05-04 11:48:15 +02:00
|
|
|
*
|
2005-11-10 12:15:22 +01:00
|
|
|
* NOTES
|
2005-05-04 11:48:15 +02:00
|
|
|
* crashes when passed a null pointer
|
2002-07-19 02:26:02 +02:00
|
|
|
*/
|
|
|
|
LPITEMIDLIST WINAPI SHBrowseForFolderW (LPBROWSEINFOW lpbi)
|
|
|
|
{
|
2005-05-04 11:48:15 +02:00
|
|
|
browse_info info;
|
|
|
|
DWORD r;
|
2005-11-09 11:30:28 +01:00
|
|
|
HRESULT hr;
|
2007-06-07 23:55:09 +02:00
|
|
|
const WCHAR * templateName;
|
2013-10-17 18:05:28 +02:00
|
|
|
INITCOMMONCONTROLSEX icex;
|
2005-05-04 11:48:15 +02:00
|
|
|
|
|
|
|
info.hWnd = 0;
|
|
|
|
info.pidlRet = NULL;
|
|
|
|
info.lpBrowseInfo = lpbi;
|
|
|
|
info.hwndTreeView = NULL;
|
2002-12-13 01:30:30 +01:00
|
|
|
|
2013-10-17 18:05:28 +02:00
|
|
|
icex.dwSize = sizeof( icex );
|
|
|
|
icex.dwICC = ICC_TREEVIEW_CLASSES;
|
|
|
|
InitCommonControlsEx( &icex );
|
|
|
|
|
2005-11-23 15:15:16 +01:00
|
|
|
hr = OleInitialize(NULL);
|
2007-06-07 23:55:09 +02:00
|
|
|
|
|
|
|
if (lpbi->ulFlags & BIF_NEWDIALOGSTYLE)
|
|
|
|
templateName = swNewBrowseTemplateName;
|
|
|
|
else
|
|
|
|
templateName = swBrowseTemplateName;
|
|
|
|
r = DialogBoxParamW( shell32_hInstance, templateName, lpbi->hwndOwner,
|
2005-05-04 11:48:15 +02:00
|
|
|
BrsFolderDlgProc, (LPARAM)&info );
|
2005-11-09 11:30:28 +01:00
|
|
|
if (SUCCEEDED(hr))
|
2005-11-23 15:15:16 +01:00
|
|
|
OleUninitialize();
|
2005-05-04 11:48:15 +02:00
|
|
|
if (!r)
|
2011-05-03 13:07:02 +02:00
|
|
|
{
|
|
|
|
ILFree(info.pidlRet);
|
2005-05-04 11:48:15 +02:00
|
|
|
return NULL;
|
2011-05-03 13:07:02 +02:00
|
|
|
}
|
2002-12-13 01:30:30 +01:00
|
|
|
|
2005-05-04 11:48:15 +02:00
|
|
|
return info.pidlRet;
|
2002-07-19 02:26:02 +02:00
|
|
|
}
|