add a method to textbox
a method to get bounds of a text selection
This commit is contained in:
@@ -2081,6 +2081,25 @@ namespace nana{ namespace widgets
|
||||
return false;
|
||||
}
|
||||
|
||||
bool text_editor::get_select_points(nana::upoint& a, nana::upoint& b) const
|
||||
{
|
||||
if (select_.a == select_.b)
|
||||
return false;
|
||||
|
||||
if (select_.a < select_.b)
|
||||
{
|
||||
a = select_.a;
|
||||
b = select_.b;
|
||||
}
|
||||
else
|
||||
{
|
||||
a = select_.b;
|
||||
b = select_.a;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool text_editor::hit_text_area(const point& pos) const
|
||||
{
|
||||
return _m_text_area().is_hit(pos);
|
||||
@@ -2089,7 +2108,7 @@ namespace nana{ namespace widgets
|
||||
bool text_editor::hit_select_area(nana::upoint pos, bool ignore_when_select_all) const
|
||||
{
|
||||
nana::upoint a, b;
|
||||
if(_m_get_sort_select_points(a, b))
|
||||
if(get_select_points(a, b))
|
||||
{
|
||||
if (ignore_when_select_all)
|
||||
{
|
||||
@@ -3006,7 +3025,7 @@ namespace nana{ namespace widgets
|
||||
nana::upoint text_editor::_m_erase_select()
|
||||
{
|
||||
nana::upoint a, b;
|
||||
if (_m_get_sort_select_points(a, b))
|
||||
if (get_select_points(a, b))
|
||||
{
|
||||
auto & textbase = this->textbase();
|
||||
if(a.y != b.y)
|
||||
@@ -3037,7 +3056,7 @@ namespace nana{ namespace widgets
|
||||
std::wstring text;
|
||||
|
||||
nana::upoint a, b;
|
||||
if (_m_get_sort_select_points(a, b))
|
||||
if (get_select_points(a, b))
|
||||
{
|
||||
auto & textbase = this->textbase();
|
||||
if (a.y != b.y)
|
||||
@@ -3128,7 +3147,7 @@ namespace nana{ namespace widgets
|
||||
bool text_editor::_m_cancel_select(int align)
|
||||
{
|
||||
nana::upoint a, b;
|
||||
if(_m_get_sort_select_points(a, b))
|
||||
if (get_select_points(a, b))
|
||||
{
|
||||
switch(align)
|
||||
{
|
||||
@@ -3223,7 +3242,7 @@ namespace nana{ namespace widgets
|
||||
const bool at_left = (select_.b < select_.a);
|
||||
|
||||
nana::upoint a, b;
|
||||
_m_get_sort_select_points(a, b);
|
||||
get_select_points(a, b);
|
||||
if (caret.y < a.y || (caret.y == a.y && caret.x < a.x))
|
||||
{//forward
|
||||
undo_ptr->set_caret_pos();
|
||||
@@ -3419,7 +3438,7 @@ namespace nana{ namespace widgets
|
||||
const wchar_t *sbegin = nullptr, *send = nullptr;
|
||||
|
||||
nana::upoint a, b;
|
||||
if (_m_get_sort_select_points(a, b))
|
||||
if (get_select_points(a, b))
|
||||
{
|
||||
if (a.y < text_coord.y && text_coord.y < b.y)
|
||||
{
|
||||
@@ -3576,25 +3595,6 @@ namespace nana{ namespace widgets
|
||||
return true;
|
||||
}
|
||||
|
||||
bool text_editor::_m_get_sort_select_points(nana::upoint& a, nana::upoint& b) const
|
||||
{
|
||||
if (select_.a == select_.b)
|
||||
return false;
|
||||
|
||||
if (select_.a < select_.b)
|
||||
{
|
||||
a = select_.a;
|
||||
b = select_.b;
|
||||
}
|
||||
else
|
||||
{
|
||||
a = select_.b;
|
||||
b = select_.a;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void text_editor::_m_offset_y(int y)
|
||||
{
|
||||
points_.offset.y = y;
|
||||
|
||||
@@ -469,6 +469,18 @@ namespace drawerbase {
|
||||
API::update_window(*this);
|
||||
}
|
||||
|
||||
std::pair<upoint, upoint> textbox::selection() const
|
||||
{
|
||||
std::pair<upoint, upoint> points;
|
||||
|
||||
internal_scope_guard lock;
|
||||
auto editor = get_drawer_trigger().editor();
|
||||
if (editor)
|
||||
editor->get_select_points(points.first, points.second);
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
void textbox::copy() const
|
||||
{
|
||||
internal_scope_guard lock;
|
||||
|
||||
Reference in New Issue
Block a user