fix mask textbox highlight with mask

This commit is contained in:
Jinhao 2015-04-13 23:41:42 +08:00
parent ed462870e0
commit 53c36b7363

View File

@ -314,7 +314,13 @@ namespace nana{ namespace widgets
if (pos.y > static_cast<unsigned>(textbase.lines()))
pos.y = static_cast<unsigned>(textbase.lines());
pos.x = editor_._m_pixels_by_char(textbase.getline(pos.y), pos.x) + editor_.text_area_.area.x;
std::unique_ptr<nana::string> mask_str;
if (editor_.mask_char_)
mask_str.reset(new nana::string(textbase.getline(pos.y).size(), editor_.mask_char_));
auto & lnstr = editor_.mask_char_ ? *mask_str : textbase.getline(pos.y);
pos.x = editor_._m_pixels_by_char(lnstr, pos.x) + editor_.text_area_.area.x;
int pos_y = static_cast<int>((pos.y - editor_.points_.offset.y) * editor_.line_height() + editor_._m_text_top_base());
int pos_x = static_cast<int>(pos.x - editor_.points_.offset.x);
@ -327,7 +333,13 @@ namespace nana{ namespace widgets
nana::upoint res{ 0, static_cast<unsigned>(_m_textline_from_screen(scrpos.y)) };
//Convert the screen point to text caret point
const string_type& lnstr = editor_.textbase_.getline(res.y);
const string_type& real_str = editor_.textbase_.getline(res.y);
std::unique_ptr<nana::string> mask_str;
if (editor_.mask_char_)
mask_str.reset(new nana::string(real_str.size(), editor_.mask_char_));
auto & lnstr = (editor_.mask_char_ ? *mask_str : real_str);
if (lnstr.size() > 0)
{
scrpos.x += (editor_.points_.offset.x - editor_.text_area_.area.x);
@ -737,17 +749,24 @@ namespace nana{ namespace widgets
nana::point scrpos;
if (0 != pos.x)
{
nana::string str;
for (auto & sec : mtr.line_sections)
{
std::size_t chsize = sec.end - sec.begin;
str.clear();
if (editor_.mask_char_)
str.append(chsize, editor_.mask_char_);
else
str.append(sec.begin, sec.end);
if (pos.x < chsize)
{
scrpos.x = editor_._m_pixels_by_char(nana::string(sec.begin, sec.end), pos.x);
scrpos.x = editor_._m_pixels_by_char(str, pos.x);
break;
}
else if (pos.x == chsize)
{
scrpos.x = editor_._m_text_extent_size(nana::string(sec.begin, sec.end).data(), sec.end - sec.begin).width;
scrpos.x = editor_._m_text_extent_size(str.data(), sec.end - sec.begin).width;
break;
}
else
@ -773,13 +792,19 @@ namespace nana{ namespace widgets
return{ 0, static_cast<unsigned>(primary) };
//First of all, find the text of secondary.
auto str = mtr.line_sections[secondary];
auto real_str = mtr.line_sections[secondary];
std::unique_ptr<nana::string> mask_str;
if (editor_.mask_char_)
mask_str.reset(new nana::string(real_str.end - real_str.begin, editor_.mask_char_));
const ::nana::char_t * str = (editor_.mask_char_ ? mask_str->data() : real_str.begin);
std::vector<unicode_bidi::entity> reordered;
unicode_bidi bidi;
bidi.linestr(str.begin, str.end - str.begin, reordered);
bidi.linestr(str, real_str.end - real_str.begin, reordered);
nana::upoint res(static_cast<unsigned>(str.begin - mtr.line_sections.front().begin), static_cast<unsigned>(primary));
nana::upoint res(static_cast<unsigned>(real_str.begin - mtr.line_sections.front().begin), static_cast<unsigned>(primary));
scrpos.x -= editor_.text_area_.area.x;
if (scrpos.x < 0)
scrpos.x = 0;
@ -793,7 +818,7 @@ namespace nana{ namespace widgets
std::unique_ptr<unsigned[]> pxbuf(new unsigned[len]);
res.x += editor_._m_char_by_pixels(ent.begin, len, pxbuf.get(), str_px, scrpos.x, _m_is_right_text(ent));
res.x += static_cast<unsigned>(ent.begin - str.begin);
res.x += static_cast<unsigned>(ent.begin - str);
return res;
}
scrpos.x -= str_px;
@ -2760,18 +2785,17 @@ namespace nana{ namespace widgets
}
}
void text_editor::_m_draw_string(int top, const ::nana::color& clr, const nana::upoint& str_pos, const nana::string& linestr, bool if_mask) const
void text_editor::_m_draw_string(int top, const ::nana::color& clr, const nana::upoint& str_pos, const nana::string& str, bool if_mask) const
{
::nana::point text_pos{ text_area_.area.x - points_.offset.x, top };
const int xend = text_area_.area.x + static_cast<int>(text_area_.area.width);
std::unique_ptr<nana::string> mask_str;
if (if_mask && mask_char_)
{
nana::string maskstr;
maskstr.append(linestr.size(), mask_char_);
graph_.string(text_pos, maskstr, clr);
return;
}
mask_str.reset(new nana::string(str.size(), mask_char_));
auto & linestr = (if_mask && mask_char_ ? *mask_str : str);
unicode_bidi bidi;
std::vector<unicode_bidi::entity> reordered;