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
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
// 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::BracketMatchType;
use crate::ChangeCaseType;
use crate::Language;
use crate::Mark;
use crate::SortFlags;
use crate::StyleScheme;
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::transmute;

glib::wrapper! {
    pub struct Buffer(Object<ffi::GtkSourceBuffer, ffi::GtkSourceBufferClass>) @extends gtk::TextBuffer;

    match fn {
        get_type => || ffi::gtk_source_buffer_get_type(),
    }
}

impl Buffer {
    /// Creates a new source buffer.
    /// ## `table`
    /// a `gtk::TextTagTable`, or `None` to create a new one.
    ///
    /// # Returns
    ///
    /// a new source buffer.
    #[doc(alias = "gtk_source_buffer_new")]
    pub fn new(table: Option<&gtk::TextTagTable>) -> Buffer {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::gtk_source_buffer_new(table.to_glib_none().0)) }
    }

    #[doc(alias = "gtk_source_buffer_new_with_language")]
    pub fn with_language(language: &Language) -> Buffer {
        skip_assert_initialized!();
        unsafe {
            from_glib_full(ffi::gtk_source_buffer_new_with_language(
                language.to_glib_none().0,
            ))
        }
    }
}

#[derive(Clone, Default)]
pub struct BufferBuilder {
    highlight_matching_brackets: Option<bool>,
    highlight_syntax: Option<bool>,
    implicit_trailing_newline: Option<bool>,
    language: Option<Language>,
    style_scheme: Option<StyleScheme>,
    enable_undo: Option<bool>,
    tag_table: Option<gtk::TextTagTable>,
    text: Option<String>,
}

impl BufferBuilder {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn build(self) -> Buffer {
        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
        if let Some(ref highlight_matching_brackets) = self.highlight_matching_brackets {
            properties.push(("highlight-matching-brackets", highlight_matching_brackets));
        }
        if let Some(ref highlight_syntax) = self.highlight_syntax {
            properties.push(("highlight-syntax", highlight_syntax));
        }
        if let Some(ref implicit_trailing_newline) = self.implicit_trailing_newline {
            properties.push(("implicit-trailing-newline", implicit_trailing_newline));
        }
        if let Some(ref language) = self.language {
            properties.push(("language", language));
        }
        if let Some(ref style_scheme) = self.style_scheme {
            properties.push(("style-scheme", style_scheme));
        }
        if let Some(ref enable_undo) = self.enable_undo {
            properties.push(("enable-undo", enable_undo));
        }
        if let Some(ref tag_table) = self.tag_table {
            properties.push(("tag-table", tag_table));
        }
        if let Some(ref text) = self.text {
            properties.push(("text", text));
        }
        let ret = glib::Object::new::<Buffer>(&properties).expect("object new");
        ret
    }

    pub fn highlight_matching_brackets(mut self, highlight_matching_brackets: bool) -> Self {
        self.highlight_matching_brackets = Some(highlight_matching_brackets);
        self
    }

    pub fn highlight_syntax(mut self, highlight_syntax: bool) -> Self {
        self.highlight_syntax = Some(highlight_syntax);
        self
    }

    pub fn implicit_trailing_newline(mut self, implicit_trailing_newline: bool) -> Self {
        self.implicit_trailing_newline = Some(implicit_trailing_newline);
        self
    }

    pub fn language(mut self, language: &Language) -> Self {
        self.language = Some(language.clone());
        self
    }

    pub fn style_scheme(mut self, style_scheme: &StyleScheme) -> Self {
        self.style_scheme = Some(style_scheme.clone());
        self
    }

    pub fn enable_undo(mut self, enable_undo: bool) -> Self {
        self.enable_undo = Some(enable_undo);
        self
    }

    pub fn tag_table(mut self, tag_table: &gtk::TextTagTable) -> Self {
        self.tag_table = Some(tag_table.clone());
        self
    }

