From 34cca3477337511f6b5d9833da49c4cdc9be2eaa Mon Sep 17 00:00:00 2001 From: Jinhao Date: Tue, 26 Jul 2016 07:32:50 +0800 Subject: [PATCH 1/4] fix the behaviour of clicking menu disabled item --- include/nana/paint/graphics.hpp | 10 ++++ source/gui/widgets/menu.cpp | 86 +++++++++++++++------------------ source/paint/graphics.cpp | 35 ++++++++++++++ 3 files changed, 84 insertions(+), 47 deletions(-) diff --git a/include/nana/paint/graphics.hpp b/include/nana/paint/graphics.hpp index 7102c500..8e667ef2 100644 --- a/include/nana/paint/graphics.hpp +++ b/include/nana/paint/graphics.hpp @@ -179,6 +179,16 @@ namespace nana pixel_buffer pxbuf_; bool changed_; }; + + class draw + { + public: + draw(graphics& graph); + + void corner(const rectangle& r, unsigned pixels); + private: + graphics& graph_; + }; }//end namespace paint } //end namespace nana #endif diff --git a/source/gui/widgets/menu.cpp b/source/gui/widgets/menu.cpp index 2ba13a4d..dd90fdca 100644 --- a/source/gui/widgets/menu.cpp +++ b/source/gui/widgets/menu.cpp @@ -113,19 +113,15 @@ namespace nana void item(graph_reference graph, const nana::rectangle& r, const attr& at) { + if (!at.enabled) + return; + if(at.item_state == state::active) { graph.rectangle(r, false, static_cast(0xa8d8eb)); - nana::point points[4] = { - nana::point(r.x, r.y), - nana::point(r.x + r.width - 1, r.y), - nana::point(r.x, r.y + r.height - 1), - nana::point(r.x + r.width - 1, r.y + r.height - 1) - }; graph.palette(false, static_cast(0xc0ddfc)); - for(int i = 0; i < 4; ++i) - graph.set_pixel(points[i].x, points[i].y); + paint::draw(graph).corner(r, 1); if(at.enabled) graph.gradual_rectangle(nana::rectangle(r).pare_off(1), static_cast(0xE8F0F4), static_cast(0xDBECF4), true); @@ -785,9 +781,8 @@ namespace nana { if (event_code::mouse_down == arg.evt_code) _m_open_sub(0); //Try to open submenu immediately - else if (event_code::mouse_up == arg.evt_code) - if (arg.button == ::nana::mouse::left_button) - pick(); + else if ((event_code::mouse_up == arg.evt_code) && (mouse::left_button == arg.button)) + pick(); }; events.mouse_down.connect_unignorable(fn); @@ -885,48 +880,45 @@ namespace nana return; menu_item_type & item = menu->items.at(active); - if (item.flags.splitter == false && item.sub_menu == nullptr) + + if ((!item.flags.enabled) || item.flags.splitter || item.sub_menu) + return; + + if (checks::highlight == item.style) { - //There is a situation that menu will not call functor if the item style is check_option - //and it is checked before clicking. - bool call_functor = true; - - if (checks::highlight == item.style) + item.flags.checked = !item.flags.checked; + } + else if (checks::option == item.style) + { + //Forward Looks for a splitter + auto pos = active; + while (pos) { - item.flags.checked = !item.flags.checked; - } - else if (checks::option == item.style) - { - //Forward Looks for a splitter - auto pos = active; - while (pos) - { - if (menu->items.at(--pos).flags.splitter) - break; - } - - for (; pos < menu->items.size(); ++pos) - { - menu_item_type & im = menu->items.at(pos); - if (im.flags.splitter) break; - - if ((checks::option == im.style) && im.flags.checked) - im.flags.checked = false; - } - - item.flags.checked = true; + if (menu->items.at(--pos).flags.splitter) + break; } - this->_m_close_all(); //means deleting this; - //The deleting operation has moved here, because item.functor.operator()(ip) - //may create a window, which make a killing focus for menu window, if so the close_all - //operation preformences after item.functor.operator()(ip), that would be deleting this object twice! - - if (call_functor && item.flags.enabled && item.functor) + for (; pos < menu->items.size(); ++pos) { - item_type::item_proxy ip(active, item); - item.functor.operator()(ip); + menu_item_type & im = menu->items.at(pos); + if (im.flags.splitter) break; + + if ((checks::option == im.style) && im.flags.checked) + im.flags.checked = false; } + + item.flags.checked = true; + } + + this->_m_close_all(); //means deleting this; + //The deleting operation has moved here, because item.functor.operator()(ip) + //may create a window, which make a killing focus for menu window, if so the close_all + //operation preformences after item.functor.operator()(ip), that would be deleting this object twice! + + if (item.functor) + { + item_type::item_proxy ip(active, item); + item.functor.operator()(ip); } } private: diff --git a/source/paint/graphics.cpp b/source/paint/graphics.cpp index 15a29c52..40530a18 100644 --- a/source/paint/graphics.cpp +++ b/source/paint/graphics.cpp @@ -1233,5 +1233,40 @@ namespace paint } //end class graphics + //class draw + draw::draw(graphics& graph) + : graph_(graph) + {} + + void draw::corner(const rectangle& r, unsigned pixels) + { + if (1 == pixels) + { + graph_.set_pixel(r.x, r.y); + graph_.set_pixel(r.right() - 1, r.y); + + graph_.set_pixel(r.x, r.bottom() - 1); + graph_.set_pixel(r.right() - 1, r.bottom() - 1); + return; + } + else if (1 < pixels) + { + graph_.line(r.position(), point(r.x + pixels, r.y)); + graph_.line(r.position(), point(r.x, r.y + pixels)); + + int right = r.right() - 1; + graph_.line(point(right, r.y), point(right - pixels, r.y)); + graph_.line(point(right, r.y), point(right, r.y - pixels)); + + int bottom = r.bottom() - 1; + graph_.line(point(r.x, bottom), point(r.x + pixels, bottom)); + graph_.line(point(r.x, bottom), point(r.x, bottom - pixels)); + + graph_.line(point(right, bottom), point(right - pixels, bottom)); + graph_.line(point(right, bottom), point(right, bottom - pixels)); + } + } + //end class draw + }//end namespace paint }//end namespace nana From df5a786965b5828d16ed344298a97b9da79a0211 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sun, 31 Jul 2016 04:11:39 +0800 Subject: [PATCH 2/4] fix a bug that listbox::cat_proxy::append throws if model enabled --- source/gui/widgets/listbox.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index 5da2dc15..91cf6d4e 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -972,6 +972,7 @@ namespace nana if (catobj.model_ptr) { + throw_if_immutable_model(catobj.model_ptr.get()); auto container = catobj.model_ptr->container(); std::size_t item_index; // @@ -5027,9 +5028,24 @@ namespace nana internal_scope_guard lock; - cat_->sorted.push_back(cat_->items.size()); - cells.resize(columns()); - cat_->items.emplace_back(std::move(cells)); + if (cat_->model_ptr) + { + es_lister::throw_if_immutable_model(cat_->model_ptr.get()); + + auto container = cat_->model_ptr->container(); + + auto item_index = container->size(); + cat_->items.emplace_back(); + container->emplace_back(); + + container->assign(item_index, cells); + } + else + { + cat_->sorted.push_back(cat_->items.size()); + cells.resize(columns()); + cat_->items.emplace_back(std::move(cells)); + } assign_colors_for_last(ess_, cat_); } From 6fbc4a7988b3fea45b3023effa7a8d1003acf1d1 Mon Sep 17 00:00:00 2001 From: dankan1890 Date: Mon, 1 Aug 2016 03:20:07 +0200 Subject: [PATCH 3/4] Fixed the behavior of disabled items in the menus when scrolling with the arrows keys. --- source/gui/widgets/menu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/gui/widgets/menu.cpp b/source/gui/widgets/menu.cpp index dd90fdca..9b80249f 100644 --- a/source/gui/widgets/menu.cpp +++ b/source/gui/widgets/menu.cpp @@ -475,7 +475,7 @@ namespace nana --pos; } - if(! menu_->items.at(pos).flags.splitter) + if(! menu_->items.at(pos).flags.splitter && menu_->items.at(pos).flags.enabled) break; } From ebfa079f3fd22b82a077a2cc43b4b131464e112b Mon Sep 17 00:00:00 2001 From: Jinhao Date: Thu, 11 Aug 2016 02:15:19 +0800 Subject: [PATCH 4/4] fix bug that text_editor throws an exception when undo a backspace --- source/gui/widgets/skeletons/text_editor.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index 03168ce1..e30248a8 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -2300,6 +2300,8 @@ namespace nana{ namespace widgets } else { + undo_ptr->set_removed(this->_m_make_select_string()); + undo_ptr->set_selected_text(); points_.caret = _m_erase_select(); undo_ptr->set_caret_pos();