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