Added psppire-dialog and psppire-buttonbox widgets.
[pspp-builds.git] / src / ui / gui / psppire-dict.c
index 81bffe5cc9fa73623fbf491fb10663a82d51c3d8..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];
@@ -110,7 +111,7 @@ psppire_dict_class_init (PsppireDictClass *class)
 
   signal[VARIABLE_CHANGED] =
     g_signal_new ("variable_changed",
-                 G_TYPE_FROM_CLASS(class),
+                 G_TYPE_FROM_CLASS (class),
                  G_SIGNAL_RUN_FIRST,
                  0,
                  NULL, NULL,
@@ -123,7 +124,7 @@ psppire_dict_class_init (PsppireDictClass *class)
 
   signal[VARIABLE_INSERTED] =
     g_signal_new ("variable_inserted",
-                 G_TYPE_FROM_CLASS(class),
+                 G_TYPE_FROM_CLASS (class),
                  G_SIGNAL_RUN_FIRST,
                  0,
                  NULL, NULL,
@@ -135,7 +136,7 @@ psppire_dict_class_init (PsppireDictClass *class)
 
   signal[VARIABLES_DELETED] =
     g_signal_new ("variables_deleted",
-                 G_TYPE_FROM_CLASS(class),
+                 G_TYPE_FROM_CLASS (class),
                  G_SIGNAL_RUN_FIRST,
                  0,
                  NULL, NULL,
@@ -148,7 +149,7 @@ psppire_dict_class_init (PsppireDictClass *class)
 
   signal[VARIABLE_RESIZED] =
     g_signal_new ("dict-size-changed",
-                 G_TYPE_FROM_CLASS(class),
+                 G_TYPE_FROM_CLASS (class),
                  G_SIGNAL_RUN_FIRST,
                  0,
                  NULL, NULL,
@@ -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,9 +270,9 @@ 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));
-
+  g_return_if_fail (G_IS_PSPPIRE_DICT (d));
 
   if ( ! name )
     name = auto_generate_var_name (d);
@@ -253,8 +280,6 @@ psppire_dict_insert_variable (PsppireDict *d, gint idx, const gchar *name)
   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 */
@@ -264,7 +289,7 @@ psppire_dict_delete_variables (PsppireDict *d, gint first, gint n)
   gint idx;
   g_return_if_fail (d);
   g_return_if_fail (d->dict);
-  g_return_if_fail (G_IS_PSPPIRE_DICT(d));
+  g_return_if_fail (G_IS_PSPPIRE_DICT (d));
 
   for (idx = 0 ; idx < n ; ++idx )
     {
@@ -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 );
 }
 
 
@@ -288,7 +311,7 @@ psppire_dict_set_name (PsppireDict* d, gint idx, const gchar *name)
 {
   struct variable *var;
   g_assert (d);
-  g_assert (G_IS_PSPPIRE_DICT(d));
+  g_assert (G_IS_PSPPIRE_DICT (d));
 
 
   if ( idx < dict_get_var_cnt (d->dict))
@@ -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
@@ -467,7 +473,7 @@ dictionary_tree_model_init (GtkTreeModelIface *iface)
 static GtkTreeModelFlags
 tree_model_get_flags (GtkTreeModel *model)
 {
-  g_return_val_if_fail (G_IS_PSPPIRE_DICT(model), (GtkTreeModelFlags) 0);
+  g_return_val_if_fail (G_IS_PSPPIRE_DICT (model), (GtkTreeModelFlags) 0);
 
   return GTK_TREE_MODEL_LIST_ONLY;
 }
@@ -482,7 +488,7 @@ tree_model_n_columns (GtkTreeModel *model)
 static GType
 tree_model_column_type (GtkTreeModel *model, gint index)
 {
-  g_return_val_if_fail (G_IS_PSPPIRE_DICT(model), (GType) 0);
+  g_return_val_if_fail (G_IS_PSPPIRE_DICT (model), (GType) 0);
 
   switch (index)
     {
@@ -612,9 +618,9 @@ tree_model_nth_child (GtkTreeModel *model, GtkTreeIter *iter,
                     GtkTreeIter *parent, gint n)
 {
   PsppireDict *dict;
-  g_return_val_if_fail (G_IS_PSPPIRE_DICT(model), FALSE);
+  g_return_val_if_fail (G_IS_PSPPIRE_DICT (model), FALSE);
 
-  dict = PSPPIRE_DICT(model);
+  dict = PSPPIRE_DICT (model);
 
   if ( parent )
     return FALSE;
@@ -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);
+}