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