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
51 #include "frontends/mouse_state.h"
61 class InsetTabular : public UpdatableInset {
64 InsetTabular(Buffer const &, int rows = 1, int columns = 1);
66 InsetTabular(InsetTabular const &);
70 virtual std::auto_ptr<InsetBase> clone() const;
72 void read(Buffer const &, LyXLex &);
74 void write(Buffer const &, std::ostream &) const;
76 void metrics(MetricsInfo &, Dimension &) const;
78 void draw(PainterInfo & pi, int x, int y) const;
80 string const editMessage() const;
82 void insetUnlock(BufferView *);
84 void updateLocal(BufferView *) const;
86 bool lockInsetInInset(BufferView *, UpdatableInset *);
88 bool unlockInsetInInset(BufferView *, UpdatableInset *,
91 int insetInInsetY() const;
93 UpdatableInset * getLockingInset() const;
95 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
97 bool insertInset(BufferView *, InsetOld *);
99 bool insetAllowed(InsetOld::Code code) const;
101 bool isTextInset() const { return true; }
102 /** returns true if, when outputing LaTeX, font changes should
103 be closed before generating this inset. This is needed for
104 insets that may contain several paragraphs */
105 bool noFontChange() const { return true; }
107 bool display() const { return tabular.isLongTabular(); }
109 RESULT localDispatch(FuncRequest const &);
111 int latex(Buffer const &, std::ostream &,
112 LatexRunParams const &) const;
114 int ascii(Buffer const &, std::ostream &, int linelen) const;
116 int linuxdoc(Buffer const &, std::ostream &) const;
118 int docbook(Buffer const &, std::ostream &, bool mixcont) const;
120 void validate(LaTeXFeatures & features) const;
122 InsetOld::Code lyxCode() const { return InsetOld::TABULAR_CODE; }
124 void getCursorPos(BufferView *, int & x, int & y) const;
125 /// Get the absolute document x,y of the cursor
126 virtual void getCursor(BufferView &, int &, int &) const;
128 bool tabularFeatures(BufferView * bv, string const & what);
130 void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
131 string const & val = string());
133 int getActCell() const { return actcell; }
135 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
136 bool selectall = false);
138 LyXText * getLyXText(BufferView const *,
139 bool const recursive = false) const;
141 void deleteLyXText(BufferView *, bool recursive = true) const;
143 void openLayoutDialog(BufferView *) const;
145 bool showInsetDialog(BufferView *) const;
147 FuncStatus getStatus(string const & argument) const;
149 void getLabelList(std::vector<string> &) const;
151 int scroll(bool recursive=true) const;
153 void scroll(BufferView *bv, float sx) const {
154 UpdatableInset::scroll(bv, sx);
157 void scroll(BufferView *bv, int offset) const {
158 UpdatableInset::scroll(bv, offset);
161 InsetOld * getInsetFromID(int id) const;
163 ParagraphList * getParagraphs(int) const;
165 LyXCursor const & cursor(BufferView *) const;
167 bool allowSpellcheck() const { return true; }
170 selectNextWordToSpellcheck(BufferView *, float & value) const;
172 void selectSelectedWord(BufferView *);
177 bool nextChange(BufferView *, lyx::pos_type & length);
179 bool searchForward(BufferView *, string const &,
180 bool = true, bool = false);
181 bool searchBackward(BufferView *, string const &,
182 bool = true, bool = false);
184 // this should return true if we have a "normal" cell, otherwise true.
185 // "normal" means without width set!
186 bool forceDefaultParagraphs(InsetOld const * in) const;
189 void addPreview(lyx::graphics::PreviewLoader &) const;
192 // Public structures and variables
194 mutable LyXTabular tabular;
196 /// are some cells selected ?
197 bool hasSelection() const {
198 return has_selection;
202 virtual BufferView * view() const;
204 Buffer const & buffer() const;
206 /// set the owning buffer
207 void buffer(Buffer * b);
211 void lfunMousePress(FuncRequest const &);
213 // the bool return is used to see if we opened a dialog so that we can
214 // check this from an outer inset and open the dialog of the outer inset
215 // if that one has one!
217 bool lfunMouseRelease(FuncRequest const &);
219 void lfunMouseMotion(FuncRequest const &);
221 void calculate_dimensions_of_cells(MetricsInfo & mi) const;
223 void drawCellLines(Painter &, int x, int baseline,
224 int row, int cell) const;
226 void drawCellSelection(Painter &, int x, int baseline,
227 int row, int column, int cell) const;
229 void fitInsetCursor(BufferView *) const;
231 void setPos(BufferView *, int x, int y) const;
233 RESULT moveRight(BufferView *, bool lock = true);
235 RESULT moveLeft(BufferView *, bool lock = true);
237 RESULT moveUp(BufferView *, bool lock = true);
239 RESULT moveDown(BufferView *, bool lock = true);
241 bool moveNextCell(BufferView *, bool lock = false);
243 bool movePrevCell(BufferView *, bool lock = false);
245 int getCellXPos(int cell) const;
247 void resetPos(BufferView *) const;
249 void removeTabularRow();
251 void clearSelection() const {
252 sel_cell_start = sel_cell_end = 0;
253 has_selection = false;
255 void setSelection(int start, int end) const {
256 sel_cell_start = start;
258 has_selection = true;
261 bool activateCellInset(BufferView *, int x = 0, int y = 0,
262 mouse_button::state button = mouse_button::none,
263 bool behind = false);
265 bool activateCellInsetAbs(BufferView *, int x = 0, int y = 0,
266 mouse_button::state button = mouse_button::none);
268 bool insetHit(BufferView * bv, int x, int y) const;
270 bool hasPasteBuffer() const;
272 bool copySelection(BufferView *);
274 bool pasteSelection(BufferView *);
276 bool cutSelection(BufferParams const & bp);
278 bool isRightToLeft(BufferView *);
280 void getSelection(int & scol, int & ecol,
281 int & srow, int & erow) const;
283 WordLangTuple selectNextWordInt(BufferView *, float & value) const;
285 bool insertAsciiString(BufferView *, string const & buf, bool usePaste);
288 // Private structures and variables
290 InsetText * the_locking_inset;
292 InsetText * old_locking_inset;
294 Buffer const * buffer_;
296 mutable int cursorx_;
298 mutable int cursory_;
300 mutable unsigned int inset_x;
302 mutable unsigned int inset_y;
303 /// true if a set of cells are selected
304 mutable bool has_selection;
305 /// the starting cell selection nr
306 mutable int sel_cell_start;
307 /// the ending cell selection nr
308 mutable int sel_cell_end;
318 mutable int first_visible_cell;
324 mutable int in_reset_pos;
328 #include "mailinset.h"
331 class InsetTabularMailer : public MailInset {
334 InsetTabularMailer(InsetTabular const & inset);
336 virtual InsetBase & inset() const { return inset_; }
338 virtual string const & name() const { return name_; }
340 virtual string const inset2string(Buffer const &) const;
341 /// Returns the active cell if successful, else -1.
342 static int string2params(string const &, InsetTabular &);
344 static string const params2string(InsetTabular const &);
347 static string const name_;
349 InsetTabular & inset_;
352 string const featureAsString(LyXTabular::Feature feature);