output: Add support for captions.
[pspp.git] / src / output / tab.h
blob9371d812c652292de4fb8e64032665be96a12ab6
1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997, 1998, 1999, 2000, 2009, 2011, 2014 Free Software Foundation, Inc.
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/>. */
17 #ifndef OUTPUT_TAB_H
18 #define OUTPUT_TAB_H
20 /* Simple table class.
22 This is a type of table (see output/table.h) whose content is composed
23 manually by the code that generates it, by filling in cells one by one.
25 Some of the features of this type of table are obsolete but have not yet
26 been removed, because some code still uses them. These features are:
28 - The title and caption. These are properties of the table_item (see
29 output/table-item.h) in which a table is embedded, not properties of
30 the table itself.
32 - Row and columns offsets (via tab_offset(), tab_next_row()). This
33 feature simply isn't used enough to justify keeping it.
35 - Table resizing. The code that does use this feature is just as well
36 served by creating multiple tables and pasting them together with
37 table_paste(). Eliminating this feature would also slightly simplify
38 the table code here.
41 #include "libpspp/compiler.h"
42 #include "output/table.h"
43 #include "data/format.h"
45 enum result_class
47 RC_INTEGER,
48 RC_WEIGHT,
49 RC_PVALUE,
50 RC_OTHER,
51 n_RC
54 /* A table. */
55 struct tab_table
57 struct table table;
58 struct pool *container;
60 /* Table title and caption, or null. */
61 char *title, *caption;
62 int cf; /* Column factor for indexing purposes. */
64 /* Table contents.
66 Each array element in cc[] is ordinarily a "char *" pointer to a
67 string. If TAB_JOIN (defined in tab.c) is set in ct[] for the element,
68 however, it is a joined cell and the corresponding element of cc[]
69 points to a struct tab_joined_cell. */
70 void **cc; /* Cell contents; void *[nr][nc]. */
71 unsigned char *ct; /* Cell types; unsigned char[nr][nc]. */
73 /* Rules. */
74 unsigned char *rh; /* Horiz rules; unsigned char[nr+1][nc]. */
75 unsigned char *rv; /* Vert rules; unsigned char[nr][nc+1]. */
77 /* X and Y offsets. */
78 int col_ofs, row_ofs;
80 struct fmt_spec fmtmap [n_RC];
83 struct tab_table *tab_cast (const struct table *);
85 /* Number of rows or columns in TABLE. */
86 static inline int tab_nr (const struct tab_table *table)
87 { return table_nr (&table->table); }
88 static inline int tab_nc (const struct tab_table *table)
89 { return table_nc (&table->table); }
91 /* Number of left/right/top/bottom header columns/rows in TABLE. */
92 static inline int tab_l (const struct tab_table *table)
93 { return table_hl (&table->table); }
94 static inline int tab_r (const struct tab_table *table)
95 { return table_hr (&table->table); }
96 static inline int tab_t (const struct tab_table *table)
97 { return table_ht (&table->table); }
98 static inline int tab_b (const struct tab_table *table)
99 { return table_hb (&table->table); }
101 /* Tables. */
102 struct tab_table *tab_create (int nc, int nr);
103 void tab_resize (struct tab_table *, int nc, int nr);
104 void tab_realloc (struct tab_table *, int nc, int nr);
105 void tab_headers (struct tab_table *, int l, int r, int t, int b);
106 void tab_title (struct tab_table *, const char *, ...)
107 PRINTF_FORMAT (2, 3);
108 void tab_caption (struct tab_table *, const char *, ...)
109 PRINTF_FORMAT (2, 3);
110 void tab_submit (struct tab_table *);
112 /* Rules. */
113 void tab_hline (struct tab_table *, int style, int x1, int x2, int y);
114 void tab_vline (struct tab_table *, int style, int x, int y1, int y2);
115 void tab_box (struct tab_table *, int f_h, int f_v, int i_h, int i_v,
116 int x1, int y1, int x2, int y2);
118 /* Obsolete cell options. */
119 #define TAT_TITLE TAB_EMPH /* Title attributes. */
121 void tab_set_format (struct tab_table *, enum result_class, const struct fmt_spec *);
124 /* Cells. */
125 struct fmt_spec;
126 struct dictionary;
127 union value;
128 void tab_value (struct tab_table *, int c, int r, unsigned char opt,
129 const union value *, const struct variable *,
130 const struct fmt_spec *);
132 void tab_double (struct tab_table *, int c, int r, unsigned char opt,
133 double v, const struct fmt_spec *, enum result_class );
135 void tab_text (struct tab_table *, int c, int r, unsigned opt, const char *);
136 void tab_text_format (struct tab_table *, int c, int r, unsigned opt,
137 const char *, ...)
138 PRINTF_FORMAT (5, 6);
140 void tab_joint_text (struct tab_table *, int x1, int y1, int x2, int y2,
141 unsigned opt, const char *);
142 void tab_joint_text_format (struct tab_table *, int x1, int y1, int x2, int y2,
143 unsigned opt, const char *, ...)
144 PRINTF_FORMAT (7, 8);
146 void tab_footnote (struct tab_table *, int x, int y, const char *format, ...)
147 PRINTF_FORMAT (4, 5);
149 void tab_subtable (struct tab_table *, int x1, int y1, int x2, int y2,
150 unsigned opt, struct table_item *subtable);
151 void tab_subtable_bare (struct tab_table *, int x1, int y1, int x2, int y2,
152 unsigned opt, struct table_item *subtable);
154 bool tab_cell_is_empty (const struct tab_table *, int c, int r);
156 /* Editing. */
157 void tab_offset (struct tab_table *, int col, int row);
158 void tab_next_row (struct tab_table *);
160 /* Current row/column offset. */
161 #define tab_row(TABLE) ((TABLE)->row_ofs)
162 #define tab_col(TABLE) ((TABLE)->col_ofs)
164 /* Simple output. */
165 void tab_output_text (int options, const char *string);
166 void tab_output_text_format (int options, const char *, ...)
167 PRINTF_FORMAT (2, 3);
169 #endif /* output/tab.h */