mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 09:25:10 +00:00
[SHELL32] Simplify CExplorerBand::CompareTreeItems (#7214)
Reduce code. JIRA issue: CORE-19686 - Delete useless _ILIsSpecialFolder and GetDisplayName helper functions. - Simply use IShellFolder::CompareIDs for item comparison.
This commit is contained in:
parent
90de2b660b
commit
e51fddf030
1 changed files with 9 additions and 94 deletions
|
@ -20,51 +20,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
|
||||||
* - TESTING
|
* - TESTING
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct _PIDLDATA
|
|
||||||
{
|
|
||||||
BYTE type;
|
|
||||||
BYTE data[1];
|
|
||||||
} PIDLDATA, *LPPIDLDATA;
|
|
||||||
|
|
||||||
#define PT_GUID 0x1F
|
|
||||||
#define PT_SHELLEXT 0x2E
|
|
||||||
#define PT_YAGUID 0x70
|
|
||||||
|
|
||||||
static BOOL _ILIsSpecialFolder (LPCITEMIDLIST pidl)
|
|
||||||
{
|
|
||||||
LPPIDLDATA lpPData = (LPPIDLDATA)&pidl->mkid.abID;
|
|
||||||
|
|
||||||
return (pidl &&
|
|
||||||
((lpPData && (PT_GUID == lpPData->type || PT_SHELLEXT== lpPData->type ||
|
|
||||||
PT_YAGUID == lpPData->type)) || (pidl && pidl->mkid.cb == 0x00)));
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT GetDisplayName(LPCITEMIDLIST pidlDirectory,TCHAR *szDisplayName,UINT cchMax,DWORD uFlags)
|
|
||||||
{
|
|
||||||
IShellFolder *pShellFolder = NULL;
|
|
||||||
LPCITEMIDLIST pidlRelative = NULL;
|
|
||||||
STRRET str;
|
|
||||||
HRESULT hr;
|
|
||||||
|
|
||||||
if (pidlDirectory == NULL || szDisplayName == NULL)
|
|
||||||
{
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
hr = SHBindToParent(pidlDirectory, IID_PPV_ARG(IShellFolder, &pShellFolder), &pidlRelative);
|
|
||||||
|
|
||||||
if (SUCCEEDED(hr))
|
|
||||||
{
|
|
||||||
hr = pShellFolder->GetDisplayNameOf(pidlRelative,uFlags,&str);
|
|
||||||
if (SUCCEEDED(hr))
|
|
||||||
{
|
|
||||||
hr = StrRetToBuf(&str,pidlDirectory,szDisplayName,cchMax);
|
|
||||||
}
|
|
||||||
pShellFolder->Release();
|
|
||||||
}
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
|
|
||||||
CExplorerBand::CExplorerBand()
|
CExplorerBand::CExplorerBand()
|
||||||
: m_pSite(NULL)
|
: m_pSite(NULL)
|
||||||
, m_fVisible(FALSE)
|
, m_fVisible(FALSE)
|
||||||
|
@ -788,7 +743,7 @@ CExplorerBand::InsertItem(
|
||||||
TVSORTCB sortCallback;
|
TVSORTCB sortCallback;
|
||||||
sortCallback.hParent = hParent;
|
sortCallback.hParent = hParent;
|
||||||
sortCallback.lpfnCompare = CompareTreeItems;
|
sortCallback.lpfnCompare = CompareTreeItems;
|
||||||
sortCallback.lParam = (LPARAM)this;
|
sortCallback.lParam = (LPARAM)(PVOID)m_pDesktop;
|
||||||
SendMessage(TVM_SORTCHILDRENCB, 0, (LPARAM)&sortCallback);
|
SendMessage(TVM_SORTCHILDRENCB, 0, (LPARAM)&sortCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -882,7 +837,7 @@ BOOL CExplorerBand::InsertSubitems(HTREEITEM hItem, NodeInfo *pNodeInfo)
|
||||||
/* Let's do sorting */
|
/* Let's do sorting */
|
||||||
sortCallback.hParent = hItem;
|
sortCallback.hParent = hItem;
|
||||||
sortCallback.lpfnCompare = CompareTreeItems;
|
sortCallback.lpfnCompare = CompareTreeItems;
|
||||||
sortCallback.lParam = (LPARAM)this;
|
sortCallback.lParam = (LPARAM)(PVOID)m_pDesktop;
|
||||||
SendMessage(TVM_SORTCHILDRENCB, 0, (LPARAM)&sortCallback);
|
SendMessage(TVM_SORTCHILDRENCB, 0, (LPARAM)&sortCallback);
|
||||||
|
|
||||||
/* Now we can redraw */
|
/* Now we can redraw */
|
||||||
|
@ -1014,55 +969,15 @@ BOOL CExplorerBand::NavigateToCurrentFolder()
|
||||||
// *** Tree item sorting callback ***
|
// *** Tree item sorting callback ***
|
||||||
int CALLBACK CExplorerBand::CompareTreeItems(LPARAM p1, LPARAM p2, LPARAM p3)
|
int CALLBACK CExplorerBand::CompareTreeItems(LPARAM p1, LPARAM p2, LPARAM p3)
|
||||||
{
|
{
|
||||||
/*
|
NodeInfo *info1 = (NodeInfo*)p1;
|
||||||
* We first sort drive letters (Path root), then PIDLs and then regular folder
|
NodeInfo *info2 = (NodeInfo*)p2;
|
||||||
* display name.
|
IShellFolder *pDesktop = (IShellFolder *)p3;
|
||||||
* This is not how Windows sorts item, but it gives decent results.
|
|
||||||
*/
|
|
||||||
NodeInfo *info1;
|
|
||||||
NodeInfo *info2;
|
|
||||||
CExplorerBand *pThis;
|
|
||||||
WCHAR wszFolder1[MAX_PATH];
|
|
||||||
WCHAR wszFolder2[MAX_PATH];
|
|
||||||
|
|
||||||
info1 = (NodeInfo*)p1;
|
HRESULT hr = pDesktop->CompareIDs(0, info1->absolutePidl, info2->absolutePidl);
|
||||||
info2 = (NodeInfo*)p2;
|
if (FAILED(hr))
|
||||||
pThis = (CExplorerBand*)p3;
|
return 0;
|
||||||
|
|
||||||
GetDisplayName(info1->absolutePidl, wszFolder1, MAX_PATH, SHGDN_FORPARSING);
|
return (SHORT)HRESULT_CODE(hr);
|
||||||
GetDisplayName(info2->absolutePidl, wszFolder2, MAX_PATH, SHGDN_FORPARSING);
|
|
||||||
if (PathIsRoot(wszFolder1) && PathIsRoot(wszFolder2))
|
|
||||||
{
|
|
||||||
return lstrcmpiW(wszFolder1,wszFolder2);
|
|
||||||
}
|
|
||||||
if (PathIsRoot(wszFolder1) && !PathIsRoot(wszFolder2))
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (!PathIsRoot(wszFolder1) && PathIsRoot(wszFolder2))
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
// Now, we compare non-root folders, grab display name
|
|
||||||
GetDisplayName(info1->absolutePidl, wszFolder1, MAX_PATH, SHGDN_INFOLDER);
|
|
||||||
GetDisplayName(info2->absolutePidl, wszFolder2, MAX_PATH, SHGDN_INFOLDER);
|
|
||||||
|
|
||||||
if (_ILIsSpecialFolder(info1->relativePidl) && !_ILIsSpecialFolder(info2->relativePidl))
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (!_ILIsSpecialFolder(info1->relativePidl) && _ILIsSpecialFolder(info2->relativePidl))
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (_ILIsSpecialFolder(info1->relativePidl) && !_ILIsSpecialFolder(info2->relativePidl))
|
|
||||||
{
|
|
||||||
HRESULT hr;
|
|
||||||
hr = pThis->m_pDesktop->CompareIDs(0, info1->absolutePidl, info2->absolutePidl);
|
|
||||||
if (!hr) return 0;
|
|
||||||
return (hr > 0) ? -1 : 1;
|
|
||||||
}
|
|
||||||
return StrCmpLogicalW(wszFolder1, wszFolder2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// *** IOleWindow methods ***
|
// *** IOleWindow methods ***
|
||||||
|
|
Loading…
Reference in a new issue