3b89d443a37013327cbeeda0afe54893d2dcb900
[pspp] / src / ui / gui / psppire-dialog-action-scatterplot.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2015  Free Software Foundation
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17
18 #include <config.h>
19
20 #include "psppire-dialog-action-scatterplot.h"
21
22 #include "psppire-var-view.h"
23
24 #include "psppire-dialog.h"
25 #include "builder-wrapper.h"
26 #include "helper.h"
27
28
29 #include "gettext.h"
30 #define _(msgid) gettext (msgid)
31 #define N_(msgid) msgid
32
33
34 static void psppire_dialog_action_scatterplot_init            (PsppireDialogActionScatterplot      *act);
35 static void psppire_dialog_action_scatterplot_class_init      (PsppireDialogActionScatterplotClass *class);
36
37 G_DEFINE_TYPE (PsppireDialogActionScatterplot, psppire_dialog_action_scatterplot, PSPPIRE_TYPE_DIALOG_ACTION);
38
39
40 static char *
41 generate_syntax (PsppireDialogAction *act)
42 {
43   PsppireDialogActionScatterplot *ow = PSPPIRE_DIALOG_ACTION_SCATTERPLOT (act);
44   gchar *text;
45   struct string dss;
46
47   ds_init_cstr (&dss, "GRAPH SCATTERPLOT(BIVARIATE) = ");
48
49   ds_put_cstr (&dss, gtk_entry_get_text (GTK_ENTRY (ow->y_axis)));
50   
51   ds_put_cstr (&dss, " WITH ");
52
53   ds_put_cstr (&dss, gtk_entry_get_text (GTK_ENTRY (ow->x_axis)));
54
55   ds_put_cstr (&dss, ".\n");
56
57   text = ds_steal_cstr (&dss);
58   ds_destroy (&dss);
59
60   return text;
61 }
62
63
64 static gboolean
65 dialog_state_valid (gpointer data)
66 {
67   PsppireDialogActionScatterplot *ow = PSPPIRE_DIALOG_ACTION_SCATTERPLOT (data);
68
69   const char *xvar = gtk_entry_get_text (GTK_ENTRY  (ow->x_axis));
70   const char *yvar = gtk_entry_get_text (GTK_ENTRY  (ow->y_axis));
71
72   if ( 0 == strcmp ("", xvar))
73     return FALSE;
74
75   if ( 0 == strcmp ("", yvar))
76     return FALSE;
77
78   
79   return TRUE;
80 }
81
82 static void
83 refresh (PsppireDialogAction *rd_)
84 {
85   PsppireDialogActionScatterplot *ow = PSPPIRE_DIALOG_ACTION_SCATTERPLOT (rd_);
86
87   gtk_entry_set_text (GTK_ENTRY (ow->x_axis), "");
88   gtk_entry_set_text (GTK_ENTRY (ow->y_axis), "");
89 }
90
91
92
93 static void
94 psppire_dialog_action_scatterplot_activate (GtkAction *a)
95 {
96   PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
97   PsppireDialogActionScatterplot *act = PSPPIRE_DIALOG_ACTION_SCATTERPLOT (a);
98
99   GHashTable *thing = psppire_dialog_action_get_pointer (pda);
100   GtkBuilder *xml = g_hash_table_lookup (thing, a);
101   if (!xml)
102     {
103       xml = builder_new ("scatterplot.ui");
104       g_hash_table_insert (thing, a, xml);
105     }
106
107   pda->dialog = get_widget_assert   (xml, "scatterplot-dialog");
108   pda->source = get_widget_assert   (xml, "scatterplot-treeview1");
109
110   act->y_axis =  get_widget_assert (xml, "scatterplot-y-axis");
111   act->x_axis =  get_widget_assert (xml, "scatterplot-x-axis");
112
113   psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid);
114   psppire_dialog_action_set_refresh (pda, refresh);
115
116   if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_scatterplot_parent_class)->activate)
117     PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_scatterplot_parent_class)->activate (pda);
118 }
119
120 static void
121 psppire_dialog_action_scatterplot_class_init (PsppireDialogActionScatterplotClass *class)
122 {
123   GtkActionClass *action_class = GTK_ACTION_CLASS (class);
124
125   action_class->activate = psppire_dialog_action_scatterplot_activate;
126   PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
127 }
128
129
130 static void
131 psppire_dialog_action_scatterplot_init (PsppireDialogActionScatterplot *act)
132 {
133 }