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 static void psppire_output_window_base_finalize (PsppireOutputWindowClass *, gpointer);
48 static void psppire_output_window_base_init (PsppireOutputWindowClass *class);
49 static void psppire_output_window_class_init (PsppireOutputWindowClass *class);
50 static void psppire_output_window_init (PsppireOutputWindow *window);
54 psppire_output_window_get_type (void)
56 static GType psppire_output_window_type = 0;
58 if (!psppire_output_window_type)
60 static const GTypeInfo psppire_output_window_info =
62 sizeof (PsppireOutputWindowClass),
63 (GBaseInitFunc) psppire_output_window_base_init,
64 (GBaseFinalizeFunc) psppire_output_window_base_finalize,
65 (GClassInitFunc)psppire_output_window_class_init,
66 (GClassFinalizeFunc) NULL,
68 sizeof (PsppireOutputWindow),
70 (GInstanceInitFunc) psppire_output_window_init,
73 psppire_output_window_type =
74 g_type_register_static (PSPPIRE_TYPE_WINDOW, "PsppireOutputWindow",
75 &psppire_output_window_info, 0);
78 return psppire_output_window_type;
81 static GObjectClass *parent_class;
84 psppire_output_window_finalize (GObject *object)
86 if (G_OBJECT_CLASS (parent_class)->finalize)
87 (*G_OBJECT_CLASS (parent_class)->finalize) (object);
92 psppire_output_window_class_init (PsppireOutputWindowClass *class)
94 parent_class = g_type_class_peek_parent (class);
99 psppire_output_window_base_init (PsppireOutputWindowClass *class)
101 GObjectClass *object_class = G_OBJECT_CLASS (class);
103 object_class->finalize = psppire_output_window_finalize;
109 psppire_output_window_base_finalize (PsppireOutputWindowClass *class,
114 /* Output driver class. */
116 static PsppireOutputWindow *the_output_viewer = NULL;
119 expose_event_callback (GtkWidget *widget, GdkEventExpose *event, gpointer data)
121 struct som_entity *entity = g_object_get_data (G_OBJECT (widget), "entity");
122 GdkWindow *window = widget->window;
123 cairo_t *cairo = gdk_cairo_create (GDK_DRAWABLE (window));
124 struct outp_driver *driver = xr_create_driver (cairo); /* XXX can fail */
125 struct tab_table *t = entity->ext;
128 rendering = entity->class->render_init (entity, driver, tab_l (t),
129 tab_r (t), tab_t (t), tab_b (t));
131 entity->class->title (rendering, 0, 0,
132 entity->table_num, entity->subtable_num,
133 entity->command_name);
134 entity->class->render (rendering, tab_l (t), tab_t (t),
135 tab_nc (t) - tab_r (t),
136 tab_nr (t) - tab_b (t));
138 entity->class->render_free (rendering);
139 driver->class->close_driver (driver);
140 outp_free_driver (driver);
145 psppire_output_submit (struct outp_driver *this, struct som_entity *entity)
147 if (the_output_viewer == NULL)
149 the_output_viewer = PSPPIRE_OUTPUT_WINDOW (psppire_output_window_new ());
150 gtk_widget_show_all (GTK_WIDGET (the_output_viewer));
153 if (entity->type == SOM_TABLE)
155 GdkWindow *window = GTK_WIDGET (the_output_viewer)->window;
156 cairo_t *cairo = gdk_cairo_create (GDK_DRAWABLE (window));
157 struct outp_driver *driver = xr_create_driver (cairo); /* XXX can fail */
158 struct tab_table *t = entity->ext;
159 GtkWidget *drawing_area;
164 rendering = entity->class->render_init (entity, driver, tab_l (t),
165 tab_r (t), tab_t (t), tab_b (t));
166 entity->class->area (rendering, &tw, &th);
168 drawing_area = gtk_drawing_area_new ();
169 gtk_widget_modify_bg (GTK_WIDGET (drawing_area), GTK_STATE_NORMAL,
170 >k_widget_get_style (drawing_area)->base[GTK_STATE_NORMAL]);
171 g_object_set_data (G_OBJECT (drawing_area),
172 "entity", som_entity_clone (entity));
173 gtk_widget_set_size_request (drawing_area, tw / 1024, th / 1024);
174 gtk_layout_put (the_output_viewer->output, drawing_area,
175 0, the_output_viewer->y);
176 gtk_widget_show (drawing_area);
177 g_signal_connect (G_OBJECT (drawing_area), "expose_event",
178 G_CALLBACK (expose_event_callback), NULL);
180 entity->class->render_free (rendering);
181 driver->class->close_driver (driver);
182 outp_free_driver (driver);
184 if (tw / 1024 > the_output_viewer->max_width)
185 the_output_viewer->max_width = tw / 1024;
186 the_output_viewer->y += th / 1024;
188 gtk_layout_set_size (the_output_viewer->output,
189 the_output_viewer->max_width, the_output_viewer->y);
192 gtk_window_set_urgency_hint (GTK_WINDOW (the_output_viewer), TRUE);
195 static struct outp_class psppire_output_class =
197 "PSPPIRE", /* name */
199 NULL, /* open_driver */
200 NULL, /* close_driver */
201 NULL, /* open_page */
202 NULL, /* close_page */
204 psppire_output_submit, /* submit */
206 NULL, /* text_metrics */
207 NULL, /* text_draw */
208 NULL, /* initialise_chart */
209 NULL, /* finalise_chart */
213 psppire_output_window_setup (void)
215 outp_register_driver (outp_allocate_driver (&psppire_output_class,
219 int viewer_length = 16;
220 int viewer_width = 59;
222 /* Callback for the "delete" action (clicking the x on the top right
223 hand corner of the window) */
225 on_delete (GtkWidget *w, GdkEvent *event, gpointer user_data)
227 PsppireOutputWindow *ow = PSPPIRE_OUTPUT_WINDOW (user_data);
229 gtk_widget_destroy (GTK_WIDGET (ow));
231 the_output_viewer = NULL;
239 cancel_urgency (GtkWindow *window, gpointer data)
241 gtk_window_set_urgency_hint (window, FALSE);
246 psppire_output_window_init (PsppireOutputWindow *window)
248 GtkBuilder *xml = builder_new ("output-viewer.ui");
250 gtk_widget_reparent (get_widget_assert (xml, "vbox1"), GTK_WIDGET (window));
252 window->output = GTK_LAYOUT (get_widget_assert (xml, "output"));
255 gtk_widget_modify_bg (GTK_WIDGET (window->output), GTK_STATE_NORMAL,
256 >k_widget_get_style (GTK_WIDGET (window->output))->base[GTK_STATE_NORMAL]);
260 g_signal_connect (window,
262 G_CALLBACK (cancel_urgency),
265 g_signal_connect (get_action_assert (xml,"help_about"),
267 G_CALLBACK (about_new),
270 g_signal_connect (get_action_assert (xml,"help_reference"),
272 G_CALLBACK (reference_manual),
275 g_signal_connect (get_action_assert (xml,"windows_minimise-all"),
277 G_CALLBACK (psppire_window_minimise_all),
281 GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (xml, "uimanager1", GTK_TYPE_UI_MANAGER));
283 PSPPIRE_WINDOW (window)->menu =
284 GTK_MENU_SHELL (gtk_ui_manager_get_widget (uim,"/ui/menubar1/windows_menuitem/windows_minimise-all")->parent);
287 g_object_unref (xml);
289 g_signal_connect (window, "delete-event",
290 G_CALLBACK (on_delete), window);
295 psppire_output_window_new (void)
297 return GTK_WIDGET (g_object_new (psppire_output_window_get_type (),
298 "filename", "Output",
299 "description", _("Output Viewer"),