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
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
// 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 gdk;
use glib;
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::StaticType;
use glib::ToValue;
use glib::Value;
use glib_sys;
use gobject_sys;
use gtk_sys;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;
use Border;
use CssSection;
use JunctionSides;
use StateFlags;
#[cfg(any(feature = "v3_20", feature = "dox"))]
use StyleContextPrintFlags;
use StyleProvider;
use TextDirection;
use WidgetPath;

glib_wrapper! {
    /// `StyleContext` is an object that stores styling information affecting
    /// a widget defined by `WidgetPath`.
    ///
    /// In order to construct the final style information, `StyleContext`
    /// queries information from all attached ``GtkStyleProviders``. Style providers
    /// can be either attached explicitly to the context through
    /// `StyleContextExt::add_provider`, or to the screen through
    /// `StyleContext::add_provider_for_screen`. The resulting style is a
    /// combination of all providers’ information in priority order.
    ///
    /// For GTK+ widgets, any `StyleContext` returned by
    /// `WidgetExt::get_style_context` will already have a `WidgetPath`, a
    /// `gdk::Screen` and RTL/LTR information set. The style context will also be
    /// updated automatically if any of these settings change on the widget.
    ///
    /// If you are using the theming layer standalone, you will need to set a
    /// widget path and a screen yourself to the created style context through
    /// `StyleContextExt::set_path` and possibly `StyleContextExt::set_screen`. See
    /// the “Foreign drawing“ example in gtk3-demo.
    ///
    /// # Style Classes # {`gtkstylecontext`-classes}
    ///
    /// Widgets can add style classes to their context, which can be used to associate
    /// different styles by class. The documentation for individual widgets lists
    /// which style classes it uses itself, and which style classes may be added by
    /// applications to affect their appearance.
    ///
    /// GTK+ defines macros for a number of style classes.
    ///
    /// # Style Regions
    ///
    /// Widgets can also add regions with flags to their context. This feature is
    /// deprecated and will be removed in a future GTK+ update. Please use style
    /// classes instead.
    ///
    /// GTK+ defines macros for a number of style regions.
    ///
    /// # Custom styling in UI libraries and applications
    ///
    /// If you are developing a library with custom ``GtkWidgets`` that
    /// render differently than standard components, you may need to add a
    /// `StyleProvider` yourself with the `GTK_STYLE_PROVIDER_PRIORITY_FALLBACK`
    /// priority, either a `CssProvider` or a custom object implementing the
    /// `StyleProvider` interface. This way themes may still attempt
    /// to style your UI elements in a different way if needed so.
    ///
    /// If you are using custom styling on an applications, you probably want then
    /// to make your style information prevail to the theme’s, so you must use
    /// a `StyleProvider` with the `GTK_STYLE_PROVIDER_PRIORITY_APPLICATION`
    /// priority, keep in mind that the user settings in
    /// `XDG_CONFIG_HOME/gtk-3.0/gtk.css` will
    /// still take precedence over your changes, as it uses the
    /// `GTK_STYLE_PROVIDER_PRIORITY_USER` priority.
    ///
    /// # Implements
    ///
    /// [`StyleContextExt`](trait.StyleContextExt.html), [`glib::object::ObjectExt`](../glib/object/trait.ObjectExt.html), [`StyleContextExtManual`](prelude/trait.StyleContextExtManual.html)
    pub struct StyleContext(Object<gtk_sys::GtkStyleContext, gtk_sys::GtkStyleContextClass, StyleContextClass>);

    match fn {
        get_type => || gtk_sys::gtk_style_context_get_type(),
    }
}

