1 /*
2 * PROJECT: ReactOS shdocvw
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: Utility routines
5 * COPYRIGHT: Copyright 2024 Whindmar Saksit <whindsaks@proton.me>
6 */
7
8 #include "objects.h"
9
10 #include <wine/debug.h>
11 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
12
13 #ifndef SHCIDS_CANONICALONLY
14 #define SHCIDS_CANONICALONLY 0x10000000L
15 #endif
16
17 EXTERN_C HRESULT
SHELL_GetIDListFromObject(IUnknown * punk,PIDLIST_ABSOLUTE * ppidl)18 SHELL_GetIDListFromObject(IUnknown *punk, PIDLIST_ABSOLUTE *ppidl)
19 {
20 #if DLL_EXPORT_VERSION >= _WIN32_WINNT_VISTA && 0 // FIXME: SHELL32 not ready yet
21 return SHGetIDListFromObject(punk, ppidl);
22 #else
23 HRESULT hr;
24 IPersistFolder2 *pf2;
25 if (SUCCEEDED(hr = punk->QueryInterface(IID_PPV_ARG(IPersistFolder2, &pf2))))
26 {
27 hr = pf2->GetCurFolder(ppidl);
28 pf2->Release();
29 }
30 IPersistIDList *pil;
31 if (FAILED(hr) && SUCCEEDED(hr = punk->QueryInterface(IID_PPV_ARG(IPersistIDList, &pil))))
32 {
33 hr = pil->GetIDList(ppidl);
34 pil->Release();
35 }
36 return hr;
37 #endif
38 }
39
SHELL_CompareAbsoluteIDs(LPARAM lParam,PCIDLIST_ABSOLUTE a,PCIDLIST_ABSOLUTE b)40 static HRESULT SHELL_CompareAbsoluteIDs(LPARAM lParam, PCIDLIST_ABSOLUTE a, PCIDLIST_ABSOLUTE b)
41 {
42 IShellFolder *psf;
43 HRESULT hr = SHGetDesktopFolder(&psf);
44 if (FAILED(hr))
45 return hr;
46 hr = psf->CompareIDs(lParam, a, b);
47 psf->Release();
48 return hr;
49 }
50
51 EXTERN_C BOOL
SHELL_IsEqualAbsoluteID(PCIDLIST_ABSOLUTE a,PCIDLIST_ABSOLUTE b)52 SHELL_IsEqualAbsoluteID(PCIDLIST_ABSOLUTE a, PCIDLIST_ABSOLUTE b)
53 {
54 return !SHELL_CompareAbsoluteIDs(SHCIDS_CANONICALONLY, a, b);
55 }
56
57 EXTERN_C BOOL
SHELL_IsVerb(IContextMenu * pcm,UINT_PTR idCmd,LPCWSTR Verb)58 SHELL_IsVerb(IContextMenu *pcm, UINT_PTR idCmd, LPCWSTR Verb)
59 {
60 HRESULT hr;
61 WCHAR wide[MAX_PATH];
62 if (SUCCEEDED(hr = pcm->GetCommandString(idCmd, GCS_VERBW, NULL, (LPSTR)wide, _countof(wide))))
63 return !lstrcmpiW(wide, Verb);
64
65 CHAR ansi[_countof(wide)], buf[MAX_PATH];
66 if (SHUnicodeToAnsi(Verb, buf, _countof(buf)))
67 {
68 if (SUCCEEDED(hr = pcm->GetCommandString(idCmd, GCS_VERBA, NULL, ansi, _countof(ansi))))
69 return !lstrcmpiA(ansi, buf);
70 }
71 return FALSE;
72 }
73
74 EXTERN_C BOOL
_ILIsDesktop(LPCITEMIDLIST pidl)75 _ILIsDesktop(LPCITEMIDLIST pidl)
76 {
77 return (pidl == NULL || pidl->mkid.cb == 0);
78 }
79
80 /*************************************************************************
81 * IEILIsEqual [SHDOCVW.219]
82 */
83 EXTERN_C BOOL WINAPI
IEILIsEqual(_In_ LPCITEMIDLIST pidl1,_In_ LPCITEMIDLIST pidl2,_In_ BOOL bUnknown)84 IEILIsEqual(
85 _In_ LPCITEMIDLIST pidl1,
86 _In_ LPCITEMIDLIST pidl2,
87 _In_ BOOL bUnknown)
88 {
89 UINT cb1 = ILGetSize(pidl1), cb2 = ILGetSize(pidl2);
90 if (cb1 == cb2 && memcmp(pidl1, pidl2, cb1) == 0)
91 return TRUE;
92
93 FIXME("%p, %p\n", pidl1, pidl2);
94 return FALSE;
95 }
96