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 forward to the next tag toggle before @limit.
929 ///
930 /// Finds the next start or end of @tag, or of any tag if @tag is [`None`].
931 /// Toggles at the initial position of @self and at @limit are excluded.
932 /// If no toggle is found, sets @self to @limit and returns [`false`].
933 /// If @limit is at or before @self, returns [`false`] without moving @self.
934 ///
935 /// If @limit is [`None`], searches to the end of the buffer, including any
936 /// toggle at the end iterator, just like
937 /// [`forward_to_tag_toggle()`][Self::forward_to_tag_toggle()].
938 /// ## `tag`
939 /// a [`TextTag`][crate::TextTag], or [`None`] to find any tag toggle
940 /// ## `limit`
941 /// the exclusive search limit, in the same buffer as @self
942 ///
943 /// # Returns
944 ///
945 /// whether a matching tag toggle was found
946 #[cfg(feature = "v4_26")]
947 #[cfg_attr(docsrs, doc(cfg(feature = "v4_26")))]
948 #[doc(alias = "gtk_text_iter_forward_to_tag_toggle_with_limit")]
949 pub fn forward_to_tag_toggle_with_limit(
950 &mut self,
951 tag: Option<&impl IsA<TextTag>>,
952 limit: Option<&TextIter>,
953 ) -> bool {
954 unsafe {
955 from_glib(ffi::gtk_text_iter_forward_to_tag_toggle_with_limit(
956 self.to_glib_none_mut().0,
957 tag.map(|p| p.as_ref()).to_glib_none().0,
958 limit.to_glib_none().0,
959 ))
960 }
961 }
962
963 /// Moves @self forward to the next visible cursor position.
964 ///
965 /// See [`forward_cursor_position()`][Self::forward_cursor_position()] for details.
966 ///
967 /// # Returns
968 ///
969 /// [`true`] if we moved and the new position is dereferenceable
970 #[doc(alias = "gtk_text_iter_forward_visible_cursor_position")]
971 pub fn forward_visible_cursor_position(&mut self) -> bool {
972 unsafe {
973 from_glib(ffi::gtk_text_iter_forward_visible_cursor_position(
974 self.to_glib_none_mut().0,
975 ))
976 }
977 }
978
979 /// Moves up to @count visible cursor positions.
980 ///
981 /// See [`forward_cursor_position()`][Self::forward_cursor_position()] for details.
982 /// ## `count`
983 /// number of positions to move
984 ///
985 /// # Returns
986 ///
987 /// [`true`] if we moved and the new position is dereferenceable
988 #[doc(alias = "gtk_text_iter_forward_visible_cursor_positions")]
989 pub fn forward_visible_cursor_positions(&mut self, count: i32) -> bool {
990 unsafe {
991 from_glib(ffi::gtk_text_iter_forward_visible_cursor_positions(
992 self.to_glib_none_mut().0,
993 count,
994 ))
995 }
996 }
997
998 /// Moves @self to the start of the next visible line.
999 ///
1000 /// Returns [`true`] if there
1001 /// was a next line to move to, and [`false`] if @self was simply moved to
1002 /// the end of the buffer and is now not dereferenceable, or if @self was
1003 /// already at the end of the buffer.
1004 ///
1005 /// # Returns
1006 ///
1007 /// whether @self can be dereferenced
1008 #[doc(alias = "gtk_text_iter_forward_visible_line")]
1009 pub fn forward_visible_line(&mut self) -> bool {
1010 unsafe {
1011 from_glib(ffi::gtk_text_iter_forward_visible_line(
1012 self.to_glib_none_mut().0,
1013 ))
1014 }
1015 }
1016
1017 /// Moves @count visible lines forward, if possible.
1018 ///
1019 /// If @count would move past the start or end of the buffer, moves to
1020 /// the start or end of the buffer.
1021 ///
1022 /// The return value indicates whether the iterator moved
1023 /// onto a dereferenceable position; if the iterator didn’t move, or
1024 /// moved onto the end iterator, then [`false`] is returned. If @count is 0,
1025 /// the function does nothing and returns [`false`]. If @count is negative,
1026 /// moves backward by 0 - @count lines.
1027 /// ## `count`
1028 /// number of lines to move forward
1029 ///
1030 /// # Returns
1031 ///
1032 /// whether @self moved and is dereferenceable
1033 #[doc(alias = "gtk_text_iter_forward_visible_lines")]
1034 pub fn forward_visible_lines(&mut self, count: i32) -> bool {
1035 unsafe {
1036 from_glib(ffi::gtk_text_iter_forward_visible_lines(
1037 self.to_glib_none_mut().0,
1038 count,
1039 ))
1040 }
1041 }
1042
1043 /// Moves forward to the next visible word end.
1044 ///
1045 /// If @self is currently on a word end, moves forward to the
1046 /// next one after that.
1047 ///
1048 /// Word breaks are determined by Pango and should be correct
1049 /// for nearly any language
1050 ///
1051 /// # Returns
1052 ///
1053 /// [`true`] if @self moved and is not the end iterator
1054 #[doc(alias = "gtk_text_iter_forward_visible_word_end")]
1055 pub fn forward_visible_word_end(&mut self) -> bool {
1056 unsafe {
1057 from_glib(ffi::gtk_text_iter_forward_visible_word_end(
1058 self.to_glib_none_mut().0,
1059 ))
1060 }
1061 }
1062
1063 /// Calls [`forward_visible_word_end()`][Self::forward_visible_word_end()] up to @count times.
1064 /// ## `count`
1065 /// number of times to move
1066 ///
1067 /// # Returns
1068 ///
1069 /// [`true`] if @self moved and is not the end iterator
1070 #[doc(alias = "gtk_text_iter_forward_visible_word_ends")]
1071 pub fn forward_visible_word_ends(&mut self, count: i32) -> bool {
1072 unsafe {
1073 from_glib(ffi::gtk_text_iter_forward_visible_word_ends(
1074 self.to_glib_none_mut().0,
1075 count,
1076 ))
1077 }
1078 }
1079
1080 /// Moves forward to the next word end.
1081 ///
1082 /// If @self is currently on a word end, moves forward to the
1083 /// next one after that.
1084 ///
1085 /// Word breaks are determined by Pango and should be correct
1086 /// for nearly any language.
1087 ///
1088 /// # Returns
1089 ///
1090 /// [`true`] if @self moved and is not the end iterator
1091 #[doc(alias = "gtk_text_iter_forward_word_end")]
1092 pub fn forward_word_end(&mut self) -> bool {
1093 unsafe {
1094 from_glib(ffi::gtk_text_iter_forward_word_end(
1095 self.to_glib_none_mut().0,
1096 ))
1097 }
1098 }
1099
1100 /// Calls [`forward_word_end()`][Self::forward_word_end()] up to @count times.
1101 /// ## `count`
1102 /// number of times to move
1103 ///
1104 /// # Returns
1105 ///
1106 /// [`true`] if @self moved and is not the end iterator
1107 #[doc(alias = "gtk_text_iter_forward_word_ends")]
1108 pub fn forward_word_ends(&mut self, count: i32) -> bool {
1109 unsafe {
1110 from_glib(ffi::gtk_text_iter_forward_word_ends(
1111 self.to_glib_none_mut().0,
1112 count,
1113 ))
1114 }
1115 }
1116
1117 /// Returns the [`TextBuffer`][crate::TextBuffer] this iterator is associated with.
1118 ///
1119 /// # Returns
1120 ///
1121 /// the buffer
1122 #[doc(alias = "gtk_text_iter_get_buffer")]
1123 #[doc(alias = "get_buffer")]
1124 pub fn buffer(&self) -> TextBuffer {
1125 unsafe { from_glib_none(ffi::gtk_text_iter_get_buffer(self.to_glib_none().0)) }
1126 }
1127
1128 /// Returns the number of bytes in the line containing @self,
1129 /// including the paragraph delimiters.
1130 ///
1131 /// # Returns
1132 ///
1133 /// number of bytes in the line
1134 #[doc(alias = "gtk_text_iter_get_bytes_in_line")]
1135 #[doc(alias = "get_bytes_in_line")]
1136 pub fn bytes_in_line(&self) -> i32 {
1137 unsafe { ffi::gtk_text_iter_get_bytes_in_line(self.to_glib_none().0) }
1138 }
1139
1140 /// The Unicode character at this iterator is returned.
1141 ///
1142 /// Equivalent to operator* on a C++ iterator. If the element at
1143 /// this iterator is a non-character element, such as an image
1144 /// embedded in the buffer, the Unicode “unknown” character 0xFFFC
1145 /// is returned. If invoked on the end iterator, zero is returned;
1146 /// zero is not a valid Unicode character.
1147 ///
1148 /// So you can write a loop which ends when this function returns 0.
1149 ///
1150 /// # Returns
1151 ///
1152 /// a Unicode character, or 0 if @self is not dereferenceable
1153 #[doc(alias = "gtk_text_iter_get_char")]
1154 #[doc(alias = "get_char")]
1155 pub fn char(&self) -> char {
1156 unsafe {
1157 std::convert::TryFrom::try_from(ffi::gtk_text_iter_get_char(self.to_glib_none().0))
1158 .expect("conversion from an invalid Unicode value attempted")
1159 }
1160 }
1161
1162 /// Returns the number of characters in the line containing @self,
1163 /// including the paragraph delimiters.
1164 ///
1165 /// # Returns
1166 ///
1167 /// number of characters in the line
1168 #[doc(alias = "gtk_text_iter_get_chars_in_line")]
1169 #[doc(alias = "get_chars_in_line")]
1170 pub fn chars_in_line(&self) -> i32 {
1171 unsafe { ffi::gtk_text_iter_get_chars_in_line(self.to_glib_none().0) }
1172 }
1173
1174 /// If the location at @self contains a child anchor, the
1175 /// anchor is returned.
1176 ///
1177 /// Otherwise, [`None`] is returned.
1178 ///
1179 /// # Returns
1180 ///
1181 /// the anchor at @self
1182 #[doc(alias = "gtk_text_iter_get_child_anchor")]
1183 #[doc(alias = "get_child_anchor")]
1184 pub fn child_anchor(&self) -> Option<TextChildAnchor> {
1185 unsafe { from_glib_none(ffi::gtk_text_iter_get_child_anchor(self.to_glib_none().0)) }
1186 }
1187
1188 /// Returns the language in effect at @self.
1189 ///
1190 /// If no tags affecting language apply to @self, the return
1191 /// value is identical to that of [`default_language()`][crate::default_language()].
1192 ///
1193 /// # Returns
1194 ///
1195 /// language in effect at @self
1196 #[doc(alias = "gtk_text_iter_get_language")]
1197 #[doc(alias = "get_language")]
1198 pub fn language(&self) -> pango::Language {
1199 unsafe { from_glib_full(ffi::gtk_text_iter_get_language(self.to_glib_none().0)) }
1200 }
1201
1202 /// Returns the line number containing the iterator.
1203 ///
1204 /// Lines in a [`TextBuffer`][crate::TextBuffer] are numbered beginning
1205 /// with 0 for the first line in the buffer.
1206 ///
1207 /// # Returns
1208 ///
1209 /// a line number
1210 #[doc(alias = "gtk_text_iter_get_line")]
1211 #[doc(alias = "get_line")]
1212 pub fn line(&self) -> i32 {
1213 unsafe { ffi::gtk_text_iter_get_line(self.to_glib_none().0) }
1214 }
1215
1216 /// Returns the byte index of the iterator, counting
1217 /// from the start of a newline-terminated line.
1218 ///
1219 /// Remember that [`TextBuffer`][crate::TextBuffer] encodes text in
1220 /// UTF-8, and that characters can require a variable
1221 /// number of bytes to represent.
1222 ///
1223 /// # Returns
1224 ///
1225 /// distance from start of line, in bytes
1226 #[doc(alias = "gtk_text_iter_get_line_index")]
1227 #[doc(alias = "get_line_index")]
1228 pub fn line_index(&self) -> i32 {
1229 unsafe { ffi::gtk_text_iter_get_line_index(self.to_glib_none().0) }
1230 }
1231
1232 /// Returns the character offset of the iterator,
1233 /// counting from the start of a newline-terminated line.
1234 ///
1235 /// The first character on the line has offset 0.
1236 ///
1237 /// # Returns
1238 ///
1239 /// offset from start of line
1240 #[doc(alias = "gtk_text_iter_get_line_offset")]
1241 #[doc(alias = "get_line_offset")]
1242 pub fn line_offset(&self) -> i32 {
1243 unsafe { ffi::gtk_text_iter_get_line_offset(self.to_glib_none().0) }
1244 }
1245
1246 /// Returns a list of all [`TextMark`][crate::TextMark] at this location.
1247 ///
1248 /// Because marks are not iterable (they don’t take up any "space"
1249 /// in the buffer, they are just marks in between iterable locations),
1250 /// multiple marks can exist in the same place.
1251 ///
1252 /// The returned list is not in any meaningful order.
1253 ///
1254 /// # Returns
1255 ///
1256 ///
1257 /// list of [`TextMark`][crate::TextMark]
1258 #[doc(alias = "gtk_text_iter_get_marks")]
1259 #[doc(alias = "get_marks")]
1260 pub fn marks(&self) -> Vec<TextMark> {
1261 unsafe {
1262 FromGlibPtrContainer::from_glib_container(ffi::gtk_text_iter_get_marks(
1263 self.to_glib_none().0,
1264 ))
1265 }
1266 }
1267
1268 /// Returns the character offset of an iterator.
1269 ///
1270 /// Each character in a [`TextBuffer`][crate::TextBuffer] has an offset,
1271 /// starting with 0 for the first character in the buffer.
1272 /// Use [`TextBufferExt::iter_at_offset()`][crate::prelude::TextBufferExt::iter_at_offset()] to convert
1273 /// an offset back into an iterator.
1274 ///
1275 /// # Returns
1276 ///
1277 /// a character offset
1278 #[doc(alias = "gtk_text_iter_get_offset")]
1279 #[doc(alias = "get_offset")]
1280 pub fn offset(&self) -> i32 {
1281 unsafe { ffi::gtk_text_iter_get_offset(self.to_glib_none().0) }
1282 }
1283
1284 /// If the element at @self is a paintable, the paintable is returned.
1285 ///
1286 /// Otherwise, [`None`] is returned.
1287 ///
1288 /// # Returns
1289 ///
1290 /// the paintable at @self
1291 #[doc(alias = "gtk_text_iter_get_paintable")]
1292 #[doc(alias = "get_paintable")]
1293 pub fn paintable(&self) -> Option<gdk::Paintable> {
1294 unsafe { from_glib_none(ffi::gtk_text_iter_get_paintable(self.to_glib_none().0)) }
1295 }
1296
1297 /// Returns the text in the given range.
1298 ///
1299 /// A “slice” is an array of characters encoded in UTF-8 format,
1300 /// including the Unicode “unknown” character 0xFFFC for iterable
1301 /// non-character elements in the buffer, such as images.
1302 /// Because images are encoded in the slice, byte and
1303 /// character offsets in the returned array will correspond to byte
1304 /// offsets in the text buffer. Note that 0xFFFC can occur in normal
1305 /// text as well, so it is not a reliable indicator that a paintable or
1306 /// widget is in the buffer.
1307 /// ## `end`
1308 /// iterator at end of a range
1309 ///
1310 /// # Returns
1311 ///
1312 /// slice of text from the buffer
1313 #[doc(alias = "gtk_text_iter_get_slice")]
1314 #[doc(alias = "get_slice")]
1315 pub fn slice(&self, end: &TextIter) -> glib::GString {
1316 unsafe {
1317 from_glib_full(ffi::gtk_text_iter_get_slice(
1318 self.to_glib_none().0,
1319 end.to_glib_none().0,
1320 ))
1321 }
1322 }
1323
1324 /// Returns a list of tags that apply to @self, in ascending order of
1325 /// priority.
1326 ///
1327 /// The highest-priority tags are last.
1328 ///
1329 /// The [`TextTag`][crate::TextTag]s in the list don’t have a reference added,
1330 /// but you have to free the list itself.
1331 ///
1332 /// # Returns
1333 ///
1334 /// list of
1335 /// [`TextTag`][crate::TextTag]
1336 #[doc(alias = "gtk_text_iter_get_tags")]
1337 #[doc(alias = "get_tags")]
1338 pub fn tags(&self) -> Vec<TextTag> {
1339 unsafe {
1340 FromGlibPtrContainer::from_glib_container(ffi::gtk_text_iter_get_tags(
1341 self.to_glib_none().0,
1342 ))
1343 }
1344 }
1345
1346 /// Returns text in the given range.
1347 ///
1348 /// If the range
1349 /// contains non-text elements such as images, the character and byte
1350 /// offsets in the returned string will not correspond to character and
1351 /// byte offsets in the buffer. If you want offsets to correspond, see
1352 /// [`slice()`][Self::slice()].
1353 /// ## `end`
1354 /// iterator at end of a range
1355 ///
1356 /// # Returns
1357 ///
1358 /// array of characters from the buffer
1359 #[doc(alias = "gtk_text_iter_get_text")]
1360 #[doc(alias = "get_text")]
1361 pub fn text(&self, end: &TextIter) -> glib::GString {
1362 unsafe {
1363 from_glib_full(ffi::gtk_text_iter_get_text(
1364 self.to_glib_none().0,
1365 end.to_glib_none().0,
1366 ))
1367 }
1368 }
1369
1370 /// Returns a list of [`TextTag`][crate::TextTag] that are toggled on or off at this
1371 /// point.
1372 ///
1373 /// If @toggled_on is [`true`], the list contains tags that are
1374 /// toggled on. If a tag is toggled on at @self, then some non-empty
1375 /// range of characters following @self has that tag applied to it. If
1376 /// a tag is toggled off, then some non-empty range following @self
1377 /// does not have the tag applied to it.
1378 /// ## `toggled_on`
1379 /// [`true`] to get toggled-on tags
1380 ///
1381 /// # Returns
1382 ///
1383 /// tags
1384 /// toggled at this point
1385 #[doc(alias = "gtk_text_iter_get_toggled_tags")]
1386 #[doc(alias = "get_toggled_tags")]
1387 pub fn toggled_tags(&self, toggled_on: bool) -> Vec<TextTag> {
1388 unsafe {
1389 FromGlibPtrContainer::from_glib_container(ffi::gtk_text_iter_get_toggled_tags(
1390 self.to_glib_none().0,
1391 toggled_on.into_glib(),
1392 ))
1393 }
1394 }
1395
1396 /// Returns the number of bytes from the start of the
1397 /// line to the given @self, not counting bytes that
1398 /// are invisible due to tags with the “invisible” flag
1399 /// toggled on.
1400 ///
1401 /// # Returns
1402 ///
1403 /// byte index of @self with respect to the start of the line
1404 #[doc(alias = "gtk_text_iter_get_visible_line_index")]
1405 #[doc(alias = "get_visible_line_index")]
1406 pub fn visible_line_index(&self) -> i32 {
1407 unsafe { ffi::gtk_text_iter_get_visible_line_index(self.to_glib_none().0) }
1408 }
1409
1410 /// Returns the offset in characters from the start of the
1411 /// line to the given @self, not counting characters that
1412 /// are invisible due to tags with the “invisible” flag
1413 /// toggled on.
1414 ///
1415 /// # Returns
1416 ///
1417 /// offset in visible characters from the start of the line
1418 #[doc(alias = "gtk_text_iter_get_visible_line_offset")]
1419 #[doc(alias = "get_visible_line_offset")]
1420 pub fn visible_line_offset(&self) -> i32 {
1421 unsafe { ffi::gtk_text_iter_get_visible_line_offset(self.to_glib_none().0) }
1422 }
1423
1424 /// Returns visible text in the given range.
1425 ///
1426 /// Like [`slice()`][Self::slice()], but invisible text
1427 /// is not included. Invisible text is usually invisible because
1428 /// a [`TextTag`][crate::TextTag] with the “invisible” attribute turned on has
1429 /// been applied to it.
1430 /// ## `end`
1431 /// iterator at end of range
1432 ///
1433 /// # Returns
1434 ///
1435 /// slice of text from the buffer
1436 #[doc(alias = "gtk_text_iter_get_visible_slice")]
1437 #[doc(alias = "get_visible_slice")]
1438 pub fn visible_slice(&self, end: &TextIter) -> glib::GString {
1439 unsafe {
1440 from_glib_full(ffi::gtk_text_iter_get_visible_slice(
1441 self.to_glib_none().0,
1442 end.to_glib_none().0,
1443 ))
1444 }
1445 }
1446
1447 /// Returns visible text in the given range.
1448 ///
1449 /// Like [`text()`][Self::text()], but invisible text
1450 /// is not included. Invisible text is usually invisible because
1451 /// a [`TextTag`][crate::TextTag] with the “invisible” attribute turned on has
1452 /// been applied to it.
1453 /// ## `end`
1454 /// iterator at end of range
1455 ///
1456 /// # Returns
1457 ///
1458 /// string containing visible text in the
1459 /// range
1460 #[doc(alias = "gtk_text_iter_get_visible_text")]
1461 #[doc(alias = "get_visible_text")]
1462 pub fn visible_text(&self, end: &TextIter) -> glib::GString {
1463 unsafe {
1464 from_glib_full(ffi::gtk_text_iter_get_visible_text(
1465 self.to_glib_none().0,
1466 end.to_glib_none().0,
1467 ))
1468 }
1469 }
1470
1471 /// Returns [`true`] if @self points to a character that is part
1472 /// of a range tagged with @tag.
1473 ///
1474 /// See also [`starts_tag()`][Self::starts_tag()] and
1475 /// [`ends_tag()`][Self::ends_tag()].
1476 /// ## `tag`
1477 /// a [`TextTag`][crate::TextTag]
1478 ///
1479 /// # Returns
1480 ///
1481 /// whether @self is tagged with @tag
1482 #[doc(alias = "gtk_text_iter_has_tag")]
1483 pub fn has_tag(&self, tag: &impl IsA<TextTag>) -> bool {
1484 unsafe {
1485 from_glib(ffi::gtk_text_iter_has_tag(
1486 self.to_glib_none().0,
1487 tag.as_ref().to_glib_none().0,
1488 ))
1489 }
1490 }
1491
1492 /// Checks whether @self falls in the range [@start, @end).
1493 ///
1494 /// @start and @end must be in ascending order.
1495 /// ## `start`
1496 /// start of range
1497 /// ## `end`
1498 /// end of range
1499 ///
1500 /// # Returns
1501 ///
1502 /// [`true`] if @self is in the range
1503 #[doc(alias = "gtk_text_iter_in_range")]
1504 pub fn in_range(&self, start: &TextIter, end: &TextIter) -> bool {
1505 unsafe {
1506 from_glib(ffi::gtk_text_iter_in_range(
1507 self.to_glib_none().0,
1508 start.to_glib_none().0,
1509 end.to_glib_none().0,
1510 ))
1511 }
1512 }
1513
1514 /// Determines whether @self is inside a sentence (as opposed to in
1515 /// between two sentences, e.g. after a period and before the first
1516 /// letter of the next sentence).
1517 ///
1518 /// Sentence boundaries are determined by Pango and should be correct
1519 /// for nearly any language.
1520 ///
1521 /// # Returns
1522 ///
1523 /// [`true`] if @self is inside a sentence.
1524 #[doc(alias = "gtk_text_iter_inside_sentence")]
1525 pub fn inside_sentence(&self) -> bool {
1526 unsafe { from_glib(ffi::gtk_text_iter_inside_sentence(self.to_glib_none().0)) }
1527 }
1528
1529 /// Determines whether the character pointed by @self is part of a
1530 /// natural-language word (as opposed to say inside some whitespace).
1531 ///
1532 /// Word breaks are determined by Pango and should be correct
1533 /// for nearly any language.
1534 ///
1535 /// Note that if [`starts_word()`][Self::starts_word()] returns [`true`],
1536 /// then this function returns [`true`] too, since @self points to
1537 /// the first character of the word.
1538 ///
1539 /// # Returns
1540 ///
1541 /// [`true`] if @self is inside a word
1542 #[doc(alias = "gtk_text_iter_inside_word")]
1543 pub fn inside_word(&self) -> bool {
1544 unsafe { from_glib(ffi::gtk_text_iter_inside_word(self.to_glib_none().0)) }
1545 }
1546
1547 /// Determine if @self is at a cursor position.
1548 ///
1549 /// See [`forward_cursor_position()`][Self::forward_cursor_position()] or
1550 /// `Pango::LogAttr` or `break()` for details
1551 /// on what a cursor position is.
1552 ///
1553 /// # Returns
1554 ///
1555 /// [`true`] if the cursor can be placed at @self
1556 #[doc(alias = "gtk_text_iter_is_cursor_position")]
1557 pub fn is_cursor_position(&self) -> bool {
1558 unsafe { from_glib(ffi::gtk_text_iter_is_cursor_position(self.to_glib_none().0)) }
1559 }
1560
1561 /// Returns [`true`] if @self is the end iterator.
1562 ///
1563 /// This means it is one past the last dereferenceable iterator
1564 /// in the buffer. [`is_end()`][Self::is_end()] is the most efficient
1565 /// way to check whether an iterator is the end iterator.
1566 ///
1567 /// # Returns
1568 ///
1569 /// whether @self is the end iterator
1570 #[doc(alias = "gtk_text_iter_is_end")]
1571 pub fn is_end(&self) -> bool {
1572 unsafe { from_glib(ffi::gtk_text_iter_is_end(self.to_glib_none().0)) }
1573 }
1574
1575 /// Returns [`true`] if @self is the first iterator in the buffer.
1576 ///
1577 /// # Returns
1578 ///
1579 /// whether @self is the first in the buffer
1580 #[doc(alias = "gtk_text_iter_is_start")]
1581 pub fn is_start(&self) -> bool {
1582 unsafe { from_glib(ffi::gtk_text_iter_is_start(self.to_glib_none().0)) }
1583 }
1584
1585 /// Swaps the value of @self and @second if @second comes before
1586 /// @self in the buffer.
1587 ///
1588 /// That is, ensures that @self and @second are in sequence.
1589 /// Most text buffer functions that take a range call this
1590 /// automatically on your behalf, so there’s no real reason to
1591 /// call it yourself in those cases. There are some exceptions,
1592 /// such as [`in_range()`][Self::in_range()], that expect a
1593 /// pre-sorted range.
1594 /// ## `second`
1595 /// another [`TextIter`][crate::TextIter]
1596 #[doc(alias = "gtk_text_iter_order")]
1597 pub fn order(&mut self, second: &mut TextIter) {
1598 unsafe {
1599 ffi::gtk_text_iter_order(self.to_glib_none_mut().0, second.to_glib_none_mut().0);
1600 }
1601 }
1602
1603 /// Moves iterator @self to the start of the line @line_number.
1604 ///
1605 /// If @line_number is negative or larger than or equal to the number of lines
1606 /// in the buffer, moves @self to the start of the last line in the buffer.
1607 /// ## `line_number`
1608 /// line number (counted from 0)
1609 #[doc(alias = "gtk_text_iter_set_line")]
1610 pub fn set_line(&mut self, line_number: i32) {
1611 unsafe {
1612 ffi::gtk_text_iter_set_line(self.to_glib_none_mut().0, line_number);
1613 }
1614 }
1615
1616 /// Same as [`set_line_offset()`][Self::set_line_offset()], but works with a
1617 /// byte index. The given byte index must be at
1618 /// the start of a character, it can’t be in the middle of a UTF-8
1619 /// encoded character.
1620 /// ## `byte_on_line`
1621 /// a byte index relative to the start of @self’s current line
1622 #[doc(alias = "gtk_text_iter_set_line_index")]
1623 pub fn set_line_index(&mut self, byte_on_line: i32) {
1624 unsafe {
1625 ffi::gtk_text_iter_set_line_index(self.to_glib_none_mut().0, byte_on_line);
1626 }
1627 }
1628
1629 /// Moves @self within a line, to a new character (not byte) offset.
1630 ///
1631 /// The given character offset must be less than or equal to the number
1632 /// of characters in the line; if equal, @self moves to the start of the
1633 /// next line. See [`set_line_index()`][Self::set_line_index()] if you have a byte
1634 /// index rather than a character offset.
1635 /// ## `char_on_line`
1636 /// a character offset relative to the start of @self’s current line
1637 #[doc(alias = "gtk_text_iter_set_line_offset")]
1638 pub fn set_line_offset(&mut self, char_on_line: i32) {
1639 unsafe {
1640 ffi::gtk_text_iter_set_line_offset(self.to_glib_none_mut().0, char_on_line);
1641 }
1642 }
1643
1644 /// Sets @self to point to @char_offset.
1645 ///
1646 /// @char_offset counts from the start
1647 /// of the entire text buffer, starting with 0.
1648 /// ## `char_offset`
1649 /// a character number
1650 #[doc(alias = "gtk_text_iter_set_offset")]
1651 pub fn set_offset(&mut self, char_offset: i32) {
1652 unsafe {
1653 ffi::gtk_text_iter_set_offset(self.to_glib_none_mut().0, char_offset);
1654 }
1655 }
1656
1657 /// Like [`set_line_index()`][Self::set_line_index()], but the index is in visible
1658 /// bytes, i.e. text with a tag making it invisible is not counted
1659 /// in the index.
1660 /// ## `byte_on_line`
1661 /// a byte index
1662 #[doc(alias = "gtk_text_iter_set_visible_line_index")]
1663 pub fn set_visible_line_index(&mut self, byte_on_line: i32) {
1664 unsafe {
1665 ffi::gtk_text_iter_set_visible_line_index(self.to_glib_none_mut().0, byte_on_line);
1666 }
1667 }
1668
1669 /// Like [`set_line_offset()`][Self::set_line_offset()], but the offset is in visible
1670 /// characters, i.e. text with a tag making it invisible is not
1671 /// counted in the offset.
1672 /// ## `char_on_line`
1673 /// a character offset
1674 #[doc(alias = "gtk_text_iter_set_visible_line_offset")]
1675 pub fn set_visible_line_offset(&mut self, char_on_line: i32) {
1676 unsafe {
1677 ffi::gtk_text_iter_set_visible_line_offset(self.to_glib_none_mut().0, char_on_line);
1678 }
1679 }
1680
1681 /// Returns [`true`] if @self begins a paragraph.
1682 ///
1683 /// This is the case if [`line_offset()`][Self::line_offset()]
1684 /// would return 0. However this function is potentially more
1685 /// efficient than [`line_offset()`][Self::line_offset()], because
1686 /// it doesn’t have to compute the offset, it just has to see
1687 /// whether it’s 0.
1688 ///
1689 /// # Returns
1690 ///
1691 /// whether @self begins a line
1692 #[doc(alias = "gtk_text_iter_starts_line")]
1693 pub fn starts_line(&self) -> bool {
1694 unsafe { from_glib(ffi::gtk_text_iter_starts_line(self.to_glib_none().0)) }
1695 }
1696
1697 /// Determines whether @self begins a sentence.
1698 ///
1699 /// Sentence boundaries are determined by Pango and
1700 /// should be correct for nearly any language.
1701 ///
1702 /// # Returns
1703 ///
1704 /// [`true`] if @self is at the start of a sentence.
1705 #[doc(alias = "gtk_text_iter_starts_sentence")]
1706 pub fn starts_sentence(&self) -> bool {
1707 unsafe { from_glib(ffi::gtk_text_iter_starts_sentence(self.to_glib_none().0)) }
1708 }
1709
1710 /// Returns [`true`] if @tag is toggled on at exactly this point.
1711 ///
1712 /// If @tag is [`None`], returns [`true`] if any tag is toggled on at this point.
1713 ///
1714 /// Note that if this function returns [`true`], it means that
1715 /// @self is at the beginning of the tagged range, and that the
1716 /// character at @self is inside the tagged range. In other
1717 /// words, unlike [`ends_tag()`][Self::ends_tag()], if
1718 /// this function returns [`true`], [`has_tag()`][Self::has_tag()]
1719 /// will also return [`true`] for the same parameters.
1720 /// ## `tag`
1721 /// a [`TextTag`][crate::TextTag]
1722 ///
1723 /// # Returns
1724 ///
1725 /// whether @self is the start of a range tagged with @tag
1726 #[doc(alias = "gtk_text_iter_starts_tag")]
1727 pub fn starts_tag(&self, tag: Option<&impl IsA<TextTag>>) -> bool {
1728 unsafe {
1729 from_glib(ffi::gtk_text_iter_starts_tag(
1730 self.to_glib_none().0,
1731 tag.map(|p| p.as_ref()).to_glib_none().0,
1732 ))
1733 }
1734 }
1735
1736 /// Determines whether @self begins a natural-language word.
1737 ///
1738 /// Word breaks are determined by Pango and should be correct
1739 /// for nearly any language.
1740 ///
1741 /// # Returns
1742 ///
1743 /// [`true`] if @self is at the start of a word
1744 #[doc(alias = "gtk_text_iter_starts_word")]
1745 pub fn starts_word(&self) -> bool {
1746 unsafe { from_glib(ffi::gtk_text_iter_starts_word(self.to_glib_none().0)) }
1747 }
1748
1749 /// Gets whether a range with @tag applied to it begins
1750 /// or ends at @self.
1751 ///
1752 /// This is equivalent to (gtk_text_iter_starts_tag() ||
1753 /// gtk_text_iter_ends_tag())
1754 /// ## `tag`
1755 /// a [`TextTag`][crate::TextTag]
1756 ///
1757 /// # Returns
1758 ///
1759 /// whether @tag is toggled on or off at @self
1760 #[doc(alias = "gtk_text_iter_toggles_tag")]
1761 pub fn toggles_tag(&self, tag: Option<&impl IsA<TextTag>>) -> bool {
1762 unsafe {
1763 from_glib(ffi::gtk_text_iter_toggles_tag(
1764 self.to_glib_none().0,
1765 tag.map(|p| p.as_ref()).to_glib_none().0,
1766 ))
1767 }
1768 }
1769}
1770
1771impl PartialOrd for TextIter {
1772 #[inline]
1773 fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
1774 Some(self.cmp(other))
1775 }
1776}
1777
1778impl Ord for TextIter {
1779 #[inline]
1780 fn cmp(&self, other: &Self) -> std::cmp::Ordering {
1781 self.compare(other).cmp(&0)
1782 }
1783}
1784
1785impl PartialEq for TextIter {
1786 #[inline]
1787 fn eq(&self, other: &Self) -> bool {
1788 self.equal(other)
1789 }
1790}
1791
1792impl Eq for TextIter {}