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 int insetInInsetY() const;
85 bool insertInset(BufferView *, InsetOld *);
87 bool insetAllowed(InsetOld::Code code) const;
89 bool isTextInset() const { return true; }
90 /** returns true if, when outputing LaTeX, font changes should
91 be closed before generating this inset. This is needed for
92 insets that may contain several paragraphs */
93 bool noFontChange() const { return true; }
95 bool display() const { return tabular.isLongTabular(); }
97 int latex(Buffer const &, std::ostream &,
98 OutputParams const &) const;
100 int plaintext(Buffer const &, std::ostream &,
101 OutputParams const &) const;
103 int linuxdoc(Buffer const &, std::ostream &,
104 OutputParams const &) const;
106 int docbook(Buffer const &, std::ostream &,
107 OutputParams const &) const;
109 void validate(LaTeXFeatures & features) const;
111 InsetOld::Code lyxCode() const { return InsetOld::TABULAR_CODE; }
112 /// get the absolute screen x,y of the cursor
113 void getCursorPos(BufferView *, int & x, int & y) const;
115 bool tabularFeatures(BufferView * bv, std::string const & what);
117 void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
118 std::string const & val = std::string());
120 int getActCell() const { return actcell; }
122 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
123 bool selectall = false);
125 void openLayoutDialog(BufferView *) const;
127 bool showInsetDialog(BufferView *) const;
129 FuncStatus getStatus(std::string const & argument) const;
130 /// Appends \c list with all labels found within this inset.
131 void getLabelList(Buffer const &, std::vector<std::string> & list) const;
133 int scroll(bool recursive=true) const;
135 void scroll(BufferView *bv, float sx) const {
136 UpdatableInset::scroll(bv, sx);
139 void scroll(BufferView *bv, int offset) const {
140 UpdatableInset::scroll(bv, offset);
143 ParagraphList * getParagraphs(int) const;
145 int numParagraphs() const;
147 LyXText * getText(int) const;
152 // this should return true if we have a "normal" cell, otherwise true.
153 // "normal" means without width set!
154 bool forceDefaultParagraphs(InsetOld const * in) const;
157 void addPreview(lyx::graphics::PreviewLoader &) const;
160 // Public structures and variables
162 mutable LyXTabular tabular;
164 /// are some cells selected ?
165 bool hasSelection() const { return has_selection; }
168 Buffer const & buffer() const;
170 /// set the owning buffer
171 void buffer(Buffer * buf);
172 /// lock cell with given index
173 void edit(BufferView * bv, bool);
175 void edit(BufferView * bv, int, int);
180 priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
183 void lfunMousePress(FuncRequest const &);
185 void lfunMouseRelease(FuncRequest const &);
187 void lfunMouseMotion(FuncRequest const &);
189 void calculate_dimensions_of_cells(MetricsInfo & mi) const;
191 void drawCellLines(Painter &, int x, int baseline,
192 int row, int cell) const;
194 void drawCellSelection(Painter &, int x, int baseline,
195 int row, int column, int cell) const;
197 void setPos(BufferView *, int x, int y) const;
199 DispatchResult moveRight(BufferView *, bool lock);
201 DispatchResult moveLeft(BufferView *, bool lock);
203 DispatchResult moveUp(BufferView *, bool lock);
205 DispatchResult moveDown(BufferView *, bool lock);
207 bool moveNextCell(BufferView *, bool lock = false);
209 bool movePrevCell(BufferView *, bool lock = false);
211 int getCellXPos(int cell) const;
213 void resetPos(BufferView *) const;
215 void removeTabularRow();
217 void clearSelection() const {
218 sel_cell_start = sel_cell_end = 0;
219 has_selection = false;
221 void setSelection(int start, int end) const {
222 sel_cell_start = start;
224 has_selection = true;
227 bool activateCellInset(BufferView *, int x = 0, int y = 0,
228 bool behind = false);
230 bool hasPasteBuffer() const;
232 bool copySelection(BufferView *);
234 bool pasteSelection(BufferView *);
236 bool cutSelection(BufferParams const & bp);
238 bool isRightToLeft(BufferView *);
240 void getSelection(int & scol, int & ecol, int & srow, int & erow) const;
242 bool insertAsciiString(BufferView *, std::string const & buf, bool usePaste);
245 // Private structures and variables
247 InsetText * the_locking_inset;
249 Buffer const * buffer_;
251 mutable int cursorx_;
253 mutable int cursory_;
254 /// true if a set of cells are selected
255 mutable bool has_selection;
256 /// the starting cell selection nr
257 mutable int sel_cell_start;
258 /// the ending cell selection nr
259 mutable int sel_cell_end;
267 mutable int first_visible_cell;
269 mutable int in_reset_pos;
273 #include "mailinset.h"
276 class InsetTabularMailer : public MailInset {
279 InsetTabularMailer(InsetTabular const & inset);
281 virtual InsetBase & inset() const { return inset_; }
283 virtual std::string const & name() const { return name_; }
285 virtual std::string const inset2string(Buffer const &) const;
286 /// Returns the active cell if successful, else -1.
287 static int string2params(std::string const &, InsetTabular &);
289 static std::string const params2string(InsetTabular const &);
292 static std::string const name_;
294 InsetTabular & inset_;
297 std::string const featureAsString(LyXTabular::Feature feature);