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>
59 #ifdef SIGC_CXX_NAMESPACES
68 class InsetTabular : public UpdatableInset {
80 InsetTabular(Buffer const &, int rows = 1, int columns = 1);
82 InsetTabular(InsetTabular const &, Buffer const &);
86 Inset * Clone(Buffer const &) 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, unsigned int);
106 bool doClearArea() const { return !locked; };
108 void InsetUnlock(BufferView *);
110 void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty) const;
112 bool LockInsetInInset(BufferView *, UpdatableInset *);
114 bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
116 bool UpdateInsetInInset(BufferView *, Inset *);
118 unsigned int InsetInInsetY();
120 UpdatableInset * GetLockingInset();
122 UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
124 bool InsertInset(BufferView *, Inset *);
126 bool IsTextInset() const { return true; }
128 bool display() const { return tabular->IsLongTabular(); }
130 void InsetButtonRelease(BufferView *, int, int, int);
132 void InsetButtonPress(BufferView *, int, int, int);
134 void InsetMotionNotify(BufferView *, int, int, int);
136 void InsetKeyPress(XKeyEvent *);
138 UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
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);
165 int getMaxWidth(Painter & pain, UpdatableInset const *) const;
167 Buffer * BufferOwner() const { return const_cast<Buffer *>(buffer); }
169 LyXText * getLyXText(BufferView const *) const;
171 void resizeLyXText(BufferView *) const;
173 void OpenLayoutDialog(BufferView *) const;
175 LyXFunc::func_status getStatus(string const & argument) const;
178 // Public structures and variables
180 LyXTabular * tabular;
182 Signal0<void> hideDialog;
186 bool calculate_dimensions_of_cells(BufferView *, LyXFont const &,
189 void DrawCellLines(Painter &, int x, int baseline,
190 int row, int cell) const;
192 void DrawCellSelection(Painter &, int x, int baseline,
193 int row, int column, int cell) const;
195 void ShowInsetCursor(BufferView *, bool show=true);
197 void HideInsetCursor(BufferView *);
199 void setPos(BufferView *, int x, int y) const;
201 UpdatableInset::RESULT moveRight(BufferView *, bool lock = true);
203 UpdatableInset::RESULT moveLeft(BufferView *, bool lock = true);
205 UpdatableInset::RESULT moveUp(BufferView *, bool lock = true);
207 UpdatableInset::RESULT moveDown(BufferView *, bool lock = true);
209 bool moveNextCell(BufferView *, bool lock = false);
211 bool movePrevCell(BufferView *, bool lock = false);
215 int getCellXPos(int cell) const;
217 void resetPos(BufferView *) const;
219 void RemoveTabularRow();
221 bool hasSelection() const {
222 return sel_cell_start != sel_cell_end;
225 void clearSelection() const {
226 sel_cell_start = sel_cell_end = 0;
229 bool ActivateCellInset(BufferView *, int x = 0, int y = 0, int button = 0,
230 bool behind = false);
232 bool ActivateCellInsetAbs(BufferView *, int x = 0, int y = 0, int button = 0);
234 bool InsetHit(BufferView * bv, int x, int y) const;
236 int GetMaxWidthOfCell(Painter &, int cell) const;
238 bool hasPasteBuffer() const;
240 bool copySelection(BufferView *);
242 bool pasteSelection(BufferView *);
246 bool isRightToLeft(BufferView *);
249 // Private structures and variables
251 InsetText * the_locking_inset;
253 InsetText * old_locking_inset;
255 Buffer const * buffer;
257 mutable LyXCursor cursor;
259 mutable unsigned int inset_x;
261 mutable unsigned int inset_y;
263 mutable int sel_cell_start;
265 mutable int sel_cell_end;
279 mutable UpdateCodes need_update;