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 bool doClearArea() const;
107 void insetUnlock(BufferView *);
109 void updateLocal(BufferView *, UpdateCodes, bool mark_dirty) const;
111 bool lockInsetInInset(BufferView *, UpdatableInset *);
113 bool unlockInsetInInset(BufferView *, UpdatableInset *,
116 bool updateInsetInInset(BufferView *, Inset *);
118 unsigned int insetInInsetY();
120 UpdatableInset * getLockingInset();
122 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
124 bool insertInset(BufferView *, Inset *);
126 bool insertInsetAllowed(Inset *) const {
127 return the_locking_inset != 0;
130 bool isTextInset() const { return true; }
132 bool display() const { return tabular->IsLongTabular(); }
134 void insetButtonRelease(BufferView *, int, int, int);
136 void insetButtonPress(BufferView *, int, int, int);
138 void insetMotionNotify(BufferView *, int, int, int);
140 void insetKeyPress(XKeyEvent *);
142 UpdatableInset::RESULT localDispatch(BufferView *, kb_action,
145 int latex(Buffer const *, std::ostream &, bool, bool) const;
147 int ascii(Buffer const *, std::ostream &, int linelen) const;
149 int linuxdoc(Buffer const *, std::ostream &) const;
151 int docBook(Buffer const *, std::ostream &) const;
153 void validate(LaTeXFeatures & features) const;
155 Inset::Code lyxCode() const { return Inset::TABULAR_CODE; }
157 void getCursorPos(BufferView *, int & x, int & y) const;
159 void toggleInsetCursor(BufferView *);
161 bool tabularFeatures(BufferView * bv, string const & what);
163 void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
164 string const & val = string());
166 int getActCell() const { return actcell; }
168 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
169 bool selectall = false);
171 int getMaxWidth(BufferView *, UpdatableInset const *) const;
173 Buffer * bufferOwner() const { return const_cast<Buffer *>(buffer); }
175 LyXText * getLyXText(BufferView const *,
176 bool const recursive = false) const;
178 void deleteLyXText(BufferView *, bool recursive = true) const;
180 void resizeLyXText(BufferView *, bool force = false) const;
182 void openLayoutDialog(BufferView *) const;
184 bool showInsetDialog(BufferView *) const;
186 func_status::value_type getStatus(string const & argument) const;
188 std::vector<string> const getLabelList() const;
190 void nodraw(bool b) {
191 UpdatableInset::nodraw(b);
195 int scroll(bool recursive=true) const;
197 void scroll(BufferView *bv, float sx) const {
198 UpdatableInset::scroll(bv, sx);
201 void scroll(BufferView *bv, int offset) const {
202 UpdatableInset::scroll(bv, offset);
205 Paragraph * getParFromID(int id) const;
207 Inset * getInsetFromID(int id) const;
209 Paragraph * firstParagraph() const;
211 LyXCursor const & cursor(BufferView *) const;
214 // Public structures and variables
216 boost::scoped_ptr<LyXTabular> tabular;
218 SigC::Signal0<void> hideDialog;
222 bool calculate_dimensions_of_cells(BufferView *, LyXFont const &,
225 void drawCellLines(Painter &, int x, int baseline,
226 int row, int cell) const;
228 void drawCellSelection(Painter &, int x, int baseline,
229 int row, int column, int cell) const;
231 void showInsetCursor(BufferView *, bool show=true);
233 void hideInsetCursor(BufferView *);
235 void setPos(BufferView *, int x, int y) const;
237 UpdatableInset::RESULT moveRight(BufferView *, bool lock = true);
239 UpdatableInset::RESULT moveLeft(BufferView *, bool lock = true);
241 UpdatableInset::RESULT moveUp(BufferView *, bool lock = true);
243 UpdatableInset::RESULT moveDown(BufferView *, bool lock = true);
245 bool moveNextCell(BufferView *, bool lock = false);
247 bool movePrevCell(BufferView *, bool lock = false);
251 int getCellXPos(int cell) const;
253 void resetPos(BufferView *) const;
255 void removeTabularRow();
257 bool hasSelection() const {
258 return sel_cell_start != sel_cell_end;
261 void clearSelection() const {
262 sel_cell_start = sel_cell_end = 0;
265 bool activateCellInset(BufferView *, int x = 0, int y = 0,
267 bool behind = false);
269 bool activateCellInsetAbs(BufferView *, int x = 0, int y = 0,
272 bool insetHit(BufferView * bv, int x, int y) const;
274 int getMaxWidthOfCell(BufferView * bv, int cell) const;
276 bool hasPasteBuffer() const;
278 bool copySelection(BufferView *);
280 bool pasteSelection(BufferView *);
284 bool isRightToLeft(BufferView *);
286 void getSelection(int & scol, int & ecol, int & srow, int & erow) const;
289 // Private structures and variables
291 InsetText * the_locking_inset;
293 InsetText * old_locking_inset;
295 Buffer const * buffer;
297 mutable LyXCursor cursor_;
299 mutable unsigned int inset_x;
301 mutable unsigned int inset_y;
303 mutable int sel_cell_start;
305 mutable int sel_cell_end;
315 mutable int first_visible_cell;
321 mutable UpdateCodes need_update;