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
50 #include "frontends/mouse_state.h"
60 class InsetTabular : public UpdatableInset {
63 InsetTabular(Buffer const &, int rows = 1, int columns = 1);
65 InsetTabular(InsetTabular const &);
69 virtual std::auto_ptr<InsetBase> clone() const;
71 void read(Buffer const &, LyXLex &);
73 void write(Buffer const &, std::ostream &) const;
75 void metrics(MetricsInfo &, Dimension &) const;
77 void draw(PainterInfo & pi, int x, int y) const;
79 std::string const editMessage() const;
81 void insetUnlock(BufferView *);
83 void updateLocal(BufferView *) const;
85 bool lockInsetInInset(BufferView *, UpdatableInset *);
87 bool unlockInsetInInset(BufferView *, UpdatableInset *,
90 int insetInInsetY() const;
92 UpdatableInset * getLockingInset() const;
94 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
96 bool insertInset(BufferView *, InsetOld *);
98 bool insetAllowed(InsetOld::Code code) const;
100 bool isTextInset() const { return true; }
101 /** returns true if, when outputing LaTeX, font changes should
102 be closed before generating this inset. This is needed for
103 insets that may contain several paragraphs */
104 bool noFontChange() const { return true; }
106 bool display() const { return tabular.isLongTabular(); }
108 dispatch_result localDispatch(FuncRequest const &);
110 int latex(Buffer const &, std::ostream &,
111 LatexRunParams const &) const;
113 int ascii(Buffer const &, std::ostream &, int linelen) const;
115 int linuxdoc(Buffer const &, std::ostream &) const;
117 int docbook(Buffer const &, std::ostream &, bool mixcont) const;
119 void validate(LaTeXFeatures & features) const;
121 InsetOld::Code lyxCode() const { return InsetOld::TABULAR_CODE; }
123 void getCursorPos(BufferView *, int & x, int & y) const;
124 /// Get the absolute document x,y of the cursor
125 virtual void getCursor(BufferView &, int &, int &) const;
127 bool tabularFeatures(BufferView * bv, std::string const & what);
129 void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
130 std::string const & val = std::string());
132 int getActCell() const { return actcell; }
134 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
135 bool selectall = false);
137 LyXText * getLyXText(BufferView const *,
138 bool const recursive = false) const;
140 void deleteLyXText(BufferView *, bool recursive = true) const;
142 void openLayoutDialog(BufferView *) const;
144 bool showInsetDialog(BufferView *) const;
146 FuncStatus getStatus(std::string const & argument) const;
147 /// Appends \c list with all labels found within this inset.
148 void getLabelList(Buffer const &, std::vector<std::string> & list) const;
150 int scroll(bool recursive=true) const;
152 void scroll(BufferView *bv, float sx) const {
153 UpdatableInset::scroll(bv, sx);
156 void scroll(BufferView *bv, int offset) const {
157 UpdatableInset::scroll(bv, offset);
160 InsetOld * getInsetFromID(int id) const;
162 ParagraphList * getParagraphs(int) const;
164 LyXText * getText(int) const;
166 LyXCursor const & cursor(BufferView *) const;
168 bool allowSpellcheck() const { return true; }
171 selectNextWordToSpellcheck(BufferView *, float & value) const;
173 void selectSelectedWord(BufferView *);
178 bool nextChange(BufferView *, lyx::pos_type & length);
180 bool searchForward(BufferView *, std::string const &,
181 bool = true, bool = false);
182 bool searchBackward(BufferView *, std::string const &,
183 bool = true, bool = false);
185 // this should return true if we have a "normal" cell, otherwise true.
186 // "normal" means without width set!
187 bool forceDefaultParagraphs(InsetOld const * in) const;
190 void addPreview(lyx::graphics::PreviewLoader &) const;
193 // Public structures and variables
195 mutable LyXTabular tabular;
197 /// are some cells selected ?
198 bool hasSelection() const {
199 return has_selection;
203 virtual BufferView * view() const;
205 Buffer const & buffer() const;
207 /// set the owning buffer
208 void buffer(Buffer * b);
212 void lfunMousePress(FuncRequest const &);
214 // the bool return is used to see if we opened a dialog so that we can
215 // check this from an outer inset and open the dialog of the outer inset
216 // if that one has one!
218 bool lfunMouseRelease(FuncRequest const &);
220 void lfunMouseMotion(FuncRequest const &);
222 void calculate_dimensions_of_cells(MetricsInfo & mi) const;
224 void drawCellLines(Painter &, int x, int baseline,
225 int row, int cell) const;
227 void drawCellSelection(Painter &, int x, int baseline,
228 int row, int column, int cell) const;
230 void fitInsetCursor(BufferView *) const;
232 void setPos(BufferView *, int x, int y) const;
234 dispatch_result moveRight(BufferView *, bool lock = true);
236 dispatch_result moveLeft(BufferView *, bool lock = true);
238 dispatch_result moveUp(BufferView *, bool lock = true);
240 dispatch_result moveDown(BufferView *, bool lock = true);
242 bool moveNextCell(BufferView *, bool lock = false);
244 bool movePrevCell(BufferView *, bool lock = false);
246 int getCellXPos(int cell) const;
248 void resetPos(BufferView *) const;
250 void removeTabularRow();
252 void clearSelection() const {
253 sel_cell_start = sel_cell_end = 0;
254 has_selection = false;
256 void setSelection(int start, int end) const {
257 sel_cell_start = start;
259 has_selection = true;
262 bool activateCellInset(BufferView *, int x = 0, int y = 0,
263 mouse_button::state button = mouse_button::none,
264 bool behind = false);
266 bool insetHit(BufferView * bv, int x, int y) const;
268 bool hasPasteBuffer() const;
270 bool copySelection(BufferView *);
272 bool pasteSelection(BufferView *);
274 bool cutSelection(BufferParams const & bp);
276 bool isRightToLeft(BufferView *);
278 void getSelection(int & scol, int & ecol,
279 int & srow, int & erow) const;
281 WordLangTuple selectNextWordInt(BufferView *, float & value) const;
283 bool insertAsciiString(BufferView *, std::string const & buf, bool usePaste);
286 // Private structures and variables
288 InsetText * the_locking_inset;
290 InsetText * old_locking_inset;
292 Buffer const * buffer_;
294 mutable int cursorx_;
296 mutable int cursory_;
298 mutable unsigned int inset_x;
300 mutable unsigned int inset_y;
301 /// true if a set of cells are selected
302 mutable bool has_selection;
303 /// the starting cell selection nr
304 mutable int sel_cell_start;
305 /// the ending cell selection nr
306 mutable int sel_cell_end;
316 mutable int first_visible_cell;
322 mutable int in_reset_pos;
326 #include "mailinset.h"
329 class InsetTabularMailer : public MailInset {
332 InsetTabularMailer(InsetTabular const & inset);
334 virtual InsetBase & inset() const { return inset_; }
336 virtual std::string const & name() const { return name_; }
338 virtual std::string const inset2string(Buffer const &) const;
339 /// Returns the active cell if successful, else -1.
340 static int string2params(std::string const &, InsetTabular &);
342 static std::string const params2string(InsetTabular const &);
345 static std::string const name_;
347 InsetTabular & inset_;
350 std::string const featureAsString(LyXTabular::Feature feature);