impl StyleContext {
    /// Creates a standalone `StyleContext`, this style context
    /// won’t be attached to any widget, so you may want
    /// to call `StyleContextExt::set_path` yourself.
    ///
    /// This function is only useful when using the theming layer
    /// separated from GTK+, if you are using `StyleContext` to
    /// theme ``GtkWidgets``, use `WidgetExt::get_style_context`
    /// in order to get a style context ready to theme the widget.
    ///
    /// # Returns
    ///
    /// A newly created `StyleContext`.
    pub fn new() -> StyleContext {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(gtk_sys::gtk_style_context_new()) }
    }

    /// Adds a global style provider to `screen`, which will be used
    /// in style construction for all ``GtkStyleContexts`` under `screen`.
    ///
    /// GTK+ uses this to make styling information from `Settings`
    /// available.
    ///
    /// Note: If both priorities are the same, A `StyleProvider`
    /// added through `StyleContextExt::add_provider` takes precedence
    /// over another added through this function.
    /// ## `screen`
    /// a `gdk::Screen`
    /// ## `provider`
    /// a `StyleProvider`
    /// ## `priority`
    /// the priority of the style provider. The lower
    ///  it is, the earlier it will be used in the style
    ///  construction. Typically this will be in the range
    ///  between `GTK_STYLE_PROVIDER_PRIORITY_FALLBACK` and
    ///  `GTK_STYLE_PROVIDER_PRIORITY_USER`
    pub fn add_provider_for_screen<P: IsA<StyleProvider>>(
        screen: &gdk::Screen,
        provider: &P,
        priority: u32,
    ) {
        skip_assert_initialized!();
        unsafe {
            gtk_sys::gtk_style_context_add_provider_for_screen(
                screen.to_glib_none().0,
                provider.as_ref().to_glib_none().0,
                priority,
            );
        }
    }

    /// Removes `provider` from the global style providers list in `screen`.
    /// ## `screen`
    /// a `gdk::Screen`
    /// ## `provider`
    /// a `StyleProvider`
    pub fn remove_provider_for_screen<P: IsA<StyleProvider>>(screen: &gdk::Screen, provider: &P) {
        skip_assert_initialized!();
        unsafe {
            gtk_sys::gtk_style_context_remove_provider_for_screen(
                screen.to_glib_none().0,
                provider.as_ref().to_glib_none().0,
            );
        }
    }

    /// This function recomputes the styles for all widgets under a particular
    /// `gdk::Screen`. This is useful when some global parameter has changed that
    /// affects the appearance of all widgets, because when a widget gets a new
    /// style, it will both redraw and recompute any cached information about
    /// its appearance. As an example, it is used when the color scheme changes
    /// in the related `Settings` object.
    /// ## `screen`
    /// a `gdk::Screen`
    pub fn reset_widgets(screen: &gdk::Screen) {
        assert_initialized_main_thread!();
        unsafe {
            gtk_sys::gtk_style_context_reset_widgets(screen.to_glib_none().0);
        }
    }
}

impl Default for StyleContext {
    fn default() -> Self {
        Self::new()
    }
}

#[derive(Clone, Default)]
pub struct StyleContextBuilder {
    direction: Option<TextDirection>,
    paint_clock: Option<gdk::FrameClock>,
    parent: Option<StyleContext>,
    screen: Option<gdk::Screen>,
}

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

    pub fn build(self) -> StyleContext {
        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
        if let Some(ref direction) = self.direction {
            properties.push(("direction", direction));
        }
        if let Some(ref paint_clock) = self.paint_clock {
            properties.push(("paint-clock", paint_clock));
        }
        if let Some(ref parent) = self.parent {
            properties.push(("parent", parent));
        }
        if let Some(ref screen) = self.screen {
            properties.push(("screen", screen));
        }
        let ret = glib::Object::new(StyleContext::static_type(), &properties)
            .expect("object new")
            .downcast::<StyleContext>()
            .expect("downcast");
        ret
    }

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

    pub fn paint_clock(mut self, paint_clock: &gdk::FrameClock) -> Self {
        self.paint_clock = Some(paint_clock.clone());
        self
    }

    pub fn parent<P: IsA<StyleContext>>(mut self, parent: &P) -> Self {
        self.parent = Some(parent.clone().upcast());
        self
    }

    pub fn screen(mut self, screen: &gdk::Screen) -> Self {
        self.screen = Some(screen.clone());
        self
    }
}

pub const NONE_STYLE_CONTEXT: Option<&StyleContext> = None;

