[balsa/wip/gtk4: 159/351] mime-widget-image: simplify showing the image



commit a380edaa1a0e2f8ece413d76ce0694c490a5d488
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Fri Feb 9 13:31:24 2018 -0500

    mime-widget-image: simplify showing the image
    
    We can replace the "missing" icon at "realize" time.

 src/balsa-message.c           |   10 ---
 src/balsa-mime-widget-image.c |  131 +++++++++++++++++++---------------------
 src/balsa-mime-widget-image.h |    1 -
 3 files changed, 62 insertions(+), 80 deletions(-)
---
diff --git a/src/balsa-message.c b/src/balsa-message.c
index 948bea3..589d6a3 100644
--- a/src/balsa-message.c
+++ b/src/balsa-message.c
@@ -310,14 +310,6 @@ bm_header_tl_buttons(BalsaMessage * bm)
     return (GtkWidget **) g_ptr_array_free(array, FALSE);
 }
 
-static void
-on_content_size_alloc(GtkWidget * widget, GtkAllocation * allocation,
-                      gint baseline, GtkAllocation * clip,
-                     gpointer user_data)
-{
-    gtk_container_foreach (GTK_CONTAINER(widget), balsa_mime_widget_image_resize_all, NULL);
-}
-
 /*
  * Callbacks and helpers for the find bar.
  */
@@ -703,8 +695,6 @@ balsa_message_init(BalsaMessage * bm)
                     G_CALLBACK(balsa_mime_widget_key_press_event), bm);
     gtk_widget_set_vexpand(scroll, TRUE);
     gtk_box_pack_start(GTK_BOX(vbox), scroll);
-    g_signal_connect(bm->scroll, "size-allocate",
-                    G_CALLBACK(on_content_size_alloc), NULL);
 
     /* Widget to hold headers */
     buttons = bm_header_tl_buttons(bm);
diff --git a/src/balsa-mime-widget-image.c b/src/balsa-mime-widget-image.c
index 87f0b3c..1e14b72 100644
--- a/src/balsa-mime-widget-image.c
+++ b/src/balsa-mime-widget-image.c
@@ -29,75 +29,6 @@
 #include <glib/gi18n.h>
 
 
-static void balsa_mime_widget_image_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
-                                                       gint                  n_press,
-                                                       gdouble               x,
-                                                       gdouble               y,
-                                                       gpointer              user_data);
-static gboolean img_check_size(GtkImage ** widget_p);
-
-BalsaMimeWidget *
-balsa_mime_widget_new_image(BalsaMessage * bm,
-                            LibBalsaMessageBody * mime_body,
-                           const gchar * content_type, gpointer data)
-{
-    GdkPixbuf *pixbuf;
-    GtkWidget *image;
-    GError * load_err = NULL;
-    GtkGesture *gesture;
-    BalsaMimeWidget *mw;
-
-    g_return_val_if_fail(mime_body != NULL, NULL);
-    g_return_val_if_fail(content_type != NULL, NULL);
-
-    pixbuf = libbalsa_message_body_get_pixbuf(mime_body, &load_err);
-    if (pixbuf == NULL) {
-       if (load_err != NULL) {
-            balsa_information(LIBBALSA_INFORMATION_ERROR,
-                             _("Error loading attached image: %s\n"),
-                             load_err->message);
-           g_error_free(load_err);
-       }
-       return NULL;
-    }
-
-    image = gtk_image_new_from_icon_name("image-missing");
-
-    g_object_set_data_full(G_OBJECT(image), "pixbuf", pixbuf, g_object_unref);
-
-    gesture = gtk_gesture_multi_press_new(GTK_WIDGET(image));
-    gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 0);
-    g_object_set_data_full(G_OBJECT(image), "balsa-gesture", gesture, g_object_unref);
-    g_signal_connect(gesture, "pressed",
-                     G_CALLBACK(balsa_mime_widget_image_gesture_pressed_cb), data);
-
-    mw = (BalsaMimeWidget *) g_object_new(BALSA_TYPE_MIME_WIDGET, NULL);
-    balsa_mime_widget_set_widget(mw, image);
-
-    return mw;
-}
-
-
-void
-balsa_mime_widget_image_resize_all(GtkWidget * widget, gpointer user_data)
-{
-    if (GTK_IS_CONTAINER(widget))
-        gtk_container_foreach(GTK_CONTAINER(widget),
-                             balsa_mime_widget_image_resize_all, NULL);
-    else if (GTK_IS_IMAGE(widget) &&
-             g_object_get_data(G_OBJECT(widget), "pixbuf") != NULL &&
-             !GPOINTER_TO_INT(g_object_get_data
-                              (G_OBJECT(widget), "check_size_sched"))) {
-        GtkWidget **widget_p = g_new(GtkWidget *, 1);
-        g_object_set_data(G_OBJECT(widget), "check_size_sched",
-                          GINT_TO_POINTER(TRUE));
-        *widget_p = widget;
-        g_object_add_weak_pointer(G_OBJECT(widget), (gpointer *) widget_p);
-        g_idle_add((GSourceFunc) img_check_size, widget_p);
-    }
-}
-
-
 static void
 balsa_mime_widget_image_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
                                            gint                  n_press,