    pub fn text(mut self, text: &str) -> Self {
        self.text = Some(text.to_string());
        self
    }
}

pub const NONE_BUFFER: Option<&Buffer> = None;

/// Trait containing all `Buffer` methods.
///
/// # Implementors
///
/// [`Buffer`](struct.Buffer.html)
pub trait BufferExt: 'static {
    //#[doc(alias = "gtk_source_buffer_backward_iter_to_source_mark")]
    //fn backward_iter_to_source_mark(&self, iter: /*Unimplemented*/gtk::TextIter, category: Option<&str>) -> bool;

    /// Changes the case of the text between the specified iterators.
    /// ## `case_type`
    /// how to change the case.
    /// ## `start`
    /// a `gtk::TextIter`.
    /// ## `end`
    /// a `gtk::TextIter`.
    #[doc(alias = "gtk_source_buffer_change_case")]
    fn change_case(
        &self,
        case_type: ChangeCaseType,
        start: &mut gtk::TextIter,
        end: &mut gtk::TextIter,
    );

    /// Creates a source mark in the `self` of category `category`. A source mark is
    /// a `gtk::TextMark` but organised into categories. Depending on the category
    /// a pixbuf can be specified that will be displayed along the line of the mark.
    ///
    /// Like a `gtk::TextMark`, a `Mark` can be anonymous if the
    /// passed `name` is `None`. Also, the buffer owns the marks so you
    /// shouldn't unreference it.
    ///
    /// Marks always have left gravity and are moved to the beginning of
    /// the line when the user deletes the line they were in.
    ///
    /// Typical uses for a source mark are bookmarks, breakpoints, current
    /// executing instruction indication in a source file, etc..
    /// ## `name`
    /// the name of the mark, or `None`.
    /// ## `category`
    /// a string defining the mark category.
    /// ## `where_`
    /// location to place the mark.
    ///
    /// # Returns
    ///
    /// a new `Mark`, owned by the buffer.
    #[doc(alias = "gtk_source_buffer_create_source_mark")]
    fn create_source_mark(
        &self,
        name: Option<&str>,
        category: &str,
        where_: &gtk::TextIter,
    ) -> Option<Mark>;

    //#[doc(alias = "gtk_source_buffer_create_source_tag")]
    //fn create_source_tag(&self, tag_name: Option<&str>, first_property_name: Option<&str>, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Option<gtk::TextTag>;

    /// Forces buffer to analyze and highlight the given area synchronously.
    ///
    /// `<note>`
    ///  `<para>`
    ///  This is a potentially slow operation and should be used only
    ///  when you need to make sure that some text not currently
    ///  visible is highlighted, for instance before printing.
    ///  `</para>`
    /// `</note>`
    /// ## `start`
    /// start of the area to highlight.
    /// ## `end`
    /// end of the area to highlight.
    #[doc(alias = "gtk_source_buffer_ensure_highlight")]
    fn ensure_highlight(&self, start: &gtk::TextIter, end: &gtk::TextIter);

    //#[doc(alias = "gtk_source_buffer_forward_iter_to_source_mark")]
    //fn forward_iter_to_source_mark(&self, iter: /*Unimplemented*/gtk::TextIter, category: Option<&str>) -> bool;

    /// Get all defined context classes at `iter`.
    ///
    /// See the `Buffer` description for the list of default context classes.
    /// ## `iter`
    /// a `gtk::TextIter`.
    ///
    /// # Returns
    ///
    /// a new `None`
    /// terminated array of context class names.
    /// Use `g_strfreev` to free the array if it is no longer needed.
    #[doc(alias = "gtk_source_buffer_get_context_classes_at_iter")]
    fn get_context_classes_at_iter(&self, iter: &gtk::TextIter) -> Vec<glib::GString>;

    /// Determines whether bracket match highlighting is activated for the
    /// source buffer.
    ///
    /// # Returns
    ///
    /// `true` if the source buffer will highlight matching
    /// brackets.
    #[doc(alias = "gtk_source_buffer_get_highlight_matching_brackets")]
    fn get_highlight_matching_brackets(&self) -> bool;

    /// Determines whether syntax highlighting is activated in the source
    /// buffer.
    ///
    /// # Returns
    ///
    /// `true` if syntax highlighting is enabled, `false` otherwise.
    #[doc(alias = "gtk_source_buffer_get_highlight_syntax")]
    fn get_highlight_syntax(&self) -> bool;

    ///
    /// # Returns
    ///
    /// whether the `self` has an implicit trailing newline.
    #[doc(alias = "gtk_source_buffer_get_implicit_trailing_newline")]
    fn get_implicit_trailing_newline(&self) -> bool;

    /// Returns the `Language` associated with the buffer,
    /// see `BufferExt::set_language`. The returned object should not be
    /// unreferenced by the user.
    ///
    /// # Returns
    ///
    /// the `Language` associated
    /// with the buffer, or `None`.
    #[doc(alias = "gtk_source_buffer_get_language")]
    fn get_language(&self) -> Option<Language>;

    /// Returns the list of marks of the given category at `iter`. If `category`
    /// is `None` it returns all marks at `iter`.
    /// ## `iter`
    /// an iterator.
    /// ## `category`
    /// category to search for, or `None`
    ///
    /// # Returns
    ///
    ///
    /// a newly allocated `glib::SList`.
    #[doc(alias = "gtk_source_buffer_get_source_marks_at_iter")]
    fn get_source_marks_at_iter(
        &self,
        iter: &mut gtk::TextIter,
        category: Option<&str>,
    ) -> Vec<Mark>;

    /// Returns the list of marks of the given category at `line`.
    /// If `category` is `None`, all marks at `line` are returned.
    /// ## `line`
    /// a line number.
    /// ## `category`
    /// category to search for, or `None`
    ///
    /// # Returns
    ///
    ///
    /// a newly allocated `glib::SList`.
    #[doc(alias = "gtk_source_buffer_get_source_marks_at_line")]
    fn get_source_marks_at_line(&self, line: i32, category: Option<&str>) -> Vec<Mark>;

    /// Returns the `StyleScheme` associated with the buffer,
    /// see `BufferExt::set_style_scheme`.
    /// The returned object should not be unreferenced by the user.
    ///
    /// # Returns
    ///
    /// the `StyleScheme`
    /// associated with the buffer, or `None`.
    #[doc(alias = "gtk_source_buffer_get_style_scheme")]
    fn get_style_scheme(&self) -> Option<StyleScheme>;

    //#[doc(alias = "gtk_source_buffer_iter_backward_to_context_class_toggle")]
    //fn iter_backward_to_context_class_toggle(&self, iter: /*Unimplemented*/gtk::TextIter, context_class: &str) -> bool;

    //#[doc(alias = "gtk_source_buffer_iter_forward_to_context_class_toggle")]
    //fn iter_forward_to_context_class_toggle(&self, iter: /*Unimplemented*/gtk::TextIter, context_class: &str) -> bool;

    /// Check if the class `context_class` is set on `iter`.
    ///
    /// See the `Buffer` description for the list of default context classes.
    /// ## `iter`
    /// a `gtk::TextIter`.
    /// ## `context_class`
    /// class to search for.
    ///
    /// # Returns
    ///
    /// whether `iter` has the context class.
    #[doc(alias = "gtk_source_buffer_iter_has_context_class")]
    fn iter_has_context_class(&self, iter: &gtk::TextIter, context_class: &str) -> bool;

    /// Joins the lines of text between the specified iterators.
    /// ## `start`
    /// a `gtk::TextIter`.
    /// ## `end`
    /// a `gtk::TextIter`.
    #[doc(alias = "gtk_source_buffer_join_lines")]
    fn join_lines(&self, start: &mut gtk::TextIter, end: &mut gtk::TextIter);

    /// Remove all marks of `category` between `start` and `end` from the buffer.
    /// If `category` is NULL, all marks in the range will be removed.
    /// ## `start`
    /// a `gtk::TextIter`.
    /// ## `end`
    /// a `gtk::TextIter`.
    /// ## `category`
    /// category to search for, or `None`.
    #[doc(alias = "gtk_source_buffer_remove_source_marks")]
    fn remove_source_marks(
        &self,
        start: &gtk::TextIter,
        end: &gtk::TextIter,
        category: Option<&str>,
    );

    /// Controls the bracket match highlighting function in the buffer. If
    /// activated, when you position your cursor over a bracket character
    /// (a parenthesis, a square bracket, etc.) the matching opening or
    /// closing bracket character will be highlighted.
    /// ## `highlight`
    /// `true` if you want matching brackets highlighted.
    #[doc(alias = "gtk_source_buffer_set_highlight_matching_brackets")]
    fn set_highlight_matching_brackets(&self, highlight: bool);

    /// Controls whether syntax is highlighted in the buffer.
    ///
    /// If `highlight` is `true`, the text will be highlighted according to the syntax
    /// patterns specified in the `Language` set with
    /// `BufferExt::set_language`.
    ///
    /// If `highlight` is `false`, syntax highlighting is disabled and all the
    /// `gtk::TextTag` objects that have been added by the syntax highlighting engine
    /// are removed from the buffer.
    /// ## `highlight`
    /// `true` to enable syntax highlighting, `false` to disable it.
    #[doc(alias = "gtk_source_buffer_set_highlight_syntax")]
    fn set_highlight_syntax(&self, highlight: bool);

    /// Sets whether the `self` has an implicit trailing newline.
    ///
    /// If an explicit trailing newline is present in a `gtk::TextBuffer`, `gtk::TextView`
    /// shows it as an empty line. This is generally not what the user expects.
    ///
    /// If `implicit_trailing_newline` is `true` (the default value):
    ///  - when a `FileLoader` loads the content of a file into the `self`,
    ///  the trailing newline (if present in the file) is not inserted into the
    ///  `self`.
    ///  - when a `FileSaver` saves the content of the `self` into a file, a
    ///  trailing newline is added to the file.
    ///
    /// On the other hand, if `implicit_trailing_newline` is `false`, the file's
    /// content is not modified when loaded into the `self`, and the `self`'s
    /// content is not modified when saved into a file.
    /// ## `implicit_trailing_newline`
    /// the new value.
    #[doc(alias = "gtk_source_buffer_set_implicit_trailing_newline")]
    fn set_implicit_trailing_newline(&self, implicit_trailing_newline: bool);

    /// Associates a `Language` with the buffer.
    ///
    /// Note that a `Language` affects not only the syntax highlighting, but
    /// also the [context classes][context-classes]. If you want to disable just the
    /// syntax highlighting, see `BufferExt::set_highlight_syntax`.
    ///
    /// The buffer holds a reference to `language`.
    /// ## `language`
    /// a `Language` to set, or `None`.
    #[doc(alias = "gtk_source_buffer_set_language")]
    fn set_language(&self, language: Option<&Language>);

    /// Sets a `StyleScheme` to be used by the buffer and the view.
    ///
    /// Note that a `StyleScheme` affects not only the syntax highlighting,
    /// but also other `View` features such as highlighting the current line,
    /// matching brackets, the line numbers, etc.
    ///
    /// Instead of setting a `None` `scheme`, it is better to disable syntax
    /// highlighting with `BufferExt::set_highlight_syntax`, and setting the
    /// `StyleScheme` with the "classic" or "tango" ID, because those two
    /// style schemes follow more closely the GTK+ theme (for example for the
    /// background color).
    ///
    /// The buffer holds a reference to `scheme`.
    /// ## `scheme`
    /// a `StyleScheme` or `None`.
    #[doc(alias = "gtk_source_buffer_set_style_scheme")]
    fn set_style_scheme(&self, scheme: Option<&StyleScheme>);

    /// Sort the lines of text between the specified iterators.
    /// ## `start`
    /// a `gtk::TextIter`.
    /// ## `end`
    /// a `gtk::TextIter`.
    /// ## `flags`
    /// `SortFlags` specifying how the sort should behave
    /// ## `column`
    /// sort considering the text starting at the given column
    #[doc(alias = "gtk_source_buffer_sort_lines")]
    fn sort_lines(
        &self,
        start: &mut gtk::TextIter,
        end: &mut gtk::TextIter,
        flags: SortFlags,
        column: i32,
    );

    /// `iter` is set to a valid iterator pointing to the matching bracket
    /// if `state` is `BracketMatchType::Found`. Otherwise `iter` is
    /// meaningless.
    ///
    /// The signal is emitted only when the `state` changes, typically when
    /// the cursor moves.
    ///
    /// A use-case for this signal is to show messages in a `gtk::Statusbar`.
    /// ## `iter`
    /// if found, the location of the matching bracket.
    /// ## `state`
    /// state of bracket matching.
    fn connect_bracket_matched<F: Fn(&Self, Option<&gtk::TextIter>, BracketMatchType) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId;

    /// The "cursor-moved" signal is emitted when then insertion mark has moved.
    ///
    /// Feature: `v5_0`
    ///
    #[cfg(any(feature = "v5_0", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v5_0")))]
    fn connect_cursor_moved<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    /// The ::highlight-updated signal is emitted when the syntax
    /// highlighting and [context classes][context-classes] are updated in a
    /// certain region of the `buffer`.
    /// ## `start`
    /// the start of the updated region
    /// ## `end`
    /// the end of the updated region
    fn connect_highlight_updated<F: Fn(&Self, &gtk::TextIter, &gtk::TextIter) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId;

    /// The ::source-mark-updated signal is emitted each time
    /// a mark is added to, moved or removed from the `buffer`.
    /// ## `mark`
    /// the `Mark`
    fn connect_source_mark_updated<F: Fn(&Self, &gtk::TextMark) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId;

    fn connect_property_highlight_matching_brackets_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId;

    fn connect_property_highlight_syntax_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId;

    fn connect_property_implicit_trailing_newline_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId;

    fn connect_property_language_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_style_scheme_notify<F: Fn(&Self) + 'static>(&self, f: F)
        -> SignalHandlerId;
}

