4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Matthias Ettrich
10 * \author Jürgen Vigna
11 * \author Edwin Leuven
13 * \author Scott Kostyshak
15 * Full author contact details are available in file CREDITS.
18 // Things to think of when designing the new tabular support:
19 // - color support (colortbl, color)
20 // - decimal alignment (dcloumn)
21 // - custom lines (hhline)
24 #ifndef INSET_TABULAR_H
25 #define INSET_TABULAR_H
27 #include "BufferParams.h"
29 #include "InsetText.h"
31 #include "support/Length.h"
32 #include "support/types.h"
51 namespace support { class Lexer; }
54 class InsetTableCell : public InsetText
58 explicit InsetTableCell(Buffer * buf);
59 /// We need this since generation of the default is deprecated
60 /// (since we declare the assignment constuctor below).
61 InsetTableCell(InsetTableCell const & in) = default;
63 InsetCode lyxCode() const override { return CELL_CODE; }
65 docstring layoutName() const override { return from_ascii("Tabular:Cell"); }
67 Inset * clone() const override { return new InsetTableCell(*this); }
69 bool getStatus(Cursor & cur, FuncRequest const & cmd,
70 FuncStatus & status) const override;
72 void toggleFixedWidth(bool fw) { isFixedWidth = fw; }
74 void toggleVarWidth(bool vw) { isVarwidth = vw; }
76 void toggleMultiCol(bool m) { isMultiColumn = m; }
78 void toggleMultiRow(bool m) { isMultiRow = m; }
80 void toggleCaptionRow(bool m) { isCaptionRow = m; }
82 void setContentAlignment(LyXAlignment al) { contentAlign = al; }
83 /// writes the contents of the cell as a string, optionally
84 /// descending into insets
85 docstring asString(bool intoInsets = true);
87 docstring xhtml(XMLStream &, OutputParams const &) const override;
89 void docbook(XMLStream &, OutputParams const &) const override;
91 void addToToc(DocIterator const & di, bool output_active,
92 UpdateType utype, TocBackend & backend) const override;
94 void metrics(MetricsInfo &, Dimension &) const override;
95 /// Can the cell contain several paragraphs?
96 bool allowMultiPar() const override { return !isMultiRow && (!isMultiColumn || isFixedWidth); }
98 bool canPaintChange(BufferView const &) const override { return false; }
99 /// This assures we never output \maketitle in table cells
100 bool isInTitle() const override { return true; }
103 InsetTableCell() = delete;
105 void operator=(InsetTableCell const &) = delete;
107 // These booleans are supposed to track whether the cell has had its
108 // width explicitly set and whether it is part of a multicolumn, respectively.
109 // We need to know this to determine whether
110 // layout changes and paragraph customization are allowed---that is,
111 // we need it in forcePlainLayout() and allowParagraphCustomization().
112 // Unfortunately, that information is not readily available in
113 // InsetTableCell. In the case of multicolumn cells, it is present
114 // in CellData, and so would be available here if CellData were to
115 // become a member of InsetTableCell. But in the other case, it isn't
116 // even available there, but is held in Tabular::ColumnData.
117 // So, the present solution uses this boolean to track the information
118 // we need to track, and tries to keep it updated. This is not ideal,
119 // but the other solutions are no better. These are:
120 // (i) Keep a pointer in InsetTableCell to the table;
121 // (ii) Find the table by iterating over the Buffer's insets.
122 // Solution (i) raises the problem of updating the pointer when an
123 // InsetTableCell is copied, and we'd therefore need a copy constructor
124 // in InsetTabular and then in Tabular, which seems messy, given how
125 // complicated those classes are. Solution (ii) involves a lot of
126 // iterating, since this information is needed quite often, and so may
128 // So, well, if someone can do better, please do!
138 // FIXME: For the next two items the thoughts from the comment above also apply.
142 LyXAlignment contentAlign;
143 /// should paragraph indentation be omitted in any case?
144 bool neverIndent() const override { return true; }
146 LyXAlignment contentAlignment() const override { return contentAlign; }
148 bool usePlainLayout() const override { return true; }
150 bool allowParagraphCustomization(idx_type = 0) const override;
152 bool forceLocalFontSwitch() const override;
153 /// Is the width forced to some value?
154 bool hasFixedWidth() const override { return isFixedWidth; }
156 bool insetAllowed(InsetCode code) const override;
161 // A helper struct for tables
264 RESET_FORMAL_DEFAULT,
278 TOGGLE_VARWIDTH_COLUMN,
282 UNSET_ROTATE_TABULAR,
284 TOGGLE_ROTATE_TABULAR,
317 SET_SPECIAL_MULTICOLUMN,
335 TABULAR_VALIGN_MIDDLE,
337 TABULAR_VALIGN_BOTTOM,
339 LONGTABULAR_ALIGN_LEFT,
341 LONGTABULAR_ALIGN_CENTER,
343 LONGTABULAR_ALIGN_RIGHT,
364 CELL_BEGIN_OF_MULTICOLUMN,
366 CELL_PART_OF_MULTICOLUMN,
368 CELL_BEGIN_OF_MULTIROW,
370 CELL_PART_OF_MULTIROW
378 LYX_VALIGN_MIDDLE = 1,
380 LYX_VALIGN_BOTTOM = 2
386 LYX_LONGTABULAR_ALIGN_LEFT = 0,
388 LYX_LONGTABULAR_ALIGN_CENTER = 1,
390 LYX_LONGTABULAR_ALIGN_RIGHT = 2
431 // we have this header type (is set in the getLT... functions)
433 // double borders on top
435 // double borders on bottom
437 // used for FirstHeader & LastFooter and if this is true
438 // all the rows marked as FirstHeader or LastFooter are
439 // ignored in the output and it is set to be empty!
443 /// index indicating an invalid position
444 static const idx_type npos = static_cast<idx_type>(-1);
447 Tabular(Buffer * buf, col_type columns_arg, row_type rows_arg);
449 /// Returns true if there is a topline, returns false if not
450 bool topLine(idx_type cell) const;
451 /// Returns true if there is a topline, returns false if not
452 bool bottomLine(idx_type cell) const;
453 /// Returns true if there is a topline, returns false if not
454 /// If \p ignore_bt is true, we return the state as if booktabs was
456 bool leftLine(idx_type cell, bool const ignore_bt = false) const;
457 /// Returns true if there is a topline, returns false if not
458 /// If \p ignore_bt is true, we return the state as if booktabs was
460 bool rightLine(idx_type cell, bool const ignore_bt = false) const;
461 /// Returns true if there is an outside border around the selection
462 bool outsideBorders(row_type sel_row_start, row_type sel_row_end,
463 col_type sel_col_start, col_type sel_col_end) const;
464 /// Returns true if there are inside lines in the selection
465 bool innerBorders(row_type sel_row_start, row_type sel_row_end,
466 col_type sel_col_start, col_type sel_col_end) const;
467 /// Sets the grid lines in the selection
468 /// if \p setLinesInnerOnly is true, outside borders are excluded
469 /// if \p setLines is true the lines are set otherwise they are unset
470 void setLines(row_type const sel_row_start, row_type const sel_row_end,
471 col_type const sel_col_start, col_type const sel_col_end,
472 bool setLinesInnerOnly, bool setLines);
473 /// Returns whether the top line is trimmed left and/or right
474 std::pair<bool, bool> topLineTrim(idx_type const cell) const;
475 /// Returns whether the bottom line is trimmed left and/or right
476 std::pair<bool, bool> bottomLineTrim(idx_type const cell) const;
478 /// return space occupied by the second horizontal line and
479 /// interline space above row \p row in pixels
480 int interRowSpace(row_type row) const;
482 int interColumnSpace(idx_type cell) const;
484 /* returns the maximum over all rows */
486 int cellWidth(idx_type cell) const;
488 int cellHeight(idx_type cell) const;
494 row_type nrows() const {return row_info.size();}
496 col_type ncols() const {return column_info.size();}
498 int rowAscent(row_type row) const;
500 int rowDescent(row_type row) const;
502 void setRowAscent(row_type row, int height);
504 void setRowDescent(row_type row, int height);
506 void setTopLine(idx_type cell, bool line);
508 void setBottomLine(idx_type cell, bool line);
510 void setTopLineLTrim(idx_type cell, bool val);
512 void setBottomLineLTrim(idx_type cell, bool val);
514 void setTopLineRTrim(idx_type cell, bool val);
516 void setBottomLineRTrim(idx_type cell, bool val);
518 void setTopLineTrim(idx_type cell, std::pair<bool, bool>);
520 void setBottomLineTrim(idx_type cell, std::pair<bool, bool>);
522 void setLeftLine(idx_type cell, bool line);
524 void setRightLine(idx_type cell, bool line);
526 bool rowTopLine(row_type row) const;
528 bool rowBottomLine(row_type row) const;
530 bool columnLeftLine(col_type column) const;
532 bool columnRightLine(col_type column) const;
534 void setAlignment(idx_type cell, LyXAlignment align,
535 bool onlycolumn = false);
537 void setVAlignment(idx_type cell, VAlignment align,
538 bool onlycolumn = false);
540 void setTabularWidth(Length const & l) { tabular_width = l; }
542 Length tabularWidth() const { return tabular_width; }
544 void setColumnPWidth(Cursor &, idx_type, Length const &);
546 bool setMColumnPWidth(Cursor &, idx_type, Length const &);
548 bool toggleVarwidth(idx_type, bool const);
550 bool setMROffset(Cursor &, idx_type, Length const &);
552 void setAlignSpecial(idx_type cell, docstring const & special,
555 LyXAlignment getAlignment(idx_type cell,
556 bool onlycolumn = false) const;
558 VAlignment getVAlignment(idx_type cell,
559 bool onlycolumn = false) const;
560 /// The vertical offset of the table due to the vertical
561 /// alignment with respect to the baseline.
562 int offsetVAlignment() const;
564 Length const getPWidth(idx_type cell) const;
566 Length const getMROffset(idx_type cell) const;
568 int textHOffset(idx_type cell) const;
570 int textVOffset(idx_type cell) const;
572 void appendRow(row_type row);
574 void deleteRow(row_type row, bool const force = false);
576 void copyRow(row_type row);
578 void insertRow(row_type row, bool copy);
580 void moveColumn(col_type col_start, col_type col_end,
581 ColDirection direction);
583 void moveRow(row_type row_start, row_type row_end,
584 RowDirection direction);
586 void appendColumn(col_type column);
588 void deleteColumn(col_type column, bool const force = false);
590 void copyColumn(col_type column);
592 void insertColumn(col_type column, bool copy);
594 idx_type getFirstCellInRow(row_type row, bool const ct = false) const;
596 idx_type getLastCellInRow(row_type row, bool const ct = false) const;
598 idx_type getFirstRow(bool const ct = false) const;
600 idx_type getLastRow(bool const ct = false) const;
602 idx_type numberOfCellsInRow(row_type row) const;
604 void write(std::ostream &) const;
606 void read(support::Lexer &);
608 void latex(otexstream &, OutputParams const &) const;
609 /// serialise the table in DocBook, according to buffer parameters
610 void docbook(XMLStream &, OutputParams const &) const;
612 docstring xhtml(XMLStream &, OutputParams const &) const;
614 void plaintext(odocstringstream &,
615 OutputParams const & runparams, int const depth,
616 bool onlydata, char_type delim, size_t max_length = INT_MAX) const;
618 bool isMultiColumn(idx_type cell) const;
620 bool hasMultiColumn(col_type cell) const;
622 bool hasVarwidthColumn() const;
624 bool isVTypeColumn(col_type cell) const;
626 idx_type setMultiColumn(Cursor & cur, idx_type cell, idx_type number,
627 bool const right_border);
629 void unsetMultiColumn(idx_type cell);
631 bool isPartOfMultiColumn(row_type row, col_type column) const;
633 bool isPartOfMultiRow(row_type row, col_type column) const;
635 bool isMultiRow(idx_type cell) const;
637 bool hasMultiRow(row_type r) const;
639 idx_type setMultiRow(Cursor & cur, idx_type cell, idx_type number,
640 bool const bottom_border,
641 LyXAlignment const halign);
643 void unsetMultiRow(idx_type cell);
645 row_type cellRow(idx_type cell) const;
647 col_type cellColumn(idx_type cell) const;
649 void setRotateCell(idx_type cell, int);
651 int getRotateCell(idx_type cell) const;
653 bool needRotating() const;
655 bool isLastCell(idx_type cell) const;
657 idx_type cellAbove(idx_type cell) const;
659 idx_type cellBelow(idx_type cell) const;
660 /// \return the index of the VISIBLE cell at row, column
661 /// this will be the same as the cell in the previous row,
662 /// e.g., if the cell is part of a multirow
663 idx_type cellIndex(row_type row, col_type column) const;
665 void setUsebox(idx_type cell, BoxType);
667 BoxType getUsebox(idx_type cell) const;
669 // Long Tabular Options support functions
671 void setLTHead(row_type row, bool flag, ltType const &, bool first);
673 bool getRowOfLTHead(row_type row, ltType &) const;
675 bool getRowOfLTFirstHead(row_type row, ltType &) const;
677 void setLTFoot(row_type row, bool flag, ltType const &, bool last);
679 bool getRowOfLTFoot(row_type row, ltType &) const;
681 bool getRowOfLTLastFoot(row_type row, ltType &) const;
683 void setLTNewPage(row_type row, bool what);
685 bool getLTNewPage(row_type row) const;
687 idx_type setLTCaption(Cursor & cur, row_type row, bool what);
689 bool ltCaption(row_type row) const;
691 bool haveLTHead(bool withcaptions = true) const;
693 bool haveLTFirstHead(bool withcaptions = true) const;
695 bool haveLTFoot(bool withcaptions = true) const;
697 bool haveLTLastFoot(bool withcaptions = true) const;
699 bool haveLTCaption(CaptionType captiontype = CAPTION_ANY) const;
701 // end longtable support
704 /// there is a subtle difference between these two methods.
707 /// cellInset(cellIndex(r,c));
708 /// can return different things. this is because cellIndex(r,c)
709 /// returns the VISIBLE cell at r,c, which may be the same as the
710 /// cell at the previous row or column, if we're dealing with some
711 /// multirow or multicolumn.
712 std::shared_ptr<InsetTableCell> cellInset(idx_type cell);
713 std::shared_ptr<InsetTableCell> cellInset(row_type row, col_type column);
714 InsetTableCell const * cellInset(idx_type cell) const;
717 void setCellInset(row_type row, col_type column,
718 std::shared_ptr<InsetTableCell>);
719 /// Search for \param inset in the tabular, with the
721 void validate(LaTeXFeatures &) const;
724 // FIXME Now that cells have an InsetTableCell as their insets, rather
725 // than an InsetText, it'd be possible to reverse the relationship here,
726 // so that cell_vector was a vector<InsetTableCell> rather than a
727 // vector<CellData>, and an InsetTableCell had a CellData as a member,
728 // or perhaps just had its members as members.
733 explicit CellData(Buffer *);
735 CellData(CellData const &);
737 CellData & operator=(CellData const &);
749 LyXAlignment alignment;
751 VAlignment valignment;
752 /// width of the part before the decimal
754 /// width of the decimal part
767 bool top_line_rtrimmed;
769 bool top_line_ltrimmed;
771 bool bottom_line_rtrimmed;
773 bool bottom_line_ltrimmed;
779 docstring align_special;
781 Length p_width; // this is only set for multicolumn!!!
783 std::shared_ptr<InsetTableCell> inset;
786 CellData const & cellInfo(idx_type cell) const;
788 CellData & cellInfo(idx_type cell);
790 typedef std::vector<CellData> cell_vector;
792 typedef std::vector<cell_vector> cell_vvector;
803 /// Extra space between the top line and this row
805 /// Ignore top_space if true and use the default top space
806 bool top_space_default;
807 /// Extra space between this row and the bottom line
809 /// Ignore bottom_space if true and use the default bottom space
810 bool bottom_space_default;
811 /// Extra space between the bottom line and the next top line
812 Length interline_space;
813 /// Ignore interline_space if true and use the default interline space
814 bool interline_space_default;
815 /// This are for longtabulars only
818 /// a row of endfirsthead
822 /// row of endlastfoot
824 /// row for a newpage
832 typedef std::vector<RowData> row_vector;
840 LyXAlignment alignment;
842 VAlignment valignment;
848 docstring align_special;
850 docstring decimal_point;
857 typedef std::vector<ColumnData> column_vector;
860 // Determines the style of borders, per row.
861 class XmlRowWiseBorders {
863 // Whether to draw double bottom line.
864 bool completeBorder = true;
866 // Whether to draw booktabs' thicker lines.
867 bool completeBorderAbove = true;
868 bool completeBorderBelow = true;
870 // Size of the borders.
871 double borderBottomWidth = 1.0;
872 double borderBottomWidthComplete = 3.0;
873 double borderTopWidth = 1.0;
878 idx_type numberofcells;
880 std::vector<row_type> rowofcell;
882 std::vector<col_type> columnofcell;
886 column_vector column_info;
888 cell_vvector cell_info;
890 Length tabular_width;
896 VAlignment tabular_valignment;
900 HAlignment longtabular_alignment;
902 bool is_long_tabular;
905 /// endfirsthead data
913 void init(Buffer *, row_type rows_arg,
914 col_type columns_arg);
916 void updateIndexes();
918 bool setFixedWidth(row_type r, col_type c);
919 /// return true of update is needed
920 bool updateColumnWidths(MetricsInfo & mi);
922 idx_type columnSpan(idx_type cell) const;
924 idx_type rowSpan(idx_type cell) const;
926 BoxType useBox(idx_type cell) const;
928 bool hasNewlines(idx_type cell) const;
930 bool isValidRow(row_type const row) const;
932 void TeXRow(otexstream &, row_type const row, OutputParams const &,
933 std::list<col_type> const &, std::list<col_type> const &) const;
935 /// change associated Buffer
936 void setBuffer(Buffer & buffer);
937 /// retrieve associated Buffer
938 Buffer const & buffer() const { return *buffer_; }
939 /// retrieve associated Buffer
940 Buffer & buffer() { return *buffer_; }
946 // helper function for DocBook
948 /// Determines whether the tabular item should be generated as DocBook or XHTML.
949 enum class XmlOutputFormat : bool {
954 /// Transforms the vertical alignment of the given cell as prebaked CSS (for HTML tables in HTML output).
955 std::string getHAlignAsXmlAttribute(idx_type cell) const;
956 /// Transforms the vertical alignment of the given cell as a prebaked XML attribute (for CALS or HTML tables in DocBook).
957 std::string getHAlignAsCssAttribute(idx_type cell) const;
958 /// Transforms the vertical alignment of the given cell as prebaked CSS (for HTML tables in HTML output).
959 std::string getVAlignAsCssAttribute(idx_type cell) const;
960 /// Transforms the vertical alignment of the given cell as a prebaked XML attribute (for CALS or HTML tables in DocBook).
961 std::string getVAlignAsXmlAttribute(idx_type cell) const;
963 /// Helpers for XML tables (XHTML or DocBook).
964 docstring xmlRow(XMLStream & xs, row_type row, OutputParams const &,
965 bool header, XmlOutputFormat output_format,
966 BufferParams::TableOutput docbook_table_output = BufferParams::TableOutput::HTMLTable) const;
967 void xmlHeader(XMLStream & xs, OutputParams const &, XmlOutputFormat output_format) const;
968 void xmlFooter(XMLStream & xs, OutputParams const &, XmlOutputFormat output_format) const;
969 void xmlBody(XMLStream & xs, OutputParams const &, XmlOutputFormat output_format) const;
970 XmlRowWiseBorders computeXmlBorders(row_type row) const;
971 std::vector<std::string> computeCssStylePerCell(row_type row, col_type col, idx_type cell) const;
974 // helper functions for plain text
976 bool plaintextTopHLine(odocstringstream &, row_type row,
977 std::vector<unsigned int> const &) const;
979 bool plaintextBottomHLine(odocstringstream &, row_type row,
980 std::vector<unsigned int> const &) const;
982 void plaintextPrintCell(odocstringstream &,
983 OutputParams const &,
984 idx_type cell, row_type row, col_type column,
985 std::vector<unsigned int> const &,
986 bool onlydata, size_t max_length) const;
989 // helper function for LaTeX
991 void TeXTopHLine(otexstream &, row_type row, std::list<col_type> const &,
992 std::list<col_type> const &) const;
994 void TeXBottomHLine(otexstream &, row_type row, std::list<col_type> const &,
995 std::list<col_type> const &) const;
997 void TeXCellPreamble(otexstream &, idx_type cell, bool & ismulticol, bool & ismultirow,
998 bool const bidi) const;
1000 void TeXCellPostamble(otexstream &, idx_type cell, bool ismulticol, bool ismultirow) const;
1002 void TeXLongtableHeaderFooter(otexstream &, OutputParams const &, std::list<col_type> const &,
1003 std::list<col_type> const &) const;
1008 class InsetTabular : public Inset
1012 InsetTabular(Buffer *, row_type rows = 1,
1013 col_type columns = 1);
1017 void setBuffer(Buffer & buffer) override;
1020 static void string2params(std::string const &, InsetTabular &);
1022 static std::string params2string(InsetTabular const &);
1024 void read(support::Lexer &) override;
1026 void write(std::ostream &) const override;
1028 void metrics(MetricsInfo &, Dimension &) const override;
1030 void draw(PainterInfo & pi, int x, int y) const override;
1032 void drawSelection(PainterInfo & pi, int x, int y) const override;
1034 void drawBackground(PainterInfo & pi, int x, int y) const override;
1036 bool editable() const override { return true; }
1038 bool hasSettings() const override { return true; }
1040 bool insetAllowed(InsetCode code) const override;
1042 bool allowSpellCheck() const override { return true; }
1044 bool canTrackChanges() const override { return true; }
1046 bool canPaintChange(BufferView const &) const override { return true; }
1048 bool allowMultiPar() const override;
1050 bool allowsCaptionVariation(std::string const &) const override;
1052 bool isTable() const override { return true; }
1054 int rowFlags() const override;
1056 void latex(otexstream &, OutputParams const &) const override;
1058 int plaintext(odocstringstream & ods, OutputParams const & op,
1059 size_t max_length = INT_MAX) const override;
1061 void docbook(XMLStream &, OutputParams const &) const override;
1063 docstring xhtml(XMLStream &, OutputParams const &) const override;
1065 void validate(LaTeXFeatures & features) const override;
1067 InsetCode lyxCode() const override { return TABULAR_CODE; }
1069 std::string contextMenu(BufferView const &, int, int) const override;
1071 std::string contextMenuName() const override;
1072 /// get offset of this cursor slice relative to our upper left corner
1073 void cursorPos(BufferView const & bv, CursorSlice const & sl,
1074 bool boundary, int & x, int & y) const override;
1075 /// Executes a space-separated sequence of tabular-features requests
1076 void tabularFeatures(Cursor & cur, std::string const & what);
1077 /// Change a single tabular feature; does not handle undo.
1078 void tabularFeatures(Cursor & cur, Tabular::Feature feature,
1079 std::string const & val = std::string());
1081 size_t nargs() const override { return tabular.numberofcells; }
1083 std::shared_ptr<InsetTableCell const> cell(idx_type) const;
1085 std::shared_ptr<InsetTableCell> cell(idx_type);
1087 Text * getText(int) const override;
1089 /// does the inset contain changes ?
1090 bool isChanged() const override;
1091 /// set the change for the entire inset
1092 void setChange(Change const & change) override;
1093 /// accept the changes within the inset
1094 void acceptChanges() override;
1095 /// reject the changes within the inset
1096 void rejectChanges() override;
1098 // this should return true if we have a "normal" cell, otherwise false.
1099 // "normal" means without width set!
1100 /// should all paragraphs be output with "Standard" layout?
1101 bool allowParagraphCustomization(idx_type cell = 0) const override;
1103 void addPreview(DocIterator const & inset_pos,
1104 graphics::PreviewLoader &) const override;
1106 /// lock cell with given index
1107 void edit(Cursor & cur, bool front, EntryDirection entry_from) override;
1108 /// get table row from x coordinate
1109 int rowFromY(Cursor & cur, int y) const;
1110 /// get table column from y coordinate
1111 int columnFromX(Cursor & cur, int x) const;
1113 Inset * editXY(Cursor & cur, int x, int y) override;
1114 /// can we go further down on mouse click?
1115 bool descendable(BufferView const &) const override { return true; }
1116 /// Update the counters of this inset and of its contents
1117 void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false) override;
1119 void addToToc(DocIterator const & di, bool output_active,
1120 UpdateType utype, TocBackend & backend) const override;
1123 bool completionSupported(Cursor const &) const override;
1125 bool inlineCompletionSupported(Cursor const & cur) const override;
1127 bool automaticInlineCompletion() const override;
1129 bool automaticPopupCompletion() const override;
1131 bool showCompletionCursor() const override;
1133 CompletionList const * createCompletionList(Cursor const & cur) const override;
1135 docstring completionPrefix(Cursor const & cur) const override;
1137 bool insertCompletion(Cursor & cur, docstring const & s, bool /*finished*/) override;
1139 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const override;
1141 bool usePlainLayout() const override { return true; }
1143 docstring layoutName() const override { return from_ascii("Tabular"); }
1147 InsetTabular * asInsetTabular() override { return this; }
1149 InsetTabular const * asInsetTabular() const override { return this; }
1151 bool isRightToLeft(Cursor & cur) const;
1152 /// writes the cells between stidx and enidx as a string, optionally
1153 /// descending into the insets
1154 docstring asString(idx_type stidx, idx_type enidx, bool intoInsets = true);
1156 ParagraphList asParList(idx_type stidx, idx_type enidx);
1158 bool confirmDeletion() const override { return true; }
1159 /// Returns whether the cell in the specified row and column is selected.
1160 bool isCellSelected(Cursor & cur, row_type row, col_type col) const;
1162 void setLayoutForHiddenCells(DocumentClass const & dc);
1164 // Public structures and variables
1166 mutable Tabular tabular;
1170 InsetTabular(InsetTabular const &);
1172 void doDispatch(Cursor & cur, FuncRequest & cmd) override;
1174 bool getFeatureStatus(Cursor & cur, std::string const & s,
1175 std::string const & argument, FuncStatus & status) const;
1177 bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const override;
1179 Inset * clone() const override { return new InsetTabular(*this); }
1182 bool hitSelectRow(BufferView const & bv, int x) const;
1184 bool hitSelectColumn(BufferView const & bv, int y) const;
1185 /// Returns true if coordinates are on row/column selection zones
1186 bool clickable(BufferView const &, int x, int y) const override;
1189 void drawCellLines(PainterInfo &, int x, int y, row_type row,
1190 idx_type cell) const;
1192 void setCursorFromCoordinates(Cursor & cur, int x, int y) const;
1195 void moveNextCell(Cursor & cur,
1196 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
1198 void movePrevCell(Cursor & cur,
1199 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
1201 int cellXPos(idx_type cell) const;
1203 int cellYPos(idx_type cell) const;
1205 bool copySelection(Cursor & cur);
1207 bool pasteClipboard(Cursor & cur);
1209 void cutSelection(Cursor & cur);
1211 void getSelection(Cursor & cur, row_type & rs, row_type & re,
1212 col_type & cs, col_type & ce) const;
1214 bool insertPlaintextString(BufferView &, docstring const & buf, bool usePaste);
1216 /// return the "Manhattan distance" to nearest corner
1217 int dist(BufferView &, idx_type cell, int x, int y) const;
1218 /// return the cell nearest to x, y
1219 idx_type getNearestCell(BufferView &, int x, int y) const;
1221 /// test the rotation state of the given cell range.
1222 bool oneCellHasRotationState(bool rotated,
1223 row_type row_start, row_type row_end,
1224 col_type col_start, col_type col_end) const;
1226 /// true when selecting rows with the mouse
1228 /// true when selecting columns with the mouse
1232 std::string const featureAsString(Tabular::Feature feature);
1234 /// Split cell on decimal symbol
1235 InsetTableCell splitCell(InsetTableCell & head, docstring const & decimal_sym, bool & hassep);
1239 #endif // INSET_TABULAR_H