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