Debian Codegraph @

gtk/src/cellarea.ccg

raw
1 /* Copyright (C) 2010 The gtkmm Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
15 */
16
17 #include <gtk/gtk.h>
18
19
20 namespace //anonymous namespace
21 {
22
23 static gboolean proxy_foreach_callback(GtkCellRenderer* cell, void* data)
24 {
25 typedef Gtk::CellArea::SlotForeach SlotType;
26 auto& slot = *static_cast<SlotType*>(data);
27
28 try
29 {
30 return slot(Glib::wrap(cell));
31 }
32 catch(...)
33 {
34 Glib::exception_handlers_invoke();
35 }
36
37 return FALSE;
38 }
39
40 static gboolean proxy_foreach_alloc_callback(GtkCellRenderer* cell, const GdkRectangle* cell_area, const GdkRectangle* cell_background, void* data)
41 {
42 typedef Gtk::CellArea::SlotForeachAlloc SlotType;
43 auto& slot = *static_cast<SlotType*>(data);
44
45 try
46 {
47 return slot(Glib::wrap(cell), Glib::wrap(cell_area), Glib::wrap(cell_background));
48 }
49 catch(...)
50 {
51 Glib::exception_handlers_invoke();
52 }
53
54 return FALSE;
55 }
56
57
58 } //anonymous namespace
59
60
61
62 namespace Gtk
63 {
64
65 void CellArea::foreach(const SlotForeach& slot)
66 {
67 SlotForeach slot_copy(slot);
68 gtk_cell_area_foreach(const_cast<GtkCellArea*>(gobj()), &proxy_foreach_callback, &slot_copy);
69 }
70
71 void CellArea::foreach(const Glib::RefPtr<CellAreaContext>& context, Widget* widget, const Gdk::Rectangle& cell_area, const Gdk::Rectangle& background_area, const SlotForeachAlloc& slot)
72 {
73 SlotForeachAlloc slot_copy(slot);
74 gtk_cell_area_foreach_alloc(const_cast<GtkCellArea*>(gobj()), Glib::unwrap(context), Glib::unwrap(widget), cell_area.gobj(), background_area.gobj(), &proxy_foreach_alloc_callback, &slot_copy);
75 }
76
77
78 //These vfunc callbacks are custom implemented because we want the output
79 //arguments of the C++ vfuncs to be int& (not int*), and the vfunc_callback
80 //functions may be called from gtk+ with a NULL pointer.
81 void CellArea_Class::get_preferred_width_vfunc_callback(GtkCellArea* self, GtkCellAreaContext* context, GtkWidget* widget, gint* minimum_width, gint* natural_width)
82 {
83 const auto obj_base = static_cast<Glib::ObjectBase*>(
84 Glib::ObjectBase::_get_current_wrapper((GObject*)self));
85
86 // Non-gtkmmproc-generated custom classes implicitly call the default
87 // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
88 // generated classes can use this optimisation, which avoids the unnecessary
89 // parameter conversions if there is no possibility of the virtual function
90 // being overridden:
91 if(obj_base && obj_base->is_derived_())
92 {
93 const auto obj = dynamic_cast<CppObjectType* const>(obj_base);
94 if(obj) // This can be NULL during destruction.
95 {
96 try // Trap C++ exceptions which would normally be lost because this is a C callback.
97 {
98 // Call the virtual member method, which derived classes might override.
99 int min_width = 0;
100 int nat_width = 0;
101 obj->get_preferred_width_vfunc(Glib::wrap(context, true),
102 *Glib::wrap(widget),
103 (minimum_width ? *minimum_width : min_width),
104 (natural_width ? *natural_width : nat_width));
105 return;
106 }
107 catch(...)
108 {
109 Glib::exception_handlers_invoke();
110 }
111 }
112 }
113
114 const auto base = static_cast<BaseClassType*>(
115 g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
116 );
117
118 // Call the original underlying C function:
119 if(base && base->get_preferred_width)
120 (*base->get_preferred_width)(self, context, widget, minimum_width, natural_width);
121 }
122
123 void CellArea_Class::get_preferred_height_for_width_vfunc_callback(GtkCellArea* self, GtkCellAreaContext* context, GtkWidget* widget, gint width, gint* minimum_height, gint* natural_height)
124 {
125 const auto obj_base = static_cast<Glib::ObjectBase*>(
126 Glib::ObjectBase::_get_current_wrapper((GObject*)self));
127
128 // Non-gtkmmproc-generated custom classes implicitly call the default
129 // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
130 // generated classes can use this optimisation, which avoids the unnecessary
131 // parameter conversions if there is no possibility of the virtual function
132 // being overridden:
133 if(obj_base && obj_base->is_derived_())
134 {
135 const auto obj = dynamic_cast<CppObjectType* const>(obj_base);
136 if(obj) // This can be NULL during destruction.
137 {
138 try // Trap C++ exceptions which would normally be lost because this is a C callback.
139 {
140 // Call the virtual member method, which derived classes might override.
141 int min_height = 0;
142 int nat_height = 0;
143 obj->get_preferred_height_for_width_vfunc(Glib::wrap(context, true),
144 *Glib::wrap(widget), width,
145 (minimum_height ? *minimum_height : min_height),
146 (natural_height ? *natural_height : nat_height));
147 return;
148 }
149 catch(...)
150 {
151 Glib::exception_handlers_invoke();
152 }
153 }
154 }
155
156 const auto base = static_cast<BaseClassType*>(
157 g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
158 );
159
160 // Call the original underlying C function:
161 if(base && base->get_preferred_height_for_width)
162 (*base->get_preferred_height_for_width)(self, context, widget, width, minimum_height, natural_height);
163 }
164
165 void CellArea_Class::get_preferred_height_vfunc_callback(GtkCellArea* self, GtkCellAreaContext* context, GtkWidget* widget, gint* minimum_height, gint* natural_height)
166 {
167 const auto obj_base = static_cast<Glib::ObjectBase*>(
168 Glib::ObjectBase::_get_current_wrapper((GObject*)self));
169
170 // Non-gtkmmproc-generated custom classes implicitly call the default
171 // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
172 // generated classes can use this optimisation, which avoids the unnecessary
173 // parameter conversions if there is no possibility of the virtual function
174 // being overridden:
175 if(obj_base && obj_base->is_derived_())
176 {
177 const auto obj = dynamic_cast<CppObjectType* const>(obj_base);
178 if(obj) // This can be NULL during destruction.
179 {
180 try // Trap C++ exceptions which would normally be lost because this is a C callback.
181 {
182 // Call the virtual member method, which derived classes might override.
183 int min_height = 0;
184 int nat_height = 0;
185 obj->get_preferred_height_vfunc(Glib::wrap(context, true),
186 *Glib::wrap(widget),
187 (minimum_height ? *minimum_height : min_height),
188 (natural_height ? *natural_height : nat_height));
189 return;
190 }
191 catch(...)
192 {
193 Glib::exception_handlers_invoke();
194 }
195 }
196 }
197
198 const auto base = static_cast<BaseClassType*>(
199 g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
200 );
201
202 // Call the original underlying C function:
203 if(base && base->get_preferred_height)
204 (*base->get_preferred_height)(self, context, widget, minimum_height, natural_height);
205 }
206
207 void CellArea_Class::get_preferred_width_for_height_vfunc_callback(GtkCellArea* self, GtkCellAreaContext* context, GtkWidget* widget, gint height, gint* minimum_width, gint* natural_width)
208 {
209 const auto obj_base = static_cast<Glib::ObjectBase*>(
210 Glib::ObjectBase::_get_current_wrapper((GObject*)self));
211
212 // Non-gtkmmproc-generated custom classes implicitly call the default
213 // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
214 // generated classes can use this optimisation, which avoids the unnecessary
215 // parameter conversions if there is no possibility of the virtual function
216 // being overridden:
217 if(obj_base && obj_base->is_derived_())
218 {
219 const auto obj = dynamic_cast<CppObjectType* const>(obj_base);
220 if(obj) // This can be NULL during destruction.
221 {
222 try // Trap C++ exceptions which would normally be lost because this is a C callback.
223 {
224 // Call the virtual member method, which derived classes might override.
225 int min_width = 0;
226 int nat_width = 0;
227 obj->get_preferred_width_for_height_vfunc(Glib::wrap(context, true),
228 *Glib::wrap(widget), height,
229 (minimum_width ? *minimum_width : min_width),
230 (natural_width ? *natural_width : nat_width));
231 return;
232 }
233 catch(...)
234 {
235 Glib::exception_handlers_invoke();
236 }
237 }
238 }
239
240 const auto base = static_cast<BaseClassType*>(
241 g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
242 );
243
244 // Call the original underlying C function:
245 if(base && base->get_preferred_width_for_height)
246 (*base->get_preferred_width_for_height)(self, context, widget, height, minimum_width, natural_width);
247 }
248
249 } //namespace Gtk