Debian Codegraph @

gtk/src/cellarea.hg

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 <gtkmm/buildable.h>
18 #include <gtkmm/cellareacontext.h>
19 #include <gtkmm/celllayout.h>
20 #include <glibmm/object.h>
21 _DEFS(gtkmm,gtk)
22 _PINCLUDE(gtkmm/private/object_p.h)
23
24
25 namespace Gtk
26 {
27
28 //TODO: This documentation omits the examples from the C documentation. We should translate them to C++.
29 /** An abstract base class for laying out CellRenderers.
30 *
31 * This is an abstract base class for CellLayout widgets
32 * (also referred to as "layouting widgets") to interface with an
33 * arbitrary number of CellRenderers and interact with the user
34 * for a given TreeModel row.
35 *
36 * The cell area handles events, focus navigation, drawing and
37 * size requests and allocations for a given row of data.
38 *
39 * Usually users dont have to interact with the CellArea directly
40 * unless they are implementing a cell layouting widget themselves.
41 *
42 * <h2>Requesting area sizes</h2>
43 *
44 * As outlined in Gtk::Widget's
45 * geometry management description, GTK+ uses a height-for-width
46 * geometry management system to compute the sizes of widgets and user
47 * interfaces. CellArea uses the same semantics to calculate the
48 * size of an area for an arbitrary number of TreeModel rows.
49 *
50 * When requesting the size of a cell area one needs to calculate
51 * the size for a handful of rows, and this will be done differently by
52 * different layouting widgets. For instance a TreeViewColumn
53 * always lines up the areas from top to bottom while an IconView,
54 * on the other hand, might enforce that all areas received the same
55 * width and wrap the areas around, requesting height for more cell
56 * areas when allocated less width.
57 *
58 * It's also important for areas to maintain some cell
59 * alignments with areas rendered for adjacent rows (cells can
60 * appear "columnized" inside an area even when the size of
61 * cells are different in each row). For this reason the CellArea
62 * uses a CellAreaContext object to store the alignments
63 * and sizes along the way (as well as the overall largest minimum
64 * and natural size for all the rows which have been calculated
65 * with the said context).
66 *
67 * The CellAreaContext is an opaque object specific to the
68 * CellArea which created it (see CellArea::create_context()).
69 * The owning cell-layouting widget can create as many contexts as
70 * it wishes to calculate sizes of rows which should receive the
71 * same size in at least one orientation (horizontally or vertically).
72 * However, it's important that the same CellAreaContext which
73 * was used to request the sizes for a given TreeModel row be
74 * used when rendering or processing events for that row.
75 *
76 * <h2>Cell Properties</h2>
77 *
78 * The CellArea introduces cell properties
79 * for CellRenderers in very much the same way that Gtk::Container
80 * introduces child properties
81 * for Widgets. This provides some general interfaces for defining
82 * the relationship cell areas have with their cells. For instance in a
83 * CellAreaBox a cell might "expand" and receive extra space when
84 * the area is allocated more than its full natural request, or a cell
85 * might be configured to "align" with adjacent rows which were requested
86 * and rendered with the same CellAreaContext.
87 *
88 * To set the value of a cell property, use cell_set_property(). To obtain
89 * the value of a cell property, use cell_get_property().
90 *
91 * @newin{3,0}
92 */
93 class GTKMM_API CellArea
94 : public Glib::Object,
95 public Buildable,
96 public CellLayout
97 {
98 _CLASS_GOBJECT(CellArea, GtkCellArea, GTK_CELL_AREA, Glib::Object, GObject, , , GTKMM_API)
99 _DERIVES_INITIALLY_UNOWNED()
100 _IMPLEMENTS_INTERFACE(Buildable)
101 _IMPLEMENTS_INTERFACE(CellLayout)
102
103 protected:
104 _CTOR_DEFAULT
105 public:
106
107 _WRAP_METHOD(void add(CellRenderer& renderer), gtk_cell_area_add)
108 _WRAP_METHOD(void remove(CellRenderer& renderer), gtk_cell_area_remove)
109 _WRAP_METHOD(bool has_renderer(CellRenderer& renderer), gtk_cell_area_has_renderer)
110
111 /** For instance,
112 * bool on_foreach(Gtk::CellRenderer* renderer);
113 *
114 * @param renderer the cell renderer to operate on
115 * @returns true to stop iterating over cells.
116 *
117 * @newin{3,4}
118 */
119 typedef sigc::slot<bool, CellRenderer*> SlotForeach;
120
121 /** Calls the @a slot for every CellRenderer in the CellArea.
122 *
123 * @param slot The slot to call for every CellRenderer.
124 *
125 * @newin{3,4}
126 */
127 void foreach(const SlotForeach& slot);
128 _IGNORE(gtk_cell_area_foreach)
129
130
131 /** For instance,
132 * bool on_foreach(Gtk::CellRenderer* renderer, const Gdk::Rectangle& cell_area, const Gdk::Rectangle& background_area);
133 *
134 * @param renderer the cell renderer to operate on
135 * @param cell_area the area allocated to the @a renderer inside the rectangle provided to foreach().
136 * @param background_area The background area for the @a renderer inside the background area provided to foreach().
137 * @returns true to stop iterating over cells.
138 *
139 * @newin{3,4}
140 */
141 typedef sigc::slot<bool, CellRenderer*, const Gdk::Rectangle&, const Gdk::Rectangle&> SlotForeachAlloc;
142
143 /** Calls the @a slot for every CellRenderer in the CellArea
144 * with the allocated rectangle inside the @a cell_area rectangle.
145 *
146 * @param context The CellAreaContext for this row of data.
147 * @param widget The widget that the CellArea is rendering to.
148 * @param cell_area The widget-relative coordinates and size for the CellArea.
149 * @param background_area The widget-relative coordinates of the background area.
150 *
151 * @param slot The slot to call for every CellRenderer.
152 *
153 * @newin{3,4}
154 */
155 void foreach(const Glib::RefPtr<CellAreaContext>& context, Widget* widget, const Gdk::Rectangle& cell_area, const Gdk::Rectangle& background_area, const SlotForeachAlloc& slot);
156 _IGNORE(gtk_cell_area_foreach_alloc)
157
158 _WRAP_METHOD(int event(const Glib::RefPtr<CellAreaContext>& context, Widget& widget, GdkEvent* gdk_event, const Gdk::Rectangle& cell_area, GtkCellRendererState flags), gtk_cell_area_event)
159 _WRAP_METHOD(void render(const Glib::RefPtr<CellAreaContext>& context, Widget& widget, const ::Cairo::RefPtr< ::Cairo::Context>& cr, const Gdk::Rectangle& background_area, const Gdk::Rectangle& cell_area, CellRendererState flags, bool paint_focus), gtk_cell_area_render)
160
161 _WRAP_METHOD(void get_cell_allocation(const Glib::RefPtr<CellAreaContext>& context, Widget& widget, CellRenderer& renderer, const Gdk::Rectangle& cell_area, Gdk::Rectangle& allocation), gtk_cell_area_get_cell_allocation)
162
163 _WRAP_METHOD(CellRenderer* get_cell_at_position(const Glib::RefPtr<CellAreaContext>& context, Widget& widget, const Gdk::Rectangle& cell_area, int x, int y, Gdk::Rectangle& alloc_area), gtk_cell_area_get_cell_at_position)
164 _WRAP_METHOD(const CellRenderer* get_cell_at_position(const Glib::RefPtr<CellAreaContext>& context, Widget& widget, const Gdk::Rectangle& cell_area, int x, int y, Gdk::Rectangle& alloc_area) const, gtk_cell_area_get_cell_at_position, constversion)
165
166 _WRAP_METHOD(Glib::RefPtr<CellAreaContext> create_context() const, gtk_cell_area_create_context)
167
168 _WRAP_METHOD(Glib::RefPtr<CellAreaContext> copy_context(const Glib::RefPtr<const CellAreaContext>& context), gtk_cell_area_copy_context)
169
170 _WRAP_METHOD(SizeRequestMode get_request_mode() const, gtk_cell_area_get_request_mode)
171 _WRAP_METHOD(void get_preferred_width(const Glib::RefPtr<CellAreaContext>& context, Widget& widget, int& minimum_width, int& natural_width), gtk_cell_area_get_preferred_width)
172 _WRAP_METHOD(void get_preferred_height_for_width (const Glib::RefPtr<CellAreaContext>& context, Widget& widget, int width, int& minimum_height, int& natural_height), gtk_cell_area_get_preferred_height_for_width)
173 _WRAP_METHOD(void get_preferred_height( const Glib::RefPtr<CellAreaContext>& context, Widget& widget, int& minimum_height, int& natural_height), gtk_cell_area_get_preferred_height)
174 _WRAP_METHOD(void get_preferred_width_for_height(const Glib::RefPtr<CellAreaContext>& context, Widget& widget, int height, int& minimum_width, int& natural_width), gtk_cell_area_get_preferred_width_for_height)
175 _WRAP_METHOD(Glib::ustring get_current_path_string () const, gtk_cell_area_get_current_path_string)
176
177
178 _WRAP_METHOD(void apply_attributes(const Glib::RefPtr<TreeModel>& tree_model, const TreeModel::iterator& iter, bool is_expander, bool is_expanded), gtk_cell_area_apply_attributes)
179 _WRAP_METHOD(void attribute_connect(CellRenderer& renderer, const Glib::ustring& attribute, int column), gtk_cell_area_attribute_connect)
180 _WRAP_METHOD(void attribute_disconnect(CellRenderer& renderer, const Glib::ustring& attribute), gtk_cell_area_attribute_disconnect)
181
182 _WRAP_METHOD(int attribute_get_column(CellRenderer& renderer,const Glib::ustring& attribute) const, gtk_cell_area_attribute_get_column)
183
184 //Ignore the C convenience functions.
185 _IGNORE(gtk_cell_area_cell_set, gtk_cell_area_cell_get, gtk_cell_area_cell_set_valist, gtk_cell_area_cell_get_valist)
186
187 _WRAP_METHOD(void cell_set_property(CellRenderer& renderer, const Glib::ustring& property_name, const Glib::ValueBase& value), gtk_cell_area_cell_set_property)
188 _WRAP_METHOD(void cell_get_property(CellRenderer& renderer, const Glib::ustring& property_name, Glib::ValueBase& value), gtk_cell_area_cell_get_property)
189
190 _WRAP_METHOD(bool is_activatable() const, gtk_cell_area_is_activatable)
191 _WRAP_METHOD(bool activate(const Glib::RefPtr<CellAreaContext>& context, Widget& widget, const Gdk::Rectangle& cell_area, CellRendererState flags, bool edit_only), gtk_cell_area_activate)
192 _WRAP_METHOD(bool focus(DirectionType direction), gtk_cell_area_focus)
193 _WRAP_METHOD(void set_focus_cell(CellRenderer& renderer), gtk_cell_area_set_focus_cell)
194
195 _WRAP_METHOD(CellRenderer* get_focus_cell(), gtk_cell_area_get_focus_cell)
196 _WRAP_METHOD(const CellRenderer* get_focus_cell() const, gtk_cell_area_get_focus_cell, constversion)
197
198 _WRAP_METHOD(void add_focus_sibling(CellRenderer& renderer, CellRenderer& sibling), gtk_cell_area_add_focus_sibling)
199 _WRAP_METHOD(void remove_focus_sibling( CellRenderer& renderer, CellRenderer& sibling), gtk_cell_area_remove_focus_sibling)
200 _WRAP_METHOD(bool is_focus_sibling(CellRenderer& renderer, CellRenderer& sibling), gtk_cell_area_is_focus_sibling)
201
202
203 #m4 _CONVERSION(`const GList*',`std::vector<CellRenderer*>',`Glib::ListHandler<CellRenderer*>::list_to_vector(const_cast<GList*>($3), Glib::OWNERSHIP_NONE)')
204 _WRAP_METHOD(std::vector<CellRenderer*> get_focus_siblings(CellRenderer& renderer), gtk_cell_area_get_focus_siblings)
205
206 #m4 _CONVERSION(`const GList*',`std::vector<const CellRenderer*>',`Glib::ListHandler<const CellRenderer*>::list_to_vector(const_cast<GList*>($3), Glib::OWNERSHIP_NONE)')
207 _WRAP_METHOD(std::vector<const CellRenderer*> get_focus_siblings(const CellRenderer& renderer) const, gtk_cell_area_get_focus_siblings)
208
209 _WRAP_METHOD(CellRenderer* get_focus_from_sibling(CellRenderer& renderer), gtk_cell_area_get_focus_from_sibling)
210 _WRAP_METHOD(const CellRenderer* get_focus_from_sibling(CellRenderer& renderer) const, gtk_cell_area_get_focus_from_sibling, constversion)
211
212 _WRAP_METHOD(CellRenderer* get_edited_cell(), gtk_cell_area_get_edited_cell)
213 _WRAP_METHOD(const CellRenderer* get_edited_cell() const, gtk_cell_area_get_edited_cell, constversion)
214
215 _WRAP_METHOD(CellEditable* get_edit_widget(), gtk_cell_area_get_edit_widget)
216 _WRAP_METHOD(const CellEditable* get_edit_widget() const, gtk_cell_area_get_edit_widget, constversion)
217
218 _WRAP_METHOD(bool activate_cell(Widget& widget, CellRenderer& renderer, GdkEvent* gdk_event, const Gdk::Rectangle& cell_area, CellRendererState flags), gtk_cell_area_activate_cell)
219 _WRAP_METHOD(void stop_editing(bool canceled), gtk_cell_area_stop_editing)
220
221 _WRAP_METHOD(void inner_cell_area(Widget& widget, const Gdk::Rectangle& cell_area, Gdk::Rectangle& inner_area), gtk_cell_area_inner_cell_area)
222
223 _WRAP_METHOD(void request_renderer(CellRenderer& renderer, Orientation orientation, Widget& widget, int for_size, int& minimum_size, int& natural_size), gtk_cell_area_request_renderer)
224
225 protected:
226 #m4 _CONVERSION(`GtkCellAreaContext*',`const Glib::RefPtr<CellAreaContext>&',`Glib::wrap($3, true)')
227 #m4 _CONVERSION(`GtkTreeModel*',`const Glib::RefPtr<TreeModel>&',`Glib::wrap($3, true)')
228 #m4 _CONVERSION(`GtkTreeIter*',`const TreeModel::iterator&',`Gtk::TreeModel::iterator(p0, $3)')
229 //TODO: Remove no_default_handler when we can break ABI:
230 _WRAP_SIGNAL(void apply_attributes(const Glib::RefPtr<TreeModel>& tree_model, const TreeModel::iterator& iter, bool is_expander, bool is_expanded), "apply-attributes", no_default_handler)
231
232 // The add-editable, remove-editable and focus-changed signals can't have default handlers because the wrapped C signals have no default handlers.
233 #m4 _CONVERSION(`GdkRectangle*',`const Gdk::Rectangle&',`Glib::wrap($3)')
234 _WRAP_SIGNAL(void add_editable(CellRenderer* renderer, CellEditable* editable, const Gdk::Rectangle& cell_area, const Glib::ustring& path), "add-editable", no_default_handler)
235
236 _WRAP_SIGNAL(void remove_editable(CellRenderer* renderer, CellEditable* editable), "remove-editable", no_default_handler)
237 _WRAP_SIGNAL(void focus_changed(CellRenderer* renderer, const Glib::ustring& path), "focus-changed", no_default_handler)
238
239 //TODO: Wrap these vfuncs, mentioned in the GtkCellAreaContext overview documentation?
240 // GtkCellAreaContext *(* create_context) (GtkCellArea *area);
241 // GtkCellAreaContext *(* copy_context) (GtkCellArea *area,
242
243 _WRAP_VFUNC(SizeRequestMode get_request_mode() const, get_request_mode)
244 _WRAP_VFUNC(void get_preferred_width(const Glib::RefPtr<CellAreaContext>& context, Widget& widget, int& minimum_width, int& natural_width), get_preferred_width, custom_vfunc_callback)
245 _WRAP_VFUNC(void get_preferred_height_for_width(const Glib::RefPtr<CellAreaContext>& context, Widget& widget, int width, int& minimum_height, int& natural_height), get_preferred_height_for_width, custom_vfunc_callback)
246 _WRAP_VFUNC(void get_preferred_height(const Glib::RefPtr<CellAreaContext>& context, Widget& widget, int& minimum_height, int& natural_height), get_preferred_height, custom_vfunc_callback)
247 _WRAP_VFUNC(void get_preferred_width_for_height(const Glib::RefPtr<CellAreaContext>& context, Widget& widget, int height, int& minimum_width, int& natural_width), get_preferred_width_for_height, custom_vfunc_callback)
248
249 _WRAP_PROPERTY("focus-cell", CellRenderer*)
250 _WRAP_PROPERTY("edited-cell", CellRenderer*)
251 _WRAP_PROPERTY("edit-widget", CellEditable*)
252 };
253
254 } // namespace Gtk