Reference Manual

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

# childproperty.h

Go to the documentation of this file.

    00001 /*  Inti: Integrated Foundation Classes
    00002  *  Copyright (C) 2002 The Inti Development Team.
    00003  *
    00004  *  This program is free software; you can redistribute it and/or modify
    00005  *  it under the terms of the GNU General Public License as published by
    00006  *  the Free Software Foundation; either version 2 of the License, or
    00007  *  (at your option) any later version.
    00008  *
    00009  *  This program is distributed in the hope that it will be useful,
    00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012  *  GNU Library General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU Library General Public License
    00015  *  along with this program; if not, write to the Free Software
    00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    00017  */
    00018
    00033
    00034 #ifndef INTI_GTK_CHILD_PROPERTY_H
    00035 #define INTI_GTK_CHILD_PROPERTY_H
    00036
    00037 #ifndef INTI_G_PROPERTY_H
    00038 #include <inti/glib/property.h>
    00039 #endif
    00040
    00041 #ifndef INTI_G_VALUE_H
    00042 #include <inti/glib/value.h>
    00043 #endif
    00044
    00045 namespace Inti {
    00046
    00047 namespace Gtk {
    00048
    00049 class Container;
    00050
    00051 /*  Gtk::ChildProperty (readable and writable)
    00052  */
    00053
    00054 template<typename DataType, typename ValueType = DataType>
    00055 class ChildProperty : public G::PropertyBase
    00056 {
    00057 public:
    00058         typedef DataType Data;
    00059
    00060         ChildProperty(const char* name) : G::PropertyBase(name)
    00061         {
    00062         }
    00063
    00064         void get(const Container *container, const Widget& child, DataType& data) const
    00065         {
    00066                 GParamSpec *pspec = find_property(container, true);
    00067                 ValueType tmp_data = 0;
    00068                 if (pspec)
    00069                 {
    00070                         G::Value value(pspec);
    00071                         get_property(container, &child, value);
    00072                         value.get(tmp_data);
    00073                 }
    00074                 data = static_cast<DataType>(tmp_data);
    00075         }
    00076
    00077         void set(const Container *container, Widget& child, const DataType& data) const
    00078         {
    00079                 GParamSpec *pspec = find_property(container, true);
    00080                 if (pspec)
    00081                 {
    00082                         G::Value value(pspec);
    00083                         value.set((ValueType)data);
    00084                         set_property(container, &child, value);
    00085                 }
    00086         }
    00087 };
    00088
    00089 /*  Gtk::ReadableChildProperty (read only)
    00090  */
    00091
    00092 template<typename DataType, typename ValueType = DataType>
    00093 class ReadableChildProperty : private ChildProperty<DataType, ValueType>
    00094 {
    00095         typedef ChildProperty<DataType, ValueType> Base;
    00096
    00097 public:
    00098         typedef DataType Data;
    00099
    00100         using Base::get;
    00101
    00102         ReadableChildProperty(const char *name) : Base(name)
    00103         {
    00104         }
    00105 };
    00106
    00107 /*  Gtk::WritableChildProperty (write only)
    00108  */
    00109
    00110 template<typename DataType, typename ValueType = DataType>
    00111 class WritableChildProperty : private ChildProperty<DataType, ValueType>
    00112 {
    00113         typedef ChildProperty<DataType, ValueType> Base;
    00114
    00115 public:
    00116         typedef DataType Data;
    00117
    00118         using Base::set;
    00119
    00120         WritableChildProperty(const char *name) : Base(name)
    00121         {
    00122         }
    00123 };
    00124
    00125 /*  Gtk::ChildPropertyProxy
    00126  */
    00127
    00128 template<typename ObjectType, typename PropertyType>
    00129 class ChildPropertyProxy : public G::PropertyProxyBase<ObjectType, PropertyType>
    00130 {
    00131         typedef G::PropertyProxyBase<ObjectType, PropertyType> Base;
    00132
    00133 public:
    00134         typedef typename PropertyType::Data DataType;
    00135
    00136         ChildPropertyProxy(ObjectType *object, const PropertyType *property) : Base(object, property)
    00137         {
    00138         }
    00139
    00140         void get(const Widget& child, DataType& data) const
    00141         {
    00142                 property()->get(object(), child, data);
    00143         }
    00144
    00145         void set(Widget& child, const DataType& data) const
    00146         {
    00147                 property()->set(object(), child, data);
    00148         }
    00149 };
    00150
    00151 } // namespace Gtk
    00152
    00153 } // namespace Inti
    00154
    00155 #endif // INTI_GTK_CHILD_PROPERTY_H

Main Page - Footer