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
52 #include "lyxcursor.h"
53 #include "FuncStatus.h"
55 #include <boost/scoped_ptr.hpp>
56 #include <boost/weak_ptr.hpp>
65 class InsetTabular : public UpdatableInset {
77 InsetTabular(Buffer const &, int rows = 1, int columns = 1);
79 InsetTabular(InsetTabular const &, Buffer const &, bool same_id = false);
83 Inset * clone(Buffer const &, bool same_id = false) const;
85 void read(Buffer const *, LyXLex &);
87 void write(Buffer const *, std::ostream &) const;
89 int ascent(BufferView *, LyXFont const &) const;
91 int descent(BufferView *, LyXFont const &) const;
93 int width(BufferView *, LyXFont const & f) const;
95 void draw(BufferView *, const LyXFont &, int , float &) const;
97 void update(BufferView *, bool = false);
99 string const editMessage() const;
101 void edit(BufferView *, int x, int y, mouse_button::state);
103 void edit(BufferView * bv, bool front = true);
105 void insetUnlock(BufferView *);
107 void updateLocal(BufferView *, UpdateCodes) const;
109 bool lockInsetInInset(BufferView *, UpdatableInset *);
111 bool unlockInsetInInset(BufferView *, UpdatableInset *,
114 bool updateInsetInInset(BufferView *, Inset *);
116 int insetInInsetY() const;
118 UpdatableInset * getLockingInset() const;
120 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
122 bool insertInset(BufferView *, Inset *);
124 bool insetAllowed(Inset::Code code) const;
126 bool isTextInset() const { return true; }
127 /** returns true if, when outputing LaTeX, font changes should
128 be closed before generating this inset. This is needed for
129 insets that may contain several paragraphs */
130 bool noFontChange() const { return true; }
132 bool display() const { return tabular->IsLongTabular(); }
134 RESULT localDispatch(FuncRequest const &);
136 int latex(Buffer const *, std::ostream &, bool, bool) const;
138 int ascii(Buffer const *, std::ostream &, int linelen) const;
140 int linuxdoc(Buffer const *, std::ostream &) const;
142 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
144 void validate(LaTeXFeatures & features) const;
146 Inset::Code lyxCode() const { return Inset::TABULAR_CODE; }
148 void getCursorPos(BufferView *, int & x, int & y) const;
149 /// Get the absolute document x,y of the cursor
150 virtual void getCursor(BufferView &, int &, int &) const;
152 bool tabularFeatures(BufferView * bv, string const & what);
154 void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
155 string const & val = string());
157 int getActCell() const { return actcell; }
159 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
160 bool selectall = false);
162 int getMaxWidth(BufferView *, UpdatableInset const *) const;
164 Buffer * bufferOwner() const { return const_cast<Buffer *>(buffer); }
166 LyXText * getLyXText(BufferView const *,
167 bool const recursive = false) const;
169 void deleteLyXText(BufferView *, bool recursive = true) const;
171 void resizeLyXText(BufferView *, bool force = false) const;
173 void openLayoutDialog(BufferView *) const;
175 bool showInsetDialog(BufferView *) const;
177 FuncStatus getStatus(string const & argument) const;
179 std::vector<string> const getLabelList() const;
181 void nodraw(bool b) const {
182 UpdatableInset::nodraw(b);
186 int scroll(bool recursive=true) const;
188 void scroll(BufferView *bv, float sx) const {
189 UpdatableInset::scroll(bv, sx);
192 void scroll(BufferView *bv, int offset) const {
193 UpdatableInset::scroll(bv, offset);
196 Inset * getInsetFromID(int id) const;
198 Paragraph * firstParagraph() const;
200 Paragraph * getFirstParagraph(int) const;
202 LyXCursor const & cursor(BufferView *) const;
204 bool allowSpellcheck() const { return true; }
207 selectNextWordToSpellcheck(BufferView *, float & value) const;
209 void selectSelectedWord(BufferView *);
211 void toggleSelection(BufferView *, bool kill_selection);
216 bool nextChange(BufferView *, lyx::pos_type & length);
218 bool searchForward(BufferView *, string const &,
219 bool = true, bool = false);
220 bool searchBackward(BufferView *, string const &,
221 bool = true, bool = false);
223 // this should return true if we have a "normal" cell, otherwise true.
224 // "normal" means without width set!
225 bool forceDefaultParagraphs(Inset const * in) const;
228 void addPreview(grfx::PreviewLoader &) const;
231 // Public structures and variables
233 boost::scoped_ptr<LyXTabular> tabular;
235 /// are some cells selected ?
236 bool hasSelection() const {
237 return has_selection;
241 virtual BufferView * view() const;
244 void lfunMousePress(FuncRequest const &);
246 // the bool return is used to see if we opened a dialog so that we can
247 // check this from an outer inset and open the dialog of the outer inset
248 // if that one has one!
250 bool lfunMouseRelease(FuncRequest const &);
252 void lfunMouseMotion(FuncRequest const &);
254 bool calculate_dimensions_of_cells(BufferView *, bool = false) const;
256 void drawCellLines(Painter &, int x, int baseline,
257 int row, int cell) const;
259 void drawCellSelection(Painter &, int x, int baseline,
260 int row, int column, int cell) const;
262 void fitInsetCursor(BufferView *) const;
264 void setPos(BufferView *, int x, int y) const;
266 RESULT moveRight(BufferView *, bool lock = true);
268 RESULT moveLeft(BufferView *, bool lock = true);
270 RESULT moveUp(BufferView *, bool lock = true);
272 RESULT moveDown(BufferView *, bool lock = true);
274 bool moveNextCell(BufferView *, bool lock = false);
276 bool movePrevCell(BufferView *, bool lock = false);
278 int getCellXPos(int cell) const;
280 void resetPos(BufferView *) const;
282 void removeTabularRow();
284 void clearSelection() const {
285 sel_cell_start = sel_cell_end = 0;
286 has_selection = false;
288 void setSelection(int start, int end) const {
289 sel_cell_start = start;
291 has_selection = true;
294 bool activateCellInset(BufferView *, int x = 0, int y = 0,
295 mouse_button::state button = mouse_button::none,
296 bool behind = false);
298 bool activateCellInsetAbs(BufferView *, int x = 0, int y = 0,
299 mouse_button::state button = mouse_button::none);
301 bool insetHit(BufferView * bv, int x, int y) const;
303 int getMaxWidthOfCell(BufferView * bv, int cell) const;
305 bool hasPasteBuffer() const;
307 bool copySelection(BufferView *);
309 bool pasteSelection(BufferView *);
311 bool cutSelection(BufferParams const & bp);
313 bool isRightToLeft(BufferView *);
315 void getSelection(int & scol, int & ecol,
316 int & srow, int & erow) const;
318 WordLangTuple selectNextWordInt(BufferView *, float & value) const;
320 bool insertAsciiString(BufferView *, string const & buf, bool usePaste);
323 // Private structures and variables
325 InsetText * the_locking_inset;
327 InsetText * old_locking_inset;
329 Buffer const * buffer;
331 mutable LyXCursor cursor_;
333 mutable unsigned int inset_x;
335 mutable unsigned int inset_y;
336 /// true if a set of cells are selected
337 mutable bool has_selection;
338 /// the starting cell selection nr
339 mutable int sel_cell_start;
340 /// the ending cell selection nr
341 mutable int sel_cell_end;
351 mutable int first_visible_cell;
357 mutable UpdateCodes need_update;
361 mutable int in_reset_pos;
365 #include "mailinset.h"
368 class InsetTabularMailer : public MailInset {
371 InsetTabularMailer(InsetTabular & inset);
373 virtual InsetBase & inset() const { return inset_; }
375 virtual string const & name() const { return name_; }
377 virtual string const inset2string() const;
378 /// Returns the active cell if successful, else -1.
379 static int string2params(string const &, InsetTabular &);
381 static string const params2string(InsetTabular const &);
384 static string const name_;
386 InsetTabular & inset_;
389 string const featureAsString(LyXTabular::Feature feature);