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