Added psppire-dialog and psppire-buttonbox widgets.
[pspp-builds.git] / src / ui / gui / psppire-dict.c
index 5cf2f4faafc78de385dfd1bd67ae69a35b77ee6c..4fc9c372c9af27ace50a7c2dfb924c858b4ebf7a 100644 (file)
@@ -49,6 +49,7 @@ enum  {VARIABLE_CHANGED,
        VARIABLE_RESIZED,
        VARIABLE_INSERTED,
        VARIABLES_DELETED,
+       WEIGHT_CHANGED,
        n_SIGNALS};
 
 static guint signal[n_SIGNALS];
@@ -158,6 +159,17 @@ psppire_dict_class_init (PsppireDictClass *class)
                  G_TYPE_INT,
                  G_TYPE_INT);
 
+
+  signal [WEIGHT_CHANGED] =
+    g_signal_new ("weight-changed",
+                 G_TYPE_FROM_CLASS (class),
+                 G_SIGNAL_RUN_FIRST,
+                 0,
+                 NULL, NULL,
+                 g_cclosure_marshal_VOID__INT,
+                 G_TYPE_NONE,
+                 1,
+                 G_TYPE_INT);
 }
 
 static void
@@ -190,11 +202,19 @@ mutcb (struct dictionary *d, int idx, void *pd)
   g_signal_emit (pd, signal[VARIABLE_CHANGED], 0, idx);
 }
 
+static void
+weight_changed_callback (struct dictionary *d, int idx, void *pd)
+{
+  g_signal_emit (pd, signal [WEIGHT_CHANGED], 0, idx);
+}
+
+
 static const struct dict_callbacks gui_callbacks =
   {
     addcb,
     delcb,
-    mutcb
+    mutcb,
+    weight_changed_callback
   };
 
 static void
@@ -221,6 +241,13 @@ psppire_dict_new_from_dict (struct dictionary *d)
 }
 
 
+void
+psppire_dict_replace_dictionary (PsppireDict *dict, struct dictionary *d)
+{
+  dict->dict = d;
+}
+
+
 /* Returns a valid name for a new variable in DICT.
    The return value is statically allocated */
 static gchar *
@@ -243,18 +270,16 @@ void
 psppire_dict_insert_variable (PsppireDict *d, gint idx, const gchar *name)
 {
   struct variable *var ;
+  g_return_if_fail (idx >= 0);
   g_return_if_fail (d);
   g_return_if_fail (G_IS_PSPPIRE_DICT (d));
 
-
   if ( ! name )
     name = auto_generate_var_name (d);
 
   var = dict_create_var (d->dict, name, 0);
 
   dict_reorder_var (d->dict, var, idx);
-
-  g_signal_emit (d, signal[VARIABLE_INSERTED], 0, idx );
 }
 
 /* Delete N variables beginning at FIRST */
@@ -278,8 +303,6 @@ psppire_dict_delete_variables (PsppireDict *d, gint first, gint n)
       dict_delete_var (d->dict, var);
     }
   dict_compact_values (d->dict);
-
-  g_signal_emit (d, signal[VARIABLES_DELETED], 0, first, idx );
 }
 
 
@@ -296,13 +319,11 @@ psppire_dict_set_name (PsppireDict* d, gint idx, const gchar *name)
       /* This is an existing variable? */
       var = dict_get_var (d->dict, idx);
       dict_rename_var (d->dict, var, name);
-      g_signal_emit (d, signal[VARIABLE_CHANGED], 0, idx);
     }
   else
     {
       /* new variable */
       dict_create_var (d->dict, name, 0);
-      g_signal_emit (d, signal[VARIABLE_INSERTED], 0, idx);
     }
 }
 
@@ -310,7 +331,7 @@ psppire_dict_set_name (PsppireDict* d, gint idx, const gchar *name)
 
 /* Return the IDXth variable */
 struct variable *
-psppire_dict_get_variable (PsppireDict *d, gint idx)
+psppire_dict_get_variable (const PsppireDict *d, gint idx)
 {
   g_return_val_if_fail (d, NULL);
   g_return_val_if_fail (d->dict, NULL);
@@ -345,16 +366,6 @@ psppire_dict_lookup_var (const PsppireDict *d, const gchar *name)
   return dict_lookup_var (d->dict, name);
 }
 
-
-void
-psppire_dict_var_changed (PsppireDict *d, gint idx)
-{
-  g_return_if_fail (d);
-
-  g_signal_emit (d, signal[VARIABLE_CHANGED], 0, idx);
-}
-
-
 /* Clears the contents of D */
 void
 psppire_dict_clear (PsppireDict *d)
@@ -363,16 +374,11 @@ psppire_dict_clear (PsppireDict *d)
   g_return_if_fail (d->dict);
 
   {
-    const gint n_vars = dict_get_var_cnt (d->dict);
-
     dict_clear (d->dict);
-
-    g_signal_emit (d, signal[VARIABLES_DELETED], 0, 0, n_vars );
   }
 }
 
 
-
 /* Return true is NAME would be a valid name of a variable to add to the
    dictionary.  False otherwise.
    If REPORT is true, then invalid names will be reported as such as errors
@@ -639,3 +645,18 @@ psppire_dict_rename_var (PsppireDict *dict, struct variable *v,
 {
   dict_rename_var (dict->dict, v, text);
 }
+
+
+void
+psppire_dict_set_weight_variable (PsppireDict *dict, struct variable *v)
+{
+  g_return_if_fail (v == NULL || var_is_numeric (v));
+  dict_set_weight (dict->dict, v);
+}
+
+
+struct variable *
+psppire_dict_get_weight_variable (const PsppireDict *dict)
+{
+  return dict_get_weight (dict->dict);
+}