2 #ifndef _GLIBMM_PROPERTYPROXY_H
3 #define _GLIBMM_PROPERTYPROXY_H
4 /* $Id: propertyproxy.h 291 2006-05-12 08:08:45Z murrayc $ */
8 * Copyright 2002 The gtkmm Development Team
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library; if not, write to the Free
22 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <glibmm/propertyproxy_base.h>
27 #ifdef GLIBMM_PROPERTIES_ENABLED
32 /** A PropertyProxy can be used to get and set the value of an object's property.
33 * There are usually also get and set methods on the class itself, which you might find more convenient.
34 * With the PropertyProxy, you may use either get_value() and set_value(), or operator=() and
35 * operator PropertyType(), like so:
37 * int height = cellrenderer.property_height();
38 * cellrenderer.property_editable() = true;
41 * You may also receive notification when a property's value changes, by connecting to signal_changed().
44 class PropertyProxy : public PropertyProxy_Base
47 typedef T PropertyType;
49 PropertyProxy(ObjectBase* obj, const char* name)
50 : PropertyProxy_Base(obj, name) {}
52 /** Set the value of this property.
53 * @param data The new value for the property.
55 void set_value(const PropertyType& data);
57 /** Get the value of this property.
58 * @result The current value of the property.
60 PropertyType get_value() const;
62 /** Set the value of this property back to its default value
65 { reset_property_(); }
67 PropertyProxy<T>& operator=(const PropertyType& data)
68 { this->set_value(data); return *this; }
70 operator PropertyType() const
71 { return this->get_value(); }
75 /** See PropertyProxy().
76 * This property can be written, but not read, so there is no get_value() method.
79 class PropertyProxy_WriteOnly : public PropertyProxy_Base
82 typedef T PropertyType;
84 PropertyProxy_WriteOnly(ObjectBase* obj, const char* name)
85 : PropertyProxy_Base(obj, name) {}
87 /** Set the value of this property.
88 * @param data The new value for the property.
90 void set_value(const PropertyType& data);
92 /** Set the value of this property back to its default value
95 { reset_property_(); }
97 PropertyProxy_WriteOnly<T>& operator=(const PropertyType& data)
98 { this->set_value(data); return *this; }
101 /** See PropertyProxy().
102 * This property can be read, but not written, so there is no set_value() method.
105 class PropertyProxy_ReadOnly : public PropertyProxy_Base
108 typedef T PropertyType;
110 //obj is const, because this should be returned by const accessors.
111 PropertyProxy_ReadOnly(const ObjectBase* obj, const char* name)
112 : PropertyProxy_Base(const_cast<ObjectBase*>(obj), name) {}
114 /** Get the value of this property.
115 * @result The current value of the property.
117 PropertyType get_value() const;
119 operator PropertyType() const
120 { return this->get_value(); }
124 /**** Template Implementation **********************************************/
126 #ifndef DOXYGEN_SHOULD_SKIP_THIS
129 void PropertyProxy<T>::set_value(const T& data)
131 Glib::Value<T> value;
132 value.init(Glib::Value<T>::value_type());
135 set_property_(value);
139 T PropertyProxy<T>::get_value() const
141 Glib::Value<T> value;
142 value.init(Glib::Value<T>::value_type());
144 get_property_(value);
148 //We previously just static_cast<> PropertyProxy_WriteOnly<> to PropertyProxy<> to call its set_value(),
149 //to avoid code duplication.
150 //But the AIX compiler does not like that hack.
152 void PropertyProxy_WriteOnly<T>::set_value(const T& data)
154 Glib::Value<T> value;
155 value.init(Glib::Value<T>::value_type());
158 set_property_(value);
161 //We previously just static_cast<> PropertyProxy_WriteOnly<> to PropertyProxy<> to call its set_value(),
162 //to avoid code duplication.
163 //But the AIX compiler does not like that hack.
165 T PropertyProxy_ReadOnly<T>::get_value() const
167 Glib::Value<T> value;
168 value.init(Glib::Value<T>::value_type());
170 get_property_(value);
174 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
178 #endif //GLIBMM_PROPERTIES_ENABLED
180 #endif /* _GLIBMM_PROPERTYPROXY_H */