]> git.lyx.org Git - lyx.git/blob - src/tabular.h
update copyright year
[lyx.git] / src / tabular.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor
6  *       
7  *           Copyright 2000-2001 The LyX Team.
8  *
9  *           @author: Jürgen Vigna
10  *
11  * ====================================================== */
12 #ifndef TABULAR_H
13 #define TABULAR_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include <iosfwd>
20 #include <vector>
21
22 #include "lyxlex.h"
23 #include "LString.h"
24 #include "insets/insettext.h"
25
26 class InsetTabular;
27 class LaTeXFeatures;
28 class Buffer;
29
30 /* The features the text class offers for tables */ 
31
32 ///
33 class LyXTabular  {
34 public:
35         ///
36         enum Feature {
37                 ///
38                 APPEND_ROW = 0,
39                 ///
40                 APPEND_COLUMN,
41                 ///
42                 DELETE_ROW,
43                 ///
44                 DELETE_COLUMN,
45                 ///
46                 TOGGLE_LINE_TOP,
47                 ///
48                 TOGGLE_LINE_BOTTOM,
49                 ///
50                 TOGGLE_LINE_LEFT,
51                 ///
52                 TOGGLE_LINE_RIGHT,
53                 ///
54                 ALIGN_LEFT,
55                 ///
56                 ALIGN_RIGHT,
57                 ///
58                 ALIGN_CENTER,
59                 ///
60                 VALIGN_TOP,
61                 ///
62                 VALIGN_BOTTOM,
63                 ///
64                 VALIGN_CENTER,
65                 ///
66                 M_TOGGLE_LINE_TOP,
67                 ///
68                 M_TOGGLE_LINE_BOTTOM,
69                 ///
70                 M_TOGGLE_LINE_LEFT,
71                 ///
72                 M_TOGGLE_LINE_RIGHT,
73                 ///
74                 M_ALIGN_LEFT,
75                 ///
76                 M_ALIGN_RIGHT,
77                 ///
78                 M_ALIGN_CENTER,
79                 ///
80                 M_VALIGN_TOP,
81                 ///
82                 M_VALIGN_BOTTOM,
83                 ///
84                 M_VALIGN_CENTER,
85                 ///
86                 MULTICOLUMN,
87                 ///
88                 SET_ALL_LINES,
89                 ///
90                 UNSET_ALL_LINES,
91                 ///
92                 SET_LONGTABULAR,
93                 ///
94                 UNSET_LONGTABULAR,
95                 ///
96                 SET_PWIDTH,
97                 ///
98                 SET_MPWIDTH,
99                 ///
100                 SET_ROTATE_TABULAR,
101                 ///
102                 UNSET_ROTATE_TABULAR,
103                 ///
104                 SET_ROTATE_CELL,
105                 ///
106                 UNSET_ROTATE_CELL,
107                 ///
108                 SET_USEBOX,
109                 ///
110                 SET_LTHEAD,
111                 ///
112                 SET_LTFIRSTHEAD,
113                 ///
114                 SET_LTFOOT,
115                 ///
116                 SET_LTLASTFOOT,
117                 ///
118                 SET_LTNEWPAGE,
119                 ///
120                 SET_SPECIAL_COLUMN,
121                 ///
122                 SET_SPECIAL_MULTI,
123                 ///
124                 LAST_ACTION
125         };
126         ///
127         enum {
128                 ///
129                 CELL_NORMAL = 0,
130                 ///
131                 CELL_BEGIN_OF_MULTICOLUMN,
132                 ///
133                 CELL_PART_OF_MULTICOLUMN
134         };
135
136         ///
137         enum VAlignment {
138                 ///
139                 LYX_VALIGN_TOP = 0,
140                 ///
141                 LYX_VALIGN_BOTTOM = 1,
142                 ///
143                 LYX_VALIGN_CENTER = 2
144         };
145
146         enum BoxType {
147                 ///
148                 BOX_NONE = 0,
149                 ///
150                 BOX_PARBOX = 1,
151                 ///
152                 BOX_MINIPAGE = 2
153         };
154
155         /* konstruktor */
156         ///
157         LyXTabular(InsetTabular *, int columns_arg, int rows_arg);
158         ///
159         LyXTabular(InsetTabular *, LyXTabular const &);
160         ///
161         explicit
162         LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
163         ///
164         LyXTabular & operator=(LyXTabular const &);
165         ///
166         LyXTabular * Clone(InsetTabular *);
167         
168         /// Returns true if there is a topline, returns false if not
169         bool TopLine(int cell, bool onlycolumn = false) const;
170         /// Returns true if there is a topline, returns false if not
171         bool BottomLine(int cell, bool onlycolumn = false) const;
172         /// Returns true if there is a topline, returns false if not
173         bool LeftLine(int cell, bool onlycolumn = false) const;
174         /// Returns true if there is a topline, returns false if not
175         bool RightLine(int cell, bool onlycolumn = false) const;
176         
177         ///
178         bool TopAlreadyDrawed(int cell) const;
179         ///
180         bool LeftAlreadyDrawed(int cell) const;
181         ///
182         bool IsLastRow(int cell) const;
183
184         ///
185         int GetAdditionalHeight(int row) const;
186         ///
187         int GetAdditionalWidth(int cell) const;
188         
189         /* returns the maximum over all rows */
190         ///
191         int GetWidthOfColumn(int cell) const;
192         ///
193         int GetWidthOfTabular() const;
194         ///
195         int GetAscentOfRow(int row) const;
196         ///
197         int GetDescentOfRow(int row) const;
198         ///
199         int GetHeightOfTabular() const;
200         /// Returns true if a complete update is necessary, otherwise false
201         bool SetAscentOfRow(int row, int height);
202         /// Returns true if a complete update is necessary, otherwise false
203         bool SetDescentOfRow(int row, int height);
204         /// Returns true if a complete update is necessary, otherwise false
205         bool SetWidthOfCell(int cell, int new_width);
206         /// Returns true if a complete update is necessary, otherwise false
207         bool SetAllLines(int cell, bool line);
208         /// Returns true if a complete update is necessary, otherwise false
209         bool SetTopLine(int cell, bool line, bool onlycolumn = false);
210         /// Returns true if a complete update is necessary, otherwise false
211         bool SetBottomLine(int cell, bool line, bool onlycolumn = false);
212         /// Returns true if a complete update is necessary, otherwise false
213         bool SetLeftLine(int cell, bool line, bool onlycolumn = false);
214         /// Returns true if a complete update is necessary, otherwise false
215         bool SetRightLine(int cell, bool line, bool onlycolumn = false);
216         /// Returns true if a complete update is necessary, otherwise false
217         bool SetAlignment(int cell, LyXAlignment align,
218                           bool onlycolumn = false);
219         /// Returns true if a complete update is necessary, otherwise false
220         bool SetVAlignment(int cell, VAlignment align,
221                            bool onlycolumn = false);
222         ///
223         bool SetColumnPWidth(int cell, string const & width);
224         ///
225         bool SetMColumnPWidth(int cell, string const & width);
226         ///
227         bool SetAlignSpecial(int cell, string const & special, Feature what);
228         ///
229         LyXAlignment GetAlignment(int cell, bool onlycolumn = false) const;
230         ///
231         VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
232         ///
233         string const GetPWidth(int cell) const;
234         ///
235         string const GetColumnPWidth(int cell) const;
236         ///
237         string const GetMColumnPWidth(int cell) const;
238         ///
239         string const GetAlignSpecial(int cell, int what) const;
240         ///
241         int GetWidthOfCell(int cell) const;
242         ///
243         int GetBeginningOfTextInCell(int cell) const;
244         ///
245         void AppendRow(int cell);
246         ///
247         void DeleteRow(int row);
248         ///
249         void AppendColumn(int cell);
250         ///
251         void DeleteColumn(int column);
252         ///
253         bool IsFirstCellInRow(int cell) const;
254         ///
255         int GetFirstCellInRow(int row) const;
256         ///
257         bool IsLastCellInRow(int cell) const;
258         ///
259         int GetLastCellInRow(int row) const;
260         ///
261         int GetNumberOfCells() const;
262         ///
263         int NumberOfCellsInRow(int cell) const;
264         ///
265         void Write(Buffer const *, std::ostream &) const;
266         ///
267         void Read(Buffer const *, LyXLex &);
268         ///
269         void OldFormatRead(LyXLex &, string const &);
270         //
271         // helper function for Latex returns number of newlines
272         ///
273         int TeXTopHLine(std::ostream &, int row) const;
274         ///
275         int TeXBottomHLine(std::ostream &, int row) const;
276         ///
277         int TeXCellPreamble(std::ostream &, int cell) const;
278         ///
279         int TeXCellPostamble(std::ostream &, int cell) const;
280         ///
281         int Latex(Buffer const *, std::ostream &, bool, bool) const;
282         ///
283         int DocBook(Buffer const * buf, std::ostream & os) const;
284         ///
285         // helper function for Latex returns number of newlines
286         ///
287         int AsciiTopHLine(std::ostream &, int row,
288                           std::vector<unsigned int> const &) const;
289         ///
290         int AsciiBottomHLine(std::ostream &, int row,
291                              std::vector<unsigned int> const &) const;
292         ///
293         int AsciiPrintCell(Buffer const *, std::ostream &,
294                            int cell, int row, int column,
295                            std::vector<unsigned int> const &) const;
296         ///
297         int Ascii(Buffer const *, std::ostream &) const;
298         ///
299         bool IsMultiColumn(int cell, bool real = false) const;
300         ///
301         void SetMultiColumn(int cell, int number);
302         ///
303         int UnsetMultiColumn(int cell); // returns number of new cells
304         ///
305         bool IsPartOfMultiColumn(int row, int column) const;
306         ///
307         int row_of_cell(int cell) const;
308         ///
309         int column_of_cell(int cell) const;
310         ///
311         int right_column_of_cell(int cell) const;
312         ///
313         void SetLongTabular(bool);
314         ///
315         bool IsLongTabular() const;
316         ///
317         void SetRotateTabular(bool);
318         ///
319         bool GetRotateTabular() const;
320         ///
321         void SetRotateCell(int cell, bool);
322         ///
323         bool GetRotateCell(int cell) const;
324         ///
325         bool NeedRotating() const;
326         ///
327         bool IsLastCell(int cell) const;
328         ///
329         int GetCellAbove(int cell) const;
330         ///
331         int GetCellBelow(int cell) const;
332         ///
333         int GetLastCellAbove(int cell) const;
334         ///
335         int GetLastCellBelow(int cell) const;
336         ///
337         int GetCellNumber(int row, int column) const;
338         ///
339         void SetUsebox(int cell, BoxType);
340         ///
341         BoxType GetUsebox(int cell) const;
342         //
343         // Long Tabular Options
344         ///
345         void SetLTHead(int cell, bool first);
346         ///
347         bool GetRowOfLTHead(int cell, int & row) const;
348         ///
349         bool GetRowOfLTFirstHead(int cell, int & row) const;
350         ///
351         void SetLTFoot(int cell, bool last);
352         ///
353         bool GetRowOfLTFoot(int cell, int & row) const;
354         ///
355         bool GetRowOfLTLastFoot(int cell, int & row) const;
356         ///
357         void SetLTNewPage(int cell, bool what);
358         ///
359         bool GetLTNewPage(int cell) const;
360         ///
361         InsetText * GetCellInset(int cell) const;
362         ///
363         InsetText * GetCellInset(int row, int column) const;
364         ///
365         int rows() const { return rows_; }
366         ///
367         int columns() const { return columns_;}
368         ///
369         InsetTabular * owner() const { return owner_; }
370         ///
371         void Validate(LaTeXFeatures &) const;
372         ///
373         std::vector<string> const getLabelList() const;
374 private:
375         ///
376         struct cellstruct {
377                 ///
378                 cellstruct();
379                 ///
380                 int cellno;
381                 ///
382                 int width_of_cell;
383                 ///
384                 int multicolumn;
385                 ///
386                 LyXAlignment alignment;
387                 ///
388                 VAlignment valignment;
389                 ///
390                 bool top_line;
391                 ///
392                 bool bottom_line;
393                 ///
394                 bool left_line;
395                 ///
396                 bool right_line;
397                 ///
398                 BoxType usebox;
399                 ///
400                 bool rotate;
401                 ///
402                 string align_special;
403                 ///
404                 string p_width; // this is only set for multicolumn!!!
405                 ///
406                 InsetText inset;
407         };
408         ///
409         typedef std::vector<cellstruct> cell_vector;
410         ///
411         typedef std::vector<cell_vector> cell_vvector;
412
413         ///
414         struct rowstruct {
415                 ///
416                 rowstruct();
417                 ///
418                 bool top_line;
419                 ///
420                 bool bottom_line;
421                 ///
422                 int ascent_of_row;
423                 ///
424                 int descent_of_row;
425                 /// This are for longtabulars only
426                 bool newpage;
427         };
428         ///
429         typedef std::vector<rowstruct> row_vector;
430
431         ///
432         struct columnstruct {
433                 ///
434                 columnstruct();
435                 ///
436                 LyXAlignment alignment;
437                 ///
438                 VAlignment valignment;
439                 ///
440                 bool left_line;
441                 ///
442                 bool right_line;
443                 ///
444                 int  width_of_column;
445                 ///
446                 string p_width;
447                 ///
448                 string align_special;
449         };
450         ///
451         typedef std::vector<columnstruct> column_vector;
452
453         ///
454         void ReadNew(Buffer const * buf, std::istream & is,
455                                  LyXLex & lex, string const & l);
456         ///
457         void ReadOld(Buffer const * buf, std::istream & is,
458                                  LyXLex & lex, string const & l);
459         ///
460         int rows_;
461         ///
462         int columns_;
463         ///
464         int numberofcells;
465         ///
466         std::vector<int> rowofcell;
467         ///
468         std::vector<int> columnofcell;
469         ///
470         row_vector row_info;
471         ///
472         column_vector column_info;
473         ///
474         mutable cell_vvector cell_info;
475         ///
476         int width_of_tabular;
477         ///
478         bool rotate;
479         //
480         // for long tabulars
481         ///
482         bool is_long_tabular;
483         /// row of endhead
484         int endhead;
485         /// row of endfirsthead
486         int endfirsthead;
487         /// row of endfoot
488         int endfoot;
489         /// row of endlastfoot
490         int endlastfoot;
491         ///
492         InsetTabular * owner_;
493
494         ///
495         void Init(int columns_arg, int rows_arg, LyXTabular const * lt = 0);
496         ///
497         void Reinit();
498         ///
499         void set_row_column_number_info(bool oldformat = false);
500         /// Returns true if a complete update is necessary, otherwise false
501         bool SetWidthOfMulticolCell(int cell, int new_width);
502         ///
503         void recalculateMulticolCells(int cell, int new_width);
504         /// Returns true if change
505         bool calculate_width_of_column(int column);
506         ///
507         bool calculate_width_of_column_NMC(int column); // no multi cells
508         ///
509         void calculate_width_of_tabular();
510         ///
511         cellstruct * cellinfo_of_cell(int cell) const;
512         ///
513         void delete_column(int column);
514         ///
515         int cells_in_multicolumn(int cell) const;
516         ///
517         BoxType UseParbox(int cell) const;
518 };
519
520 #endif