2 /* $Id: propertyproxy_base.cc 354 2006-11-28 12:59:19Z murrayc $ */
4 /* propertyproxy_base.h
6 * Copyright 2002 The gtkmm Development Team
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.
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.
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.
23 #include <glibmm/propertyproxy_base.h>
26 #include <glibmm/signalproxy_connectionnode.h>
27 #include <glibmm/object.h>
28 #include <glibmm/private/object_p.h>
33 PropertyProxyConnectionNode::PropertyProxyConnectionNode(const sigc::slot_base& slot, GObject* gobject)
34 : SignalProxyConnectionNode(slot, gobject)
38 void PropertyProxyConnectionNode::callback(GObject*, GParamSpec* pspec, gpointer data) //static
42 if(sigc::slot_base *const slot = SignalProxyBase::data_to_slot(data))
43 (*static_cast<sigc::slot<void>*>(slot))();
47 #ifdef GLIBMM_PROPERTIES_ENABLED
49 //SignalProxyProperty implementation:
51 SignalProxyProperty::SignalProxyProperty(Glib::ObjectBase* obj, const gchar* property_name)
52 : SignalProxyBase(obj),
53 property_name_(property_name)
57 SignalProxyProperty::~SignalProxyProperty()
61 sigc::connection SignalProxyProperty::connect(const SlotType& sl)
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());
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,
77 return sigc::connection(pConnectionNode->slot_);
81 //PropertyProxy_Base implementation:
83 PropertyProxy_Base::PropertyProxy_Base(ObjectBase* obj, const char* property_name)
86 property_name_ (property_name)
89 PropertyProxy_Base::PropertyProxy_Base(const PropertyProxy_Base& other)
92 property_name_ (other.property_name_)
95 SignalProxyProperty PropertyProxy_Base::signal_changed()
97 return SignalProxyProperty(obj_, property_name_);
100 void PropertyProxy_Base::set_property_(const Glib::ValueBase& value)
102 g_object_set_property(obj_->gobj(), property_name_, value.gobj());
105 void PropertyProxy_Base::get_property_(Glib::ValueBase& value) const
107 g_object_get_property(obj_->gobj(), property_name_, value.gobj());
110 void PropertyProxy_Base::reset_property_()
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_);
116 g_return_if_fail(pParamSpec != 0);
118 Glib::ValueBase value;
119 value.init(G_PARAM_SPEC_VALUE_TYPE(pParamSpec));
121 // An explicit reset is not needed, because ValueBase:init()
122 // has already initialized it to the default value for this type.
125 g_object_set_property(obj_->gobj(), property_name_, value.gobj());
128 #endif //GLIBMM_PROPERTIES_ENABLED