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.
13 // This is Juergen's rewrite of the tabular (table) support.
15 // Things to think of when designing the new tabular support:
16 // - color support (colortbl, color)
17 // - decimal alignment (dcloumn)
18 // - custom lines (hhline)
24 // This is what I have written about tabular support in the LyX3-Tasks file:
26 // o rewrite of table code. Should probably be written as some
27 // kind of an inset. [Done]
28 // o enhance longtable support
32 #ifndef INSETTABULAR_H
33 #define INSETTABULAR_H
48 class InsetTabular : public UpdatableInset {
51 InsetTabular(Buffer const &, int rows = 1, int columns = 1);
55 void read(Buffer const &, LyXLex &);
57 void write(Buffer const &, std::ostream &) const;
59 void metrics(MetricsInfo &, Dimension &) const;
61 void draw(PainterInfo & pi, int x, int y) const;
63 std::string const editMessage() const;
65 bool insetAllowed(InsetBase::Code) const { return true; }
67 bool isTextInset() const { return true; }
68 /** returns true if, when outputing LaTeX, font changes should
69 be closed before generating this inset. This is needed for
70 insets that may contain several paragraphs */
71 bool noFontChange() const { return true; }
73 bool display() const { return tabular.isLongTabular(); }
75 int latex(Buffer const &, std::ostream &,
76 OutputParams const &) const;
78 int plaintext(Buffer const &, std::ostream &,
79 OutputParams const &) const;
81 int linuxdoc(Buffer const &, std::ostream &,
82 OutputParams const &) const;
84 int docbook(Buffer const &, std::ostream &,
85 OutputParams const &) const;
87 void validate(LaTeXFeatures & features) const;
89 Code lyxCode() const { return InsetBase::TABULAR_CODE; }
90 /// get the absolute screen x,y of the cursor
91 void getCursorPos(LCursor const & cur, int & x, int & y) const;
93 bool tabularFeatures(LCursor & cur, std::string const & what);
95 void tabularFeatures(LCursor & cur, LyXTabular::Feature feature,
96 std::string const & val = std::string());
98 void openLayoutDialog(BufferView *) const;
100 bool showInsetDialog(BufferView *) const;
101 /// Appends \c list with all labels found within this inset.
102 void getLabelList(Buffer const &, std::vector<std::string> & list) const;
104 size_t nargs() const;
106 boost::shared_ptr<InsetText const> cell(int) const;
108 boost::shared_ptr<InsetText> cell(int);
110 LyXText * getText(int) const;
115 // this should return true if we have a "normal" cell, otherwise true.
116 // "normal" means without width set!
117 bool forceDefaultParagraphs(InsetBase const * in) const;
120 void addPreview(lyx::graphics::PreviewLoader &) const;
123 Buffer const & buffer() const;
125 /// set the owning buffer
126 void buffer(Buffer const * buf);
127 /// lock cell with given index
128 void edit(LCursor & cur, bool left);
130 InsetBase * editXY(LCursor & cur, int x, int y) const;
131 /// can we go further down on mouse click?
132 bool descendable() const { return true; }
135 // Public structures and variables
137 mutable LyXTabular tabular;
140 InsetTabular(InsetTabular const &);
142 void priv_dispatch(LCursor & cur, FuncRequest & cmd);
144 bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
146 virtual std::auto_ptr<InsetBase> doClone() const;
149 void drawCellLines(Painter &, int x, int baseline,
150 int row, int cell) const;
152 void drawCellSelection(PainterInfo &, int x, int baseline,
153 int row, int column, int cell) const;
155 InsetBase * setPos(LCursor & cur, int x, int y) const;
158 void moveNextCell(LCursor & cur);
160 void movePrevCell(LCursor & cur);
162 int getCellXPos(int cell) const;
164 void resetPos(LCursor & cur) const;
166 void removeTabularRow();
168 bool hasPasteBuffer() const;
170 bool copySelection(LCursor & cur);
172 bool pasteSelection(LCursor & cur);
174 void cutSelection(LCursor & cur);
176 bool isRightToLeft(LCursor & cur) const;
178 void getSelection(LCursor & cur,
179 int & rs, int & re, int & cs, int & ce) const;
181 bool insertAsciiString(BufferView &, std::string const & buf, bool usePaste);
182 /// are we operating on several cells?
183 bool tablemode(LCursor & cur) const;
186 Buffer const * buffer_;
188 mutable int cursorx_;
190 mutable int first_visible_cell;
194 #include "mailinset.h"
197 class InsetTabularMailer : public MailInset {
200 InsetTabularMailer(InsetTabular const & inset);
202 virtual InsetBase & inset() const { return inset_; }
204 virtual std::string const & name() const { return name_; }
206 virtual std::string const inset2string(Buffer const &) const;
208 static void string2params(std::string const &, InsetTabular &);
210 static std::string const params2string(InsetTabular const &);
213 static std::string const name_;
215 InsetTabular & inset_;
218 std::string const featureAsString(LyXTabular::Feature feature);