This commit is contained in:
qPCR4vir 2016-03-04 23:54:42 +01:00
parent dae3b4e815
commit 7125ab8f48
4 changed files with 68 additions and 13 deletions

View File

@ -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);

View File

@ -23,6 +23,7 @@
#include "msgbox.hpp"
#include "place.hpp"
namespace nana
{
namespace detail

View File

@ -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<basic_window*> v;
internal_scope_guard lock;
restrict::wd_manager().all_handles(v);
if (v.size())
{
std::vector<native_window_type> 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.

View File

@ -29,6 +29,7 @@ namespace nana
void click(widget& w)
{
std::cout << "Automatically clicking widget "<<w.caption()<<":\n";
arg_click arg;
arg.window_handle = w.handle();
w.events().click.emit(arg);
@ -37,8 +38,9 @@ namespace nana
/// in seconds
void Wait(unsigned wait)
{
if (wait)
std::this_thread::sleep_for(std::chrono::seconds{ wait });
if (!wait) return;
std::cout << "waiting " << wait << " sec...\n";
std::this_thread::sleep_for(std::chrono::seconds{ wait });
}
void pump()
@ -57,23 +59,31 @@ namespace nana
//if (!wait)
// wait = 1;
//if (!main_form && !f)
// f = []() {API::exit(); };
// f = []() {API::exit_all(); };
std::cout << "Will wait " << wait << " sec...\n";
std::thread t([wait, &f, wait_end, main_form]()
{ if (wait)
{
std::cout << "Waiting " << wait << " sec...\n";
Wait( wait );
std::cout << "running... \n" ;
if (f) f();
if (f)
{
f();
std::cout << "\nCongratulations, this was not trivial !" << std::endl;
}else
{
std::cout << "\nJust a trivial test." << std::endl;
}
std::cout << "Done... \n";
std::cout << "Now waiting anothers " << wait_end << " sec...\n";
std::cout << "Now again ";
Wait(wait_end);
std::cout << "Done... \n";
if (main_form)
main_form->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();