gtk4/auto/cell_layout.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4#![allow(deprecated)]
5
6use crate::{ffi, CellArea, CellRenderer, TreeIter, TreeModel};
7use glib::{prelude::*, translate::*};
8use std::boxed::Box as Box_;
9
10glib::wrapper! {
11 /// List views use widgets to display their contents.
12 /// See [`LayoutManager`][crate::LayoutManager] for layout manager delegate objects
13 /// An interface for packing cells
14 ///
15 /// [`CellLayout`][crate::CellLayout] is an interface to be implemented by all objects which
16 /// want to provide a [`TreeViewColumn`][crate::TreeViewColumn] like API for packing cells,
17 /// setting attributes and data funcs.
18 ///
19 /// One of the notable features provided by implementations of
20 /// [`CellLayout`][crate::CellLayout] are attributes. Attributes let you set the properties
21 /// in flexible ways. They can just be set to constant values like regular
22 /// properties. But they can also be mapped to a column of the underlying
23 /// tree model with gtk_cell_layout_set_attributes(), which means that the value
24 /// of the attribute can change from cell to cell as they are rendered by
25 /// the cell renderer. Finally, it is possible to specify a function with
26 /// gtk_cell_layout_set_cell_data_func() that is called to determine the
27 /// value of the attribute for each cell that is rendered.
28 ///
29 /// ## GtkCellLayouts as GtkBuildable
30 ///
31 /// Implementations of GtkCellLayout which also implement the GtkBuildable
32 /// interface ([`CellView`][crate::CellView], [`IconView`][crate::IconView], [`ComboBox`][crate::ComboBox],
33 /// [`EntryCompletion`][crate::EntryCompletion], [`TreeViewColumn`][crate::TreeViewColumn]) accept [`CellRenderer`][crate::CellRenderer] objects
34 /// as `<child>` elements in UI definitions. They support a custom `<attributes>`
35 /// element for their children, which can contain multiple `<attribute>`
36 /// elements. Each `<attribute>` element has a name attribute which specifies
37 /// a property of the cell renderer; the content of the element is the
38 /// attribute value.
39 ///
40 /// This is an example of a UI definition fragment specifying attributes:
41 ///
42 /// ```xml
43 /// <object class="GtkCellView">
44 /// <child>
45 /// <object class="GtkCellRendererText"/>
46 /// <attributes>
47 /// <attribute name="text">0</attribute>
48 /// </attributes>
49 /// </child>
50 /// </object>
51 /// ```
52 ///
53 /// Furthermore for implementations of [`CellLayout`][crate::CellLayout] that use a [`CellArea`][crate::CellArea]
54 /// to lay out cells (all [`CellLayout`][crate::CellLayout]s in GTK use a [`CellArea`][crate::CellArea])
55 /// [cell properties](class.CellArea.html#cell-properties) can also be defined
56 /// in the format by specifying the custom `<cell-packing>` attribute which can
57 /// contain multiple `<property>` elements.
58 ///
59 /// Here is a UI definition fragment specifying cell properties:
60 ///
61 /// ```xml
62 /// <object class="GtkTreeViewColumn">
63 /// <child>
64 /// <object class="GtkCellRendererText"/>
65 /// <cell-packing>
66 /// <property name="align">True</property>
67 /// <property name="expand">False</property>
68 /// </cell-packing>
69 /// </child>
70 /// </object>
71 /// ```
72 ///
73 /// ## Subclassing GtkCellLayout implementations
74 ///
75 /// When subclassing a widget that implements [`CellLayout`][crate::CellLayout] like
76 /// [`IconView`][crate::IconView] or [`ComboBox`][crate::ComboBox], there are some considerations related
77 /// to the fact that these widgets internally use a [`CellArea`][crate::CellArea].
78 /// The cell area is exposed as a construct-only property by these
79 /// widgets. This means that it is possible to e.g. do
80 ///
81 /// **⚠️ The following code is in c ⚠️**
82 ///
83 /// ```c
84 /// GtkWIdget *combo =
85 /// g_object_new (GTK_TYPE_COMBO_BOX, "cell-area", my_cell_area, NULL);
86 /// ```
87 ///
88 /// to use a custom cell area with a combo box. But construct properties
89 /// are only initialized after instance `init()`
90 /// functions have run, which means that using functions which rely on
91 /// the existence of the cell area in your subclass `init()` function will
92 /// cause the default cell area to be instantiated. In this case, a provided
93 /// construct property value will be ignored (with a warning, to alert
94 /// you to the problem).
95 ///
96 /// **⚠️ The following code is in c ⚠️**
97 ///
98 /// ```c
99 /// static void
100 /// my_combo_box_init (MyComboBox *b)
101 /// {
102 /// GtkCellRenderer *cell;
103 ///
104 /// cell = gtk_cell_renderer_pixbuf_new ();
105 ///
106 /// // The following call causes the default cell area for combo boxes,
107 /// // a GtkCellAreaBox, to be instantiated
108 /// gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (b), cell, FALSE);
109 /// ...
110 /// }
111 ///
112 /// GtkWidget *
113 /// my_combo_box_new (GtkCellArea *area)
114 /// {
115 /// // This call is going to cause a warning about area being ignored
116 /// return g_object_new (MY_TYPE_COMBO_BOX, "cell-area", area, NULL);
117 /// }
118 /// ```
119 ///
120 /// If supporting alternative cell areas with your derived widget is
121 /// not important, then this does not have to concern you. If you want
122 /// to support alternative cell areas, you can do so by moving the
123 /// problematic calls out of `init()` and into a `constructor()`
124 /// for your class.
125 ///
126 /// # Implements
127 ///
128 /// [`CellLayoutExt`][trait@crate::prelude::CellLayoutExt], [`CellLayoutExtManual`][trait@crate::prelude::CellLayoutExtManual]
129 #[doc(alias = "GtkCellLayout")]
130 pub struct CellLayout(Interface<ffi::GtkCellLayout, ffi::GtkCellLayoutIface>);
131
132 match fn {
133 type_ => || ffi::gtk_cell_layout_get_type(),
134 }
135}
136
137impl CellLayout {
138 pub const NONE: Option<&'static CellLayout> = None;
139}
140
141mod sealed {
142 pub trait Sealed {}
143 impl<T: super::IsA<super::CellLayout>> Sealed for T {}
144}
145
146/// Trait containing all [`struct@CellLayout`] methods.
147///
148/// # Implementors
149///
150/// [`CellAreaBox`][struct@crate::CellAreaBox], [`CellArea`][struct@crate::CellArea], [`CellLayout`][struct@crate::CellLayout], [`CellView`][struct@crate::CellView], [`ComboBoxText`][struct@crate::ComboBoxText], [`ComboBox`][struct@crate::ComboBox], [`EntryCompletion`][struct@crate::EntryCompletion], [`IconView`][struct@crate::IconView], [`TreeViewColumn`][struct@crate::TreeViewColumn]
151pub trait CellLayoutExt: IsA<CellLayout> + sealed::Sealed + 'static {
152 /// Adds an attribute mapping to the list in @self.
153 ///
154 /// The @column is the column of the model to get a value from, and the
155 /// @attribute is the property on @cell to be set from that value. So for
156 /// example if column 2 of the model contains strings, you could have the
157 /// “text” attribute of a [`CellRendererText`][crate::CellRendererText] get its values from column 2.
158 /// In this context "attribute" and "property" are used interchangeably.
159 ///
160 /// # Deprecated since 4.10
161 ///
162 /// ## `cell`
163 /// a [`CellRenderer`][crate::CellRenderer]
164 /// ## `attribute`
165 /// a property on the renderer
166 /// ## `column`
167 /// the column position on the model to get the attribute from
168 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
169 #[allow(deprecated)]
170 #[doc(alias = "gtk_cell_layout_add_attribute")]
171 fn add_attribute(&self, cell: &impl IsA<CellRenderer>, attribute: &str, column: i32) {
172 unsafe {
173 ffi::gtk_cell_layout_add_attribute(
174 self.as_ref().to_glib_none().0,
175 cell.as_ref().to_glib_none().0,
176 attribute.to_glib_none().0,
177 column,
178 );
179 }
180 }
181
182 /// Unsets all the mappings on all renderers on @self and
183 /// removes all renderers from @self.
184 ///
185 /// # Deprecated since 4.10
186 ///
187 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
188 #[allow(deprecated)]
189 #[doc(alias = "gtk_cell_layout_clear")]
190 fn clear(&self) {
191 unsafe {
192 ffi::gtk_cell_layout_clear(self.as_ref().to_glib_none().0);
193 }
194 }
195
196 /// Clears all existing attributes previously set with
197 /// gtk_cell_layout_set_attributes().
198 ///
199 /// # Deprecated since 4.10
200 ///
201 /// ## `cell`
202 /// a [`CellRenderer`][crate::CellRenderer] to clear the attribute mapping on
203 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
204 #[allow(deprecated)]
205 #[doc(alias = "gtk_cell_layout_clear_attributes")]
206 fn clear_attributes(&self, cell: &impl IsA<CellRenderer>) {
207 unsafe {
208 ffi::gtk_cell_layout_clear_attributes(
209 self.as_ref().to_glib_none().0,
210 cell.as_ref().to_glib_none().0,
211 );
212 }
213 }
214
215 /// Returns the underlying [`CellArea`][crate::CellArea] which might be @self
216 /// if called on a [`CellArea`][crate::CellArea] or might be [`None`] if no [`CellArea`][crate::CellArea]
217 /// is used by @self.
218 ///
219 /// # Deprecated since 4.10
220 ///
221 ///
222 /// # Returns
223 ///
224 /// the cell area used by @self
225 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
226 #[allow(deprecated)]
227 #[doc(alias = "gtk_cell_layout_get_area")]
228 #[doc(alias = "get_area")]
229 fn area(&self) -> Option<CellArea> {
230 unsafe {
231 from_glib_none(ffi::gtk_cell_layout_get_area(
232 self.as_ref().to_glib_none().0,
233 ))
234 }
235 }
236
237 /// Returns the cell renderers which have been added to @self.
238 ///
239 /// # Deprecated since 4.10
240 ///
241 ///
242 /// # Returns
243 ///
244 ///
245 /// a list of cell renderers. The list, but not the renderers has
246 /// been newly allocated and should be freed with g_list_free()
247 /// when no longer needed.
248 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
249 #[allow(deprecated)]
250 #[doc(alias = "gtk_cell_layout_get_cells")]
251 #[doc(alias = "get_cells")]
252 fn cells(&self) -> Vec<CellRenderer> {
253 unsafe {
254 FromGlibPtrContainer::from_glib_container(ffi::gtk_cell_layout_get_cells(
255 self.as_ref().to_glib_none().0,
256 ))
257 }
258 }
259
260 /// Adds the @cell to the end of @self. If @expand is [`false`], then the
261 /// @cell is allocated no more space than it needs. Any unused space is
262 /// divided evenly between cells for which @expand is [`true`].
263 ///
264 /// Note that reusing the same cell renderer is not supported.
265 ///
266 /// # Deprecated since 4.10
267 ///
268 /// ## `cell`
269 /// a [`CellRenderer`][crate::CellRenderer]
270 /// ## `expand`
271 /// [`true`] if @cell is to be given extra space allocated to @self
272 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
273 #[allow(deprecated)]
274 #[doc(alias = "gtk_cell_layout_pack_end")]
275 fn pack_end(&self, cell: &impl IsA<CellRenderer>, expand: bool) {
276 unsafe {
277 ffi::gtk_cell_layout_pack_end(
278 self.as_ref().to_glib_none().0,
279 cell.as_ref().to_glib_none().0,
280 expand.into_glib(),
281 );
282 }
283 }
284
285 /// Packs the @cell into the beginning of @self. If @expand is [`false`],
286 /// then the @cell is allocated no more space than it needs. Any unused space
287 /// is divided evenly between cells for which @expand is [`true`].
288 ///
289 /// Note that reusing the same cell renderer is not supported.
290 ///
291 /// # Deprecated since 4.10
292 ///
293 /// ## `cell`
294 /// a [`CellRenderer`][crate::CellRenderer]
295 /// ## `expand`
296 /// [`true`] if @cell is to be given extra space allocated to @self
297 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
298 #[allow(deprecated)]
299 #[doc(alias = "gtk_cell_layout_pack_start")]
300 fn pack_start(&self, cell: &impl IsA<CellRenderer>, expand: bool) {
301 unsafe {
302 ffi::gtk_cell_layout_pack_start(
303 self.as_ref().to_glib_none().0,
304 cell.as_ref().to_glib_none().0,
305 expand.into_glib(),
306 );
307 }
308 }
309
310 /// Re-inserts @cell at @position.
311 ///
312 /// Note that @cell has already to be packed into @self
313 /// for this to function properly.
314 ///
315 /// # Deprecated since 4.10
316 ///
317 /// ## `cell`
318 /// a [`CellRenderer`][crate::CellRenderer] to reorder
319 /// ## `position`
320 /// new position to insert @cell at
321 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
322 #[allow(deprecated)]
323 #[doc(alias = "gtk_cell_layout_reorder")]
324 fn reorder(&self, cell: &impl IsA<CellRenderer>, position: i32) {
325 unsafe {
326 ffi::gtk_cell_layout_reorder(
327 self.as_ref().to_glib_none().0,
328 cell.as_ref().to_glib_none().0,
329 position,
330 );
331 }
332 }
333
334 /// Sets the [`CellLayout`][crate::CellLayout]DataFunc to use for @self.
335 ///
336 /// This function is used instead of the standard attributes mapping
337 /// for setting the column value, and should set the value of @self’s
338 /// cell renderer(s) as appropriate.
339 ///
340 /// @func may be [`None`] to remove a previously set function.
341 ///
342 /// # Deprecated since 4.10
343 ///
344 /// ## `cell`
345 /// a [`CellRenderer`][crate::CellRenderer]
346 /// ## `func`
347 /// the [`CellLayout`][crate::CellLayout]DataFunc to use
348 /// ## `func_data`
349 /// user data for @func
350 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
351 #[allow(deprecated)]
352 #[doc(alias = "gtk_cell_layout_set_cell_data_func")]
353 fn set_cell_data_func<P: Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>(
354 &self,
355 cell: &impl IsA<CellRenderer>,
356 func: P,
357 ) {
358 let func_data: Box_<P> = Box_::new(func);
359 unsafe extern "C" fn func_func<
360 P: Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static,
361 >(
362 cell_layout: *mut ffi::GtkCellLayout,
363 cell: *mut ffi::GtkCellRenderer,
364 tree_model: *mut ffi::GtkTreeModel,
365 iter: *mut ffi::GtkTreeIter,
366 data: glib::ffi::gpointer,
367 ) {
368 let cell_layout = from_glib_borrow(cell_layout);
369 let cell = from_glib_borrow(cell);
370 let tree_model = from_glib_borrow(tree_model);
371 let iter = from_glib_borrow(iter);
372 let callback = &*(data as *mut P);
373 (*callback)(&cell_layout, &cell, &tree_model, &iter)
374 }
375 let func = Some(func_func::<P> as _);
376 unsafe extern "C" fn destroy_func<
377 P: Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static,
378 >(
379 data: glib::ffi::gpointer,
380 ) {
381 let _callback = Box_::from_raw(data as *mut P);
382 }
383 let destroy_call4 = Some(destroy_func::<P> as _);
384 let super_callback0: Box_<P> = func_data;
385 unsafe {
386 ffi::gtk_cell_layout_set_cell_data_func(
387 self.as_ref().to_glib_none().0,
388 cell.as_ref().to_glib_none().0,
389 func,
390 Box_::into_raw(super_callback0) as *mut _,
391 destroy_call4,
392 );
393 }
394 }
395}
396
397impl<O: IsA<CellLayout>> CellLayoutExt for O {}