html: Pop up tooltip with table notes in output.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 27 Dec 2020 01:54:56 +0000 (17:54 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 27 Dec 2020 01:55:48 +0000 (17:55 -0800)
I can't see how to do this for ODP or PDF output.  (PDF supports tooltips
but Cairo doesn't expose the feature; ODP doesn't seem to support it at
all.)

src/output/ascii.c
src/output/html.c
src/output/pivot-output.c
src/output/pivot-table.h
src/output/table-item.c
src/output/table-item.h
src/output/text-item.c
tests/output/render-test.c

index ce3356954b4416bc59be22496a8b1080c38204a2..07b05580162d154f5e26bd562aa58c63f7fce258 100644 (file)
@@ -485,7 +485,7 @@ static void
 ascii_output_text (struct ascii_driver *a, const char *text)
 {
   ascii_output_table_item_unref (
-    a, table_item_create (table_from_string (text), NULL, NULL));
+    a, table_item_create (table_from_string (text), NULL, NULL, NULL));
 }
 
 static void
index b8679b57eca1ce7b41968dde01cf9b2404ecfe71..c1613c4fea24d5668322540f9e2087e2763b90b5 100644 (file)
@@ -505,7 +505,14 @@ html_output_table (struct html_driver *html, const struct table_item *item)
   bool tfoot = false;
   int y;
 
-  fputs ("<table>\n", html->file);
+  fputs ("<table", html->file);
+  if (item->notes)
+    {
+      fputs (" title=\"", html->file);
+      escape_string (html->file, item->notes, " ", "\n");
+      putc ('"', html->file);
+    }
+  fputs (">\n", html->file);
 
   const struct table_item_text *caption = table_item_get_caption (item);
   if (caption)
