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.
11 // This is the rewrite of the tabular (table) support.
13 // It will probably be a lot of work.
15 // One first goal could be to make the inset read the old table format
16 // and just output it again... no viewing at all.
18 // When making the internal structure of tabular support I really think
19 // that STL containers should be used. This will separate the container from
20 // the rest of the code, which is a good thing.
22 // Ideally the tabular support should do as the mathed and use
23 // LaTeX in the .lyx file too.
25 // Things to think of when desingning the new tabular support:
26 // - color support (colortbl, color)
27 // - decimal alignment (dcloumn)
28 // - custom lines (hhline)
34 // This is what I have written about tabular support in the LyX3-Tasks file:
36 // o rewrite of table code. Should probably be written as some
37 // kind of an inset. At least get the code out of the kernel.
38 // - colortbl -multirow
39 // - hhline -multicolumn
41 // o enhance longtable support
45 #ifndef INSETTABULAR_H
46 #define INSETTABULAR_H
50 #include "frontends/mouse_state.h"
60 class InsetTabular : public UpdatableInset {
63 InsetTabular(Buffer const &, int rows = 1, int columns = 1);
65 InsetTabular(InsetTabular const &);
69 virtual std::auto_ptr<InsetBase> clone() const;
71 void read(Buffer const &, LyXLex &);
73 void write(Buffer const &, std::ostream &) const;
75 void metrics(MetricsInfo &, Dimension &) const;
77 void draw(PainterInfo & pi, int x, int y) const;
79 std::string const editMessage() const;
81 void updateLocal(BufferView *) const;
83 bool insetAllowed(InsetOld::Code code) const;
85 bool isTextInset() const { return true; }
86 /** returns true if, when outputing LaTeX, font changes should
87 be closed before generating this inset. This is needed for
88 insets that may contain several paragraphs */
89 bool noFontChange() const { return true; }
91 bool display() const { return tabular.isLongTabular(); }
93 int latex(Buffer const &, std::ostream &,
94 OutputParams const &) const;
96 int plaintext(Buffer const &, std::ostream &,
97 OutputParams const &) const;
99 int linuxdoc(Buffer const &, std::ostream &,
100 OutputParams const &) const;
102 int docbook(Buffer const &, std::ostream &,
103 OutputParams const &) const;
105 void validate(LaTeXFeatures & features) const;
107 InsetOld::Code lyxCode() const { return InsetOld::TABULAR_CODE; }
108 /// get the absolute screen x,y of the cursor
109 void getCursorPos(int & x, int & y) const;
111 bool tabularFeatures(BufferView * bv, std::string const & what);
113 void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
114 std::string const & val = std::string());
116 int getActCell() const { return actcell; }
118 void openLayoutDialog(BufferView *) const;
120 bool showInsetDialog(BufferView *) const;
122 FuncStatus getStatus(std::string const & argument) const;
123 /// Appends \c list with all labels found within this inset.
124 void getLabelList(Buffer const &, std::vector<std::string> & list) const;
126 int scroll(bool recursive = true) const;
128 void scroll(BufferView * bv, float sx) const {
129 UpdatableInset::scroll(bv, sx);
132 void scroll(BufferView * bv, int offset) const {
133 UpdatableInset::scroll(bv, offset);
136 int numParagraphs() const;
138 LyXText * getText(int) const;
143 // this should return true if we have a "normal" cell, otherwise true.
144 // "normal" means without width set!
145 bool forceDefaultParagraphs(InsetOld const * in) const;
148 void addPreview(lyx::graphics::PreviewLoader &) const;
150 /// are some cells selected ?
151 bool hasSelection() const { return has_selection; }
153 Buffer const & buffer() const;
155 /// set the owning buffer
156 void buffer(Buffer * buf);
157 /// lock cell with given index
158 void edit(BufferView * bv, bool);
160 void edit(BufferView * bv, int, int);
161 /// can we go further down on mouse click?
162 bool descendable() const { return true; }
165 // Public structures and variables
167 mutable LyXTabular tabular;
173 priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
176 void lfunMousePress(FuncRequest const &);
178 void lfunMouseRelease(FuncRequest const &);
180 void lfunMouseMotion(FuncRequest const &);
182 void calculate_dimensions_of_cells(MetricsInfo & mi) const;
184 void drawCellLines(Painter &, int x, int baseline,
185 int row, int cell) const;
187 void drawCellSelection(Painter &, int x, int baseline,
188 int row, int column, int cell) const;
190 void setPos(BufferView *, int x, int y) const;
192 DispatchResult moveRight(BufferView *, bool lock);
194 DispatchResult moveLeft(BufferView *, bool lock);
196 DispatchResult moveUp(BufferView *, bool lock);
198 DispatchResult moveDown(BufferView *, bool lock);
200 bool moveNextCell(BufferView *, bool lock = false);
202 bool movePrevCell(BufferView *, bool lock = false);
204 int getCellXPos(int cell) const;
206 void resetPos(BufferView *) const;
208 void removeTabularRow();
210 void clearSelection() const {
211 sel_cell_start = sel_cell_end = 0;
212 has_selection = false;
214 void setSelection(int start, int end) const {
215 sel_cell_start = start;
217 has_selection = true;
220 bool activateCellInset(BufferView *, int x = 0, int y = 0,
221 bool behind = false);
223 bool hasPasteBuffer() const;
225 bool copySelection(BufferView *);
227 bool pasteSelection(BufferView *);
229 bool cutSelection(BufferParams const & bp);
231 bool isRightToLeft(BufferView *);
233 void getSelection(int & scol, int & ecol, int & srow, int & erow) const;
235 bool insertAsciiString(BufferView *, std::string const & buf, bool usePaste);
238 // Private structures and variables
240 InsetText * the_locking_inset;
242 Buffer const * buffer_;
244 mutable int cursorx_;
246 mutable int cursory_;
247 /// true if a set of cells are selected
248 mutable bool has_selection;
249 /// the starting cell selection nr
250 mutable int sel_cell_start;
251 /// the ending cell selection nr
252 mutable int sel_cell_end;
260 mutable int first_visible_cell;
262 mutable int in_reset_pos;
266 #include "mailinset.h"
269 class InsetTabularMailer : public MailInset {
272 InsetTabularMailer(InsetTabular const & inset);
274 virtual InsetBase & inset() const { return inset_; }
276 virtual std::string const & name() const { return name_; }
278 virtual std::string const inset2string(Buffer const &) const;
279 /// Returns the active cell if successful, else -1.
280 static int string2params(std::string const &, InsetTabular &);
282 static std::string const params2string(InsetTabular const &);
285 static std::string const name_;
287 InsetTabular & inset_;
290 std::string const featureAsString(LyXTabular::Feature feature);