output: Make groups contain their subitems, and get rid of spv_item.
[pspp] / src / output / output-item.h
index a408807f0fe7c9114125633b996f2820d0fe0211..72d4661510d3993e8cf5ffc95ce5c9d78e1b172d 100644 (file)
 #include <cairo.h>
 #include <stdbool.h>
 #include "libpspp/cast.h"
 #include <cairo.h>
 #include <stdbool.h>
 #include "libpspp/cast.h"
+#include "libpspp/string-array.h"
 
 enum output_item_type
   {
     OUTPUT_ITEM_CHART,
 
 enum output_item_type
   {
     OUTPUT_ITEM_CHART,
-    OUTPUT_ITEM_GROUP_OPEN,
-    OUTPUT_ITEM_GROUP_CLOSE,
+    OUTPUT_ITEM_GROUP,
     OUTPUT_ITEM_IMAGE,
     OUTPUT_ITEM_MESSAGE,
     OUTPUT_ITEM_PAGE_BREAK,
     OUTPUT_ITEM_IMAGE,
     OUTPUT_ITEM_MESSAGE,
     OUTPUT_ITEM_PAGE_BREAK,
@@ -39,6 +39,8 @@ enum output_item_type
     OUTPUT_ITEM_TEXT,
   };
 
     OUTPUT_ITEM_TEXT,
   };
 
+const char *output_item_type_to_string (enum output_item_type);
+
 /* A single output item. */
 struct output_item
   {
 /* A single output item. */
 struct output_item
   {
@@ -59,7 +61,7 @@ struct output_item
        output. */
     char *command_name;
 
        output. */
     char *command_name;
 
-    /* For OUTPUT_ITEM_GROUP_OPEN, this is true if the group's subtree should
+    /* For OUTPUT_ITEM_GROUP, this is true if the group's subtree should
        be expanded in an outline view, false otherwise.
 
        For other kinds of output items, this is true to show the item's
        be expanded in an outline view, false otherwise.
 
        For other kinds of output items, this is true to show the item's
@@ -67,6 +69,10 @@ struct output_item
        outline view. */
     bool show;
 
        outline view. */
     bool show;
 
+    /* Information about the SPV file this output_item was read from.
+       May be NULL. */
+    struct spv_info *spv_info;
+
     enum output_item_type type;
     union
       {
     enum output_item_type type;
     union
       {
@@ -74,6 +80,14 @@ struct output_item
 
         cairo_surface_t *image;
 
 
         cairo_surface_t *image;
 
+        struct
+          {
+            struct output_item **children;
+            size_t n_children;
+            size_t allocated_children;
+          }
+        group;
+
         struct msg *message;
 
         struct page_setup *page_setup;
         struct msg *message;
 
         struct page_setup *page_setup;
@@ -104,23 +118,65 @@ bool output_item_is_shared (const struct output_item *);
 struct output_item *output_item_unshare (struct output_item *);
 
 void output_item_submit (struct output_item *);
 struct output_item *output_item_unshare (struct output_item *);
 
 void output_item_submit (struct output_item *);
+void output_item_submit_children (struct output_item *);
 
 const char *output_item_get_label (const struct output_item *);
 void output_item_set_label (struct output_item *, const char *);
 void output_item_set_label_nocopy (struct output_item *, char *);
 
 const char *output_item_get_label (const struct output_item *);
 void output_item_set_label (struct output_item *, const char *);
 void output_item_set_label_nocopy (struct output_item *, char *);
+
+void output_item_set_command_name (struct output_item *, const char *);
+void output_item_set_command_name_nocopy (struct output_item *, char *);
+
+char *output_item_get_subtype (const struct output_item *);
+
+void output_item_add_spv_info (struct output_item *);
+
+void output_item_dump (const struct output_item *, int indentation);
+\f
+/* In-order traversal of a tree of output items. */
+
+struct output_iterator_node
+  {
+    const struct output_item *group;
+    size_t idx;
+  };
+
+struct output_iterator
+  {
+    const struct output_item *cur;
+    struct output_iterator_node *nodes;
+    size_t n, allocated;
+  };
+#define OUTPUT_ITERATOR_INIT(ITEM) { .cur = ITEM }
+
+/* Iteration functions. */
+void output_iterator_init (struct output_iterator *,
+                           const struct output_item *);
+void output_iterator_destroy (struct output_iterator *);
+void output_iterator_next (struct output_iterator *);
+
+/* Iteration helper macros. */
+#define OUTPUT_ITEM_FOR_EACH(ITER, ROOT) \
+  for (output_iterator_init (ITER, ROOT); (ITER)->cur; \
+       output_iterator_next (ITER))
+#define OUTPUT_ITEM_FOR_EACH_SKIP_ROOT(ITER, ROOT) \
+  for (output_iterator_init (ITER, ROOT), output_iterator_next (ITER); \
+       (ITER)->cur; output_iterator_next (ITER))
 \f
 /* OUTPUT_ITEM_CHART. */
 struct output_item *chart_item_create (struct chart *);
 \f
 \f
 /* OUTPUT_ITEM_CHART. */
 struct output_item *chart_item_create (struct chart *);
 \f
-/* OUTPUT_ITEM_GROUP_OPEN. */
-struct output_item *group_open_item_create (const char *command_name,
-                                            const char *label);
-struct output_item *group_open_item_create_nocopy (char *command_name,
-                                                   char *label);
-\f
-/* OUTPUT_ITEM_GROUP_CLOSE. */
+/* OUTPUT_ITEM_GROUP. */
+struct output_item *group_item_create (const char *command_name,
+                                       const char *label);
+struct output_item *group_item_create_nocopy (char *command_name, char *label);
 
 
-struct output_item *group_close_item_create (void);
+void group_item_add_child (struct output_item *parent,
+                           struct output_item *child);
+
+struct output_item *root_item_create (void);
+
+struct output_item *group_item_clone_empty (const struct output_item *);
 \f
 /* OUTPUT_ITEM_IMAGE. */
 
 \f
 /* OUTPUT_ITEM_IMAGE. */
 
@@ -164,5 +220,29 @@ bool text_item_append (struct output_item *dst, const struct output_item *src);
 struct output_item *text_item_to_table_item (struct output_item *);
 
 const char *text_item_subtype_to_string (enum text_item_subtype);
 struct output_item *text_item_to_table_item (struct output_item *);
 
 const char *text_item_subtype_to_string (enum text_item_subtype);
+\f
+/* An informational node for output items that were read from an .spv file.
+   This is mostly for debugging and troubleshooting purposes with the
+   pspp-output program. */
+struct spv_info
+  {
+    /* The .spv file. */
+    struct zip_reader *zip_reader;
+
+    /* True if there was an error reading the output item (e.g. because of
+       corruption or because PSPP doesn't understand the format.) */
+    bool error;
+
+    /* Zip member names.  All may be NULL. */
+    char *structure_member;
+    char *xml_member;
+    char *bin_member;
+    char *png_member;
+  };
+
+void spv_info_destroy (struct spv_info *);
+struct spv_info *spv_info_clone (const struct spv_info *);
+size_t spv_info_get_members (const struct spv_info *, const char **members,
+                             size_t allocated_members);
 
 #endif /* output/output-item.h */
 
 #endif /* output/output-item.h */