rollback to 3428, before the mysterious removal of libs/* at 3431/3432
[ardour.git] / libs / glibmm2 / glib / glibmm / propertyproxy_base.cc
1 // -*- c++ -*-
2 /* $Id: propertyproxy_base.cc 354 2006-11-28 12:59:19Z murrayc $ */
3
4 /* propertyproxy_base.h
5  *
6  * Copyright 2002 The gtkmm Development Team
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #include <glibmm/propertyproxy_base.h>
24
25
26 #include <glibmm/signalproxy_connectionnode.h>
27 #include <glibmm/object.h>
28 #include <glibmm/private/object_p.h>
29
30 namespace Glib
31 {
32
33 PropertyProxyConnectionNode::PropertyProxyConnectionNode(const sigc::slot_base& slot, GObject* gobject)
34 : SignalProxyConnectionNode(slot, gobject)
35 {
36 }
37
38 void PropertyProxyConnectionNode::callback(GObject*, GParamSpec* pspec, gpointer data) //static
39 {
40   if(pspec && data)
41   {
42     if(sigc::slot_base *const slot = SignalProxyBase::data_to_slot(data))
43       (*static_cast<sigc::slot<void>*>(slot))();
44   }
45 }
46
47 #ifdef GLIBMM_PROPERTIES_ENABLED
48
49 //SignalProxyProperty implementation:
50
51 SignalProxyProperty::SignalProxyProperty(Glib::ObjectBase* obj, const gchar* property_name)
52 : SignalProxyBase(obj),
53   property_name_(property_name)
54 {
55 }
56
57 SignalProxyProperty::~SignalProxyProperty()
58 {
59 }
60
61 sigc::connection SignalProxyProperty::connect(const SlotType& sl)
62 {
63   // Create a proxy to hold our connection info
64   // This will be deleted by destroy_notify_handler.
65   PropertyProxyConnectionNode* pConnectionNode = new PropertyProxyConnectionNode(sl, obj_->gobj());
66
67   // connect it to gtk+
68   // pConnectionNode will be passed as the data argument to the callback.
69   // The callback will then call the virtual Object::property_change_notify() method,
70   // which will contain a switch/case statement which will examine the property name.
71   const Glib::ustring notify_signal_name = "notify::" + Glib::ustring(property_name_);
72   pConnectionNode->connection_id_ = g_signal_connect_data(obj_->gobj(),
73          notify_signal_name.c_str(), (GCallback)(&PropertyProxyConnectionNode::callback), pConnectionNode,
74          &PropertyProxyConnectionNode::destroy_notify_handler,
75          G_CONNECT_AFTER);
76
77   return sigc::connection(pConnectionNode->slot_);
78 }
79
80
81 //PropertyProxy_Base implementation:
82
83 PropertyProxy_Base::PropertyProxy_Base(ObjectBase* obj, const char* property_name)
84 :
85   obj_           (obj),
86   property_name_ (property_name)
87 {}
88
89 PropertyProxy_Base::PropertyProxy_Base(const PropertyProxy_Base& other)
90 :
91   obj_           (other.obj_),
92   property_name_ (other.property_name_)
93 {}
94
95 SignalProxyProperty PropertyProxy_Base::signal_changed()
96 {
97   return SignalProxyProperty(obj_, property_name_);
98 }
99
100 void PropertyProxy_Base::set_property_(const Glib::ValueBase& value)
101 {
102   g_object_set_property(obj_->gobj(), property_name_, value.gobj());
103 }
104
105 void PropertyProxy_Base::get_property_(Glib::ValueBase& value) const
106 {
107   g_object_get_property(obj_->gobj(), property_name_, value.gobj());
108 }
109
110 void PropertyProxy_Base::reset_property_()
111 {
112   // Get information about the parameter:
113   const GParamSpec *const pParamSpec =
114       g_object_class_find_property(G_OBJECT_GET_CLASS(obj_->gobj()), property_name_);
115
116   g_return_if_fail(pParamSpec != 0);
117
118   Glib::ValueBase value;
119   value.init(G_PARAM_SPEC_VALUE_TYPE(pParamSpec));
120
121   // An explicit reset is not needed, because ValueBase:init()
122   // has already initialized it to the default value for this type.
123   // value.reset();
124
125   g_object_set_property(obj_->gobj(), property_name_, value.gobj());
126 }
127
128 #endif //GLIBMM_PROPERTIES_ENABLED
129
130 } // namespace Glib
131