diff --git a/include/nana/gui/widgets/menu.hpp b/include/nana/gui/widgets/menu.hpp index 407397a0..8e0e7b44 100644 --- a/include/nana/gui/widgets/menu.hpp +++ b/include/nana/gui/widgets/menu.hpp @@ -13,7 +13,7 @@ #ifndef NANA_GUI_WIDGETS_MENU_HPP #define NANA_GUI_WIDGETS_MENU_HPP -#include +#include "widget.hpp" #include #include diff --git a/include/nana/gui/widgets/menubar.hpp b/include/nana/gui/widgets/menubar.hpp index 5d5606f7..b636a125 100644 --- a/include/nana/gui/widgets/menubar.hpp +++ b/include/nana/gui/widgets/menubar.hpp @@ -12,8 +12,8 @@ #ifndef NANA_GUI_WIDGETS_MENUBAR_HPP #define NANA_GUI_WIDGETS_MENUBAR_HPP -#include -#include +#include "widget.hpp" +#include "menu.hpp" #include namespace nana diff --git a/include/nana/gui/widgets/skeletons/text_editor.hpp b/include/nana/gui/widgets/skeletons/text_editor.hpp index 0725d4bd..ef509462 100644 --- a/include/nana/gui/widgets/skeletons/text_editor.hpp +++ b/include/nana/gui/widgets/skeletons/text_editor.hpp @@ -99,12 +99,6 @@ namespace nana{ namespace widgets void indent(bool, std::function generator); void set_event(event_interface*); - /// Determine whether the text_editor is line wrapped. - bool line_wrapped() const; - - /// Set the text_editor whether it is line wrapped, it returns false if the state is not changed. - bool line_wrapped(bool); - bool load(const char*); /// Sets the text area. @@ -116,7 +110,12 @@ namespace nana{ namespace widgets bool tip_string(::std::string&&); - const attributes & attr() const; + /// Returns the reference of listbox attributes + const attributes & attr() const noexcept; + + /// Set the text_editor whether it is line wrapped, it returns false if the state is not changed. + bool line_wrapped(bool); + bool multi_lines(bool); /// Enables/disables the editability of text_editor diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index 3e4c8714..16076d8a 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -430,7 +430,7 @@ namespace nana{ namespace widgets nana::point caret_to_screen(nana::upoint pos) override { - pos.y = (std::min)(pos.y, static_cast(editor_.textbase().lines())); + pos.y = (std::min)(pos.y, static_cast(editor_.textbase().lines())); auto text_ptr = &editor_.textbase().getline(pos.y); @@ -440,9 +440,8 @@ namespace nana{ namespace widgets mask_str.resize(text_ptr->size(), editor_.mask_char_); text_ptr = &mask_str; } - - if (pos.x > text_ptr->size()) - pos.x = static_cast(text_ptr->size()); + + pos.x = (std::min)(static_cast(text_ptr->size()), pos.x); pos.x = editor_._m_pixels_by_char(*text_ptr, pos.x) + editor_.text_area_.area.x; int pos_y = static_cast((pos.y - editor_.points_.offset.y) * editor_.line_height() + editor_._m_text_top_base()); @@ -543,12 +542,12 @@ namespace nana{ namespace widgets editor_._m_get_scrollbar_size(); auto& lnstr = textbase.getline(points.caret.y); - const auto x = (points.caret.x > lnstr.size() ? static_cast(lnstr.size()) : points.caret.x); + const auto x = (std::min)(points.caret.x, static_cast(lnstr.size())); auto const text_w = editor_._m_pixels_by_char(lnstr, x); unsigned area_w = editor_._m_text_area().width; - bool adjusted_cond = true; + const auto pre_x = points.offset.x; if (static_cast(text_w) < points.offset.x) { auto delta_pixels = editor_._m_text_extent_size(L" ", 4).width; @@ -556,12 +555,11 @@ namespace nana{ namespace widgets } else if (area_w && (text_w >= points.offset.x + area_w)) points.offset.x = text_w - area_w + 2; - else - adjusted_cond = false; - bool adjusted_cond2 = true; int value = points.offset.y; - if (scrlines && (points.caret.y >= points.offset.y + scrlines)) + const auto pre_y = points.offset.y; + + if (points.caret.y >= points.offset.y + scrlines) //implicit condition scrlines > 0 { value = static_cast(points.caret.y - scrlines) + 1; } @@ -574,12 +572,10 @@ namespace nana{ namespace widgets } else if (points.offset.y && (textbase.lines() <= scrlines)) value = 0; - else - adjusted_cond2 = false; editor_._m_offset_y(value); editor_._m_scrollbar(); - return (adjusted_cond || adjusted_cond2); + return (pre_x != points.offset.x) || (pre_y != points.offset.y); } private: @@ -1333,12 +1329,6 @@ namespace nana{ namespace widgets pos = text.find(ds.text, pos); if (pos == text.npos) break; - - if (ds.whole_word_matched) - { - if (!_m_whole_word(text, pos, ds.text.size())) - continue; - } } else { @@ -1348,16 +1338,13 @@ namespace nana{ namespace widgets pos = cistr.find(ds.text.c_str(), pos); if (pos == cistr.npos) break; - - if (ds.whole_word_matched) - { - if (!_m_whole_word(text, pos, ds.text.size())) - continue; - } } + if (ds.whole_word_matched && (!_m_whole_word(text, pos, ds.text.size()))) + continue; + auto ki = keywords.schemes.find(ds.scheme); - if (ki != keywords.schemes.end() && ki->second) + if ((ki != keywords.schemes.end()) && ki->second) { entities.emplace_back(); auto & last = entities.back(); @@ -1591,10 +1578,6 @@ namespace nana{ namespace widgets void text_editor::indent(bool enb, std::function generator) { - /* - indent_.enabled = enb; - indent_.generator = std::move(generator); - */ impl_->indent.enabled = enb; impl_->indent.generator = std::move(generator); } @@ -1604,39 +1587,6 @@ namespace nana{ namespace widgets event_handler_ = ptr; } - bool text_editor::line_wrapped() const - { - return attributes_.line_wrapped; - } - - bool text_editor::line_wrapped(bool autl) - { - if (autl != attributes_.line_wrapped) - { - attributes_.line_wrapped = autl; - - delete impl_->capacities.behavior; - if (autl) - { - impl_->capacities.behavior = new behavior_linewrapped(*this); - text_area_.vscroll = text_area_.scroll_pixels; - text_area_.hscroll = 0; - impl_->capacities.behavior->pre_calc_lines(width_pixels()); - } - else - impl_->capacities.behavior = new behavior_normal(*this); - - points_.offset.x = 0; - _m_offset_y(0); - move_caret(upoint{}); - - _m_scrollbar(); - render(API::is_focus_ready(window_)); - return true; - } - return false; - } - bool text_editor::load(const char* fs) { if (!impl_->textbase.load(fs)) @@ -1681,11 +1631,39 @@ namespace nana{ namespace widgets return true; } - const text_editor::attributes& text_editor::attr() const + const text_editor::attributes& text_editor::attr() const noexcept { return attributes_; } + bool text_editor::line_wrapped(bool autl) + { + if (autl != attributes_.line_wrapped) + { + attributes_.line_wrapped = autl; + + delete impl_->capacities.behavior; + if (autl) + { + impl_->capacities.behavior = new behavior_linewrapped(*this); + text_area_.vscroll = text_area_.scroll_pixels; + text_area_.hscroll = 0; + impl_->capacities.behavior->pre_calc_lines(width_pixels()); + } + else + impl_->capacities.behavior = new behavior_normal(*this); + + points_.offset.x = 0; + _m_offset_y(0); + move_caret(upoint{}); + + _m_scrollbar(); + render(API::is_focus_ready(window_)); + return true; + } + return false; + } + bool text_editor::multi_lines(bool ml) { if((ml == false) && attributes_.multi_lines) @@ -2054,7 +2032,7 @@ namespace nana{ namespace widgets void text_editor::reset_caret_pixels() const { - API::open_caret(window_, true)->dimension({ 1, line_height() }); + API::open_caret(window_, true).get()->dimension({ 1, line_height() }); } void text_editor::reset_caret() @@ -2065,7 +2043,7 @@ namespace nana{ namespace widgets void text_editor::show_caret(bool isshow) { if(isshow == false || API::is_focus_ready(window_)) - API::open_caret(window_, true)->visible(isshow); + API::open_caret(window_, true).get()->visible(isshow); } bool text_editor::selected() const @@ -2187,7 +2165,7 @@ namespace nana{ namespace widgets if (attributes_.line_wrapped) exclude_px = text_area_.vscroll; else - exclude_px = API::open_caret(window_, true)->dimension().width; + exclude_px = API::open_caret(window_, true).get()->dimension().width; return (text_area_.area.width > exclude_px ? text_area_.area.width - exclude_px : 0); } diff --git a/source/gui/widgets/textbox.cpp b/source/gui/widgets/textbox.cpp index 195ea935..5d671595 100644 --- a/source/gui/widgets/textbox.cpp +++ b/source/gui/widgets/textbox.cpp @@ -392,7 +392,7 @@ namespace drawerbase { bool textbox::line_wrapped() const { internal_scope_guard lock; - return get_drawer_trigger().editor()->line_wrapped(); + return get_drawer_trigger().editor()->attr().line_wrapped; } textbox& textbox::line_wrapped(bool autl)