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 "frontends/mouse_state.h"
64 class InsetTabular : public UpdatableInset {
67 InsetTabular(Buffer const &, int rows = 1, int columns = 1);
69 InsetTabular(InsetTabular const &);
73 virtual std::auto_ptr<InsetBase> clone() const;
75 void read(Buffer const &, LyXLex &);
77 void write(Buffer const &, std::ostream &) const;
79 void metrics(MetricsInfo &, Dimension &) const;
81 void draw(PainterInfo & pi, int x, int y) const;
83 std::string const editMessage() const;
85 void updateLocal(LCursor & cur) const;
87 bool insetAllowed(InsetOld::Code) const { return true; }
89 bool isTextInset() const { return true; }
90 /** returns true if, when outputing LaTeX, font changes should
91 be closed before generating this inset. This is needed for
92 insets that may contain several paragraphs */
93 bool noFontChange() const { return true; }
95 bool display() const { return tabular.isLongTabular(); }
97 int latex(Buffer const &, std::ostream &,
98 OutputParams const &) const;
100 int plaintext(Buffer const &, std::ostream &,
101 OutputParams const &) const;
103 int linuxdoc(Buffer const &, std::ostream &,
104 OutputParams const &) const;
106 int docbook(Buffer const &, std::ostream &,
107 OutputParams const &) const;
109 void validate(LaTeXFeatures & features) const;
111 InsetOld::Code lyxCode() const { return InsetOld::TABULAR_CODE; }
112 /// get the absolute screen x,y of the cursor
113 void getCursorPos(CursorSlice const & cur, int & x, int & y) const;
115 bool tabularFeatures(LCursor & cur, std::string const & what);
117 void tabularFeatures(LCursor & cur, LyXTabular::Feature feature,
118 std::string const & val = std::string());
120 void openLayoutDialog(BufferView *) const;
122 bool showInsetDialog(BufferView *) const;
124 FuncStatus getStatus(BufferView &,
125 std::string const & argument, int cell) const;
126 /// Appends \c list with all labels found within this inset.
127 void getLabelList(Buffer const &, std::vector<std::string> & list) const;
129 int numParagraphs() const;
131 LyXText * getText(int) const;
136 // this should return true if we have a "normal" cell, otherwise true.
137 // "normal" means without width set!
138 bool forceDefaultParagraphs(InsetBase const * in) const;
141 void addPreview(lyx::graphics::PreviewLoader &) const;
144 Buffer const & buffer() const;
146 /// set the owning buffer
147 void buffer(Buffer * buf);
148 /// lock cell with given index
149 void edit(LCursor & cur, bool left);
151 InsetBase * editXY(LCursor & cur, int x, int y);
152 /// can we go further down on mouse click?
153 bool descendable() const { return true; }
156 // Public structures and variables
158 mutable LyXTabular tabular;
162 DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
165 void lfunMousePress(LCursor & cur, FuncRequest const & cmd);
167 void lfunMouseRelease(LCursor & cur, FuncRequest const & cmd);
169 void lfunMouseMotion(LCursor & cur, FuncRequest const & cmd);
171 void calculate_dimensions_of_cells(MetricsInfo & mi) const;
173 void drawCellLines(Painter &, int x, int baseline,
174 int row, int cell) const;
176 void drawCellSelection(PainterInfo &, int x, int baseline,
177 int row, int column, int cell) const;
179 InsetBase * setPos(LCursor & cur, int x, int y) const;
181 bool moveRight(LCursor & cur);
183 bool moveLeft(LCursor & cur);
185 bool moveUp(LCursor & cur);
187 bool moveDown(LCursor & cur);
190 bool moveRightLock(LCursor & cur);
192 bool moveLeftLock(LCursor & cur);
194 bool moveUpLock(LCursor & cur);
196 bool moveDownLock(LCursor & cur);
199 bool moveNextCell(LCursor & cur);
201 bool movePrevCell(LCursor & cur);
205 int getCellXPos(int cell) const;
207 void resetPos(LCursor & cur) const;
209 void removeTabularRow();
211 //void clearSelection() const;
213 //void setSelection(int start, int end) const;
215 void activateCellInset(LCursor &, int cell, int x, int y);
217 void activateCellInset(LCursor &, int cell, bool behind);
219 bool hasPasteBuffer() const;
221 bool copySelection(LCursor & cur);
223 bool pasteSelection(LCursor & cur);
225 void cutSelection(LCursor & cur);
227 bool isRightToLeft(LCursor & cur);
229 void getSelection(LCursor & cur,
230 int & rs, int & re, int & cs, int & ce) const;
232 bool insertAsciiString(BufferView &, std::string const & buf, bool usePaste);
234 /// are we operating on several cells?
235 bool tablemode(LCursor & cur) const;
238 // Private structures and variables
240 Buffer const * buffer_;
242 mutable int cursorx_;
244 mutable int cursory_;
245 /// true if a set of cells are selected
246 //mutable bool has_selection;
247 /// the starting cell selection nr
248 //mutable int sel_cell_start;
249 /// the ending cell selection nr
250 //mutable int sel_cell_end;
252 mutable int first_visible_cell;
254 mutable int in_reset_pos;
258 #include "mailinset.h"
261 class InsetTabularMailer : public MailInset {
264 InsetTabularMailer(InsetTabular const & inset);
266 virtual InsetBase & inset() const { return inset_; }
268 virtual std::string const & name() const { return name_; }
270 virtual std::string const inset2string(Buffer const &) const;
271 /// Returns the active cell if successful, else -1.
272 static int string2params(std::string const &, InsetTabular &);
274 static std::string const params2string(InsetTabular const &);
277 static std::string const name_;
279 InsetTabular & inset_;
282 std::string const featureAsString(LyXTabular::Feature feature);