impl<O: IsA<Buffer>> BufferExt for O {
    //fn backward_iter_to_source_mark(&self, iter: /*Unimplemented*/gtk::TextIter, category: Option<&str>) -> bool {
    //    unsafe { TODO: call ffi:gtk_source_buffer_backward_iter_to_source_mark() }
    //}

    fn change_case(
        &self,
        case_type: ChangeCaseType,
        start: &mut gtk::TextIter,
        end: &mut gtk::TextIter,
    ) {
        unsafe {
            ffi::gtk_source_buffer_change_case(
                self.as_ref().to_glib_none().0,
                case_type.to_glib(),
                start.to_glib_none_mut().0,
                end.to_glib_none_mut().0,
            );
        }
    }

    fn create_source_mark(
        &self,
        name: Option<&str>,
        category: &str,
        where_: &gtk::TextIter,
    ) -> Option<Mark> {
        unsafe {
            from_glib_none(ffi::gtk_source_buffer_create_source_mark(
                self.as_ref().to_glib_none().0,
                name.to_glib_none().0,
                category.to_glib_none().0,
                where_.to_glib_none().0,
            ))
        }
    }

    //fn create_source_tag(&self, tag_name: Option<&str>, first_property_name: Option<&str>, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Option<gtk::TextTag> {
    //    unsafe { TODO: call ffi:gtk_source_buffer_create_source_tag() }
    //}

