gtk4/auto/
drag_icon.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::{ffi, Accessible, Buildable, ConstraintTarget, Native, Root, Widget};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// [`DragIcon`][crate::DragIcon] is a [`Root`][crate::Root] implementation for drag icons.
15    ///
16    /// A drag icon moves with the pointer during a Drag-and-Drop operation
17    /// and is destroyed when the drag ends.
18    ///
19    /// To set up a drag icon and associate it with an ongoing drag operation,
20    /// use [`for_drag()`][Self::for_drag()] to get the icon for a drag. You can
21    /// then use it like any other widget and use [`set_child()`][Self::set_child()]
22    /// to set whatever widget should be used for the drag icon.
23    ///
24    /// Keep in mind that drag icons do not allow user input.
25    ///
26    /// ## Properties
27    ///
28    ///
29    /// #### `child`
30    ///  The widget to display as drag icon.
31    ///
32    /// Readable | Writeable
33    /// <details><summary><h4>Widget</h4></summary>
34    ///
35    ///
36    /// #### `can-focus`
37    ///  Whether the widget or any of its descendents can accept
38    /// the input focus.
39    ///
40    /// This property is meant to be set by widget implementations,
41    /// typically in their instance init function.
42    ///
43    /// Readable | Writeable
44    ///
45    ///
46    /// #### `can-target`
47    ///  Whether the widget can receive pointer events.
48    ///
49    /// Readable | Writeable
50    ///
51    ///
52    /// #### `css-classes`
53    ///  A list of css classes applied to this widget.
54    ///
55    /// Readable | Writeable
56    ///
57    ///
58    /// #### `css-name`
59    ///  The name of this widget in the CSS tree.
60    ///
61    /// This property is meant to be set by widget implementations,
62    /// typically in their instance init function.
63    ///
64    /// Readable | Writeable | Construct Only
65    ///
66    ///
67    /// #### `cursor`
68    ///  The cursor used by @widget.
69    ///
70    /// Readable | Writeable
71    ///
72    ///
73    /// #### `focus-on-click`
74    ///  Whether the widget should grab focus when it is clicked with the mouse.
75    ///
76    /// This property is only relevant for widgets that can take focus.
77    ///
78    /// Readable | Writeable
79    ///
80    ///
81    /// #### `focusable`
82    ///  Whether this widget itself will accept the input focus.
83    ///
84    /// Readable | Writeable
85    ///
86    ///
87    /// #### `halign`
88    ///  How to distribute horizontal space if widget gets extra space.
89    ///
90    /// Readable | Writeable
91    ///
92    ///
93    /// #### `has-default`
94    ///  Whether the widget is the default widget.
95    ///
96    /// Readable
97    ///
98    ///
99    /// #### `has-focus`
100    ///  Whether the widget has the input focus.
101    ///
102    /// Readable
103    ///
104    ///
105    /// #### `has-tooltip`
106    ///  Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
107    /// signal on @widget.
108    ///
109    /// A true value indicates that @widget can have a tooltip, in this case
110    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
111    /// determine whether it will provide a tooltip or not.
112    ///
113    /// Readable | Writeable
114    ///
115    ///
116    /// #### `height-request`
117    ///  Overrides for height request of the widget.
118    ///
119    /// If this is -1, the natural request will be used.
120    ///
121    /// Readable | Writeable
122    ///
123    ///
124    /// #### `hexpand`
125    ///  Whether to expand horizontally.
126    ///
127    /// Readable | Writeable
128    ///
129    ///
130    /// #### `hexpand-set`
131    ///  Whether to use the `hexpand` property.
132    ///
133    /// Readable | Writeable
134    ///
135    ///
136    /// #### `layout-manager`
137    ///  The [`LayoutManager`][crate::LayoutManager] instance to use to compute
138    /// the preferred size of the widget, and allocate its children.
139    ///
140    /// This property is meant to be set by widget implementations,
141    /// typically in their instance init function.
142    ///
143    /// Readable | Writeable
144    ///
145    ///
146    /// #### `limit-events`
147    ///  Makes this widget act like a modal dialog, with respect to
148    /// event delivery.
149    ///
150    /// Global event controllers will not handle events with targets
151    /// inside the widget, unless they are set up to ignore propagation
152    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
153    ///
154    /// Readable | Writeable
155    ///
156    ///
157    /// #### `margin-bottom`
158    ///  Margin on bottom side of widget.
159    ///
160    /// This property adds margin outside of the widget's normal size
161    /// request, the margin will be added in addition to the size from
162    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
163    ///
164    /// Readable | Writeable
165    ///
166    ///
167    /// #### `margin-end`
168    ///  Margin on end of widget, horizontally.
169    ///
170    /// This property supports left-to-right and right-to-left text
171    /// directions.
172    ///
173    /// This property adds margin outside of the widget's normal size
174    /// request, the margin will be added in addition to the size from
175    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
176    ///
177    /// Readable | Writeable
178    ///
179    ///
180    /// #### `margin-start`
181    ///  Margin on start of widget, horizontally.
182    ///
183    /// This property supports left-to-right and right-to-left text
184    /// directions.
185    ///
186    /// This property adds margin outside of the widget's normal size
187    /// request, the margin will be added in addition to the size from
188    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
189    ///
190    /// Readable | Writeable
191    ///
192    ///
193    /// #### `margin-top`
194    ///  Margin on top side of widget.
195    ///
196    /// This property adds margin outside of the widget's normal size
197    /// request, the margin will be added in addition to the size from
198    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
199    ///
200    /// Readable | Writeable
201    ///
202    ///
203    /// #### `name`
204    ///  The name of the widget.
205    ///
206    /// Readable | Writeable
207    ///
208    ///
209    /// #### `opacity`
210    ///  The requested opacity of the widget.
211    ///
212    /// Readable | Writeable
213    ///
214    ///
215    /// #### `overflow`
216    ///  How content outside the widget's content area is treated.
217    ///
218    /// This property is meant to be set by widget implementations,
219    /// typically in their instance init function.
220    ///
221    /// Readable | Writeable
222    ///
223    ///
224    /// #### `parent`
225    ///  The parent widget of this widget.
226    ///
227    /// Readable
228    ///
229    ///
230    /// #### `receives-default`
231    ///  Whether the widget will receive the default action when it is focused.
232    ///
233    /// Readable | Writeable
234    ///
235    ///
236    /// #### `root`
237    ///  The [`Root`][crate::Root] widget of the widget tree containing this widget.
238    ///
239    /// This will be `NULL` if the widget is not contained in a root widget.
240    ///
241    /// Readable
242    ///
243    ///
244    /// #### `scale-factor`
245    ///  The scale factor of the widget.
246    ///
247    /// Readable
248    ///
249    ///
250    /// #### `sensitive`
251    ///  Whether the widget responds to input.
252    ///
253    /// Readable | Writeable
254    ///
255    ///
256    /// #### `tooltip-markup`
257    ///  Sets the text of tooltip to be the given string, which is marked up
258    /// with Pango markup.
259    ///
260    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
261    ///
262    /// This is a convenience property which will take care of getting the
263    /// tooltip shown if the given string is not `NULL`:
264    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
265    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
266    /// the default signal handler.
267    ///
268    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
269    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
270    ///
271    /// Readable | Writeable
272    ///
273    ///
274    /// #### `tooltip-text`
275    ///  Sets the text of tooltip to be the given string.
276    ///
277    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
278    ///
279    /// This is a convenience property which will take care of getting the
280    /// tooltip shown if the given string is not `NULL`:
281    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
282    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
283    /// the default signal handler.
284    ///
285    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
286    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
287    ///
288    /// Readable | Writeable
289    ///
290    ///
291    /// #### `valign`
292    ///  How to distribute vertical space if widget gets extra space.
293    ///
294    /// Readable | Writeable
295    ///
296    ///
297    /// #### `vexpand`
298    ///  Whether to expand vertically.
299    ///
300    /// Readable | Writeable
301    ///
302    ///
303    /// #### `vexpand-set`
304    ///  Whether to use the `vexpand` property.
305    ///
306    /// Readable | Writeable
307    ///
308    ///
309    /// #### `visible`
310    ///  Whether the widget is visible.
311    ///
312    /// Readable | Writeable
313    ///
314    ///
315    /// #### `width-request`
316    ///  Overrides for width request of the widget.
317    ///
318    /// If this is -1, the natural request will be used.
319    ///
320    /// Readable | Writeable
321    /// </details>
322    /// <details><summary><h4>Accessible</h4></summary>
323    ///
324    ///
325    /// #### `accessible-role`
326    ///  The accessible role of the given [`Accessible`][crate::Accessible] implementation.
327    ///
328    /// The accessible role cannot be changed once set.
329    ///
330    /// Readable | Writeable
331    /// </details>
332    ///
333    /// # Implements
334    ///
335    /// [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`NativeExt`][trait@crate::prelude::NativeExt], [`RootExt`][trait@crate::prelude::RootExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
336    #[doc(alias = "GtkDragIcon")]
337    pub struct DragIcon(Object<ffi::GtkDragIcon, ffi::GtkDragIconClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, Native, Root;
338
339    match fn {
340        type_ => || ffi::gtk_drag_icon_get_type(),
341    }
342}
343
344impl DragIcon {
345    /// Gets the [`DragIcon`][crate::DragIcon] in use with @drag.
346    ///
347    /// If no drag icon exists yet, a new one will be created
348    /// and shown.
349    /// ## `drag`
350    /// a [`gdk::Drag`][crate::gdk::Drag]
351    ///
352    /// # Returns
353    ///
354    /// the [`DragIcon`][crate::DragIcon]
355    #[doc(alias = "gtk_drag_icon_get_for_drag")]
356    #[doc(alias = "get_for_drag")]
357    pub fn for_drag(drag: &gdk::Drag) -> DragIcon {
358        assert_initialized_main_thread!();
359        unsafe {
360            Widget::from_glib_none(ffi::gtk_drag_icon_get_for_drag(drag.to_glib_none().0))
361                .unsafe_cast()
362        }
363    }
364
365    /// Gets the widget currently used as drag icon.
366    ///
367    /// # Returns
368    ///
369    /// The drag icon
370    #[doc(alias = "gtk_drag_icon_get_child")]
371    #[doc(alias = "get_child")]
372    pub fn child(&self) -> Option<Widget> {
373        unsafe { from_glib_none(ffi::gtk_drag_icon_get_child(self.to_glib_none().0)) }
374    }
375
376    /// Sets the widget to display as the drag icon.
377    /// ## `child`
378    /// a [`Widget`][crate::Widget]
379    #[doc(alias = "gtk_drag_icon_set_child")]
380    #[doc(alias = "child")]
381    pub fn set_child(&self, child: Option<&impl IsA<Widget>>) {
382        unsafe {
383            ffi::gtk_drag_icon_set_child(
384                self.to_glib_none().0,
385                child.map(|p| p.as_ref()).to_glib_none().0,
386            );
387        }
388    }
389
390    /// Creates a widget that can be used as a drag icon for the given
391    /// @value.
392    ///
393    /// Supported types include strings, [`gdk::RGBA`][crate::gdk::RGBA] and [`TextBuffer`][crate::TextBuffer].
394    /// If GTK does not know how to create a widget for a given value,
395    /// it will return [`None`].
396    ///
397    /// This method is used to set the default drag icon on drag-and-drop
398    /// operations started by [`DragSource`][crate::DragSource], so you don't need to set
399    /// a drag icon using this function there.
400    /// ## `value`
401    /// a `GValue`
402    ///
403    /// # Returns
404    ///
405    /// A new [`Widget`][crate::Widget]
406    ///   for displaying @value as a drag icon.
407    #[doc(alias = "gtk_drag_icon_create_widget_for_value")]
408    pub fn create_widget_for_value(value: &glib::Value) -> Option<Widget> {
409        assert_initialized_main_thread!();
410        unsafe {
411            from_glib_full(ffi::gtk_drag_icon_create_widget_for_value(
412                value.to_glib_none().0,
413            ))
414        }
415    }
416
417    /// Creates a [`DragIcon`][crate::DragIcon] that shows @paintable, and associates
418    /// it with the drag operation.
419    ///
420    /// The hotspot position on the paintable is aligned with the
421    /// hotspot of the cursor.
422    /// ## `drag`
423    /// a [`gdk::Drag`][crate::gdk::Drag]
424    /// ## `paintable`
425    /// a [`gdk::Paintable`][crate::gdk::Paintable] to display
426    /// ## `hot_x`
427    /// X coordinate of the hotspot
428    /// ## `hot_y`
429    /// Y coordinate of the hotspot
430    #[doc(alias = "gtk_drag_icon_set_from_paintable")]
431    pub fn set_from_paintable(
432        drag: &gdk::Drag,
433        paintable: &impl IsA<gdk::Paintable>,
434        hot_x: i32,
435        hot_y: i32,
436    ) {
437        assert_initialized_main_thread!();
438        unsafe {
439            ffi::gtk_drag_icon_set_from_paintable(
440                drag.to_glib_none().0,
441                paintable.as_ref().to_glib_none().0,
442                hot_x,
443                hot_y,
444            );
445        }
446    }
447
448    #[doc(alias = "child")]
449    pub fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
450        unsafe extern "C" fn notify_child_trampoline<F: Fn(&DragIcon) + 'static>(
451            this: *mut ffi::GtkDragIcon,
452            _param_spec: glib::ffi::gpointer,
453            f: glib::ffi::gpointer,
454        ) {
455            let f: &F = &*(f as *const F);
456            f(&from_glib_borrow(this))
457        }
458        unsafe {
459            let f: Box_<F> = Box_::new(f);
460            connect_raw(
461                self.as_ptr() as *mut _,
462                b"notify::child\0".as_ptr() as *const _,
463                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
464                    notify_child_trampoline::<F> as *const (),
465                )),
466                Box_::into_raw(f),
467            )
468        }
469    }
470}