1use crate::{ffi, Expression, Filter};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GtkBoolFilter")]
15 pub struct BoolFilter(Object<ffi::GtkBoolFilter, ffi::GtkBoolFilterClass>) @extends Filter;
16
17 match fn {
18 type_ => || ffi::gtk_bool_filter_get_type(),
19 }
20}
21
22impl BoolFilter {
23 #[doc(alias = "gtk_bool_filter_new")]
24 pub fn new(expression: Option<impl AsRef<Expression>>) -> BoolFilter {
25 assert_initialized_main_thread!();
26 unsafe {
27 from_glib_full(ffi::gtk_bool_filter_new(
28 expression
29 .map(|p| p.as_ref().clone().upcast())
30 .into_glib_ptr(),
31 ))
32 }
33 }
34
35 pub fn builder() -> BoolFilterBuilder {
40 BoolFilterBuilder::new()
41 }
42
43 #[doc(alias = "gtk_bool_filter_get_expression")]
44 #[doc(alias = "get_expression")]
45 pub fn expression(&self) -> Option<Expression> {
46 unsafe { from_glib_none(ffi::gtk_bool_filter_get_expression(self.to_glib_none().0)) }
47 }
48
49 #[doc(alias = "gtk_bool_filter_get_invert")]
50 #[doc(alias = "get_invert")]
51 #[doc(alias = "invert")]
52 pub fn inverts(&self) -> bool {
53 unsafe { from_glib(ffi::gtk_bool_filter_get_invert(self.to_glib_none().0)) }
54 }
55
56 #[doc(alias = "gtk_bool_filter_set_expression")]
57 #[doc(alias = "expression")]
58 pub fn set_expression(&self, expression: Option<impl AsRef<Expression>>) {
59 unsafe {
60 ffi::gtk_bool_filter_set_expression(
61 self.to_glib_none().0,
62 expression.as_ref().map(|p| p.as_ref()).to_glib_none().0,
63 );
64 }
65 }
66
67 #[doc(alias = "gtk_bool_filter_set_invert")]
68 #[doc(alias = "invert")]
69 pub fn set_invert(&self, invert: bool) {
70 unsafe {
71 ffi::gtk_bool_filter_set_invert(self.to_glib_none().0, invert.into_glib());
72 }
73 }
74
75 #[doc(alias = "expression")]
76 pub fn connect_expression_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
77 unsafe extern "C" fn notify_expression_trampoline<F: Fn(&BoolFilter) + 'static>(
78 this: *mut ffi::GtkBoolFilter,
79 _param_spec: glib::ffi::gpointer,
80 f: glib::ffi::gpointer,
81 ) {
82 let f: &F = &*(f as *const F);
83 f(&from_glib_borrow(this))
84 }
85 unsafe {
86 let f: Box_<F> = Box_::new(f);
87 connect_raw(
88 self.as_ptr() as *mut _,
89 c"notify::expression".as_ptr() as *const _,
90 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
91 notify_expression_trampoline::<F> as *const (),
92 )),
93 Box_::into_raw(f),
94 )
95 }
96 }
97
98 #[doc(alias = "invert")]
99 pub fn connect_invert_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
100 unsafe extern "C" fn notify_invert_trampoline<F: Fn(&BoolFilter) + 'static>(
101 this: *mut ffi::GtkBoolFilter,
102 _param_spec: glib::ffi::gpointer,
103 f: glib::ffi::gpointer,
104 ) {
105 let f: &F = &*(f as *const F);
106 f(&from_glib_borrow(this))
107 }
108 unsafe {
109 let f: Box_<F> = Box_::new(f);
110 connect_raw(
111 self.as_ptr() as *mut _,
112 c"notify::invert".as_ptr() as *const _,
113 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
114 notify_invert_trampoline::<F> as *const (),
115 )),
116 Box_::into_raw(f),
117 )
118 }
119 }
120}
121
122impl Default for BoolFilter {
123 fn default() -> Self {
124 glib::object::Object::new::<Self>()
125 }
126}
127
128#[must_use = "The builder must be built to be used"]
133pub struct BoolFilterBuilder {
134 builder: glib::object::ObjectBuilder<'static, BoolFilter>,
135}
136
137impl BoolFilterBuilder {
138 fn new() -> Self {
139 Self {
140 builder: glib::object::Object::builder(),
141 }
142 }
143
144 pub fn expression(self, expression: impl AsRef<Expression>) -> Self {
145 Self {
146 builder: self
147 .builder
148 .property("expression", expression.as_ref().clone()),
149 }
150 }
151
152 pub fn invert(self, invert: bool) -> Self {
153 Self {
154 builder: self.builder.property("invert", invert),
155 }
156 }
157
158 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
161 pub fn build(self) -> BoolFilter {
162 assert_initialized_main_thread!();
163 self.builder.build()
164 }
165}