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