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 "lyxcursor.h"
52 #include "FuncStatus.h"
53 #include "frontends/mouse_state.h"
62 class InsetTabular : public UpdatableInset {
74 InsetTabular(Buffer const &, int rows = 1, int columns = 1);
76 InsetTabular(InsetTabular const &);
80 Inset * clone() const;
82 void read(Buffer const *, LyXLex &);
84 void write(Buffer const *, std::ostream &) const;
86 void metrics(MetricsInfo &, Dimension &) const;
88 void draw(PainterInfo & pi, int x, int y) const;
90 void update(BufferView *, bool = false);
92 string const editMessage() const;
94 void insetUnlock(BufferView *);
96 void updateLocal(BufferView *, UpdateCodes) const;
98 bool lockInsetInInset(BufferView *, UpdatableInset *);
100 bool unlockInsetInInset(BufferView *, UpdatableInset *,
103 bool updateInsetInInset(BufferView *, Inset *);
105 int insetInInsetY() const;
107 UpdatableInset * getLockingInset() const;
109 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
111 bool insertInset(BufferView *, Inset *);
113 bool insetAllowed(Inset::Code code) const;
115 bool isTextInset() const { return true; }
116 /** returns true if, when outputing LaTeX, font changes should
117 be closed before generating this inset. This is needed for
118 insets that may contain several paragraphs */
119 bool noFontChange() const { return true; }
121 bool display() const { return tabular.isLongTabular(); }
123 RESULT localDispatch(FuncRequest const &);
125 int latex(Buffer const *, std::ostream &,
126 LatexRunParams const &) const;
128 int ascii(Buffer const *, std::ostream &, int linelen) const;
130 int linuxdoc(Buffer const *, std::ostream &) const;
132 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
134 void validate(LaTeXFeatures & features) const;
136 Inset::Code lyxCode() const { return Inset::TABULAR_CODE; }
138 void getCursorPos(BufferView *, int & x, int & y) const;
139 /// Get the absolute document x,y of the cursor
140 virtual void getCursor(BufferView &, int &, int &) const;
142 bool tabularFeatures(BufferView * bv, string const & what);
144 void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
145 string const & val = string());
147 int getActCell() const { return actcell; }
149 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
150 bool selectall = false);
152 int getMaxWidth(BufferView *, UpdatableInset const *) const;
154 LyXText * getLyXText(BufferView const *,
155 bool const recursive = false) const;
157 void deleteLyXText(BufferView *, bool recursive = true) const;
159 void resizeLyXText(BufferView *, bool force = false) const;
161 void openLayoutDialog(BufferView *) const;
163 bool showInsetDialog(BufferView *) const;
165 FuncStatus getStatus(string const & argument) const;
167 std::vector<string> const getLabelList() const;
169 void nodraw(bool b) const {
170 UpdatableInset::nodraw(b);
174 int scroll(bool recursive=true) const;
176 void scroll(BufferView *bv, float sx) const {
177 UpdatableInset::scroll(bv, sx);
180 void scroll(BufferView *bv, int offset) const {
181 UpdatableInset::scroll(bv, offset);
184 Inset * getInsetFromID(int id) const;
186 ParagraphList * getParagraphs(int) const;
188 LyXCursor const & cursor(BufferView *) const;
190 bool allowSpellcheck() const { return true; }
193 selectNextWordToSpellcheck(BufferView *, float & value) const;
195 void selectSelectedWord(BufferView *);
197 void toggleSelection(BufferView *, bool kill_selection);
202 bool nextChange(BufferView *, lyx::pos_type & length);
204 bool searchForward(BufferView *, string const &,
205 bool = true, bool = false);
206 bool searchBackward(BufferView *, string const &,
207 bool = true, bool = false);
209 // this should return true if we have a "normal" cell, otherwise true.
210 // "normal" means without width set!
211 bool forceDefaultParagraphs(Inset const * in) const;
214 void addPreview(grfx::PreviewLoader &) const;
217 // Public structures and variables
219 mutable LyXTabular tabular;
221 /// are some cells selected ?
222 bool hasSelection() const {
223 return has_selection;
227 virtual BufferView * view() const;
229 /// set the owning buffer
230 void buffer(Buffer * b);
234 void lfunMousePress(FuncRequest const &);
236 // the bool return is used to see if we opened a dialog so that we can
237 // check this from an outer inset and open the dialog of the outer inset
238 // if that one has one!
240 bool lfunMouseRelease(FuncRequest const &);
242 void lfunMouseMotion(FuncRequest const &);
244 bool calculate_dimensions_of_cells(BufferView *, bool = false) const;
246 void drawCellLines(Painter &, int x, int baseline,
247 int row, int cell) const;
249 void drawCellSelection(Painter &, int x, int baseline,
250 int row, int column, int cell) const;
252 void fitInsetCursor(BufferView *) const;
254 void setPos(BufferView *, int x, int y) const;
256 RESULT moveRight(BufferView *, bool lock = true);
258 RESULT moveLeft(BufferView *, bool lock = true);
260 RESULT moveUp(BufferView *, bool lock = true);
262 RESULT moveDown(BufferView *, bool lock = true);
264 bool moveNextCell(BufferView *, bool lock = false);
266 bool movePrevCell(BufferView *, bool lock = false);
268 int getCellXPos(int cell) const;
270 void resetPos(BufferView *) const;
272 void removeTabularRow();
274 void clearSelection() const {
275 sel_cell_start = sel_cell_end = 0;
276 has_selection = false;
278 void setSelection(int start, int end) const {
279 sel_cell_start = start;
281 has_selection = true;
284 bool activateCellInset(BufferView *, int x = 0, int y = 0,
285 mouse_button::state button = mouse_button::none,
286 bool behind = false);
288 bool activateCellInsetAbs(BufferView *, int x = 0, int y = 0,
289 mouse_button::state button = mouse_button::none);
291 bool insetHit(BufferView * bv, int x, int y) const;
293 int getMaxWidthOfCell(BufferView * bv, int cell) const;
295 bool hasPasteBuffer() const;
297 bool copySelection(BufferView *);
299 bool pasteSelection(BufferView *);
301 bool cutSelection(BufferParams const & bp);
303 bool isRightToLeft(BufferView *);
305 void getSelection(int & scol, int & ecol,
306 int & srow, int & erow) const;
308 WordLangTuple selectNextWordInt(BufferView *, float & value) const;
310 bool insertAsciiString(BufferView *, string const & buf, bool usePaste);
313 // Private structures and variables
315 InsetText * the_locking_inset;
317 InsetText * old_locking_inset;
319 Buffer const * buffer_;
321 mutable LyXCursor cursor_;
323 mutable unsigned int inset_x;
325 mutable unsigned int inset_y;
326 /// true if a set of cells are selected
327 mutable bool has_selection;
328 /// the starting cell selection nr
329 mutable int sel_cell_start;
330 /// the ending cell selection nr
331 mutable int sel_cell_end;
341 mutable int first_visible_cell;
347 mutable UpdateCodes need_update;
351 mutable int in_reset_pos;
355 #include "mailinset.h"
358 class InsetTabularMailer : public MailInset {
361 InsetTabularMailer(InsetTabular & inset);
363 virtual InsetBase & inset() const { return inset_; }
365 virtual string const & name() const { return name_; }
367 virtual string const inset2string() const;
368 /// Returns the active cell if successful, else -1.
369 static int string2params(string const &, InsetTabular &);
371 static string const params2string(InsetTabular const &);
374 static string const name_;
376 InsetTabular & inset_;
379 string const featureAsString(LyXTabular::Feature feature);