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