1use crate::{Action, Actor, ActorMeta, DragAxis, InternalRect, ModifierType};
2use glib::{
3 object as gobject,
4 object::{Cast, IsA},
5 signal::{connect_raw, SignalHandlerId},
6 translate::*,
7 StaticType, Value,
8};
9use std::boxed::Box as Box_;
10use std::{fmt, mem, mem::transmute};
11
12glib_wrapper! {
13 pub struct DragAction(Object<ffi::ClutterDragAction, ffi::ClutterDragActionClass, DragActionClass>) @extends Action, ActorMeta, gobject::InitiallyUnowned;
14
15 match fn {
16 get_type => || ffi::clutter_drag_action_get_type(),
17 }
18}
19
20impl DragAction {
21 pub fn new() -> DragAction {
27 unsafe { Action::from_glib_none(ffi::clutter_drag_action_new()).unsafe_cast() }
28 }
29}
30
31impl Default for DragAction {
32 fn default() -> Self {
33 Self::new()
34 }
35}
36
37pub trait DragActionExt: 'static {
43 fn get_drag_area(&self) -> Option<InternalRect>;
54
55 fn get_drag_axis(&self) -> DragAxis;
61
62 fn get_drag_handle(&self) -> Option<Actor>;
69
70 fn get_drag_threshold(&self) -> (u32, u32);
83
84 fn get_motion_coords(&self) -> (f32, f32);
93
94 fn get_press_coords(&self) -> (f32, f32);
101
102 fn set_drag_area(&self, drag_area: Option<&InternalRect>);
109
110 fn set_drag_axis(&self, axis: DragAxis);
114
115 fn set_drag_handle<P: IsA<Actor>>(&self, handle: Option<&P>);
119
120 fn set_drag_threshold(&self, x_threshold: i32, y_threshold: i32);
133
134 fn get_property_drag_area_set(&self) -> bool;
136
137 fn get_property_x_drag_threshold(&self) -> i32;
152
153 fn set_property_x_drag_threshold(&self, x_drag_threshold: i32);
168
169 fn get_property_y_drag_threshold(&self) -> i32;
184
185 fn set_property_y_drag_threshold(&self, y_drag_threshold: i32);
200
201 fn connect_drag_begin<F: Fn(&Self, &Actor, f32, f32, ModifierType) + 'static>(
216 &self,
217 f: F,
218 ) -> SignalHandlerId;
219
220 fn connect_drag_end<F: Fn(&Self, &Actor, f32, f32, ModifierType) + 'static>(
234 &self,
235 f: F,
236 ) -> SignalHandlerId;
237
238 fn connect_drag_motion<F: Fn(&Self, &Actor, f32, f32) + 'static>(
264 &self,
265 f: F,
266 ) -> SignalHandlerId;
267
268 fn connect_drag_progress<F: Fn(&Self, &Actor, f32, f32) -> bool + 'static>(
295 &self,
296 f: F,
297 ) -> SignalHandlerId;
298
299 fn connect_property_drag_area_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
300
301 fn connect_property_drag_area_set_notify<F: Fn(&Self) + 'static>(
302 &self,
303 f: F,
304 ) -> SignalHandlerId;
305
306 fn connect_property_drag_axis_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
307
308 fn connect_property_drag_handle_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
309
310 fn connect_property_x_drag_threshold_notify<F: Fn(&Self) + 'static>(
311 &self,
312 f: F,
313 ) -> SignalHandlerId;
314
315 fn connect_property_y_drag_threshold_notify<F: Fn(&Self) + 'static>(
316 &self,
317 f: F,
318 ) -> SignalHandlerId;
319}
320
321impl<O: IsA<DragAction>> DragActionExt for O {
322 fn get_drag_area(&self) -> Option<InternalRect> {
323 unsafe {
324 let mut drag_area = InternalRect::uninitialized();
325 let ret = from_glib(ffi::clutter_drag_action_get_drag_area(
326 self.as_ref().to_glib_none().0,
327 drag_area.to_glib_none_mut().0,
328 ));
329 if ret {
330 Some(drag_area)
331 } else {
332 None
333 }
334 }
335 }
336
337 fn get_drag_axis(&self) -> DragAxis {
338 unsafe {
339 from_glib(ffi::clutter_drag_action_get_drag_axis(
340 self.as_ref().to_glib_none().0,
341 ))
342 }
343 }
344
345 fn get_drag_handle(&self) -> Option<Actor> {
346 unsafe {
347 from_glib_none(ffi::clutter_drag_action_get_drag_handle(
348 self.as_ref().to_glib_none().0,
349 ))
350 }
351 }
352
353 fn get_drag_threshold(&self) -> (u32, u32) {
354 unsafe {
355 let mut x_threshold = mem::MaybeUninit::uninit();
356 let mut y_threshold = mem::MaybeUninit::uninit();
357 ffi::clutter_drag_action_get_drag_threshold(
358 self.as_ref().to_glib_none().0,
359 x_threshold.as_mut_ptr(),
360 y_threshold.as_mut_ptr(),
361 );
362 let x_threshold = x_threshold.assume_init();
363 let y_threshold = y_threshold.assume_init();
364 (x_threshold, y_threshold)
365 }
366 }
367
368 fn get_motion_coords(&self) -> (f32, f32) {
369 unsafe {
370 let mut motion_x = mem::MaybeUninit::uninit();
371 let mut motion_y = mem::MaybeUninit::uninit();
372 ffi::clutter_drag_action_get_motion_coords(
373 self.as_ref().to_glib_none().0,
374 motion_x.as_mut_ptr(),
375 motion_y.as_mut_ptr(),
376 );
377 let motion_x = motion_x.assume_init();
378 let motion_y = motion_y.assume_init();
379 (motion_x, motion_y)
380 }
381 }
382
383 fn get_press_coords(&self) -> (f32, f32) {
384 unsafe {
385 let mut press_x = mem::MaybeUninit::uninit();
386 let mut press_y = mem::MaybeUninit::uninit();
387 ffi::clutter_drag_action_get_press_coords(
388 self.as_ref().to_glib_none().0,
389 press_x.as_mut_ptr(),
390 press_y.as_mut_ptr(),
391 );
392 let press_x = press_x.assume_init();
393 let press_y = press_y.assume_init();
394 (press_x, press_y)
395 }
396 }
397
398 fn set_drag_area(&self, drag_area: Option<&InternalRect>) {
399 unsafe {
400 ffi::clutter_drag_action_set_drag_area(
401 self.as_ref().to_glib_none().0,
402 drag_area.to_glib_none().0,
403 );
404 }
405 }
406
407 fn set_drag_axis(&self, axis: DragAxis) {
408 unsafe {
409 ffi::clutter_drag_action_set_drag_axis(self.as_ref().to_glib_none().0, axis.to_glib());
410 }
411 }
412
413 fn set_drag_handle<P: IsA<Actor>>(&self, handle: Option<&P>) {
414 unsafe {
415 ffi::clutter_drag_action_set_drag_handle(
416 self.as_ref().to_glib_none().0,
417 handle.map(|p| p.as_ref()).to_glib_none().0,
418 );
419 }
420 }
421
422 fn set_drag_threshold(&self, x_threshold: i32, y_threshold: i32) {
423 unsafe {
424 ffi::clutter_drag_action_set_drag_threshold(
425 self.as_ref().to_glib_none().0,
426 x_threshold,
427 y_threshold,
428 );
429 }
430 }
431
432 fn get_property_drag_area_set(&self) -> bool {
433 unsafe {
434 let mut value = Value::from_type(<bool as StaticType>::static_type());
435 gobject_sys::g_object_get_property(
436 self.to_glib_none().0 as *mut gobject_sys::GObject,
437 b"drag-area-set\0".as_ptr() as *const _,
438 value.to_glib_none_mut().0,
439 );
440 value
441 .get()
442 .expect("Return Value for property `drag-area-set` getter")
443 .unwrap()
444 }
445 }
446
447 fn get_property_x_drag_threshold(&self) -> i32 {
448 unsafe {
449 let mut value = Value::from_type(<i32 as StaticType>::static_type());
450 gobject_sys::g_object_get_property(
451 self.to_glib_none().0 as *mut gobject_sys::GObject,
452 b"x-drag-threshold\0".as_ptr() as *const _,
453 value.to_glib_none_mut().0,
454 );
455 value
456 .get()
457 .expect("Return Value for property `x-drag-threshold` getter")
458 .unwrap()
459 }
460 }
461
462 fn set_property_x_drag_threshold(&self, x_drag_threshold: i32) {
463 unsafe {
464 gobject_sys::g_object_set_property(
465 self.to_glib_none().0 as *mut gobject_sys::GObject,
466 b"x-drag-threshold\0".as_ptr() as *const _,
467 Value::from(&x_drag_threshold).to_glib_none().0,
468 );
469 }
470 }
471
472 fn get_property_y_drag_threshold(&self) -> i32 {
473 unsafe {
474 let mut value = Value::from_type(<i32 as StaticType>::static_type());
475 gobject_sys::g_object_get_property(
476 self.to_glib_none().0 as *mut gobject_sys::GObject,
477 b"y-drag-threshold\0".as_ptr() as *const _,
478 value.to_glib_none_mut().0,
479 );
480 value
481 .get()
482 .expect("Return Value for property `y-drag-threshold` getter")
483 .unwrap()
484 }
485 }
486
487 fn set_property_y_drag_threshold(&self, y_drag_threshold: i32) {
488 unsafe {
489 gobject_sys::g_object_set_property(
490 self.to_glib_none().0 as *mut gobject_sys::GObject,
491 b"y-drag-threshold\0".as_ptr() as *const _,
492 Value::from(&y_drag_threshold).to_glib_none().0,
493 );
494 }
495 }
496
497 fn connect_drag_begin<F: Fn(&Self, &Actor, f32, f32, ModifierType) + 'static>(
498 &self,
499 f: F,
500 ) -> SignalHandlerId {
501 unsafe extern "C" fn drag_begin_trampoline<
502 P,
503 F: Fn(&P, &Actor, f32, f32, ModifierType) + 'static,
504 >(
505 this: *mut ffi::ClutterDragAction,
506 actor: *mut ffi::ClutterActor,
507 event_x: libc::c_float,
508 event_y: libc::c_float,
509 modifiers: ffi::ClutterModifierType,
510 f: glib_sys::gpointer,
511 ) where
512 P: IsA<DragAction>,
513 {
514 let f: &F = &*(f as *const F);
515 f(
516 &DragAction::from_glib_borrow(this).unsafe_cast_ref(),
517 &from_glib_borrow(actor),
518 event_x,
519 event_y,
520 from_glib(modifiers),
521 )
522 }
523 unsafe {
524 let f: Box_<F> = Box_::new(f);
525 connect_raw(
526 self.as_ptr() as *mut _,
527 b"drag-begin\0".as_ptr() as *const _,
528 Some(transmute::<_, unsafe extern "C" fn()>(
529 drag_begin_trampoline::<Self, F> as *const (),
530 )),
531 Box_::into_raw(f),
532 )
533 }
534 }
535
536 fn connect_drag_end<F: Fn(&Self, &Actor, f32, f32, ModifierType) + 'static>(
537 &self,
538 f: F,
539 ) -> SignalHandlerId {
540 unsafe extern "C" fn drag_end_trampoline<
541 P,
542 F: Fn(&P, &Actor, f32, f32, ModifierType) + 'static,
543 >(
544 this: *mut ffi::ClutterDragAction,
545 actor: *mut ffi::ClutterActor,
546 event_x: libc::c_float,
547 event_y: libc::c_float,
548 modifiers: ffi::ClutterModifierType,
549 f: glib_sys::gpointer,
550 ) where
551 P: IsA<DragAction>,
552 {
553 let f: &F = &*(f as *const F);
554 f(
555 &DragAction::from_glib_borrow(this).unsafe_cast_ref(),
556 &from_glib_borrow(actor),
557 event_x,
558 event_y,
559 from_glib(modifiers),
560 )
561 }
562 unsafe {
563 let f: Box_<F> = Box_::new(f);
564 connect_raw(
565 self.as_ptr() as *mut _,
566 b"drag-end\0".as_ptr() as *const _,
567 Some(transmute::<_, unsafe extern "C" fn()>(
568 drag_end_trampoline::<Self, F> as *const (),
569 )),
570 Box_::into_raw(f),
571 )
572 }
573 }
574
575 fn connect_drag_motion<F: Fn(&Self, &Actor, f32, f32) + 'static>(
576 &self,
577 f: F,
578 ) -> SignalHandlerId {
579 unsafe extern "C" fn drag_motion_trampoline<P, F: Fn(&P, &Actor, f32, f32) + 'static>(
580 this: *mut ffi::ClutterDragAction,
581 actor: *mut ffi::ClutterActor,
582 delta_x: libc::c_float,
583 delta_y: libc::c_float,
584 f: glib_sys::gpointer,
585 ) where
586 P: IsA<DragAction>,
587 {
588 let f: &F = &*(f as *const F);
589 f(
590 &DragAction::from_glib_borrow(this).unsafe_cast_ref(),
591 &from_glib_borrow(actor),
592 delta_x,
593 delta_y,
594 )
595 }
596 unsafe {
597 let f: Box_<F> = Box_::new(f);
598 connect_raw(
599 self.as_ptr() as *mut _,
600 b"drag-motion\0".as_ptr() as *const _,
601 Some(transmute::<_, unsafe extern "C" fn()>(
602 drag_motion_trampoline::<Self, F> as *const (),
603 )),
604 Box_::into_raw(f),
605 )
606 }
607 }
608
609 fn connect_drag_progress<F: Fn(&Self, &Actor, f32, f32) -> bool + 'static>(
610 &self,
611 f: F,
612 ) -> SignalHandlerId {
613 unsafe extern "C" fn drag_progress_trampoline<
614 P,
615 F: Fn(&P, &Actor, f32, f32) -> bool + 'static,
616 >(
617 this: *mut ffi::ClutterDragAction,
618 actor: *mut ffi::ClutterActor,
619 delta_x: libc::c_float,
620 delta_y: libc::c_float,
621 f: glib_sys::gpointer,
622 ) -> glib_sys::gboolean
623 where
624 P: IsA<DragAction>,
625 {
626 let f: &F = &*(f as *const F);
627 f(
628 &DragAction::from_glib_borrow(this).unsafe_cast_ref(),
629 &from_glib_borrow(actor),
630 delta_x,
631 delta_y,
632 )
633 .to_glib()
634 }
635 unsafe {
636 let f: Box_<F> = Box_::new(f);
637 connect_raw(
638 self.as_ptr() as *mut _,
639 b"drag-progress\0".as_ptr() as *const _,
640 Some(transmute::<_, unsafe extern "C" fn()>(
641 drag_progress_trampoline::<Self, F> as *const (),
642 )),
643 Box_::into_raw(f),
644 )
645 }
646 }
647
648 fn connect_property_drag_area_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
649 unsafe extern "C" fn notify_drag_area_trampoline<P, F: Fn(&P) + 'static>(
650 this: *mut ffi::ClutterDragAction,
651 _param_spec: glib_sys::gpointer,
652 f: glib_sys::gpointer,
653 ) where
654 P: IsA<DragAction>,
655 {
656 let f: &F = &*(f as *const F);
657 f(&DragAction::from_glib_borrow(this).unsafe_cast_ref())
658 }
659 unsafe {
660 let f: Box_<F> = Box_::new(f);
661 connect_raw(
662 self.as_ptr() as *mut _,
663 b"notify::drag-area\0".as_ptr() as *const _,
664 Some(transmute::<_, unsafe extern "C" fn()>(
665 notify_drag_area_trampoline::<Self, F> as *const (),
666 )),
667 Box_::into_raw(f),
668 )
669 }
670 }
671
672 fn connect_property_drag_area_set_notify<F: Fn(&Self) + 'static>(
673 &self,
674 f: F,
675 ) -> SignalHandlerId {
676 unsafe extern "C" fn notify_drag_area_set_trampoline<P, F: Fn(&P) + 'static>(
677 this: *mut ffi::ClutterDragAction,
678 _param_spec: glib_sys::gpointer,
679 f: glib_sys::gpointer,
680 ) where
681 P: IsA<DragAction>,
682 {
683 let f: &F = &*(f as *const F);
684 f(&DragAction::from_glib_borrow(this).unsafe_cast_ref())
685 }
686 unsafe {
687 let f: Box_<F> = Box_::new(f);
688 connect_raw(
689 self.as_ptr() as *mut _,
690 b"notify::drag-area-set\0".as_ptr() as *const _,
691 Some(transmute::<_, unsafe extern "C" fn()>(
692 notify_drag_area_set_trampoline::<Self, F> as *const (),
693 )),
694 Box_::into_raw(f),
695 )
696 }
697 }
698
699 fn connect_property_drag_axis_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
700 unsafe extern "C" fn notify_drag_axis_trampoline<P, F: Fn(&P) + 'static>(
701 this: *mut ffi::ClutterDragAction,
702 _param_spec: glib_sys::gpointer,
703 f: glib_sys::gpointer,
704 ) where
705 P: IsA<DragAction>,
706 {
707 let f: &F = &*(f as *const F);
708 f(&DragAction::from_glib_borrow(this).unsafe_cast_ref())
709 }
710 unsafe {
711 let f: Box_<F> = Box_::new(f);
712 connect_raw(
713 self.as_ptr() as *mut _,
714 b"notify::drag-axis\0".as_ptr() as *const _,
715 Some(transmute::<_, unsafe extern "C" fn()>(
716 notify_drag_axis_trampoline::<Self, F> as *const (),
717 )),
718 Box_::into_raw(f),
719 )
720 }
721 }
722
723 fn connect_property_drag_handle_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
724 unsafe extern "C" fn notify_drag_handle_trampoline<P, F: Fn(&P) + 'static>(
725 this: *mut ffi::ClutterDragAction,
726 _param_spec: glib_sys::gpointer,
727 f: glib_sys::gpointer,
728 ) where
729 P: IsA<DragAction>,
730 {
731 let f: &F = &*(f as *const F);
732 f(&DragAction::from_glib_borrow(this).unsafe_cast_ref())
733 }
734 unsafe {
735 let f: Box_<F> = Box_::new(f);
736 connect_raw(
737 self.as_ptr() as *mut _,
738 b"notify::drag-handle\0".as_ptr() as *const _,
739 Some(transmute::<_, unsafe extern "C" fn()>(
740 notify_drag_handle_trampoline::<Self, F> as *const (),
741 )),
742 Box_::into_raw(f),
743 )
744 }
745 }
746
747 fn connect_property_x_drag_threshold_notify<F: Fn(&Self) + 'static>(
748 &self,
749 f: F,
750 ) -> SignalHandlerId {
751 unsafe extern "C" fn notify_x_drag_threshold_trampoline<P, F: Fn(&P) + 'static>(
752 this: *mut ffi::ClutterDragAction,
753 _param_spec: glib_sys::gpointer,
754 f: glib_sys::gpointer,
755 ) where
756 P: IsA<DragAction>,
757 {
758 let f: &F = &*(f as *const F);
759 f(&DragAction::from_glib_borrow(this).unsafe_cast_ref())
760 }
761 unsafe {
762 let f: Box_<F> = Box_::new(f);
763 connect_raw(
764 self.as_ptr() as *mut _,
765 b"notify::x-drag-threshold\0".as_ptr() as *const _,
766 Some(transmute::<_, unsafe extern "C" fn()>(
767 notify_x_drag_threshold_trampoline::<Self, F> as *const (),
768 )),
769 Box_::into_raw(f),
770 )
771 }
772 }
773
774 fn connect_property_y_drag_threshold_notify<F: Fn(&Self) + 'static>(
775 &self,
776 f: F,
777 ) -> SignalHandlerId {
778 unsafe extern "C" fn notify_y_drag_threshold_trampoline<P, F: Fn(&P) + 'static>(
779 this: *mut ffi::ClutterDragAction,
780 _param_spec: glib_sys::gpointer,
781 f: glib_sys::gpointer,
782 ) where
783 P: IsA<DragAction>,
784 {
785 let f: &F = &*(f as *const F);
786 f(&DragAction::from_glib_borrow(this).unsafe_cast_ref())
787 }
788 unsafe {
789 let f: Box_<F> = Box_::new(f);
790 connect_raw(
791 self.as_ptr() as *mut _,
792 b"notify::y-drag-threshold\0".as_ptr() as *const _,
793 Some(transmute::<_, unsafe extern "C" fn()>(
794 notify_y_drag_threshold_trampoline::<Self, F> as *const (),
795 )),
796 Box_::into_raw(f),
797 )
798 }
799 }
800}
801
802impl fmt::Display for DragAction {
803 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
804 write!(f, "DragAction")
805 }
806}