1#[cfg(feature = "v3_24")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
7use crate::FontChooserLevel;
8use glib::{
9 prelude::*,
10 signal::{connect_raw, SignalHandlerId},
11 translate::*,
12};
13use std::{boxed::Box as Box_, fmt, mem::transmute};
14
15glib::wrapper! {
16 #[doc(alias = "GtkFontChooser")]
17 pub struct FontChooser(Interface<ffi::GtkFontChooser, ffi::GtkFontChooserIface>);
18
19 match fn {
20 type_ => || ffi::gtk_font_chooser_get_type(),
21 }
22}
23
24impl FontChooser {
25 pub const NONE: Option<&'static FontChooser> = None;
26}
27
28mod sealed {
29 pub trait Sealed {}
30 impl<T: super::IsA<super::FontChooser>> Sealed for T {}
31}
32
33pub trait FontChooserExt: IsA<FontChooser> + sealed::Sealed + 'static {
34 #[doc(alias = "gtk_font_chooser_get_font")]
35 #[doc(alias = "get_font")]
36 fn font(&self) -> Option<glib::GString> {
37 unsafe {
38 from_glib_full(ffi::gtk_font_chooser_get_font(
39 self.as_ref().to_glib_none().0,
40 ))
41 }
42 }
43
44 #[doc(alias = "gtk_font_chooser_get_font_desc")]
45 #[doc(alias = "get_font_desc")]
46 fn font_desc(&self) -> Option<pango::FontDescription> {
47 unsafe {
48 from_glib_full(ffi::gtk_font_chooser_get_font_desc(
49 self.as_ref().to_glib_none().0,
50 ))
51 }
52 }
53
54 #[doc(alias = "gtk_font_chooser_get_font_face")]
55 #[doc(alias = "get_font_face")]
56 fn font_face(&self) -> Option<pango::FontFace> {
57 unsafe {
58 from_glib_none(ffi::gtk_font_chooser_get_font_face(
59 self.as_ref().to_glib_none().0,
60 ))
61 }
62 }
63
64 #[doc(alias = "gtk_font_chooser_get_font_family")]
65 #[doc(alias = "get_font_family")]
66 fn font_family(&self) -> Option<pango::FontFamily> {
67 unsafe {
68 from_glib_none(ffi::gtk_font_chooser_get_font_family(
69 self.as_ref().to_glib_none().0,
70 ))
71 }
72 }
73
74 #[cfg(feature = "v3_24")]
75 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
76 #[doc(alias = "gtk_font_chooser_get_font_features")]
77 #[doc(alias = "get_font_features")]
78 fn font_features(&self) -> Option<glib::GString> {
79 unsafe {
80 from_glib_full(ffi::gtk_font_chooser_get_font_features(
81 self.as_ref().to_glib_none().0,
82 ))
83 }
84 }
85
86 #[doc(alias = "gtk_font_chooser_get_font_map")]
87 #[doc(alias = "get_font_map")]
88 fn font_map(&self) -> Option<pango::FontMap> {
89 unsafe {
90 from_glib_full(ffi::gtk_font_chooser_get_font_map(
91 self.as_ref().to_glib_none().0,
92 ))
93 }
94 }
95
96 #[doc(alias = "gtk_font_chooser_get_font_size")]
97 #[doc(alias = "get_font_size")]
98 fn font_size(&self) -> i32 {
99 unsafe { ffi::gtk_font_chooser_get_font_size(self.as_ref().to_glib_none().0) }
100 }
101
102 #[cfg(feature = "v3_24")]
103 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
104 #[doc(alias = "gtk_font_chooser_get_language")]
105 #[doc(alias = "get_language")]
106 fn language(&self) -> Option<glib::GString> {
107 unsafe {
108 from_glib_full(ffi::gtk_font_chooser_get_language(
109 self.as_ref().to_glib_none().0,
110 ))
111 }
112 }
113
114 #[cfg(feature = "v3_24")]
115 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
116 #[doc(alias = "gtk_font_chooser_get_level")]
117 #[doc(alias = "get_level")]
118 fn level(&self) -> FontChooserLevel {
119 unsafe {
120 from_glib(ffi::gtk_font_chooser_get_level(
121 self.as_ref().to_glib_none().0,
122 ))
123 }
124 }
125
126 #[doc(alias = "gtk_font_chooser_get_preview_text")]
127 #[doc(alias = "get_preview_text")]
128 fn preview_text(&self) -> Option<glib::GString> {
129 unsafe {
130 from_glib_full(ffi::gtk_font_chooser_get_preview_text(
131 self.as_ref().to_glib_none().0,
132 ))
133 }
134 }
135
136 #[doc(alias = "gtk_font_chooser_get_show_preview_entry")]
137 #[doc(alias = "get_show_preview_entry")]
138 fn shows_preview_entry(&self) -> bool {
139 unsafe {
140 from_glib(ffi::gtk_font_chooser_get_show_preview_entry(
141 self.as_ref().to_glib_none().0,
142 ))
143 }
144 }
145
146 #[doc(alias = "gtk_font_chooser_set_filter_func")]
147 fn set_filter_func(
148 &self,
149 filter: Option<Box_<dyn Fn(&pango::FontFamily, &pango::FontFace) -> bool + 'static>>,
150 ) {
151 let filter_data: Box_<
152 Option<Box_<dyn Fn(&pango::FontFamily, &pango::FontFace) -> bool + 'static>>,
153 > = Box_::new(filter);
154 unsafe extern "C" fn filter_func(
155 family: *const pango::ffi::PangoFontFamily,
156 face: *const pango::ffi::PangoFontFace,
157 data: glib::ffi::gpointer,
158 ) -> glib::ffi::gboolean {
159 let family = from_glib_borrow(family);
160 let face = from_glib_borrow(face);
161 let callback: &Option<
162 Box_<dyn Fn(&pango::FontFamily, &pango::FontFace) -> bool + 'static>,
163 > = &*(data as *mut _);
164 if let Some(ref callback) = *callback {
165 callback(&family, &face)
166 } else {
167 panic!("cannot get closure...")
168 }
169 .into_glib()
170 }
171 let filter = if filter_data.is_some() {
172 Some(filter_func as _)
173 } else {
174 None
175 };
176 unsafe extern "C" fn destroy_func(data: glib::ffi::gpointer) {
177 let _callback: Box_<
178 Option<Box_<dyn Fn(&pango::FontFamily, &pango::FontFace) -> bool + 'static>>,
179 > = Box_::from_raw(data as *mut _);
180 }
181 let destroy_call3 = Some(destroy_func as _);
182 let super_callback0: Box_<
183 Option<Box_<dyn Fn(&pango::FontFamily, &pango::FontFace) -> bool + 'static>>,
184 > = filter_data;
185 unsafe {
186 ffi::gtk_font_chooser_set_filter_func(
187 self.as_ref().to_glib_none().0,
188 filter,
189 Box_::into_raw(super_callback0) as *mut _,
190 destroy_call3,
191 );
192 }
193 }
194
195 #[doc(alias = "gtk_font_chooser_set_font")]
196 fn set_font(&self, fontname: &str) {
197 unsafe {
198 ffi::gtk_font_chooser_set_font(
199 self.as_ref().to_glib_none().0,
200 fontname.to_glib_none().0,
201 );
202 }
203 }
204
205 #[doc(alias = "gtk_font_chooser_set_font_desc")]
206 fn set_font_desc(&self, font_desc: &pango::FontDescription) {
207 unsafe {
208 ffi::gtk_font_chooser_set_font_desc(
209 self.as_ref().to_glib_none().0,
210 font_desc.to_glib_none().0,
211 );
212 }
213 }
214
215 #[doc(alias = "gtk_font_chooser_set_font_map")]
216 fn set_font_map(&self, fontmap: Option<&impl IsA<pango::FontMap>>) {
217 unsafe {
218 ffi::gtk_font_chooser_set_font_map(
219 self.as_ref().to_glib_none().0,
220 fontmap.map(|p| p.as_ref()).to_glib_none().0,
221 );
222 }
223 }
224
225 #[cfg(feature = "v3_24")]
226 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
227 #[doc(alias = "gtk_font_chooser_set_language")]
228 fn set_language(&self, language: &str) {
229 unsafe {
230 ffi::gtk_font_chooser_set_language(
231 self.as_ref().to_glib_none().0,
232 language.to_glib_none().0,
233 );
234 }
235 }
236
237 #[cfg(feature = "v3_24")]
238 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
239 #[doc(alias = "gtk_font_chooser_set_level")]
240 fn set_level(&self, level: FontChooserLevel) {
241 unsafe {
242 ffi::gtk_font_chooser_set_level(self.as_ref().to_glib_none().0, level.into_glib());
243 }
244 }
245
246 #[doc(alias = "gtk_font_chooser_set_preview_text")]
247 fn set_preview_text(&self, text: &str) {
248 unsafe {
249 ffi::gtk_font_chooser_set_preview_text(
250 self.as_ref().to_glib_none().0,
251 text.to_glib_none().0,
252 );
253 }
254 }
255
256 #[doc(alias = "gtk_font_chooser_set_show_preview_entry")]
257 fn set_show_preview_entry(&self, show_preview_entry: bool) {
258 unsafe {
259 ffi::gtk_font_chooser_set_show_preview_entry(
260 self.as_ref().to_glib_none().0,
261 show_preview_entry.into_glib(),
262 );
263 }
264 }
265
266 #[doc(alias = "font-activated")]
267 fn connect_font_activated<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
268 unsafe extern "C" fn font_activated_trampoline<
269 P: IsA<FontChooser>,
270 F: Fn(&P, &str) + 'static,
271 >(
272 this: *mut ffi::GtkFontChooser,
273 fontname: *mut libc::c_char,
274 f: glib::ffi::gpointer,
275 ) {
276 let f: &F = &*(f as *const F);
277 f(
278 FontChooser::from_glib_borrow(this).unsafe_cast_ref(),
279 &glib::GString::from_glib_borrow(fontname),
280 )
281 }
282 unsafe {
283 let f: Box_<F> = Box_::new(f);
284 connect_raw(
285 self.as_ptr() as *mut _,
286 b"font-activated\0".as_ptr() as *const _,
287 Some(transmute::<_, unsafe extern "C" fn()>(
288 font_activated_trampoline::<Self, F> as *const (),
289 )),
290 Box_::into_raw(f),
291 )
292 }
293 }
294
295 #[doc(alias = "font")]
296 fn connect_font_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
297 unsafe extern "C" fn notify_font_trampoline<P: IsA<FontChooser>, F: Fn(&P) + 'static>(
298 this: *mut ffi::GtkFontChooser,
299 _param_spec: glib::ffi::gpointer,
300 f: glib::ffi::gpointer,
301 ) {
302 let f: &F = &*(f as *const F);
303 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
304 }
305 unsafe {
306 let f: Box_<F> = Box_::new(f);
307 connect_raw(
308 self.as_ptr() as *mut _,
309 b"notify::font\0".as_ptr() as *const _,
310 Some(transmute::<_, unsafe extern "C" fn()>(
311 notify_font_trampoline::<Self, F> as *const (),
312 )),
313 Box_::into_raw(f),
314 )
315 }
316 }
317
318 #[doc(alias = "font-desc")]
319 fn connect_font_desc_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
320 unsafe extern "C" fn notify_font_desc_trampoline<
321 P: IsA<FontChooser>,
322 F: Fn(&P) + 'static,
323 >(
324 this: *mut ffi::GtkFontChooser,
325 _param_spec: glib::ffi::gpointer,
326 f: glib::ffi::gpointer,
327 ) {
328 let f: &F = &*(f as *const F);
329 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
330 }
331 unsafe {
332 let f: Box_<F> = Box_::new(f);
333 connect_raw(
334 self.as_ptr() as *mut _,
335 b"notify::font-desc\0".as_ptr() as *const _,
336 Some(transmute::<_, unsafe extern "C" fn()>(
337 notify_font_desc_trampoline::<Self, F> as *const (),
338 )),
339 Box_::into_raw(f),
340 )
341 }
342 }
343
344 #[cfg(feature = "v3_24")]
345 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
346 #[doc(alias = "font-features")]
347 fn connect_font_features_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
348 unsafe extern "C" fn notify_font_features_trampoline<
349 P: IsA<FontChooser>,
350 F: Fn(&P) + 'static,
351 >(
352 this: *mut ffi::GtkFontChooser,
353 _param_spec: glib::ffi::gpointer,
354 f: glib::ffi::gpointer,
355 ) {
356 let f: &F = &*(f as *const F);
357 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
358 }
359 unsafe {
360 let f: Box_<F> = Box_::new(f);
361 connect_raw(
362 self.as_ptr() as *mut _,
363 b"notify::font-features\0".as_ptr() as *const _,
364 Some(transmute::<_, unsafe extern "C" fn()>(
365 notify_font_features_trampoline::<Self, F> as *const (),
366 )),
367 Box_::into_raw(f),
368 )
369 }
370 }
371
372 #[cfg(feature = "v3_24")]
373 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
374 #[doc(alias = "language")]
375 fn connect_language_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
376 unsafe extern "C" fn notify_language_trampoline<
377 P: IsA<FontChooser>,
378 F: Fn(&P) + 'static,
379 >(
380 this: *mut ffi::GtkFontChooser,
381 _param_spec: glib::ffi::gpointer,
382 f: glib::ffi::gpointer,
383 ) {
384 let f: &F = &*(f as *const F);
385 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
386 }
387 unsafe {
388 let f: Box_<F> = Box_::new(f);
389 connect_raw(
390 self.as_ptr() as *mut _,
391 b"notify::language\0".as_ptr() as *const _,
392 Some(transmute::<_, unsafe extern "C" fn()>(
393 notify_language_trampoline::<Self, F> as *const (),
394 )),
395 Box_::into_raw(f),
396 )
397 }
398 }
399
400 #[cfg(feature = "v3_24")]
401 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
402 #[doc(alias = "level")]
403 fn connect_level_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
404 unsafe extern "C" fn notify_level_trampoline<P: IsA<FontChooser>, F: Fn(&P) + 'static>(
405 this: *mut ffi::GtkFontChooser,
406 _param_spec: glib::ffi::gpointer,
407 f: glib::ffi::gpointer,
408 ) {
409 let f: &F = &*(f as *const F);
410 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
411 }
412 unsafe {
413 let f: Box_<F> = Box_::new(f);
414 connect_raw(
415 self.as_ptr() as *mut _,
416 b"notify::level\0".as_ptr() as *const _,
417 Some(transmute::<_, unsafe extern "C" fn()>(
418 notify_level_trampoline::<Self, F> as *const (),
419 )),
420 Box_::into_raw(f),
421 )
422 }
423 }
424
425 #[doc(alias = "preview-text")]
426 fn connect_preview_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
427 unsafe extern "C" fn notify_preview_text_trampoline<
428 P: IsA<FontChooser>,
429 F: Fn(&P) + 'static,
430 >(
431 this: *mut ffi::GtkFontChooser,
432 _param_spec: glib::ffi::gpointer,
433 f: glib::ffi::gpointer,
434 ) {
435 let f: &F = &*(f as *const F);
436 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
437 }
438 unsafe {
439 let f: Box_<F> = Box_::new(f);
440 connect_raw(
441 self.as_ptr() as *mut _,
442 b"notify::preview-text\0".as_ptr() as *const _,
443 Some(transmute::<_, unsafe extern "C" fn()>(
444 notify_preview_text_trampoline::<Self, F> as *const (),
445 )),
446 Box_::into_raw(f),
447 )
448 }
449 }
450
451 #[doc(alias = "show-preview-entry")]
452 fn connect_show_preview_entry_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
453 unsafe extern "C" fn notify_show_preview_entry_trampoline<
454 P: IsA<FontChooser>,
455 F: Fn(&P) + 'static,
456 >(
457 this: *mut ffi::GtkFontChooser,
458 _param_spec: glib::ffi::gpointer,
459 f: glib::ffi::gpointer,
460 ) {
461 let f: &F = &*(f as *const F);
462 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
463 }
464 unsafe {
465 let f: Box_<F> = Box_::new(f);
466 connect_raw(
467 self.as_ptr() as *mut _,
468 b"notify::show-preview-entry\0".as_ptr() as *const _,
469 Some(transmute::<_, unsafe extern "C" fn()>(
470 notify_show_preview_entry_trampoline::<Self, F> as *const (),
471 )),
472 Box_::into_raw(f),
473 )
474 }
475 }
476}
477
478impl<O: IsA<FontChooser>> FontChooserExt for O {}
479
480impl fmt::Display for FontChooser {
481 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
482 f.write_str("FontChooser")
483 }
484}