2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995-2001 The LyX Team.
9 *======================================================
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
55 #include "lyxcursor.h"
56 #include "FuncStatus.h"
58 #include <boost/scoped_ptr.hpp>
60 #include <boost/signals/signal0.hpp>
68 class InsetTabular : public UpdatableInset {
80 InsetTabular(Buffer const &, int rows = 1, int columns = 1);
82 InsetTabular(InsetTabular const &, Buffer const &, bool same_id = false);
86 Inset * clone(Buffer const &, bool same_id = false) const;
88 void read(Buffer const *, LyXLex &);
90 void write(Buffer const *, std::ostream &) const;
92 int ascent(BufferView *, LyXFont const &) const;
94 int descent(BufferView *, LyXFont const &) const;
96 int width(BufferView *, LyXFont const & f) const;
98 void draw(BufferView *, const LyXFont &, int , float &, bool) const;
100 void update(BufferView *, LyXFont const &, bool = false);
102 string const editMessage() const;
104 void edit(BufferView *, int x, int y, mouse_button::state);
106 void edit(BufferView * bv, bool front = true);
108 bool doClearArea() const;
110 void insetUnlock(BufferView *);
112 void updateLocal(BufferView *, UpdateCodes, bool mark_dirty) const;
114 bool lockInsetInInset(BufferView *, UpdatableInset *);
116 bool unlockInsetInInset(BufferView *, UpdatableInset *,
119 bool updateInsetInInset(BufferView *, Inset *);
121 int insetInInsetY() const;
123 UpdatableInset * getLockingInset() const;
125 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
127 bool insertInset(BufferView *, Inset *);
129 bool insetAllowed(Inset::Code code) const;
131 bool isTextInset() const { return true; }
133 bool display() const { return tabular->IsLongTabular(); }
135 bool insetButtonRelease(BufferView *, int, int, mouse_button::state);
137 void insetButtonPress(BufferView *, int, int, mouse_button::state);
139 void insetMotionNotify(BufferView *, int, int, mouse_button::state);
141 UpdatableInset::RESULT localDispatch(BufferView *, kb_action,
144 int latex(Buffer const *, std::ostream &, bool, bool) const;
146 int ascii(Buffer const *, std::ostream &, int linelen) const;
148 int linuxdoc(Buffer const *, std::ostream &) const;
150 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
152 void validate(LaTeXFeatures & features) const;
154 Inset::Code lyxCode() const { return Inset::TABULAR_CODE; }
156 void getCursorPos(BufferView *, int & x, int & y) const;
158 void toggleInsetCursor(BufferView *);
160 bool tabularFeatures(BufferView * bv, string const & what);
162 void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
163 string const & val = string());
165 int getActCell() const { return actcell; }
167 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
168 bool selectall = false);
170 int getMaxWidth(BufferView *, UpdatableInset const *) const;
172 Buffer * bufferOwner() const { return const_cast<Buffer *>(buffer); }
174 LyXText * getLyXText(BufferView const *,
175 bool const recursive = false) const;
177 void deleteLyXText(BufferView *, bool recursive = true) const;
179 void resizeLyXText(BufferView *, bool force = false) const;
181 void openLayoutDialog(BufferView *) const;
183 bool showInsetDialog(BufferView *) const;
185 FuncStatus getStatus(string const & argument) const;
187 std::vector<string> const getLabelList() const;
189 void nodraw(bool b) const {
190 UpdatableInset::nodraw(b);
194 int scroll(bool recursive=true) const;
196 void scroll(BufferView *bv, float sx) const {
197 UpdatableInset::scroll(bv, sx);
200 void scroll(BufferView *bv, int offset) const {
201 UpdatableInset::scroll(bv, offset);
204 Paragraph * getParFromID(int id) const;
206 Inset * getInsetFromID(int id) const;
208 Paragraph * firstParagraph() const;
210 Paragraph * getFirstParagraph(int) const;
212 LyXCursor const & cursor(BufferView *) const;
214 bool allowSpellcheck() { return true; }
215 string const selectNextWordToSpellcheck(BufferView *, float & value) const;
216 void selectSelectedWord(BufferView *);
217 void toggleSelection(BufferView *, bool kill_selection);
219 bool searchForward(BufferView *, string const &,
220 bool = true, bool = false);
221 bool searchBackward(BufferView *, string const &,
222 bool = true, bool = false);
224 // this should return true if we have a "normal" cell, otherwise true.
225 // "normal" means without width set!
226 bool forceDefaultParagraphs(Inset const * in) const;
229 // Public structures and variables
231 boost::scoped_ptr<LyXTabular> tabular;
233 boost::signal0<void> hideDialog;
237 bool calculate_dimensions_of_cells(BufferView *, LyXFont const &,
240 void drawCellLines(Painter &, int x, int baseline,
241 int row, int cell) const;
243 void drawCellSelection(Painter &, int x, int baseline,
244 int row, int column, int cell) const;
246 void showInsetCursor(BufferView *, bool show=true);
248 void hideInsetCursor(BufferView *);
250 void fitInsetCursor(BufferView *) const;
252 void setPos(BufferView *, int x, int y) const;
254 UpdatableInset::RESULT moveRight(BufferView *, bool lock = true);
256 UpdatableInset::RESULT moveLeft(BufferView *, bool lock = true);
258 UpdatableInset::RESULT moveUp(BufferView *, bool lock = true);
260 UpdatableInset::RESULT moveDown(BufferView *, bool lock = true);
262 bool moveNextCell(BufferView *, bool lock = false);
264 bool movePrevCell(BufferView *, bool lock = false);
266 bool deletable() const;
268 int getCellXPos(int cell) const;
270 void resetPos(BufferView *) const;
272 void removeTabularRow();
274 bool hasSelection() const {
275 return has_selection;
278 void clearSelection() const {
279 sel_cell_start = sel_cell_end = 0;
280 has_selection = false;
282 void setSelection(int start, int end) const {
283 sel_cell_start = start;
285 has_selection = true;
288 bool activateCellInset(BufferView *, int x = 0, int y = 0,
289 mouse_button::state button = mouse_button::none,
290 bool behind = false);
292 bool activateCellInsetAbs(BufferView *, int x = 0, int y = 0,
293 mouse_button::state button = mouse_button::none);
295 bool insetHit(BufferView * bv, int x, int y) const;
297 int getMaxWidthOfCell(BufferView * bv, int cell) const;
299 bool hasPasteBuffer() const;
301 bool copySelection(BufferView *);
303 bool pasteSelection(BufferView *);
307 bool isRightToLeft(BufferView *);
309 void getSelection(int & scol, int & ecol,
310 int & srow, int & erow) const;
312 string selectNextWordInt(BufferView *, float & value) const;
314 bool insertAsciiString(BufferView *, string const & buf, bool usePaste);
317 // Private structures and variables
319 InsetText * the_locking_inset;
321 InsetText * old_locking_inset;
323 Buffer const * buffer;
325 mutable LyXCursor cursor_;
327 mutable unsigned int inset_x;
329 mutable unsigned int inset_y;
330 /// true if a set of cells are selected
331 mutable bool has_selection;
332 /// the starting cell selection nr
333 mutable int sel_cell_start;
334 /// the ending cell selection nr
335 mutable int sel_cell_end;
345 mutable int first_visible_cell;
351 mutable UpdateCodes need_update;
355 mutable int in_reset_pos;