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/message-item.h"
31 #include "output/output-item.h"
32 #include "output/table-item.h"
33 #include "output/text-item.h"
35 #include "gl/c-xvasprintf.h"
36 #include "gl/minmax.h"
37 #include "gl/tmpdir.h"
38 #include "gl/xalloc.h"
41 #define _(msgid) gettext (msgid)
43 struct output_view_item
45 struct output_item *item;
46 GtkWidget *drawing_area;
49 struct psppire_output_view
59 struct string_map render_opts;
60 GtkTreeView *overview;
61 GtkTreeIter cur_command;
66 struct output_view_item *items;
67 size_t n_items, allocated_items;
69 /* Variables pertaining to printing */
70 GtkPrintSettings *print_settings;
71 struct xr_driver *print_xrd;
79 COL_NAME, /* Table name. */
80 COL_ADDR, /* Pointer to the table */
81 COL_Y, /* Y position of top of name. */
86 draw_callback (GtkWidget *widget, cairo_t *cr, gpointer data)
88 struct xr_rendering *r = g_object_get_data (G_OBJECT (widget), "rendering");
89 xr_rendering_draw_all (r, cr);
94 free_rendering (gpointer rendering_)
96 struct xr_rendering *rendering = rendering_;
97 xr_rendering_destroy (rendering);
101 create_xr (struct psppire_output_view *view)
103 struct text_item *text_item;
104 PangoFontDescription *font_desc;
105 struct xr_rendering *r;
111 GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (view->output));
112 GtkStateFlags state = gtk_widget_get_state_flags (GTK_WIDGET (view->output));
115 gtk_style_context_get (context, state,
116 "font", &font_desc, "color", &fg_color, NULL);
118 cr = gdk_cairo_create (gtk_widget_get_window (GTK_WIDGET (view->output)));
120 /* Set the widget's text color as the foreground color for the output driver */
121 /* gdk_rgba_to_string() would be perfect, but xr's parse_color does not */
122 /* understand the rgb(255,128,33) format. Therefore we do it ourself. */
123 fgc = xasprintf("#%4x%4x%4x",(int)(fg_color->red*0xffff),
124 (int)(fg_color->green*0xffff),(int)(fg_color->blue*0xffff));
125 string_map_insert (&view->render_opts, "foreground-color", fgc);
127 gdk_rgba_free (fg_color);
129 /* Use GTK+ default font as proportional font. */
130 font_name = pango_font_description_to_string (font_desc);
131 string_map_insert (&view->render_opts, "prop-font", font_name);
134 /* Derived emphasized font from proportional font. */
135 pango_font_description_set_style (font_desc, PANGO_STYLE_ITALIC);
136 font_name = pango_font_description_to_string (font_desc);
137 string_map_insert (&view->render_opts, "emph-font", font_name);
139 pango_font_description_free (font_desc);
141 /* Pretend that the "page" has a reasonable width and a very big length,
142 so that most tables can be conveniently viewed on-screen with vertical
143 scrolling only. (The length should not be increased very much because
144 it is already close enough to INT_MAX when expressed as thousands of a
146 string_map_insert_nocopy (&view->render_opts, xstrdup ("paper-size"),
147 xasprintf ("%dx1000000pt", view->render_width));
148 string_map_insert (&view->render_opts, "left-margin", "0");
149 string_map_insert (&view->render_opts, "right-margin", "0");
150 string_map_insert (&view->render_opts, "top-margin", "0");
151 string_map_insert (&view->render_opts, "bottom-margin", "0");
153 view->xr = xr_driver_create (cr, &view->render_opts);
155 text_item = text_item_create (TEXT_ITEM_PARAGRAPH, "X");
156 r = xr_rendering_create (view->xr, text_item_super (text_item), cr);
157 xr_rendering_measure (r, &font_width, &view->font_height);
158 text_item_unref (text_item);
163 /* Return the horizontal position to place a widget whose
164 width is CHILD_WIDTH */
166 get_xpos (const struct psppire_output_view *view, gint child_width)
168 GdkWindow *gdkw = gtk_widget_get_window (GTK_WIDGET (view->output));
169 guint w = gdk_window_get_width (gdkw);
171 g_object_get (view->output, "border-width", &gutter, NULL);
172 return (gtk_widget_get_direction (GTK_WIDGET (view->output)) == GTK_TEXT_DIR_RTL) ? w - child_width - gutter: gutter;
176 create_drawing_area (struct psppire_output_view *view,
177 GtkWidget *drawing_area, struct xr_rendering *r,
180 /* Enable this to help with debugging. It shows you which widgets are being
184 GdkRGBA green = {0, 1, 0, 1};
185 gtk_widget_override_background_color (GTK_WIDGET (view->output),
186 GTK_STATE_NORMAL, &green);
187 GdkRGBA red = {1, 0, 0, 1};
188 gtk_widget_override_background_color (drawing_area, GTK_STATE_NORMAL, &red);
191 g_object_set_data_full (G_OBJECT (drawing_area),
192 "rendering", r, free_rendering);
194 g_signal_connect (drawing_area, "draw",
195 G_CALLBACK (draw_callback), view);
197 gtk_widget_set_size_request (drawing_area, tw, th);
198 gint xpos = get_xpos (view, tw);
200 gtk_layout_put (view->output, drawing_area, xpos, view->y);
202 gtk_widget_show (drawing_area);
206 rerender (struct psppire_output_view *view)
208 struct output_view_item *item;
209 GdkWindow *gdkw = gtk_widget_get_window (GTK_WIDGET (view->output));
212 if (!view->n_items || ! gdkw)
215 cr = gdk_cairo_create (gdkw);
216 if (view->xr == NULL)
220 for (item = view->items; item < &view->items[view->n_items]; item++)
222 struct xr_rendering *r;
227 view->y += view->font_height / 2;
229 r = xr_rendering_create (view->xr, item->item, cr);
232 g_warn_if_reached ();
236 xr_rendering_measure (r, &tw, &th);
238 gint xpos = get_xpos (view, tw);
240 if (!item->drawing_area)
242 item->drawing_area = gtk_drawing_area_new ();
243 create_drawing_area (view, item->drawing_area, r, tw, th);
247 g_object_set_data_full (G_OBJECT (item->drawing_area),
248 "rendering", r, free_rendering);
249 gtk_widget_set_size_request (item->drawing_area, tw, th);
250 gtk_layout_move (view->output, item->drawing_area, xpos, view->y);
256 /* This code probably doesn't bring us anthing, but Gtk
257 shows warnings if get_preferred_width/height is not
258 called before the size_allocate below is called. */
259 gtk_widget_get_preferred_width (item->drawing_area, &minw, NULL);
260 gtk_widget_get_preferred_height (item->drawing_area, &minh, NULL);
261 if (th > minh) th = minh;
262 if (tw > minw) tw = minw;
269 gtk_widget_size_allocate (item->drawing_area, &alloc);
271 if (view->max_width < tw)
272 view->max_width = tw;
276 gtk_layout_set_size (view->output, view->max_width, view->y);
281 psppire_output_view_put (struct psppire_output_view *view,
282 const struct output_item *item)
284 struct output_view_item *view_item;
285 GtkWidget *drawing_area;
286 struct xr_rendering *r;
294 if (is_text_item (item))
296 const struct text_item *text_item = to_text_item (item);
297 enum text_item_type type = text_item_get_type (text_item);
298 const char *text = text_item_get_text (text_item);
300 if (type == TEXT_ITEM_COMMAND_CLOSE)
302 view->in_command = false;
305 else if (text[0] == '\0')
309 if (view->n_items >= view->allocated_items)
310 view->items = x2nrealloc (view->items, &view->allocated_items,
311 sizeof *view->items);
312 view_item = &view->items[view->n_items++];
313 view_item->item = output_item_ref (item);
314 view_item->drawing_area = NULL;
316 if (gtk_widget_get_window (GTK_WIDGET (view->output)))
318 view_item->drawing_area = drawing_area = gtk_drawing_area_new ();
320 cr = gdk_cairo_create (gtk_widget_get_window (GTK_WIDGET (view->output)));
321 if (view->xr == NULL)
325 view->y += view->font_height / 2;
327 r = xr_rendering_create (view->xr, item, cr);
331 xr_rendering_measure (r, &tw, &th);
333 create_drawing_area (view, drawing_area, r, tw, th);
339 && (!is_text_item (item)
340 || text_item_get_type (to_text_item (item)) != TEXT_ITEM_SYNTAX
341 || !view->in_command))
343 store = GTK_TREE_STORE (gtk_tree_view_get_model (view->overview));
345 ds_init_empty (&name);
346 if (is_text_item (item)
347 && text_item_get_type (to_text_item (item)) == TEXT_ITEM_COMMAND_OPEN)
349 gtk_tree_store_append (store, &iter, NULL);
350 view->cur_command = iter; /* XXX shouldn't save a GtkTreeIter */
351 view->in_command = true;
355 GtkTreeIter *p = view->in_command ? &view->cur_command : NULL;
356 gtk_tree_store_append (store, &iter, p);
360 if (is_text_item (item))
361 ds_put_cstr (&name, text_item_get_text (to_text_item (item)));
362 else if (is_message_item (item))
364 const struct message_item *msg_item = to_message_item (item);
365 const struct msg *msg = message_item_get_msg (msg_item);
366 ds_put_format (&name, "%s: %s", _("Message"),
367 msg_severity_to_string (msg->severity));
369 else if (is_table_item (item))
371 const char *title = table_item_get_title (to_table_item (item));
373 ds_put_format (&name, "Table: %s", title);
375 ds_put_cstr (&name, "Table");
377 else if (is_chart_item (item))
379 const char *s = chart_item_get_title (to_chart_item (item));
381 ds_put_format (&name, "Chart: %s", s);
383 ds_put_cstr (&name, "Chart");
385 gtk_tree_store_set (store, &iter,
386 COL_NAME, ds_cstr (&name),
392 path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter);
393 gtk_tree_view_expand_row (view->overview, path, TRUE);
394 gtk_tree_path_free (path);
397 if (view->max_width < tw)
398 view->max_width = tw;
401 gtk_layout_set_size (view->output, view->max_width, view->y);
408 on_row_activate (GtkTreeView *overview,
410 GtkTreeViewColumn *column,
411 struct psppire_output_view *view)
419 model = gtk_tree_view_get_model (overview);
420 if (!gtk_tree_model_get_iter (model, &iter, path))
423 gtk_tree_model_get_value (model, &iter, COL_Y, &value);
424 y = g_value_get_long (&value);
425 g_value_unset (&value);
427 vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (view->output));
428 min = gtk_adjustment_get_lower (vadj);
429 max = gtk_adjustment_get_upper (vadj) - gtk_adjustment_get_page_size (vadj);
434 gtk_adjustment_set_value (vadj, y);
438 on_style_updated (GtkWidget *toplevel, struct psppire_output_view *view)
440 if (!view->n_items || !gtk_widget_get_window (GTK_WIDGET (view->output)))
442 string_map_clear (&view->render_opts);
443 xr_driver_destroy (view->xr);
456 /* GNU Hurd doesn't have PATH_MAX. Use a fallback.
457 Temporary directory names are usually not that long. */
459 # define PATH_MAX 1024
463 clipboard_get_cb (GtkClipboard *clipboard,
464 GtkSelectionData *selection_data,
468 struct psppire_output_view *view = data;
472 struct output_driver *driver = NULL;
473 char dirname[PATH_MAX], *filename;
474 struct string_map options;
476 GtkTreeSelection *sel = gtk_tree_view_get_selection (view->overview);
477 GtkTreeModel *model = gtk_tree_view_get_model (view->overview);
479 GList *rows = gtk_tree_selection_get_selected_rows (sel, &model);
485 if (path_search (dirname, sizeof dirname, NULL, NULL, true)
486 || mkdtemp (dirname) == NULL)
488 msg_error (errno, _("failed to create temporary directory during clipboard operation"));
491 filename = xasprintf ("%s/clip.tmp", dirname);
493 string_map_init (&options);
494 string_map_insert (&options, "output-file", filename);
498 case SELECT_FMT_UTF8:
499 string_map_insert (&options, "box", "unicode");
502 case SELECT_FMT_TEXT:
503 string_map_insert (&options, "format", "txt");
506 case SELECT_FMT_HTML:
507 string_map_insert (&options, "format", "html");
508 string_map_insert (&options, "borders", "false");
509 string_map_insert (&options, "css", "false");
513 string_map_insert (&options, "format", "odt");
517 g_warning ("unsupported clip target\n");
522 driver = output_driver_create (&options);
528 GtkTreePath *path = n->data ;
530 struct output_item *item ;
532 gtk_tree_model_get_iter (model, &iter, path);
533 gtk_tree_model_get (model, &iter, COL_ADDR, &item, -1);
535 driver->class->submit (driver, item);
540 if ( driver->class->flush)
541 driver->class->flush (driver);
544 /* Some drivers (eg: the odt one) don't write anything until they
546 output_driver_destroy (driver);
549 if ( g_file_get_contents (filename, &text, &length, NULL) )
551 gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data),
553 (const guchar *) text, length);
559 output_driver_destroy (driver);
571 clipboard_clear_cb (GtkClipboard *clipboard,
576 static const GtkTargetEntry targets[] = {
578 { "STRING", 0, SELECT_FMT_TEXT },
579 { "TEXT", 0, SELECT_FMT_TEXT },
580 { "COMPOUND_TEXT", 0, SELECT_FMT_TEXT },
581 { "text/plain", 0, SELECT_FMT_TEXT },
583 { "UTF8_STRING", 0, SELECT_FMT_UTF8 },
584 { "text/plain;charset=utf-8", 0, SELECT_FMT_UTF8 },
586 { "text/html", 0, SELECT_FMT_HTML },
588 { "application/vnd.oasis.opendocument.text", 0, SELECT_FMT_ODT }
592 on_copy (struct psppire_output_view *view)
594 GtkWidget *widget = GTK_WIDGET (view->overview);
595 GtkClipboard *cb = gtk_widget_get_clipboard (widget, GDK_SELECTION_CLIPBOARD);
597 if (!gtk_clipboard_set_with_data (cb, targets, G_N_ELEMENTS (targets),
598 clipboard_get_cb, clipboard_clear_cb,
600 clipboard_clear_cb (cb, view);
604 on_selection_change (GtkTreeSelection *sel, GAction *copy_action)
606 /* The Copy action is available only if there is something selected */
607 g_object_set (copy_action,
608 "enabled", gtk_tree_selection_count_selected_rows (sel) > 0,
613 on_select_all (struct psppire_output_view *view)
615 GtkTreeSelection *sel = gtk_tree_view_get_selection (view->overview);
616 gtk_tree_view_expand_all (view->overview);
617 gtk_tree_selection_select_all (sel);
621 on_size_allocate (GtkWidget *widget,
622 GdkRectangle *allocation,
623 struct psppire_output_view *view)
625 int new_render_width = MAX (300, allocation->width);
627 if (view->render_width != new_render_width)
629 view->render_width = new_render_width;
635 on_realize (GtkWidget *overview, GObject *view)
637 GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (overview));
638 gtk_tree_selection_set_mode (sel, GTK_SELECTION_MULTIPLE);
640 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (overview));
642 GAction *copy_action = g_action_map_lookup_action (G_ACTION_MAP (toplevel),
645 GAction *select_all_action = g_action_map_lookup_action (G_ACTION_MAP (toplevel),
648 g_object_set (copy_action, "enabled", FALSE, NULL);
650 g_signal_connect_swapped (select_all_action, "activate",
651 G_CALLBACK (on_select_all), view);
653 g_signal_connect_swapped (copy_action, "activate",
654 G_CALLBACK (on_copy), view);
656 g_signal_connect (sel, "changed", G_CALLBACK (on_selection_change),
660 struct psppire_output_view *
661 psppire_output_view_new (GtkLayout *output, GtkTreeView *overview)
663 struct psppire_output_view *view;
664 GtkTreeViewColumn *column;
665 GtkCellRenderer *renderer;
669 view = xmalloc (sizeof *view);
671 view->font_height = 0;
672 view->output = output;
673 view->render_width = 0;
676 string_map_init (&view->render_opts);
677 view->overview = overview;
678 memset (&view->cur_command, 0, sizeof view->cur_command);
679 view->in_command = false;
680 view->toplevel = gtk_widget_get_toplevel (GTK_WIDGET (output));
682 view->n_items = view->allocated_items = 0;
683 view->print_settings = NULL;
684 view->print_xrd = NULL;
685 view->print_item = 0;
686 view->print_n_pages = 0;
687 view->paginated = FALSE;
689 g_signal_connect (output, "style-updated", G_CALLBACK (on_style_updated), view);
691 g_signal_connect (output, "size-allocate", G_CALLBACK (on_size_allocate), view);
693 gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (output)),
694 GTK_STYLE_CLASS_VIEW);
698 g_signal_connect (overview, "realize", G_CALLBACK (on_realize), view);
700 model = GTK_TREE_MODEL (gtk_tree_store_new (
702 G_TYPE_STRING, /* COL_NAME */
703 G_TYPE_POINTER, /* COL_ADDR */
704 G_TYPE_LONG)); /* COL_Y */
705 gtk_tree_view_set_model (overview, model);
706 g_object_unref (model);
708 column = gtk_tree_view_column_new ();
709 gtk_tree_view_append_column (GTK_TREE_VIEW (overview), column);
710 renderer = gtk_cell_renderer_text_new ();
711 gtk_tree_view_column_pack_start (column, renderer, TRUE);
712 gtk_tree_view_column_add_attribute (column, renderer, "text", COL_NAME);
714 g_signal_connect (GTK_TREE_VIEW (overview),
715 "row-activated", G_CALLBACK (on_row_activate), view);
722 psppire_output_view_destroy (struct psppire_output_view *view)
729 g_signal_handlers_disconnect_by_func (view->output,
730 G_CALLBACK (on_style_updated), view);
732 string_map_destroy (&view->render_opts);
734 for (i = 0; i < view->n_items; i++)
735 output_item_unref (view->items[i].item);
738 view->n_items = view->allocated_items = 0;
740 if (view->print_settings != NULL)
741 g_object_unref (view->print_settings);
743 xr_driver_destroy (view->xr);
749 psppire_output_view_clear (struct psppire_output_view *view)
756 for (i = 0; i < view->n_items; i++)
758 gtk_container_remove (GTK_CONTAINER (view->output),
759 view->items[i].drawing_area);
760 output_item_unref (view->items[i].item);
764 view->n_items = view->allocated_items = 0;
770 psppire_output_view_export (struct psppire_output_view *view,
771 struct string_map *options)
773 struct output_driver *driver;
775 driver = output_driver_create (options);
780 for (i = 0; i < view->n_items; i++)
781 driver->class->submit (driver, view->items[i].item);
782 output_driver_destroy (driver);
789 get_cairo_context_from_print_context (GtkPrintContext *context)
791 cairo_t *cr = gtk_print_context_get_cairo_context (context);
794 For all platforms except windows, gtk_print_context_get_dpi_[xy] returns 72.
797 double xres = gtk_print_context_get_dpi_x (context);
798 double yres = gtk_print_context_get_dpi_y (context);
800 /* This means that the cairo context now has its dimensions in Points */
801 cairo_scale (cr, xres / 72.0, yres / 72.0);
808 create_xr_print_driver (GtkPrintContext *context, struct psppire_output_view *view)
810 struct string_map options;
811 GtkPageSetup *page_setup;
812 double width, height;
816 double bottom_margin;
818 page_setup = gtk_print_context_get_page_setup (context);
819 width = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_MM);
820 height = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_MM);
821 left_margin = gtk_page_setup_get_left_margin (page_setup, GTK_UNIT_MM);
822 right_margin = gtk_page_setup_get_right_margin (page_setup, GTK_UNIT_MM);
823 top_margin = gtk_page_setup_get_top_margin (page_setup, GTK_UNIT_MM);
824 bottom_margin = gtk_page_setup_get_bottom_margin (page_setup, GTK_UNIT_MM);
826 string_map_init (&options);
827 string_map_insert_nocopy (&options, xstrdup ("paper-size"),
828 c_xasprintf("%.2fx%.2fmm", width, height));
829 string_map_insert_nocopy (&options, xstrdup ("left-margin"),
830 c_xasprintf ("%.2fmm", left_margin));
831 string_map_insert_nocopy (&options, xstrdup ("right-margin"),
832 c_xasprintf ("%.2fmm", right_margin));
833 string_map_insert_nocopy (&options, xstrdup ("top-margin"),
834 c_xasprintf ("%.2fmm", top_margin));
835 string_map_insert_nocopy (&options, xstrdup ("bottom-margin"),
836 c_xasprintf ("%.2fmm", bottom_margin));
838 view->print_xrd = xr_driver_create (get_cairo_context_from_print_context (context), &options);
840 string_map_destroy (&options);
844 paginate (GtkPrintOperation *operation,
845 GtkPrintContext *context,
846 struct psppire_output_view *view)
850 /* Sometimes GTK+ emits this signal again even after pagination is
851 complete. Don't let that screw up printing. */
854 else if ( view->print_item < view->n_items )
856 xr_driver_output_item (view->print_xrd,
857 view->items[view->print_item++].item);
858 while (xr_driver_need_new_page (view->print_xrd))
860 xr_driver_next_page (view->print_xrd, get_cairo_context_from_print_context (context));
861 view->print_n_pages ++;
867 gtk_print_operation_set_n_pages (operation, view->print_n_pages);
869 /* Re-create the driver to do the real printing. */
870 xr_driver_destroy (view->print_xrd);
871 create_xr_print_driver (context, view);
872 view->print_item = 0;
873 view->paginated = TRUE;
880 begin_print (GtkPrintOperation *operation,
881 GtkPrintContext *context,
882 struct psppire_output_view *view)
884 create_xr_print_driver (context, view);
886 view->print_item = 0;
887 view->print_n_pages = 1;
888 view->paginated = FALSE;
892 end_print (GtkPrintOperation *operation,
893 GtkPrintContext *context,
894 struct psppire_output_view *view)
896 xr_driver_destroy (view->print_xrd);
901 draw_page (GtkPrintOperation *operation,
902 GtkPrintContext *context,
904 struct psppire_output_view *view)
906 xr_driver_next_page (view->print_xrd, get_cairo_context_from_print_context (context));
907 while (!xr_driver_need_new_page (view->print_xrd)
908 && view->print_item < view->n_items)
909 xr_driver_output_item (view->print_xrd, view->items [view->print_item++].item);
914 psppire_output_view_print (struct psppire_output_view *view,
915 GtkWindow *parent_window)
917 GtkPrintOperationResult res;
919 GtkPrintOperation *print = gtk_print_operation_new ();
921 if (view->print_settings != NULL)
922 gtk_print_operation_set_print_settings (print, view->print_settings);
924 g_signal_connect (print, "begin_print", G_CALLBACK (begin_print), view);
925 g_signal_connect (print, "end_print", G_CALLBACK (end_print), view);
926 g_signal_connect (print, "paginate", G_CALLBACK (paginate), view);
927 g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), view);
929 res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
930 parent_window, NULL);
932 if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
934 if (view->print_settings != NULL)
935 g_object_unref (view->print_settings);
936 view->print_settings = g_object_ref (gtk_print_operation_get_print_settings (print));
939 g_object_unref (print);
942 struct psppire_output_view_driver
944 struct output_driver driver;
945 struct psppire_output_view *view;
948 static struct psppire_output_view_driver *
949 psppire_output_view_driver_cast (struct output_driver *driver)
951 return UP_CAST (driver, struct psppire_output_view_driver, driver);
955 psppire_output_view_submit (struct output_driver *this,
956 const struct output_item *item)
958 struct psppire_output_view_driver *povd = psppire_output_view_driver_cast (this);
960 if (is_table_item (item))
961 psppire_output_view_put (povd->view, item);
964 static struct output_driver_class psppire_output_view_driver_class =
966 "PSPPIRE Output View", /* name */
968 psppire_output_view_submit, /* submit */
973 psppire_output_view_register_driver (struct psppire_output_view *view)
975 struct psppire_output_view_driver *povd;
976 struct output_driver *d;
978 povd = xzalloc (sizeof *povd);
981 output_driver_init (d, &psppire_output_view_driver_class, "PSPPIRE Output View",
982 SETTINGS_DEVICE_UNFILTERED);
983 output_driver_register (d);