Added new files resulting from directory restructuring.
[pspp-builds.git] / src / output / table.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18    02110-1301, USA. */
19
20 #if !tab_h
21 #define tab_h 1
22
23 #include <limits.h>
24 #include "str.h"
25
26 /* Cell options. */
27 enum
28   {
29     TAB_NONE = 0,
30
31     /* Must match output.h: OUTP_T_JUST_*. */
32     TAB_ALIGN_MASK = 03,        /* Alignment mask. */
33     TAB_RIGHT = 00,             /* Right justify. */
34     TAB_LEFT = 01,              /* Left justify. */
35     TAB_CENTER = 02,            /* Center. */
36
37     /* Oddball cell types. */
38     TAB_JOIN = 010,             /* Joined cell. */
39     TAB_EMPTY = 020             /* Empty cell. */
40   };
41
42 /* Line styles.  These must match output.h:OUTP_L_*. */
43 enum
44   {
45     TAL_0 = 0,                  /* No line. */
46     TAL_1 = 1,                  /* Single line. */
47     TAL_2 = 2,                  /* Double line. */
48     TAL_3 = 3,                  /* Special line of driver-defined style. */
49     TAL_COUNT,                  /* Number of line styles. */
50
51     TAL_SPACING = 0200          /* Don't draw the line, just reserve space. */
52   };
53
54 /* Column styles.  Must correspond to SOM_COL_*. */
55 enum
56   {
57     TAB_COL_NONE,                       /* No columns. */
58     TAB_COL_DOWN                        /* Columns down first. */
59   };
60
61 /* Joined cell. */
62 struct tab_joined_cell
63   {
64     int x1, y1;
65     int x2, y2;
66     int hit;
67     struct fixed_string contents;
68   };
69
70 struct outp_driver;
71 struct tab_table;
72 typedef void tab_dim_func (struct tab_table *, struct outp_driver *);
73
74 /* A table. */
75 struct tab_table
76   {
77     struct pool *container;
78     
79     /* Contents. */
80     int col_style;              /* Columns: One of TAB_COL_*. */
81     int col_group;              /* Number of rows per column group. */
82     struct fixed_string title;  /* Table title. */
83     unsigned flags;             /* SOMF_*. */
84     int nc, nr;                 /* Number of columns, rows. */
85     int cf;                     /* Column factor for indexing purposes. */
86     int l, r, t, b;             /* Number of header rows on each side. */
87     struct fixed_string *cc;    /* Cell contents; fixed_string *[nr][nc]. */
88     unsigned char *ct;          /* Cell types; unsigned char[nr][nc]. */
89     unsigned char *rh;          /* Horiz rules; unsigned char[nr+1][nc]. */
90     unsigned char *trh;         /* Types of horiz rules; [nr+1]. */
91     unsigned char *rv;          /* Vert rules; unsigned char[nr][nc+1]. */
92     unsigned char *trv;         /* Types of vert rules; [nc+1]. */
93     tab_dim_func *dim;          /* Calculates cell widths and heights. */
94
95     /* Calculated during output. */
96     int *w;                     /* Column widths; [nc]. */
97     int *h;                     /* Row heights; [nr]. */
98     int *hrh;                   /* Heights of horizontal rules; [nr+1]. */
99     int *wrv;                   /* Widths of vertical rules; [nc+1]. */
100     int wl, wr, ht, hb;         /* Width/height of header rows/columns. */
101     int hr_tot, vr_tot;         /* Hrules total height, vrules total width. */
102
103     /* Editing info. */
104     int col_ofs, row_ofs;       /* X and Y offsets. */
105 #if GLOBAL_DEBUGGING
106     int reallocable;            /* Can table be reallocated? */
107 #endif
108   };
109
110 extern int tab_hit;
111
112 /* Number of rows in TABLE. */
113 #define tab_nr(TABLE) ((TABLE)->nr)
114
115 /* Number of columns in TABLE. */
116 #define tab_nc(TABLE) ((TABLE)->nc)
117
118 /* Number of left header columns in TABLE. */
119 #define tab_l(TABLE) ((TABLE)->l)
120
121 /* Number of right header columns in TABLE. */
122 #define tab_r(TABLE) ((TABLE)->r)
123
124 /* Number of top header rows in TABLE. */
125 #define tab_t(TABLE) ((TABLE)->t)
126
127 /* Number of bottom header rows in TABLE. */
128 #define tab_b(TABLE) ((TABLE)->b)
129
130 /* Tables. */
131 struct tab_table *tab_create (int nc, int nr, int reallocable);
132 void tab_destroy (struct tab_table *);
133 void tab_resize (struct tab_table *, int nc, int nr);
134 void tab_realloc (struct tab_table *, int nc, int nr);
135 void tab_headers (struct tab_table *, int l, int r, int t, int b);
136 void tab_columns (struct tab_table *, int style, int group);
137 void tab_title (struct tab_table *, int format, const char *, ...);
138 void tab_flags (struct tab_table *, unsigned);
139 void tab_submit (struct tab_table *);
140
141 /* Dimensioning. */
142 tab_dim_func tab_natural_dimensions;
143 int tab_natural_width (struct tab_table *t, struct outp_driver *d, int c);
144 int tab_natural_height (struct tab_table *t, struct outp_driver *d, int r);
145 void tab_dim (struct tab_table *, tab_dim_func *);
146
147 /* Rules. */
148 void tab_hline (struct tab_table *, int style, int x1, int x2, int y);
149 void tab_vline (struct tab_table *, int style, int x, int y1, int y2);
150 void tab_box (struct tab_table *, int f_h, int f_v, int i_h, int i_v,
151               int x1, int y1, int x2, int y2);
152
153 /* Text options, passed in the `opt' argument. */
154 enum
155   {
156     TAT_NONE = 0,               /* No options. */
157     TAT_PRINTF = 0x0100,        /* Format the text string with sprintf. */
158     TAT_TITLE = 0x0204,         /* Title attributes. */
159     TAT_FIX = 0x0400,           /* Use fixed-pitch font. */
160     TAT_NOWRAP = 0x0800         /* No text wrap (tab_output_text() only). */
161   };
162
163 /* Cells. */
164 struct fmt_spec;
165 union value;
166 void tab_value (struct tab_table *, int c, int r, unsigned char opt,
167                 const union value *, const struct fmt_spec *);
168 void tab_float (struct tab_table *, int c, int r, unsigned char opt,
169                 double v, int w, int d);
170 void tab_text (struct tab_table *, int c, int r, unsigned opt,
171                const char *, ...)
172      PRINTF_FORMAT (5, 6);
173 void tab_joint_text (struct tab_table *, int x1, int y1, int x2, int y2,
174                      unsigned opt, const char *, ...)
175      PRINTF_FORMAT (7, 8);
176
177 /* Cell low-level access. */
178 #define tab_alloc(TABLE, AMT) pool_alloc ((TABLE)->container, (AMT))
179 void tab_raw (struct tab_table *, int c, int r, unsigned opt,
180               struct fixed_string *);
181
182 /* Editing. */
183 void tab_offset (struct tab_table *, int col, int row);
184 void tab_next_row (struct tab_table *);
185
186 /* Current row/column offset. */
187 #define tab_row(TABLE) ((TABLE)->row_ofs)
188 #define tab_col(TABLE) ((TABLE)->col_ofs)
189
190 /* Simple output. */
191 void tab_output_text (int options, const char *string, ...)
192      PRINTF_FORMAT (2, 3);
193
194 /* Embedding the command name in the output. */
195 void tab_set_command_name (const char *);
196
197 #endif /* tab_h */
198