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
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use crate::Accessible;
use crate::Buildable;
use crate::ConstraintTarget;
use crate::Widget;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::StaticType;
use glib::ToValue;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem;
use std::mem::transmute;

glib::wrapper! {
    /// [`Editable`][crate::Editable] is an interface for text editing widgets.
    ///
    /// Typical examples of editable widgets are [`Entry`][crate::Entry] and
    /// [`SpinButton`][crate::SpinButton]. It contains functions for generically manipulating
    /// an editable widget, a large number of action signals used for key bindings,
    /// and several signals that an application can connect to modify the behavior
    /// of a widget.
    ///
    /// As an example of the latter usage, by connecting the following handler to
    /// `signal::Editable::insert-text`, an application can convert all entry
    /// into a widget into uppercase.
    ///
    /// ## Forcing entry to uppercase.
    ///
    /// **⚠️ The following code is in c ⚠️**
    ///
    /// ```c
    /// #include <ctype.h>
    ///
    /// void
    /// insert_text_handler (GtkEditable *editable,
    ///                      const char  *text,
    ///                      int          length,
    ///                      int         *position,
    ///                      gpointer     data)
    /// {
    ///   char *result = g_utf8_strup (text, length);
    ///
    ///   g_signal_handlers_block_by_func (editable,
    ///                                (gpointer) insert_text_handler, data);
    ///   gtk_editable_insert_text (editable, result, length, position);
    ///   g_signal_handlers_unblock_by_func (editable,
    ///                                      (gpointer) insert_text_handler, data);
    ///
    ///   g_signal_stop_emission_by_name (editable, "insert_text");
    ///
    ///   g_free (result);
    /// }
    /// ```
    ///
    /// ## Implementing GtkEditable
    ///
    /// The most likely scenario for implementing [`Editable`][crate::Editable] on your own widget
    /// is that you will embed a [`Text`][crate::Text] inside a complex widget, and want to
    /// delegate the editable functionality to that text widget. [`Editable`][crate::Editable]
    /// provides some utility functions to make this easy.
    ///
    /// In your class_init function, call [``install_properties()``][`Self::install_properties()`],
    /// passing the first available property ID:
    ///
    /// **⚠️ The following code is in c ⚠️**
    ///
    /// ```c
    /// static void
    /// my_class_init (MyClass *class)
    /// {
    ///   ...
    ///   g_object_class_install_properties (object_class, NUM_PROPERTIES, props);
    ///   gtk_editable_install_properties (object_clas, NUM_PROPERTIES);
    ///   ...
    /// }
    /// ```
    ///
    /// In your interface_init function for the [`Editable`][crate::Editable] interface, provide
    /// an implementation for the get_delegate vfunc that returns your text widget:
    ///
    /// **⚠️ The following code is in c ⚠️**
    ///
    /// ```c
    /// GtkEditable *
    /// get_editable_delegate (GtkEditable *editable)
    /// {
    ///   return GTK_EDITABLE (MY_WIDGET (editable)->text_widget);
    /// }
    ///
    /// static void
    /// my_editable_init (GtkEditableInterface *iface)
    /// {
    ///   iface->get_delegate = get_editable_delegate;
    /// }
    /// ```
    ///
    /// You don't need to provide any other vfuncs. The default implementations
    /// work by forwarding to the delegate that the `GtkEditableInterface.get_delegate()`
    /// vfunc returns.
    ///
    /// In your instance_init function, create your text widget, and then call
    /// [``EditableExt::init_delegate()``][crate::prelude::`EditableExt::init_delegate()`]:
    ///
    /// **⚠️ The following code is in c ⚠️**
    ///
    /// ```c
    /// static void
    /// my_widget_init (MyWidget *self)
    /// {
    ///   ...
    ///   self->text_widget = gtk_text_new ();
    ///   gtk_editable_init_delegate (GTK_EDITABLE (self));
    ///   ...
    /// }
    /// ```
    ///
    /// In your dispose function, call [``EditableExt::finish_delegate()``][crate::prelude::`EditableExt::finish_delegate()`] before
    /// destroying your text widget:
    ///
    /// **⚠️ The following code is in c ⚠️**
    ///
    /// ```c
    /// static void
    /// my_widget_dispose (GObject *object)
    /// {
    ///   ...
    ///   gtk_editable_finish_delegate (GTK_EDITABLE (self));
    ///   g_clear_pointer (&self->text_widget, gtk_widget_unparent);
    ///   ...
    /// }
    /// ```
    ///
    /// Finally, use [``delegate_set_property()``][`Self::delegate_set_property()`] in your `set_property`
    /// function (and similar for `get_property`), to set the editable properties:
    ///
    /// **⚠️ The following code is in c ⚠️**
    ///
    /// ```c
    ///   ...
    ///   if (gtk_editable_delegate_set_property (object, prop_id, value, pspec))
    ///     return;
    ///
    ///   switch (prop_id)
    ///   ...
    /// ```
    ///
    /// It is important to note that if you create a [`Editable`][crate::Editable] that uses
    /// a delegate, the low level `signal::Editable::insert-text` and
    /// `signal::Editable::delete-text` signals will be propagated from the
    /// "wrapper" editable to the delegate, but they will not be propagated from
    /// the delegate to the "wrapper" editable, as they would cause an infinite
    /// recursion. If you wish to connect to the `signal::Editable::insert-text`
    /// and `signal::Editable::delete-text` signals, you will need to connect
    /// to them on the delegate obtained via [``EditableExt::delegate()``][crate::prelude::`EditableExt::delegate()`].
    ///
    /// # Implements
    ///
    /// [`EditableExt`][trait@crate::prelude::EditableExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`EditableExtManual`][trait@crate::prelude::EditableExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
    #[doc(alias = "GtkEditable")]
    pub struct Editable(Interface<ffi::GtkEditable, ffi::GtkEditableInterface>) @requires Widget, Accessible, Buildable, ConstraintTarget;

    match fn {
        type_ => || ffi::gtk_editable_get_type(),
    }
}

