psppire-output-view: Set tooltips on tables from table_item notes.
[pspp] / src / ui / gui / psppire-var-view.c
index 0e72cb3717d784c1df0f7a0fba1d6561a72d0692..0a020008fb0c0c0630cca080deb4e7c177120960 100644 (file)
@@ -21,6 +21,7 @@
 #include "psppire-var-ptr.h"
 #include "psppire-select-dest.h"
 
+#include <libpspp/cast.h>
 #include <libpspp/str.h>
 #include <data/variable.h>
 
@@ -28,8 +29,6 @@
 #define _(msgid) gettext (msgid)
 #define N_(msgid) msgid
 
-static void psppire_var_view_base_finalize (PsppireVarViewClass *, gpointer);
-static void psppire_var_view_base_init     (PsppireVarViewClass *class);
 static void psppire_var_view_class_init    (PsppireVarViewClass *class);
 static void psppire_var_view_init          (PsppireVarView      *var_view);
 
@@ -63,45 +62,10 @@ model_init (PsppireSelectDestWidgetIface *iface)
   iface->contains_var = var_view_contains_var;
 }
 
-GType
-psppire_var_view_get_type (void)
-{
-  static GType psppire_var_view_type = 0;
-
-  if (!psppire_var_view_type)
-    {
-      static const GTypeInfo psppire_var_view_info =
-      {
-       sizeof (PsppireVarViewClass),
-       (GBaseInitFunc) psppire_var_view_base_init,
-        (GBaseFinalizeFunc) psppire_var_view_base_finalize,
-       (GClassInitFunc)psppire_var_view_class_init,
-       (GClassFinalizeFunc) NULL,
-       NULL,
-        sizeof (PsppireVarView),
-       0,
-       (GInstanceInitFunc) psppire_var_view_init,
-      };
-
-      static const GInterfaceInfo var_view_model_info = {
-       (GInterfaceInitFunc) model_init, /* Fill this in */
-       NULL,
-       NULL
-      };
-
-      psppire_var_view_type =
-       g_type_register_static (GTK_TYPE_TREE_VIEW, "PsppireVarView",
-                               &psppire_var_view_info, 0);
-
-      g_type_add_interface_static (psppire_var_view_type,
-                                  PSPPIRE_TYPE_SELECT_DEST_WIDGET,
-                                  &var_view_model_info);
-    }
+G_DEFINE_TYPE_WITH_CODE (PsppireVarView, psppire_var_view, GTK_TYPE_TREE_VIEW,
+               G_IMPLEMENT_INTERFACE (PSPPIRE_TYPE_SELECT_DEST_WIDGET, model_init))
 
-  return psppire_var_view_type;
-}
-
-void 
+void
 psppire_var_view_clear (PsppireVarView *vv)
 {
   GtkListStore *l = gtk_list_store_newv  (vv->n_cols, vv->cols);
@@ -180,28 +144,28 @@ set_renderers (PsppireVarView *var_view)
 {
   gint c;
   var_view->nums = g_malloc (sizeof *var_view->nums * var_view->n_cols);
-  
+
   for (c = 0 ; c < var_view->n_cols; ++c)
     {
       GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
       GtkTreeViewColumn *col = gtk_tree_view_column_new ();
-      
+
       gchar *label = g_strdup_printf (_("Var%d"), c + 1);
-      
+
       gtk_tree_view_column_set_min_width (col, 100);
       gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
       gtk_tree_view_column_set_resizable (col, TRUE);
       gtk_tree_view_column_set_title (col, label);
-      
+
       g_free (label);
-      
+
       var_view->nums[c] = c;
-      
+
       gtk_tree_view_column_pack_start (col, renderer, TRUE);
       gtk_tree_view_column_set_cell_data_func (col, renderer,
                                               display_cell_var_name,
                                               &var_view->nums[c], 0);
-      
+
       gtk_tree_view_append_column (GTK_TREE_VIEW (var_view), col);
     }
 }
@@ -228,7 +192,7 @@ psppire_var_view_set_property (GObject         *object,
        gint c;
        var_view->n_cols = g_value_get_int (value);
 
-       var_view->cols = xrealloc (var_view->cols, sizeof (GType) *  var_view->n_cols);
+       var_view->cols = g_realloc (var_view->cols, sizeof (GType) *  var_view->n_cols);
 
        for (c = 0 ; c < var_view->n_cols; ++c)
          var_view->cols[c] = PSPPIRE_VAR_PTR_TYPE;
@@ -249,6 +213,8 @@ psppire_var_view_class_init (PsppireVarViewClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
 
+  object_class->finalize = psppire_var_view_finalize;
+
   GParamSpec *n_cols_spec =
     g_param_spec_int ("n-cols",
                      "Number of columns",
@@ -266,26 +232,6 @@ psppire_var_view_class_init (PsppireVarViewClass *class)
                                    n_cols_spec);
 }
 
-
-static void
-psppire_var_view_base_init (PsppireVarViewClass *class)
-{
-
-  GObjectClass *object_class = G_OBJECT_CLASS (class);
-
-  object_class->finalize = psppire_var_view_finalize;
-}
-
-
-
-static void
-psppire_var_view_base_finalize (PsppireVarViewClass *class,
-                                gpointer class_data)
-{
-}
-
-
-
 static void
 psppire_var_view_init (PsppireVarView *vv)
 {
@@ -325,7 +271,7 @@ psppire_var_view_get_var_from_model (GtkTreeModel *model, gint column, GtkTreeIt
   GValue value = {0};
   gtk_tree_model_get_value (model, iter, column, &value);
 
-  if ( G_VALUE_TYPE (&value) == PSPPIRE_VAR_PTR_TYPE)
+  if (G_VALUE_TYPE (&value) == PSPPIRE_VAR_PTR_TYPE)
     var = g_value_get_boxed (&value);
   else
     g_critical ("Unsupported type `%s', in variable name treeview.",
@@ -355,7 +301,7 @@ psppire_var_view_append_names (PsppireVarView *vv, gint column, GString *string)
   gint n_vars = 0;
   GtkTreeIter iter;
 
-  if ( psppire_var_view_get_iter_first (vv, &iter) )
+  if (psppire_var_view_get_iter_first (vv, &iter))
     {
       do
        {
@@ -382,13 +328,13 @@ psppire_var_view_list_names (PsppireVarView *vv, gint column)
 {
   GtkTreeIter iter;
   GSList *list = NULL;
-  
-  if ( psppire_var_view_get_iter_first (vv, &iter) )
+
+  if (psppire_var_view_get_iter_first (vv, &iter))
     {
       do
        {
          const struct variable *var = psppire_var_view_get_variable (vv, column, &iter);
-         list = g_slist_prepend (list, var);
+         list = g_slist_prepend (list, CONST_CAST (struct variable *, var));
        }
       while (psppire_var_view_get_iter_next (vv, &iter));
     }
@@ -401,13 +347,13 @@ psppire_var_view_list_names (PsppireVarView *vv, gint column)
   Append the names of selected variables to STR
   Returns the number of variables appended.
 */
-gint 
+gint
 psppire_var_view_append_names_str (PsppireVarView *vv, gint column, struct string *str)
 {
   gint n_vars = 0;
   GtkTreeIter iter;
 
-  if ( psppire_var_view_get_iter_first (vv, &iter) )
+  if (psppire_var_view_get_iter_first (vv, &iter))
     {
       do
        {