]> git.lyx.org Git - lyx.git/blob - src/table.h
56f8e91e7c9a33988859d293c9c7534dd8f00f1b
[lyx.git] / src / table.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor
6  *       
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2000 The LyX Team.
9  *
10  * ====================================================== */
11 #ifndef TABLE_H
12 #define TABLE_H
13
14 #ifdef __GNUG__
15 #pragma interface
16 #endif
17
18 #include <iosfwd>
19
20 #include "lyxlex.h"
21 #include "LString.h"
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(std::ostream &);
164         ///
165         void Read(std::istream &);
166
167         // cell <0 will tex the preamble
168         // returns the number of printed newlines
169         ///
170         int TexEndOfCell(std::ostream &, int cell);
171         ///
172         int DocBookEndOfCell(std::ostream &, int cell, int & depth);
173 #if 0
174         ///
175         int RoffEndOfCell(std::ostream &, int cell);
176 #endif
177         ///
178         char const * getDocBookAlign(int cell, bool isColumn = false);
179
180         ///
181         bool IsMultiColumn(int cell);
182         ///
183         void SetMultiColumn(int cell, int number);
184         ///
185         int UnsetMultiColumn(int cell); // returns number of new cells
186         ///
187         int row_of_cell(int cell);
188         ///
189         int column_of_cell(int cell);
190         ///
191         int rows;
192         ///
193         int columns;
194         ///
195         void SetLongTable(int what);
196         ///
197         bool IsLongTable();
198         ///
199         void SetRotateTable(int what);
200         ///
201         bool RotateTable();
202         ///
203         void SetRotateCell(int cell, int what);
204         ///
205         bool RotateCell(int cell);
206         ///
207         bool NeedRotating();
208         ///
209         void AppendContRow(int cell);
210         ///
211         bool IsContRow(int cell);
212         /// returns the number of the cell which continues
213         /// or -1 if no ContRow
214         int CellHasContRow(int cell);
215         ///
216         bool RowHasContRow(int cell);
217         ///
218         int FirstVirtualCell(int cell);
219         ///
220         int NextVirtualCell(int cell);
221         ///
222         bool ShouldBeVeryLastCell(int cell);
223         ///
224         bool ShouldBeVeryLastRow(int cell);
225         ///
226         int GetCellAbove(int cell);
227         ///
228         int GetCellNumber(int column, int row);
229         ///
230         void SetLinebreaks(int cell, bool what);
231         ///
232         bool Linebreaks(int cell);
233         ///
234         /// Long Table Options
235         ///
236         void SetLTHead(int cell, bool first);
237         ///
238         bool RowOfLTHead(int cell);
239         ///
240         bool RowOfLTFirstHead(int cell);
241         ///
242         void SetLTFoot(int cell, bool last);
243         ///
244         bool RowOfLTFoot(int cell);
245         ///
246         bool RowOfLTLastFoot(int cell);
247         ///
248         void SetLTNewPage(int cell, bool what);
249         ///
250         bool LTNewPage(int cell);
251 private:
252         ///
253         struct cellstruct {
254             ///
255             int cellno;
256             ///
257             int width_of_cell;
258             ///
259             int  multicolumn; // add approp. signedness
260             ///
261             int alignment; // add approp. signedness
262             ///
263             bool top_line;
264             ///
265             bool bottom_line;
266             ///
267             bool has_cont_row;
268             ///
269             bool linebreaks;
270             ///
271             int rotate;
272             ///
273             string align_special;
274             ///
275             string p_width; // this is only set for multicolumn!!!
276         };
277         ///
278         struct rowstruct {
279                 bool top_line;
280                 bool bottom_line;
281                 bool is_cont_row;
282                 /// This are for longtables only
283                 bool newpage;
284         };
285         ///
286         struct columnstruct {
287                 int alignment; // add approp. signedness
288                 bool left_line;
289                 bool right_line;
290                 int  width_of_column;
291                 string p_width;
292                 string align_special;
293         };
294         ///
295         int numberofcells;
296         ///
297         int * rowofcell;
298         ///
299         int * columnofcell;
300         ///
301         void set_row_column_number_info();
302
303         ///
304         rowstruct * row_info;
305         ///
306         columnstruct * column_info;
307         ///
308         cellstruct ** cell_info;
309         ///
310         int width_of_table;
311         ///
312         /// for long tables
313         ///
314         int endhead; // row of endhead
315         int endfirsthead; // row of endfirsthead
316         int endfoot; // row of endfoot
317         int endlastfoot; // row of endlastfoot
318    
319         /// Returns true if a complete update is necessary, otherwise false
320         bool SetWidthOfMulticolCell(int cell, int new_width);
321         void recalculateMulticolCells(int cell, int new_width);
322         /// Returns true if change
323         bool calculate_width_of_column(int column);
324         bool calculate_width_of_column_NMC(int column); // no multi cells
325         ///
326         void calculate_width_of_table();
327
328         ///
329         int right_column_of_cell(int cell);
330
331         ///
332         cellstruct * cellinfo_of_cell(int cell);
333
334         ///
335         void delete_column(int column);
336
337         ///
338         int cells_in_multicolumn(int cell);
339         ///
340         int is_long_table;
341         ///
342         int rotate;
343 };
344
345 #endif