1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2008, 2009 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 <gtk/gtksignal.h>
20 #include <gtk/gtkbox.h>
23 #include <libpspp/message.h>
24 #include <output/cairo.h>
25 #include <output/manager.h>
26 #include <output/output.h>
27 #include <output/table.h>
32 #include "psppire-output-window.h"
37 #include <sys/types.h>
42 #define _(msgid) gettext (msgid)
43 #define N_(msgid) msgid
47 COL_TITLE, /* Table title. */
51 static void psppire_output_window_base_finalize (PsppireOutputWindowClass *, gpointer);
52 static void psppire_output_window_base_init (PsppireOutputWindowClass *class);
53 static void psppire_output_window_class_init (PsppireOutputWindowClass *class);
54 static void psppire_output_window_init (PsppireOutputWindow *window);
58 psppire_output_window_get_type (void)
60 static GType psppire_output_window_type = 0;
62 if (!psppire_output_window_type)
64 static const GTypeInfo psppire_output_window_info =
66 sizeof (PsppireOutputWindowClass),
67 (GBaseInitFunc) psppire_output_window_base_init,
68 (GBaseFinalizeFunc) psppire_output_window_base_finalize,
69 (GClassInitFunc)psppire_output_window_class_init,
70 (GClassFinalizeFunc) NULL,
72 sizeof (PsppireOutputWindow),
74 (GInstanceInitFunc) psppire_output_window_init,
77 psppire_output_window_type =
78 g_type_register_static (PSPPIRE_TYPE_WINDOW, "PsppireOutputWindow",
79 &psppire_output_window_info, 0);
82 return psppire_output_window_type;
85 static GObjectClass *parent_class;
88 psppire_output_window_finalize (GObject *object)
90 if (G_OBJECT_CLASS (parent_class)->finalize)
91 (*G_OBJECT_CLASS (parent_class)->finalize) (object);
96 psppire_output_window_class_init (PsppireOutputWindowClass *class)
98 parent_class = g_type_class_peek_parent (class);
103 psppire_output_window_base_init (PsppireOutputWindowClass *class)
105 GObjectClass *object_class = G_OBJECT_CLASS (class);
107 object_class->finalize = psppire_output_window_finalize;
113 psppire_output_window_base_finalize (PsppireOutputWindowClass *class,
118 /* Output driver class. */
120 static PsppireOutputWindow *the_output_viewer = NULL;
123 expose_event_callback (GtkWidget *widget, GdkEventExpose *event, gpointer data)
125 struct som_entity *entity = g_object_get_data (G_OBJECT (widget), "entity");
126 GdkWindow *window = widget->window;
127 cairo_t *cairo = gdk_cairo_create (GDK_DRAWABLE (window));
128 struct outp_driver *driver = xr_create_driver (cairo); /* XXX can fail */
129 struct tab_table *t = entity->ext;
132 rendering = entity->class->render_init (entity, driver, tab_l (t),
133 tab_r (t), tab_t (t), tab_b (t));
135 entity->class->title (rendering, 0, 0,
136 entity->table_num, entity->subtable_num,
137 entity->command_name);
138 entity->class->render (rendering, tab_l (t), tab_t (t),
139 tab_nc (t) - tab_r (t),
140 tab_nr (t) - tab_b (t));
142 entity->class->render_free (rendering);
143 driver->class->close_driver (driver);
144 outp_free_driver (driver);
149 psppire_output_submit (struct outp_driver *this, struct som_entity *entity)
151 if (the_output_viewer == NULL)
153 the_output_viewer = PSPPIRE_OUTPUT_WINDOW (psppire_output_window_new ());
154 gtk_widget_show_all (GTK_WIDGET (the_output_viewer));
157 if (entity->type == SOM_TABLE)
159 GdkWindow *window = GTK_WIDGET (the_output_viewer)->window;
160 cairo_t *cairo = gdk_cairo_create (GDK_DRAWABLE (window));
161 struct outp_driver *driver = xr_create_driver (cairo); /* XXX can fail */
162 struct tab_table *t = entity->ext;
166 GtkWidget *drawing_area;
171 rendering = entity->class->render_init (entity, driver, tab_l (t),
172 tab_r (t), tab_t (t), tab_b (t));
173 entity->class->area (rendering, &tw, &th);
175 drawing_area = gtk_drawing_area_new ();
176 gtk_widget_modify_bg (GTK_WIDGET (drawing_area), GTK_STATE_NORMAL,
177 >k_widget_get_style (drawing_area)->base[GTK_STATE_NORMAL]);
178 g_object_set_data (G_OBJECT (drawing_area),
179 "entity", som_entity_clone (entity));
180 gtk_widget_set_size_request (drawing_area, tw / 1024, th / 1024);
181 gtk_layout_put (the_output_viewer->output, drawing_area,
182 0, the_output_viewer->y);
183 gtk_widget_show (drawing_area);
184 g_signal_connect (G_OBJECT (drawing_area), "expose_event",
185 G_CALLBACK (expose_event_callback), NULL);
187 entity->class->render_free (rendering);
188 driver->class->close_driver (driver);
189 outp_free_driver (driver);
191 if (tw / 1024 > the_output_viewer->max_width)
192 the_output_viewer->max_width = tw / 1024;
193 the_output_viewer->y += th / 1024;
195 gtk_layout_set_size (the_output_viewer->output,
196 the_output_viewer->max_width, the_output_viewer->y);
198 store = GTK_TREE_STORE (gtk_tree_view_get_model (
199 the_output_viewer->overview));
200 if (entity->table_num != the_output_viewer->last_table_num)
202 gtk_tree_store_append (store, &item, NULL);
203 gtk_tree_store_set (store, &item, COL_TITLE, entity->command_name,
206 /* XXX shouldn't save a GtkTreeIter */
207 the_output_viewer->last_table_num = entity->table_num;
208 the_output_viewer->last_top_level = item;
210 gtk_tree_store_append (store, &item,
211 &the_output_viewer->last_top_level);
212 gtk_tree_store_set (store, &item, COL_TITLE,
213 t->title ? t->title : "(unnamed)", -1);
215 path = gtk_tree_model_get_path (GTK_TREE_MODEL (store),
216 &the_output_viewer->last_top_level);
217 gtk_tree_view_expand_row (the_output_viewer->overview, path, TRUE);
218 gtk_tree_path_free (path);
221 gtk_window_set_urgency_hint (GTK_WINDOW (the_output_viewer), TRUE);
224 static struct outp_class psppire_output_class =
226 "PSPPIRE", /* name */
228 NULL, /* open_driver */
229 NULL, /* close_driver */
230 NULL, /* open_page */
231 NULL, /* close_page */
233 psppire_output_submit, /* submit */
235 NULL, /* text_metrics */
236 NULL, /* text_draw */
237 NULL, /* initialise_chart */
238 NULL, /* finalise_chart */
242 psppire_output_window_setup (void)
244 outp_register_driver (outp_allocate_driver (&psppire_output_class,
248 int viewer_length = 16;
249 int viewer_width = 59;
251 /* Callback for the "delete" action (clicking the x on the top right
252 hand corner of the window) */
254 on_delete (GtkWidget *w, GdkEvent *event, gpointer user_data)
256 PsppireOutputWindow *ow = PSPPIRE_OUTPUT_WINDOW (user_data);
258 gtk_widget_destroy (GTK_WIDGET (ow));
260 the_output_viewer = NULL;
268 cancel_urgency (GtkWindow *window, gpointer data)
270 gtk_window_set_urgency_hint (window, FALSE);
275 psppire_output_window_init (PsppireOutputWindow *window)
277 GtkTreeViewColumn *column;
278 GtkCellRenderer *renderer;
281 xml = builder_new ("output-viewer.ui");
283 gtk_widget_reparent (get_widget_assert (xml, "vbox1"), GTK_WIDGET (window));
285 window->output = GTK_LAYOUT (get_widget_assert (xml, "output"));
288 window->overview = GTK_TREE_VIEW (get_widget_assert (xml, "overview"));
289 gtk_tree_view_set_model (window->overview,
290 GTK_TREE_MODEL (gtk_tree_store_new (
292 G_TYPE_STRING))); /* COL_TITLE */
293 window->last_table_num = -1;
295 column = gtk_tree_view_column_new ();
296 gtk_tree_view_append_column (GTK_TREE_VIEW (window->overview), column);
297 renderer = gtk_cell_renderer_text_new ();
298 gtk_tree_view_column_pack_start (column, renderer, TRUE);
299 gtk_tree_view_column_add_attribute (column, renderer, "text", COL_TITLE);
301 gtk_widget_modify_bg (GTK_WIDGET (window->output), GTK_STATE_NORMAL,
302 >k_widget_get_style (GTK_WIDGET (window->output))->base[GTK_STATE_NORMAL]);
306 g_signal_connect (window,
308 G_CALLBACK (cancel_urgency),
311 g_signal_connect (get_action_assert (xml,"help_about"),
313 G_CALLBACK (about_new),
316 g_signal_connect (get_action_assert (xml,"help_reference"),
318 G_CALLBACK (reference_manual),
321 g_signal_connect (get_action_assert (xml,"windows_minimise-all"),
323 G_CALLBACK (psppire_window_minimise_all),
327 GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (xml, "uimanager1", GTK_TYPE_UI_MANAGER));
329 PSPPIRE_WINDOW (window)->menu =
330 GTK_MENU_SHELL (gtk_ui_manager_get_widget (uim,"/ui/menubar1/windows_menuitem/windows_minimise-all")->parent);
333 g_object_unref (xml);
335 g_signal_connect (window, "delete-event",
336 G_CALLBACK (on_delete), window);
341 psppire_output_window_new (void)
343 return GTK_WIDGET (g_object_new (psppire_output_window_get_type (),
344 "filename", "Output",
345 "description", _("Output Viewer"),