Debian Codegraph @

gtk/gtkmm/childpropertyproxy.h

raw symbols SCIP
1 #ifndef _GTKMM_CHILDPROPERTYPROXY_H
2 #define _GTKMM_CHILDPROPERTYPROXY_H
3
4 /* childpropertyproxy.h
5 *
6 * Copyright (C) 2014 The gtkmm Development Team
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
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 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #include <gtkmm/childpropertyproxy_base.h>
23
24 namespace Gtk
25 {
26
27 /** A ChildPropertyProxy can be used to get and set the value of a GtkContainer's child property.
28 * Child properties are not specific to either the container or the contained widget, but rather
29 * to their relation.
30 * With the ChildPropertyProxy, you may use either get_value() and set_value(), or operator=()
31 * and operator PropertyType(), like in this example:
32 * @code
33 * bool first_tab_tab_expand = notebook.property_tab_expand(first_tab_widget);
34 * notebook.property_tab_expand(first_tab_widget) = true;
35 * @endcode
36 *
37 * You may also receive notification when a property's value changes on a child, by connecting
38 * to signal_changed().
39 */
40 template <class T>
41 class ChildPropertyProxy : public ChildPropertyProxy_Base
42 {
43 public:
44 typedef T PropertyType;
45
46 ChildPropertyProxy(Gtk::Container* parent, Gtk::Widget& child, const char* property_name)
47 : ChildPropertyProxy_Base(parent, child, property_name) {}
48
49 /** Set the value of this property in child.
50 * @param data The new value for the property.
51 */
52 void set_value(const PropertyType& data);
53
54 /** Get the value of this property in child.
55 * @result The current value of the property.
56 */
57 PropertyType get_value() const;
58
59 /** Set the value of this property in child back to its default value.
60 */
61 void reset_value()
62 { reset_property_(); }
63
64 ChildPropertyProxy<T>& operator=(const PropertyType& data)
65 { set_value(data); return *this; }
66
67 operator PropertyType() const
68 { return get_value(); }
69
70 SignalProxyChildProperty signal_changed();
71 };
72
73
74 /** See ChildPropertyProxy().
75 * This property can be written, but not read, so there is no get_value() method.
76 */
77 template <class T>
78 class ChildPropertyProxy_WriteOnly : public ChildPropertyProxy_Base
79 {
80 public:
81 typedef T PropertyType;
82
83 ChildPropertyProxy_WriteOnly(Gtk::Container* parent, Gtk::Widget& child, const char* property_name)
84 : ChildPropertyProxy_Base(parent, child, property_name) {}
85
86 /** Set the value of this property in child.
87 * @param data The new value for the property.
88 */
89 void set_value(const PropertyType& data);
90
91 /** Set the value of this property in child back to its default value.
92 */
93 void reset_value()
94 { reset_property_(); }
95
96 ChildPropertyProxy_WriteOnly<T>& operator=(const PropertyType& data)
97 { set_value(data); return *this; }
98 };
99
100 /** See ChildPropertyProxy().
101 * This property can be read, but not written, so there is no set_value() method.
102 */
103 template <class T>
104 class ChildPropertyProxy_ReadOnly : public ChildPropertyProxy_Base
105 {
106 public:
107 typedef T PropertyType;
108
109 //obj is const, because this should be returned by const accessors.
110 ChildPropertyProxy_ReadOnly(const Gtk::Container* parent, const Gtk::Widget& child, const char* property_name)
111 : ChildPropertyProxy_Base(const_cast<Gtk::Container*>(parent), const_cast<Gtk::Widget&>(child), property_name) {}
112
113 /** Get the value of this property in child.
114 * @result The current value of the property.
115 */
116 PropertyType get_value() const;
117
118 operator PropertyType() const
119 { return get_value(); }
120 };
121
122
123 /**** Template Implementation **********************************************/
124
125 #ifndef DOXYGEN_SHOULD_SKIP_THIS
126
127 template <class T>
128 void ChildPropertyProxy<T>::set_value(const T& data)
129 {
130 Glib::Value<T> value;
131 value.init(Glib::Value<T>::value_type());
132
133 value.set(data);
134 set_property_(value);
135 }
136
137 template <class T>
138 T ChildPropertyProxy<T>::get_value() const
139 {
140 Glib::Value<T> value;
141 value.init(Glib::Value<T>::value_type());
142
143 get_property_(value);
144 return value.get();
145 }
146
147 template <class T>
148 SignalProxyChildProperty ChildPropertyProxy<T>::signal_changed()
149 {
150 return SignalProxyChildProperty(&child_, property_name_);
151 }
152
153 template <class T>
154 void ChildPropertyProxy_WriteOnly<T>::set_value(const T& data)
155 {
156 Glib::Value<T> value;
157 value.init(Glib::Value<T>::value_type());
158
159 value.set(data);
160 set_property_(value);
161 }
162
163 template <class T>
164 T ChildPropertyProxy_ReadOnly<T>::get_value() const
165 {
166 Glib::Value<T> value;
167 value.init(Glib::Value<T>::value_type());
168
169 get_property_(value);
170 return value.get();
171 }
172
173 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
174
175 } // namespace Gtk
176
177 #endif /* _GTKMM_CHILDPROPERTYPROXY_H */