use crate::{Action, Actor, ActorMeta};
use glib::{
object as gobject,
object::{Cast, IsA},
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
use std::{fmt, mem::transmute};
glib_wrapper! {
pub struct DropAction(Object<ffi::ClutterDropAction, ffi::ClutterDropActionClass, DropActionClass>) @extends Action, ActorMeta, gobject::InitiallyUnowned;
match fn {
get_type => || ffi::clutter_drop_action_get_type(),
}
}
impl DropAction {
pub fn new() -> DropAction {
unsafe { Action::from_glib_none(ffi::clutter_drop_action_new()).unsafe_cast() }
}
}
impl Default for DropAction {
fn default() -> Self {
Self::new()
}
}
pub trait DropActionExt: 'static {
fn connect_can_drop<F: Fn(&Self, &Actor, f32, f32) -> bool + 'static>(
&self,
f: F,
) -> SignalHandlerId;
fn connect_drop<F: Fn(&Self, &Actor, f32, f32) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_drop_cancel<F: Fn(&Self, &Actor, f32, f32) + 'static>(
&self,
f: F,
) -> SignalHandlerId;
fn connect_over_in<F: Fn(&Self, &Actor) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_over_out<F: Fn(&Self, &Actor) + 'static>(&self, f: F) -> SignalHandlerId;
}
impl<O: IsA<DropAction>> DropActionExt for O {
fn connect_can_drop<F: Fn(&Self, &Actor, f32, f32) -> bool + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn can_drop_trampoline<P, F: Fn(&P, &Actor, f32, f32) -> bool + 'static>(
this: *mut ffi::ClutterDropAction,
actor: *mut ffi::ClutterActor,
event_x: libc::c_float,
event_y: libc::c_float,
f: glib_sys::gpointer,
) -> glib_sys::gboolean
where
P: IsA<DropAction>,
{
let f: &F = &*(f as *const F);
f(
&DropAction::from_glib_borrow(this).unsafe_cast_ref(),
&from_glib_borrow(actor),
event_x,
event_y,
)
.to_glib()
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"can-drop\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
can_drop_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_drop<F: Fn(&Self, &Actor, f32, f32) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn drop_trampoline<P, F: Fn(&P, &Actor, f32, f32) + 'static>(
this: *mut ffi::ClutterDropAction,
actor: *mut ffi::ClutterActor,
event_x: libc::c_float,
event_y: libc::c_float,
f: glib_sys::gpointer,
) where
P: IsA<DropAction>,
{
let f: &F = &*(f as *const F);
f(
&DropAction::from_glib_borrow(this).unsafe_cast_ref(),
&from_glib_borrow(actor),
event_x,
event_y,
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"drop\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
drop_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_drop_cancel<F: Fn(&Self, &Actor, f32, f32) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn drop_cancel_trampoline<P, F: Fn(&P, &Actor, f32, f32) + 'static>(
this: *mut ffi::ClutterDropAction,
actor: *mut ffi::ClutterActor,
event_x: libc::c_float,
event_y: libc::c_float,
f: glib_sys::gpointer,
) where
P: IsA<DropAction>,
{
let f: &F = &*(f as *const F);
f(
&DropAction::from_glib_borrow(this).unsafe_cast_ref(),
&from_glib_borrow(actor),
event_x,
event_y,
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"drop-cancel\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
drop_cancel_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_over_in<F: Fn(&Self, &Actor) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn over_in_trampoline<P, F: Fn(&P, &Actor) + 'static>(
this: *mut ffi::ClutterDropAction,
actor: *mut ffi::ClutterActor,
f: glib_sys::gpointer,
) where
P: IsA<DropAction>,
{
let f: &F = &*(f as *const F);
f(
&DropAction::from_glib_borrow(this).unsafe_cast_ref(),
&from_glib_borrow(actor),
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"over-in\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
over_in_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_over_out<F: Fn(&Self, &Actor) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn over_out_trampoline<P, F: Fn(&P, &Actor) + 'static>(
this: *mut ffi::ClutterDropAction,
actor: *mut ffi::ClutterActor,
f: glib_sys::gpointer,
) where
P: IsA<DropAction>,
{
let f: &F = &*(f as *const F);
f(
&DropAction::from_glib_borrow(this).unsafe_cast_ref(),
&from_glib_borrow(actor),
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"over-out\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
over_out_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl fmt::Display for DropAction {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "DropAction")
}
}