From eeaaf07f4c8e6f1a4fa25cadb0796eaf016e8b49 Mon Sep 17 00:00:00 2001 From: PeterAddy960 Date: Wed, 31 Aug 2016 20:29:34 -0500 Subject: [PATCH 1/6] Added methods to font object to get if font has underline and strikeout. --- source/paint/graphics.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/source/paint/graphics.cpp b/source/paint/graphics.cpp index 40530a18..ea8212cb 100644 --- a/source/paint/graphics.cpp +++ b/source/paint/graphics.cpp @@ -156,6 +156,18 @@ namespace paint return (impl_->font_ptr->italic); } + bool font::underline() const + { + if(empty()) return false; + return (impl_->font_ptr->underline); + } + + bool font::strikeout() const + { + if(empty()) return false; + return (impl_->font_ptr->strikeout); + } + native_font_type font::handle() const { if(empty()) return nullptr; From f4443bba903f84ea1ba8ea3f2bcd06addbc50b11 Mon Sep 17 00:00:00 2001 From: PeterAddy960 Date: Wed, 31 Aug 2016 20:30:11 -0500 Subject: [PATCH 2/6] Added methods to font object to get if font has underline and strikeout. --- include/nana/paint/graphics.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/nana/paint/graphics.hpp b/include/nana/paint/graphics.hpp index 8e667ef2..af4e1bdc 100644 --- a/include/nana/paint/graphics.hpp +++ b/include/nana/paint/graphics.hpp @@ -52,6 +52,8 @@ namespace nana bool italic() const; native_font_type handle() const; void release(); + bool strikeout() const; + bool underline() const; font& operator=(const font&); bool operator==(const font&) const; From 021ee1edb457be8dd14de8c163e82083e6624219 Mon Sep 17 00:00:00 2001 From: PeterAddy960 Date: Fri, 28 Oct 2016 00:05:56 -0500 Subject: [PATCH 3/6] Added a clear undo method to the textbox to erase all previous undo actions. Added an overload to the selected method that give back the bounds of the selection. --- include/nana/gui/widgets/skeletons/text_editor.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/nana/gui/widgets/skeletons/text_editor.hpp b/include/nana/gui/widgets/skeletons/text_editor.hpp index 22e099e4..a13c9dcf 100644 --- a/include/nana/gui/widgets/skeletons/text_editor.hpp +++ b/include/nana/gui/widgets/skeletons/text_editor.hpp @@ -205,6 +205,8 @@ namespace nana{ namespace widgets void undo_max_steps(std::size_t); std::size_t undo_max_steps() const; + void clear_undo(); + ext_renderer_tag& ext_renderer() const; unsigned line_height() const; @@ -226,6 +228,7 @@ namespace nana{ namespace widgets void show_caret(bool isshow); bool selected() const; + bool selected(nana::upoint &a,nana::upoint &b) const; bool select(bool); /// Sets the end position of a selected string. void set_end_caret(); From ea1edb5a4a12fe2cb3180ce85451350e81ab22b4 Mon Sep 17 00:00:00 2001 From: PeterAddy960 Date: Fri, 28 Oct 2016 00:07:33 -0500 Subject: [PATCH 4/6] Added a clear undo method. Added an overload to selected to get the selection bounds. Added an overload to the getline method to allow an offset from the beginning of the line. --- include/nana/gui/widgets/textbox.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/nana/gui/widgets/textbox.hpp b/include/nana/gui/widgets/textbox.hpp index 12008c37..c74fac54 100644 --- a/include/nana/gui/widgets/textbox.hpp +++ b/include/nana/gui/widgets/textbox.hpp @@ -162,6 +162,9 @@ namespace nana /// Read the text from a specified line. It returns true for success. bool getline(std::size_t pos, std::string&) const; + /// Read the text from a specified line with a set offset. It returns true for success. + bool getline(std::size_t line_index,std::size_t offset,std::string& text) const; + /// Gets the caret position /// Returns true if the caret is in the area of display, false otherwise. bool caret_pos(point& pos, bool text_coordinate) const; @@ -193,6 +196,7 @@ namespace nana /// Returns true if some text is selected. bool selected() const; + bool selected(nana::upoint &a,nana::upoint &b) const; /// Selects/unselects all text. void select(bool); @@ -206,6 +210,8 @@ namespace nana textbox& from(int); textbox& from(double); + void clear_undo(); + void set_highlight(const std::string& name, const ::nana::color& fgcolor, const ::nana::color& bgcolor); void erase_highlight(const std::string& name); void set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list kw_list); From 78c3527f10c5f5ee90272192bf505d7344a491b4 Mon Sep 17 00:00:00 2001 From: PeterAddy960 Date: Fri, 28 Oct 2016 00:10:11 -0500 Subject: [PATCH 5/6] Modified the implementation so that nana::keyboard::os_del is sent throght the set_accept function, so that os_del can be blocked. Added overload to selected to get the selection bounds. --- source/gui/widgets/skeletons/text_editor.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index a030471a..5574f9a2 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -1602,6 +1602,11 @@ namespace nana{ namespace widgets return undo_.max_steps(); } + void text_editor::clear_undo() + { + undo_.clear(); + } + text_editor::ext_renderer_tag& text_editor::ext_renderer() const { return ext_renderer_; From 8e84383a7b9addb965177944f67ffce246f22f0d Mon Sep 17 00:00:00 2001 From: PeterAddy960 Date: Fri, 28 Oct 2016 00:17:59 -0500 Subject: [PATCH 6/6] 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;