remove the internal signal manager of window_manager

This commit is contained in:
Jinhao
2015-05-25 01:19:35 +08:00
parent ffe32e1bcb
commit e04b0749e0
13 changed files with 132 additions and 275 deletions

View File

@@ -15,13 +15,12 @@
#include "drawer.hpp"
#include "events_holder.hpp"
#include "widget_colors.hpp"
#include "widget_notifier_interface.hpp"
#include <nana/basic_types.hpp>
#include <nana/system/platform.hpp>
#include <nana/gui/effects.hpp>
#include <memory>
namespace nana{
class widget; //declaration of nana/widgets/widget.hpp
namespace detail
{
struct basic_window;
@@ -89,11 +88,11 @@ namespace detail
//basic_window
//@brief: constructor for the root window
basic_window(basic_window* owner, widget*, category::root_tag**);
basic_window(basic_window* owner, std::unique_ptr<widget_notifier_interface>&&, category::root_tag**);
template<typename Category>
basic_window(basic_window* parent, const rectangle& r, widget* wdg, Category**)
: widget_ptr(wdg), other(Category::value)
basic_window(basic_window* parent, std::unique_ptr<widget_notifier_interface>&& wdg_notifier, const rectangle& r, Category**)
: widget_notifier(std::move(wdg_notifier)), other(Category::value)
{
drawer.bind(this);
if(parent)
@@ -146,7 +145,7 @@ namespace detail
basic_window* root_widget; //A pointer refers to the root basic window, if the window is a root, the pointer refers to itself.
paint::graphics* root_graph; //Refer to the root buffer graphics
cursor predef_cursor;
widget* const widget_ptr;
std::unique_ptr<widget_notifier_interface> widget_notifier;
struct flags_type
{

View File

@@ -1,7 +1,7 @@
/*
* Inner Forward Declaration
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
@@ -19,37 +19,6 @@
namespace nana{
namespace detail
{
struct signals
{
enum class code
{
caption,
read_caption,
destroy,
size,
end
};
union
{
const nana::char_t* caption;
nana::string * str;
struct
{
unsigned width;
unsigned height;
}size;
}info;
};
class signal_invoker_interface
{
public:
virtual ~signal_invoker_interface()
{}
virtual void call_signal(signals::code, const signals&) = 0;
};
}
}
#endif //NANA_GUI_INNER_FWD_HPP

View File

@@ -170,34 +170,6 @@ namespace nana{
std::map<native_window_type, root_misc> table_;
};
class signal_manager
{
typedef basic_window core_window_t;
public:
void make(core_window_t* wd, signal_invoker_interface* si)
{
if (si)
table_[wd].reset(si);
else
table_.erase(wd);
}
void umake(core_window_t * wd)
{
table_.erase(wd);
}
void call_signal(core_window_t * wd, signals::code code, const signals& s)
{
auto i = table_.find(wd);
if (i != table_.end())
i->second->call_signal(code, s);
}
private:
std::map<core_window_t*, std::unique_ptr<signal_invoker_interface>> table_;
};
}
}//end namespace nana
#endif //NANA_GUI_INNER_FWD_IMPLEMENT_HPP

View File

@@ -42,24 +42,7 @@ namespace nana
namespace nana{
namespace detail
{
template<typename T>
class signal_invoker_mf
: public signal_invoker_interface
{
public:
signal_invoker_mf(T& obj, void(T::*mf)(signals::code, const signals&))
: obj_(obj),
mf_(mf)
{}
void call_signal(signals::code code, const signals& s) override
{
(obj_.*mf_)(code, s);
}
private:
T& obj_;
void(T::*mf_)(signals::code, const signals&);
};
class widget_notifier_interface; //forward declaration
struct root_misc;
@@ -103,14 +86,6 @@ namespace detail
mutex_type & internal_lock() const;
void all_handles(std::vector<core_window_t*>&) const;
template<typename T, typename Concept>
void attach_signal(core_window_t* wd, T& obj, void(Concept::*mf)(signals::code, const signals&))
{
return _m_attach_signal(wd, new signal_invoker_mf<Concept>(obj, mf));
}
void signal_fire_caption(core_window_t*, const nana::char_t*);
nana::string signal_fire_caption(core_window_t*);
void event_filter(core_window_t*, bool is_make, event_code);
void default_icon(const nana::paint::image&);
@@ -121,6 +96,7 @@ namespace detail
core_window_t* create_root(core_window_t*, bool nested, rectangle, const appearance&, widget*);
core_window_t* create_widget(core_window_t*, const rectangle&, bool is_lite, widget*);
core_window_t* create_frame(core_window_t*, const rectangle&, widget*);
bool insert_frame(core_window_t* frame, native_window);
bool insert_frame(core_window_t* frame, core_window_t*);
void close(core_window_t*);
@@ -188,7 +164,6 @@ namespace detail
core_window_t* find_shortkey(native_window_type, unsigned long key);
private:
void _m_attach_signal(core_window_t*, signal_invoker_interface*);
void _m_disengage(core_window_t*, core_window_t* for_new);
void _m_destroy(core_window_t*);
void _m_move_core(core_window_t*, const point& delta);
@@ -200,8 +175,6 @@ namespace detail
struct wdm_private_impl;
wdm_private_impl * const impl_;
signals signals_;
struct attribute
{
struct captured

View File

@@ -48,13 +48,6 @@ namespace API
//@brief: The interfaces defined in namespace dev are used for developing the nana.gui
namespace dev
{
template<typename Object, typename Concept>
void attach_signal(window wd, Object& object, void (Concept::*f)(::nana::detail::signals::code, const ::nana::detail::signals&))
{
using namespace ::nana::detail;
bedrock::instance().wd_manager.attach_signal(reinterpret_cast<bedrock::core_window_t*>(wd), object, f);
}
bool set_events(window, const std::shared_ptr<general_events>&);
template<typename Scheme>

View File

@@ -22,10 +22,18 @@
namespace nana
{
namespace detail
{
//Forward declaration of widget_notifier_interface
class widget_notifier_interface;
}
/// Abstract class for defining the capacity interface.
class widget
: nana::noncopyable, nana::nonmovable
{
friend class detail::widget_notifier_interface;
class notifier;
typedef void(*dummy_bool_type)(widget* (*)(const widget&));
public:
virtual ~widget() = default;
@@ -88,6 +96,11 @@ namespace nana
operator dummy_bool_type() const;
operator window() const;
protected:
std::unique_ptr<::nana::detail::widget_notifier_interface> _m_wdg_notifier();
private:
virtual void _m_notify_destroy() = 0;
protected:
//protected members, a derived class must call this implementation if it overrides an implementation
virtual void _m_complete_creation();
@@ -152,7 +165,6 @@ namespace nana
handle_ = API::dev::create_widget(parent_wd, r, this);
API::dev::set_events(handle_, events_);
API::dev::set_scheme(handle_, scheme_.get());
API::dev::attach_signal(handle_, *this, &widget_object::signal);
API::dev::attach_drawer(*this, trigger_);
if(visible)
API::show_window(handle_, true);
@@ -193,29 +205,15 @@ namespace nana
return trigger_;
}
private:
void signal(detail::signals::code code, const detail::signals& sig)
{
typedef detail::signals::code codes;
switch(code)
{
case codes::caption:
this->_m_caption(sig.info.caption);
break;
case codes::read_caption:
*sig.info.str = this->_m_caption();
break;
case codes::destroy:
handle_ = nullptr;
break;
default:
break;
}
}
general_events& _m_get_general_events() const override
{
return *events_;
}
void _m_notify_destroy() override final
{
handle_ = nullptr;
}
private:
window handle_{nullptr};
DrawerTrigger trigger_;
@@ -276,29 +274,15 @@ namespace nana
return *scheme_;
}
private:
void signal(detail::signals::code code, const detail::signals& sig)
{
typedef detail::signals::code codes;
switch(code)
{
case codes::caption:
this->_m_caption(sig.info.caption);
break;
case codes::read_caption:
*sig.info.str = this->_m_caption();
break;
case codes::destroy:
handle_ = nullptr;
break;
default:
break;
}
}
general_events& _m_get_general_events() const override
{
return *events_;
}
void _m_notify_destroy() override final
{
handle_ = nullptr;
}
private:
window handle_{nullptr};
std::shared_ptr<Events> events_;
@@ -430,25 +414,6 @@ namespace nana
return trigger_;
}
private:
void signal(detail::signals::code code, const detail::signals& sig)
{
typedef detail::signals::code codes;
switch(code)
{
case codes::caption:
this->_m_caption(sig.info.caption);
break;
case codes::read_caption:
*sig.info.str = this->_m_caption();
break;
case codes::destroy:
handle_ = nullptr;
break;
default:
break;
}
}
void _m_bind_and_attach()
{
events_ = std::make_shared<Events>();
@@ -456,7 +421,6 @@ namespace nana
scheme_ = API::dev::make_scheme<scheme_type>();
API::dev::set_scheme(handle_, scheme_.get());
API::dev::attach_signal(handle_, *this, &widget_object::signal);
API::dev::attach_drawer(*this, trigger_);
}
@@ -464,6 +428,11 @@ namespace nana
{
return *events_;
}
void _m_notify_destroy() override final
{
handle_ = nullptr;
}
private:
window handle_;
DrawerTrigger trigger_;
@@ -511,7 +480,6 @@ namespace nana
handle_ = API::dev::create_frame(parent_wd, r, this);
API::dev::set_events(handle_, events_);
API::dev::set_scheme(handle_, scheme_.get());
API::dev::attach_signal(handle_, *this, &widget_object::signal);
API::show_window(handle_, visible);
this->_m_complete_creation();
}
@@ -533,29 +501,15 @@ namespace nana
return nullptr;
}
void signal(detail::signals::code code, const detail::signals& sig)
{
typedef detail::signals::code codes;
switch(code)
{
case codes::caption:
this->_m_caption(sig.info.caption);
break;
case codes::read_caption:
*sig.info.str = this->_m_caption();
break;
case codes::destroy:
handle_ = nullptr;
break;
default:
break;
}
}
general_events& _m_get_general_events() const override
{
return *events_;
}
void _m_notify_destroy() override final
{
handle_ = nullptr;
}
private:
window handle_{nullptr};
std::shared_ptr<Events> events_;