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