sourceview/auto/
style_scheme.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::StaticType;
12use glib::ToValue;
13use glib_sys;
14use gtk_source_sys;
15use std::boxed::Box as Box_;
16use std::fmt;
17use std::mem::transmute;
18use Style;
19
20glib_wrapper! {
21    pub struct StyleScheme(Object<gtk_source_sys::GtkSourceStyleScheme, gtk_source_sys::GtkSourceStyleSchemeClass, StyleSchemeClass>);
22
23    match fn {
24        get_type => || gtk_source_sys::gtk_source_style_scheme_get_type(),
25    }
26}
27
28#[derive(Clone, Default)]
29pub struct StyleSchemeBuilder {
30    id: Option<String>,
31}
32
33impl StyleSchemeBuilder {
34    pub fn new() -> Self {
35        Self::default()
36    }
37
38    pub fn build(self) -> StyleScheme {
39        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
40        if let Some(ref id) = self.id {
41            properties.push(("id", id));
42        }
43        glib::Object::new(StyleScheme::static_type(), &properties)
44            .expect("object new")
45            .downcast()
46            .expect("downcast")
47    }
48
49    pub fn id(mut self, id: &str) -> Self {
50        self.id = Some(id.to_string());
51        self
52    }
53}
54
55pub const NONE_STYLE_SCHEME: Option<&StyleScheme> = None;
56
57pub trait StyleSchemeExt: 'static {
58    fn get_authors(&self) -> Vec<GString>;
59
60    fn get_description(&self) -> Option<GString>;
61
62    fn get_filename(&self) -> Option<GString>;
63
64    fn get_id(&self) -> Option<GString>;
65
66    fn get_name(&self) -> Option<GString>;
67
68    fn get_style(&self, style_id: &str) -> Option<Style>;
69
70    fn connect_property_description_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
71
72    fn connect_property_filename_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
73
74    fn connect_property_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
75}
76
77impl<O: IsA<StyleScheme>> StyleSchemeExt for O {
78    fn get_authors(&self) -> Vec<GString> {
79        unsafe {
80            FromGlibPtrContainer::from_glib_none(
81                gtk_source_sys::gtk_source_style_scheme_get_authors(self.as_ref().to_glib_none().0),
82            )
83        }
84    }
85
86    fn get_description(&self) -> Option<GString> {
87        unsafe {
88            from_glib_none(gtk_source_sys::gtk_source_style_scheme_get_description(
89                self.as_ref().to_glib_none().0,
90            ))
91        }
92    }
93
94    fn get_filename(&self) -> Option<GString> {
95        unsafe {
96            from_glib_none(gtk_source_sys::gtk_source_style_scheme_get_filename(
97                self.as_ref().to_glib_none().0,
98            ))
99        }
100    }
101
102    fn get_id(&self) -> Option<GString> {
103        unsafe {
104            from_glib_none(gtk_source_sys::gtk_source_style_scheme_get_id(
105                self.as_ref().to_glib_none().0,
106            ))
107        }
108    }
109
110    fn get_name(&self) -> Option<GString> {
111        unsafe {
112            from_glib_none(gtk_source_sys::gtk_source_style_scheme_get_name(
113                self.as_ref().to_glib_none().0,
114            ))
115        }
116    }
117
118    fn get_style(&self, style_id: &str) -> Option<Style> {
119        unsafe {
120            from_glib_none(gtk_source_sys::gtk_source_style_scheme_get_style(
121                self.as_ref().to_glib_none().0,
122                style_id.to_glib_none().0,
123            ))
124        }
125    }
126
127    fn connect_property_description_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
128        unsafe extern "C" fn notify_description_trampoline<P, F: Fn(&P) + 'static>(
129            this: *mut gtk_source_sys::GtkSourceStyleScheme,
130            _param_spec: glib_sys::gpointer,
131            f: glib_sys::gpointer,
132        ) where
133            P: IsA<StyleScheme>,
134        {
135            let f: &F = &*(f as *const F);
136            f(&StyleScheme::from_glib_borrow(this).unsafe_cast_ref())
137        }
138        unsafe {
139            let f: Box_<F> = Box_::new(f);
140            connect_raw(
141                self.as_ptr() as *mut _,
142                b"notify::description\0".as_ptr() as *const _,
143                Some(transmute::<_, unsafe extern "C" fn()>(
144                    notify_description_trampoline::<Self, F> as *const (),
145                )),
146                Box_::into_raw(f),
147            )
148        }
149    }
150
151    fn connect_property_filename_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
152        unsafe extern "C" fn notify_filename_trampoline<P, F: Fn(&P) + 'static>(
153            this: *mut gtk_source_sys::GtkSourceStyleScheme,
154            _param_spec: glib_sys::gpointer,
155            f: glib_sys::gpointer,
156        ) where
157            P: IsA<StyleScheme>,
158        {
159            let f: &F = &*(f as *const F);
160            f(&StyleScheme::from_glib_borrow(this).unsafe_cast_ref())
161        }
162        unsafe {
163            let f: Box_<F> = Box_::new(f);
164            connect_raw(
165                self.as_ptr() as *mut _,
166                b"notify::filename\0".as_ptr() as *const _,
167                Some(transmute::<_, unsafe extern "C" fn()>(
168                    notify_filename_trampoline::<Self, F> as *const (),
169                )),
170                Box_::into_raw(f),
171            )
172        }
173    }
174
175    fn connect_property_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
176        unsafe extern "C" fn notify_name_trampoline<P, F: Fn(&P) + 'static>(
177            this: *mut gtk_source_sys::GtkSourceStyleScheme,
178            _param_spec: glib_sys::gpointer,
179            f: glib_sys::gpointer,
180        ) where
181            P: IsA<StyleScheme>,
182        {
183            let f: &F = &*(f as *const F);
184            f(&StyleScheme::from_glib_borrow(this).unsafe_cast_ref())
185        }
186        unsafe {
187            let f: Box_<F> = Box_::new(f);
188            connect_raw(
189                self.as_ptr() as *mut _,
190                b"notify::name\0".as_ptr() as *const _,
191                Some(transmute::<_, unsafe extern "C" fn()>(
192                    notify_name_trampoline::<Self, F> as *const (),
193                )),
194                Box_::into_raw(f),
195            )
196        }
197    }
198}
199
200impl fmt::Display for StyleScheme {
201    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
202        write!(f, "StyleScheme")
203    }
204}