gdk4/auto/
drag.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::{
6    ffi, ContentFormats, ContentProvider, Device, Display, DragAction, DragCancelReason, Surface,
7};
8use glib::{
9    object::ObjectType as _,
10    prelude::*,
11    signal::{connect_raw, SignalHandlerId},
12    translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17    #[doc(alias = "GdkDrag")]
18    pub struct Drag(Object<ffi::GdkDrag>);
19
20    match fn {
21        type_ => || ffi::gdk_drag_get_type(),
22    }
23}
24
25impl Drag {
26    pub const NONE: Option<&'static Drag> = None;
27
28    #[doc(alias = "gdk_drag_begin")]
29    pub fn begin(
30        surface: &impl IsA<Surface>,
31        device: &impl IsA<Device>,
32        content: &impl IsA<ContentProvider>,
33        actions: DragAction,
34        dx: f64,
35        dy: f64,
36    ) -> Option<Drag> {
37        skip_assert_initialized!();
38        unsafe {
39            from_glib_full(ffi::gdk_drag_begin(
40                surface.as_ref().to_glib_none().0,
41                device.as_ref().to_glib_none().0,
42                content.as_ref().to_glib_none().0,
43                actions.into_glib(),
44                dx,
45                dy,
46            ))
47        }
48    }
49}
50
51pub trait DragExt: IsA<Drag> + 'static {
52    #[doc(alias = "gdk_drag_drop_done")]
53    fn drop_done(&self, success: bool) {
54        unsafe {
55            ffi::gdk_drag_drop_done(self.as_ref().to_glib_none().0, success.into_glib());
56        }
57    }
58
59    #[doc(alias = "gdk_drag_get_actions")]
60    #[doc(alias = "get_actions")]
61    fn actions(&self) -> DragAction {
62        unsafe { from_glib(ffi::gdk_drag_get_actions(self.as_ref().to_glib_none().0)) }
63    }
64
65    #[doc(alias = "gdk_drag_get_content")]
66    #[doc(alias = "get_content")]
67    fn content(&self) -> ContentProvider {
68        unsafe { from_glib_none(ffi::gdk_drag_get_content(self.as_ref().to_glib_none().0)) }
69    }
70
71    #[doc(alias = "gdk_drag_get_device")]
72    #[doc(alias = "get_device")]
73    fn device(&self) -> Device {
74        unsafe { from_glib_none(ffi::gdk_drag_get_device(self.as_ref().to_glib_none().0)) }
75    }
76
77    #[doc(alias = "gdk_drag_get_display")]
78    #[doc(alias = "get_display")]
79    fn display(&self) -> Display {
80        unsafe { from_glib_none(ffi::gdk_drag_get_display(self.as_ref().to_glib_none().0)) }
81    }
82
83    #[doc(alias = "gdk_drag_get_drag_surface")]
84    #[doc(alias = "get_drag_surface")]
85    fn drag_surface(&self) -> Option<Surface> {
86        unsafe {
87            from_glib_none(ffi::gdk_drag_get_drag_surface(
88                self.as_ref().to_glib_none().0,
89            ))
90        }
91    }
92
93    #[doc(alias = "gdk_drag_get_formats")]
94    #[doc(alias = "get_formats")]
95    fn formats(&self) -> ContentFormats {
96        unsafe { from_glib_none(ffi::gdk_drag_get_formats(self.as_ref().to_glib_none().0)) }
97    }
98
99    #[doc(alias = "gdk_drag_get_selected_action")]
100    #[doc(alias = "get_selected_action")]
101    #[doc(alias = "selected-action")]
102    fn selected_action(&self) -> DragAction {
103        unsafe {
104            from_glib(ffi::gdk_drag_get_selected_action(
105                self.as_ref().to_glib_none().0,
106            ))
107        }
108    }
109
110    #[doc(alias = "gdk_drag_get_surface")]
111    #[doc(alias = "get_surface")]
112    fn surface(&self) -> Surface {
113        unsafe { from_glib_none(ffi::gdk_drag_get_surface(self.as_ref().to_glib_none().0)) }
114    }
115
116    #[doc(alias = "gdk_drag_set_hotspot")]
117    fn set_hotspot(&self, hot_x: i32, hot_y: i32) {
118        unsafe {
119            ffi::gdk_drag_set_hotspot(self.as_ref().to_glib_none().0, hot_x, hot_y);
120        }
121    }
122
123    fn set_actions(&self, actions: DragAction) {
124        ObjectExt::set_property(self.as_ref(), "actions", actions)
125    }
126
127    #[doc(alias = "selected-action")]
128    fn set_selected_action(&self, selected_action: DragAction) {
129        ObjectExt::set_property(self.as_ref(), "selected-action", selected_action)
130    }
131
132    #[doc(alias = "cancel")]
133    fn connect_cancel<F: Fn(&Self, DragCancelReason) + 'static>(&self, f: F) -> SignalHandlerId {
134        unsafe extern "C" fn cancel_trampoline<
135            P: IsA<Drag>,
136            F: Fn(&P, DragCancelReason) + 'static,
137        >(
138            this: *mut ffi::GdkDrag,
139            reason: ffi::GdkDragCancelReason,
140            f: glib::ffi::gpointer,
141        ) {
142            let f: &F = &*(f as *const F);
143            f(
144                Drag::from_glib_borrow(this).unsafe_cast_ref(),
145                from_glib(reason),
146            )
147        }
148        unsafe {
149            let f: Box_<F> = Box_::new(f);
150            connect_raw(
151                self.as_ptr() as *mut _,
152                c"cancel".as_ptr() as *const _,
153                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
154                    cancel_trampoline::<Self, F> as *const (),
155                )),
156                Box_::into_raw(f),
157            )
158        }
159    }
160
161    #[doc(alias = "dnd-finished")]
162    fn connect_dnd_finished<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
163        unsafe extern "C" fn dnd_finished_trampoline<P: IsA<Drag>, F: Fn(&P) + 'static>(
164            this: *mut ffi::GdkDrag,
165            f: glib::ffi::gpointer,
166        ) {
167            let f: &F = &*(f as *const F);
168            f(Drag::from_glib_borrow(this).unsafe_cast_ref())
169        }
170        unsafe {
171            let f: Box_<F> = Box_::new(f);
172            connect_raw(
173                self.as_ptr() as *mut _,
174                c"dnd-finished".as_ptr() as *const _,
175                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
176                    dnd_finished_trampoline::<Self, F> as *const (),
177                )),
178                Box_::into_raw(f),
179            )
180        }
181    }
182
183    #[doc(alias = "drop-performed")]
184    fn connect_drop_performed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
185        unsafe extern "C" fn drop_performed_trampoline<P: IsA<Drag>, F: Fn(&P) + 'static>(
186            this: *mut ffi::GdkDrag,
187            f: glib::ffi::gpointer,
188        ) {
189            let f: &F = &*(f as *const F);
190            f(Drag::from_glib_borrow(this).unsafe_cast_ref())
191        }
192        unsafe {
193            let f: Box_<F> = Box_::new(f);
194            connect_raw(
195                self.as_ptr() as *mut _,
196                c"drop-performed".as_ptr() as *const _,
197                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
198                    drop_performed_trampoline::<Self, F> as *const (),
199                )),
200                Box_::into_raw(f),
201            )
202        }
203    }
204
205    #[doc(alias = "actions")]
206    fn connect_actions_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
207        unsafe extern "C" fn notify_actions_trampoline<P: IsA<Drag>, F: Fn(&P) + 'static>(
208            this: *mut ffi::GdkDrag,
209            _param_spec: glib::ffi::gpointer,
210            f: glib::ffi::gpointer,
211        ) {
212            let f: &F = &*(f as *const F);
213            f(Drag::from_glib_borrow(this).unsafe_cast_ref())
214        }
215        unsafe {
216            let f: Box_<F> = Box_::new(f);
217            connect_raw(
218                self.as_ptr() as *mut _,
219                c"notify::actions".as_ptr() as *const _,
220                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
221                    notify_actions_trampoline::<Self, F> as *const (),
222                )),
223                Box_::into_raw(f),
224            )
225        }
226    }
227
228    #[doc(alias = "display")]
229    fn connect_display_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
230        unsafe extern "C" fn notify_display_trampoline<P: IsA<Drag>, F: Fn(&P) + 'static>(
231            this: *mut ffi::GdkDrag,
232            _param_spec: glib::ffi::gpointer,
233            f: glib::ffi::gpointer,
234        ) {
235            let f: &F = &*(f as *const F);
236            f(Drag::from_glib_borrow(this).unsafe_cast_ref())
237        }
238        unsafe {
239            let f: Box_<F> = Box_::new(f);
240            connect_raw(
241                self.as_ptr() as *mut _,
242                c"notify::display".as_ptr() as *const _,
243                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
244                    notify_display_trampoline::<Self, F> as *const (),
245                )),
246                Box_::into_raw(f),
247            )
248        }
249    }
250
251    #[doc(alias = "selected-action")]
252    fn connect_selected_action_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
253        unsafe extern "C" fn notify_selected_action_trampoline<
254            P: IsA<Drag>,
255            F: Fn(&P) + 'static,
256        >(
257            this: *mut ffi::GdkDrag,
258            _param_spec: glib::ffi::gpointer,
259            f: glib::ffi::gpointer,
260        ) {
261            let f: &F = &*(f as *const F);
262            f(Drag::from_glib_borrow(this).unsafe_cast_ref())
263        }
264        unsafe {
265            let f: Box_<F> = Box_::new(f);
266            connect_raw(
267                self.as_ptr() as *mut _,
268                c"notify::selected-action".as_ptr() as *const _,
269                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
270                    notify_selected_action_trampoline::<Self, F> as *const (),
271                )),
272                Box_::into_raw(f),
273            )
274        }
275    }
276}
277
278impl<O: IsA<Drag>> DragExt for O {}