[go: up one dir, main page]

gtk4/auto/
drag_source.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, Gesture, GestureSingle, 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 = "GtkDragSource")]
16    pub struct DragSource(Object<ffi::GtkDragSource, ffi::GtkDragSourceClass>) @extends GestureSingle, Gesture, EventController;
17
18    match fn {
19        type_ => || ffi::gtk_drag_source_get_type(),
20    }
21}
22
23impl DragSource {
24    #[doc(alias = "gtk_drag_source_new")]
25    pub fn new() -> DragSource {
26        assert_initialized_main_thread!();
27        unsafe { from_glib_full(ffi::gtk_drag_source_new()) }
28    }
29
30    // rustdoc-stripper-ignore-next
31    /// Creates a new builder-pattern struct instance to construct [`DragSource`] objects.
32    ///
33    /// This method returns an instance of [`DragSourceBuilder`](crate::builders::DragSourceBuilder) which can be used to create [`DragSource`] objects.
34    pub fn builder() -> DragSourceBuilder {
35        DragSourceBuilder::new()
36    }
37
38    #[doc(alias = "gtk_drag_source_drag_cancel")]
39    pub fn drag_cancel(&self) {
40        unsafe {
41            ffi::gtk_drag_source_drag_cancel(self.to_glib_none().0);
42        }
43    }
44
45    #[doc(alias = "gtk_drag_source_get_actions")]
46    #[doc(alias = "get_actions")]
47    pub fn actions(&self) -> gdk::DragAction {
48        unsafe { from_glib(ffi::gtk_drag_source_get_actions(self.to_glib_none().0)) }
49    }
50
51    #[doc(alias = "gtk_drag_source_get_content")]
52    #[doc(alias = "get_content")]
53    pub fn content(&self) -> Option<gdk::ContentProvider> {
54        unsafe { from_glib_none(ffi::gtk_drag_source_get_content(self.to_glib_none().0)) }
55    }
56
57    #[doc(alias = "gtk_drag_source_get_drag")]
58    #[doc(alias = "get_drag")]
59    pub fn drag(&self) -> Option<gdk::Drag> {
60        unsafe { from_glib_none(ffi::gtk_drag_source_get_drag(self.to_glib_none().0)) }
61    }
62
63    #[doc(alias = "gtk_drag_source_set_actions")]
64    #[doc(alias = "actions")]
65    pub fn set_actions(&self, actions: gdk::DragAction) {
66        unsafe {
67            ffi::gtk_drag_source_set_actions(self.to_glib_none().0, actions.into_glib());
68        }
69    }
70
71    #[doc(alias = "gtk_drag_source_set_content")]
72    #[doc(alias = "content")]
73    pub fn set_content(&self, content: Option<&impl IsA<gdk::ContentProvider>>) {
74        unsafe {
75            ffi::gtk_drag_source_set_content(
76                self.to_glib_none().0,
77                content.map(|p| p.as_ref()).to_glib_none().0,
78            );
79        }
80    }
81
82    #[doc(alias = "gtk_drag_source_set_icon")]
83    pub fn set_icon(&self, paintable: Option<&impl IsA<gdk::Paintable>>, hot_x: i32, hot_y: i32) {
84        unsafe {
85            ffi::gtk_drag_source_set_icon(
86                self.to_glib_none().0,
87                paintable.map(|p| p.as_ref()).to_glib_none().0,
88                hot_x,
89                hot_y,
90            );
91        }
92    }
93
94    #[doc(alias = "drag-begin")]
95    pub fn connect_drag_begin<F: Fn(&Self, &gdk::Drag) + 'static>(&self, f: F) -> SignalHandlerId {
96        unsafe extern "C" fn drag_begin_trampoline<F: Fn(&DragSource, &gdk::Drag) + 'static>(
97            this: *mut ffi::GtkDragSource,
98            drag: *mut gdk::ffi::GdkDrag,
99            f: glib::ffi::gpointer,
100        ) {
101            let f: &F = &*(f as *const F);
102            f(&from_glib_borrow(this), &from_glib_borrow(drag))
103        }
104        unsafe {
105            let f: Box_<F> = Box_::new(f);
106            connect_raw(
107                self.as_ptr() as *mut _,
108                c"drag-begin".as_ptr() as *const _,
109                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
110                    drag_begin_trampoline::<F> as *const (),
111                )),
112                Box_::into_raw(f),
113            )
114        }
115    }
116
117    #[doc(alias = "drag-cancel")]
118    pub fn connect_drag_cancel<
119        F: Fn(&Self, &gdk::Drag, gdk::DragCancelReason) -> bool + 'static,
120    >(
121        &self,
122        f: F,
123    ) -> SignalHandlerId {
124        unsafe extern "C" fn drag_cancel_trampoline<
125            F: Fn(&DragSource, &gdk::Drag, gdk::DragCancelReason) -> bool + 'static,
126        >(
127            this: *mut ffi::GtkDragSource,
128            drag: *mut gdk::ffi::GdkDrag,
129            reason: gdk::ffi::GdkDragCancelReason,
130            f: glib::ffi::gpointer,
131        ) -> glib::ffi::gboolean {
132            let f: &F = &*(f as *const F);
133            f(
134                &from_glib_borrow(this),
135                &from_glib_borrow(drag),
136                from_glib(reason),
137            )
138            .into_glib()
139        }
140        unsafe {
141            let f: Box_<F> = Box_::new(f);
142            connect_raw(
143                self.as_ptr() as *mut _,
144                c"drag-cancel".as_ptr() as *const _,
145                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
146                    drag_cancel_trampoline::<F> as *const (),
147                )),
148                Box_::into_raw(f),
149            )
150        }
151    }
152
153    #[doc(alias = "drag-end")]
154    pub fn connect_drag_end<F: Fn(&Self, &gdk::Drag, bool) + 'static>(
155        &self,
156        f: F,
157    ) -> SignalHandlerId {
158        unsafe extern "C" fn drag_end_trampoline<F: Fn(&DragSource, &gdk::Drag, bool) + 'static>(
159            this: *mut ffi::GtkDragSource,
160            drag: *mut gdk::ffi::GdkDrag,
161            delete_data: glib::ffi::gboolean,
162            f: glib::ffi::gpointer,
163        ) {
164            let f: &F = &*(f as *const F);
165            f(
166                &from_glib_borrow(this),
167                &from_glib_borrow(drag),
168                from_glib(delete_data),
169            )
170        }
171        unsafe {
172            let f: Box_<F> = Box_::new(f);
173            connect_raw(
174                self.as_ptr() as *mut _,
175                c"drag-end".as_ptr() as *const _,
176                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
177                    drag_end_trampoline::<F> as *const (),
178                )),
179                Box_::into_raw(f),
180            )
181        }
182    }
183
184    #[doc(alias = "prepare")]
185    pub fn connect_prepare<F: Fn(&Self, f64, f64) -> Option<gdk::ContentProvider> + 'static>(
186        &self,
187        f: F,
188    ) -> SignalHandlerId {
189        unsafe extern "C" fn prepare_trampoline<
190            F: Fn(&DragSource, f64, f64) -> Option<gdk::ContentProvider> + 'static,
191        >(
192            this: *mut ffi::GtkDragSource,
193            x: std::ffi::c_double,
194            y: std::ffi::c_double,
195            f: glib::ffi::gpointer,
196        ) -> *mut gdk::ffi::GdkContentProvider {
197            let f: &F = &*(f as *const F);
198            f(&from_glib_borrow(this), x, y).to_glib_full()
199        }
200        unsafe {
201            let f: Box_<F> = Box_::new(f);
202            connect_raw(
203                self.as_ptr() as *mut _,
204                c"prepare".as_ptr() as *const _,
205                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
206                    prepare_trampoline::<F> as *const (),
207                )),
208                Box_::into_raw(f),
209            )
210        }
211    }
212
213    #[doc(alias = "actions")]
214    pub fn connect_actions_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
215        unsafe extern "C" fn notify_actions_trampoline<F: Fn(&DragSource) + 'static>(
216            this: *mut ffi::GtkDragSource,
217            _param_spec: glib::ffi::gpointer,
218            f: glib::ffi::gpointer,
219        ) {
220            let f: &F = &*(f as *const F);
221            f(&from_glib_borrow(this))
222        }
223        unsafe {
224            let f: Box_<F> = Box_::new(f);
225            connect_raw(
226                self.as_ptr() as *mut _,
227                c"notify::actions".as_ptr() as *const _,
228                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
229                    notify_actions_trampoline::<F> as *const (),
230                )),
231                Box_::into_raw(f),
232            )
233        }
234    }
235
236    #[doc(alias = "content")]
237    pub fn connect_content_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
238        unsafe extern "C" fn notify_content_trampoline<F: Fn(&DragSource) + 'static>(
239            this: *mut ffi::GtkDragSource,
240            _param_spec: glib::ffi::gpointer,
241            f: glib::ffi::gpointer,
242        ) {
243            let f: &F = &*(f as *const F);
244            f(&from_glib_borrow(this))
245        }
246        unsafe {
247            let f: Box_<F> = Box_::new(f);
248            connect_raw(
249                self.as_ptr() as *mut _,
250                c"notify::content".as_ptr() as *const _,
251                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
252                    notify_content_trampoline::<F> as *const (),
253                )),
254                Box_::into_raw(f),
255            )
256        }
257    }
258}
259
260impl Default for DragSource {
261    fn default() -> Self {
262        Self::new()
263    }
264}
265
266// rustdoc-stripper-ignore-next
267/// A [builder-pattern] type to construct [`DragSource`] objects.
268///
269/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
270#[must_use = "The builder must be built to be used"]
271pub struct DragSourceBuilder {
272    builder: glib::object::ObjectBuilder<'static, DragSource>,
273}
274
275impl DragSourceBuilder {
276    fn new() -> Self {
277        Self {
278            builder: glib::object::Object::builder(),
279        }
280    }
281
282    pub fn actions(self, actions: gdk::DragAction) -> Self {
283        Self {
284            builder: self.builder.property("actions", actions),
285        }
286    }
287
288    pub fn content(self, content: &impl IsA<gdk::ContentProvider>) -> Self {
289        Self {
290            builder: self.builder.property("content", content.clone().upcast()),
291        }
292    }
293
294    pub fn button(self, button: u32) -> Self {
295        Self {
296            builder: self.builder.property("button", button),
297        }
298    }
299
300    pub fn exclusive(self, exclusive: bool) -> Self {
301        Self {
302            builder: self.builder.property("exclusive", exclusive),
303        }
304    }
305
306    pub fn touch_only(self, touch_only: bool) -> Self {
307        Self {
308            builder: self.builder.property("touch-only", touch_only),
309        }
310    }
311
312    pub fn n_points(self, n_points: u32) -> Self {
313        Self {
314            builder: self.builder.property("n-points", n_points),
315        }
316    }
317
318    pub fn name(self, name: impl Into<glib::GString>) -> Self {
319        Self {
320            builder: self.builder.property("name", name.into()),
321        }
322    }
323
324    pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
325        Self {
326            builder: self
327                .builder
328                .property("propagation-limit", propagation_limit),
329        }
330    }
331
332    pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
333        Self {
334            builder: self
335                .builder
336                .property("propagation-phase", propagation_phase),
337        }
338    }
339
340    // rustdoc-stripper-ignore-next
341    /// Build the [`DragSource`].
342    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
343    pub fn build(self) -> DragSource {
344        assert_initialized_main_thread!();
345        self.builder.build()
346    }
347}