]> git.lyx.org Git - features.git/blob - src/tabular.h
reversed jug-bug, will apply pieces later
[features.git] / src / tabular.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor
6  *       
7  *           Copyright 2000 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 cell) const;
186
187         ///
188         int GetAdditionalWidth(int cell) const;
189         
190         /* returns the maximum over all rows */
191         ///
192         int GetWidthOfColumn(int cell) const;
193         ///
194         int GetWidthOfTabular() const;
195         ///
196         int GetAscentOfRow(int row) const;
197         ///
198         int GetDescentOfRow(int row) const;
199         ///
200         int GetHeightOfTabular() const;
201         /// Returns true if a complete update is necessary, otherwise false
202         bool SetAscentOfRow(int row, int height);
203         /// Returns true if a complete update is necessary, otherwise false
204         bool SetDescentOfRow(int row, int height);
205         /// Returns true if a complete update is necessary, otherwise false
206         bool SetWidthOfCell(int cell, int new_width);
207         /// Returns true if a complete update is necessary, otherwise false
208         bool SetAllLines(int cell, bool line);
209         /// Returns true if a complete update is necessary, otherwise false
210         bool SetTopLine(int cell, bool line, bool onlycolumn = false);
211         /// Returns true if a complete update is necessary, otherwise false
212         bool SetBottomLine(int cell, bool line, bool onlycolumn = false);
213         /// Returns true if a complete update is necessary, otherwise false
214         bool SetLeftLine(int cell, bool line, bool onlycolumn = false);
215         /// Returns true if a complete update is necessary, otherwise false
216         bool SetRightLine(int cell, bool line, bool onlycolumn = false);
217         /// Returns true if a complete update is necessary, otherwise false
218         bool SetAlignment(int cell, LyXAlignment align,
219                           bool onlycolumn = false);
220         /// Returns true if a complete update is necessary, otherwise false
221         bool SetVAlignment(int cell, VAlignment align,
222                            bool onlycolumn = false);
223         ///
224         bool SetColumnPWidth(int cell, string const & width);
225         ///
226         bool SetMColumnPWidth(int cell, string const & width);
227         ///
228         bool SetAlignSpecial(int cell, string const & special, Feature what);
229         ///
230         LyXAlignment GetAlignment(int cell, bool onlycolumn = false) const;
231         ///
232         VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
233         ///
234         string const GetPWidth(int cell) const;
235         ///
236         string const GetColumnPWidth(int cell) const;
237         ///
238         string const GetMColumnPWidth(int cell) const;
239         ///
240         string const GetAlignSpecial(int cell, int what) const;
241         ///
242         int GetWidthOfCell(int cell) const;
243         ///
244         int GetBeginningOfTextInCell(int cell) const;
245         ///
246         void AppendRow(int cell);
247         ///
248         void DeleteRow(int row);
249         ///
250         void AppendColumn(int cell);
251         ///
252         void DeleteColumn(int column);
253         ///
254         bool IsFirstCellInRow(int cell) const;
255         ///
256         int GetFirstCellInRow(int row) const;
257         ///
258         bool IsLastCellInRow(int cell) const;
259         ///
260         int GetLastCellInRow(int row) const;
261         ///
262         int GetNumberOfCells() const;
263         ///
264         int NumberOfCellsInRow(int cell) const;
265         ///
266         void Write(Buffer const *, std::ostream &) const;
267         ///
268         void Read(Buffer const *, LyXLex &);
269         ///
270         void OldFormatRead(LyXLex &, string const &);
271         //
272         // helper function for Latex returns number of newlines
273         ///
274         int TeXTopHLine(std::ostream &, int row) const;
275         ///
276         int TeXBottomHLine(std::ostream &, int row) const;
277         ///
278         int TeXCellPreamble(std::ostream &, int cell) const;
279         ///
280         int TeXCellPostamble(std::ostream &, int cell) const;
281         ///
282         int Latex(Buffer const *, std::ostream &, bool, bool) const;
283         ///
284         int DocBook(Buffer const * buf, std::ostream & os) const;
285         ///
286         // helper function for Latex returns number of newlines
287         ///
288         int AsciiTopHLine(std::ostream &, int row,
289                           std::vector<unsigned int> const &) const;
290         ///
291         int AsciiBottomHLine(std::ostream &, int row,
292                              std::vector<unsigned int> const &) const;
293         ///
294         int AsciiPrintCell(Buffer const *, std::ostream &,
295                            int cell, int row, int column,
296                            std::vector<unsigned int> const &) const;
297         ///
298         int Ascii(Buffer const *, std::ostream &) const;
299         ///
300         bool IsMultiColumn(int cell, bool real = false) const;
301         ///
302         void SetMultiColumn(int cell, int number);
303         ///
304         int UnsetMultiColumn(int cell); // returns number of new cells
305         ///
306         bool IsPartOfMultiColumn(int row, int column) const;
307         ///
308         int row_of_cell(int cell) const;
309         ///
310         int column_of_cell(int cell) const;
311         ///
312         int right_column_of_cell(int cell) const;
313         ///
314         void SetLongTabular(bool);
315         ///
316         bool IsLongTabular() const;
317         ///
318         void SetRotateTabular(bool);
319         ///
320         bool GetRotateTabular() const;
321         ///
322         void SetRotateCell(int cell, bool);
323         ///
324         bool GetRotateCell(int cell) const;
325         ///
326         bool NeedRotating() const;
327         ///
328         bool IsLastCell(int cell) const;
329         ///
330         int GetCellAbove(int cell) const;
331         ///
332         int GetCellBelow(int cell) const;
333         ///
334         int GetLastCellAbove(int cell) const;
335         ///
336         int GetLastCellBelow(int cell) const;
337         ///
338         int GetCellNumber(int row, int column) const;
339         ///
340         void SetUsebox(int cell, BoxType);
341         ///
342         BoxType GetUsebox(int cell) const;
343         //
344         // Long Tabular Options
345         ///
346         void SetLTHead(int cell, bool first);
347         ///
348         bool GetRowOfLTHead(int cell, int & row) const;
349         ///
350         bool GetRowOfLTFirstHead(int cell, int & row) const;
351         ///
352         void SetLTFoot(int cell, bool last);
353         ///
354         bool GetRowOfLTFoot(int cell, int & row) const;
355         ///
356         bool GetRowOfLTLastFoot(int cell, int & row) const;
357         ///
358         void SetLTNewPage(int cell, bool what);
359         ///
360         bool GetLTNewPage(int cell) const;
361         ///
362         InsetText * GetCellInset(int cell) const;
363         ///
364         InsetText * GetCellInset(int row, int column) const;
365         ///
366         int rows() const { return rows_; }
367         ///
368         int columns() const { return columns_;}
369         ///
370         InsetTabular * owner() const { return owner_; }
371         ///
372         void Validate(LaTeXFeatures &) const;
373         ///
374         std::vector<string> const getLabelList() const;
375 private:
376         ///
377         struct cellstruct {
378                 ///
379                 cellstruct();
380                 ///
381                 int cellno;
382                 ///
383                 int width_of_cell;
384                 ///
385                 int multicolumn;
386                 ///
387                 LyXAlignment alignment;
388                 ///
389                 VAlignment valignment;
390                 ///
391                 bool top_line;
392                 ///
393                 bool bottom_line;
394                 ///
395                 bool left_line;
396                 ///
397                 bool right_line;
398                 ///
399                 BoxType usebox;
400                 ///
401                 bool rotate;
402                 ///
403                 string align_special;
404                 ///
405                 string p_width; // this is only set for multicolumn!!!
406                 ///
407                 InsetText inset;
408         };
409         ///
410         typedef std::vector<cellstruct> cell_vector;
411         ///
412         typedef std::vector<cell_vector> cell_vvector;
413
414         ///
415         struct rowstruct {
416                 ///
417                 rowstruct();
418                 ///
419                 bool top_line;
420                 ///
421                 bool bottom_line;
422                 ///
423                 int ascent_of_row;
424                 ///
425                 int descent_of_row;
426                 /// This are for longtabulars only
427                 bool newpage;
428         };
429         ///
430         typedef std::vector<rowstruct> row_vector;
431
432         ///
433         struct columnstruct {
434                 ///
435                 columnstruct();
436                 ///
437                 LyXAlignment alignment;
438                 ///
439                 VAlignment valignment;
440                 ///
441                 bool left_line;
442                 ///
443                 bool right_line;
444                 ///
445                 int  width_of_column;
446                 ///
447                 string p_width;
448                 ///
449                 string align_special;
450         };
451         ///
452         typedef std::vector<columnstruct> column_vector;
453
454         ///
455         void ReadNew(Buffer const * buf, std::istream & is,
456                                  LyXLex & lex, string const & l);
457         ///
458         void ReadOld(Buffer const * buf, std::istream & is,
459                                  LyXLex & lex, string const & l);
460         ///
461         int rows_;
462         ///
463         int columns_;
464         ///
465         int numberofcells;
466         ///
467         std::vector<int> rowofcell;
468         ///
469         std::vector<int> columnofcell;
470         ///
471         row_vector row_info;
472         ///
473         column_vector column_info;
474         ///
475         mutable cell_vvector cell_info;
476         ///
477         int width_of_tabular;
478         ///
479         bool rotate;
480         //
481         // for long tabulars
482         ///
483         bool is_long_tabular;
484         /// row of endhead
485         int endhead;
486         /// row of endfirsthead
487         int endfirsthead;
488         /// row of endfoot
489         int endfoot;
490         /// row of endlastfoot
491         int endlastfoot;
492         ///
493         InsetTabular * owner_;
494
495         ///
496         void Init(int columns_arg, int rows_arg);
497         ///
498         void Reinit();
499         ///
500         void set_row_column_number_info(bool oldformat = false);
501         /// Returns true if a complete update is necessary, otherwise false
502         bool SetWidthOfMulticolCell(int cell, int new_width);
503         ///
504         void recalculateMulticolCells(int cell, int new_width);
505         /// Returns true if change
506         bool calculate_width_of_column(int column);
507         ///
508         bool calculate_width_of_column_NMC(int column); // no multi cells
509         ///
510         void calculate_width_of_tabular();
511         ///
512         cellstruct * cellinfo_of_cell(int cell) const;
513         ///
514         void delete_column(int column);
515         ///
516         int cells_in_multicolumn(int cell) const;
517         ///
518         BoxType UseParbox(int cell) const;
519 };
520
521 #endif