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")]
420 fn set_font_map(&self, fontmap: Option<&impl IsA<pango::FontMap>>) {
421 unsafe {
422 ffi::gtk_font_chooser_set_font_map(
423 self.as_ref().to_glib_none().0,
424 fontmap.map(|p| p.as_ref()).to_glib_none().0,
425 );
426 }
427 }
428
429 #[cfg(feature = "v3_24")]
433 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
434 #[doc(alias = "gtk_font_chooser_set_language")]
435 #[doc(alias = "language")]
436 fn set_language(&self, language: &str) {
437 unsafe {
438 ffi::gtk_font_chooser_set_language(
439 self.as_ref().to_glib_none().0,
440 language.to_glib_none().0,
441 );
442 }
443 }
444
445 #[cfg(feature = "v3_24")]
449 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
450 #[doc(alias = "gtk_font_chooser_set_level")]
451 #[doc(alias = "level")]
452 fn set_level(&self, level: FontChooserLevel) {
453 unsafe {
454 ffi::gtk_font_chooser_set_level(self.as_ref().to_glib_none().0, level.into_glib());
455 }
456 }
457
458 #[doc(alias = "gtk_font_chooser_set_preview_text")]
463 #[doc(alias = "preview-text")]
464 fn set_preview_text(&self, text: &str) {
465 unsafe {
466 ffi::gtk_font_chooser_set_preview_text(
467 self.as_ref().to_glib_none().0,
468 text.to_glib_none().0,
469 );
470 }
471 }
472
473 #[doc(alias = "gtk_font_chooser_set_show_preview_entry")]
477 #[doc(alias = "show-preview-entry")]
478 fn set_show_preview_entry(&self, show_preview_entry: bool) {
479 unsafe {
480 ffi::gtk_font_chooser_set_show_preview_entry(
481 self.as_ref().to_glib_none().0,
482 show_preview_entry.into_glib(),
483 );
484 }
485 }
486
487 #[doc(alias = "font-activated")]
494 fn connect_font_activated<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
495 unsafe extern "C" fn font_activated_trampoline<
496 P: IsA<FontChooser>,
497 F: Fn(&P, &str) + 'static,
498 >(
499 this: *mut ffi::GtkFontChooser,
500 fontname: *mut std::ffi::c_char,
501 f: glib::ffi::gpointer,
502 ) {
503 unsafe {
504 let f: &F = &*(f as *const F);
505 f(
506 FontChooser::from_glib_borrow(this).unsafe_cast_ref(),
507 &glib::GString::from_glib_borrow(fontname),
508 )
509 }
510 }
511 unsafe {
512 let f: Box_<F> = Box_::new(f);
513 connect_raw(
514 self.as_ptr() as *mut _,
515 c"font-activated".as_ptr(),
516 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
517 font_activated_trampoline::<Self, F> as *const (),
518 )),
519 Box_::into_raw(f),
520 )
521 }
522 }
523
524 #[doc(alias = "font")]
525 fn connect_font_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
526 unsafe extern "C" fn notify_font_trampoline<P: IsA<FontChooser>, F: Fn(&P) + 'static>(
527 this: *mut ffi::GtkFontChooser,
528 _param_spec: glib::ffi::gpointer,
529 f: glib::ffi::gpointer,
530 ) {
531 unsafe {
532 let f: &F = &*(f as *const F);
533 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
534 }
535 }
536 unsafe {
537 let f: Box_<F> = Box_::new(f);
538 connect_raw(
539 self.as_ptr() as *mut _,
540 c"notify::font".as_ptr(),
541 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
542 notify_font_trampoline::<Self, F> as *const (),
543 )),
544 Box_::into_raw(f),
545 )
546 }
547 }
548
549 #[doc(alias = "font-desc")]
550 fn connect_font_desc_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
551 unsafe extern "C" fn notify_font_desc_trampoline<
552 P: IsA<FontChooser>,
553 F: Fn(&P) + 'static,
554 >(
555 this: *mut ffi::GtkFontChooser,
556 _param_spec: glib::ffi::gpointer,
557 f: glib::ffi::gpointer,
558 ) {
559 unsafe {
560 let f: &F = &*(f as *const F);
561 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
562 }
563 }
564 unsafe {
565 let f: Box_<F> = Box_::new(f);
566 connect_raw(
567 self.as_ptr() as *mut _,
568 c"notify::font-desc".as_ptr(),
569 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
570 notify_font_desc_trampoline::<Self, F> as *const (),
571 )),
572 Box_::into_raw(f),
573 )
574 }
575 }
576
577 #[cfg(feature = "v3_24")]
578 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
579 #[doc(alias = "font-features")]
580 fn connect_font_features_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
581 unsafe extern "C" fn notify_font_features_trampoline<
582 P: IsA<FontChooser>,
583 F: Fn(&P) + 'static,
584 >(
585 this: *mut ffi::GtkFontChooser,
586 _param_spec: glib::ffi::gpointer,
587 f: glib::ffi::gpointer,
588 ) {
589 unsafe {
590 let f: &F = &*(f as *const F);
591 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
592 }
593 }
594 unsafe {
595 let f: Box_<F> = Box_::new(f);
596 connect_raw(
597 self.as_ptr() as *mut _,
598 c"notify::font-features".as_ptr(),
599 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
600 notify_font_features_trampoline::<Self, F> as *const (),
601 )),
602 Box_::into_raw(f),
603 )
604 }
605 }
606
607 #[cfg(feature = "v3_24")]
608 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
609 #[doc(alias = "language")]
610 fn connect_language_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
611 unsafe extern "C" fn notify_language_trampoline<
612 P: IsA<FontChooser>,
613 F: Fn(&P) + 'static,
614 >(
615 this: *mut ffi::GtkFontChooser,
616 _param_spec: glib::ffi::gpointer,
617 f: glib::ffi::gpointer,
618 ) {
619 unsafe {
620 let f: &F = &*(f as *const F);
621 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
622 }
623 }
624 unsafe {
625 let f: Box_<F> = Box_::new(f);
626 connect_raw(
627 self.as_ptr() as *mut _,
628 c"notify::language".as_ptr(),
629 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
630 notify_language_trampoline::<Self, F> as *const (),
631 )),
632 Box_::into_raw(f),
633 )
634 }
635 }
636
637 #[cfg(feature = "v3_24")]
638 #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
639 #[doc(alias = "level")]
640 fn connect_level_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
641 unsafe extern "C" fn notify_level_trampoline<P: IsA<FontChooser>, F: Fn(&P) + 'static>(
642 this: *mut ffi::GtkFontChooser,
643 _param_spec: glib::ffi::gpointer,
644 f: glib::ffi::gpointer,
645 ) {
646 unsafe {
647 let f: &F = &*(f as *const F);
648 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
649 }
650 }
651 unsafe {
652 let f: Box_<F> = Box_::new(f);
653 connect_raw(
654 self.as_ptr() as *mut _,
655 c"notify::level".as_ptr(),
656 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
657 notify_level_trampoline::<Self, F> as *const (),
658 )),
659 Box_::into_raw(f),
660 )
661 }
662 }
663
664 #[doc(alias = "preview-text")]
665 fn connect_preview_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
666 unsafe extern "C" fn notify_preview_text_trampoline<
667 P: IsA<FontChooser>,
668 F: Fn(&P) + 'static,
669 >(
670 this: *mut ffi::GtkFontChooser,
671 _param_spec: glib::ffi::gpointer,
672 f: glib::ffi::gpointer,
673 ) {
674 unsafe {
675 let f: &F = &*(f as *const F);
676 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
677 }
678 }
679 unsafe {
680 let f: Box_<F> = Box_::new(f);
681 connect_raw(
682 self.as_ptr() as *mut _,
683 c"notify::preview-text".as_ptr(),
684 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
685 notify_preview_text_trampoline::<Self, F> as *const (),
686 )),
687 Box_::into_raw(f),
688 )
689 }
690 }
691
692 #[doc(alias = "show-preview-entry")]
693 fn connect_show_preview_entry_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
694 unsafe extern "C" fn notify_show_preview_entry_trampoline<
695 P: IsA<FontChooser>,
696 F: Fn(&P) + 'static,
697 >(
698 this: *mut ffi::GtkFontChooser,
699 _param_spec: glib::ffi::gpointer,
700 f: glib::ffi::gpointer,
701 ) {
702 unsafe {
703 let f: &F = &*(f as *const F);
704 f(FontChooser::from_glib_borrow(this).unsafe_cast_ref())
705 }
706 }
707 unsafe {
708 let f: Box_<F> = Box_::new(f);
709 connect_raw(
710 self.as_ptr() as *mut _,
711 c"notify::show-preview-entry".as_ptr(),
712 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
713 notify_show_preview_entry_trampoline::<Self, F> as *const (),
714 )),
715 Box_::into_raw(f),
716 )
717 }
718 }
719}
720
721impl<O: IsA<FontChooser>> FontChooserExt for O {}