diff --git a/include/nana/gui/widgets/listbox.hpp b/include/nana/gui/widgets/listbox.hpp index 212be2f7..844f8229 100644 --- a/include/nana/gui/widgets/listbox.hpp +++ b/include/nana/gui/widgets/listbox.hpp @@ -535,7 +535,7 @@ namespace nana throw std::invalid_argument("invalid listbox model container type"); if (nullptr == p->pointer()) - throw std::runtime_error("the modal is immutable"); + throw std::runtime_error("the modal is immutable, please declare model_guard with const"); return *static_cast(p->pointer()); } @@ -1250,8 +1250,9 @@ By \a clicking on one header the list get \a reordered, first up, and then down } return false; } - listbox.anyobj(0, 0, 10); //the type of customer's object is int. - listbox.anyobj(0, 0, 20); + auto cat = listbox.at(0); + cat.at(0).value(10); //10 is custom data. + cat.at(1).value(20); //20 is custom data. 5. listbox is a widget_object, with template parameters drawerbase::listbox::trigger and drawerbase::listbox::scheme amon others. That means that listbox have a member trigger_ constructed first and accecible with get_drawer_trigger() and diff --git a/source/gui/detail/window_layout.cpp b/source/gui/detail/window_layout.cpp index 72195e66..6c3b7578 100644 --- a/source/gui/detail/window_layout.cpp +++ b/source/gui/detail/window_layout.cpp @@ -114,8 +114,30 @@ namespace nana return false; } - for (auto* parent = wd->parent; parent; parent = parent->parent) + for (auto parent = wd->parent; parent; parent = parent->parent) { + if (category::flags::root == parent->other.category) + { + //visual rectangle of wd's parent + rectangle vrt_parent{parent->pos_root, parent->dimension}; + + point pos_root; + while (parent->parent) + { + pos_root -= native_interface::window_position(parent->root); + + if (!overlap(rectangle{ pos_root, parent->parent->root_widget->dimension }, vrt_parent, vrt_parent)) + return false; + + parent = parent->parent->root_widget; + } + + if (!overlap(vrt_parent, visual, visual)) + return false; + + return true; + } + if (!overlap(rectangle{ parent->pos_root, parent->dimension }, visual, visual)) return false; } diff --git a/source/gui/detail/window_manager.cpp b/source/gui/detail/window_manager.cpp index 6d1ce3ca..159cfdc6 100644 --- a/source/gui/detail/window_manager.cpp +++ b/source/gui/detail/window_manager.cpp @@ -733,30 +733,6 @@ namespace detail } } - void sync_child_root_display(window_manager::core_window_t* wd) - { - for (auto & child : wd->children) - { - if (category::flags::root != child->other.category) - { - sync_child_root_display(child); - continue; - } - - auto const vs_parents = child->visible_parents(); - - if (vs_parents != child->visible) - { - native_interface::show_window(child->root, vs_parents, false); - } - else - { - if (child->visible != native_interface::is_window_visible(child->root)) - native_interface::show_window(child->root, child->visible, false); - } - } - } - //show //@brief: show or hide a window bool window_manager::show(core_window_t* wd, bool visible) @@ -792,14 +768,7 @@ namespace detail bedrock::instance().event_expose(wd, visible); if (nv) - { - if (visible && !wd->visible_parents()) - return true; - native_interface::show_window(nv, visible, wd->flags.take_active); - } - - sync_child_root_display(wd); } return true; } diff --git a/source/gui/widgets/combox.cpp b/source/gui/widgets/combox.cpp index 4204dbe8..c9b6311d 100644 --- a/source/gui/widgets/combox.cpp +++ b/source/gui/widgets/combox.cpp @@ -143,6 +143,7 @@ namespace nana auto scheme = dynamic_cast< ::nana::widgets::skeletons::text_editor_scheme*>(API::dev::get_scheme(wd)); editor_ = new widgets::skeletons::text_editor(widget_->handle(), graph, scheme); + _m_text_area(graph.size()); editor_->multi_lines(false); editable(false); graph_ = &graph; @@ -177,21 +178,6 @@ namespace nana return any_ptr.get(); } - void text_area(const nana::size& s) - { - auto extension = measurer_->extension(); - - nana::rectangle r(2, 2, s.width > extension.width ? s.width - extension.width : 0, s.height > extension.height ? s.height - extension.height : 0); - if(image_enabled_) - { - unsigned place = image_pixels_ + 2; - r.x += place; - if(r.width > place) r.width -= place; - } - editor_->text_area(r); - editor_->render(state_.focused); - } - widgets::skeletons::text_editor * editor() const { return editor_; @@ -364,12 +350,13 @@ namespace nana void draw() { bool enb = widget_->enabled(); - if(editor_) - { - text_area(widget_->size()); - } + + _m_text_area(widget_->size()); + editor_->render(state_.focused); + _m_draw_push_button(enb); _m_draw_image(); + } std::size_t the_number_of_options() const @@ -496,6 +483,20 @@ namespace nana return true; } private: + void _m_text_area(const nana::size& s) + { + auto extension = measurer_->extension(); + + nana::rectangle r(2, 2, s.width > extension.width ? s.width - extension.width : 0, s.height > extension.height ? s.height - extension.height : 0); + if (image_enabled_) + { + unsigned place = image_pixels_ + 2; + r.x += place; + if (r.width > place) r.width -= place; + } + editor_->text_area(r); + } + void _m_draw_push_button(bool enabled) { ::nana::rectangle r{graph_->size()}; diff --git a/source/gui/widgets/menu.cpp b/source/gui/widgets/menu.cpp index 61e6a610..bdf2cba1 100644 --- a/source/gui/widgets/menu.cpp +++ b/source/gui/widgets/menu.cpp @@ -624,10 +624,14 @@ namespace nana } else if (item_ptr->flags.enabled) { + //A pointer refers to a menu object which owns the menu window. + //After fn_close_tree_(), *this is an invalid object. + auto owner = menu_->owner; + fn_close_tree_(); if (item_ptr->event_handler) { - item_proxy ip{ index, menu_->owner }; + item_proxy ip{ index, owner }; item_ptr->event_handler.operator()(ip); } return 1; @@ -1019,13 +1023,18 @@ namespace nana close(); break; default: - if (2 != send_shortkey(arg.key)) + switch (send_shortkey(arg.key)) { - if (API::empty_window(*this) == false) + case 0: + if (this->empty() == false) close(); - } - else + break; + case 1: //The menu has been closed + break; + case 2: this->submenu(true); + break; + } } } diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index bbfed031..edea68cb 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -887,6 +887,7 @@ namespace nana{ namespace widgets return (pos < linemtr_.size() ? linemtr_[pos].take_lines : 0); } private: + /// Split a text into multiple sections, a section indicates an english word or a CKJ character void _m_text_section(const std::wstring& str, std::vector& tsec) { if (str.empty()) @@ -1025,14 +1026,14 @@ namespace nana{ namespace widgets if (pos) { auto chr = text[pos - 1]; - if ((std::iswalpha(chr) && !std::isspace(chr)) || chr == '_') + if ((std::iswalpha(chr) && !std::iswspace(chr)) || chr == '_') return false; } if (pos + len < text.size()) { auto chr = text[pos + len]; - if ((std::iswalpha(chr) && !std::isspace(chr)) || chr == '_') + if ((std::iswalpha(chr) && !std::iswspace(chr)) || chr == '_') return false; } @@ -1596,18 +1597,6 @@ namespace nana{ namespace widgets if(!attributes_.enable_caret) return false; - auto is_whitespace = [](wchar_t c) { - switch (c) { - case L' ': - case L'\t': - case L'\n': - case L'\r': - return true; - default: - return false; - } - }; - // Set caret pos by screen point and get the caret pos. mouse_caret(arg.pos, true); @@ -1616,11 +1605,11 @@ namespace nana{ namespace widgets const auto& line = impl_->textbase.getline(select_.b.y); // Expand the selection forward to the word's end. - while (select_.b.x < line.size() && !is_whitespace(line[select_.b.x])) + while (select_.b.x < line.size() && !std::iswspace(line[select_.b.x])) ++select_.b.x; // Expand the selection backward to the word's start. - while (select_.a.x > 0 && !is_whitespace(line[select_.a.x - 1])) + while (select_.a.x > 0 && !std::iswspace(line[select_.a.x - 1])) --select_.a.x; select_.mode_selection = selection::mode::method_selected; @@ -2876,7 +2865,6 @@ namespace nana{ namespace widgets return ('0' <= ch && ch <= '9'); } - ::nana::color text_editor::_m_bgcolor() const { return (!API::window_enabled(window_) ? static_cast(0xE0E0E0) : API::bgcolor(window_)); diff --git a/source/gui/widgets/slider.cpp b/source/gui/widgets/slider.cpp index b6fdfc09..20109237 100644 --- a/source/gui/widgets/slider.cpp +++ b/source/gui/widgets/slider.cpp @@ -524,14 +524,16 @@ namespace nana if((::nana::mouse_action::pressed == slider_state_.mouse_state) && (API::capture_window() == this->other_.wd)) return false; + auto state_changed = ((slider_state_.mouse_state != ::nana::mouse_action::normal) + || (attr_.adorn_pos != attr_.slider.pos)); + slider_state_.mouse_state = ::nana::mouse_action::normal; attr_.is_draw_adorn = false; - if(attr_.adorn_pos != attr_.slider.pos) - { - attr_.adorn_pos = attr_.slider.pos; - return true; - } - return false; + + attr_.adorn_pos = attr_.slider.pos; + slider_state_.mouse_state = ::nana::mouse_action::normal; + + return state_changed; } private: