[gtk/wip/baedert/for-master: 53/53] Start using GtkWidget's new style class API



commit baa1788dc1e4fbf56ef61d11f6859de692571229
Author: Timm Bäder <mail baedert org>
Date:   Wed Jan 29 12:11:39 2020 +0100

    Start using GtkWidget's new style class API

 gtk/gtkbutton.c           | 26 ++++++++----------------
 gtk/gtkcolorbutton.c      |  4 +---
 gtk/gtkcolorswatch.c      | 14 ++++++-------
 gtk/gtkcombobox.c         |  6 ++----
 gtk/gtkfontbutton.c       |  4 +---
 gtk/gtkframe.c            |  6 ++----
 gtk/gtkheaderbar.c        | 51 +++++++++++++++++++----------------------------
 gtk/gtkinfobar.c          | 13 +++++-------
 gtk/gtklinkbutton.c       |  4 +---
 gtk/gtklistbox.c          | 13 +++++-------
 gtk/gtklockbutton.c       |  4 +---
 gtk/gtkpaned.c            |  9 +++------
 gtk/gtkpasswordentry.c    |  4 ++--
 gtk/gtkpopovermenu.c      |  5 +----
 gtk/gtkprogressbar.c      | 34 +++++++++++++------------------
 gtk/gtkscale.c            | 39 ++++++++++++++----------------------
 gtk/gtkshortcutlabel.c    |  4 ++--
 gtk/gtkshortcutssection.c |  5 ++---
 gtk/gtkspinbutton.c       |  4 ++--
 gtk/gtkstackswitcher.c    | 20 +++++++------------
 gtk/gtktoolbutton.c       | 17 ++++++++--------
 gtk/gtkwidget.c           |  7 ++-----
 22 files changed, 112 insertions(+), 181 deletions(-)
