From 7125ab8f48e661e61a4fd6ab4f33e872da2bfae5 Mon Sep 17 00:00:00 2001 From: qPCR4vir Date: Fri, 4 Mar 2016 23:54:42 +0100 Subject: [PATCH] exit_all --- include/nana/gui/programming_interface.hpp | 12 +++++-- include/nana/gui/wvl.hpp | 1 + source/gui/programming_interface.cpp | 38 +++++++++++++++++++++- source/gui/wvl.cpp | 30 +++++++++++------ 4 files changed, 68 insertions(+), 13 deletions(-) diff --git a/include/nana/gui/programming_interface.hpp b/include/nana/gui/programming_interface.hpp index 8adfd2eb..db8ffc1c 100644 --- a/include/nana/gui/programming_interface.hpp +++ b/include/nana/gui/programming_interface.hpp @@ -143,9 +143,17 @@ namespace API }; }//end namespace detail - void exit(); + void exit(); ///< close all windows in current thread + void exit_all(); ///< close all windows - std::string transform_shortkey_text(std::string text, wchar_t &shortkey, std::string::size_type *skpos); + /// @brief Searchs whether the text contains a '&' and removes the character for transforming. + /// If the text contains more than one '&' charachers, the others are ignored. e.g + /// text = "&&a&bcd&ef", the result should be "&abcdef", shortkey = 'b', and pos = 2. + std::string transform_shortkey_text + ( std::string text, ///< the text is transformed + wchar_t &shortkey, ///< the character which indicates a short key. + std::string::size_type *skpos ///< retrives the shortkey position if it is not a null_ptr; + ); bool register_shortkey(window, unsigned long); void unregister_shortkey(window); diff --git a/include/nana/gui/wvl.hpp b/include/nana/gui/wvl.hpp index 5d6d756c..176af43d 100644 --- a/include/nana/gui/wvl.hpp +++ b/include/nana/gui/wvl.hpp @@ -23,6 +23,7 @@ #include "msgbox.hpp" #include "place.hpp" + namespace nana { namespace detail diff --git a/source/gui/programming_interface.cpp b/source/gui/programming_interface.cpp index a5f96e98..12670941 100644 --- a/source/gui/programming_interface.cpp +++ b/source/gui/programming_interface.cpp @@ -326,7 +326,7 @@ namespace API return nullptr; } - //exit + //close all windows in current thread void exit() { @@ -363,6 +363,42 @@ namespace API interface_type::close_window(i); } } + //close all windows + void exit_all() + { + std::vector v; + + internal_scope_guard lock; + restrict::wd_manager().all_handles(v); + if (v.size()) + { + std::vector roots; + native_window_type root = nullptr; + //unsigned tid = nana::system::this_thread_id(); + for (auto wd : v) + { + if (/*(wd->thread_id == tid) &&*/ (wd->root != root)) + { + root = wd->root; + bool exists = false; + for (auto i = roots.cbegin(); i != roots.cend(); ++i) + { + if (*i == root) + { + exists = true; + break; + } + } + + if (!exists) + roots.push_back(root); + } + } + + for (auto i : roots) + interface_type::close_window(i); + } + } //transform_shortkey_text //@brief: This function searchs whether the text contains a '&' and removes the character for transforming. diff --git a/source/gui/wvl.cpp b/source/gui/wvl.cpp index 732a1c69..24e58ee0 100644 --- a/source/gui/wvl.cpp +++ b/source/gui/wvl.cpp @@ -29,6 +29,7 @@ namespace nana void click(widget& w) { + std::cout << "Automatically clicking widget "<close(); - API::exit(); // why not works? + std::cout << "Done... Now closing the main form...\n"; + /*if (main_form) + main_form->close();*/ + std::cout << "Closed... Now API::exit ...\n"; + API::exit_all(); // why not works? + std::cout << "Done... Upps - this had not to appear !! \n"; } }); pump();