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