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 void drawSelection(PainterInfo & pi, int x, int y) const;
65 std::string const editMessage() const;
67 bool insetAllowed(InsetBase::Code) const { return true; }
69 bool isTextInset() const { return true; }
70 /** returns true if, when outputing LaTeX, font changes should
71 be closed before generating this inset. This is needed for
72 insets that may contain several paragraphs */
73 bool noFontChange() const { return true; }
75 bool display() const { return tabular.isLongTabular(); }
77 int latex(Buffer const &, std::ostream &,
78 OutputParams const &) const;
80 int plaintext(Buffer const &, std::ostream &,
81 OutputParams const &) const;
83 int linuxdoc(Buffer const &, std::ostream &,
84 OutputParams const &) const;
86 int docbook(Buffer const &, std::ostream &,
87 OutputParams const &) const;
89 void validate(LaTeXFeatures & features) const;
91 Code lyxCode() const { return InsetBase::TABULAR_CODE; }
92 /// get offset of this cursor slice relative to our upper left corner
93 void getCursorPos(CursorSlice const & sl, int & x, int & y) const;
95 bool tabularFeatures(LCursor & cur, std::string const & what);
97 void tabularFeatures(LCursor & cur, LyXTabular::Feature feature,
98 std::string const & val = std::string());
100 void openLayoutDialog(BufferView *) const;
102 bool showInsetDialog(BufferView *) const;
103 /// Appends \c list with all labels found within this inset.
104 void getLabelList(Buffer const &, std::vector<std::string> & list) const;
106 size_t nargs() const;
108 boost::shared_ptr<InsetText const> cell(int) const;
110 boost::shared_ptr<InsetText> cell(int);
112 LyXText * getText(int) const;
117 // this should return true if we have a "normal" cell, otherwise true.
118 // "normal" means without width set!
119 bool forceDefaultParagraphs(InsetBase const * in) const;
122 void addPreview(lyx::graphics::PreviewLoader &) const;
125 Buffer const & buffer() const;
127 /// set the owning buffer
128 void buffer(Buffer const * buf);
129 /// lock cell with given index
130 void edit(LCursor & cur, bool left);
132 InsetBase * editXY(LCursor & cur, int x, int y) const;
133 /// can we go further down on mouse click?
134 bool descendable() const { return true; }
137 // Public structures and variables
139 mutable LyXTabular tabular;
142 InsetTabular(InsetTabular const &);
144 virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
147 bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
149 virtual std::auto_ptr<InsetBase> doClone() const;
152 void drawCellLines(Painter &, int x, int y, int row, int cell) const;
154 InsetBase * setPos(LCursor & cur, int x, int y) const;
157 void moveNextCell(LCursor & cur);
159 void movePrevCell(LCursor & cur);
161 int getCellXPos(int cell) const;
163 void resetPos(LCursor & cur) const;
165 void removeTabularRow();
167 bool hasPasteBuffer() const;
169 bool copySelection(LCursor & cur);
171 bool pasteSelection(LCursor & cur);
173 void cutSelection(LCursor & cur);
175 bool isRightToLeft(LCursor & cur) const;
177 void getSelection(LCursor & cur,
178 int & rs, int & re, int & cs, int & ce) const;
180 bool insertAsciiString(BufferView &, std::string const & buf, bool usePaste);
181 /// are we operating on several cells?
182 bool tablemode(LCursor & cur) const;
185 Buffer const * buffer_;
187 mutable int cursorx_;
189 mutable int first_visible_cell;
193 #include "mailinset.h"
196 class InsetTabularMailer : public MailInset {
199 InsetTabularMailer(InsetTabular const & inset);
201 virtual InsetBase & inset() const { return inset_; }
203 virtual std::string const & name() const { return name_; }
205 virtual std::string const inset2string(Buffer const &) const;
207 static void string2params(std::string const &, InsetTabular &);
209 static std::string const params2string(InsetTabular const &);
212 static std::string const name_;
214 InsetTabular & inset_;
217 std::string const featureAsString(LyXTabular::Feature feature);