ReactOS  0.4.15-dev-3181-g4acf100
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 "rosctrls.h"
26 
27 class CACListView;
28 class CACScrollBar;
29 class CACSizeBox;
30 class CAutoComplete;
31 
33 // CACListView --- auto-completion list control
34 
35 class CACListView : public CWindowImpl<CACListView, CListView>
36 {
37 public:
40  static LPCWSTR GetWndClassName() { return WC_LISTVIEW; }
41 
42  CACListView();
45 
47  CStringW GetItemText(INT iItem);
49 
50  INT GetCurSel();
51  VOID SetCurSel(INT iItem);
53 
54 protected:
55  // message map
65  END_MSG_MAP()
66  // message handlers
67  LRESULT OnButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
72 };
73 
75 // CACScrollBar --- auto-completion scrollbar control
76 
77 class CACScrollBar : public CWindowImpl<CACScrollBar>
78 {
79 public:
81  static LPCWSTR GetWndClassName() { return WC_SCROLLBARW; }
84 
85 protected:
86  // message map
88  END_MSG_MAP()
89 };
90 
92 // CACSizeBox --- auto-completion size-box control
93 
94 class CACSizeBox : public CWindowImpl<CACSizeBox>
95 {
96 public:
98  static LPCWSTR GetWndClassName() { return WC_SCROLLBARW; }
99  CACSizeBox() : m_pDropDown(NULL), m_bDowner(TRUE), m_bLongList(FALSE) { }
101  VOID SetStatus(BOOL bDowner, BOOL bLongList);
102 
103 protected:
104  // protected variables
107  // message map
109  MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkGnd)
112  END_MSG_MAP()
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 {
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 {
151 public:
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
158  CAutoComplete();
159  HWND CreateDropDown();
160  virtual ~CAutoComplete();
161 
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 
209 protected:
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)
263  MESSAGE_HANDLER(WM_SHOWWINDOW, OnShowWindow)
266  END_MSG_MAP()
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);
271  LRESULT OnDrawItem(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 
290 
292  COM_INTERFACE_ENTRY_IID(IID_IAutoComplete, IAutoComplete)
293  COM_INTERFACE_ENTRY_IID(IID_IAutoComplete2, IAutoComplete2)
294  COM_INTERFACE_ENTRY_IID(IID_IAutoCompleteDropDown, IAutoCompleteDropDown)
296  END_COM_MAP()
297 };
#define WM_MBUTTONUP
Definition: winuser.h:1766
#define WM_NCLBUTTONDOWN
Definition: winuser.h:1675
BOOL m_bExpand
CACScrollBar m_hwndScrollBar
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
const GUID IID_IEnumString
#define WM_LBUTTONDOWN
Definition: winuser.h:1759
CAutoComplete * m_pThis
LRESULT OnMouseWheel(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
CStringW m_strStemText
#define CS_DROPSHADOW
Definition: winuser.h:655
CSimpleArray< CStringW > m_innerList
struct AC_THREAD AC_THREAD
#define TRUE
Definition: types.h:120
#define WM_MOUSEWHEEL
Definition: treelist.c:96
void OnTimer(HWND hwnd, UINT id)
Definition: maze.c:850
#define WC_DROPDOWNW
WORD vk
Definition: input.c:77
static LPCWSTR GetWndClassName()
Definition: CAutoComplete.h:81
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
#define DECLARE_WND_CLASS_EX(WndClassName, style, bkgnd)
Definition: atlwin.h:1935
CACSizeBox m_hwndSizeBox
static LRESULT OnNotify(HWND hWnd, LPARAM lParam)
Definition: wordpad.c:2004
#define WM_EXITSIZEMOVE
Definition: winuser.h:1807
#define WM_SHOWWINDOW
Definition: winuser.h:1611
INT GetVisibleCount()
CAutoComplete * m_pDropDown
Definition: CAutoComplete.h:80
#define DECLARE_NOT_AGGREGATABLE(x)
Definition: atlcom.h:612
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define WM_NCHITTEST
Definition: winuser.h:1669
UINT_PTR WPARAM
Definition: windef.h:207
BOOL Init(PUSERCONNECT UserCon)
Definition: dllmain.c:385
#define AUTOCOMP_START
static LPOLESTR
Definition: stg_prop.c:27
BOOL m_bLongList
int32_t INT
Definition: typedefs.h:58
WPARAM wParam
Definition: combotst.c:138
HFONT hFont
Definition: main.c:53
PAC_THREAD m_pThread
CSimpleArray< CStringW > m_innerList
WNDPROC m_fnOldEditProc
#define COLOR_3DFACE
Definition: winuser.h:919
#define FALSE
Definition: types.h:117
#define WM_NCACTIVATE
Definition: winuser.h:1671
unsigned int BOOL
Definition: ntddk_ex.h:94
CComPtr< IACList > m_pACList
VOID SetFont(HFONT hFont)
#define STDMETHODIMP
Definition: basetyps.h:43
static HWND hwndParent
Definition: cryptui.c:300
LONG_PTR LPARAM
Definition: windef.h:208
#define WM_MOUSEACTIVATE
Definition: winuser.h:1620
static LRESULT OnDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
Definition: welcome.c:1411
LRESULT OnButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
#define WM_RBUTTONDOWN
Definition: winuser.h:1762
#define BEGIN_COM_MAP(x)
Definition: atlcom.h:542
#define IDR_AUTOCOMPLETE
Definition: resource.h:103
CStringA CString
Definition: atlstr.h:139
static VOID OnSize(HWND hDlg, PDETAILDATA pData, INT cx, INT cy)
Definition: evtdetctl.c:484
static unsigned __stdcall AutoCompThreadProc(void *arg)
EDITWORDBREAKPROCW m_fnOldWordBreakProc
static LRESULT CALLBACK EditWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: monthcal.c:2082
#define WM_SIZE
Definition: winuser.h:1594
#define END_MSG_MAP()
Definition: atlwin.h:1848
#define WM_TIMER
Definition: winuser.h:1725
#define WM_NCDESTROY
Definition: winuser.h:1667
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WM_MEASUREITEM
Definition: winuser.h:1629
#define WM_RBUTTONUP
Definition: winuser.h:1763
#define WM_PAINT
Definition: winuser.h:1603
#define CS_SAVEBITS
Definition: winuser.h:652
LRESULT OnNCHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
LRESULT OnMRButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
static LPCWSTR GetWndClassName()
Definition: CAutoComplete.h:40
VOID SetCurSel(INT iItem)
CACListView m_hwndList
int(CALLBACK * EDITWORDBREAKPROCW)(LPWSTR, int, int, int)
Definition: winuser.h:2881
#define DECLARE_REGISTRY_RESOURCEID(x)
Definition: atlcom.h:606
void OnMeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
Definition: page1.c:138
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2882
HWND hwndEdit
Definition: combotst.c:65
CStringW m_strText
#define COM_INTERFACE_ENTRY_IID(iid, x)
Definition: atlcom.h:562
#define WM_LBUTTONUP
Definition: winuser.h:1760
#define WM_MBUTTONDOWN
Definition: winuser.h:1765
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define WC_SCROLLBARW
Definition: commctrl.h:4729
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
static VOID OnGetMinMaxInfo(PGUI_CONSOLE_DATA GuiData, PMINMAXINFO minMaxInfo)
Definition: conwnd.c:2015
LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
#define BEGIN_MSG_MAP(theClass)
Definition: atlwin.h:1829
#define WM_DRAWITEM
Definition: winuser.h:1628
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define DECLARE_PROTECT_FINAL_CONSTRUCT()
Definition: atlcom.h:640
#define AUTOCOMP_FINISH
static VOID OnVScroll(PMAP infoPtr, INT Value, INT Pos)
Definition: map.c:455
#define MESSAGE_HANDLER(msg, func)
Definition: atlwin.h:1857
#define WC_LISTVIEW
Definition: commctrl.h:2259
CComPtr< IEnumString > m_pEnum
HWND Create(HWND hwndParent)
#define WM_CREATE
Definition: winuser.h:1591
const WCHAR * class
Definition: main.c:68
unsigned int ULONG
Definition: retypes.h:1
CAtlStringW CStringW
Definition: atlstr.h:130
BOOL m_bAppendOK
#define END_COM_MAP()
Definition: atlcom.h:553
void OnPaint(HWND hWnd)
Definition: appswitch.c:321
#define WM_ERASEBKGND
Definition: winuser.h:1608
INT ItemFromPoint(INT x, INT y)
CAutoComplete * m_pDropDown
Definition: CAutoComplete.h:97
WCHAR * LPWSTR
Definition: xmlstorage.h:184
LONG_PTR LRESULT
Definition: windef.h:209
static LPCWSTR GetWndClassName()
Definition: CAutoComplete.h:98
CSimpleArray< CStringW > m_outerList
VOID SelectHere(INT x, INT y)
CStringW m_strText
LPARAM lParam
Definition: combotst.c:139
#define WM_GETMINMAXINFO
Definition: winuser.h:1623
CAutoComplete * m_pDropDown
Definition: CAutoComplete.h:38
#define WM_NOTIFY
Definition: richedit.h:61
struct AC_THREAD * PAC_THREAD
BOOL OnCreate(HWND hWnd)
Definition: msconfig.c:83
#define WM_VSCROLL
Definition: winuser.h:1727
CStringW GetItemText(INT iItem)
CStringW m_strQuickComplete
CSimpleArray< CStringW > m_outerList