]> git.lyx.org Git - lyx.git/blob - src/insets/InsetTabular.h
Support non-default styles in multirow
[lyx.git] / src / insets / InsetTabular.h
1 // -*- C++ -*-
2 /**
3  * \file InsetTabular.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Matthias Ettrich
9  * \author André Pönitz
10  * \author Jürgen Vigna
11  * \author Edwin Leuven
12  * \author Uwe Stöhr
13  * \author Scott Kostyshak
14  *
15  * Full author contact details are available in file CREDITS.
16  */
17
18 // Things to think of when designing the new tabular support:
19 // - color support (colortbl, color)
20 // - decimal alignment (dcloumn)
21 // - custom lines (hhline)
22 // - column styles
23
24 #ifndef INSET_TABULAR_H
25 #define INSET_TABULAR_H
26
27 #include "Changes.h"
28 #include "InsetText.h"
29
30 #include "support/Length.h"
31 #include "support/types.h"
32
33 #include <climits>
34 #include <iosfwd>
35 #include <memory>
36 #include <vector>
37
38
39 namespace lyx {
40
41 class Buffer;
42 class BufferView;
43 class CompletionList;
44 class Cursor;
45 class CursorSlice;
46 class FuncStatus;
47 class Lexer;
48 class OutputParams;
49 class XMLStream;
50
51
52 ///
53 class InsetTableCell : public InsetText
54 {
55 public:
56         ///
57         explicit InsetTableCell(Buffer * buf);
58         /// We need this since generation of the default is deprecated
59         /// (since we declare the assignment constuctor below).
60         InsetTableCell(InsetTableCell const & in) = default;
61         ///
62         InsetCode lyxCode() const override { return CELL_CODE; }
63         ///
64         Inset * clone() const override { return new InsetTableCell(*this); }
65         ///
66         bool getStatus(Cursor & cur, FuncRequest const & cmd,
67                 FuncStatus & status) const override;
68         ///
69         void toggleFixedWidth(bool fw) { isFixedWidth = fw; }
70         ///
71         void toggleMultiCol(bool m) { isMultiColumn = m; }
72         ///
73         void toggleMultiRow(bool m) { isMultiRow = m; }
74         ///
75         void setContentAlignment(LyXAlignment al) {contentAlign = al; }
76         /// writes the contents of the cell as a string, optionally
77         /// descending into insets
78         docstring asString(bool intoInsets = true);
79         ///
80         docstring xhtml(XMLStream &, OutputParams const &) const override;
81         ///
82         void docbook(XMLStream &, OutputParams const &) const override;
83         ///
84         void addToToc(DocIterator const & di, bool output_active,
85                                   UpdateType utype, TocBackend & backend) const override;
86         ///
87         void metrics(MetricsInfo &, Dimension &) const override;
88         /// Needs to be same as InsetTabular
89         bool inheritFont() const override { return false; }
90         /// Can the cell contain several paragraphs?
91         bool allowMultiPar() const override { return !isMultiRow && (!isMultiColumn || isFixedWidth); }
92         ///
93         bool canPaintChange(BufferView const &) const override { return false; }
94 private:
95         ///
96         InsetTableCell() = delete;
97         ///
98         void operator=(InsetTableCell const &) = delete;
99         // FIXME
100         // These booleans are supposed to track whether the cell has had its
101         // width explicitly set and whether it is part of a multicolumn, respectively.
102         // We need to know this to determine whether
103         // layout changes and paragraph customization are allowed---that is,
104         // we need it in forcePlainLayout() and allowParagraphCustomization().
105         // Unfortunately, that information is not readily available in
106         // InsetTableCell. In the case of multicolumn cells, it is present
107         // in CellData, and so would be available here if CellData were to
108         // become a member of InsetTableCell. But in the other case, it isn't
109         // even available there, but is held in Tabular::ColumnData.
110         // So, the present solution uses this boolean to track the information
111         // we need to track, and tries to keep it updated. This is not ideal,
112         // but the other solutions are no better. These are:
113         // (i)  Keep a pointer in InsetTableCell to the table;
114         // (ii) Find the table by iterating over the Buffer's insets.
115         // Solution (i) raises the problem of updating the pointer when an
116         // InsetTableCell is copied, and we'd therefore need a copy constructor
117         // in InsetTabular and then in Tabular, which seems messy, given how
118         // complicated those classes are. Solution (ii) involves a lot of
119         // iterating, since this information is needed quite often, and so may
120         // be quite slow.
121         // So, well, if someone can do better, please do!
122         // --rkh
123         ///
124         bool isFixedWidth;
125         ///
126         bool isMultiColumn;
127         ///
128         bool isMultiRow;
129         // FIXME: Here the thoughts from the comment above also apply.
130         ///
131         LyXAlignment contentAlign;
132         /// should paragraph indentation be omitted in any case?
133         bool neverIndent() const override { return true; }
134         ///
135         LyXAlignment contentAlignment() const override { return contentAlign; }
136         ///
137         bool usePlainLayout() const override { return true; }
138         ///
139         bool allowParagraphCustomization(idx_type = 0) const override;
140         ///
141         bool forceLocalFontSwitch() const override;
142         /// Is the width forced to some value?
143         bool hasFixedWidth() const override { return isFixedWidth; }
144 };
145
146
147 //
148 // A helper struct for tables
149 //
150 class Tabular {
151 public:
152         ///
153         enum Feature {
154                 ///
155                 APPEND_ROW = 0,
156                 ///
157                 APPEND_COLUMN,
158                 ///
159                 DELETE_ROW,
160                 ///
161                 DELETE_COLUMN,
162                 ///
163                 COPY_ROW,
164                 ///
165                 COPY_COLUMN,
166                 ///
167                 MOVE_COLUMN_RIGHT,
168                 ///
169                 MOVE_COLUMN_LEFT,
170                 ///
171                 MOVE_ROW_DOWN,
172                 ///
173                 MOVE_ROW_UP,
174                 ///
175                 SET_LINE_TOP,
176                 ///
177                 SET_LINE_BOTTOM,
178                 ///
179                 SET_LINE_LEFT,
180                 ///
181                 SET_LINE_RIGHT,
182                 ///FIXME: remove
183                 TOGGLE_LINE_TOP,
184                 ///FIXME: remove
185                 TOGGLE_LINE_BOTTOM,
186                 ///FIXME: remove
187                 TOGGLE_LINE_LEFT,
188                 ///FIXME: remove
189                 TOGGLE_LINE_RIGHT,
190                 ///
191                 SET_LTRIM_TOP,
192                 ///
193                 SET_RTRIM_TOP,
194                 ///
195                 SET_LTRIM_BOTTOM,
196                 ///
197                 SET_RTRIM_BOTTOM,
198                 ///
199                 TOGGLE_LTRIM_TOP,
200                 ///
201                 TOGGLE_RTRIM_TOP,
202                 ///
203                 TOGGLE_LTRIM_BOTTOM,
204                 ///
205                 TOGGLE_RTRIM_BOTTOM,
206                 ///
207                 ALIGN_LEFT,
208                 ///
209                 ALIGN_RIGHT,
210                 ///
211                 ALIGN_CENTER,
212                 ///
213                 ALIGN_BLOCK,
214                 ///
215                 ALIGN_DECIMAL,
216                 ///
217                 VALIGN_TOP,
218                 ///
219                 VALIGN_BOTTOM,
220                 ///
221                 VALIGN_MIDDLE,
222                 ///
223                 M_ALIGN_LEFT,
224                 ///
225                 M_ALIGN_RIGHT,
226                 ///
227                 M_ALIGN_CENTER,
228                 ///
229                 M_VALIGN_TOP,
230                 ///
231                 M_VALIGN_BOTTOM,
232                 ///
233                 M_VALIGN_MIDDLE,
234                 ///
235                 MULTICOLUMN,
236                 ///
237                 SET_MULTICOLUMN,
238                 ///
239                 UNSET_MULTICOLUMN,
240                 ///
241                 MULTIROW,
242                 ///
243                 SET_MULTIROW,
244                 ///
245                 UNSET_MULTIROW,
246                 ///
247                 SET_MROFFSET,
248                 ///
249                 SET_ALL_LINES,
250                 ///
251                 RESET_FORMAL_DEFAULT,
252                 ///
253                 UNSET_ALL_LINES,
254                 ///
255                 TOGGLE_LONGTABULAR,
256                 ///
257                 SET_LONGTABULAR,
258                 ///
259                 UNSET_LONGTABULAR,
260                 ///
261                 SET_PWIDTH,
262                 ///
263                 SET_MPWIDTH,
264                 ///
265                 TOGGLE_VARWIDTH_COLUMN,
266                 ///
267                 SET_ROTATE_TABULAR,
268                 ///
269                 UNSET_ROTATE_TABULAR,
270                 ///
271                 TOGGLE_ROTATE_TABULAR,
272                 ///
273                 SET_ROTATE_CELL,
274                 ///
275                 UNSET_ROTATE_CELL,
276                 ///
277                 TOGGLE_ROTATE_CELL,
278                 ///
279                 SET_USEBOX,
280                 ///
281                 SET_LTHEAD,
282                 UNSET_LTHEAD,
283                 ///
284                 SET_LTFIRSTHEAD,
285                 UNSET_LTFIRSTHEAD,
286                 ///
287                 SET_LTFOOT,
288                 UNSET_LTFOOT,
289                 ///
290                 SET_LTLASTFOOT,
291                 UNSET_LTLASTFOOT,
292                 ///
293                 SET_LTNEWPAGE,
294                 UNSET_LTNEWPAGE,
295                 ///
296                 TOGGLE_LTCAPTION,
297                 ///
298                 SET_LTCAPTION,
299                 ///
300                 UNSET_LTCAPTION,
301                 ///
302                 SET_SPECIAL_COLUMN,
303                 ///
304                 SET_SPECIAL_MULTICOLUMN,
305                 ///
306                 TOGGLE_BOOKTABS,
307                 ///
308                 SET_BOOKTABS,
309                 ///
310                 UNSET_BOOKTABS,
311                 ///
312                 SET_TOP_SPACE,
313                 ///
314                 SET_BOTTOM_SPACE,
315                 ///
316                 SET_INTERLINE_SPACE,
317                 ///
318                 SET_BORDER_LINES,
319                 ///
320                 TABULAR_VALIGN_TOP,
321                 ///
322                 TABULAR_VALIGN_MIDDLE,
323                 ///
324                 TABULAR_VALIGN_BOTTOM,
325                 ///
326                 LONGTABULAR_ALIGN_LEFT,
327                 ///
328                 LONGTABULAR_ALIGN_CENTER,
329                 ///
330                 LONGTABULAR_ALIGN_RIGHT,
331                 ///
332                 SET_DECIMAL_POINT,
333                 ///
334                 SET_TABULAR_WIDTH,
335                 ///
336                 SET_INNER_LINES,
337                 ///
338                 LAST_ACTION
339         };
340         ///
341         enum {
342                 ///
343                 CELL_NORMAL = 0,
344                 ///
345                 CELL_BEGIN_OF_MULTICOLUMN,
346                 ///
347                 CELL_PART_OF_MULTICOLUMN,
348                 ///
349                 CELL_BEGIN_OF_MULTIROW,
350                 ///
351                 CELL_PART_OF_MULTIROW
352         };
353
354         ///
355         enum VAlignment {
356                 ///
357                 LYX_VALIGN_TOP = 0,
358                 ///
359                 LYX_VALIGN_MIDDLE = 1,
360                 ///
361                 LYX_VALIGN_BOTTOM = 2
362
363         };
364         ///
365         enum HAlignment {
366                 ///
367                 LYX_LONGTABULAR_ALIGN_LEFT = 0,
368                 ///
369                 LYX_LONGTABULAR_ALIGN_CENTER = 1,
370                 ///
371                 LYX_LONGTABULAR_ALIGN_RIGHT = 2
372         };
373
374         enum BoxType {
375                 ///
376                 BOX_NONE = 0,
377                 ///
378                 BOX_PARBOX = 1,
379                 ///
380                 BOX_MINIPAGE = 2,
381                 ///
382                 BOX_VARWIDTH = 3
383         };
384
385         enum CaptionType {
386                 ///
387                 CAPTION_FIRSTHEAD,
388                 ///
389                 CAPTION_HEAD,
390                 ///
391                 CAPTION_FOOT,
392                 ///
393                 CAPTION_LASTFOOT,
394                 ///
395                 CAPTION_ANY
396         };
397
398         enum RowDirection {
399                 UP,
400                 DOWN
401         };
402
403         enum ColDirection {
404                 RIGHT,
405                 LEFT
406         };
407
408         class ltType {
409         public:
410                 // constructor
411                 ltType();
412                 // we have this header type (is set in the getLT... functions)
413                 bool set;
414                 // double borders on top
415                 bool topDL;
416                 // double borders on bottom
417                 bool bottomDL;
418                 // used for FirstHeader & LastFooter and if this is true
419                 // all the rows marked as FirstHeader or LastFooter are
420                 // ignored in the output and it is set to be empty!
421                 bool empty;
422         };
423
424         /// index indicating an invalid position
425         static const idx_type npos = static_cast<idx_type>(-1);
426
427         /// constructor
428         Tabular(Buffer * buf, col_type columns_arg, row_type rows_arg);
429
430         /// Returns true if there is a topline, returns false if not
431         bool topLine(idx_type cell) const;
432         /// Returns true if there is a topline, returns false if not
433         bool bottomLine(idx_type cell) const;
434         /// Returns true if there is a topline, returns false if not
435         /// If \p ignore_bt is true, we return the state as if booktabs was
436         /// not used
437         bool leftLine(idx_type cell, bool const ignore_bt = false) const;
438         /// Returns true if there is a topline, returns false if not
439         /// If \p ignore_bt is true, we return the state as if booktabs was
440         /// not used
441         bool rightLine(idx_type cell, bool const ignore_bt = false) const;
442         /// Returns whether the top line is trimmed left and/or right
443         std::pair<bool, bool> topLineTrim(idx_type const cell) const;
444         /// Returns whether the bottom line is trimmed left and/or right
445         std::pair<bool, bool> bottomLineTrim(idx_type const cell) const;
446
447         /// return space occupied by the second horizontal line and
448         /// interline space above row \p row in pixels
449         int interRowSpace(row_type row) const;
450         ///
451         int interColumnSpace(idx_type cell) const;
452
453         /* returns the maximum over all rows */
454         ///
455         int cellWidth(idx_type cell) const;
456         ///
457         int cellHeight(idx_type cell) const;
458         ///
459         int width() const;
460         ///
461         int height() const;
462         ///
463         row_type nrows() const {return row_info.size();}
464         ///
465         col_type ncols() const {return column_info.size();}
466         ///
467         int rowAscent(row_type row) const;
468         ///
469         int rowDescent(row_type row) const;
470         ///
471         void setRowAscent(row_type row, int height);
472         ///
473         void setRowDescent(row_type row, int height);
474         ///
475         void setTopLine(idx_type cell, bool line);
476         ///
477         void setBottomLine(idx_type cell, bool line);
478         ///
479         void setTopLineLTrim(idx_type cell, bool val);
480         ///
481         void setBottomLineLTrim(idx_type cell, bool val);
482         ///
483         void setTopLineRTrim(idx_type cell, bool val);
484         ///
485         void setBottomLineRTrim(idx_type cell, bool val);
486         ///
487         void setTopLineTrim(idx_type cell, std::pair<bool, bool>);
488         ///
489         void setBottomLineTrim(idx_type cell, std::pair<bool, bool>);
490         ///
491         void setLeftLine(idx_type cell, bool line);
492         ///
493         void setRightLine(idx_type cell, bool line);
494         ///
495         bool rowTopLine(row_type row) const;
496         ///
497         bool rowBottomLine(row_type row) const;
498         ///
499         bool columnLeftLine(col_type column) const;
500         ///
501         bool columnRightLine(col_type column) const;
502
503         void setAlignment(idx_type cell, LyXAlignment align,
504                           bool onlycolumn = false);
505         ///
506         void setVAlignment(idx_type cell, VAlignment align,
507                            bool onlycolumn = false);
508         ///
509         void setTabularWidth(Length const & l) { tabular_width = l; }
510         ///
511         Length tabularWidth() const { return tabular_width; }
512         ///
513         void setColumnPWidth(Cursor &, idx_type, Length const &);
514         ///
515         bool setMColumnPWidth(Cursor &, idx_type, Length const &);
516         ///
517         bool toggleVarwidth(idx_type, bool const);
518         ///
519         bool setMROffset(Cursor &, idx_type, Length const &);
520         ///
521         void setAlignSpecial(idx_type cell, docstring const & special,
522                              Feature what);
523         ///
524         LyXAlignment getAlignment(idx_type cell,
525                                   bool onlycolumn = false) const;
526         ///
527         VAlignment getVAlignment(idx_type cell,
528                                  bool onlycolumn = false) const;
529         /// The vertical offset of the table due to the vertical
530         /// alignment with respect to the baseline.
531         int offsetVAlignment() const;
532         ///
533         Length const getPWidth(idx_type cell) const;
534         ///
535         Length const getMROffset(idx_type cell) const;
536         ///
537         int textHOffset(idx_type cell) const;
538         ///
539         int textVOffset(idx_type cell) const;
540         ///
541         void appendRow(row_type row);
542         ///
543         void deleteRow(row_type row, bool const force = false);
544         ///
545         void copyRow(row_type row);
546         ///
547         void insertRow(row_type row, bool copy);
548         ///
549         void moveColumn(col_type col, ColDirection direction);
550         ///
551         void moveRow(row_type row, RowDirection direction);
552         ///
553         void appendColumn(col_type column);
554         ///
555         void deleteColumn(col_type column, bool const force = false);
556         ///
557         void copyColumn(col_type column);
558         ///
559         void insertColumn(col_type column, bool copy);
560         ///
561         idx_type getFirstCellInRow(row_type row, bool const ct = false) const;
562         ///
563         idx_type getLastCellInRow(row_type row, bool const ct = false) const;
564         ///
565         idx_type getFirstRow(bool const ct = false) const;
566         ///
567         idx_type getLastRow(bool const ct = false) const;
568         ///
569         idx_type numberOfCellsInRow(row_type row) const;
570         ///
571         void write(std::ostream &) const;
572         ///
573         void read(Lexer &);
574         ///
575         void latex(otexstream &, OutputParams const &) const;
576         /// serialise the table in DocBook, according to buffer parameters
577         void docbook(XMLStream &, OutputParams const &) const;
578         ///
579         docstring xhtml(XMLStream &, OutputParams const &) const;
580         ///
581         void plaintext(odocstringstream &,
582                        OutputParams const & runparams, int const depth,
583                        bool onlydata, char_type delim, size_t max_length = INT_MAX) const;
584         ///
585         bool isMultiColumn(idx_type cell) const;
586         ///
587         bool hasMultiColumn(col_type cell) const;
588         ///
589         bool hasVarwidthColumn() const;
590         ///
591         bool isVTypeColumn(col_type cell) const;
592         ///
593         idx_type setMultiColumn(Cursor & cur, idx_type cell, idx_type number,
594                              bool const right_border);
595         ///
596         void unsetMultiColumn(idx_type cell);
597         ///
598         bool isPartOfMultiColumn(row_type row, col_type column) const;
599         ///
600         bool isPartOfMultiRow(row_type row, col_type column) const;
601         ///
602         bool isMultiRow(idx_type cell) const;
603         ///
604         bool hasMultiRow(row_type r) const;
605         ///
606         idx_type setMultiRow(Cursor & cur, idx_type cell, idx_type number,
607                              bool const bottom_border,
608                              LyXAlignment const halign);
609         ///
610         void unsetMultiRow(idx_type cell);
611         ///
612         row_type cellRow(idx_type cell) const;
613         ///
614         col_type cellColumn(idx_type cell) const;
615         ///
616         void setRotateCell(idx_type cell, int);
617         ///
618         int getRotateCell(idx_type cell) const;
619         ///
620         bool needRotating() const;
621         ///
622         bool isLastCell(idx_type cell) const;
623         ///
624         idx_type cellAbove(idx_type cell) const;
625         ///
626         idx_type cellBelow(idx_type cell) const;
627         /// \return the index of the VISIBLE cell at row, column
628         /// this will be the same as the cell in the previous row,
629         /// e.g., if the cell is part of a multirow
630         idx_type cellIndex(row_type row, col_type column) const;
631         ///
632         void setUsebox(idx_type cell, BoxType);
633         ///
634         BoxType getUsebox(idx_type cell) const;
635         //
636         // Long Tabular Options support functions
637         ///
638         void setLTHead(row_type row, bool flag, ltType const &, bool first);
639         ///
640         bool getRowOfLTHead(row_type row, ltType &) const;
641         ///
642         bool getRowOfLTFirstHead(row_type row, ltType &) const;
643         ///
644         void setLTFoot(row_type row, bool flag, ltType const &, bool last);
645         ///
646         bool getRowOfLTFoot(row_type row, ltType &) const;
647         ///
648         bool getRowOfLTLastFoot(row_type row, ltType &) const;
649         ///
650         void setLTNewPage(row_type row, bool what);
651         ///
652         bool getLTNewPage(row_type row) const;
653         ///
654         idx_type setLTCaption(Cursor & cur, row_type row, bool what);
655         ///
656         bool ltCaption(row_type row) const;
657         ///
658         bool haveLTHead(bool withcaptions = true) const;
659         ///
660         bool haveLTFirstHead(bool withcaptions = true) const;
661         ///
662         bool haveLTFoot(bool withcaptions = true) const;
663         ///
664         bool haveLTLastFoot(bool withcaptions = true) const;
665         ///
666         bool haveLTCaption(CaptionType captiontype = CAPTION_ANY) const;
667         ///
668         // end longtable support
669
670         //@{
671         /// there is a subtle difference between these two methods.
672         ///   cellInset(r,c);
673         /// and
674         ///   cellInset(cellIndex(r,c));
675         /// can return different things. this is because cellIndex(r,c)
676         /// returns the VISIBLE cell at r,c, which may be the same as the
677         /// cell at the previous row or column, if we're dealing with some
678         /// multirow or multicell.
679         std::shared_ptr<InsetTableCell> cellInset(idx_type cell);
680         std::shared_ptr<InsetTableCell> cellInset(row_type row, col_type column);
681         InsetTableCell const * cellInset(idx_type cell) const;
682         //@}
683         ///
684         void setCellInset(row_type row, col_type column,
685                           std::shared_ptr<InsetTableCell>);
686         /// Search for \param inset in the tabular, with the
687         ///
688         void validate(LaTeXFeatures &) const;
689
690         //private:
691         // FIXME Now that cells have an InsetTableCell as their insets, rather
692         // than an InsetText, it'd be possible to reverse the relationship here,
693         // so that cell_vector was a vector<InsetTableCell> rather than a
694         // vector<CellData>, and an InsetTableCell had a CellData as a member,
695         // or perhaps just had its members as members.
696         ///
697         class CellData {
698         public:
699                 ///
700                 explicit CellData(Buffer *);
701                 ///
702                 CellData(CellData const &);
703                 ///
704                 CellData & operator=(CellData const &);
705                 ///
706                 idx_type cellno;
707                 ///
708                 int width;
709                 ///
710                 int multicolumn;
711                 ///
712                 int multirow;
713                 ///
714                 Length mroffset;
715                 ///
716                 LyXAlignment alignment;
717                 ///
718                 VAlignment valignment;
719                 /// width of the part before the decimal
720                 int decimal_hoffset;
721                 /// width of the decimal part
722                 int decimal_width;
723                 ///
724                 int voffset;
725                 ///
726                 bool top_line;
727                 ///
728                 bool bottom_line;
729                 ///
730                 bool left_line;
731                 ///
732                 bool right_line;
733                 ///
734                 bool top_line_rtrimmed;
735                 ///
736                 bool top_line_ltrimmed;
737                 ///
738                 bool bottom_line_rtrimmed;
739                 ///
740                 bool bottom_line_ltrimmed;
741                 ///
742                 BoxType usebox;
743                 ///
744                 int rotate;
745                 ///
746                 docstring align_special;
747                 ///
748                 Length p_width; // this is only set for multicolumn!!!
749                 ///
750                 std::shared_ptr<InsetTableCell> inset;
751         };
752         ///
753         CellData const & cellInfo(idx_type cell) const;
754         ///
755         CellData & cellInfo(idx_type cell);
756         ///
757         typedef std::vector<CellData> cell_vector;
758         ///
759         typedef std::vector<cell_vector> cell_vvector;
760
761         ///
762         class RowData {
763         public:
764                 ///
765                 RowData();
766                 ///
767                 int ascent;
768                 ///
769                 int descent;
770                 /// Extra space between the top line and this row
771                 Length top_space;
772                 /// Ignore top_space if true and use the default top space
773                 bool top_space_default;
774                 /// Extra space between this row and the bottom line
775                 Length bottom_space;
776                 /// Ignore bottom_space if true and use the default bottom space
777                 bool bottom_space_default;
778                 /// Extra space between the bottom line and the next top line
779                 Length interline_space;
780                 /// Ignore interline_space if true and use the default interline space
781                 bool interline_space_default;
782                 /// This are for longtabulars only
783                 /// a row of endhead
784                 bool endhead;
785                 /// a row of endfirsthead
786                 bool endfirsthead;
787                 /// a row of endfoot
788                 bool endfoot;
789                 /// row of endlastfoot
790                 bool endlastfoot;
791                 /// row for a newpage
792                 bool newpage;
793                 /// caption
794                 bool caption;
795                 ///
796                 Change change;
797         };
798         ///
799         typedef std::vector<RowData> row_vector;
800
801         ///
802         class ColumnData {
803                 public:
804                 ///
805                 ColumnData();
806                 ///
807                 LyXAlignment alignment;
808                 ///
809                 VAlignment valignment;
810                 ///
811                 int width;
812                 ///
813                 Length p_width;
814                 ///
815                 docstring align_special;
816                 ///
817                 docstring decimal_point;
818                 ///
819                 bool varwidth;
820                 ///
821                 Change change;
822         };
823         ///
824         typedef std::vector<ColumnData> column_vector;
825
826         ///
827         idx_type numberofcells;
828         ///
829         std::vector<row_type> rowofcell;
830         ///
831         std::vector<col_type> columnofcell;
832         ///
833         row_vector row_info;
834         ///
835         column_vector column_info;
836         ///
837         cell_vvector cell_info;
838         ///
839         Length tabular_width;
840         ///
841         bool use_booktabs;
842         ///
843         int rotate;
844         ///
845         VAlignment tabular_valignment;
846         //
847         // for long tabulars
848         ///
849         HAlignment longtabular_alignment;
850         //
851         bool is_long_tabular;
852         /// endhead data
853         ltType endhead;
854         /// endfirsthead data
855         ltType endfirsthead;
856         /// endfoot data
857         ltType endfoot;
858         /// endlastfoot data
859         ltType endlastfoot;
860
861         ///
862         void init(Buffer *, row_type rows_arg,
863                   col_type columns_arg);
864         ///
865         void updateIndexes();
866         ///
867         bool setFixedWidth(row_type r, col_type c);
868         /// return true of update is needed
869         bool updateColumnWidths(MetricsInfo & mi);
870         ///
871         idx_type columnSpan(idx_type cell) const;
872         ///
873         idx_type rowSpan(idx_type cell) const;
874         ///
875         BoxType useBox(idx_type cell) const;
876         ///
877         // helper function for Latex
878         ///
879         void TeXTopHLine(otexstream &, row_type row, std::list<col_type>,
880                          std::list<col_type>) const;
881         ///
882         void TeXBottomHLine(otexstream &, row_type row, std::list<col_type>,
883                             std::list<col_type>) const;
884         ///
885         void TeXCellPreamble(otexstream &, idx_type cell, bool & ismulticol, bool & ismultirow,
886                              bool const bidi) const;
887         ///
888         void TeXCellPostamble(otexstream &, idx_type cell, bool ismulticol, bool ismultirow) const;
889         ///
890         void TeXLongtableHeaderFooter(otexstream &, OutputParams const &, std::list<col_type>,
891                                       std::list<col_type>) const;
892         ///
893         bool isValidRow(row_type const row) const;
894         ///
895         void TeXRow(otexstream &, row_type const row,
896                     OutputParams const &, std::list<col_type>, std::list<col_type>) const;
897         ///
898         // helper functions for plain text
899         ///
900         bool plaintextTopHLine(odocstringstream &, row_type row,
901                                std::vector<unsigned int> const &) const;
902         ///
903         bool plaintextBottomHLine(odocstringstream &, row_type row,
904                                   std::vector<unsigned int> const &) const;
905         ///
906         void plaintextPrintCell(odocstringstream &,
907                                 OutputParams const &,
908                                 idx_type cell, row_type row, col_type column,
909                                 std::vector<unsigned int> const &,
910                                 bool onlydata, size_t max_length) const;
911         /// auxiliary function for DocBook
912         void docbookRow(XMLStream &, row_type, OutputParams const &,
913                                         bool header = false) const;
914         /// auxiliary function for DocBook: export this row as HTML
915         void docbookRowAsHTML(XMLStream &, row_type, OutputParams const &,
916                                         bool header) const;
917         /// auxiliary function for DocBook: export this row as CALS
918         void docbookRowAsCALS(XMLStream &, row_type, OutputParams const &) const;
919         ///
920         docstring xhtmlRow(XMLStream & xs, row_type, OutputParams const &,
921                            bool header = false) const;
922
923         /// change associated Buffer
924         void setBuffer(Buffer & buffer);
925         /// retrieve associated Buffer
926         Buffer const & buffer() const { return *buffer_; }
927         /// retrieve associated Buffer
928         Buffer & buffer() { return *buffer_; }
929
930 private:
931         Buffer * buffer_;
932
933 }; // Tabular
934
935
936 class InsetTabular : public Inset
937 {
938 public:
939         ///
940         InsetTabular(Buffer *, row_type rows = 1,
941                      col_type columns = 1);
942         ///
943         ~InsetTabular();
944         ///
945         void setBuffer(Buffer & buffer) override;
946
947         ///
948         static void string2params(std::string const &, InsetTabular &);
949         ///
950         static std::string params2string(InsetTabular const &);
951         ///
952         void read(Lexer &) override;
953         ///
954         void write(std::ostream &) const override;
955         ///
956         void metrics(MetricsInfo &, Dimension &) const override;
957         ///
958         void draw(PainterInfo & pi, int x, int y) const override;
959         ///
960         void drawSelection(PainterInfo & pi, int x, int y) const override;
961         ///
962         void drawBackground(PainterInfo & pi, int x, int y) const override;
963         ///
964         bool editable() const override { return true; }
965         ///
966         bool hasSettings() const override { return true; }
967         ///
968         bool insetAllowed(InsetCode code) const override;
969         ///
970         bool allowSpellCheck() const override { return true; }
971         ///
972         bool canTrackChanges() const override { return true; }
973         ///
974         bool canPaintChange(BufferView const &) const override { return true; }
975         /** returns false if, when outputting LaTeX, font changes should
976             be closed before generating this inset. This is needed for
977             insets that may contain several paragraphs */
978         bool inheritFont() const override { return false; }
979         ///
980         bool allowMultiPar() const override;
981         ///
982         bool allowsCaptionVariation(std::string const &) const override;
983         //
984         bool isTable() const override { return true; }
985         ///
986         RowFlags rowFlags() const override;
987         ///
988         void latex(otexstream &, OutputParams const &) const override;
989         ///
990         int plaintext(odocstringstream & ods, OutputParams const & op,
991                       size_t max_length = INT_MAX) const override;
992         ///
993         void docbook(XMLStream &, OutputParams const &) const override;
994         ///
995         docstring xhtml(XMLStream &, OutputParams const &) const override;
996         ///
997         void validate(LaTeXFeatures & features) const override;
998         ///
999         InsetCode lyxCode() const override { return TABULAR_CODE; }
1000         ///
1001         std::string contextMenu(BufferView const &, int, int) const override;
1002         ///
1003         std::string contextMenuName() const override;
1004         /// get offset of this cursor slice relative to our upper left corner
1005         void cursorPos(BufferView const & bv, CursorSlice const & sl,
1006                 bool boundary, int & x, int & y) const override;
1007         /// Executes a space-separated sequence of tabular-features requests
1008         void tabularFeatures(Cursor & cur, std::string const & what);
1009         /// Change a single tabular feature; does not handle undo.
1010         void tabularFeatures(Cursor & cur, Tabular::Feature feature,
1011                              std::string const & val = std::string());
1012         /// number of cells
1013         size_t nargs() const override { return tabular.numberofcells; }
1014         ///
1015         std::shared_ptr<InsetTableCell const> cell(idx_type) const;
1016         ///
1017         std::shared_ptr<InsetTableCell> cell(idx_type);
1018         ///
1019         Text * getText(int) const override;
1020
1021         /// does the inset contain changes ?
1022         bool isChanged() const override;
1023         /// set the change for the entire inset
1024         void setChange(Change const & change) override;
1025         /// accept the changes within the inset
1026         void acceptChanges() override;
1027         /// reject the changes within the inset
1028         void rejectChanges() override;
1029
1030         // this should return true if we have a "normal" cell, otherwise false.
1031         // "normal" means without width set!
1032         /// should all paragraphs be output with "Standard" layout?
1033         bool allowParagraphCustomization(idx_type cell = 0) const override;
1034         ///
1035         void addPreview(DocIterator const & inset_pos,
1036                 graphics::PreviewLoader &) const override;
1037
1038         /// lock cell with given index
1039         void edit(Cursor & cur, bool front, EntryDirection entry_from) override;
1040         /// get table row from x coordinate
1041         int rowFromY(Cursor & cur, int y) const;
1042         /// get table column from y coordinate
1043         int columnFromX(Cursor & cur, int x) const;
1044         ///
1045         Inset * editXY(Cursor & cur, int x, int y) override;
1046         /// can we go further down on mouse click?
1047         bool descendable(BufferView const &) const override { return true; }
1048         /// Update the counters of this inset and of its contents
1049         void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false) override;
1050         ///
1051         void addToToc(DocIterator const & di, bool output_active,
1052                                   UpdateType utype, TocBackend & backend) const override;
1053
1054         ///
1055         bool completionSupported(Cursor const &) const override;
1056         ///
1057         bool inlineCompletionSupported(Cursor const & cur) const override;
1058         ///
1059         bool automaticInlineCompletion() const override;
1060         ///
1061         bool automaticPopupCompletion() const override;
1062         ///
1063         bool showCompletionCursor() const override;
1064         ///
1065         CompletionList const * createCompletionList(Cursor const & cur) const override;
1066         ///
1067         docstring completionPrefix(Cursor const & cur) const override;
1068         ///
1069         bool insertCompletion(Cursor & cur, docstring const & s, bool finished) override;
1070         ///
1071         void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const override;
1072         ///
1073         bool usePlainLayout() const override { return true; }
1074         ///
1075         docstring layoutName() const override { return from_ascii("Tabular"); }
1076
1077
1078         ///
1079         InsetTabular * asInsetTabular() override { return this; }
1080         ///
1081         InsetTabular const * asInsetTabular() const override { return this; }
1082         ///
1083         bool isRightToLeft(Cursor & cur) const;
1084         /// writes the cells between stidx and enidx as a string, optionally
1085         /// descending into the insets
1086         docstring asString(idx_type stidx, idx_type enidx, bool intoInsets = true);
1087         ///
1088         ParagraphList asParList(idx_type stidx, idx_type enidx);
1089
1090         /// Returns whether the cell in the specified row and column is selected.
1091         bool isCellSelected(Cursor & cur, row_type row, col_type col) const;
1092         ///
1093         void setLayoutForHiddenCells(DocumentClass const & dc);
1094         //
1095         // Public structures and variables
1096         ///
1097         mutable Tabular tabular;
1098
1099 private:
1100         ///
1101         InsetTabular(InsetTabular const &);
1102         ///
1103         void doDispatch(Cursor & cur, FuncRequest & cmd) override;
1104         ///
1105         bool getFeatureStatus(Cursor & cur, std::string const & s,
1106                          std::string const & argument, FuncStatus & status) const;
1107         ///
1108         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const override;
1109         ///
1110         Inset * clone() const override { return new InsetTabular(*this); }
1111
1112         ///
1113         bool hitSelectRow(BufferView const & bv, int x) const;
1114         ///
1115         bool hitSelectColumn(BufferView const & bv, int y) const;
1116         /// Returns true if coordinates are on row/column selection zones
1117         bool clickable(BufferView const &, int x, int y) const override;
1118
1119         ///
1120         void drawCellLines(PainterInfo &, int x, int y, row_type row,
1121                            idx_type cell) const;
1122         ///
1123         void setCursorFromCoordinates(Cursor & cur, int x, int y) const;
1124
1125         ///
1126         void moveNextCell(Cursor & cur,
1127                                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
1128         ///
1129         void movePrevCell(Cursor & cur,
1130                                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
1131         ///
1132         int cellXPos(idx_type cell) const;
1133         ///
1134         int cellYPos(idx_type cell) const;
1135         ///
1136         bool copySelection(Cursor & cur);
1137         ///
1138         bool pasteClipboard(Cursor & cur);
1139         ///
1140         void cutSelection(Cursor & cur);
1141         ///
1142         void getSelection(Cursor & cur, row_type & rs, row_type & re,
1143                           col_type & cs, col_type & ce) const;
1144         ///
1145         bool insertPlaintextString(BufferView &, docstring const & buf, bool usePaste);
1146
1147         /// return the "Manhattan distance" to nearest corner
1148         int dist(BufferView &, idx_type cell, int x, int y) const;
1149         /// return the cell nearest to x, y
1150         idx_type getNearestCell(BufferView &, int x, int y) const;
1151
1152         /// test the rotation state of the given cell range.
1153         bool oneCellHasRotationState(bool rotated,
1154                                 row_type row_start, row_type row_end,
1155                                 col_type col_start, col_type col_end) const;
1156
1157         /// true when selecting rows with the mouse
1158         bool rowselect_;
1159         /// true when selecting columns with the mouse
1160         bool colselect_;
1161 };
1162
1163 std::string const featureAsString(Tabular::Feature feature);
1164
1165 /// Split cell on decimal symbol
1166 InsetTableCell splitCell(InsetTableCell & head, docstring const & decimal_sym, bool & hassep);
1167
1168 } // namespace lyx
1169
1170 #endif // INSET_TABULAR_H