1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2008-2015, 2016 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 "ui/gui/psppire-output-view.h"
24 #include "libpspp/assertion.h"
25 #include "libpspp/string-map.h"
26 #include "output/cairo.h"
27 #include "output/driver-provider.h"
28 #include "output/driver.h"
29 #include "output/chart-item.h"
30 #include "output/group-item.h"
31 #include "output/message-item.h"
32 #include "output/output-item.h"
33 #include "output/table-item.h"
34 #include "output/text-item.h"
36 #include "gl/c-xvasprintf.h"
37 #include "gl/minmax.h"
38 #include "gl/tmpdir.h"
39 #include "gl/xalloc.h"
42 #define _(msgid) gettext (msgid)
44 struct output_view_item
46 struct output_item *item;
47 GtkWidget *drawing_area;
50 struct psppire_output_view
60 struct string_map render_opts;
61 GtkTreeView *overview;
62 GtkTreeIter cur_command;
67 struct output_view_item *items;
68 size_t n_items, allocated_items;
70 /* Variables pertaining to printing */
71 GtkPrintSettings *print_settings;
72 struct xr_driver *print_xrd;
80 COL_NAME, /* Table name. */
81 COL_ADDR, /* Pointer to the table */
82 COL_Y, /* Y position of top of name. */
86 /* Draws a white background on the GtkLayout to match the white background of
87 each of the output items. */
89 layout_draw_callback (GtkWidget *widget, cairo_t *cr, gpointer data)
93 int width = gtk_widget_get_allocated_width (widget);
94 int height = gtk_widget_get_allocated_height (widget);
95 cairo_rectangle (cr, 0, 0, width, height);
96 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
101 return FALSE; /* Continue drawing the GtkDrawingAreas. */
105 draw_callback (GtkWidget *widget, cairo_t *cr, gpointer data)
108 if (!gdk_cairo_get_clip_rectangle (cr, &clip))
111 struct xr_rendering *r = g_object_get_data (G_OBJECT (widget), "rendering");
112 xr_rendering_draw (r, cr, clip.x, clip.y,
113 clip.x + clip.width, clip.y + clip.height);
118 free_rendering (gpointer rendering_)
120 struct xr_rendering *rendering = rendering_;
121 xr_rendering_destroy (rendering);
125 get_xr_options (struct psppire_output_view *view, struct string_map *options)
127 string_map_clear (options);
129 GtkStyleContext *context
130 = gtk_widget_get_style_context (GTK_WIDGET (view->output));
131 GtkStateFlags state = gtk_widget_get_state_flags (GTK_WIDGET (view->output));
133 /* Use GTK+ default font as proportional font. */
134 PangoFontDescription *font_desc;
135 gtk_style_context_get (context, state, "font", &font_desc, NULL);
136 char *font_name = pango_font_description_to_string (font_desc);
137 string_map_insert (options, "prop-font", font_name);
140 /* Derived emphasized font from proportional font. */
141 pango_font_description_set_style (font_desc, PANGO_STYLE_ITALIC);
142 font_name = pango_font_description_to_string (font_desc);
143 string_map_insert (options, "emph-font", font_name);
145 pango_font_description_free (font_desc);
147 /* Pretend that the "page" has a reasonable width and a very big length,
148 so that most tables can be conveniently viewed on-screen with vertical
149 scrolling only. (The length should not be increased very much because
150 it is already close enough to INT_MAX when expressed as thousands of a
152 string_map_insert_nocopy (options, xstrdup ("paper-size"),
153 xasprintf ("%dx1000000pt", view->render_width));
154 string_map_insert (options, "left-margin", "0");
155 string_map_insert (options, "right-margin", "0");
156 string_map_insert (options, "top-margin", "0");
157 string_map_insert (options, "bottom-margin", "0");
161 create_xr (struct psppire_output_view *view)
163 get_xr_options (view, &view->render_opts);
165 struct string_map options;
166 string_map_clone (&options, &view->render_opts);
167 cairo_t *cr = gdk_cairo_create (
168 gtk_widget_get_window (GTK_WIDGET (view->output)));
169 view->xr = xr_driver_create (cr, &options);
170 string_map_destroy (&options);
172 struct text_item *text_item = text_item_create (TEXT_ITEM_LOG, "X");
173 struct xr_rendering *r = xr_rendering_create (
174 view->xr, text_item_super (text_item), cr);
175 xr_rendering_measure (r, NULL, &view->font_height);
176 text_item_unref (text_item);
181 /* Return the horizontal position to place a widget whose
182 width is CHILD_WIDTH */
184 get_xpos (const struct psppire_output_view *view, gint child_width)
186 GdkWindow *gdkw = gtk_widget_get_window (GTK_WIDGET (view->output));
187 guint w = gdk_window_get_width (gdkw);
189 g_object_get (view->output, "border-width", &gutter, NULL);
190 return (gtk_widget_get_direction (GTK_WIDGET (view->output)) == GTK_TEXT_DIR_RTL) ? w - child_width - gutter: gutter;
194 create_drawing_area (struct psppire_output_view *view,
195 GtkWidget *drawing_area, struct xr_rendering *r,
198 /* Enable this to help with debugging. It shows you which widgets are being
202 GdkRGBA green = {0, 1, 0, 1};
203 gtk_widget_override_background_color (GTK_WIDGET (view->output),
204 GTK_STATE_FLAG_NORMAL, &green);
205 GdkRGBA red = {1, 0, 0, 1};
206 gtk_widget_override_background_color (drawing_area,
207 GTK_STATE_FLAG_NORMAL, &red);
210 g_object_set_data_full (G_OBJECT (drawing_area),
211 "rendering", r, free_rendering);
213 g_signal_connect (drawing_area, "draw",
214 G_CALLBACK (draw_callback), view);
216 gtk_widget_set_size_request (drawing_area, tw, th);
217 gint xpos = get_xpos (view, tw);
219 gtk_layout_put (view->output, drawing_area, xpos, view->y);
221 gtk_widget_show (drawing_area);
225 rerender (struct psppire_output_view *view)
227 struct output_view_item *item;
228 GdkWindow *gdkw = gtk_widget_get_window (GTK_WIDGET (view->output));
231 if (!view->n_items || ! gdkw)
234 cr = gdk_cairo_create (gdkw);
235 if (view->xr == NULL)
239 for (item = view->items; item < &view->items[view->n_items]; item++)
241 struct xr_rendering *r;
246 view->y += view->font_height / 2;
248 r = xr_rendering_create (view->xr, item->item, cr);
251 g_warn_if_reached ();
255 xr_rendering_measure (r, &tw, &th);
257 gint xpos = get_xpos (view, tw);
259 if (!item->drawing_area)
261 item->drawing_area = gtk_drawing_area_new ();
262 create_drawing_area (view, item->drawing_area, r, tw, th);
266 g_object_set_data_full (G_OBJECT (item->drawing_area),
267 "rendering", r, free_rendering);
268 gtk_widget_set_size_request (item->drawing_area, tw, th);
269 gtk_layout_move (view->output, item->drawing_area, xpos, view->y);
275 /* This code probably doesn't bring us anthing, but Gtk
276 shows warnings if get_preferred_width/height is not
277 called before the size_allocate below is called. */
278 gtk_widget_get_preferred_width (item->drawing_area, &minw, NULL);
279 gtk_widget_get_preferred_height (item->drawing_area, &minh, NULL);
280 if (th > minh) th = minh;
281 if (tw > minw) tw = minw;
288 gtk_widget_size_allocate (item->drawing_area, &alloc);
290 if (view->max_width < tw)
291 view->max_width = tw;
295 gtk_layout_set_size (view->output,
296 view->max_width + view->font_height,
297 view->y + view->font_height);
302 psppire_output_view_put (struct psppire_output_view *view,
303 const struct output_item *item)
305 struct output_view_item *view_item;
306 GtkWidget *drawing_area;
307 struct xr_rendering *r;
315 if (is_group_close_item (item))
317 if (output_get_group_level () == 0)
319 view->in_command = false;
323 else if (is_text_item (item))
325 const struct text_item *text_item = to_text_item (item);
326 const char *text = text_item_get_text (text_item);
331 if (view->n_items >= view->allocated_items)
332 view->items = x2nrealloc (view->items, &view->allocated_items,
333 sizeof *view->items);
334 view_item = &view->items[view->n_items++];
335 view_item->item = output_item_ref (item);
336 view_item->drawing_area = NULL;
338 if (gtk_widget_get_window (GTK_WIDGET (view->output)))
340 view_item->drawing_area = drawing_area = gtk_drawing_area_new ();
342 cr = gdk_cairo_create (gtk_widget_get_window (GTK_WIDGET (view->output)));
343 if (view->xr == NULL)
347 view->y += view->font_height / 2;
349 r = xr_rendering_create (view->xr, item, cr);
353 xr_rendering_measure (r, &tw, &th);
355 create_drawing_area (view, drawing_area, r, tw, th);
361 && (!is_text_item (item)
362 || text_item_get_type (to_text_item (item)) != TEXT_ITEM_SYNTAX
363 || !view->in_command))
365 store = GTK_TREE_STORE (gtk_tree_view_get_model (view->overview));
367 ds_init_empty (&name);
368 if (is_group_open_item (item) && output_get_group_level () == 1)
370 gtk_tree_store_append (store, &iter, NULL);
371 view->cur_command = iter; /* XXX shouldn't save a GtkTreeIter */
372 view->in_command = true;
376 GtkTreeIter *p = view->in_command ? &view->cur_command : NULL;
377 gtk_tree_store_append (store, &iter, p);
381 if (is_text_item (item))
382 ds_put_cstr (&name, text_item_get_text (to_text_item (item)));
383 else if (is_message_item (item))
385 const struct message_item *msg_item = to_message_item (item);
386 const struct msg *msg = message_item_get_msg (msg_item);
387 ds_put_format (&name, "%s: %s", _("Message"),
388 msg_severity_to_string (msg->severity));
390 else if (is_table_item (item))
392 const struct table_item_text *title
393 = table_item_get_title (to_table_item (item));
395 ds_put_format (&name, "Table: %s", title->content);
397 ds_put_cstr (&name, "Table");
399 else if (is_chart_item (item))
401 const char *s = chart_item_get_title (to_chart_item (item));
403 ds_put_format (&name, "Chart: %s", s);
405 ds_put_cstr (&name, "Chart");
407 else if (is_group_open_item (item))
408 ds_put_cstr (&name, to_group_open_item (item)->command_name);
409 gtk_tree_store_set (store, &iter,
410 COL_NAME, ds_cstr (&name),
416 path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter);
417 gtk_tree_view_expand_row (view->overview, path, TRUE);
418 gtk_tree_path_free (path);
421 if (view->max_width < tw)
422 view->max_width = tw;
425 gtk_layout_set_size (view->output, view->max_width, view->y);
432 on_row_activate (GtkTreeView *overview,
434 GtkTreeViewColumn *column,
435 struct psppire_output_view *view)
443 model = gtk_tree_view_get_model (overview);
444 if (!gtk_tree_model_get_iter (model, &iter, path))
447 gtk_tree_model_get_value (model, &iter, COL_Y, &value);
448 y = g_value_get_long (&value);
449 g_value_unset (&value);
451 vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (view->output));
452 min = gtk_adjustment_get_lower (vadj);
453 max = gtk_adjustment_get_upper (vadj) - gtk_adjustment_get_page_size (vadj);
458 gtk_adjustment_set_value (vadj, y);
462 on_style_updated (GtkWidget *toplevel, struct psppire_output_view *view)
464 if (!view->n_items || !gtk_widget_get_window (GTK_WIDGET (view->output)))
467 /* GTK+ fires this signal for trivial changes like the mouse moving in or out
468 of the window. Check whether the actual rendering options changed and
469 re-render only if they did. */
470 struct string_map options = STRING_MAP_INITIALIZER (options);
471 get_xr_options (view, &options);
472 if (!string_map_equals (&options, &view->render_opts))
474 xr_driver_destroy (view->xr);
479 string_map_destroy (&options);
490 /* GNU Hurd doesn't have PATH_MAX. Use a fallback.
491 Temporary directory names are usually not that long. */
493 # define PATH_MAX 1024
497 clipboard_get_cb (GtkClipboard *clipboard,
498 GtkSelectionData *selection_data,
502 struct psppire_output_view *view = data;
506 struct output_driver *driver = NULL;
507 char dirname[PATH_MAX], *filename;
508 struct string_map options;
510 GtkTreeSelection *sel = gtk_tree_view_get_selection (view->overview);
511 GtkTreeModel *model = gtk_tree_view_get_model (view->overview);
513 GList *rows = gtk_tree_selection_get_selected_rows (sel, &model);
519 if (path_search (dirname, sizeof dirname, NULL, NULL, true)
520 || mkdtemp (dirname) == NULL)
522 msg_error (errno, _("failed to create temporary directory during clipboard operation"));
525 filename = xasprintf ("%s/clip.tmp", dirname);
527 string_map_init (&options);
528 string_map_insert (&options, "output-file", filename);
532 case SELECT_FMT_UTF8:
533 string_map_insert (&options, "box", "unicode");
536 case SELECT_FMT_TEXT:
537 string_map_insert (&options, "format", "txt");
540 case SELECT_FMT_HTML:
541 string_map_insert (&options, "format", "html");
542 string_map_insert (&options, "borders", "false");
543 string_map_insert (&options, "css", "false");
547 string_map_insert (&options, "format", "odt");
551 g_warning ("unsupported clip target\n");
556 driver = output_driver_create (&options);
562 GtkTreePath *path = n->data ;
564 struct output_item *item ;
566 gtk_tree_model_get_iter (model, &iter, path);
567 gtk_tree_model_get (model, &iter, COL_ADDR, &item, -1);
569 driver->class->submit (driver, item);
574 if ( driver->class->flush)
575 driver->class->flush (driver);
578 /* Some drivers (eg: the odt one) don't write anything until they
580 output_driver_destroy (driver);
583 if ( g_file_get_contents (filename, &text, &length, NULL) )
585 gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data),
587 (const guchar *) text, length);
593 output_driver_destroy (driver);
605 clipboard_clear_cb (GtkClipboard *clipboard,
610 static const GtkTargetEntry targets[] = {
612 { "STRING", 0, SELECT_FMT_TEXT },
613 { "TEXT", 0, SELECT_FMT_TEXT },
614 { "COMPOUND_TEXT", 0, SELECT_FMT_TEXT },
615 { "text/plain", 0, SELECT_FMT_TEXT },
617 { "UTF8_STRING", 0, SELECT_FMT_UTF8 },
618 { "text/plain;charset=utf-8", 0, SELECT_FMT_UTF8 },
620 { "text/html", 0, SELECT_FMT_HTML },
622 { "application/vnd.oasis.opendocument.text", 0, SELECT_FMT_ODT }
626 on_copy (struct psppire_output_view *view)
628 GtkWidget *widget = GTK_WIDGET (view->overview);
629 GtkClipboard *cb = gtk_widget_get_clipboard (widget, GDK_SELECTION_CLIPBOARD);
631 if (!gtk_clipboard_set_with_data (cb, targets, G_N_ELEMENTS (targets),
632 clipboard_get_cb, clipboard_clear_cb,
634 clipboard_clear_cb (cb, view);
638 on_selection_change (GtkTreeSelection *sel, GAction *copy_action)
640 /* The Copy action is available only if there is something selected */
641 g_object_set (copy_action,
642 "enabled", gtk_tree_selection_count_selected_rows (sel) > 0,
647 on_select_all (struct psppire_output_view *view)
649 GtkTreeSelection *sel = gtk_tree_view_get_selection (view->overview);
650 gtk_tree_view_expand_all (view->overview);
651 gtk_tree_selection_select_all (sel);
655 on_size_allocate (GtkWidget *widget,
656 GdkRectangle *allocation,
657 struct psppire_output_view *view)
659 view->render_width = MAX (300, allocation->width);
664 on_realize (GtkWidget *overview, GObject *view)
666 GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (overview));
667 gtk_tree_selection_set_mode (sel, GTK_SELECTION_MULTIPLE);
669 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (overview));
671 GAction *copy_action = g_action_map_lookup_action (G_ACTION_MAP (toplevel),
674 GAction *select_all_action = g_action_map_lookup_action (G_ACTION_MAP (toplevel),
677 g_object_set (copy_action, "enabled", FALSE, NULL);
679 g_signal_connect_swapped (select_all_action, "activate",
680 G_CALLBACK (on_select_all), view);
682 g_signal_connect_swapped (copy_action, "activate",
683 G_CALLBACK (on_copy), view);
685 g_signal_connect (sel, "changed", G_CALLBACK (on_selection_change),
689 struct psppire_output_view *
690 psppire_output_view_new (GtkLayout *output, GtkTreeView *overview)
692 struct psppire_output_view *view;
693 GtkTreeViewColumn *column;
694 GtkCellRenderer *renderer;
698 view = xmalloc (sizeof *view);
700 view->font_height = 0;
701 view->output = output;
702 view->render_width = 0;
705 string_map_init (&view->render_opts);
706 view->overview = overview;
707 memset (&view->cur_command, 0, sizeof view->cur_command);
708 view->in_command = false;
709 view->toplevel = gtk_widget_get_toplevel (GTK_WIDGET (output));
711 view->n_items = view->allocated_items = 0;
712 view->print_settings = NULL;
713 view->print_xrd = NULL;
714 view->print_item = 0;
715 view->print_n_pages = 0;
716 view->paginated = FALSE;
718 g_signal_connect (output, "draw", G_CALLBACK (layout_draw_callback), NULL);
720 g_signal_connect (output, "style-updated", G_CALLBACK (on_style_updated), view);
722 g_signal_connect (output, "size-allocate", G_CALLBACK (on_size_allocate), view);
724 gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (output)),
725 GTK_STYLE_CLASS_VIEW);
729 g_signal_connect (overview, "realize", G_CALLBACK (on_realize), view);
731 model = GTK_TREE_MODEL (gtk_tree_store_new (
733 G_TYPE_STRING, /* COL_NAME */
734 G_TYPE_POINTER, /* COL_ADDR */
735 G_TYPE_LONG)); /* COL_Y */
736 gtk_tree_view_set_model (overview, model);
737 g_object_unref (model);
739 column = gtk_tree_view_column_new ();
740 gtk_tree_view_append_column (GTK_TREE_VIEW (overview), column);
741 renderer = gtk_cell_renderer_text_new ();
742 gtk_tree_view_column_pack_start (column, renderer, TRUE);
743 gtk_tree_view_column_add_attribute (column, renderer, "text", COL_NAME);
745 g_signal_connect (GTK_TREE_VIEW (overview),
746 "row-activated", G_CALLBACK (on_row_activate), view);
753 psppire_output_view_destroy (struct psppire_output_view *view)
760 g_signal_handlers_disconnect_by_func (view->output,
761 G_CALLBACK (on_style_updated), view);
763 string_map_destroy (&view->render_opts);
765 for (i = 0; i < view->n_items; i++)
766 output_item_unref (view->items[i].item);
769 view->n_items = view->allocated_items = 0;
771 if (view->print_settings != NULL)
772 g_object_unref (view->print_settings);
774 xr_driver_destroy (view->xr);
780 psppire_output_view_clear (struct psppire_output_view *view)
787 for (i = 0; i < view->n_items; i++)
789 gtk_container_remove (GTK_CONTAINER (view->output),
790 view->items[i].drawing_area);
791 output_item_unref (view->items[i].item);
795 view->n_items = view->allocated_items = 0;
801 psppire_output_view_export (struct psppire_output_view *view,
802 struct string_map *options)
804 struct output_driver *driver;
806 driver = output_driver_create (options);
811 for (i = 0; i < view->n_items; i++)
812 driver->class->submit (driver, view->items[i].item);
813 output_driver_destroy (driver);
820 get_cairo_context_from_print_context (GtkPrintContext *context)
822 cairo_t *cr = gtk_print_context_get_cairo_context (context);
825 For all platforms except windows, gtk_print_context_get_dpi_[xy] returns 72.
828 double xres = gtk_print_context_get_dpi_x (context);
829 double yres = gtk_print_context_get_dpi_y (context);
831 /* This means that the cairo context now has its dimensions in Points */
832 cairo_scale (cr, xres / 72.0, yres / 72.0);
839 create_xr_print_driver (GtkPrintContext *context, struct psppire_output_view *view)
841 struct string_map options;
842 GtkPageSetup *page_setup;
843 double width, height;
847 double bottom_margin;
849 page_setup = gtk_print_context_get_page_setup (context);
850 width = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_MM);
851 height = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_MM);
852 left_margin = gtk_page_setup_get_left_margin (page_setup, GTK_UNIT_MM);
853 right_margin = gtk_page_setup_get_right_margin (page_setup, GTK_UNIT_MM);
854 top_margin = gtk_page_setup_get_top_margin (page_setup, GTK_UNIT_MM);
855 bottom_margin = gtk_page_setup_get_bottom_margin (page_setup, GTK_UNIT_MM);
857 string_map_init (&options);
858 string_map_insert_nocopy (&options, xstrdup ("paper-size"),
859 c_xasprintf("%.2fx%.2fmm", width, height));
860 string_map_insert_nocopy (&options, xstrdup ("left-margin"),
861 c_xasprintf ("%.2fmm", left_margin));
862 string_map_insert_nocopy (&options, xstrdup ("right-margin"),
863 c_xasprintf ("%.2fmm", right_margin));
864 string_map_insert_nocopy (&options, xstrdup ("top-margin"),
865 c_xasprintf ("%.2fmm", top_margin));
866 string_map_insert_nocopy (&options, xstrdup ("bottom-margin"),
867 c_xasprintf ("%.2fmm", bottom_margin));
869 view->print_xrd = xr_driver_create (get_cairo_context_from_print_context (context), &options);
871 string_map_destroy (&options);
875 paginate (GtkPrintOperation *operation,
876 GtkPrintContext *context,
877 struct psppire_output_view *view)
881 /* Sometimes GTK+ emits this signal again even after pagination is
882 complete. Don't let that screw up printing. */
885 else if ( view->print_item < view->n_items )
887 xr_driver_output_item (view->print_xrd,
888 view->items[view->print_item++].item);
889 while (xr_driver_need_new_page (view->print_xrd))
891 xr_driver_next_page (view->print_xrd, get_cairo_context_from_print_context (context));
892 view->print_n_pages ++;
898 gtk_print_operation_set_n_pages (operation, view->print_n_pages);
900 /* Re-create the driver to do the real printing. */
901 xr_driver_destroy (view->print_xrd);
902 create_xr_print_driver (context, view);
903 view->print_item = 0;
904 view->paginated = TRUE;
911 begin_print (GtkPrintOperation *operation,
912 GtkPrintContext *context,
913 struct psppire_output_view *view)
915 create_xr_print_driver (context, view);
917 view->print_item = 0;
918 view->print_n_pages = 1;
919 view->paginated = FALSE;
923 end_print (GtkPrintOperation *operation,
924 GtkPrintContext *context,
925 struct psppire_output_view *view)
927 xr_driver_destroy (view->print_xrd);
932 draw_page (GtkPrintOperation *operation,
933 GtkPrintContext *context,
935 struct psppire_output_view *view)
937 xr_driver_next_page (view->print_xrd, get_cairo_context_from_print_context (context));
938 while (!xr_driver_need_new_page (view->print_xrd)
939 && view->print_item < view->n_items)
940 xr_driver_output_item (view->print_xrd, view->items [view->print_item++].item);
945 psppire_output_view_print (struct psppire_output_view *view,
946 GtkWindow *parent_window)
948 GtkPrintOperationResult res;
950 GtkPrintOperation *print = gtk_print_operation_new ();
952 if (view->print_settings != NULL)
953 gtk_print_operation_set_print_settings (print, view->print_settings);
955 g_signal_connect (print, "begin_print", G_CALLBACK (begin_print), view);
956 g_signal_connect (print, "end_print", G_CALLBACK (end_print), view);
957 g_signal_connect (print, "paginate", G_CALLBACK (paginate), view);
958 g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), view);
960 res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
961 parent_window, NULL);
963 if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
965 if (view->print_settings != NULL)
966 g_object_unref (view->print_settings);
967 view->print_settings = g_object_ref (gtk_print_operation_get_print_settings (print));
970 g_object_unref (print);
973 struct psppire_output_view_driver
975 struct output_driver driver;
976 struct psppire_output_view *view;
979 static struct psppire_output_view_driver *
980 psppire_output_view_driver_cast (struct output_driver *driver)
982 return UP_CAST (driver, struct psppire_output_view_driver, driver);
986 psppire_output_view_submit (struct output_driver *this,
987 const struct output_item *item)
989 struct psppire_output_view_driver *povd = psppire_output_view_driver_cast (this);
991 if (is_table_item (item))
992 psppire_output_view_put (povd->view, item);
995 static struct output_driver_class psppire_output_view_driver_class =
997 "PSPPIRE Output View", /* name */
999 psppire_output_view_submit, /* submit */
1004 psppire_output_view_register_driver (struct psppire_output_view *view)
1006 struct psppire_output_view_driver *povd;
1007 struct output_driver *d;
1009 povd = xzalloc (sizeof *povd);
1012 output_driver_init (d, &psppire_output_view_driver_class, "PSPPIRE Output View",
1013 SETTINGS_DEVICE_UNFILTERED);
1014 output_driver_register (d);