output-item: Make label a part of every output_item.
[pspp] / src / ui / gui / psppire-output-view.c
index f48b1ade4f5e8fa88a057d6e3e66a3cf56ec1e15..cc00a05bdaa327f8188f43bdeb826bc311daa00c 100644 (file)
@@ -22,9 +22,6 @@
 #include <errno.h>
 #include <stdbool.h>
 
-#if HAVE_RSVG
-#include "librsvg/rsvg.h"
-#endif
 #include "libpspp/assertion.h"
 #include "libpspp/string-map.h"
 #include "output/cairo-fsm.h"
@@ -87,9 +84,9 @@ struct psppire_output_view
 
 enum
   {
-    COL_NAME,                   /* Table name. */
+    COL_LABEL,                  /* Output item label. */
     COL_ADDR,                   /* Pointer to the table */
-    COL_Y,                      /* Y position of top of name. */
+    COL_Y,                      /* Y position of top of object. */
     N_COLS
   };
 
@@ -167,7 +164,6 @@ get_xr_fsm_style (struct psppire_output_view *view)
       [XR_FONT_FIXED] = ff,
     },
     .use_system_colors = true,
-    .transparent = true,
     .font_resolution = 96.0,
   };
 
@@ -365,6 +361,12 @@ rerender (struct psppire_output_view *view)
           gtk_layout_move (view->output, item->drawing_area, xpos, view->y);
         }
 
