1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2012 Free Software Foundation
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.
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.
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/>. */
19 #include "psppire-means-layer.h"
20 #include "psppire-selector.h"
21 #include "psppire-var-view.h"
26 #define _(msgid) gettext (msgid)
27 #define N_(msgid) msgid
30 static void psppire_means_layer_class_init (PsppireMeansLayerClass *class);
31 static void psppire_means_layer_init (PsppireMeansLayer *window);
33 G_DEFINE_TYPE (PsppireMeansLayer, psppire_means_layer, GTK_TYPE_VBOX);
37 psppire_means_layer_class_init (PsppireMeansLayerClass *class)
39 // GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
43 update (PsppireMeansLayer *ml)
45 gchar *l = g_strdup_printf (_("Layer %d of %d"),
46 ml->current_layer + 1, ml->n_layers);
48 gtk_label_set_text (GTK_LABEL (ml->label), l);
51 psppire_var_view_set_current_model (PSPPIRE_VAR_VIEW (ml->var_view),
54 gtk_widget_set_sensitive (ml->back, ml->current_layer > 0);
55 gtk_widget_set_sensitive (ml->forward,
56 psppire_var_view_get_iter_first (PSPPIRE_VAR_VIEW (ml->var_view), NULL));
60 on_forward (PsppireMeansLayer *ml)
63 if (ml->current_layer >= ml->n_layers)
65 ml->n_layers = ml->current_layer + 1;
66 psppire_var_view_push_model (PSPPIRE_VAR_VIEW (ml->var_view));
73 on_back (PsppireMeansLayer *ml)
75 g_return_if_fail (ml->current_layer > 0);
83 psppire_means_layer_init (PsppireMeansLayer *ml)
85 GtkWidget *hbox_upper = gtk_hbox_new (FALSE, 5);
86 GtkWidget *hbox_lower = gtk_hbox_new (FALSE, 5);
87 GtkWidget *alignment = gtk_alignment_new (0, 0.5, 0, 0);
88 GtkWidget *sw = gtk_scrolled_window_new (NULL, NULL);
90 ml->forward = gtk_button_new_from_stock (GTK_STOCK_GO_FORWARD);
91 ml->back = gtk_button_new_from_stock (GTK_STOCK_GO_BACK);
92 ml->var_view = psppire_var_view_new ();
93 ml->selector = psppire_selector_new ();
94 ml->label = gtk_label_new ("");
96 g_signal_connect_swapped (ml->forward, "clicked", G_CALLBACK (on_forward),
99 g_signal_connect_swapped (ml->back, "clicked", G_CALLBACK (on_back), ml);
101 g_signal_connect_swapped (ml->selector, "selected", G_CALLBACK (update), ml);
102 g_signal_connect_swapped (ml->selector, "de-selected", G_CALLBACK (update),
105 g_object_set (ml->var_view, "headers-visible", FALSE, NULL);
107 "shadow-type", GTK_SHADOW_ETCHED_IN,
108 "hscrollbar-policy", GTK_POLICY_AUTOMATIC,
111 g_object_set (ml->selector, "dest-widget", ml->var_view, NULL);
113 gtk_box_pack_start (GTK_BOX (hbox_upper), ml->back, FALSE, FALSE, 5);
114 gtk_box_pack_start (GTK_BOX (hbox_upper), ml->label, TRUE, FALSE, 5);
115 gtk_box_pack_start (GTK_BOX (hbox_upper), ml->forward, FALSE, FALSE, 5);
117 gtk_box_pack_start (GTK_BOX (hbox_lower), alignment, FALSE, FALSE, 5);
118 gtk_container_add (GTK_CONTAINER (alignment), ml->selector);
119 gtk_box_pack_start (GTK_BOX (hbox_lower), sw, TRUE, TRUE, 5);
120 gtk_container_add (GTK_CONTAINER (sw), ml->var_view);
122 gtk_box_pack_start (GTK_BOX (ml), hbox_upper, FALSE, FALSE, 5);
123 gtk_box_pack_start (GTK_BOX (ml), hbox_lower, TRUE, TRUE, 5);
126 ml->current_layer = 0;
129 gtk_widget_show_all (hbox_upper);
130 gtk_widget_show_all (hbox_lower);
134 psppire_means_layer_new (void)
136 return GTK_WIDGET (g_object_new (psppire_means_layer_get_type (), NULL));
141 psppire_means_layer_set_source (PsppireMeansLayer *ml, GtkWidget *w)
143 g_object_set (ml->selector, "source-widget", w, NULL);
148 psppire_means_layer_clear (PsppireMeansLayer *ml)
150 psppire_var_view_clear (PSPPIRE_VAR_VIEW (ml->var_view));
152 ml->current_layer = 0;