From 8e84383a7b9addb965177944f67ffce246f22f0d Mon Sep 17 00:00:00 2001 From: PeterAddy960 Date: Fri, 28 Oct 2016 00:17:59 -0500 Subject: [PATCH] Added an overload to getline to allow an offset from the beginning of the line. Added a clear undo method. Added an overload to selected to get the selected bounds. --- source/gui/widgets/skeletons/text_editor.cpp | 10 ++++++- source/gui/widgets/textbox.cpp | 31 ++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index 5574f9a2..d8b4cd56 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -1427,7 +1427,8 @@ namespace nana{ namespace widgets _handle_move_key(arg); break; case keyboard::os_del: - if (this->attr().editable) + // send delete to set_accept function + if (this->attr().editable && (!attributes_.pred_acceptive || attributes_.pred_acceptive(key))) del(); break; default: @@ -1916,6 +1917,13 @@ namespace nana{ namespace widgets return (select_.a != select_.b); } + bool text_editor::selected(nana::upoint &a,nana::upoint &b) const + { + a = select_.a; + b = select_.b; + return selected(); + } + void text_editor::set_end_caret() { bool new_sel_end = (select_.b != points_.caret); diff --git a/source/gui/widgets/textbox.cpp b/source/gui/widgets/textbox.cpp index 76aed3ac..c6c5575c 100644 --- a/source/gui/widgets/textbox.cpp +++ b/source/gui/widgets/textbox.cpp @@ -318,6 +318,25 @@ namespace drawerbase { return false; } + bool textbox::getline(std::size_t line_index,std::size_t start_point,std::string& text) const + { + internal_scope_guard lock; + auto editor = get_drawer_trigger().editor(); + if(editor) + { + std::wstring line_text; + if(editor->getline(line_index,line_text)) + { + if(line_text.length() >= start_point) + { + text = to_utf8(line_text.substr(start_point)); + return true; + } + } + } + return false; + } + /// Gets the caret position bool textbox::caret_pos(point& pos, bool text_coordinate) const { @@ -451,6 +470,13 @@ namespace drawerbase { return (editor ? editor->selected() : false); } + bool textbox::selected(nana::upoint &a,nana::upoint &b) const + { + internal_scope_guard lock; + auto editor = get_drawer_trigger().editor(); + return (editor ? editor->selected(a,b) : false); + } + void textbox::select(bool yes) { internal_scope_guard lock; @@ -517,6 +543,11 @@ namespace drawerbase { return *this; } + void textbox::clear_undo() + { + get_drawer_trigger().editor()->clear_undo(); + } + void textbox::set_highlight(const std::string& name, const ::nana::color& fgcolor, const ::nana::color& bgcolor) { internal_scope_guard lock;