1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
#![allow(deprecated)]

use crate::{CellArea, CellRenderer, TreeIter, TreeModel};
use glib::{prelude::*, translate::*};
use std::boxed::Box as Box_;

glib::wrapper! {
    /// List views use widgets to display their contents.
    ///   See [`LayoutManager`][crate::LayoutManager] for layout manager delegate objects
    /// An interface for packing cells
    ///
    /// [`CellLayout`][crate::CellLayout] is an interface to be implemented by all objects which
    /// want to provide a [`TreeViewColumn`][crate::TreeViewColumn] like API for packing cells,
    /// setting attributes and data funcs.
    ///
    /// One of the notable features provided by implementations of
    /// [`CellLayout`][crate::CellLayout] are attributes. Attributes let you set the properties
    /// in flexible ways. They can just be set to constant values like regular
    /// properties. But they can also be mapped to a column of the underlying
    /// tree model with gtk_cell_layout_set_attributes(), which means that the value
    /// of the attribute can change from cell to cell as they are rendered by
    /// the cell renderer. Finally, it is possible to specify a function with
    /// gtk_cell_layout_set_cell_data_func() that is called to determine the
    /// value of the attribute for each cell that is rendered.
    ///
    /// ## GtkCellLayouts as GtkBuildable
    ///
    /// Implementations of GtkCellLayout which also implement the GtkBuildable
    /// interface ([`CellView`][crate::CellView], [`IconView`][crate::IconView], [`ComboBox`][crate::ComboBox],
    /// [`EntryCompletion`][crate::EntryCompletion], [`TreeViewColumn`][crate::TreeViewColumn]) accept [`CellRenderer`][crate::CellRenderer] objects
    /// as `<child>` elements in UI definitions. They support a custom `<attributes>`
    /// element for their children, which can contain multiple `<attribute>`
    /// elements. Each `<attribute>` element has a name attribute which specifies
    /// a property of the cell renderer; the content of the element is the
    /// attribute value.
    ///
    /// This is an example of a UI definition fragment specifying attributes:
    ///
    /// ```xml
    /// <object class="GtkCellView">
    ///   <child>
    ///     <object class="GtkCellRendererText"/>
    ///     <attributes>
    ///       <attribute name="text">0</attribute>
    ///     </attributes>
    ///   </child>
    /// </object>
    /// ```
    ///
    /// Furthermore for implementations of [`CellLayout`][crate::CellLayout] that use a [`CellArea`][crate::CellArea]
    /// to lay out cells (all [`CellLayout`][crate::CellLayout]s in GTK use a [`CellArea`][crate::CellArea])
    /// [cell properties](class.CellArea.html#cell-properties) can also be defined
    /// in the format by specifying the custom `<cell-packing>` attribute which can
    /// contain multiple `<property>` elements.
    ///
    /// Here is a UI definition fragment specifying cell properties:
    ///
    /// ```xml
    /// <object class="GtkTreeViewColumn">
    ///   <child>
    ///     <object class="GtkCellRendererText"/>
    ///     <cell-packing>
    ///       <property name="align">True</property>
    ///       <property name="expand">False</property>
    ///     </cell-packing>
    ///   </child>
    /// </object>
    /// ```
    ///
    /// ## Subclassing GtkCellLayout implementations
    ///
    /// When subclassing a widget that implements [`CellLayout`][crate::CellLayout] like
    /// [`IconView`][crate::IconView] or [`ComboBox`][crate::ComboBox], there are some considerations related
    /// to the fact that these widgets internally use a [`CellArea`][crate::CellArea].
    /// The cell area is exposed as a construct-only property by these
    /// widgets. This means that it is possible to e.g. do
    ///
    /// **⚠️ The following code is in c ⚠️**
    ///
    /// ```c
    /// GtkWIdget *combo =
    ///   g_object_new (GTK_TYPE_COMBO_BOX, "cell-area", my_cell_area, NULL);
    /// ```
    ///
    /// to use a custom cell area with a combo box. But construct properties
    /// are only initialized after instance `init()`
    /// functions have run, which means that using functions which rely on
    /// the existence of the cell area in your subclass `init()` function will
    /// cause the default cell area to be instantiated. In this case, a provided
    /// construct property value will be ignored (with a warning, to alert
    /// you to the problem).
    ///
    /// **⚠️ The following code is in c ⚠️**
    ///
    /// ```c
    /// static void
    /// my_combo_box_init (MyComboBox *b)
    /// {
    ///   GtkCellRenderer *cell;
    ///
    ///   cell = gtk_cell_renderer_pixbuf_new ();
    ///
    ///   // The following call causes the default cell area for combo boxes,
    ///   // a GtkCellAreaBox, to be instantiated
    ///   gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (b), cell, FALSE);
    ///   ...
    /// }
    ///
    /// GtkWidget *
    /// my_combo_box_new (GtkCellArea *area)
    /// {
    ///   // This call is going to cause a warning about area being ignored
    ///   return g_object_new (MY_TYPE_COMBO_BOX, "cell-area", area, NULL);
    /// }
    /// ```
    ///
    /// If supporting alternative cell areas with your derived widget is
    /// not important, then this does not have to concern you. If you want
    /// to support alternative cell areas, you can do so by moving the
    /// problematic calls out of `init()` and into a `constructor()`
    /// for your class.
    ///
    /// # Implements
    ///
    /// [`CellLayoutExt`][trait@crate::prelude::CellLayoutExt], [`CellLayoutExtManual`][trait@crate::prelude::CellLayoutExtManual]
    #[doc(alias = "GtkCellLayout")]
    pub struct CellLayout(Interface<ffi::GtkCellLayout, ffi::GtkCellLayoutIface>);

    match fn {
        type_ => || ffi::gtk_cell_layout_get_type(),
    }
}

