]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcssimagelinear.c
filechooserbutton: Update the combo box even after the dialog is cancelled
[~andy/gtk] / gtk / gtkcssimagelinear.c
index 998d3660cf0732267a55744ccc814902baaf70ff..0bf89e7d8b13e620b07c11b0bc39b978a806d0e4 100644 (file)
 
 #include <math.h>
 
+#include "gtkcsscolorvalueprivate.h"
 #include "gtkcssnumbervalueprivate.h"
 #include "gtkcssrgbavalueprivate.h"
 #include "gtkcssprovider.h"
-#include "gtksymboliccolorprivate.h"
 
 G_DEFINE_TYPE (GtkCssImageLinear, _gtk_css_image_linear, GTK_TYPE_CSS_IMAGE)
 
@@ -40,28 +40,36 @@ gtk_css_image_linear_get_start_end (GtkCssImageLinear *linear,
   double pos;
   guint i;
       
-  stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, 0);
-  if (stop->offset == NULL)
-    *start = 0;
-  else
-    *start = _gtk_css_number_value_get (stop->offset, length) / length;
-
-  *end = *start;
-
-  for (i = 0; i < linear->stops->len; i++)
+  if (linear->repeating)
     {
-      stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, i);
-      
+      stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, 0);
       if (stop->offset == NULL)
-        continue;
+        *start = 0;
+      else
+        *start = _gtk_css_number_value_get (stop->offset, length) / length;
 
-      pos = _gtk_css_number_value_get (stop->offset, length) / length;
+      *end = *start;
 
-      *end = MAX (pos, *end);
+      for (i = 0; i < linear->stops->len; i++)
+        {
+          stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, i);
+          
+          if (stop->offset == NULL)
+            continue;
+
+          pos = _gtk_css_number_value_get (stop->offset, length) / length;
+
+          *end = MAX (pos, *end);
+        }
+      
+      if (stop->offset == NULL)
+        *end = MAX (*end, 1.0);
+    }
+  else
+    {
+      *start = 0;
+      *end = 1;
     }
-  
-  if (stop->offset == NULL)
-    *end = MAX (*end, 1.0);
 }
 
 static void
