#include <language/syntax-string-source.h>
#include "syntax-editor.h"
+#include <gl/xalloc.h>
+
#include <gettext.h>
#define _(msgid) gettext (msgid)
#define N_(msgid) msgid
+enum group_definition
+ {
+ GROUPS_UNDEF,
+ GROUPS_VALUES,
+ GROUPS_CUT_POINT
+ };
+
+struct tt_groups_dialog
+{
+ GtkWidget *dialog;
+ GtkWidget *label;
+ GtkWidget *table1;
+ GtkWidget *table2;
+ GtkWidget *hbox1;
+
+ GtkWidget *values_toggle_button;
+ GtkWidget *cut_point_toggle_button;
+
+ GtkWidget *grp_entry[2];
+ GtkWidget *cut_point_entry;
+
+ enum group_definition group_defn;
+ gchar *val[2];
+};
+
+static void
+set_group_criterion_type (GtkToggleButton *button,
+ struct tt_groups_dialog *groups)
+{
+ gboolean by_values = gtk_toggle_button_get_active (button);
+
+ gtk_widget_set_sensitive (groups->label, by_values);
+ gtk_widget_set_sensitive (groups->table2, by_values);
+
+ gtk_widget_set_sensitive (groups->hbox1, !by_values);
+}
+
+static void
+tt_groups_dialog_destroy (struct tt_groups_dialog *grps)
+{
+ g_object_unref (grps->table1);
+ g_object_unref (grps->table2);
+
+ g_free (grps->val[0]);
+ g_free (grps->val[1]);
+
+ g_free (grps);
+}
+
+static struct tt_groups_dialog *
+tt_groups_dialog_create (GladeXML *xml, GtkWindow *parent)
+{
+ struct tt_groups_dialog *grps = xmalloc (sizeof (*grps));
+
+ grps->group_defn = GROUPS_UNDEF;
+
+ grps->dialog = get_widget_assert (xml, "define-groups-dialog");
+ grps->table1 = get_widget_assert (xml, "table1");
+ grps->table2 = get_widget_assert (xml, "table2");
+ grps->label = get_widget_assert (xml, "label4");
+ grps->hbox1 = get_widget_assert (xml, "hbox1");
+
+ grps->grp_entry[0] = get_widget_assert (xml, "group1-entry");
+ grps->grp_entry[1] = get_widget_assert (xml, "group2-entry");
+ grps->cut_point_entry = get_widget_assert (xml, "cut-point-entry");
+
+ grps->cut_point_toggle_button = get_widget_assert (xml, "radiobutton4");
+ grps->values_toggle_button = get_widget_assert (xml, "radiobutton3");
+
+ g_object_ref (grps->table1);
+ g_object_ref (grps->table2);
+
+ g_signal_connect (grps->values_toggle_button, "toggled",
+ G_CALLBACK (set_group_criterion_type), grps);
+
+ gtk_window_set_transient_for (parent,
+ GTK_WINDOW (grps->dialog));
+
+
+
+ grps->val[0] = strdup ("");
+ grps->val[1] = strdup ("");
+
+ return grps;
+}
+
+
struct tt_indep_samples_dialog
{
GladeXML *xml; /* The xml that generated the widgets */
GtkWidget *dialog;
PsppireDict *dict;
- gboolean groups_defined;
+ GtkWidget *define_groups_button;
+ GtkWidget *groups_entry;
+ struct tt_groups_dialog *grps;
struct tt_options_dialog *opts;
};
+static void
+set_define_groups_sensitivity (GtkEntry *entry,
+ struct tt_indep_samples_dialog *tt_d)
+{
+ const gchar *text = gtk_entry_get_text (entry);
+
+ const struct variable *v = psppire_dict_lookup_var (tt_d->dict, text);
+
+ gtk_widget_set_sensitive (tt_d->define_groups_button, v != NULL);
+}
+
+
static gchar *
generate_syntax (const struct tt_indep_samples_dialog *d)
{
struct variable *group_variable;
gchar *text;
- GtkWidget *entry =
- get_widget_assert (d->xml, "indep-samples-t-test-entry");
GtkWidget *tv =
get_widget_assert (d->xml, "indep-samples-t-test-treeview2");
g_string_append (str, "\n\t/GROUPS=");
group_variable =
- psppire_dict_lookup_var (d->dict, gtk_entry_get_text (GTK_ENTRY (entry)));
+ psppire_dict_lookup_var (d->dict,
+ gtk_entry_get_text (GTK_ENTRY (d->groups_entry)));
g_string_append (str, var_get_name (group_variable));
- if ( d->groups_defined )
+ if (d->grps->group_defn != GROUPS_UNDEF)
{
- GtkWidget *entry1 = get_widget_assert (d->xml, "group1-entry");
- GtkWidget *entry2 = get_widget_assert (d->xml, "group2-entry");
-
- const gchar *val1 = gtk_entry_get_text (GTK_ENTRY (entry1));
- const gchar *val2 = gtk_entry_get_text (GTK_ENTRY (entry2));
-
g_string_append (str, "(");
+
if ( var_is_alpha (group_variable))
{
struct string s;
- ds_init_cstr (&s, val1);
+ ds_init_cstr (&s, d->grps->val[0]);
gen_quoted_string (&s);
g_string_append (str, ds_cstr (&s));
ds_destroy (&s);
}
else
{
- g_string_append (str, val1);
- }
- g_string_append (str, ",");
- if ( var_is_alpha (group_variable))
- {
- struct string s;
- ds_init_cstr (&s, val2);
- gen_quoted_string (&s);
- g_string_append (str, ds_cstr (&s));
- ds_destroy (&s);
+ g_string_append (str, d->grps->val[0]);
}
- else
+
+ if ( d->grps->group_defn == GROUPS_VALUES )
{
- g_string_append (str, val2);
+ g_string_append (str, ",");
+
+ if ( var_is_alpha (group_variable))
+ {
+ struct string s;
+ ds_init_cstr (&s, d->grps->val[1]);
+ gen_quoted_string (&s);
+ g_string_append (str, ds_cstr (&s));
+ ds_destroy (&s);
+ }
+ else
+ {
+ g_string_append (str, d->grps->val[1]);
+ }
}
+
g_string_append (str, ")");
}
-
tt_options_dialog_append_syntax (d->opts, str);
g_string_append (str, ".\n");
return text;
}
-
-
static void
-refresh (GladeXML *xml)
+refresh (struct tt_indep_samples_dialog *ttd)
{
- GtkWidget *entry =
- get_widget_assert (xml, "indep-samples-t-test-entry");
-
GtkWidget *tv =
- get_widget_assert (xml, "indep-samples-t-test-treeview2");
+ get_widget_assert (ttd->xml, "indep-samples-t-test-treeview2");
GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (tv));
- gtk_entry_set_text (GTK_ENTRY (entry), "");
+ gtk_entry_set_text (GTK_ENTRY (ttd->groups_entry), "");
gtk_list_store_clear (GTK_LIST_STORE (model));
+
+ gtk_widget_set_sensitive (ttd->define_groups_button, FALSE);
}
+/* Returns TRUE iff the define groups subdialog has a
+ state which defines a valid group criterion */
static gboolean
define_groups_state_valid (gpointer data)
{
- struct tt_indep_samples_dialog *d = data;
-
- GtkWidget *entry1 = get_widget_assert (d->xml, "group1-entry");
- GtkWidget *entry2 = get_widget_assert (d->xml, "group2-entry");
+ struct tt_groups_dialog *d = data;
- if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry1))))
- return FALSE;
+ if ( gtk_toggle_button_get_active
+ (GTK_TOGGLE_BUTTON (d->values_toggle_button)))
+ {
+ if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (d->grp_entry[0]))))
+ return FALSE;
- if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry2))))
- return FALSE;
+ if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (d->grp_entry[1]))))
+ return FALSE;
+ }
+ else
+ {
+ if ( 0 == strcmp ("",
+ gtk_entry_get_text (GTK_ENTRY (d->cut_point_entry))))
+ return FALSE;
+ }
return TRUE;
}
static void
run_define_groups (struct tt_indep_samples_dialog *ttd)
{
+ struct tt_groups_dialog *grps = ttd->grps;
+
gint response;
- GtkWidget *dialog =
- get_widget_assert (ttd->xml, "define-groups-dialog");
+ GtkWidget *box = get_widget_assert (ttd->xml, "dialog-hbox2");
+
+ const gchar *text = gtk_entry_get_text (GTK_ENTRY (ttd->groups_entry));
+
+ const struct variable *v = psppire_dict_lookup_var (ttd->dict, text);
+
+ if ( grps->table2->parent)
+ gtk_container_remove (GTK_CONTAINER (grps->table2->parent), grps->table2);
+
+ if ( grps->table1->parent)
+ gtk_container_remove (GTK_CONTAINER (grps->table1->parent), grps->table1);
- psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
- define_groups_state_valid, ttd);
- gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (ttd->dialog));
+ if ( var_is_numeric (v))
+ {
+ gtk_table_attach_defaults (GTK_TABLE (grps->table1), grps->table2,
+ 1, 2, 1, 2);
+
+ gtk_container_add (GTK_CONTAINER (box), grps->table1);
+ }
+ else
+ {
+ gtk_container_add (GTK_CONTAINER (box), grps->table2);
+ grps->group_defn = GROUPS_VALUES;
+ }
+
+
+ psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (grps->dialog),
+ define_groups_state_valid, grps);
+
+ if ( grps->group_defn != GROUPS_CUT_POINT )
+ {
+ gtk_toggle_button_set_active
+ (GTK_TOGGLE_BUTTON (grps->cut_point_toggle_button), TRUE);
+
+ gtk_toggle_button_set_active
+ (GTK_TOGGLE_BUTTON (grps->values_toggle_button), TRUE);
+
+ gtk_entry_set_text (GTK_ENTRY (grps->grp_entry[0]), grps->val[0]);
+ gtk_entry_set_text (GTK_ENTRY (grps->grp_entry[1]), grps->val[1]);
+
+ gtk_entry_set_text (GTK_ENTRY (grps->cut_point_entry), "");
+ }
+ else
+ {
+ gtk_toggle_button_set_active
+ (GTK_TOGGLE_BUTTON (grps->values_toggle_button), TRUE);
+
+ gtk_toggle_button_set_active
+ (GTK_TOGGLE_BUTTON (grps->cut_point_toggle_button), TRUE);
- response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
+ gtk_entry_set_text (GTK_ENTRY (grps->grp_entry[0]), "");
+ gtk_entry_set_text (GTK_ENTRY (grps->grp_entry[1]), "");
- ttd->groups_defined = (response == PSPPIRE_RESPONSE_CONTINUE);
+ gtk_entry_set_text (GTK_ENTRY (grps->cut_point_entry), grps->val[0]);
+ }
+
+ g_signal_emit_by_name (grps->grp_entry[0], "changed");
+ g_signal_emit_by_name (grps->grp_entry[1], "changed");
+ g_signal_emit_by_name (grps->cut_point_entry, "changed");
+
+ response = psppire_dialog_run (PSPPIRE_DIALOG (grps->dialog));
+
+ if (response == PSPPIRE_RESPONSE_CONTINUE)
+ {
+ g_free (grps->val[0]);
+ g_free (grps->val[1]);
+
+ if (gtk_toggle_button_get_active
+ (GTK_TOGGLE_BUTTON (grps->values_toggle_button)))
+ {
+ grps->group_defn = GROUPS_VALUES;
+
+ grps->val[0] =
+ strdup (gtk_entry_get_text (GTK_ENTRY (grps->grp_entry[0])));
+
+ grps->val[1] =
+ strdup (gtk_entry_get_text (GTK_ENTRY (grps->grp_entry[1])));
+ }
+ else
+ {
+ grps->group_defn = GROUPS_CUT_POINT;
+
+ grps->val[1] = NULL;
+
+ grps->val[0] =
+ strdup (gtk_entry_get_text (GTK_ENTRY (grps->cut_point_entry)));
+ }
+
+ psppire_dialog_notify_change (PSPPIRE_DIALOG (ttd->dialog));
+ }
}
{
struct tt_indep_samples_dialog *tt_d = data;
- GtkWidget *entry =
- get_widget_assert (tt_d->xml, "indep-samples-t-test-entry");
-
GtkWidget *tv_vars =
get_widget_assert (tt_d->xml, "indep-samples-t-test-treeview2");
GtkTreeIter notused;
- if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))))
+ if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (tt_d->groups_entry))))
return FALSE;
-
if ( 0 == gtk_tree_model_get_iter_first (vars, ¬used))
return FALSE;
+ if ( tt_d->grps->group_defn == GROUPS_UNDEF)
+ return FALSE;
+
return TRUE;
}
-
/* Pops up the dialog box */
void
t_test_independent_samples_dialog (GObject *o, gpointer data)
GtkWidget *selector1 =
get_widget_assert (xml, "indep-samples-t-test-selector1");
- GtkWidget *entry =
- get_widget_assert (xml, "indep-samples-t-test-entry");
-
- GtkWidget *define_groups_button =
- get_widget_assert (xml, "define-groups-button");
-
GtkWidget *options_button =
get_widget_assert (xml, "options-button");
tt_d.dialog = get_widget_assert (xml, "t-test-independent-samples-dialog");
tt_d.xml = xml;
tt_d.dict = vs->dict;
- tt_d.groups_defined = FALSE;
+
+ tt_d.define_groups_button = get_widget_assert (xml, "define-groups-button");
+ tt_d.groups_entry = get_widget_assert (xml, "indep-samples-t-test-entry");
tt_d.opts = tt_options_dialog_create (xml, de->parent.window);
+ tt_d.grps = tt_groups_dialog_create (xml, de->parent.window);
+
gtk_window_set_transient_for (GTK_WINDOW (tt_d.dialog), de->parent.window);
insert_source_row_into_tree_view,
NULL);
+ psppire_selector_set_allow (PSPPIRE_SELECTOR (selector1),
+ numeric_only);
+
psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector2),
- dict_view, entry,
+ dict_view, tt_d.groups_entry,
insert_source_row_into_entry,
is_currently_in_entry);
- g_signal_connect_swapped (define_groups_button, "clicked",
+ g_signal_connect_swapped (tt_d.define_groups_button, "clicked",
G_CALLBACK (run_define_groups), &tt_d);
G_CALLBACK (tt_options_dialog_run), tt_d.opts);
- g_signal_connect_swapped (tt_d.dialog, "refresh", G_CALLBACK (refresh), xml);
+ g_signal_connect_swapped (tt_d.dialog, "refresh", G_CALLBACK (refresh),
+ &tt_d);
+
+ g_signal_connect (tt_d.groups_entry, "changed",
+ G_CALLBACK (set_define_groups_sensitivity), &tt_d);
psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (tt_d.dialog),
}
tt_options_dialog_destroy (tt_d.opts);
+ tt_groups_dialog_destroy (tt_d.grps);
+
g_object_unref (xml);
}
<widget class="GtkLabel" id="label36">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Grouping Variable:</property>
+ <property name="label" translatable="yes">Define Groups</property>
</widget>
<packing>
<property name="expand">False</property>
<widget class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="n_rows">2</property>
+ <property name="n_rows">3</property>
<property name="n_columns">2</property>
<property name="column_spacing">5</property>
+ <property name="row_spacing">5</property>
+ <child>
+ <placeholder/>
+ </child>
<child>
- <widget class="GtkEntry" id="group1-entry">
+ <widget class="GtkRadioButton" id="radiobutton4">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ <property name="group">radiobutton3</property>
</widget>
<packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="x_options"></property>
+ <property name="y_options"></property>
</packing>
</child>
<child>
- <widget class="GtkEntry" id="group2-entry">
+ <widget class="GtkLabel" id="label4">
<property name="visible">True</property>
- <property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">_Use specified values:</property>
+ <property name="use_underline">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
+ <property name="y_options"></property>
</packing>
</child>
<child>
- <widget class="GtkLabel" id="label1">
+ <widget class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="label" translatable="yes">Group_1 value:</property>
- <property name="use_underline">True</property>
+ <child>
+ <widget class="GtkLabel" id="label5">
+ <property name="visible">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">_Cut point:</property>
+ <property name="use_underline">True</property>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkEntry" id="cut-point-entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ </widget>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
</widget>
<packing>
- <property name="x_options"></property>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="y_options"></property>
+ <property name="y_padding">5</property>
</packing>
</child>
<child>
- <widget class="GtkLabel" id="label2">
+ <widget class="GtkTable" id="table2">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="label" translatable="yes">Group_2 value:</property>
- <property name="use_underline">True</property>
+ <property name="n_rows">2</property>
+ <property name="n_columns">2</property>
+ <property name="column_spacing">5</property>
+ <property name="row_spacing">5</property>
+ <child>
+ <widget class="GtkEntry" id="group1-entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ </widget>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkEntry" id="group2-entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ </widget>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="label" translatable="yes">Group_1 value:</property>
+ <property name="use_underline">True</property>
+ </widget>
+ <packing>
+ <property name="x_options"></property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="label" translatable="yes">Group_2 value:</property>
+ <property name="use_underline">True</property>
+ </widget>
+ <packing>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options"></property>
+ </packing>
+ </child>
</widget>
<packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
+ <property name="y_options">GTK_EXPAND</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkRadioButton" id="radiobutton3">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ </widget>
+ <packing>
<property name="x_options"></property>
</packing>
</child>