refactoring and fix
fix a potential dead-lock caused by timer
This commit is contained in:
parent
50d2c61b9e
commit
5acbbf548e
@ -1 +1,54 @@
|
|||||||
#include "gui/wvl.hpp"
|
/**
|
||||||
|
* Nana GUI Header
|
||||||
|
* Nana C++ Library(http://www.nanapro.org)
|
||||||
|
* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com)
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0.
|
||||||
|
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* @file nana/gui.hpp
|
||||||
|
* @description
|
||||||
|
* the header file contains the files required for running of Nana.GUI
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NANA_GUI_HPP
|
||||||
|
#define NANA_GUI_HPP
|
||||||
|
|
||||||
|
#include "gui/compact.hpp"
|
||||||
|
#include "gui/screen.hpp"
|
||||||
|
#include "gui/widgets/form.hpp"
|
||||||
|
#include "gui/drawing.hpp"
|
||||||
|
#include "gui/msgbox.hpp"
|
||||||
|
#include "gui/place.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
namespace nana
|
||||||
|
{
|
||||||
|
#ifdef NANA_AUTOMATIC_GUI_TESTING
|
||||||
|
|
||||||
|
/// @brief Take control of the GUI and optionally automatically tests it.
|
||||||
|
///
|
||||||
|
/// @detail It transfers to nana the program flow control, which begin pumping messages
|
||||||
|
/// from the underlying OS, interpreting and sending it with suitable arguments
|
||||||
|
/// to the nana widgets that registered a response in the corresponding event.
|
||||||
|
/// It also accept arguments to be used in case of automatic GUI testing.
|
||||||
|
/// Other Way the arguments are ignored.
|
||||||
|
void exec(
|
||||||
|
unsigned wait = 1, ///< for the GUI to be constructed, in seconds
|
||||||
|
unsigned wait_end = 1, ///< for the GUI to be destructed, in seconds
|
||||||
|
std::function<void()> = {} ///< emit events to mimics user actions and may assert results
|
||||||
|
);
|
||||||
|
|
||||||
|
/// send a click message to this widget - useful in GUI testing
|
||||||
|
void click(widget& w);
|
||||||
|
|
||||||
|
/// in seconds
|
||||||
|
void Wait(unsigned wait = 0);
|
||||||
|
#else
|
||||||
|
void exec();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
}//end namespace nana
|
||||||
|
#endif
|
||||||
|
57
include/nana/gui/compact.hpp
Normal file
57
include/nana/gui/compact.hpp
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/**
|
||||||
|
* Nana GUI Library Definition
|
||||||
|
* Nana C++ Library(http://www.nanapro.org)
|
||||||
|
* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com)
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0.
|
||||||
|
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* @file nana/gui/compact.hpp
|
||||||
|
* @description
|
||||||
|
* the header file contains the files required for running of Nana.GUI
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NANA_GUI_WVL_HPP
|
||||||
|
#define NANA_GUI_WVL_HPP
|
||||||
|
|
||||||
|
#include "programming_interface.hpp"
|
||||||
|
|
||||||
|
namespace nana
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
struct form_loader_private
|
||||||
|
{
|
||||||
|
template<typename, bool> friend class form_loader;
|
||||||
|
private:
|
||||||
|
static void insert_form(::nana::widget*);
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Form, bool IsVisible>
|
||||||
|
class form_loader
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template<typename... Args>
|
||||||
|
Form & operator()(Args &&... args) const
|
||||||
|
{
|
||||||
|
auto p = new Form(std::forward<Args>(args)...);
|
||||||
|
|
||||||
|
if (p->empty())
|
||||||
|
throw std::runtime_error("form_loader failed to create the form");
|
||||||
|
|
||||||
|
|
||||||
|
detail::form_loader_private::insert_form(p);
|
||||||
|
if (IsVisible)
|
||||||
|
p->show();
|
||||||
|
|
||||||
|
return *p;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Form, bool IsVisible = true>
|
||||||
|
using form_loader = detail::form_loader<Form, IsVisible>;
|
||||||
|
}//end namespace nana
|
||||||
|
#endif
|
@ -1,88 +0,0 @@
|
|||||||
/**
|
|
||||||
* Nana GUI Library Definition
|
|
||||||
* Nana C++ Library(http://www.nanapro.org)
|
|
||||||
* Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
|
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License, Version 1.0.
|
|
||||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*
|
|
||||||
* @file nana/gui/wvl.hpp
|
|
||||||
* @description
|
|
||||||
* the header file contains the files required for running of Nana.GUI
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef NANA_GUI_WVL_HPP
|
|
||||||
#define NANA_GUI_WVL_HPP
|
|
||||||
|
|
||||||
#include "programming_interface.hpp"
|
|
||||||
#include "screen.hpp"
|
|
||||||
#include "widgets/form.hpp"
|
|
||||||
#include "drawing.hpp"
|
|
||||||
#include "msgbox.hpp"
|
|
||||||
#include "place.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
namespace nana
|
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
struct form_loader_private
|
|
||||||
{
|
|
||||||
template<typename, bool> friend class form_loader;
|
|
||||||
private:
|
|
||||||
static void insert_form(::nana::widget*);
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Form, bool IsVisible>
|
|
||||||
class form_loader
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
template<typename... Args>
|
|
||||||
Form & operator()(Args &&... args) const
|
|
||||||
{
|
|
||||||
auto p = new Form(std::forward<Args>(args)...);
|
|
||||||
|
|
||||||
if (p->empty())
|
|
||||||
throw std::logic_error("form_loader failed to create the form");
|
|
||||||
|
|
||||||
detail::form_loader_private::insert_form(p);
|
|
||||||
if (IsVisible)
|
|
||||||
p->show();
|
|
||||||
|
|
||||||
return *p;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Form, bool IsVisible = true>
|
|
||||||
using form_loader = detail::form_loader<Form, IsVisible>;
|
|
||||||
|
|
||||||
#ifdef NANA_AUTOMATIC_GUI_TESTING
|
|
||||||
|
|
||||||
/// @brief Take control of the GUI and optionally automatically tests it.
|
|
||||||
///
|
|
||||||
/// @detail It transfers to nana the program flow control, which begin pumping messages
|
|
||||||
/// from the underlying OS, interpreting and sending it with suitable arguments
|
|
||||||
/// to the nana widgets that registered a response in the corresponding event.
|
|
||||||
/// It also accept arguments to be used in case of automatic GUI testing.
|
|
||||||
/// Other Way the arguments are ignored.
|
|
||||||
void exec(
|
|
||||||
unsigned wait = 1, ///< for the GUI to be constructed, in seconds
|
|
||||||
unsigned wait_end = 1, ///< for the GUI to be destructed, in seconds
|
|
||||||
std::function<void()> = {} ///< emit events to mimics user actions and may assert results
|
|
||||||
);
|
|
||||||
|
|
||||||
/// send a click message to this widget - useful in GUI testing
|
|
||||||
void click(widget& w);
|
|
||||||
|
|
||||||
/// in seconds
|
|
||||||
void Wait(unsigned wait = 0);
|
|
||||||
#else
|
|
||||||
void exec();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
}//end namespace nana
|
|
||||||
#endif
|
|
@ -13,10 +13,11 @@
|
|||||||
#include "../../detail/platform_spec_selector.hpp"
|
#include "../../detail/platform_spec_selector.hpp"
|
||||||
#include "basic_window.hpp"
|
#include "basic_window.hpp"
|
||||||
#include "bedrock_types.hpp"
|
#include "bedrock_types.hpp"
|
||||||
|
#include <nana/gui/compact.hpp>
|
||||||
|
#include <nana/gui/widgets/widget.hpp>
|
||||||
#include <nana/gui/detail/event_code.hpp>
|
#include <nana/gui/detail/event_code.hpp>
|
||||||
#include <nana/system/platform.hpp>
|
#include <nana/system/platform.hpp>
|
||||||
#include <nana/system/timepiece.hpp>
|
#include <nana/system/timepiece.hpp>
|
||||||
#include <nana/gui/wvl.hpp>
|
|
||||||
#include <nana/gui/detail/native_window_interface.hpp>
|
#include <nana/gui/detail/native_window_interface.hpp>
|
||||||
#include <nana/gui/layout_utility.hpp>
|
#include <nana/gui/layout_utility.hpp>
|
||||||
#include <nana/gui/detail/element_store.hpp>
|
#include <nana/gui/detail/element_store.hpp>
|
||||||
|
@ -18,7 +18,8 @@
|
|||||||
#include <nana/gui/detail/event_code.hpp>
|
#include <nana/gui/detail/event_code.hpp>
|
||||||
#include <nana/system/platform.hpp>
|
#include <nana/system/platform.hpp>
|
||||||
#include <nana/system/timepiece.hpp>
|
#include <nana/system/timepiece.hpp>
|
||||||
#include <nana/gui.hpp>
|
#include <nana/gui/compact.hpp>
|
||||||
|
#include <nana/gui/msgbox.hpp>
|
||||||
#include <nana/gui/detail/native_window_interface.hpp>
|
#include <nana/gui/detail/native_window_interface.hpp>
|
||||||
#include <nana/gui/layout_utility.hpp>
|
#include <nana/gui/layout_utility.hpp>
|
||||||
#include <nana/gui/detail/window_layout.hpp>
|
#include <nana/gui/detail/window_layout.hpp>
|
||||||
|
@ -12,7 +12,9 @@
|
|||||||
* James Bremner
|
* James Bremner
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <nana/gui.hpp>
|
#include <nana/gui/compact.hpp>
|
||||||
|
#include <nana/gui/msgbox.hpp>
|
||||||
|
#include <nana/gui/widgets/form.hpp>
|
||||||
#include <nana/gui/widgets/label.hpp>
|
#include <nana/gui/widgets/label.hpp>
|
||||||
#include <nana/gui/widgets/button.hpp>
|
#include <nana/gui/widgets/button.hpp>
|
||||||
#include <nana/gui/widgets/spinbox.hpp>
|
#include <nana/gui/widgets/spinbox.hpp>
|
||||||
|
@ -43,8 +43,6 @@ namespace nana
|
|||||||
|
|
||||||
class timer_driver
|
class timer_driver
|
||||||
{
|
{
|
||||||
typedef std::lock_guard<std::recursive_mutex> lock_guard;
|
|
||||||
|
|
||||||
friend class timer_core;
|
friend class timer_core;
|
||||||
|
|
||||||
timer_driver() = default;
|
timer_driver() = default;
|
||||||
@ -70,7 +68,7 @@ namespace nana
|
|||||||
auto tmid = p;
|
auto tmid = p;
|
||||||
::nana::detail::platform_spec::instance().set_timer(reinterpret_cast<std::size_t>(tmid), ms, &timer_driver::_m_timer_proc);
|
::nana::detail::platform_spec::instance().set_timer(reinterpret_cast<std::size_t>(tmid), ms, &timer_driver::_m_timer_proc);
|
||||||
#endif
|
#endif
|
||||||
lock_guard lock(mutex_);
|
::nana::internal_scope_guard lock;
|
||||||
timer_table_[tmid].reset(p);
|
timer_table_[tmid].reset(p);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@ -82,7 +80,8 @@ namespace nana
|
|||||||
|
|
||||||
void destroy(timer_identifier tid)
|
void destroy(timer_identifier tid)
|
||||||
{
|
{
|
||||||
lock_guard lock(mutex_);
|
::nana::internal_scope_guard lock;
|
||||||
|
|
||||||
auto i = timer_table_.find(tid);
|
auto i = timer_table_.find(tid);
|
||||||
if (i != timer_table_.end())
|
if (i != timer_table_.end())
|
||||||
{
|
{
|
||||||
@ -101,7 +100,6 @@ namespace nana
|
|||||||
static void _m_timer_proc(std::size_t id);
|
static void _m_timer_proc(std::size_t id);
|
||||||
#endif
|
#endif
|
||||||
private:
|
private:
|
||||||
std::recursive_mutex mutex_;
|
|
||||||
std::map<timer_identifier, std::unique_ptr<timer_core>> timer_table_;
|
std::map<timer_identifier, std::unique_ptr<timer_core>> timer_table_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -141,21 +139,19 @@ namespace nana
|
|||||||
nana::basic_event<arg_elapse> & evt_elapse_;
|
nana::basic_event<arg_elapse> & evt_elapse_;
|
||||||
}; //end class timer_core
|
}; //end class timer_core
|
||||||
|
|
||||||
|
|
||||||
#if defined(NANA_WINDOWS)
|
#if defined(NANA_WINDOWS)
|
||||||
void __stdcall timer_driver::_m_timer_proc(HWND /*hwnd*/, UINT /*uMsg*/, UINT_PTR id, DWORD /*dwTime*/)
|
void __stdcall timer_driver::_m_timer_proc(HWND /*hwnd*/, UINT /*uMsg*/, UINT_PTR id, DWORD /*dwTime*/)
|
||||||
#else
|
#else
|
||||||
void timer_driver::_m_timer_proc(std::size_t id)
|
void timer_driver::_m_timer_proc(std::size_t id)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
auto & driver = instance();
|
auto & time_tbl = instance().timer_table_;
|
||||||
|
|
||||||
lock_guard lock(driver.mutex_);
|
::nana::internal_scope_guard lock;
|
||||||
#if defined(NANA_WINDOWS)
|
|
||||||
auto i = driver.timer_table_.find(id);
|
auto i = time_tbl.find(id);
|
||||||
#else
|
if (i == time_tbl.end())
|
||||||
auto i = driver.timer_table_.find(reinterpret_cast<timer_identifier>(id));
|
|
||||||
#endif
|
|
||||||
if (i == driver.timer_table_.end())
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
arg_elapse arg;
|
arg_elapse arg;
|
||||||
@ -183,8 +179,7 @@ namespace nana
|
|||||||
|
|
||||||
timer::~timer()
|
timer::~timer()
|
||||||
{
|
{
|
||||||
if (impl_->tm_core)
|
stop();
|
||||||
timer_driver::instance().destroy(impl_->tm_core->id());
|
|
||||||
delete impl_;
|
delete impl_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* A Categorize Implementation
|
* A Categorize Implementation
|
||||||
* Nana C++ Library(http://www.nanapro.org)
|
* Nana C++ Library(http://www.nanapro.org)
|
||||||
* Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
|
* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com)
|
||||||
*
|
*
|
||||||
* Distributed under the Boost Software License, Version 1.0.
|
* Distributed under the Boost Software License, Version 1.0.
|
||||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
@ -10,7 +10,7 @@
|
|||||||
* @file nana/gui/widgets/categorize.cpp
|
* @file nana/gui/widgets/categorize.cpp
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <nana/gui/wvl.hpp>
|
#include <nana/gui/compact.hpp>
|
||||||
#include <nana/gui/widgets/categorize.hpp>
|
#include <nana/gui/widgets/categorize.hpp>
|
||||||
#include <nana/gui/widgets/float_listbox.hpp>
|
#include <nana/gui/widgets/float_listbox.hpp>
|
||||||
#include <nana/gui/element.hpp>
|
#include <nana/gui/element.hpp>
|
||||||
|
@ -10,9 +10,9 @@
|
|||||||
* @file: nana/gui/widgets/combox.cpp
|
* @file: nana/gui/widgets/combox.cpp
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <nana/gui.hpp>
|
#include <nana/gui/compact.hpp>
|
||||||
#include <nana/gui/widgets/combox.hpp>
|
|
||||||
#include <nana/gui/element.hpp>
|
#include <nana/gui/element.hpp>
|
||||||
|
#include <nana/gui/widgets/combox.hpp>
|
||||||
#include <nana/system/dataexch.hpp>
|
#include <nana/system/dataexch.hpp>
|
||||||
#include <nana/gui/widgets/float_listbox.hpp>
|
#include <nana/gui/widgets/float_listbox.hpp>
|
||||||
#include <nana/gui/widgets/skeletons/text_editor.hpp>
|
#include <nana/gui/widgets/skeletons/text_editor.hpp>
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* Benjamin Navarro(pr#81)
|
* Benjamin Navarro(pr#81)
|
||||||
* besh81(pr#130)
|
* besh81(pr#130)
|
||||||
* dankan1890(pr#158)
|
* dankan1890(pr#158)
|
||||||
* ErrorFlynn(pr#418)
|
* ErrorFlynn(pr#418,pr#448,pr#454)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -13,12 +13,13 @@
|
|||||||
* dankan1890(pr#158)
|
* dankan1890(pr#158)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <nana/gui/compact.hpp>
|
||||||
|
#include <nana/gui/screen.hpp>
|
||||||
#include <nana/gui/widgets/menu.hpp>
|
#include <nana/gui/widgets/menu.hpp>
|
||||||
#include <nana/gui/timer.hpp>
|
#include <nana/gui/timer.hpp>
|
||||||
|
|
||||||
#include <nana/system/platform.hpp>
|
#include <nana/system/platform.hpp>
|
||||||
#include <nana/gui/element.hpp>
|
#include <nana/gui/element.hpp>
|
||||||
#include <nana/gui/wvl.hpp>
|
|
||||||
#include <nana/paint/text_renderer.hpp>
|
#include <nana/paint/text_renderer.hpp>
|
||||||
#include <cctype> //introduces tolower
|
#include <cctype> //introduces tolower
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Nana GUI Library Definition
|
* Nana GUI Library Definition
|
||||||
* Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
|
* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com)
|
||||||
*
|
*
|
||||||
* Distributed under the Boost Software License, Version 1.0.
|
* Distributed under the Boost Software License, Version 1.0.
|
||||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
@ -11,7 +11,8 @@
|
|||||||
* the file contains the files required for running of Nana.GUI
|
* the file contains the files required for running of Nana.GUI
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <nana/gui/wvl.hpp>
|
#include <nana/gui/compact.hpp>
|
||||||
|
#include <nana/gui/widgets/widget.hpp>
|
||||||
#include <nana/gui/detail/bedrock.hpp>
|
#include <nana/gui/detail/bedrock.hpp>
|
||||||
#include <nana/std_thread.hpp>
|
#include <nana/std_thread.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -1,3 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Unicode Bidi-Language Implementation
|
||||||
|
* Nana C++ Library(http://www.nanapro.org)
|
||||||
|
* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com)
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0.
|
||||||
|
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* @file: nana/unicode_bidi.cpp
|
||||||
|
* @contributors:
|
||||||
|
* glavangeorge(pr#440)
|
||||||
|
|
||||||
|
*/
|
||||||
#include <nana/unicode_bidi.hpp>
|
#include <nana/unicode_bidi.hpp>
|
||||||
#include <nana/c++defines.hpp>
|
#include <nana/c++defines.hpp>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user