gtk4/auto/
drop_target_async.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::{ffi, EventController, PropagationLimit, PropagationPhase};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    #[doc(alias = "GtkDropTargetAsync")]
16    pub struct DropTargetAsync(Object<ffi::GtkDropTargetAsync, ffi::GtkDropTargetAsyncClass>) @extends EventController;
17
18    match fn {
19        type_ => || ffi::gtk_drop_target_async_get_type(),
20    }
21}
22
23impl DropTargetAsync {
24    #[doc(alias = "gtk_drop_target_async_new")]
25    pub fn new(formats: Option<gdk::ContentFormats>, actions: gdk::DragAction) -> DropTargetAsync {
26        assert_initialized_main_thread!();
27        unsafe {
28            from_glib_full(ffi::gtk_drop_target_async_new(
29                formats.into_glib_ptr(),
30                actions.into_glib(),
31            ))
32        }
33    }
34
35    // rustdoc-stripper-ignore-next
36    /// Creates a new builder-pattern struct instance to construct [`DropTargetAsync`] objects.
37    ///
38    /// This method returns an instance of [`DropTargetAsyncBuilder`](crate::builders::DropTargetAsyncBuilder) which can be used to create [`DropTargetAsync`] objects.
39    pub fn builder() -> DropTargetAsyncBuilder {
40        DropTargetAsyncBuilder::new()
41    }
42
43    #[doc(alias = "gtk_drop_target_async_get_actions")]
44    #[doc(alias = "get_actions")]
45    pub fn actions(&self) -> gdk::DragAction {
46        unsafe {
47            from_glib(ffi::gtk_drop_target_async_get_actions(
48                self.to_glib_none().0,
49            ))
50        }
51    }
52
53    #[doc(alias = "gtk_drop_target_async_get_formats")]
54    #[doc(alias = "get_formats")]
55    pub fn formats(&self) -> Option<gdk::ContentFormats> {
56        unsafe {
57            from_glib_full(ffi::gtk_drop_target_async_get_formats(
58                self.to_glib_none().0,
59            ))
60        }
61    }
62
63    #[doc(alias = "gtk_drop_target_async_reject_drop")]
64    pub fn reject_drop(&self, drop: &gdk::Drop) {
65        unsafe {
66            ffi::gtk_drop_target_async_reject_drop(self.to_glib_none().0, drop.to_glib_none().0);
67        }
68    }
69
70    #[doc(alias = "gtk_drop_target_async_set_actions")]
71    #[doc(alias = "actions")]
72    pub fn set_actions(&self, actions: gdk::DragAction) {
73        unsafe {
74            ffi::gtk_drop_target_async_set_actions(self.to_glib_none().0, actions.into_glib());
75        }
76    }
77
78    #[doc(alias = "gtk_drop_target_async_set_formats")]
79    #[doc(alias = "formats")]
80    pub fn set_formats(&self, formats: Option<&gdk::ContentFormats>) {
81        unsafe {
82            ffi::gtk_drop_target_async_set_formats(self.to_glib_none().0, formats.to_glib_none().0);
83        }
84    }
85
86    #[doc(alias = "accept")]
87    pub fn connect_accept<F: Fn(&Self, &gdk::Drop) -> bool + 'static>(
88        &self,
89        f: F,
90    ) -> SignalHandlerId {
91        unsafe extern "C" fn accept_trampoline<
92            F: Fn(&DropTargetAsync, &gdk::Drop) -> bool + 'static,
93        >(
94            this: *mut ffi::GtkDropTargetAsync,
95            drop: *mut gdk::ffi::GdkDrop,
96            f: glib::ffi::gpointer,
97        ) -> glib::ffi::gboolean {
98            let f: &F = &*(f as *const F);
99            f(&from_glib_borrow(this), &from_glib_borrow(drop)).into_glib()
100        }
101        unsafe {
102            let f: Box_<F> = Box_::new(f);
103            connect_raw(
104                self.as_ptr() as *mut _,
105                c"accept".as_ptr() as *const _,
106                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
107                    accept_trampoline::<F> as *const (),
108                )),
109                Box_::into_raw(f),
110            )
111        }
112    }
113
114    #[doc(alias = "drag-enter")]
115    pub fn connect_drag_enter<F: Fn(&Self, &gdk::Drop, f64, f64) -> gdk::DragAction + 'static>(
116        &self,
117        f: F,
118    ) -> SignalHandlerId {
119        unsafe extern "C" fn drag_enter_trampoline<
120            F: Fn(&DropTargetAsync, &gdk::Drop, f64, f64) -> gdk::DragAction + 'static,
121        >(
122            this: *mut ffi::GtkDropTargetAsync,
123            drop: *mut gdk::ffi::GdkDrop,
124            x: std::ffi::c_double,
125            y: std::ffi::c_double,
126            f: glib::ffi::gpointer,
127        ) -> gdk::ffi::GdkDragAction {
128            let f: &F = &*(f as *const F);
129            f(&from_glib_borrow(this), &from_glib_borrow(drop), x, y).into_glib()
130        }
131        unsafe {
132            let f: Box_<F> = Box_::new(f);
133            connect_raw(
134                self.as_ptr() as *mut _,
135                c"drag-enter".as_ptr() as *const _,
136                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
137                    drag_enter_trampoline::<F> as *const (),
138                )),
139                Box_::into_raw(f),
140            )
141        }
142    }
143
144    #[doc(alias = "drag-leave")]
145    pub fn connect_drag_leave<F: Fn(&Self, &gdk::Drop) + 'static>(&self, f: F) -> SignalHandlerId {
146        unsafe extern "C" fn drag_leave_trampoline<
147            F: Fn(&DropTargetAsync, &gdk::Drop) + 'static,
148        >(
149            this: *mut ffi::GtkDropTargetAsync,
150            drop: *mut gdk::ffi::GdkDrop,
151            f: glib::ffi::gpointer,
152        ) {
153            let f: &F = &*(f as *const F);
154            f(&from_glib_borrow(this), &from_glib_borrow(drop))
155        }
156        unsafe {
157            let f: Box_<F> = Box_::new(f);
158            connect_raw(
159                self.as_ptr() as *mut _,
160                c"drag-leave".as_ptr() as *const _,
161                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
162                    drag_leave_trampoline::<F> as *const (),
163                )),
164                Box_::into_raw(f),
165            )
166        }
167    }
168
169    #[doc(alias = "drag-motion")]
170    pub fn connect_drag_motion<F: Fn(&Self, &gdk::Drop, f64, f64) -> gdk::DragAction + 'static>(
171        &self,
172        f: F,
173    ) -> SignalHandlerId {
174        unsafe extern "C" fn drag_motion_trampoline<
175            F: Fn(&DropTargetAsync, &gdk::Drop, f64, f64) -> gdk::DragAction + 'static,
176        >(
177            this: *mut ffi::GtkDropTargetAsync,
178            drop: *mut gdk::ffi::GdkDrop,
179            x: std::ffi::c_double,
180            y: std::ffi::c_double,
181            f: glib::ffi::gpointer,
182        ) -> gdk::ffi::GdkDragAction {
183            let f: &F = &*(f as *const F);
184            f(&from_glib_borrow(this), &from_glib_borrow(drop), x, y).into_glib()
185        }
186        unsafe {
187            let f: Box_<F> = Box_::new(f);
188            connect_raw(
189                self.as_ptr() as *mut _,
190                c"drag-motion".as_ptr() as *const _,
191                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
192                    drag_motion_trampoline::<F> as *const (),
193                )),
194                Box_::into_raw(f),
195            )
196        }
197    }
198
199    #[doc(alias = "drop")]
200    pub fn connect_drop<F: Fn(&Self, &gdk::Drop, f64, f64) -> bool + 'static>(
201        &self,
202        f: F,
203    ) -> SignalHandlerId {
204        unsafe extern "C" fn drop_trampoline<
205            F: Fn(&DropTargetAsync, &gdk::Drop, f64, f64) -> bool + 'static,
206        >(
207            this: *mut ffi::GtkDropTargetAsync,
208            drop: *mut gdk::ffi::GdkDrop,
209            x: std::ffi::c_double,
210            y: std::ffi::c_double,
211            f: glib::ffi::gpointer,
212        ) -> glib::ffi::gboolean {
213            let f: &F = &*(f as *const F);
214            f(&from_glib_borrow(this), &from_glib_borrow(drop), x, y).into_glib()
215        }
216        unsafe {
217            let f: Box_<F> = Box_::new(f);
218            connect_raw(
219                self.as_ptr() as *mut _,
220                c"drop".as_ptr() as *const _,
221                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
222                    drop_trampoline::<F> as *const (),
223                )),
224                Box_::into_raw(f),
225            )
226        }
227    }
228
229    #[doc(alias = "actions")]
230    pub fn connect_actions_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
231        unsafe extern "C" fn notify_actions_trampoline<F: Fn(&DropTargetAsync) + 'static>(
232            this: *mut ffi::GtkDropTargetAsync,
233            _param_spec: glib::ffi::gpointer,
234            f: glib::ffi::gpointer,
235        ) {
236            let f: &F = &*(f as *const F);
237            f(&from_glib_borrow(this))
238        }
239        unsafe {
240            let f: Box_<F> = Box_::new(f);
241            connect_raw(
242                self.as_ptr() as *mut _,
243                c"notify::actions".as_ptr() as *const _,
244                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
245                    notify_actions_trampoline::<F> as *const (),
246                )),
247                Box_::into_raw(f),
248            )
249        }
250    }
251
252    #[doc(alias = "formats")]
253    pub fn connect_formats_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
254        unsafe extern "C" fn notify_formats_trampoline<F: Fn(&DropTargetAsync) + 'static>(
255            this: *mut ffi::GtkDropTargetAsync,
256            _param_spec: glib::ffi::gpointer,
257            f: glib::ffi::gpointer,
258        ) {
259            let f: &F = &*(f as *const F);
260            f(&from_glib_borrow(this))
261        }
262        unsafe {
263            let f: Box_<F> = Box_::new(f);
264            connect_raw(
265                self.as_ptr() as *mut _,
266                c"notify::formats".as_ptr() as *const _,
267                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
268                    notify_formats_trampoline::<F> as *const (),
269                )),
270                Box_::into_raw(f),
271            )
272        }
273    }
274}
275
276impl Default for DropTargetAsync {
277    fn default() -> Self {
278        glib::object::Object::new::<Self>()
279    }
280}
281
282// rustdoc-stripper-ignore-next
283/// A [builder-pattern] type to construct [`DropTargetAsync`] objects.
284///
285/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
286#[must_use = "The builder must be built to be used"]
287pub struct DropTargetAsyncBuilder {
288    builder: glib::object::ObjectBuilder<'static, DropTargetAsync>,
289}
290
291impl DropTargetAsyncBuilder {
292    fn new() -> Self {
293        Self {
294            builder: glib::object::Object::builder(),
295        }
296    }
297
298    pub fn actions(self, actions: gdk::DragAction) -> Self {
299        Self {
300            builder: self.builder.property("actions", actions),
301        }
302    }
303
304    pub fn formats(self, formats: &gdk::ContentFormats) -> Self {
305        Self {
306            builder: self.builder.property("formats", formats.clone()),
307        }
308    }
309
310    pub fn name(self, name: impl Into<glib::GString>) -> Self {
311        Self {
312            builder: self.builder.property("name", name.into()),
313        }
314    }
315
316    pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
317        Self {
318            builder: self
319                .builder
320                .property("propagation-limit", propagation_limit),
321        }
322    }
323
324    pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
325        Self {
326            builder: self
327                .builder
328                .property("propagation-phase", propagation_phase),
329        }
330    }
331
332    // rustdoc-stripper-ignore-next
333    /// Build the [`DropTargetAsync`].
334    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
335    pub fn build(self) -> DropTargetAsync {
336        assert_initialized_main_thread!();
337        self.builder.build()
338    }
339}