ReactOS 0.4.16-dev-106-g10b08aa
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
157
158 // public methods
160 virtual ~CAutoComplete();
161
162 HWND CreateDropDown();
163 BOOL CanAutoSuggest() const;
164 BOOL CanAutoAppend() const;
165 BOOL UseTab() const;
166 BOOL IsComboBoxDropped() const;
167 BOOL FilterPrefixes() const;
168 INT GetItemCount() const;
169 CStringW GetItemText(INT iItem) const;
170
171 CStringW GetEditText() const;
172 VOID SetEditText(LPCWSTR pszText);
173 CStringW GetStemText(const CStringW& strText) const;
174 VOID SetEditSel(INT ich0, INT ich1);
175
176 VOID ShowDropDown();
177 VOID HideDropDown();
178 VOID SelectItem(INT iItem);
179 VOID DoAutoAppend(PAC_THREAD pThread);
180 VOID DoThreadWork(PAC_THREAD pThread);
181 VOID DoBackWord();
182 VOID UpdateScrollBar();
183
184 VOID StartCompletion(BOOL bAppendOK);
186 VOID FinishCompletion(PAC_THREAD pThread);
187
189 LRESULT OnEditChar(WPARAM wParam, LPARAM lParam);
190 BOOL OnEditKeyDown(WPARAM wParam, LPARAM lParam);
191 VOID OnListSelChange();
192 BOOL OnListUpDown(UINT vk);
193
194 // IAutoComplete methods
195 STDMETHODIMP Enable(BOOL fEnable) override;
196 STDMETHODIMP Init(HWND hwndEdit, IUnknown *punkACL, LPCOLESTR pwszRegKeyPath,
197 LPCOLESTR pwszQuickComplete) override;
198 // IAutoComplete2 methods
199 STDMETHODIMP GetOptions(DWORD *pdwFlag) override;
200 STDMETHODIMP SetOptions(DWORD dwFlag) override;
201 // IAutoCompleteDropDown methods
202 STDMETHODIMP GetDropDownStatus(DWORD *pdwFlags, LPWSTR *ppwszString) override;
203 STDMETHODIMP ResetEnumerator() override;
204 // IEnumString methods
205 STDMETHODIMP Next(ULONG celt, LPOLESTR *rgelt, ULONG *pceltFetched) override;
206 STDMETHODIMP Skip(ULONG celt) override;
207 STDMETHODIMP Reset() override;
208 STDMETHODIMP Clone(IEnumString **ppOut) override;
209
210protected:
211 // The following variables are POD (plain old data):
212 BOOL m_bDowner; // downer or upper? (below textbox or above textbox)
213 DWORD m_dwOptions; // for IAutoComplete2::SetOptions
214 DWORD m_bEnabled; // the auto-composition is enabled?
215 HWND m_hwndCombo; // the combobox if any
216 HFONT m_hFont; // the font
217 BOOL m_bResized; // re-sized by size-box?
218 RECT m_rcEdit; // in screen coordinates, to watch the position
219 HWND m_hwndEdit; // the textbox
220 WNDPROC m_fnOldEditProc; // old textbox procedure
224
225 // The following variables are non-POD:
226 CStringW m_strText; // internal text (used in selecting item and reverting text)
227 CStringW m_strStemText; // dirname + '\\'
228 CStringW m_strQuickComplete; // used for [Ctrl]+[Enter]
229 CACListView m_hwndList; // this listview is virtual
230 CACScrollBar m_hwndScrollBar; // scroll bar contol
231 CACSizeBox m_hwndSizeBox; // the size grip
232 CComPtr<IEnumString> m_pEnum; // used for enumeration
233 CComPtr<IACList> m_pACList; // for IACList::Expand to update the list
236
237 // protected methods
238 VOID UpdateDropDownState();
239 VOID CalcRects(BOOL bDowner, RECT& rcListView, RECT& rcScrollBar, RECT& rcSizeBox) const;
240 VOID LoadQuickComplete(LPCWSTR pwszRegKeyPath, LPCWSTR pwszQuickComplete);
241 CStringW GetQuickEdit(LPCWSTR pszText) const;
242 VOID RepositionDropDown();
243 VOID ReLoadInnerList(PAC_THREAD pThread);
244 VOID ExtractInnerList(CSimpleArray<CStringW>& outerList,
245 const CSimpleArray<CStringW>& innerList,
246 const CString& strText);
247
248 // message map
250 MESSAGE_HANDLER(AUTOCOMP_START, OnAutoCompStart)
251 MESSAGE_HANDLER(AUTOCOMP_FINISH, OnAutoCompFinish)
253 MESSAGE_HANDLER(WM_NCDESTROY, OnNCDestroy)
255 MESSAGE_HANDLER(WM_EXITSIZEMOVE, OnExitSizeMove)
258 MESSAGE_HANDLER(WM_MOUSEACTIVATE, OnMouseActivate)
259 MESSAGE_HANDLER(WM_NCACTIVATE, OnNCActivate)
260 MESSAGE_HANDLER(WM_NCLBUTTONDOWN, OnNCLButtonDown)
262 MESSAGE_HANDLER(WM_NCHITTEST, OnNCHitTest)
264 MESSAGE_HANDLER(WM_SHOWWINDOW, OnShowWindow)
268
269 // message handlers
270 LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
271 LRESULT OnNCDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
273 LRESULT OnExitSizeMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
276 LRESULT OnMouseActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
277 LRESULT OnNCActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
278 LRESULT OnNCLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
279 LRESULT OnNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
280 LRESULT OnNCHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
281 LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
282 LRESULT OnShowWindow(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
283 LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
284 LRESULT OnVScroll(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
285 LRESULT OnAutoCompStart(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
286 LRESULT OnAutoCompFinish(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
287
288 virtual VOID OnFinalMessage(HWND) override;
289
293
295 COM_INTERFACE_ENTRY_IID(IID_IAutoComplete, IAutoComplete)
296 COM_INTERFACE_ENTRY_IID(IID_IAutoComplete2, IAutoComplete2)
297 COM_INTERFACE_ENTRY_IID(IID_IAutoCompleteDropDown, IAutoCompleteDropDown)
300};
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:2015
@ 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:2079
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:2264
#define WC_SCROLLBARW
Definition: commctrl.h:4734
#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:1623
#define WM_ERASEBKGND
Definition: winuser.h:1628
#define CS_DROPSHADOW
Definition: winuser.h:660
#define WM_VSCROLL
Definition: winuser.h:1747
#define WM_CREATE
Definition: winuser.h:1611
#define WM_SIZE
Definition: winuser.h:1614
#define WM_NCHITTEST
Definition: winuser.h:1689
#define WM_RBUTTONUP
Definition: winuser.h:1783
#define WM_LBUTTONDOWN
Definition: winuser.h:1779
#define WM_DRAWITEM
Definition: winuser.h:1648
#define WM_SHOWWINDOW
Definition: winuser.h:1631
#define WM_RBUTTONDOWN
Definition: winuser.h:1782
#define WM_NCACTIVATE
Definition: winuser.h:1691
#define WM_GETMINMAXINFO
Definition: winuser.h:1643
#define WM_EXITSIZEMOVE
Definition: winuser.h:1827
#define WM_TIMER
Definition: winuser.h:1745
#define WM_MOUSEACTIVATE
Definition: winuser.h:1640
#define WM_MEASUREITEM
Definition: winuser.h:1649
int(CALLBACK * EDITWORDBREAKPROCW)(LPWSTR, int, int, int)
Definition: winuser.h:2908
#define WM_LBUTTONUP
Definition: winuser.h:1780
#define WM_NCDESTROY
Definition: winuser.h:1687
#define CS_SAVEBITS
Definition: winuser.h:657
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2909
#define WM_MBUTTONUP
Definition: winuser.h:1786
#define WM_NCLBUTTONDOWN
Definition: winuser.h:1695
#define WM_MBUTTONDOWN
Definition: winuser.h:1785
#define COLOR_3DFACE
Definition: winuser.h:932
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185