Skip to main content

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