impl CellLayout {
    pub const NONE: Option<&'static CellLayout> = None;
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::CellLayout>> Sealed for T {}
}

/// Trait containing all [`struct@CellLayout`] methods.
///
/// # Implementors
///
/// [`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]
pub trait CellLayoutExt: IsA<CellLayout> + sealed::Sealed + 'static {
    /// Adds an attribute mapping to the list in @self.
    ///
    /// The @column is the column of the model to get a value from, and the
    /// @attribute is the property on @cell to be set from that value. So for
    /// example if column 2 of the model contains strings, you could have the
    /// “text” attribute of a [`CellRendererText`][crate::CellRendererText] get its values from column 2.
    /// In this context "attribute" and "property" are used interchangeably.
    ///
    /// # Deprecated since 4.10
    ///
    /// ## `cell`
    /// a [`CellRenderer`][crate::CellRenderer]
    /// ## `attribute`
    /// a property on the renderer
    /// ## `column`
    /// the column position on the model to get the attribute from
    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
    #[allow(deprecated)]
    #[doc(alias = "gtk_cell_layout_add_attribute")]
    fn add_attribute(&self, cell: &impl IsA<CellRenderer>, attribute: &str, column: i32) {
        unsafe {
            ffi::gtk_cell_layout_add_attribute(
                self.as_ref().to_glib_none().0,
                cell.as_ref().to_glib_none().0,
                attribute.to_glib_none().0,
                column,
            );
        }
    }

    /// Unsets all the mappings on all renderers on @self and
    /// removes all renderers from @self.
    ///
    /// # Deprecated since 4.10
    ///
    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
    #[allow(deprecated)]
    #[doc(alias = "gtk_cell_layout_clear")]
    fn clear(&self) {
        unsafe {
            ffi::gtk_cell_layout_clear(self.as_ref().to_glib_none().0);
        }
    }

    /// Clears all existing attributes previously set with
    /// gtk_cell_layout_set_attributes().
    ///
    /// # Deprecated since 4.10
    ///
    /// ## `cell`
    /// a [`CellRenderer`][crate::CellRenderer] to clear the attribute mapping on
    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
    #[allow(deprecated)]
    #[doc(alias = "gtk_cell_layout_clear_attributes")]
    fn clear_attributes(&self, cell: &impl IsA<CellRenderer>) {
        unsafe {
            ffi::gtk_cell_layout_clear_attributes(
                self.as_ref().to_glib_none().0,
                cell.as_ref().to_glib_none().0,
            );
        }
    }

    /// Returns the underlying [`CellArea`][crate::CellArea] which might be @self
    /// if called on a [`CellArea`][crate::CellArea] or might be [`None`] if no [`CellArea`][crate::CellArea]
    /// is used by @self.
    ///
    /// # Deprecated since 4.10
    ///
    ///
    /// # Returns
    ///
    /// the cell area used by @self
    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
    #[allow(deprecated)]
    #[doc(alias = "gtk_cell_layout_get_area")]
    #[doc(alias = "get_area")]
    fn area(&self) -> Option<CellArea> {
        unsafe {
            from_glib_none(ffi::gtk_cell_layout_get_area(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Returns the cell renderers which have been added to @self.
    ///
    /// # Deprecated since 4.10
    ///
    ///
    /// # Returns
    ///
    ///
    ///   a list of cell renderers. The list, but not the renderers has
    ///   been newly allocated and should be freed with g_list_free()
    ///   when no longer needed.
    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
    #[allow(deprecated)]
    #[doc(alias = "gtk_cell_layout_get_cells")]
    #[doc(alias = "get_cells")]
    fn cells(&self) -> Vec<CellRenderer> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::gtk_cell_layout_get_cells(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Adds the @cell to the end of @self. If @expand is [`false`], then the
    /// @cell is allocated no more space than it needs. Any unused space is
    /// divided evenly between cells for which @expand is [`true`].
    ///
    /// Note that reusing the same cell renderer is not supported.
    ///
    /// # Deprecated since 4.10
    ///
    /// ## `cell`
    /// a [`CellRenderer`][crate::CellRenderer]
    /// ## `expand`
    /// [`true`] if @cell is to be given extra space allocated to @self
    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
    #[allow(deprecated)]
    #[doc(alias = "gtk_cell_layout_pack_end")]
    fn pack_end(&self, cell: &impl IsA<CellRenderer>, expand: bool) {
        unsafe {
            ffi::gtk_cell_layout_pack_end(
                self.as_ref().to_glib_none().0,
                cell.as_ref().to_glib_none().0,
                expand.into_glib(),
            );
        }
    }

    /// Packs the @cell into the beginning of @self. If @expand is [`false`],
    /// then the @cell is allocated no more space than it needs. Any unused space
    /// is divided evenly between cells for which @expand is [`true`].
    ///
    /// Note that reusing the same cell renderer is not supported.
    ///
    /// # Deprecated since 4.10
    ///
    /// ## `cell`
    /// a [`CellRenderer`][crate::CellRenderer]
    /// ## `expand`
    /// [`true`] if @cell is to be given extra space allocated to @self
    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
    #[allow(deprecated)]
    #[doc(alias = "gtk_cell_layout_pack_start")]
    fn pack_start(&self, cell: &impl IsA<CellRenderer>, expand: bool) {
        unsafe {
            ffi::gtk_cell_layout_pack_start(
                self.as_ref().to_glib_none().0,
                cell.as_ref().to_glib_none().0,
                expand.into_glib(),
            );
        }
    }

    /// Re-inserts @cell at @position.
    ///
    /// Note that @cell has already to be packed into @self
    /// for this to function properly.
    ///
    /// # Deprecated since 4.10
    ///
    /// ## `cell`
    /// a [`CellRenderer`][crate::CellRenderer] to reorder
    /// ## `position`
    /// new position to insert @cell at
    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
    #[allow(deprecated)]
    #[doc(alias = "gtk_cell_layout_reorder")]
    fn reorder(&self, cell: &impl IsA<CellRenderer>, position: i32) {
        unsafe {
            ffi::gtk_cell_layout_reorder(
                self.as_ref().to_glib_none().0,
                cell.as_ref().to_glib_none().0,
                position,
            );
        }
    }

    /// Sets the [`CellLayout`][crate::CellLayout]DataFunc to use for @self.
    ///
    /// This function is used instead of the standard attributes mapping
    /// for setting the column value, and should set the value of @self’s
    /// cell renderer(s) as appropriate.
    ///
    /// @func may be [`None`] to remove a previously set function.
    ///
    /// # Deprecated since 4.10
    ///
    /// ## `cell`
    /// a [`CellRenderer`][crate::CellRenderer]
    /// ## `func`
    /// the [`CellLayout`][crate::CellLayout]DataFunc to use
    /// ## `func_data`
    /// user data for @func
    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
    #[allow(deprecated)]
    #[doc(alias = "gtk_cell_layout_set_cell_data_func")]
    fn set_cell_data_func<P: Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>(
        &self,
        cell: &impl IsA<CellRenderer>,
        func: P,
    ) {
        let func_data: Box_<P> = Box_::new(func);
        unsafe extern "C" fn func_func<
            P: Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static,
        >(
            cell_layout: *mut ffi::GtkCellLayout,
            cell: *mut ffi::GtkCellRenderer,
            tree_model: *mut ffi::GtkTreeModel,
            iter: *mut ffi::GtkTreeIter,
            data: glib::ffi::gpointer,
        ) {
            let cell_layout = from_glib_borrow(cell_layout);
            let cell = from_glib_borrow(cell);
            let tree_model = from_glib_borrow(tree_model);
            let iter = from_glib_borrow(iter);
            let callback = &*(data as *mut P);
            (*callback)(&cell_layout, &cell, &tree_model, &iter)
        }
        let func = Some(func_func::<P> as _);
        unsafe extern "C" fn destroy_func<
            P: Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static,
        >(
            data: glib::ffi::gpointer,
        ) {
            let _callback = Box_::from_raw(data as *mut P);
        }
        let destroy_call4 = Some(destroy_func::<P> as _);
        let super_callback0: Box_<P> = func_data;
        unsafe {
            ffi::gtk_cell_layout_set_cell_data_func(
                self.as_ref().to_glib_none().0,
                cell.as_ref().to_glib_none().0,
                func,
                Box_::into_raw(super_callback0) as *mut _,
                destroy_call4,
            );
        }
    }
}

impl<O: IsA<CellLayout>> CellLayoutExt for O {}