pub const NONE_EDITABLE: Option<&Editable> = None;

/// Trait containing all [`struct@Editable`] methods.
///
/// # Implementors
///
/// [`EditableLabel`][struct@crate::EditableLabel], [`Editable`][struct@crate::Editable], [`Entry`][struct@crate::Entry], [`PasswordEntry`][struct@crate::PasswordEntry], [`SearchEntry`][struct@crate::SearchEntry], [`SpinButton`][struct@crate::SpinButton], [`Text`][struct@crate::Text]
pub trait EditableExt: 'static {
    /// Deletes the currently selected text of the editable.
    ///
    /// This call doesn’t do anything if there is no selected text.
    #[doc(alias = "gtk_editable_delete_selection")]
    fn delete_selection(&self);

    /// Deletes a sequence of characters.
    ///
    /// The characters that are deleted are those characters at positions
    /// from `start_pos` up to, but not including `end_pos`. If `end_pos` is
    /// negative, then the characters deleted are those from `start_pos` to
    /// the end of the text.
    ///
    /// Note that the positions are specified in characters, not bytes.
    /// ## `start_pos`
    /// start position
    /// ## `end_pos`
    /// end position
    #[doc(alias = "gtk_editable_delete_text")]
    fn delete_text(&self, start_pos: i32, end_pos: i32);

    /// Undoes the setup done by [``init_delegate()``][`Self::init_delegate()`].
    ///
    /// This is a helper function that should be called from dispose,
    /// before removing the delegate object.
    #[doc(alias = "gtk_editable_finish_delegate")]
    fn finish_delegate(&self);

    /// Gets the alignment of the editable.
    ///
    /// # Returns
    ///
    /// the alignment
    #[doc(alias = "gtk_editable_get_alignment")]
    #[doc(alias = "get_alignment")]
    fn alignment(&self) -> f32;

    /// Retrieves a sequence of characters.
    ///
    /// The characters that are retrieved are those characters at positions
    /// from `start_pos` up to, but not including `end_pos`. If `end_pos` is negative,
    /// then the characters retrieved are those characters from `start_pos` to
    /// the end of the text.
    ///
    /// Note that positions are specified in characters, not bytes.
    /// ## `start_pos`
    /// start of text
    /// ## `end_pos`
    /// end of text
    ///
    /// # Returns
    ///
    /// a pointer to the contents of the widget as a
    ///  string. This string is allocated by the [`Editable`][crate::Editable] implementation
    ///  and should be freed by the caller.
    #[doc(alias = "gtk_editable_get_chars")]
    #[doc(alias = "get_chars")]
    fn chars(&self, start_pos: i32, end_pos: i32) -> glib::GString;

    /// Gets the [`Editable`][crate::Editable] that `self` is delegating its
    /// implementation to.
    ///
    /// Typically, the delegate is a [`Text`][crate::Text] widget.
    ///
    /// # Returns
    ///
    /// the delegate [`Editable`][crate::Editable]
    #[doc(alias = "gtk_editable_get_delegate")]
    #[doc(alias = "get_delegate")]
    fn delegate(&self) -> Option<Editable>;

    /// Retrieves whether `self` is editable.
    ///
    /// # Returns
    ///
    /// [`true`] if `self` is editable.
    #[doc(alias = "gtk_editable_get_editable")]
    #[doc(alias = "get_editable")]
    fn is_editable(&self) -> bool;

    /// Gets if undo/redo actions are enabled for `self`
    ///
    /// # Returns
    ///
    /// [`true`] if undo is enabled
    #[doc(alias = "gtk_editable_get_enable_undo")]
    #[doc(alias = "get_enable_undo")]
    fn enables_undo(&self) -> bool;

    /// Retrieves the desired maximum width of `self`, in characters.
    ///
    /// # Returns
    ///
    /// the maximum width of the entry, in characters
    #[doc(alias = "gtk_editable_get_max_width_chars")]
    #[doc(alias = "get_max_width_chars")]
    fn max_width_chars(&self) -> i32;

    /// Retrieves the current position of the cursor relative
    /// to the start of the content of the editable.
    ///
    /// Note that this position is in characters, not in bytes.
    ///
    /// # Returns
    ///
    /// the cursor position
    #[doc(alias = "gtk_editable_get_position")]
    #[doc(alias = "get_position")]
    fn position(&self) -> i32;

    /// Retrieves the selection bound of the editable.
    ///
    /// `start_pos` will be filled with the start of the selection and
    /// `end_pos` with end. If no text was selected both will be identical
    /// and [`false`] will be returned.
    ///
    /// Note that positions are specified in characters, not bytes.
    ///
    /// # Returns
    ///
    /// [`true`] if there is a non-empty selection, [`false`] otherwise
    ///
    /// ## `start_pos`
    /// location to store the starting position
    ///
    /// ## `end_pos`
    /// location to store the end position
    #[doc(alias = "gtk_editable_get_selection_bounds")]
    #[doc(alias = "get_selection_bounds")]
    fn selection_bounds(&self) -> Option<(i32, i32)>;

    /// Retrieves the contents of `self`.
    ///
    /// The returned string is owned by GTK and must not be modified or freed.
    ///
    /// # Returns
    ///
    /// a pointer to the contents of the editable
    #[doc(alias = "gtk_editable_get_text")]
    #[doc(alias = "get_text")]
    fn text(&self) -> glib::GString;

    /// Gets the number of characters of space reserved
    /// for the contents of the editable.
    ///
    /// # Returns
    ///
    /// number of chars to request space for, or negative if unset
    #[doc(alias = "gtk_editable_get_width_chars")]
    #[doc(alias = "get_width_chars")]
    fn width_chars(&self) -> i32;

    /// Sets up a delegate for [`Editable`][crate::Editable].
    ///
    /// This is assuming that the get_delegate vfunc in the [`Editable`][crate::Editable]
    /// interface has been set up for the `self`'s type.
    ///
    /// This is a helper function that should be called in instance init,
    /// after creating the delegate object.
    #[doc(alias = "gtk_editable_init_delegate")]
    fn init_delegate(&self);

    /// Inserts `length` bytes of `text` into the contents of the
    /// widget, at position `position`.
    ///
    /// Note that the position is in characters, not in bytes.
    /// The function updates `position` to point after the newly
    /// inserted text.
    /// ## `text`
    /// the text to append
    /// ## `length`
    /// the length of the text in bytes, or -1
    /// ## `position`
    /// location of the position text will be inserted at
    #[doc(alias = "gtk_editable_insert_text")]
    fn insert_text(&self, text: &str, position: &mut i32);

    /// Selects a region of text.
    ///
    /// The characters that are selected are those characters at positions
    /// from `start_pos` up to, but not including `end_pos`. If `end_pos` is
    /// negative, then the characters selected are those characters from
    /// `start_pos` to the end of the text.
    ///
    /// Note that positions are specified in characters, not bytes.
    /// ## `start_pos`
    /// start of region
    /// ## `end_pos`
    /// end of region
    #[doc(alias = "gtk_editable_select_region")]
    fn select_region(&self, start_pos: i32, end_pos: i32);

    /// Sets the alignment for the contents of the editable.
    ///
    /// This controls the horizontal positioning of the contents when
    /// the displayed text is shorter than the width of the editable.
    /// ## `xalign`
    /// The horizontal alignment, from 0 (left) to 1 (right).
    ///  Reversed for RTL layouts
    #[doc(alias = "gtk_editable_set_alignment")]
    fn set_alignment(&self, xalign: f32);

    /// Determines if the user can edit the text in the editable widget.
    /// ## `is_editable`
    /// [`true`] if the user is allowed to edit the text
    ///  in the widget
    #[doc(alias = "gtk_editable_set_editable")]
    fn set_editable(&self, is_editable: bool);

    /// If enabled, changes to `self` will be saved for undo/redo
    /// actions.
    ///
    /// This results in an additional copy of text changes and are not
    /// stored in secure memory. As such, undo is forcefully disabled
    /// when `property::Text::visibility` is set to [`false`].
    /// ## `enable_undo`
    /// if undo/redo should be enabled
    #[doc(alias = "gtk_editable_set_enable_undo")]
    fn set_enable_undo(&self, enable_undo: bool);

    /// Sets the desired maximum width in characters of `self`.
    /// ## `n_chars`
    /// the new desired maximum width, in characters
    #[doc(alias = "gtk_editable_set_max_width_chars")]
    fn set_max_width_chars(&self, n_chars: i32);

    /// Sets the cursor position in the editable to the given value.
    ///
    /// The cursor is displayed before the character with the given (base 0)
    /// index in the contents of the editable. The value must be less than
    /// or equal to the number of characters in the editable. A value of -1
    /// indicates that the position should be set after the last character
    /// of the editable. Note that `position` is in characters, not in bytes.
    /// ## `position`
    /// the position of the cursor
    #[doc(alias = "gtk_editable_set_position")]
    fn set_position(&self, position: i32);

    /// Sets the text in the editable to the given value.
    ///
    /// This is replacing the current contents.
    /// ## `text`
    /// the text to set
    #[doc(alias = "gtk_editable_set_text")]
    fn set_text(&self, text: &str);

    /// Changes the size request of the editable to be about the
    /// right size for `n_chars` characters.
    ///
    /// Note that it changes the size request, the size can still
    /// be affected by how you pack the widget into containers.
    /// If `n_chars` is -1, the size reverts to the default size.
    /// ## `n_chars`
    /// width in chars
    #[doc(alias = "gtk_editable_set_width_chars")]
    fn set_width_chars(&self, n_chars: i32);

    /// The current position of the insertion cursor in chars.
    #[doc(alias = "cursor-position")]
    fn cursor_position(&self) -> i32;

    /// The position of the opposite end of the selection from the cursor in chars.
    #[doc(alias = "selection-bound")]
    fn selection_bound(&self) -> i32;

    /// The horizontal alignment, from 0 (left) to 1 (right).
    ///
    /// Reversed for RTL layouts.
    fn xalign(&self) -> f32;

    /// The horizontal alignment, from 0 (left) to 1 (right).
    ///
    /// Reversed for RTL layouts.
    fn set_xalign(&self, xalign: f32);

    /// Emitted at the end of a single user-visible operation on the
    /// contents.
    ///
    /// E.g., a paste operation that replaces the contents of the
    /// selection will cause only one signal emission (even though it
    /// is implemented by first deleting the selection, then inserting
    /// the new content, and may cause multiple ::notify::text signals
    /// to be emitted).
    #[doc(alias = "changed")]
    fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    /// Emitted when text is deleted from the widget by the user.
    ///
    /// The default handler for this signal will normally be responsible for
    /// deleting the text, so by connecting to this signal and then stopping
    /// the signal with `g_signal_stop_emission()`, it is possible to modify the
    /// range of deleted text, or prevent it from being deleted entirely.
    ///
    /// The `start_pos` and `end_pos` parameters are interpreted as for
    /// [``delete_text()``][`Self::delete_text()`].
    /// ## `start_pos`
    /// the starting position
    /// ## `end_pos`
    /// the end position
    #[doc(alias = "delete-text")]
    fn connect_delete_text<F: Fn(&Self, i32, i32) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "cursor-position")]
    fn connect_cursor_position_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "editable")]
    fn connect_editable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "enable-undo")]
    fn connect_enable_undo_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "max-width-chars")]
    fn connect_max_width_chars_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "selection-bound")]
    fn connect_selection_bound_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "text")]
    fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "width-chars")]
    fn connect_width_chars_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "xalign")]
    fn connect_xalign_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<Editable>> EditableExt for O {
    fn delete_selection(&self) {
        unsafe {
            ffi::gtk_editable_delete_selection(self.as_ref().to_glib_none().0);
        }
    }

    fn delete_text(&self, start_pos: i32, end_pos: i32) {
        unsafe {
            ffi::gtk_editable_delete_text(self.as_ref().to_glib_none().0, start_pos, end_pos);
        }
    }

    fn finish_delegate(&self) {
        unsafe {
            ffi::gtk_editable_finish_delegate(self.as_ref().to_glib_none().0);
        }
    }

    fn alignment(&self) -> f32 {
        unsafe { ffi::gtk_editable_get_alignment(self.as_ref().to_glib_none().0) }
    }

    fn chars(&self, start_pos: i32, end_pos: i32) -> glib::GString {
        unsafe {
            from_glib_full(ffi::gtk_editable_get_chars(
                self.as_ref().to_glib_none().0,
                start_pos,
                end_pos,
            ))
        }
    }

    fn delegate(&self) -> Option<Editable> {
        unsafe {
            from_glib_none(ffi::gtk_editable_get_delegate(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn is_editable(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_editable_get_editable(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn enables_undo(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_editable_get_enable_undo(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn max_width_chars(&self) -> i32 {
        unsafe { ffi::gtk_editable_get_max_width_chars(self.as_ref().to_glib_none().0) }
    }

    fn position(&self) -> i32 {
        unsafe { ffi::gtk_editable_get_position(self.as_ref().to_glib_none().0) }
    }

    fn selection_bounds(&self) -> Option<(i32, i32)> {
        unsafe {
            let mut start_pos = mem::MaybeUninit::uninit();
            let mut end_pos = mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::gtk_editable_get_selection_bounds(
                self.as_ref().to_glib_none().0,
                start_pos.as_mut_ptr(),
                end_pos.as_mut_ptr(),
            ));
            let start_pos = start_pos.assume_init();
            let end_pos = end_pos.assume_init();
            if ret {
                Some((start_pos, end_pos))
            } else {
                None
            }
        }
    }

    fn text(&self) -> glib::GString {
        unsafe { from_glib_none(ffi::gtk_editable_get_text(self.as_ref().to_glib_none().0)) }
    }

    fn width_chars(&self) -> i32 {
        unsafe { ffi::gtk_editable_get_width_chars(self.as_ref().to_glib_none().0) }
    }

    fn init_delegate(&self) {
        unsafe {
            ffi::gtk_editable_init_delegate(self.as_ref().to_glib_none().0);
        }
    }

    fn insert_text(&self, text: &str, position: &mut i32) {
        let length = text.len() as i32;
        unsafe {
            ffi::gtk_editable_insert_text(
                self.as_ref().to_glib_none().0,
                text.to_glib_none().0,
                length,
                position,
            );
        }
    }

    fn select_region(&self, start_pos: i32, end_pos: i32) {
        unsafe {
            ffi::gtk_editable_select_region(self.as_ref().to_glib_none().0, start_pos, end_pos);
        }
    }

    fn set_alignment(&self, xalign: f32) {
        unsafe {
            ffi::gtk_editable_set_alignment(self.as_ref().to_glib_none().0, xalign);
        }
    }

    fn set_editable(&self, is_editable: bool) {
        unsafe {
            ffi::gtk_editable_set_editable(self.as_ref().to_glib_none().0, is_editable.into_glib());
        }
    }

    fn set_enable_undo(&self, enable_undo: bool) {
        unsafe {
            ffi::gtk_editable_set_enable_undo(
                self.as_ref().to_glib_none().0,
                enable_undo.into_glib(),
            );
        }
    }

    fn set_max_width_chars(&self, n_chars: i32) {
        unsafe {
            ffi::gtk_editable_set_max_width_chars(self.as_ref().to_glib_none().0, n_chars);
        }
    }

    fn set_position(&self, position: i32) {
        unsafe {
            ffi::gtk_editable_set_position(self.as_ref().to_glib_none().0, position);
        }
    }

    fn set_text(&self, text: &str) {
        unsafe {
            ffi::gtk_editable_set_text(self.as_ref().to_glib_none().0, text.to_glib_none().0);
        }
    }

    fn set_width_chars(&self, n_chars: i32) {
        unsafe {
            ffi::gtk_editable_set_width_chars(self.as_ref().to_glib_none().0, n_chars);
        }
    }

    fn cursor_position(&self) -> i32 {
        unsafe {
            let mut value = glib::Value::from_type(<i32 as StaticType>::static_type());
            glib::gobject_ffi::g_object_get_property(
                self.to_glib_none().0 as *mut glib::gobject_ffi::GObject,
                b"cursor-position\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `cursor-position` getter")
        }
    }

    fn selection_bound(&self) -> i32 {
        unsafe {
            let mut value = glib::Value::from_type(<i32 as StaticType>::static_type());
            glib::gobject_ffi::g_object_get_property(
                self.to_glib_none().0 as *mut glib::gobject_ffi::GObject,
                b"selection-bound\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `selection-bound` getter")
        }
    }

    fn xalign(&self) -> f32 {
        unsafe {
            let mut value = glib::Value::from_type(<f32 as StaticType>::static_type());
            glib::gobject_ffi::g_object_get_property(
                self.to_glib_none().0 as *mut glib::gobject_ffi::GObject,
                b"xalign\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `xalign` getter")
        }
    }

    fn set_xalign(&self, xalign: f32) {
        unsafe {
            glib::gobject_ffi::g_object_set_property(
                self.to_glib_none().0 as *mut glib::gobject_ffi::GObject,
                b"xalign\0".as_ptr() as *const _,
                xalign.to_value().to_glib_none().0,
            );
        }
    }

    fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn changed_trampoline<P: IsA<Editable>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkEditable,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Editable::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"changed\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    changed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_delete_text<F: Fn(&Self, i32, i32) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn delete_text_trampoline<
            P: IsA<Editable>,
            F: Fn(&P, i32, i32) + 'static,
        >(
            this: *mut ffi::GtkEditable,
            start_pos: libc::c_int,
            end_pos: libc::c_int,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                Editable::from_glib_borrow(this).unsafe_cast_ref(),
                start_pos,
                end_pos,
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"delete-text\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    delete_text_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_cursor_position_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_cursor_position_trampoline<
            P: IsA<Editable>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkEditable,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Editable::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::cursor-position\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_cursor_position_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_editable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_editable_trampoline<P: IsA<Editable>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkEditable,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Editable::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::editable\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_editable_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_enable_undo_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_enable_undo_trampoline<
            P: IsA<Editable>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkEditable,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Editable::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::enable-undo\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_enable_undo_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_max_width_chars_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_max_width_chars_trampoline<
            P: IsA<Editable>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkEditable,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Editable::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::max-width-chars\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_max_width_chars_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_selection_bound_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_selection_bound_trampoline<
            P: IsA<Editable>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkEditable,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Editable::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::selection-bound\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_selection_bound_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_text_trampoline<P: IsA<Editable>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkEditable,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Editable::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::text\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_text_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_width_chars_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_width_chars_trampoline<
            P: IsA<Editable>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkEditable,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Editable::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::width-chars\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_width_chars_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_xalign_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_xalign_trampoline<P: IsA<Editable>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkEditable,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Editable::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::xalign\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_xalign_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for Editable {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("Editable")
    }
}