#include <config.h>
#include "psppire-dialog-action-roc.h"
+#include "psppire-value-entry.h"
#include "dialog-common.h"
#include <ui/syntax-gen.h>
static gboolean
dialog_state_valid (gpointer data)
{
+ int width;
+ gboolean result ;
+ union value val;
PsppireDialogActionRoc *rd = data;
- const gchar *text;
+ const gchar *var_name;
+ const struct variable *var;
GtkTreeModel *liststore =
gtk_tree_view_get_model (GTK_TREE_VIEW (rd->test_variables));
if (gtk_tree_model_iter_n_children (liststore, NULL) < 1)
return FALSE;
-
- text = gtk_entry_get_text (GTK_ENTRY (rd->state_variable));
- if ( 0 == strcmp ("", text))
- return FALSE;
+ var_name = gtk_entry_get_text (GTK_ENTRY (rd->state_variable));
+ var = psppire_dict_lookup_var (PSPPIRE_DIALOG_ACTION (rd)->dict, var_name);
- text = gtk_entry_get_text (GTK_ENTRY (rd->state_value));
- if ( 0 == strcmp ("", text))
+ if ( var == NULL)
return FALSE;
+ width = var_get_width (var);
+ value_init (&val, width);
+
+ result = psppire_value_entry_get_value (PSPPIRE_VALUE_ENTRY (rd->state_value), &val, width);
+
+ if (var_is_value_missing (var, &val, MV_SYSTEM))
+ result = FALSE;
- return TRUE;
+ value_destroy (&val, width);
+
+ return result;
}
static void
g_object_set (rd->reference, "inconsistent", TRUE, NULL);
g_object_set (rd->reference, "sensitive", FALSE, NULL);
}
- else
+ else
{
g_object_set (rd->reference, "inconsistent", FALSE, NULL);
g_object_set (rd->reference, "sensitive", TRUE, NULL);
gtk_list_store_clear (GTK_LIST_STORE (liststore));
gtk_entry_set_text (GTK_ENTRY (rd->state_variable), "");
- gtk_entry_set_text (GTK_ENTRY (rd->state_value), "");
+ psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (rd->state_value), NULL);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->curve), TRUE);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->reference), FALSE);
}
static void
-psppire_dialog_action_roc_activate (GtkAction *a)
+on_state_var_changed (PsppireDialogAction *a)
+{
+ PsppireDialogActionRoc *act = PSPPIRE_DIALOG_ACTION_ROC (a);
+
+ const gchar *var_name = gtk_entry_get_text (GTK_ENTRY(act->state_variable));
+
+ const struct variable *var =
+ psppire_dict_lookup_var (PSPPIRE_DIALOG_ACTION(act)->dict, var_name);
+
+ if ( var == NULL)
+ return;
+
+ psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (act->state_value), var);
+}
+
+static GtkBuilder *
+psppire_dialog_action_roc_activate (PsppireDialogAction *a, GVariant *param)
{
PsppireDialogActionRoc *act = PSPPIRE_DIALOG_ACTION_ROC (a);
PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
- GtkBuilder *xml = builder_new ("roc.ui");
+ GtkBuilder *xml = builder_new ( "roc.ui");
+
pda->dialog = get_widget_assert (xml, "roc-dialog");
pda->source = get_widget_assert (xml, "dict-view");
- pda->source = get_widget_assert (xml, "dict-view");
act->test_variables = get_widget_assert (xml, "psppire-var-view1");
act->state_variable = get_widget_assert (xml, "entry1");
act->standard_error = get_widget_assert (xml, "standard-error");
act->coordinates = get_widget_assert (xml, "co-ordinates");
- g_object_unref (xml);
+ g_signal_connect_swapped (act->state_variable, "changed",
+ G_CALLBACK (on_state_var_changed), act);
g_signal_connect (act->curve, "toggled",
G_CALLBACK (on_curve_button_toggle), act);
psppire_dialog_action_set_valid_predicate (pda,
dialog_state_valid);
-
- if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_roc_parent_class)->activate)
- PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_roc_parent_class)->activate (pda);
+ return xml;
}
static char *
-generate_syntax (PsppireDialogAction *a)
+generate_syntax (const PsppireDialogAction *a)
{
PsppireDialogActionRoc *rd = PSPPIRE_DIALOG_ACTION_ROC (a);
gchar *text;
g_string_append (string, " (");
{
- const gchar *value = gtk_entry_get_text (GTK_ENTRY (rd->state_value));
+ const struct variable *var =
+ psppire_dict_lookup_var (PSPPIRE_DIALOG_ACTION(rd)->dict, var_name);
+
+ union value val;
+ value_init (&val, var_get_width (var));
- const struct variable *var = psppire_dict_lookup_var (PSPPIRE_DIALOG_ACTION(rd)->dict, var_name);
+ psppire_value_entry_get_value (PSPPIRE_VALUE_ENTRY (rd->state_value),
+ &val, var_get_width (var));
g_return_val_if_fail (var, NULL);
- if ( var_is_alpha (var))
- {
- struct string str;
- ds_init_empty (&str);
- syntax_gen_string (&str, ss_cstr (value));
- g_string_append (string, ds_cstr (&str));
- ds_destroy (&str);
- }
- else
- g_string_append (string, value);
+ {
+ struct string str;
+ ds_init_empty (&str);
+
+ syntax_gen_value (&str, &val, var_get_width (var),
+ var_get_print_format (var));
+
+ g_string_append (string, ds_cstr (&str));
+ ds_destroy (&str);
+ }
+ value_destroy (&val, var_get_width (var));
}
+
g_string_append (string, ")");
static void
psppire_dialog_action_roc_class_init (PsppireDialogActionRocClass *class)
{
- GtkActionClass *action_class = GTK_ACTION_CLASS (class);
-
- action_class->activate = psppire_dialog_action_roc_activate;
+ PSPPIRE_DIALOG_ACTION_CLASS (class)->initial_activate = psppire_dialog_action_roc_activate;
PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
}