data-out: Make binary output buffer big enough for a null terminator.
[pspp] / src / ui / gui / psppire-dict.c
index 70d3b4934551d7576c50f7383b1735e620c66ce8..32a5cc13e26fa40d4c477023984c23d109141c77 100644 (file)
@@ -50,7 +50,8 @@ GType role_enum_type;
 enum  {
   VARIABLE_CHANGED,
   VARIABLE_INSERTED,
-  VARIABLE_DELETED,
+  VARIABLES_DELETED,
+  VARIABLE_MOVED,
 
   WEIGHT_CHANGED,
   FILTER_CHANGED,
@@ -191,18 +192,29 @@ psppire_dict_class_init (PsppireDictClass *class)
                  1,
                  G_TYPE_INT);
 
-  signals [VARIABLE_DELETED] =
-    g_signal_new ("variable-deleted",
+  signals [VARIABLES_DELETED] =
+    g_signal_new ("variables-deleted",
                  G_TYPE_FROM_CLASS (class),
                  G_SIGNAL_RUN_FIRST,
                  0,
                  NULL, NULL,
-                 psppire_marshal_VOID__POINTER_INT_INT,
+                 psppire_marshal_VOID__INT_UINT,
                  G_TYPE_NONE,
-                 3,
-                 G_TYPE_POINTER,
+                 2,
                  G_TYPE_INT,
-                 G_TYPE_INT);
+                  G_TYPE_UINT);
+
+  signals [VARIABLE_MOVED] =
+    g_signal_new ("variable-moved",
+                 G_TYPE_FROM_CLASS (class),
+                 G_SIGNAL_RUN_FIRST,
+                 0,
+                 NULL, NULL,
+                 psppire_marshal_VOID__INT_INT,
+                 G_TYPE_NONE,
+                 2,
+                 G_TYPE_INT,
+                  G_TYPE_INT);
 
   signals [WEIGHT_CHANGED] =
     g_signal_new ("weight-changed",
@@ -256,7 +268,7 @@ psppire_dict_dispose (GObject *object)
 /* Pass on callbacks from src/data/dictionary, as
    signals in the Gtk library */
 static void
-addcb (struct dictionary *d, int idx, void *pd)
+var_added_callback (struct dictionary *d, int idx, void *pd)
 {
   PsppireDict *dict = PSPPIRE_DICT (pd);
 
@@ -268,16 +280,20 @@ addcb (struct dictionary *d, int idx, void *pd)
 }
 
 static void
-delcb (struct dictionary *d, const struct variable *var,
-       int dict_idx, int case_idx, void *pd)
+vars_deleted_callback (struct dictionary *d, int dict_idx, unsigned int n, void *pd)
 {
-  g_signal_emit (pd, signals [VARIABLE_DELETED], 0,
-                 var, dict_idx, case_idx);
+  g_signal_emit (pd, signals [VARIABLES_DELETED], 0, dict_idx, n);
   g_signal_emit_by_name (pd, "items-changed",  dict_idx, 1, 0);
 }
 
 static void
-mutcb (struct dictionary *d, int idx, unsigned int what, const struct variable *oldvar, void *pd)
+var_moved_callback (struct dictionary *d, int new_dict_index, int old_dict_index, void *pd)
+{
+  g_signal_emit (pd, signals [VARIABLE_MOVED], 0, new_dict_index, old_dict_index);
+}
+
+static void
+var_changed_callback (struct dictionary *d, int idx, unsigned int what, const struct variable *oldvar, void *pd)
 {
   g_signal_emit (pd, signals [VARIABLE_CHANGED], 0, idx, what, oldvar);
   g_signal_emit_by_name (pd, "items-changed", idx, 1, 1);
@@ -303,12 +319,13 @@ split_changed_callback (struct dictionary *d, void *pd)
 
 static const struct dict_callbacks gui_callbacks =
   {
-    addcb,
-    delcb,
-    mutcb,
-    weight_changed_callback,
-    filter_changed_callback,
-    split_changed_callback
+    .var_added = var_added_callback,
+    .vars_deleted = vars_deleted_callback,
+    .var_moved = var_moved_callback,
+    .var_changed = var_changed_callback,
+    .weight_changed = weight_changed_callback,
+    .filter_changed = filter_changed_callback,
+    .split_changed = split_changed_callback
   };
 
 static void
@@ -501,17 +518,6 @@ psppire_dict_get_n_vars (const PsppireDict *d)
 }
 
 
-/* Return the number of `union value's in the dictionary */
-size_t
-psppire_dict_get_n_values (const PsppireDict *d)
-{
-  g_return_val_if_fail (d, -1);
-  g_return_val_if_fail (d->dict, -1);
-
-  return dict_get_next_value_idx (d->dict);
-}
-
-
 /* Returns the prototype for the cases that match the dictionary */
 const struct caseproto *
 psppire_dict_get_proto (const PsppireDict *d)
@@ -559,13 +565,6 @@ psppire_dict_check_name (const PsppireDict *dict,
           && !psppire_dict_lookup_var (dict, name));
 }
 
-gint
-psppire_dict_get_next_value_idx (const PsppireDict *dict)
-{
-  return dict_get_next_value_idx (dict->dict);
-}
-
-
 /* Tree Model Stuff */
 
 static GtkTreeModelFlags tree_model_get_flags (GtkTreeModel *model);
@@ -770,7 +769,7 @@ tree_model_get_path (GtkTreeModel *model, GtkTreeIter *iter)
   return path;
 }
 
-const struct fmt_spec *var_get_write_format (const struct variable *);
+struct fmt_spec var_get_write_format (const struct variable *);
 
 static void
 tree_model_get_value (GtkTreeModel *model, GtkTreeIter *iter,
@@ -783,7 +782,7 @@ tree_model_get_value (GtkTreeModel *model, GtkTreeIter *iter,
 
   var = iter->user_data;
 
-  const struct fmt_spec *fs = var_get_write_format (var);
+  struct fmt_spec fs = var_get_write_format (var);
 
   switch (column)
     {
@@ -793,11 +792,11 @@ tree_model_get_value (GtkTreeModel *model, GtkTreeIter *iter,
       break;
     case DICT_TVM_COL_WIDTH:
       g_value_init (value, G_TYPE_INT);
-      g_value_set_int (value, fs->w);
+      g_value_set_int (value, fs.w);
       break;
     case DICT_TVM_COL_DECIMAL:
       g_value_init (value, G_TYPE_INT);
-      g_value_set_int (value, fs->d);
+      g_value_set_int (value, fs.d);
       break;
     case DICT_TVM_COL_LABEL:
       g_value_init (value, G_TYPE_STRING);