---
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c
index 6fcc605b08..756e40ea02 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -654,9 +654,8 @@ gtk_button_new_with_mnemonic (const gchar *label)
  */
 void
 gtk_button_set_relief (GtkButton      *button,
-                      GtkReliefStyle  relief)
+                       GtkReliefStyle  relief)
 {
-  GtkStyleContext *context;
   GtkReliefStyle old_relief;
 
   g_return_if_fail (GTK_IS_BUTTON (button));
@@ -664,11 +663,10 @@ gtk_button_set_relief (GtkButton      *button,
   old_relief = gtk_button_get_relief (button);
   if (old_relief != relief)
     {
-      context = gtk_widget_get_style_context (GTK_WIDGET (button));
       if (relief == GTK_RELIEF_NONE)
-        gtk_style_context_add_class (context, GTK_STYLE_CLASS_FLAT);
+        gtk_widget_add_style_class (GTK_WIDGET (button), GTK_STYLE_CLASS_FLAT);
       else
-        gtk_style_context_remove_class (context, GTK_STYLE_CLASS_FLAT);
+        gtk_widget_remove_style_class (GTK_WIDGET (button), GTK_STYLE_CLASS_FLAT);
 
       g_object_notify_by_pspec (G_OBJECT (button), props[PROP_RELIEF]);
     }
@@ -685,12 +683,9 @@ gtk_button_set_relief (GtkButton      *button,
 GtkReliefStyle
 gtk_button_get_relief (GtkButton *button)
 {
-  GtkStyleContext *context;
-
   g_return_val_if_fail (GTK_IS_BUTTON (button), GTK_RELIEF_NORMAL);
 
-  context = gtk_widget_get_style_context (GTK_WIDGET (button));
-  if (gtk_style_context_has_class (context, GTK_STYLE_CLASS_FLAT))
+  if (gtk_widget_has_style_class (GTK_WIDGET (button), GTK_STYLE_CLASS_FLAT))
     return GTK_RELIEF_NONE;
   else
     return GTK_RELIEF_NORMAL;
@@ -787,12 +782,9 @@ gtk_button_set_label (GtkButton   *button,
 {
   GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
   GtkWidget *child;
-  GtkStyleContext *context;
 
   g_return_if_fail (GTK_IS_BUTTON (button));
 
-  context = gtk_widget_get_style_context (GTK_WIDGET (button));
-
   child = gtk_bin_get_child (GTK_BIN (button));
 
   if (priv->child_type != LABEL_CHILD || child == NULL)
@@ -811,8 +803,8 @@ gtk_button_set_label (GtkButton   *button,
           gtk_label_set_xalign (GTK_LABEL (child), 0.0);
         }
       gtk_container_add (GTK_CONTAINER (button), child);
-      gtk_style_context_remove_class (context, "image-button");
-      gtk_style_context_add_class (context, "text-button");
+      gtk_widget_remove_style_class (GTK_WIDGET (button), "image-button");
+      gtk_widget_add_style_class (GTK_WIDGET (button), "text-button");
     }
 
   gtk_label_set_label (GTK_LABEL (child), label);
@@ -944,13 +936,11 @@ gtk_button_set_icon_name (GtkButton  *button,
 {
   GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
   GtkWidget *child;
-  GtkStyleContext *context;
 
   g_return_if_fail (GTK_IS_BUTTON (button));
   g_return_if_fail (icon_name != NULL);
 
   child = gtk_bin_get_child (GTK_BIN (button));
-  context = gtk_widget_get_style_context (GTK_WIDGET (button));
 
   if (priv->child_type != ICON_CHILD || child == NULL)
     {
@@ -959,8 +949,8 @@ gtk_button_set_icon_name (GtkButton  *button,
 
       child = gtk_image_new_from_icon_name (icon_name);
       gtk_container_add (GTK_CONTAINER (button), child);
-      gtk_style_context_remove_class (context, "text-button");
-      gtk_style_context_add_class (context, "image-button");
+      gtk_widget_remove_style_class (GTK_WIDGET (button), "text-button");
+      gtk_widget_add_style_class (GTK_WIDGET (button), "image-button");
     }
   else
     {
diff --git a/gtk/gtkcolorbutton.c b/gtk/gtkcolorbutton.c
index 19759ff8e4..13908fc957 100644
--- a/gtk/gtkcolorbutton.c
+++ b/gtk/gtkcolorbutton.c
@@ -299,7 +299,6 @@ gtk_color_button_init (GtkColorButton *button)
   GtkColorButtonPrivate *priv = gtk_color_button_get_instance_private (button);
   PangoLayout *layout;
   PangoRectangle rect;
-  GtkStyleContext *context;
   GdkContentFormats *targets;
   GdkContentProvider *content;
   GtkDragSource *source;
@@ -340,8 +339,7 @@ gtk_color_button_init (GtkColorButton *button)
   g_signal_connect (source, "drag-begin", G_CALLBACK (gtk_color_button_drag_begin), button);
   gtk_widget_add_controller (priv->button, GTK_EVENT_CONTROLLER (source));
 
-  context = gtk_widget_get_style_context (GTK_WIDGET (priv->button));
-  gtk_style_context_add_class (context, "color");
+  gtk_widget_add_style_class (priv->button, "color");
 }
 
 static void
diff --git a/gtk/gtkcolorswatch.c b/gtk/gtkcolorswatch.c
index af7dcbd6b5..44edf1e005 100644
--- a/gtk/gtkcolorswatch.c
+++ b/gtk/gtkcolorswatch.c
@@ -558,7 +558,7 @@ gtk_color_swatch_init (GtkColorSwatch *swatch)
                     G_CALLBACK (key_controller_key_pressed), swatch);
   gtk_widget_add_controller (GTK_WIDGET (swatch), controller);
 
-  gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (swatch)), "activatable");
+  gtk_widget_add_style_class (GTK_WIDGET (swatch), "activatable");
 
   priv->overlay_widget = g_object_new (GTK_TYPE_IMAGE,
                                                "css-name", "overlay",
@@ -591,9 +591,6 @@ gtk_color_swatch_set_rgba (GtkColorSwatch *swatch,
                            const GdkRGBA  *color)
 {
   GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
-  GtkStyleContext *context;
-
-  context = gtk_widget_get_style_context (GTK_WIDGET (swatch));
 
   if (!priv->has_color)
     {
@@ -614,13 +611,14 @@ gtk_color_swatch_set_rgba (GtkColorSwatch *swatch,
 
   if (INTENSITY (priv->color.red, priv->color.green, priv->color.blue) > 0.5)
     {
-      gtk_style_context_add_class (context, "light");
-      gtk_style_context_remove_class (context, "dark");
+      gtk_widget_add_style_class (GTK_WIDGET (swatch), "light");
+      gtk_widget_remove_style_class (GTK_WIDGET (swatch), "dark");
     }
   else
     {
-      gtk_style_context_add_class (context, "dark");
-      gtk_style_context_remove_class (context, "light");
+      gtk_widget_add_style_class (GTK_WIDGET (swatch), "dark");
+      gtk_widget_remove_style_class (GTK_WIDGET (swatch), "light");
+
     }
 
   gtk_widget_queue_draw (GTK_WIDGET (swatch));
diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c
index bbb7dba9b1..b94e01872c 100644
--- a/gtk/gtkcombobox.c
+++ b/gtk/gtkcombobox.c
@@ -825,7 +825,6 @@ static void
 gtk_combo_box_init (GtkComboBox *combo_box)
 {
   GtkComboBoxPrivate *priv = gtk_combo_box_get_instance_private (combo_box);
-  GtkStyleContext *context;
   GtkEventController *controller;
 
   priv->active = -1;
@@ -848,9 +847,8 @@ gtk_combo_box_init (GtkComboBox *combo_box)
   g_type_ensure (GTK_TYPE_TREE_POPOVER);
   gtk_widget_init_template (GTK_WIDGET (combo_box));
 
-  context = gtk_widget_get_style_context (priv->button);
-  gtk_style_context_remove_class (context, "toggle");
-  gtk_style_context_add_class (context, "combo");
+  gtk_widget_remove_style_class (priv->button, "toggle");
+  gtk_widget_add_style_class (priv->button, "combo");
 
   gtk_tree_popover_set_row_separator_func (GTK_TREE_POPOVER (priv->popup_widget),
                                            (GtkTreeViewRowSeparatorFunc)gtk_combo_box_row_separator_func,
diff --git a/gtk/gtkfontbutton.c b/gtk/gtkfontbutton.c
index 79ac0c31ed..f9ef7ad7b3 100644
--- a/gtk/gtkfontbutton.c
+++ b/gtk/gtkfontbutton.c
@@ -555,7 +555,6 @@ gtk_font_button_class_init (GtkFontButtonClass *klass)
 static void
 gtk_font_button_init (GtkFontButton *font_button)
 {
-  GtkStyleContext *context;
   GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
   GtkWidget *box;
 
@@ -592,8 +591,7 @@ gtk_font_button_init (GtkFontButton *font_button)
 
   gtk_font_button_take_font_desc (font_button, NULL);
 
-  context = gtk_widget_get_style_context (GTK_WIDGET (priv->button));
-  gtk_style_context_add_class (context, "font");
+  gtk_widget_add_style_class (priv->button, "font");
 }
 
 static void
diff --git a/gtk/gtkframe.c b/gtk/gtkframe.c
index 40d5bc2939..ab7ccb429c 100644
--- a/gtk/gtkframe.c
+++ b/gtk/gtkframe.c
@@ -534,11 +534,9 @@ gtk_frame_set_shadow_type (GtkFrame      *frame,
       priv->shadow_type = type;
 
       if (type == GTK_SHADOW_NONE)
-        gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (frame)),
-                                     GTK_STYLE_CLASS_FLAT);
+        gtk_widget_add_style_class (GTK_WIDGET (frame), "flat");
       else
-        gtk_style_context_remove_class (gtk_widget_get_style_context (GTK_WIDGET (frame)),
-                                        GTK_STYLE_CLASS_FLAT);
+        gtk_widget_remove_style_class (GTK_WIDGET (frame), "flat");
 
       g_object_notify_by_pspec (G_OBJECT (frame), frame_props[PROP_SHADOW_TYPE]);
     }
diff --git a/gtk/gtkheaderbar.c b/gtk/gtkheaderbar.c
index 0c8100872d..b00dc0b6cd 100644
--- a/gtk/gtkheaderbar.c
+++ b/gtk/gtkheaderbar.c
@@ -163,7 +163,6 @@ init_sizing_box (GtkHeaderBar *bar)
 {
   GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
   GtkWidget *w;
-  GtkStyleContext *context;
 
   /* We use this box to always request size for the two labels (title
    * and subtitle) as if they were always visible, but then allocate
@@ -174,8 +173,7 @@ init_sizing_box (GtkHeaderBar *bar)
   priv->label_sizing_box = g_object_ref_sink (w);
 
   w = gtk_label_new (NULL);
-  context = gtk_widget_get_style_context (w);
-  gtk_style_context_add_class (context, GTK_STYLE_CLASS_TITLE);
+  gtk_widget_add_style_class (w, GTK_STYLE_CLASS_TITLE);
   gtk_container_add (GTK_CONTAINER (priv->label_sizing_box), w);
   gtk_label_set_wrap (GTK_LABEL (w), FALSE);
   gtk_label_set_single_line_mode (GTK_LABEL (w), TRUE);
@@ -183,8 +181,7 @@ init_sizing_box (GtkHeaderBar *bar)
   gtk_label_set_width_chars (GTK_LABEL (w), MIN_TITLE_CHARS);
 
   w = gtk_label_new (NULL);
-  context = gtk_widget_get_style_context (w);
-  gtk_style_context_add_class (context, GTK_STYLE_CLASS_SUBTITLE);
+  gtk_widget_add_style_class (w, GTK_STYLE_CLASS_SUBTITLE);
   gtk_container_add (GTK_CONTAINER (priv->label_sizing_box), w);
   gtk_label_set_wrap (GTK_LABEL (w), FALSE);
   gtk_label_set_single_line_mode (GTK_LABEL (w), TRUE);
@@ -202,14 +199,12 @@ create_title_box (const char *title,
   GtkWidget *label_box;
   GtkWidget *title_label;
   GtkWidget *subtitle_label;
-  GtkStyleContext *context;
 
   label_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
   gtk_widget_set_valign (label_box, GTK_ALIGN_CENTER);
 
   title_label = gtk_label_new (title);
-  context = gtk_widget_get_style_context (title_label);
-  gtk_style_context_add_class (context, GTK_STYLE_CLASS_TITLE);
+  gtk_widget_add_style_class (title_label, GTK_STYLE_CLASS_TITLE);
   gtk_label_set_wrap (GTK_LABEL (title_label), FALSE);
   gtk_label_set_single_line_mode (GTK_LABEL (title_label), TRUE);
   gtk_label_set_ellipsize (GTK_LABEL (title_label), PANGO_ELLIPSIZE_END);
@@ -217,8 +212,7 @@ create_title_box (const char *title,
   gtk_label_set_width_chars (GTK_LABEL (title_label), MIN_TITLE_CHARS);
 
   subtitle_label = gtk_label_new (subtitle);
-  context = gtk_widget_get_style_context (subtitle_label);
-  gtk_style_context_add_class (context, GTK_STYLE_CLASS_SUBTITLE);
+  gtk_widget_add_style_class (subtitle_label, GTK_STYLE_CLASS_SUBTITLE);
   gtk_label_set_wrap (GTK_LABEL (subtitle_label), FALSE);
   gtk_label_set_single_line_mode (GTK_LABEL (subtitle_label), TRUE);
   gtk_label_set_ellipsize (GTK_LABEL (subtitle_label), PANGO_ELLIPSIZE_END);
@@ -371,7 +365,7 @@ _gtk_header_bar_update_window_buttons (GtkHeaderBar *bar)
           t = g_strsplit (tokens[i], ",", -1);
 
           separator = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
-          gtk_style_context_add_class (gtk_widget_get_style_context (separator), "titlebutton");
+          gtk_widget_add_style_class (separator, "titlebutton");
 
           box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
 
@@ -387,8 +381,8 @@ _gtk_header_bar_update_window_buttons (GtkHeaderBar *bar)
                   button = gtk_image_new ();
                   gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
                   priv->titlebar_icon = button;
-                  gtk_style_context_add_class (gtk_widget_get_style_context (button), "titlebutton");
-                  gtk_style_context_add_class (gtk_widget_get_style_context (button), "icon");
+                  gtk_widget_add_style_class (button, "titlebutton");
+                  gtk_widget_add_style_class (button, "icon");
                   gtk_widget_set_size_request (button, 20, 20);
 
                   if (!_gtk_header_bar_update_window_icon (bar, window))
@@ -405,8 +399,8 @@ _gtk_header_bar_update_window_buttons (GtkHeaderBar *bar)
                   button = gtk_menu_button_new ();
                   gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
                   gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), menu);
-                  gtk_style_context_add_class (gtk_widget_get_style_context (button), "titlebutton");
-                  gtk_style_context_add_class (gtk_widget_get_style_context (button), "menu");
+                  gtk_widget_add_style_class (button, "titlebutton");
+                  gtk_widget_add_style_class (button, "menu");
                   image = gtk_image_new ();
                   gtk_menu_button_add_child (GTK_MENU_BUTTON (button), image);
                   gtk_widget_set_can_focus (button, FALSE);
@@ -426,8 +420,8 @@ _gtk_header_bar_update_window_buttons (GtkHeaderBar *bar)
                 {
                   button = gtk_button_new ();
                   gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
-                  gtk_style_context_add_class (gtk_widget_get_style_context (button), "titlebutton");
-                  gtk_style_context_add_class (gtk_widget_get_style_context (button), "minimize");
+                  gtk_widget_add_style_class (button, "titlebutton");
+                  gtk_widget_add_style_class (button, "minimize");
                   image = gtk_image_new_from_icon_name ("window-minimize-symbolic");
                   g_object_set (image, "use-fallback", TRUE, NULL);
                   gtk_container_add (GTK_CONTAINER (button), image);
@@ -449,8 +443,8 @@ _gtk_header_bar_update_window_buttons (GtkHeaderBar *bar)
                   icon_name = maximized ? "window-restore-symbolic" : "window-maximize-symbolic";
                   button = gtk_button_new ();
                   gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
-                  gtk_style_context_add_class (gtk_widget_get_style_context (button), "titlebutton");
-                  gtk_style_context_add_class (gtk_widget_get_style_context (button), "maximize");
+                  gtk_widget_add_style_class (button, "titlebutton");
+                  gtk_widget_add_style_class (button, "maximize");
                   image = gtk_image_new_from_icon_name (icon_name);
                   g_object_set (image, "use-fallback", TRUE, NULL);
                   gtk_container_add (GTK_CONTAINER (button), image);
@@ -468,8 +462,8 @@ _gtk_header_bar_update_window_buttons (GtkHeaderBar *bar)
                   button = gtk_button_new ();
                   gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
                   image = gtk_image_new_from_icon_name ("window-close-symbolic");
-                  gtk_style_context_add_class (gtk_widget_get_style_context (button), "titlebutton");
-                  gtk_style_context_add_class (gtk_widget_get_style_context (button), "close");
+                  gtk_widget_add_style_class (button, "titlebutton");
+                  gtk_widget_add_style_class (button, "close");
                   g_object_set (image, "use-fallback", TRUE, NULL);
                   gtk_container_add (GTK_CONTAINER (button), image);
                   gtk_widget_set_can_focus (button, FALSE);
@@ -503,9 +497,9 @@ _gtk_header_bar_update_window_buttons (GtkHeaderBar *bar)
             gtk_box_reorder_child_after (GTK_BOX (box), separator, NULL);
 
           if (i == 0)
-            gtk_style_context_add_class (gtk_widget_get_style_context (box), GTK_STYLE_CLASS_LEFT);
+            gtk_widget_add_style_class (box, GTK_STYLE_CLASS_LEFT);
           else
-            gtk_style_context_add_class (gtk_widget_get_style_context (box), GTK_STYLE_CLASS_RIGHT);
+            gtk_widget_add_style_class (box, GTK_STYLE_CLASS_RIGHT);
 
           if (i == 0)
             {
@@ -540,7 +534,6 @@ update_default_decoration (GtkHeaderBar *bar)
 {
   GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
   GtkLayoutManager *layout = gtk_widget_get_layout_manager (GTK_WIDGET (bar));
-  GtkStyleContext *context;
   gboolean have_children = FALSE;
 
   /* Check whether we have any child widgets that we didn't add ourselves */
@@ -576,12 +569,10 @@ update_default_decoration (GtkHeaderBar *bar)
           }
     }
 
-  context = gtk_widget_get_style_context (GTK_WIDGET (bar));
-
   if (have_children || priv->custom_title != NULL)
-    gtk_style_context_remove_class (context, "default-decoration");
+    gtk_widget_remove_style_class (GTK_WIDGET (bar), "default-decoration");
   else
-    gtk_style_context_add_class (context, "default-decoration");
+    gtk_widget_add_style_class (GTK_WIDGET (bar), "default-decoration");
 }
 
 void
@@ -1242,11 +1233,11 @@ gtk_header_bar_init (GtkHeaderBar *bar)
 
   layout = gtk_widget_get_layout_manager (GTK_WIDGET (bar));
   priv->start_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-  gtk_style_context_add_class (gtk_widget_get_style_context (priv->start_box), "start");
+  gtk_widget_add_style_class (priv->start_box, "start");
   gtk_widget_set_parent (priv->start_box, GTK_WIDGET (bar));
   gtk_center_layout_set_start_widget (GTK_CENTER_LAYOUT (layout), priv->start_box);
   priv->end_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-  gtk_style_context_add_class (gtk_widget_get_style_context (priv->end_box), "end");
+  gtk_widget_add_style_class (priv->end_box, "end");
   gtk_widget_set_parent (priv->end_box, GTK_WIDGET (bar));
   gtk_center_layout_set_end_widget (GTK_CENTER_LAYOUT (layout), priv->end_box);
 
diff --git a/gtk/gtkinfobar.c b/gtk/gtkinfobar.c
index a7b902cf17..d7c04299dd 100644
--- a/gtk/gtkinfobar.c
+++ b/gtk/gtkinfobar.c
@@ -516,7 +516,7 @@ gtk_info_bar_init (GtkInfoBar *info_bar)
   priv->close_button = gtk_button_new_from_icon_name ("window-close-symbolic");
   gtk_widget_hide (priv->close_button);
   gtk_widget_set_valign (priv->close_button, GTK_ALIGN_CENTER);
-  gtk_style_context_add_class (gtk_widget_get_style_context (priv->close_button), "close");
+  gtk_widget_add_style_class (priv->close_button, "close");
   gtk_container_add (GTK_CONTAINER (main_box), priv->close_button);
   g_signal_connect (priv->close_button, "clicked",
                     G_CALLBACK (close_button_clicked_cb), info_bar);
@@ -787,9 +787,9 @@ update_default_response (GtkInfoBar *info_bar,
   priv->default_response_sensitive = sensitive;
 
   if (response_id && sensitive)
-    gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (info_bar)), "action");
+    gtk_widget_add_style_class (GTK_WIDGET (info_bar), "action");
   else
-    gtk_style_context_remove_class (gtk_widget_get_style_context (GTK_WIDGET (info_bar)), "action");
+    gtk_widget_remove_style_class (GTK_WIDGET (info_bar), "action");
 }
 
 /**
@@ -1137,7 +1137,6 @@ gtk_info_bar_set_message_type (GtkInfoBar     *info_bar,
 
   if (priv->message_type != message_type)
     {
-      GtkStyleContext *context;
       AtkObject *atk_obj;
       const char *type_class[] = {
         GTK_STYLE_CLASS_INFO,
@@ -1147,10 +1146,8 @@ gtk_info_bar_set_message_type (GtkInfoBar     *info_bar,
         NULL
       };
 
-      context = gtk_widget_get_style_context (GTK_WIDGET (info_bar));
-
       if (type_class[priv->message_type])
-        gtk_style_context_remove_class (context, type_class[priv->message_type]);
+        gtk_widget_remove_style_class (GTK_WIDGET (info_bar), type_class[priv->message_type]);
 
       priv->message_type = message_type;
 
@@ -1194,7 +1191,7 @@ gtk_info_bar_set_message_type (GtkInfoBar     *info_bar,
         }
 
       if (type_class[priv->message_type])
-        gtk_style_context_add_class (context, type_class[priv->message_type]);
+        gtk_widget_add_style_class (GTK_WIDGET (info_bar), type_class[priv->message_type]);
 
       g_object_notify_by_pspec (G_OBJECT (info_bar), props[PROP_MESSAGE_TYPE]);
     }
diff --git a/gtk/gtklinkbutton.c b/gtk/gtklinkbutton.c
index 2621591a5e..be28f64613 100644
--- a/gtk/gtklinkbutton.c
+++ b/gtk/gtklinkbutton.c
@@ -320,7 +320,6 @@ gtk_link_content_init (GtkLinkContent *content)
 static void
 gtk_link_button_init (GtkLinkButton *link_button)
 {
-  GtkStyleContext *context;
   GtkGesture *gesture;
   GdkContentProvider *content;
   GtkDragSource *source;
@@ -347,8 +346,7 @@ gtk_link_button_init (GtkLinkButton *link_button)
                     link_button);
   gtk_widget_add_controller (GTK_WIDGET (link_button), GTK_EVENT_CONTROLLER (gesture));
 
-  context = gtk_widget_get_style_context (GTK_WIDGET (link_button));
-  gtk_style_context_add_class (context, "link");
+  gtk_widget_add_style_class (GTK_WIDGET (link_button), "link");
 
   gtk_widget_set_cursor_from_name (GTK_WIDGET (link_button), "pointer");
 }
diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c
index 681c33f3aa..580dcf44a7 100644
--- a/gtk/gtklistbox.c
+++ b/gtk/gtklistbox.c
@@ -3157,7 +3157,6 @@ static void
 gtk_list_box_update_row_style (GtkListBox    *box,
                                GtkListBoxRow *row)
 {
-  GtkStyleContext *context;
   gboolean can_select;
 
   if (box && BOX_PRIV (box)->selection_mode != GTK_SELECTION_NONE)
@@ -3165,12 +3164,11 @@ gtk_list_box_update_row_style (GtkListBox    *box,
   else
     can_select = FALSE;
 
-  context = gtk_widget_get_style_context (GTK_WIDGET (row));
   if (ROW_PRIV (row)->activatable ||
       (ROW_PRIV (row)->selectable && can_select))
-    gtk_style_context_add_class (context, "activatable");
+    gtk_widget_add_style_class (GTK_WIDGET (row), "activatable");
   else
-    gtk_style_context_remove_class (context, "activatable");
+    gtk_widget_remove_style_class (GTK_WIDGET (row), "activatable");
 }
 
 static void
@@ -3496,8 +3494,7 @@ gtk_list_box_row_init (GtkListBoxRow *row)
   ROW_PRIV (row)->activatable = TRUE;
   ROW_PRIV (row)->selectable = TRUE;
 
-  gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (row)),
-                               "activatable");
+  gtk_widget_add_style_class (GTK_WIDGET (row), "activatable");
 }
 
 static void
@@ -3669,9 +3666,9 @@ gtk_list_box_set_show_separators (GtkListBox *box,
   priv->show_separators = show_separators;
 
   if (show_separators)
-    gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (box)), "separators");
+    gtk_widget_add_style_class (GTK_WIDGET (box), "separators");
   else
-    gtk_style_context_remove_class (gtk_widget_get_style_context (GTK_WIDGET (box)), "separators");
+    gtk_widget_remove_style_class (GTK_WIDGET (box), "separators");
 
   g_object_notify_by_pspec (G_OBJECT (box), properties[PROP_SHOW_SEPARATORS]);
 }
diff --git a/gtk/gtklockbutton.c b/gtk/gtklockbutton.c
index f22670110a..5312b07434 100644
--- a/gtk/gtklockbutton.c
+++ b/gtk/gtklockbutton.c
@@ -241,7 +241,6 @@ gtk_lock_button_init (GtkLockButton *button)
 {
   GtkLockButtonPrivate *priv = gtk_lock_button_get_instance_private (button);
   const char *names[3];
-  GtkStyleContext *context;
 
   gtk_widget_init_template (GTK_WIDGET (button));
 
@@ -257,8 +256,7 @@ gtk_lock_button_init (GtkLockButton *button)
 
   update_state (button);
 
-  context = gtk_widget_get_style_context (GTK_WIDGET (button));
-  gtk_style_context_add_class (context, I_("lock"));
+  gtk_widget_add_style_class (GTK_WIDGET (button), I_("lock"));
 }
 
 static void
diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c
index f1689302ca..06eff84f67 100644
--- a/gtk/gtkpaned.c
+++ b/gtk/gtkpaned.c
@@ -2421,11 +2421,9 @@ gtk_paned_set_wide_handle (GtkPaned *paned,
   if (old_wide != wide)
     {
       if (wide)
-        gtk_style_context_add_class (gtk_widget_get_style_context (priv->handle_widget),
-                                     GTK_STYLE_CLASS_WIDE);
+        gtk_widget_add_style_class (priv->handle_widget, GTK_STYLE_CLASS_WIDE);
       else
-        gtk_style_context_remove_class (gtk_widget_get_style_context (priv->handle_widget),
-                                        GTK_STYLE_CLASS_WIDE);
+        gtk_widget_remove_style_class (priv->handle_widget, GTK_STYLE_CLASS_WIDE);
 
       g_object_notify_by_pspec (G_OBJECT (paned), paned_props[PROP_WIDE_HANDLE]);
     }
@@ -2446,6 +2444,5 @@ gtk_paned_get_wide_handle (GtkPaned *paned)
 
   g_return_val_if_fail (GTK_IS_PANED (paned), FALSE);
 
-  return gtk_style_context_has_class (gtk_widget_get_style_context (priv->handle_widget),
-                                      GTK_STYLE_CLASS_WIDE);
+  return gtk_widget_has_style_class (priv->handle_widget, GTK_STYLE_CLASS_WIDE);
 }
diff --git a/gtk/gtkpasswordentry.c b/gtk/gtkpasswordentry.c
index a2eeda7900..a3de52e488 100644
--- a/gtk/gtkpasswordentry.c
+++ b/gtk/gtkpasswordentry.c
@@ -149,11 +149,11 @@ gtk_password_entry_init (GtkPasswordEntry *entry)
 
   priv->icon = gtk_image_new_from_icon_name ("caps-lock-symbolic");
   gtk_widget_set_tooltip_text (priv->icon, _("Caps Lock is on"));
-  gtk_style_context_add_class (gtk_widget_get_style_context (priv->icon), "caps-lock-indicator");
+  gtk_widget_add_style_class (priv->icon, "caps-lock-indicator");
   gtk_widget_set_cursor (priv->icon, gtk_widget_get_cursor (priv->entry));
   gtk_widget_set_parent (priv->icon, GTK_WIDGET (entry));
 
-  gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (entry)), I_("password"));
+  gtk_widget_add_style_class (GTK_WIDGET (entry), I_("password"));
 
   gtk_password_entry_set_extra_menu (entry, NULL);
 }
diff --git a/gtk/gtkpopovermenu.c b/gtk/gtkpopovermenu.c
index 0765c9dd3d..3bacdc53f9 100644
--- a/gtk/gtkpopovermenu.c
+++ b/gtk/gtkpopovermenu.c
@@ -201,7 +201,6 @@ static void
 gtk_popover_menu_init (GtkPopoverMenu *popover)
 {
   GtkWidget *stack;
-  GtkStyleContext *style_context;
   GtkEventController *controller;
 
   stack = gtk_stack_new ();
@@ -212,8 +211,7 @@ gtk_popover_menu_init (GtkPopoverMenu *popover)
   g_signal_connect (stack, "notify::visible-child-name",
                     G_CALLBACK (visible_submenu_changed), popover);
 
-  style_context = gtk_widget_get_style_context (GTK_WIDGET (popover));
-  gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_MENU);
+  gtk_widget_add_style_class (GTK_WIDGET (popover), "menu");
 
   controller = gtk_event_controller_key_new ();
   g_signal_connect (controller, "focus-out", G_CALLBACK (focus_out), popover);
@@ -222,7 +220,6 @@ gtk_popover_menu_init (GtkPopoverMenu *popover)
   controller = gtk_event_controller_motion_new ();
   g_signal_connect (controller, "leave", G_CALLBACK (leave_cb), popover);
   gtk_widget_add_controller (GTK_WIDGET (popover), controller);
-
 }
 
 static void
diff --git a/gtk/gtkprogressbar.c b/gtk/gtkprogressbar.c
index c950dcfff2..a19c390870 100644
--- a/gtk/gtkprogressbar.c
+++ b/gtk/gtkprogressbar.c
@@ -266,7 +266,6 @@ static void
 update_fraction_classes (GtkProgressBar *pbar)
 {
   GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar);
-  GtkStyleContext *context;
   gboolean empty = FALSE;
   gboolean full = FALSE;
 
@@ -281,25 +280,22 @@ update_fraction_classes (GtkProgressBar *pbar)
         full = TRUE;
     }
 
-  context = gtk_widget_get_style_context (priv->trough_widget);
-
   if (empty)
-    gtk_style_context_add_class (context, "empty");
+    gtk_widget_add_style_class (priv->trough_widget, "empty");
   else
-    gtk_style_context_remove_class (context, "empty");
+    gtk_widget_remove_style_class (priv->trough_widget, "empty");
 
   if (full)
-    gtk_style_context_add_class (context, "full");
+    gtk_widget_add_style_class (priv->trough_widget, "full");
   else
-    gtk_style_context_remove_class (context, "full");
+    gtk_widget_remove_style_class (priv->trough_widget, "full");
 }
 
 static void
 update_node_classes (GtkProgressBar *pbar)
 {
   GtkProgressBarPrivate *priv = gtk_progress_bar_get_instance_private (pbar);
-  GtkStyleContext *context;
-  gboolean left = FALSE;
+    gboolean left = FALSE;
   gboolean right = FALSE;
   gboolean top = FALSE;
   gboolean bottom = FALSE;
@@ -344,27 +340,25 @@ update_node_classes (GtkProgressBar *pbar)
         }
     }
 
-  context = gtk_widget_get_style_context (priv->progress_widget);
-
   if (left)
-    gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
+    gtk_widget_add_style_class (priv->progress_widget, GTK_STYLE_CLASS_LEFT);
   else
-    gtk_style_context_remove_class (context, GTK_STYLE_CLASS_LEFT);
+    gtk_widget_remove_style_class (priv->progress_widget, GTK_STYLE_CLASS_LEFT);
 
   if (right)
-    gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
+    gtk_widget_add_style_class (priv->progress_widget, GTK_STYLE_CLASS_RIGHT);
   else
-    gtk_style_context_remove_class (context, GTK_STYLE_CLASS_RIGHT);
+    gtk_widget_remove_style_class (priv->progress_widget, GTK_STYLE_CLASS_RIGHT);
 
   if (top)
-    gtk_style_context_add_class (context, GTK_STYLE_CLASS_TOP);
+    gtk_widget_add_style_class (priv->progress_widget, GTK_STYLE_CLASS_TOP);
   else
-    gtk_style_context_remove_class (context, GTK_STYLE_CLASS_TOP);
+    gtk_widget_remove_style_class (priv->progress_widget, GTK_STYLE_CLASS_TOP);
 
   if (bottom)
-    gtk_style_context_add_class (context, GTK_STYLE_CLASS_BOTTOM);
+    gtk_widget_add_style_class (priv->progress_widget, GTK_STYLE_CLASS_BOTTOM);
   else
-    gtk_style_context_remove_class (context, GTK_STYLE_CLASS_BOTTOM);
+    gtk_widget_remove_style_class (priv->progress_widget, GTK_STYLE_CLASS_BOTTOM);
 
   update_fraction_classes (pbar);
 }
@@ -667,7 +661,7 @@ gtk_progress_bar_act_mode_enter (GtkProgressBar *pbar)
   GtkWidget *widget = GTK_WIDGET (pbar);
   gboolean inverted;
 
-  gtk_style_context_add_class (gtk_widget_get_style_context (priv->progress_widget), GTK_STYLE_CLASS_PULSE);
+  gtk_widget_add_style_class (priv->progress_widget, GTK_STYLE_CLASS_PULSE);
 
   inverted = priv->inverted;
   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c
index 918ecb3bbb..e49675934a 100644
--- a/gtk/gtkscale.c
+++ b/gtk/gtkscale.c
@@ -1042,24 +1042,21 @@ static void
 update_value_position (GtkScale *scale)
 {
   GtkScalePrivate *priv = gtk_scale_get_instance_private (scale);
-  GtkStyleContext *context;
 
   if (!priv->value_widget)
     return;
 
-  context = gtk_widget_get_style_context (priv->value_widget);
-
-  gtk_style_context_remove_class (context, GTK_STYLE_CLASS_TOP);
-  gtk_style_context_remove_class (context, GTK_STYLE_CLASS_RIGHT);
-  gtk_style_context_remove_class (context, GTK_STYLE_CLASS_BOTTOM);
-  gtk_style_context_remove_class (context, GTK_STYLE_CLASS_LEFT);
+  gtk_widget_remove_style_class (priv->value_widget, GTK_STYLE_CLASS_TOP);
+  gtk_widget_remove_style_class (priv->value_widget, GTK_STYLE_CLASS_RIGHT);
+  gtk_widget_remove_style_class (priv->value_widget, GTK_STYLE_CLASS_BOTTOM);
+  gtk_widget_remove_style_class (priv->value_widget, GTK_STYLE_CLASS_LEFT);
 
   switch (priv->value_pos)
     {
-    case GTK_POS_TOP:    gtk_style_context_add_class (context, GTK_STYLE_CLASS_TOP); break;
-    case GTK_POS_RIGHT:  gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT); break;
-    case GTK_POS_BOTTOM: gtk_style_context_add_class (context, GTK_STYLE_CLASS_BOTTOM); break;
-    case GTK_POS_LEFT:   gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT); break;
+    case GTK_POS_TOP:    gtk_widget_add_style_class (priv->value_widget, GTK_STYLE_CLASS_TOP); break;
+    case GTK_POS_RIGHT:  gtk_widget_add_style_class (priv->value_widget, GTK_STYLE_CLASS_RIGHT); break;
+    case GTK_POS_BOTTOM: gtk_widget_add_style_class (priv->value_widget, GTK_STYLE_CLASS_BOTTOM); break;
+    case GTK_POS_LEFT:   gtk_widget_add_style_class (priv->value_widget, GTK_STYLE_CLASS_LEFT); break;
 
     default: g_assert_not_reached ();
     }
@@ -1646,20 +1643,17 @@ void
 gtk_scale_clear_marks (GtkScale *scale)
 {
   GtkScalePrivate *priv = gtk_scale_get_instance_private (scale);
-  GtkStyleContext *context;
 
   g_return_if_fail (GTK_IS_SCALE (scale));
 
   g_slist_free_full (priv->marks, gtk_scale_mark_free);
   priv->marks = NULL;
 
-
   g_clear_pointer (&priv->top_marks_widget, gtk_widget_unparent);
   g_clear_pointer (&priv->bottom_marks_widget, gtk_widget_unparent);
 
-  context = gtk_widget_get_style_context (GTK_WIDGET (scale));
-  gtk_style_context_remove_class (context, "marks-before");
-  gtk_style_context_remove_class (context, "marks-after");
+  gtk_widget_remove_style_class (GTK_WIDGET (scale), "marks-before");
+  gtk_widget_remove_style_class (GTK_WIDGET (scale), "marks-after");
 
   _gtk_range_set_stop_values (GTK_RANGE (scale), NULL, 0);
 
@@ -1700,7 +1694,6 @@ gtk_scale_add_mark (GtkScale        *scale,
   GSList *m;
   gdouble *values;
   gint n, i;
-  GtkStyleContext *context;
   GtkWidget *marks_widget;
 
   g_return_if_fail (GTK_IS_SCALE (scale));
@@ -1735,8 +1728,7 @@ gtk_scale_add_mark (GtkScale        *scale,
                                    (priv->value_widget &&
                                     (priv->value_pos == GTK_POS_TOP || priv->value_pos == GTK_POS_LEFT)) ?
                                      priv->value_widget : NULL);
-          gtk_style_context_add_class (gtk_widget_get_style_context (priv->top_marks_widget),
-                                       GTK_STYLE_CLASS_TOP);
+          gtk_widget_add_style_class (priv->top_marks_widget, GTK_STYLE_CLASS_TOP);
         }
       marks_widget = priv->top_marks_widget;
     }
@@ -1755,8 +1747,7 @@ gtk_scale_add_mark (GtkScale        *scale,
                                     (priv->value_widget &&
                                      (priv->value_pos == GTK_POS_BOTTOM || priv->value_pos == 
GTK_POS_RIGHT)) ?
                                       priv->value_widget: NULL);
-          gtk_style_context_add_class (gtk_widget_get_style_context (priv->bottom_marks_widget),
-                                       GTK_STYLE_CLASS_BOTTOM);
+          gtk_widget_add_style_class (priv->bottom_marks_widget, GTK_STYLE_CLASS_BOTTOM);
         }
       marks_widget = priv->bottom_marks_widget;
     }
@@ -1810,11 +1801,11 @@ gtk_scale_add_mark (GtkScale        *scale,
 
   g_free (values);
 
-  context = gtk_widget_get_style_context (GTK_WIDGET (scale));
   if (priv->top_marks_widget)
-    gtk_style_context_add_class (context, "marks-before");
+    gtk_widget_add_style_class (GTK_WIDGET (scale), "marks-before");
+
   if (priv->bottom_marks_widget)
-    gtk_style_context_add_class (context, "marks-after");
+    gtk_widget_add_style_class (GTK_WIDGET (scale), "marks-after");
 
   gtk_widget_queue_resize (widget);
 }
diff --git a/gtk/gtkshortcutlabel.c b/gtk/gtkshortcutlabel.c
index 4afa3f901f..9dc6355333 100644
--- a/gtk/gtkshortcutlabel.c
+++ b/gtk/gtkshortcutlabel.c
@@ -258,7 +258,7 @@ dim_label (const gchar *text)
   GtkWidget *label;
 
   label = gtk_label_new (text);
-  gtk_style_context_add_class (gtk_widget_get_style_context (label), "dim-label");
+  gtk_widget_add_style_class (label, "dim-label");
 
   return label;
 }
@@ -284,7 +284,7 @@ display_shortcut (GtkWidget       *self,
       if (i < n_mods)
         gtk_widget_set_size_request (disp, 50, -1);
 
-      gtk_style_context_add_class (gtk_widget_get_style_context (disp), "keycap");
+      gtk_widget_add_style_class (disp, "keycap");
       gtk_label_set_use_markup (GTK_LABEL (disp), TRUE);
 
       gtk_widget_set_parent (disp, self);
diff --git a/gtk/gtkshortcutssection.c b/gtk/gtkshortcutssection.c
index 0bb55fee01..9195f09ea0 100644
--- a/gtk/gtkshortcutssection.c
+++ b/gtk/gtkshortcutssection.c
@@ -729,8 +729,7 @@ gtk_shortcuts_section_reflow_groups (GtkShortcutsSection *self)
   {
     GtkWidget *w;
 
-    gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self->switcher)),
-                                 "circular");
+    gtk_widget_add_style_class (GTK_WIDGET (self->switcher), "circular");
 
     for (w = gtk_widget_get_first_child (GTK_WIDGET (self->switcher));
          w != NULL;
@@ -738,7 +737,7 @@ gtk_shortcuts_section_reflow_groups (GtkShortcutsSection *self)
       {
         GtkWidget *label;
 
-        gtk_style_context_add_class (gtk_widget_get_style_context (w), "circular");
+        gtk_widget_add_style_class (w, "circular");
 
         label = gtk_bin_get_child (GTK_BIN (w));
         gtk_label_set_use_underline (GTK_LABEL (label), TRUE);
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c
index 93484a617f..c2e916b87b 100644
--- a/gtk/gtkspinbutton.c
+++ b/gtk/gtkspinbutton.c
@@ -965,7 +965,7 @@ gtk_spin_button_init (GtkSpinButton *spin_button)
   gtk_widget_set_parent (priv->entry, GTK_WIDGET (spin_button));
 
   priv->down_button = gtk_button_new_from_icon_name ("value-decrease-symbolic");
-  gtk_style_context_add_class (gtk_widget_get_style_context (priv->down_button), "down");
+  gtk_widget_add_style_class (priv->down_button, "down");
   gtk_widget_set_can_focus (priv->down_button, FALSE);
   gtk_widget_set_parent (priv->down_button, GTK_WIDGET (spin_button));
 
@@ -980,7 +980,7 @@ gtk_spin_button_init (GtkSpinButton *spin_button)
   gtk_widget_add_controller (GTK_WIDGET (priv->down_button), GTK_EVENT_CONTROLLER (gesture));
 
   priv->up_button = gtk_button_new_from_icon_name ("value-increase-symbolic");
-  gtk_style_context_add_class (gtk_widget_get_style_context (priv->up_button), "up");
+  gtk_widget_add_style_class (priv->up_button, "up");
   gtk_widget_set_can_focus (priv->up_button, FALSE);
   gtk_widget_set_parent (priv->up_button, GTK_WIDGET (spin_button));
 
diff --git a/gtk/gtkstackswitcher.c b/gtk/gtkstackswitcher.c
index c9d30fecf1..572c108958 100644
--- a/gtk/gtkstackswitcher.c
+++ b/gtk/gtkstackswitcher.c
@@ -111,14 +111,12 @@ static void
 gtk_stack_switcher_init (GtkStackSwitcher *switcher)
 {
   GtkStackSwitcherPrivate *priv = gtk_stack_switcher_get_instance_private (switcher);
-  GtkStyleContext *context;
   GdkContentFormats *formats;
   GtkDropTarget *dest;
 
   priv->buttons = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, NULL);
 
-  context = gtk_widget_get_style_context (GTK_WIDGET (switcher));
-  gtk_style_context_add_class (context, GTK_STYLE_CLASS_LINKED);
+  gtk_widget_add_style_class (GTK_WIDGET (switcher), "linked");
 
   formats = gdk_content_formats_new (NULL, 0);
   dest = gtk_drop_target_new (formats, 0);
@@ -157,7 +155,6 @@ rebuild_child (GtkWidget   *self,
                const gchar *icon_name,
                const gchar *title)
 {
-  GtkStyleContext *context;
   GtkWidget *button_child;
 
   button_child = gtk_bin_get_child (GTK_BIN (self));
@@ -165,7 +162,6 @@ rebuild_child (GtkWidget   *self,
     gtk_widget_destroy (button_child);
 
   button_child = NULL;
-  context = gtk_widget_get_style_context (GTK_WIDGET (self));
 
   if (icon_name != NULL)
     {
@@ -173,8 +169,8 @@ rebuild_child (GtkWidget   *self,
       if (title != NULL)
         gtk_widget_set_tooltip_text (GTK_WIDGET (self), title);
 
-      gtk_style_context_remove_class (context, "text-button");
-      gtk_style_context_add_class (context, "image-button");
+      gtk_widget_remove_style_class (self, "text-button");
+      gtk_widget_add_style_class (self, "image-button");
     }
   else if (title != NULL)
     {
@@ -182,8 +178,8 @@ rebuild_child (GtkWidget   *self,
 
       gtk_widget_set_tooltip_text (GTK_WIDGET (self), NULL);
 
-      gtk_style_context_remove_class (context, "image-button");
-      gtk_style_context_add_class (context, "text-button");
+      gtk_widget_remove_style_class (self, "image-button");
+      gtk_widget_add_style_class (self, "text-button");
     }
 
   if (button_child)
@@ -202,7 +198,6 @@ update_button (GtkStackSwitcher *self,
   gchar *icon_name;
   gboolean needs_attention;
   gboolean visible;
-  GtkStyleContext *context;
 
   g_object_get (page,
                 "title", &title,
@@ -215,11 +210,10 @@ update_button (GtkStackSwitcher *self,
 
   gtk_widget_set_visible (button, visible && (title != NULL || icon_name != NULL));
 
-  context = gtk_widget_get_style_context (button);
   if (needs_attention)
-    gtk_style_context_add_class (context, GTK_STYLE_CLASS_NEEDS_ATTENTION);
+    gtk_widget_add_style_class (button, GTK_STYLE_CLASS_NEEDS_ATTENTION);
   else
-    gtk_style_context_remove_class (context, GTK_STYLE_CLASS_NEEDS_ATTENTION);
+    gtk_widget_remove_style_class (button, GTK_STYLE_CLASS_NEEDS_ATTENTION);
 
   g_free (title);
   g_free (icon_name);
diff --git a/gtk/gtktoolbutton.c b/gtk/gtktoolbutton.c
index 8cc681cf8f..d99a064f9c 100644
--- a/gtk/gtktoolbutton.c
+++ b/gtk/gtktoolbutton.c
@@ -492,8 +492,8 @@ gtk_tool_button_construct_contents (GtkToolItem *tool_item)
     case GTK_TOOLBAR_ICONS:
       if (icon)
         gtk_container_add (GTK_CONTAINER (button->priv->button), icon);
-      gtk_style_context_add_class (gtk_widget_get_style_context (button->priv->button), "image-button");
-      gtk_style_context_remove_class (gtk_widget_get_style_context (button->priv->button), "text-button");
+      gtk_widget_add_style_class (button->priv->button, "image-button");
+      gtk_widget_remove_style_class (button->priv->button, "text-button");
       break;
 
     case GTK_TOOLBAR_BOTH:
@@ -507,8 +507,9 @@ gtk_tool_button_construct_contents (GtkToolItem *tool_item)
 
       gtk_container_add (GTK_CONTAINER (box), label);
       gtk_container_add (GTK_CONTAINER (button->priv->button), box);
-      gtk_style_context_add_class (gtk_widget_get_style_context (button->priv->button), "image-button");
-      gtk_style_context_add_class (gtk_widget_get_style_context (button->priv->button), "text-button");
+      gtk_widget_add_style_class (button->priv->button, "image-button");
+      gtk_widget_add_style_class (button->priv->button, "text-button");
+
       break;
 
     case GTK_TOOLBAR_BOTH_HORIZ:
@@ -537,14 +538,14 @@ gtk_tool_button_construct_contents (GtkToolItem *tool_item)
             gtk_container_add (GTK_CONTAINER (box), label);
        }
       gtk_container_add (GTK_CONTAINER (button->priv->button), box);
-      gtk_style_context_add_class (gtk_widget_get_style_context (button->priv->button), "image-button");
-      gtk_style_context_add_class (gtk_widget_get_style_context (button->priv->button), "text-button");
+      gtk_widget_add_style_class (button->priv->button, "image-button");
+      gtk_widget_add_style_class (button->priv->button, "text-button");
       break;
 
     case GTK_TOOLBAR_TEXT:
       gtk_container_add (GTK_CONTAINER (button->priv->button), label);
-      gtk_style_context_add_class (gtk_widget_get_style_context (button->priv->button), "text-button");
-      gtk_style_context_remove_class (gtk_widget_get_style_context (button->priv->button), "image-button");
+      gtk_widget_add_style_class (button->priv->button, "text-button");
+      gtk_widget_remove_style_class (button->priv->button, "image-button");
       break;
     }
 
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index f29b2936ca..4b4382de1f 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -5476,16 +5476,13 @@ _gtk_widget_set_has_default (GtkWidget *widget,
                              gboolean   has_default)
 {
   GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
-  GtkStyleContext *context;
 
   priv->has_default = has_default;
 
-  context = _gtk_widget_get_style_context (widget);
-
   if (has_default)
-    gtk_style_context_add_class (context, GTK_STYLE_CLASS_DEFAULT);
+    gtk_widget_add_style_class (widget, GTK_STYLE_CLASS_DEFAULT);
   else
-    gtk_style_context_remove_class (context, GTK_STYLE_CLASS_DEFAULT);
+    gtk_widget_remove_style_class (widget, GTK_STYLE_CLASS_DEFAULT);
 }
 
 /**



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]