1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use atk_sys;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::GString;
use glib_sys;
use libc;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem;
use std::mem::transmute;
use CoordType;
#[cfg(any(feature = "v2_32", feature = "dox"))]
use ScrollType;
use TextBoundary;
use TextClipType;
use TextGranularity;
use TextRange;
use TextRectangle;

glib_wrapper! {
    /// `Text` should be implemented by `AtkObjects` on behalf of widgets
    /// that have text content which is either attributed or otherwise
    /// non-trivial. `AtkObjects` whose text content is simple,
    /// unattributed, and very brief may expose that content via
    /// `AtkObjectExt::get_name` instead; however if the text is editable,
    /// multi-line, typically longer than three or four words, attributed,
    /// selectable, or if the object already uses the 'name' ATK property
    /// for other information, the `Text` interface should be used to
    /// expose the text content. In the case of editable text content,
    /// `EditableText` (a subtype of the `Text` interface) should be
    /// implemented instead.
    ///
    ///  `Text` provides not only traversal facilities and change
    /// notification for text content, but also caret tracking and glyph
    /// bounding box calculations. Note that the text strings are exposed
    /// as UTF-8, and are therefore potentially multi-byte, and
    /// caret-to-byte offset mapping makes no assumptions about the
    /// character length; also bounding box glyph-to-offset mapping may be
    /// complex for languages which use ligatures.
    ///
    /// # Implements
    ///
    /// [`TextExt`](trait.TextExt.html)
    pub struct Text(Interface<atk_sys::AtkText>);

    match fn {
        get_type => || atk_sys::atk_text_get_type(),
    }
}

pub const NONE_TEXT: Option<&Text> = None;

