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
48 #include <sigc++/signal_system.h>
49 #include <boost/smart_ptr.hpp>
58 #include "lyxcursor.h"
59 #include "func_status.h"
67 class InsetTabular : public UpdatableInset {
79 InsetTabular(Buffer const &, int rows = 1, int columns = 1);
81 InsetTabular(InsetTabular const &, Buffer const &, bool same_id = false);
85 Inset * clone(Buffer const &, bool same_id = false) const;
87 void read(Buffer const *, LyXLex &);
89 void write(Buffer const *, std::ostream &) const;
91 int ascent(BufferView *, LyXFont const &) const;
93 int descent(BufferView *, LyXFont const &) const;
95 int width(BufferView *, LyXFont const & f) const;
97 void draw(BufferView *, const LyXFont &, int , float &, bool) const;
99 void update(BufferView *, LyXFont const &, bool = false);
101 string const editMessage() const;
103 void edit(BufferView *, int x, int y, unsigned int);
105 void edit(BufferView * bv, bool front = true);
107 bool doClearArea() const;
109 void insetUnlock(BufferView *);
111 void updateLocal(BufferView *, UpdateCodes, bool mark_dirty) const;
113 bool lockInsetInInset(BufferView *, UpdatableInset *);
115 bool unlockInsetInInset(BufferView *, UpdatableInset *,
118 bool updateInsetInInset(BufferView *, Inset *);
120 unsigned int insetInInsetY();
122 UpdatableInset * getLockingInset() const;
124 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
126 bool insertInset(BufferView *, Inset *);
128 bool insetAllowed(Inset::Code) const {
129 return the_locking_inset != 0;
132 bool isTextInset() const { return true; }
134 bool display() const { return tabular->IsLongTabular(); }
136 void insetButtonRelease(BufferView *, int, int, int);
138 void insetButtonPress(BufferView *, int, int, int);
140 void insetMotionNotify(BufferView *, int, int, int);
142 void insetKeyPress(XKeyEvent *);
144 UpdatableInset::RESULT localDispatch(BufferView *, kb_action,
147 int latex(Buffer const *, std::ostream &, bool, bool) const;
149 int ascii(Buffer const *, std::ostream &, int linelen) const;
151 int linuxdoc(Buffer const *, std::ostream &) const;
153 int docBook(Buffer const *, std::ostream &) const;
155 void validate(LaTeXFeatures & features) const;
157 Inset::Code lyxCode() const { return Inset::TABULAR_CODE; }
159 void getCursorPos(BufferView *, int & x, int & y) const;
161 void toggleInsetCursor(BufferView *);
163 bool tabularFeatures(BufferView * bv, string const & what);
165 void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
166 string const & val = string());
168 int getActCell() const { return actcell; }
170 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
171 bool selectall = false);
173 int getMaxWidth(BufferView *, UpdatableInset const *) const;
175 Buffer * bufferOwner() const { return const_cast<Buffer *>(buffer); }
177 LyXText * getLyXText(BufferView const *,
178 bool const recursive = false) const;
180 void deleteLyXText(BufferView *, bool recursive = true) const;
182 void resizeLyXText(BufferView *, bool force = false) const;
184 void openLayoutDialog(BufferView *) const;
186 bool showInsetDialog(BufferView *) const;
188 func_status::value_type getStatus(string const & argument) const;
190 std::vector<string> const getLabelList() const;
192 void nodraw(bool b) {
193 UpdatableInset::nodraw(b);
197 int scroll(bool recursive=true) const;
199 void scroll(BufferView *bv, float sx) const {
200 UpdatableInset::scroll(bv, sx);
203 void scroll(BufferView *bv, int offset) const {
204 UpdatableInset::scroll(bv, offset);
207 Paragraph * getParFromID(int id) const;
209 Inset * getInsetFromID(int id) const;
211 Paragraph * firstParagraph() const;
213 LyXCursor const & cursor(BufferView *) const;
215 string const selectNextWord(BufferView *, float & value) const;
216 void selectSelectedWord(BufferView *);
217 void toggleSelection(BufferView *, bool kill_selection);
219 bool searchForward(BufferView *, string const &,
220 bool const & = true, bool const & = false);
221 bool searchBackward(BufferView *, string const &,
222 bool const & = true, bool const & = false);
225 // Public structures and variables
227 boost::scoped_ptr<LyXTabular> tabular;
229 SigC::Signal0<void> hideDialog;
233 bool calculate_dimensions_of_cells(BufferView *, LyXFont const &,
236 void drawCellLines(Painter &, int x, int baseline,
237 int row, int cell) const;
239 void drawCellSelection(Painter &, int x, int baseline,
240 int row, int column, int cell) const;
242 void showInsetCursor(BufferView *, bool show=true);
244 void hideInsetCursor(BufferView *);
246 void setPos(BufferView *, int x, int y) const;
248 UpdatableInset::RESULT moveRight(BufferView *, bool lock = true);
250 UpdatableInset::RESULT moveLeft(BufferView *, bool lock = true);
252 UpdatableInset::RESULT moveUp(BufferView *, bool lock = true);
254 UpdatableInset::RESULT moveDown(BufferView *, bool lock = true);
256 bool moveNextCell(BufferView *, bool lock = false);
258 bool movePrevCell(BufferView *, bool lock = false);
262 int getCellXPos(int cell) const;
264 void resetPos(BufferView *) const;
266 void removeTabularRow();
268 bool hasSelection() const {
269 return sel_cell_start != sel_cell_end;
272 void clearSelection() const {
273 sel_cell_start = sel_cell_end = 0;
276 bool activateCellInset(BufferView *, int x = 0, int y = 0,
278 bool behind = false);
280 bool activateCellInsetAbs(BufferView *, int x = 0, int y = 0,
283 bool insetHit(BufferView * bv, int x, int y) const;
285 int getMaxWidthOfCell(BufferView * bv, int cell) const;
287 bool hasPasteBuffer() const;
289 bool copySelection(BufferView *);
291 bool pasteSelection(BufferView *);
295 bool isRightToLeft(BufferView *);
297 void getSelection(int & scol, int & ecol,
298 int & srow, int & erow) const;
300 string selectNextWordInt(BufferView *, float & value) const;
303 // Private structures and variables
305 InsetText * the_locking_inset;
307 InsetText * old_locking_inset;
309 Buffer const * buffer;
311 mutable LyXCursor cursor_;
313 mutable unsigned int inset_x;
315 mutable unsigned int inset_y;
317 mutable int sel_cell_start;
319 mutable int sel_cell_end;
329 mutable int first_visible_cell;
335 mutable UpdateCodes need_update;