[balsa/gtk3] BalsaMimeWidgetImage subclasses BalsaMimeWidget



commit e824234360da6614b4dbc6ea849760f20e4c3141
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Fri Aug 26 17:52:17 2011 -0400

    BalsaMimeWidgetImage subclasses BalsaMimeWidget
    
    	* src/balsa-mime-widget-image.h: subclass boilerplate.
    	* src/balsa-mime-widget-image.c (balsa_mime_widget_image_init),
    	(balsa_mime_widget_image_class_init): ditto.
    	(balsa_mime_widget_image_dispose): disconnect signal handler.
    	(balsa_mime_widget_new_image): store signal handler id.

 ChangeLog                     |   10 +++++
 src/balsa-mime-widget-image.c |   78 +++++++++++++++++++++++++++++++++-------
 src/balsa-mime-widget-image.h |   52 ++++++++++++++++++++++-----
 3 files changed, 116 insertions(+), 24 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0570d28..70e91b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-08-26  Peter Bloomfield
+
+	Make BalsaMimeWidgetImage a subclass of BalsaMimeWidget
+
+	* src/balsa-mime-widget-image.h: subclass boilerplate.
+	* src/balsa-mime-widget-image.c (balsa_mime_widget_image_init),
+	(balsa_mime_widget_image_class_init): ditto.
+	(balsa_mime_widget_image_dispose): disconnect signal handler.
+	(balsa_mime_widget_new_image): store signal handler id.
+
 2011-08-21  Peter Bloomfield
 
 	* libbalsa/libbalsa-vfs.c (libbalsa_vfs_get_size): get size as
diff --git a/src/balsa-mime-widget-image.c b/src/balsa-mime-widget-image.c
index f17d081..fcd0e48 100644
--- a/src/balsa-mime-widget-image.c
+++ b/src/balsa-mime-widget-image.c
@@ -7,28 +7,75 @@
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
- *  
+ *
  * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of 
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *  
+ *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  
- * 02111-1307, USA.
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H
 # include "config.h"
 #endif                          /* HAVE_CONFIG_H */
+
 #include "balsa-mime-widget-image.h"
 
 #include "balsa-app.h"
-#include <glib/gi18n.h>
 #include "balsa-mime-widget.h"
 #include "balsa-mime-widget-callbacks.h"
+#include <glib/gi18n.h>
+
+/*
+ * GObject class definitions
+ */
+struct _BalsaMimeWidgetImage {
+    BalsaMimeWidget  parent;
+
+    GtkStyleContext *context;
+    gulong           context_changed_handler_id;
+};
+
+struct _BalsaMimeWidgetImageClass {
+    BalsaMimeWidgetClass parent;
+};
+
+G_DEFINE_TYPE(BalsaMimeWidgetImage,
+              balsa_mime_widget_image,
+              BALSA_TYPE_MIME_WIDGET);
+
+static void
+balsa_mime_widget_image_init(BalsaMimeWidgetImage * mwi)
+{
+}
+
+static void
+balsa_mime_widget_image_dispose(GObject * obj)
+{
+    BalsaMimeWidgetImage *mwi = BALSA_MIME_WIDGET_IMAGE(obj);
+
+    if (mwi->context_changed_handler_id) {
+        g_signal_handler_disconnect(mwi->context,
+                                    mwi->context_changed_handler_id);
+        mwi->context_changed_handler_id = 0;
+    }
+
+    (*G_OBJECT_CLASS(balsa_mime_widget_image_parent_class)->
+          dispose) (obj);
+}
 
+static void
+balsa_mime_widget_image_class_init(BalsaMimeWidgetImageClass * klass)
+{
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+    object_class->dispose = balsa_mime_widget_image_dispose;
+}
+/*
+ * End of GObject class definitions
+ */
 
 static gboolean balsa_image_button_press_cb(GtkWidget * widget, GdkEventButton * event,
 					    GtkMenu * menu);
