Skip to main content

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