forked from microsoft/terminal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTfTxtevCb.cpp
169 lines (140 loc) · 5.14 KB
/
TfTxtevCb.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
/*++
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Module Name:
TfTxtevCb.cpp
Abstract:
This file implements the CTextEventSinkCallBack Class.
Author:
Revision History:
Notes:
--*/
#include "precomp.h"
#include "ConsoleTSF.h"
#include "TfEditSession.h"
//+---------------------------------------------------------------------------
//
// CConsoleTSF::HasCompositionChanged
//
//----------------------------------------------------------------------------
BOOL CConsoleTSF::_HasCompositionChanged(ITfContext* pInputContext, TfEditCookie ecReadOnly, ITfEditRecord* pEditRecord)
{
BOOL fChanged;
if (SUCCEEDED(pEditRecord->GetSelectionStatus(&fChanged)))
{
if (fChanged)
{
return TRUE;
}
}
//
// Find GUID_PROP_CONIME_TRACKCOMPOSITION property.
//
wil::com_ptr_nothrow<ITfProperty> Property;
wil::com_ptr_nothrow<ITfRange> FoundRange;
wil::com_ptr_nothrow<ITfProperty> PropertyTrackComposition;
BOOL bFound = FALSE;
if (SUCCEEDED(pInputContext->GetProperty(GUID_PROP_CONIME_TRACKCOMPOSITION, &Property)))
{
wil::com_ptr_nothrow<IEnumTfRanges> EnumFindFirstTrackCompRange;
if (SUCCEEDED(Property->EnumRanges(ecReadOnly, &EnumFindFirstTrackCompRange, NULL)))
{
HRESULT hr;
wil::com_ptr_nothrow<ITfRange> range;
while ((hr = EnumFindFirstTrackCompRange->Next(1, &range, nullptr)) == S_OK)
{
VARIANT var;
VariantInit(&var);
hr = Property->GetValue(ecReadOnly, range.get(), &var);
if (SUCCEEDED(hr))
{
if ((V_VT(&var) == VT_I4 && V_I4(&var) != 0))
{
range->Clone(&FoundRange);
bFound = TRUE; // FOUND!!
break;
}
}
VariantClear(&var);
if (bFound)
{
break; // FOUND!!
}
}
}
}
//
// if there is no track composition property,
// the composition has been changed since we put it.
//
if (!bFound)
{
return TRUE;
}
if (FoundRange == nullptr)
{
return FALSE;
}
bFound = FALSE; // RESET bFound flag...
wil::com_ptr_nothrow<ITfRange> rangeTrackComposition;
if (SUCCEEDED(FoundRange->Clone(&rangeTrackComposition)))
{
//
// get the text range that does not include read only area for
// reconversion.
//
wil::com_ptr_nothrow<ITfRange> rangeAllText;
LONG cch;
if (SUCCEEDED(CEditSessionObject::GetAllTextRange(ecReadOnly, pInputContext, &rangeAllText, &cch)))
{
LONG lResult;
if (SUCCEEDED(rangeTrackComposition->CompareStart(ecReadOnly, rangeAllText.get(), TF_ANCHOR_START, &lResult)))
{
//
// if the start position of the track composition range is not
// the beginning of IC,
// the composition has been changed since we put it.
//
if (lResult != 0)
{
bFound = TRUE; // FOUND!!
}
else if (SUCCEEDED(rangeTrackComposition->CompareEnd(ecReadOnly, rangeAllText.get(), TF_ANCHOR_END, &lResult)))
{
//
// if the start position of the track composition range is not
// the beginning of IC,
// the composition has been changed since we put it.
//
//
// If we find the changes in these property, we need to update hIMC.
//
const GUID* guids[] = { &GUID_PROP_COMPOSING,
&GUID_PROP_ATTRIBUTE };
const int guid_size = sizeof(guids) / sizeof(GUID*);
wil::com_ptr_nothrow<IEnumTfRanges> EnumPropertyChanged;
if (lResult != 0)
{
bFound = TRUE; // FOUND!!
}
else if (SUCCEEDED(pEditRecord->GetTextAndPropertyUpdates(TF_GTP_INCL_TEXT, guids, guid_size, &EnumPropertyChanged)))
{
HRESULT hr;
wil::com_ptr_nothrow<ITfRange> range;
while ((hr = EnumPropertyChanged->Next(1, &range, nullptr)) == S_OK)
{
BOOL empty;
if (range->IsEmpty(ecReadOnly, &empty) == S_OK && empty)
{
continue;
}
bFound = TRUE; // FOUND!!
break;
}
}
}
}
}
}
return bFound;
}