[gtk+/wip/baedert/gtkimageview: 169/186] imageview: Remove obsolete code



commit f7f8d24966bf0727ef4a473d385e0d59a1323ee5
Author: Timm Bäder <mail baedert org>
Date:   Fri Feb 26 12:37:01 2016 +0100

    imageview: Remove obsolete code

 demos/gtk-demo/image_view.c |   10 ++-
 gtk/gtkabstractimage.c      |   18 ++----
 gtk/gtkabstractimage.h      |    4 +-
 gtk/gtkimageview.c          |  163 +++++-------------------------------------
 4 files changed, 34 insertions(+), 161 deletions(-)
---
diff --git a/demos/gtk-demo/image_view.c b/demos/gtk-demo/image_view.c
index 6f1a68c..5d33b3d 100644
--- a/demos/gtk-demo/image_view.c
+++ b/demos/gtk-demo/image_view.c
@@ -154,7 +154,13 @@ scale_scale_format_value_cb (GtkScale *scale,
 void
 load_pixbuf_button_clicked_cb ()
 {
-  GtkPixbufImage *image = gtk_pixbuf_image_new ("/usr/share/backgrounds/gnome/Fabric.jpg", 1);
+  GdkPixbuf *pixbuf;
+  GtkPixbufImage *image;
+
+  pixbuf = gdk_pixbuf_new_from_file ("/usr/share/backgrounds/gnome/Fabric.jpg", NULL);
+  image = gtk_pixbuf_image_new (pixbuf, 1);
+
+  g_object_unref (pixbuf);
 
   gtk_image_view_set_abstract_image (GTK_IMAGE_VIEW (image_view),
                                      GTK_ABSTRACT_IMAGE (image));
@@ -172,8 +178,6 @@ load_hidpi_pixbuf_button_clicked_cb ()
   animation = gdk_pixbuf_animation_new_from_file ("/home/baedert/0mKXcg1.gif", NULL);
   image = gtk_pixbuf_animation_image_new (animation, 1);
 
-  g_message ("%s", g_type_name (G_TYPE_FROM_INSTANCE (image)));
-
   gtk_image_view_set_abstract_image (GTK_IMAGE_VIEW (image_view), GTK_ABSTRACT_IMAGE (image));
 }
 
diff --git a/gtk/gtkabstractimage.c b/gtk/gtkabstractimage.c
index 82d40ed..6b71048 100644
--- a/gtk/gtkabstractimage.c
+++ b/gtk/gtkabstractimage.c
@@ -88,11 +88,11 @@ G_DEFINE_TYPE (GtkPixbufImage, gtk_pixbuf_image, GTK_TYPE_ABSTRACT_IMAGE)
 
 
 GtkPixbufImage *
-gtk_pixbuf_image_new (const char *path, int scale_factor)
+gtk_pixbuf_image_new (const GdkPixbuf *pixbuf, int scale_factor)
 {
   GtkPixbufImage *image = g_object_new (GTK_TYPE_PIXBUF_IMAGE, NULL);
   image->scale_factor = scale_factor;
-  image->pixbuf = gdk_pixbuf_new_from_file (path, NULL);
+  image->surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL);
 
   return image;
 }
@@ -100,13 +100,13 @@ gtk_pixbuf_image_new (const char *path, int scale_factor)
 static int
 gtk_pixbuf_image_get_width (GtkAbstractImage *image)
 {
-  return gdk_pixbuf_get_width (GTK_PIXBUF_IMAGE (image)->pixbuf);
+  return cairo_image_surface_get_width (GTK_PIXBUF_IMAGE (image)->surface);
 }
 
 static int
 gtk_pixbuf_image_get_height (GtkAbstractImage *image)
 {
-  return gdk_pixbuf_get_height (GTK_PIXBUF_IMAGE (image)->pixbuf);
+  return cairo_image_surface_get_height (GTK_PIXBUF_IMAGE (image)->surface);
 }
 
 static int
@@ -118,10 +118,7 @@ gtk_pixbuf_image_get_scale_factor (GtkAbstractImage *image)
 static void
 gtk_pixbuf_image_draw (GtkAbstractImage *image, cairo_t *ct)
 {
-  cairo_surface_t *surface = gdk_cairo_surface_create_from_pixbuf (
-      GTK_PIXBUF_IMAGE (image)->pixbuf, 1, NULL);
-
-  cairo_set_source_surface (ct, surface, 0, 0);
+  cairo_set_source_surface (ct, GTK_PIXBUF_IMAGE (image)->surface, 0, 0);
 }
 
 
