db38b6b8144d0b94cb638a7abe0c65174d1b7b48
[pspp-builds.git] / src / output / tab.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997, 1998, 1999, 2000, 2009 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_TAB_H
18 #define OUTPUT_TAB_H
19
20 /* Simple table class.
21
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.
24
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:
27
28        - The title.  The title (or caption, actually) is a property of the
29          table_item (see output/table-item.h) in which a table is embedded,
30          not a property of the table itself.
31
32        - Row and columns offsets (via tab_offset(), tab_next_row()).  This
33          feature simply isn't used enough to justify keeping it.
34
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.
39 */
40
41 #include <libpspp/compiler.h>
42 #include <output/table.h>
43
44 /* A table. */
45 struct tab_table
46   {
47     struct table table;
48     struct pool *container;
49
50     /* Table title, or a null pointer if no title has been set.
51
52        The table title is properly part of struct table_item, not struc*/
53     char *title;
54     int cf;                     /* Column factor for indexing purposes. */
55
56     /* Table contents.
57
58        Each array element in cc[] is ordinarily a "char *" pointer to a
59        string.  If TAB_JOIN (defined in tab.c) is set in ct[] for the element,
60        however, it is a joined cell and the corresponding element of cc[]
61        points to a struct tab_joined_cell. */
62     void **cc;                  /* Cell contents; void *[nr][nc]. */
63     unsigned char *ct;          /* Cell types; unsigned char[nr][nc]. */
64
65     /* Rules. */
66     unsigned char *rh;          /* Horiz rules; unsigned char[nr+1][nc]. */
67     unsigned char *rv;          /* Vert rules; unsigned char[nr][nc+1]. */
68
69     /* X and Y offsets. */
70     int col_ofs, row_ofs;
71   };
72
73 struct tab_table *tab_cast (const struct table *);
74
75 /* Number of rows or columns in TABLE. */
76 static inline int tab_nr (const struct tab_table *table)
77         { return table_nr (&table->table); }
78 static inline int tab_nc (const struct tab_table *table)
79         { return table_nc (&table->table); }
80
81 /* Number of left/right/top/bottom header columns/rows in TABLE. */
82 static inline int tab_l (const struct tab_table *table)
83         { return table_hl (&table->table); }
84 static inline int tab_r (const struct tab_table *table)
85         { return table_hr (&table->table); }
86 static inline int tab_t (const struct tab_table *table)
87         { return table_ht (&table->table); }
88 static inline int tab_b (const struct tab_table *table)
89         { return table_hb (&table->table); }
90
91 /* Tables. */
92 struct tab_table *tab_create (int nc, int nr);
93 void tab_resize (struct tab_table *, int nc, int nr);
94 void tab_realloc (struct tab_table *, int nc, int nr);
95 void tab_headers (struct tab_table *, int l, int r, int t, int b);
96 void tab_title (struct tab_table *, const char *, ...)
97      PRINTF_FORMAT (2, 3);
98 void tab_submit (struct tab_table *);
99
100 /* Rules. */
101 void tab_hline (struct tab_table *, int style, int x1, int x2, int y);
102 void tab_vline (struct tab_table *, int style, int x, int y1, int y2);
103 void tab_box (struct tab_table *, int f_h, int f_v, int i_h, int i_v,
104               int x1, int y1, int x2, int y2);
105
106 /* Obsolete cell options. */
107 #define TAT_TITLE TAB_EMPH      /* Title attributes. */
108
109 /* Cells. */
110 struct fmt_spec;
111 struct dictionary;
112 union value;
113 void tab_value (struct tab_table *, int c, int r, unsigned char opt,
114                 const union value *, const struct dictionary *dict,
115                 const struct fmt_spec *);
116
117 void tab_fixed (struct tab_table *, int c, int r, unsigned char opt,
118                 double v, int w, int d);
119
120 void tab_double (struct tab_table *, int c, int r, unsigned char opt,
121                 double v, const struct fmt_spec *);
122
123 void tab_text (struct tab_table *, int c, int r, unsigned opt, const char *);
124 void tab_text_format (struct tab_table *, int c, int r, unsigned opt,
125                       const char *, ...)
126      PRINTF_FORMAT (5, 6);
127
128 void tab_joint_text (struct tab_table *, int x1, int y1, int x2, int y2,
129                      unsigned opt, const char *);
130 void tab_joint_text_format (struct tab_table *, int x1, int y1, int x2, int y2,
131                             unsigned opt, const char *, ...)
132      PRINTF_FORMAT (7, 8);
133
134 bool tab_cell_is_empty (const struct tab_table *, int c, int r);
135
136 /* Editing. */
137 void tab_offset (struct tab_table *, int col, int row);
138 void tab_next_row (struct tab_table *);
139
140 /* Current row/column offset. */
141 #define tab_row(TABLE) ((TABLE)->row_ofs)
142 #define tab_col(TABLE) ((TABLE)->col_ofs)
143
144 /* Simple output. */
145 void tab_output_text (int options, const char *string);
146 void tab_output_text_format (int options, const char *, ...)
147      PRINTF_FORMAT (2, 3);
148
149 #endif /* output/tab.h */
150