Skip to main content

gdk/
drag_context.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::atom::Atom;
4use crate::Device;
5use crate::DragAction;
6use crate::DragContext;
7use crate::DragProtocol;
8use crate::Screen;
9use crate::Window;
10use glib::object::IsA;
11use glib::translate::*;
12use std::ptr;
13
14impl DragContext {
15    #[doc(alias = "gdk_drag_get_selection")]
16    pub fn drag_get_selection(&self) -> Atom {
17        unsafe { from_glib_none(ffi::gdk_drag_get_selection(self.to_glib_none().0) as *mut _) }
18    }
19
20    #[doc(alias = "gdk_drag_abort")]
21    pub fn drag_abort(&self, time_: u32) {
22        unsafe { ffi::gdk_drag_abort(self.to_glib_none().0, time_) }
23    }
24
25    #[doc(alias = "gdk_drop_reply")]
26    pub fn drop_reply(&self, accepted: bool, time_: u32) {
27        unsafe { ffi::gdk_drop_reply(self.to_glib_none().0, accepted.into_glib(), time_) }
28    }
29
30    #[doc(alias = "gdk_drag_drop")]
31    pub fn drop(&self, time_: u32) {
32        unsafe { ffi::gdk_drag_drop(self.to_glib_none().0, time_) }
33    }
34
35    #[doc(alias = "gdk_drag_find_window_for_screen")]
36    pub fn drag_find_window_for_screen(
37        &self,
38        drag_window: &Window,
39        screen: &Screen,
40        x_root: i32,
41        y_root: i32,
42    ) -> (Option<Window>, DragProtocol) {
43        unsafe {
44            let mut dest_window = ptr::null_mut();
45            let mut protocol = ffi::GDK_DRAG_PROTO_NONE;
46            ffi::gdk_drag_find_window_for_screen(
47                self.to_glib_none().0,
48                drag_window.to_glib_none().0,
49                screen.to_glib_none().0,
50                x_root,
51                y_root,
52                &mut dest_window,
53                &mut protocol,
54            );
55            (from_glib_full(dest_window), from_glib(protocol))
56        }
57    }
58
59    #[allow(clippy::too_many_arguments)]
60    #[doc(alias = "gdk_drag_motion")]
61    pub fn drag_motion(
62        &self,
63        dest_window: &Window,
64        protocol: DragProtocol,
65        x_root: i32,
66        y_root: i32,
67        suggested_action: DragAction,
68        possible_actions: DragAction,
69        time_: u32,
70    ) -> bool {
71        unsafe {
72            from_glib(ffi::gdk_drag_motion(
73                self.to_glib_none().0,
74                dest_window.to_glib_none().0,
75                protocol.into_glib(),
76                x_root,
77                y_root,
78                suggested_action.into_glib(),
79                possible_actions.into_glib(),
80                time_,
81            ))
82        }
83    }
84
85    #[doc(alias = "gdk_drop_finish")]
86    pub fn drop_finish(&self, success: bool, time_: u32) {
87        unsafe { ffi::gdk_drop_finish(self.to_glib_none().0, success.into_glib(), time_) }
88    }
89
90    #[doc(alias = "gdk_drag_status")]
91    pub fn drag_status(&self, action: DragAction, time_: u32) {
92        unsafe { ffi::gdk_drag_status(self.to_glib_none().0, action.into_glib(), time_) }
93    }
94
95    #[doc(alias = "gdk_drag_drop_succeeded")]
96    pub fn drag_drop_succeeded(&self) -> bool {
97        unsafe { from_glib(ffi::gdk_drag_drop_succeeded(self.to_glib_none().0)) }
98    }
99
100    #[doc(alias = "gdk_drag_begin")]
101    pub fn drag_begin(window: &Window, targets: &[Atom]) -> Option<DragContext> {
102        skip_assert_initialized!();
103        unsafe {
104            from_glib_full(ffi::gdk_drag_begin(
105                window.to_glib_none().0,
106                targets.to_glib_none().0,
107            ))
108        }
109    }
110
111    #[doc(alias = "gdk_drag_begin_for_device")]
112    pub fn drag_begin_for_device<P: IsA<Device>>(
113        window: &Window,
114        device: &P,
115        targets: &[Atom],
116    ) -> Option<DragContext> {
117        skip_assert_initialized!();
118        unsafe {
119            from_glib_full(ffi::gdk_drag_begin_for_device(
120                window.to_glib_none().0,
121                device.as_ref().to_glib_none().0,
122                targets.to_glib_none().0,
123            ))
124        }
125    }
126
127    #[doc(alias = "gdk_drag_begin_from_point")]
128    pub fn drag_begin_from_point<P: IsA<Device>>(
129        window: &Window,
130        device: &P,
131        targets: &[Atom],
132        x_root: i32,
133        y_root: i32,
134    ) -> Option<DragContext> {
135        skip_assert_initialized!();
136        unsafe {
137            from_glib_full(ffi::gdk_drag_begin_from_point(
138                window.to_glib_none().0,
139                device.as_ref().to_glib_none().0,
140                targets.to_glib_none().0,
141                x_root,
142                y_root,
143            ))
144        }
145    }
146
147    #[doc(alias = "gdk_drag_drop_done")]
148    pub fn drag_drop_done(&self, success: bool) {
149        skip_assert_initialized!();
150        unsafe {
151            ffi::gdk_drag_drop_done(self.to_glib_none().0, success.into_glib());
152        }
153    }
154}