@@ -156,14 +153,9 @@ gtk_pixbuf_animation_image_new (GdkPixbufAnimation *animation, int scale_factor)
   image->iter = gdk_pixbuf_animation_get_iter (animation, NULL);
   /* TODO: Use the delay for the CURRENT iter... */
   image->delay_ms = gdk_pixbuf_animation_iter_get_delay_time (image->iter);
-  g_assert (image->iter);
-  g_assert (gdk_pixbuf_animation_iter_get_pixbuf (image->iter));
   image->frame = gdk_cairo_surface_create_from_pixbuf (gdk_pixbuf_animation_iter_get_pixbuf (image->iter),
                                                        scale_factor, NULL);
 
-  g_assert (image->frame);
-
-  g_message ("CTOR");
   return image;
 }
 
diff --git a/gtk/gtkabstractimage.h b/gtk/gtkabstractimage.h
index 1e1569a..7936d54 100644
--- a/gtk/gtkabstractimage.h
+++ b/gtk/gtkabstractimage.h
@@ -80,7 +80,7 @@ typedef struct _GtkPixbufImageClass GtkPixbufImageClass;
 struct _GtkPixbufImage
 {
   GtkAbstractImage parent;
-  GdkPixbuf *pixbuf;
+  cairo_surface_t *surface;
   int scale_factor;
 };
 
@@ -93,7 +93,7 @@ GDK_AVAILABLE_IN_3_20
 GType gtk_pixbuf_image_get_type (void) G_GNUC_CONST;
 
 GDK_AVAILABLE_IN_3_20
-GtkPixbufImage *gtk_pixbuf_image_new (const char *path, int scale_factor);
+GtkPixbufImage *gtk_pixbuf_image_new (const GdkPixbuf *pixbuf, int scale_factor);
 
 
 /* ------------------------------------------------------------------------------------ */
diff --git a/gtk/gtkimageview.c b/gtk/gtkimageview.c
index 424dfbb..d00ed4e 100644
--- a/gtk/gtkimageview.c
+++ b/gtk/gtkimageview.c
@@ -121,13 +121,6 @@ struct _GtkImageViewPrivate
   GtkScrollablePolicy  hscroll_policy : 1;
   GtkScrollablePolicy  vscroll_policy : 1;
 
-  gboolean                is_animation;
-  GdkPixbufAnimation     *source_animation;
-  GdkPixbufAnimationIter *source_animation_iter;
-  /*cairo_surface_t        *image_surface;*/
-  int                     animation_timeout;
-
-
   GtkAbstractImage *image;
 
 
@@ -606,7 +599,6 @@ gtk_image_view_compute_bounding_box (GtkImageView *image_view,
   gtk_widget_get_allocation (GTK_WIDGET (image_view), &alloc);
   angle = gtk_image_view_get_real_angle (image_view);
 
-  g_message ("%s", g_type_name (G_TYPE_FROM_INSTANCE (priv->image)));
   image_width = gtk_abstract_image_get_width (priv->image) /
                 gtk_abstract_image_get_scale_factor (priv->image);
   image_height = gtk_abstract_image_get_height (priv->image) /
@@ -1006,59 +998,6 @@ gtk_image_view_init (GtkImageView *image_view)
   gtk_image_view_ensure_gestures (image_view);
 }
 
