Skip to main content

gtk/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
5use crate::{CellArea, CellRenderer, TreeIter, TreeModel, ffi};
6use glib::{prelude::*, translate::*};
7use std::boxed::Box as Box_;
8
9glib::wrapper! {
10    ///
11    /// static void
12    /// my_combo_box_init (MyComboBox *b)
13    /// {
14    ///  GtkCellRenderer *cell;
15    ///
16    ///  cell = gtk_cell_renderer_pixbuf_new ();
17    ///  // The following call causes the default cell area for combo boxes,
18    ///  // a GtkCellAreaBox, to be instantiated
19    ///  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (b), cell, FALSE);
20    ///  ...
21    /// }
22    ///
23    /// GtkWidget *
24    /// my_combo_box_new (GtkCellArea *area)
25    /// {
26    ///  // This call is going to cause a warning about area being ignored
27    ///  return g_object_new (MY_TYPE_COMBO_BOX, "cell-area", area, NULL);
28    /// }
29    /// ]|
30    ///
31    /// If supporting alternative cell areas with your derived widget is
32    /// not important, then this does not have to concern you. If you want
33    /// to support alternative cell areas, you can do so by moving the
34    /// problematic calls out of `init()` and into a `constructor()`
35    /// for your class.
36    ///
37    /// # Implements
38    ///
39    /// [`CellLayoutExt`][trait@crate::prelude::CellLayoutExt]
40    #[doc(alias = "GtkCellLayout")]
41    pub struct CellLayout(Interface<ffi::GtkCellLayout, ffi::GtkCellLayoutIface>);
42
43    match fn {
44        type_ => || ffi::gtk_cell_layout_get_type(),
45    }
46}
47
48impl CellLayout {
49    pub const NONE: Option<&'static CellLayout> = None;
50}
51
52/// Trait containing all [`struct@CellLayout`] methods.
53///
54/// # Implementors
55///
56/// [`AppChooserButton`][struct@crate::AppChooserButton], [`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]
57pub trait CellLayoutExt: IsA<CellLayout> + 'static {
58    /// Adds an attribute mapping to the list in `self`.
59    ///
60    /// The `column` is the column of the model to get a value from, and the
61    /// `attribute` is the parameter on `cell` to be set from the value. So for
62    /// example if column 2 of the model contains strings, you could have the
63    /// “text” attribute of a [`CellRendererText`][crate::CellRendererText] get its values from column 2.
64    /// ## `cell`
65    /// a [`CellRenderer`][crate::CellRenderer]
66    /// ## `attribute`
67    /// an attribute on the renderer
68    /// ## `column`
69    /// the column position on the model to get the attribute from
70    #[doc(alias = "gtk_cell_layout_add_attribute")]
71    fn add_attribute(&self, cell: &impl IsA<CellRenderer>, attribute: &str, column: i32) {
72        unsafe {
73            ffi::gtk_cell_layout_add_attribute(
74                self.as_ref().to_glib_none().0,
75                cell.as_ref().to_glib_none().0,
76                attribute.to_glib_none().0,
77                column,
78            );
79        }
80    }
81
82    /// Unsets all the mappings on all renderers on `self` and
83    /// removes all renderers from `self`.
84    #[doc(alias = "gtk_cell_layout_clear")]
85    fn clear(&self) {
86        unsafe {
87            ffi::gtk_cell_layout_clear(self.as_ref().to_glib_none().0);
88        }
89    }
90
91    /// Clears all existing attributes previously set with
92    /// `gtk_cell_layout_set_attributes()`.
93    /// ## `cell`
94    /// a [`CellRenderer`][crate::CellRenderer] to clear the attribute mapping on
95    #[doc(alias = "gtk_cell_layout_clear_attributes")]
96    fn clear_attributes(&self, cell: &impl IsA<CellRenderer>) {
97        unsafe {
98            ffi::gtk_cell_layout_clear_attributes(
99                self.as_ref().to_glib_none().0,
100                cell.as_ref().to_glib_none().0,
101            );
102        }
103    }
104
105    /// Returns the underlying [`CellArea`][crate::CellArea] which might be `self`
106    /// if called on a [`CellArea`][crate::CellArea] or might be [`None`] if no [`CellArea`][crate::CellArea]
107    /// is used by `self`.
108    ///
109    /// # Returns
110    ///
111    /// the cell area used by `self`,
112    /// or [`None`] in case no cell area is used.
113    #[doc(alias = "gtk_cell_layout_get_area")]
114    #[doc(alias = "get_area")]
115    fn area(&self) -> Option<CellArea> {
116        unsafe {
117            from_glib_none(ffi::gtk_cell_layout_get_area(
118                self.as_ref().to_glib_none().0,
119            ))
120        }
121    }
122
123    /// Returns the cell renderers which have been added to `self`.
124    ///
125    /// # Returns
126    ///
127    ///
128    ///  a list of cell renderers. The list, but not the renderers has
129    ///  been newly allocated and should be freed with `g_list_free()`
130    ///  when no longer needed.
131    #[doc(alias = "gtk_cell_layout_get_cells")]
132    #[doc(alias = "get_cells")]
133    fn cells(&self) -> Vec<CellRenderer> {
134        unsafe {
135            FromGlibPtrContainer::from_glib_container(ffi::gtk_cell_layout_get_cells(
136                self.as_ref().to_glib_none().0,
137            ))
138        }
139    }
140
141    /// Adds the `cell` to the end of `self`. If `expand` is [`false`], then the
142    /// `cell` is allocated no more space than it needs. Any unused space is
143    /// divided evenly between cells for which `expand` is [`true`].
144    ///
145    /// Note that reusing the same cell renderer is not supported.
146    /// ## `cell`
147    /// a [`CellRenderer`][crate::CellRenderer]
148    /// ## `expand`
149    /// [`true`] if `cell` is to be given extra space allocated to `self`
150    #[doc(alias = "gtk_cell_layout_pack_end")]
151    fn pack_end(&self, cell: &impl IsA<CellRenderer>, expand: bool) {
152        unsafe {
153            ffi::gtk_cell_layout_pack_end(
154                self.as_ref().to_glib_none().0,
155                cell.as_ref().to_glib_none().0,
156                expand.into_glib(),
157            );
158        }
159    }
160
161    /// Packs the `cell` into the beginning of `self`. If `expand` is [`false`],
162    /// then the `cell` is allocated no more space than it needs. Any unused space
163    /// is divided evenly between cells for which `expand` is [`true`].
164    ///
165    /// Note that reusing the same cell renderer is not supported.
166    /// ## `cell`
167    /// a [`CellRenderer`][crate::CellRenderer]
168    /// ## `expand`
169    /// [`true`] if `cell` is to be given extra space allocated to `self`
170    #[doc(alias = "gtk_cell_layout_pack_start")]
171    fn pack_start(&self, cell: &impl IsA<CellRenderer>, expand: bool) {
172        unsafe {
173            ffi::gtk_cell_layout_pack_start(
174                self.as_ref().to_glib_none().0,
175                cell.as_ref().to_glib_none().0,
176                expand.into_glib(),
177            );
178        }
179    }
180
181    /// Re-inserts `cell` at `position`.
182    ///
183    /// Note that `cell` has already to be packed into `self`
184    /// for this to function properly.
185    /// ## `cell`
186    /// a [`CellRenderer`][crate::CellRenderer] to reorder
187    /// ## `position`
188    /// new position to insert `cell` at
189    #[doc(alias = "gtk_cell_layout_reorder")]
190    fn reorder(&self, cell: &impl IsA<CellRenderer>, position: i32) {
191        unsafe {
192            ffi::gtk_cell_layout_reorder(
193                self.as_ref().to_glib_none().0,
194                cell.as_ref().to_glib_none().0,
195                position,
196            );
197        }
198    }
199
200    //#[doc(alias = "gtk_cell_layout_set_attributes")]
201    //fn set_attributes(&self, cell: &impl IsA<CellRenderer>, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
202    //    unsafe { TODO: call ffi:gtk_cell_layout_set_attributes() }
203    //}
204
205    /// Sets the `GtkCellLayoutDataFunc` to use for `self`.
206    ///
207    /// This function is used instead of the standard attributes mapping
208    /// for setting the column value, and should set the value of `self`’s
209    /// cell renderer(s) as appropriate.
210    ///
211    /// `func` may be [`None`] to remove a previously set function.
212    /// ## `cell`
213    /// a [`CellRenderer`][crate::CellRenderer]
214    /// ## `func`
215    /// the `GtkCellLayoutDataFunc` to use, or [`None`]
216    /// ## `func_data`
217    /// user data for `func`
218    #[doc(alias = "gtk_cell_layout_set_cell_data_func")]
219    fn set_cell_data_func(
220        &self,
221        cell: &impl IsA<CellRenderer>,
222        func: Option<Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>>,
223    ) {
224        let func_data: Box_<
225            Option<Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>>,
226        > = Box_::new(func);
227        unsafe extern "C" fn func_func(
228            cell_layout: *mut ffi::GtkCellLayout,
229            cell: *mut ffi::GtkCellRenderer,
230            tree_model: *mut ffi::GtkTreeModel,
231            iter: *mut ffi::GtkTreeIter,
232            data: glib::ffi::gpointer,
233        ) {
234            unsafe {
235                let cell_layout = from_glib_borrow(cell_layout);
236                let cell = from_glib_borrow(cell);
237                let tree_model = from_glib_borrow(tree_model);
238                let iter = from_glib_borrow(iter);
239                let callback = &*(data as *mut Option<
240                    Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>,
241                >);
242                if let Some(ref callback) = *callback {
243                    callback(&cell_layout, &cell, &tree_model, &iter)
244                } else {
245                    panic!("cannot get closure...")
246                }
247            }
248        }
249        let func = if func_data.is_some() {
250            Some(func_func as _)
251        } else {
252            None
253        };
254        unsafe extern "C" fn destroy_func(data: glib::ffi::gpointer) {
255            unsafe {
256                let _callback = Box_::from_raw(
257                    data as *mut Option<
258                        Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>,
259                    >,
260                );
261            }
262        }
263        let destroy_call4 = Some(destroy_func as _);
264        let super_callback0: Box_<
265            Option<Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>>,
266        > = func_data;
267        unsafe {
268            ffi::gtk_cell_layout_set_cell_data_func(
269                self.as_ref().to_glib_none().0,
270                cell.as_ref().to_glib_none().0,
271                func,
272                Box_::into_raw(super_callback0) as *mut _,
273                destroy_call4,
274            );
275        }
276    }
277}
278
279impl<O: IsA<CellLayout>> CellLayoutExt for O {}