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 Code lyxCode() const { return InsetOld::TABULAR_CODE; }
100 /// get the absolute screen x,y of the cursor
101 void getCursorPos(LCursor 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;
111 /// Appends \c list with all labels found within this inset.
112 void getLabelList(Buffer const &, std::vector<std::string> & list) const;
114 size_t nargs() const;
116 InsetText const & cell(int) const;
118 InsetText & cell(int);
120 LyXText * getText(int) const;
125 // this should return true if we have a "normal" cell, otherwise true.
126 // "normal" means without width set!
127 bool forceDefaultParagraphs(InsetBase const * in) const;
130 void addPreview(lyx::graphics::PreviewLoader &) const;
133 Buffer const & buffer() const;
135 /// set the owning buffer
136 void buffer(Buffer const * buf);
137 /// lock cell with given index
138 void edit(LCursor & cur, bool left);
140 InsetBase * editXY(LCursor & cur, int x, int y) const;
141 /// can we go further down on mouse click?
142 bool descendable() const { return true; }
145 // Public structures and variables
147 mutable LyXTabular tabular;
151 void priv_dispatch(LCursor & cur, FuncRequest & cmd);
153 bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
156 void drawCellLines(Painter &, int x, int baseline,
157 int row, int cell) const;
159 void drawCellSelection(PainterInfo &, int x, int baseline,
160 int row, int column, int cell) const;
162 InsetBase * setPos(LCursor & cur, int x, int y) const;
165 void moveNextCell(LCursor & cur);
167 void movePrevCell(LCursor & cur);
169 int getCellXPos(int cell) const;
171 void resetPos(LCursor & cur) const;
173 void removeTabularRow();
175 bool hasPasteBuffer() const;
177 bool copySelection(LCursor & cur);
179 bool pasteSelection(LCursor & cur);
181 void cutSelection(LCursor & cur);
183 bool isRightToLeft(LCursor & cur);
185 void getSelection(LCursor & cur,
186 int & rs, int & re, int & cs, int & ce) const;
188 bool insertAsciiString(BufferView &, std::string const & buf, bool usePaste);
189 /// are we operating on several cells?
190 bool tablemode(LCursor & cur) const;
193 Buffer const * buffer_;
195 mutable int cursorx_;
197 mutable int first_visible_cell;
201 #include "mailinset.h"
204 class InsetTabularMailer : public MailInset {
207 InsetTabularMailer(InsetTabular const & inset);
209 virtual InsetBase & inset() const { return inset_; }
211 virtual std::string const & name() const { return name_; }
213 virtual std::string const inset2string(Buffer const &) const;
214 /// Returns the active cell if successful, else -1.
215 static int string2params(std::string const &, InsetTabular &);
217 static std::string const params2string(InsetTabular const &);
220 static std::string const name_;
222 InsetTabular & inset_;
225 std::string const featureAsString(LyXTabular::Feature feature);