[gtk+] GtkScale: Add style classes for marks
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] GtkScale: Add style classes for marks
- Date: Thu, 3 Mar 2011 21:50:04 +0000 (UTC)
commit 77e46de0e173fda917d1141ccfe69ce668a81b31
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Mar 3 16:47:55 2011 -0500
GtkScale: Add style classes for marks
This enables better styling of the slider in the presence of
marks. Based on a patch by Bastien Nocera,
https://bugzilla.gnome.org/show_bug.cgi?id=643685
gtk/gtkscale.c | 34 +++++++++++++++++++++++++++++++---
gtk/gtkstylecontext.h | 18 ++++++++++++++++++
2 files changed, 49 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c
index a9a9880..95ce6ba 100644
--- a/gtk/gtkscale.c
+++ b/gtk/gtkscale.c
@@ -77,7 +77,6 @@
* unrelated code portions otherwise
*/
-
typedef struct _GtkScaleMark GtkScaleMark;
struct _GtkScalePrivate
@@ -1459,6 +1458,7 @@ void
gtk_scale_clear_marks (GtkScale *scale)
{
GtkScalePrivate *priv;
+ GtkStyleContext *context;
g_return_if_fail (GTK_IS_SCALE (scale));
@@ -1468,6 +1468,10 @@ gtk_scale_clear_marks (GtkScale *scale)
g_slist_free (priv->marks);
priv->marks = NULL;
+ context = gtk_widget_get_style_context (GTK_WIDGET (scale));
+ gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW);
+ gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
+
_gtk_range_set_stop_values (GTK_RANGE (scale), NULL, 0);
gtk_widget_queue_resize (GTK_WIDGET (scale));
@@ -1518,6 +1522,8 @@ gtk_scale_add_mark (GtkScale *scale,
GSList *m;
gdouble *values;
gint n, i;
+ GtkStyleContext *context;
+ int all_pos;
g_return_if_fail (GTK_IS_SCALE (scale));
@@ -1531,22 +1537,44 @@ gtk_scale_add_mark (GtkScale *scale,
mark->position = GTK_POS_TOP;
else
mark->position = GTK_POS_BOTTOM;
-
+
priv->marks = g_slist_insert_sorted (priv->marks, mark,
(GCompareFunc) compare_marks);
+#define MARKS_ABOVE 1
+#define MARKS_BELOW 2
+
+ all_pos = 0;
n = g_slist_length (priv->marks);
values = g_new (gdouble, n);
for (m = priv->marks, i = 0; m; m = m->next, i++)
{
mark = m->data;
values[i] = mark->value;
+ if (mark->position == GTK_POS_TOP)
+ all_pos |= MARKS_ABOVE;
+ else
+ all_pos |= MARKS_BELOW;
}
-
+
_gtk_range_set_stop_values (GTK_RANGE (scale), values, n);
g_free (values);
+ /* Set the style classes for the slider, so it could
+ * point to the right direction when marks are present
+ */
+ context = gtk_widget_get_style_context (GTK_WIDGET (scale));
+
+ if (all_pos & MARKS_ABOVE)
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
+ else
+ gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
+ if (all_pos & MARKS_BELOW)
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW);
+ else
+ gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW);
+
gtk_widget_queue_resize (GTK_WIDGET (scale));
}
diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h
index 2fad447..b0a278a 100644
--- a/gtk/gtkstylecontext.h
+++ b/gtk/gtkstylecontext.h
@@ -277,6 +277,24 @@ struct _GtkStyleContextClass
#define GTK_STYLE_CLASS_SCALE "scale"
/**
+ * GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE:
+ *
+ * A CSS class to match scale widgets with marks attached,
+ * all the marks are above for horizontal #GtkScale.
+ * left for vertical #GtkScale.
+ */
+#define GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE "scale-has-marks-above"
+
+/**
+ * GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW:
+ *
+ * A CSS class to match scale widgets with marks attached,
+ * all the marks are below for horizontal #GtkScale,
+ * right for vertical #GtkScale.
+ */
+#define GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW "scale-has-marks-below"
+
+/**
* GTK_STYLE_CLASS_HEADER:
*
* A CSS class to match a header element.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]