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"
66 class InsetTabular : public UpdatableInset {
78 InsetTabular(Buffer const &, int rows = 1, int columns = 1);
80 InsetTabular(InsetTabular const &, Buffer const &);
84 Inset * Clone(Buffer const &) 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, unsigned int);
104 bool doClearArea() const;
106 void InsetUnlock(BufferView *);
108 void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty) const;
110 bool LockInsetInInset(BufferView *, UpdatableInset *);
112 bool UnlockInsetInInset(BufferView *, UpdatableInset *,
115 bool UpdateInsetInInset(BufferView *, Inset *);
117 unsigned int InsetInInsetY();
119 UpdatableInset * GetLockingInset();
121 UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
123 bool InsertInset(BufferView *, Inset *);
125 bool IsTextInset() const { return true; }
127 bool display() const { return tabular->IsLongTabular(); }
129 void InsetButtonRelease(BufferView *, int, int, int);
131 void InsetButtonPress(BufferView *, int, int, int);
133 void InsetMotionNotify(BufferView *, int, int, int);
135 void InsetKeyPress(XKeyEvent *);
137 UpdatableInset::RESULT LocalDispatch(BufferView *, kb_action,
140 int Latex(Buffer const *, std::ostream &, bool, bool) const;
142 int Ascii(Buffer const *, std::ostream &, int linelen) const;
144 int Linuxdoc(Buffer const *, std::ostream &) const;
146 int DocBook(Buffer const *, std::ostream &) const;
148 void Validate(LaTeXFeatures & features) const;
150 Inset::Code LyxCode() const { return Inset::TABULAR_CODE; }
152 void GetCursorPos(BufferView *, int & x, int & y) const;
154 void ToggleInsetCursor(BufferView *);
156 bool TabularFeatures(BufferView * bv, string const & what);
158 void TabularFeatures(BufferView * bv, LyXTabular::Feature feature,
159 string const & val = string());
161 int GetActCell() const { return actcell; }
163 void SetFont(BufferView *, LyXFont const &, bool toggleall = false,
164 bool selectall = false);
166 int getMaxWidth(BufferView *, UpdatableInset const *) const;
168 Buffer * BufferOwner() const { return const_cast<Buffer *>(buffer); }
170 LyXText * getLyXText(BufferView const *,
171 bool const recursive = false) const;
173 void deleteLyXText(BufferView *, bool recursive = true) const;
175 void resizeLyXText(BufferView *, bool force = false) const;
177 void OpenLayoutDialog(BufferView *) const;
179 bool ShowInsetDialog(BufferView *) const;
181 LyXFunc::func_status getStatus(string const & argument) const;
183 std::vector<string> const getLabelList() const;
185 void nodraw(bool b) {
186 UpdatableInset::nodraw(b);
190 int scroll(bool recursive=true) const;
191 void scroll(BufferView *bv, float sx) const {
192 UpdatableInset::scroll(bv, sx);
194 void scroll(BufferView *bv, int offset) const {
195 UpdatableInset::scroll(bv, offset);
199 // Public structures and variables
201 //LyXTabular * tabular;
202 boost::scoped_ptr<LyXTabular> tabular;
204 SigC::Signal0<void> hideDialog;
208 bool calculate_dimensions_of_cells(BufferView *, LyXFont const &,
211 void DrawCellLines(Painter &, int x, int baseline,
212 int row, int cell) const;
214 void DrawCellSelection(Painter &, int x, int baseline,
215 int row, int column, int cell) const;
217 void ShowInsetCursor(BufferView *, bool show=true);
219 void HideInsetCursor(BufferView *);
221 void setPos(BufferView *, int x, int y) const;
223 UpdatableInset::RESULT moveRight(BufferView *, bool lock = true);
225 UpdatableInset::RESULT moveLeft(BufferView *, bool lock = true);
227 UpdatableInset::RESULT moveUp(BufferView *, bool lock = true);
229 UpdatableInset::RESULT moveDown(BufferView *, bool lock = true);
231 bool moveNextCell(BufferView *, bool lock = false);
233 bool movePrevCell(BufferView *, bool lock = false);
237 int getCellXPos(int cell) const;
239 void resetPos(BufferView *) const;
241 void RemoveTabularRow();
243 bool hasSelection() const {
244 return sel_cell_start != sel_cell_end;
247 void clearSelection() const {
248 sel_cell_start = sel_cell_end = 0;
251 bool ActivateCellInset(BufferView *, int x = 0, int y = 0,
253 bool behind = false);
255 bool ActivateCellInsetAbs(BufferView *, int x = 0, int y = 0,
258 bool InsetHit(BufferView * bv, int x, int y) const;
260 int GetMaxWidthOfCell(BufferView * bv, int cell) const;
262 bool hasPasteBuffer() const;
264 bool copySelection(BufferView *);
266 bool pasteSelection(BufferView *);
270 bool isRightToLeft(BufferView *);
272 void getSelection(int & scol, int & ecol, int & srow, int & erow) const;
275 // Private structures and variables
277 InsetText * the_locking_inset;
279 InsetText * old_locking_inset;
281 Buffer const * buffer;
283 mutable LyXCursor cursor;
285 mutable unsigned int inset_x;
287 mutable unsigned int inset_y;
289 mutable int sel_cell_start;
291 mutable int sel_cell_end;
301 mutable int first_visible_cell;
307 mutable UpdateCodes need_update;