]> git.lyx.org Git - lyx.git/blob - src/table.h
small patch from jamatos
[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         explicit
73         LyXTable(LyXLex & lex);
74         ///
75         ~LyXTable();
76         ///
77         LyXTable * Clone();
78
79         /// Returns true if there is a topline, returns false if not
80         bool TopLine(int cell);
81         /// Returns true if there is a topline, returns false if not
82         bool BottomLine(int cell);
83         /// Returns true if there is a topline, returns false if not
84         bool LeftLine(int cell);
85         /// Returns true if there is a topline, returns false if not
86         bool RightLine(int cell);
87
88         ///
89         bool TopAlreadyDrawed(int cell);
90         ///
91         bool VeryLastRow(int cell);
92
93         ///
94         int AdditionalHeight(int cell);
95         ///
96         int AdditionalWidth(int cell);
97    
98         /* returns the maximum over all rows */
99         ///
100         int WidthOfColumn(int cell);
101         ///
102         int WidthOfTable();
103    
104         /// Returns true if a complete update is necessary, otherwise false
105         bool SetWidthOfCell(int cell, int new_width);
106         /// Returns true if a complete update is necessary, otherwise false
107         bool SetAllLines(int cell, bool line);
108         /// Returns true if a complete update is necessary, otherwise false
109         bool SetTopLine(int cell, bool line);
110         /// Returns true if a complete update is necessary, otherwise false
111         bool SetBottomLine(int cell, bool line);
112         /// Returns true if a complete update is necessary, otherwise false
113         bool SetLeftLine(int cell, bool line);
114         /// Returns true if a complete update is necessary, otherwise false
115         bool SetRightLine(int cell, bool line);
116         /// Returns true if a complete update is necessary, otherwise false
117         bool SetAlignment(int cell, char align);
118         ///
119         bool SetPWidth(int cell, string width);
120         ///
121         bool SetAlignSpecial(int cell, string special, int what);
122         ///
123         char GetAlignment(int cell); // add approp. signedness
124         ///
125         string GetPWidth(int cell);
126         ///
127         string GetAlignSpecial(int cell, int what);
128
129         ///
130         int GetWidthOfCell(int cell);
131         ///
132         int GetBeginningOfTextInCell(int cell);
133
134         ///
135         void AppendRow(int cell);
136         ///
137         void DeleteRow(int cell);
138
139         ///
140         void AppendColumn(int cell);
141         ///
142         void DeleteColumn(int cell);
143
144         ///
145         bool IsFirstCell(int cell);
146         ///
147         bool IsLastCell(int cell);
148
149         ///
150         int GetNumberOfCells();
151         ///
152         int AppendCellAfterCell(int append_cell, int question_cell);
153         ///
154         int DeleteCellIfColumnIsDeleted(int cell, int delete_column_cell);
155         ///
156         int NumberOfCellsInRow(int cell);
157         ///
158         void Reinit();
159
160         ///
161         void Init(int columns_arg, int rows_arg);
162
163         ///
164         void Write(std::ostream &);
165         ///
166         void Read(std::istream &);
167
168         // cell <0 will tex the preamble
169         // returns the number of printed newlines
170         ///
171         int TexEndOfCell(std::ostream &, int cell);
172         ///
173         int DocBookEndOfCell(std::ostream &, int cell, int & depth);
174 #if 0
175         ///
176         int RoffEndOfCell(std::ostream &, int cell);
177 #endif
178         ///
179         char const * getDocBookAlign(int cell, bool isColumn = false);
180
181         ///
182         bool IsMultiColumn(int cell);
183         ///
184         void SetMultiColumn(int cell, int number);
185         ///
186         int UnsetMultiColumn(int cell); // returns number of new cells
187         ///
188         int row_of_cell(int cell);
189         ///
190         int column_of_cell(int cell);
191         ///
192         int rows;
193         ///
194         int columns;
195         ///
196         void SetLongTable(int what);
197         ///
198         bool IsLongTable();
199         ///
200         void SetRotateTable(int what);
201         ///
202         bool RotateTable();
203         ///
204         void SetRotateCell(int cell, int what);
205         ///
206         bool RotateCell(int cell);
207         ///
208         bool NeedRotating();
209         ///
210         void AppendContRow(int cell);
211         ///
212         bool IsContRow(int cell);
213         /// returns the number of the cell which continues
214         /// or -1 if no ContRow
215         int CellHasContRow(int cell);
216         ///
217         bool RowHasContRow(int cell);
218         ///
219         int FirstVirtualCell(int cell);
220         ///
221         int NextVirtualCell(int cell);
222         ///
223         bool ShouldBeVeryLastCell(int cell);
224         ///
225         bool ShouldBeVeryLastRow(int cell);
226         ///
227         int GetCellAbove(int cell);
228         ///
229         int GetCellNumber(int column, int row);
230         ///
231         void SetLinebreaks(int cell, bool what);
232         ///
233         bool Linebreaks(int cell);
234         ///
235         /// Long Table Options
236         ///
237         void SetLTHead(int cell, bool first);
238         ///
239         bool RowOfLTHead(int cell);
240         ///
241         bool RowOfLTFirstHead(int cell);
242         ///
243         void SetLTFoot(int cell, bool last);
244         ///
245         bool RowOfLTFoot(int cell);
246         ///
247         bool RowOfLTLastFoot(int cell);
248         ///
249         void SetLTNewPage(int cell, bool what);
250         ///
251         bool LTNewPage(int cell);
252 private:
253         ///
254         struct cellstruct {
255             ///
256             int cellno;
257             ///
258             int width_of_cell;
259             ///
260             int  multicolumn; // add approp. signedness
261             ///
262             int alignment; // add approp. signedness
263             ///
264             bool top_line;
265             ///
266             bool bottom_line;
267             ///
268             bool has_cont_row;
269             ///
270             bool linebreaks;
271             ///
272             int rotate;
273             ///
274             string align_special;
275             ///
276             string p_width; // this is only set for multicolumn!!!
277         };
278         ///
279         struct rowstruct {
280                 bool top_line;
281                 bool bottom_line;
282                 bool is_cont_row;
283                 /// This are for longtables only
284                 bool newpage;
285         };
286         ///
287         struct columnstruct {
288                 int alignment; // add approp. signedness
289                 bool left_line;
290                 bool right_line;
291                 int  width_of_column;
292                 string p_width;
293                 string align_special;
294         };
295         ///
296         int numberofcells;
297         ///
298         int * rowofcell;
299         ///
300         int * columnofcell;
301         ///
302         void set_row_column_number_info();
303
304         ///
305         rowstruct * row_info;
306         ///
307         columnstruct * column_info;
308         ///
309         cellstruct ** cell_info;
310         ///
311         int width_of_table;
312         ///
313         /// for long tables
314         ///
315         int endhead; // row of endhead
316         int endfirsthead; // row of endfirsthead
317         int endfoot; // row of endfoot
318         int endlastfoot; // row of endlastfoot
319    
320         /// Returns true if a complete update is necessary, otherwise false
321         bool SetWidthOfMulticolCell(int cell, int new_width);
322         void recalculateMulticolCells(int cell, int new_width);
323         /// Returns true if change
324         bool calculate_width_of_column(int column);
325         bool calculate_width_of_column_NMC(int column); // no multi cells
326         ///
327         void calculate_width_of_table();
328
329         ///
330         int right_column_of_cell(int cell);
331
332         ///
333         cellstruct * cellinfo_of_cell(int cell);
334
335         ///
336         void delete_column(int column);
337
338         ///
339         int cells_in_multicolumn(int cell);
340         ///
341         int is_long_table;
342         ///
343         int rotate;
344 };
345
346 #endif