gtk/auto/
font_chooser.rs

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