1use glib;
6use glib::object::Cast;
7use glib::object::IsA;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib::GString;
12use glib_sys;
13use gtk_sys;
14use std::boxed::Box as Box_;
15use std::fmt;
16use std::mem::transmute;
17use Buildable;
18use Widget;
19
20glib_wrapper! {
21 pub struct Actionable(Interface<gtk_sys::GtkActionable>) @requires Widget, Buildable;
22
23 match fn {
24 get_type => || gtk_sys::gtk_actionable_get_type(),
25 }
26}
27
28pub const NONE_ACTIONABLE: Option<&Actionable> = None;
29
30pub trait ActionableExt: 'static {
31 fn get_action_name(&self) -> Option<GString>;
32
33 fn get_action_target_value(&self) -> Option<glib::Variant>;
34
35 fn set_action_name(&self, action_name: Option<&str>);
36
37 fn set_action_target_value(&self, target_value: Option<&glib::Variant>);
40
41 fn set_detailed_action_name(&self, detailed_action_name: &str);
42
43 fn connect_property_action_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
44}
45
46impl<O: IsA<Actionable>> ActionableExt for O {
47 fn get_action_name(&self) -> Option<GString> {
48 unsafe {
49 from_glib_none(gtk_sys::gtk_actionable_get_action_name(
50 self.as_ref().to_glib_none().0,
51 ))
52 }
53 }
54
55 fn get_action_target_value(&self) -> Option<glib::Variant> {
56 unsafe {
57 from_glib_none(gtk_sys::gtk_actionable_get_action_target_value(
58 self.as_ref().to_glib_none().0,
59 ))
60 }
61 }
62
63 fn set_action_name(&self, action_name: Option<&str>) {
64 unsafe {
65 gtk_sys::gtk_actionable_set_action_name(
66 self.as_ref().to_glib_none().0,
67 action_name.to_glib_none().0,
68 );
69 }
70 }
71
72 fn set_action_target_value(&self, target_value: Option<&glib::Variant>) {
77 unsafe {
78 gtk_sys::gtk_actionable_set_action_target_value(
79 self.as_ref().to_glib_none().0,
80 target_value.to_glib_none().0,
81 );
82 }
83 }
84
85 fn set_detailed_action_name(&self, detailed_action_name: &str) {
86 unsafe {
87 gtk_sys::gtk_actionable_set_detailed_action_name(
88 self.as_ref().to_glib_none().0,
89 detailed_action_name.to_glib_none().0,
90 );
91 }
92 }
93
94 fn connect_property_action_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
95 unsafe extern "C" fn notify_action_name_trampoline<P, F: Fn(&P) + 'static>(
96 this: *mut gtk_sys::GtkActionable,
97 _param_spec: glib_sys::gpointer,
98 f: glib_sys::gpointer,
99 ) where
100 P: IsA<Actionable>,
101 {
102 let f: &F = &*(f as *const F);
103 f(&Actionable::from_glib_borrow(this).unsafe_cast())
104 }
105 unsafe {
106 let f: Box_<F> = Box_::new(f);
107 connect_raw(
108 self.as_ptr() as *mut _,
109 b"notify::action-name\0".as_ptr() as *const _,
110 Some(transmute(notify_action_name_trampoline::<Self, F> as usize)),
111 Box_::into_raw(f),
112 )
113 }
114 }
115}
116
117impl fmt::Display for Actionable {
118 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
119 write!(f, "Actionable")
120 }
121}