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 5 use crate::Action; 6 use glib::object::ObjectType as ObjectType_; 7 use glib::signal::connect_raw; 8 use glib::signal::SignalHandlerId; 9 use glib::translate::*; 10 use std::boxed::Box as Box_; 11 use std::fmt; 12 use std::mem::transmute; 13 14 glib::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 23 impl SimpleAction { 24 #[doc(alias = "g_simple_action_new")] new(name: &str, parameter_type: Option<&glib::VariantTy>) -> SimpleAction25 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")] new_stateful( name: &str, parameter_type: Option<&glib::VariantTy>, state: &glib::Variant, ) -> SimpleAction35 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")] set_enabled(&self, enabled: bool)50 pub fn set_enabled(&self, enabled: bool) { 51 unsafe { 52 ffi::g_simple_action_set_enabled(self.to_glib_none().0, enabled.into_glib()); 53 } 54 } 55 56 #[doc(alias = "g_simple_action_set_state")] set_state(&self, value: &glib::Variant)57 pub fn set_state(&self, value: &glib::Variant) { 58 unsafe { 59 ffi::g_simple_action_set_state(self.to_glib_none().0, value.to_glib_none().0); 60 } 61 } 62 63 #[doc(alias = "g_simple_action_set_state_hint")] set_state_hint(&self, state_hint: Option<&glib::Variant>)64 pub fn set_state_hint(&self, state_hint: Option<&glib::Variant>) { 65 unsafe { 66 ffi::g_simple_action_set_state_hint(self.to_glib_none().0, state_hint.to_glib_none().0); 67 } 68 } 69 70 #[doc(alias = "activate")] connect_activate<F: Fn(&Self, Option<&glib::Variant>) + 'static>( &self, f: F, ) -> SignalHandlerId71 pub fn connect_activate<F: Fn(&Self, Option<&glib::Variant>) + 'static>( 72 &self, 73 f: F, 74 ) -> SignalHandlerId { 75 unsafe extern "C" fn activate_trampoline< 76 F: Fn(&SimpleAction, Option<&glib::Variant>) + 'static, 77 >( 78 this: *mut ffi::GSimpleAction, 79 parameter: *mut glib::ffi::GVariant, 80 f: glib::ffi::gpointer, 81 ) { 82 let f: &F = &*(f as *const F); 83 f( 84 &from_glib_borrow(this), 85 Option::<glib::Variant>::from_glib_borrow(parameter) 86 .as_ref() 87 .as_ref(), 88 ) 89 } 90 unsafe { 91 let f: Box_<F> = Box_::new(f); 92 connect_raw( 93 self.as_ptr() as *mut _, 94 b"activate\0".as_ptr() as *const _, 95 Some(transmute::<_, unsafe extern "C" fn()>( 96 activate_trampoline::<F> as *const (), 97 )), 98 Box_::into_raw(f), 99 ) 100 } 101 } 102 103 #[doc(alias = "change-state")] connect_change_state<F: Fn(&Self, Option<&glib::Variant>) + 'static>( &self, f: F, ) -> SignalHandlerId104 pub fn connect_change_state<F: Fn(&Self, Option<&glib::Variant>) + 'static>( 105 &self, 106 f: F, 107 ) -> SignalHandlerId { 108 unsafe extern "C" fn change_state_trampoline< 109 F: Fn(&SimpleAction, Option<&glib::Variant>) + 'static, 110 >( 111 this: *mut ffi::GSimpleAction, 112 value: *mut glib::ffi::GVariant, 113 f: glib::ffi::gpointer, 114 ) { 115 let f: &F = &*(f as *const F); 116 f( 117 &from_glib_borrow(this), 118 Option::<glib::Variant>::from_glib_borrow(value) 119 .as_ref() 120 .as_ref(), 121 ) 122 } 123 unsafe { 124 let f: Box_<F> = Box_::new(f); 125 connect_raw( 126 self.as_ptr() as *mut _, 127 b"change-state\0".as_ptr() as *const _, 128 Some(transmute::<_, unsafe extern "C" fn()>( 129 change_state_trampoline::<F> as *const (), 130 )), 131 Box_::into_raw(f), 132 ) 133 } 134 } 135 136 #[doc(alias = "enabled")] connect_enabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId137 pub fn connect_enabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 138 unsafe extern "C" fn notify_enabled_trampoline<F: Fn(&SimpleAction) + 'static>( 139 this: *mut ffi::GSimpleAction, 140 _param_spec: glib::ffi::gpointer, 141 f: glib::ffi::gpointer, 142 ) { 143 let f: &F = &*(f as *const F); 144 f(&from_glib_borrow(this)) 145 } 146 unsafe { 147 let f: Box_<F> = Box_::new(f); 148 connect_raw( 149 self.as_ptr() as *mut _, 150 b"notify::enabled\0".as_ptr() as *const _, 151 Some(transmute::<_, unsafe extern "C" fn()>( 152 notify_enabled_trampoline::<F> as *const (), 153 )), 154 Box_::into_raw(f), 155 ) 156 } 157 } 158 159 #[doc(alias = "state-type")] connect_state_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId160 pub fn connect_state_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 161 unsafe extern "C" fn notify_state_type_trampoline<F: Fn(&SimpleAction) + 'static>( 162 this: *mut ffi::GSimpleAction, 163 _param_spec: glib::ffi::gpointer, 164 f: glib::ffi::gpointer, 165 ) { 166 let f: &F = &*(f as *const F); 167 f(&from_glib_borrow(this)) 168 } 169 unsafe { 170 let f: Box_<F> = Box_::new(f); 171 connect_raw( 172 self.as_ptr() as *mut _, 173 b"notify::state-type\0".as_ptr() as *const _, 174 Some(transmute::<_, unsafe extern "C" fn()>( 175 notify_state_type_trampoline::<F> as *const (), 176 )), 177 Box_::into_raw(f), 178 ) 179 } 180 } 181 } 182 183 impl fmt::Display for SimpleAction { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result184 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 185 f.write_str("SimpleAction") 186 } 187 } 188