gtk4/auto/
drop_target.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#![allow(deprecated)]
5
6use crate::{ffi, EventController, PropagationLimit, PropagationPhase};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{connect_raw, SignalHandlerId},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    #[doc(alias = "GtkDropTarget")]
17    pub struct DropTarget(Object<ffi::GtkDropTarget, ffi::GtkDropTargetClass>) @extends EventController;
18
19    match fn {
20        type_ => || ffi::gtk_drop_target_get_type(),
21    }
22}
23
24impl DropTarget {
25    #[doc(alias = "gtk_drop_target_new")]
26    pub fn new(type_: glib::types::Type, actions: gdk::DragAction) -> DropTarget {
27        assert_initialized_main_thread!();
28        unsafe {
29            from_glib_full(ffi::gtk_drop_target_new(
30                type_.into_glib(),
31                actions.into_glib(),
32            ))
33        }
34    }
35
36    // rustdoc-stripper-ignore-next
37    /// Creates a new builder-pattern struct instance to construct [`DropTarget`] objects.
38    ///
39    /// This method returns an instance of [`DropTargetBuilder`](crate::builders::DropTargetBuilder) which can be used to create [`DropTarget`] objects.
40    pub fn builder() -> DropTargetBuilder {
41        DropTargetBuilder::new()
42    }
43
44    #[doc(alias = "gtk_drop_target_get_actions")]
45    #[doc(alias = "get_actions")]
46    pub fn actions(&self) -> gdk::DragAction {
47        unsafe { from_glib(ffi::gtk_drop_target_get_actions(self.to_glib_none().0)) }
48    }
49
50    #[cfg(feature = "v4_4")]
51    #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
52    #[doc(alias = "gtk_drop_target_get_current_drop")]
53    #[doc(alias = "get_current_drop")]
54    #[doc(alias = "current-drop")]
55    pub fn current_drop(&self) -> Option<gdk::Drop> {
56        unsafe { from_glib_none(ffi::gtk_drop_target_get_current_drop(self.to_glib_none().0)) }
57    }
58
59    #[cfg_attr(feature = "v4_4", deprecated = "Since 4.4")]
60    #[allow(deprecated)]
61    #[doc(alias = "gtk_drop_target_get_drop")]
62    #[doc(alias = "get_drop")]
63    pub fn drop(&self) -> Option<gdk::Drop> {
64        unsafe { from_glib_none(ffi::gtk_drop_target_get_drop(self.to_glib_none().0)) }
65    }
66
67    #[doc(alias = "gtk_drop_target_get_formats")]
68    #[doc(alias = "get_formats")]
69    pub fn formats(&self) -> Option<gdk::ContentFormats> {
70        unsafe { from_glib_none(ffi::gtk_drop_target_get_formats(self.to_glib_none().0)) }
71    }
72
73    #[doc(alias = "gtk_drop_target_get_preload")]
74    #[doc(alias = "get_preload")]
75    #[doc(alias = "preload")]
76    pub fn is_preload(&self) -> bool {
77        unsafe { from_glib(ffi::gtk_drop_target_get_preload(self.to_glib_none().0)) }
78    }
79
80    #[doc(alias = "gtk_drop_target_get_value")]
81    #[doc(alias = "get_value")]
82    pub fn value(&self) -> Option<glib::Value> {
83        unsafe { from_glib_none(ffi::gtk_drop_target_get_value(self.to_glib_none().0)) }
84    }
85
86    #[doc(alias = "gtk_drop_target_reject")]
87    pub fn reject(&self) {
88        unsafe {
89            ffi::gtk_drop_target_reject(self.to_glib_none().0);
90        }
91    }
92
93    #[doc(alias = "gtk_drop_target_set_actions")]
94    #[doc(alias = "actions")]
95    pub fn set_actions(&self, actions: gdk::DragAction) {
96        unsafe {
97            ffi::gtk_drop_target_set_actions(self.to_glib_none().0, actions.into_glib());
98        }
99    }
100
101    #[doc(alias = "gtk_drop_target_set_preload")]
102    #[doc(alias = "preload")]
103    pub fn set_preload(&self, preload: bool) {
104        unsafe {
105            ffi::gtk_drop_target_set_preload(self.to_glib_none().0, preload.into_glib());
106        }
107    }
108
109    #[doc(alias = "accept")]
110    pub fn connect_accept<F: Fn(&Self, &gdk::Drop) -> bool + 'static>(
111        &self,
112        f: F,
113    ) -> SignalHandlerId {
114        unsafe extern "C" fn accept_trampoline<F: Fn(&DropTarget, &gdk::Drop) -> bool + 'static>(
115            this: *mut ffi::GtkDropTarget,
116            drop: *mut gdk::ffi::GdkDrop,
117            f: glib::ffi::gpointer,
118        ) -> glib::ffi::gboolean {
119            let f: &F = &*(f as *const F);
120            f(&from_glib_borrow(this), &from_glib_borrow(drop)).into_glib()
121        }
122        unsafe {
123            let f: Box_<F> = Box_::new(f);
124            connect_raw(
125                self.as_ptr() as *mut _,
126                c"accept".as_ptr() as *const _,
127                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
128                    accept_trampoline::<F> as *const (),
129                )),
130                Box_::into_raw(f),
131            )
132        }
133    }
134
135    #[doc(alias = "enter")]
136    pub fn connect_enter<F: Fn(&Self, f64, f64) -> gdk::DragAction + 'static>(
137        &self,
138        f: F,
139    ) -> SignalHandlerId {
140        unsafe extern "C" fn enter_trampoline<
141            F: Fn(&DropTarget, f64, f64) -> gdk::DragAction + 'static,
142        >(
143            this: *mut ffi::GtkDropTarget,
144            x: std::ffi::c_double,
145            y: std::ffi::c_double,
146            f: glib::ffi::gpointer,
147        ) -> gdk::ffi::GdkDragAction {
148            let f: &F = &*(f as *const F);
149            f(&from_glib_borrow(this), x, y).into_glib()
150        }
151        unsafe {
152            let f: Box_<F> = Box_::new(f);
153            connect_raw(
154                self.as_ptr() as *mut _,
155                c"enter".as_ptr() as *const _,
156                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
157                    enter_trampoline::<F> as *const (),
158                )),
159                Box_::into_raw(f),
160            )
161        }
162    }
163
164    #[doc(alias = "leave")]
165    pub fn connect_leave<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
166        unsafe extern "C" fn leave_trampoline<F: Fn(&DropTarget) + 'static>(
167            this: *mut ffi::GtkDropTarget,
168            f: glib::ffi::gpointer,
169        ) {
170            let f: &F = &*(f as *const F);
171            f(&from_glib_borrow(this))
172        }
173        unsafe {
174            let f: Box_<F> = Box_::new(f);
175            connect_raw(
176                self.as_ptr() as *mut _,
177                c"leave".as_ptr() as *const _,
178                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
179                    leave_trampoline::<F> as *const (),
180                )),
181                Box_::into_raw(f),
182            )
183        }
184    }
185
186    #[doc(alias = "motion")]
187    pub fn connect_motion<F: Fn(&Self, f64, f64) -> gdk::DragAction + 'static>(
188        &self,
189        f: F,
190    ) -> SignalHandlerId {
191        unsafe extern "C" fn motion_trampoline<
192            F: Fn(&DropTarget, f64, f64) -> gdk::DragAction + 'static,
193        >(
194            this: *mut ffi::GtkDropTarget,
195            x: std::ffi::c_double,
196            y: std::ffi::c_double,
197            f: glib::ffi::gpointer,
198        ) -> gdk::ffi::GdkDragAction {
199            let f: &F = &*(f as *const F);
200            f(&from_glib_borrow(this), x, y).into_glib()
201        }
202        unsafe {
203            let f: Box_<F> = Box_::new(f);
204            connect_raw(
205                self.as_ptr() as *mut _,
206                c"motion".as_ptr() as *const _,
207                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
208                    motion_trampoline::<F> as *const (),
209                )),
210                Box_::into_raw(f),
211            )
212        }
213    }
214
215    #[doc(alias = "actions")]
216    pub fn connect_actions_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
217        unsafe extern "C" fn notify_actions_trampoline<F: Fn(&DropTarget) + 'static>(
218            this: *mut ffi::GtkDropTarget,
219            _param_spec: glib::ffi::gpointer,
220            f: glib::ffi::gpointer,
221        ) {
222            let f: &F = &*(f as *const F);
223            f(&from_glib_borrow(this))
224        }
225        unsafe {
226            let f: Box_<F> = Box_::new(f);
227            connect_raw(
228                self.as_ptr() as *mut _,
229                c"notify::actions".as_ptr() as *const _,
230                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
231                    notify_actions_trampoline::<F> as *const (),
232                )),
233                Box_::into_raw(f),
234            )
235        }
236    }
237
238    #[cfg(feature = "v4_4")]
239    #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
240    #[doc(alias = "current-drop")]
241    pub fn connect_current_drop_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
242        unsafe extern "C" fn notify_current_drop_trampoline<F: Fn(&DropTarget) + 'static>(
243            this: *mut ffi::GtkDropTarget,
244            _param_spec: glib::ffi::gpointer,
245            f: glib::ffi::gpointer,
246        ) {
247            let f: &F = &*(f as *const F);
248            f(&from_glib_borrow(this))
249        }
250        unsafe {
251            let f: Box_<F> = Box_::new(f);
252            connect_raw(
253                self.as_ptr() as *mut _,
254                c"notify::current-drop".as_ptr() as *const _,
255                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
256                    notify_current_drop_trampoline::<F> as *const (),
257                )),
258                Box_::into_raw(f),
259            )
260        }
261    }
262
263    #[cfg_attr(feature = "v4_4", deprecated = "Since 4.4")]
264    #[doc(alias = "drop")]
265    pub fn connect_drop_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
266        unsafe extern "C" fn notify_drop_trampoline<F: Fn(&DropTarget) + 'static>(
267            this: *mut ffi::GtkDropTarget,
268            _param_spec: glib::ffi::gpointer,
269            f: glib::ffi::gpointer,
270        ) {
271            let f: &F = &*(f as *const F);
272            f(&from_glib_borrow(this))
273        }
274        unsafe {
275            let f: Box_<F> = Box_::new(f);
276            connect_raw(
277                self.as_ptr() as *mut _,
278                c"notify::drop".as_ptr() as *const _,
279                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
280                    notify_drop_trampoline::<F> as *const (),
281                )),
282                Box_::into_raw(f),
283            )
284        }
285    }
286
287    #[doc(alias = "preload")]
288    pub fn connect_preload_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
289        unsafe extern "C" fn notify_preload_trampoline<F: Fn(&DropTarget) + 'static>(
290            this: *mut ffi::GtkDropTarget,
291            _param_spec: glib::ffi::gpointer,
292            f: glib::ffi::gpointer,
293        ) {
294            let f: &F = &*(f as *const F);
295            f(&from_glib_borrow(this))
296        }
297        unsafe {
298            let f: Box_<F> = Box_::new(f);
299            connect_raw(
300                self.as_ptr() as *mut _,
301                c"notify::preload".as_ptr() as *const _,
302                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
303                    notify_preload_trampoline::<F> as *const (),
304                )),
305                Box_::into_raw(f),
306            )
307        }
308    }
309
310    #[doc(alias = "value")]
311    pub fn connect_value_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
312        unsafe extern "C" fn notify_value_trampoline<F: Fn(&DropTarget) + 'static>(
313            this: *mut ffi::GtkDropTarget,
314            _param_spec: glib::ffi::gpointer,
315            f: glib::ffi::gpointer,
316        ) {
317            let f: &F = &*(f as *const F);
318            f(&from_glib_borrow(this))
319        }
320        unsafe {
321            let f: Box_<F> = Box_::new(f);
322            connect_raw(
323                self.as_ptr() as *mut _,
324                c"notify::value".as_ptr() as *const _,
325                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
326                    notify_value_trampoline::<F> as *const (),
327                )),
328                Box_::into_raw(f),
329            )
330        }
331    }
332}
333
334impl Default for DropTarget {
335    fn default() -> Self {
336        glib::object::Object::new::<Self>()
337    }
338}
339
340// rustdoc-stripper-ignore-next
341/// A [builder-pattern] type to construct [`DropTarget`] objects.
342///
343/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
344#[must_use = "The builder must be built to be used"]
345pub struct DropTargetBuilder {
346    builder: glib::object::ObjectBuilder<'static, DropTarget>,
347}
348
349impl DropTargetBuilder {
350    fn new() -> Self {
351        Self {
352            builder: glib::object::Object::builder(),
353        }
354    }
355
356    pub fn actions(self, actions: gdk::DragAction) -> Self {
357        Self {
358            builder: self.builder.property("actions", actions),
359        }
360    }
361
362    pub fn formats(self, formats: &gdk::ContentFormats) -> Self {
363        Self {
364            builder: self.builder.property("formats", formats.clone()),
365        }
366    }
367
368    pub fn preload(self, preload: bool) -> Self {
369        Self {
370            builder: self.builder.property("preload", preload),
371        }
372    }
373
374    pub fn name(self, name: impl Into<glib::GString>) -> Self {
375        Self {
376            builder: self.builder.property("name", name.into()),
377        }
378    }
379
380    pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
381        Self {
382            builder: self
383                .builder
384                .property("propagation-limit", propagation_limit),
385        }
386    }
387
388    pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
389        Self {
390            builder: self
391                .builder
392                .property("propagation-phase", propagation_phase),
393        }
394    }
395
396    // rustdoc-stripper-ignore-next
397    /// Build the [`DropTarget`].
398    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
399    pub fn build(self) -> DropTarget {
400        assert_initialized_main_thread!();
401        self.builder.build()
402    }
403}