output-item: Add basic support for visibility.
[pspp] / src / output / output-item.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2009, 2011 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17 #ifndef OUTPUT_ITEM_H
18 #define OUTPUT_ITEM_H 1
19
20 /* Output items.
21
22    An output item is a self-contained chunk of output.
23 */
24
25 #include <cairo.h>
26 #include <stdbool.h>
27 #include "libpspp/cast.h"
28
29 enum output_item_type
30   {
31     OUTPUT_ITEM_CHART,
32     OUTPUT_ITEM_GROUP_OPEN,
33     OUTPUT_ITEM_GROUP_CLOSE,
34     OUTPUT_ITEM_IMAGE,
35     OUTPUT_ITEM_MESSAGE,
36     OUTPUT_ITEM_PAGE_BREAK,
37     OUTPUT_ITEM_PAGE_SETUP,
38     OUTPUT_ITEM_TABLE,
39     OUTPUT_ITEM_TEXT,
40   };
41
42 /* A single output item. */
43 struct output_item
44   {
45     /* Reference count.  An output item may be shared between multiple owners,
46        indicated by a reference count greater than 1.  When this is the case,
47        the output item must not be modified. */
48     int ref_cnt;
49
50     /* The localized label for the item that appears in the outline pane in the
51        PSPPIRE output viewer and in PDF outlines.  This is NULL if no label has
52        been explicitly set.
53
54        Use output_item_get_label() to read an item's label. */
55     char *label;
56
57     /* A locale-invariant identifier for the command that produced the output,
58        which may be NULL if unknown or if a command did not produce this
59        output. */
60     char *command_name;
61
62     /* For OUTPUT_ITEM_GROUP_OPEN, this is true if the group's subtree should
63        be expanded in an outline view, false otherwise.
64
65        For other kinds of output items, this is true to show the item's
66        content, false to hide it.  The item's label is always shown in an
67        outline view. */
68     bool show;
69
70     enum output_item_type type;
71     union
72       {
73         struct chart *chart;
74
75         cairo_surface_t *image;
76
77         struct msg *message;
78
79         struct page_setup *page_setup;
80
81         struct pivot_table *table;
82
83         struct
84           {
85             enum text_item_subtype
86               {
87                 TEXT_ITEM_PAGE_TITLE,       /* TITLE and SUBTITLE commands. */
88                 TEXT_ITEM_TITLE,            /* Title. */
89                 TEXT_ITEM_SYNTAX,           /* Syntax printback logging. */
90                 TEXT_ITEM_LOG,              /* Other logging. */
91               }
92             subtype;
93             struct pivot_value *content;
94           }
95         text;
96       };
97
98     char *cached_label;
99   };
100
101 struct output_item *output_item_ref (const struct output_item *);
102 void output_item_unref (struct output_item *);
103 bool output_item_is_shared (const struct output_item *);
104 struct output_item *output_item_unshare (struct output_item *);
105
106 void output_item_submit (struct output_item *);
107
108 const char *output_item_get_label (const struct output_item *);
109 void output_item_set_label (struct output_item *, const char *);
110 void output_item_set_label_nocopy (struct output_item *, char *);
111 \f
112 /* OUTPUT_ITEM_CHART. */
113 struct output_item *chart_item_create (struct chart *);
114 \f
115 /* OUTPUT_ITEM_GROUP_OPEN. */
116 struct output_item *group_open_item_create (const char *command_name,
117                                             const char *label);
118 struct output_item *group_open_item_create_nocopy (char *command_name,
119                                                    char *label);
120 \f
121 /* OUTPUT_ITEM_GROUP_CLOSE. */
122
123 struct output_item *group_close_item_create (void);
124 \f
125 /* OUTPUT_ITEM_IMAGE. */
126
127 struct output_item *image_item_create (cairo_surface_t *);
128 \f
129 /* OUTPUT_ITEM_MESSAGE. */
130
131 struct output_item *message_item_create (const struct msg *);
132
133 const struct msg *message_item_get_msg (const struct output_item *);
134
135 struct output_item *message_item_to_text_item (struct output_item *);
136 \f
137 /* OUTPUT_ITEM_PAGE_BREAK. */
138
139 struct output_item *page_break_item_create (void);
140 \f
141 /* OUTPUT_ITEM_PAGE_SETUP. */
142
143 struct output_item *page_setup_item_create (const struct page_setup *);
144 \f
145 /* OUTPUT_ITEM_TABLE. */
146
147 struct output_item *table_item_create (struct pivot_table *);
148 \f
149 /* OUTPUT_ITEM_TEXT. */
150
151 struct output_item *text_item_create (enum text_item_subtype,
152                                       const char *text, const char *label);
153 struct output_item *text_item_create_nocopy (enum text_item_subtype,
154                                              char *text, char *label);
155 struct output_item *text_item_create_value (enum text_item_subtype,
156                                             struct pivot_value *value,
157                                             char *label);
158
159 enum text_item_subtype text_item_get_subtype (const struct output_item *);
160 char *text_item_get_plain_text (const struct output_item *);
161
162 bool text_item_append (struct output_item *dst, const struct output_item *src);
163
164 struct output_item *text_item_to_table_item (struct output_item *);
165
166 const char *text_item_subtype_to_string (enum text_item_subtype);
167
168 #endif /* output/output-item.h */