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