ReactOS 0.4.15-dev-7834-g00c4b3d
autocomp.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Common Dialogs
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Implement auto-completion for comdlg32
5 * COPYRIGHT: Copyright 2021 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 */
7#include "precomp.h"
8
10
13{
14 pInfo->pvCWD = pInfo->pvDropDown = pInfo->pvACList = NULL;
15
16 WCHAR szClass[32];
17 GetClassNameW(hwndEdit, szClass, _countof(szClass));
18 if (lstrcmpiW(szClass, WC_COMBOBOXW) == 0)
19 {
20 COMBOBOXINFO info = { sizeof(info) };
22 hwndEdit = info.hwndItem;
23 }
24 else if (lstrcmpiW(szClass, WC_COMBOBOXEXW) == 0)
25 {
27 }
28
29 IACList2 *pACList = NULL;
30 HRESULT hr = CoCreateInstance(CLSID_ACListISF, NULL, CLSCTX_INPROC_SERVER,
31 IID_IACList2, reinterpret_cast<LPVOID *>(&pACList));
32 if (FAILED(hr))
33 {
34 TRACE("CoCreateInstance(CLSID_ACListISF): 0x%08lX\n", hr);
35 return hr;
36 }
37 pInfo->pvACList = static_cast<LPVOID>(pACList);
38
39 IAutoComplete2 *pAC = NULL;
40 hr = CoCreateInstance(CLSID_AutoComplete, NULL, CLSCTX_INPROC_SERVER,
41 IID_IAutoComplete2, reinterpret_cast<LPVOID *>(&pAC));
42 if (SUCCEEDED(hr))
43 {
44 pAC->Init(hwndEdit, pACList, NULL, NULL);
45 pAC->SetOptions(ACO_AUTOSUGGEST);
46 pAC->QueryInterface(IID_IAutoCompleteDropDown, &pInfo->pvDropDown);
47 pAC->Release();
48 }
49 else
50 {
51 TRACE("CoCreateInstance(CLSID_AutoComplete): 0x%08lX\n", hr);
52 pACList->Release();
53 pInfo->pvACList = NULL;
54 return hr;
55 }
56
57 pACList->QueryInterface(IID_ICurrentWorkingDirectory, &pInfo->pvCWD);
58
59 return hr;
60}
61
64{
65 FileOpenDlgInfos *pInfo = const_cast<FileOpenDlgInfos*>(info);
66 if (!pInfo)
67 return E_POINTER;
68
69 ICurrentWorkingDirectory* pCWD =
70 reinterpret_cast<ICurrentWorkingDirectory*>(pInfo->pvCWD);
71
72 IAutoCompleteDropDown* pDropDown =
73 reinterpret_cast<IAutoCompleteDropDown*>(pInfo->pvDropDown);
74
75 IACList2* pACList = static_cast<IACList2*>(pInfo->pvACList);
76
78 if (!pidl || !SHGetPathFromIDListW(pidl, szPath))
79 {
81 }
82
83 if (pCWD)
84 pCWD->SetDirectory(szPath);
85 if (pDropDown)
86 pDropDown->ResetEnumerator();
87 if (pACList)
88 pACList->Expand(L"");
89
90 return S_OK;
91}
92
95{
96 if (!pInfo)
97 return E_POINTER;
98
99 ICurrentWorkingDirectory* pCWD =
100 reinterpret_cast<ICurrentWorkingDirectory*>(pInfo->pvCWD);
101 if (pCWD)
102 pCWD->Release();
103
104 IAutoCompleteDropDown* pDropDown =
105 reinterpret_cast<IAutoCompleteDropDown*>(pInfo->pvDropDown);
106 if (pDropDown)
107 pDropDown->Release();
108
109 IACList2 *pACList = static_cast<IACList2*>(pInfo->pvACList);
110 if (pACList)
111 pACList->Release();
112
113 pInfo->pvCWD = pInfo->pvDropDown = pInfo->pvACList = NULL;
114 return S_OK;
115}
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define EXTERN_C
Definition: basetyps.h:12
HWND hwndEdit
Definition: combotst.c:65
EXTERN_C HRESULT DoInitAutoCompleteWithCWD(FileOpenDlgInfos *pInfo, HWND hwndEdit)
Definition: autocomp.cpp:12
EXTERN_C HRESULT DoUpdateAutoCompleteWithCWD(const FileOpenDlgInfos *info, LPCITEMIDLIST pidl)
Definition: autocomp.cpp:63
EXTERN_C HRESULT DoReleaseAutoCompleteWithCWD(FileOpenDlgInfos *pInfo)
Definition: autocomp.cpp:94
#define NULL
Definition: types.h:112
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:756
HANDLE HWND
Definition: compat.h:19
#define MAX_PATH
Definition: compat.h:34
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
HRESULT SetOptions([in] DWORD dwFlag)
HRESULT Init([in] HWND hwndEdit, [in] IUnknown *punkACL, [in] LPCOLESTR pwszRegKeyPath, [in] LPCOLESTR pwszQuickComplete)
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
ULONG Release()
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
int WINAPI lstrcmpiW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:194
LPCWSTR szPath
Definition: env.c:37
#define L(x)
Definition: ntvdm.h:50
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1344
#define WC_COMBOBOXEXW
Definition: commctrl.h:3781
#define WC_COMBOBOXW
Definition: commctrl.h:4717
#define CBEM_GETEDITCONTROL
Definition: commctrl.h:3833
HRESULT hr
Definition: shlfolder.c:183
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
#define _countof(array)
Definition: sndvol32.h:68
#define TRACE(s)
Definition: solgame.cpp:4
#define E_POINTER
Definition: winerror.h:2365
BOOL WINAPI GetComboBoxInfo(_In_ HWND, _Inout_ PCOMBOBOXINFO)
int WINAPI GetClassNameW(_In_ HWND hWnd, _Out_writes_to_(nMaxCount, return) LPWSTR lpClassName, _In_ int nMaxCount)
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
__wchar_t WCHAR
Definition: xmlstorage.h:180