From e4831db229641ee88ad8a2c1e0d82d7d3442e96b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 8 Jan 2013 18:58:11 +0000 Subject: Add signals and default handlers for every property in conventional Gtkmm style. git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@4908 a436a847-0d15-0410-975c-d299462d15a1 --- ganv/Item.hpp | 2 +- ganv/Node.hpp | 9 +++++++++ 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, &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 + 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*)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 + +#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& signal_##name() { return _signal_##name; } \ +private: \ + sigc::signal _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& signal_##name() { return _signal_##name; } \ -private: \ - sigc::signal _signal_##name; - #define GANV_GLIB_WRAP(Name) \ namespace Ganv { \ class Name; \ -- cgit v1.2.1