// -*- c++ -*- #ifndef _GLIBMM_PROPERTY_H #define _GLIBMM_PROPERTY_H /* $Id$ */ /* Copyright 2002 The gtkmm Development Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include namespace Glib { #ifndef DOXYGEN_SHOULD_SKIP_THIS #ifdef GLIBMM_CXX_CAN_USE_NAMESPACES_INSIDE_EXTERNC //For the AIX xlC compiler, I can not find a way to do this without putting the functions in the global namespace. murrayc extern "C" { #endif //GLIBMM_CXX_CAN_USE_NAMESPACES_INSIDE_EXTERNC void custom_get_property_callback(GObject* object, unsigned int property_id, GValue* value, GParamSpec* param_spec); void custom_set_property_callback(GObject* object, unsigned int property_id, const GValue* value, GParamSpec* param_spec); #ifdef GLIBMM_CXX_CAN_USE_NAMESPACES_INSIDE_EXTERNC } //extern "C" #endif //GLIBMM_CXX_CAN_USE_NAMESPACES_INSIDE_EXTERNC #endif /* DOXYGEN_SHOULD_SKIP_THIS */ class PropertyBase { public: Glib::ustring get_name() const; void notify(); protected: Glib::Object* object_; Glib::ValueBase value_; GParamSpec* param_spec_; PropertyBase(Glib::Object& object, GType value_type); ~PropertyBase(); bool lookup_property(const Glib::ustring& name); void install_property(GParamSpec* param_spec); const char* get_name_internal() const; private: // noncopyable PropertyBase(const PropertyBase&); PropertyBase& operator=(const PropertyBase&); #ifndef DOXYGEN_SHOULD_SKIP_THIS friend void Glib::custom_get_property_callback(GObject* object, unsigned int property_id, GValue* value, GParamSpec* param_spec); friend void Glib::custom_set_property_callback(GObject* object, unsigned int property_id, const GValue* value, GParamSpec* param_spec); #endif /* DOXYGEN_SHOULD_SKIP_THIS */ }; template class Property : public PropertyBase { public: typedef T PropertyType; typedef Glib::Value ValueType; Property(Glib::Object& object, const Glib::ustring& name); Property(Glib::Object& object, const Glib::ustring& name, const PropertyType& default_value); inline void set_value(const PropertyType& data); inline PropertyType get_value() const; inline Property& operator=(const PropertyType& data); inline operator PropertyType() const; inline Glib::PropertyProxy get_proxy(); }; #ifndef DOXYGEN_SHOULD_SKIP_THIS /**** Glib::Property ****************************************************/ template Property::Property(Glib::Object& object, const Glib::ustring& name) : PropertyBase(object, ValueType::value_type()) { if(!lookup_property(name)) install_property(static_cast(value_).create_param_spec(name)); } template Property::Property(Glib::Object& object, const Glib::ustring& name, const typename Property::PropertyType& default_value) : PropertyBase(object, ValueType::value_type()) { static_cast(value_).set(default_value); if(!lookup_property(name)) install_property(static_cast(value_).create_param_spec(name)); } template inline void Property::set_value(const typename Property::PropertyType& data) { static_cast(value_).set(data); this->notify(); } template inline typename Property::PropertyType Property::get_value() const { return static_cast(value_).get(); } template inline Property& Property::operator=(const typename Property::PropertyType& data) { static_cast(value_).set(data); this->notify(); return *this; } template inline Property::operator T() const { return static_cast(value_).get(); } template inline Glib::PropertyProxy Property::get_proxy() { return Glib::PropertyProxy(object_, get_name_internal()); } #endif /* DOXYGEN_SHOULD_SKIP_THIS */ } // namespace Glib #endif /* _GLIBMM_PROPERTY_H */