1use crate::{ffi, Accessible, AccessibleRole};
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 = "GtkATContext")]
16 pub struct ATContext(Object<ffi::GtkATContext, ffi::GtkATContextClass>);
17
18 match fn {
19 type_ => || ffi::gtk_at_context_get_type(),
20 }
21}
22
23impl ATContext {
24 #[doc(alias = "gtk_at_context_create")]
25 pub fn create(
26 accessible_role: AccessibleRole,
27 accessible: &impl IsA<Accessible>,
28 display: &impl IsA<gdk::Display>,
29 ) -> Option<ATContext> {
30 skip_assert_initialized!();
31 unsafe {
32 from_glib_full(ffi::gtk_at_context_create(
33 accessible_role.into_glib(),
34 accessible.as_ref().to_glib_none().0,
35 display.as_ref().to_glib_none().0,
36 ))
37 }
38 }
39
40 #[doc(alias = "gtk_at_context_get_accessible")]
41 #[doc(alias = "get_accessible")]
42 pub fn accessible(&self) -> Accessible {
43 unsafe { from_glib_none(ffi::gtk_at_context_get_accessible(self.to_glib_none().0)) }
44 }
45
46 #[doc(alias = "gtk_at_context_get_accessible_role")]
47 #[doc(alias = "get_accessible_role")]
48 #[doc(alias = "accessible-role")]
49 pub fn accessible_role(&self) -> AccessibleRole {
50 unsafe {
51 from_glib(ffi::gtk_at_context_get_accessible_role(
52 self.to_glib_none().0,
53 ))
54 }
55 }
56
57 #[doc(alias = "accessible-role")]
58 pub fn set_accessible_role(&self, accessible_role: AccessibleRole) {
59 ObjectExt::set_property(self, "accessible-role", accessible_role)
60 }
61
62 pub fn display(&self) -> Option<gdk::Display> {
63 ObjectExt::property(self, "display")
64 }
65
66 pub fn set_display<P: IsA<gdk::Display>>(&self, display: Option<&P>) {
67 ObjectExt::set_property(self, "display", display)
68 }
69
70 #[doc(alias = "state-change")]
71 pub fn connect_state_change<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
72 unsafe extern "C" fn state_change_trampoline<F: Fn(&ATContext) + 'static>(
73 this: *mut ffi::GtkATContext,
74 f: glib::ffi::gpointer,
75 ) {
76 let f: &F = &*(f as *const F);
77 f(&from_glib_borrow(this))
78 }
79 unsafe {
80 let f: Box_<F> = Box_::new(f);
81 connect_raw(
82 self.as_ptr() as *mut _,
83 c"state-change".as_ptr() as *const _,
84 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
85 state_change_trampoline::<F> as *const (),
86 )),
87 Box_::into_raw(f),
88 )
89 }
90 }
91
92 #[doc(alias = "accessible-role")]
93 pub fn connect_accessible_role_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
94 unsafe extern "C" fn notify_accessible_role_trampoline<F: Fn(&ATContext) + 'static>(
95 this: *mut ffi::GtkATContext,
96 _param_spec: glib::ffi::gpointer,
97 f: glib::ffi::gpointer,
98 ) {
99 let f: &F = &*(f as *const F);
100 f(&from_glib_borrow(this))
101 }
102 unsafe {
103 let f: Box_<F> = Box_::new(f);
104 connect_raw(
105 self.as_ptr() as *mut _,
106 c"notify::accessible-role".as_ptr() as *const _,
107 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
108 notify_accessible_role_trampoline::<F> as *const (),
109 )),
110 Box_::into_raw(f),
111 )
112 }
113 }
114
115 #[doc(alias = "display")]
116 pub fn connect_display_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
117 unsafe extern "C" fn notify_display_trampoline<F: Fn(&ATContext) + 'static>(
118 this: *mut ffi::GtkATContext,
119 _param_spec: glib::ffi::gpointer,
120 f: glib::ffi::gpointer,
121 ) {
122 let f: &F = &*(f as *const F);
123 f(&from_glib_borrow(this))
124 }
125 unsafe {
126 let f: Box_<F> = Box_::new(f);
127 connect_raw(
128 self.as_ptr() as *mut _,
129 c"notify::display".as_ptr() as *const _,
130 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
131 notify_display_trampoline::<F> as *const (),
132 )),
133 Box_::into_raw(f),
134 )
135 }
136 }
137}