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 /// The [`Drag`][crate::Drag] object represents the source of an ongoing DND operation.
18 ///
19 /// A [`Drag`][crate::Drag] is created when a drag is started, and stays alive for duration of
20 /// the DND operation. After a drag has been started with [`begin()`][Self::begin()],
21 /// the caller gets informed about the status of the ongoing drag operation
22 /// with signals on the [`Drag`][crate::Drag] object.
23 ///
24 /// GTK provides a higher level abstraction based on top of these functions,
25 /// and so they are not normally needed in GTK applications. See the
26 /// "Drag and Drop" section of the GTK documentation for more information.
27 ///
28 /// This is an Abstract Base Class, you cannot instantiate it.
29 ///
30 /// ## Properties
31 ///
32 ///
33 /// #### `actions`
34 /// The possible actions of this drag.
35 ///
36 /// Readable | Writeable
37 ///
38 ///
39 /// #### `content`
40 /// The [`ContentProvider`][crate::ContentProvider].
41 ///
42 /// Readable | Writeable | Construct Only
43 ///
44 ///
45 /// #### `device`
46 /// The [`Device`][crate::Device] that is performing the drag.
47 ///
48 /// Readable | Writeable | Construct Only
49 ///
50 ///
51 /// #### `display`
52 /// The [`Display`][crate::Display] that the drag belongs to.
53 ///
54 /// Readable
55 ///
56 ///
57 /// #### `formats`
58 /// The possible formats that the drag can provide its data in.
59 ///
60 /// Readable | Writeable | Construct Only
61 ///
62 ///
63 /// #### `selected-action`
64 /// The currently selected action of the drag.
65 ///
66 /// Readable | Writeable
67 ///
68 ///
69 /// #### `surface`
70 /// The surface where the drag originates.
71 ///
72 /// Readable | Writeable | Construct Only
73 ///
74 /// ## Signals
75 ///
76 ///
77 /// #### `cancel`
78 /// Emitted when the drag operation is cancelled.
79 ///
80 ///
81 ///
82 ///
83 /// #### `dnd-finished`
84 /// Emitted when the destination side has finished reading all data.
85 ///
86 /// The drag object can now free all miscellaneous data.
87 ///
88 ///
89 ///
90 ///
91 /// #### `drop-performed`
92 /// Emitted when the drop operation is performed on an accepting client.
93 ///
94 ///
95 ///
96 /// # Implements
97 ///
98 /// [`DragExt`][trait@crate::prelude::DragExt]
99 #[doc(alias = "GdkDrag")]
100 pub struct Drag(Object<ffi::GdkDrag>);
101
102 match fn {
103 type_ => || ffi::gdk_drag_get_type(),
104 }
105}
106
107impl Drag {
108 pub const NONE: Option<&'static Drag> = None;
109
110 /// Starts a drag and creates a new drag context for it.
111 ///
112 /// This function is called by the drag source. After this call, you
113 /// probably want to set up the drag icon using the surface returned
114 /// by [`DragExt::drag_surface()`][crate::prelude::DragExt::drag_surface()].
115 ///
116 /// This function returns a reference to the [`Drag`][crate::Drag] object,
117 /// but GTK keeps its own reference as well, as long as the DND operation
118 /// is going on.
119 ///
120 /// Note: if @actions include [`DragAction::MOVE`][crate::DragAction::MOVE], you need to listen for
121 /// the [`dnd-finished`][struct@crate::Drag#dnd-finished] signal and delete the data at
122 /// the source if [`DragExt::selected_action()`][crate::prelude::DragExt::selected_action()] returns
123 /// [`DragAction::MOVE`][crate::DragAction::MOVE].
124 /// ## `surface`
125 /// the source surface for this drag
126 /// ## `device`
127 /// the device that controls this drag
128 /// ## `content`
129 /// the offered content
130 /// ## `actions`
131 /// the actions supported by this drag
132 /// ## `dx`
133 /// the x offset to @device's position where the drag nominally started
134 /// ## `dy`
135 /// the y offset to @device's position where the drag nominally started
136 ///
137 /// # Returns
138 ///
139 /// a newly created [`Drag`][crate::Drag]
140 #[doc(alias = "gdk_drag_begin")]
141 pub fn begin(
142 surface: &impl IsA<Surface>,
143 device: &impl IsA<Device>,
144 content: &impl IsA<ContentProvider>,
145 actions: DragAction,
146 dx: f64,
147 dy: f64,
148 ) -> Option<Drag> {
149 skip_assert_initialized!();
150 unsafe {
151 from_glib_full(ffi::gdk_drag_begin(
152 surface.as_ref().to_glib_none().0,
153 device.as_ref().to_glib_none().0,
154 content.as_ref().to_glib_none().0,
155 actions.into_glib(),
156 dx,
157 dy,
158 ))
159 }
160 }
161}
162
163mod sealed {
164 pub trait Sealed {}
165 impl<T: super::IsA<super::Drag>> Sealed for T {}
166}
167
168/// Trait containing all [`struct@Drag`] methods.
169///
170/// # Implementors
171///
172/// [`Drag`][struct@crate::Drag]
173pub trait DragExt: IsA<Drag> + sealed::Sealed + 'static {
174 /// Informs GDK that the drop ended.
175 ///
176 /// Passing [`false`] for @success may trigger a drag cancellation
177 /// animation.
178 ///
179 /// This function is called by the drag source, and should be the
180 /// last call before dropping the reference to the @self.
181 ///
182 /// The [`Drag`][crate::Drag] will only take the first [`drop_done()`][Self::drop_done()]
183 /// call as effective, if this function is called multiple times,
184 /// all subsequent calls will be ignored.
185 /// ## `success`
186 /// whether the drag was ultimatively successful
187 #[doc(alias = "gdk_drag_drop_done")]
188 fn drop_done(&self, success: bool) {
189 unsafe {
190 ffi::gdk_drag_drop_done(self.as_ref().to_glib_none().0, success.into_glib());
191 }
192 }
193
194 /// Determines the bitmask of possible actions proposed by the source.
195 ///
196 /// # Returns
197 ///
198 /// the [`DragAction`][crate::DragAction] flags
199 #[doc(alias = "gdk_drag_get_actions")]
200 #[doc(alias = "get_actions")]
201 fn actions(&self) -> DragAction {
202 unsafe { from_glib(ffi::gdk_drag_get_actions(self.as_ref().to_glib_none().0)) }
203 }
204
205 /// Returns the [`ContentProvider`][crate::ContentProvider] associated to the [`Drag`][crate::Drag] object.
206 ///
207 /// # Returns
208 ///
209 /// The [`ContentProvider`][crate::ContentProvider] associated to @self.
210 #[doc(alias = "gdk_drag_get_content")]
211 #[doc(alias = "get_content")]
212 fn content(&self) -> ContentProvider {
213 unsafe { from_glib_none(ffi::gdk_drag_get_content(self.as_ref().to_glib_none().0)) }
214 }
215
216 /// Returns the [`Device`][crate::Device] associated to the [`Drag`][crate::Drag] object.
217 ///
218 /// # Returns
219 ///
220 /// The [`Device`][crate::Device] associated to @self.
221 #[doc(alias = "gdk_drag_get_device")]
222 #[doc(alias = "get_device")]
223 fn device(&self) -> Device {
224 unsafe { from_glib_none(ffi::gdk_drag_get_device(self.as_ref().to_glib_none().0)) }
225 }
226
227 /// Gets the [`Display`][crate::Display] that the drag object was created for.
228 ///
229 /// # Returns
230 ///
231 /// a [`Display`][crate::Display]
232 #[doc(alias = "gdk_drag_get_display")]
233 #[doc(alias = "get_display")]
234 fn display(&self) -> Display {
235 unsafe { from_glib_none(ffi::gdk_drag_get_display(self.as_ref().to_glib_none().0)) }
236 }
237
238 /// Returns the surface on which the drag icon should be rendered
239 /// during the drag operation.
240 ///
241 /// Note that the surface may not be available until the drag operation
242 /// has begun. GDK will move the surface in accordance with the ongoing
243 /// drag operation. The surface is owned by @self and will be destroyed
244 /// when the drag operation is over.
245 ///
246 /// # Returns
247 ///
248 /// the drag surface
249 #[doc(alias = "gdk_drag_get_drag_surface")]
250 #[doc(alias = "get_drag_surface")]
251 fn drag_surface(&self) -> Option<Surface> {
252 unsafe {
253 from_glib_none(ffi::gdk_drag_get_drag_surface(
254 self.as_ref().to_glib_none().0,
255 ))
256 }
257 }
258
259 /// Retrieves the formats supported by this [`Drag`][crate::Drag] object.
260 ///
261 /// # Returns
262 ///
263 /// a [`ContentFormats`][crate::ContentFormats]
264 #[doc(alias = "gdk_drag_get_formats")]
265 #[doc(alias = "get_formats")]
266 fn formats(&self) -> ContentFormats {
267 unsafe { from_glib_none(ffi::gdk_drag_get_formats(self.as_ref().to_glib_none().0)) }
268 }
269
270 /// Determines the action chosen by the drag destination.
271 ///
272 /// # Returns
273 ///
274 /// a [`DragAction`][crate::DragAction] value
275 #[doc(alias = "gdk_drag_get_selected_action")]
276 #[doc(alias = "get_selected_action")]
277 #[doc(alias = "selected-action")]
278 fn selected_action(&self) -> DragAction {
279 unsafe {
280 from_glib(ffi::gdk_drag_get_selected_action(
281 self.as_ref().to_glib_none().0,
282 ))
283 }
284 }
285
286 /// Returns the [`Surface`][crate::Surface] where the drag originates.
287 ///
288 /// # Returns
289 ///
290 /// The [`Surface`][crate::Surface] where the drag originates
291 #[doc(alias = "gdk_drag_get_surface")]
292 #[doc(alias = "get_surface")]
293 fn surface(&self) -> Surface {
294 unsafe { from_glib_none(ffi::gdk_drag_get_surface(self.as_ref().to_glib_none().0)) }
295 }
296
297 /// Sets the position of the drag surface that will be kept
298 /// under the cursor hotspot.
299 ///
300 /// Initially, the hotspot is at the top left corner of the drag surface.
301 /// ## `hot_x`
302 /// x coordinate of the drag surface hotspot
303 /// ## `hot_y`
304 /// y coordinate of the drag surface hotspot
305 #[doc(alias = "gdk_drag_set_hotspot")]
306 fn set_hotspot(&self, hot_x: i32, hot_y: i32) {
307 unsafe {
308 ffi::gdk_drag_set_hotspot(self.as_ref().to_glib_none().0, hot_x, hot_y);
309 }
310 }
311
312 /// The possible actions of this drag.
313 fn set_actions(&self, actions: DragAction) {
314 ObjectExt::set_property(self.as_ref(), "actions", actions)
315 }
316
317 /// The currently selected action of the drag.
318 #[doc(alias = "selected-action")]
319 fn set_selected_action(&self, selected_action: DragAction) {
320 ObjectExt::set_property(self.as_ref(), "selected-action", selected_action)
321 }
322
323 /// Emitted when the drag operation is cancelled.
324 /// ## `reason`
325 /// The reason the drag was cancelled
326 #[doc(alias = "cancel")]
327 fn connect_cancel<F: Fn(&Self, DragCancelReason) + 'static>(&self, f: F) -> SignalHandlerId {
328 unsafe extern "C" fn cancel_trampoline<
329 P: IsA<Drag>,
330 F: Fn(&P, DragCancelReason) + 'static,
331 >(
332 this: *mut ffi::GdkDrag,
333 reason: ffi::GdkDragCancelReason,
334 f: glib::ffi::gpointer,
335 ) {
336 let f: &F = &*(f as *const F);
337 f(
338 Drag::from_glib_borrow(this).unsafe_cast_ref(),
339 from_glib(reason),
340 )
341 }
342 unsafe {
343 let f: Box_<F> = Box_::new(f);
344 connect_raw(
345 self.as_ptr() as *mut _,
346 b"cancel\0".as_ptr() as *const _,
347 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
348 cancel_trampoline::<Self, F> as *const (),
349 )),
350 Box_::into_raw(f),
351 )
352 }
353 }
354
355 /// Emitted when the destination side has finished reading all data.
356 ///
357 /// The drag object can now free all miscellaneous data.
358 #[doc(alias = "dnd-finished")]
359 fn connect_dnd_finished<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
360 unsafe extern "C" fn dnd_finished_trampoline<P: IsA<Drag>, F: Fn(&P) + 'static>(
361 this: *mut ffi::GdkDrag,
362 f: glib::ffi::gpointer,
363 ) {
364 let f: &F = &*(f as *const F);
365 f(Drag::from_glib_borrow(this).unsafe_cast_ref())
366 }
367 unsafe {
368 let f: Box_<F> = Box_::new(f);
369 connect_raw(
370 self.as_ptr() as *mut _,
371 b"dnd-finished\0".as_ptr() as *const _,
372 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
373 dnd_finished_trampoline::<Self, F> as *const (),
374 )),
375 Box_::into_raw(f),
376 )
377 }
378 }
379
380 /// Emitted when the drop operation is performed on an accepting client.
381 #[doc(alias = "drop-performed")]
382 fn connect_drop_performed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
383 unsafe extern "C" fn drop_performed_trampoline<P: IsA<Drag>, F: Fn(&P) + 'static>(
384 this: *mut ffi::GdkDrag,
385 f: glib::ffi::gpointer,
386 ) {
387 let f: &F = &*(f as *const F);
388 f(Drag::from_glib_borrow(this).unsafe_cast_ref())
389 }
390 unsafe {
391 let f: Box_<F> = Box_::new(f);
392 connect_raw(
393 self.as_ptr() as *mut _,
394 b"drop-performed\0".as_ptr() as *const _,
395 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
396 drop_performed_trampoline::<Self, F> as *const (),
397 )),
398 Box_::into_raw(f),
399 )
400 }
401 }
402
403 #[doc(alias = "actions")]
404 fn connect_actions_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
405 unsafe extern "C" fn notify_actions_trampoline<P: IsA<Drag>, F: Fn(&P) + 'static>(
406 this: *mut ffi::GdkDrag,
407 _param_spec: glib::ffi::gpointer,
408 f: glib::ffi::gpointer,
409 ) {
410 let f: &F = &*(f as *const F);
411 f(Drag::from_glib_borrow(this).unsafe_cast_ref())
412 }
413 unsafe {
414 let f: Box_<F> = Box_::new(f);
415 connect_raw(
416 self.as_ptr() as *mut _,
417 b"notify::actions\0".as_ptr() as *const _,
418 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
419 notify_actions_trampoline::<Self, F> as *const (),
420 )),
421 Box_::into_raw(f),
422 )
423 }
424 }
425
426 #[doc(alias = "display")]
427 fn connect_display_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
428 unsafe extern "C" fn notify_display_trampoline<P: IsA<Drag>, F: Fn(&P) + 'static>(
429 this: *mut ffi::GdkDrag,
430 _param_spec: glib::ffi::gpointer,
431 f: glib::ffi::gpointer,
432 ) {
433 let f: &F = &*(f as *const F);
434 f(Drag::from_glib_borrow(this).unsafe_cast_ref())
435 }
436 unsafe {
437 let f: Box_<F> = Box_::new(f);
438 connect_raw(
439 self.as_ptr() as *mut _,
440 b"notify::display\0".as_ptr() as *const _,
441 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
442 notify_display_trampoline::<Self, F> as *const (),
443 )),
444 Box_::into_raw(f),
445 )
446 }
447 }
448
449 #[doc(alias = "selected-action")]
450 fn connect_selected_action_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
451 unsafe extern "C" fn notify_selected_action_trampoline<
452 P: IsA<Drag>,
453 F: Fn(&P) + 'static,
454 >(
455 this: *mut ffi::GdkDrag,
456 _param_spec: glib::ffi::gpointer,
457 f: glib::ffi::gpointer,
458 ) {
459 let f: &F = &*(f as *const F);
460 f(Drag::from_glib_borrow(this).unsafe_cast_ref())
461 }
462 unsafe {
463 let f: Box_<F> = Box_::new(f);
464 connect_raw(
465 self.as_ptr() as *mut _,
466 b"notify::selected-action\0".as_ptr() as *const _,
467 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
468 notify_selected_action_trampoline::<Self, F> as *const (),
469 )),
470 Box_::into_raw(f),
471 )
472 }
473 }
474}
475
476impl<O: IsA<Drag>> DragExt for O {}