gtk4/auto/
text_iter.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 crate::{ffi, TextBuffer, TextChildAnchor, TextMark, TextSearchFlags, TextTag};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// An iterator for the contents of a [`TextBuffer`][crate::TextBuffer].
10    ///
11    /// You may wish to begin by reading the
12    /// [text widget conceptual overview](section-text-widget.html),
13    /// which gives an overview of all the objects and data types
14    /// related to the text widget and how they work together.
15    #[derive(Debug)]
16    pub struct TextIter(BoxedInline<ffi::GtkTextIter>);
17
18    match fn {
19        copy => |ptr| ffi::gtk_text_iter_copy(ptr),
20        free => |ptr| ffi::gtk_text_iter_free(ptr),
21        type_ => || ffi::gtk_text_iter_get_type(),
22    }
23}
24
25impl TextIter {
26    /// Assigns the value of @other to @self.
27    ///
28    /// This function is not useful in applications, because
29    /// iterators can be assigned with `GtkTextIter i = j;`.
30    ///
31    /// The function is used by language bindings.
32    /// ## `other`
33    /// another [`TextIter`][crate::TextIter]
34    #[doc(alias = "gtk_text_iter_assign")]
35    pub fn assign(&mut self, other: &TextIter) {
36        unsafe {
37            ffi::gtk_text_iter_assign(self.to_glib_none_mut().0, other.to_glib_none().0);
38        }
39    }
40
41    /// Moves backward by one character offset.
42    ///
43    /// Returns [`true`] if movement was possible; if @self was the first
44    /// in the buffer (character offset 0), this function returns [`false`]
45    /// for convenience when writing loops.
46    ///
47    /// # Returns
48    ///
49    /// whether movement was possible
50    #[doc(alias = "gtk_text_iter_backward_char")]
51    pub fn backward_char(&mut self) -> bool {
52        unsafe { from_glib(ffi::gtk_text_iter_backward_char(self.to_glib_none_mut().0)) }
53    }
54
55    /// Moves @count characters backward, if possible.
56    ///
57    /// If @count would move past the start or end of the buffer, moves
58    /// to the start or end of the buffer.
59    ///
60    /// The return value indicates whether the iterator moved
61    /// onto a dereferenceable position; if the iterator didn’t move, or
62    /// moved onto the end iterator, then [`false`] is returned. If @count is 0,
63    /// the function does nothing and returns [`false`].
64    /// ## `count`
65    /// number of characters to move
66    ///
67    /// # Returns
68    ///
69    /// whether @self moved and is dereferenceable
70    #[doc(alias = "gtk_text_iter_backward_chars")]
71    pub fn backward_chars(&mut self, count: i32) -> bool {
72        unsafe {
73            from_glib(ffi::gtk_text_iter_backward_chars(
74                self.to_glib_none_mut().0,
75                count,
76            ))
77        }
78    }
79
80    /// Like [`forward_cursor_position()`][Self::forward_cursor_position()], but moves backward.
81    ///
82    /// # Returns
83    ///
84    /// [`true`] if we moved
85    #[doc(alias = "gtk_text_iter_backward_cursor_position")]
86    pub fn backward_cursor_position(&mut self) -> bool {
87        unsafe {
88            from_glib(ffi::gtk_text_iter_backward_cursor_position(
89                self.to_glib_none_mut().0,
90            ))
91        }
92    }
93
94    /// Moves up to @count cursor positions.
95    ///
96    /// See [`forward_cursor_position()`][Self::forward_cursor_position()] for details.
97    /// ## `count`
98    /// number of positions to move
99    ///
100    /// # Returns
101    ///
102    /// [`true`] if we moved and the new position is dereferenceable
103    #[doc(alias = "gtk_text_iter_backward_cursor_positions")]
104    pub fn backward_cursor_positions(&mut self, count: i32) -> bool {
105        unsafe {
106            from_glib(ffi::gtk_text_iter_backward_cursor_positions(
107                self.to_glib_none_mut().0,
108                count,
109            ))
110        }
111    }
112
113    /// Same as [`forward_find_char()`][Self::forward_find_char()],
114    /// but goes backward from @self.
115    /// ## `pred`
116    /// function to be called on each character
117    /// ## `limit`
118    /// search limit
119    ///
120    /// # Returns
121    ///
122    /// whether a match was found
123    #[doc(alias = "gtk_text_iter_backward_find_char")]
124    pub fn backward_find_char<P: FnMut(char) -> bool>(
125        &mut self,
126        pred: P,
127        limit: Option<&TextIter>,
128    ) -> bool {
129        let mut pred_data: P = pred;
130        unsafe extern "C" fn pred_func<P: FnMut(char) -> bool>(
131            ch: u32,
132            user_data: glib::ffi::gpointer,
133        ) -> glib::ffi::gboolean {
134            let ch = std::convert::TryFrom::try_from(ch)
135                .expect("conversion from an invalid Unicode value attempted");
136            let callback = user_data as *mut P;
137            (*callback)(ch).into_glib()
138        }
139        let pred = Some(pred_func::<P> as _);
140        let super_callback0: &mut P = &mut pred_data;
141        unsafe {
142            from_glib(ffi::gtk_text_iter_backward_find_char(
143                self.to_glib_none_mut().0,
144                pred,
145                super_callback0 as *mut _ as *mut _,
146                limit.to_glib_none().0,
147            ))
148        }
149    }
150
151    /// Moves @self to the start of the previous line.
152    ///
153    /// Returns [`true`] if @self could be moved; i.e. if @self was at
154    /// character offset 0, this function returns [`false`]. Therefore,
155    /// if @self was already on line 0, but not at the start of the line,
156    /// @self is snapped to the start of the line and the function returns
157    /// [`true`]. (Note that this implies that
158    /// in a loop calling this function, the line number may not change on
159    /// every iteration, if your first iteration is on line 0.)
160    ///
161    /// # Returns
162    ///
163    /// whether @self moved
164    #[doc(alias = "gtk_text_iter_backward_line")]
165    pub fn backward_line(&mut self) -> bool {
166        unsafe { from_glib(ffi::gtk_text_iter_backward_line(self.to_glib_none_mut().0)) }
167    }
168
169    /// Moves @count lines backward, if possible.
170    ///
171    /// If @count would move past the start or end of the buffer, moves to
172    /// the start or end of the buffer.
173    ///
174    /// The return value indicates whether the iterator moved
175    /// onto a dereferenceable position; if the iterator didn’t move, or
176    /// moved onto the end iterator, then [`false`] is returned. If @count is 0,
177    /// the function does nothing and returns [`false`]. If @count is negative,
178    /// moves forward by 0 - @count lines.
179    /// ## `count`
180    /// number of lines to move backward
181    ///
182    /// # Returns
183    ///
184    /// whether @self moved and is dereferenceable
185    #[doc(alias = "gtk_text_iter_backward_lines")]
186    pub fn backward_lines(&mut self, count: i32) -> bool {
187        unsafe {
188            from_glib(ffi::gtk_text_iter_backward_lines(
189                self.to_glib_none_mut().0,
190                count,
191            ))
192        }
193    }
194
195    /// Same as [`forward_search()`][Self::forward_search()], but moves backward.
196    ///
197    /// @match_end will never be set to a [`TextIter`][crate::TextIter] located after @self,
198    /// even if there is a possible @match_start before or at @self.
199    /// ## `str`
200    /// search string
201    /// ## `flags`
202    /// bitmask of flags affecting the search
203    /// ## `limit`
204    /// location of last possible @match_start, or [`None`] for start of buffer
205    ///
206    /// # Returns
207    ///
208    /// whether a match was found
209    ///
210    /// ## `match_start`
211    /// return location for start of match
212    ///
213    /// ## `match_end`
214    /// return location for end of match
215    #[doc(alias = "gtk_text_iter_backward_search")]
216    pub fn backward_search(
217        &self,
218        str: &str,
219        flags: TextSearchFlags,
220        limit: Option<&TextIter>,
221    ) -> Option<(TextIter, TextIter)> {
222        unsafe {
223            let mut match_start = TextIter::uninitialized();
224            let mut match_end = TextIter::uninitialized();
225            let ret = from_glib(ffi::gtk_text_iter_backward_search(
226                self.to_glib_none().0,
227                str.to_glib_none().0,
228                flags.into_glib(),
229                match_start.to_glib_none_mut().0,
230                match_end.to_glib_none_mut().0,
231                limit.to_glib_none().0,
232            ));
233            if ret {
234                Some((match_start, match_end))
235            } else {
236                None
237            }
238        }
239    }
240
241    /// Moves backward to the previous sentence start.
242    ///
243    /// If @self is already at the start of a sentence, moves backward
244    /// to the next one.
245    ///
246    /// Sentence boundaries are determined by Pango and should
247    /// be correct for nearly any language.
248    ///
249    /// # Returns
250    ///
251    /// [`true`] if @self moved and is not the end iterator
252    #[doc(alias = "gtk_text_iter_backward_sentence_start")]
253    pub fn backward_sentence_start(&mut self) -> bool {
254        unsafe {
255            from_glib(ffi::gtk_text_iter_backward_sentence_start(
256                self.to_glib_none_mut().0,
257            ))
258        }
259    }
260
261    /// Calls [`backward_sentence_start()`][Self::backward_sentence_start()] up to @count times.
262    ///
263    /// If @count is negative, moves forward instead of backward.
264    /// ## `count`
265    /// number of sentences to move
266    ///
267    /// # Returns
268    ///
269    /// [`true`] if @self moved and is not the end iterator
270    #[doc(alias = "gtk_text_iter_backward_sentence_starts")]
271    pub fn backward_sentence_starts(&mut self, count: i32) -> bool {
272        unsafe {
273            from_glib(ffi::gtk_text_iter_backward_sentence_starts(
274                self.to_glib_none_mut().0,
275                count,
276            ))
277        }
278    }
279
280    /// Moves backward to the next toggle (on or off) of the
281    /// @tag, or to the next toggle of any tag if
282    /// @tag is [`None`].
283    ///
284    /// If no matching tag toggles are found,
285    /// returns [`false`], otherwise [`true`]. Does not return toggles
286    /// located at @self, only toggles before @self. Sets @self
287    /// to the location of the toggle, or the start of the buffer
288    /// if no toggle is found.
289    /// ## `tag`
290    /// a [`TextTag`][crate::TextTag]
291    ///
292    /// # Returns
293    ///
294    /// whether we found a tag toggle before @self
295    #[doc(alias = "gtk_text_iter_backward_to_tag_toggle")]
296    pub fn backward_to_tag_toggle(&mut self, tag: Option<&impl IsA<TextTag>>) -> bool {
297        unsafe {
298            from_glib(ffi::gtk_text_iter_backward_to_tag_toggle(
299                self.to_glib_none_mut().0,
300                tag.map(|p| p.as_ref()).to_glib_none().0,
301            ))
302        }
303    }
304
305    /// Moves @self backward to the previous visible cursor position.
306    ///
307    /// See [`backward_cursor_position()`][Self::backward_cursor_position()] for details.
308    ///
309    /// # Returns
310    ///
311    /// [`true`] if we moved and the new position is dereferenceable
312    #[doc(alias = "gtk_text_iter_backward_visible_cursor_position")]
313    pub fn backward_visible_cursor_position(&mut self) -> bool {
314        unsafe {
315            from_glib(ffi::gtk_text_iter_backward_visible_cursor_position(
316                self.to_glib_none_mut().0,
317            ))
318        }
319    }
320
321    /// Moves up to @count visible cursor positions.
322    ///
323    /// See [`backward_cursor_position()`][Self::backward_cursor_position()] for details.
324    /// ## `count`
325    /// number of positions to move
326    ///
327    /// # Returns
328    ///
329    /// [`true`] if we moved and the new position is dereferenceable
330    #[doc(alias = "gtk_text_iter_backward_visible_cursor_positions")]
331    pub fn backward_visible_cursor_positions(&mut self, count: i32) -> bool {
332        unsafe {
333            from_glib(ffi::gtk_text_iter_backward_visible_cursor_positions(
334                self.to_glib_none_mut().0,
335                count,
336            ))
337        }
338    }
339
340    /// Moves @self to the start of the previous visible line.
341    ///
342    /// Returns [`true`] if
343    /// @self could be moved; i.e. if @self was at character offset 0, this
344    /// function returns [`false`]. Therefore if @self was already on line 0,
345    /// but not at the start of the line, @self is snapped to the start of
346    /// the line and the function returns [`true`]. (Note that this implies that
347    /// in a loop calling this function, the line number may not change on
348    /// every iteration, if your first iteration is on line 0.)
349    ///
350    /// # Returns
351    ///
352    /// whether @self moved
353    #[doc(alias = "gtk_text_iter_backward_visible_line")]
354    pub fn backward_visible_line(&mut self) -> bool {
355        unsafe {
356            from_glib(ffi::gtk_text_iter_backward_visible_line(
357                self.to_glib_none_mut().0,
358            ))
359        }
360    }
361
362    /// Moves @count visible lines backward, if possible.
363    ///
364    /// If @count would move past the start or end of the buffer, moves to
365    /// the start or end of the buffer.
366    ///
367    /// The return value indicates whether the iterator moved
368    /// onto a dereferenceable position; if the iterator didn’t move, or
369    /// moved onto the end iterator, then [`false`] is returned. If @count is 0,
370    /// the function does nothing and returns [`false`]. If @count is negative,
371    /// moves forward by 0 - @count lines.
372    /// ## `count`
373    /// number of lines to move backward
374    ///
375    /// # Returns
376    ///
377    /// whether @self moved and is dereferenceable
378    #[doc(alias = "gtk_text_iter_backward_visible_lines")]
379    pub fn backward_visible_lines(&mut self, count: i32) -> bool {
380        unsafe {
381            from_glib(ffi::gtk_text_iter_backward_visible_lines(
382                self.to_glib_none_mut().0,
383                count,
384            ))
385        }
386    }
387
388    /// Moves backward to the previous visible word start.
389    ///
390    /// If @self is currently on a word start, moves backward to the
391    /// next one after that.
392    ///
393    /// Word breaks are determined by Pango and should be correct
394    /// for nearly any language.
395    ///
396    /// # Returns
397    ///
398    /// [`true`] if @self moved and is not the end iterator
399    #[doc(alias = "gtk_text_iter_backward_visible_word_start")]
400    pub fn backward_visible_word_start(&mut self) -> bool {
401        unsafe {
402            from_glib(ffi::gtk_text_iter_backward_visible_word_start(
403                self.to_glib_none_mut().0,
404            ))
405        }
406    }
407
408    /// Calls [`backward_visible_word_start()`][Self::backward_visible_word_start()] up to @count times.
409    /// ## `count`
410    /// number of times to move
411    ///
412    /// # Returns
413    ///
414    /// [`true`] if @self moved and is not the end iterator
415    #[doc(alias = "gtk_text_iter_backward_visible_word_starts")]
416    pub fn backward_visible_word_starts(&mut self, count: i32) -> bool {
417        unsafe {
418            from_glib(ffi::gtk_text_iter_backward_visible_word_starts(
419                self.to_glib_none_mut().0,
420                count,
421            ))
422        }
423    }
424
425    /// Moves backward to the previous word start.
426    ///
427    /// If @self is currently on a word start, moves backward to the
428    /// next one after that.
429    ///
430    /// Word breaks are determined by Pango and should be correct
431    /// for nearly any language
432    ///
433    /// # Returns
434    ///
435    /// [`true`] if @self moved and is not the end iterator
436    #[doc(alias = "gtk_text_iter_backward_word_start")]
437    pub fn backward_word_start(&mut self) -> bool {
438        unsafe {
439            from_glib(ffi::gtk_text_iter_backward_word_start(
440                self.to_glib_none_mut().0,
441            ))
442        }
443    }
444
445    /// Calls [`backward_word_start()`][Self::backward_word_start()] up to @count times.
446    /// ## `count`
447    /// number of times to move
448    ///
449    /// # Returns
450    ///
451    /// [`true`] if @self moved and is not the end iterator
452    #[doc(alias = "gtk_text_iter_backward_word_starts")]
453    pub fn backward_word_starts(&mut self, count: i32) -> bool {
454        unsafe {
455            from_glib(ffi::gtk_text_iter_backward_word_starts(
456                self.to_glib_none_mut().0,
457                count,
458            ))
459        }
460    }
461
462    /// Considering the default editability of the buffer, and tags that
463    /// affect editability, determines whether text inserted at @self would
464    /// be editable.
465    ///
466    /// If text inserted at @self would be editable then the
467    /// user should be allowed to insert text at @self.
468    /// [`TextBufferExt::insert_interactive()`][crate::prelude::TextBufferExt::insert_interactive()] uses this function
469    /// to decide whether insertions are allowed at a given position.
470    /// ## `default_editability`
471    /// [`true`] if text is editable by default
472    ///
473    /// # Returns
474    ///
475    /// whether text inserted at @self would be editable
476    #[doc(alias = "gtk_text_iter_can_insert")]
477    pub fn can_insert(&self, default_editability: bool) -> bool {
478        unsafe {
479            from_glib(ffi::gtk_text_iter_can_insert(
480                self.to_glib_none().0,
481                default_editability.into_glib(),
482            ))
483        }
484    }
485
486    #[doc(alias = "gtk_text_iter_compare")]
487    fn compare(&self, rhs: &TextIter) -> i32 {
488        unsafe { ffi::gtk_text_iter_compare(self.to_glib_none().0, rhs.to_glib_none().0) }
489    }
490
491    /// Returns whether the character at @self is within an editable region
492    /// of text.
493    ///
494    /// Non-editable text is “locked” and can’t be changed by the
495    /// user via [`TextView`][crate::TextView]. If no tags applied to this text affect
496    /// editability, @default_setting will be returned.
497    ///
498    /// You don’t want to use this function to decide whether text can be
499    /// inserted at @self, because for insertion you don’t want to know
500    /// whether the char at @self is inside an editable range, you want to
501    /// know whether a new character inserted at @self would be inside an
502    /// editable range. Use [`can_insert()`][Self::can_insert()] to handle this
503    /// case.
504    /// ## `default_setting`
505    /// [`true`] if text is editable by default
506    ///
507    /// # Returns
508    ///
509    /// whether @self is inside an editable range
510    #[doc(alias = "gtk_text_iter_editable")]
511    pub fn editable(&self, default_setting: bool) -> bool {
512        unsafe {
513            from_glib(ffi::gtk_text_iter_editable(
514                self.to_glib_none().0,
515                default_setting.into_glib(),
516            ))
517        }
518    }
519
520    /// Returns [`true`] if @self points to the start of the paragraph
521    /// delimiter characters for a line.
522    ///
523    /// Delimiters will be either a newline, a carriage return, a carriage
524    /// return followed by a newline, or a Unicode paragraph separator
525    /// character.
526    ///
527    /// Note that an iterator pointing to the \n of a \r\n pair will not be
528    /// counted as the end of a line, the line ends before the \r. The end
529    /// iterator is considered to be at the end of a line, even though there
530    /// are no paragraph delimiter chars there.
531    ///
532    /// # Returns
533    ///
534    /// whether @self is at the end of a line
535    #[doc(alias = "gtk_text_iter_ends_line")]
536    pub fn ends_line(&self) -> bool {
537        unsafe { from_glib(ffi::gtk_text_iter_ends_line(self.to_glib_none().0)) }
538    }
539
540    /// Determines whether @self ends a sentence.
541    ///
542    /// Sentence boundaries are determined by Pango and should
543    /// be correct for nearly any language.
544    ///
545    /// # Returns
546    ///
547    /// [`true`] if @self is at the end of a sentence.
548    #[doc(alias = "gtk_text_iter_ends_sentence")]
549    pub fn ends_sentence(&self) -> bool {
550        unsafe { from_glib(ffi::gtk_text_iter_ends_sentence(self.to_glib_none().0)) }
551    }
552
553    /// Returns [`true`] if @tag is toggled off at exactly this point.
554    ///
555    /// If @tag is [`None`], returns [`true`] if any tag is toggled off at this point.
556    ///
557    /// Note that if this function returns [`true`], it means that
558    /// @self is at the end of the tagged range, but that the character
559    /// at @self is outside the tagged range. In other words,
560    /// unlike [`starts_tag()`][Self::starts_tag()], if this function
561    /// returns [`true`], [`has_tag()`][Self::has_tag()] will return
562    /// [`false`] for the same parameters.
563    /// ## `tag`
564    /// a [`TextTag`][crate::TextTag]
565    ///
566    /// # Returns
567    ///
568    /// whether @self is the end of a range tagged with @tag
569    #[doc(alias = "gtk_text_iter_ends_tag")]
570    pub fn ends_tag(&self, tag: Option<&impl IsA<TextTag>>) -> bool {
571        unsafe {
572            from_glib(ffi::gtk_text_iter_ends_tag(
573                self.to_glib_none().0,
574                tag.map(|p| p.as_ref()).to_glib_none().0,
575            ))
576        }
577    }
578
579    /// Determines whether @self ends a natural-language word.
580    ///
581    /// Word breaks are determined by Pango and should be correct
582    /// for nearly any language.
583    ///
584    /// # Returns
585    ///
586    /// [`true`] if @self is at the end of a word
587    #[doc(alias = "gtk_text_iter_ends_word")]
588    pub fn ends_word(&self) -> bool {
589        unsafe { from_glib(ffi::gtk_text_iter_ends_word(self.to_glib_none().0)) }
590    }
591
592    #[doc(alias = "gtk_text_iter_equal")]
593    fn equal(&self, rhs: &TextIter) -> bool {
594        unsafe {
595            from_glib(ffi::gtk_text_iter_equal(
596                self.to_glib_none().0,
597                rhs.to_glib_none().0,
598            ))
599        }
600    }
601
602    /// Moves @self forward by one character offset.
603    ///
604    /// Note that images embedded in the buffer occupy 1 character slot, so
605    /// this function may actually move onto an image instead of a character,
606    /// if you have images in your buffer. If @self is the end iterator or
607    /// one character before it, @self will now point at the end iterator,
608    /// and this function returns [`false`] for convenience when writing loops.
609    ///
610    /// # Returns
611    ///
612    /// whether @self moved and is dereferenceable
613    #[doc(alias = "gtk_text_iter_forward_char")]
614    pub fn forward_char(&mut self) -> bool {
615        unsafe { from_glib(ffi::gtk_text_iter_forward_char(self.to_glib_none_mut().0)) }
616    }
617
618    /// Moves @count characters if possible.
619    ///
620    /// If @count would move past the start or end of the buffer,
621    /// moves to the start or end of the buffer.
622    ///
623    /// The return value indicates whether the new position of
624    /// @self is different from its original position, and dereferenceable
625    /// (the last iterator in the buffer is not dereferenceable). If @count
626    /// is 0, the function does nothing and returns [`false`].
627    /// ## `count`
628    /// number of characters to move, may be negative
629    ///
630    /// # Returns
631    ///
632    /// whether @self moved and is dereferenceable
633    #[doc(alias = "gtk_text_iter_forward_chars")]
634    pub fn forward_chars(&mut self, count: i32) -> bool {
635        unsafe {
636            from_glib(ffi::gtk_text_iter_forward_chars(
637                self.to_glib_none_mut().0,
638                count,
639            ))
640        }
641    }
642
643    /// Moves @self forward by a single cursor position.
644    ///
645    /// Cursor positions are (unsurprisingly) positions where the
646    /// cursor can appear. Perhaps surprisingly, there may not be
647    /// a cursor position between all characters. The most common
648    /// example for European languages would be a carriage return/newline
649    /// sequence.
650    ///
651    /// For some Unicode characters, the equivalent of say the letter “a”
652    /// with an accent mark will be represented as two characters, first
653    /// the letter then a "combining mark" that causes the accent to be
654    /// rendered; so the cursor can’t go between those two characters.
655    ///
656    /// See also the `Pango::LogAttr` struct and the `break()`
657    /// function.
658    ///
659    /// # Returns
660    ///
661    /// [`true`] if we moved and the new position is dereferenceable
662    #[doc(alias = "gtk_text_iter_forward_cursor_position")]
663    pub fn forward_cursor_position(&mut self) -> bool {
664        unsafe {
665            from_glib(ffi::gtk_text_iter_forward_cursor_position(
666                self.to_glib_none_mut().0,
667            ))
668        }
669    }
670
671    /// Moves up to @count cursor positions.
672    ///
673    /// See [`forward_cursor_position()`][Self::forward_cursor_position()] for details.
674    /// ## `count`
675    /// number of positions to move
676    ///
677    /// # Returns
678    ///
679    /// [`true`] if we moved and the new position is dereferenceable
680    #[doc(alias = "gtk_text_iter_forward_cursor_positions")]
681    pub fn forward_cursor_positions(&mut self, count: i32) -> bool {
682        unsafe {
683            from_glib(ffi::gtk_text_iter_forward_cursor_positions(
684                self.to_glib_none_mut().0,
685                count,
686            ))
687        }
688    }
689
690    /// Advances @self, calling @pred on each character.
691    ///
692    /// If @pred returns [`true`], returns [`true`] and stops scanning.
693    /// If @pred never returns [`true`], @self is set to @limit if
694    /// @limit is non-[`None`], otherwise to the end iterator.
695    /// ## `pred`
696    /// a function to be called on each character
697    /// ## `limit`
698    /// search limit
699    ///
700    /// # Returns
701    ///
702    /// whether a match was found
703    #[doc(alias = "gtk_text_iter_forward_find_char")]
704    pub fn forward_find_char<P: FnMut(char) -> bool>(
705        &mut self,
706        pred: P,
707        limit: Option<&TextIter>,
708    ) -> bool {
709        let mut pred_data: P = pred;
710        unsafe extern "C" fn pred_func<P: FnMut(char) -> bool>(
711            ch: u32,
712            user_data: glib::ffi::gpointer,
713        ) -> glib::ffi::gboolean {
714            let ch = std::convert::TryFrom::try_from(ch)
715                .expect("conversion from an invalid Unicode value attempted");
716            let callback = user_data as *mut P;
717            (*callback)(ch).into_glib()
718        }
719        let pred = Some(pred_func::<P> as _);
720        let super_callback0: &mut P = &mut pred_data;
721        unsafe {
722            from_glib(ffi::gtk_text_iter_forward_find_char(
723                self.to_glib_none_mut().0,
724                pred,
725                super_callback0 as *mut _ as *mut _,
726                limit.to_glib_none().0,
727            ))
728        }
729    }
730
731    /// Moves @self to the start of the next line.
732    ///
733    /// If the iter is already on the last line of the buffer,
734    /// moves the iter to the end of the current line. If after
735    /// the operation, the iter is at the end of the buffer and not
736    /// dereferenceable, returns [`false`]. Otherwise, returns [`true`].
737    ///
738    /// # Returns
739    ///
740    /// whether @self can be dereferenced
741    #[doc(alias = "gtk_text_iter_forward_line")]
742    pub fn forward_line(&mut self) -> bool {
743        unsafe { from_glib(ffi::gtk_text_iter_forward_line(self.to_glib_none_mut().0)) }
744    }
745
746    /// Moves @count lines forward, if possible.
747    ///
748    /// If @count would move past the start or end of the buffer, moves to
749    /// the start or end of the buffer.
750    ///
751    /// The return value indicates whether the iterator moved
752    /// onto a dereferenceable position; if the iterator didn’t move, or
753    /// moved onto the end iterator, then [`false`] is returned. If @count is 0,
754    /// the function does nothing and returns [`false`]. If @count is negative,
755    /// moves backward by 0 - @count lines.
756    /// ## `count`
757    /// number of lines to move forward
758    ///
759    /// # Returns
760    ///
761    /// whether @self moved and is dereferenceable
762    #[doc(alias = "gtk_text_iter_forward_lines")]
763    pub fn forward_lines(&mut self, count: i32) -> bool {
764        unsafe {
765            from_glib(ffi::gtk_text_iter_forward_lines(
766                self.to_glib_none_mut().0,
767                count,
768            ))
769        }
770    }
771
772    /// Searches forward for @str.
773    ///
774    /// Any match is returned by setting @match_start to the first character
775    /// of the match and @match_end to the first character after the match.
776    /// The search will not continue past @limit. Note that a search is a
777    /// linear or O(n) operation, so you may wish to use @limit to avoid
778    /// locking up your UI on large buffers.
779    ///
780    /// @match_start will never be set to a [`TextIter`][crate::TextIter] located before @self,
781    /// even if there is a possible @match_end after or at @self.
782    /// ## `str`
783    /// a search string
784    /// ## `flags`
785    /// flags affecting how the search is done
786    /// ## `limit`
787    /// location of last possible @match_end, or [`None`] for the end of the buffer
788    ///
789    /// # Returns
790    ///
791    /// whether a match was found
792    ///
793    /// ## `match_start`
794    /// return location for start of match
795    ///
796    /// ## `match_end`
797    /// return location for end of match
798    #[doc(alias = "gtk_text_iter_forward_search")]
799    pub fn forward_search(
800        &self,
801        str: &str,
802        flags: TextSearchFlags,
803        limit: Option<&TextIter>,
804    ) -> Option<(TextIter, TextIter)> {
805        unsafe {
806            let mut match_start = TextIter::uninitialized();
807            let mut match_end = TextIter::uninitialized();
808            let ret = from_glib(ffi::gtk_text_iter_forward_search(
809                self.to_glib_none().0,
810                str.to_glib_none().0,
811                flags.into_glib(),
812                match_start.to_glib_none_mut().0,
813                match_end.to_glib_none_mut().0,
814                limit.to_glib_none().0,
815            ));
816            if ret {
817                Some((match_start, match_end))
818            } else {
819                None
820            }
821        }
822    }
823
824    /// Moves forward to the next sentence end.
825    ///
826    /// If @self is at the end of a sentence, moves to the next
827    /// end of sentence.
828    ///
829    /// Sentence boundaries are determined by Pango and should
830    /// be correct for nearly any language.
831    ///
832    /// # Returns
833    ///
834    /// [`true`] if @self moved and is not the end iterator
835    #[doc(alias = "gtk_text_iter_forward_sentence_end")]
836    pub fn forward_sentence_end(&mut self) -> bool {
837        unsafe {
838            from_glib(ffi::gtk_text_iter_forward_sentence_end(
839                self.to_glib_none_mut().0,
840            ))
841        }
842    }
843
844    /// Calls [`forward_sentence_end()`][Self::forward_sentence_end()] @count times.
845    ///
846    /// If @count is negative, moves backward instead of forward.
847    /// ## `count`
848    /// number of sentences to move
849    ///
850    /// # Returns
851    ///
852    /// [`true`] if @self moved and is not the end iterator
853    #[doc(alias = "gtk_text_iter_forward_sentence_ends")]
854    pub fn forward_sentence_ends(&mut self, count: i32) -> bool {
855        unsafe {
856            from_glib(ffi::gtk_text_iter_forward_sentence_ends(
857                self.to_glib_none_mut().0,
858                count,
859            ))
860        }
861    }
862
863    /// Moves @self forward to the “end iterator”, which points
864    /// one past the last valid character in the buffer.
865    ///
866    /// [`char()`][Self::char()] called on the end iterator
867    /// returns 0, which is convenient for writing loops.
868    #[doc(alias = "gtk_text_iter_forward_to_end")]
869    pub fn forward_to_end(&mut self) {
870        unsafe {
871            ffi::gtk_text_iter_forward_to_end(self.to_glib_none_mut().0);
872        }
873    }
874
875    /// Moves the iterator to point to the paragraph delimiter characters.
876    ///
877    /// The possible characters are either a newline, a carriage return,
878    /// a carriage return/newline in sequence, or the Unicode paragraph
879    /// separator character.
880    ///
881    /// If the iterator is already at the paragraph delimiter
882    /// characters, moves to the paragraph delimiter characters for the
883    /// next line. If @self is on the last line in the buffer, which does
884    /// not end in paragraph delimiters, moves to the end iterator (end of
885    /// the last line), and returns [`false`].
886    ///
887    /// # Returns
888    ///
889    /// [`true`] if we moved and the new location is not the end iterator
890    #[doc(alias = "gtk_text_iter_forward_to_line_end")]
891    pub fn forward_to_line_end(&mut self) -> bool {
892        unsafe {
893            from_glib(ffi::gtk_text_iter_forward_to_line_end(
894                self.to_glib_none_mut().0,
895            ))
896        }
897    }
898
899    /// Moves forward to the next toggle (on or off) of the
900    /// @tag, or to the next toggle of any tag if
901    /// @tag is [`None`].
902    ///
903    /// If no matching tag toggles are found,
904    /// returns [`false`], otherwise [`true`]. Does not return toggles
905    /// located at @self, only toggles after @self. Sets @self to
906    /// the location of the toggle, or to the end of the buffer
907    /// if no toggle is found.
908    /// ## `tag`
909    /// a [`TextTag`][crate::TextTag]
910    ///
911    /// # Returns
912    ///
913    /// whether we found a tag toggle after @self
914    #[doc(alias = "gtk_text_iter_forward_to_tag_toggle")]
915    pub fn forward_to_tag_toggle(&mut self, tag: Option<&impl IsA<TextTag>>) -> bool {
916        unsafe {
917            from_glib(ffi::gtk_text_iter_forward_to_tag_toggle(
918                self.to_glib_none_mut().0,
919                tag.map(|p| p.as_ref()).to_glib_none().0,
920            ))
921        }
922    }
923
924    /// Moves @self forward to the next visible cursor position.
925    ///
926    /// See [`forward_cursor_position()`][Self::forward_cursor_position()] for details.
927    ///
928    /// # Returns
929    ///
930    /// [`true`] if we moved and the new position is dereferenceable
931    #[doc(alias = "gtk_text_iter_forward_visible_cursor_position")]
932    pub fn forward_visible_cursor_position(&mut self) -> bool {
933        unsafe {
934            from_glib(ffi::gtk_text_iter_forward_visible_cursor_position(
935                self.to_glib_none_mut().0,
936            ))
937        }
938    }
939
940    /// Moves up to @count visible cursor positions.
941    ///
942    /// See [`forward_cursor_position()`][Self::forward_cursor_position()] for details.
943    /// ## `count`
944    /// number of positions to move
945    ///
946    /// # Returns
947    ///
948    /// [`true`] if we moved and the new position is dereferenceable
949    #[doc(alias = "gtk_text_iter_forward_visible_cursor_positions")]
950    pub fn forward_visible_cursor_positions(&mut self, count: i32) -> bool {
951        unsafe {
952            from_glib(ffi::gtk_text_iter_forward_visible_cursor_positions(
953                self.to_glib_none_mut().0,
954                count,
955            ))
956        }
957    }
958
959    /// Moves @self to the start of the next visible line.
960    ///
961    /// Returns [`true`] if there
962    /// was a next line to move to, and [`false`] if @self was simply moved to
963    /// the end of the buffer and is now not dereferenceable, or if @self was
964    /// already at the end of the buffer.
965    ///
966    /// # Returns
967    ///
968    /// whether @self can be dereferenced
969    #[doc(alias = "gtk_text_iter_forward_visible_line")]
970    pub fn forward_visible_line(&mut self) -> bool {
971        unsafe {
972            from_glib(ffi::gtk_text_iter_forward_visible_line(
973                self.to_glib_none_mut().0,
974            ))
975        }
976    }
977
978    /// Moves @count visible lines forward, if possible.
979    ///
980    /// If @count would move past the start or end of the buffer, moves to
981    /// the start or end of the buffer.
982    ///
983    /// The return value indicates whether the iterator moved
984    /// onto a dereferenceable position; if the iterator didn’t move, or
985    /// moved onto the end iterator, then [`false`] is returned. If @count is 0,
986    /// the function does nothing and returns [`false`]. If @count is negative,
987    /// moves backward by 0 - @count lines.
988    /// ## `count`
989    /// number of lines to move forward
990    ///
991    /// # Returns
992    ///
993    /// whether @self moved and is dereferenceable
994    #[doc(alias = "gtk_text_iter_forward_visible_lines")]
995    pub fn forward_visible_lines(&mut self, count: i32) -> bool {
996        unsafe {
997            from_glib(ffi::gtk_text_iter_forward_visible_lines(
998                self.to_glib_none_mut().0,
999                count,
1000            ))
1001        }
1002    }
1003
1004    /// Moves forward to the next visible word end.
1005    ///
1006    /// If @self is currently on a word end, moves forward to the
1007    /// next one after that.
1008    ///
1009    /// Word breaks are determined by Pango and should be correct
1010    /// for nearly any language
1011    ///
1012    /// # Returns
1013    ///
1014    /// [`true`] if @self moved and is not the end iterator
1015    #[doc(alias = "gtk_text_iter_forward_visible_word_end")]
1016    pub fn forward_visible_word_end(&mut self) -> bool {
1017        unsafe {
1018            from_glib(ffi::gtk_text_iter_forward_visible_word_end(
1019                self.to_glib_none_mut().0,
1020            ))
1021        }
1022    }
1023
1024    /// Calls [`forward_visible_word_end()`][Self::forward_visible_word_end()] up to @count times.
1025    /// ## `count`
1026    /// number of times to move
1027    ///
1028    /// # Returns
1029    ///
1030    /// [`true`] if @self moved and is not the end iterator
1031    #[doc(alias = "gtk_text_iter_forward_visible_word_ends")]
1032    pub fn forward_visible_word_ends(&mut self, count: i32) -> bool {
1033        unsafe {
1034            from_glib(ffi::gtk_text_iter_forward_visible_word_ends(
1035                self.to_glib_none_mut().0,
1036                count,
1037            ))
1038        }
1039    }
1040
1041    /// Moves forward to the next word end.
1042    ///
1043    /// If @self is currently on a word end, moves forward to the
1044    /// next one after that.
1045    ///
1046    /// Word breaks are determined by Pango and should be correct
1047    /// for nearly any language.
1048    ///
1049    /// # Returns
1050    ///
1051    /// [`true`] if @self moved and is not the end iterator
1052    #[doc(alias = "gtk_text_iter_forward_word_end")]
1053    pub fn forward_word_end(&mut self) -> bool {
1054        unsafe {
1055            from_glib(ffi::gtk_text_iter_forward_word_end(
1056                self.to_glib_none_mut().0,
1057            ))
1058        }
1059    }
1060
1061    /// Calls [`forward_word_end()`][Self::forward_word_end()] up to @count times.
1062    /// ## `count`
1063    /// number of times to move
1064    ///
1065    /// # Returns
1066    ///
1067    /// [`true`] if @self moved and is not the end iterator
1068    #[doc(alias = "gtk_text_iter_forward_word_ends")]
1069    pub fn forward_word_ends(&mut self, count: i32) -> bool {
1070        unsafe {
1071            from_glib(ffi::gtk_text_iter_forward_word_ends(
1072                self.to_glib_none_mut().0,
1073                count,
1074            ))
1075        }
1076    }
1077
1078    /// Returns the [`TextBuffer`][crate::TextBuffer] this iterator is associated with.
1079    ///
1080    /// # Returns
1081    ///
1082    /// the buffer
1083    #[doc(alias = "gtk_text_iter_get_buffer")]
1084    #[doc(alias = "get_buffer")]
1085    pub fn buffer(&self) -> TextBuffer {
1086        unsafe { from_glib_none(ffi::gtk_text_iter_get_buffer(self.to_glib_none().0)) }
1087    }
1088
1089    /// Returns the number of bytes in the line containing @self,
1090    /// including the paragraph delimiters.
1091    ///
1092    /// # Returns
1093    ///
1094    /// number of bytes in the line
1095    #[doc(alias = "gtk_text_iter_get_bytes_in_line")]
1096    #[doc(alias = "get_bytes_in_line")]
1097    pub fn bytes_in_line(&self) -> i32 {
1098        unsafe { ffi::gtk_text_iter_get_bytes_in_line(self.to_glib_none().0) }
1099    }
1100
1101    /// The Unicode character at this iterator is returned.
1102    ///
1103    /// Equivalent to operator* on a C++ iterator. If the element at
1104    /// this iterator is a non-character element, such as an image
1105    /// embedded in the buffer, the Unicode “unknown” character 0xFFFC
1106    /// is returned. If invoked on the end iterator, zero is returned;
1107    /// zero is not a valid Unicode character.
1108    ///
1109    /// So you can write a loop which ends when this function returns 0.
1110    ///
1111    /// # Returns
1112    ///
1113    /// a Unicode character, or 0 if @self is not dereferenceable
1114    #[doc(alias = "gtk_text_iter_get_char")]
1115    #[doc(alias = "get_char")]
1116    pub fn char(&self) -> char {
1117        unsafe {
1118            std::convert::TryFrom::try_from(ffi::gtk_text_iter_get_char(self.to_glib_none().0))
1119                .expect("conversion from an invalid Unicode value attempted")
1120        }
1121    }
1122
1123    /// Returns the number of characters in the line containing @self,
1124    /// including the paragraph delimiters.
1125    ///
1126    /// # Returns
1127    ///
1128    /// number of characters in the line
1129    #[doc(alias = "gtk_text_iter_get_chars_in_line")]
1130    #[doc(alias = "get_chars_in_line")]
1131    pub fn chars_in_line(&self) -> i32 {
1132        unsafe { ffi::gtk_text_iter_get_chars_in_line(self.to_glib_none().0) }
1133    }
1134
1135    /// If the location at @self contains a child anchor, the
1136    /// anchor is returned.
1137    ///
1138    /// Otherwise, [`None`] is returned.
1139    ///
1140    /// # Returns
1141    ///
1142    /// the anchor at @self
1143    #[doc(alias = "gtk_text_iter_get_child_anchor")]
1144    #[doc(alias = "get_child_anchor")]
1145    pub fn child_anchor(&self) -> Option<TextChildAnchor> {
1146        unsafe { from_glib_none(ffi::gtk_text_iter_get_child_anchor(self.to_glib_none().0)) }
1147    }
1148
1149    /// Returns the language in effect at @self.
1150    ///
1151    /// If no tags affecting language apply to @self, the return
1152    /// value is identical to that of [`default_language()`][crate::default_language()].
1153    ///
1154    /// # Returns
1155    ///
1156    /// language in effect at @self
1157    #[doc(alias = "gtk_text_iter_get_language")]
1158    #[doc(alias = "get_language")]
1159    pub fn language(&self) -> pango::Language {
1160        unsafe { from_glib_full(ffi::gtk_text_iter_get_language(self.to_glib_none().0)) }
1161    }
1162
1163    /// Returns the line number containing the iterator.
1164    ///
1165    /// Lines in a [`TextBuffer`][crate::TextBuffer] are numbered beginning
1166    /// with 0 for the first line in the buffer.
1167    ///
1168    /// # Returns
1169    ///
1170    /// a line number
1171    #[doc(alias = "gtk_text_iter_get_line")]
1172    #[doc(alias = "get_line")]
1173    pub fn line(&self) -> i32 {
1174        unsafe { ffi::gtk_text_iter_get_line(self.to_glib_none().0) }
1175    }
1176
1177    /// Returns the byte index of the iterator, counting
1178    /// from the start of a newline-terminated line.
1179    ///
1180    /// Remember that [`TextBuffer`][crate::TextBuffer] encodes text in
1181    /// UTF-8, and that characters can require a variable
1182    /// number of bytes to represent.
1183    ///
1184    /// # Returns
1185    ///
1186    /// distance from start of line, in bytes
1187    #[doc(alias = "gtk_text_iter_get_line_index")]
1188    #[doc(alias = "get_line_index")]
1189    pub fn line_index(&self) -> i32 {
1190        unsafe { ffi::gtk_text_iter_get_line_index(self.to_glib_none().0) }
1191    }
1192
1193    /// Returns the character offset of the iterator,
1194    /// counting from the start of a newline-terminated line.
1195    ///
1196    /// The first character on the line has offset 0.
1197    ///
1198    /// # Returns
1199    ///
1200    /// offset from start of line
1201    #[doc(alias = "gtk_text_iter_get_line_offset")]
1202    #[doc(alias = "get_line_offset")]
1203    pub fn line_offset(&self) -> i32 {
1204        unsafe { ffi::gtk_text_iter_get_line_offset(self.to_glib_none().0) }
1205    }
1206
1207    /// Returns a list of all [`TextMark`][crate::TextMark] at this location.
1208    ///
1209    /// Because marks are not iterable (they don’t take up any "space"
1210    /// in the buffer, they are just marks in between iterable locations),
1211    /// multiple marks can exist in the same place.
1212    ///
1213    /// The returned list is not in any meaningful order.
1214    ///
1215    /// # Returns
1216    ///
1217    ///
1218    ///   list of [`TextMark`][crate::TextMark]
1219    #[doc(alias = "gtk_text_iter_get_marks")]
1220    #[doc(alias = "get_marks")]
1221    pub fn marks(&self) -> Vec<TextMark> {
1222        unsafe {
1223            FromGlibPtrContainer::from_glib_container(ffi::gtk_text_iter_get_marks(
1224                self.to_glib_none().0,
1225            ))
1226        }
1227    }
1228
1229    /// Returns the character offset of an iterator.
1230    ///
1231    /// Each character in a [`TextBuffer`][crate::TextBuffer] has an offset,
1232    /// starting with 0 for the first character in the buffer.
1233    /// Use [`TextBufferExt::iter_at_offset()`][crate::prelude::TextBufferExt::iter_at_offset()] to convert
1234    /// an offset back into an iterator.
1235    ///
1236    /// # Returns
1237    ///
1238    /// a character offset
1239    #[doc(alias = "gtk_text_iter_get_offset")]
1240    #[doc(alias = "get_offset")]
1241    pub fn offset(&self) -> i32 {
1242        unsafe { ffi::gtk_text_iter_get_offset(self.to_glib_none().0) }
1243    }
1244
1245    /// If the element at @self is a paintable, the paintable is returned.
1246    ///
1247    /// Otherwise, [`None`] is returned.
1248    ///
1249    /// # Returns
1250    ///
1251    /// the paintable at @self
1252    #[doc(alias = "gtk_text_iter_get_paintable")]
1253    #[doc(alias = "get_paintable")]
1254    pub fn paintable(&self) -> Option<gdk::Paintable> {
1255        unsafe { from_glib_none(ffi::gtk_text_iter_get_paintable(self.to_glib_none().0)) }
1256    }
1257
1258    /// Returns the text in the given range.
1259    ///
1260    /// A “slice” is an array of characters encoded in UTF-8 format,
1261    /// including the Unicode “unknown” character 0xFFFC for iterable
1262    /// non-character elements in the buffer, such as images.
1263    /// Because images are encoded in the slice, byte and
1264    /// character offsets in the returned array will correspond to byte
1265    /// offsets in the text buffer. Note that 0xFFFC can occur in normal
1266    /// text as well, so it is not a reliable indicator that a paintable or
1267    /// widget is in the buffer.
1268    /// ## `end`
1269    /// iterator at end of a range
1270    ///
1271    /// # Returns
1272    ///
1273    /// slice of text from the buffer
1274    #[doc(alias = "gtk_text_iter_get_slice")]
1275    #[doc(alias = "get_slice")]
1276    pub fn slice(&self, end: &TextIter) -> glib::GString {
1277        unsafe {
1278            from_glib_full(ffi::gtk_text_iter_get_slice(
1279                self.to_glib_none().0,
1280                end.to_glib_none().0,
1281            ))
1282        }
1283    }
1284
1285    /// Returns a list of tags that apply to @self, in ascending order of
1286    /// priority.
1287    ///
1288    /// The highest-priority tags are last.
1289    ///
1290    /// The [`TextTag`][crate::TextTag]s in the list don’t have a reference added,
1291    /// but you have to free the list itself.
1292    ///
1293    /// # Returns
1294    ///
1295    /// list of
1296    ///   [`TextTag`][crate::TextTag]
1297    #[doc(alias = "gtk_text_iter_get_tags")]
1298    #[doc(alias = "get_tags")]
1299    pub fn tags(&self) -> Vec<TextTag> {
1300        unsafe {
1301            FromGlibPtrContainer::from_glib_container(ffi::gtk_text_iter_get_tags(
1302                self.to_glib_none().0,
1303            ))
1304        }
1305    }
1306
1307    /// Returns text in the given range.
1308    ///
1309    /// If the range
1310    /// contains non-text elements such as images, the character and byte
1311    /// offsets in the returned string will not correspond to character and
1312    /// byte offsets in the buffer. If you want offsets to correspond, see
1313    /// [`slice()`][Self::slice()].
1314    /// ## `end`
1315    /// iterator at end of a range
1316    ///
1317    /// # Returns
1318    ///
1319    /// array of characters from the buffer
1320    #[doc(alias = "gtk_text_iter_get_text")]
1321    #[doc(alias = "get_text")]
1322    pub fn text(&self, end: &TextIter) -> glib::GString {
1323        unsafe {
1324            from_glib_full(ffi::gtk_text_iter_get_text(
1325                self.to_glib_none().0,
1326                end.to_glib_none().0,
1327            ))
1328        }
1329    }
1330
1331    /// Returns a list of [`TextTag`][crate::TextTag] that are toggled on or off at this
1332    /// point.
1333    ///
1334    /// If @toggled_on is [`true`], the list contains tags that are
1335    /// toggled on. If a tag is toggled on at @self, then some non-empty
1336    /// range of characters following @self has that tag applied to it.  If
1337    /// a tag is toggled off, then some non-empty range following @self
1338    /// does not have the tag applied to it.
1339    /// ## `toggled_on`
1340    /// [`true`] to get toggled-on tags
1341    ///
1342    /// # Returns
1343    ///
1344    /// tags
1345    ///   toggled at this point
1346    #[doc(alias = "gtk_text_iter_get_toggled_tags")]
1347    #[doc(alias = "get_toggled_tags")]
1348    pub fn toggled_tags(&self, toggled_on: bool) -> Vec<TextTag> {
1349        unsafe {
1350            FromGlibPtrContainer::from_glib_container(ffi::gtk_text_iter_get_toggled_tags(
1351                self.to_glib_none().0,
1352                toggled_on.into_glib(),
1353            ))
1354        }
1355    }
1356
1357    /// Returns the number of bytes from the start of the
1358    /// line to the given @self, not counting bytes that
1359    /// are invisible due to tags with the “invisible” flag
1360    /// toggled on.
1361    ///
1362    /// # Returns
1363    ///
1364    /// byte index of @self with respect to the start of the line
1365    #[doc(alias = "gtk_text_iter_get_visible_line_index")]
1366    #[doc(alias = "get_visible_line_index")]
1367    pub fn visible_line_index(&self) -> i32 {
1368        unsafe { ffi::gtk_text_iter_get_visible_line_index(self.to_glib_none().0) }
1369    }
1370
1371    /// Returns the offset in characters from the start of the
1372    /// line to the given @self, not counting characters that
1373    /// are invisible due to tags with the “invisible” flag
1374    /// toggled on.
1375    ///
1376    /// # Returns
1377    ///
1378    /// offset in visible characters from the start of the line
1379    #[doc(alias = "gtk_text_iter_get_visible_line_offset")]
1380    #[doc(alias = "get_visible_line_offset")]
1381    pub fn visible_line_offset(&self) -> i32 {
1382        unsafe { ffi::gtk_text_iter_get_visible_line_offset(self.to_glib_none().0) }
1383    }
1384
1385    /// Returns visible text in the given range.
1386    ///
1387    /// Like [`slice()`][Self::slice()], but invisible text
1388    /// is not included. Invisible text is usually invisible because
1389    /// a [`TextTag`][crate::TextTag] with the “invisible” attribute turned on has
1390    /// been applied to it.
1391    /// ## `end`
1392    /// iterator at end of range
1393    ///
1394    /// # Returns
1395    ///
1396    /// slice of text from the buffer
1397    #[doc(alias = "gtk_text_iter_get_visible_slice")]
1398    #[doc(alias = "get_visible_slice")]
1399    pub fn visible_slice(&self, end: &TextIter) -> glib::GString {
1400        unsafe {
1401            from_glib_full(ffi::gtk_text_iter_get_visible_slice(
1402                self.to_glib_none().0,
1403                end.to_glib_none().0,
1404            ))
1405        }
1406    }
1407
1408    /// Returns visible text in the given range.
1409    ///
1410    /// Like [`text()`][Self::text()], but invisible text
1411    /// is not included. Invisible text is usually invisible because
1412    /// a [`TextTag`][crate::TextTag] with the “invisible” attribute turned on has
1413    /// been applied to it.
1414    /// ## `end`
1415    /// iterator at end of range
1416    ///
1417    /// # Returns
1418    ///
1419    /// string containing visible text in the
1420    /// range
1421    #[doc(alias = "gtk_text_iter_get_visible_text")]
1422    #[doc(alias = "get_visible_text")]
1423    pub fn visible_text(&self, end: &TextIter) -> glib::GString {
1424        unsafe {
1425            from_glib_full(ffi::gtk_text_iter_get_visible_text(
1426                self.to_glib_none().0,
1427                end.to_glib_none().0,
1428            ))
1429        }
1430    }
1431
1432    /// Returns [`true`] if @self points to a character that is part
1433    /// of a range tagged with @tag.
1434    ///
1435    /// See also [`starts_tag()`][Self::starts_tag()] and
1436    /// [`ends_tag()`][Self::ends_tag()].
1437    /// ## `tag`
1438    /// a [`TextTag`][crate::TextTag]
1439    ///
1440    /// # Returns
1441    ///
1442    /// whether @self is tagged with @tag
1443    #[doc(alias = "gtk_text_iter_has_tag")]
1444    pub fn has_tag(&self, tag: &impl IsA<TextTag>) -> bool {
1445        unsafe {
1446            from_glib(ffi::gtk_text_iter_has_tag(
1447                self.to_glib_none().0,
1448                tag.as_ref().to_glib_none().0,
1449            ))
1450        }
1451    }
1452
1453    /// Checks whether @self falls in the range [@start, @end).
1454    ///
1455    /// @start and @end must be in ascending order.
1456    /// ## `start`
1457    /// start of range
1458    /// ## `end`
1459    /// end of range
1460    ///
1461    /// # Returns
1462    ///
1463    /// [`true`] if @self is in the range
1464    #[doc(alias = "gtk_text_iter_in_range")]
1465    pub fn in_range(&self, start: &TextIter, end: &TextIter) -> bool {
1466        unsafe {
1467            from_glib(ffi::gtk_text_iter_in_range(
1468                self.to_glib_none().0,
1469                start.to_glib_none().0,
1470                end.to_glib_none().0,
1471            ))
1472        }
1473    }
1474
1475    /// Determines whether @self is inside a sentence (as opposed to in
1476    /// between two sentences, e.g. after a period and before the first
1477    /// letter of the next sentence).
1478    ///
1479    /// Sentence boundaries are determined by Pango and should be correct
1480    /// for nearly any language.
1481    ///
1482    /// # Returns
1483    ///
1484    /// [`true`] if @self is inside a sentence.
1485    #[doc(alias = "gtk_text_iter_inside_sentence")]
1486    pub fn inside_sentence(&self) -> bool {
1487        unsafe { from_glib(ffi::gtk_text_iter_inside_sentence(self.to_glib_none().0)) }
1488    }
1489
1490    /// Determines whether the character pointed by @self is part of a
1491    /// natural-language word (as opposed to say inside some whitespace).
1492    ///
1493    /// Word breaks are determined by Pango and should be correct
1494    /// for nearly any language.
1495    ///
1496    /// Note that if [`starts_word()`][Self::starts_word()] returns [`true`],
1497    /// then this function returns [`true`] too, since @self points to
1498    /// the first character of the word.
1499    ///
1500    /// # Returns
1501    ///
1502    /// [`true`] if @self is inside a word
1503    #[doc(alias = "gtk_text_iter_inside_word")]
1504    pub fn inside_word(&self) -> bool {
1505        unsafe { from_glib(ffi::gtk_text_iter_inside_word(self.to_glib_none().0)) }
1506    }
1507
1508    /// Determine if @self is at a cursor position.
1509    ///
1510    /// See [`forward_cursor_position()`][Self::forward_cursor_position()] or
1511    /// `Pango::LogAttr` or `break()` for details
1512    /// on what a cursor position is.
1513    ///
1514    /// # Returns
1515    ///
1516    /// [`true`] if the cursor can be placed at @self
1517    #[doc(alias = "gtk_text_iter_is_cursor_position")]
1518    pub fn is_cursor_position(&self) -> bool {
1519        unsafe { from_glib(ffi::gtk_text_iter_is_cursor_position(self.to_glib_none().0)) }
1520    }
1521
1522    /// Returns [`true`] if @self is the end iterator.
1523    ///
1524    /// This means it is one past the last dereferenceable iterator
1525    /// in the buffer. [`is_end()`][Self::is_end()] is the most efficient
1526    /// way to check whether an iterator is the end iterator.
1527    ///
1528    /// # Returns
1529    ///
1530    /// whether @self is the end iterator
1531    #[doc(alias = "gtk_text_iter_is_end")]
1532    pub fn is_end(&self) -> bool {
1533        unsafe { from_glib(ffi::gtk_text_iter_is_end(self.to_glib_none().0)) }
1534    }
1535
1536    /// Returns [`true`] if @self is the first iterator in the buffer.
1537    ///
1538    /// # Returns
1539    ///
1540    /// whether @self is the first in the buffer
1541    #[doc(alias = "gtk_text_iter_is_start")]
1542    pub fn is_start(&self) -> bool {
1543        unsafe { from_glib(ffi::gtk_text_iter_is_start(self.to_glib_none().0)) }
1544    }
1545
1546    /// Swaps the value of @self and @second if @second comes before
1547    /// @self in the buffer.
1548    ///
1549    /// That is, ensures that @self and @second are in sequence.
1550    /// Most text buffer functions that take a range call this
1551    /// automatically on your behalf, so there’s no real reason to
1552    /// call it yourself in those cases. There are some exceptions,
1553    /// such as [`in_range()`][Self::in_range()], that expect a
1554    /// pre-sorted range.
1555    /// ## `second`
1556    /// another [`TextIter`][crate::TextIter]
1557    #[doc(alias = "gtk_text_iter_order")]
1558    pub fn order(&mut self, second: &mut TextIter) {
1559        unsafe {
1560            ffi::gtk_text_iter_order(self.to_glib_none_mut().0, second.to_glib_none_mut().0);
1561        }
1562    }
1563
1564    /// Moves iterator @self to the start of the line @line_number.
1565    ///
1566    /// If @line_number is negative or larger than or equal to the number of lines
1567    /// in the buffer, moves @self to the start of the last line in the buffer.
1568    /// ## `line_number`
1569    /// line number (counted from 0)
1570    #[doc(alias = "gtk_text_iter_set_line")]
1571    pub fn set_line(&mut self, line_number: i32) {
1572        unsafe {
1573            ffi::gtk_text_iter_set_line(self.to_glib_none_mut().0, line_number);
1574        }
1575    }
1576
1577    /// Same as [`set_line_offset()`][Self::set_line_offset()], but works with a
1578    /// byte index. The given byte index must be at
1579    /// the start of a character, it can’t be in the middle of a UTF-8
1580    /// encoded character.
1581    /// ## `byte_on_line`
1582    /// a byte index relative to the start of @self’s current line
1583    #[doc(alias = "gtk_text_iter_set_line_index")]
1584    pub fn set_line_index(&mut self, byte_on_line: i32) {
1585        unsafe {
1586            ffi::gtk_text_iter_set_line_index(self.to_glib_none_mut().0, byte_on_line);
1587        }
1588    }
1589
1590    /// Moves @self within a line, to a new character (not byte) offset.
1591    ///
1592    /// The given character offset must be less than or equal to the number
1593    /// of characters in the line; if equal, @self moves to the start of the
1594    /// next line. See [`set_line_index()`][Self::set_line_index()] if you have a byte
1595    /// index rather than a character offset.
1596    /// ## `char_on_line`
1597    /// a character offset relative to the start of @self’s current line
1598    #[doc(alias = "gtk_text_iter_set_line_offset")]
1599    pub fn set_line_offset(&mut self, char_on_line: i32) {
1600        unsafe {
1601            ffi::gtk_text_iter_set_line_offset(self.to_glib_none_mut().0, char_on_line);
1602        }
1603    }
1604
1605    /// Sets @self to point to @char_offset.
1606    ///
1607    /// @char_offset counts from the start
1608    /// of the entire text buffer, starting with 0.
1609    /// ## `char_offset`
1610    /// a character number
1611    #[doc(alias = "gtk_text_iter_set_offset")]
1612    pub fn set_offset(&mut self, char_offset: i32) {
1613        unsafe {
1614            ffi::gtk_text_iter_set_offset(self.to_glib_none_mut().0, char_offset);
1615        }
1616    }
1617
1618    /// Like [`set_line_index()`][Self::set_line_index()], but the index is in visible
1619    /// bytes, i.e. text with a tag making it invisible is not counted
1620    /// in the index.
1621    /// ## `byte_on_line`
1622    /// a byte index
1623    #[doc(alias = "gtk_text_iter_set_visible_line_index")]
1624    pub fn set_visible_line_index(&mut self, byte_on_line: i32) {
1625        unsafe {
1626            ffi::gtk_text_iter_set_visible_line_index(self.to_glib_none_mut().0, byte_on_line);
1627        }
1628    }
1629
1630    /// Like [`set_line_offset()`][Self::set_line_offset()], but the offset is in visible
1631    /// characters, i.e. text with a tag making it invisible is not
1632    /// counted in the offset.
1633    /// ## `char_on_line`
1634    /// a character offset
1635    #[doc(alias = "gtk_text_iter_set_visible_line_offset")]
1636    pub fn set_visible_line_offset(&mut self, char_on_line: i32) {
1637        unsafe {
1638            ffi::gtk_text_iter_set_visible_line_offset(self.to_glib_none_mut().0, char_on_line);
1639        }
1640    }
1641
1642    /// Returns [`true`] if @self begins a paragraph.
1643    ///
1644    /// This is the case if [`line_offset()`][Self::line_offset()]
1645    /// would return 0. However this function is potentially more
1646    /// efficient than [`line_offset()`][Self::line_offset()], because
1647    /// it doesn’t have to compute the offset, it just has to see
1648    /// whether it’s 0.
1649    ///
1650    /// # Returns
1651    ///
1652    /// whether @self begins a line
1653    #[doc(alias = "gtk_text_iter_starts_line")]
1654    pub fn starts_line(&self) -> bool {
1655        unsafe { from_glib(ffi::gtk_text_iter_starts_line(self.to_glib_none().0)) }
1656    }
1657
1658    /// Determines whether @self begins a sentence.
1659    ///
1660    /// Sentence boundaries are determined by Pango and
1661    /// should be correct for nearly any language.
1662    ///
1663    /// # Returns
1664    ///
1665    /// [`true`] if @self is at the start of a sentence.
1666    #[doc(alias = "gtk_text_iter_starts_sentence")]
1667    pub fn starts_sentence(&self) -> bool {
1668        unsafe { from_glib(ffi::gtk_text_iter_starts_sentence(self.to_glib_none().0)) }
1669    }
1670
1671    /// Returns [`true`] if @tag is toggled on at exactly this point.
1672    ///
1673    /// If @tag is [`None`], returns [`true`] if any tag is toggled on at this point.
1674    ///
1675    /// Note that if this function returns [`true`], it means that
1676    /// @self is at the beginning of the tagged range, and that the
1677    /// character at @self is inside the tagged range. In other
1678    /// words, unlike [`ends_tag()`][Self::ends_tag()], if
1679    /// this function returns [`true`], [`has_tag()`][Self::has_tag()]
1680    /// will also return [`true`] for the same parameters.
1681    /// ## `tag`
1682    /// a [`TextTag`][crate::TextTag]
1683    ///
1684    /// # Returns
1685    ///
1686    /// whether @self is the start of a range tagged with @tag
1687    #[doc(alias = "gtk_text_iter_starts_tag")]
1688    pub fn starts_tag(&self, tag: Option<&impl IsA<TextTag>>) -> bool {
1689        unsafe {
1690            from_glib(ffi::gtk_text_iter_starts_tag(
1691                self.to_glib_none().0,
1692                tag.map(|p| p.as_ref()).to_glib_none().0,
1693            ))
1694        }
1695    }
1696
1697    /// Determines whether @self begins a natural-language word.
1698    ///
1699    /// Word breaks are determined by Pango and should be correct
1700    /// for nearly any language.
1701    ///
1702    /// # Returns
1703    ///
1704    /// [`true`] if @self is at the start of a word
1705    #[doc(alias = "gtk_text_iter_starts_word")]
1706    pub fn starts_word(&self) -> bool {
1707        unsafe { from_glib(ffi::gtk_text_iter_starts_word(self.to_glib_none().0)) }
1708    }
1709
1710    /// Gets whether a range with @tag applied to it begins
1711    /// or ends at @self.
1712    ///
1713    /// This is equivalent to (gtk_text_iter_starts_tag() ||
1714    /// gtk_text_iter_ends_tag())
1715    /// ## `tag`
1716    /// a [`TextTag`][crate::TextTag]
1717    ///
1718    /// # Returns
1719    ///
1720    /// whether @tag is toggled on or off at @self
1721    #[doc(alias = "gtk_text_iter_toggles_tag")]
1722    pub fn toggles_tag(&self, tag: Option<&impl IsA<TextTag>>) -> bool {
1723        unsafe {
1724            from_glib(ffi::gtk_text_iter_toggles_tag(
1725                self.to_glib_none().0,
1726                tag.map(|p| p.as_ref()).to_glib_none().0,
1727            ))
1728        }
1729    }
1730}
1731
1732impl PartialOrd for TextIter {
1733    #[inline]
1734    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
1735        Some(self.cmp(other))
1736    }
1737}
1738
1739impl Ord for TextIter {
1740    #[inline]
1741    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
1742        self.compare(other).cmp(&0)
1743    }
1744}
1745
1746impl PartialEq for TextIter {
1747    #[inline]
1748    fn eq(&self, other: &Self) -> bool {
1749        self.equal(other)
1750    }
1751}
1752
1753impl Eq for TextIter {}