@@ -53,8 +100,8 @@ balsa_mime_widget_new_image(BalsaMessage * bm,
     GdkPixbuf *pixbuf;
     GtkWidget *image;
     GError * load_err = NULL;
+    BalsaMimeWidgetImage *mwi;
     BalsaMimeWidget *mw;
-    GtkStyleContext *context;
 
     g_return_val_if_fail(mime_body != NULL, NULL);
     g_return_val_if_fail(content_type != NULL, NULL);
@@ -70,16 +117,19 @@ balsa_mime_widget_new_image(BalsaMessage * bm,
 	return NULL;
     }
 
-    mw = g_object_new(BALSA_TYPE_MIME_WIDGET, NULL);
+    mwi = g_object_new(BALSA_TYPE_MIME_WIDGET_IMAGE, NULL);
+    mw = (BalsaMimeWidget *) mwi;
 
     mw->widget = gtk_event_box_new();
     g_signal_connect(G_OBJECT(mw->widget), "button-press-event",
                      G_CALLBACK(balsa_image_button_press_cb), data);
 
-    context = gtk_widget_get_style_context(GTK_WIDGET(bm->cont_viewport));
-    bmwi_context_changed_cb(context, mw);
-    g_signal_connect(context, "changed",
-                     G_CALLBACK(bmwi_context_changed_cb), mw);
+    mwi->context =
+        gtk_widget_get_style_context(GTK_WIDGET(bm->cont_viewport));
+    bmwi_context_changed_cb(mwi->context, mw);
+    mwi->context_changed_handler_id =
+        g_signal_connect(mwi->context, "changed",
+                         G_CALLBACK(bmwi_context_changed_cb), mw);
 
     image = gtk_image_new_from_stock(GTK_STOCK_MISSING_IMAGE,
                                      GTK_ICON_SIZE_BUTTON);
diff --git a/src/balsa-mime-widget-image.h b/src/balsa-mime-widget-image.h
index 17fcd61..358fcea 100644
--- a/src/balsa-mime-widget-image.h
+++ b/src/balsa-mime-widget-image.h
@@ -1,28 +1,26 @@
 /* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
 /* Balsa E-Mail Client
- * Copyright (C) 1997-2001 Stuart Parmenter and others,
+ * Copyright (C) 1997-2011 Stuart Parmenter and others,
  *                         See the file AUTHORS for a list.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option) 
+ * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
- *  
+ *
  * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of 
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *  
+ *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  
- * 02111-1307, USA.
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #ifndef __BALSA_MIME_WIDGET_IMAGE_H__
 #define __BALSA_MIME_WIDGET_IMAGE_H__
 
-#include "balsa-app.h"
+#include <glib-object.h>
 #include "balsa-message.h"
 #include "balsa-mime-widget.h"
 
@@ -30,6 +28,40 @@
 extern "C" {
 #endif				/* __cplusplus */
 
+/*
+ * GObject class definitions
+ */
+#define BALSA_TYPE_MIME_WIDGET_IMAGE                                    \
+    (balsa_mime_widget_image_get_type())
+
+#define BALSA_MIME_WIDGET_IMAGE(obj)                                    \
+    (G_TYPE_CHECK_INSTANCE_CAST((obj),                                  \
+                                BALSA_TYPE_MIME_WIDGET_IMAGE,           \
+                                BalsaMimeWidgetImage))
+
+#define BALSA_IS_MIME_WIDGET_IMAGE(obj)                                 \
+    (G_TYPE_CHECK_INSTANCE_TYPE((obj), BALSA_TYPE_MIME_WIDGET_IMAGE))
+
+#define BALSA_MIME_WIDGET_IMAGE_CLASS(klass)                            \
+    (G_TYPE_CHECK_CLASS_CAST((klass),                                   \
+                             BALSA_TYPE_MIME_WIDGET_IMAGE,              \
+                             BalsaMimeWidgetImageClass))
+
+#define BALSA_IS_MIME_WIDGET_IMAGE_CLASS(klass)                         \
+    (G_TYPE_CHECK_CLASS_TYPE((klass), BALSA_TYPE_MIME_WIDGET_IMAGE))
+
+#define BALSA_MIME_WIDGET_IMAGE_GET_CLASS(obj)                          \
+    (G_TYPE_INSTANCE_GET_CLASS((obj),                                   \
+                               BALSA_TYPE_MIME_WIDGET_IMAGE,            \
+                               BalsaMimeWidgetImageClass))
+
+GType balsa_mime_widget_image_get_type(void);
+
+typedef struct _BalsaMimeWidgetImage        BalsaMimeWidgetImage;
+typedef struct _BalsaMimeWidgetImageClass   BalsaMimeWidgetImageClass;
+/*
+ * End of GObject class definitions
+ */
 
 BalsaMimeWidget *balsa_mime_widget_new_image(BalsaMessage * bm,
 					     LibBalsaMessageBody * mime_body,



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