-static GdkPixbuf *
-gtk_image_view_get_current_frame (GtkImageView *image_view)
-{
-  GtkImageViewPrivate *priv = gtk_image_view_get_instance_private (image_view);
-
-  g_assert (priv->source_animation);
-
-  if (priv->is_animation)
-    return gdk_pixbuf_animation_iter_get_pixbuf (priv->source_animation_iter);
-  else
-    return gdk_pixbuf_animation_get_static_image (priv->source_animation);
-}
-
-static gboolean
-gtk_image_view_update_animation (gpointer user_data)
-{
-  GtkImageView *image_view = user_data;
-  GtkImageViewPrivate *priv = gtk_image_view_get_instance_private (image_view);
-
-  gdk_pixbuf_animation_iter_advance (priv->source_animation_iter, NULL);
-  gtk_image_view_update_surface (image_view,
-                                 gtk_image_view_get_current_frame (image_view),
-                                 priv->scale_factor);
-
-  return priv->is_animation;
-}
-
-static void
-gtk_image_view_start_animation (GtkImageView *image_view)
-{
-  GtkImageViewPrivate *priv = gtk_image_view_get_instance_private (image_view);
-  int delay_ms;
-
-  g_assert (priv->is_animation);
-
-  delay_ms = gdk_pixbuf_animation_iter_get_delay_time (priv->source_animation_iter);
-
-  priv->animation_timeout = g_timeout_add (delay_ms, gtk_image_view_update_animation, image_view);
-}
-
-static void
-gtk_image_view_stop_animation (GtkImageView *image_view)
-{
-  GtkImageViewPrivate *priv = gtk_image_view_get_instance_private (image_view);
-
-  if (priv->animation_timeout != 0)
-    {
-      g_assert (priv->is_animation);
-      g_source_remove (priv->animation_timeout);
-      priv->animation_timeout = 0;
-    }
-}
-
 static gboolean
 gtk_image_view_draw (GtkWidget *widget, cairo_t *ct)
 {
@@ -1784,9 +1723,6 @@ gtk_image_view_map (GtkWidget *widget)
 {
   GtkImageViewPrivate *priv = gtk_image_view_get_instance_private (GTK_IMAGE_VIEW (widget));
 
-  if (priv->is_animation)
-    gtk_image_view_start_animation (GTK_IMAGE_VIEW (widget));
-
   if (priv->event_window)
     gdk_window_show (priv->event_window);
 
@@ -1798,8 +1734,8 @@ gtk_image_view_unmap (GtkWidget *widget)
 {
   GtkImageViewPrivate *priv = gtk_image_view_get_instance_private (GTK_IMAGE_VIEW (widget));
 
-  if (priv->is_animation)
-    gtk_image_view_stop_animation (GTK_IMAGE_VIEW (widget));
+  if (priv->event_window)
+    gdk_window_hide (priv->event_window);
 
   GTK_WIDGET_CLASS (gtk_image_view_parent_class)->unmap (widget);
 }
@@ -2005,19 +1941,12 @@ gtk_image_view_finalize (GObject *object)
   GtkImageView *image_view  = (GtkImageView *)object;
   GtkImageViewPrivate *priv = gtk_image_view_get_instance_private (image_view);
 
-  gtk_image_view_stop_animation (image_view);
-
-  g_clear_object (&priv->source_animation);
-
   g_clear_object (&priv->rotate_gesture);
   g_clear_object (&priv->zoom_gesture);
 
   g_clear_object (&priv->hadjustment);
   g_clear_object (&priv->vadjustment);
 
-  /*if (priv->image_surface)*/
-    /*cairo_surface_destroy (priv->image_surface);*/
-
   G_OBJECT_CLASS (gtk_image_view_parent_class)->finalize (object);
 }
 
@@ -2204,12 +2133,11 @@ gtk_image_view_update_surface (GtkImageView    *image_view,
 {
   GtkImageViewPrivate *priv = gtk_image_view_get_instance_private (image_view);
   GdkWindow *window = gtk_widget_get_window (GTK_WIDGET (image_view));
-  cairo_surface_t *new_surface;
   gboolean size_changed = TRUE;
 
-  new_surface = gdk_cairo_surface_create_from_pixbuf (frame,
-                                                      scale_factor,
-                                                      window);
+  /*new_surface = gdk_cairo_surface_create_from_pixbuf (frame,*/
+                                                      /*scale_factor,*/
+                                                      /*window);*/
 
   /*if (priv->image_surface)*/
     /*{*/
@@ -2233,58 +2161,24 @@ gtk_image_view_update_surface (GtkImageView    *image_view,
 }
 
 static void
-gtk_image_view_replace_animation (GtkImageView       *image_view,
-                                  GdkPixbufAnimation *animation,
-                                  int                 scale_factor)
-{
-  GtkImageViewPrivate *priv = gtk_image_view_get_instance_private (image_view);
-
-  if (priv->source_animation)
-    {
-      /*g_assert (priv->image_surface);*/
-      if (priv->is_animation)
-        gtk_image_view_stop_animation (image_view);
-    }
-
-  priv->is_animation = !gdk_pixbuf_animation_is_static_image (animation);
-
-  if (priv->is_animation)
-    {
-      priv->source_animation = animation;
-      priv->source_animation_iter = gdk_pixbuf_animation_get_iter (priv->source_animation,
-                                                                   NULL);
-      gtk_image_view_update_surface (image_view,
-                                     gtk_image_view_get_current_frame (image_view),
-                                     scale_factor);
-
-      gtk_image_view_start_animation (image_view);
-    }
-  else
-    {
-      gtk_image_view_update_surface (image_view,
-                                     gdk_pixbuf_animation_get_static_image (animation),
-                                     scale_factor);
-      g_object_unref (animation);
-    }
-
-}
-
-static void
 gtk_image_view_load_image_from_stream (GtkImageView *image_view,
                                        GInputStream *input_stream,
                                        int           scale_factor,
                                        GCancellable *cancellable,
                                        GError       *error)
 {
-  GdkPixbufAnimation *result;
+  /*GdkPixbufAnimation *result;*/
 
   g_assert (error == NULL);
-  result = gdk_pixbuf_animation_new_from_stream (input_stream,
-                                                 cancellable,
-                                                 &error);
+  /*result = gdk_pixbuf_animation_new_from_stream (input_stream,*/
+                                                 /*cancellable,*/
+                                                 /*&error);*/
 
   if (!error)
-    gtk_image_view_replace_animation (image_view, result, scale_factor);
+    {
+      g_error ("");
+    /*gtk_image_view_replace_animation (image_view, result, scale_factor);*/
+    }
 
   g_object_unref (input_stream);
 }
@@ -2485,24 +2379,18 @@ gtk_image_view_set_pixbuf (GtkImageView    *image_view,
                            const GdkPixbuf *pixbuf,
                            int              scale_factor)
 {
-  GtkImageViewPrivate *priv = gtk_image_view_get_instance_private (image_view);
+  GtkPixbufImage *image;
+  /*GtkImageViewPrivate *priv = gtk_image_view_get_instance_private (image_view);*/
 
   g_return_if_fail (GTK_IS_IMAGE_VIEW (image_view));
   g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
   g_return_if_fail (scale_factor >= 0);
 
-  if (priv->is_animation)
-    {
-      g_clear_object (&priv->source_animation);
-      gtk_image_view_stop_animation (image_view);
-      priv->is_animation = FALSE;
-    }
-
   gtk_image_view_update_surface (image_view, pixbuf, scale_factor);
 
-  gtk_image_view_update_adjustments (image_view);
+  image = gtk_pixbuf_image_new (pixbuf, scale_factor);
 
-  /* gtk_image_view_update_surface already calls queue_draw/queue_resize */
+  gtk_image_view_set_abstract_image (image_view, GTK_ABSTRACT_IMAGE (image));
 }
 
 /**
@@ -2536,13 +2424,6 @@ gtk_image_view_set_surface (GtkImageView    *image_view,
       g_return_if_fail (scale_x == scale_y);
     }
 
-  if (priv->is_animation)
-    {
-      g_clear_object (&priv->source_animation);
-      gtk_image_view_stop_animation (image_view);
-      priv->is_animation = FALSE;
-    }
-
   image = gtk_surface_image_new (surface);
 
   gtk_image_view_replace_image (image_view, GTK_ABSTRACT_IMAGE (image));
@@ -2573,14 +2454,13 @@ gtk_image_view_set_animation (GtkImageView       *image_view,
                               GdkPixbufAnimation *animation,
                               int                 scale_factor)
 {
-  /*GtkPixbufAnimationImage *image;*/
+  GtkPixbufAnimationImage *image;
   g_return_if_fail (GTK_IS_IMAGE_VIEW (image_view));
   g_return_if_fail (GDK_IS_PIXBUF_ANIMATION (animation));
   g_return_if_fail (scale_factor >= 0);
 
-  /*gtk_image_view_replace_animation (image_view, animation, scale_factor);*/
-
-  /*image = gtk_pixbuf_animation_image-nwe (animation, scale_factor);*/
+  image = gtk_pixbuf_animation_image_new (animation, scale_factor);
+  gtk_image_view_set_abstract_image (image_view, GTK_ABSTRACT_IMAGE (image));
 }
 
 void
@@ -2600,9 +2480,6 @@ gtk_image_view_set_abstract_image (GtkImageView     *image_view,
   g_return_if_fail (GTK_IS_IMAGE_VIEW (image_view));
   g_return_if_fail (GTK_IS_ABSTRACT_IMAGE (abstract_image));
 
-
-  g_message ("%s", g_type_name (G_TYPE_FROM_INSTANCE (abstract_image)));
-
   priv->image = abstract_image;
 
   g_signal_connect (G_OBJECT (priv->image),


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