/// Trait containing all `StyleContext` methods.
///
/// # Implementors
///
/// [`StyleContext`](struct.StyleContext.html)
pub trait StyleContextExt: 'static {
    /// Adds a style class to `self`, so posterior calls to
    /// `StyleContextExt::get` or any of the gtk_render_*()
    /// functions will make use of this new class for styling.
    ///
    /// In the CSS file format, a `Entry` defining a “search”
    /// class, would be matched by:
    ///
    ///
    /// ```CSS
    /// entry.search { ... }
    /// ```
    ///
    /// While any widget defining a “search” class would be
    /// matched by:
    ///
    /// ```CSS
    /// .search { ... }
    /// ```
    /// ## `class_name`
    /// class name to use in styling
    fn add_class(&self, class_name: &str);

    /// Adds a style provider to `self`, to be used in style construction.
    /// Note that a style provider added by this function only affects
    /// the style of the widget to which `self` belongs. If you want
    /// to affect the style of all widgets, use
    /// `StyleContext::add_provider_for_screen`.
    ///
    /// Note: If both priorities are the same, a `StyleProvider`
    /// added through this function takes precedence over another added
    /// through `StyleContext::add_provider_for_screen`.
    /// ## `provider`
    /// a `StyleProvider`
    /// ## `priority`
    /// the priority of the style provider. The lower
    ///  it is, the earlier it will be used in the style
    ///  construction. Typically this will be in the range
    ///  between `GTK_STYLE_PROVIDER_PRIORITY_FALLBACK` and
    ///  `GTK_STYLE_PROVIDER_PRIORITY_USER`
    fn add_provider<P: IsA<StyleProvider>>(&self, provider: &P, priority: u32);

    //fn get(&self, state: StateFlags, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);

    /// Gets the background color for a given state.
    ///
    /// This function is far less useful than it seems, and it should not be used in
    /// newly written code. CSS has no concept of "background color", as a background
    /// can be an image, or a gradient, or any other pattern including solid colors.
    ///
    /// The only reason why you would call `StyleContextExt::get_background_color` is
    /// to use the returned value to draw the background with it; the correct way to
    /// achieve this result is to use `gtk_render_background` instead, along with CSS
    /// style classes to modify the color to be rendered.
    ///
    /// # Deprecated since 3.16
    ///
    /// Use `gtk_render_background` instead.
    /// ## `state`
    /// state to retrieve the color for
    /// ## `color`
    /// return value for the background color
    #[cfg_attr(feature = "v3_16", deprecated)]
    fn get_background_color(&self, state: StateFlags) -> gdk::RGBA;

    /// Gets the border for a given state as a `Border`.
    ///
    /// See `StyleContextExt::get_property` and
    /// `GTK_STYLE_PROPERTY_BORDER_WIDTH` for details.
    /// ## `state`
    /// state to retrieve the border for
    /// ## `border`
    /// return value for the border settings
    fn get_border(&self, state: StateFlags) -> Border;

    /// Gets the border color for a given state.
    ///
    /// # Deprecated since 3.16
    ///
    /// Use `gtk_render_frame` instead.
    /// ## `state`
    /// state to retrieve the color for
    /// ## `color`
    /// return value for the border color
    #[cfg_attr(feature = "v3_16", deprecated)]
    fn get_border_color(&self, state: StateFlags) -> gdk::RGBA;

    /// Gets the foreground color for a given state.
    ///
    /// See `StyleContextExt::get_property` and
    /// `GTK_STYLE_PROPERTY_COLOR` for details.
    /// ## `state`
    /// state to retrieve the color for
    /// ## `color`
    /// return value for the foreground color
    fn get_color(&self, state: StateFlags) -> gdk::RGBA;

    /// Returns the `gdk::FrameClock` to which `self` is attached.
    ///
    /// # Returns
    ///
    /// a `gdk::FrameClock`, or `None`
    ///  if `self` does not have an attached frame clock.
    fn get_frame_clock(&self) -> Option<gdk::FrameClock>;

    /// Returns the sides where rendered elements connect visually with others.
    ///
    /// # Returns
    ///
    /// the junction sides
    fn get_junction_sides(&self) -> JunctionSides;

    /// Gets the margin for a given state as a `Border`.
    /// See `gtk_style_property_get` and `GTK_STYLE_PROPERTY_MARGIN`
    /// for details.
    /// ## `state`
    /// state to retrieve the border for
    /// ## `margin`
    /// return value for the margin settings
    fn get_margin(&self, state: StateFlags) -> Border;

    /// Gets the padding for a given state as a `Border`.
    /// See `StyleContextExt::get` and `GTK_STYLE_PROPERTY_PADDING`
    /// for details.
    /// ## `state`
    /// state to retrieve the padding for
    /// ## `padding`
    /// return value for the padding settings
    fn get_padding(&self, state: StateFlags) -> Border;

    /// Gets the parent context set via `StyleContextExt::set_parent`.
    /// See that function for details.
    ///
    /// # Returns
    ///
    /// the parent context or `None`
    fn get_parent(&self) -> Option<StyleContext>;

    /// Returns the widget path used for style matching.
    ///
    /// # Returns
    ///
    /// A `WidgetPath`
    fn get_path(&self) -> Option<WidgetPath>;

    /// Gets a style property from `self` for the given state.
    ///
    /// Note that not all CSS properties that are supported by GTK+ can be
    /// retrieved in this way, since they may not be representable as `gobject::Value`.
    /// GTK+ defines macros for a number of properties that can be used
    /// with this function.
    ///
    /// Note that passing a state other than the current state of `self`
    /// is not recommended unless the style context has been saved with
    /// `StyleContextExt::save`.
    ///
    /// When `value` is no longer needed, `gobject::Value::unset` must be called
    /// to free any allocated memory.
    /// ## `property`
    /// style property name
    /// ## `state`
    /// state to retrieve the property value for
    /// ## `value`
    /// return location for the style property value
    fn get_property(&self, property: &str, state: StateFlags) -> glib::Value;

    /// Returns the scale used for assets.
    ///
    /// # Returns
    ///
    /// the scale
    fn get_scale(&self) -> i32;

    /// Returns the `gdk::Screen` to which `self` is attached.
    ///
    /// # Returns
    ///
    /// a `gdk::Screen`.
    fn get_screen(&self) -> Option<gdk::Screen>;

    /// Queries the location in the CSS where `property` was defined for the
    /// current `self`. Note that the state to be queried is taken from
    /// `StyleContextExt::get_state`.
    ///
    /// If the location is not available, `None` will be returned. The
    /// location might not be available for various reasons, such as the
    /// property being overridden, `property` not naming a supported CSS
    /// property or tracking of definitions being disabled for performance
    /// reasons.
    ///
    /// Shorthand CSS properties cannot be queried for a location and will
    /// always return `None`.
    /// ## `property`
    /// style property name
    ///
    /// # Returns
    ///
    /// `None` or the section where a value
    /// for `property` was defined
    fn get_section(&self, property: &str) -> Option<CssSection>;

    /// Returns the state used for style matching.
    ///
    /// This method should only be used to retrieve the `StateFlags`
    /// to pass to `StyleContext` methods, like `StyleContextExt::get_padding`.
    /// If you need to retrieve the current state of a `Widget`, use
    /// `WidgetExt::get_state_flags`.
    ///
    /// # Returns
    ///
    /// the state flags
    fn get_state(&self) -> StateFlags;

    //fn get_style(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);

    /// Gets the value for a widget style property.
    ///
    /// When `value` is no longer needed, `gobject::Value::unset` must be called
    /// to free any allocated memory.
    /// ## `property_name`
    /// the name of the widget style property
    /// ## `value`
    /// Return location for the property value
    fn get_style_property(&self, property_name: &str) -> glib::Value;

    //fn get_style_valist(&self, args: /*Unknown conversion*//*Unimplemented*/Unsupported);

    //fn get_valist(&self, state: StateFlags, args: /*Unknown conversion*//*Unimplemented*/Unsupported);

    /// Returns `true` if `self` currently has defined the
    /// given class name.
    /// ## `class_name`
    /// a class name
    ///
    /// # Returns
    ///
    /// `true` if `self` has `class_name` defined
    fn has_class(&self, class_name: &str) -> bool;

    /// Returns the list of classes currently defined in `self`.
    ///
    /// # Returns
    ///
    /// a `glib::List` of
    ///  strings with the currently defined classes. The contents
    ///  of the list are owned by GTK+, but you must free the list
    ///  itself with `glib::List::free` when you are done with it.
    fn list_classes(&self) -> Vec<GString>;

    /// Looks up and resolves a color name in the `self` color map.
    /// ## `color_name`
    /// color name to lookup
    /// ## `color`
    /// Return location for the looked up color
    ///
    /// # Returns
    ///
    /// `true` if `color_name` was found and resolved, `false` otherwise
    fn lookup_color(&self, color_name: &str) -> Option<gdk::RGBA>;

    /// Removes `class_name` from `self`.
    /// ## `class_name`
    /// class name to remove
    fn remove_class(&self, class_name: &str);

    /// Removes `provider` from the style providers list in `self`.
    /// ## `provider`
    /// a `StyleProvider`
    fn remove_provider<P: IsA<StyleProvider>>(&self, provider: &P);

    /// Restores `self` state to a previous stage.
    /// See `StyleContextExt::save`.
    fn restore(&self);

    /// Saves the `self` state, so temporary modifications done through
    /// `StyleContextExt::add_class`, `StyleContextExt::remove_class`,
    /// `StyleContextExt::set_state`, etc. can quickly be reverted
    /// in one go through `StyleContextExt::restore`.
    ///
    /// The matching call to `StyleContextExt::restore` must be done
    /// before GTK returns to the main loop.
    fn save(&self);

    /// Sets the background of `window` to the background pattern or
    /// color specified in `self` for its current state.
    ///
    /// # Deprecated since 3.18
    ///
    /// Use `gtk_render_background` instead.
    ///  Note that clients still using this function are now responsible
    ///  for calling this function again whenever `self` is invalidated.
    /// ## `window`
    /// a `gdk::Window`
    #[cfg_attr(feature = "v3_18", deprecated)]
    fn set_background<P: IsA<gdk::Window>>(&self, window: &P);

    /// Attaches `self` to the given frame clock.
    ///
    /// The frame clock is used for the timing of animations.
    ///
    /// If you are using a `StyleContext` returned from
    /// `WidgetExt::get_style_context`, you do not need to
    /// call this yourself.
    /// ## `frame_clock`
    /// a `gdk::FrameClock`
    fn set_frame_clock(&self, frame_clock: &gdk::FrameClock);

    /// Sets the sides where rendered elements (mostly through
    /// `gtk_render_frame`) will visually connect with other visual elements.
    ///
    /// This is merely a hint that may or may not be honored
    /// by themes.
    ///
    /// Container widgets are expected to set junction hints as appropriate
    /// for their children, so it should not normally be necessary to call
    /// this function manually.
    /// ## `sides`
    /// sides where rendered elements are visually connected to
    ///  other elements
    fn set_junction_sides(&self, sides: JunctionSides);

    /// Sets the parent style context for `self`. The parent style
    /// context is used to implement
    /// [inheritance](http://www.w3.org/TR/css3-cascade/`inheritance`)
    /// of properties.
    ///
    /// If you are using a `StyleContext` returned from
    /// `WidgetExt::get_style_context`, the parent will be set for you.
    /// ## `parent`
    /// the new parent or `None`
    fn set_parent<P: IsA<StyleContext>>(&self, parent: Option<&P>);

    /// Sets the `WidgetPath` used for style matching. As a
    /// consequence, the style will be regenerated to match
    /// the new given path.
    ///
    /// If you are using a `StyleContext` returned from
    /// `WidgetExt::get_style_context`, you do not need to call
    /// this yourself.
    /// ## `path`
    /// a `WidgetPath`
    fn set_path(&self, path: &WidgetPath);

    /// Sets the scale to use when getting image assets for the style.
    /// ## `scale`
    /// scale
    fn set_scale(&self, scale: i32);

    /// Attaches `self` to the given screen.
    ///
    /// The screen is used to add style information from “global” style
    /// providers, such as the screen’s `Settings` instance.
    ///
    /// If you are using a `StyleContext` returned from
    /// `WidgetExt::get_style_context`, you do not need to
    /// call this yourself.
    /// ## `screen`
    /// a `gdk::Screen`
    fn set_screen(&self, screen: &gdk::Screen);

    /// Sets the state to be used for style matching.
    /// ## `flags`
    /// state to represent
    fn set_state(&self, flags: StateFlags);

    /// Converts the style context into a string representation.
    ///
    /// The string representation always includes information about
    /// the name, state, id, visibility and style classes of the CSS
    /// node that is backing `self`. Depending on the flags, more
    /// information may be included.
    ///
    /// This function is intended for testing and debugging of the
    /// CSS implementation in GTK+. There are no guarantees about
    /// the format of the returned string, it may change.
    ///
    /// Feature: `v3_20`
    ///
    /// ## `flags`
    /// Flags that determine what to print
    ///
    /// # Returns
    ///
    /// a newly allocated string representing `self`
    #[cfg(any(feature = "v3_20", feature = "dox"))]
    fn to_string(&self, flags: StyleContextPrintFlags) -> GString;

    fn get_property_direction(&self) -> TextDirection;

    fn set_property_direction(&self, direction: TextDirection);

    fn get_property_paint_clock(&self) -> Option<gdk::FrameClock>;

    fn set_property_paint_clock(&self, paint_clock: Option<&gdk::FrameClock>);

    /// The ::changed signal is emitted when there is a change in the
    /// `StyleContext`.
    ///
    /// For a `StyleContext` returned by `WidgetExt::get_style_context`, the
    /// `Widget::style-updated` signal/vfunc might be more convenient to use.
    ///
    /// This signal is useful when using the theming layer standalone.
    fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

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

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

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

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

