1use crate::{Expression, Filter, ffi};
6use glib::{
7 prelude::*,
8 signal::{SignalHandlerId, connect_raw},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GtkBoolFilter")]
34 pub struct BoolFilter(Object<ffi::GtkBoolFilter, ffi::GtkBoolFilterClass>) @extends Filter;
35
36 match fn {
37 type_ => || ffi::gtk_bool_filter_get_type(),
38 }
39}
40
41impl BoolFilter {
42 #[doc(alias = "gtk_bool_filter_new")]
50 pub fn new(expression: Option<impl AsRef<Expression>>) -> BoolFilter {
51 assert_initialized_main_thread!();
52 unsafe {
53 from_glib_full(ffi::gtk_bool_filter_new(
54 expression
55 .map(|p| p.as_ref().clone().upcast())
56 .into_glib_ptr(),
57 ))
58 }
59 }
60
61 pub fn builder() -> BoolFilterBuilder {
66 BoolFilterBuilder::new()
67 }
68
69 #[doc(alias = "gtk_bool_filter_get_expression")]
76 #[doc(alias = "get_expression")]
77 pub fn expression(&self) -> Option<Expression> {
78 unsafe { from_glib_none(ffi::gtk_bool_filter_get_expression(self.to_glib_none().0)) }
79 }
80
81 #[doc(alias = "gtk_bool_filter_get_invert")]
87 #[doc(alias = "get_invert")]
88 #[doc(alias = "invert")]
89 pub fn inverts(&self) -> bool {
90 unsafe { from_glib(ffi::gtk_bool_filter_get_invert(self.to_glib_none().0)) }
91 }
92
93 #[doc(alias = "gtk_bool_filter_set_expression")]
100 #[doc(alias = "expression")]
101 pub fn set_expression(&self, expression: Option<impl AsRef<Expression>>) {
102 unsafe {
103 ffi::gtk_bool_filter_set_expression(
104 self.to_glib_none().0,
105 expression.as_ref().map(|p| p.as_ref()).to_glib_none().0,
106 );
107 }
108 }
109
110 #[doc(alias = "gtk_bool_filter_set_invert")]
114 #[doc(alias = "invert")]
115 pub fn set_invert(&self, invert: bool) {
116 unsafe {
117 ffi::gtk_bool_filter_set_invert(self.to_glib_none().0, invert.into_glib());
118 }
119 }
120
121 #[doc(alias = "expression")]
122 pub fn connect_expression_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
123 unsafe extern "C" fn notify_expression_trampoline<F: Fn(&BoolFilter) + 'static>(
124 this: *mut ffi::GtkBoolFilter,
125 _param_spec: glib::ffi::gpointer,
126 f: glib::ffi::gpointer,
127 ) {
128 unsafe {
129 let f: &F = &*(f as *const F);
130 f(&from_glib_borrow(this))
131 }
132 }
133 unsafe {
134 let f: Box_<F> = Box_::new(f);
135 connect_raw(
136 self.as_ptr() as *mut _,
137 c"notify::expression".as_ptr() as *const _,
138 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
139 notify_expression_trampoline::<F> as *const (),
140 )),
141 Box_::into_raw(f),
142 )
143 }
144 }
145
146 #[doc(alias = "invert")]
147 pub fn connect_invert_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
148 unsafe extern "C" fn notify_invert_trampoline<F: Fn(&BoolFilter) + 'static>(
149 this: *mut ffi::GtkBoolFilter,
150 _param_spec: glib::ffi::gpointer,
151 f: glib::ffi::gpointer,
152 ) {
153 unsafe {
154 let f: &F = &*(f as *const F);
155 f(&from_glib_borrow(this))
156 }
157 }
158 unsafe {
159 let f: Box_<F> = Box_::new(f);
160 connect_raw(
161 self.as_ptr() as *mut _,
162 c"notify::invert".as_ptr() as *const _,
163 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
164 notify_invert_trampoline::<F> as *const (),
165 )),
166 Box_::into_raw(f),
167 )
168 }
169 }
170}
171
172impl Default for BoolFilter {
173 fn default() -> Self {
174 glib::object::Object::new::<Self>()
175 }
176}
177
178#[must_use = "The builder must be built to be used"]
183pub struct BoolFilterBuilder {
184 builder: glib::object::ObjectBuilder<'static, BoolFilter>,
185}
186
187impl BoolFilterBuilder {
188 fn new() -> Self {
189 Self {
190 builder: glib::object::Object::builder(),
191 }
192 }
193
194 pub fn expression(self, expression: impl AsRef<Expression>) -> Self {
196 Self {
197 builder: self
198 .builder
199 .property("expression", expression.as_ref().clone()),
200 }
201 }
202
203 pub fn invert(self, invert: bool) -> Self {
205 Self {
206 builder: self.builder.property("invert", invert),
207 }
208 }
209
210 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
213 pub fn build(self) -> BoolFilter {
214 assert_initialized_main_thread!();
215 self.builder.build()
216 }
217}