/// Trait containing all `Text` methods.
///
/// # Implementors
///
/// [`NoOpObject`](struct.NoOpObject.html), [`Text`](struct.Text.html)
pub trait TextExt: 'static {
    /// Adds a selection bounded by the specified offsets.
    /// ## `start_offset`
    /// the starting character offset of the selected region
    /// ## `end_offset`
    /// the offset of the first character after the selected region.
    ///
    /// # Returns
    ///
    /// `true` if successful, `false` otherwise
    fn add_selection(&self, start_offset: i32, end_offset: i32) -> bool;

    /// Get the ranges of text in the specified bounding box.
    /// ## `rect`
    /// An AtkTextRectangle giving the dimensions of the bounding box.
    /// ## `coord_type`
    /// Specify whether coordinates are relative to the screen or widget window.
    /// ## `x_clip_type`
    /// Specify the horizontal clip type.
    /// ## `y_clip_type`
    /// Specify the vertical clip type.
    ///
    /// # Returns
    ///
    /// Array of AtkTextRange. The last
    ///  element of the array returned by this function will be NULL.
    fn get_bounded_ranges(
        &self,
        rect: &mut TextRectangle,
        coord_type: CoordType,
        x_clip_type: TextClipType,
        y_clip_type: TextClipType,
    ) -> Vec<TextRange>;

    /// Gets the offset of the position of the caret (cursor).
    ///
    /// # Returns
    ///
    /// the character offset of the position of the caret or -1 if
    ///  the caret is not located inside the element or in the case of
    ///  any other failure.
    fn get_caret_offset(&self) -> i32;

    /// Gets the specified text.
    /// ## `offset`
    /// a character offset within `self`
    ///
    /// # Returns
    ///
    /// the character at `offset` or 0 in the case of failure.
    fn get_character_at_offset(&self, offset: i32) -> char;

    /// Gets the character count.
    ///
    /// # Returns
    ///
    /// the number of characters or -1 in case of failure.
    fn get_character_count(&self) -> i32;

    /// Get the bounding box containing the glyph representing the character at
    ///  a particular text offset.
    /// ## `offset`
    /// The offset of the text character for which bounding information is required.
    /// ## `x`
    /// Pointer for the x coordinate of the bounding box
    /// ## `y`
    /// Pointer for the y coordinate of the bounding box
    /// ## `width`
    /// Pointer for the width of the bounding box
    /// ## `height`
    /// Pointer for the height of the bounding box
    /// ## `coords`
    /// specify whether coordinates are relative to the screen or widget window
    fn get_character_extents(&self, offset: i32, coords: CoordType) -> (i32, i32, i32, i32);

    //fn get_default_attributes(&self) -> /*Ignored*/Option<AttributeSet>;

    /// Gets the number of selected regions.
    ///
    /// # Returns
    ///
    /// The number of selected regions, or -1 in the case of failure.
    fn get_n_selections(&self) -> i32;

    /// Gets the offset of the character located at coordinates `x` and `y`. `x` and `y`
    /// are interpreted as being relative to the screen or this widget's window
    /// depending on `coords`.
    /// ## `x`
    /// screen x-position of character
    /// ## `y`
    /// screen y-position of character
    /// ## `coords`
    /// specify whether coordinates are relative to the screen or
    /// widget window
    ///
    /// # Returns
    ///
    /// the offset to the character which is located at the specified
    ///  `x` and `y` coordinates of -1 in case of failure.
    fn get_offset_at_point(&self, x: i32, y: i32, coords: CoordType) -> i32;

    /// Get the bounding box for text within the specified range.
    /// ## `start_offset`
    /// The offset of the first text character for which boundary
    ///  information is required.
    /// ## `end_offset`
    /// The offset of the text character after the last character
    ///  for which boundary information is required.
    /// ## `coord_type`
    /// Specify whether coordinates are relative to the screen or widget window.
    /// ## `rect`
    /// A pointer to a AtkTextRectangle which is filled in by this function.
    fn get_range_extents(
        &self,
        start_offset: i32,
        end_offset: i32,
        coord_type: CoordType,
    ) -> TextRectangle;

    //fn get_run_attributes(&self, offset: i32) -> (/*Ignored*/AttributeSet, i32, i32);

    /// Gets the text from the specified selection.
    /// ## `selection_num`
    /// The selection number. The selected regions are
    /// assigned numbers that correspond to how far the region is from the
    /// start of the text. The selected region closest to the beginning
    /// of the text region is assigned the number 0, etc. Note that adding,
    /// moving or deleting a selected region can change the numbering.
    /// ## `start_offset`
    /// passes back the starting character offset of the selected region
    /// ## `end_offset`
    /// passes back the ending character offset (offset immediately past)
    /// of the selected region
    ///
    /// # Returns
    ///
    /// a newly allocated string containing the selected text. Use `g_free`
    ///  to free the returned string.
    fn get_selection(&self, selection_num: i32) -> (GString, i32, i32);

    /// Gets a portion of the text exposed through an `Text` according to a given `offset`
    /// and a specific `granularity`, along with the start and end offsets defining the
    /// boundaries of such a portion of text.
    ///
    /// If `granularity` is ATK_TEXT_GRANULARITY_CHAR the character at the
    /// offset is returned.
    ///
    /// If `granularity` is ATK_TEXT_GRANULARITY_WORD the returned string
    /// is from the word start at or before the offset to the word start after
    /// the offset.
    ///
    /// The returned string will contain the word at the offset if the offset
    /// is inside a word and will contain the word before the offset if the
    /// offset is not inside a word.
    ///
    /// If `granularity` is ATK_TEXT_GRANULARITY_SENTENCE the returned string
    /// is from the sentence start at or before the offset to the sentence
    /// start after the offset.
    ///
    /// The returned string will contain the sentence at the offset if the offset
    /// is inside a sentence and will contain the sentence before the offset
    /// if the offset is not inside a sentence.
    ///
    /// If `granularity` is ATK_TEXT_GRANULARITY_LINE the returned string
    /// is from the line start at or before the offset to the line
    /// start after the offset.
    ///
    /// If `granularity` is ATK_TEXT_GRANULARITY_PARAGRAPH the returned string
    /// is from the start of the paragraph at or before the offset to the start
    /// of the following paragraph after the offset.
    /// ## `offset`
    /// position
    /// ## `granularity`
    /// An `TextGranularity`
    /// ## `start_offset`
    /// the starting character offset of the returned string, or -1
    ///  in the case of error (e.g. invalid offset, not implemented)
    /// ## `end_offset`
    /// the offset of the first character after the returned string,
    ///  or -1 in the case of error (e.g. invalid offset, not implemented)
    ///
    /// # Returns
    ///
    /// a newly allocated string containing the text at
    ///  the `offset` bounded by the specified `granularity`. Use `g_free`
    ///  to free the returned string. Returns `None` if the offset is invalid
    ///  or no implementation is available.
    fn get_string_at_offset(
        &self,
        offset: i32,
        granularity: TextGranularity,
    ) -> (Option<GString>, i32, i32);

    /// Gets the specified text.
    /// ## `start_offset`
    /// a starting character offset within `self`
    /// ## `end_offset`
    /// an ending character offset within `self`, or -1 for the end of the string.
    ///
    /// # Returns
    ///
    /// a newly allocated string containing the text from `start_offset` up
    ///  to, but not including `end_offset`. Use `g_free` to free the returned
    ///  string.
    fn get_text(&self, start_offset: i32, end_offset: i32) -> Option<GString>;

    /// Gets the specified text.
    ///
    /// If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character at the
    /// offset is returned.
    ///
    /// If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
    /// is from the word start at or before the offset to the word start after
    /// the offset.
    ///
    /// The returned string will contain the word at the offset if the offset
    /// is inside a word and will contain the word before the offset if the
    /// offset is not inside a word.
    ///
    /// If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
    /// string is from the sentence start at or before the offset to the sentence
    /// start after the offset.
    ///
    /// The returned string will contain the sentence at the offset if the offset
    /// is inside a sentence and will contain the sentence before the offset
    /// if the offset is not inside a sentence.
    ///
    /// If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
    /// string is from the line start at or before the offset to the line
    /// start after the offset.
    ///
    /// # Deprecated
    ///
    /// This method is deprecated since ATK version
    /// 2.9.4. Please use `Text::get_string_at_offset` instead.
    /// ## `offset`
    /// position
    /// ## `boundary_type`
    /// An `TextBoundary`
    /// ## `start_offset`
    /// the starting character offset of the returned string
    /// ## `end_offset`
    /// the offset of the first character after the
    ///  returned substring
    ///
    /// # Returns
    ///
    /// a newly allocated string containing the text at `offset` bounded
    ///  by the specified `boundary_type`. Use `g_free` to free the returned
    ///  string.
    fn get_text_at_offset(&self, offset: i32, boundary_type: TextBoundary) -> (GString, i32, i32);

    /// Removes the specified selection.
    /// ## `selection_num`
    /// The selection number. The selected regions are
    /// assigned numbers that correspond to how far the region is from the
    /// start of the text. The selected region closest to the beginning
    /// of the text region is assigned the number 0, etc. Note that adding,
    /// moving or deleting a selected region can change the numbering.
    ///
    /// # Returns
    ///
    /// `true` if successful, `false` otherwise
    fn remove_selection(&self, selection_num: i32) -> bool;

    /// Makes `self` visible on the screen by scrolling all necessary parents.
    ///
    /// Contrary to atk_text_set_position, this does not actually move
    /// `self` in its parent, this only makes the parents scroll so that the
    /// object shows up on the screen, given its current position within the parents.
    ///
    /// Feature: `v2_32`
    ///
    /// ## `start_offset`
    /// start position
    /// ## `end_offset`
    /// end position, or -1 for the end of the string.
    /// ## `type_`
    /// specify where the object should be made visible.
    ///
    /// # Returns
    ///
    /// whether scrolling was successful.
    #[cfg(any(feature = "v2_32", feature = "dox"))]
    fn scroll_substring_to(&self, start_offset: i32, end_offset: i32, type_: ScrollType) -> bool;

    /// Makes an object visible on the screen at a given position by scrolling all
    /// necessary parents.
    ///
    /// Feature: `v2_32`
    ///
    /// ## `start_offset`
    /// start position
    /// ## `end_offset`
    /// end position, or -1 for the end of the string.
    /// ## `coords`
    /// specify whether coordinates are relative to the screen or to the
    /// parent object.
    /// ## `x`
    /// x-position where to scroll to
    /// ## `y`
    /// y-position where to scroll to
    ///
    /// # Returns
    ///
    /// whether scrolling was successful.
    #[cfg(any(feature = "v2_32", feature = "dox"))]
    fn scroll_substring_to_point(
        &self,
        start_offset: i32,
        end_offset: i32,
        coords: CoordType,
        x: i32,
        y: i32,
    ) -> bool;

    /// Sets the caret (cursor) position to the specified `offset`.
    /// ## `offset`
    /// the character offset of the new caret position
    ///
    /// # Returns
    ///
    /// `true` if successful, `false` otherwise.
    fn set_caret_offset(&self, offset: i32) -> bool;

    /// Changes the start and end offset of the specified selection.
    /// ## `selection_num`
    /// The selection number. The selected regions are
    /// assigned numbers that correspond to how far the region is from the
    /// start of the text. The selected region closest to the beginning
    /// of the text region is assigned the number 0, etc. Note that adding,
    /// moving or deleting a selected region can change the numbering.
    /// ## `start_offset`
    /// the new starting character offset of the selection
    /// ## `end_offset`
    /// the new end position of (e.g. offset immediately past)
    /// the selection
    ///
    /// # Returns
    ///
    /// `true` if successful, `false` otherwise
    fn set_selection(&self, selection_num: i32, start_offset: i32, end_offset: i32) -> bool;

    /// The "text-attributes-changed" signal is emitted when the text
    /// attributes of the text of an object which implements AtkText
    /// changes.
    fn connect_text_attributes_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    /// The "text-caret-moved" signal is emitted when the caret
    /// position of the text of an object which implements AtkText
    /// changes.
    /// ## `arg1`
    /// The new position of the text caret.
    fn connect_text_caret_moved<F: Fn(&Self, i32) + 'static>(&self, f: F) -> SignalHandlerId;

    /// The "text-insert" signal is emitted when a new text is
    /// inserted. If the signal was not triggered by the user
    /// (e.g. typing or pasting text), the "system" detail should be
    /// included.
    /// ## `arg1`
    /// The position (character offset) of the insertion.
    /// ## `arg2`
    /// The length (in characters) of text inserted.
    /// ## `arg3`
    /// The new text inserted
    fn connect_text_insert<F: Fn(&Self, i32, i32, &str) + 'static>(&self, f: F) -> SignalHandlerId;

    /// The "text-remove" signal is emitted when a new text is
    /// removed. If the signal was not triggered by the user
    /// (e.g. typing or pasting text), the "system" detail should be
    /// included.
    /// ## `arg1`
    /// The position (character offset) of the removal.
    /// ## `arg2`
    /// The length (in characters) of text removed.
    /// ## `arg3`
    /// The old text removed
    fn connect_text_remove<F: Fn(&Self, i32, i32, &str) + 'static>(&self, f: F) -> SignalHandlerId;

    /// The "text-selection-changed" signal is emitted when the
    /// selected text of an object which implements AtkText changes.
    fn connect_text_selection_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<Text>> TextExt for O {
    fn add_selection(&self, start_offset: i32, end_offset: i32) -> bool {
        unsafe {
            from_glib(atk_sys::atk_text_add_selection(
                self.as_ref().to_glib_none().0,
                start_offset,
                end_offset,
            ))
        }
    }

    fn get_bounded_ranges(
        &self,
        rect: &mut TextRectangle,
        coord_type: CoordType,
        x_clip_type: TextClipType,
        y_clip_type: TextClipType,
    ) -> Vec<TextRange> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(atk_sys::atk_text_get_bounded_ranges(
                self.as_ref().to_glib_none().0,
                rect.to_glib_none_mut().0,
                coord_type.to_glib(),
                x_clip_type.to_glib(),
                y_clip_type.to_glib(),
            ))
        }
    }

    fn get_caret_offset(&self) -> i32 {
        unsafe { atk_sys::atk_text_get_caret_offset(self.as_ref().to_glib_none().0) }
    }

    fn get_character_at_offset(&self, offset: i32) -> char {
        unsafe {
            from_glib(atk_sys::atk_text_get_character_at_offset(
                self.as_ref().to_glib_none().0,
                offset,
            ))
        }
    }

    fn get_character_count(&self) -> i32 {
        unsafe { atk_sys::atk_text_get_character_count(self.as_ref().to_glib_none().0) }
    }

    fn get_character_extents(&self, offset: i32, coords: CoordType) -> (i32, i32, i32, i32) {
        unsafe {
            let mut x = mem::MaybeUninit::uninit();
            let mut y = mem::MaybeUninit::uninit();
            let mut width = mem::MaybeUninit::uninit();
            let mut height = mem::MaybeUninit::uninit();
            atk_sys::atk_text_get_character_extents(
                self.as_ref().to_glib_none().0,
                offset,
                x.as_mut_ptr(),
                y.as_mut_ptr(),
                width.as_mut_ptr(),
                height.as_mut_ptr(),
                coords.to_glib(),
            );
            let x = x.assume_init();
            let y = y.assume_init();
            let width = width.assume_init();
            let height = height.assume_init();
            (x, y, width, height)
        }
    }

    //fn get_default_attributes(&self) -> /*Ignored*/Option<AttributeSet> {
    //    unsafe { TODO: call atk_sys:atk_text_get_default_attributes() }
    //}

    fn get_n_selections(&self) -> i32 {
        unsafe { atk_sys::atk_text_get_n_selections(self.as_ref().to_glib_none().0) }
    }

    fn get_offset_at_point(&self, x: i32, y: i32, coords: CoordType) -> i32 {
        unsafe {
            atk_sys::atk_text_get_offset_at_point(
                self.as_ref().to_glib_none().0,
                x,
                y,
                coords.to_glib(),
            )
        }
    }

    fn get_range_extents(
        &self,
        start_offset: i32,
        end_offset: i32,
        coord_type: CoordType,
    ) -> TextRectangle {
        unsafe {
            let mut rect = TextRectangle::uninitialized();
            atk_sys::atk_text_get_range_extents(
                self.as_ref().to_glib_none().0,
                start_offset,
                end_offset,
                coord_type.to_glib(),
                rect.to_glib_none_mut().0,
            );
            rect
        }
    }

    //fn get_run_attributes(&self, offset: i32) -> (/*Ignored*/AttributeSet, i32, i32) {
    //    unsafe { TODO: call atk_sys:atk_text_get_run_attributes() }
    //}

    fn get_selection(&self, selection_num: i32) -> (GString, i32, i32) {
        unsafe {
            let mut start_offset = mem::MaybeUninit::uninit();
            let mut end_offset = mem::MaybeUninit::uninit();
            let ret = from_glib_full(atk_sys::atk_text_get_selection(
                self.as_ref().to_glib_none().0,
                selection_num,
                start_offset.as_mut_ptr(),
                end_offset.as_mut_ptr(),
            ));
            let start_offset = start_offset.assume_init();
            let end_offset = end_offset.assume_init();
            (ret, start_offset, end_offset)
        }
    }

    fn get_string_at_offset(
        &self,
        offset: i32,
        granularity: TextGranularity,
    ) -> (Option<GString>, i32, i32) {
        unsafe {
            let mut start_offset = mem::MaybeUninit::uninit();
            let mut end_offset = mem::MaybeUninit::uninit();
            let ret = from_glib_full(atk_sys::atk_text_get_string_at_offset(
                self.as_ref().to_glib_none().0,
                offset,
                granularity.to_glib(),
                start_offset.as_mut_ptr(),
                end_offset.as_mut_ptr(),
            ));
            let start_offset = start_offset.assume_init();
            let end_offset = end_offset.assume_init();
            (ret, start_offset, end_offset)
        }
    }

    fn get_text(&self, start_offset: i32, end_offset: i32) -> Option<GString> {
        unsafe {
            from_glib_full(atk_sys::atk_text_get_text(
                self.as_ref().to_glib_none().0,
                start_offset,
                end_offset,
            ))
        }
    }

    fn get_text_at_offset(&self, offset: i32, boundary_type: TextBoundary) -> (GString, i32, i32) {
        unsafe {
            let mut start_offset = mem::MaybeUninit::uninit();
            let mut end_offset = mem::MaybeUninit::uninit();
            let ret = from_glib_full(atk_sys::atk_text_get_text_at_offset(
                self.as_ref().to_glib_none().0,
                offset,
                boundary_type.to_glib(),
                start_offset.as_mut_ptr(),
                end_offset.as_mut_ptr(),
            ));
            let start_offset = start_offset.assume_init();
            let end_offset = end_offset.assume_init();
            (ret, start_offset, end_offset)
        }
    }

    fn remove_selection(&self, selection_num: i32) -> bool {
        unsafe {
            from_glib(atk_sys::atk_text_remove_selection(
                self.as_ref().to_glib_none().0,
                selection_num,
            ))
        }
    }

    #[cfg(any(feature = "v2_32", feature = "dox"))]
    fn scroll_substring_to(&self, start_offset: i32, end_offset: i32, type_: ScrollType) -> bool {
        unsafe {
            from_glib(atk_sys::atk_text_scroll_substring_to(
                self.as_ref().to_glib_none().0,
                start_offset,
                end_offset,
                type_.to_glib(),
            ))
        }
    }

    #[cfg(any(feature = "v2_32", feature = "dox"))]
    fn scroll_substring_to_point(
        &self,
        start_offset: i32,
        end_offset: i32,
        coords: CoordType,
        x: i32,
        y: i32,
    ) -> bool {
        unsafe {
            from_glib(atk_sys::atk_text_scroll_substring_to_point(
                self.as_ref().to_glib_none().0,
                start_offset,
                end_offset,
                coords.to_glib(),
                x,
                y,
            ))
        }
    }

    fn set_caret_offset(&self, offset: i32) -> bool {
        unsafe {
            from_glib(atk_sys::atk_text_set_caret_offset(
                self.as_ref().to_glib_none().0,
                offset,
            ))
        }
    }

    fn set_selection(&self, selection_num: i32, start_offset: i32, end_offset: i32) -> bool {
        unsafe {
            from_glib(atk_sys::atk_text_set_selection(
                self.as_ref().to_glib_none().0,
                selection_num,
                start_offset,
                end_offset,
            ))
        }
    }

    fn connect_text_attributes_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn text_attributes_changed_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut atk_sys::AtkText,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Text>,
        {
            let f: &F = &*(f as *const F);
            f(&Text::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"text-attributes-changed\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    text_attributes_changed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_text_caret_moved<F: Fn(&Self, i32) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn text_caret_moved_trampoline<P, F: Fn(&P, i32) + 'static>(
            this: *mut atk_sys::AtkText,
            arg1: libc::c_int,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Text>,
        {
            let f: &F = &*(f as *const F);
            f(&Text::from_glib_borrow(this).unsafe_cast_ref(), arg1)
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"text-caret-moved\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    text_caret_moved_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_text_insert<F: Fn(&Self, i32, i32, &str) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn text_insert_trampoline<P, F: Fn(&P, i32, i32, &str) + 'static>(
            this: *mut atk_sys::AtkText,
            arg1: libc::c_int,
            arg2: libc::c_int,
            arg3: *mut libc::c_char,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Text>,
        {
            let f: &F = &*(f as *const F);
            f(
                &Text::from_glib_borrow(this).unsafe_cast_ref(),
                arg1,
                arg2,
                &GString::from_glib_borrow(arg3),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"text-insert\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    text_insert_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_text_remove<F: Fn(&Self, i32, i32, &str) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn text_remove_trampoline<P, F: Fn(&P, i32, i32, &str) + 'static>(
            this: *mut atk_sys::AtkText,
            arg1: libc::c_int,
            arg2: libc::c_int,
            arg3: *mut libc::c_char,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Text>,
        {
            let f: &F = &*(f as *const F);
            f(
                &Text::from_glib_borrow(this).unsafe_cast_ref(),
                arg1,
                arg2,
                &GString::from_glib_borrow(arg3),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"text-remove\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    text_remove_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_text_selection_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn text_selection_changed_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut atk_sys::AtkText,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Text>,
        {
            let f: &F = &*(f as *const F);
            f(&Text::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"text-selection-changed\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    text_selection_changed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for Text {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "Text")
    }
}