impl<O: IsA<StyleContext>> StyleContextExt for O {
    fn add_class(&self, class_name: &str) {
        unsafe {
            gtk_sys::gtk_style_context_add_class(
                self.as_ref().to_glib_none().0,
                class_name.to_glib_none().0,
            );
        }
    }

    fn add_provider<P: IsA<StyleProvider>>(&self, provider: &P, priority: u32) {
        unsafe {
            gtk_sys::gtk_style_context_add_provider(
                self.as_ref().to_glib_none().0,
                provider.as_ref().to_glib_none().0,
                priority,
            );
        }
    }

    //fn get(&self, state: StateFlags, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
    //    unsafe { TODO: call gtk_sys:gtk_style_context_get() }
    //}

    fn get_background_color(&self, state: StateFlags) -> gdk::RGBA {
        unsafe {
            let mut color = gdk::RGBA::uninitialized();
            gtk_sys::gtk_style_context_get_background_color(
                self.as_ref().to_glib_none().0,
                state.to_glib(),
                color.to_glib_none_mut().0,
            );
            color
        }
    }

    fn get_border(&self, state: StateFlags) -> Border {
        unsafe {
            let mut border = Border::uninitialized();
            gtk_sys::gtk_style_context_get_border(
                self.as_ref().to_glib_none().0,
                state.to_glib(),
                border.to_glib_none_mut().0,
            );
            border
        }
    }

