1use crate::{Accessible, AccessibleRole, ffi};
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GtkATContext")]
65 pub struct ATContext(Object<ffi::GtkATContext, ffi::GtkATContextClass>);
66
67 match fn {
68 type_ => || ffi::gtk_at_context_get_type(),
69 }
70}
71
72impl ATContext {
73 #[doc(alias = "gtk_at_context_create")]
89 pub fn create(
90 accessible_role: AccessibleRole,
91 accessible: &impl IsA<Accessible>,
92 display: &impl IsA<gdk::Display>,
93 ) -> Option<ATContext> {
94 skip_assert_initialized!();
95 unsafe {
96 from_glib_full(ffi::gtk_at_context_create(
97 accessible_role.into_glib(),
98 accessible.as_ref().to_glib_none().0,
99 display.as_ref().to_glib_none().0,
100 ))
101 }
102 }
103
104 #[doc(alias = "gtk_at_context_get_accessible")]
110 #[doc(alias = "get_accessible")]
111 pub fn accessible(&self) -> Accessible {
112 unsafe { from_glib_none(ffi::gtk_at_context_get_accessible(self.to_glib_none().0)) }
113 }
114
115 #[doc(alias = "gtk_at_context_get_accessible_role")]
121 #[doc(alias = "get_accessible_role")]
122 #[doc(alias = "accessible-role")]
123 pub fn accessible_role(&self) -> AccessibleRole {
124 unsafe {
125 from_glib(ffi::gtk_at_context_get_accessible_role(
126 self.to_glib_none().0,
127 ))
128 }
129 }
130
131 #[doc(alias = "accessible-role")]
136 pub fn set_accessible_role(&self, accessible_role: AccessibleRole) {
137 ObjectExt::set_property(self, "accessible-role", accessible_role)
138 }
139
140 pub fn display(&self) -> Option<gdk::Display> {
142 ObjectExt::property(self, "display")
143 }
144
145 pub fn set_display<P: IsA<gdk::Display>>(&self, display: Option<&P>) {
147 ObjectExt::set_property(self, "display", display)
148 }
149
150 #[cfg(feature = "v4_24")]
152 #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
153 pub fn is_realized(&self) -> bool {
154 ObjectExt::property(self, "realized")
155 }
156
157 #[doc(alias = "state-change")]
160 pub fn connect_state_change<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
161 unsafe extern "C" fn state_change_trampoline<F: Fn(&ATContext) + 'static>(
162 this: *mut ffi::GtkATContext,
163 f: glib::ffi::gpointer,
164 ) {
165 unsafe {
166 let f: &F = &*(f as *const F);
167 f(&from_glib_borrow(this))
168 }
169 }
170 unsafe {
171 let f: Box_<F> = Box_::new(f);
172 connect_raw(
173 self.as_ptr() as *mut _,
174 c"state-change".as_ptr(),
175 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
176 state_change_trampoline::<F> as *const (),
177 )),
178 Box_::into_raw(f),
179 )
180 }
181 }
182
183 #[doc(alias = "accessible-role")]
184 pub fn connect_accessible_role_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
185 unsafe extern "C" fn notify_accessible_role_trampoline<F: Fn(&ATContext) + 'static>(
186 this: *mut ffi::GtkATContext,
187 _param_spec: glib::ffi::gpointer,
188 f: glib::ffi::gpointer,
189 ) {
190 unsafe {
191 let f: &F = &*(f as *const F);
192 f(&from_glib_borrow(this))
193 }
194 }
195 unsafe {
196 let f: Box_<F> = Box_::new(f);
197 connect_raw(
198 self.as_ptr() as *mut _,
199 c"notify::accessible-role".as_ptr(),
200 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
201 notify_accessible_role_trampoline::<F> as *const (),
202 )),
203 Box_::into_raw(f),
204 )
205 }
206 }
207
208 #[doc(alias = "display")]
209 pub fn connect_display_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
210 unsafe extern "C" fn notify_display_trampoline<F: Fn(&ATContext) + 'static>(
211 this: *mut ffi::GtkATContext,
212 _param_spec: glib::ffi::gpointer,
213 f: glib::ffi::gpointer,
214 ) {
215 unsafe {
216 let f: &F = &*(f as *const F);
217 f(&from_glib_borrow(this))
218 }
219 }
220 unsafe {
221 let f: Box_<F> = Box_::new(f);
222 connect_raw(
223 self.as_ptr() as *mut _,
224 c"notify::display".as_ptr(),
225 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
226 notify_display_trampoline::<F> as *const (),
227 )),
228 Box_::into_raw(f),
229 )
230 }
231 }
232
233 #[cfg(feature = "v4_24")]
234 #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
235 #[doc(alias = "realized")]
236 pub fn connect_realized_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
237 unsafe extern "C" fn notify_realized_trampoline<F: Fn(&ATContext) + 'static>(
238 this: *mut ffi::GtkATContext,
239 _param_spec: glib::ffi::gpointer,
240 f: glib::ffi::gpointer,
241 ) {
242 unsafe {
243 let f: &F = &*(f as *const F);
244 f(&from_glib_borrow(this))
245 }
246 }
247 unsafe {
248 let f: Box_<F> = Box_::new(f);
249 connect_raw(
250 self.as_ptr() as *mut _,
251 c"notify::realized".as_ptr(),
252 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
253 notify_realized_trampoline::<F> as *const (),
254 )),
255 Box_::into_raw(f),
256 )
257 }
258 }
259}