Skip to main content

gtk/auto/
text_buffer.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::{
6    Clipboard, TargetList, TextChildAnchor, TextIter, TextMark, TextTag, TextTagTable, ffi,
7};
8use glib::{
9    object::ObjectType as _,
10    prelude::*,
11    signal::{SignalHandlerId, connect_raw},
12    translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17    /// You may wish to begin by reading the
18    /// [text widget conceptual overview](TextWidget.html)
19    /// which gives an overview of all the objects and data
20    /// types related to the text widget and how they work together.
21    ///
22    /// ## Properties
23    ///
24    ///
25    /// #### `copy-target-list`
26    ///  The list of targets this buffer supports for clipboard copying
27    /// and as DND source.
28    ///
29    /// Readable
30    ///
31    ///
32    /// #### `cursor-position`
33    ///  The position of the insert mark (as offset from the beginning
34    /// of the buffer). It is useful for getting notified when the
35    /// cursor moves.
36    ///
37    /// Readable
38    ///
39    ///
40    /// #### `has-selection`
41    ///  Whether the buffer has some text currently selected.
42    ///
43    /// Readable
44    ///
45    ///
46    /// #### `paste-target-list`
47    ///  The list of targets this buffer supports for clipboard pasting
48    /// and as DND destination.
49    ///
50    /// Readable
51    ///
52    ///
53    /// #### `tag-table`
54    ///  Readable | Writable | Construct Only
55    ///
56    ///
57    /// #### `text`
58    ///  The text content of the buffer. Without child widgets and images,
59    /// see [`TextBufferExt::text()`][crate::prelude::TextBufferExt::text()] for more information.
60    ///
61    /// Readable | Writable
62    ///
63    /// ## Signals
64    ///
65    ///
66    /// #### `apply-tag`
67    ///  The ::apply-tag signal is emitted to apply a tag to a
68    /// range of text in a [`TextBuffer`][crate::TextBuffer].
69    /// Applying actually occurs in the default handler.
70    ///
71    /// Note that if your handler runs before the default handler it must not
72    /// invalidate the `start` and `end` iters (or has to revalidate them).
73    ///
74    /// See also:
75    /// [`TextBufferExt::apply_tag()`][crate::prelude::TextBufferExt::apply_tag()],
76    /// `gtk_text_buffer_insert_with_tags()`,
77    /// [`TextBufferExt::insert_range()`][crate::prelude::TextBufferExt::insert_range()].
78    ///
79    ///
80    ///
81    ///
82    /// #### `begin-user-action`
83    ///  The ::begin-user-action signal is emitted at the beginning of a single
84    /// user-visible operation on a [`TextBuffer`][crate::TextBuffer].
85    ///
86    /// See also:
87    /// [`TextBufferExt::begin_user_action()`][crate::prelude::TextBufferExt::begin_user_action()],
88    /// [`TextBufferExt::insert_interactive()`][crate::prelude::TextBufferExt::insert_interactive()],
89    /// [`TextBufferExt::insert_range_interactive()`][crate::prelude::TextBufferExt::insert_range_interactive()],
90    /// [`TextBufferExt::delete_interactive()`][crate::prelude::TextBufferExt::delete_interactive()],
91    /// [`TextBufferExt::backspace()`][crate::prelude::TextBufferExt::backspace()],
92    /// [`TextBufferExt::delete_selection()`][crate::prelude::TextBufferExt::delete_selection()].
93    ///
94    ///
95    ///
96    ///
97    /// #### `changed`
98    ///  The ::changed signal is emitted when the content of a [`TextBuffer`][crate::TextBuffer]
99    /// has changed.
100    ///
101    ///
102    ///
103    ///
104    /// #### `delete-range`
105    ///  The ::delete-range signal is emitted to delete a range
106    /// from a [`TextBuffer`][crate::TextBuffer].
107    ///
108    /// Note that if your handler runs before the default handler it must not
109    /// invalidate the `start` and `end` iters (or has to revalidate them).
110    /// The default signal handler revalidates the `start` and `end` iters to
111    /// both point to the location where text was deleted. Handlers
112    /// which run after the default handler (see `g_signal_connect_after()`)
113    /// do not have access to the deleted text.
114    ///
115    /// See also: [`TextBufferExt::delete()`][crate::prelude::TextBufferExt::delete()].
116    ///
117    ///
118    ///
119    ///
120    /// #### `end-user-action`
121    ///  The ::end-user-action signal is emitted at the end of a single
122    /// user-visible operation on the [`TextBuffer`][crate::TextBuffer].
123    ///
124    /// See also:
125    /// [`TextBufferExt::end_user_action()`][crate::prelude::TextBufferExt::end_user_action()],
126    /// [`TextBufferExt::insert_interactive()`][crate::prelude::TextBufferExt::insert_interactive()],
127    /// [`TextBufferExt::insert_range_interactive()`][crate::prelude::TextBufferExt::insert_range_interactive()],
128    /// [`TextBufferExt::delete_interactive()`][crate::prelude::TextBufferExt::delete_interactive()],
129    /// [`TextBufferExt::backspace()`][crate::prelude::TextBufferExt::backspace()],
130    /// [`TextBufferExt::delete_selection()`][crate::prelude::TextBufferExt::delete_selection()],
131    /// [`TextBufferExt::backspace()`][crate::prelude::TextBufferExt::backspace()].
132    ///
133    ///
134    ///
135    ///
136    /// #### `insert-child-anchor`
137    ///  The ::insert-child-anchor signal is emitted to insert a
138    /// [`TextChildAnchor`][crate::TextChildAnchor] in a [`TextBuffer`][crate::TextBuffer].
139    /// Insertion actually occurs in the default handler.
140    ///
141    /// Note that if your handler runs before the default handler it must
142    /// not invalidate the `location` iter (or has to revalidate it).
143    /// The default signal handler revalidates it to be placed after the
144    /// inserted `anchor`.
145    ///
146    /// See also: [`TextBufferExt::insert_child_anchor()`][crate::prelude::TextBufferExt::insert_child_anchor()].
147    ///
148    ///
149    ///
150    ///
151    /// #### `insert-pixbuf`
152    ///  The ::insert-pixbuf signal is emitted to insert a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf]
153    /// in a [`TextBuffer`][crate::TextBuffer]. Insertion actually occurs in the default handler.
154    ///
155    /// Note that if your handler runs before the default handler it must not
156    /// invalidate the `location` iter (or has to revalidate it).
157    /// The default signal handler revalidates it to be placed after the
158    /// inserted `pixbuf`.
159    ///
160    /// See also: [`TextBufferExt::insert_pixbuf()`][crate::prelude::TextBufferExt::insert_pixbuf()].
161    ///
162    ///
163    ///
164    ///
165    /// #### `insert-text`
166    ///  The ::insert-text signal is emitted to insert text in a [`TextBuffer`][crate::TextBuffer].
167    /// Insertion actually occurs in the default handler.
168    ///
169    /// Note that if your handler runs before the default handler it must not
170    /// invalidate the `location` iter (or has to revalidate it).
171    /// The default signal handler revalidates it to point to the end of the
172    /// inserted text.
173    ///
174    /// See also:
175    /// [`TextBufferExt::insert()`][crate::prelude::TextBufferExt::insert()],
176    /// [`TextBufferExt::insert_range()`][crate::prelude::TextBufferExt::insert_range()].
177    ///
178    ///
179    ///
180    ///
181    /// #### `mark-deleted`
182    ///  The ::mark-deleted signal is emitted as notification
183    /// after a [`TextMark`][crate::TextMark] is deleted.
184    ///
185    /// See also:
186    /// [`TextBufferExt::delete_mark()`][crate::prelude::TextBufferExt::delete_mark()].
187    ///
188    ///
189    ///
190    ///
191    /// #### `mark-set`
192    ///  The ::mark-set signal is emitted as notification
193    /// after a [`TextMark`][crate::TextMark] is set.
194    ///
195    /// See also:
196    /// [`TextBufferExt::create_mark()`][crate::prelude::TextBufferExt::create_mark()],
197    /// [`TextBufferExt::move_mark()`][crate::prelude::TextBufferExt::move_mark()].
198    ///
199    ///
200    ///
201    ///
202    /// #### `modified-changed`
203    ///  The ::modified-changed signal is emitted when the modified bit of a
204    /// [`TextBuffer`][crate::TextBuffer] flips.
205    ///
206    /// See also:
207    /// [`TextBufferExt::set_modified()`][crate::prelude::TextBufferExt::set_modified()].
208    ///
209    ///
210    ///
211    ///
212    /// #### `paste-done`
213    ///  The paste-done signal is emitted after paste operation has been completed.
214    /// This is useful to properly scroll the view to the end of the pasted text.
215    /// See [`TextBufferExt::paste_clipboard()`][crate::prelude::TextBufferExt::paste_clipboard()] for more details.
216    ///
217    ///
218    ///
219    ///
220    /// #### `remove-tag`
221    ///  The ::remove-tag signal is emitted to remove all occurrences of `tag` from
222    /// a range of text in a [`TextBuffer`][crate::TextBuffer].
223    /// Removal actually occurs in the default handler.
224    ///
225    /// Note that if your handler runs before the default handler it must not
226    /// invalidate the `start` and `end` iters (or has to revalidate them).
227    ///
228    /// See also:
229    /// [`TextBufferExt::remove_tag()`][crate::prelude::TextBufferExt::remove_tag()].
230    ///
231    ///
232    ///
233    /// # Implements
234    ///
235    /// [`TextBufferExt`][trait@crate::prelude::TextBufferExt], [`trait@glib::ObjectExt`], [`TextBufferExtManual`][trait@crate::prelude::TextBufferExtManual]
236    #[doc(alias = "GtkTextBuffer")]
237    pub struct TextBuffer(Object<ffi::GtkTextBuffer, ffi::GtkTextBufferClass>);
238
239    match fn {
240        type_ => || ffi::gtk_text_buffer_get_type(),
241    }
242}
243
244impl TextBuffer {
245    pub const NONE: Option<&'static TextBuffer> = None;
246
247    /// Creates a new text buffer.
248    /// ## `table`
249    /// a tag table, or [`None`] to create a new one
250    ///
251    /// # Returns
252    ///
253    /// a new text buffer
254    #[doc(alias = "gtk_text_buffer_new")]
255    pub fn new(table: Option<&impl IsA<TextTagTable>>) -> TextBuffer {
256        assert_initialized_main_thread!();
257        unsafe {
258            from_glib_full(ffi::gtk_text_buffer_new(
259                table.map(|p| p.as_ref()).to_glib_none().0,
260            ))
261        }
262    }
263
264    // rustdoc-stripper-ignore-next
265    /// Creates a new builder-pattern struct instance to construct [`TextBuffer`] objects.
266    ///
267    /// This method returns an instance of [`TextBufferBuilder`](crate::builders::TextBufferBuilder) which can be used to create [`TextBuffer`] objects.
268    pub fn builder() -> TextBufferBuilder {
269        TextBufferBuilder::new()
270    }
271}
272
273impl Default for TextBuffer {
274    fn default() -> Self {
275        glib::object::Object::new::<Self>()
276    }
277}
278
279// rustdoc-stripper-ignore-next
280/// A [builder-pattern] type to construct [`TextBuffer`] objects.
281///
282/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
283#[must_use = "The builder must be built to be used"]
284pub struct TextBufferBuilder {
285    builder: glib::object::ObjectBuilder<'static, TextBuffer>,
286}
287
288impl TextBufferBuilder {
289    fn new() -> Self {
290        Self {
291            builder: glib::object::Object::builder(),
292        }
293    }
294
295    pub fn tag_table(self, tag_table: &impl IsA<TextTagTable>) -> Self {
296        Self {
297            builder: self
298                .builder
299                .property("tag-table", tag_table.clone().upcast()),
300        }
301    }
302
303    /// The text content of the buffer. Without child widgets and images,
304    /// see [`TextBufferExt::text()`][crate::prelude::TextBufferExt::text()] for more information.
305    pub fn text(self, text: impl Into<glib::GString>) -> Self {
306        Self {
307            builder: self.builder.property("text", text.into()),
308        }
309    }
310
311    // rustdoc-stripper-ignore-next
312    /// Build the [`TextBuffer`].
313    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
314    pub fn build(self) -> TextBuffer {
315        assert_initialized_main_thread!();
316        self.builder.build()
317    }
318}
319
320/// Trait containing all [`struct@TextBuffer`] methods.
321///
322/// # Implementors
323///
324/// [`TextBuffer`][struct@crate::TextBuffer]
325pub trait TextBufferExt: IsA<TextBuffer> + 'static {
326    /// Adds the mark at position `where_`. The mark must not be added to
327    /// another buffer, and if its name is not [`None`] then there must not
328    /// be another mark in the buffer with the same name.
329    ///
330    /// Emits the [`mark-set`][struct@crate::TextBuffer#mark-set] signal as notification of the mark's
331    /// initial placement.
332    /// ## `mark`
333    /// the mark to add
334    /// ## `where_`
335    /// location to place mark
336    #[doc(alias = "gtk_text_buffer_add_mark")]
337    fn add_mark(&self, mark: &impl IsA<TextMark>, where_: &TextIter) {
338        unsafe {
339            ffi::gtk_text_buffer_add_mark(
340                self.as_ref().to_glib_none().0,
341                mark.as_ref().to_glib_none().0,
342                where_.to_glib_none().0,
343            );
344        }
345    }
346
347    /// Adds `clipboard` to the list of clipboards in which the selection
348    /// contents of `self` are available. In most cases, `clipboard` will be
349    /// the [`Clipboard`][crate::Clipboard] of type `GDK_SELECTION_PRIMARY` for a view of `self`.
350    /// ## `clipboard`
351    /// a [`Clipboard`][crate::Clipboard]
352    #[doc(alias = "gtk_text_buffer_add_selection_clipboard")]
353    fn add_selection_clipboard(&self, clipboard: &Clipboard) {
354        unsafe {
355            ffi::gtk_text_buffer_add_selection_clipboard(
356                self.as_ref().to_glib_none().0,
357                clipboard.to_glib_none().0,
358            );
359        }
360    }
361
362    /// Emits the “apply-tag” signal on `self`. The default
363    /// handler for the signal applies `tag` to the given range.
364    /// `start` and `end` do not have to be in order.
365    /// ## `tag`
366    /// a [`TextTag`][crate::TextTag]
367    /// ## `start`
368    /// one bound of range to be tagged
369    /// ## `end`
370    /// other bound of range to be tagged
371    #[doc(alias = "gtk_text_buffer_apply_tag")]
372    fn apply_tag(&self, tag: &impl IsA<TextTag>, start: &TextIter, end: &TextIter) {
373        unsafe {
374            ffi::gtk_text_buffer_apply_tag(
375                self.as_ref().to_glib_none().0,
376                tag.as_ref().to_glib_none().0,
377                start.to_glib_none().0,
378                end.to_glib_none().0,
379            );
380        }
381    }
382
383    /// Calls [`TextTagTableExt::lookup()`][crate::prelude::TextTagTableExt::lookup()] on the buffer’s tag table to
384    /// get a [`TextTag`][crate::TextTag], then calls [`apply_tag()`][Self::apply_tag()].
385    /// ## `name`
386    /// name of a named [`TextTag`][crate::TextTag]
387    /// ## `start`
388    /// one bound of range to be tagged
389    /// ## `end`
390    /// other bound of range to be tagged
391    #[doc(alias = "gtk_text_buffer_apply_tag_by_name")]
392    fn apply_tag_by_name(&self, name: &str, start: &TextIter, end: &TextIter) {
393        unsafe {
394            ffi::gtk_text_buffer_apply_tag_by_name(
395                self.as_ref().to_glib_none().0,
396                name.to_glib_none().0,
397                start.to_glib_none().0,
398                end.to_glib_none().0,
399            );
400        }
401    }
402
403    /// Performs the appropriate action as if the user hit the delete
404    /// key with the cursor at the position specified by `iter`. In the
405    /// normal case a single character will be deleted, but when
406    /// combining accents are involved, more than one character can
407    /// be deleted, and when precomposed character and accent combinations
408    /// are involved, less than one character will be deleted.
409    ///
410    /// Because the buffer is modified, all outstanding iterators become
411    /// invalid after calling this function; however, the `iter` will be
412    /// re-initialized to point to the location where text was deleted.
413    /// ## `iter`
414    /// a position in `self`
415    /// ## `interactive`
416    /// whether the deletion is caused by user interaction
417    /// ## `default_editable`
418    /// whether the buffer is editable by default
419    ///
420    /// # Returns
421    ///
422    /// [`true`] if the buffer was modified
423    #[doc(alias = "gtk_text_buffer_backspace")]
424    fn backspace(&self, iter: &mut TextIter, interactive: bool, default_editable: bool) -> bool {
425        unsafe {
426            from_glib(ffi::gtk_text_buffer_backspace(
427                self.as_ref().to_glib_none().0,
428                iter.to_glib_none_mut().0,
429                interactive.into_glib(),
430                default_editable.into_glib(),
431            ))
432        }
433    }
434
435    /// Called to indicate that the buffer operations between here and a
436    /// call to [`end_user_action()`][Self::end_user_action()] are part of a single
437    /// user-visible operation. The operations between
438    /// [`begin_user_action()`][Self::begin_user_action()] and
439    /// [`end_user_action()`][Self::end_user_action()] can then be grouped when creating
440    /// an undo stack. [`TextBuffer`][crate::TextBuffer] maintains a count of calls to
441    /// [`begin_user_action()`][Self::begin_user_action()] that have not been closed with
442    /// a call to [`end_user_action()`][Self::end_user_action()], and emits the
443    /// “begin-user-action” and “end-user-action” signals only for the
444    /// outermost pair of calls. This allows you to build user actions
445    /// from other user actions.
446    ///
447    /// The “interactive” buffer mutation functions, such as
448    /// [`insert_interactive()`][Self::insert_interactive()], automatically call begin/end
449    /// user action around the buffer operations they perform, so there's
450    /// no need to add extra calls if you user action consists solely of a
451    /// single call to one of those functions.
452    #[doc(alias = "gtk_text_buffer_begin_user_action")]
453    fn begin_user_action(&self) {
454        unsafe {
455            ffi::gtk_text_buffer_begin_user_action(self.as_ref().to_glib_none().0);
456        }
457    }
458
459    /// Copies the currently-selected text to a clipboard.
460    /// ## `clipboard`
461    /// the [`Clipboard`][crate::Clipboard] object to copy to
462    #[doc(alias = "gtk_text_buffer_copy_clipboard")]
463    fn copy_clipboard(&self, clipboard: &Clipboard) {
464        unsafe {
465            ffi::gtk_text_buffer_copy_clipboard(
466                self.as_ref().to_glib_none().0,
467                clipboard.to_glib_none().0,
468            );
469        }
470    }
471
472    /// This is a convenience function which simply creates a child anchor
473    /// with [`TextChildAnchor::new()`][crate::TextChildAnchor::new()] and inserts it into the buffer
474    /// with [`insert_child_anchor()`][Self::insert_child_anchor()]. The new anchor is
475    /// owned by the buffer; no reference count is returned to
476    /// the caller of [`create_child_anchor()`][Self::create_child_anchor()].
477    /// ## `iter`
478    /// location in the buffer
479    ///
480    /// # Returns
481    ///
482    /// the created child anchor
483    #[doc(alias = "gtk_text_buffer_create_child_anchor")]
484    fn create_child_anchor(&self, iter: &mut TextIter) -> Option<TextChildAnchor> {
485        unsafe {
486            from_glib_none(ffi::gtk_text_buffer_create_child_anchor(
487                self.as_ref().to_glib_none().0,
488                iter.to_glib_none_mut().0,
489            ))
490        }
491    }
492
493    /// Creates a mark at position `where_`. If `mark_name` is [`None`], the mark
494    /// is anonymous; otherwise, the mark can be retrieved by name using
495    /// [`mark()`][Self::mark()]. If a mark has left gravity, and text is
496    /// inserted at the mark’s current location, the mark will be moved to
497    /// the left of the newly-inserted text. If the mark has right gravity
498    /// (`left_gravity` = [`false`]), the mark will end up on the right of
499    /// newly-inserted text. The standard left-to-right cursor is a mark
500    /// with right gravity (when you type, the cursor stays on the right
501    /// side of the text you’re typing).
502    ///
503    /// The caller of this function does not own a
504    /// reference to the returned [`TextMark`][crate::TextMark], so you can ignore the
505    /// return value if you like. Marks are owned by the buffer and go
506    /// away when the buffer does.
507    ///
508    /// Emits the [`mark-set`][struct@crate::TextBuffer#mark-set] signal as notification of the mark's
509    /// initial placement.
510    /// ## `mark_name`
511    /// name for mark, or [`None`]
512    /// ## `where_`
513    /// location to place mark
514    /// ## `left_gravity`
515    /// whether the mark has left gravity
516    ///
517    /// # Returns
518    ///
519    /// the new [`TextMark`][crate::TextMark] object
520    #[doc(alias = "gtk_text_buffer_create_mark")]
521    fn create_mark(
522        &self,
523        mark_name: Option<&str>,
524        where_: &TextIter,
525        left_gravity: bool,
526    ) -> Option<TextMark> {
527        unsafe {
528            from_glib_none(ffi::gtk_text_buffer_create_mark(
529                self.as_ref().to_glib_none().0,
530                mark_name.to_glib_none().0,
531                where_.to_glib_none().0,
532                left_gravity.into_glib(),
533            ))
534        }
535    }
536
537    /// Copies the currently-selected text to a clipboard, then deletes
538    /// said text if it’s editable.
539    /// ## `clipboard`
540    /// the [`Clipboard`][crate::Clipboard] object to cut to
541    /// ## `default_editable`
542    /// default editability of the buffer
543    #[doc(alias = "gtk_text_buffer_cut_clipboard")]
544    fn cut_clipboard(&self, clipboard: &Clipboard, default_editable: bool) {
545        unsafe {
546            ffi::gtk_text_buffer_cut_clipboard(
547                self.as_ref().to_glib_none().0,
548                clipboard.to_glib_none().0,
549                default_editable.into_glib(),
550            );
551        }
552    }
553
554    /// Deletes text between `start` and `end`. The order of `start` and `end`
555    /// is not actually relevant; [`delete()`][Self::delete()] will reorder
556    /// them. This function actually emits the “delete-range” signal, and
557    /// the default handler of that signal deletes the text. Because the
558    /// buffer is modified, all outstanding iterators become invalid after
559    /// calling this function; however, the `start` and `end` will be
560    /// re-initialized to point to the location where text was deleted.
561    /// ## `start`
562    /// a position in `self`
563    /// ## `end`
564    /// another position in `self`
565    #[doc(alias = "gtk_text_buffer_delete")]
566    fn delete(&self, start: &mut TextIter, end: &mut TextIter) {
567        unsafe {
568            ffi::gtk_text_buffer_delete(
569                self.as_ref().to_glib_none().0,
570                start.to_glib_none_mut().0,
571                end.to_glib_none_mut().0,
572            );
573        }
574    }
575
576    /// Deletes all editable text in the given range.
577    /// Calls [`delete()`][Self::delete()] for each editable sub-range of
578    /// [`start`,`end`). `start` and `end` are revalidated to point to
579    /// the location of the last deleted range, or left untouched if
580    /// no text was deleted.
581    /// ## `start_iter`
582    /// start of range to delete
583    /// ## `end_iter`
584    /// end of range
585    /// ## `default_editable`
586    /// whether the buffer is editable by default
587    ///
588    /// # Returns
589    ///
590    /// whether some text was actually deleted
591    #[doc(alias = "gtk_text_buffer_delete_interactive")]
592    fn delete_interactive(
593        &self,
594        start_iter: &mut TextIter,
595        end_iter: &mut TextIter,
596        default_editable: bool,
597    ) -> bool {
598        unsafe {
599            from_glib(ffi::gtk_text_buffer_delete_interactive(
600                self.as_ref().to_glib_none().0,
601                start_iter.to_glib_none_mut().0,
602                end_iter.to_glib_none_mut().0,
603                default_editable.into_glib(),
604            ))
605        }
606    }
607
608    /// Deletes `mark`, so that it’s no longer located anywhere in the
609    /// buffer. Removes the reference the buffer holds to the mark, so if
610    /// you haven’t called `g_object_ref()` on the mark, it will be freed. Even
611    /// if the mark isn’t freed, most operations on `mark` become
612    /// invalid, until it gets added to a buffer again with
613    /// [`add_mark()`][Self::add_mark()]. Use [`TextMarkExt::is_deleted()`][crate::prelude::TextMarkExt::is_deleted()] to
614    /// find out if a mark has been removed from its buffer.
615    /// The [`mark-deleted`][struct@crate::TextBuffer#mark-deleted] signal will be emitted as notification after
616    /// the mark is deleted.
617    /// ## `mark`
618    /// a [`TextMark`][crate::TextMark] in `self`
619    #[doc(alias = "gtk_text_buffer_delete_mark")]
620    fn delete_mark(&self, mark: &impl IsA<TextMark>) {
621        unsafe {
622            ffi::gtk_text_buffer_delete_mark(
623                self.as_ref().to_glib_none().0,
624                mark.as_ref().to_glib_none().0,
625            );
626        }
627    }
628
629    /// Deletes the mark named `name`; the mark must exist. See
630    /// [`delete_mark()`][Self::delete_mark()] for details.
631    /// ## `name`
632    /// name of a mark in `self`
633    #[doc(alias = "gtk_text_buffer_delete_mark_by_name")]
634    fn delete_mark_by_name(&self, name: &str) {
635        unsafe {
636            ffi::gtk_text_buffer_delete_mark_by_name(
637                self.as_ref().to_glib_none().0,
638                name.to_glib_none().0,
639            );
640        }
641    }
642
643    /// Deletes the range between the “insert” and “selection_bound” marks,
644    /// that is, the currently-selected text. If `interactive` is [`true`],
645    /// the editability of the selection will be considered (users can’t delete
646    /// uneditable text).
647    /// ## `interactive`
648    /// whether the deletion is caused by user interaction
649    /// ## `default_editable`
650    /// whether the buffer is editable by default
651    ///
652    /// # Returns
653    ///
654    /// whether there was a non-empty selection to delete
655    #[doc(alias = "gtk_text_buffer_delete_selection")]
656    fn delete_selection(&self, interactive: bool, default_editable: bool) -> bool {
657        unsafe {
658            from_glib(ffi::gtk_text_buffer_delete_selection(
659                self.as_ref().to_glib_none().0,
660                interactive.into_glib(),
661                default_editable.into_glib(),
662            ))
663        }
664    }
665
666    /// This function deserializes rich text in format `format` and inserts
667    /// it at `iter`.
668    ///
669    /// `formats` to be used must be registered using
670    /// `gtk_text_buffer_register_deserialize_format()` or
671    /// [`register_deserialize_tagset()`][Self::register_deserialize_tagset()] beforehand.
672    /// ## `content_buffer`
673    /// the [`TextBuffer`][crate::TextBuffer] to deserialize into
674    /// ## `format`
675    /// the rich text format to use for deserializing
676    /// ## `iter`
677    /// insertion point for the deserialized text
678    /// ## `data`
679    /// data to deserialize
680    ///
681    /// # Returns
682    ///
683    /// [`true`] on success, [`false`] otherwise.
684    #[doc(alias = "gtk_text_buffer_deserialize")]
685    fn deserialize(
686        &self,
687        content_buffer: &impl IsA<TextBuffer>,
688        format: &gdk::Atom,
689        iter: &mut TextIter,
690        data: &[u8],
691    ) -> Result<(), glib::Error> {
692        let length = data.len() as _;
693        unsafe {
694            let mut error = std::ptr::null_mut();
695            let is_ok = ffi::gtk_text_buffer_deserialize(
696                self.as_ref().to_glib_none().0,
697                content_buffer.as_ref().to_glib_none().0,
698                format.to_glib_none().0,
699                iter.to_glib_none_mut().0,
700                data.to_glib_none().0,
701                length,
702                &mut error,
703            );
704            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
705            if error.is_null() {
706                Ok(())
707            } else {
708                Err(from_glib_full(error))
709            }
710        }
711    }
712
713    /// This functions returns the value set with
714    /// [`deserialize_set_can_create_tags()`][Self::deserialize_set_can_create_tags()]
715    /// ## `format`
716    /// a [`gdk::Atom`][crate::gdk::Atom] representing a registered rich text format
717    ///
718    /// # Returns
719    ///
720    /// whether deserializing this format may create tags
721    #[doc(alias = "gtk_text_buffer_deserialize_get_can_create_tags")]
722    fn deserialize_get_can_create_tags(&self, format: &gdk::Atom) -> bool {
723        unsafe {
724            from_glib(ffi::gtk_text_buffer_deserialize_get_can_create_tags(
725                self.as_ref().to_glib_none().0,
726                format.to_glib_none().0,
727            ))
728        }
729    }
730
731    /// Use this function to allow a rich text deserialization function to
732    /// create new tags in the receiving buffer. Note that using this
733    /// function is almost always a bad idea, because the rich text
734    /// functions you register should know how to map the rich text format
735    /// they handler to your text buffers set of tags.
736    ///
737    /// The ability of creating new (arbitrary!) tags in the receiving buffer
738    /// is meant for special rich text formats like the internal one that
739    /// is registered using [`register_deserialize_tagset()`][Self::register_deserialize_tagset()],
740    /// because that format is essentially a dump of the internal structure
741    /// of the source buffer, including its tag names.
742    ///
743    /// You should allow creation of tags only if you know what you are
744    /// doing, e.g. if you defined a tagset name for your application
745    /// suite’s text buffers and you know that it’s fine to receive new
746    /// tags from these buffers, because you know that your application can
747    /// handle the newly created tags.
748    /// ## `format`
749    /// a [`gdk::Atom`][crate::gdk::Atom] representing a registered rich text format
750    /// ## `can_create_tags`
751    /// whether deserializing this format may create tags
752    #[doc(alias = "gtk_text_buffer_deserialize_set_can_create_tags")]
753    fn deserialize_set_can_create_tags(&self, format: &gdk::Atom, can_create_tags: bool) {
754        unsafe {
755            ffi::gtk_text_buffer_deserialize_set_can_create_tags(
756                self.as_ref().to_glib_none().0,
757                format.to_glib_none().0,
758                can_create_tags.into_glib(),
759            );
760        }
761    }
762
763    /// Should be paired with a call to [`begin_user_action()`][Self::begin_user_action()].
764    /// See that function for a full explanation.
765    #[doc(alias = "gtk_text_buffer_end_user_action")]
766    fn end_user_action(&self) {
767        unsafe {
768            ffi::gtk_text_buffer_end_user_action(self.as_ref().to_glib_none().0);
769        }
770    }
771
772    /// Retrieves the first and last iterators in the buffer, i.e. the
773    /// entire buffer lies within the range [`start`,`end`).
774    ///
775    /// # Returns
776    ///
777    ///
778    /// ## `start`
779    /// iterator to initialize with first position in the buffer
780    ///
781    /// ## `end`
782    /// iterator to initialize with the end iterator
783    #[doc(alias = "gtk_text_buffer_get_bounds")]
784    #[doc(alias = "get_bounds")]
785    fn bounds(&self) -> (TextIter, TextIter) {
786        unsafe {
787            let mut start = TextIter::uninitialized();
788            let mut end = TextIter::uninitialized();
789            ffi::gtk_text_buffer_get_bounds(
790                self.as_ref().to_glib_none().0,
791                start.to_glib_none_mut().0,
792                end.to_glib_none_mut().0,
793            );
794            (start, end)
795        }
796    }
797
798    /// Gets the number of characters in the buffer; note that characters
799    /// and bytes are not the same, you can’t e.g. expect the contents of
800    /// the buffer in string form to be this many bytes long. The character
801    /// count is cached, so this function is very fast.
802    ///
803    /// # Returns
804    ///
805    /// number of characters in the buffer
806    #[doc(alias = "gtk_text_buffer_get_char_count")]
807    #[doc(alias = "get_char_count")]
808    fn char_count(&self) -> i32 {
809        unsafe { ffi::gtk_text_buffer_get_char_count(self.as_ref().to_glib_none().0) }
810    }
811
812    /// This function returns the list of targets this text buffer can
813    /// provide for copying and as DND source. The targets in the list are
814    /// added with `info` values from the `GtkTextBufferTargetInfo` enum,
815    /// using [`TargetList::add_rich_text_targets()`][crate::TargetList::add_rich_text_targets()] and
816    /// [`TargetList::add_text_targets()`][crate::TargetList::add_text_targets()].
817    ///
818    /// # Returns
819    ///
820    /// the [`TargetList`][crate::TargetList]
821    #[doc(alias = "gtk_text_buffer_get_copy_target_list")]
822    #[doc(alias = "get_copy_target_list")]
823    #[doc(alias = "copy-target-list")]
824    fn copy_target_list(&self) -> Option<TargetList> {
825        unsafe {
826            from_glib_none(ffi::gtk_text_buffer_get_copy_target_list(
827                self.as_ref().to_glib_none().0,
828            ))
829        }
830    }
831
832    /// This function returns the rich text deserialize formats registered
833    /// with `self` using `gtk_text_buffer_register_deserialize_format()` or
834    /// [`register_deserialize_tagset()`][Self::register_deserialize_tagset()]
835    ///
836    /// # Returns
837    ///
838    /// an array of
839    ///  `GdkAtoms` representing the registered formats.
840    #[doc(alias = "gtk_text_buffer_get_deserialize_formats")]
841    #[doc(alias = "get_deserialize_formats")]
842    fn deserialize_formats(&self) -> Vec<gdk::Atom> {
843        unsafe {
844            let mut n_formats = std::mem::MaybeUninit::uninit();
845            let ret = FromGlibContainer::from_glib_container_num(
846                ffi::gtk_text_buffer_get_deserialize_formats(
847                    self.as_ref().to_glib_none().0,
848                    n_formats.as_mut_ptr(),
849                ),
850                n_formats.assume_init() as _,
851            );
852            ret
853        }
854    }
855
856    /// Initializes `iter` with the “end iterator,” one past the last valid
857    /// character in the text buffer. If dereferenced with
858    /// [`TextIter::char()`][crate::TextIter::char()], the end iterator has a character value of 0.
859    /// The entire buffer lies in the range from the first position in
860    /// the buffer (call [`start_iter()`][Self::start_iter()] to get
861    /// character position 0) to the end iterator.
862    ///
863    /// # Returns
864    ///
865    ///
866    /// ## `iter`
867    /// iterator to initialize
868    #[doc(alias = "gtk_text_buffer_get_end_iter")]
869    #[doc(alias = "get_end_iter")]
870    fn end_iter(&self) -> TextIter {
871        unsafe {
872            let mut iter = TextIter::uninitialized();
873            ffi::gtk_text_buffer_get_end_iter(
874                self.as_ref().to_glib_none().0,
875                iter.to_glib_none_mut().0,
876            );
877            iter
878        }
879    }
880
881    /// Indicates whether the buffer has some text currently selected.
882    ///
883    /// # Returns
884    ///
885    /// [`true`] if the there is text selected
886    #[doc(alias = "gtk_text_buffer_get_has_selection")]
887    #[doc(alias = "get_has_selection")]
888    #[doc(alias = "has-selection")]
889    fn has_selection(&self) -> bool {
890        unsafe {
891            from_glib(ffi::gtk_text_buffer_get_has_selection(
892                self.as_ref().to_glib_none().0,
893            ))
894        }
895    }
896
897    /// Returns the mark that represents the cursor (insertion point).
898    /// Equivalent to calling [`mark()`][Self::mark()] to get the mark
899    /// named “insert”, but very slightly more efficient, and involves less
900    /// typing.
901    ///
902    /// # Returns
903    ///
904    /// insertion point mark
905    #[doc(alias = "gtk_text_buffer_get_insert")]
906    fn get_insert(&self) -> Option<TextMark> {
907        unsafe {
908            from_glib_none(ffi::gtk_text_buffer_get_insert(
909                self.as_ref().to_glib_none().0,
910            ))
911        }
912    }
913
914    /// Obtains the location of `anchor` within `self`.
915    /// ## `anchor`
916    /// a child anchor that appears in `self`
917    ///
918    /// # Returns
919    ///
920    ///
921    /// ## `iter`
922    /// an iterator to be initialized
923    #[doc(alias = "gtk_text_buffer_get_iter_at_child_anchor")]
924    #[doc(alias = "get_iter_at_child_anchor")]
925    fn iter_at_child_anchor(&self, anchor: &impl IsA<TextChildAnchor>) -> TextIter {
926        unsafe {
927            let mut iter = TextIter::uninitialized();
928            ffi::gtk_text_buffer_get_iter_at_child_anchor(
929                self.as_ref().to_glib_none().0,
930                iter.to_glib_none_mut().0,
931                anchor.as_ref().to_glib_none().0,
932            );
933            iter
934        }
935    }
936
937    /// Initializes `iter` to the start of the given line. If `line_number` is greater
938    /// than the number of lines in the `self`, the end iterator is returned.
939    /// ## `line_number`
940    /// line number counting from 0
941    ///
942    /// # Returns
943    ///
944    ///
945    /// ## `iter`
946    /// iterator to initialize
947    #[doc(alias = "gtk_text_buffer_get_iter_at_line")]
948    #[doc(alias = "get_iter_at_line")]
949    fn iter_at_line(&self, line_number: i32) -> TextIter {
950        unsafe {
951            let mut iter = TextIter::uninitialized();
952            ffi::gtk_text_buffer_get_iter_at_line(
953                self.as_ref().to_glib_none().0,
954                iter.to_glib_none_mut().0,
955                line_number,
956            );
957            iter
958        }
959    }
960
961    /// Obtains an iterator pointing to `byte_index` within the given line.
962    /// `byte_index` must be the start of a UTF-8 character. Note bytes, not
963    /// characters; UTF-8 may encode one character as multiple bytes.
964    ///
965    /// Before the 3.20 version, it was not allowed to pass an invalid location.
966    ///
967    /// Since the 3.20 version, if `line_number` is greater than the number of lines
968    /// in the `self`, the end iterator is returned. And if `byte_index` is off the
969    /// end of the line, the iterator at the end of the line is returned.
970    /// ## `line_number`
971    /// line number counting from 0
972    /// ## `byte_index`
973    /// byte index from start of line
974    ///
975    /// # Returns
976    ///
977    ///
978    /// ## `iter`
979    /// iterator to initialize
980    #[doc(alias = "gtk_text_buffer_get_iter_at_line_index")]
981    #[doc(alias = "get_iter_at_line_index")]
982    fn iter_at_line_index(&self, line_number: i32, byte_index: i32) -> TextIter {
983        unsafe {
984            let mut iter = TextIter::uninitialized();
985            ffi::gtk_text_buffer_get_iter_at_line_index(
986                self.as_ref().to_glib_none().0,
987                iter.to_glib_none_mut().0,
988                line_number,
989                byte_index,
990            );
991            iter
992        }
993    }
994
995    /// Obtains an iterator pointing to `char_offset` within the given line. Note
996    /// characters, not bytes; UTF-8 may encode one character as multiple bytes.
997    ///
998    /// Before the 3.20 version, it was not allowed to pass an invalid location.
999    ///
1000    /// Since the 3.20 version, if `line_number` is greater than the number of lines
1001    /// in the `self`, the end iterator is returned. And if `char_offset` is off the
1002    /// end of the line, the iterator at the end of the line is returned.
1003    /// ## `line_number`
1004    /// line number counting from 0
1005    /// ## `char_offset`
1006    /// char offset from start of line
1007    ///
1008    /// # Returns
1009    ///
1010    ///
1011    /// ## `iter`
1012    /// iterator to initialize
1013    #[doc(alias = "gtk_text_buffer_get_iter_at_line_offset")]
1014    #[doc(alias = "get_iter_at_line_offset")]
1015    fn iter_at_line_offset(&self, line_number: i32, char_offset: i32) -> TextIter {
1016        unsafe {
1017            let mut iter = TextIter::uninitialized();
1018            ffi::gtk_text_buffer_get_iter_at_line_offset(
1019                self.as_ref().to_glib_none().0,
1020                iter.to_glib_none_mut().0,
1021                line_number,
1022                char_offset,
1023            );
1024            iter
1025        }
1026    }
1027
1028    /// Initializes `iter` with the current position of `mark`.
1029    /// ## `mark`
1030    /// a [`TextMark`][crate::TextMark] in `self`
1031    ///
1032    /// # Returns
1033    ///
1034    ///
1035    /// ## `iter`
1036    /// iterator to initialize
1037    #[doc(alias = "gtk_text_buffer_get_iter_at_mark")]
1038    #[doc(alias = "get_iter_at_mark")]
1039    fn iter_at_mark(&self, mark: &impl IsA<TextMark>) -> TextIter {
1040        unsafe {
1041            let mut iter = TextIter::uninitialized();
1042            ffi::gtk_text_buffer_get_iter_at_mark(
1043                self.as_ref().to_glib_none().0,
1044                iter.to_glib_none_mut().0,
1045                mark.as_ref().to_glib_none().0,
1046            );
1047            iter
1048        }
1049    }
1050
1051    /// Initializes `iter` to a position `char_offset` chars from the start
1052    /// of the entire buffer. If `char_offset` is -1 or greater than the number
1053    /// of characters in the buffer, `iter` is initialized to the end iterator,
1054    /// the iterator one past the last valid character in the buffer.
1055    /// ## `char_offset`
1056    /// char offset from start of buffer, counting from 0, or -1
1057    ///
1058    /// # Returns
1059    ///
1060    ///
1061    /// ## `iter`
1062    /// iterator to initialize
1063    #[doc(alias = "gtk_text_buffer_get_iter_at_offset")]
1064    #[doc(alias = "get_iter_at_offset")]
1065    fn iter_at_offset(&self, char_offset: i32) -> TextIter {
1066        unsafe {
1067            let mut iter = TextIter::uninitialized();
1068            ffi::gtk_text_buffer_get_iter_at_offset(
1069                self.as_ref().to_glib_none().0,
1070                iter.to_glib_none_mut().0,
1071                char_offset,
1072            );
1073            iter
1074        }
1075    }
1076
1077    /// Obtains the number of lines in the buffer. This value is cached, so
1078    /// the function is very fast.
1079    ///
1080    /// # Returns
1081    ///
1082    /// number of lines in the buffer
1083    #[doc(alias = "gtk_text_buffer_get_line_count")]
1084    #[doc(alias = "get_line_count")]
1085    fn line_count(&self) -> i32 {
1086        unsafe { ffi::gtk_text_buffer_get_line_count(self.as_ref().to_glib_none().0) }
1087    }
1088
1089    /// Returns the mark named `name` in buffer `self`, or [`None`] if no such
1090    /// mark exists in the buffer.
1091    /// ## `name`
1092    /// a mark name
1093    ///
1094    /// # Returns
1095    ///
1096    /// a [`TextMark`][crate::TextMark], or [`None`]
1097    #[doc(alias = "gtk_text_buffer_get_mark")]
1098    #[doc(alias = "get_mark")]
1099    fn mark(&self, name: &str) -> Option<TextMark> {
1100        unsafe {
1101            from_glib_none(ffi::gtk_text_buffer_get_mark(
1102                self.as_ref().to_glib_none().0,
1103                name.to_glib_none().0,
1104            ))
1105        }
1106    }
1107
1108    /// Indicates whether the buffer has been modified since the last call
1109    /// to [`set_modified()`][Self::set_modified()] set the modification flag to
1110    /// [`false`]. Used for example to enable a “save” function in a text
1111    /// editor.
1112    ///
1113    /// # Returns
1114    ///
1115    /// [`true`] if the buffer has been modified
1116    #[doc(alias = "gtk_text_buffer_get_modified")]
1117    #[doc(alias = "get_modified")]
1118    fn is_modified(&self) -> bool {
1119        unsafe {
1120            from_glib(ffi::gtk_text_buffer_get_modified(
1121                self.as_ref().to_glib_none().0,
1122            ))
1123        }
1124    }
1125
1126    /// This function returns the list of targets this text buffer supports
1127    /// for pasting and as DND destination. The targets in the list are
1128    /// added with `info` values from the `GtkTextBufferTargetInfo` enum,
1129    /// using [`TargetList::add_rich_text_targets()`][crate::TargetList::add_rich_text_targets()] and
1130    /// [`TargetList::add_text_targets()`][crate::TargetList::add_text_targets()].
1131    ///
1132    /// # Returns
1133    ///
1134    /// the [`TargetList`][crate::TargetList]
1135    #[doc(alias = "gtk_text_buffer_get_paste_target_list")]
1136    #[doc(alias = "get_paste_target_list")]
1137    #[doc(alias = "paste-target-list")]
1138    fn paste_target_list(&self) -> Option<TargetList> {
1139        unsafe {
1140            from_glib_none(ffi::gtk_text_buffer_get_paste_target_list(
1141                self.as_ref().to_glib_none().0,
1142            ))
1143        }
1144    }
1145
1146    /// Returns the mark that represents the selection bound. Equivalent
1147    /// to calling [`mark()`][Self::mark()] to get the mark named
1148    /// “selection_bound”, but very slightly more efficient, and involves
1149    /// less typing.
1150    ///
1151    /// The currently-selected text in `self` is the region between the
1152    /// “selection_bound” and “insert” marks. If “selection_bound” and
1153    /// “insert” are in the same place, then there is no current selection.
1154    /// [`selection_bounds()`][Self::selection_bounds()] is another convenient function
1155    /// for handling the selection, if you just want to know whether there’s a
1156    /// selection and what its bounds are.
1157    ///
1158    /// # Returns
1159    ///
1160    /// selection bound mark
1161    #[doc(alias = "gtk_text_buffer_get_selection_bound")]
1162    #[doc(alias = "get_selection_bound")]
1163    fn selection_bound(&self) -> Option<TextMark> {
1164        unsafe {
1165            from_glib_none(ffi::gtk_text_buffer_get_selection_bound(
1166                self.as_ref().to_glib_none().0,
1167            ))
1168        }
1169    }
1170
1171    /// Returns [`true`] if some text is selected; places the bounds
1172    /// of the selection in `start` and `end` (if the selection has length 0,
1173    /// then `start` and `end` are filled in with the same value).
1174    /// `start` and `end` will be in ascending order. If `start` and `end` are
1175    /// NULL, then they are not filled in, but the return value still indicates
1176    /// whether text is selected.
1177    ///
1178    /// # Returns
1179    ///
1180    /// whether the selection has nonzero length
1181    ///
1182    /// ## `start`
1183    /// iterator to initialize with selection start
1184    ///
1185    /// ## `end`
1186    /// iterator to initialize with selection end
1187    #[doc(alias = "gtk_text_buffer_get_selection_bounds")]
1188    #[doc(alias = "get_selection_bounds")]
1189    fn selection_bounds(&self) -> Option<(TextIter, TextIter)> {
1190        unsafe {
1191            let mut start = TextIter::uninitialized();
1192            let mut end = TextIter::uninitialized();
1193            let ret = from_glib(ffi::gtk_text_buffer_get_selection_bounds(
1194                self.as_ref().to_glib_none().0,
1195                start.to_glib_none_mut().0,
1196                end.to_glib_none_mut().0,
1197            ));
1198            if ret { Some((start, end)) } else { None }
1199        }
1200    }
1201
1202    /// This function returns the rich text serialize formats registered
1203    /// with `self` using `gtk_text_buffer_register_serialize_format()` or
1204    /// [`register_serialize_tagset()`][Self::register_serialize_tagset()]
1205    ///
1206    /// # Returns
1207    ///
1208    /// an array of
1209    ///  `GdkAtoms` representing the registered formats.
1210    #[doc(alias = "gtk_text_buffer_get_serialize_formats")]
1211    #[doc(alias = "get_serialize_formats")]
1212    fn serialize_formats(&self) -> Vec<gdk::Atom> {
1213        unsafe {
1214            let mut n_formats = std::mem::MaybeUninit::uninit();
1215            let ret = FromGlibContainer::from_glib_container_num(
1216                ffi::gtk_text_buffer_get_serialize_formats(
1217                    self.as_ref().to_glib_none().0,
1218                    n_formats.as_mut_ptr(),
1219                ),
1220                n_formats.assume_init() as _,
1221            );
1222            ret
1223        }
1224    }
1225
1226    /// Returns the text in the range [`start`,`end`). Excludes undisplayed
1227    /// text (text marked with tags that set the invisibility attribute) if
1228    /// `include_hidden_chars` is [`false`]. The returned string includes a
1229    /// 0xFFFC character whenever the buffer contains
1230    /// embedded images, so byte and character indexes into
1231    /// the returned string do correspond to byte
1232    /// and character indexes into the buffer. Contrast with
1233    /// [`text()`][Self::text()]. Note that 0xFFFC can occur in normal
1234    /// text as well, so it is not a reliable indicator that a pixbuf or
1235    /// widget is in the buffer.
1236    /// ## `start`
1237    /// start of a range
1238    /// ## `end`
1239    /// end of a range
1240    /// ## `include_hidden_chars`
1241    /// whether to include invisible text
1242    ///
1243    /// # Returns
1244    ///
1245    /// an allocated UTF-8 string
1246    #[doc(alias = "gtk_text_buffer_get_slice")]
1247    #[doc(alias = "get_slice")]
1248    fn slice(
1249        &self,
1250        start: &TextIter,
1251        end: &TextIter,
1252        include_hidden_chars: bool,
1253    ) -> Option<glib::GString> {
1254        unsafe {
1255            from_glib_full(ffi::gtk_text_buffer_get_slice(
1256                self.as_ref().to_glib_none().0,
1257                start.to_glib_none().0,
1258                end.to_glib_none().0,
1259                include_hidden_chars.into_glib(),
1260            ))
1261        }
1262    }
1263
1264    /// Initialized `iter` with the first position in the text buffer. This
1265    /// is the same as using [`iter_at_offset()`][Self::iter_at_offset()] to get
1266    /// the iter at character offset 0.
1267    ///
1268    /// # Returns
1269    ///
1270    ///
1271    /// ## `iter`
1272    /// iterator to initialize
1273    #[doc(alias = "gtk_text_buffer_get_start_iter")]
1274    #[doc(alias = "get_start_iter")]
1275    fn start_iter(&self) -> TextIter {
1276        unsafe {
1277            let mut iter = TextIter::uninitialized();
1278            ffi::gtk_text_buffer_get_start_iter(
1279                self.as_ref().to_glib_none().0,
1280                iter.to_glib_none_mut().0,
1281            );
1282            iter
1283        }
1284    }
1285
1286    /// Get the [`TextTagTable`][crate::TextTagTable] associated with this buffer.
1287    ///
1288    /// # Returns
1289    ///
1290    /// the buffer’s tag table
1291    #[doc(alias = "gtk_text_buffer_get_tag_table")]
1292    #[doc(alias = "get_tag_table")]
1293    #[doc(alias = "tag-table")]
1294    fn tag_table(&self) -> Option<TextTagTable> {
1295        unsafe {
1296            from_glib_none(ffi::gtk_text_buffer_get_tag_table(
1297                self.as_ref().to_glib_none().0,
1298            ))
1299        }
1300    }
1301
1302    /// Returns the text in the range [`start`,`end`). Excludes undisplayed
1303    /// text (text marked with tags that set the invisibility attribute) if
1304    /// `include_hidden_chars` is [`false`]. Does not include characters
1305    /// representing embedded images, so byte and character indexes into
1306    /// the returned string do not correspond to byte
1307    /// and character indexes into the buffer. Contrast with
1308    /// [`slice()`][Self::slice()].
1309    /// ## `start`
1310    /// start of a range
1311    /// ## `end`
1312    /// end of a range
1313    /// ## `include_hidden_chars`
1314    /// whether to include invisible text
1315    ///
1316    /// # Returns
1317    ///
1318    /// an allocated UTF-8 string
1319    #[doc(alias = "gtk_text_buffer_get_text")]
1320    #[doc(alias = "get_text")]
1321    fn text(
1322        &self,
1323        start: &TextIter,
1324        end: &TextIter,
1325        include_hidden_chars: bool,
1326    ) -> Option<glib::GString> {
1327        unsafe {
1328            from_glib_full(ffi::gtk_text_buffer_get_text(
1329                self.as_ref().to_glib_none().0,
1330                start.to_glib_none().0,
1331                end.to_glib_none().0,
1332                include_hidden_chars.into_glib(),
1333            ))
1334        }
1335    }
1336
1337    /// Inserts `len` bytes of `text` at position `iter`. If `len` is -1,
1338    /// `text` must be nul-terminated and will be inserted in its
1339    /// entirety. Emits the “insert-text” signal; insertion actually occurs
1340    /// in the default handler for the signal. `iter` is invalidated when
1341    /// insertion occurs (because the buffer contents change), but the
1342    /// default signal handler revalidates it to point to the end of the
1343    /// inserted text.
1344    /// ## `iter`
1345    /// a position in the buffer
1346    /// ## `text`
1347    /// text in UTF-8 format
1348    /// ## `len`
1349    /// length of text in bytes, or -1
1350    #[doc(alias = "gtk_text_buffer_insert")]
1351    fn insert(&self, iter: &mut TextIter, text: &str) {
1352        let len = text.len() as _;
1353        unsafe {
1354            ffi::gtk_text_buffer_insert(
1355                self.as_ref().to_glib_none().0,
1356                iter.to_glib_none_mut().0,
1357                text.to_glib_none().0,
1358                len,
1359            );
1360        }
1361    }
1362
1363    /// Simply calls [`insert()`][Self::insert()], using the current
1364    /// cursor position as the insertion point.
1365    /// ## `text`
1366    /// text in UTF-8 format
1367    /// ## `len`
1368    /// length of text, in bytes
1369    #[doc(alias = "gtk_text_buffer_insert_at_cursor")]
1370    fn insert_at_cursor(&self, text: &str) {
1371        let len = text.len() as _;
1372        unsafe {
1373            ffi::gtk_text_buffer_insert_at_cursor(
1374                self.as_ref().to_glib_none().0,
1375                text.to_glib_none().0,
1376                len,
1377            );
1378        }
1379    }
1380
1381    /// Inserts a child widget anchor into the text buffer at `iter`. The
1382    /// anchor will be counted as one character in character counts, and
1383    /// when obtaining the buffer contents as a string, will be represented
1384    /// by the Unicode “object replacement character” 0xFFFC. Note that the
1385    /// “slice” variants for obtaining portions of the buffer as a string
1386    /// include this character for child anchors, but the “text” variants do
1387    /// not. E.g. see [`slice()`][Self::slice()] and
1388    /// [`text()`][Self::text()]. Consider
1389    /// [`create_child_anchor()`][Self::create_child_anchor()] as a more convenient
1390    /// alternative to this function. The buffer will add a reference to
1391    /// the anchor, so you can unref it after insertion.
1392    /// ## `iter`
1393    /// location to insert the anchor
1394    /// ## `anchor`
1395    /// a [`TextChildAnchor`][crate::TextChildAnchor]
1396    #[doc(alias = "gtk_text_buffer_insert_child_anchor")]
1397    fn insert_child_anchor(&self, iter: &mut TextIter, anchor: &impl IsA<TextChildAnchor>) {
1398        unsafe {
1399            ffi::gtk_text_buffer_insert_child_anchor(
1400                self.as_ref().to_glib_none().0,
1401                iter.to_glib_none_mut().0,
1402                anchor.as_ref().to_glib_none().0,
1403            );
1404        }
1405    }
1406
1407    /// Like [`insert()`][Self::insert()], but the insertion will not occur if
1408    /// `iter` is at a non-editable location in the buffer. Usually you
1409    /// want to prevent insertions at ineditable locations if the insertion
1410    /// results from a user action (is interactive).
1411    ///
1412    /// `default_editable` indicates the editability of text that doesn't
1413    /// have a tag affecting editability applied to it. Typically the
1414    /// result of [`TextViewExt::is_editable()`][crate::prelude::TextViewExt::is_editable()] is appropriate here.
1415    /// ## `iter`
1416    /// a position in `self`
1417    /// ## `text`
1418    /// some UTF-8 text
1419    /// ## `len`
1420    /// length of text in bytes, or -1
1421    /// ## `default_editable`
1422    /// default editability of buffer
1423    ///
1424    /// # Returns
1425    ///
1426    /// whether text was actually inserted
1427    #[doc(alias = "gtk_text_buffer_insert_interactive")]
1428    fn insert_interactive(&self, iter: &mut TextIter, text: &str, default_editable: bool) -> bool {
1429        let len = text.len() as _;
1430        unsafe {
1431            from_glib(ffi::gtk_text_buffer_insert_interactive(
1432                self.as_ref().to_glib_none().0,
1433                iter.to_glib_none_mut().0,
1434                text.to_glib_none().0,
1435                len,
1436                default_editable.into_glib(),
1437            ))
1438        }
1439    }
1440
1441    /// Calls [`insert_interactive()`][Self::insert_interactive()] at the cursor
1442    /// position.
1443    ///
1444    /// `default_editable` indicates the editability of text that doesn't
1445    /// have a tag affecting editability applied to it. Typically the
1446    /// result of [`TextViewExt::is_editable()`][crate::prelude::TextViewExt::is_editable()] is appropriate here.
1447    /// ## `text`
1448    /// text in UTF-8 format
1449    /// ## `len`
1450    /// length of text in bytes, or -1
1451    /// ## `default_editable`
1452    /// default editability of buffer
1453    ///
1454    /// # Returns
1455    ///
1456    /// whether text was actually inserted
1457    #[doc(alias = "gtk_text_buffer_insert_interactive_at_cursor")]
1458    fn insert_interactive_at_cursor(&self, text: &str, default_editable: bool) -> bool {
1459        let len = text.len() as _;
1460        unsafe {
1461            from_glib(ffi::gtk_text_buffer_insert_interactive_at_cursor(
1462                self.as_ref().to_glib_none().0,
1463                text.to_glib_none().0,
1464                len,
1465                default_editable.into_glib(),
1466            ))
1467        }
1468    }
1469
1470    /// Inserts the text in `markup` at position `iter`. `markup` will be inserted
1471    /// in its entirety and must be nul-terminated and valid UTF-8. Emits the
1472    /// [`insert-text`][struct@crate::TextBuffer#insert-text] signal, possibly multiple times; insertion
1473    /// actually occurs in the default handler for the signal. `iter` will point
1474    /// to the end of the inserted text on return.
1475    /// ## `iter`
1476    /// location to insert the markup
1477    /// ## `markup`
1478    /// a nul-terminated UTF-8 string containing [Pango markup][PangoMarkupFormat]
1479    /// ## `len`
1480    /// length of `markup` in bytes, or -1
1481    #[doc(alias = "gtk_text_buffer_insert_markup")]
1482    fn insert_markup(&self, iter: &mut TextIter, markup: &str) {
1483        let len = markup.len() as _;
1484        unsafe {
1485            ffi::gtk_text_buffer_insert_markup(
1486                self.as_ref().to_glib_none().0,
1487                iter.to_glib_none_mut().0,
1488                markup.to_glib_none().0,
1489                len,
1490            );
1491        }
1492    }
1493
1494    /// Inserts an image into the text buffer at `iter`. The image will be
1495    /// counted as one character in character counts, and when obtaining
1496    /// the buffer contents as a string, will be represented by the Unicode
1497    /// “object replacement character” 0xFFFC. Note that the “slice”
1498    /// variants for obtaining portions of the buffer as a string include
1499    /// this character for pixbufs, but the “text” variants do
1500    /// not. e.g. see [`slice()`][Self::slice()] and
1501    /// [`text()`][Self::text()].
1502    /// ## `iter`
1503    /// location to insert the pixbuf
1504    /// ## `pixbuf`
1505    /// a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf]
1506    #[doc(alias = "gtk_text_buffer_insert_pixbuf")]
1507    fn insert_pixbuf(&self, iter: &mut TextIter, pixbuf: &gdk_pixbuf::Pixbuf) {
1508        unsafe {
1509            ffi::gtk_text_buffer_insert_pixbuf(
1510                self.as_ref().to_glib_none().0,
1511                iter.to_glib_none_mut().0,
1512                pixbuf.to_glib_none().0,
1513            );
1514        }
1515    }
1516
1517    /// Copies text, tags, and pixbufs between `start` and `end` (the order
1518    /// of `start` and `end` doesn’t matter) and inserts the copy at `iter`.
1519    /// Used instead of simply getting/inserting text because it preserves
1520    /// images and tags. If `start` and `end` are in a different buffer from
1521    /// `self`, the two buffers must share the same tag table.
1522    ///
1523    /// Implemented via emissions of the insert_text and apply_tag signals,
1524    /// so expect those.
1525    /// ## `iter`
1526    /// a position in `self`
1527    /// ## `start`
1528    /// a position in a [`TextBuffer`][crate::TextBuffer]
1529    /// ## `end`
1530    /// another position in the same buffer as `start`
1531    #[doc(alias = "gtk_text_buffer_insert_range")]
1532    fn insert_range(&self, iter: &mut TextIter, start: &TextIter, end: &TextIter) {
1533        unsafe {
1534            ffi::gtk_text_buffer_insert_range(
1535                self.as_ref().to_glib_none().0,
1536                iter.to_glib_none_mut().0,
1537                start.to_glib_none().0,
1538                end.to_glib_none().0,
1539            );
1540        }
1541    }
1542
1543    /// Same as [`insert_range()`][Self::insert_range()], but does nothing if the
1544    /// insertion point isn’t editable. The `default_editable` parameter
1545    /// indicates whether the text is editable at `iter` if no tags
1546    /// enclosing `iter` affect editability. Typically the result of
1547    /// [`TextViewExt::is_editable()`][crate::prelude::TextViewExt::is_editable()] is appropriate here.
1548    /// ## `iter`
1549    /// a position in `self`
1550    /// ## `start`
1551    /// a position in a [`TextBuffer`][crate::TextBuffer]
1552    /// ## `end`
1553    /// another position in the same buffer as `start`
1554    /// ## `default_editable`
1555    /// default editability of the buffer
1556    ///
1557    /// # Returns
1558    ///
1559    /// whether an insertion was possible at `iter`
1560    #[doc(alias = "gtk_text_buffer_insert_range_interactive")]
1561    fn insert_range_interactive(
1562        &self,
1563        iter: &mut TextIter,
1564        start: &TextIter,
1565        end: &TextIter,
1566        default_editable: bool,
1567    ) -> bool {
1568        unsafe {
1569            from_glib(ffi::gtk_text_buffer_insert_range_interactive(
1570                self.as_ref().to_glib_none().0,
1571                iter.to_glib_none_mut().0,
1572                start.to_glib_none().0,
1573                end.to_glib_none().0,
1574                default_editable.into_glib(),
1575            ))
1576        }
1577    }
1578
1579    //#[doc(alias = "gtk_text_buffer_insert_with_tags_by_name")]
1580    //fn insert_with_tags_by_name(&self, iter: &mut TextIter, text: &str, first_tag_name: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
1581    //    unsafe { TODO: call ffi:gtk_text_buffer_insert_with_tags_by_name() }
1582    //}
1583
1584    /// Moves `mark` to the new location `where_`. Emits the [`mark-set`][struct@crate::TextBuffer#mark-set]
1585    /// signal as notification of the move.
1586    /// ## `mark`
1587    /// a [`TextMark`][crate::TextMark]
1588    /// ## `where_`
1589    /// new location for `mark` in `self`
1590    #[doc(alias = "gtk_text_buffer_move_mark")]
1591    fn move_mark(&self, mark: &impl IsA<TextMark>, where_: &TextIter) {
1592        unsafe {
1593            ffi::gtk_text_buffer_move_mark(
1594                self.as_ref().to_glib_none().0,
1595                mark.as_ref().to_glib_none().0,
1596                where_.to_glib_none().0,
1597            );
1598        }
1599    }
1600
1601    /// Moves the mark named `name` (which must exist) to location `where_`.
1602    /// See [`move_mark()`][Self::move_mark()] for details.
1603    /// ## `name`
1604    /// name of a mark
1605    /// ## `where_`
1606    /// new location for mark
1607    #[doc(alias = "gtk_text_buffer_move_mark_by_name")]
1608    fn move_mark_by_name(&self, name: &str, where_: &TextIter) {
1609        unsafe {
1610            ffi::gtk_text_buffer_move_mark_by_name(
1611                self.as_ref().to_glib_none().0,
1612                name.to_glib_none().0,
1613                where_.to_glib_none().0,
1614            );
1615        }
1616    }
1617
1618    /// Pastes the contents of a clipboard. If `override_location` is [`None`], the
1619    /// pasted text will be inserted at the cursor position, or the buffer selection
1620    /// will be replaced if the selection is non-empty.
1621    ///
1622    /// Note: pasting is asynchronous, that is, we’ll ask for the paste data and
1623    /// return, and at some point later after the main loop runs, the paste data will
1624    /// be inserted.
1625    /// ## `clipboard`
1626    /// the [`Clipboard`][crate::Clipboard] to paste from
1627    /// ## `override_location`
1628    /// location to insert pasted text, or [`None`]
1629    /// ## `default_editable`
1630    /// whether the buffer is editable by default
1631    #[doc(alias = "gtk_text_buffer_paste_clipboard")]
1632    fn paste_clipboard(
1633        &self,
1634        clipboard: &Clipboard,
1635        override_location: Option<&TextIter>,
1636        default_editable: bool,
1637    ) {
1638        unsafe {
1639            ffi::gtk_text_buffer_paste_clipboard(
1640                self.as_ref().to_glib_none().0,
1641                clipboard.to_glib_none().0,
1642                mut_override(override_location.to_glib_none().0),
1643                default_editable.into_glib(),
1644            );
1645        }
1646    }
1647
1648    /// This function moves the “insert” and “selection_bound” marks
1649    /// simultaneously. If you move them to the same place in two steps
1650    /// with [`move_mark()`][Self::move_mark()], you will temporarily select a
1651    /// region in between their old and new locations, which can be pretty
1652    /// inefficient since the temporarily-selected region will force stuff
1653    /// to be recalculated. This function moves them as a unit, which can
1654    /// be optimized.
1655    /// ## `where_`
1656    /// where to put the cursor
1657    #[doc(alias = "gtk_text_buffer_place_cursor")]
1658    fn place_cursor(&self, where_: &TextIter) {
1659        unsafe {
1660            ffi::gtk_text_buffer_place_cursor(
1661                self.as_ref().to_glib_none().0,
1662                where_.to_glib_none().0,
1663            );
1664        }
1665    }
1666
1667    /// This function registers GTK+’s internal rich text serialization
1668    /// format with the passed `self`. See
1669    /// [`register_serialize_tagset()`][Self::register_serialize_tagset()] for details.
1670    /// ## `tagset_name`
1671    /// an optional tagset name, on [`None`]
1672    ///
1673    /// # Returns
1674    ///
1675    /// the [`gdk::Atom`][crate::gdk::Atom] that corresponds to the
1676    ///  newly registered format’s mime-type.
1677    #[doc(alias = "gtk_text_buffer_register_deserialize_tagset")]
1678    fn register_deserialize_tagset(&self, tagset_name: Option<&str>) -> gdk::Atom {
1679        unsafe {
1680            from_glib_none(ffi::gtk_text_buffer_register_deserialize_tagset(
1681                self.as_ref().to_glib_none().0,
1682                tagset_name.to_glib_none().0,
1683            ))
1684        }
1685    }
1686
1687    /// This function registers GTK+’s internal rich text serialization
1688    /// format with the passed `self`. The internal format does not comply
1689    /// to any standard rich text format and only works between [`TextBuffer`][crate::TextBuffer]
1690    /// instances. It is capable of serializing all of a text buffer’s tags
1691    /// and embedded pixbufs.
1692    ///
1693    /// This function is just a wrapper around
1694    /// `gtk_text_buffer_register_serialize_format()`. The mime type used
1695    /// for registering is “application/x-gtk-text-buffer-rich-text”, or
1696    /// “application/x-gtk-text-buffer-rich-text;format=`tagset_name`” if a
1697    /// `tagset_name` was passed.
1698    ///
1699    /// The `tagset_name` can be used to restrict the transfer of rich text
1700    /// to buffers with compatible sets of tags, in order to avoid unknown
1701    /// tags from being pasted. It is probably the common case to pass an
1702    /// identifier != [`None`] here, since the [`None`] tagset requires the
1703    /// receiving buffer to deal with with pasting of arbitrary tags.
1704    /// ## `tagset_name`
1705    /// an optional tagset name, on [`None`]
1706    ///
1707    /// # Returns
1708    ///
1709    /// the [`gdk::Atom`][crate::gdk::Atom] that corresponds to the
1710    ///  newly registered format’s mime-type.
1711    #[doc(alias = "gtk_text_buffer_register_serialize_tagset")]
1712    fn register_serialize_tagset(&self, tagset_name: Option<&str>) -> gdk::Atom {
1713        unsafe {
1714            from_glib_none(ffi::gtk_text_buffer_register_serialize_tagset(
1715                self.as_ref().to_glib_none().0,
1716                tagset_name.to_glib_none().0,
1717            ))
1718        }
1719    }
1720
1721    /// Removes all tags in the range between `start` and `end`. Be careful
1722    /// with this function; it could remove tags added in code unrelated to
1723    /// the code you’re currently writing. That is, using this function is
1724    /// probably a bad idea if you have two or more unrelated code sections
1725    /// that add tags.
1726    /// ## `start`
1727    /// one bound of range to be untagged
1728    /// ## `end`
1729    /// other bound of range to be untagged
1730    #[doc(alias = "gtk_text_buffer_remove_all_tags")]
1731    fn remove_all_tags(&self, start: &TextIter, end: &TextIter) {
1732        unsafe {
1733            ffi::gtk_text_buffer_remove_all_tags(
1734                self.as_ref().to_glib_none().0,
1735                start.to_glib_none().0,
1736                end.to_glib_none().0,
1737            );
1738        }
1739    }
1740
1741    /// Removes a [`Clipboard`][crate::Clipboard] added with
1742    /// [`add_selection_clipboard()`][Self::add_selection_clipboard()].
1743    /// ## `clipboard`
1744    /// a [`Clipboard`][crate::Clipboard] added to `self` by
1745    ///  [`add_selection_clipboard()`][Self::add_selection_clipboard()]
1746    #[doc(alias = "gtk_text_buffer_remove_selection_clipboard")]
1747    fn remove_selection_clipboard(&self, clipboard: &Clipboard) {
1748        unsafe {
1749            ffi::gtk_text_buffer_remove_selection_clipboard(
1750                self.as_ref().to_glib_none().0,
1751                clipboard.to_glib_none().0,
1752            );
1753        }
1754    }
1755
1756    /// Emits the “remove-tag” signal. The default handler for the signal
1757    /// removes all occurrences of `tag` from the given range. `start` and
1758    /// `end` don’t have to be in order.
1759    /// ## `tag`
1760    /// a [`TextTag`][crate::TextTag]
1761    /// ## `start`
1762    /// one bound of range to be untagged
1763    /// ## `end`
1764    /// other bound of range to be untagged
1765    #[doc(alias = "gtk_text_buffer_remove_tag")]
1766    fn remove_tag(&self, tag: &impl IsA<TextTag>, start: &TextIter, end: &TextIter) {
1767        unsafe {
1768            ffi::gtk_text_buffer_remove_tag(
1769                self.as_ref().to_glib_none().0,
1770                tag.as_ref().to_glib_none().0,
1771                start.to_glib_none().0,
1772                end.to_glib_none().0,
1773            );
1774        }
1775    }
1776
1777    /// Calls [`TextTagTableExt::lookup()`][crate::prelude::TextTagTableExt::lookup()] on the buffer’s tag table to
1778    /// get a [`TextTag`][crate::TextTag], then calls [`remove_tag()`][Self::remove_tag()].
1779    /// ## `name`
1780    /// name of a [`TextTag`][crate::TextTag]
1781    /// ## `start`
1782    /// one bound of range to be untagged
1783    /// ## `end`
1784    /// other bound of range to be untagged
1785    #[doc(alias = "gtk_text_buffer_remove_tag_by_name")]
1786    fn remove_tag_by_name(&self, name: &str, start: &TextIter, end: &TextIter) {
1787        unsafe {
1788            ffi::gtk_text_buffer_remove_tag_by_name(
1789                self.as_ref().to_glib_none().0,
1790                name.to_glib_none().0,
1791                start.to_glib_none().0,
1792                end.to_glib_none().0,
1793            );
1794        }
1795    }
1796
1797    /// This function moves the “insert” and “selection_bound” marks
1798    /// simultaneously. If you move them in two steps
1799    /// with [`move_mark()`][Self::move_mark()], you will temporarily select a
1800    /// region in between their old and new locations, which can be pretty
1801    /// inefficient since the temporarily-selected region will force stuff
1802    /// to be recalculated. This function moves them as a unit, which can
1803    /// be optimized.
1804    /// ## `ins`
1805    /// where to put the “insert” mark
1806    /// ## `bound`
1807    /// where to put the “selection_bound” mark
1808    #[doc(alias = "gtk_text_buffer_select_range")]
1809    fn select_range(&self, ins: &TextIter, bound: &TextIter) {
1810        unsafe {
1811            ffi::gtk_text_buffer_select_range(
1812                self.as_ref().to_glib_none().0,
1813                ins.to_glib_none().0,
1814                bound.to_glib_none().0,
1815            );
1816        }
1817    }
1818
1819    /// This function serializes the portion of text between `start`
1820    /// and `end` in the rich text format represented by `format`.
1821    ///
1822    /// `formats` to be used must be registered using
1823    /// `gtk_text_buffer_register_serialize_format()` or
1824    /// [`register_serialize_tagset()`][Self::register_serialize_tagset()] beforehand.
1825    /// ## `content_buffer`
1826    /// the [`TextBuffer`][crate::TextBuffer] to serialize
1827    /// ## `format`
1828    /// the rich text format to use for serializing
1829    /// ## `start`
1830    /// start of block of text to serialize
1831    /// ## `end`
1832    /// end of block of test to serialize
1833    ///
1834    /// # Returns
1835    ///
1836    /// the serialized
1837    ///  data, encoded as `format`
1838    #[doc(alias = "gtk_text_buffer_serialize")]
1839    fn serialize(
1840        &self,
1841        content_buffer: &impl IsA<TextBuffer>,
1842        format: &gdk::Atom,
1843        start: &TextIter,
1844        end: &TextIter,
1845    ) -> Vec<u8> {
1846        unsafe {
1847            let mut length = std::mem::MaybeUninit::uninit();
1848            let ret = FromGlibContainer::from_glib_full_num(
1849                ffi::gtk_text_buffer_serialize(
1850                    self.as_ref().to_glib_none().0,
1851                    content_buffer.as_ref().to_glib_none().0,
1852                    format.to_glib_none().0,
1853                    start.to_glib_none().0,
1854                    end.to_glib_none().0,
1855                    length.as_mut_ptr(),
1856                ),
1857                length.assume_init() as _,
1858            );
1859            ret
1860        }
1861    }
1862
1863    /// Used to keep track of whether the buffer has been modified since the
1864    /// last time it was saved. Whenever the buffer is saved to disk, call
1865    /// gtk_text_buffer_set_modified (`self`, FALSE). When the buffer is modified,
1866    /// it will automatically toggled on the modified bit again. When the modified
1867    /// bit flips, the buffer emits the [`modified-changed`][struct@crate::TextBuffer#modified-changed] signal.
1868    /// ## `setting`
1869    /// modification flag setting
1870    #[doc(alias = "gtk_text_buffer_set_modified")]
1871    fn set_modified(&self, setting: bool) {
1872        unsafe {
1873            ffi::gtk_text_buffer_set_modified(self.as_ref().to_glib_none().0, setting.into_glib());
1874        }
1875    }
1876
1877    /// Deletes current contents of `self`, and inserts `text` instead. If
1878    /// `len` is -1, `text` must be nul-terminated. `text` must be valid UTF-8.
1879    /// ## `text`
1880    /// UTF-8 text to insert
1881    /// ## `len`
1882    /// length of `text` in bytes
1883    #[doc(alias = "gtk_text_buffer_set_text")]
1884    #[doc(alias = "text")]
1885    fn set_text(&self, text: &str) {
1886        let len = text.len() as _;
1887        unsafe {
1888            ffi::gtk_text_buffer_set_text(
1889                self.as_ref().to_glib_none().0,
1890                text.to_glib_none().0,
1891                len,
1892            );
1893        }
1894    }
1895
1896    /// This function unregisters a rich text format that was previously
1897    /// registered using `gtk_text_buffer_register_deserialize_format()` or
1898    /// [`register_deserialize_tagset()`][Self::register_deserialize_tagset()].
1899    /// ## `format`
1900    /// a [`gdk::Atom`][crate::gdk::Atom] representing a registered rich text format.
1901    #[doc(alias = "gtk_text_buffer_unregister_deserialize_format")]
1902    fn unregister_deserialize_format(&self, format: &gdk::Atom) {
1903        unsafe {
1904            ffi::gtk_text_buffer_unregister_deserialize_format(
1905                self.as_ref().to_glib_none().0,
1906                format.to_glib_none().0,
1907            );
1908        }
1909    }
1910
1911    /// This function unregisters a rich text format that was previously
1912    /// registered using `gtk_text_buffer_register_serialize_format()` or
1913    /// [`register_serialize_tagset()`][Self::register_serialize_tagset()]
1914    /// ## `format`
1915    /// a [`gdk::Atom`][crate::gdk::Atom] representing a registered rich text format.
1916    #[doc(alias = "gtk_text_buffer_unregister_serialize_format")]
1917    fn unregister_serialize_format(&self, format: &gdk::Atom) {
1918        unsafe {
1919            ffi::gtk_text_buffer_unregister_serialize_format(
1920                self.as_ref().to_glib_none().0,
1921                format.to_glib_none().0,
1922            );
1923        }
1924    }
1925
1926    /// The position of the insert mark (as offset from the beginning
1927    /// of the buffer). It is useful for getting notified when the
1928    /// cursor moves.
1929    #[doc(alias = "cursor-position")]
1930    fn cursor_position(&self) -> i32 {
1931        ObjectExt::property(self.as_ref(), "cursor-position")
1932    }
1933
1934    /// The ::begin-user-action signal is emitted at the beginning of a single
1935    /// user-visible operation on a [`TextBuffer`][crate::TextBuffer].
1936    ///
1937    /// See also:
1938    /// [`begin_user_action()`][Self::begin_user_action()],
1939    /// [`insert_interactive()`][Self::insert_interactive()],
1940    /// [`insert_range_interactive()`][Self::insert_range_interactive()],
1941    /// [`delete_interactive()`][Self::delete_interactive()],
1942    /// [`backspace()`][Self::backspace()],
1943    /// [`delete_selection()`][Self::delete_selection()].
1944    #[doc(alias = "begin-user-action")]
1945    fn connect_begin_user_action<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1946        unsafe extern "C" fn begin_user_action_trampoline<
1947            P: IsA<TextBuffer>,
1948            F: Fn(&P) + 'static,
1949        >(
1950            this: *mut ffi::GtkTextBuffer,
1951            f: glib::ffi::gpointer,
1952        ) {
1953            unsafe {
1954                let f: &F = &*(f as *const F);
1955                f(TextBuffer::from_glib_borrow(this).unsafe_cast_ref())
1956            }
1957        }
1958        unsafe {
1959            let f: Box_<F> = Box_::new(f);
1960            connect_raw(
1961                self.as_ptr() as *mut _,
1962                c"begin-user-action".as_ptr(),
1963                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1964                    begin_user_action_trampoline::<Self, F> as *const (),
1965                )),
1966                Box_::into_raw(f),
1967            )
1968        }
1969    }
1970
1971    /// The ::changed signal is emitted when the content of a [`TextBuffer`][crate::TextBuffer]
1972    /// has changed.
1973    #[doc(alias = "changed")]
1974    fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1975        unsafe extern "C" fn changed_trampoline<P: IsA<TextBuffer>, F: Fn(&P) + 'static>(
1976            this: *mut ffi::GtkTextBuffer,
1977            f: glib::ffi::gpointer,
1978        ) {
1979            unsafe {
1980                let f: &F = &*(f as *const F);
1981                f(TextBuffer::from_glib_borrow(this).unsafe_cast_ref())
1982            }
1983        }
1984        unsafe {
1985            let f: Box_<F> = Box_::new(f);
1986            connect_raw(
1987                self.as_ptr() as *mut _,
1988                c"changed".as_ptr(),
1989                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1990                    changed_trampoline::<Self, F> as *const (),
1991                )),
1992                Box_::into_raw(f),
1993            )
1994        }
1995    }
1996
1997    /// The ::end-user-action signal is emitted at the end of a single
1998    /// user-visible operation on the [`TextBuffer`][crate::TextBuffer].
1999    ///
2000    /// See also:
2001    /// [`end_user_action()`][Self::end_user_action()],
2002    /// [`insert_interactive()`][Self::insert_interactive()],
2003    /// [`insert_range_interactive()`][Self::insert_range_interactive()],
2004    /// [`delete_interactive()`][Self::delete_interactive()],
2005    /// [`backspace()`][Self::backspace()],
2006    /// [`delete_selection()`][Self::delete_selection()],
2007    /// [`backspace()`][Self::backspace()].
2008    #[doc(alias = "end-user-action")]
2009    fn connect_end_user_action<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2010        unsafe extern "C" fn end_user_action_trampoline<P: IsA<TextBuffer>, F: Fn(&P) + 'static>(
2011            this: *mut ffi::GtkTextBuffer,
2012            f: glib::ffi::gpointer,
2013        ) {
2014            unsafe {
2015                let f: &F = &*(f as *const F);
2016                f(TextBuffer::from_glib_borrow(this).unsafe_cast_ref())
2017            }
2018        }
2019        unsafe {
2020            let f: Box_<F> = Box_::new(f);
2021            connect_raw(
2022                self.as_ptr() as *mut _,
2023                c"end-user-action".as_ptr(),
2024                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2025                    end_user_action_trampoline::<Self, F> as *const (),
2026                )),
2027                Box_::into_raw(f),
2028            )
2029        }
2030    }
2031
2032    /// The ::mark-deleted signal is emitted as notification
2033    /// after a [`TextMark`][crate::TextMark] is deleted.
2034    ///
2035    /// See also:
2036    /// [`delete_mark()`][Self::delete_mark()].
2037    /// ## `mark`
2038    /// The mark that was deleted
2039    #[doc(alias = "mark-deleted")]
2040    fn connect_mark_deleted<F: Fn(&Self, &TextMark) + 'static>(&self, f: F) -> SignalHandlerId {
2041        unsafe extern "C" fn mark_deleted_trampoline<
2042            P: IsA<TextBuffer>,
2043            F: Fn(&P, &TextMark) + 'static,
2044        >(
2045            this: *mut ffi::GtkTextBuffer,
2046            mark: *mut ffi::GtkTextMark,
2047            f: glib::ffi::gpointer,
2048        ) {
2049            unsafe {
2050                let f: &F = &*(f as *const F);
2051                f(
2052                    TextBuffer::from_glib_borrow(this).unsafe_cast_ref(),
2053                    &from_glib_borrow(mark),
2054                )
2055            }
2056        }
2057        unsafe {
2058            let f: Box_<F> = Box_::new(f);
2059            connect_raw(
2060                self.as_ptr() as *mut _,
2061                c"mark-deleted".as_ptr(),
2062                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2063                    mark_deleted_trampoline::<Self, F> as *const (),
2064                )),
2065                Box_::into_raw(f),
2066            )
2067        }
2068    }
2069
2070    /// The ::mark-set signal is emitted as notification
2071    /// after a [`TextMark`][crate::TextMark] is set.
2072    ///
2073    /// See also:
2074    /// [`create_mark()`][Self::create_mark()],
2075    /// [`move_mark()`][Self::move_mark()].
2076    /// ## `location`
2077    /// The location of `mark` in `textbuffer`
2078    /// ## `mark`
2079    /// The mark that is set
2080    #[doc(alias = "mark-set")]
2081    fn connect_mark_set<F: Fn(&Self, &TextIter, &TextMark) + 'static>(
2082        &self,
2083        f: F,
2084    ) -> SignalHandlerId {
2085        unsafe extern "C" fn mark_set_trampoline<
2086            P: IsA<TextBuffer>,
2087            F: Fn(&P, &TextIter, &TextMark) + 'static,
2088        >(
2089            this: *mut ffi::GtkTextBuffer,
2090            location: *mut ffi::GtkTextIter,
2091            mark: *mut ffi::GtkTextMark,
2092            f: glib::ffi::gpointer,
2093        ) {
2094            unsafe {
2095                let f: &F = &*(f as *const F);
2096                f(
2097                    TextBuffer::from_glib_borrow(this).unsafe_cast_ref(),
2098                    &from_glib_borrow(location),
2099                    &from_glib_borrow(mark),
2100                )
2101            }
2102        }
2103        unsafe {
2104            let f: Box_<F> = Box_::new(f);
2105            connect_raw(
2106                self.as_ptr() as *mut _,
2107                c"mark-set".as_ptr(),
2108                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2109                    mark_set_trampoline::<Self, F> as *const (),
2110                )),
2111                Box_::into_raw(f),
2112            )
2113        }
2114    }
2115
2116    /// The ::modified-changed signal is emitted when the modified bit of a
2117    /// [`TextBuffer`][crate::TextBuffer] flips.
2118    ///
2119    /// See also:
2120    /// [`set_modified()`][Self::set_modified()].
2121    #[doc(alias = "modified-changed")]
2122    fn connect_modified_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2123        unsafe extern "C" fn modified_changed_trampoline<
2124            P: IsA<TextBuffer>,
2125            F: Fn(&P) + 'static,
2126        >(
2127            this: *mut ffi::GtkTextBuffer,
2128            f: glib::ffi::gpointer,
2129        ) {
2130            unsafe {
2131                let f: &F = &*(f as *const F);
2132                f(TextBuffer::from_glib_borrow(this).unsafe_cast_ref())
2133            }
2134        }
2135        unsafe {
2136            let f: Box_<F> = Box_::new(f);
2137            connect_raw(
2138                self.as_ptr() as *mut _,
2139                c"modified-changed".as_ptr(),
2140                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2141                    modified_changed_trampoline::<Self, F> as *const (),
2142                )),
2143                Box_::into_raw(f),
2144            )
2145        }
2146    }
2147
2148    /// The paste-done signal is emitted after paste operation has been completed.
2149    /// This is useful to properly scroll the view to the end of the pasted text.
2150    /// See [`paste_clipboard()`][Self::paste_clipboard()] for more details.
2151    /// ## `clipboard`
2152    /// the [`Clipboard`][crate::Clipboard] pasted from
2153    #[doc(alias = "paste-done")]
2154    fn connect_paste_done<F: Fn(&Self, &Clipboard) + 'static>(&self, f: F) -> SignalHandlerId {
2155        unsafe extern "C" fn paste_done_trampoline<
2156            P: IsA<TextBuffer>,
2157            F: Fn(&P, &Clipboard) + 'static,
2158        >(
2159            this: *mut ffi::GtkTextBuffer,
2160            clipboard: *mut ffi::GtkClipboard,
2161            f: glib::ffi::gpointer,
2162        ) {
2163            unsafe {
2164                let f: &F = &*(f as *const F);
2165                f(
2166                    TextBuffer::from_glib_borrow(this).unsafe_cast_ref(),
2167                    &from_glib_borrow(clipboard),
2168                )
2169            }
2170        }
2171        unsafe {
2172            let f: Box_<F> = Box_::new(f);
2173            connect_raw(
2174                self.as_ptr() as *mut _,
2175                c"paste-done".as_ptr(),
2176                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2177                    paste_done_trampoline::<Self, F> as *const (),
2178                )),
2179                Box_::into_raw(f),
2180            )
2181        }
2182    }
2183
2184    #[doc(alias = "copy-target-list")]
2185    fn connect_copy_target_list_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2186        unsafe extern "C" fn notify_copy_target_list_trampoline<
2187            P: IsA<TextBuffer>,
2188            F: Fn(&P) + 'static,
2189        >(
2190            this: *mut ffi::GtkTextBuffer,
2191            _param_spec: glib::ffi::gpointer,
2192            f: glib::ffi::gpointer,
2193        ) {
2194            unsafe {
2195                let f: &F = &*(f as *const F);
2196                f(TextBuffer::from_glib_borrow(this).unsafe_cast_ref())
2197            }
2198        }
2199        unsafe {
2200            let f: Box_<F> = Box_::new(f);
2201            connect_raw(
2202                self.as_ptr() as *mut _,
2203                c"notify::copy-target-list".as_ptr(),
2204                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2205                    notify_copy_target_list_trampoline::<Self, F> as *const (),
2206                )),
2207                Box_::into_raw(f),
2208            )
2209        }
2210    }
2211
2212    #[doc(alias = "cursor-position")]
2213    fn connect_cursor_position_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2214        unsafe extern "C" fn notify_cursor_position_trampoline<
2215            P: IsA<TextBuffer>,
2216            F: Fn(&P) + 'static,
2217        >(
2218            this: *mut ffi::GtkTextBuffer,
2219            _param_spec: glib::ffi::gpointer,
2220            f: glib::ffi::gpointer,
2221        ) {
2222            unsafe {
2223                let f: &F = &*(f as *const F);
2224                f(TextBuffer::from_glib_borrow(this).unsafe_cast_ref())
2225            }
2226        }
2227        unsafe {
2228            let f: Box_<F> = Box_::new(f);
2229            connect_raw(
2230                self.as_ptr() as *mut _,
2231                c"notify::cursor-position".as_ptr(),
2232                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2233                    notify_cursor_position_trampoline::<Self, F> as *const (),
2234                )),
2235                Box_::into_raw(f),
2236            )
2237        }
2238    }
2239
2240    #[doc(alias = "has-selection")]
2241    fn connect_has_selection_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2242        unsafe extern "C" fn notify_has_selection_trampoline<
2243            P: IsA<TextBuffer>,
2244            F: Fn(&P) + 'static,
2245        >(
2246            this: *mut ffi::GtkTextBuffer,
2247            _param_spec: glib::ffi::gpointer,
2248            f: glib::ffi::gpointer,
2249        ) {
2250            unsafe {
2251                let f: &F = &*(f as *const F);
2252                f(TextBuffer::from_glib_borrow(this).unsafe_cast_ref())
2253            }
2254        }
2255        unsafe {
2256            let f: Box_<F> = Box_::new(f);
2257            connect_raw(
2258                self.as_ptr() as *mut _,
2259                c"notify::has-selection".as_ptr(),
2260                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2261                    notify_has_selection_trampoline::<Self, F> as *const (),
2262                )),
2263                Box_::into_raw(f),
2264            )
2265        }
2266    }
2267
2268    #[doc(alias = "paste-target-list")]
2269    fn connect_paste_target_list_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2270        unsafe extern "C" fn notify_paste_target_list_trampoline<
2271            P: IsA<TextBuffer>,
2272            F: Fn(&P) + 'static,
2273        >(
2274            this: *mut ffi::GtkTextBuffer,
2275            _param_spec: glib::ffi::gpointer,
2276            f: glib::ffi::gpointer,
2277        ) {
2278            unsafe {
2279                let f: &F = &*(f as *const F);
2280                f(TextBuffer::from_glib_borrow(this).unsafe_cast_ref())
2281            }
2282        }
2283        unsafe {
2284            let f: Box_<F> = Box_::new(f);
2285            connect_raw(
2286                self.as_ptr() as *mut _,
2287                c"notify::paste-target-list".as_ptr(),
2288                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2289                    notify_paste_target_list_trampoline::<Self, F> as *const (),
2290                )),
2291                Box_::into_raw(f),
2292            )
2293        }
2294    }
2295
2296    #[doc(alias = "text")]
2297    fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2298        unsafe extern "C" fn notify_text_trampoline<P: IsA<TextBuffer>, F: Fn(&P) + 'static>(
2299            this: *mut ffi::GtkTextBuffer,
2300            _param_spec: glib::ffi::gpointer,
2301            f: glib::ffi::gpointer,
2302        ) {
2303            unsafe {
2304                let f: &F = &*(f as *const F);
2305                f(TextBuffer::from_glib_borrow(this).unsafe_cast_ref())
2306            }
2307        }
2308        unsafe {
2309            let f: Box_<F> = Box_::new(f);
2310            connect_raw(
2311                self.as_ptr() as *mut _,
2312                c"notify::text".as_ptr(),
2313                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2314                    notify_text_trampoline::<Self, F> as *const (),
2315                )),
2316                Box_::into_raw(f),
2317            )
2318        }
2319    }
2320}
2321
2322impl<O: IsA<TextBuffer>> TextBufferExt for O {}