From 5653bd2416bae7fe009c76de05859abdd4bed37a Mon Sep 17 00:00:00 2001 From: Jinhao Date: Wed, 13 Dec 2017 06:28:12 +0800 Subject: [PATCH 01/12] fix crash where listbox::item_proxy==str --- source/gui/widgets/listbox.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index e473a080..54611aa1 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -4662,12 +4662,12 @@ namespace nana bool item_proxy::operator==(const std::string& s) const { - return (text(pos_.item) == s); + return (text(0) == s); } bool item_proxy::operator==(const std::wstring& s) const { - return (text(pos_.item) == to_utf8(s)); + return (text(0) == to_utf8(s)); } item_proxy & item_proxy::operator=(const item_proxy& rhs) From 58b7bdf2f7a3654062a07eaa69085cdab385785a Mon Sep 17 00:00:00 2001 From: Jinhao Date: Wed, 3 Jan 2018 07:32:21 +0800 Subject: [PATCH 02/12] fix a stackoverflow error --- source/gui/detail/window_layout.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/gui/detail/window_layout.cpp b/source/gui/detail/window_layout.cpp index 27357217..4add7b03 100644 --- a/source/gui/detail/window_layout.cpp +++ b/source/gui/detail/window_layout.cpp @@ -1,7 +1,7 @@ /* * Window Layout Implementation * Nana C++ Library(http://www.nanapro.org) -* Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com) +* Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -386,6 +386,13 @@ namespace nana nana::rectangle r_of_sigwd(sigwd->pos_root, sigwd->dimension); for (auto wd : data_sect.effects_bground_windows) { + //Don't notify the window if both native root windows are not same(e.g. wd and sigwd have + //a some parent). Otherwise, _m_paint_glass_window() recursively paints sigwd to make stack overflow. + //On the other hand, a nested root window is always floating on its parent's child widgets, it's unnecessary to + //notify the wd if they haven't a same native root window. + if (sigwd->root != wd->root) + continue; + if (wd == sigwd || !wd->displayed() || (false == overlapped(nana::rectangle{ wd->pos_root, wd->dimension }, r_of_sigwd))) continue; From 970872c96f92e0891625ff9463bd5ef40c7a7e3a Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sun, 7 Jan 2018 04:18:23 +0800 Subject: [PATCH 03/12] fix bug that integer overflow in progress widget --- source/gui/widgets/progress.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/gui/widgets/progress.cpp b/source/gui/widgets/progress.cpp index 2c498f7c..8a679c4c 100644 --- a/source/gui/widgets/progress.cpp +++ b/source/gui/widgets/progress.cpp @@ -1,6 +1,6 @@ /* * A Progress Indicator Implementation - * Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -96,7 +96,11 @@ namespace nana { if (widget_) { - auto value_px = (widget_->size().width - border_px * 2) * value_ / max_; + auto value_px = (widget_->size().width - border_px * 2); + + //avoid overflow + if (value_ < max_) + value_px = static_cast(value_px * (double(value_) / double(max_))); if (value_px != value_px_) { From 48be0b4b07fbdeb9a6b43c8bdf0066e8fdf3db55 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sat, 13 Jan 2018 10:49:37 +0800 Subject: [PATCH 04/12] improve visualization of group caption --- include/nana/gui/programming_interface.hpp | 2 ++ source/gui/programming_interface.cpp | 9 +++++++++ source/gui/widgets/group.cpp | 23 +++++++++++++++++++--- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/include/nana/gui/programming_interface.hpp b/include/nana/gui/programming_interface.hpp index 8c0d85fe..814a98b7 100644 --- a/include/nana/gui/programming_interface.hpp +++ b/include/nana/gui/programming_interface.hpp @@ -301,6 +301,8 @@ namespace API void window_size(window, const size&); size window_outline_size(window); void window_outline_size(window, const size&); + + nana::optional window_rectangle(window); bool get_window_rectangle(window, rectangle&); bool track_window_size(window, const size&, bool true_for_max); ///< Sets the minimum or maximum tracking size of a window. void window_enabled(window, bool); diff --git a/source/gui/programming_interface.cpp b/source/gui/programming_interface.cpp index 22e22cac..626803d3 100644 --- a/source/gui/programming_interface.cpp +++ b/source/gui/programming_interface.cpp @@ -821,6 +821,15 @@ namespace API } } + nana::optional window_rectangle(window wd) + { + auto iwd = reinterpret_cast(wd); + internal_scope_guard lock; + if (restrict::wd_manager().available(iwd)) + return rectangle(iwd->pos_owner, iwd->dimension); + return{}; + } + bool get_window_rectangle(window wd, rectangle& r) { auto iwd = reinterpret_cast(wd); diff --git a/source/gui/widgets/group.cpp b/source/gui/widgets/group.cpp index ab8e9e73..74d76575 100644 --- a/source/gui/widgets/group.cpp +++ b/source/gui/widgets/group.cpp @@ -208,8 +208,8 @@ namespace nana{ outter[field_title] << impl_->caption; outter.collocate(); + impl_->caption.transparent(true); color pbg = API::bgcolor(this->parent()); - impl_->caption.bgcolor(pbg.blend(colors::black, 0.025)); this->bgcolor(pbg.blend(colors::black, 0.05)); @@ -222,10 +222,27 @@ namespace nana{ auto gap_px = impl_->gap - 1; graph.rectangle(true, API::bgcolor(this->parent())); - graph.round_rectangle(rectangle(point(gap_px, impl_->caption_dimension.height / 2), - nana::size(graph.width() - 2 * gap_px, graph.height() - impl_->caption_dimension.height / 2 - gap_px) + + auto const top_round_line = static_cast(impl_->caption_dimension.height) / 2; + + graph.round_rectangle(rectangle(point(gap_px, top_round_line), + nana::size(graph.width() - 2 * gap_px, graph.height() - top_round_line - gap_px) ), 3, 3, colors::gray_border, true, this->bgcolor()); + + auto opt_r = API::window_rectangle(impl_->caption); + if (opt_r) + { + rectangle grad_r{ opt_r->position(), nana::size{ opt_r->width, static_cast(top_round_line - opt_r->y) } }; + + grad_r.y += top_round_line / 2; + grad_r.x -= 2; + grad_r.width += 4; + + graph.gradual_rectangle(grad_r, + API::bgcolor(this->parent()), this->bgcolor(), true + ); + } }); } From c80b4ce484006db44d5b176e931b9e5c5d73ba26 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sat, 13 Jan 2018 13:07:40 +0800 Subject: [PATCH 05/12] improve visualization of group caption --- source/gui/widgets/group.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/gui/widgets/group.cpp b/source/gui/widgets/group.cpp index 74d76575..87d2ebc6 100644 --- a/source/gui/widgets/group.cpp +++ b/source/gui/widgets/group.cpp @@ -235,7 +235,7 @@ namespace nana{ { rectangle grad_r{ opt_r->position(), nana::size{ opt_r->width, static_cast(top_round_line - opt_r->y) } }; - grad_r.y += top_round_line / 2; + grad_r.y += top_round_line*2 / 3; grad_r.x -= 2; grad_r.width += 4; From 08077a98454367a72378557007eecd18ef94e5db Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sat, 13 Jan 2018 13:08:43 +0800 Subject: [PATCH 06/12] fix bug that wrong listbox selection after sorting --- include/nana/gui/widgets/listbox.hpp | 2 +- source/gui/widgets/listbox.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/nana/gui/widgets/listbox.hpp b/include/nana/gui/widgets/listbox.hpp index 71280b7e..d57ee4c6 100644 --- a/include/nana/gui/widgets/listbox.hpp +++ b/include/nana/gui/widgets/listbox.hpp @@ -1,7 +1,7 @@ /** * A List Box Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index 54611aa1..b21cf392 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -1,7 +1,7 @@ /* * A List Box Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -1586,7 +1586,7 @@ namespace nana return pairs; } - bool select_for_all(bool sel, const index_pair& except = index_pair{npos, npos}) + bool select_for_all(bool sel, const index_pair& except_abs = index_pair{npos, npos}) { bool changed = false; index_pair pos; @@ -1595,7 +1595,7 @@ namespace nana pos.item = 0; for(auto & m : cat.items) { - if (except != pos) + if (except_abs != pos) { if (m.flags.selected != sel) { @@ -4150,12 +4150,12 @@ namespace nana //Unselects all selected items if the current item is not selected before selecting. auto selected = lister.pick_items(true); if (selected.cend() == std::find(selected.cbegin(), selected.cend(), item_pos)) - lister.select_for_all(false, item_pos); + lister.select_for_all(false, abs_item_pos); } else { //Unselects all selected items except current item if right button clicked. - lister.select_for_all(false, item_pos); //cancel all selections + lister.select_for_all(false, abs_item_pos); //cancel all selections } } } From 710880372bc4d1e139572f5d923581c2c9340a60 Mon Sep 17 00:00:00 2001 From: 5cript Date: Sun, 14 Jan 2018 07:52:56 +0100 Subject: [PATCH 07/12] Added missing std::move, withing tabbar insert overload for std::string. --- include/nana/gui/widgets/tabbar.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/nana/gui/widgets/tabbar.hpp b/include/nana/gui/widgets/tabbar.hpp index 0e2e2e9c..56fc213d 100644 --- a/include/nana/gui/widgets/tabbar.hpp +++ b/include/nana/gui/widgets/tabbar.hpp @@ -277,7 +277,7 @@ namespace nana this->get_drawer_trigger().insert(::nana::npos, to_nstring(std::move(text)), std::move(value)); if (attach_wd) this->attach(this->get_drawer_trigger().length() - 1, attach_wd); - + API::update_window(*this); return *this; } @@ -293,7 +293,7 @@ namespace nana if (pos > length()) throw std::out_of_range("tabbar::insert invalid position"); - this->get_drawer_trigger().insert(pos, to_nstring(text), std::move(value)); + this->get_drawer_trigger().insert(pos, to_nstring(std::move(text)), std::move(value)); API::update_window(*this); } @@ -306,7 +306,7 @@ namespace nana API::update_window(*this); } - /// Attach a window to a specified tab. When the tab is activated, tabbar shows the attached window. + /// Attach a window to a specified tab. When the tab is activated, tabbar shows the attached window. /** * @param pos The position of tab to set the attached window. * @param attach_wd A handle to the window to be set. @@ -364,7 +364,7 @@ namespace nana namespace nana -{ +{ namespace drawerbase { namespace tabbar_lite From 0196d2583a3e49c61c968708a9529f98f52e458e Mon Sep 17 00:00:00 2001 From: Jinhao Date: Thu, 18 Jan 2018 00:18:01 +0800 Subject: [PATCH 08/12] mutable variable members of arg_tabbar_removed --- include/nana/gui/widgets/tabbar.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/nana/gui/widgets/tabbar.hpp b/include/nana/gui/widgets/tabbar.hpp index 0e2e2e9c..a9cc70cb 100644 --- a/include/nana/gui/widgets/tabbar.hpp +++ b/include/nana/gui/widgets/tabbar.hpp @@ -1,7 +1,7 @@ /** * A Tabbar implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -42,9 +42,8 @@ namespace nana : arg_tabbar({wdg, v}) {} - bool remove = true; ///< determines whether to remove the item - bool close_attach_window = true; ///< determines whether to close the attached window. It is ignored if remove is false - + mutable bool remove = true; ///< determines whether to remove the item + mutable bool close_attach_window = true; ///< determines whether to close the attached window. It is ignored if remove is false }; namespace drawerbase From 2a262236288c15410382744122bac2e179970f6d Mon Sep 17 00:00:00 2001 From: Jinhao Date: Mon, 22 Jan 2018 06:29:40 +0800 Subject: [PATCH 09/12] small fix for constructor of scroll --- include/nana/gui/widgets/scroll.hpp | 2 +- include/nana/gui/widgets/tabbar.hpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/nana/gui/widgets/scroll.hpp b/include/nana/gui/widgets/scroll.hpp index c4e39981..0603c308 100644 --- a/include/nana/gui/widgets/scroll.hpp +++ b/include/nana/gui/widgets/scroll.hpp @@ -398,7 +398,7 @@ namespace nana /// \brief The construct that creates a widget. /// @param wd A handle to the parent window of the widget being created. /// @param visible specify the visibility after creation. - scroll(window wd, bool visible) + scroll(window wd, bool visible = true) { this->create(wd, rectangle(), visible); // add a widget scheme? and take some colors from these wd? } diff --git a/include/nana/gui/widgets/tabbar.hpp b/include/nana/gui/widgets/tabbar.hpp index e0d56f1a..a24cce4a 100644 --- a/include/nana/gui/widgets/tabbar.hpp +++ b/include/nana/gui/widgets/tabbar.hpp @@ -276,7 +276,7 @@ namespace nana this->get_drawer_trigger().insert(::nana::npos, to_nstring(std::move(text)), std::move(value)); if (attach_wd) this->attach(this->get_drawer_trigger().length() - 1, attach_wd); - + API::update_window(*this); return *this; } @@ -305,7 +305,7 @@ namespace nana API::update_window(*this); } - /// Attach a window to a specified tab. When the tab is activated, tabbar shows the attached window. + /// Attach a window to a specified tab. When the tab is activated, tabbar shows the attached window. /** * @param pos The position of tab to set the attached window. * @param attach_wd A handle to the window to be set. @@ -363,7 +363,7 @@ namespace nana namespace nana -{ +{ namespace drawerbase { namespace tabbar_lite From e1c5fcdb0ab8ff6dcc80bc5d63e5e9b74a3391fa Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sun, 28 Jan 2018 11:21:45 +0800 Subject: [PATCH 10/12] enhance performance of setting model for a listbox --- source/gui/widgets/listbox.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index b21cf392..a0c2db52 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -5158,7 +5158,8 @@ namespace nana cat_->make_sort_order(); ess_->lister.sort(); - ess_->update(true); + //Don't ignore the auto-draw flag for performance enhancement. + ess_->update(); } } //end class cat_proxy From 2574f4fffa5d3e097f303816e641089633cdfbfb Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sun, 28 Jan 2018 11:23:05 +0800 Subject: [PATCH 11/12] remove a compiler warning --- source/paint/detail/image_jpeg.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/paint/detail/image_jpeg.hpp b/source/paint/detail/image_jpeg.hpp index 1f19373b..d63a2c1d 100644 --- a/source/paint/detail/image_jpeg.hpp +++ b/source/paint/detail/image_jpeg.hpp @@ -91,7 +91,7 @@ namespace nana { ::jpeg_create_decompress(&jdstru); - ::jpeg_mem_src(&jdstru, const_cast(reinterpret_cast(data)), bytes); + ::jpeg_mem_src(&jdstru, const_cast(reinterpret_cast(data)), static_cast(bytes)); _m_read_jpg(jdstru); jpeg_finish_decompress(&jdstru); From 9bd3dc7e582f260283da42fb68b988f33e229995 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sun, 28 Jan 2018 13:57:07 +0800 Subject: [PATCH 12/12] fix bug that nested_form draws incompletely --- source/gui/detail/window_layout.cpp | 49 +++++++++++++++-------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/source/gui/detail/window_layout.cpp b/source/gui/detail/window_layout.cpp index 4add7b03..45764b81 100644 --- a/source/gui/detail/window_layout.cpp +++ b/source/gui/detail/window_layout.cpp @@ -106,43 +106,46 @@ namespace nana visual = rectangle{ wd->pos_root, wd->dimension }; - if (wd->root_widget != wd) + if (category::flags::root != wd->other.category) { //Test if the root widget is overlapped the specified widget //the pos of root widget is (0, 0) if (overlapped(visual, rectangle{ wd->root_widget->pos_owner, wd->root_widget->dimension }) == false) return false; - } - for (auto parent = wd->parent; parent; parent = parent->parent) - { - if (category::flags::root == parent->other.category) + for (auto parent = wd->parent; parent; parent = parent->parent) { - //visual rectangle of wd's parent - rectangle vrt_parent{parent->pos_root, parent->dimension}; - - point pos_root; - while (parent->parent) + if (category::flags::root == parent->other.category) { - 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; + wd = parent; + break; } - if (!overlap(vrt_parent, visual, visual)) + if (!overlap(rectangle{ parent->pos_root, parent->dimension }, visual, visual)) return false; - - return true; } - - if (!overlap(rectangle{ parent->pos_root, parent->dimension }, visual, visual)) - return false; } - return true; + //Now, wd actually is the root widget of original parameter wd + if (nullptr == wd->parent) + return true; + + auto parent_rw = wd->parent->root_widget; + //visual rectangle of wd's parent + rectangle vrt_parent{ parent_rw->pos_root, parent_rw->dimension }; + + point pos_root; + while (parent_rw->parent) + { + pos_root -= native_interface::window_position(parent_rw->root); + + if (!overlap(rectangle{ pos_root, parent_rw->parent->root_widget->dimension }, vrt_parent, vrt_parent)) + return false; + + parent_rw = parent_rw->parent->root_widget; + } + + return overlap(vrt_parent, visual, visual); } //read_overlaps