Add gtk_widget_get_style_color
authorMatthias Clasen <mclasen@redhat.com>
Wed, 12 Oct 2022 18:51:22 +0000 (14:51 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 12 Oct 2022 19:35:00 +0000 (15:35 -0400)
There is a widespread need to access the CSS foreground
color for custom drawing in snapshot functions, so make
it available after gtk_style_context_get_color was
deprecated with a new widget api.

gtk/deprecated/gtkstylecontext.c
gtk/gtkwidget.c
gtk/gtkwidget.h

index 0f399a5a9544e0eb812977f4ada84e6d04de9a69..d8f113f3698c409ff618638a9944d4c0708fa4ef 100644 (file)
@@ -824,7 +824,7 @@ gtk_style_context_lookup_color (GtkStyleContext *context,
  *
  * Gets the foreground color for a given state.
  *
- * Deprecated: 4.10: This api will be removed in GTK 5
+ * Deprecated: 4.10: Use [method@Gtk.Widget.get_style_color] instead
  */
 void
 gtk_style_context_get_color (GtkStyleContext *context,
index 1aa14bf06be7a3606c74948f73befa3d3d46c746..e0e3c169aef09d184f487cd15e6a65d9d0d42f8d 100644 (file)
@@ -35,6 +35,7 @@
 #include "gtkconstraint.h"
 #include "gtkcssboxesprivate.h"
 #include "gtkcssfiltervalueprivate.h"
+#include "gtkcsscolorvalueprivate.h"
 #include "gtkcsstransformvalueprivate.h"
 #include "gtkcsspositionvalueprivate.h"
 #include "gtkcssfontvariationsvalueprivate.h"
@@ -12869,6 +12870,33 @@ gtk_widget_set_css_classes (GtkWidget   *widget,
   g_object_notify_by_pspec (G_OBJECT (widget), widget_props[PROP_CSS_CLASSES]);
 }
 
+/**
+ * gtk_widget_get_css_style:
+ * @widget: a `GtkWidget`
+ * @color: (out): return location for the color
+ *
+ * Gets the current foreground color for the widgets
+ * CSS style.
+ *
+ * This function should only be used in snapshot
+ * implementations that need need to do custom
+ * drawing with the foreground color.
+ *
+ * Since: 4.10
+ */
+void
+gtk_widget_get_style_color (GtkWidget *widget,
+                            GdkRGBA   *color)
+{
+  GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
+  GtkCssStyle *style;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+
+  style = gtk_css_node_get_style (priv->cssnode);
+  *color = *gtk_css_color_value_get_rgba (style->core->color);
+}
+
 /*< private >
  * gtk_widget_update_orientation:
  * @widget: a `GtkWidget` implementing `GtkOrientable`
index 5374160dcfe1a590cc945180ce24548bdd9c0dd2..fce637a3fdece840768100cb603257d3fed80ae2 100644 (file)
@@ -928,7 +928,9 @@ GDK_AVAILABLE_IN_ALL
 void                    gtk_widget_set_css_classes      (GtkWidget   *widget,
                                                          const char **classes);
 
-
+GDK_AVAILABLE_IN_4_10
+void                    gtk_widget_get_style_color      (GtkWidget   *widget,
+                                                         GdkRGBA     *rgba);
 
 
 /**