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 "FuncStatus.h"
52 #include "frontends/mouse_state.h"
61 class InsetTabular : public UpdatableInset {
72 InsetTabular(Buffer const &, int rows = 1, int columns = 1);
74 InsetTabular(InsetTabular const &);
78 virtual std::auto_ptr<InsetBase> clone() const;
80 void read(Buffer const *, LyXLex &);
82 void write(Buffer const *, std::ostream &) const;
84 void metrics(MetricsInfo &, Dimension &) const;
86 void draw(PainterInfo & pi, int x, int y) const;
88 string const editMessage() const;
90 void insetUnlock(BufferView *);
92 void updateLocal(BufferView *, UpdateCodes) const;
94 bool lockInsetInInset(BufferView *, UpdatableInset *);
96 bool unlockInsetInInset(BufferView *, UpdatableInset *,
99 bool updateInsetInInset(BufferView *, Inset *);
101 int insetInInsetY() const;
103 UpdatableInset * getLockingInset() const;
105 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
107 bool insertInset(BufferView *, Inset *);
109 bool insetAllowed(Inset::Code code) const;
111 bool isTextInset() const { return true; }
112 /** returns true if, when outputing LaTeX, font changes should
113 be closed before generating this inset. This is needed for
114 insets that may contain several paragraphs */
115 bool noFontChange() const { return true; }
117 bool display() const { return tabular.isLongTabular(); }
119 RESULT localDispatch(FuncRequest const &);
121 int latex(Buffer const *, std::ostream &,
122 LatexRunParams const &) const;
124 int ascii(Buffer const *, std::ostream &, int linelen) const;
126 int linuxdoc(Buffer const *, std::ostream &) const;
128 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
130 void validate(LaTeXFeatures & features) const;
132 Inset::Code lyxCode() const { return Inset::TABULAR_CODE; }
134 void getCursorPos(BufferView *, int & x, int & y) const;
135 /// Get the absolute document x,y of the cursor
136 virtual void getCursor(BufferView &, int &, int &) const;
138 bool tabularFeatures(BufferView * bv, string const & what);
140 void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
141 string const & val = string());
143 int getActCell() const { return actcell; }
145 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
146 bool selectall = false);
148 LyXText * getLyXText(BufferView const *,
149 bool const recursive = false) const;
151 void deleteLyXText(BufferView *, bool recursive = true) const;
153 void resizeLyXText(BufferView *, bool force = false) const;
155 void openLayoutDialog(BufferView *) const;
157 bool showInsetDialog(BufferView *) const;
159 FuncStatus getStatus(string const & argument) const;
161 void getLabelList(std::vector<string> &) const;
163 void nodraw(bool b) const {
164 UpdatableInset::nodraw(b);
168 int scroll(bool recursive=true) const;
170 void scroll(BufferView *bv, float sx) const {
171 UpdatableInset::scroll(bv, sx);
174 void scroll(BufferView *bv, int offset) const {
175 UpdatableInset::scroll(bv, offset);
178 Inset * getInsetFromID(int id) const;
180 ParagraphList * getParagraphs(int) const;
182 LyXCursor const & cursor(BufferView *) const;
184 bool allowSpellcheck() const { return true; }
187 selectNextWordToSpellcheck(BufferView *, float & value) const;
189 void selectSelectedWord(BufferView *);
191 void toggleSelection(BufferView *, bool kill_selection);
196 bool nextChange(BufferView *, lyx::pos_type & length);
198 bool searchForward(BufferView *, string const &,
199 bool = true, bool = false);
200 bool searchBackward(BufferView *, string const &,
201 bool = true, bool = false);
203 // this should return true if we have a "normal" cell, otherwise true.
204 // "normal" means without width set!
205 bool forceDefaultParagraphs(Inset const * in) const;
208 void addPreview(lyx::graphics::PreviewLoader &) const;
211 // Public structures and variables
213 mutable LyXTabular tabular;
215 /// are some cells selected ?
216 bool hasSelection() const {
217 return has_selection;
221 virtual BufferView * view() const;
223 Buffer const * buffer() const;
225 /// set the owning buffer
226 void buffer(Buffer * b);
230 void lfunMousePress(FuncRequest const &);
232 // the bool return is used to see if we opened a dialog so that we can
233 // check this from an outer inset and open the dialog of the outer inset
234 // if that one has one!
236 bool lfunMouseRelease(FuncRequest const &);
238 void lfunMouseMotion(FuncRequest const &);
240 void calculate_dimensions_of_cells(MetricsInfo & mi) const;
242 void drawCellLines(Painter &, int x, int baseline,
243 int row, int cell) const;
245 void drawCellSelection(Painter &, int x, int baseline,
246 int row, int column, int cell) const;
248 void fitInsetCursor(BufferView *) const;
250 void setPos(BufferView *, int x, int y) const;
252 RESULT moveRight(BufferView *, bool lock = true);
254 RESULT moveLeft(BufferView *, bool lock = true);
256 RESULT moveUp(BufferView *, bool lock = true);
258 RESULT moveDown(BufferView *, bool lock = true);
260 bool moveNextCell(BufferView *, bool lock = false);
262 bool movePrevCell(BufferView *, bool lock = false);
264 int getCellXPos(int cell) const;
266 void resetPos(BufferView *) const;
268 void removeTabularRow();
270 void clearSelection() const {
271 sel_cell_start = sel_cell_end = 0;
272 has_selection = false;
274 void setSelection(int start, int end) const {
275 sel_cell_start = start;
277 has_selection = true;
280 bool activateCellInset(BufferView *, int x = 0, int y = 0,
281 mouse_button::state button = mouse_button::none,
282 bool behind = false);
284 bool activateCellInsetAbs(BufferView *, int x = 0, int y = 0,
285 mouse_button::state button = mouse_button::none);
287 bool insetHit(BufferView * bv, int x, int y) const;
289 bool hasPasteBuffer() const;
291 bool copySelection(BufferView *);
293 bool pasteSelection(BufferView *);
295 bool cutSelection(BufferParams const & bp);
297 bool isRightToLeft(BufferView *);
299 void getSelection(int & scol, int & ecol,
300 int & srow, int & erow) const;
302 WordLangTuple selectNextWordInt(BufferView *, float & value) const;
304 bool insertAsciiString(BufferView *, string const & buf, bool usePaste);
307 // Private structures and variables
309 InsetText * the_locking_inset;
311 InsetText * old_locking_inset;
313 Buffer const * buffer_;
315 mutable int cursorx_;
317 mutable int cursory_;
319 mutable unsigned int inset_x;
321 mutable unsigned int inset_y;
322 /// true if a set of cells are selected
323 mutable bool has_selection;
324 /// the starting cell selection nr
325 mutable int sel_cell_start;
326 /// the ending cell selection nr
327 mutable int sel_cell_end;
337 mutable int first_visible_cell;
343 mutable UpdateCodes need_update;
345 mutable int in_reset_pos;
349 #include "mailinset.h"
352 class InsetTabularMailer : public MailInset {
355 InsetTabularMailer(InsetTabular const & inset);
357 virtual InsetBase & inset() const { return inset_; }
359 virtual string const & name() const { return name_; }
361 virtual string const inset2string(Buffer const &) const;
362 /// Returns the active cell if successful, else -1.
363 static int string2params(string const &, InsetTabular &);
365 static string const params2string(InsetTabular const &);
368 static string const name_;
370 InsetTabular & inset_;
373 string const featureAsString(LyXTabular::Feature feature);