Skip to main content

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::{CellArea, CellRenderer, TreeIter, TreeModel, ffi};
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    ///
14    /// ```text
15    ///
16    /// ## Subclassing GtkCellLayout implementations
17    ///
18    /// When subclassing a widget that implements `GtkCellLayout` like
19    /// `GtkIconView` or `GtkComboBox`, there are some considerations related
20    /// to the fact that these widgets internally use a `GtkCellArea`.
21    /// The cell area is exposed as a construct-only property by these
22    /// widgets. This means that it is possible to e.g. do
23    ///
24    /// ```c
25    /// GtkWIdget *combo =
26    ///   g_object_new (GTK_TYPE_COMBO_BOX, "cell-area", my_cell_area, NULL);
27    /// ```text
28    ///
29    /// to use a custom cell area with a combo box. But construct properties
30    /// are only initialized after instance `init()`
31    /// functions have run, which means that using functions which rely on
32    /// the existence of the cell area in your subclass `init()` function will
33    /// cause the default cell area to be instantiated. In this case, a provided
34    /// construct property value will be ignored (with a warning, to alert
35    /// you to the problem).
36    ///
37    /// ```c
38    /// static void
39    /// my_combo_box_init (MyComboBox *b)
40    /// {
41    ///   GtkCellRenderer *cell;
42    ///
43    ///   cell = gtk_cell_renderer_pixbuf_new ();
44    ///
45    ///   // The following call causes the default cell area for combo boxes,
46    ///   // a GtkCellAreaBox, to be instantiated
47    ///   gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (b), cell, FALSE);
48    ///   ...
49    /// }
50    ///
51    /// GtkWidget *
52    /// my_combo_box_new (GtkCellArea *area)
53    /// {
54    ///   // This call is going to cause a warning about area being ignored
55    ///   return g_object_new (MY_TYPE_COMBO_BOX, "cell-area", area, NULL);
56    /// }
57    /// ```text
58    ///
59    /// If supporting alternative cell areas with your derived widget is
60    /// not important, then this does not have to concern you. If you want
61    /// to support alternative cell areas, you can do so by moving the
62    /// problematic calls out of `init()` and into a `constructor()`
63    /// for your class.
64    ///
65    /// # Implements
66    ///
67    /// [`CellLayoutExt`][trait@crate::prelude::CellLayoutExt], [`CellLayoutExtManual`][trait@crate::prelude::CellLayoutExtManual]
68    #[doc(alias = "GtkCellLayout")]
69    pub struct CellLayout(Interface<ffi::GtkCellLayout, ffi::GtkCellLayoutIface>);
70
71    match fn {
72        type_ => || ffi::gtk_cell_layout_get_type(),
73    }
74}
75
76impl CellLayout {
77    pub const NONE: Option<&'static CellLayout> = None;
78}
79
80/// Trait containing all [`struct@CellLayout`] methods.
81///
82/// # Implementors
83///
84/// [`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]
85pub trait CellLayoutExt: IsA<CellLayout> + 'static {
86    /// Adds an attribute mapping to the list in @self.
87    ///
88    /// The @column is the column of the model to get a value from, and the
89    /// @attribute is the property on @cell to be set from that value. So for
90    /// example if column 2 of the model contains strings, you could have the
91    /// “text” attribute of a [`CellRendererText`][crate::CellRendererText] get its values from column 2.
92    /// In this context "attribute" and "property" are used interchangeably.
93    ///
94    /// # Deprecated since 4.10
95    ///
96    /// ## `cell`
97    /// a [`CellRenderer`][crate::CellRenderer]
98    /// ## `attribute`
99    /// a property on the renderer
100    /// ## `column`
101    /// the column position on the model to get the attribute from
102    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
103    #[allow(deprecated)]
104    #[doc(alias = "gtk_cell_layout_add_attribute")]
105    fn add_attribute(&self, cell: &impl IsA<CellRenderer>, attribute: &str, column: i32) {
106        unsafe {
107            ffi::gtk_cell_layout_add_attribute(
108                self.as_ref().to_glib_none().0,
109                cell.as_ref().to_glib_none().0,
110                attribute.to_glib_none().0,
111                column,
112            );
113        }
114    }
115
116    /// Unsets all the mappings on all renderers on @self and
117    /// removes all renderers from @self.
118    ///
119    /// # Deprecated since 4.10
120    ///
121    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
122    #[allow(deprecated)]
123    #[doc(alias = "gtk_cell_layout_clear")]
124    fn clear(&self) {
125        unsafe {
126            ffi::gtk_cell_layout_clear(self.as_ref().to_glib_none().0);
127        }
128    }
129
130    /// Clears all existing attributes previously set with
131    /// gtk_cell_layout_set_attributes().
132    ///
133    /// # Deprecated since 4.10
134    ///
135    /// ## `cell`
136    /// a [`CellRenderer`][crate::CellRenderer] to clear the attribute mapping on
137    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
138    #[allow(deprecated)]
139    #[doc(alias = "gtk_cell_layout_clear_attributes")]
140    fn clear_attributes(&self, cell: &impl IsA<CellRenderer>) {
141        unsafe {
142            ffi::gtk_cell_layout_clear_attributes(
143                self.as_ref().to_glib_none().0,
144                cell.as_ref().to_glib_none().0,
145            );
146        }
147    }
148
149    /// Returns the underlying [`CellArea`][crate::CellArea] which might be @self
150    /// if called on a [`CellArea`][crate::CellArea] or might be [`None`] if no [`CellArea`][crate::CellArea]
151    /// is used by @self.
152    ///
153    /// # Deprecated since 4.10
154    ///
155    ///
156    /// # Returns
157    ///
158    /// the cell area used by @self
159    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
160    #[allow(deprecated)]
161    #[doc(alias = "gtk_cell_layout_get_area")]
162    #[doc(alias = "get_area")]
163    fn area(&self) -> Option<CellArea> {
164        unsafe {
165            from_glib_none(ffi::gtk_cell_layout_get_area(
166                self.as_ref().to_glib_none().0,
167            ))
168        }
169    }
170
171    /// Returns the cell renderers which have been added to @self.
172    ///
173    /// # Deprecated since 4.10
174    ///
175    ///
176    /// # Returns
177    ///
178    ///
179    ///   a list of cell renderers. The list, but not the renderers has
180    ///   been newly allocated and should be freed with g_list_free()
181    ///   when no longer needed.
182    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
183    #[allow(deprecated)]
184    #[doc(alias = "gtk_cell_layout_get_cells")]
185    #[doc(alias = "get_cells")]
186    fn cells(&self) -> Vec<CellRenderer> {
187        unsafe {
188            FromGlibPtrContainer::from_glib_container(ffi::gtk_cell_layout_get_cells(
189                self.as_ref().to_glib_none().0,
190            ))
191        }
192    }
193
194    /// Adds the @cell to the end of @self. If @expand is [`false`], then the
195    /// @cell is allocated no more space than it needs. Any unused space is
196    /// divided evenly between cells for which @expand is [`true`].
197    ///
198    /// Note that reusing the same cell renderer is not supported.
199    ///
200    /// # Deprecated since 4.10
201    ///
202    /// ## `cell`
203    /// a [`CellRenderer`][crate::CellRenderer]
204    /// ## `expand`
205    /// [`true`] if @cell is to be given extra space allocated to @self
206    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
207    #[allow(deprecated)]
208    #[doc(alias = "gtk_cell_layout_pack_end")]
209    fn pack_end(&self, cell: &impl IsA<CellRenderer>, expand: bool) {
210        unsafe {
211            ffi::gtk_cell_layout_pack_end(
212                self.as_ref().to_glib_none().0,
213                cell.as_ref().to_glib_none().0,
214                expand.into_glib(),
215            );
216        }
217    }
218
219    /// Packs the @cell into the beginning of @self. If @expand is [`false`],
220    /// then the @cell is allocated no more space than it needs. Any unused space
221    /// is divided evenly between cells for which @expand is [`true`].
222    ///
223    /// Note that reusing the same cell renderer is not supported.
224    ///
225    /// # Deprecated since 4.10
226    ///
227    /// ## `cell`
228    /// a [`CellRenderer`][crate::CellRenderer]
229    /// ## `expand`
230    /// [`true`] if @cell is to be given extra space allocated to @self
231    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
232    #[allow(deprecated)]
233    #[doc(alias = "gtk_cell_layout_pack_start")]
234    fn pack_start(&self, cell: &impl IsA<CellRenderer>, expand: bool) {
235        unsafe {
236            ffi::gtk_cell_layout_pack_start(
237                self.as_ref().to_glib_none().0,
238                cell.as_ref().to_glib_none().0,
239                expand.into_glib(),
240            );
241        }
242    }
243
244    /// Re-inserts @cell at @position.
245    ///
246    /// Note that @cell has already to be packed into @self
247    /// for this to function properly.
248    ///
249    /// # Deprecated since 4.10
250    ///
251    /// ## `cell`
252    /// a [`CellRenderer`][crate::CellRenderer] to reorder
253    /// ## `position`
254    /// new position to insert @cell at
255    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
256    #[allow(deprecated)]
257    #[doc(alias = "gtk_cell_layout_reorder")]
258    fn reorder(&self, cell: &impl IsA<CellRenderer>, position: i32) {
259        unsafe {
260            ffi::gtk_cell_layout_reorder(
261                self.as_ref().to_glib_none().0,
262                cell.as_ref().to_glib_none().0,
263                position,
264            );
265        }
266    }
267
268    /// Sets the [`CellLayout`][crate::CellLayout]DataFunc to use for @self.
269    ///
270    /// This function is used instead of the standard attributes mapping
271    /// for setting the column value, and should set the value of @self’s
272    /// cell renderer(s) as appropriate.
273    ///
274    /// @func may be [`None`] to remove a previously set function.
275    ///
276    /// # Deprecated since 4.10
277    ///
278    /// ## `cell`
279    /// a [`CellRenderer`][crate::CellRenderer]
280    /// ## `func`
281    /// the [`CellLayout`][crate::CellLayout]DataFunc to use
282    /// ## `func_data`
283    /// user data for @func
284    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
285    #[allow(deprecated)]
286    #[doc(alias = "gtk_cell_layout_set_cell_data_func")]
287    fn set_cell_data_func<P: Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>(
288        &self,
289        cell: &impl IsA<CellRenderer>,
290        func: P,
291    ) {
292        let func_data: Box_<P> = Box_::new(func);
293        unsafe extern "C" fn func_func<
294            P: Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static,
295        >(
296            cell_layout: *mut ffi::GtkCellLayout,
297            cell: *mut ffi::GtkCellRenderer,
298            tree_model: *mut ffi::GtkTreeModel,
299            iter: *mut ffi::GtkTreeIter,
300            data: glib::ffi::gpointer,
301        ) {
302            unsafe {
303                let cell_layout = from_glib_borrow(cell_layout);
304                let cell = from_glib_borrow(cell);
305                let tree_model = from_glib_borrow(tree_model);
306                let iter = from_glib_borrow(iter);
307                let callback = &*(data as *mut P);
308                (*callback)(&cell_layout, &cell, &tree_model, &iter)
309            }
310        }
311        let func = Some(func_func::<P> as _);
312        unsafe extern "C" fn destroy_func<
313            P: Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static,
314        >(
315            data: glib::ffi::gpointer,
316        ) {
317            unsafe {
318                let _callback = Box_::from_raw(data as *mut P);
319            }
320        }
321        let destroy_call4 = Some(destroy_func::<P> as _);
322        let super_callback0: Box_<P> = func_data;
323        unsafe {
324            ffi::gtk_cell_layout_set_cell_data_func(
325                self.as_ref().to_glib_none().0,
326                cell.as_ref().to_glib_none().0,
327                func,
328                Box_::into_raw(super_callback0) as *mut _,
329                destroy_call4,
330            );
331        }
332    }
333}
334
335impl<O: IsA<CellLayout>> CellLayoutExt for O {}