summaryrefslogtreecommitdiffstats
path: root/ganv
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2013-01-08 18:58:11 +0000
committerDavid Robillard <d@drobilla.net>2013-01-08 18:58:11 +0000
commite4831db229641ee88ad8a2c1e0d82d7d3442e96b (patch)
tree59cd424127442d2881bcd4680bbcaa1271cf0948 /ganv
parentc0ce35232594b1aa07473f8e61fcee14cf97fbe8 (diff)
downloadganv-e4831db229641ee88ad8a2c1e0d82d7d3442e96b.tar.gz
ganv-e4831db229641ee88ad8a2c1e0d82d7d3442e96b.tar.bz2
ganv-e4831db229641ee88ad8a2c1e0d82d7d3442e96b.zip
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
Diffstat (limited to 'ganv')
-rw-r--r--ganv/Item.hpp2
-rw-r--r--ganv/Node.hpp9
-rw-r--r--ganv/wrap.hpp26
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; \