gtk4/auto/drop_controller_motion.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 /// An event controller tracking the pointer during Drag-and-Drop operations.
16 ///
17 /// It is modeled after [`EventControllerMotion`][crate::EventControllerMotion] so if you
18 /// have used that, this should feel really familiar.
19 ///
20 /// This controller is not able to accept drops, use [`DropTarget`][crate::DropTarget]
21 /// for that purpose.
22 ///
23 /// ## Properties
24 ///
25 ///
26 /// #### `contains-pointer`
27 /// Whether the pointer of a Drag-and-Drop operation is in
28 /// the controller's widget or a descendant.
29 ///
30 /// See also [`is-pointer`][struct@crate::DropControllerMotion#is-pointer].
31 ///
32 /// When handling crossing events, this property is updated
33 /// before [`enter`][struct@crate::DropControllerMotion#enter], but after
34 /// [`leave`][struct@crate::DropControllerMotion#leave] is emitted.
35 ///
36 /// Readable
37 ///
38 ///
39 /// #### `drop`
40 /// The ongoing drop operation over the controller's widget or
41 /// its descendant.
42 ///
43 /// If no drop operation is going on, this property returns [`None`].
44 ///
45 /// The event controller should not modify the @drop, but it might
46 /// want to query its properties.
47 ///
48 /// When handling crossing events, this property is updated
49 /// before [`enter`][struct@crate::DropControllerMotion#enter], but after
50 /// [`leave`][struct@crate::DropControllerMotion#leave] is emitted.
51 ///
52 /// Readable
53 ///
54 ///
55 /// #### `is-pointer`
56 /// Whether the pointer is in the controllers widget itself,
57 /// as opposed to in a descendent widget.
58 ///
59 /// See also [`contains-pointer`][struct@crate::DropControllerMotion#contains-pointer].
60 ///
61 /// When handling crossing events, this property is updated
62 /// before [`enter`][struct@crate::DropControllerMotion#enter], but after
63 /// [`leave`][struct@crate::DropControllerMotion#leave] is emitted.
64 ///
65 /// Readable
66 /// <details><summary><h4>EventController</h4></summary>
67 ///
68 ///
69 /// #### `name`
70 /// The name for this controller, typically used for debugging purposes.
71 ///
72 /// Readable | Writeable
73 ///
74 ///
75 /// #### `propagation-limit`
76 /// The limit for which events this controller will handle.
77 ///
78 /// Readable | Writeable
79 ///
80 ///
81 /// #### `propagation-phase`
82 /// The propagation phase at which this controller will handle events.
83 ///
84 /// Readable | Writeable
85 ///
86 ///
87 /// #### `widget`
88 /// The widget receiving the `GdkEvents` that the controller will handle.
89 ///
90 /// Readable
91 /// </details>
92 ///
93 /// ## Signals
94 ///
95 ///
96 /// #### `enter`
97 /// Signals that the pointer has entered the widget.
98 ///
99 ///
100 ///
101 ///
102 /// #### `leave`
103 /// Signals that the pointer has left the widget.
104 ///
105 ///
106 ///
107 ///
108 /// #### `motion`
109 /// Emitted when the pointer moves inside the widget.
110 ///
111 ///
112 ///
113 /// # Implements
114 ///
115 /// [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
116 #[doc(alias = "GtkDropControllerMotion")]
117 pub struct DropControllerMotion(Object<ffi::GtkDropControllerMotion, ffi::GtkDropControllerMotionClass>) @extends EventController;
118
119 match fn {
120 type_ => || ffi::gtk_drop_controller_motion_get_type(),
121 }
122}
123
124impl DropControllerMotion {
125 /// Creates a new event controller that will handle pointer motion
126 /// events during drag and drop.
127 ///
128 /// # Returns
129 ///
130 /// a new [`DropControllerMotion`][crate::DropControllerMotion]
131 #[doc(alias = "gtk_drop_controller_motion_new")]
132 pub fn new() -> DropControllerMotion {
133 assert_initialized_main_thread!();
134 unsafe {
135 EventController::from_glib_full(ffi::gtk_drop_controller_motion_new()).unsafe_cast()
136 }
137 }
138
139 // rustdoc-stripper-ignore-next
140 /// Creates a new builder-pattern struct instance to construct [`DropControllerMotion`] objects.
141 ///
142 /// This method returns an instance of [`DropControllerMotionBuilder`](crate::builders::DropControllerMotionBuilder) which can be used to create [`DropControllerMotion`] objects.
143 pub fn builder() -> DropControllerMotionBuilder {
144 DropControllerMotionBuilder::new()
145 }
146
147 /// Returns if a Drag-and-Drop operation is within the widget
148 /// @self or one of its children.
149 ///
150 /// # Returns
151 ///
152 /// [`true`] if a dragging pointer is within @self or one of its children.
153 #[doc(alias = "gtk_drop_controller_motion_contains_pointer")]
154 #[doc(alias = "contains-pointer")]
155 pub fn contains_pointer(&self) -> bool {
156 unsafe {
157 from_glib(ffi::gtk_drop_controller_motion_contains_pointer(
158 self.to_glib_none().0,
159 ))
160 }
161 }
162
163 /// Returns the [`gdk::Drop`][crate::gdk::Drop] of a current Drag-and-Drop operation
164 /// over the widget of @self.
165 ///
166 /// # Returns
167 ///
168 /// The [`gdk::Drop`][crate::gdk::Drop] currently
169 /// happening within @self
170 #[doc(alias = "gtk_drop_controller_motion_get_drop")]
171 #[doc(alias = "get_drop")]
172 pub fn drop(&self) -> Option<gdk::Drop> {
173 unsafe {
174 from_glib_none(ffi::gtk_drop_controller_motion_get_drop(
175 self.to_glib_none().0,
176 ))
177 }
178 }
179
180 /// Returns if a Drag-and-Drop operation is within the widget
181 /// @self, not one of its children.
182 ///
183 /// # Returns
184 ///
185 /// [`true`] if a dragging pointer is within @self but
186 /// not one of its children
187 #[doc(alias = "gtk_drop_controller_motion_is_pointer")]
188 #[doc(alias = "is-pointer")]
189 pub fn is_pointer(&self) -> bool {
190 unsafe {
191 from_glib(ffi::gtk_drop_controller_motion_is_pointer(
192 self.to_glib_none().0,
193 ))
194 }
195 }
196
197 /// Signals that the pointer has entered the widget.
198 /// ## `x`
199 /// coordinates of pointer location
200 /// ## `y`
201 /// coordinates of pointer location
202 #[doc(alias = "enter")]
203 pub fn connect_enter<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
204 unsafe extern "C" fn enter_trampoline<F: Fn(&DropControllerMotion, f64, f64) + 'static>(
205 this: *mut ffi::GtkDropControllerMotion,
206 x: std::ffi::c_double,
207 y: std::ffi::c_double,
208 f: glib::ffi::gpointer,
209 ) {
210 let f: &F = &*(f as *const F);
211 f(&from_glib_borrow(this), x, y)
212 }
213 unsafe {
214 let f: Box_<F> = Box_::new(f);
215 connect_raw(
216 self.as_ptr() as *mut _,
217 c"enter".as_ptr() as *const _,
218 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
219 enter_trampoline::<F> as *const (),
220 )),
221 Box_::into_raw(f),
222 )
223 }
224 }
225
226 /// Signals that the pointer has left the widget.
227 #[doc(alias = "leave")]
228 pub fn connect_leave<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
229 unsafe extern "C" fn leave_trampoline<F: Fn(&DropControllerMotion) + 'static>(
230 this: *mut ffi::GtkDropControllerMotion,
231 f: glib::ffi::gpointer,
232 ) {
233 let f: &F = &*(f as *const F);
234 f(&from_glib_borrow(this))
235 }
236 unsafe {
237 let f: Box_<F> = Box_::new(f);
238 connect_raw(
239 self.as_ptr() as *mut _,
240 c"leave".as_ptr() as *const _,
241 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
242 leave_trampoline::<F> as *const (),
243 )),
244 Box_::into_raw(f),
245 )
246 }
247 }
248
249 /// Emitted when the pointer moves inside the widget.
250 /// ## `x`
251 /// the x coordinate
252 /// ## `y`
253 /// the y coordinate
254 #[doc(alias = "motion")]
255 pub fn connect_motion<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
256 unsafe extern "C" fn motion_trampoline<F: Fn(&DropControllerMotion, f64, f64) + 'static>(
257 this: *mut ffi::GtkDropControllerMotion,
258 x: std::ffi::c_double,
259 y: std::ffi::c_double,
260 f: glib::ffi::gpointer,
261 ) {
262 let f: &F = &*(f as *const F);
263 f(&from_glib_borrow(this), x, y)
264 }
265 unsafe {
266 let f: Box_<F> = Box_::new(f);
267 connect_raw(
268 self.as_ptr() as *mut _,
269 c"motion".as_ptr() as *const _,
270 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
271 motion_trampoline::<F> as *const (),
272 )),
273 Box_::into_raw(f),
274 )
275 }
276 }
277
278 #[doc(alias = "contains-pointer")]
279 pub fn connect_contains_pointer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
280 unsafe extern "C" fn notify_contains_pointer_trampoline<
281 F: Fn(&DropControllerMotion) + 'static,
282 >(
283 this: *mut ffi::GtkDropControllerMotion,
284 _param_spec: glib::ffi::gpointer,
285 f: glib::ffi::gpointer,
286 ) {
287 let f: &F = &*(f as *const F);
288 f(&from_glib_borrow(this))
289 }
290 unsafe {
291 let f: Box_<F> = Box_::new(f);
292 connect_raw(
293 self.as_ptr() as *mut _,
294 c"notify::contains-pointer".as_ptr() as *const _,
295 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
296 notify_contains_pointer_trampoline::<F> as *const (),
297 )),
298 Box_::into_raw(f),
299 )
300 }
301 }
302
303 #[doc(alias = "drop")]
304 pub fn connect_drop_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
305 unsafe extern "C" fn notify_drop_trampoline<F: Fn(&DropControllerMotion) + 'static>(
306 this: *mut ffi::GtkDropControllerMotion,
307 _param_spec: glib::ffi::gpointer,
308 f: glib::ffi::gpointer,
309 ) {
310 let f: &F = &*(f as *const F);
311 f(&from_glib_borrow(this))
312 }
313 unsafe {
314 let f: Box_<F> = Box_::new(f);
315 connect_raw(
316 self.as_ptr() as *mut _,
317 c"notify::drop".as_ptr() as *const _,
318 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
319 notify_drop_trampoline::<F> as *const (),
320 )),
321 Box_::into_raw(f),
322 )
323 }
324 }
325
326 #[doc(alias = "is-pointer")]
327 pub fn connect_is_pointer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
328 unsafe extern "C" fn notify_is_pointer_trampoline<
329 F: Fn(&DropControllerMotion) + 'static,
330 >(
331 this: *mut ffi::GtkDropControllerMotion,
332 _param_spec: glib::ffi::gpointer,
333 f: glib::ffi::gpointer,
334 ) {
335 let f: &F = &*(f as *const F);
336 f(&from_glib_borrow(this))
337 }
338 unsafe {
339 let f: Box_<F> = Box_::new(f);
340 connect_raw(
341 self.as_ptr() as *mut _,
342 c"notify::is-pointer".as_ptr() as *const _,
343 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
344 notify_is_pointer_trampoline::<F> as *const (),
345 )),
346 Box_::into_raw(f),
347 )
348 }
349 }
350}
351
352impl Default for DropControllerMotion {
353 fn default() -> Self {
354 Self::new()
355 }
356}
357
358// rustdoc-stripper-ignore-next
359/// A [builder-pattern] type to construct [`DropControllerMotion`] objects.
360///
361/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
362#[must_use = "The builder must be built to be used"]
363pub struct DropControllerMotionBuilder {
364 builder: glib::object::ObjectBuilder<'static, DropControllerMotion>,
365}
366
367impl DropControllerMotionBuilder {
368 fn new() -> Self {
369 Self {
370 builder: glib::object::Object::builder(),
371 }
372 }
373
374 /// The name for this controller, typically used for debugging purposes.
375 pub fn name(self, name: impl Into<glib::GString>) -> Self {
376 Self {
377 builder: self.builder.property("name", name.into()),
378 }
379 }
380
381 /// The limit for which events this controller will handle.
382 pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
383 Self {
384 builder: self
385 .builder
386 .property("propagation-limit", propagation_limit),
387 }
388 }
389
390 /// The propagation phase at which this controller will handle events.
391 pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
392 Self {
393 builder: self
394 .builder
395 .property("propagation-phase", propagation_phase),
396 }
397 }
398
399 // rustdoc-stripper-ignore-next
400 /// Build the [`DropControllerMotion`].
401 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
402 pub fn build(self) -> DropControllerMotion {
403 assert_initialized_main_thread!();
404 self.builder.build()
405 }
406}