gio/auto/
simple_action.rs1use crate::{ffi, Action};
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 = "GSimpleAction")]
16 pub struct SimpleAction(Object<ffi::GSimpleAction>) @implements Action;
17
18 match fn {
19 type_ => || ffi::g_simple_action_get_type(),
20 }
21}
22
23impl SimpleAction {
24 #[doc(alias = "g_simple_action_new")]
25 pub fn new(name: &str, parameter_type: Option<&glib::VariantTy>) -> SimpleAction {
26 unsafe {
27 from_glib_full(ffi::g_simple_action_new(
28 name.to_glib_none().0,
29 parameter_type.to_glib_none().0,
30 ))
31 }
32 }
33
34 #[doc(alias = "g_simple_action_new_stateful")]
35 pub fn new_stateful(
36 name: &str,
37 parameter_type: Option<&glib::VariantTy>,
38 state: &glib::Variant,
39 ) -> SimpleAction {
40 unsafe {
41 from_glib_full(ffi::g_simple_action_new_stateful(
42 name.to_glib_none().0,
43 parameter_type.to_glib_none().0,
44 state.to_glib_none().0,
45 ))
46 }
47 }
48
49 #[doc(alias = "g_simple_action_set_enabled")]
50 #[doc(alias = "enabled")]
51 pub fn set_enabled(&self, enabled: bool) {
52 unsafe {
53 ffi::g_simple_action_set_enabled(self.to_glib_none().0, enabled.into_glib());
54 }
55 }
56
57 #[doc(alias = "g_simple_action_set_state")]
58 #[doc(alias = "state")]
59 pub fn set_state(&self, value: &glib::Variant) {
60 unsafe {
61 ffi::g_simple_action_set_state(self.to_glib_none().0, value.to_glib_none().0);
62 }
63 }
64
65 #[doc(alias = "g_simple_action_set_state_hint")]
66 pub fn set_state_hint(&self, state_hint: Option<&glib::Variant>) {
67 unsafe {
68 ffi::g_simple_action_set_state_hint(self.to_glib_none().0, state_hint.to_glib_none().0);
69 }
70 }
71
72 #[doc(alias = "activate")]
73 pub fn connect_activate<F: Fn(&Self, Option<&glib::Variant>) + 'static>(
74 &self,
75 f: F,
76 ) -> SignalHandlerId {
77 unsafe extern "C" fn activate_trampoline<
78 F: Fn(&SimpleAction, Option<&glib::Variant>) + 'static,
79 >(
80 this: *mut ffi::GSimpleAction,
81 parameter: *mut glib::ffi::GVariant,
82 f: glib::ffi::gpointer,
83 ) {
84 let f: &F = &*(f as *const F);
85 f(
86 &from_glib_borrow(this),
87 Option::<glib::Variant>::from_glib_borrow(parameter)
88 .as_ref()
89 .as_ref(),
90 )
91 }
92 unsafe {
93 let f: Box_<F> = Box_::new(f);
94 connect_raw(
95 self.as_ptr() as *mut _,
96 c"activate".as_ptr() as *const _,
97 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
98 activate_trampoline::<F> as *const (),
99 )),
100 Box_::into_raw(f),
101 )
102 }
103 }
104
105 #[doc(alias = "change-state")]
106 pub fn connect_change_state<F: Fn(&Self, Option<&glib::Variant>) + 'static>(
107 &self,
108 f: F,
109 ) -> SignalHandlerId {
110 unsafe extern "C" fn change_state_trampoline<
111 F: Fn(&SimpleAction, Option<&glib::Variant>) + 'static,
112 >(
113 this: *mut ffi::GSimpleAction,
114 value: *mut glib::ffi::GVariant,
115 f: glib::ffi::gpointer,
116 ) {
117 let f: &F = &*(f as *const F);
118 f(
119 &from_glib_borrow(this),
120 Option::<glib::Variant>::from_glib_borrow(value)
121 .as_ref()
122 .as_ref(),
123 )
124 }
125 unsafe {
126 let f: Box_<F> = Box_::new(f);
127 connect_raw(
128 self.as_ptr() as *mut _,
129 c"change-state".as_ptr() as *const _,
130 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
131 change_state_trampoline::<F> as *const (),
132 )),
133 Box_::into_raw(f),
134 )
135 }
136 }
137}