+      if (is_table_item (item->item))
+        {
+          const struct table_item *ti = to_table_item (item->item);
+          gtk_widget_set_tooltip_text (item->drawing_area, ti->notes);
+        }
+
       {
        gint minw;
        gint minh;
@@ -403,7 +405,6 @@ psppire_output_view_put (struct psppire_output_view *view,
 {
   struct output_view_item *view_item;
   GtkWidget *drawing_area;
-  struct string name;
   int tw, th;
 
   if (is_group_close_item (item))
@@ -471,8 +472,6 @@ psppire_output_view_put (struct psppire_output_view *view,
       GtkTreeStore *store = GTK_TREE_STORE (
         gtk_tree_view_get_model (view->overview));
 
-      ds_init_empty (&name);
-
       /* Create a new node in the tree and puts a reference to it in 'iter'. */
       GtkTreeIter iter;
       GtkTreeIter parent;
@@ -491,45 +490,11 @@ psppire_output_view_put (struct psppire_output_view *view,
                                                      &iter);
         }
 
-      ds_clear (&name);
-      if (is_text_item (item))
-        {
-          const struct text_item *text_item = to_text_item (item);
-          ds_put_cstr (&name, text_item_type_to_string (
-                         text_item_get_type (text_item)));
-        }
-      else if (is_message_item (item))
-        {
-          const struct message_item *msg_item = to_message_item (item);
-          const struct msg *msg = message_item_get_msg (msg_item);
-          ds_put_format (&name, "%s: %s", _("Message"),
-                         msg_severity_to_string (msg->severity));
-        }
-      else if (is_table_item (item))
-        {
-          const struct table_item_text *title
-            = table_item_get_title (to_table_item (item));
-          if (title != NULL)
-            ds_put_format (&name, "Table: %s", title->content);
-          else
-            ds_put_cstr (&name, "Table");
-        }
-      else if (is_chart_item (item))
-        {
-          const char *s = chart_item_get_title (to_chart_item (item));
-          if (s != NULL)
-            ds_put_format (&name, "Chart: %s", s);
-          else
-            ds_put_cstr (&name, "Chart");
-        }
-      else if (is_group_open_item (item))
-        ds_put_cstr (&name, to_group_open_item (item)->command_name);
       gtk_tree_store_set (store, &iter,
-                          COL_NAME, ds_cstr (&name),
+                          COL_LABEL, output_item_get_label (item),
                          COL_ADDR, item,
-                          COL_Y, (view->y),
+                          COL_Y, view->y,
                           -1);
-      ds_destroy (&name);
 
       GtkTreePath *path = gtk_tree_model_get_path (
         GTK_TREE_MODEL (store), &iter);
@@ -603,32 +568,16 @@ enum {
   SELECT_FMT_ODT
 };
 
-/* Returns a pixbuf from a svg file      */
-/* You must unref the pixbuf after usage */
-static GdkPixbuf *
-derive_pixbuf_from_svg (const char *filename)
+static void
+clear_rectangle (cairo_surface_t *surface,
+                 double x0, double y0, double x1, double y1)
 {
-  GError *err = NULL;
-  GdkPixbuf *pixbuf = NULL;
-#if HAVE_RSVG
-  RsvgHandle *handle = rsvg_handle_new_from_file (filename, &err);
-  if (err == NULL)
-    {
-      rsvg_handle_set_dpi (handle, 300.0);
-      pixbuf = rsvg_handle_get_pixbuf (handle);
-      g_object_unref (handle);
-    }
-#else
-  pixbuf = gdk_pixbuf_new_from_file (filename, &err);
-#endif
-  if (err != NULL)
-    {
-      msg (ME, _("Could not open file %s during copy operation: %s"),
-          filename, err->message);
-      g_error_free (err);
-      return NULL;
-    }
-  return pixbuf;
+  cairo_t *cr = cairo_create (surface);
+  cairo_set_source_rgb (cr, 1, 1, 1);
+  cairo_new_path (cr);
+  cairo_rectangle (cr, x0, y0, x1 - x0, y1 - y0);
+  cairo_fill (cr);
+  cairo_destroy (cr);
 }
 
 static void
@@ -668,6 +617,7 @@ clipboard_get_cb (GtkClipboard     *clipboard,
 
     case SELECT_FMT_TEXT:
       string_map_insert (&options, "format", "txt");
+      string_map_insert (&options, "width", "1000");
       break;
 
     case SELECT_FMT_HTML:
@@ -708,16 +658,25 @@ clipboard_get_cb (GtkClipboard     *clipboard,
       gdk_window_end_draw_frame (win, ctx);
       cairo_region_destroy (region);
 
-      cairo_surface_t *surface = cairo_svg_surface_create (filename, w, h);
-      if (surface)
+      cairo_surface_t *surface
+        = (info == SELECT_FMT_SVG
+           ? cairo_svg_surface_create (filename, w, h)
+           : cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h));
+      clear_rectangle (surface, 0, 0, w, h);
+      cairo_t *cr2 = cairo_create (surface);
+      xr_fsm_draw_all (fsm, cr2);
+      cairo_destroy (cr2);
+      if (info == SELECT_FMT_IMG)
         {
-          cairo_t *cr = cairo_create (surface);
-          xr_fsm_draw_all (fsm, cr);
-          cairo_destroy (cr);
-          cairo_surface_destroy (surface);
+          GdkPixbuf *pixbuf = gdk_pixbuf_get_from_surface (surface,
+                                                           0, 0, w, h);
+          if (pixbuf)
+            {
+              gtk_selection_data_set_pixbuf (selection_data, pixbuf);
+              g_object_unref (pixbuf);
+            }
         }
-      else
-        g_error ("Could not create cairo svg surface with file %s", filename);
+      cairo_surface_destroy (surface);
     }
   else
     {
@@ -736,19 +695,11 @@ clipboard_get_cb (GtkClipboard     *clipboard,
       driver = NULL;
     }
 
-  if (info == SELECT_FMT_IMG)
-    {
-      GdkPixbuf *pixbuf = derive_pixbuf_from_svg (filename);
-      if (pixbuf)
-       {
-         gtk_selection_data_set_pixbuf (selection_data, pixbuf);
-         g_object_unref (pixbuf);
-       }
-    }
-  else if (g_file_get_contents (filename, &text, &length, NULL))
-    gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data),
-                           8,
-                           (const guchar *) text, length);
+  if (info != SELECT_FMT_IMG
+      && g_file_get_contents (filename, &text, &length, NULL))
+    gtk_selection_data_set (selection_data,
+                            gtk_selection_data_get_target (selection_data),
+                            8, (const guchar *) text, length);
 
  finish:
 
@@ -889,7 +840,7 @@ psppire_output_view_new (GtkLayout *output, GtkTreeView *overview)
 
       model = GTK_TREE_MODEL (gtk_tree_store_new (
                                 N_COLS,
-                                G_TYPE_STRING,  /* COL_NAME */
+                                G_TYPE_STRING,  /* COL_LABEL */
                                 G_TYPE_POINTER, /* COL_ADDR */
                                 G_TYPE_LONG));  /* COL_Y */
       gtk_tree_view_set_model (overview, model);
@@ -899,7 +850,7 @@ psppire_output_view_new (GtkLayout *output, GtkTreeView *overview)
       gtk_tree_view_append_column (GTK_TREE_VIEW (overview), column);
       renderer = gtk_cell_renderer_text_new ();
       gtk_tree_view_column_pack_start (column, renderer, TRUE);
-      gtk_tree_view_column_add_attribute (column, renderer, "text", COL_NAME);
+      gtk_tree_view_column_add_attribute (column, renderer, "text", COL_LABEL);
 
       g_signal_connect (GTK_TREE_VIEW (overview),
                         "row-activated", G_CALLBACK (on_row_activate), view);
@@ -1020,7 +971,6 @@ create_xr_print_driver (GtkPrintContext *context, struct psppire_output_view *vi
       [H] = { margins[H][0], margins[H][1] },
       [V] = { margins[V][0], margins[V][1] },
     },
-    .bg = { .alpha = 0 },
     .initial_page_number = 1,
     .object_spacing = 12 * XR_POINT,
   };
@@ -1037,7 +987,6 @@ create_xr_print_driver (GtkPrintContext *context, struct psppire_output_view *vi
     },
     .fg = CELL_COLOR_BLACK,
     .use_system_colors = false,
-    .transparent = false,
     .font_resolution = 72.0
   };