1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use glib::object::Cast;
use glib::object::IsA;
use glib::translate::*;
use glib::StaticType;
use glib::ToValue;
use std::fmt;

glib::wrapper! {
    pub struct Region(Object<ffi::GtkSourceRegion, ffi::GtkSourceRegionClass>);

    match fn {
        get_type => || ffi::gtk_source_region_get_type(),
    }
}

impl Region {
    /// ## `buffer`
    /// a `gtk::TextBuffer`.
    ///
    /// # Returns
    ///
    /// a new `Region` object for `buffer`.
    #[doc(alias = "gtk_source_region_new")]
    pub fn new<P: IsA<gtk::TextBuffer>>(buffer: &P) -> Region {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::gtk_source_region_new(buffer.as_ref().to_glib_none().0)) }
    }
}

impl fmt::Display for Region {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str(&RegionExt::to_str(self))
    }
}

#[derive(Clone, Default)]
pub struct RegionBuilder {
    buffer: Option<gtk::TextBuffer>,
}

impl RegionBuilder {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn build(self) -> Region {
        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
        if let Some(ref buffer) = self.buffer {
            properties.push(("buffer", buffer));
        }
        let ret = glib::Object::new::<Region>(&properties).expect("object new");
        ret
    }

    pub fn buffer<P: IsA<gtk::TextBuffer>>(mut self, buffer: &P) -> Self {
        self.buffer = Some(buffer.clone().upcast());
        self
    }
}

pub const NONE_REGION: Option<&Region> = None;

/// Trait containing all `Region` methods.
///
/// # Implementors
///
/// [`Region`](struct.Region.html)
pub trait RegionExt: 'static {
    /// Adds `region_to_add` to `self`. `region_to_add` is not modified.
    /// ## `region_to_add`
    /// the `Region` to add to `self`, or `None`.
    #[doc(alias = "gtk_source_region_add_region")]
    fn add_region<P: IsA<Region>>(&self, region_to_add: Option<&P>);

    /// Adds the subregion delimited by `_start` and `_end` to `self`.
    /// ## `_start`
    /// the start of the subregion.
    /// ## `_end`
    /// the end of the subregion.
    #[doc(alias = "gtk_source_region_add_subregion")]
    fn add_subregion(&self, _start: &gtk::TextIter, _end: &gtk::TextIter);

    /// Gets the `start` and `end` bounds of the `self`.
    /// ## `start`
    /// iterator to initialize with the start of `self`,
    ///  or `None`.
    /// ## `end`
    /// iterator to initialize with the end of `self`,
    ///  or `None`.
    ///
    /// # Returns
    ///
    /// `true` if `start` and `end` have been set successfully (if non-`None`),
    ///  or `false` if the `self` is empty.
    #[doc(alias = "gtk_source_region_get_bounds")]
    fn get_bounds(&self) -> Option<(gtk::TextIter, gtk::TextIter)>;

    ///
    /// # Returns
    ///
    /// the `gtk::TextBuffer`.
    #[doc(alias = "gtk_source_region_get_buffer")]
    fn get_buffer(&self) -> Option<gtk::TextBuffer>;

    //#[doc(alias = "gtk_source_region_get_start_region_iter")]
    //fn get_start_region_iter(&self, iter: /*Ignored*/RegionIter);

    /// Returns the intersection between `self` and `region2`. `self` and
    /// `region2` are not modified.
    /// ## `region2`
    /// a `Region`, or `None`.
    ///
    /// # Returns
    ///
    /// the intersection as a `Region`
    ///  object.
    #[doc(alias = "gtk_source_region_intersect_region")]
    fn intersect_region<P: IsA<Region>>(&self, region2: Option<&P>) -> Option<Region>;

    /// Returns the intersection between `self` and the subregion delimited by
    /// `_start` and `_end`. `self` is not modified.
    /// ## `_start`
    /// the start of the subregion.
    /// ## `_end`
    /// the end of the subregion.
    ///
    /// # Returns
    ///
    /// the intersection as a new
    ///  `Region`.
    #[doc(alias = "gtk_source_region_intersect_subregion")]
    fn intersect_subregion(&self, _start: &gtk::TextIter, _end: &gtk::TextIter) -> Option<Region>;

    /// Returns whether the `self` is empty. A `None` `self` is considered empty.
    ///
    /// # Returns
    ///
    /// whether the `self` is empty.
    #[doc(alias = "gtk_source_region_is_empty")]
    fn is_empty(&self) -> bool;

    /// Subtracts `region_to_subtract` from `self`. `region_to_subtract` is not
    /// modified.
    /// ## `region_to_subtract`
    /// the `Region` to subtract from
    ///  `self`, or `None`.
    #[doc(alias = "gtk_source_region_subtract_region")]
    fn subtract_region<P: IsA<Region>>(&self, region_to_subtract: Option<&P>);

    /// Subtracts the subregion delimited by `_start` and `_end` from `self`.
    /// ## `_start`
    /// the start of the subregion.
    /// ## `_end`
    /// the end of the subregion.
    #[doc(alias = "gtk_source_region_subtract_subregion")]
    fn subtract_subregion(&self, _start: &gtk::TextIter, _end: &gtk::TextIter);

    #[doc(alias = "gtk_source_region_to_string")]
    fn to_str(&self) -> glib::GString;
}

