Created a new stock item for Reset buttons.
[pspp-builds.git] / src / ui / gui / psppire.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2004, 2005, 2006  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 #include <config.h>
18
19 #include <assert.h>
20 #include <libintl.h>
21 #include <gsl/gsl_errno.h>
22
23 #include "relocatable.h"
24
25 #include "data-editor.h"
26 #include "psppire.h"
27
28 #include <unistd.h>
29 #include <data/casereader.h>
30 #include <data/datasheet.h>
31 #include <data/file-handle-def.h>
32 #include <data/format.h>
33 #include <data/settings.h>
34 #include <data/file-name.h>
35 #include <data/procedure.h>
36 #include <libpspp/getl.h>
37 #include <language/lexer/lexer.h>
38 #include <libpspp/version.h>
39 #include <output/output.h>
40 #include <output/journal.h>
41
42 #include <gtk/gtk.h>
43 #include <glade/glade.h>
44 #include "psppire-dict.h"
45 #include "psppire-var-store.h"
46 #include "psppire-data-store.h"
47 #include "helper.h"
48 #include "data-sheet.h"
49 #include "var-sheet.h"
50 #include "message-dialog.h"
51
52 #include "output-viewer.h"
53
54 PsppireDataStore *the_data_store = 0;
55 PsppireVarStore *the_var_store = 0;
56
57 static void create_icon_factory (void);
58
59 struct source_stream *the_source_stream ;
60 struct dataset * the_dataset = NULL;
61
62
63 static void
64 replace_casereader (struct casereader *s)
65 {
66   PsppireCaseFile *pcf = psppire_case_file_new (s);
67
68   psppire_data_store_set_case_file (the_data_store, pcf);
69 }
70
71 #define _(msgid) gettext (msgid)
72 #define N_(msgid) msgid
73
74
75 void
76 initialize (void)
77 {
78   PsppireDict *dictionary = 0;
79
80   /* gtk_init messes with the locale.
81      So unset the bits we want to control ourselves */
82   setlocale (LC_NUMERIC, "C");
83
84   bindtextdomain (PACKAGE, locale_dir);
85
86
87   glade_init ();
88
89   gsl_set_error_handler_off ();
90   fmt_init ();
91   fn_init ();
92   outp_init ();
93   settings_init (&viewer_width, &viewer_length);
94   fh_init ();
95   the_source_stream =
96     create_source_stream (
97                           fn_getenv_default ("STAT_INCLUDE_PATH", include_path)
98                           );
99
100   the_dataset = create_dataset ();
101
102
103   message_dialog_init (the_source_stream);
104
105   dictionary = psppire_dict_new_from_dict (dataset_dict (the_dataset));
106
107   bind_textdomain_codeset (PACKAGE, "UTF-8");
108
109   /* Create the model for the var_sheet */
110   the_var_store = psppire_var_store_new (dictionary);
111
112   the_data_store = psppire_data_store_new (dictionary);
113   replace_casereader (NULL);
114
115   create_icon_factory ();
116
117   outp_configure_driver_line (
118     ss_cstr ("gui:ascii:screen:squeeze=on headers=off top-margin=0 "
119              "bottom-margin=0 paginate=off length=auto width=auto "
120              "emphasis=none "
121              "output-file=\"" OUTPUT_FILE_NAME "\" append=yes"));
122
123   unlink (OUTPUT_FILE_NAME);
124
125   journal_enable ();
126   textdomain (PACKAGE);
127
128   new_data_window (NULL, NULL);
129 }
130
131
132 void
133 de_initialize (void)
134 {
135   destroy_source_stream (the_source_stream);
136   message_dialog_done ();
137   settings_done ();
138   outp_done ();
139 }
140
141
142
143 struct icon_info
144 {
145   const char *file_name;
146   const gchar *id;
147 };
148
149
150 static const struct icon_info icons[] =
151   {
152     {PKGDATADIR "/value-labels.png",    "pspp-value-labels"},
153     {PKGDATADIR "/weight-cases.png",    "pspp-weight-cases"},
154     {PKGDATADIR "/goto-variable.png",   "pspp-goto-variable"},
155     {PKGDATADIR "/insert-variable.png", "pspp-insert-variable"},
156     {PKGDATADIR "/insert-case.png",     "pspp-insert-case"},
157     {PKGDATADIR "/split-file.png",      "pspp-split-file"},
158     {PKGDATADIR "/select-cases.png",    "pspp-select-cases"},
159     {PKGDATADIR "/recent-dialogs.png",  "pspp-recent-dialogs"},
160     {PKGDATADIR "/nominal.png",         "var-nominal"},
161     {PKGDATADIR "/ordinal.png",         "var-ordinal"},
162     {PKGDATADIR "/scale.png",           "var-scale"},
163     {PKGDATADIR "/string.png",          "var-string"},
164     {PKGDATADIR "/date-scale.png",      "var-date-scale"}
165   };
166
167 static void
168 create_icon_factory (void)
169 {
170   gint i;
171   GtkIconFactory *factory = gtk_icon_factory_new ();
172
173   for (i = 0 ; i < sizeof (icons) / sizeof(icons[0]); ++i)
174     {
175       GError *err = NULL;
176       GdkPixbuf *pixbuf =
177         gdk_pixbuf_new_from_file (relocate (icons[i].file_name), &err);
178
179       if ( pixbuf )
180         {
181           GtkIconSet *icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
182           g_object_unref (pixbuf);
183           gtk_icon_factory_add ( factory, icons[i].id, icon_set);
184         }
185       else
186         {
187           g_warning ("Cannot create icon: %s", err->message);
188           g_clear_error (&err);
189         }
190     }
191
192
193   {
194     /* Create our own "pspp-stock-reset" item, using the
195        GTK_STOCK_REFRESH icon set */
196
197     GtkStockItem item = {"pspp-stock-reset", N_("_Reset"), 0, 0, PACKAGE};
198     GtkIconSet *icon_set =
199       gtk_icon_factory_lookup_default (GTK_STOCK_REFRESH);
200
201     gtk_stock_add (&item, 1);
202     gtk_icon_factory_add (factory, "pspp-stock-reset", icon_set);
203   }
204
205   gtk_icon_factory_add_default (factory);
206 }
207