1#[cfg(feature = "v3_24")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
7use crate::FontChooserLevel;
8use crate::ffi;
9use glib::{
10 object::ObjectType as _,
11 prelude::*,
12 signal::{SignalHandlerId, connect_raw},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 #[doc(alias = "GtkFontChooser")]
86 pub struct FontChooser(Interface<ffi::GtkFontChooser, ffi::GtkFontChooserIface>);
87
88 match fn {
89 type_ => || ffi::gtk_font_chooser_get_type(),
90 }
91}
92
93impl FontChooser {
94 pub const NONE: Option<&'static FontChooser> = None;
95}
96
97pub trait FontChooserExt: IsA<FontChooser> + 'static {
103 #[doc(alias = "gtk_font_chooser_get_font")]
120 #[doc(alias = "get_font")]
121 fn font(&self) -> Option<glib::GString> {
122 unsafe {
123 from_glib_full(ffi::gtk_font_chooser_get_font(
124 self.as_ref().to_glib_none().0,
125 ))
126 }
127 }
128
129 #[doc(alias = "gtk_font_chooser_get_font_desc")]
145 #[doc(alias = "get_font_desc")]
146 #[doc(alias = "font-desc")]
147 fn font_desc(&self) -> Option<pango::FontDescription> {
148 unsafe {
149 from_glib_full(ffi::gtk_font_chooser_get_font_desc(
150 self.as_ref().to_glib_none().0,
151 ))
152 }
153 }
154
155 #[doc(alias = "gtk_font_chooser_get_font_face")]
166 #[doc(alias = "get_font_face")]
167 fn font_face(&self) -> Option<pango::FontFace> {
168 unsafe {
169 from_glib_none(ffi::gtk_font_chooser_get_font_face(
170 self.as_ref().to_glib_none().0,
171 ))
172 }
173 }
174
175 #[doc(alias = "gtk_font_chooser_get_font_family")]
186 #[doc(alias = "get_font_family")]
187 fn font_family(&self) -> Option<pango::FontFamily> {
188 unsafe {
189 from_glib_none(ffi::gtk_font_chooser_get_font_family(
190 self.as_ref().to_glib_none().0,
191 ))
192 }
193 }
194
195 #[cfg(feature = "v3_24")]
201 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
202 #[doc(alias = "gtk_font_chooser_get_font_features")]
203 #[doc(alias = "get_font_features")]
204 #[doc(alias = "font-features")]
205 fn font_features(&self) -> Option<glib::GString> {
206 unsafe {
207 from_glib_full(ffi::gtk_font_chooser_get_font_features(
208 self.as_ref().to_glib_none().0,
209 ))
210 }
211 }
212
213 #[doc(alias = "gtk_font_chooser_get_font_map")]
220 #[doc(alias = "get_font_map")]
221 fn font_map(&self) -> Option<pango::FontMap> {
222 unsafe {
223 from_glib_full(ffi::gtk_font_chooser_get_font_map(
224 self.as_ref().to_glib_none().0,
225 ))
226 }
227 }
228
229 #[doc(alias = "gtk_font_chooser_get_font_size")]
236 #[doc(alias = "get_font_size")]
237 fn font_size(&self) -> i32 {
238 unsafe { ffi::gtk_font_chooser_get_font_size(self.as_ref().to_glib_none().0) }
239 }
240
241 #[cfg(feature = "v3_24")]
247 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
248 #[doc(alias = "gtk_font_chooser_get_language")]
249 #[doc(alias = "get_language")]
250 fn language(&self) -> Option<glib::GString> {
251 unsafe {
252 from_glib_full(ffi::gtk_font_chooser_get_language(
253 self.as_ref().to_glib_none().0,
254 ))
255 }
256 }
257
258 #[cfg(feature = "v3_24")]
264 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
265 #[doc(alias = "gtk_font_chooser_get_level")]
266 #[doc(alias = "get_level")]
267 fn level(&self) -> FontChooserLevel {
268 unsafe {
269 from_glib(ffi::gtk_font_chooser_get_level(
270 self.as_ref().to_glib_none().0,
271 ))
272 }
273 }
274
275 #[doc(alias = "gtk_font_chooser_get_preview_text")]
282 #[doc(alias = "get_preview_text")]
283 #[doc(alias = "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 #[doc(alias = "show-preview-entry")]
301 fn shows_preview_entry(&self) -> bool {
302 unsafe {
303 from_glib(ffi::gtk_font_chooser_get_show_preview_entry(
304 self.as_ref().to_glib_none().0,
305 ))
306 }
307 }
308
309 #[doc(alias = "gtk_font_chooser_set_filter_func")]
314 fn set_filter_func(
315 &self,
316 filter: Option<Box_<dyn Fn(&pango::FontFamily, &pango::FontFace) -> bool + 'static>>,
317 ) {
318 let filter_data: Box_<
319 Option<Box_<dyn Fn(&pango::FontFamily, &pango::FontFace) -> bool + 'static>>,
320 > = Box_::new(filter);
321 unsafe extern "C" fn filter_func(
322 family: *const pango::ffi::PangoFontFamily,
323 face: *const pango::ffi::PangoFontFace,
324 data: glib::ffi::gpointer,
325 ) -> glib::ffi::gboolean {
326 unsafe {
327 let family = from_glib_borrow(family);
328 let face = from_glib_borrow(face);
329 let callback = &*(data as *mut Option<
330 Box_<dyn Fn(&pango::FontFamily, &pango::FontFace) -> bool + 'static>,
331 >);
332 if let Some(ref callback) = *callback {
333 callback(&family, &face)
334 } else {
335 panic!("cannot get closure...")
336 }
337 .into_glib()
338 }
339 }
340 let filter = if filter_data.is_some() {
341 Some(filter_func as _)
342 } else {
343 None
344 };
345 unsafe extern "C" fn destroy_func(data: glib::ffi::gpointer) {
346 unsafe {
347 let _callback = Box_::from_raw(
348 data as *mut Option<
349 Box_<dyn Fn(&pango::FontFamily, &pango::FontFace) -> bool + 'static>,
350 >,
351 );
352 }
353 }
354 let destroy_call3 = Some(destroy_func as _);
355 let super_callback0: Box_<
356 Option<Box_<dyn Fn(&pango::FontFamily, &pango::FontFace) -> bool + 'static>>,
357 > = filter_data;
358 unsafe {
359 ffi::gtk_font_chooser_set_filter_func(
360 self.as_ref().to_glib_none().0,
361 filter,
362 Box_::into_raw(super_callback0) as *mut _,
363 destroy_call3,
364 );
365 }
366 }
367
368 #[doc(alias = "gtk_font_chooser_set_font")]
372 #[doc(alias = "font")]
373 fn set_font(&self, fontname: &str) {
374 unsafe {
375 ffi::gtk_font_chooser_set_font(
376 self.as_ref().to_glib_none().0,
377 fontname.to_glib_none().0,
378 );
379 }
380 }
381
382 #[doc(alias = "gtk_font_chooser_set_font_desc")]
386 #[doc(alias = "font-desc")]
387 fn set_font_desc(&self, font_desc: &pango::FontDescription) {
388 unsafe {
389 ffi::gtk_font_chooser_set_font_desc(
390 self.as_ref().to_glib_none().0,
391 font_desc.to_glib_none().0,
392 );
393 }
394 }
395
396 #[doc(alias = "gtk_font_chooser_set_font_map")]
428 fn set_font_map(&self, fontmap: Option<&impl IsA<pango::FontMap>>) {
429 unsafe {
430 ffi::gtk_font_chooser_set_font_map(
431 self.as_ref().to_glib_none().0,
432 fontmap.map(|p| p.as_ref()).to_glib_none().0,
433 );
434 }
435 }
436
437 #[cfg(feature = "v3_24")]
441 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
442 #[doc(alias = "gtk_font_chooser_set_language")]
443 #[doc(alias = "language")]
444 fn set_language(&self, language: &str) {
445 unsafe {
446 ffi::gtk_font_chooser_set_language(
447 self.as_ref().to_glib_none().0,
448 language.to_glib_none().0,
449 );
450 }
451 }
452
453 #[cfg(feature = "v3_24")]
457 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
458 #[doc(alias = "gtk_font_chooser_set_level")]
459 #[doc(alias = "level")]
460 fn set_level(&self, level: FontChooserLevel) {
461 unsafe {
462 ffi::gtk_font_chooser_set_level(self.as_ref().to_glib_none().0, level.into_glib());
463 }
464 }
465
466 #[doc(alias = "gtk_font_chooser_set_preview_text")]
471 #[doc(alias = "preview-text")]
472 fn set_preview_text(&self, text: &str) {
473 unsafe {
474 ffi::gtk_font_chooser_set_preview_text(
475 self.as_ref().to_glib_none().0,
476 text.to_glib_none().0,
477 );
478 }
479 }
480
481 #[doc(alias = "gtk_font_chooser_set_show_preview_entry")]
485 #[doc(alias = "show-preview-entry")]
486 fn set_show_preview_entry(&self, show_preview_entry: bool) {
487 unsafe {
488 ffi::gtk_font_chooser_set_show_preview_entry(
489 self.as_ref().to_glib_none().0,
490 show_preview_entry.into_glib(),
491 );
492 }
493 }
494
495 #[doc(alias = "font-activated")]
502 fn connect_font_activated<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
503 unsafe extern "C" fn font_activated_trampoline<
504 P: IsA<FontChooser>,
505 F: Fn(&P, &str) + 'static,
506 >(
507 this: *mut ffi::GtkFontChooser,
508 fontname: *mut std::ffi::c_char,
509 f: glib::ffi::gpointer,
510 ) {
511 unsafe {
512 let f: &F = &*(f as *const F);
513 f(
514 FontChooser::from_glib_borrow(this).unsafe_cast_ref(),
515 &glib::GString::from_glib_borrow(fontname),
516 )
517 }
518 }
519 unsafe {
520 let f: Box_<F> = Box_::new(f);
521 connect_raw(
522 self.as_ptr() as *mut _,
523 c"font-activated".as_ptr(),
524 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
525 font_activated_trampoline::<Self, F> as *const (),
526 )),
527 Box_::into_raw(f),
528 )
529 }
530 }
531
532 #[doc(alias = "font")]
533 fn connect_font_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
534 unsafe extern "C" fn notify_font_trampoline<P: IsA<FontChooser>, F: Fn(&P) + 'static>(
535 this: *mut ffi::GtkFontChooser,
536 _param_spec: glib::ffi::gpointer,
537 f: glib::ffi::gpointer,
538 ) {
539 unsafe {
540 let f: &F = &*(f as *const F);
541 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
542 }
543 }
544 unsafe {
545 let f: Box_<F> = Box_::new(f);
546 connect_raw(
547 self.as_ptr() as *mut _,
548 c"notify::font".as_ptr(),
549 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
550 notify_font_trampoline::<Self, F> as *const (),
551 )),
552 Box_::into_raw(f),
553 )
554 }
555 }
556
557 #[doc(alias = "font-desc")]
558 fn connect_font_desc_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
559 unsafe extern "C" fn notify_font_desc_trampoline<
560 P: IsA<FontChooser>,
561 F: Fn(&P) + 'static,
562 >(
563 this: *mut ffi::GtkFontChooser,
564 _param_spec: glib::ffi::gpointer,
565 f: glib::ffi::gpointer,
566 ) {
567 unsafe {
568 let f: &F = &*(f as *const F);
569 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
570 }
571 }
572 unsafe {
573 let f: Box_<F> = Box_::new(f);
574 connect_raw(
575 self.as_ptr() as *mut _,
576 c"notify::font-desc".as_ptr(),
577 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
578 notify_font_desc_trampoline::<Self, F> as *const (),
579 )),
580 Box_::into_raw(f),
581 )
582 }
583 }
584
585 #[cfg(feature = "v3_24")]
586 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
587 #[doc(alias = "font-features")]
588 fn connect_font_features_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
589 unsafe extern "C" fn notify_font_features_trampoline<
590 P: IsA<FontChooser>,
591 F: Fn(&P) + 'static,
592 >(
593 this: *mut ffi::GtkFontChooser,
594 _param_spec: glib::ffi::gpointer,
595 f: glib::ffi::gpointer,
596 ) {
597 unsafe {
598 let f: &F = &*(f as *const F);
599 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
600 }
601 }
602 unsafe {
603 let f: Box_<F> = Box_::new(f);
604 connect_raw(
605 self.as_ptr() as *mut _,
606 c"notify::font-features".as_ptr(),
607 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
608 notify_font_features_trampoline::<Self, F> as *const (),
609 )),
610 Box_::into_raw(f),
611 )
612 }
613 }
614
615 #[cfg(feature = "v3_24")]
616 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
617 #[doc(alias = "language")]
618 fn connect_language_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
619 unsafe extern "C" fn notify_language_trampoline<
620 P: IsA<FontChooser>,
621 F: Fn(&P) + 'static,
622 >(
623 this: *mut ffi::GtkFontChooser,
624 _param_spec: glib::ffi::gpointer,
625 f: glib::ffi::gpointer,
626 ) {
627 unsafe {
628 let f: &F = &*(f as *const F);
629 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
630 }
631 }
632 unsafe {
633 let f: Box_<F> = Box_::new(f);
634 connect_raw(
635 self.as_ptr() as *mut _,
636 c"notify::language".as_ptr(),
637 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
638 notify_language_trampoline::<Self, F> as *const (),
639 )),
640 Box_::into_raw(f),
641 )
642 }
643 }
644
645 #[cfg(feature = "v3_24")]
646 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
647 #[doc(alias = "level")]
648 fn connect_level_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
649 unsafe extern "C" fn notify_level_trampoline<P: IsA<FontChooser>, F: Fn(&P) + 'static>(
650 this: *mut ffi::GtkFontChooser,
651 _param_spec: glib::ffi::gpointer,
652 f: glib::ffi::gpointer,
653 ) {
654 unsafe {
655 let f: &F = &*(f as *const F);
656 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
657 }
658 }
659 unsafe {
660 let f: Box_<F> = Box_::new(f);
661 connect_raw(
662 self.as_ptr() as *mut _,
663 c"notify::level".as_ptr(),
664 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
665 notify_level_trampoline::<Self, F> as *const (),
666 )),
667 Box_::into_raw(f),
668 )
669 }
670 }
671
672 #[doc(alias = "preview-text")]
673 fn connect_preview_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
674 unsafe extern "C" fn notify_preview_text_trampoline<
675 P: IsA<FontChooser>,
676 F: Fn(&P) + 'static,
677 >(
678 this: *mut ffi::GtkFontChooser,
679 _param_spec: glib::ffi::gpointer,
680 f: glib::ffi::gpointer,
681 ) {
682 unsafe {
683 let f: &F = &*(f as *const F);
684 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
685 }
686 }
687 unsafe {
688 let f: Box_<F> = Box_::new(f);
689 connect_raw(
690 self.as_ptr() as *mut _,
691 c"notify::preview-text".as_ptr(),
692 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
693 notify_preview_text_trampoline::<Self, F> as *const (),
694 )),
695 Box_::into_raw(f),
696 )
697 }
698 }
699
700 #[doc(alias = "show-preview-entry")]
701 fn connect_show_preview_entry_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
702 unsafe extern "C" fn notify_show_preview_entry_trampoline<
703 P: IsA<FontChooser>,
704 F: Fn(&P) + 'static,
705 >(
706 this: *mut ffi::GtkFontChooser,
707 _param_spec: glib::ffi::gpointer,
708 f: glib::ffi::gpointer,
709 ) {
710 unsafe {
711 let f: &F = &*(f as *const F);
712 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
713 }
714 }
715 unsafe {
716 let f: Box_<F> = Box_::new(f);
717 connect_raw(
718 self.as_ptr() as *mut _,
719 c"notify::show-preview-entry".as_ptr(),
720 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
721 notify_show_preview_entry_trampoline::<Self, F> as *const (),
722 )),
723 Box_::into_raw(f),
724 )
725 }
726 }
727}
728
729impl<O: IsA<FontChooser>> FontChooserExt for O {}