]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcssstringvalue.c
gtkenums: correct various documentation typos
[~andy/gtk] / gtk / gtkcssstringvalue.c
index 16debf991c4a9ecbf2154ae463e4f51113fd8cf8..82e7c37b6ed59edb163e939a87b4787f1c9ed50d 100644 (file)
@@ -29,9 +29,21 @@ struct _GtkCssValue {
 static void
 gtk_css_value_string_free (GtkCssValue *value)
 {
+  g_free (value->string);
   g_slice_free (GtkCssValue, value);
 }
 
+static GtkCssValue *
+gtk_css_value_string_compute (GtkCssValue             *value,
+                              guint                    property_id,
+                              GtkStyleProviderPrivate *provider,
+                              GtkCssComputedValues    *values,
+                              GtkCssComputedValues    *parent_values,
+                              GtkCssDependencies      *dependencies)
+{
+  return _gtk_css_value_ref (value);
+}
+
 static gboolean
 gtk_css_value_string_equal (const GtkCssValue *value1,
                             const GtkCssValue *value2)
@@ -39,6 +51,15 @@ gtk_css_value_string_equal (const GtkCssValue *value1,
   return g_strcmp0 (value1->string, value2->string) == 0;
 }
 
+static GtkCssValue *
+gtk_css_value_string_transition (GtkCssValue *start,
+                                 GtkCssValue *end,
+                                 guint        property_id,
+                                 double       progress)
+{
+  return NULL;
+}
+
 static void
 gtk_css_value_string_print (const GtkCssValue *value,
                             GString           *str)
@@ -46,6 +67,12 @@ gtk_css_value_string_print (const GtkCssValue *value,
   char *string = value->string;
   gsize len;
 
+  if (string == NULL)
+    {
+      g_string_append (str, "none");
+      return;
+    }
+
   g_string_append_c (str, '"');
 
   do {
@@ -80,12 +107,62 @@ gtk_css_value_string_print (const GtkCssValue *value,
   g_string_append_c (str, '"');
 }
 
+static void
+gtk_css_value_ident_print (const GtkCssValue *value,
+                            GString           *str)
+{
+  char *string = value->string;
+  gsize len;
+
+  do {
+    len = strcspn (string, "\"\n\r\f");
+    g_string_append_len (str, string, len);
+    string += len;
+    switch (*string)
+      {
+      case '\0':
+        break;
+      case '\n':
+        g_string_append (str, "\\A ");
+        break;
+      case '\r':
+        g_string_append (str, "\\D ");
+        break;
+      case '\f':
+        g_string_append (str, "\\C ");
+        break;
+      case '\"':
+        g_string_append (str, "\\\"");
+        break;
+      case '\'':
+        g_string_append (str, "\\'");
+        break;
+      case '\\':
+        g_string_append (str, "\\\\");
+        break;
+      default:
+        g_assert_not_reached ();
+        break;
+      }
+  } while (*string);
+}
+
 static const GtkCssValueClass GTK_CSS_VALUE_STRING = {
   gtk_css_value_string_free,
+  gtk_css_value_string_compute,
   gtk_css_value_string_equal,
+  gtk_css_value_string_transition,
   gtk_css_value_string_print
 };
 
+static const GtkCssValueClass GTK_CSS_VALUE_IDENT = {
+  gtk_css_value_string_free,
+  gtk_css_value_string_compute,
+  gtk_css_value_string_equal,
+  gtk_css_value_string_transition,
+  gtk_css_value_ident_print
+};
+
 GtkCssValue *
 _gtk_css_string_value_new (const char *string)
 {
@@ -126,3 +203,43 @@ _gtk_css_string_value_get (const GtkCssValue *value)
   return value->string;
 }
 
+GtkCssValue *
+_gtk_css_ident_value_new (const char *ident)
+{
+  return _gtk_css_ident_value_new_take (g_strdup (ident));
+}
+
+GtkCssValue *
+_gtk_css_ident_value_new_take (char *ident)
+{
+  GtkCssValue *result;
+
+  result = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_IDENT);
+  result->string = ident;
+
+  return result;
+}
+
+GtkCssValue *
+_gtk_css_ident_value_try_parse (GtkCssParser *parser)
+{
+  char *ident;
+
+  g_return_val_if_fail (parser != NULL, NULL);
+
+  ident = _gtk_css_parser_try_ident (parser, TRUE);
+  if (ident == NULL)
+    return NULL;
+  
+  return _gtk_css_ident_value_new_take (ident);
+}
+
+const char *
+_gtk_css_ident_value_get (const GtkCssValue *value)
+{
+  g_return_val_if_fail (value != NULL, NULL);
+  g_return_val_if_fail (value->class == &GTK_CSS_VALUE_IDENT, NULL);
+
+  return value->string;
+}
+