4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS
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
51 #include "FuncStatus.h"
52 #include "frontends/mouse_state.h"
61 class InsetTabular : public UpdatableInset {
72 InsetTabular(Buffer const &, int rows = 1, int columns = 1);
74 InsetTabular(InsetTabular const &);
78 virtual std::auto_ptr<InsetBase> clone() const;
80 void read(Buffer const *, LyXLex &);
82 void write(Buffer const *, std::ostream &) const;
84 void metrics(MetricsInfo &, Dimension &) const;
86 void draw(PainterInfo & pi, int x, int y) const;
88 string const editMessage() const;
90 void insetUnlock(BufferView *);
92 void updateLocal(BufferView *, UpdateCodes) const;
94 bool lockInsetInInset(BufferView *, UpdatableInset *);
96 bool unlockInsetInInset(BufferView *, UpdatableInset *,
99 bool updateInsetInInset(BufferView *, InsetOld *);
101 int insetInInsetY() const;
103 UpdatableInset * getLockingInset() const;
105 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
107 bool insertInset(BufferView *, InsetOld *);
109 bool insetAllowed(InsetOld::Code code) const;
111 bool isTextInset() const { return true; }
112 /** returns true if, when outputing LaTeX, font changes should
113 be closed before generating this inset. This is needed for
114 insets that may contain several paragraphs */
115 bool noFontChange() const { return true; }
117 bool display() const { return tabular.isLongTabular(); }
119 RESULT localDispatch(FuncRequest const &);
121 int latex(Buffer const *, std::ostream &,
122 LatexRunParams const &) const;
124 int ascii(Buffer const *, std::ostream &, int linelen) const;
126 int linuxdoc(Buffer const *, std::ostream &) const;
128 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
130 void validate(LaTeXFeatures & features) const;
132 InsetOld::Code lyxCode() const { return InsetOld::TABULAR_CODE; }
134 void getCursorPos(BufferView *, int & x, int & y) const;
135 /// Get the absolute document x,y of the cursor
136 virtual void getCursor(BufferView &, int &, int &) const;
138 bool tabularFeatures(BufferView * bv, string const & what);
140 void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
141 string const & val = string());
143 int getActCell() const { return actcell; }
145 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
146 bool selectall = false);
148 LyXText * getLyXText(BufferView const *,
149 bool const recursive = false) const;
151 void deleteLyXText(BufferView *, bool recursive = true) const;
153 void resizeLyXText(BufferView *, bool force = false) const;
155 void openLayoutDialog(BufferView *) const;
157 bool showInsetDialog(BufferView *) const;
159 FuncStatus getStatus(string const & argument) const;
161 void getLabelList(std::vector<string> &) const;
163 int scroll(bool recursive=true) const;
165 void scroll(BufferView *bv, float sx) const {
166 UpdatableInset::scroll(bv, sx);
169 void scroll(BufferView *bv, int offset) const {
170 UpdatableInset::scroll(bv, offset);
173 InsetOld * getInsetFromID(int id) const;
175 ParagraphList * getParagraphs(int) const;
177 LyXCursor const & cursor(BufferView *) const;
179 bool allowSpellcheck() const { return true; }
182 selectNextWordToSpellcheck(BufferView *, float & value) const;
184 void selectSelectedWord(BufferView *);
189 bool nextChange(BufferView *, lyx::pos_type & length);
191 bool searchForward(BufferView *, string const &,
192 bool = true, bool = false);
193 bool searchBackward(BufferView *, string const &,
194 bool = true, bool = false);
196 // this should return true if we have a "normal" cell, otherwise true.
197 // "normal" means without width set!
198 bool forceDefaultParagraphs(InsetOld const * in) const;
201 void addPreview(lyx::graphics::PreviewLoader &) const;
204 // Public structures and variables
206 mutable LyXTabular tabular;
208 /// are some cells selected ?
209 bool hasSelection() const {
210 return has_selection;
214 virtual BufferView * view() const;
216 Buffer const * buffer() const;
218 /// set the owning buffer
219 void buffer(Buffer * b);
223 void lfunMousePress(FuncRequest const &);
225 // the bool return is used to see if we opened a dialog so that we can
226 // check this from an outer inset and open the dialog of the outer inset
227 // if that one has one!
229 bool lfunMouseRelease(FuncRequest const &);
231 void lfunMouseMotion(FuncRequest const &);
233 void calculate_dimensions_of_cells(MetricsInfo & mi) const;
235 void drawCellLines(Painter &, int x, int baseline,
236 int row, int cell) const;
238 void drawCellSelection(Painter &, int x, int baseline,
239 int row, int column, int cell) const;
241 void fitInsetCursor(BufferView *) const;
243 void setPos(BufferView *, int x, int y) const;
245 RESULT moveRight(BufferView *, bool lock = true);
247 RESULT moveLeft(BufferView *, bool lock = true);
249 RESULT moveUp(BufferView *, bool lock = true);
251 RESULT moveDown(BufferView *, bool lock = true);
253 bool moveNextCell(BufferView *, bool lock = false);
255 bool movePrevCell(BufferView *, bool lock = false);
257 int getCellXPos(int cell) const;
259 void resetPos(BufferView *) const;
261 void removeTabularRow();
263 void clearSelection() const {
264 sel_cell_start = sel_cell_end = 0;
265 has_selection = false;
267 void setSelection(int start, int end) const {
268 sel_cell_start = start;
270 has_selection = true;
273 bool activateCellInset(BufferView *, int x = 0, int y = 0,
274 mouse_button::state button = mouse_button::none,
275 bool behind = false);
277 bool activateCellInsetAbs(BufferView *, int x = 0, int y = 0,
278 mouse_button::state button = mouse_button::none);
280 bool insetHit(BufferView * bv, int x, int y) const;
282 bool hasPasteBuffer() const;
284 bool copySelection(BufferView *);
286 bool pasteSelection(BufferView *);
288 bool cutSelection(BufferParams const & bp);
290 bool isRightToLeft(BufferView *);
292 void getSelection(int & scol, int & ecol,
293 int & srow, int & erow) const;
295 WordLangTuple selectNextWordInt(BufferView *, float & value) const;
297 bool insertAsciiString(BufferView *, string const & buf, bool usePaste);
300 // Private structures and variables
302 InsetText * the_locking_inset;
304 InsetText * old_locking_inset;
306 Buffer const * buffer_;
308 mutable int cursorx_;
310 mutable int cursory_;
312 mutable unsigned int inset_x;
314 mutable unsigned int inset_y;
315 /// true if a set of cells are selected
316 mutable bool has_selection;
317 /// the starting cell selection nr
318 mutable int sel_cell_start;
319 /// the ending cell selection nr
320 mutable int sel_cell_end;
330 mutable int first_visible_cell;
336 mutable UpdateCodes need_update;
338 mutable int in_reset_pos;
342 #include "mailinset.h"
345 class InsetTabularMailer : public MailInset {
348 InsetTabularMailer(InsetTabular const & inset);
350 virtual InsetBase & inset() const { return inset_; }
352 virtual string const & name() const { return name_; }
354 virtual string const inset2string(Buffer const &) const;
355 /// Returns the active cell if successful, else -1.
356 static int string2params(string const &, InsetTabular &);
358 static string const params2string(InsetTabular const &);
361 static string const name_;
363 InsetTabular & inset_;
366 string const featureAsString(LyXTabular::Feature feature);