2 #ifndef _GLIBMM_PROPERTY_H
3 #define _GLIBMM_PROPERTY_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.h>
24 #include <glibmm/value.h>
30 #ifndef DOXYGEN_SHOULD_SKIP_THIS
32 #ifdef GLIBMM_CXX_CAN_USE_NAMESPACES_INSIDE_EXTERNC
33 //For the AIX xlC compiler, I can not find a way to do this without putting the functions in the global namespace. murrayc
36 #endif //GLIBMM_CXX_CAN_USE_NAMESPACES_INSIDE_EXTERNC
38 void custom_get_property_callback(GObject* object, unsigned int property_id,
39 GValue* value, GParamSpec* param_spec);
41 void custom_set_property_callback(GObject* object, unsigned int property_id,
42 const GValue* value, GParamSpec* param_spec);
44 #ifdef GLIBMM_CXX_CAN_USE_NAMESPACES_INSIDE_EXTERNC
46 #endif //GLIBMM_CXX_CAN_USE_NAMESPACES_INSIDE_EXTERNC
48 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
54 Glib::ustring get_name() const;
58 Glib::Object* object_;
59 Glib::ValueBase value_;
60 GParamSpec* param_spec_;
62 PropertyBase(Glib::Object& object, GType value_type);
65 bool lookup_property(const Glib::ustring& name);
66 void install_property(GParamSpec* param_spec);
68 const char* get_name_internal() const;
72 PropertyBase(const PropertyBase&);
73 PropertyBase& operator=(const PropertyBase&);
75 #ifndef DOXYGEN_SHOULD_SKIP_THIS
77 friend void Glib::custom_get_property_callback(GObject* object, unsigned int property_id,
78 GValue* value, GParamSpec* param_spec);
80 friend void Glib::custom_set_property_callback(GObject* object, unsigned int property_id,
81 const GValue* value, GParamSpec* param_spec);
83 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
88 class Property : public PropertyBase
91 typedef T PropertyType;
92 typedef Glib::Value<T> ValueType;
94 Property(Glib::Object& object, const Glib::ustring& name);
95 Property(Glib::Object& object, const Glib::ustring& name, const PropertyType& default_value);
97 inline void set_value(const PropertyType& data);
98 inline PropertyType get_value() const;
100 inline Property<T>& operator=(const PropertyType& data);
101 inline operator PropertyType() const;
103 inline Glib::PropertyProxy<T> get_proxy();
107 #ifndef DOXYGEN_SHOULD_SKIP_THIS
109 /**** Glib::Property<T> ****************************************************/
112 Property<T>::Property(Glib::Object& object, const Glib::ustring& name)
114 PropertyBase(object, ValueType::value_type())
116 if(!lookup_property(name))
117 install_property(static_cast<ValueType&>(value_).create_param_spec(name));
121 Property<T>::Property(Glib::Object& object, const Glib::ustring& name,
122 const typename Property<T>::PropertyType& default_value)
124 PropertyBase(object, ValueType::value_type())
126 static_cast<ValueType&>(value_).set(default_value);
128 if(!lookup_property(name))
129 install_property(static_cast<ValueType&>(value_).create_param_spec(name));
132 template <class T> inline
133 void Property<T>::set_value(const typename Property<T>::PropertyType& data)
135 static_cast<ValueType&>(value_).set(data);
139 template <class T> inline
140 typename Property<T>::PropertyType Property<T>::get_value() const
142 return static_cast<const ValueType&>(value_).get();
145 template <class T> inline
146 Property<T>& Property<T>::operator=(const typename Property<T>::PropertyType& data)
148 static_cast<ValueType&>(value_).set(data);
153 template <class T> inline
154 Property<T>::operator T() const
156 return static_cast<const ValueType&>(value_).get();
159 template <class T> inline
160 Glib::PropertyProxy<T> Property<T>::get_proxy()
162 return Glib::PropertyProxy<T>(object_, get_name_internal());
165 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
170 #endif /* _GLIBMM_PROPERTY_H */