Add missing license headers on *.hh files and others
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / OnlineRender / TableDefn.hh
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 // $XConsortium: TableDefn.hh /main/13 1996/11/06 16:52:17 cde-hal $
24
25 #define CRSEP_NOT_SPECIFIED     -1
26 #define CRSEP_NO                0
27 #define CRSEP_YES               1
28
29 class TableDefn;
30
31 class ColFormat
32 {
33 public:
34   ColFormat();
35   ~ColFormat();
36
37   char          char_align ()           { return f_char_align  ; }
38   char          char_align (const char *s)
39     { f_char_align = s[0] ; return f_char_align ; }
40
41   const char   *name ()                 { return f_name ; }
42   const char   *name (const char *);
43
44   _DtCvFrmtOption justify ()            
45     { return f_justify  ; }
46   _DtCvFrmtOption justify (_DtCvFrmtOption c)   
47     { f_justify = c ; return c ; }
48
49   unsigned      width ()                { return f_width  ; }
50   unsigned      width (int w)           { f_width = w ; return w ; }
51
52   int           colsep()                { return f_colsep; }
53   void          colsep(int v)           { f_colsep = v; }
54   int           rowsep()                { return f_rowsep; }
55   void          rowsep(int v)           { f_rowsep = v; }
56
57   bool operator==(const ColFormat &c) const
58     { return &c == this ; }
59
60 private:
61   char                  f_char_align ; // alignment character
62   char                  *f_name ;
63   _DtCvFrmtOption       f_justify ;    // 
64   unsigned              f_width ;      // percentage of total width
65   int                   f_colsep;
66   int                   f_rowsep;
67 };
68
69 class ColDefn
70 {
71 public:
72   ColDefn(_DtCvSegment *par, _DtCvSegment *gpar,
73           unsigned rows, char *colref, char* colstart, char* colend,
74           _DtCvFrmtOption justify, _DtCvFrmtOption vjustify,
75           int colsep, int rowsep, char char_align)
76     : f_parseg (par),
77   f_gparseg(gpar),
78   f_spanrows (rows),
79   f_colref (colref),
80   f_colstart (colstart),
81   f_colend (colend),
82   f_justify (justify),
83   f_vjustify (vjustify),
84   f_colsep(colsep),
85   f_rowsep(rowsep),
86   f_char_align(char_align)
87       {}
88
89   ~ColDefn () {
90         if (f_colref)   delete f_colref;
91         if (f_colstart) delete f_colstart;
92         if (f_colend)   delete f_colend;
93   }
94
95   _DtCvSegment  *parseg()  const { return f_parseg; }
96   _DtCvSegment  *gparseg() const { return f_gparseg; }
97
98   unsigned spanrows () const { return f_spanrows ; } 
99
100   const char *colref(char *r) { f_colref = r ; return r ; }
101   const char *colref()        { return f_colref ; }
102
103   void        colstart(char *s) { f_colstart = s; }
104   const char* colstart() const  { return f_colstart; }
105
106   void        colend(char *e) { f_colend = e; }
107   const char* colend()        { return f_colend; }
108
109   bool operator==(const ColDefn &c) const
110     { return &c == this ; }
111
112   _DtCvFrmtOption justify() { return f_justify; }
113   _DtCvFrmtOption justify(_DtCvFrmtOption c) { f_justify = c ; return c ; }
114
115   _DtCvFrmtOption vjustify() { return f_vjustify; }
116   _DtCvFrmtOption vjustify(_DtCvFrmtOption c) { f_vjustify = c ; return c ; }
117
118   int   colsep()        { return f_colsep; }
119   void  colsep(int v)   { f_colsep = v; }
120   int   rowsep()        { return f_rowsep; }
121   void  rowsep(int v)   { f_rowsep = v; }
122
123   void char_align(char c) { f_char_align = c; }
124   char char_align() { return f_char_align; }
125
126 private:
127   _DtCvSegment  *f_parseg ;
128   _DtCvSegment  *f_gparseg ;
129   unsigned       f_spanrows ;
130   char          *f_colref ;     // column format name
131   char          *f_colstart;
132   char          *f_colend;
133   _DtCvFrmtOption f_justify;
134   _DtCvFrmtOption f_vjustify;
135   int           f_colsep;
136   int           f_rowsep;
137   char          f_char_align;
138 };
139
140
141 class RowDefn
142 {
143 public:
144   RowDefn() ;
145   ~RowDefn() ;
146
147   void append(ColDefn *cd) { f_columns.append (cd); } 
148
149   CC_TPtrSlist<ColDefn> &columns() { return f_columns ; }
150
151   bool operator==(const RowDefn &r) const
152     { return &r == this ; }
153
154   _DtCvFrmtOption vjustify ()           
155     { return f_vjustify  ; }
156   _DtCvFrmtOption vjustify (_DtCvFrmtOption c)  
157     { f_vjustify = c ; return c ; }
158
159   int   rowsep()        { return f_rowsep; }
160   void  rowsep(int v)   { f_rowsep = v; }
161
162 private:
163   CC_TPtrSlist<ColDefn> f_columns ;
164
165   _DtCvFrmtOption       f_vjustify ;
166   int                   f_rowsep;
167 } ;
168
169 class TGDefn
170 {
171 public:
172   TGDefn (_DtCvFrmtOption justify, _DtCvFrmtOption vjustify);
173   ~TGDefn();
174   
175   void  set_segment (_DtCvSegment *seg) { f_segment = seg ; } 
176
177   void  add_row(RowDefn *);
178   void  add (ColFormat *);
179   void  add (ColDefn *);
180   
181   unsigned      numcols ()      { return f_numcols ; }
182   unsigned      numcols (int n) { f_numcols = n ; return n ; }
183
184   void build();         // fill in the Canvas Segment data
185
186   void setup_cell(_DtCvSegment*, ColDefn*, RowDefn*, ColFormat*, ColFormat*);
187
188   bool operator==(const TGDefn& t) const
189     { return &t == this ; } 
190
191   _DtCvFrmtOption justify() { return f_justify; }
192   _DtCvFrmtOption justify(_DtCvFrmtOption c) { f_justify = c ; return c ; }
193
194   _DtCvFrmtOption vjustify() { return f_vjustify  ; }
195   _DtCvFrmtOption vjustify(_DtCvFrmtOption c) { f_vjustify = c ; return c ; }
196
197   int   colsep()        { return f_colsep; }
198   void  colsep(int v)   { f_colsep = v; }
199   int   rowsep()        { return f_rowsep; }
200   void  rowsep(int v)   { f_rowsep = v; }
201
202   TableDefn* table() { return f_table; }
203   void table(TableDefn* t) { f_table = t; }
204
205   void char_align(const char* s) { f_char_align = *s; }
206   char char_align() const { return f_char_align; }
207
208 private:
209   ColFormat *find_format (const char *name, int* index = NULL) ;
210
211
212 private:
213   unsigned                      f_numcols ;
214   _DtCvSegment                 *f_segment ;
215   CC_TPtrSlist<ColFormat>       f_colformats ;
216   CC_TPtrSlist<RowDefn>         f_rows ;
217   _DtCvFrmtOption               f_justify;
218   _DtCvFrmtOption               f_vjustify;
219   int                           f_colsep;
220   int                           f_rowsep;
221   char                          f_char_align;
222   TableDefn*                    f_table; // table which contains this tgroup
223 };
224
225 class TableDefn
226 {
227 public:
228   typedef enum {
229     table_frame_default = -1,
230     table_frame_none    = 0,
231     table_frame_top     = 1 << 0,
232     table_frame_bottom  = 1 << 1,
233     table_frame_left    = 1 << 2,
234     table_frame_right   = 1 << 3,
235     table_frame_topbot  = table_frame_top | table_frame_bottom,
236     table_frame_sides   = table_frame_left | table_frame_right,
237     table_frame_all     = table_frame_topbot | table_frame_sides
238   } table_frame_t;
239
240   TableDefn(table_frame_t frame_tok, int colsep = CRSEP_NOT_SPECIFIED,
241                                      int rowsep = CRSEP_NOT_SPECIFIED) :
242     f_frame(frame_tok), f_colsep(colsep), f_rowsep(rowsep) {}
243   TableDefn(const char* frame_str, int colsep = CRSEP_NOT_SPECIFIED,
244                                    int rowsep = CRSEP_NOT_SPECIFIED);
245   ~TableDefn();
246
247   table_frame_t frame() { return f_frame; }
248   void frame(table_frame_t frame_tok) { f_frame = frame_tok; }
249   void frame(const char* frame_str);
250
251   int   colsep()        { return f_colsep; }
252   void  colsep(int v)   { f_colsep = v; }
253   int   rowsep()        { return f_rowsep; }
254   void  rowsep(int v)   { f_rowsep = v; }
255
256 protected:
257
258   table_frame_t string_to_token(const char* frame_str);
259
260 private:
261
262   table_frame_t f_frame;
263   int           f_colsep;
264   int           f_rowsep;
265
266 };