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