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 /// 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
163/// Trait containing all [`struct@Drag`] methods.
164///
165/// # Implementors
166///
167/// [`Drag`][struct@crate::Drag]
168pub trait DragExt: IsA<Drag> + 'static {
169 /// Informs GDK that the drop ended.
170 ///
171 /// Passing [`false`] for @success may trigger a drag cancellation
172 /// animation.
173 ///
174 /// This function is called by the drag source, and should be the
175 /// last call before dropping the reference to the @self.
176 ///
177 /// The [`Drag`][crate::Drag] will only take the first [`drop_done()`][Self::drop_done()]
178 /// call as effective, if this function is called multiple times,
179 /// all subsequent calls will be ignored.
180 /// ## `success`
181 /// whether the drag was ultimatively successful
182 #[doc(alias = "gdk_drag_drop_done")]
183 fn drop_done(&self, success: bool) {
184 unsafe {
185 ffi::gdk_drag_drop_done(self.as_ref().to_glib_none().0, success.into_glib());
186 }
187 }
188
189 /// Determines the bitmask of possible actions proposed by the source.
190 ///
191 /// # Returns
192 ///
193 /// the [`DragAction`][crate::DragAction] flags
194 #[doc(alias = "gdk_drag_get_actions")]
195 #[doc(alias = "get_actions")]
196 fn actions(&self) -> DragAction {
197 unsafe { from_glib(ffi::gdk_drag_get_actions(self.as_ref().to_glib_none().0)) }
198 }
199
200 /// Returns the [`ContentProvider`][crate::ContentProvider] associated to the [`Drag`][crate::Drag] object.
201 ///
202 /// # Returns
203 ///
204 /// The [`ContentProvider`][crate::ContentProvider] associated to @self.
205 #[doc(alias = "gdk_drag_get_content")]
206 #[doc(alias = "get_content")]
207 fn content(&self) -> ContentProvider {
208 unsafe { from_glib_none(ffi::gdk_drag_get_content(self.as_ref().to_glib_none().0)) }
209 }
210
211 /// Returns the [`Device`][crate::Device] associated to the [`Drag`][crate::Drag] object.
212 ///
213 /// # Returns
214 ///
215 /// The [`Device`][crate::Device] associated to @self.
216 #[doc(alias = "gdk_drag_get_device")]
217 #[doc(alias = "get_device")]
218 fn device(&self) -> Device {
219 unsafe { from_glib_none(ffi::gdk_drag_get_device(self.as_ref().to_glib_none().0)) }
220 }
221
222 /// Gets the [`Display`][crate::Display] that the drag object was created for.
223 ///
224 /// # Returns
225 ///
226 /// a [`Display`][crate::Display]
227 #[doc(alias = "gdk_drag_get_display")]
228 #[doc(alias = "get_display")]
229 fn display(&self) -> Display {
230 unsafe { from_glib_none(ffi::gdk_drag_get_display(self.as_ref().to_glib_none().0)) }
231 }
232
233 /// Returns the surface on which the drag icon should be rendered
234 /// during the drag operation.
235 ///
236 /// Note that the surface may not be available until the drag operation
237 /// has begun. GDK will move the surface in accordance with the ongoing
238 /// drag operation. The surface is owned by @self and will be destroyed
239 /// when the drag operation is over.
240 ///
241 /// # Returns
242 ///
243 /// the drag surface
244 #[doc(alias = "gdk_drag_get_drag_surface")]
245 #[doc(alias = "get_drag_surface")]
246 fn drag_surface(&self) -> Option<Surface> {
247 unsafe {
248 from_glib_none(ffi::gdk_drag_get_drag_surface(
249 self.as_ref().to_glib_none().0,
250 ))
251 }
252 }
253
254 /// Retrieves the formats supported by this [`Drag`][crate::Drag] object.
255 ///
256 /// # Returns
257 ///
258 /// a [`ContentFormats`][crate::ContentFormats]
259 #[doc(alias = "gdk_drag_get_formats")]
260 #[doc(alias = "get_formats")]
261 fn formats(&self) -> ContentFormats {
262 unsafe { from_glib_none(ffi::gdk_drag_get_formats(self.as_ref().to_glib_none().0)) }
263 }
264
265 /// Determines the action chosen by the drag destination.
266 ///
267 /// # Returns
268 ///
269 /// a [`DragAction`][crate::DragAction] value
270 #[doc(alias = "gdk_drag_get_selected_action")]
271 #[doc(alias = "get_selected_action")]
272 #[doc(alias = "selected-action")]
273 fn selected_action(&self) -> DragAction {
274 unsafe {
275 from_glib(ffi::gdk_drag_get_selected_action(
276 self.as_ref().to_glib_none().0,
277 ))
278 }
279 }
280
281 /// Returns the [`Surface`][crate::Surface] where the drag originates.
282 ///
283 /// # Returns
284 ///
285 /// The [`Surface`][crate::Surface] where the drag originates
286 #[doc(alias = "gdk_drag_get_surface")]
287 #[doc(alias = "get_surface")]
288 fn surface(&self) -> Surface {
289 unsafe { from_glib_none(ffi::gdk_drag_get_surface(self.as_ref().to_glib_none().0)) }
290 }
291
292 /// Sets the position of the drag surface that will be kept
293 /// under the cursor hotspot.
294 ///
295 /// Initially, the hotspot is at the top left corner of the drag surface.
296 /// ## `hot_x`
297 /// x coordinate of the drag surface hotspot
298 /// ## `hot_y`
299 /// y coordinate of the drag surface hotspot
300 #[doc(alias = "gdk_drag_set_hotspot")]
301 fn set_hotspot(&self, hot_x: i32, hot_y: i32) {
302 unsafe {
303 ffi::gdk_drag_set_hotspot(self.as_ref().to_glib_none().0, hot_x, hot_y);
304 }
305 }
306
307 /// The possible actions of this drag.
308 fn set_actions(&self, actions: DragAction) {
309 ObjectExt::set_property(self.as_ref(), "actions", actions)
310 }
311
312 /// The currently selected action of the drag.
313 #[doc(alias = "selected-action")]
314 fn set_selected_action(&self, selected_action: DragAction) {
315 ObjectExt::set_property(self.as_ref(), "selected-action", selected_action)
316 }
317
318 /// Emitted when the drag operation is cancelled.
319 /// ## `reason`
320 /// The reason the drag was cancelled
321 #[doc(alias = "cancel")]
322 fn connect_cancel<F: Fn(&Self, DragCancelReason) + 'static>(&self, f: F) -> SignalHandlerId {
323 unsafe extern "C" fn cancel_trampoline<
324 P: IsA<Drag>,
325 F: Fn(&P, DragCancelReason) + 'static,
326 >(
327 this: *mut ffi::GdkDrag,
328 reason: ffi::GdkDragCancelReason,
329 f: glib::ffi::gpointer,
330 ) {
331 let f: &F = &*(f as *const F);
332 f(
333 Drag::from_glib_borrow(this).unsafe_cast_ref(),
334 from_glib(reason),
335 )
336 }
337 unsafe {
338 let f: Box_<F> = Box_::new(f);
339 connect_raw(
340 self.as_ptr() as *mut _,
341 c"cancel".as_ptr() as *const _,
342 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
343 cancel_trampoline::<Self, F> as *const (),
344 )),
345 Box_::into_raw(f),
346 )
347 }
348 }
349
350 /// Emitted when the destination side has finished reading all data.
351 ///
352 /// The drag object can now free all miscellaneous data.
353 #[doc(alias = "dnd-finished")]
354 fn connect_dnd_finished<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
355 unsafe extern "C" fn dnd_finished_trampoline<P: IsA<Drag>, F: Fn(&P) + 'static>(
356 this: *mut ffi::GdkDrag,
357 f: glib::ffi::gpointer,
358 ) {
359 let f: &F = &*(f as *const F);
360 f(Drag::from_glib_borrow(this).unsafe_cast_ref())
361 }
362 unsafe {
363 let f: Box_<F> = Box_::new(f);
364 connect_raw(
365 self.as_ptr() as *mut _,
366 c"dnd-finished".as_ptr() as *const _,
367 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
368 dnd_finished_trampoline::<Self, F> as *const (),
369 )),
370 Box_::into_raw(f),
371 )
372 }
373 }
374
375 /// Emitted when the drop operation is performed on an accepting client.
376 #[doc(alias = "drop-performed")]
377 fn connect_drop_performed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
378 unsafe extern "C" fn drop_performed_trampoline<P: IsA<Drag>, F: Fn(&P) + 'static>(
379 this: *mut ffi::GdkDrag,
380 f: glib::ffi::gpointer,
381 ) {
382 let f: &F = &*(f as *const F);
383 f(Drag::from_glib_borrow(this).unsafe_cast_ref())
384 }
385 unsafe {
386 let f: Box_<F> = Box_::new(f);
387 connect_raw(
388 self.as_ptr() as *mut _,
389 c"drop-performed".as_ptr() as *const _,
390 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
391 drop_performed_trampoline::<Self, F> as *const (),
392 )),
393 Box_::into_raw(f),
394 )
395 }
396 }
397
398 #[doc(alias = "actions")]
399 fn connect_actions_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
400 unsafe extern "C" fn notify_actions_trampoline<P: IsA<Drag>, F: Fn(&P) + 'static>(
401 this: *mut ffi::GdkDrag,
402 _param_spec: glib::ffi::gpointer,
403 f: glib::ffi::gpointer,
404 ) {
405 let f: &F = &*(f as *const F);
406 f(Drag::from_glib_borrow(this).unsafe_cast_ref())
407 }
408 unsafe {
409 let f: Box_<F> = Box_::new(f);
410 connect_raw(
411 self.as_ptr() as *mut _,
412 c"notify::actions".as_ptr() as *const _,
413 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
414 notify_actions_trampoline::<Self, F> as *const (),
415 )),
416 Box_::into_raw(f),
417 )
418 }
419 }
420
421 #[doc(alias = "display")]
422 fn connect_display_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
423 unsafe extern "C" fn notify_display_trampoline<P: IsA<Drag>, F: Fn(&P) + 'static>(
424 this: *mut ffi::GdkDrag,
425 _param_spec: glib::ffi::gpointer,
426 f: glib::ffi::gpointer,
427 ) {
428 let f: &F = &*(f as *const F);
429 f(Drag::from_glib_borrow(this).unsafe_cast_ref())
430 }
431 unsafe {
432 let f: Box_<F> = Box_::new(f);
433 connect_raw(
434 self.as_ptr() as *mut _,
435 c"notify::display".as_ptr() as *const _,
436 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
437 notify_display_trampoline::<Self, F> as *const (),
438 )),
439 Box_::into_raw(f),
440 )
441 }
442 }
443
444 #[doc(alias = "selected-action")]
445 fn connect_selected_action_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
446 unsafe extern "C" fn notify_selected_action_trampoline<
447 P: IsA<Drag>,
448 F: Fn(&P) + 'static,
449 >(
450 this: *mut ffi::GdkDrag,
451 _param_spec: glib::ffi::gpointer,
452 f: glib::ffi::gpointer,
453 ) {
454 let f: &F = &*(f as *const F);
455 f(Drag::from_glib_borrow(this).unsafe_cast_ref())
456 }
457 unsafe {
458 let f: Box_<F> = Box_::new(f);
459 connect_raw(
460 self.as_ptr() as *mut _,
461 c"notify::selected-action".as_ptr() as *const _,
462 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
463 notify_selected_action_trampoline::<Self, F> as *const (),
464 )),
465 Box_::into_raw(f),
466 )
467 }
468 }
469}
470
471impl<O: IsA<Drag>> DragExt for O {}