[balsa/wip/gtk4: 298/351] balsa-index: Use G_DECLARE_FINAL_TYPE



commit f76ca17f5875b759abf33aa00f0f09b530ccc5f6
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Fri Apr 27 08:45:20 2018 -0400

    balsa-index: Use G_DECLARE_FINAL_TYPE

 src/balsa-index.c |   42 +++++-------------------------------------
 src/balsa-index.h |   23 ++++++++---------------
 2 files changed, 13 insertions(+), 52 deletions(-)
---
diff --git a/src/balsa-index.c b/src/balsa-index.c
index 85eadc5..c317d46 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -60,8 +60,6 @@
 
 
 /* gtk widget */
-static void bndx_class_init(BalsaIndexClass * klass);
-static void bndx_instance_init(BalsaIndex * index);
 static void bndx_destroy(GObject * obj);
 static gboolean bndx_popup_menu(GtkWidget * widget);
 
@@ -146,38 +144,14 @@ static void bndx_select_row(BalsaIndex * index, GtkTreePath * path);
 /* Other callbacks. */
 static void bndx_store_address(gpointer data);
 
-static GtkTreeViewClass *parent_class = NULL;
 
 /* Class type. */
-GType
-balsa_index_get_type(void)
-{
-    static GType balsa_index_type = 0;
-
-    if (!balsa_index_type) {
-        static const GTypeInfo balsa_index_info = {
-            sizeof(BalsaIndexClass),
-            NULL,               /* base_init */
-            NULL,               /* base_finalize */
-            (GClassInitFunc) bndx_class_init,
-            NULL,               /* class_finalize */
-            NULL,               /* class_data */
-            sizeof(BalsaIndex),
-            0,                  /* n_preallocs */
-            (GInstanceInitFunc) bndx_instance_init
-        };
-
-        balsa_index_type =
-            g_type_register_static(GTK_TYPE_TREE_VIEW,
-                                   "BalsaIndex", &balsa_index_info, 0);
-    }
 
-    return balsa_index_type;
-}
+G_DEFINE_TYPE(BalsaIndex, balsa_index, GTK_TYPE_TREE_VIEW)
 
 /* BalsaIndex class init method. */
 static void
-bndx_class_init(BalsaIndexClass * klass)
+balsa_index_class_init(BalsaIndexClass * klass)
 {
     GObjectClass *object_class;
     GtkWidgetClass *widget_class;
@@ -185,21 +159,15 @@ bndx_class_init(BalsaIndexClass * klass)
     object_class = (GObjectClass *) klass;
     widget_class = (GtkWidgetClass *) klass;
 
-    parent_class = g_type_class_peek_parent(klass);
-
     balsa_index_signals[INDEX_CHANGED] =
         g_signal_new("index-changed",
                      G_TYPE_FROM_CLASS(object_class),
                     G_SIGNAL_RUN_FIRST,
-                     G_STRUCT_OFFSET(BalsaIndexClass,
-                                     index_changed),
-                     NULL, NULL,
-                    g_cclosure_marshal_VOID__VOID,
+                     0, NULL, NULL, NULL,
                      G_TYPE_NONE, 0);
 
     object_class->dispose = bndx_destroy;
     widget_class->popup_menu = bndx_popup_menu;
-    klass->index_changed = NULL;
 }
 
 /* Object class destroy method. */
@@ -244,7 +212,7 @@ bndx_destroy(GObject * obj)
     g_clear_object(&index->popup_menu);
     g_clear_object(&index->gesture);
 
-    G_OBJECT_CLASS(parent_class)->dispose(obj);
+    G_OBJECT_CLASS(balsa_index_parent_class)->dispose(obj);
 }
 
 /* Widget class popup menu method. */
@@ -289,7 +257,7 @@ bndx_string_width(const gchar * text)
 /* BalsaIndex instance init method; no tree store is set on the tree
  * view--that's handled later, when the view is populated. */
 static void
-bndx_instance_init(BalsaIndex * index)
+balsa_index_init(BalsaIndex * index)
 {
     GtkTreeView *tree_view = GTK_TREE_VIEW(index);
     GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
diff --git a/src/balsa-index.h b/src/balsa-index.h
index 5ab256e..67786a3 100644
--- a/src/balsa-index.h
+++ b/src/balsa-index.h
@@ -28,22 +28,21 @@ G_BEGIN_DECLS
 
     GType balsa_index_get_type(void);
 
-#define BALSA_TYPE_INDEX          (balsa_index_get_type ())
-#define BALSA_INDEX(obj)          (G_TYPE_CHECK_INSTANCE_CAST (obj, BALSA_TYPE_INDEX, BalsaIndex))
-#define BALSA_INDEX_CLASS(klass)  (G_TYPE_CHECK_CLASS_CAST (klass, BALSA_TYPE_INDEX, BalsaIndexClass))
-#define BALSA_IS_INDEX(obj)       (G_TYPE_CHECK_INSTANCE_TYPE (obj, BALSA_TYPE_INDEX))
-#define BALSA_IS_INDEX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE (klass, BALSA_TYPE_INDEX))
+#define BALSA_TYPE_INDEX balsa_index_get_type()
+
+G_DECLARE_FINAL_TYPE(BalsaIndex,
+                     balsa_index,
+                     BALSA,
+                     INDEX,
+                     GtkTreeView)
 
 
     typedef enum { BALSA_INDEX_WIDE, BALSA_INDEX_NARROW }
         BalsaIndexWidthPreference;
 
-    typedef struct _BalsaIndex BalsaIndex;
-    typedef struct _BalsaIndexClass BalsaIndexClass;
-
     struct _BalsaIndex {
         GtkTreeView tree_view;
-        
+
         /* the popup menu and some items we need to refer to */
         GtkWidget *popup_menu;
         GtkWidget *delete_item;
@@ -75,12 +74,6 @@ G_BEGIN_DECLS
         GtkGesture *gesture;
     };
 
-    struct _BalsaIndexClass {
-       GtkTreeViewClass parent_class;
-
-        void (*index_changed) (BalsaIndex* bindex);
-    };
-
 /* tree model columns */
     enum {
         BNDX_MESSAGE_COLUMN,


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