829410edfd3db644930a18233f9a3a939a8413c9
[pspp-builds.git] / src / output / table.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000 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 #if !tab_h
18 #define tab_h 1
19
20 #include <limits.h>
21 #include <libpspp/str.h>
22
23 /* Cell options. */
24 enum
25   {
26     TAB_NONE = 0,
27
28     TAB_ALIGN_MASK = 03,        /* Alignment mask. */
29     TAB_RIGHT = 00,             /* Right justify. */
30     TAB_LEFT = 01,              /* Left justify. */
31     TAB_CENTER = 02,            /* Center. */
32
33     /* Cell types. */
34     TAB_JOIN = 004,             /* Joined cell. */
35     TAB_EMPTY = 010,            /* Empty cell. */
36
37     /* Flags. */
38     TAB_EMPH = 020,             /* Emphasize cell contents. */
39     TAB_FIX = 040,              /* Use fixed font. */
40   };
41
42 /* Line styles. */
43 enum
44   {
45     TAL_0 = 0,                  /* No line. */
46     TAL_1 = 1,                  /* Single line. */
47     TAL_2 = 2,                  /* Double line. */
48     TAL_GAP = 3,                /* Spacing but no line. */
49     TAL_COUNT,                  /* Number of line styles. */
50   };
51
52 /* Column styles.  Must correspond to SOM_COL_*. */
53 enum
54   {
55     TAB_COL_NONE,                       /* No columns. */
56     TAB_COL_DOWN                        /* Columns down first. */
57   };
58
59 /* Joined cell. */
60 struct tab_joined_cell
61   {
62     int x1, y1;
63     int x2, y2;
64     int hit;
65     struct substring contents;
66   };
67
68 struct outp_driver;
69 struct tab_table;
70 typedef void tab_dim_func (struct tab_table *, struct outp_driver *);
71
72 /* A table. */
73 struct tab_table
74   {
75     struct pool *container;
76
77     /* Contents. */
78     int col_style;              /* Columns: One of TAB_COL_*. */
79     int col_group;              /* Number of rows per column group. */
80     char *title;                /* Table title. */
81     unsigned flags;             /* SOMF_*. */
82     int nc, nr;                 /* Number of columns, rows. */
83     int cf;                     /* Column factor for indexing purposes. */
84     int l, r, t, b;             /* Number of header rows on each side. */
85     struct substring *cc;       /* Cell contents; substring *[nr][nc]. */
86     unsigned char *ct;          /* Cell types; unsigned char[nr][nc]. */
87     unsigned char *rh;          /* Horiz rules; unsigned char[nr+1][nc]. */
88     unsigned char *rv;          /* Vert rules; unsigned char[nr][nc+1]. */
89     tab_dim_func *dim;          /* Calculates cell widths and heights. */
90
91     /* Calculated during output. */
92     int *w;                     /* Column widths; [nc]. */
93     int *h;                     /* Row heights; [nr]. */
94     int *hrh;                   /* Heights of horizontal rules; [nr+1]. */
95     int *wrv;                   /* Widths of vertical rules; [nc+1]. */
96     int wl, wr, ht, hb;         /* Width/height of header rows/columns. */
97
98     /* Editing info. */
99     int col_ofs, row_ofs;       /* X and Y offsets. */
100   };
101
102 /* Number of rows in TABLE. */
103 #define tab_nr(TABLE) ((TABLE)->nr)
104
105 /* Number of columns in TABLE. */
106 #define tab_nc(TABLE) ((TABLE)->nc)
107
108 /* Number of left header columns in TABLE. */
109 #define tab_l(TABLE) ((TABLE)->l)
110
111 /* Number of right header columns in TABLE. */
112 #define tab_r(TABLE) ((TABLE)->r)
113
114 /* Number of top header rows in TABLE. */
115 #define tab_t(TABLE) ((TABLE)->t)
116
117 /* Number of bottom header rows in TABLE. */
118 #define tab_b(TABLE) ((TABLE)->b)
119
120 /* Tables. */
121 struct tab_table *tab_create (int nc, int nr, int reallocable);
122 void tab_destroy (struct tab_table *);
123 void tab_resize (struct tab_table *, int nc, int nr);
124 void tab_realloc (struct tab_table *, int nc, int nr);
125 void tab_headers (struct tab_table *, int l, int r, int t, int b);
126 void tab_columns (struct tab_table *, int style, int group);
127 void tab_title (struct tab_table *, const char *, ...)
128      PRINTF_FORMAT (2, 3);
129 void tab_flags (struct tab_table *, unsigned);
130 void tab_submit (struct tab_table *);
131
132 /* Dimensioning. */
133 tab_dim_func tab_natural_dimensions;
134 int tab_natural_width (struct tab_table *t, struct outp_driver *d, int c);
135 int tab_natural_height (struct tab_table *t, struct outp_driver *d, int r);
136 void tab_dim (struct tab_table *, tab_dim_func *);
137
138 /* Rules. */
139 void tab_hline (struct tab_table *, int style, int x1, int x2, int y);
140 void tab_vline (struct tab_table *, int style, int x, int y1, int y2);
141 void tab_box (struct tab_table *, int f_h, int f_v, int i_h, int i_v,
142               int x1, int y1, int x2, int y2);
143
144 /* Text options, passed in the `opt' argument. */
145 enum
146   {
147     TAT_NONE = 0,               /* No options. */
148     TAT_PRINTF = 0x0100,        /* Format the text string with sprintf. */
149     TAT_TITLE = 0x0200 | TAB_EMPH, /* Title attributes. */
150     TAT_NOWRAP = 0x0800         /* No text wrap (tab_output_text() only). */
151   };
152
153 /* Cells. */
154 struct fmt_spec;
155 union value;
156 void tab_value (struct tab_table *, int c, int r, unsigned char opt,
157                 const union value *, const struct fmt_spec *);
158
159 void tab_fixed (struct tab_table *, int c, int r, unsigned char opt,
160                 double v, int w, int d);
161
162 void tab_double (struct tab_table *, int c, int r, unsigned char opt,
163                 double v, const struct fmt_spec *);
164
165 void tab_text (struct tab_table *, int c, int r, unsigned opt,
166                const char *, ...)
167      PRINTF_FORMAT (5, 6);
168 void tab_joint_text (struct tab_table *, int x1, int y1, int x2, int y2,
169                      unsigned opt, const char *, ...)
170      PRINTF_FORMAT (7, 8);
171
172 /* Cell low-level access. */
173 #define tab_alloc(TABLE, AMT) pool_alloc ((TABLE)->container, (AMT))
174 void tab_raw (struct tab_table *, int c, int r, unsigned opt,
175               struct substring *);
176
177 /* Editing. */
178 void tab_offset (struct tab_table *, int col, int row);
179 void tab_next_row (struct tab_table *);
180
181 /* Current row/column offset. */
182 #define tab_row(TABLE) ((TABLE)->row_ofs)
183 #define tab_col(TABLE) ((TABLE)->col_ofs)
184
185 /* Simple output. */
186 void tab_output_text (int options, const char *string, ...)
187      PRINTF_FORMAT (2, 3);
188
189 /* Embedding the command name in the output. */
190 void tab_set_command_name (const char *);
191
192 #endif /* tab_h */
193