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>
57 #include <boost/signals/signal0.hpp>
66 class InsetTabular : public UpdatableInset {
78 InsetTabular(Buffer const &, int rows = 1, int columns = 1);
80 InsetTabular(InsetTabular const &, Buffer const &, bool same_id = false);
84 Inset * clone(Buffer const &, bool same_id = false) const;
86 void read(Buffer const *, LyXLex &);
88 void write(Buffer const *, std::ostream &) const;
90 int ascent(BufferView *, LyXFont const &) const;
92 int descent(BufferView *, LyXFont const &) const;
94 int width(BufferView *, LyXFont const & f) const;
96 void draw(BufferView *, const LyXFont &, int , float &, bool) const;
98 void update(BufferView *, LyXFont const &, bool = false);
100 string const editMessage() const;
102 void edit(BufferView *, int x, int y, mouse_button::state);
104 void edit(BufferView * bv, bool front = true);
106 bool doClearArea() const;
108 void insetUnlock(BufferView *);
110 void updateLocal(BufferView *, UpdateCodes, bool mark_dirty) const;
112 bool lockInsetInInset(BufferView *, UpdatableInset *);
114 bool unlockInsetInInset(BufferView *, UpdatableInset *,
117 bool updateInsetInInset(BufferView *, Inset *);
119 int insetInInsetY() const;
121 UpdatableInset * getLockingInset() const;
123 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
125 bool insertInset(BufferView *, Inset *);
127 bool insetAllowed(Inset::Code code) const;
129 bool isTextInset() const { return true; }
130 /** returns true if, when outputing LaTeX, font changes should
131 be closed before generating this inset. This is needed for
132 insets that may contain several paragraphs */
133 bool noFontChange() const { return true; }
135 bool display() const { return tabular->IsLongTabular(); }
137 RESULT localDispatch(FuncRequest const &);
139 int latex(Buffer const *, std::ostream &, bool, bool) const;
141 int ascii(Buffer const *, std::ostream &, int linelen) const;
143 int linuxdoc(Buffer const *, std::ostream &) const;
145 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
147 void validate(LaTeXFeatures & features) const;
149 Inset::Code lyxCode() const { return Inset::TABULAR_CODE; }
151 void getCursorPos(BufferView *, int & x, int & y) const;
153 void toggleInsetCursor(BufferView *);
155 bool tabularFeatures(BufferView * bv, string const & what);
157 void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
158 string const & val = string());
160 int getActCell() const { return actcell; }
162 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
163 bool selectall = false);
165 int getMaxWidth(BufferView *, UpdatableInset const *) const;
167 Buffer * bufferOwner() const { return const_cast<Buffer *>(buffer); }
169 LyXText * getLyXText(BufferView const *,
170 bool const recursive = false) const;
172 void deleteLyXText(BufferView *, bool recursive = true) const;
174 void resizeLyXText(BufferView *, bool force = false) const;
176 void openLayoutDialog(BufferView *) const;
178 bool showInsetDialog(BufferView *) const;
180 FuncStatus getStatus(string const & argument) const;
182 std::vector<string> const getLabelList() const;
184 void nodraw(bool b) const {
185 UpdatableInset::nodraw(b);
189 int scroll(bool recursive=true) const;
191 void scroll(BufferView *bv, float sx) const {
192 UpdatableInset::scroll(bv, sx);
195 void scroll(BufferView *bv, int offset) const {
196 UpdatableInset::scroll(bv, offset);
199 Inset * getInsetFromID(int id) const;
201 Paragraph * firstParagraph() const;
203 Paragraph * getFirstParagraph(int) const;
205 LyXCursor const & cursor(BufferView *) const;
207 bool allowSpellcheck() const { return true; }
210 selectNextWordToSpellcheck(BufferView *, float & value) const;
212 void selectSelectedWord(BufferView *);
214 void toggleSelection(BufferView *, bool kill_selection);
219 bool nextChange(BufferView *, lyx::pos_type & length);
221 bool searchForward(BufferView *, string const &,
222 bool = true, bool = false);
223 bool searchBackward(BufferView *, string const &,
224 bool = true, bool = false);
226 // this should return true if we have a "normal" cell, otherwise true.
227 // "normal" means without width set!
228 bool forceDefaultParagraphs(Inset const * in) const;
231 void addPreview(grfx::PreviewLoader &) const;
234 // Public structures and variables
236 boost::scoped_ptr<LyXTabular> tabular;
238 boost::signal0<void> hideDialog;
240 /// are some cells selected ?
241 bool hasSelection() const {
242 return has_selection;
246 void lfunMousePress(FuncRequest const &);
248 // the bool return is used to see if we opened a dialog so that we can
249 // check this from an outer inset and open the dialog of the outer inset
250 // if that one has one!
252 bool lfunMouseRelease(FuncRequest const &);
254 void lfunMouseMotion(FuncRequest const &);
256 bool calculate_dimensions_of_cells(BufferView *, LyXFont const &,
259 void drawCellLines(Painter &, int x, int baseline,
260 int row, int cell) const;
262 void drawCellSelection(Painter &, int x, int baseline,
263 int row, int column, int cell) const;
265 void showInsetCursor(BufferView *, bool show=true);
267 void hideInsetCursor(BufferView *);
269 void fitInsetCursor(BufferView *) const;
271 void setPos(BufferView *, int x, int y) const;
273 RESULT moveRight(BufferView *, bool lock = true);
275 RESULT moveLeft(BufferView *, bool lock = true);
277 RESULT moveUp(BufferView *, bool lock = true);
279 RESULT moveDown(BufferView *, bool lock = true);
281 bool moveNextCell(BufferView *, bool lock = false);
283 bool movePrevCell(BufferView *, bool lock = false);
285 int getCellXPos(int cell) const;
287 void resetPos(BufferView *) const;
289 void removeTabularRow();
291 void clearSelection() const {
292 sel_cell_start = sel_cell_end = 0;
293 has_selection = false;
295 void setSelection(int start, int end) const {
296 sel_cell_start = start;
298 has_selection = true;
301 bool activateCellInset(BufferView *, int x = 0, int y = 0,
302 mouse_button::state button = mouse_button::none,
303 bool behind = false);
305 bool activateCellInsetAbs(BufferView *, int x = 0, int y = 0,
306 mouse_button::state button = mouse_button::none);
308 bool insetHit(BufferView * bv, int x, int y) const;
310 int getMaxWidthOfCell(BufferView * bv, int cell) const;
312 bool hasPasteBuffer() const;
314 bool copySelection(BufferView *);
316 bool pasteSelection(BufferView *);
318 bool cutSelection(BufferParams const & bp);
320 bool isRightToLeft(BufferView *);
322 void getSelection(int & scol, int & ecol,
323 int & srow, int & erow) const;
325 WordLangTuple selectNextWordInt(BufferView *, float & value) const;
327 bool insertAsciiString(BufferView *, string const & buf, bool usePaste);
330 // Private structures and variables
332 InsetText * the_locking_inset;
334 InsetText * old_locking_inset;
336 Buffer const * buffer;
338 mutable LyXCursor cursor_;
340 mutable unsigned int inset_x;
342 mutable unsigned int inset_y;
343 /// true if a set of cells are selected
344 mutable bool has_selection;
345 /// the starting cell selection nr
346 mutable int sel_cell_start;
347 /// the ending cell selection nr
348 mutable int sel_cell_end;
358 mutable int first_visible_cell;
364 mutable UpdateCodes need_update;
368 mutable int in_reset_pos;