diff options
Diffstat (limited to 'ganv')
-rw-r--r-- | ganv/Item.hpp | 2 | ||||
-rw-r--r-- | ganv/Node.hpp | 9 | ||||
-rw-r--r-- | ganv/wrap.hpp | 26 |
3 files changed, 26 insertions, 11 deletions
diff --git a/ganv/Item.hpp b/ganv/Item.hpp index 1009e12..ae4cbdf 100644 --- a/ganv/Item.hpp +++ b/ganv/Item.hpp @@ -81,7 +81,7 @@ private: GdkEvent* ev, void* item) { - return ((Item*)item)->on_event(ev); + return ((Item*)item)->signal_event().emit(ev); } }; diff --git a/ganv/Node.hpp b/ganv/Node.hpp index fb1c1be..c9aaa63 100644 --- a/ganv/Node.hpp +++ b/ganv/Node.hpp @@ -38,6 +38,8 @@ public: : Item(GANV_ITEM(g_object_ref(gobj))) { g_signal_connect(gobj, "moved", G_CALLBACK(on_moved), this); + CONNECT_PROP_SIGNAL(gobj, selected, + on_notify<gboolean>, &Node::on_selected) } ~Node() { @@ -83,6 +85,13 @@ private: static void on_moved(GanvNode* node, double x, double y) { Glib::wrap(node)->_signal_moved.emit(x, y); } + + template<typename T> + static void on_notify(GObject* gobj, GParamSpec* pspec, gpointer signal) { + T value; + g_object_get(gobj, g_param_spec_get_name(pspec), &value, NULL); + ((sigc::signal<bool, T>*)signal)->emit(value); + } }; } // namespace Ganv diff --git a/ganv/wrap.hpp b/ganv/wrap.hpp index d29740e..d0cdfa4 100644 --- a/ganv/wrap.hpp +++ b/ganv/wrap.hpp @@ -17,6 +17,19 @@ #define GANV_WRAP_HPP #include <glib.h> + +#define CONNECT_PROP_SIGNAL(gobj, name, notify, handler) \ + g_signal_connect(gobj, "notify::" #name, \ + G_CALLBACK(notify), &_signal_##name); \ + _signal_##name.connect(sigc::mem_fun(this, handler)); + +#define SIGNAL1(name, argtype) \ +public: \ + virtual bool on_##name(argtype arg) { return true; } \ + sigc::signal<bool, argtype>& signal_##name() { return _signal_##name; } \ +private: \ + sigc::signal<bool, argtype> _signal_##name; + #define RW_PROPERTY(type, name) \ virtual type get_##name() const { \ type value; \ @@ -25,7 +38,9 @@ } \ virtual void set_##name(type value) { \ g_object_set(G_OBJECT(_gobj), #name, value, NULL); \ - } + } \ + SIGNAL1(name, type) \ + public: #define RW_OBJECT_PROPERTY(type, name) \ type get_##name() const { \ @@ -75,15 +90,6 @@ prefix##_##name(gobj(), a1, a2, a3); \ } -#define SIGNAL1(name, argtype) \ -public: \ - virtual bool on_##name(argtype arg) { \ - return _signal_##name.emit(arg); \ - } \ - sigc::signal<bool, argtype>& signal_##name() { return _signal_##name; } \ -private: \ - sigc::signal<bool, argtype> _signal_##name; - #define GANV_GLIB_WRAP(Name) \ namespace Ganv { \ class Name; \ |