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 {
73 InsetTabular(Buffer const &, int rows = 1, int columns = 1);
75 InsetTabular(InsetTabular const &);
79 InsetBase * clone() const;
81 void read(Buffer const *, LyXLex &);
83 void write(Buffer const *, std::ostream &) const;
85 void metrics(MetricsInfo &, Dimension &) const;
87 void draw(PainterInfo & pi, int x, int y) const;
89 string const editMessage() const;
91 void insetUnlock(BufferView *);
93 void updateLocal(BufferView *, UpdateCodes) const;
95 bool lockInsetInInset(BufferView *, UpdatableInset *);
97 bool unlockInsetInInset(BufferView *, UpdatableInset *,
100 bool updateInsetInInset(BufferView *, Inset *);
102 int insetInInsetY() const;
104 UpdatableInset * getLockingInset() const;
106 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
108 bool insertInset(BufferView *, Inset *);
110 bool insetAllowed(Inset::Code code) const;
112 bool isTextInset() const { return true; }
113 /** returns true if, when outputing LaTeX, font changes should
114 be closed before generating this inset. This is needed for
115 insets that may contain several paragraphs */
116 bool noFontChange() const { return true; }
118 bool display() const { return tabular.isLongTabular(); }
120 RESULT localDispatch(FuncRequest const &);
122 int latex(Buffer const *, std::ostream &,
123 LatexRunParams const &) const;
125 int ascii(Buffer const *, std::ostream &, int linelen) const;
127 int linuxdoc(Buffer const *, std::ostream &) const;
129 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
131 void validate(LaTeXFeatures & features) const;
133 Inset::Code lyxCode() const { return Inset::TABULAR_CODE; }
135 void getCursorPos(BufferView *, int & x, int & y) const;
136 /// Get the absolute document x,y of the cursor
137 virtual void getCursor(BufferView &, int &, int &) const;
139 bool tabularFeatures(BufferView * bv, string const & what);
141 void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
142 string const & val = string());
144 int getActCell() const { return actcell; }
146 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
147 bool selectall = false);
149 int getMaxWidth(BufferView *, UpdatableInset const *) const;
151 LyXText * getLyXText(BufferView const *,
152 bool const recursive = false) const;
154 void deleteLyXText(BufferView *, bool recursive = true) const;
156 void resizeLyXText(BufferView *, bool force = false) const;
158 void openLayoutDialog(BufferView *) const;
160 bool showInsetDialog(BufferView *) const;
162 FuncStatus getStatus(string const & argument) const;
164 void getLabelList(std::vector<string> &) const;
166 void nodraw(bool b) const {
167 UpdatableInset::nodraw(b);
171 int scroll(bool recursive=true) const;
173 void scroll(BufferView *bv, float sx) const {
174 UpdatableInset::scroll(bv, sx);
177 void scroll(BufferView *bv, int offset) const {
178 UpdatableInset::scroll(bv, offset);
181 Inset * getInsetFromID(int id) const;
183 ParagraphList * getParagraphs(int) const;
185 LyXCursor const & cursor(BufferView *) const;
187 bool allowSpellcheck() const { return true; }
190 selectNextWordToSpellcheck(BufferView *, float & value) const;
192 void selectSelectedWord(BufferView *);
194 void toggleSelection(BufferView *, bool kill_selection);
199 bool nextChange(BufferView *, lyx::pos_type & length);
201 bool searchForward(BufferView *, string const &,
202 bool = true, bool = false);
203 bool searchBackward(BufferView *, string const &,
204 bool = true, bool = false);
206 // this should return true if we have a "normal" cell, otherwise true.
207 // "normal" means without width set!
208 bool forceDefaultParagraphs(Inset const * in) const;
211 void addPreview(lyx::graphics::PreviewLoader &) const;
214 // Public structures and variables
216 mutable LyXTabular tabular;
218 /// are some cells selected ?
219 bool hasSelection() const {
220 return has_selection;
224 virtual BufferView * view() const;
226 Buffer const * buffer() const;
228 /// set the owning buffer
229 void buffer(Buffer * b);
233 void lfunMousePress(FuncRequest const &);
235 // the bool return is used to see if we opened a dialog so that we can
236 // check this from an outer inset and open the dialog of the outer inset
237 // if that one has one!
239 bool lfunMouseRelease(FuncRequest const &);
241 void lfunMouseMotion(FuncRequest const &);
243 bool calculate_dimensions_of_cells(BufferView *, bool = false) const;
245 void drawCellLines(Painter &, int x, int baseline,
246 int row, int cell) const;
248 void drawCellSelection(Painter &, int x, int baseline,
249 int row, int column, int cell) const;
251 void fitInsetCursor(BufferView *) const;
253 void setPos(BufferView *, int x, int y) const;
255 RESULT moveRight(BufferView *, bool lock = true);
257 RESULT moveLeft(BufferView *, bool lock = true);
259 RESULT moveUp(BufferView *, bool lock = true);
261 RESULT moveDown(BufferView *, bool lock = true);
263 bool moveNextCell(BufferView *, bool lock = false);
265 bool movePrevCell(BufferView *, bool lock = false);
267 int getCellXPos(int cell) const;
269 void resetPos(BufferView *) const;
271 void removeTabularRow();
273 void clearSelection() const {
274 sel_cell_start = sel_cell_end = 0;
275 has_selection = false;
277 void setSelection(int start, int end) const {
278 sel_cell_start = start;
280 has_selection = true;
283 bool activateCellInset(BufferView *, int x = 0, int y = 0,
284 mouse_button::state button = mouse_button::none,
285 bool behind = false);
287 bool activateCellInsetAbs(BufferView *, int x = 0, int y = 0,
288 mouse_button::state button = mouse_button::none);
290 bool insetHit(BufferView * bv, int x, int y) const;
292 int getMaxWidthOfCell(BufferView * bv, int cell) const;
294 bool hasPasteBuffer() const;
296 bool copySelection(BufferView *);
298 bool pasteSelection(BufferView *);
300 bool cutSelection(BufferParams const & bp);
302 bool isRightToLeft(BufferView *);
304 void getSelection(int & scol, int & ecol,
305 int & srow, int & erow) const;
307 WordLangTuple selectNextWordInt(BufferView *, float & value) const;
309 bool insertAsciiString(BufferView *, string const & buf, bool usePaste);
312 // Private structures and variables
314 InsetText * the_locking_inset;
316 InsetText * old_locking_inset;
318 Buffer const * buffer_;
320 mutable LyXCursor cursor_;
322 mutable unsigned int inset_x;
324 mutable unsigned int inset_y;
325 /// true if a set of cells are selected
326 mutable bool has_selection;
327 /// the starting cell selection nr
328 mutable int sel_cell_start;
329 /// the ending cell selection nr
330 mutable int sel_cell_end;
340 mutable int first_visible_cell;
346 mutable UpdateCodes need_update;
348 mutable int in_reset_pos;
352 #include "mailinset.h"
355 class InsetTabularMailer : public MailInset {
358 InsetTabularMailer(InsetTabular & inset);
360 virtual InsetBase & inset() const { return inset_; }
362 virtual string const & name() const { return name_; }
364 virtual string const inset2string() const;
365 /// Returns the active cell if successful, else -1.
366 static int string2params(string const &, InsetTabular &);
368 static string const params2string(InsetTabular const &);
371 static string const name_;
373 InsetTabular & inset_;
376 string const featureAsString(LyXTabular::Feature feature);