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 int latex(Buffer const &, std::ostream &,
109 LatexRunParams const &) const;
111 int ascii(Buffer const &, std::ostream &,
112 LatexRunParams const &) const;
114 int linuxdoc(Buffer const &, std::ostream &,
115 LatexRunParams const &) const;
117 int docbook(Buffer const &, std::ostream &,
118 LatexRunParams const &) const;
120 void validate(LaTeXFeatures & features) const;
122 InsetOld::Code lyxCode() const { return InsetOld::TABULAR_CODE; }
124 void getCursorPos(BufferView *, int & x, int & y) const;
125 /// Get the absolute document x,y of the cursor
126 virtual void getCursor(BufferView &, int &, int &) const;
128 bool tabularFeatures(BufferView * bv, std::string const & what);
130 void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
131 std::string const & val = std::string());
133 int getActCell() const { return actcell; }
135 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
136 bool selectall = false);
138 LyXText * getLyXText(BufferView const *,
139 bool const recursive = false) const;
141 void deleteLyXText(BufferView *, bool recursive = true) const;
143 void openLayoutDialog(BufferView *) const;
145 bool showInsetDialog(BufferView *) const;
147 FuncStatus getStatus(std::string const & argument) const;
148 /// Appends \c list with all labels found within this inset.
149 void getLabelList(Buffer const &, std::vector<std::string> & list) const;
151 int scroll(bool recursive=true) const;
153 void scroll(BufferView *bv, float sx) const {
154 UpdatableInset::scroll(bv, sx);
157 void scroll(BufferView *bv, int offset) const {
158 UpdatableInset::scroll(bv, offset);
161 ParagraphList * getParagraphs(int) const;
163 int numParagraphs() const;
165 LyXText * getText(int) const;
167 LyXCursor const & cursor(BufferView *) const;
172 // this should return true if we have a "normal" cell, otherwise true.
173 // "normal" means without width set!
174 bool forceDefaultParagraphs(InsetOld const * in) const;
177 void addPreview(lyx::graphics::PreviewLoader &) const;
180 // Public structures and variables
182 mutable LyXTabular tabular;
184 /// are some cells selected ?
185 bool hasSelection() const {
186 return has_selection;
190 virtual BufferView * view() const;
192 Buffer const & buffer() const;
194 /// set the owning buffer
195 void buffer(Buffer * buf);
196 /// lock cell with given index
197 void edit(BufferView * bv, bool);
199 void edit(BufferView * bv, int, int);
204 priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
207 void lfunMousePress(FuncRequest const &);
209 // the bool return is used to see if we opened a dialog so that we can
210 // check this from an outer inset and open the dialog of the outer inset
211 // if that one has one!
213 bool lfunMouseRelease(FuncRequest const &);
215 void lfunMouseMotion(FuncRequest const &);
217 void calculate_dimensions_of_cells(MetricsInfo & mi) const;
219 void drawCellLines(Painter &, int x, int baseline,
220 int row, int cell) const;
222 void drawCellSelection(Painter &, int x, int baseline,
223 int row, int column, int cell) const;
225 void fitInsetCursor(BufferView *) const;
227 void setPos(BufferView *, int x, int y) const;
229 DispatchResult moveRight(BufferView *, bool lock = true);
231 DispatchResult moveLeft(BufferView *, bool lock = true);
233 DispatchResult moveUp(BufferView *, bool lock = true);
235 DispatchResult moveDown(BufferView *, bool lock = true);
237 bool moveNextCell(BufferView *, bool lock = false);
239 bool movePrevCell(BufferView *, bool lock = false);
241 int getCellXPos(int cell) const;
243 void resetPos(BufferView *) const;
245 void removeTabularRow();
247 void clearSelection() const {
248 sel_cell_start = sel_cell_end = 0;
249 has_selection = false;
251 void setSelection(int start, int end) const {
252 sel_cell_start = start;
254 has_selection = true;
257 bool activateCellInset(BufferView *, int x = 0, int y = 0,
258 bool behind = false);
260 bool insetHit(BufferView * bv, int x, int y) const;
262 bool hasPasteBuffer() const;
264 bool copySelection(BufferView *);
266 bool pasteSelection(BufferView *);
268 bool cutSelection(BufferParams const & bp);
270 bool isRightToLeft(BufferView *);
272 void getSelection(int & scol, int & ecol,
273 int & srow, int & erow) const;
275 bool insertAsciiString(BufferView *, std::string const & buf, bool usePaste);
278 // Private structures and variables
280 InsetText * the_locking_inset;
282 InsetText * old_locking_inset;
284 Buffer const * buffer_;
286 mutable int cursorx_;
288 mutable int cursory_;
290 mutable unsigned int inset_x;
292 mutable unsigned int inset_y;
293 /// true if a set of cells are selected
294 mutable bool has_selection;
295 /// the starting cell selection nr
296 mutable int sel_cell_start;
297 /// the ending cell selection nr
298 mutable int sel_cell_end;
308 mutable int first_visible_cell;
314 mutable int in_reset_pos;
318 #include "mailinset.h"
321 class InsetTabularMailer : public MailInset {
324 InsetTabularMailer(InsetTabular const & inset);
326 virtual InsetBase & inset() const { return inset_; }
328 virtual std::string const & name() const { return name_; }
330 virtual std::string const inset2string(Buffer const &) const;
331 /// Returns the active cell if successful, else -1.
332 static int string2params(std::string const &, InsetTabular &);
334 static std::string const params2string(InsetTabular const &);
337 static std::string const name_;
339 InsetTabular & inset_;
342 std::string const featureAsString(LyXTabular::Feature feature);