2019-05-03 00:29:04 +02:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
// Licensed under the MIT license.
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
#include "AttrRow.hpp"
|
|
|
|
|
2019-06-11 22:27:09 +02:00
|
|
|
// Routine Description:
|
|
|
|
// - constructor
|
|
|
|
// Arguments:
|
|
|
|
// - cchRowWidth - the length of the default text attribute
|
|
|
|
// - attr - the default text attribute
|
|
|
|
// Return Value:
|
|
|
|
// - constructed object
|
2021-05-20 19:27:50 +02:00
|
|
|
ATTR_ROW::ATTR_ROW(const uint16_t width, const TextAttribute attr) :
|
|
|
|
_data(width, attr) {}
|
2019-05-03 00:29:04 +02:00
|
|
|
|
|
|
|
// Routine Description:
|
|
|
|
// - Sets all properties of the ATTR_ROW to default values
|
|
|
|
// Arguments:
|
|
|
|
// - attr - The default text attributes to use on text in this row.
|
|
|
|
void ATTR_ROW::Reset(const TextAttribute attr)
|
|
|
|
{
|
2021-05-20 19:27:50 +02:00
|
|
|
_data.replace(0, _data.size(), attr);
|
2019-05-03 00:29:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Routine Description:
|
|
|
|
// - Takes an existing row of attributes, and changes the length so that it fills the NewWidth.
|
|
|
|
// If the new size is bigger, then the last attr is extended to fill the NewWidth.
|
|
|
|
// If the new size is smaller, the runs are cut off to fit.
|
|
|
|
// Arguments:
|
|
|
|
// - oldWidth - The original width of the row.
|
|
|
|
// - newWidth - The new width of the row.
|
|
|
|
// Return Value:
|
|
|
|
// - <none>, throws exceptions on failures.
|
2021-05-20 19:27:50 +02:00
|
|
|
void ATTR_ROW::Resize(const uint16_t newWidth)
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
2021-05-20 19:27:50 +02:00
|
|
|
_data.resize_trailing_extent(newWidth);
|
2019-05-03 00:29:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Routine Description:
|
|
|
|
// - returns a copy of the TextAttribute at the specified column
|
|
|
|
// Arguments:
|
|
|
|
// - column - the column to get the attribute for
|
|
|
|
// Return Value:
|
|
|
|
// - the text attribute at column
|
|
|
|
// Note:
|
|
|
|
// - will throw on error
|
2021-05-20 19:27:50 +02:00
|
|
|
TextAttribute ATTR_ROW::GetAttrByColumn(const uint16_t column) const
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
2021-05-20 19:27:50 +02:00
|
|
|
return _data.at(column);
|
2019-05-03 00:29:04 +02:00
|
|
|
}
|
|
|
|
|
2020-09-03 19:52:39 +02:00
|
|
|
// Routine Description:
|
|
|
|
// - Finds the hyperlink IDs present in this row and returns them
|
|
|
|
// Return value:
|
2021-01-05 19:06:06 +01:00
|
|
|
// - The hyperlink IDs present in this row
|
2021-05-20 19:27:50 +02:00
|
|
|
std::vector<uint16_t> ATTR_ROW::GetHyperlinks() const
|
2020-09-03 19:52:39 +02:00
|
|
|
{
|
2021-01-05 19:06:06 +01:00
|
|
|
std::vector<uint16_t> ids;
|
2021-05-20 19:27:50 +02:00
|
|
|
for (const auto& run : _data.runs())
|
2020-09-03 19:52:39 +02:00
|
|
|
{
|
2021-05-20 19:27:50 +02:00
|
|
|
if (run.value.IsHyperlink())
|
2020-09-03 19:52:39 +02:00
|
|
|
{
|
2021-05-20 19:27:50 +02:00
|
|
|
ids.emplace_back(run.value.GetHyperlinkId());
|
2020-09-03 19:52:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ids;
|
|
|
|
}
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
// Routine Description:
|
|
|
|
// - Sets the attributes (colors) of all character positions from the given position through the end of the row.
|
|
|
|
// Arguments:
|
|
|
|
// - iStart - Starting index position within the row
|
|
|
|
// - attr - Attribute (color) to fill remaining characters with
|
|
|
|
// Return Value:
|
|
|
|
// - <none>
|
2021-05-20 19:27:50 +02:00
|
|
|
bool ATTR_ROW::SetAttrToEnd(const uint16_t beginIndex, const TextAttribute attr)
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
2021-05-20 19:27:50 +02:00
|
|
|
_data.replace(gsl::narrow<uint16_t>(beginIndex), _data.size(), attr);
|
|
|
|
return true;
|
2019-05-03 00:29:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Method Description:
|
|
|
|
// - Replaces all runs in the row with the given toBeReplacedAttr with the new
|
|
|
|
// attribute replaceWith.
|
|
|
|
// Arguments:
|
|
|
|
// - toBeReplacedAttr - the attribute to replace in this row.
|
|
|
|
// - replaceWith - the new value for the matching runs' attributes.
|
|
|
|
// Return Value:
|
|
|
|
// - <none>
|
2021-05-20 19:27:50 +02:00
|
|
|
void ATTR_ROW::ReplaceAttrs(const TextAttribute& toBeReplacedAttr, const TextAttribute& replaceWith)
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
2021-05-20 19:27:50 +02:00
|
|
|
_data.replace_values(toBeReplacedAttr, replaceWith);
|
2019-05-03 00:29:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Routine Description:
|
2021-05-20 19:27:50 +02:00
|
|
|
// - Takes an attribute, and merges it into this row from beginIndex (inclusive) to endIndex (exclusive).
|
|
|
|
// - For example, if the current row was was [{4, BLUE}], the merge arguments were
|
|
|
|
// { beginIndex = 1, endIndex = 3, newAttr = RED }, then the row would modified to be
|
|
|
|
// [{ 1, BLUE}, {2, RED}, {1, BLUE}].
|
2019-05-03 00:29:04 +02:00
|
|
|
// Arguments:
|
2021-05-20 19:27:50 +02:00
|
|
|
// - beginIndex, endIndex: The [beginIndex, endIndex) range that's to be replaced with newAttr.
|
|
|
|
// - newAttr: The attribute to merge into this row.
|
2019-05-03 00:29:04 +02:00
|
|
|
// Return Value:
|
2021-05-20 19:27:50 +02:00
|
|
|
// - <none>
|
|
|
|
void ATTR_ROW::Replace(const uint16_t beginIndex, const uint16_t endIndex, const TextAttribute& newAttr)
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
2021-05-20 19:27:50 +02:00
|
|
|
_data.replace(beginIndex, endIndex, newAttr);
|
2019-05-03 00:29:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ATTR_ROW::const_iterator ATTR_ROW::begin() const noexcept
|
|
|
|
{
|
2021-05-20 19:27:50 +02:00
|
|
|
return _data.begin();
|
2019-05-03 00:29:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ATTR_ROW::const_iterator ATTR_ROW::end() const noexcept
|
|
|
|
{
|
2021-05-20 19:27:50 +02:00
|
|
|
return _data.end();
|
2019-05-03 00:29:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ATTR_ROW::const_iterator ATTR_ROW::cbegin() const noexcept
|
|
|
|
{
|
2021-05-20 19:27:50 +02:00
|
|
|
return _data.cbegin();
|
2019-05-03 00:29:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ATTR_ROW::const_iterator ATTR_ROW::cend() const noexcept
|
|
|
|
{
|
2021-05-20 19:27:50 +02:00
|
|
|
return _data.cend();
|
2019-05-03 00:29:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const ATTR_ROW& a, const ATTR_ROW& b) noexcept
|
|
|
|
{
|
2021-05-20 19:27:50 +02:00
|
|
|
return a._data == b._data;
|
2019-05-03 00:29:04 +02:00
|
|
|
}
|