    fn get_border_color(&self, state: StateFlags) -> gdk::RGBA {
        unsafe {
            let mut color = gdk::RGBA::uninitialized();
            gtk_sys::gtk_style_context_get_border_color(
                self.as_ref().to_glib_none().0,
                state.to_glib(),
                color.to_glib_none_mut().0,
            );
            color
        }
    }

    fn get_color(&self, state: StateFlags) -> gdk::RGBA {
        unsafe {
            let mut color = gdk::RGBA::uninitialized();
            gtk_sys::gtk_style_context_get_color(
                self.as_ref().to_glib_none().0,
                state.to_glib(),
                color.to_glib_none_mut().0,
            );
            color
        }
    }

    fn get_frame_clock(&self) -> Option<gdk::FrameClock> {
        unsafe {
            from_glib_none(gtk_sys::gtk_style_context_get_frame_clock(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_junction_sides(&self) -> JunctionSides {
        unsafe {
            from_glib(gtk_sys::gtk_style_context_get_junction_sides(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_margin(&self, state: StateFlags) -> Border {
        unsafe {
            let mut margin = Border::uninitialized();
            gtk_sys::gtk_style_context_get_margin(
                self.as_ref().to_glib_none().0,
                state.to_glib(),
                margin.to_glib_none_mut().0,
            );
            margin
        }
    }

    fn get_padding(&self, state: StateFlags) -> Border {
        unsafe {
            let mut padding = Border::uninitialized();
            gtk_sys::gtk_style_context_get_padding(
                self.as_ref().to_glib_none().0,
                state.to_glib(),
                padding.to_glib_none_mut().0,
            );
            padding
        }
    }

    fn get_parent(&self) -> Option<StyleContext> {
        unsafe {
            from_glib_none(gtk_sys::gtk_style_context_get_parent(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_path(&self) -> Option<WidgetPath> {
        unsafe {
            from_glib_none(gtk_sys::gtk_style_context_get_path(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_property(&self, property: &str, state: StateFlags) -> glib::Value {
        unsafe {
            let mut value = glib::Value::uninitialized();
            gtk_sys::gtk_style_context_get_property(
                self.as_ref().to_glib_none().0,
                property.to_glib_none().0,
                state.to_glib(),
                value.to_glib_none_mut().0,
            );
            value
        }
    }

    fn get_scale(&self) -> i32 {
        unsafe { gtk_sys::gtk_style_context_get_scale(self.as_ref().to_glib_none().0) }
    }

    fn get_screen(&self) -> Option<gdk::Screen> {
        unsafe {
            from_glib_none(gtk_sys::gtk_style_context_get_screen(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_section(&self, property: &str) -> Option<CssSection> {
        unsafe {
            from_glib_none(gtk_sys::gtk_style_context_get_section(
                self.as_ref().to_glib_none().0,
                property.to_glib_none().0,
            ))
        }
    }

    fn get_state(&self) -> StateFlags {
        unsafe {
            from_glib(gtk_sys::gtk_style_context_get_state(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    //fn get_style(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
    //    unsafe { TODO: call gtk_sys:gtk_style_context_get_style() }
    //}

    fn get_style_property(&self, property_name: &str) -> glib::Value {
        unsafe {
            let mut value = glib::Value::uninitialized();
            gtk_sys::gtk_style_context_get_style_property(
                self.as_ref().to_glib_none().0,
                property_name.to_glib_none().0,
                value.to_glib_none_mut().0,
            );
            value
        }
    }

    //fn get_style_valist(&self, args: /*Unknown conversion*//*Unimplemented*/Unsupported) {
    //    unsafe { TODO: call gtk_sys:gtk_style_context_get_style_valist() }
    //}

    //fn get_valist(&self, state: StateFlags, args: /*Unknown conversion*//*Unimplemented*/Unsupported) {
    //    unsafe { TODO: call gtk_sys:gtk_style_context_get_valist() }
    //}

    fn has_class(&self, class_name: &str) -> bool {
        unsafe {
            from_glib(gtk_sys::gtk_style_context_has_class(
                self.as_ref().to_glib_none().0,
                class_name.to_glib_none().0,
            ))
        }
    }

    fn list_classes(&self) -> Vec<GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(gtk_sys::gtk_style_context_list_classes(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn lookup_color(&self, color_name: &str) -> Option<gdk::RGBA> {
        unsafe {
            let mut color = gdk::RGBA::uninitialized();
            let ret = from_glib(gtk_sys::gtk_style_context_lookup_color(
                self.as_ref().to_glib_none().0,
                color_name.to_glib_none().0,
                color.to_glib_none_mut().0,
            ));
            if ret {
                Some(color)
            } else {
                None
            }
        }
    }

    fn remove_class(&self, class_name: &str) {
        unsafe {
            gtk_sys::gtk_style_context_remove_class(
                self.as_ref().to_glib_none().0,
                class_name.to_glib_none().0,
            );
        }
    }

    fn remove_provider<P: IsA<StyleProvider>>(&self, provider: &P) {
        unsafe {
            gtk_sys::gtk_style_context_remove_provider(
                self.as_ref().to_glib_none().0,
                provider.as_ref().to_glib_none().0,
            );
        }
    }

    fn restore(&self) {
        unsafe {
            gtk_sys::gtk_style_context_restore(self.as_ref().to_glib_none().0);
        }
    }

    fn save(&self) {
        unsafe {
            gtk_sys::gtk_style_context_save(self.as_ref().to_glib_none().0);
        }
    }

    fn set_background<P: IsA<gdk::Window>>(&self, window: &P) {
        unsafe {
            gtk_sys::gtk_style_context_set_background(
                self.as_ref().to_glib_none().0,
                window.as_ref().to_glib_none().0,
            );
        }
    }

    fn set_frame_clock(&self, frame_clock: &gdk::FrameClock) {
        unsafe {
            gtk_sys::gtk_style_context_set_frame_clock(
                self.as_ref().to_glib_none().0,
                frame_clock.to_glib_none().0,
            );
        }
    }

    fn set_junction_sides(&self, sides: JunctionSides) {
        unsafe {
            gtk_sys::gtk_style_context_set_junction_sides(
                self.as_ref().to_glib_none().0,
                sides.to_glib(),
            );
        }
    }

    fn set_parent<P: IsA<StyleContext>>(&self, parent: Option<&P>) {
        unsafe {
            gtk_sys::gtk_style_context_set_parent(
                self.as_ref().to_glib_none().0,
                parent.map(|p| p.as_ref()).to_glib_none().0,
            );
        }
    }

    fn set_path(&self, path: &WidgetPath) {
        unsafe {
            gtk_sys::gtk_style_context_set_path(
                self.as_ref().to_glib_none().0,
                path.to_glib_none().0,
            );
        }
    }

    fn set_scale(&self, scale: i32) {
        unsafe {
            gtk_sys::gtk_style_context_set_scale(self.as_ref().to_glib_none().0, scale);
        }
    }

    fn set_screen(&self, screen: &gdk::Screen) {
        unsafe {
            gtk_sys::gtk_style_context_set_screen(
                self.as_ref().to_glib_none().0,
                screen.to_glib_none().0,
            );
        }
    }

    fn set_state(&self, flags: StateFlags) {
        unsafe {
            gtk_sys::gtk_style_context_set_state(self.as_ref().to_glib_none().0, flags.to_glib());
        }
    }

    #[cfg(any(feature = "v3_20", feature = "dox"))]
    fn to_string(&self, flags: StyleContextPrintFlags) -> GString {
        unsafe {
            from_glib_full(gtk_sys::gtk_style_context_to_string(
                self.as_ref().to_glib_none().0,
                flags.to_glib(),
            ))
        }
    }

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

    fn set_property_direction(&self, direction: TextDirection) {
        unsafe {
            gobject_sys::g_object_set_property(
                self.to_glib_none().0 as *mut gobject_sys::GObject,
                b"direction\0".as_ptr() as *const _,
                Value::from(&direction).to_glib_none().0,
            );
        }
    }

    fn get_property_paint_clock(&self) -> Option<gdk::FrameClock> {
        unsafe {
            let mut value = Value::from_type(<gdk::FrameClock as StaticType>::static_type());
            gobject_sys::g_object_get_property(
                self.to_glib_none().0 as *mut gobject_sys::GObject,
                b"paint-clock\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `paint-clock` getter")
        }
    }

    fn set_property_paint_clock(&self, paint_clock: Option<&gdk::FrameClock>) {
        unsafe {
            gobject_sys::g_object_set_property(
                self.to_glib_none().0 as *mut gobject_sys::GObject,
                b"paint-clock\0".as_ptr() as *const _,
                Value::from(paint_clock).to_glib_none().0,
            );
        }
    }

    fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn changed_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut gtk_sys::GtkStyleContext,
            f: glib_sys::gpointer,
        ) where
            P: IsA<StyleContext>,
        {
            let f: &F = &*(f as *const F);
            f(&StyleContext::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_property_direction_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_direction_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut gtk_sys::GtkStyleContext,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<StyleContext>,
        {
            let f: &F = &*(f as *const F);
            f(&StyleContext::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::direction\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_direction_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_paint_clock_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_paint_clock_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut gtk_sys::GtkStyleContext,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<StyleContext>,
        {
            let f: &F = &*(f as *const F);
            f(&StyleContext::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::paint-clock\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_paint_clock_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_parent_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_parent_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut gtk_sys::GtkStyleContext,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<StyleContext>,
        {
            let f: &F = &*(f as *const F);
            f(&StyleContext::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::parent\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_parent_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_screen_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_screen_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut gtk_sys::GtkStyleContext,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<StyleContext>,
        {
            let f: &F = &*(f as *const F);
            f(&StyleContext::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::screen\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_screen_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

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