2019-05-03 00:29:04 +02:00
|
|
|
/*++
|
|
|
|
|
|
|
|
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
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2019-06-11 22:27:09 +02:00
|
|
|
[[nodiscard]] HRESULT CConversionArea::DrawComposition(const std::wstring_view CompStr,
|
|
|
|
const std::vector<TF_DISPLAYATTRIBUTE>& DisplayAttributes,
|
|
|
|
const DWORD CompCursorPos)
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
|
|
|
// 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,
|
2019-06-11 22:27:09 +02:00
|
|
|
DEFAULT_COMP_INPUT_ERROR };
|
2019-05-03 00:29:04 +02:00
|
|
|
|
|
|
|
const auto encodedAttributes = _DisplayAttributesToEncodedAttributes(DisplayAttributes,
|
|
|
|
CompCursorPos);
|
|
|
|
|
2020-07-15 18:40:42 +02:00
|
|
|
gsl::span<const BYTE> attributes(encodedAttributes.data(), encodedAttributes.size());
|
|
|
|
gsl::span<const WORD> colorArray(colors.data(), colors.size());
|
2019-05-03 00:29:04 +02:00
|
|
|
|
2019-05-21 19:32:43 +02:00
|
|
|
return ImeComposeData(CompStr, attributes, colorArray);
|
2019-05-03 00:29:04 +02:00
|
|
|
}
|
|
|
|
|
2019-06-11 22:27:09 +02:00
|
|
|
[[nodiscard]] HRESULT CConversionArea::ClearComposition()
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
|
|
|
return ImeClearComposeData();
|
|
|
|
}
|
|
|
|
|
2019-06-11 22:27:09 +02:00
|
|
|
[[nodiscard]] HRESULT CConversionArea::DrawResult(const std::wstring_view ResultStr)
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
2019-05-21 19:32:43 +02:00
|
|
|
return ImeComposeResult(ResultStr);
|
2019-05-03 00:29:04 +02:00
|
|
|
}
|
|
|
|
|
2019-06-11 22:27:09 +02:00
|
|
|
[[nodiscard]] std::vector<BYTE> CConversionArea::_DisplayAttributesToEncodedAttributes(const std::vector<TF_DISPLAYATTRIBUTE>& DisplayAttributes,
|
|
|
|
const DWORD CompCursorPos)
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2019-11-04 14:37:48 +01:00
|
|
|
encodedAttrs[CompCursorPos] |= CONIME_CURSOR_LEFT; // special handling for ConSrv... 0x20 = COMMON_LVB_GRID_SINGLEFLAG + COMMON_LVB_GRID_LVERTICAL
|
2019-05-03 00:29:04 +02:00
|
|
|
}
|
|
|
|
else if (CompCursorPos - 1 < DisplayAttributes.size())
|
|
|
|
{
|
2019-11-04 14:37:48 +01:00
|
|
|
encodedAttrs[CompCursorPos - 1] |= CONIME_CURSOR_RIGHT; // special handling for ConSrv... 0x10 = COMMON_LVB_GRID_SINGLEFLAG + COMMON_LVB_GRID_RVERTICAL
|
2019-05-03 00:29:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return encodedAttrs;
|
|
|
|
}
|