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")]
84 pub struct FontChooser(Interface<ffi::GtkFontChooser, ffi::GtkFontChooserIface>);
85
86 match fn {
87 type_ => || ffi::gtk_font_chooser_get_type(),
88 }
89}
90
91impl FontChooser {
92 pub const NONE: Option<&'static FontChooser> = None;
93}
94
95mod sealed {
96 pub trait Sealed {}
97 impl<T: super::IsA<super::FontChooser>> Sealed for T {}
98}
99
100pub trait FontChooserExt: IsA<FontChooser> + sealed::Sealed + 'static {
106 #[doc(alias = "gtk_font_chooser_get_font")]
123 #[doc(alias = "get_font")]
124 fn font(&self) -> Option<glib::GString> {
125 unsafe {
126 from_glib_full(ffi::gtk_font_chooser_get_font(
127 self.as_ref().to_glib_none().0,
128 ))
129 }
130 }
131
132 #[doc(alias = "gtk_font_chooser_get_font_desc")]
148 #[doc(alias = "get_font_desc")]
149 fn font_desc(&self) -> Option<pango::FontDescription> {
150 unsafe {
151 from_glib_full(ffi::gtk_font_chooser_get_font_desc(
152 self.as_ref().to_glib_none().0,
153 ))
154 }
155 }
156
157 #[doc(alias = "gtk_font_chooser_get_font_face")]
168 #[doc(alias = "get_font_face")]
169 fn font_face(&self) -> Option<pango::FontFace> {
170 unsafe {
171 from_glib_none(ffi::gtk_font_chooser_get_font_face(
172 self.as_ref().to_glib_none().0,
173 ))
174 }
175 }
176
177 #[doc(alias = "gtk_font_chooser_get_font_family")]
188 #[doc(alias = "get_font_family")]
189 fn font_family(&self) -> Option<pango::FontFamily> {
190 unsafe {
191 from_glib_none(ffi::gtk_font_chooser_get_font_family(
192 self.as_ref().to_glib_none().0,
193 ))
194 }
195 }
196
197 #[cfg(feature = "v3_24")]
203 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
204 #[doc(alias = "gtk_font_chooser_get_font_features")]
205 #[doc(alias = "get_font_features")]
206 fn font_features(&self) -> Option<glib::GString> {
207 unsafe {
208 from_glib_full(ffi::gtk_font_chooser_get_font_features(
209 self.as_ref().to_glib_none().0,
210 ))
211 }
212 }
213
214 #[doc(alias = "gtk_font_chooser_get_font_map")]
221 #[doc(alias = "get_font_map")]
222 fn font_map(&self) -> Option<pango::FontMap> {
223 unsafe {
224 from_glib_full(ffi::gtk_font_chooser_get_font_map(
225 self.as_ref().to_glib_none().0,
226 ))
227 }
228 }
229
230 #[doc(alias = "gtk_font_chooser_get_font_size")]
237 #[doc(alias = "get_font_size")]
238 fn font_size(&self) -> i32 {
239 unsafe { ffi::gtk_font_chooser_get_font_size(self.as_ref().to_glib_none().0) }
240 }
241
242 #[cfg(feature = "v3_24")]
248 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
249 #[doc(alias = "gtk_font_chooser_get_language")]
250 #[doc(alias = "get_language")]
251 fn language(&self) -> Option<glib::GString> {
252 unsafe {
253 from_glib_full(ffi::gtk_font_chooser_get_language(
254 self.as_ref().to_glib_none().0,
255 ))
256 }
257 }
258
259 #[cfg(feature = "v3_24")]
265 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
266 #[doc(alias = "gtk_font_chooser_get_level")]
267 #[doc(alias = "get_level")]
268 fn level(&self) -> FontChooserLevel {
269 unsafe {
270 from_glib(ffi::gtk_font_chooser_get_level(
271 self.as_ref().to_glib_none().0,
272 ))
273 }
274 }
275
276 #[doc(alias = "gtk_font_chooser_get_preview_text")]
283 #[doc(alias = "get_preview_text")]
284 fn preview_text(&self) -> Option<glib::GString> {
285 unsafe {
286 from_glib_full(ffi::gtk_font_chooser_get_preview_text(
287 self.as_ref().to_glib_none().0,
288 ))
289 }
290 }
291
292 #[doc(alias = "gtk_font_chooser_get_show_preview_entry")]
299 #[doc(alias = "get_show_preview_entry")]
300 fn shows_preview_entry(&self) -> bool {
301 unsafe {
302 from_glib(ffi::gtk_font_chooser_get_show_preview_entry(
303 self.as_ref().to_glib_none().0,
304 ))
305 }
306 }
307
308 #[doc(alias = "gtk_font_chooser_set_filter_func")]
313 fn set_filter_func(
314 &self,
315 filter: Option<Box_<dyn Fn(&pango::FontFamily, &pango::FontFace) -> bool + 'static>>,
316 ) {
317 let filter_data: Box_<
318 Option<Box_<dyn Fn(&pango::FontFamily, &pango::FontFace) -> bool + 'static>>,
319 > = Box_::new(filter);
320 unsafe extern "C" fn filter_func(
321 family: *const pango::ffi::PangoFontFamily,
322 face: *const pango::ffi::PangoFontFace,
323 data: glib::ffi::gpointer,
324 ) -> glib::ffi::gboolean {
325 let family = from_glib_borrow(family);
326 let face = from_glib_borrow(face);
327 let callback: &Option<
328 Box_<dyn Fn(&pango::FontFamily, &pango::FontFace) -> bool + 'static>,
329 > = &*(data as *mut _);
330 if let Some(ref callback) = *callback {
331 callback(&family, &face)
332 } else {
333 panic!("cannot get closure...")
334 }
335 .into_glib()
336 }
337 let filter = if filter_data.is_some() {
338 Some(filter_func as _)
339 } else {
340 None
341 };
342 unsafe extern "C" fn destroy_func(data: glib::ffi::gpointer) {
343 let _callback: Box_<
344 Option<Box_<dyn Fn(&pango::FontFamily, &pango::FontFace) -> bool + 'static>>,
345 > = Box_::from_raw(data as *mut _);
346 }
347 let destroy_call3 = Some(destroy_func as _);
348 let super_callback0: Box_<
349 Option<Box_<dyn Fn(&pango::FontFamily, &pango::FontFace) -> bool + 'static>>,
350 > = filter_data;
351 unsafe {
352 ffi::gtk_font_chooser_set_filter_func(
353 self.as_ref().to_glib_none().0,
354 filter,
355 Box_::into_raw(super_callback0) as *mut _,
356 destroy_call3,
357 );
358 }
359 }
360
361 #[doc(alias = "gtk_font_chooser_set_font")]
365 fn set_font(&self, fontname: &str) {
366 unsafe {
367 ffi::gtk_font_chooser_set_font(
368 self.as_ref().to_glib_none().0,
369 fontname.to_glib_none().0,
370 );
371 }
372 }
373
374 #[doc(alias = "gtk_font_chooser_set_font_desc")]
378 fn set_font_desc(&self, font_desc: &pango::FontDescription) {
379 unsafe {
380 ffi::gtk_font_chooser_set_font_desc(
381 self.as_ref().to_glib_none().0,
382 font_desc.to_glib_none().0,
383 );
384 }
385 }
386
387 #[doc(alias = "gtk_font_chooser_set_font_map")]
419 fn set_font_map(&self, fontmap: Option<&impl IsA<pango::FontMap>>) {
420 unsafe {
421 ffi::gtk_font_chooser_set_font_map(
422 self.as_ref().to_glib_none().0,
423 fontmap.map(|p| p.as_ref()).to_glib_none().0,
424 );
425 }
426 }
427
428 #[cfg(feature = "v3_24")]
432 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
433 #[doc(alias = "gtk_font_chooser_set_language")]
434 fn set_language(&self, language: &str) {
435 unsafe {
436 ffi::gtk_font_chooser_set_language(
437 self.as_ref().to_glib_none().0,
438 language.to_glib_none().0,
439 );
440 }
441 }
442
443 #[cfg(feature = "v3_24")]
447 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
448 #[doc(alias = "gtk_font_chooser_set_level")]
449 fn set_level(&self, level: FontChooserLevel) {
450 unsafe {
451 ffi::gtk_font_chooser_set_level(self.as_ref().to_glib_none().0, level.into_glib());
452 }
453 }
454
455 #[doc(alias = "gtk_font_chooser_set_preview_text")]
460 fn set_preview_text(&self, text: &str) {
461 unsafe {
462 ffi::gtk_font_chooser_set_preview_text(
463 self.as_ref().to_glib_none().0,
464 text.to_glib_none().0,
465 );
466 }
467 }
468
469 #[doc(alias = "gtk_font_chooser_set_show_preview_entry")]
473 fn set_show_preview_entry(&self, show_preview_entry: bool) {
474 unsafe {
475 ffi::gtk_font_chooser_set_show_preview_entry(
476 self.as_ref().to_glib_none().0,
477 show_preview_entry.into_glib(),
478 );
479 }
480 }
481
482 #[doc(alias = "font-activated")]
489 fn connect_font_activated<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
490 unsafe extern "C" fn font_activated_trampoline<
491 P: IsA<FontChooser>,
492 F: Fn(&P, &str) + 'static,
493 >(
494 this: *mut ffi::GtkFontChooser,
495 fontname: *mut libc::c_char,
496 f: glib::ffi::gpointer,
497 ) {
498 let f: &F = &*(f as *const F);
499 f(
500 FontChooser::from_glib_borrow(this).unsafe_cast_ref(),
501 &glib::GString::from_glib_borrow(fontname),
502 )
503 }
504 unsafe {
505 let f: Box_<F> = Box_::new(f);
506 connect_raw(
507 self.as_ptr() as *mut _,
508 b"font-activated\0".as_ptr() as *const _,
509 Some(transmute::<_, unsafe extern "C" fn()>(
510 font_activated_trampoline::<Self, F> as *const (),
511 )),
512 Box_::into_raw(f),
513 )
514 }
515 }
516
517 #[doc(alias = "font")]
518 fn connect_font_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
519 unsafe extern "C" fn notify_font_trampoline<P: IsA<FontChooser>, F: Fn(&P) + 'static>(
520 this: *mut ffi::GtkFontChooser,
521 _param_spec: glib::ffi::gpointer,
522 f: glib::ffi::gpointer,
523 ) {
524 let f: &F = &*(f as *const F);
525 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
526 }
527 unsafe {
528 let f: Box_<F> = Box_::new(f);
529 connect_raw(
530 self.as_ptr() as *mut _,
531 b"notify::font\0".as_ptr() as *const _,
532 Some(transmute::<_, unsafe extern "C" fn()>(
533 notify_font_trampoline::<Self, F> as *const (),
534 )),
535 Box_::into_raw(f),
536 )
537 }
538 }
539
540 #[doc(alias = "font-desc")]
541 fn connect_font_desc_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
542 unsafe extern "C" fn notify_font_desc_trampoline<
543 P: IsA<FontChooser>,
544 F: Fn(&P) + 'static,
545 >(
546 this: *mut ffi::GtkFontChooser,
547 _param_spec: glib::ffi::gpointer,
548 f: glib::ffi::gpointer,
549 ) {
550 let f: &F = &*(f as *const F);
551 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
552 }
553 unsafe {
554 let f: Box_<F> = Box_::new(f);
555 connect_raw(
556 self.as_ptr() as *mut _,
557 b"notify::font-desc\0".as_ptr() as *const _,
558 Some(transmute::<_, unsafe extern "C" fn()>(
559 notify_font_desc_trampoline::<Self, F> as *const (),
560 )),
561 Box_::into_raw(f),
562 )
563 }
564 }
565
566 #[cfg(feature = "v3_24")]
567 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
568 #[doc(alias = "font-features")]
569 fn connect_font_features_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
570 unsafe extern "C" fn notify_font_features_trampoline<
571 P: IsA<FontChooser>,
572 F: Fn(&P) + 'static,
573 >(
574 this: *mut ffi::GtkFontChooser,
575 _param_spec: glib::ffi::gpointer,
576 f: glib::ffi::gpointer,
577 ) {
578 let f: &F = &*(f as *const F);
579 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
580 }
581 unsafe {
582 let f: Box_<F> = Box_::new(f);
583 connect_raw(
584 self.as_ptr() as *mut _,
585 b"notify::font-features\0".as_ptr() as *const _,
586 Some(transmute::<_, unsafe extern "C" fn()>(
587 notify_font_features_trampoline::<Self, F> as *const (),
588 )),
589 Box_::into_raw(f),
590 )
591 }
592 }
593
594 #[cfg(feature = "v3_24")]
595 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
596 #[doc(alias = "language")]
597 fn connect_language_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
598 unsafe extern "C" fn notify_language_trampoline<
599 P: IsA<FontChooser>,
600 F: Fn(&P) + 'static,
601 >(
602 this: *mut ffi::GtkFontChooser,
603 _param_spec: glib::ffi::gpointer,
604 f: glib::ffi::gpointer,
605 ) {
606 let f: &F = &*(f as *const F);
607 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
608 }
609 unsafe {
610 let f: Box_<F> = Box_::new(f);
611 connect_raw(
612 self.as_ptr() as *mut _,
613 b"notify::language\0".as_ptr() as *const _,
614 Some(transmute::<_, unsafe extern "C" fn()>(
615 notify_language_trampoline::<Self, F> as *const (),
616 )),
617 Box_::into_raw(f),
618 )
619 }
620 }
621
622 #[cfg(feature = "v3_24")]
623 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
624 #[doc(alias = "level")]
625 fn connect_level_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
626 unsafe extern "C" fn notify_level_trampoline<P: IsA<FontChooser>, F: Fn(&P) + 'static>(
627 this: *mut ffi::GtkFontChooser,
628 _param_spec: glib::ffi::gpointer,
629 f: glib::ffi::gpointer,
630 ) {
631 let f: &F = &*(f as *const F);
632 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
633 }
634 unsafe {
635 let f: Box_<F> = Box_::new(f);
636 connect_raw(
637 self.as_ptr() as *mut _,
638 b"notify::level\0".as_ptr() as *const _,
639 Some(transmute::<_, unsafe extern "C" fn()>(
640 notify_level_trampoline::<Self, F> as *const (),
641 )),
642 Box_::into_raw(f),
643 )
644 }
645 }
646
647 #[doc(alias = "preview-text")]
648 fn connect_preview_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
649 unsafe extern "C" fn notify_preview_text_trampoline<
650 P: IsA<FontChooser>,
651 F: Fn(&P) + 'static,
652 >(
653 this: *mut ffi::GtkFontChooser,
654 _param_spec: glib::ffi::gpointer,
655 f: glib::ffi::gpointer,
656 ) {
657 let f: &F = &*(f as *const F);
658 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
659 }
660 unsafe {
661 let f: Box_<F> = Box_::new(f);
662 connect_raw(
663 self.as_ptr() as *mut _,
664 b"notify::preview-text\0".as_ptr() as *const _,
665 Some(transmute::<_, unsafe extern "C" fn()>(
666 notify_preview_text_trampoline::<Self, F> as *const (),
667 )),
668 Box_::into_raw(f),
669 )
670 }
671 }
672
673 #[doc(alias = "show-preview-entry")]
674 fn connect_show_preview_entry_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
675 unsafe extern "C" fn notify_show_preview_entry_trampoline<
676 P: IsA<FontChooser>,
677 F: Fn(&P) + 'static,
678 >(
679 this: *mut ffi::GtkFontChooser,
680 _param_spec: glib::ffi::gpointer,
681 f: glib::ffi::gpointer,
682 ) {
683 let f: &F = &*(f as *const F);
684 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
685 }
686 unsafe {
687 let f: Box_<F> = Box_::new(f);
688 connect_raw(
689 self.as_ptr() as *mut _,
690 b"notify::show-preview-entry\0".as_ptr() as *const _,
691 Some(transmute::<_, unsafe extern "C" fn()>(
692 notify_show_preview_entry_trampoline::<Self, F> as *const (),
693 )),
694 Box_::into_raw(f),
695 )
696 }
697 }
698}
699
700impl<O: IsA<FontChooser>> FontChooserExt for O {}
701
702impl fmt::Display for FontChooser {
703 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
704 f.write_str("FontChooser")
705 }
706}