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