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 int insetInInsetY() const;
101 UpdatableInset * getLockingInset() const;
103 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
105 bool insertInset(BufferView *, InsetOld *);
107 bool insetAllowed(InsetOld::Code code) const;
109 bool isTextInset() const { return true; }
110 /** returns true if, when outputing LaTeX, font changes should
111 be closed before generating this inset. This is needed for
112 insets that may contain several paragraphs */
113 bool noFontChange() const { return true; }
115 bool display() const { return tabular.isLongTabular(); }
117 RESULT localDispatch(FuncRequest const &);
119 int latex(Buffer const *, std::ostream &,
120 LatexRunParams const &) const;
122 int ascii(Buffer const *, std::ostream &, int linelen) const;
124 int linuxdoc(Buffer const *, std::ostream &) const;
126 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
128 void validate(LaTeXFeatures & features) const;
130 InsetOld::Code lyxCode() const { return InsetOld::TABULAR_CODE; }
132 void getCursorPos(BufferView *, int & x, int & y) const;
133 /// Get the absolute document x,y of the cursor
134 virtual void getCursor(BufferView &, int &, int &) const;
136 bool tabularFeatures(BufferView * bv, string const & what);
138 void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
139 string const & val = string());
141 int getActCell() const { return actcell; }
143 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
144 bool selectall = false);
146 LyXText * getLyXText(BufferView const *,
147 bool const recursive = false) const;
149 void deleteLyXText(BufferView *, bool recursive = true) const;
151 void resizeLyXText(BufferView *, bool force = false) const;
153 void openLayoutDialog(BufferView *) const;
155 bool showInsetDialog(BufferView *) const;
157 FuncStatus getStatus(string const & argument) const;
159 void getLabelList(std::vector<string> &) const;
161 int scroll(bool recursive=true) const;
163 void scroll(BufferView *bv, float sx) const {
164 UpdatableInset::scroll(bv, sx);
167 void scroll(BufferView *bv, int offset) const {
168 UpdatableInset::scroll(bv, offset);
171 InsetOld * getInsetFromID(int id) const;
173 ParagraphList * getParagraphs(int) const;
175 LyXCursor const & cursor(BufferView *) const;
177 bool allowSpellcheck() const { return true; }
180 selectNextWordToSpellcheck(BufferView *, float & value) const;
182 void selectSelectedWord(BufferView *);
187 bool nextChange(BufferView *, lyx::pos_type & length);
189 bool searchForward(BufferView *, string const &,
190 bool = true, bool = false);
191 bool searchBackward(BufferView *, string const &,
192 bool = true, bool = false);
194 // this should return true if we have a "normal" cell, otherwise true.
195 // "normal" means without width set!
196 bool forceDefaultParagraphs(InsetOld const * in) const;
199 void addPreview(lyx::graphics::PreviewLoader &) const;
202 // Public structures and variables
204 mutable LyXTabular tabular;
206 /// are some cells selected ?
207 bool hasSelection() const {
208 return has_selection;
212 virtual BufferView * view() const;
214 Buffer const * buffer() const;
216 /// set the owning buffer
217 void buffer(Buffer * b);
221 void lfunMousePress(FuncRequest const &);
223 // the bool return is used to see if we opened a dialog so that we can
224 // check this from an outer inset and open the dialog of the outer inset
225 // if that one has one!
227 bool lfunMouseRelease(FuncRequest const &);
229 void lfunMouseMotion(FuncRequest const &);
231 void calculate_dimensions_of_cells(MetricsInfo & mi) const;
233 void drawCellLines(Painter &, int x, int baseline,
234 int row, int cell) const;
236 void drawCellSelection(Painter &, int x, int baseline,
237 int row, int column, int cell) const;
239 void fitInsetCursor(BufferView *) const;
241 void setPos(BufferView *, int x, int y) const;
243 RESULT moveRight(BufferView *, bool lock = true);
245 RESULT moveLeft(BufferView *, bool lock = true);
247 RESULT moveUp(BufferView *, bool lock = true);
249 RESULT moveDown(BufferView *, bool lock = true);
251 bool moveNextCell(BufferView *, bool lock = false);
253 bool movePrevCell(BufferView *, bool lock = false);
255 int getCellXPos(int cell) const;
257 void resetPos(BufferView *) const;
259 void removeTabularRow();
261 void clearSelection() const {
262 sel_cell_start = sel_cell_end = 0;
263 has_selection = false;
265 void setSelection(int start, int end) const {
266 sel_cell_start = start;
268 has_selection = true;
271 bool activateCellInset(BufferView *, int x = 0, int y = 0,
272 mouse_button::state button = mouse_button::none,
273 bool behind = false);
275 bool activateCellInsetAbs(BufferView *, int x = 0, int y = 0,
276 mouse_button::state button = mouse_button::none);
278 bool insetHit(BufferView * bv, int x, int y) const;
280 bool hasPasteBuffer() const;
282 bool copySelection(BufferView *);
284 bool pasteSelection(BufferView *);
286 bool cutSelection(BufferParams const & bp);
288 bool isRightToLeft(BufferView *);
290 void getSelection(int & scol, int & ecol,
291 int & srow, int & erow) const;
293 WordLangTuple selectNextWordInt(BufferView *, float & value) const;
295 bool insertAsciiString(BufferView *, string const & buf, bool usePaste);
298 // Private structures and variables
300 InsetText * the_locking_inset;
302 InsetText * old_locking_inset;
304 Buffer const * buffer_;
306 mutable int cursorx_;
308 mutable int cursory_;
310 mutable unsigned int inset_x;
312 mutable unsigned int inset_y;
313 /// true if a set of cells are selected
314 mutable bool has_selection;
315 /// the starting cell selection nr
316 mutable int sel_cell_start;
317 /// the ending cell selection nr
318 mutable int sel_cell_end;
328 mutable int first_visible_cell;
334 mutable UpdateCodes need_update;
336 mutable int in_reset_pos;
340 #include "mailinset.h"
343 class InsetTabularMailer : public MailInset {
346 InsetTabularMailer(InsetTabular const & inset);
348 virtual InsetBase & inset() const { return inset_; }
350 virtual string const & name() const { return name_; }
352 virtual string const inset2string(Buffer const &) const;
353 /// Returns the active cell if successful, else -1.
354 static int string2params(string const &, InsetTabular &);
356 static string const params2string(InsetTabular const &);
359 static string const name_;
361 InsetTabular & inset_;
364 string const featureAsString(LyXTabular::Feature feature);