diff options
author | Matthias Clasen <mclasen@redhat.com> | 2015-10-25 15:42:40 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2015-10-25 15:45:13 -0400 |
commit | caa6fb073215a9700e9406bdddc513a9d3a726e3 (patch) | |
tree | 2932b0c0fe5721f4e5fb1c5d28523e5ac7edd048 /gtk/gtkaccellabel.c | |
parent | 2b20bd54c590c0f537ec43b23b0cc4017979e7a3 (diff) | |
download | gtk+-caa6fb073215a9700e9406bdddc513a9d3a726e3.tar.gz |
accel label: Use a css node for the accelerator
Use a permanent subnode with name accelerator instead of the
.accelerator style class.
Diffstat (limited to 'gtk/gtkaccellabel.c')
-rw-r--r-- | gtk/gtkaccellabel.c | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/gtk/gtkaccellabel.c b/gtk/gtkaccellabel.c index 95b0043099..d94b7a48be 100644 --- a/gtk/gtkaccellabel.c +++ b/gtk/gtkaccellabel.c @@ -36,6 +36,9 @@ #include "gtkrender.h" #include "gtksizerequest.h" #include "gtkstylecontextprivate.h" +#include "gtkwidgetprivate.h" +#include "gtkcssnodeprivate.h" +#include "gtkcssstylepropertyprivate.h" /** * SECTION:gtkaccellabel @@ -91,6 +94,11 @@ * gtk_widget_add_accelerator (save_item, "activate", accel_group, * GDK_KEY_s, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); * ]| + * + * # CSS nodes + * + * Like #GtkLabel, GtkAccelLabel has a main CSS node with the name label. + * It adds a subnode with name accelerator. */ enum { @@ -106,6 +114,7 @@ struct _GtkAccelLabelPrivate GClosure *accel_closure; /* has set function */ GtkAccelGroup *accel_group; /* set by set_accel_closure() */ gchar *accel_string; /* has set function */ + GtkCssNode *accel_node; guint accel_padding; /* should be style property? */ guint16 accel_string_width; /* seems to be private */ @@ -254,9 +263,33 @@ gtk_accel_label_get_property (GObject *object, } static void +node_style_changed_cb (GtkCssNode *node, + GtkCssStyle *old_style, + GtkCssStyle *new_style, + GtkWidget *widget) +{ + GtkBitmask *changes; + static GtkBitmask *affects_size = NULL; + + if (G_UNLIKELY (affects_size == NULL)) + affects_size = _gtk_css_style_property_get_mask_affecting (GTK_CSS_AFFECTS_SIZE | GTK_CSS_AFFECTS_CLIP); + + changes = _gtk_bitmask_new (); + changes = gtk_css_style_add_difference (changes, old_style, new_style); + + if (_gtk_bitmask_intersects (changes, affects_size)) + gtk_widget_queue_resize (widget); + else + gtk_widget_queue_draw (widget); + + _gtk_bitmask_free (changes); +} + +static void gtk_accel_label_init (GtkAccelLabel *accel_label) { GtkAccelLabelPrivate *priv; + GtkCssNode *widget_node; accel_label->priv = gtk_accel_label_get_instance_private (accel_label); priv = accel_label->priv; @@ -266,6 +299,14 @@ gtk_accel_label_init (GtkAccelLabel *accel_label) priv->accel_closure = NULL; priv->accel_group = NULL; priv->accel_string = NULL; + + widget_node = gtk_widget_get_css_node (GTK_WIDGET (accel_label)); + priv->accel_node = gtk_css_node_new (); + gtk_css_node_set_name (priv->accel_node, I_("accelerator")); + gtk_css_node_set_parent (priv->accel_node, widget_node); + gtk_css_node_set_state (priv->accel_node, gtk_css_node_get_state (widget_node)); + g_signal_connect_object (priv->accel_node, "style-changed", G_CALLBACK (node_style_changed_cb), accel_label, 0); + g_object_unref (priv->accel_node); } /** @@ -358,8 +399,7 @@ gtk_accel_label_get_accel_layout (GtkAccelLabel *accel_label) context = gtk_widget_get_style_context (widget); - gtk_style_context_save (context); - gtk_style_context_add_class (context, GTK_STYLE_CLASS_ACCELERATOR); + gtk_style_context_save_to_node (context, accel_label->priv->accel_node); layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label)); @@ -473,8 +513,7 @@ gtk_accel_label_draw (GtkWidget *widget, accel_layout = gtk_accel_label_get_accel_layout (accel_label); y += get_first_baseline (label_layout) - get_first_baseline (accel_layout) - allocation.y; - gtk_style_context_save (context); - gtk_style_context_add_class (context, GTK_STYLE_CLASS_ACCELERATOR); + gtk_style_context_save_to_node (context, accel_label->priv->accel_node); gtk_render_layout (context, cr, x, y, accel_layout); gtk_style_context_restore (context); |