gdk/
drag_context.rs

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