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