1use 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 #[doc(alias = "GtkDragIcon")]
15 pub struct DragIcon(Object<ffi::GtkDragIcon, ffi::GtkDragIconClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, Native, Root;
16
17 match fn {
18 type_ => || ffi::gtk_drag_icon_get_type(),
19 }
20}
21
22impl DragIcon {
23 #[doc(alias = "gtk_drag_icon_get_for_drag")]
24 #[doc(alias = "get_for_drag")]
25 pub fn for_drag(drag: &gdk::Drag) -> DragIcon {
26 assert_initialized_main_thread!();
27 unsafe {
28 Widget::from_glib_none(ffi::gtk_drag_icon_get_for_drag(drag.to_glib_none().0))
29 .unsafe_cast()
30 }
31 }
32
33 #[doc(alias = "gtk_drag_icon_get_child")]
34 #[doc(alias = "get_child")]
35 pub fn child(&self) -> Option<Widget> {
36 unsafe { from_glib_none(ffi::gtk_drag_icon_get_child(self.to_glib_none().0)) }
37 }
38
39 #[doc(alias = "gtk_drag_icon_set_child")]
40 #[doc(alias = "child")]
41 pub fn set_child(&self, child: Option<&impl IsA<Widget>>) {
42 unsafe {
43 ffi::gtk_drag_icon_set_child(
44 self.to_glib_none().0,
45 child.map(|p| p.as_ref()).to_glib_none().0,
46 );
47 }
48 }
49
50 #[doc(alias = "gtk_drag_icon_create_widget_for_value")]
51 pub fn create_widget_for_value(value: &glib::Value) -> Option<Widget> {
52 assert_initialized_main_thread!();
53 unsafe {
54 from_glib_full(ffi::gtk_drag_icon_create_widget_for_value(
55 value.to_glib_none().0,
56 ))
57 }
58 }
59
60 #[doc(alias = "gtk_drag_icon_set_from_paintable")]
61 pub fn set_from_paintable(
62 drag: &gdk::Drag,
63 paintable: &impl IsA<gdk::Paintable>,
64 hot_x: i32,
65 hot_y: i32,
66 ) {
67 assert_initialized_main_thread!();
68 unsafe {
69 ffi::gtk_drag_icon_set_from_paintable(
70 drag.to_glib_none().0,
71 paintable.as_ref().to_glib_none().0,
72 hot_x,
73 hot_y,
74 );
75 }
76 }
77
78 #[doc(alias = "child")]
79 pub fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
80 unsafe extern "C" fn notify_child_trampoline<F: Fn(&DragIcon) + 'static>(
81 this: *mut ffi::GtkDragIcon,
82 _param_spec: glib::ffi::gpointer,
83 f: glib::ffi::gpointer,
84 ) {
85 let f: &F = &*(f as *const F);
86 f(&from_glib_borrow(this))
87 }
88 unsafe {
89 let f: Box_<F> = Box_::new(f);
90 connect_raw(
91 self.as_ptr() as *mut _,
92 c"notify::child".as_ptr() as *const _,
93 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
94 notify_child_trampoline::<F> as *const (),
95 )),
96 Box_::into_raw(f),
97 )
98 }
99 }
100}