@@ -315,7 +323,7 @@ gtk_css_image_linear_parse (GtkCssImage  *image,
   do {
     GtkCssImageLinearColorStop stop;
 
-    stop.color = _gtk_css_symbolic_value_new (parser);
+    stop.color = _gtk_css_color_value_parse (parser);
     if (stop.color == NULL)
       return FALSE;
 
@@ -409,9 +417,12 @@ gtk_css_image_linear_print (GtkCssImage *image,
 }
 
 static GtkCssImage *
-gtk_css_image_linear_compute (GtkCssImage     *image,
-                              guint            property_id,
-                              GtkStyleContext *context)
+gtk_css_image_linear_compute (GtkCssImage             *image,
+                              guint                    property_id,
+                              GtkStyleProviderPrivate *provider,
+                              GtkCssComputedValues    *values,
+                              GtkCssComputedValues    *parent_values,
+                              GtkCssDependencies      *dependencies)
 {
   GtkCssImageLinear *linear = GTK_CSS_IMAGE_LINEAR (image);
   GtkCssImageLinear *copy;
@@ -420,27 +431,136 @@ gtk_css_image_linear_compute (GtkCssImage     *image,
   copy = g_object_new (GTK_TYPE_CSS_IMAGE_LINEAR, NULL);
   copy->repeating = linear->repeating;
 
-  copy->angle = _gtk_css_value_compute (linear->angle, property_id, context, NULL);
+  copy->angle = _gtk_css_value_compute (linear->angle, property_id, provider, values, parent_values, dependencies);
   
   g_array_set_size (copy->stops, linear->stops->len);
   for (i = 0; i < linear->stops->len; i++)
     {
       GtkCssImageLinearColorStop *stop, *scopy;
+      GtkCssDependencies child_deps;
 
       stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, i);
       scopy = &g_array_index (copy->stops, GtkCssImageLinearColorStop, i);
               
-      scopy->color = _gtk_css_value_compute (stop->color, property_id, context, NULL);
+      scopy->color = _gtk_css_value_compute (stop->color, property_id, provider, values, parent_values, &child_deps);
+      *dependencies = _gtk_css_dependencies_union (*dependencies, child_deps);
       
       if (stop->offset)
-        scopy->offset = _gtk_css_value_compute (stop->offset, property_id, context, NULL);
+        {
+          scopy->offset = _gtk_css_value_compute (stop->offset, property_id, provider, values, parent_values, &child_deps);
+          *dependencies = _gtk_css_dependencies_union (*dependencies, child_deps);
+        }
       else
-        scopy->offset = NULL;
+        {
+          scopy->offset = NULL;
+        }
     }
 
   return GTK_CSS_IMAGE (copy);
 }
 
+static GtkCssImage *
+gtk_css_image_linear_transition (GtkCssImage *start_image,
+                                 GtkCssImage *end_image,
+                                 guint        property_id,
+                                 double       progress)
+{
+  GtkCssImageLinear *start, *end, *result;
+  guint i;
+
+  start = GTK_CSS_IMAGE_LINEAR (start_image);
+
+  if (end_image == NULL)
+
+  if (!GTK_IS_CSS_IMAGE_LINEAR (end_image))
+    return GTK_CSS_IMAGE_CLASS (_gtk_css_image_linear_parent_class)->transition (start_image, end_image, property_id, progress);
+
+  end = GTK_CSS_IMAGE_LINEAR (end_image);
+
+  if ((start->repeating != end->repeating)
+      || (start->stops->len != end->stops->len))
+    return GTK_CSS_IMAGE_CLASS (_gtk_css_image_linear_parent_class)->transition (start_image, end_image, property_id, progress);
+
+  result = g_object_new (GTK_TYPE_CSS_IMAGE_LINEAR, NULL);
+  result->repeating = start->repeating;
+
+  result->angle = _gtk_css_value_transition (start->angle, end->angle, property_id, progress);
+  if (result->angle == NULL)
+    goto fail;
+  
+  for (i = 0; i < start->stops->len; i++)
+    {
+      GtkCssImageLinearColorStop stop, *start_stop, *end_stop;
+
+      start_stop = &g_array_index (start->stops, GtkCssImageLinearColorStop, i);
+      end_stop = &g_array_index (end->stops, GtkCssImageLinearColorStop, i);
+
+      if ((start_stop->offset != NULL) != (end_stop->offset != NULL))
+        goto fail;
+
+      if (start_stop->offset == NULL)
+        {
+          stop.offset = NULL;
+        }
+      else
+        {
+          stop.offset = _gtk_css_value_transition (start_stop->offset,
+                                                   end_stop->offset,
+                                                   property_id,
+                                                   progress);
+          if (stop.offset == NULL)
+            goto fail;
+        }
+
+      stop.color = _gtk_css_value_transition (start_stop->color,
+                                              end_stop->color,
+                                              property_id,
+                                              progress);
+      if (stop.color == NULL)
+        {
+          if (stop.offset)
+            _gtk_css_value_unref (stop.offset);
+          goto fail;
+        }
+
+      g_array_append_val (result->stops, stop);
+    }
+
+  return GTK_CSS_IMAGE (result);
+
+fail:
+  g_object_unref (result);
+  return GTK_CSS_IMAGE_CLASS (_gtk_css_image_linear_parent_class)->transition (start_image, end_image, property_id, progress);
+}
+
+static gboolean
+gtk_css_image_linear_equal (GtkCssImage *image1,
+                            GtkCssImage *image2)
+{
+  GtkCssImageLinear *linear1 = GTK_CSS_IMAGE_LINEAR (image1);
+  GtkCssImageLinear *linear2 = GTK_CSS_IMAGE_LINEAR (image2);
+  guint i;
+
+  if (linear1->repeating != linear2->repeating ||
+      !_gtk_css_value_equal (linear1->angle, linear2->angle) ||
+      linear1->stops->len != linear2->stops->len)
+    return FALSE;
+
+  for (i = 0; i < linear1->stops->len; i++)
+    {
+      GtkCssImageLinearColorStop *stop1, *stop2;
+
+      stop1 = &g_array_index (linear1->stops, GtkCssImageLinearColorStop, i);
+      stop2 = &g_array_index (linear2->stops, GtkCssImageLinearColorStop, i);
+
+      if (!_gtk_css_value_equal0 (stop1->offset, stop2->offset) ||
+          !_gtk_css_value_equal (stop1->color, stop2->color))
+        return FALSE;
+    }
+
+  return TRUE;
+}
+
 static void
 gtk_css_image_linear_dispose (GObject *object)
 {
@@ -471,6 +591,8 @@ _gtk_css_image_linear_class_init (GtkCssImageLinearClass *klass)
   image_class->parse = gtk_css_image_linear_parse;
   image_class->print = gtk_css_image_linear_print;
   image_class->compute = gtk_css_image_linear_compute;
+  image_class->equal = gtk_css_image_linear_equal;
+  image_class->transition = gtk_css_image_linear_transition;
 
   object_class->dispose = gtk_css_image_linear_dispose;
 }