gdk/auto/
drag_context.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 gdk_sys;
6use glib::object::IsA;
7#[cfg(any(feature = "v3_20", feature = "dox"))]
8use glib::object::ObjectType as ObjectType_;
9#[cfg(any(feature = "v3_20", feature = "dox"))]
10use glib::signal::connect_raw;
11#[cfg(any(feature = "v3_20", feature = "dox"))]
12use glib::signal::SignalHandlerId;
13use glib::translate::*;
14#[cfg(any(feature = "v3_20", feature = "dox"))]
15use glib_sys;
16#[cfg(any(feature = "v3_20", feature = "dox"))]
17use libc;
18#[cfg(any(feature = "v3_20", feature = "dox"))]
19use std::boxed::Box as Box_;
20use std::fmt;
21#[cfg(any(feature = "v3_20", feature = "dox"))]
22use std::mem::transmute;
23use Atom;
24use Device;
25use DragAction;
26#[cfg(any(feature = "v3_20", feature = "dox"))]
27use DragCancelReason;
28use DragProtocol;
29use Window;
30
31glib_wrapper! {
32    pub struct DragContext(Object<gdk_sys::GdkDragContext, DragContextClass>);
33
34    match fn {
35        get_type => || gdk_sys::gdk_drag_context_get_type(),
36    }
37}
38
39impl DragContext {
40    pub fn get_actions(&self) -> DragAction {
41        unsafe { from_glib(gdk_sys::gdk_drag_context_get_actions(self.to_glib_none().0)) }
42    }
43
44    pub fn get_dest_window(&self) -> Window {
45        unsafe {
46            from_glib_none(gdk_sys::gdk_drag_context_get_dest_window(
47                self.to_glib_none().0,
48            ))
49        }
50    }
51
52    pub fn get_device(&self) -> Device {
53        unsafe { from_glib_none(gdk_sys::gdk_drag_context_get_device(self.to_glib_none().0)) }
54    }
55
56    #[cfg(any(feature = "v3_20", feature = "dox"))]
57    pub fn get_drag_window(&self) -> Option<Window> {
58        unsafe {
59            from_glib_none(gdk_sys::gdk_drag_context_get_drag_window(
60                self.to_glib_none().0,
61            ))
62        }
63    }
64
65    pub fn get_protocol(&self) -> DragProtocol {
66        unsafe {
67            from_glib(gdk_sys::gdk_drag_context_get_protocol(
68                self.to_glib_none().0,
69            ))
70        }
71    }
72
73    pub fn get_selected_action(&self) -> DragAction {
74        unsafe {
75            from_glib(gdk_sys::gdk_drag_context_get_selected_action(
76                self.to_glib_none().0,
77            ))
78        }
79    }
80
81    pub fn get_source_window(&self) -> Window {
82        unsafe {
83            from_glib_none(gdk_sys::gdk_drag_context_get_source_window(
84                self.to_glib_none().0,
85            ))
86        }
87    }
88
89    pub fn get_suggested_action(&self) -> DragAction {
90        unsafe {
91            from_glib(gdk_sys::gdk_drag_context_get_suggested_action(
92                self.to_glib_none().0,
93            ))
94        }
95    }
96
97    pub fn list_targets(&self) -> Vec<Atom> {
98        unsafe {
99            FromGlibPtrContainer::from_glib_none(gdk_sys::gdk_drag_context_list_targets(
100                self.to_glib_none().0,
101            ))
102        }
103    }
104
105    #[cfg(any(feature = "v3_20", feature = "dox"))]
106    pub fn manage_dnd<P: IsA<Window>>(&self, ipc_window: &P, actions: DragAction) -> bool {
107        unsafe {
108            from_glib(gdk_sys::gdk_drag_context_manage_dnd(
109                self.to_glib_none().0,
110                ipc_window.as_ref().to_glib_none().0,
111                actions.to_glib(),
112            ))
113        }
114    }
115
116    pub fn set_device(&self, device: &Device) {
117        unsafe {
118            gdk_sys::gdk_drag_context_set_device(self.to_glib_none().0, device.to_glib_none().0);
119        }
120    }
121
122    #[cfg(any(feature = "v3_20", feature = "dox"))]
123    pub fn set_hotspot(&self, hot_x: i32, hot_y: i32) {
124        unsafe {
125            gdk_sys::gdk_drag_context_set_hotspot(self.to_glib_none().0, hot_x, hot_y);
126        }
127    }
128
129    #[cfg(any(feature = "v3_20", feature = "dox"))]
130    pub fn connect_action_changed<F: Fn(&DragContext, DragAction) + 'static>(
131        &self,
132        f: F,
133    ) -> SignalHandlerId {
134        unsafe extern "C" fn action_changed_trampoline<
135            F: Fn(&DragContext, DragAction) + 'static,
136        >(
137            this: *mut gdk_sys::GdkDragContext,
138            action: gdk_sys::GdkDragAction,
139            f: glib_sys::gpointer,
140        ) {
141            let f: &F = &*(f as *const F);
142            f(&from_glib_borrow(this), from_glib(action))
143        }
144        unsafe {
145            let f: Box_<F> = Box_::new(f);
146            connect_raw(
147                self.as_ptr() as *mut _,
148                b"action-changed\0".as_ptr() as *const _,
149                Some(transmute(action_changed_trampoline::<F> as usize)),
150                Box_::into_raw(f),
151            )
152        }
153    }
154
155    #[cfg(any(feature = "v3_20", feature = "dox"))]
156    pub fn connect_cancel<F: Fn(&DragContext, DragCancelReason) + 'static>(
157        &self,
158        f: F,
159    ) -> SignalHandlerId {
160        unsafe extern "C" fn cancel_trampoline<F: Fn(&DragContext, DragCancelReason) + 'static>(
161            this: *mut gdk_sys::GdkDragContext,
162            reason: gdk_sys::GdkDragCancelReason,
163            f: glib_sys::gpointer,
164        ) {
165            let f: &F = &*(f as *const F);
166            f(&from_glib_borrow(this), from_glib(reason))
167        }
168        unsafe {
169            let f: Box_<F> = Box_::new(f);
170            connect_raw(
171                self.as_ptr() as *mut _,
172                b"cancel\0".as_ptr() as *const _,
173                Some(transmute(cancel_trampoline::<F> as usize)),
174                Box_::into_raw(f),
175            )
176        }
177    }
178
179    #[cfg(any(feature = "v3_20", feature = "dox"))]
180    pub fn connect_dnd_finished<F: Fn(&DragContext) + 'static>(&self, f: F) -> SignalHandlerId {
181        unsafe extern "C" fn dnd_finished_trampoline<F: Fn(&DragContext) + 'static>(
182            this: *mut gdk_sys::GdkDragContext,
183            f: glib_sys::gpointer,
184        ) {
185            let f: &F = &*(f as *const F);
186            f(&from_glib_borrow(this))
187        }
188        unsafe {
189            let f: Box_<F> = Box_::new(f);
190            connect_raw(
191                self.as_ptr() as *mut _,
192                b"dnd-finished\0".as_ptr() as *const _,
193                Some(transmute(dnd_finished_trampoline::<F> as usize)),
194                Box_::into_raw(f),
195            )
196        }
197    }
198
199    #[cfg(any(feature = "v3_20", feature = "dox"))]
200    pub fn connect_drop_performed<F: Fn(&DragContext, i32) + 'static>(
201        &self,
202        f: F,
203    ) -> SignalHandlerId {
204        unsafe extern "C" fn drop_performed_trampoline<F: Fn(&DragContext, i32) + 'static>(
205            this: *mut gdk_sys::GdkDragContext,
206            time: libc::c_int,
207            f: glib_sys::gpointer,
208        ) {
209            let f: &F = &*(f as *const F);
210            f(&from_glib_borrow(this), time)
211        }
212        unsafe {
213            let f: Box_<F> = Box_::new(f);
214            connect_raw(
215                self.as_ptr() as *mut _,
216                b"drop-performed\0".as_ptr() as *const _,
217                Some(transmute(drop_performed_trampoline::<F> as usize)),
218                Box_::into_raw(f),
219            )
220        }
221    }
222}
223
224impl fmt::Display for DragContext {
225    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
226        write!(f, "DragContext")
227    }
228}