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
141/// Trait containing all [`struct@CellLayout`] methods.
142///
143/// # Implementors
144///
145/// [`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]
146pub trait CellLayoutExt: IsA<CellLayout> + 'static {
147    /// Adds an attribute mapping to the list in @self.
148    ///
149    /// The @column is the column of the model to get a value from, and the
150    /// @attribute is the property on @cell to be set from that value. So for
151    /// example if column 2 of the model contains strings, you could have the
152    /// “text” attribute of a [`CellRendererText`][crate::CellRendererText] get its values from column 2.
153    /// In this context "attribute" and "property" are used interchangeably.
154    ///
155    /// # Deprecated since 4.10
156    ///
157    /// ## `cell`
158    /// a [`CellRenderer`][crate::CellRenderer]
159    /// ## `attribute`
160    /// a property on the renderer
161    /// ## `column`
162    /// the column position on the model to get the attribute from
163    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
164    #[allow(deprecated)]
165    #[doc(alias = "gtk_cell_layout_add_attribute")]
166    fn add_attribute(&self, cell: &impl IsA<CellRenderer>, attribute: &str, column: i32) {
167        unsafe {
168            ffi::gtk_cell_layout_add_attribute(
169                self.as_ref().to_glib_none().0,
170                cell.as_ref().to_glib_none().0,
171                attribute.to_glib_none().0,
172                column,
173            );
174        }
175    }
176
177    /// Unsets all the mappings on all renderers on @self and
178    /// removes all renderers from @self.
179    ///
180    /// # Deprecated since 4.10
181    ///
182    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
183    #[allow(deprecated)]
184    #[doc(alias = "gtk_cell_layout_clear")]
185    fn clear(&self) {
186        unsafe {
187            ffi::gtk_cell_layout_clear(self.as_ref().to_glib_none().0);
188        }
189    }
190
191    /// Clears all existing attributes previously set with
192    /// gtk_cell_layout_set_attributes().
193    ///
194    /// # Deprecated since 4.10
195    ///
196    /// ## `cell`
197    /// a [`CellRenderer`][crate::CellRenderer] to clear the attribute mapping on
198    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
199    #[allow(deprecated)]
200    #[doc(alias = "gtk_cell_layout_clear_attributes")]
201    fn clear_attributes(&self, cell: &impl IsA<CellRenderer>) {
202        unsafe {
203            ffi::gtk_cell_layout_clear_attributes(
204                self.as_ref().to_glib_none().0,
205                cell.as_ref().to_glib_none().0,
206            );
207        }
208    }
209
210    /// Returns the underlying [`CellArea`][crate::CellArea] which might be @self
211    /// if called on a [`CellArea`][crate::CellArea] or might be [`None`] if no [`CellArea`][crate::CellArea]
212    /// is used by @self.
213    ///
214    /// # Deprecated since 4.10
215    ///
216    ///
217    /// # Returns
218    ///
219    /// the cell area used by @self
220    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
221    #[allow(deprecated)]
222    #[doc(alias = "gtk_cell_layout_get_area")]
223    #[doc(alias = "get_area")]
224    fn area(&self) -> Option<CellArea> {
225        unsafe {
226            from_glib_none(ffi::gtk_cell_layout_get_area(
227                self.as_ref().to_glib_none().0,
228            ))
229        }
230    }
231
232    /// Returns the cell renderers which have been added to @self.
233    ///
234    /// # Deprecated since 4.10
235    ///
236    ///
237    /// # Returns
238    ///
239    ///
240    ///   a list of cell renderers. The list, but not the renderers has
241    ///   been newly allocated and should be freed with g_list_free()
242    ///   when no longer needed.
243    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
244    #[allow(deprecated)]
245    #[doc(alias = "gtk_cell_layout_get_cells")]
246    #[doc(alias = "get_cells")]
247    fn cells(&self) -> Vec<CellRenderer> {
248        unsafe {
249            FromGlibPtrContainer::from_glib_container(ffi::gtk_cell_layout_get_cells(
250                self.as_ref().to_glib_none().0,
251            ))
252        }
253    }
254
255    /// Adds the @cell to the end of @self. If @expand is [`false`], then the
256    /// @cell is allocated no more space than it needs. Any unused space is
257    /// divided evenly between cells for which @expand is [`true`].
258    ///
259    /// Note that reusing the same cell renderer is not supported.
260    ///
261    /// # Deprecated since 4.10
262    ///
263    /// ## `cell`
264    /// a [`CellRenderer`][crate::CellRenderer]
265    /// ## `expand`
266    /// [`true`] if @cell is to be given extra space allocated to @self
267    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
268    #[allow(deprecated)]
269    #[doc(alias = "gtk_cell_layout_pack_end")]
270    fn pack_end(&self, cell: &impl IsA<CellRenderer>, expand: bool) {
271        unsafe {
272            ffi::gtk_cell_layout_pack_end(
273                self.as_ref().to_glib_none().0,
274                cell.as_ref().to_glib_none().0,
275                expand.into_glib(),
276            );
277        }
278    }
279
280    /// Packs the @cell into the beginning of @self. If @expand is [`false`],
281    /// then the @cell is allocated no more space than it needs. Any unused space
282    /// is divided evenly between cells for which @expand is [`true`].
283    ///
284    /// Note that reusing the same cell renderer is not supported.
285    ///
286    /// # Deprecated since 4.10
287    ///
288    /// ## `cell`
289    /// a [`CellRenderer`][crate::CellRenderer]
290    /// ## `expand`
291    /// [`true`] if @cell is to be given extra space allocated to @self
292    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
293    #[allow(deprecated)]
294    #[doc(alias = "gtk_cell_layout_pack_start")]
295    fn pack_start(&self, cell: &impl IsA<CellRenderer>, expand: bool) {
296        unsafe {
297            ffi::gtk_cell_layout_pack_start(
298                self.as_ref().to_glib_none().0,
299                cell.as_ref().to_glib_none().0,
300                expand.into_glib(),
301            );
302        }
303    }
304
305    /// Re-inserts @cell at @position.
306    ///
307    /// Note that @cell has already to be packed into @self
308    /// for this to function properly.
309    ///
310    /// # Deprecated since 4.10
311    ///
312    /// ## `cell`
313    /// a [`CellRenderer`][crate::CellRenderer] to reorder
314    /// ## `position`
315    /// new position to insert @cell at
316    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
317    #[allow(deprecated)]
318    #[doc(alias = "gtk_cell_layout_reorder")]
319    fn reorder(&self, cell: &impl IsA<CellRenderer>, position: i32) {
320        unsafe {
321            ffi::gtk_cell_layout_reorder(
322                self.as_ref().to_glib_none().0,
323                cell.as_ref().to_glib_none().0,
324                position,
325            );
326        }
327    }
328
329    /// Sets the [`CellLayout`][crate::CellLayout]DataFunc to use for @self.
330    ///
331    /// This function is used instead of the standard attributes mapping
332    /// for setting the column value, and should set the value of @self’s
333    /// cell renderer(s) as appropriate.
334    ///
335    /// @func may be [`None`] to remove a previously set function.
336    ///
337    /// # Deprecated since 4.10
338    ///
339    /// ## `cell`
340    /// a [`CellRenderer`][crate::CellRenderer]
341    /// ## `func`
342    /// the [`CellLayout`][crate::CellLayout]DataFunc to use
343    /// ## `func_data`
344    /// user data for @func
345    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
346    #[allow(deprecated)]
347    #[doc(alias = "gtk_cell_layout_set_cell_data_func")]
348    fn set_cell_data_func<P: Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>(
349        &self,
350        cell: &impl IsA<CellRenderer>,
351        func: P,
352    ) {
353        let func_data: Box_<P> = Box_::new(func);
354        unsafe extern "C" fn func_func<
355            P: Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static,
356        >(
357            cell_layout: *mut ffi::GtkCellLayout,
358            cell: *mut ffi::GtkCellRenderer,
359            tree_model: *mut ffi::GtkTreeModel,
360            iter: *mut ffi::GtkTreeIter,
361            data: glib::ffi::gpointer,
362        ) {
363            let cell_layout = from_glib_borrow(cell_layout);
364            let cell = from_glib_borrow(cell);
365            let tree_model = from_glib_borrow(tree_model);
366            let iter = from_glib_borrow(iter);
367            let callback = &*(data as *mut P);
368            (*callback)(&cell_layout, &cell, &tree_model, &iter)
369        }
370        let func = Some(func_func::<P> as _);
371        unsafe extern "C" fn destroy_func<
372            P: Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static,
373        >(
374            data: glib::ffi::gpointer,
375        ) {
376            let _callback = Box_::from_raw(data as *mut P);
377        }
378        let destroy_call4 = Some(destroy_func::<P> as _);
379        let super_callback0: Box_<P> = func_data;
380        unsafe {
381            ffi::gtk_cell_layout_set_cell_data_func(
382                self.as_ref().to_glib_none().0,
383                cell.as_ref().to_glib_none().0,
384                func,
385                Box_::into_raw(super_callback0) as *mut _,
386                destroy_call4,
387            );
388        }
389    }
390}
391
392impl<O: IsA<CellLayout>> CellLayoutExt for O {}