-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTfConvArea.cpp
More file actions
112 lines (89 loc) · 3.65 KB
/
Copy pathTfConvArea.cpp
File metadata and controls
112 lines (89 loc) · 3.65 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
/*++
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
Module Name:
TfConvArea.cpp
Abstract:
This file implements the CConversionArea Class.
Author:
Revision History:
Notes:
--*/
#include "precomp.h"
#include "ConsoleTSF.h"
#include "TfCtxtComp.h"
#include "TfConvArea.h"
//+---------------------------------------------------------------------------
// CConversionArea
//----------------------------------------------------------------------------
[[nodiscard]]
HRESULT CConversionArea::DrawComposition(const CComBSTR& CompStr,
const std::vector<TF_DISPLAYATTRIBUTE>& DisplayAttributes,
const DWORD CompCursorPos)
{
// Set up colors.
static const std::array<WORD, CONIME_ATTRCOLOR_SIZE> colors{ DEFAULT_COMP_ENTERED,
DEFAULT_COMP_ALREADY_CONVERTED,
DEFAULT_COMP_CONVERSION,
DEFAULT_COMP_YET_CONVERTED,
DEFAULT_COMP_INPUT_ERROR,
DEFAULT_COMP_INPUT_ERROR,
DEFAULT_COMP_INPUT_ERROR,
DEFAULT_COMP_INPUT_ERROR
};
std::wstring_view text(CompStr, CompStr.Length());
const auto encodedAttributes = _DisplayAttributesToEncodedAttributes(DisplayAttributes,
CompCursorPos);
std::basic_string_view<BYTE> attributes(encodedAttributes.data(), encodedAttributes.size());
std::basic_string_view<WORD> colorArray(colors.data(), colors.size());
return ImeComposeData(text, attributes, colorArray);
}
[[nodiscard]]
HRESULT CConversionArea::ClearComposition()
{
return ImeClearComposeData();
}
[[nodiscard]]
HRESULT CConversionArea::DrawResult(const CComBSTR& ResultStr)
{
std::wstring_view text(ResultStr, ResultStr.Length());
return ImeComposeResult(text);
}
[[nodiscard]]
std::vector<BYTE> CConversionArea::_DisplayAttributesToEncodedAttributes(const std::vector<TF_DISPLAYATTRIBUTE>& DisplayAttributes,
const DWORD CompCursorPos)
{
std::vector<BYTE> encodedAttrs;
for (const auto& da : DisplayAttributes)
{
BYTE bAttr;
if (da.bAttr == TF_ATTR_OTHER || da.bAttr > TF_ATTR_FIXEDCONVERTED)
{
bAttr = ATTR_TARGET_CONVERTED;
}
else
{
if (da.bAttr == TF_ATTR_INPUT_ERROR)
{
bAttr = ATTR_CONVERTED;
}
else
{
bAttr = (BYTE)da.bAttr;
}
}
encodedAttrs.emplace_back(bAttr);
}
if (CompCursorPos != -1)
{
if (CompCursorPos == 0)
{
encodedAttrs[CompCursorPos] |= (BYTE)CONIME_CURSOR_LEFT; // special handling for ConSrv... 0x20 = COMMON_LVB_GRID_SINGLEFLAG + COMMON_LVB_GRID_LVERTICAL
}
else if (CompCursorPos - 1 < DisplayAttributes.size())
{
encodedAttrs[CompCursorPos - 1] |= (BYTE)CONIME_CURSOR_RIGHT; // special handling for ConSrv... 0x10 = COMMON_LVB_GRID_SINGLEFLAG + COMMON_LVB_GRID_RVERTICAL
}
}
return encodedAttrs;
}