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 "lyxcursor.h"
52 #include "FuncStatus.h"
53 #include "frontends/mouse_state.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 void dimension(BufferView *, LyXFont const &, Dimension &) const;
91 void draw(BufferView *, const LyXFont &, int , float &) const;
93 void update(BufferView *, bool = false);
95 string const editMessage() const;
97 void insetUnlock(BufferView *);
99 void updateLocal(BufferView *, UpdateCodes) const;
101 bool lockInsetInInset(BufferView *, UpdatableInset *);
103 bool unlockInsetInInset(BufferView *, UpdatableInset *,
106 bool updateInsetInInset(BufferView *, Inset *);
108 int insetInInsetY() const;
110 UpdatableInset * getLockingInset() const;
112 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
114 bool insertInset(BufferView *, Inset *);
116 bool insetAllowed(Inset::Code code) const;
118 bool isTextInset() const { return true; }
119 /** returns true if, when outputing LaTeX, font changes should
120 be closed before generating this inset. This is needed for
121 insets that may contain several paragraphs */
122 bool noFontChange() const { return true; }
124 bool display() const { return tabular->IsLongTabular(); }
126 RESULT localDispatch(FuncRequest const &);
128 int latex(Buffer const *, std::ostream &, LatexRunParams const &,
131 int ascii(Buffer const *, std::ostream &, int linelen) const;
133 int linuxdoc(Buffer const *, std::ostream &) const;
135 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
137 void validate(LaTeXFeatures & features) const;
139 Inset::Code lyxCode() const { return Inset::TABULAR_CODE; }
141 void getCursorPos(BufferView *, int & x, int & y) const;
142 /// Get the absolute document x,y of the cursor
143 virtual void getCursor(BufferView &, int &, int &) const;
145 bool tabularFeatures(BufferView * bv, string const & what);
147 void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
148 string const & val = string());
150 int getActCell() const { return actcell; }
152 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
153 bool selectall = false);
155 int getMaxWidth(BufferView *, UpdatableInset const *) const;
157 Buffer * bufferOwner() const { return const_cast<Buffer *>(buffer); }
159 LyXText * getLyXText(BufferView const *,
160 bool const recursive = false) const;
162 void deleteLyXText(BufferView *, bool recursive = true) const;
164 void resizeLyXText(BufferView *, bool force = false) const;
166 void openLayoutDialog(BufferView *) const;
168 bool showInsetDialog(BufferView *) const;
170 FuncStatus getStatus(string const & argument) const;
172 std::vector<string> const getLabelList() const;
174 void nodraw(bool b) const {
175 UpdatableInset::nodraw(b);
179 int scroll(bool recursive=true) const;
181 void scroll(BufferView *bv, float sx) const {
182 UpdatableInset::scroll(bv, sx);
185 void scroll(BufferView *bv, int offset) const {
186 UpdatableInset::scroll(bv, offset);
189 Inset * getInsetFromID(int id) const;
191 ParagraphList * getParagraphs(int) const;
193 LyXCursor const & cursor(BufferView *) const;
195 bool allowSpellcheck() const { return true; }
198 selectNextWordToSpellcheck(BufferView *, float & value) const;
200 void selectSelectedWord(BufferView *);
202 void toggleSelection(BufferView *, bool kill_selection);
207 bool nextChange(BufferView *, lyx::pos_type & length);
209 bool searchForward(BufferView *, string const &,
210 bool = true, bool = false);
211 bool searchBackward(BufferView *, string const &,
212 bool = true, bool = false);
214 // this should return true if we have a "normal" cell, otherwise true.
215 // "normal" means without width set!
216 bool forceDefaultParagraphs(Inset const * in) const;
219 void addPreview(grfx::PreviewLoader &) const;
222 // Public structures and variables
224 boost::scoped_ptr<LyXTabular> tabular;
226 /// are some cells selected ?
227 bool hasSelection() const {
228 return has_selection;
232 virtual BufferView * view() const;
235 void lfunMousePress(FuncRequest const &);
237 // the bool return is used to see if we opened a dialog so that we can
238 // check this from an outer inset and open the dialog of the outer inset
239 // if that one has one!
241 bool lfunMouseRelease(FuncRequest const &);
243 void lfunMouseMotion(FuncRequest const &);
245 bool calculate_dimensions_of_cells(BufferView *, bool = false) const;
247 void drawCellLines(Painter &, int x, int baseline,
248 int row, int cell) const;
250 void drawCellSelection(Painter &, int x, int baseline,
251 int row, int column, int cell) const;
253 void fitInsetCursor(BufferView *) const;
255 void setPos(BufferView *, int x, int y) const;
257 RESULT moveRight(BufferView *, bool lock = true);
259 RESULT moveLeft(BufferView *, bool lock = true);
261 RESULT moveUp(BufferView *, bool lock = true);
263 RESULT moveDown(BufferView *, bool lock = true);
265 bool moveNextCell(BufferView *, bool lock = false);
267 bool movePrevCell(BufferView *, bool lock = false);
269 int getCellXPos(int cell) const;
271 void resetPos(BufferView *) const;
273 void removeTabularRow();
275 void clearSelection() const {
276 sel_cell_start = sel_cell_end = 0;
277 has_selection = false;
279 void setSelection(int start, int end) const {
280 sel_cell_start = start;
282 has_selection = true;
285 bool activateCellInset(BufferView *, int x = 0, int y = 0,
286 mouse_button::state button = mouse_button::none,
287 bool behind = false);
289 bool activateCellInsetAbs(BufferView *, int x = 0, int y = 0,
290 mouse_button::state button = mouse_button::none);
292 bool insetHit(BufferView * bv, int x, int y) const;
294 int getMaxWidthOfCell(BufferView * bv, int cell) const;
296 bool hasPasteBuffer() const;
298 bool copySelection(BufferView *);
300 bool pasteSelection(BufferView *);
302 bool cutSelection(BufferParams const & bp);
304 bool isRightToLeft(BufferView *);
306 void getSelection(int & scol, int & ecol,
307 int & srow, int & erow) const;
309 WordLangTuple selectNextWordInt(BufferView *, float & value) const;
311 bool insertAsciiString(BufferView *, string const & buf, bool usePaste);
314 // Private structures and variables
316 InsetText * the_locking_inset;
318 InsetText * old_locking_inset;
320 Buffer const * buffer;
322 mutable LyXCursor cursor_;
324 mutable unsigned int inset_x;
326 mutable unsigned int inset_y;
327 /// true if a set of cells are selected
328 mutable bool has_selection;
329 /// the starting cell selection nr
330 mutable int sel_cell_start;
331 /// the ending cell selection nr
332 mutable int sel_cell_end;
342 mutable int first_visible_cell;
348 mutable UpdateCodes need_update;
352 mutable int in_reset_pos;
356 #include "mailinset.h"
359 class InsetTabularMailer : public MailInset {
362 InsetTabularMailer(InsetTabular & inset);
364 virtual InsetBase & inset() const { return inset_; }
366 virtual string const & name() const { return name_; }
368 virtual string const inset2string() const;
369 /// Returns the active cell if successful, else -1.
370 static int string2params(string const &, InsetTabular &);
372 static string const params2string(InsetTabular const &);
375 static string const name_;
377 InsetTabular & inset_;
380 string const featureAsString(LyXTabular::Feature feature);