impl<O: IsA<Region>> RegionExt for O {
    fn add_region<P: IsA<Region>>(&self, region_to_add: Option<&P>) {
        unsafe {
            ffi::gtk_source_region_add_region(
                self.as_ref().to_glib_none().0,
                region_to_add.map(|p| p.as_ref()).to_glib_none().0,
            );
        }
    }

    fn add_subregion(&self, _start: &gtk::TextIter, _end: &gtk::TextIter) {
        unsafe {
            ffi::gtk_source_region_add_subregion(
                self.as_ref().to_glib_none().0,
                _start.to_glib_none().0,
                _end.to_glib_none().0,
            );
        }
    }

    fn get_bounds(&self) -> Option<(gtk::TextIter, gtk::TextIter)> {
        unsafe {
            let mut start = gtk::TextIter::uninitialized();
            let mut end = gtk::TextIter::uninitialized();
            let ret = from_glib(ffi::gtk_source_region_get_bounds(
                self.as_ref().to_glib_none().0,
                start.to_glib_none_mut().0,
                end.to_glib_none_mut().0,
            ));
            if ret {
                Some((start, end))
            } else {
                None
            }
        }
    }

    fn get_buffer(&self) -> Option<gtk::TextBuffer> {
        unsafe {
            from_glib_none(ffi::gtk_source_region_get_buffer(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    //fn get_start_region_iter(&self, iter: /*Ignored*/RegionIter) {
    //    unsafe { TODO: call ffi:gtk_source_region_get_start_region_iter() }
    //}

    fn intersect_region<P: IsA<Region>>(&self, region2: Option<&P>) -> Option<Region> {
        unsafe {
            from_glib_full(ffi::gtk_source_region_intersect_region(
                self.as_ref().to_glib_none().0,
                region2.map(|p| p.as_ref()).to_glib_none().0,
            ))
        }
    }

    fn intersect_subregion(&self, _start: &gtk::TextIter, _end: &gtk::TextIter) -> Option<Region> {
        unsafe {
            from_glib_full(ffi::gtk_source_region_intersect_subregion(
                self.as_ref().to_glib_none().0,
                _start.to_glib_none().0,
                _end.to_glib_none().0,
            ))
        }
    }

    fn is_empty(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_source_region_is_empty(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn subtract_region<P: IsA<Region>>(&self, region_to_subtract: Option<&P>) {
        unsafe {
            ffi::gtk_source_region_subtract_region(
                self.as_ref().to_glib_none().0,
                region_to_subtract.map(|p| p.as_ref()).to_glib_none().0,
            );
        }
    }

    fn subtract_subregion(&self, _start: &gtk::TextIter, _end: &gtk::TextIter) {
        unsafe {
            ffi::gtk_source_region_subtract_subregion(
                self.as_ref().to_glib_none().0,
                _start.to_glib_none().0,
                _end.to_glib_none().0,
            );
        }
    }

    fn to_str(&self) -> glib::GString {
        unsafe {
            from_glib_full(ffi::gtk_source_region_to_string(
                self.as_ref().to_glib_none().0,
            ))
        }
    }
}