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