    fn ensure_highlight(&self, start: &gtk::TextIter, end: &gtk::TextIter) {
        unsafe {
            ffi::gtk_source_buffer_ensure_highlight(
                self.as_ref().to_glib_none().0,
                start.to_glib_none().0,
                end.to_glib_none().0,
            );
        }
    }

    //fn forward_iter_to_source_mark(&self, iter: /*Unimplemented*/gtk::TextIter, category: Option<&str>) -> bool {
    //    unsafe { TODO: call ffi:gtk_source_buffer_forward_iter_to_source_mark() }
    //}

    fn get_context_classes_at_iter(&self, iter: &gtk::TextIter) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(
                ffi::gtk_source_buffer_get_context_classes_at_iter(
                    self.as_ref().to_glib_none().0,
                    iter.to_glib_none().0,
                ),
            )
        }
    }

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

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

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

    fn get_language(&self) -> Option<Language> {
        unsafe {
            from_glib_none(ffi::gtk_source_buffer_get_language(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_source_marks_at_iter(
        &self,
        iter: &mut gtk::TextIter,
        category: Option<&str>,
    ) -> Vec<Mark> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(
                ffi::gtk_source_buffer_get_source_marks_at_iter(
                    self.as_ref().to_glib_none().0,
                    iter.to_glib_none_mut().0,
                    category.to_glib_none().0,
                ),
            )
        }
    }

    fn get_source_marks_at_line(&self, line: i32, category: Option<&str>) -> Vec<Mark> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(
                ffi::gtk_source_buffer_get_source_marks_at_line(
                    self.as_ref().to_glib_none().0,
                    line,
                    category.to_glib_none().0,
                ),
            )
        }
    }

    fn get_style_scheme(&self) -> Option<StyleScheme> {
        unsafe {
            from_glib_none(ffi::gtk_source_buffer_get_style_scheme(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    //fn iter_backward_to_context_class_toggle(&self, iter: /*Unimplemented*/gtk::TextIter, context_class: &str) -> bool {
    //    unsafe { TODO: call ffi:gtk_source_buffer_iter_backward_to_context_class_toggle() }
    //}

    //fn iter_forward_to_context_class_toggle(&self, iter: /*Unimplemented*/gtk::TextIter, context_class: &str) -> bool {
    //    unsafe { TODO: call ffi:gtk_source_buffer_iter_forward_to_context_class_toggle() }
    //}

    fn iter_has_context_class(&self, iter: &gtk::TextIter, context_class: &str) -> bool {
        unsafe {
            from_glib(ffi::gtk_source_buffer_iter_has_context_class(
                self.as_ref().to_glib_none().0,
                iter.to_glib_none().0,
                context_class.to_glib_none().0,
            ))
        }
    }

    fn join_lines(&self, start: &mut gtk::TextIter, end: &mut gtk::TextIter) {
        unsafe {
            ffi::gtk_source_buffer_join_lines(
                self.as_ref().to_glib_none().0,
                start.to_glib_none_mut().0,
                end.to_glib_none_mut().0,
            );
        }
    }

    fn remove_source_marks(
        &self,
        start: &gtk::TextIter,
        end: &gtk::TextIter,
        category: Option<&str>,
    ) {
        unsafe {
            ffi::gtk_source_buffer_remove_source_marks(
                self.as_ref().to_glib_none().0,
                start.to_glib_none().0,
                end.to_glib_none().0,
                category.to_glib_none().0,
            );
        }
    }

    fn set_highlight_matching_brackets(&self, highlight: bool) {
        unsafe {
            ffi::gtk_source_buffer_set_highlight_matching_brackets(
                self.as_ref().to_glib_none().0,
                highlight.to_glib(),
            );
        }
    }

    fn set_highlight_syntax(&self, highlight: bool) {
        unsafe {
            ffi::gtk_source_buffer_set_highlight_syntax(
                self.as_ref().to_glib_none().0,
                highlight.to_glib(),
            );
        }
    }

    fn set_implicit_trailing_newline(&self, implicit_trailing_newline: bool) {
        unsafe {
            ffi::gtk_source_buffer_set_implicit_trailing_newline(
                self.as_ref().to_glib_none().0,
                implicit_trailing_newline.to_glib(),
            );
        }
    }

    fn set_language(&self, language: Option<&Language>) {
        unsafe {
            ffi::gtk_source_buffer_set_language(
                self.as_ref().to_glib_none().0,
                language.to_glib_none().0,
            );
        }
    }

    fn set_style_scheme(&self, scheme: Option<&StyleScheme>) {
        unsafe {
            ffi::gtk_source_buffer_set_style_scheme(
                self.as_ref().to_glib_none().0,
                scheme.to_glib_none().0,
            );
        }
    }

    fn sort_lines(
        &self,
        start: &mut gtk::TextIter,
        end: &mut gtk::TextIter,
        flags: SortFlags,
        column: i32,
    ) {
        unsafe {
            ffi::gtk_source_buffer_sort_lines(
                self.as_ref().to_glib_none().0,
                start.to_glib_none_mut().0,
                end.to_glib_none_mut().0,
                flags.to_glib(),
                column,
            );
        }
    }

    fn connect_bracket_matched<F: Fn(&Self, Option<&gtk::TextIter>, BracketMatchType) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn bracket_matched_trampoline<
            P,
            F: Fn(&P, Option<&gtk::TextIter>, BracketMatchType) + 'static,
        >(
            this: *mut ffi::GtkSourceBuffer,
            iter: *mut gtk::ffi::GtkTextIter,
            state: ffi::GtkSourceBracketMatchType,
            f: glib::ffi::gpointer,
        ) where
            P: IsA<Buffer>,
        {
            let f: &F = &*(f as *const F);
            f(
                &Buffer::from_glib_borrow(this).unsafe_cast_ref(),
                Option::<gtk::TextIter>::from_glib_borrow(iter)
                    .as_ref()
                    .as_ref(),
                from_glib(state),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"bracket-matched\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    bracket_matched_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(any(feature = "v5_0", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v5_0")))]
    fn connect_cursor_moved<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn cursor_moved_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkSourceBuffer,
            f: glib::ffi::gpointer,
        ) where
            P: IsA<Buffer>,
        {
            let f: &F = &*(f as *const F);
            f(&Buffer::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"cursor-moved\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    cursor_moved_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_highlight_updated<F: Fn(&Self, &gtk::TextIter, &gtk::TextIter) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn highlight_updated_trampoline<
            P,
            F: Fn(&P, &gtk::TextIter, &gtk::TextIter) + 'static,
        >(
            this: *mut ffi::GtkSourceBuffer,
            start: *mut gtk::ffi::GtkTextIter,
            end: *mut gtk::ffi::GtkTextIter,
            f: glib::ffi::gpointer,
        ) where
            P: IsA<Buffer>,
        {
            let f: &F = &*(f as *const F);
            f(
                &Buffer::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(start),
                &from_glib_borrow(end),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"highlight-updated\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    highlight_updated_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_source_mark_updated<F: Fn(&Self, &gtk::TextMark) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn source_mark_updated_trampoline<
            P,
            F: Fn(&P, &gtk::TextMark) + 'static,
        >(
            this: *mut ffi::GtkSourceBuffer,
            mark: *mut gtk::ffi::GtkTextMark,
            f: glib::ffi::gpointer,
        ) where
            P: IsA<Buffer>,
        {
            let f: &F = &*(f as *const F);
            f(
                &Buffer::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(mark),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"source-mark-updated\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    source_mark_updated_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

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

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

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

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

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

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