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
// 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

use crate::CellArea;
use crate::CellRenderer;
use crate::TreeIter;
use crate::TreeModel;
use glib::object::IsA;
use glib::translate::*;
use std::boxed::Box as Box_;
use std::fmt;

glib::wrapper! {
    /// [`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
    /// GtkCellLayout 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
    /// [`CellLayoutExt::set_cell_data_func()`][crate::prelude::CellLayoutExt::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 GtkCellRenderer 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:
    ///
    ///
    /// **⚠️ The following code is in C ⚠️**
    ///
    /// ```C
    /// 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]
    #[doc(alias = "GtkCellLayout")]
    pub struct CellLayout(Interface<ffi::GtkCellLayout, ffi::GtkCellLayoutIface>);

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

pub const NONE_CELL_LAYOUT: Option<&CellLayout> = None;

/// Trait containing all [`struct@CellLayout`] methods.
///
/// # Implementors
///
/// [`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]
pub trait CellLayoutExt: '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 parameter on `cell` to be set from the 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.
    /// ## `cell`
    /// a [`CellRenderer`][crate::CellRenderer]
    /// ## `attribute`
    /// an attribute on the renderer
    /// ## `column`
    /// the column position on the model to get the attribute from
    #[doc(alias = "gtk_cell_layout_add_attribute")]
    fn add_attribute<P: IsA<CellRenderer>>(&self, cell: &P, attribute: &str, column: i32);

    /// Unsets all the mappings on all renderers on `self` and
    /// removes all renderers from `self`.
    #[doc(alias = "gtk_cell_layout_clear")]
    fn clear(&self);

    /// Clears all existing attributes previously set with
    /// `gtk_cell_layout_set_attributes()`.
    /// ## `cell`
    /// a [`CellRenderer`][crate::CellRenderer] to clear the attribute mapping on
    #[doc(alias = "gtk_cell_layout_clear_attributes")]
    fn clear_attributes<P: IsA<CellRenderer>>(&self, cell: &P);

    /// 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`.
    ///
    /// # Returns
    ///
    /// the cell area used by `self`,
    /// or [`None`] in case no cell area is used.
    #[doc(alias = "gtk_cell_layout_get_area")]
    #[doc(alias = "get_area")]
    fn area(&self) -> Option<CellArea>;

    /// Returns the cell renderers which have been added to `self`.
    ///
    /// # 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.
    #[doc(alias = "gtk_cell_layout_get_cells")]
    #[doc(alias = "get_cells")]
    fn cells(&self) -> Vec<CellRenderer>;

    /// 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.
    /// ## `cell`
    /// a [`CellRenderer`][crate::CellRenderer]
    /// ## `expand`
    /// [`true`] if `cell` is to be given extra space allocated to `self`
    #[doc(alias = "gtk_cell_layout_pack_end")]
    fn pack_end<P: IsA<CellRenderer>>(&self, cell: &P, expand: bool);

    /// 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.
    /// ## `cell`
    /// a [`CellRenderer`][crate::CellRenderer]
    /// ## `expand`
    /// [`true`] if `cell` is to be given extra space allocated to `self`
    #[doc(alias = "gtk_cell_layout_pack_start")]
    fn pack_start<P: IsA<CellRenderer>>(&self, cell: &P, expand: bool);

    /// Re-inserts `cell` at `position`.
    ///
    /// Note that `cell` has already to be packed into `self`
    /// for this to function properly.
    /// ## `cell`
    /// a [`CellRenderer`][crate::CellRenderer] to reorder
    /// ## `position`
    /// new position to insert `cell` at
    #[doc(alias = "gtk_cell_layout_reorder")]
    fn reorder<P: IsA<CellRenderer>>(&self, cell: &P, position: i32);

    //#[doc(alias = "gtk_cell_layout_set_attributes")]
    //fn set_attributes<P: IsA<CellRenderer>>(&self, cell: &P, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);

    /// Sets the `GtkCellLayoutDataFunc` 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.
    /// ## `cell`
    /// a [`CellRenderer`][crate::CellRenderer]
    /// ## `func`
    /// the `GtkCellLayoutDataFunc` to use, or [`None`]
    /// ## `func_data`
    /// user data for `func`
    #[doc(alias = "gtk_cell_layout_set_cell_data_func")]
    fn set_cell_data_func<P: IsA<CellRenderer>>(
        &self,
        cell: &P,
        func: Option<Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>>,
    );
}

impl<O: IsA<CellLayout>> CellLayoutExt for O {
    fn add_attribute<P: IsA<CellRenderer>>(&self, cell: &P, 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,
            );
        }
    }

    fn clear(&self) {
        unsafe {
            ffi::gtk_cell_layout_clear(self.as_ref().to_glib_none().0);
        }
    }

    fn clear_attributes<P: IsA<CellRenderer>>(&self, cell: &P) {
        unsafe {
            ffi::gtk_cell_layout_clear_attributes(
                self.as_ref().to_glib_none().0,
                cell.as_ref().to_glib_none().0,
            );
        }
    }

    fn area(&self) -> Option<CellArea> {
        unsafe {
            from_glib_none(ffi::gtk_cell_layout_get_area(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn cells(&self) -> Vec<CellRenderer> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::gtk_cell_layout_get_cells(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn pack_end<P: IsA<CellRenderer>>(&self, cell: &P, 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(),
            );
        }
    }

    fn pack_start<P: IsA<CellRenderer>>(&self, cell: &P, 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(),
            );
        }
    }

    fn reorder<P: IsA<CellRenderer>>(&self, cell: &P, position: i32) {
        unsafe {
            ffi::gtk_cell_layout_reorder(
                self.as_ref().to_glib_none().0,
                cell.as_ref().to_glib_none().0,
                position,
            );
        }
    }

    //fn set_attributes<P: IsA<CellRenderer>>(&self, cell: &P, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
    //    unsafe { TODO: call ffi:gtk_cell_layout_set_attributes() }
    //}

    fn set_cell_data_func<P: IsA<CellRenderer>>(
        &self,
        cell: &P,
        func: Option<Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>>,
    ) {
        let func_data: Box_<
            Option<Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>>,
        > = Box_::new(func);
        unsafe extern "C" fn func_func<P: IsA<CellRenderer>>(
            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: &Option<
                Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>,
            > = &*(data as *mut _);
            if let Some(ref callback) = *callback {
                callback(&cell_layout, &cell, &tree_model, &iter)
            } else {
                panic!("cannot get closure...")
            };
        }
        let func = if func_data.is_some() {
            Some(func_func::<P> as _)
        } else {
            None
        };
        unsafe extern "C" fn destroy_func<P: IsA<CellRenderer>>(data: glib::ffi::gpointer) {
            let _callback: Box_<
                Option<Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>>,
            > = Box_::from_raw(data as *mut _);
        }
        let destroy_call4 = Some(destroy_func::<P> as _);
        let super_callback0: Box_<
            Option<Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>>,
        > = 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 fmt::Display for CellLayout {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("CellLayout")
    }
}