[gtk+/gtk-style-context: 25/191] GtkStyleContext: Add style classes.



commit 8ae07b0aaf94a09047c84b41a0c0545d81776d0e
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Mar 20 13:02:20 2010 +0100

    GtkStyleContext: Add style classes.
    
    Style classes are the replacement of detail strings.

 gtk/gtkstylecontext.c |   83 +++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkstylecontext.h |    7 ++++
 2 files changed, 90 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 6dfdf50..59fc5c3 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -44,6 +44,7 @@ struct GtkStyleContextPrivate
   GtkWidgetPath *widget_path;
 
   GtkStateFlags state_flags;
+  GList *style_classes;
 
   GtkThemingEngine *theming_engine;
 };
@@ -361,5 +362,87 @@ gtk_style_context_get_path (GtkStyleContext *context)
   return priv->widget_path;
 }
 
+void
+gtk_style_context_set_class (GtkStyleContext *context,
+                             const gchar     *class_name)
+{
+  GtkStyleContextPrivate *priv;
+  GQuark class_quark;
+  GList *link;
+
+  g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+  g_return_if_fail (class_name != NULL);
+
+  priv = GTK_STYLE_CONTEXT_GET_PRIVATE (context);
+  class_quark = g_quark_from_string (class_name);
+
+  link = priv->style_classes;
+
+  while (link)
+    {
+      GQuark link_quark;
+
+      link_quark = GUINT_TO_POINTER (link->data);
+
+      if (link_quark == class_quark)
+        return;
+      else if (link_quark > class_quark)
+        {
+          priv->style_classes = g_list_insert_before (priv->style_classes,
+                                                      link, GUINT_TO_POINTER (class_quark));
+          return;
+        }
+
+      link = link->next;
+    }
+
+  priv->style_classes = g_list_append (priv->style_classes,
+                                       GUINT_TO_POINTER (class_quark));
+}
+
+void
+gtk_style_context_unset_class (GtkStyleContext *context,
+                               const gchar     *class_name)
+{
+  GtkStyleContextPrivate *priv;
+  GQuark class_quark;
+
+  g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+  g_return_if_fail (class_name != NULL);
+
+  class_quark = g_quark_try_string (class_name);
+
+  if (!class_quark)
+    return;
+
+  priv = GTK_STYLE_CONTEXT_GET_PRIVATE (context);
+  priv->style_classes = g_list_remove (priv->style_classes,
+                                       GUINT_TO_POINTER (class_quark));
+}
+
+gboolean
+gtk_style_context_has_class (GtkStyleContext *context,
+                             const gchar     *class_name)
+{
+  GtkStyleContextPrivate *priv;
+  GQuark class_quark;
+
+  g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
+  g_return_val_if_fail (class_name != NULL, FALSE);
+
+  class_quark = g_quark_try_string (class_name);
+
+  if (!class_quark)
+    return FALSE;
+
+  priv = GTK_STYLE_CONTEXT_GET_PRIVATE (context);
+
+  if (g_list_find (priv->style_classes,
+                   GUINT_TO_POINTER (class_quark)))
+    return TRUE;
+
+  return FALSE;
+}
+
 #define __GTK_STYLE_CONTEXT_C__
 #include "gtkaliasdef.c"
diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h
index 79f0f35..3d594ee 100644
--- a/gtk/gtkstylecontext.h
+++ b/gtk/gtkstylecontext.h
@@ -77,6 +77,13 @@ void          gtk_style_context_set_path     (GtkStyleContext *context,
                                               GtkWidgetPath   *path);
 G_CONST_RETURN GtkWidgetPath * gtk_style_context_get_path (GtkStyleContext *context);
 
+void     gtk_style_context_set_class   (GtkStyleContext *context,
+                                        const gchar     *class_name);
+void     gtk_style_context_unset_class (GtkStyleContext *context,
+                                        const gchar     *class_name);
+gboolean gtk_style_context_has_class   (GtkStyleContext *context,
+                                        const gchar     *class_name);
+
 
 G_END_DECLS
 



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