]> git.lyx.org Git - lyx.git/blob - src/table.h
the fstream/iostream changes and some small other things
[lyx.git] / src / table.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor
6  *       
7  *        Copyright (C) 1995, 1996 Matthias Ettrich
8  *
9  * ====================================================== */
10 #ifndef TABLE_H
11 #define TABLE_H
12
13 #ifdef __GNUG__
14 #pragma interface
15 #endif
16
17 #include <cstdio>
18
19 #include "lyxlex.h"
20 #include "LString.h"
21
22
23 /* The features the text class offers for tables */ 
24
25 ///
26 class LyXTable  {
27 public:
28         // Are the values of these enums important? (Lgb)
29         enum {
30                 APPEND_ROW = 0,
31                 APPEND_COLUMN = 1,
32                 DELETE_ROW = 2,
33                 DELETE_COLUMN = 3,
34                 TOGGLE_LINE_TOP = 4,
35                 TOGGLE_LINE_BOTTOM = 5,
36                 TOGGLE_LINE_LEFT = 6,
37                 TOGGLE_LINE_RIGHT = 7,
38                 ALIGN_LEFT = 8, // what are these alignment enums used for?
39                 ALIGN_RIGHT = 9,
40                 ALIGN_CENTER = 10,
41                 DELETE_TABLE = 11,
42                 MULTICOLUMN = 12,
43                 SET_ALL_LINES = 13,
44                 UNSET_ALL_LINES = 14,
45                 SET_LONGTABLE = 15,
46                 UNSET_LONGTABLE = 16,
47                 SET_PWIDTH = 17,
48                 APPEND_CONT_ROW = 18,
49                 SET_ROTATE_TABLE = 19,
50                 UNSET_ROTATE_TABLE = 20,
51                 SET_ROTATE_CELL = 21,
52                 UNSET_ROTATE_CELL = 22,
53                 SET_LINEBREAKS = 23,
54                 SET_LTHEAD = 24,
55                 SET_LTFIRSTHEAD = 25,
56                 SET_LTFOOT = 26,
57                 SET_LTLASTFOOT = 27,
58                 SET_LTNEWPAGE = 28,
59                 SET_SPECIAL_COLUMN = 29,
60                 SET_SPECIAL_MULTI = 30
61         };
62
63         enum {
64                 CELL_NORMAL = 0,
65                 CELL_BEGIN_OF_MULTICOLUMN = 1,
66                 CELL_PART_OF_MULTICOLUMN = 2
67         };
68         /* konstruktor */
69         ///
70         LyXTable(int columns_arg, int rows_arg);
71         ///
72         LyXTable(LyXLex & lex);
73         ///
74         ~LyXTable();
75         ///
76         LyXTable * Clone();
77
78         /// Returns true if there is a topline, returns false if not
79         bool TopLine(int cell);
80         /// Returns true if there is a topline, returns false if not
81         bool BottomLine(int cell);
82         /// Returns true if there is a topline, returns false if not
83         bool LeftLine(int cell);
84         /// Returns true if there is a topline, returns false if not
85         bool RightLine(int cell);
86
87         ///
88         bool TopAlreadyDrawed(int cell);
89         ///
90         bool VeryLastRow(int cell);
91
92         ///
93         int AdditionalHeight(int cell);
94         ///
95         int AdditionalWidth(int cell);
96    
97         /* returns the maximum over all rows */
98         ///
99         int WidthOfColumn(int cell);
100         ///
101         int WidthOfTable();
102    
103         /// Returns true if a complete update is necessary, otherwise false
104         bool SetWidthOfCell(int cell, int new_width);
105         /// Returns true if a complete update is necessary, otherwise false
106         bool SetAllLines(int cell, bool line);
107         /// Returns true if a complete update is necessary, otherwise false
108         bool SetTopLine(int cell, bool line);
109         /// Returns true if a complete update is necessary, otherwise false
110         bool SetBottomLine(int cell, bool line);
111         /// Returns true if a complete update is necessary, otherwise false
112         bool SetLeftLine(int cell, bool line);
113         /// Returns true if a complete update is necessary, otherwise false
114         bool SetRightLine(int cell, bool line);
115         /// Returns true if a complete update is necessary, otherwise false
116         bool SetAlignment(int cell, char align);
117         ///
118         bool SetPWidth(int cell, string width);
119         ///
120         bool SetAlignSpecial(int cell, string special, int what);
121         ///
122         char GetAlignment(int cell); // add approp. signedness
123         ///
124         string GetPWidth(int cell);
125         ///
126         string GetAlignSpecial(int cell, int what);
127
128         ///
129         int GetWidthOfCell(int cell);
130         ///
131         int GetBeginningOfTextInCell(int cell);
132
133         ///
134         void AppendRow(int cell);
135         ///
136         void DeleteRow(int cell);
137
138         ///
139         void AppendColumn(int cell);
140         ///
141         void DeleteColumn(int cell);
142
143         ///
144         bool IsFirstCell(int cell);
145         ///
146         bool IsLastCell(int cell);
147
148         ///
149         int GetNumberOfCells();
150         ///
151         int AppendCellAfterCell(int append_cell, int question_cell);
152         ///
153         int DeleteCellIfColumnIsDeleted(int cell, int delete_column_cell);
154         ///
155         int NumberOfCellsInRow(int cell);
156         ///
157         void Reinit();
158
159         ///
160         void Init(int columns_arg, int rows_arg);
161
162         ///
163         void Write(ostream &);
164         ///
165         void Read(FILE * file);
166
167         // cell <0 will tex the preamble
168         // returns the number of printed newlines
169         ///
170         int TexEndOfCell(string & file, int cell);
171         ///
172         int RoffEndOfCell(ostream &, int cell);
173         ///
174         char const * getDocBookAlign(int cell, bool isColumn = false);
175         ///
176         int DocBookEndOfCell(string & file, int cell, int & depth);
177
178         ///
179         bool IsMultiColumn(int cell);
180         ///
181         void SetMultiColumn(int cell, int number);
182         ///
183         int UnsetMultiColumn(int cell); // returns number of new cells
184         ///
185         int row_of_cell(int cell);
186         ///
187         int column_of_cell(int cell);
188         ///
189         int rows;
190         ///
191         int columns;
192         ///
193         void SetLongTable(int what);
194         ///
195         bool IsLongTable();
196         ///
197         void SetRotateTable(int what);
198         ///
199         bool RotateTable();
200         ///
201         void SetRotateCell(int cell, int what);
202         ///
203         bool RotateCell(int cell);
204         ///
205         bool NeedRotating();
206         ///
207         void AppendContRow(int cell);
208         ///
209         bool IsContRow(int cell);
210         /// returns the number of the cell which continues
211         /// or -1 if no ContRow
212         int CellHasContRow(int cell);
213         ///
214         bool RowHasContRow(int cell);
215         ///
216         int FirstVirtualCell(int cell);
217         ///
218         int NextVirtualCell(int cell);
219         ///
220         bool ShouldBeVeryLastCell(int cell);
221         ///
222         bool ShouldBeVeryLastRow(int cell);
223         ///
224         int GetCellAbove(int cell);
225         ///
226         int GetCellNumber(int column, int row);
227         ///
228         void SetLinebreaks(int cell, bool what);
229         ///
230         bool Linebreaks(int cell);
231         ///
232         /// Long Table Options
233         ///
234         void SetLTHead(int cell, bool first);
235         ///
236         bool RowOfLTHead(int cell);
237         ///
238         bool RowOfLTFirstHead(int cell);
239         ///
240         void SetLTFoot(int cell, bool last);
241         ///
242         bool RowOfLTFoot(int cell);
243         ///
244         bool RowOfLTLastFoot(int cell);
245         ///
246         void SetLTNewPage(int cell, bool what);
247         ///
248         bool LTNewPage(int cell);
249 private:
250         ///
251         struct cellstruct {
252             ///
253             int cellno;
254             ///
255             int width_of_cell;
256             ///
257             int  multicolumn; // add approp. signedness
258             ///
259             int alignment; // add approp. signedness
260             ///
261             bool top_line;
262             ///
263             bool bottom_line;
264             ///
265             bool has_cont_row;
266             ///
267             bool linebreaks;
268             ///
269             int rotate;
270             ///
271             string align_special;
272             ///
273             string p_width; // this is only set for multicolumn!!!
274         };
275         ///
276         struct rowstruct {
277                 bool top_line;
278                 bool bottom_line;
279                 bool is_cont_row;
280                 /// This are for longtables only
281                 bool newpage;
282         };
283         ///
284         struct columnstruct {
285                 int alignment; // add approp. signedness
286                 bool left_line;
287                 bool right_line;
288                 int  width_of_column;
289                 string p_width;
290                 string align_special;
291         };
292         ///
293         int numberofcells;
294         ///
295         int * rowofcell;
296         ///
297         int * columnofcell;
298         ///
299         void set_row_column_number_info();
300
301         ///
302         rowstruct * row_info;
303         ///
304         columnstruct * column_info;
305         ///
306         cellstruct ** cell_info;
307         ///
308         int width_of_table;
309         ///
310         /// for long tables
311         ///
312         int endhead; // row of endhead
313         int endfirsthead; // row of endfirsthead
314         int endfoot; // row of endfoot
315         int endlastfoot; // row of endlastfoot
316    
317         /// Returns true if a complete update is necessary, otherwise false
318         bool SetWidthOfMulticolCell(int cell, int new_width);
319         void recalculateMulticolCells(int cell, int new_width);
320         /// Returns true if change
321         bool calculate_width_of_column(int column);
322         bool calculate_width_of_column_NMC(int column); // no multi cells
323         ///
324         void calculate_width_of_table();
325
326         ///
327         int right_column_of_cell(int cell);
328
329         ///
330         cellstruct * cellinfo_of_cell(int cell);
331
332         ///
333         void delete_column(int column);
334
335         ///
336         int cells_in_multicolumn(int cell);
337         ///
338         int is_long_table;
339         ///
340         int rotate;
341 };
342
343 #endif