4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
13 // This is the rewrite of the tabular (table) support.
15 // Ideally the tabular support should do as the mathed and use
16 // LaTeX in the .lyx file too.
18 // Things to think of when designing the new tabular support:
19 // - color support (colortbl, color)
20 // - decimal alignment (dcloumn)
21 // - custom lines (hhline)
27 // This is what I have written about tabular support in the LyX3-Tasks file:
29 // o rewrite of table code. Should probably be written as some
30 // kind of an inset. At least get the code out of the kernel.
31 // - colortbl -multirow
32 // - hhline -multicolumn
34 // o enhance longtable support
38 #ifndef INSETTABULAR_H
39 #define INSETTABULAR_H
54 class InsetTabular : public UpdatableInset {
57 InsetTabular(Buffer const &, int rows = 1, int columns = 1);
59 InsetTabular(InsetTabular const &);
63 virtual std::auto_ptr<InsetBase> clone() const;
65 void read(Buffer const &, LyXLex &);
67 void write(Buffer const &, std::ostream &) const;
69 void metrics(MetricsInfo &, Dimension &) const;
71 void draw(PainterInfo & pi, int x, int y) const;
73 std::string const editMessage() const;
75 bool insetAllowed(InsetOld::Code) const { return true; }
77 bool isTextInset() const { return true; }
78 /** returns true if, when outputing LaTeX, font changes should
79 be closed before generating this inset. This is needed for
80 insets that may contain several paragraphs */
81 bool noFontChange() const { return true; }
83 bool display() const { return tabular.isLongTabular(); }
85 int latex(Buffer const &, std::ostream &,
86 OutputParams const &) const;
88 int plaintext(Buffer const &, std::ostream &,
89 OutputParams const &) const;
91 int linuxdoc(Buffer const &, std::ostream &,
92 OutputParams const &) const;
94 int docbook(Buffer const &, std::ostream &,
95 OutputParams const &) const;
97 void validate(LaTeXFeatures & features) const;
99 InsetOld::Code lyxCode() const { return InsetOld::TABULAR_CODE; }
100 /// get the absolute screen x,y of the cursor
101 void getCursorPos(CursorSlice const & cur, int & x, int & y) const;
103 bool tabularFeatures(LCursor & cur, std::string const & what);
105 void tabularFeatures(LCursor & cur, LyXTabular::Feature feature,
106 std::string const & val = std::string());
108 void openLayoutDialog(BufferView *) const;
110 bool showInsetDialog(BufferView *) const;
112 FuncStatus getStatus(BufferView &,
113 std::string const & argument, int cell) const;
114 /// Appends \c list with all labels found within this inset.
115 void getLabelList(Buffer const &, std::vector<std::string> & list) const;
117 size_t nargs() const;
119 InsetText const & cell(int) const;
121 InsetText & cell(int);
123 LyXText * getText(int) const;
128 // this should return true if we have a "normal" cell, otherwise true.
129 // "normal" means without width set!
130 bool forceDefaultParagraphs(InsetBase const * in) const;
133 void addPreview(lyx::graphics::PreviewLoader &) const;
136 Buffer const & buffer() const;
138 /// set the owning buffer
139 void buffer(Buffer * buf);
140 /// lock cell with given index
141 void edit(LCursor & cur, bool left);
143 InsetBase * editXY(LCursor & cur, int x, int y);
144 /// can we go further down on mouse click?
145 bool descendable() const { return true; }
148 // Public structures and variables
150 mutable LyXTabular tabular;
154 void priv_dispatch(LCursor & cur, FuncRequest & cmd);
156 bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
159 void drawCellLines(Painter &, int x, int baseline,
160 int row, int cell) const;
162 void drawCellSelection(PainterInfo &, int x, int baseline,
163 int row, int column, int cell) const;
165 InsetBase * setPos(LCursor & cur, int x, int y) const;
168 void moveNextCell(LCursor & cur);
170 void movePrevCell(LCursor & cur);
172 int getCellXPos(int cell) const;
174 void resetPos(LCursor & cur) const;
176 void removeTabularRow();
178 bool hasPasteBuffer() const;
180 bool copySelection(LCursor & cur);
182 bool pasteSelection(LCursor & cur);
184 void cutSelection(LCursor & cur);
186 bool isRightToLeft(LCursor & cur);
188 void getSelection(LCursor & cur,
189 int & rs, int & re, int & cs, int & ce) const;
191 bool insertAsciiString(BufferView &, std::string const & buf, bool usePaste);
192 /// are we operating on several cells?
193 bool tablemode(LCursor & cur) const;
196 Buffer const * buffer_;
198 mutable int cursorx_;
200 mutable int first_visible_cell;
204 #include "mailinset.h"
207 class InsetTabularMailer : public MailInset {
210 InsetTabularMailer(InsetTabular const & inset);
212 virtual InsetBase & inset() const { return inset_; }
214 virtual std::string const & name() const { return name_; }
216 virtual std::string const inset2string(Buffer const &) const;
217 /// Returns the active cell if successful, else -1.
218 static int string2params(std::string const &, InsetTabular &);
220 static std::string const params2string(InsetTabular const &);
223 static std::string const name_;
225 InsetTabular & inset_;
228 std::string const featureAsString(LyXTabular::Feature feature);