add a method to textbox
a method to get bounds of a text selection
This commit is contained in:
parent
d6cb631bc2
commit
422f2c768b
@ -151,6 +151,8 @@ namespace nana{ namespace widgets
|
|||||||
|
|
||||||
bool selected() const;
|
bool selected() const;
|
||||||
bool select(bool);
|
bool select(bool);
|
||||||
|
bool get_select_points(nana::upoint&, nana::upoint&) const;
|
||||||
|
|
||||||
/// Sets the end position of a selected string.
|
/// Sets the end position of a selected string.
|
||||||
void set_end_caret();
|
void set_end_caret();
|
||||||
|
|
||||||
@ -233,7 +235,6 @@ namespace nana{ namespace widgets
|
|||||||
//@brief: redraw whole line specified by caret pos.
|
//@brief: redraw whole line specified by caret pos.
|
||||||
//@return: true if caret overs the border
|
//@return: true if caret overs the border
|
||||||
bool _m_update_caret_line(std::size_t secondary_before);
|
bool _m_update_caret_line(std::size_t secondary_before);
|
||||||
bool _m_get_sort_select_points(nana::upoint&, nana::upoint&) const;
|
|
||||||
|
|
||||||
void _m_offset_y(int y);
|
void _m_offset_y(int y);
|
||||||
|
|
||||||
|
|||||||
@ -184,7 +184,7 @@ namespace nana
|
|||||||
bool editable() const;
|
bool editable() const;
|
||||||
textbox& editable(bool);
|
textbox& editable(bool);
|
||||||
|
|
||||||
/// Enables the caret if the textbox current is not editable
|
/// Enables the caret if the textbox currently is not editable
|
||||||
textbox& enable_caret();
|
textbox& enable_caret();
|
||||||
|
|
||||||
void set_accept(std::function<bool(wchar_t)>);
|
void set_accept(std::function<bool(wchar_t)>);
|
||||||
@ -200,6 +200,12 @@ namespace nana
|
|||||||
/// Selects/unselects all text.
|
/// Selects/unselects all text.
|
||||||
void select(bool);
|
void select(bool);
|
||||||
|
|
||||||
|
/// Returns the bounds of a text selection
|
||||||
|
/**
|
||||||
|
* @return no selection if pair.first == pair.second.
|
||||||
|
*/
|
||||||
|
std::pair<upoint, upoint> selection() const;
|
||||||
|
|
||||||
void copy() const; ///< Copies the selected text into shared memory, such as clipboard under Windows.
|
void copy() const; ///< Copies the selected text into shared memory, such as clipboard under Windows.
|
||||||
void paste(); ///< Pastes the text from shared memory.
|
void paste(); ///< Pastes the text from shared memory.
|
||||||
void del();
|
void del();
|
||||||
|
|||||||
@ -2081,6 +2081,25 @@ namespace nana{ namespace widgets
|
|||||||
return false;
|
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
|
bool text_editor::hit_text_area(const point& pos) const
|
||||||
{
|
{
|
||||||
return _m_text_area().is_hit(pos);
|
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
|
bool text_editor::hit_select_area(nana::upoint pos, bool ignore_when_select_all) const
|
||||||
{
|
{
|
||||||
nana::upoint a, b;
|
nana::upoint a, b;
|
||||||
if(_m_get_sort_select_points(a, b))
|
if(get_select_points(a, b))
|
||||||
{
|
{
|
||||||
if (ignore_when_select_all)
|
if (ignore_when_select_all)
|
||||||
{
|
{
|
||||||
@ -3006,7 +3025,7 @@ namespace nana{ namespace widgets
|
|||||||
nana::upoint text_editor::_m_erase_select()
|
nana::upoint text_editor::_m_erase_select()
|
||||||
{
|
{
|
||||||
nana::upoint a, b;
|
nana::upoint a, b;
|
||||||
if (_m_get_sort_select_points(a, b))
|
if (get_select_points(a, b))
|
||||||
{
|
{
|
||||||
auto & textbase = this->textbase();
|
auto & textbase = this->textbase();
|
||||||
if(a.y != b.y)
|
if(a.y != b.y)
|
||||||
@ -3037,7 +3056,7 @@ namespace nana{ namespace widgets
|
|||||||
std::wstring text;
|
std::wstring text;
|
||||||
|
|
||||||
nana::upoint a, b;
|
nana::upoint a, b;
|
||||||
if (_m_get_sort_select_points(a, b))
|
if (get_select_points(a, b))
|
||||||
{
|
{
|
||||||
auto & textbase = this->textbase();
|
auto & textbase = this->textbase();
|
||||||
if (a.y != b.y)
|
if (a.y != b.y)
|
||||||
@ -3128,7 +3147,7 @@ namespace nana{ namespace widgets
|
|||||||
bool text_editor::_m_cancel_select(int align)
|
bool text_editor::_m_cancel_select(int align)
|
||||||
{
|
{
|
||||||
nana::upoint a, b;
|
nana::upoint a, b;
|
||||||
if(_m_get_sort_select_points(a, b))
|
if (get_select_points(a, b))
|
||||||
{
|
{
|
||||||
switch(align)
|
switch(align)
|
||||||
{
|
{
|
||||||
@ -3223,7 +3242,7 @@ namespace nana{ namespace widgets
|
|||||||
const bool at_left = (select_.b < select_.a);
|
const bool at_left = (select_.b < select_.a);
|
||||||
|
|
||||||
nana::upoint a, b;
|
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))
|
if (caret.y < a.y || (caret.y == a.y && caret.x < a.x))
|
||||||
{//forward
|
{//forward
|
||||||
undo_ptr->set_caret_pos();
|
undo_ptr->set_caret_pos();
|
||||||
@ -3419,7 +3438,7 @@ namespace nana{ namespace widgets
|
|||||||
const wchar_t *sbegin = nullptr, *send = nullptr;
|
const wchar_t *sbegin = nullptr, *send = nullptr;
|
||||||
|
|
||||||
nana::upoint a, b;
|
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)
|
if (a.y < text_coord.y && text_coord.y < b.y)
|
||||||
{
|
{
|
||||||
@ -3576,25 +3595,6 @@ namespace nana{ namespace widgets
|
|||||||
return true;
|
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)
|
void text_editor::_m_offset_y(int y)
|
||||||
{
|
{
|
||||||
points_.offset.y = y;
|
points_.offset.y = y;
|
||||||
|
|||||||
@ -469,6 +469,18 @@ namespace drawerbase {
|
|||||||
API::update_window(*this);
|
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
|
void textbox::copy() const
|
||||||
{
|
{
|
||||||
internal_scope_guard lock;
|
internal_scope_guard lock;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user