@@ -182,3 +113,65 @@ img_check_size(GtkImage ** widget_p)
 
     return FALSE;
 }
+
+static void
+img_realize_cb(GtkWidget * widget, gpointer user_data)
+{
+    if (g_object_get_data(G_OBJECT(widget), "pixbuf") != NULL &&
+        !GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "check_size_sched"))) {
+        GtkWidget **widget_p;
+
+        widget_p = g_new(GtkWidget *, 1);
+        g_object_set_data(G_OBJECT(widget), "check_size_sched",
+                          GINT_TO_POINTER(TRUE));
+        *widget_p = widget;
+        g_object_add_weak_pointer(G_OBJECT(widget), (gpointer *) widget_p);
+        g_idle_add((GSourceFunc) img_check_size, widget_p);
+    }
+}
+
+/*
+ * Public method
+ */
+
+BalsaMimeWidget *
+balsa_mime_widget_new_image(BalsaMessage * bm,
+                            LibBalsaMessageBody * mime_body,
+                           const gchar * content_type, gpointer data)
+{
+    GdkPixbuf *pixbuf;
+    GtkWidget *image;
+    GError * load_err = NULL;
+    GtkGesture *gesture;
+    BalsaMimeWidget *mw;
+
+    g_return_val_if_fail(mime_body != NULL, NULL);
+    g_return_val_if_fail(content_type != NULL, NULL);
+
+    pixbuf = libbalsa_message_body_get_pixbuf(mime_body, &load_err);
+    if (pixbuf == NULL) {
+       if (load_err != NULL) {
+            balsa_information(LIBBALSA_INFORMATION_ERROR,
+                             _("Error loading attached image: %s\n"),
+                             load_err->message);
+           g_error_free(load_err);
+       }
+       return NULL;
+    }
+
+    image = gtk_image_new_from_icon_name("image-missing");
+
+    g_object_set_data_full(G_OBJECT(image), "pixbuf", pixbuf, g_object_unref);
+
+    gesture = gtk_gesture_multi_press_new(GTK_WIDGET(image));
+    gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 0);
+    g_object_set_data_full(G_OBJECT(image), "balsa-gesture", gesture, g_object_unref);
+    g_signal_connect(gesture, "pressed",
+                     G_CALLBACK(balsa_mime_widget_image_gesture_pressed_cb), data);
+
+    mw = (BalsaMimeWidget *) g_object_new(BALSA_TYPE_MIME_WIDGET, NULL);
+    balsa_mime_widget_set_widget(mw, image);
+    g_signal_connect(image, "realize", G_CALLBACK(img_realize_cb), NULL);
+
+    return mw;
+}
diff --git a/src/balsa-mime-widget-image.h b/src/balsa-mime-widget-image.h
index 11a6bd0..c524ceb 100644
--- a/src/balsa-mime-widget-image.h
+++ b/src/balsa-mime-widget-image.h
@@ -28,7 +28,6 @@ G_BEGIN_DECLS
 BalsaMimeWidget *balsa_mime_widget_new_image(BalsaMessage * bm,
                                             LibBalsaMessageBody * mime_body,
                                             const gchar * content_type, gpointer data);
-void balsa_mime_widget_image_resize_all(GtkWidget * widget, gpointer user_data);
 
 
 G_END_DECLS


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