-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleTSF.h
More file actions
211 lines (172 loc) · 6.32 KB
/
Copy pathConsoleTSF.h
File metadata and controls
211 lines (172 loc) · 6.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*++
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Module Name:
TfContext.h
Abstract:
This file defines the CConsoleTSF Interface Class.
Author:
Revision History:
Notes:
--*/
#pragma once
class CConversionArea;
class CConsoleTSF final:
public ITfContextOwner,
public ITfContextOwnerCompositionSink,
public ITfInputProcessorProfileActivationSink,
public ITfUIElementSink,
public ITfCleanupContextSink,
public ITfTextEditSink
{
public:
CConsoleTSF(HWND hwndConsole,
GetSuggestionWindowPos pfnPosition) :
_hwndConsole(hwndConsole),
_pfnPosition(pfnPosition),
_cRef(1),
_tid()
{
}
virtual ~CConsoleTSF()
{
}
[[nodiscard]]
HRESULT Initialize();
void Uninitialize();
public:
// IUnknown methods
STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
STDMETHODIMP_(ULONG) AddRef(void);
STDMETHODIMP_(ULONG) Release(void);
// ITfContextOwner
STDMETHODIMP GetACPFromPoint(const POINT*, DWORD, LONG *pCP)
{
if (pCP)
{
*pCP = 0;
}
return S_OK;
}
STDMETHODIMP GetScreenExt(RECT *pRect)
{
if (pRect)
{
*pRect = _pfnPosition();
}
return S_OK;
}
STDMETHODIMP GetTextExt(LONG, LONG, RECT *pRect, BOOL *pbClipped)
{
if (pRect)
{
GetScreenExt(pRect);
}
if (pbClipped)
{
*pbClipped = FALSE;
}
return S_OK;
}
STDMETHODIMP GetStatus(TF_STATUS *pTfStatus)
{
if (pTfStatus)
{
pTfStatus->dwDynamicFlags = 0;
pTfStatus->dwStaticFlags = TF_SS_TRANSITORY;
}
return pTfStatus ? S_OK : E_INVALIDARG;
}
STDMETHODIMP GetWnd(HWND* phwnd)
{
*phwnd = _hwndConsole;
return S_OK;
}
STDMETHODIMP GetAttribute(REFGUID, VARIANT*)
{ return E_NOTIMPL; }
// ITfContextOwnerCompositionSink methods
STDMETHODIMP OnStartComposition(ITfCompositionView *pComposition, BOOL *pfOk);
STDMETHODIMP OnUpdateComposition(ITfCompositionView *pComposition, ITfRange *pRangeNew);
STDMETHODIMP OnEndComposition(ITfCompositionView* pComposition);
// ITfInputProcessorProfileActivationSink
STDMETHODIMP OnActivated(DWORD dwProfileType, LANGID langid, REFCLSID clsid,
REFGUID catid, REFGUID guidProfile, HKL hkl, DWORD dwFlags);
// ITfUIElementSink methods
STDMETHODIMP BeginUIElement(DWORD dwUIELementId, BOOL *pbShow);
STDMETHODIMP UpdateUIElement(DWORD dwUIELementId);
STDMETHODIMP EndUIElement(DWORD dwUIELementId);
// ITfCleanupContextSink methods
STDMETHODIMP OnCleanupContext(TfEditCookie ecWrite, ITfContext *pic);
// ITfTextEditSink methods
STDMETHODIMP OnEndEdit(ITfContext *pInputContext, TfEditCookie ecReadOnly, ITfEditRecord *pEditRecord);
public:
CConversionArea* CreateConversionArea();
CConversionArea* GetConversionArea() { return _pConversionArea; }
ITfContext* GetInputContext() { return _spITfInputContext; }
HWND GetConsoleHwnd() { return _hwndConsole; }
TfClientId GetTfClientId() { return _tid; }
BOOL IsInComposition() { return (_cCompositions > 0); }
void OnEditSession() { _fEditSessionRequested = FALSE; }
BOOL IsPendingCompositionCleanup() { return _fCleanupSessionRequested || _fCompositionCleanupSkipped; }
void OnCompositionCleanup(BOOL bSucceeded)
{
_fCleanupSessionRequested = FALSE;
_fCompositionCleanupSkipped = !bSucceeded;
}
void SetModifyingDocFlag(BOOL fSet) { _fModifyingDoc = fSet; }
void SetFocus(BOOL fSet)
{
if (!fSet && _cCompositions)
{
// Close (terminate) any open compositions when losing the input focus.
CComQIPtr<ITfContextOwnerCompositionServices> spCompositionServices(_spITfInputContext);
if (spCompositionServices)
{
spCompositionServices->TerminateComposition(NULL);
}
}
}
// A workaround for a MS Korean IME scenario where the IME appends a whitespace
// composition programmatically right after completing a keyboard input composition.
// Since post-composition clean-up is an async operation, the programmatic whitespace
// composition gets completed before the previous composition cleanup happened,
// and this results in a double insertion of the first composition. To avoid that, we'll
// store the length of the last completed composition here until it's cleaned up.
// (for simplicity, this patch doesn't provide a generic solution for all possible
// scenarios with subsequent synchronous compositions, only for the known 'append').
long GetCompletedRangeLength() const { return _cchCompleted; }
void SetCompletedRangeLength(long cch) { _cchCompleted = cch; }
private:
[[nodiscard]]
HRESULT _OnUpdateComposition();
[[nodiscard]]
HRESULT _OnCompleteComposition();
BOOL _HasCompositionChanged(ITfContext *pInputContext, TfEditCookie ecReadOnly, ITfEditRecord *pEditRecord);
private:
// ref count.
DWORD _cRef;
// Cicero stuff.
TfClientId _tid;
CComPtr<ITfThreadMgrEx> _spITfThreadMgr;
CComPtr<ITfDocumentMgr> _spITfDocumentMgr;
CComPtr<ITfContext> _spITfInputContext;
// Event sink cookies.
DWORD _dwContextOwnerCookie = 0;
DWORD _dwUIElementSinkCookie = 0;
DWORD _dwTextEditSinkCookie = 0;
DWORD _dwActivationSinkCookie = 0;
// Conversion area object for the languages.
CConversionArea* _pConversionArea = nullptr;
// Console info.
HWND _hwndConsole;
GetSuggestionWindowPos _pfnPosition;
// Miscellaneous flags
BOOL _fModifyingDoc = FALSE; // Set TRUE, when calls ITfRange::SetText
BOOL _fCoInitialized = FALSE;
BOOL _fEditSessionRequested = FALSE;
BOOL _fCleanupSessionRequested = FALSE;
BOOL _fCompositionCleanupSkipped = FALSE;
int _cCompositions = 0;
long _cchCompleted = 0; // length of completed composition waiting for cleanup
};
extern CConsoleTSF* g_pConsoleTSF;