ReactOS 0.4.15-dev-7924-g5949c20
CAutoComplete.h
Go to the documentation of this file.
1/*
2 * AutoComplete interfaces implementation.
3 *
4 * Copyright 2004 Maxime Bellengé <maxime.bellenge@laposte.net>
5 * Copyright 2009 Andrew Hill
6 * Copyright 2021 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22#pragma once
23
24#include <atltypes.h>
25#include <ui/rosctrls.h>
26
27class CACListView;
28class CACScrollBar;
29class CACSizeBox;
30class CAutoComplete;
31
33// CACListView --- auto-completion list control
34
35class CACListView : public CWindowImpl<CACListView, CListView>
36{
37public:
40 static LPCWSTR GetWndClassName() { return WC_LISTVIEW; }
41
45
47 CStringW GetItemText(INT iItem);
49
50 INT GetCurSel();
51 VOID SetCurSel(INT iItem);
53
54protected:
55 // message map
66 // message handlers
72};
73
75// CACScrollBar --- auto-completion scrollbar control
76
77class CACScrollBar : public CWindowImpl<CACScrollBar>
78{
79public:
84
85protected:
86 // message map
89};
90
92// CACSizeBox --- auto-completion size-box control
93
94class CACSizeBox : public CWindowImpl<CACSizeBox>
95{
96public:
99 CACSizeBox() : m_pDropDown(NULL), m_bDowner(TRUE), m_bLongList(FALSE) { }
101 VOID SetStatus(BOOL bDowner, BOOL bLongList);
102
103protected:
104 // protected variables
107 // message map
109 MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkGnd)
110 MESSAGE_HANDLER(WM_NCHITTEST, OnNCHitTest)
113 // message handlers
114 LRESULT OnEraseBkGnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
115 LRESULT OnNCHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
116 LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
117};
118
120// AC_THREAD --- Thread data for CAutoComplete
121
123{
126 CStringW m_strText;
131
132 VOID ReLoadInnerList(const CStringW& strText);
134
136// CAutoComplete --- auto-completion drop-down window
137
138#define WC_DROPDOWNW L"Auto-Suggest Dropdown" // the window class name
139
140#define AUTOCOMP_START (WM_USER + 1)
141#define AUTOCOMP_FINISH (WM_USER + 2)
142
144 : public CComCoClass<CAutoComplete, &CLSID_AutoComplete>
145 , public CComObjectRootEx<CComMultiThreadModelNoCS>
146 , public CWindowImpl<CAutoComplete>
147 , public IAutoComplete2
148 , public IAutoCompleteDropDown
149 , public IEnumString
150{
151public:
153 static LPCWSTR GetWndClassName() { return WC_DROPDOWNW; }
154 BOOL m_bInSetText; // this flag avoids subsequent action in WM_SETTEXT
155 BOOL m_bInSelectItem; // this flag avoids subsequent action in LVN_ITEMCHANGED
156
157 // public methods
159 virtual ~CAutoComplete();
160
161 HWND CreateDropDown();
162 BOOL CanAutoSuggest() const;
163 BOOL CanAutoAppend() const;
164 BOOL UseTab() const;
165 BOOL IsComboBoxDropped() const;
166 BOOL FilterPrefixes() const;
167 INT GetItemCount() const;
168 CStringW GetItemText(INT iItem) const;
169
170 CStringW GetEditText() const;
171 VOID SetEditText(LPCWSTR pszText);
172 CStringW GetStemText(const CStringW& strText) const;
173 VOID SetEditSel(INT ich0, INT ich1);
174
175 VOID ShowDropDown();
176 VOID HideDropDown();
177 VOID SelectItem(INT iItem);
178 VOID DoAutoAppend(PAC_THREAD pThread);
179 VOID DoThreadWork(PAC_THREAD pThread);
180 VOID DoBackWord();
181 VOID UpdateScrollBar();
182
183 VOID StartCompletion(BOOL bAppendOK);
185 VOID FinishCompletion(PAC_THREAD pThread);
186
188 LRESULT OnEditChar(WPARAM wParam, LPARAM lParam);
189 BOOL OnEditKeyDown(WPARAM wParam, LPARAM lParam);
190 VOID OnListSelChange();
191 BOOL OnListUpDown(UINT vk);
192
193 // IAutoComplete methods
194 STDMETHODIMP Enable(BOOL fEnable) override;
195 STDMETHODIMP Init(HWND hwndEdit, IUnknown *punkACL, LPCOLESTR pwszRegKeyPath,
196 LPCOLESTR pwszQuickComplete) override;
197 // IAutoComplete2 methods
198 STDMETHODIMP GetOptions(DWORD *pdwFlag) override;
199 STDMETHODIMP SetOptions(DWORD dwFlag) override;
200 // IAutoCompleteDropDown methods
201 STDMETHODIMP GetDropDownStatus(DWORD *pdwFlags, LPWSTR *ppwszString) override;
202 STDMETHODIMP ResetEnumerator() override;
203 // IEnumString methods
204 STDMETHODIMP Next(ULONG celt, LPOLESTR *rgelt, ULONG *pceltFetched) override;
205 STDMETHODIMP Skip(ULONG celt) override;
206 STDMETHODIMP Reset() override;
207 STDMETHODIMP Clone(IEnumString **ppOut) override;
208
209protected:
210 // The following variables are POD (plain old data):
211 BOOL m_bDowner; // downer or upper? (below textbox or above textbox)
212 DWORD m_dwOptions; // for IAutoComplete2::SetOptions
213 DWORD m_bEnabled; // the auto-composition is enabled?
214 HWND m_hwndCombo; // the combobox if any
215 HFONT m_hFont; // the font
216 BOOL m_bResized; // re-sized by size-box?
217 RECT m_rcEdit; // in screen coordinates, to watch the position
218 HWND m_hwndEdit; // the textbox
219 WNDPROC m_fnOldEditProc; // old textbox procedure
223
224 // The following variables are non-POD:
225 CStringW m_strText; // internal text (used in selecting item and reverting text)
226 CStringW m_strStemText; // dirname + '\\'
227 CStringW m_strQuickComplete; // used for [Ctrl]+[Enter]
228 CACListView m_hwndList; // this listview is virtual
229 CACScrollBar m_hwndScrollBar; // scroll bar contol
230 CACSizeBox m_hwndSizeBox; // the size grip
231 CComPtr<IEnumString> m_pEnum; // used for enumeration
232 CComPtr<IACList> m_pACList; // for IACList::Expand to update the list
235
236 // protected methods
237 VOID UpdateDropDownState();
238 VOID CalcRects(BOOL bDowner, RECT& rcListView, RECT& rcScrollBar, RECT& rcSizeBox) const;
239 VOID LoadQuickComplete(LPCWSTR pwszRegKeyPath, LPCWSTR pwszQuickComplete);
240 CStringW GetQuickEdit(LPCWSTR pszText) const;
241 VOID RepositionDropDown();
242 VOID ReLoadInnerList(PAC_THREAD pThread);
243 VOID ExtractInnerList(CSimpleArray<CStringW>& outerList,
244 const CSimpleArray<CStringW>& innerList,
245 const CString& strText);
246
247 // message map
249 MESSAGE_HANDLER(AUTOCOMP_START, OnAutoCompStart)
250 MESSAGE_HANDLER(AUTOCOMP_FINISH, OnAutoCompFinish)
252 MESSAGE_HANDLER(WM_NCDESTROY, OnNCDestroy)
254 MESSAGE_HANDLER(WM_EXITSIZEMOVE, OnExitSizeMove)
257 MESSAGE_HANDLER(WM_MOUSEACTIVATE, OnMouseActivate)
258 MESSAGE_HANDLER(WM_NCACTIVATE, OnNCActivate)
259 MESSAGE_HANDLER(WM_NCLBUTTONDOWN, OnNCLButtonDown)
261 MESSAGE_HANDLER(WM_NCHITTEST, OnNCHitTest)
263 MESSAGE_HANDLER(WM_SHOWWINDOW, OnShowWindow)
267
268 // message handlers
269 LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
270 LRESULT OnNCDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
272 LRESULT OnExitSizeMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
275 LRESULT OnMouseActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
276 LRESULT OnNCActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
277 LRESULT OnNCLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
278 LRESULT OnNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
279 LRESULT OnNCHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
280 LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
281 LRESULT OnShowWindow(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
282 LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
283 LRESULT OnVScroll(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
284 LRESULT OnAutoCompStart(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
285 LRESULT OnAutoCompFinish(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
286
287 virtual VOID OnFinalMessage(HWND) override;
288
292
294 COM_INTERFACE_ENTRY_IID(IID_IAutoComplete, IAutoComplete)
295 COM_INTERFACE_ENTRY_IID(IID_IAutoComplete2, IAutoComplete2)
296 COM_INTERFACE_ENTRY_IID(IID_IAutoCompleteDropDown, IAutoCompleteDropDown)
299};
static unsigned __stdcall AutoCompThreadProc(void *arg)
#define AUTOCOMP_FINISH
#define AUTOCOMP_START
#define WC_DROPDOWNW
struct AC_THREAD * PAC_THREAD
const WCHAR * class
Definition: main.c:68
HFONT hFont
Definition: main.c:53
static LRESULT OnNotify(HWND hWnd, LPARAM lParam)
Definition: wordpad.c:2004
@ Create
Definition: registry.c:563
static VOID OnTimer(IN HWND hwndDlg, IN PSYS_SHUTDOWN_PARAMS pShutdownParams)
Definition: shutdown.c:72
#define STDMETHODIMP
Definition: basetyps.h:43
LRESULT OnNCHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
LRESULT OnMouseWheel(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
INT ItemFromPoint(INT x, INT y)
INT GetVisibleCount()
VOID SelectHere(INT x, INT y)
static LPCWSTR GetWndClassName()
Definition: CAutoComplete.h:40
CAutoComplete * m_pDropDown
Definition: CAutoComplete.h:38
CStringW GetItemText(INT iItem)
VOID SetFont(HFONT hFont)
LRESULT OnButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
LRESULT OnMRButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
VOID SetCurSel(INT iItem)
CAutoComplete * m_pDropDown
Definition: CAutoComplete.h:80
static LPCWSTR GetWndClassName()
Definition: CAutoComplete.h:81
static LPCWSTR GetWndClassName()
Definition: CAutoComplete.h:98
CAutoComplete * m_pDropDown
Definition: CAutoComplete.h:97
BOOL m_bLongList
CSimpleArray< CStringW > m_innerList
CACListView m_hwndList
CStringW m_strQuickComplete
CStringW m_strStemText
CComPtr< IACList > m_pACList
CSimpleArray< CStringW > m_outerList
EDITWORDBREAKPROCW m_fnOldWordBreakProc
PAC_THREAD m_pThread
WNDPROC m_fnOldEditProc
CStringW m_strText
CACSizeBox m_hwndSizeBox
CACScrollBar m_hwndScrollBar
CComPtr< IEnumString > m_pEnum
WPARAM wParam
Definition: combotst.c:138
HWND hwndEdit
Definition: combotst.c:65
LPARAM lParam
Definition: combotst.c:139
static VOID OnGetMinMaxInfo(PGUI_CONSOLE_DATA GuiData, PMINMAXINFO minMaxInfo)
Definition: conwnd.c:2100
static HWND hwndParent
Definition: cryptui.c:300
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define IDR_AUTOCOMPLETE
Definition: resource.h:103
static LRESULT CALLBACK EditWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: monthcal.c:2080
static VOID OnSize(HWND hDlg, PDETAILDATA pData, INT cx, INT cy)
Definition: evtdetctl.c:470
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define BEGIN_COM_MAP(x)
Definition: atlcom.h:581
#define COM_INTERFACE_ENTRY_IID(iid, x)
Definition: atlcom.h:601
#define DECLARE_PROTECT_FINAL_CONSTRUCT()
Definition: atlcom.h:679
#define DECLARE_NOT_AGGREGATABLE(x)
Definition: atlcom.h:651
#define DECLARE_REGISTRY_RESOURCEID(x)
Definition: atlcom.h:645
#define END_COM_MAP()
Definition: atlcom.h:592
#define MESSAGE_HANDLER(msg, func)
Definition: atlwin.h:1926
#define BEGIN_MSG_MAP(theClass)
Definition: atlwin.h:1898
#define END_MSG_MAP()
Definition: atlwin.h:1917
#define DECLARE_WND_CLASS_EX(WndClassName, style, bkgnd)
Definition: atlwin.h:2004
static VOID OnVScroll(PMAP infoPtr, INT Value, INT Pos)
Definition: map.c:445
static VOID OnPaint(PMAP infoPtr, WPARAM wParam)
Definition: map.c:554
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
static HKEY override
Definition: compobj.c:81
static LPOLESTR
Definition: stg_prop.c:27
WORD vk
Definition: input.c:77
BOOL OnCreate(HWND hWnd)
Definition: msconfig.c:83
unsigned int UINT
Definition: ndis.h:50
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:142
const GUID IID_IEnumString
void OnMeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
Definition: page1.c:138
#define WC_LISTVIEW
Definition: commctrl.h:2259
#define WC_SCROLLBARW
Definition: commctrl.h:4729
#define WM_NOTIFY
Definition: richedit.h:61
CSimpleArray< CStringW > m_outerList
VOID ReLoadInnerList(const CStringW &strText)
BOOL m_bAppendOK
CAutoComplete * m_pThis
CSimpleArray< CStringW > m_innerList
CStringW m_strText
BOOL m_bExpand
#define WM_MOUSEWHEEL
Definition: treelist.c:96
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
static LRESULT OnDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
Definition: welcome.c:1411
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define WM_PAINT
Definition: winuser.h:1620
#define WM_ERASEBKGND
Definition: winuser.h:1625
#define CS_DROPSHADOW
Definition: winuser.h:660
#define WM_VSCROLL
Definition: winuser.h:1744
#define WM_CREATE
Definition: winuser.h:1608
#define WM_SIZE
Definition: winuser.h:1611
#define WM_NCHITTEST
Definition: winuser.h:1686
#define WM_RBUTTONUP
Definition: winuser.h:1780
#define WM_LBUTTONDOWN
Definition: winuser.h:1776
#define WM_DRAWITEM
Definition: winuser.h:1645
#define WM_SHOWWINDOW
Definition: winuser.h:1628
#define WM_RBUTTONDOWN
Definition: winuser.h:1779
#define WM_NCACTIVATE
Definition: winuser.h:1688
#define WM_GETMINMAXINFO
Definition: winuser.h:1640
#define WM_EXITSIZEMOVE
Definition: winuser.h:1824
#define WM_TIMER
Definition: winuser.h:1742
#define WM_MOUSEACTIVATE
Definition: winuser.h:1637
#define WM_MEASUREITEM
Definition: winuser.h:1646
int(CALLBACK * EDITWORDBREAKPROCW)(LPWSTR, int, int, int)
Definition: winuser.h:2905
#define WM_LBUTTONUP
Definition: winuser.h:1777
#define WM_NCDESTROY
Definition: winuser.h:1684
#define CS_SAVEBITS
Definition: winuser.h:657
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2906
#define WM_MBUTTONUP
Definition: winuser.h:1783
#define WM_NCLBUTTONDOWN
Definition: winuser.h:1692
#define WM_MBUTTONDOWN
Definition: winuser.h:1782
#define COLOR_3DFACE
Definition: winuser.h:929
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185