index 31d68c8d37838fda3b8418f8260abf7c5138d6d7..ea0cdd4a6e6eea178b8b5f358b64df620b58cbda 100644 (file)
@@ -451,7 +451,7 @@ pivot_table_submit_layer (const struct pivot_table *pt,
   free (column_enumeration);
   free (row_enumeration);
 
-  struct table_item *ti = table_item_create (table, NULL, NULL);
+  struct table_item *ti = table_item_create (table, NULL, NULL, pt->notes);
 
   if (pt->title)
     {
index c613e55efc81d557c03d67b28f45ce72f23c31da..2770c611d61b3ff27a083e089ea7eb1487b86133 100644 (file)
@@ -467,7 +467,7 @@ struct pivot_table
     struct pivot_value *subtype;  /* Same as spv_item's subtype. */
     struct pivot_value *corner_text;
     struct pivot_value *caption;
-    char *notes;
+    char *notes;                /* Shown as tooltip. */
 
     /* Dimensions. */
     struct pivot_dimension **dimensions;
index 1ead1f92f6b61be784c39a036e71a6b97d90b457..9355a77a115f58f20462207c71e142d97ab313a9 100644 (file)
@@ -120,10 +120,11 @@ table_item_layers_destroy (struct table_item_layers *layers)
 }
 
 /* Initializes ITEM as a table item for rendering TABLE.  The new table item
-   initially has the specified TITLE and CAPTION, which may each be NULL.  The
-   caller retains ownership of TITLE and CAPTION. */
+   initially has the specified TITLE, CAPTION, and NOTES, which may each be
+   NULL.  The caller retains ownership of TITLE, CAPTION, and NOTES. */
 struct table_item *
-table_item_create (struct table *table, const char *title, const char *caption)
+table_item_create (struct table *table, const char *title, const char *caption,
+                   const char *notes)
 {
   struct table_item *item = xmalloc (sizeof *item);
   output_item_init (&item->output_item, &table_item_class);
@@ -131,6 +132,7 @@ table_item_create (struct table *table, const char *title, const char *caption)
   item->title = table_item_text_create (title);
   item->layers = NULL;
   item->caption = table_item_text_create (caption);
+  item->notes = notes ? xstrdup (notes) : NULL;
   item->pt = NULL;
   return item;
 }
@@ -208,6 +210,26 @@ table_item_set_caption (struct table_item *item,
   item->caption = table_item_text_clone (caption);
 }
 
+/* Returns ITEM's notes, which is a null pointer if ITEM has no notes. */
+const char *
+table_item_get_notes (const struct table_item *item)
+{
+  return item->notes;
+}
+
+/* Sets ITEM's notes to NOTES, replacing any previous notes.  Specify NULL for
+   NOTES to clear any notes from ITEM.  The caller retains ownership of
+   NOTES.
+
+   This function may only be used on a table_item that is unshared.*/
+void
+table_item_set_notes (struct table_item *item, const char *notes)
+{
+  assert (!table_item_is_shared (item));
+  free (item->notes);
+  item->notes = notes ? xstrdup (notes) : NULL;
+}
+
 /* Submits TABLE_ITEM to the configured output drivers, and transfers ownership
    to the output subsystem. */
 void
@@ -223,6 +245,7 @@ table_item_destroy (struct output_item *output_item)
   table_item_text_destroy (item->title);
   table_item_text_destroy (item->caption);
   table_item_layers_destroy (item->layers);
+  free (item->notes);
   pivot_table_unref (item->pt);
   table_unref (item->table);
   free (item);
index eb3dcb16ea440ba9db1da0eb15c44836941eaef3..e4c40ab228c5ce959a90c828053cb70f24150528 100644 (file)
@@ -70,16 +70,17 @@ void table_item_layers_destroy (struct table_item_layers *);
    of the accessor functions defined below. */
 struct table_item
   {
-    struct output_item output_item;  /* Superclass. */
-    struct table *table;             /* The table to be rendered. */
-    struct table_item_text *title;   /* Null if there is no title. */
-    struct table_item_text *caption; /* Null if there is no caption. */
+    struct output_item output_item;   /* Superclass. */
+    struct table *table;              /* The table to be rendered. */
+    struct table_item_text *title;    /* Null if there is no title. */
+    struct table_item_text *caption;  /* Null if there is no caption. */
     struct table_item_layers *layers; /* Null if there is no layer info. */
+    char *notes;                      /* Shown as tooltip. */
     struct pivot_table *pt;
   };
 
 struct table_item *table_item_create (struct table *, const char *title,
-                                      const char *caption);
+                                      const char *caption, const char *notes);
 
 const struct table *table_item_get_table (const struct table_item *);
 
@@ -96,6 +97,9 @@ const struct table_item_text *table_item_get_caption (
   const struct table_item *);
 void table_item_set_caption (struct table_item *,
                              const struct table_item_text *);
+
+const char *table_item_get_notes (const struct table_item *);
+void table_item_set_notes (struct table_item *, const char *notes);
 \f
 /* This boilerplate for table_item, a subclass of output_item, was
    autogenerated by mk-class-boilerplate. */
index 95bb7723c84147043a2e429489f29f8ca50d1626..8c7f0dc51a67afe97ebdd1f09d2c9424e0673454 100644 (file)
@@ -137,7 +137,7 @@ text_item_to_table_item (struct text_item *text_item)
   if (text_item->type == TEXT_ITEM_SYNTAX || text_item->type == TEXT_ITEM_LOG)
     opts |= TAB_FIX;
   table_text (tab, 0, 0, opts, text_item_get_text (text_item));
-  struct table_item *table_item = table_item_create (tab, NULL, NULL);
+  struct table_item *table_item = table_item_create (tab, NULL, NULL, NULL);
   text_item_unref (text_item);
   return table_item;
 }
index 6b0aa73c4a049a0593acaa3e610905ead457d206..0e07f87dc16f6ef8e3ce9ebf97196ca37c525127 100644 (file)
@@ -114,7 +114,7 @@ main (int argc, char **argv)
         }
 
       table = tables[n_tables - 1];
-      table_item_submit (table_item_create (table, NULL, NULL));
+      table_item_submit (table_item_create (table, NULL, NULL, NULL));
       free (tables);
     }
   else