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