From b5db21567fa23ae7afbbbad44fec4d8293bf66ca Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sun, 18 Jun 2017 05:08:51 +0800 Subject: [PATCH] add new methods to textbox for line count --- .../gui/widgets/skeletons/text_editor.hpp | 2 ++ include/nana/gui/widgets/textbox.hpp | 11 ++++++++++ source/gui/widgets/skeletons/text_editor.cpp | 8 ++++++++ source/gui/widgets/textbox.cpp | 20 +++++++++++++++++++ 4 files changed, 41 insertions(+) diff --git a/include/nana/gui/widgets/skeletons/text_editor.hpp b/include/nana/gui/widgets/skeletons/text_editor.hpp index 49bb0867..cf8ee302 100644 --- a/include/nana/gui/widgets/skeletons/text_editor.hpp +++ b/include/nana/gui/widgets/skeletons/text_editor.hpp @@ -183,6 +183,8 @@ namespace nana{ namespace widgets void focus_behavior(text_focus_behavior); void select_behavior(bool move_to_end); + + std::size_t line_count(bool text_lines) const; public: void draw_corner(); void render(bool focused); diff --git a/include/nana/gui/widgets/textbox.hpp b/include/nana/gui/widgets/textbox.hpp index e37ed6fc..6df66d18 100644 --- a/include/nana/gui/widgets/textbox.hpp +++ b/include/nana/gui/widgets/textbox.hpp @@ -257,6 +257,17 @@ namespace nana * @param len The length of the queue. If this parameter is zero, the undo/redo is disabled. */ void set_undo_queue_length(std::size_t len); + + /// Returns the number of lines that text are displayed in the screen. + /** + * The number of display lines may be not equal to the number of text lines when the textbox + * is line wrapped mode. + * @return the number of lines that text are displayed in the screen. + */ + std::size_t display_line_count() const; + + /// Returns the number of text lines. + std::size_t text_line_count() const; protected: //Overrides widget's virtual functions native_string_type _m_caption() const throw() override; diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index 3d5077bf..50d67b85 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -1872,6 +1872,14 @@ namespace nana{ namespace widgets select_.move_to_end = move_to_end; } + std::size_t text_editor::line_count(bool text_lines) const + { + if (text_lines) + return textbase().lines(); + + return impl_->capacities.behavior->take_lines(); + } + void text_editor::draw_corner() { impl_->cview->draw_corner(graph_); diff --git a/source/gui/widgets/textbox.cpp b/source/gui/widgets/textbox.cpp index 5ae9454b..f0b3351c 100644 --- a/source/gui/widgets/textbox.cpp +++ b/source/gui/widgets/textbox.cpp @@ -720,6 +720,26 @@ namespace drawerbase { editor->set_undo_queue_length(len); } + std::size_t textbox::display_line_count() const + { + internal_scope_guard lock; + auto editor = get_drawer_trigger().editor(); + if (editor) + return editor->line_count(false); + + return 0; + } + + std::size_t textbox::text_line_count() const + { + internal_scope_guard lock; + auto editor = get_drawer_trigger().editor(); + if (editor) + return editor->line_count(true); + + return 0; + } + //Override _m_caption for caption() auto textbox::_m_caption() const throw() -> native_string_type {