]> git.lyx.org Git - lyx.git/blob - src/tabular.h
rowpainter.C: remove unused variables
[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 #include "lyxlength.h"
16 #include "insets/insettext.h"
17
18 #include <iosfwd>
19 #include <vector>
20
21 class InsetTabular;
22 class LatexRunParams;
23
24 /* The features the text class offers for tables */
25
26 ///
27 class LyXTabular  {
28 public:
29         ///
30         enum Feature {
31                 ///
32                 APPEND_ROW = 0,
33                 ///
34                 APPEND_COLUMN,
35                 ///
36                 DELETE_ROW,
37                 ///
38                 DELETE_COLUMN,
39                 ///
40                 TOGGLE_LINE_TOP,
41                 ///
42                 TOGGLE_LINE_BOTTOM,
43                 ///
44                 TOGGLE_LINE_LEFT,
45                 ///
46                 TOGGLE_LINE_RIGHT,
47                 ///
48                 ALIGN_LEFT,
49                 ///
50                 ALIGN_RIGHT,
51                 ///
52                 ALIGN_CENTER,
53                 ///
54                 ALIGN_BLOCK,
55                 ///
56                 VALIGN_TOP,
57                 ///
58                 VALIGN_BOTTOM,
59                 ///
60                 VALIGN_CENTER,
61                 ///
62                 M_TOGGLE_LINE_TOP,
63                 ///
64                 M_TOGGLE_LINE_BOTTOM,
65                 ///
66                 M_TOGGLE_LINE_LEFT,
67                 ///
68                 M_TOGGLE_LINE_RIGHT,
69                 ///
70                 M_ALIGN_LEFT,
71                 ///
72                 M_ALIGN_RIGHT,
73                 ///
74                 M_ALIGN_CENTER,
75                 ///
76                 M_VALIGN_TOP,
77                 ///
78                 M_VALIGN_BOTTOM,
79                 ///
80                 M_VALIGN_CENTER,
81                 ///
82                 MULTICOLUMN,
83                 ///
84                 SET_ALL_LINES,
85                 ///
86                 UNSET_ALL_LINES,
87                 ///
88                 SET_LONGTABULAR,
89                 ///
90                 UNSET_LONGTABULAR,
91                 ///
92                 SET_PWIDTH,
93                 ///
94                 SET_MPWIDTH,
95                 ///
96                 SET_ROTATE_TABULAR,
97                 ///
98                 UNSET_ROTATE_TABULAR,
99                 ///
100                 SET_ROTATE_CELL,
101                 ///
102                 UNSET_ROTATE_CELL,
103                 ///
104                 SET_USEBOX,
105                 ///
106                 SET_LTHEAD,
107                 UNSET_LTHEAD,
108                 ///
109                 SET_LTFIRSTHEAD,
110                 UNSET_LTFIRSTHEAD,
111                 ///
112                 SET_LTFOOT,
113                 UNSET_LTFOOT,
114                 ///
115                 SET_LTLASTFOOT,
116                 UNSET_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         struct ltType {
156                 // constructor
157                 ltType();
158                 // we have this header type (is set in the getLT... functions)
159                 bool set;
160                 // double borders on top
161                 bool topDL;
162                 // double borders on bottom
163                 bool bottomDL;
164                 // used for FirstHeader & LastFooter and if this is true
165                 // all the rows marked as FirstHeader or LastFooter are
166                 // ignored in the output and it is set to be empty!
167                 bool empty;
168         };
169
170         /// constructor
171         LyXTabular(BufferParams const &,
172                    InsetTabular *, int columns_arg, int rows_arg);
173         /// sort of copy constructor
174         LyXTabular(BufferParams const &,
175                    InsetTabular *, LyXTabular const &);
176         ///
177         explicit
178         LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
179
180         /// Returns true if there is a topline, returns false if not
181         bool topLine(int cell, bool onlycolumn = false) const;
182         /// Returns true if there is a topline, returns false if not
183         bool bottomLine(int cell, bool onlycolumn = false) const;
184         /// Returns true if there is a topline, returns false if not
185         bool leftLine(int cell, bool onlycolumn = false) const;
186         /// Returns true if there is a topline, returns false if not
187         bool rightLine(int cell, bool onlycolumn = false) const;
188
189         ///
190         bool topAlreadyDrawn(int cell) const;
191         ///
192         bool leftAlreadyDrawn(int cell) const;
193         ///
194         bool isLastRow(int cell) const;
195
196         ///
197         int getAdditionalHeight(int row) const;
198         ///
199         int getAdditionalWidth(int cell) const;
200
201         /* returns the maximum over all rows */
202         ///
203         int getWidthOfColumn(int cell) const;
204         ///
205         int getWidthOfTabular() const;
206         ///
207         int getAscentOfRow(int row) const;
208         ///
209         int getDescentOfRow(int row) const;
210         ///
211         int getHeightOfTabular() const;
212         /// Returns true if a complete update is necessary, otherwise false
213         bool setAscentOfRow(int row, int height);
214         /// Returns true if a complete update is necessary, otherwise false
215         bool setDescentOfRow(int row, int height);
216         /// Returns true if a complete update is necessary, otherwise false
217         bool setWidthOfCell(int cell, int new_width);
218         ///
219         void setAllLines(int cell, bool line);
220         ///
221         void setTopLine(int cell, bool line, bool onlycolumn = false);
222         ///
223         void setBottomLine(int cell, bool line, bool onlycolumn = false);
224         ///
225         void setLeftLine(int cell, bool line, bool onlycolumn = false);
226         ///
227         void setRightLine(int cell, bool line, bool onlycolumn = false);
228         /// 
229         void setAlignment(int cell, LyXAlignment align,
230                           bool onlycolumn = false);
231         /// 
232         void setVAlignment(int cell, VAlignment align,
233                            bool onlycolumn = false);
234         ///
235         void setColumnPWidth(int cell, LyXLength const & width);
236         ///
237         bool setMColumnPWidth(int cell, LyXLength const & width);
238         ///
239         void setAlignSpecial(int cell, string const & special, Feature what);
240         ///
241         LyXAlignment getAlignment(int cell, bool onlycolumn = false) const;
242         ///
243         VAlignment getVAlignment(int cell, bool onlycolumn = false) const;
244         ///
245         LyXLength const getPWidth(int cell) const;
246         ///
247         LyXLength const getColumnPWidth(int cell) const;
248         ///
249         LyXLength const getMColumnPWidth(int cell) const;
250         ///
251         string const getAlignSpecial(int cell, int what) const;
252         ///
253         int getWidthOfCell(int cell) const;
254         ///
255         int getBeginningOfTextInCell(int cell) const;
256         ///
257         void appendRow(BufferParams const &, int cell);
258         ///
259         void deleteRow(int row);
260         ///
261         void appendColumn(BufferParams const &, int cell);
262         ///
263         void deleteColumn(int column);
264         ///
265         bool isFirstCellInRow(int cell) const;
266         ///
267         int getFirstCellInRow(int row) const;
268         ///
269         bool isLastCellInRow(int cell) const;
270         ///
271         int getLastCellInRow(int row) const;
272         ///
273         int getNumberOfCells() const;
274         ///
275         int numberOfCellsInRow(int cell) const;
276         ///
277         void write(Buffer const *, std::ostream &) const;
278         ///
279         void read(Buffer const *, LyXLex &);
280         ///
281         int latex(Buffer const *, std::ostream &,
282                   LatexRunParams const &) const;
283         ///
284         int docbook(Buffer const * buf, std::ostream & os, bool mixcont) const;
285         ///
286         int ascii(Buffer const *, std::ostream &, int const depth,
287                   bool onlydata, unsigned char delim) const;
288         ///
289         bool isMultiColumn(int cell, bool real = false) const;
290         ///
291         void setMultiColumn(Buffer *, int cell, int number);
292         ///
293         int unsetMultiColumn(int cell); // returns number of new cells
294         ///
295         bool isPartOfMultiColumn(int row, int column) const;
296         ///
297         int row_of_cell(int cell) const;
298         ///
299         int column_of_cell(int cell) const;
300         ///
301         int right_column_of_cell(int cell) const;
302         ///
303         void setLongTabular(bool);
304         ///
305         bool isLongTabular() const;
306         ///
307         void setRotateTabular(bool);
308         ///
309         bool getRotateTabular() const;
310         ///
311         void setRotateCell(int cell, bool);
312         ///
313         bool getRotateCell(int cell) const;
314         ///
315         bool needRotating() const;
316         ///
317         bool isLastCell(int cell) const;
318         ///
319         int getCellAbove(int cell) const;
320         ///
321         int getCellBelow(int cell) const;
322         ///
323         int getLastCellAbove(int cell) const;
324         ///
325         int getLastCellBelow(int cell) const;
326         ///
327         int getCellNumber(int row, int column) const;
328         ///
329         void setUsebox(int cell, BoxType);
330         ///
331         BoxType getUsebox(int cell) const;
332         //
333         // Long Tabular Options support functions
334         ///
335         bool checkLTType(int row, ltType const &) const;
336         ///
337         void setLTHead(int row, bool flag, ltType const &, bool first);
338         ///
339         bool getRowOfLTHead(int row, ltType &) const;
340         ///
341         bool getRowOfLTFirstHead(int row, ltType &) const;
342         ///
343         void setLTFoot(int row, bool flag, ltType const &, bool last);
344         ///
345         bool getRowOfLTFoot(int row, ltType &) const;
346         ///
347         bool getRowOfLTLastFoot(int row, ltType &) const;
348         ///
349         void setLTNewPage(int row, bool what);
350         ///
351         bool getLTNewPage(int row) const;
352         ///
353         bool haveLTHead() const;
354         ///
355         bool haveLTFirstHead() const;
356         ///
357         bool haveLTFoot() const;
358         ///
359         bool haveLTLastFoot() const;
360         ///
361         // end longtable support
362         ///
363         InsetText & getCellInset(int cell) const;
364         ///
365         InsetText & getCellInset(int row, int column) const;
366         /// Search for \param inset in the tabular, with the
367         /// additional hint that it could be at \param maybe_cell
368         int getCellFromInset(Inset const * inset, int maybe_cell = -1) const;
369         ///
370         int rows() const { return rows_; }
371         ///
372         int columns() const { return columns_;}
373         ///
374         void validate(LaTeXFeatures &) const;
375         ///
376         void getLabelList(std::vector<string> &) const;
377         ///
378         /// recalculate the widths/heights only!
379         void reinit();
380         ///
381 //private:
382         ///
383         mutable int cur_cell;
384         ///
385         struct cellstruct {
386                 ///
387                 cellstruct(BufferParams const &);
388                 ///
389                 int cellno;
390                 ///
391                 int width_of_cell;
392                 ///
393                 int multicolumn;
394                 ///
395                 LyXAlignment alignment;
396                 ///
397                 VAlignment valignment;
398                 ///
399                 bool top_line;
400                 ///
401                 bool bottom_line;
402                 ///
403                 bool left_line;
404                 ///
405                 bool right_line;
406                 ///
407                 BoxType usebox;
408                 ///
409                 bool rotate;
410                 ///
411                 string align_special;
412                 ///
413                 LyXLength p_width; // this is only set for multicolumn!!!
414                 ///
415                 InsetText inset;
416         };
417         cellstruct & cellinfo_of_cell(int cell) const;
418         ///
419         typedef std::vector<cellstruct> cell_vector;
420         ///
421         typedef std::vector<cell_vector> cell_vvector;
422
423         ///
424         struct rowstruct {
425                 ///
426                 rowstruct();
427                 ///
428                 int ascent_of_row;
429                 ///
430                 int descent_of_row;
431                 ///
432                 bool top_line;
433                 ///
434                 bool bottom_line;
435                 /// This are for longtabulars only
436                 /// a row of endhead
437                 bool endhead;
438                 /// a row of endfirsthead
439                 bool endfirsthead;
440                 /// a row of endfoot
441                 bool endfoot;
442                 /// row of endlastfoot
443                 bool endlastfoot;
444                 /// row for a pagebreak
445                 bool newpage;
446         };
447         ///
448         typedef std::vector<rowstruct> row_vector;
449
450         ///
451         struct columnstruct {
452                 ///
453                 columnstruct();
454                 ///
455                 LyXAlignment alignment;
456                 ///
457                 VAlignment valignment;
458                 ///
459                 bool left_line;
460                 ///
461                 bool right_line;
462                 ///
463                 int  width_of_column;
464                 ///
465                 LyXLength p_width;
466                 ///
467                 string align_special;
468         };
469         ///
470         typedef std::vector<columnstruct> column_vector;
471
472         ///
473         int rows_;
474         ///
475         int columns_;
476         ///
477         int numberofcells;
478         ///
479         std::vector<int> rowofcell;
480         ///
481         std::vector<int> columnofcell;
482         ///
483         row_vector row_info;
484         ///
485         column_vector column_info;
486         ///
487         mutable cell_vvector cell_info;
488         ///
489         int width_of_tabular;
490         ///
491         bool rotate;
492         //
493         // for long tabulars
494         //
495         bool is_long_tabular;
496         /// endhead data
497         ltType endhead;
498         /// endfirsthead data
499         ltType endfirsthead;
500         /// endfoot data
501         ltType endfoot;
502         /// endlastfoot data
503         ltType endlastfoot;
504         //
505         ///
506         InsetTabular * owner_;
507
508         ///
509         void init(BufferParams const &,
510                   int columns_arg, int rows_arg, LyXTabular const * lt = 0);
511         ///
512         void Reinit(bool reset_widths = true);
513         ///
514         void set_row_column_number_info(bool oldformat = false);
515         /// Returns true if a complete update is necessary, otherwise false
516         bool setWidthOfMulticolCell(int cell, int new_width);
517         ///
518         void recalculateMulticolumnsOfColumn(int column);
519         /// Returns true if change
520         void calculate_width_of_column(int column);
521         ///
522         bool calculate_width_of_column_NMC(int column); // no multi cells
523         ///
524         void calculate_width_of_tabular();
525         ///
526         void delete_column(int column);
527         ///
528         int cells_in_multicolumn(int cell) const;
529         ///
530         BoxType useParbox(int cell) const;
531         ///
532         void setHeaderFooterRows(int header, int fheader, int footer, int lfooter);
533         ///
534         // helper function for Latex returns number of newlines
535         ///
536         int TeXTopHLine(std::ostream &, int row) const;
537         ///
538         int TeXBottomHLine(std::ostream &, int row) const;
539         ///
540         int TeXCellPreamble(std::ostream &, int cell) const;
541         ///
542         int TeXCellPostamble(std::ostream &, int cell) const;
543         ///
544         int TeXLongtableHeaderFooter(std::ostream &, Buffer const * buf,
545                                      LatexRunParams const &) const;
546         ///
547         bool isValidRow(int const row) const;
548         ///
549         int TeXRow(std::ostream &, int const row, Buffer const * buf,
550                    LatexRunParams const &) const;
551         ///
552         // helper function for ASCII returns number of newlines
553         ///
554         int asciiTopHLine(std::ostream &, int row,
555                           std::vector<unsigned int> const &) const;
556         ///
557         int asciiBottomHLine(std::ostream &, int row,
558                              std::vector<unsigned int> const &) const;
559         ///
560         int asciiPrintCell(Buffer const *, std::ostream &,
561                            int cell, int row, int column,
562                            std::vector<unsigned int> const &,
563                                            bool onlydata) const;
564         /// auxiliary function for docbook
565         int docbookRow(Buffer const * buf, std::ostream & os, int row) const;
566 };
567
568 #endif