2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995-2000 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"
57 #include <sigc++/signal_system.h>
64 class InsetTabular : public UpdatableInset {
76 InsetTabular(Buffer const &, int rows = 1, int columns = 1);
78 InsetTabular(InsetTabular const &, Buffer const &);
82 Inset * Clone(Buffer const &) const;
84 void Read(Buffer const *, LyXLex &);
86 void Write(Buffer const *, std::ostream &) const;
88 int ascent(BufferView *, LyXFont const &) const;
90 int descent(BufferView *, LyXFont const &) const;
92 int width(BufferView *, LyXFont const & f) const;
94 void draw(BufferView *, const LyXFont &, int , float &, bool) const;
96 void update(BufferView *, LyXFont const &, bool = false);
98 string const EditMessage() const;
100 void Edit(BufferView *, int x, int y, unsigned int);
102 bool doClearArea() const { return !locked; };
104 void InsetUnlock(BufferView *);
106 void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty) const;
108 bool LockInsetInInset(BufferView *, UpdatableInset *);
110 bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
112 bool UpdateInsetInInset(BufferView *, Inset *);
114 unsigned int InsetInInsetY();
116 UpdatableInset * GetLockingInset();
118 UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
120 bool InsertInset(BufferView *, Inset *);
122 bool IsTextInset() const { return true; }
124 bool display() const { return tabular->IsLongTabular(); }
126 void InsetButtonRelease(BufferView *, int, int, int);
128 void InsetButtonPress(BufferView *, int, int, int);
130 void InsetMotionNotify(BufferView *, int, int, int);
132 void InsetKeyPress(XKeyEvent *);
134 UpdatableInset::RESULT LocalDispatch(BufferView *, kb_action,
137 int Latex(Buffer const *, std::ostream &, bool, bool) const;
139 int Ascii(Buffer const *, std::ostream &, int linelen) const;
141 int Linuxdoc(Buffer const *, std::ostream &) const;
143 int DocBook(Buffer const *, std::ostream &) const;
145 void Validate(LaTeXFeatures & features) const;
147 Inset::Code LyxCode() const { return Inset::TABULAR_CODE; }
149 void GetCursorPos(BufferView *, int & x, int & y) const;
151 void ToggleInsetCursor(BufferView *);
153 bool TabularFeatures(BufferView * bv, string const & what);
155 void TabularFeatures(BufferView * bv, LyXTabular::Feature feature,
156 string const & val = string());
158 int GetActCell() const { return actcell; }
160 void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
162 int getMaxWidth(Painter & pain, UpdatableInset const *) const;
164 Buffer * BufferOwner() const { return const_cast<Buffer *>(buffer); }
166 LyXText * getLyXText(BufferView const *, bool const recursive = false) const;
168 void resizeLyXText(BufferView *) const;
170 void OpenLayoutDialog(BufferView *) const;
172 LyXFunc::func_status getStatus(string const & argument) const;
175 // Public structures and variables
177 LyXTabular * tabular;
179 SigC::Signal0<void> hideDialog;
183 bool calculate_dimensions_of_cells(BufferView *, LyXFont const &,
186 void DrawCellLines(Painter &, int x, int baseline,
187 int row, int cell) const;
189 void DrawCellSelection(Painter &, int x, int baseline,
190 int row, int column, int cell) const;
192 void ShowInsetCursor(BufferView *, bool show=true);
194 void HideInsetCursor(BufferView *);
196 void setPos(BufferView *, int x, int y) const;
198 UpdatableInset::RESULT moveRight(BufferView *, bool lock = true);
200 UpdatableInset::RESULT moveLeft(BufferView *, bool lock = true);
202 UpdatableInset::RESULT moveUp(BufferView *, bool lock = true);
204 UpdatableInset::RESULT moveDown(BufferView *, bool lock = true);
206 bool moveNextCell(BufferView *, bool lock = false);
208 bool movePrevCell(BufferView *, bool lock = false);
212 int getCellXPos(int cell) const;
214 void resetPos(BufferView *) const;
216 void RemoveTabularRow();
218 bool hasSelection() const {
219 return sel_cell_start != sel_cell_end;
222 void clearSelection() const {
223 sel_cell_start = sel_cell_end = 0;
226 bool ActivateCellInset(BufferView *, int x = 0, int y = 0, int button = 0,
227 bool behind = false);
229 bool ActivateCellInsetAbs(BufferView *, int x = 0, int y = 0, int button = 0);
231 bool InsetHit(BufferView * bv, int x, int y) const;
233 int GetMaxWidthOfCell(Painter &, int cell) const;
235 bool hasPasteBuffer() const;
237 bool copySelection(BufferView *);
239 bool pasteSelection(BufferView *);
243 bool isRightToLeft(BufferView *);
246 // Private structures and variables
248 InsetText * the_locking_inset;
250 InsetText * old_locking_inset;
252 Buffer const * buffer;
254 mutable LyXCursor cursor;
256 mutable unsigned int inset_x;
258 mutable unsigned int inset_y;
260 mutable int sel_cell_start;
262 mutable int sel_cell_end;
272 mutable int first_visible_cell;
280 mutable UpdateCodes need_update;