forked from jrywu/DIME
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThreadMgrEventSink.cpp
240 lines (200 loc) · 6.92 KB
/
ThreadMgrEventSink.cpp
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
//
//
// Derived from Microsoft Sample IME by Jeremy '13,7,17
//
//
//#define DEBUG_PRINT
//#define VERBOSE
#include "Private.h"
#include "Globals.h"
#include "DIME.h"
#include "UIPresenter.h"
#include "GetTextExtentEditSession.h"
//+---------------------------------------------------------------------------
//
// ITfThreadMgrEventSink::OnInitDocumentMgr
//
// Sink called by the framework just before the first context is pushed onto
// a document.
//----------------------------------------------------------------------------
STDAPI CDIME::OnInitDocumentMgr(_In_ ITfDocumentMgr *pDocMgr)
{
pDocMgr;
return E_NOTIMPL;
}
//+---------------------------------------------------------------------------
//
// ITfThreadMgrEventSink::OnUninitDocumentMgr
//
// Sink called by the framework just after the last context is popped off a
// document.
//----------------------------------------------------------------------------
STDAPI CDIME::OnUninitDocumentMgr(_In_ ITfDocumentMgr *pDocMgr)
{
pDocMgr;
return E_NOTIMPL;
}
//+---------------------------------------------------------------------------
//
// ITfThreadMgrEventSink::OnSetFocus
//
// Sink called by the framework when focus changes from one document to
// another. Either document may be NULL, meaning previously there was no
// focus document, or now no document holds the input focus.
//----------------------------------------------------------------------------
STDAPI CDIME::OnSetFocus(_In_ ITfDocumentMgr *pDocMgrFocus, _In_opt_ ITfDocumentMgr *pDocMgrPrevFocus)
{
debugPrint(L"CDIME::OnSetFocus() _isChinese = %d, _lastKeyboardMode = %d\n", _isChinese, _lastKeyboardMode);
pDocMgrPrevFocus;
ITfContext* pContext = nullptr;
_InitTextEditSink(pDocMgrFocus);
if(pDocMgrFocus && !_UpdateLanguageBarOnSetFocus(pDocMgrFocus))
{
pDocMgrFocus->GetTop(&pContext);
//Update double single byte mode
if (CConfig::GetDoubleSingleByteMode() != DOUBLE_SINGLE_BYTE_SHIFT_SPACE)
{
CCompartment CompartmentDoubleSingleByte(_pThreadMgr, _tfClientId, Global::DIMEGuidCompartmentDoubleSingleByte);
CompartmentDoubleSingleByte._SetCompartmentBOOL(CConfig::GetDoubleSingleByteMode() == DOUBLE_SINGLE_BYTE_ALWAYS_DOUBLE);
}
//Update keyboard mode
if (pContext && !(_newlyActivated && !Global::isWindows8 && isWin7IEProcess()))
{
debugPrint(L"CDIME::OnSetFocus() Set isChinese = lastkeyboardMode = %d,", _isChinese);
_lastKeyboardMode = _isChinese;
debugPrint(L"CDIME::OnSetFocus() Set keyboard mode to last state = %d", _lastKeyboardMode);
ConversionModeCompartmentUpdated(_pThreadMgr, &_lastKeyboardMode);
debugPrint(L"CDIME::OnSetFocus() show chi/eng notify _isChinese = %d", _isChinese);
if (!isBlackListedProcessForProbeComposition())
showChnEngNotify(_isChinese, 500); //only show chn/eng notify for processes no black listed (may cause strange behaviour like firefox).
}
else if (_newlyActivated)
_newlyActivated = FALSE;
}
if(pDocMgrFocus)
{
#if defined(DEBUG_PRINT) && defined(VERBOSE) //probing the TSF supprting status.
ITfContext* pContext = nullptr;
bool isTransitory = false;
bool isMultiRegion = false;
bool isMultiSelection = false;
if (SUCCEEDED(pDocMgrFocus->GetTop(&pContext)))
{
//if(_pContext == nullptr)
//_SaveCompositionContext(pContext);
TF_STATUS tfStatus;
if (SUCCEEDED(pContext->GetStatus(&tfStatus)))
{
isTransitory = (tfStatus.dwStaticFlags & TS_SS_TRANSITORY) == TS_SS_TRANSITORY;
isMultiRegion = (tfStatus.dwStaticFlags & TF_SS_REGIONS) == TF_SS_REGIONS;
isMultiSelection = (tfStatus.dwStaticFlags & TF_SS_DISJOINTSEL) == TF_SS_DISJOINTSEL;
}
}
if(isTransitory) debugPrint(L"TSF in Transitory context\n");
if(isMultiRegion) debugPrint(L"Support multi region\n");
if(isMultiSelection) debugPrint(L"Support multi selection\n");
#endif
}
//
// We have to hide/unhide candidate list depending on whether they are
// associated with pDocMgrFocus.
//
if (_pUIPresenter)
{
ITfDocumentMgr* pCandidateListDocumentMgr = nullptr;
ITfContext* pTfContext = _pUIPresenter->_GetContextDocument();
if (pTfContext &&
SUCCEEDED(pTfContext->GetDocumentMgr(&pCandidateListDocumentMgr)) && pCandidateListDocumentMgr )
{
if (pCandidateListDocumentMgr != pDocMgrFocus)
{
_pUIPresenter->OnKillThreadFocus();
}
else
{
_pUIPresenter->OnSetThreadFocus();
}
pCandidateListDocumentMgr->Release();
}
}
if (_pDocMgrLastFocused)
{
_pDocMgrLastFocused->Release();
_pDocMgrLastFocused = nullptr;
}
_pDocMgrLastFocused = pDocMgrFocus;
if (_pDocMgrLastFocused)
{
_pDocMgrLastFocused->AddRef();
}
debugPrint(L"leaving CDIME::OnSetFocus()\n");
return S_OK;
}
//+---------------------------------------------------------------------------
//
// ITfThreadMgrEventSink::OnPushContext
//
// Sink called by the framework when a context is pushed.
//----------------------------------------------------------------------------
STDAPI CDIME::OnPushContext(_In_ ITfContext *pContext)
{
pContext;
return E_NOTIMPL;
}
//+---------------------------------------------------------------------------
//
// ITfThreadMgrEventSink::OnPopContext
//
// Sink called by the framework when a context is popped.
//----------------------------------------------------------------------------
STDAPI CDIME::OnPopContext(_In_ ITfContext *pContext)
{
pContext;
return E_NOTIMPL;
}
//+---------------------------------------------------------------------------
//
// _InitThreadMgrEventSink
//
// Advise our sink.
//----------------------------------------------------------------------------
BOOL CDIME::_InitThreadMgrEventSink()
{
debugPrint(L"CDIME::_InitThreadMgrEventSink()");
ITfSource* pSource = nullptr;
BOOL ret = FALSE;
if ( (_pThreadMgr && FAILED(_pThreadMgr->QueryInterface(IID_ITfSource, (void **)&pSource))) || pSource==nullptr)
{
return ret;
}
if (FAILED(pSource->AdviseSink(IID_ITfThreadMgrEventSink, (ITfThreadMgrEventSink *)this, &_threadMgrEventSinkCookie)))
{
_threadMgrEventSinkCookie = TF_INVALID_COOKIE;
goto Exit;
}
ret = TRUE;
Exit:
pSource->Release();
return ret;
}
//+---------------------------------------------------------------------------
//
// _UninitThreadMgrEventSink
//
// Unadvise our sink.
//----------------------------------------------------------------------------
void CDIME::_UninitThreadMgrEventSink()
{
debugPrint(L"CDIME::_UninitThreadMgrEventSink()");
ITfSource* pSource = nullptr;
if (_threadMgrEventSinkCookie == TF_INVALID_COOKIE)
{
return;
}
if ( _pThreadMgr && SUCCEEDED(_pThreadMgr->QueryInterface(IID_ITfSource, (void **)&pSource)) && pSource)
{
pSource->UnadviseSink(_threadMgrEventSinkCookie);
pSource->Release();
}
_threadMgrEventSinkCookie = TF_INVALID_COOKIE;
}