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 InsetOld {
51 InsetTabular(Buffer const &, row_type rows = 1,
52 col_type columns = 1);
56 void read(Buffer const &, LyXLex &);
58 void write(Buffer const &, std::ostream &) const;
60 void metrics(MetricsInfo &, Dimension &) const;
62 void draw(PainterInfo & pi, int x, int y) const;
64 void drawSelection(PainterInfo & pi, int x, int y) const;
66 std::string const editMessage() const;
68 EDITABLE editable() const { return HIGHLY_EDITABLE; }
70 bool insetAllowed(InsetBase::Code) const { return true; }
72 bool isTextInset() const { return true; }
73 /** returns true if, when outputing LaTeX, font changes should
74 be closed before generating this inset. This is needed for
75 insets that may contain several paragraphs */
76 bool noFontChange() const { return true; }
78 bool display() const { return tabular.isLongTabular(); }
80 int latex(Buffer const &, std::ostream &,
81 OutputParams const &) const;
83 int plaintext(Buffer const &, std::ostream &,
84 OutputParams const &) const;
86 int linuxdoc(Buffer const &, std::ostream &,
87 OutputParams const &) const;
89 int docbook(Buffer const &, std::ostream &,
90 OutputParams const &) const;
92 void validate(LaTeXFeatures & features) const;
94 Code lyxCode() const { return InsetBase::TABULAR_CODE; }
95 /// get offset of this cursor slice relative to our upper left corner
96 void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
98 bool tabularFeatures(LCursor & cur, std::string const & what);
100 void tabularFeatures(LCursor & cur, LyXTabular::Feature feature,
101 std::string const & val = std::string());
103 void openLayoutDialog(BufferView *) const;
105 bool showInsetDialog(BufferView *) const;
106 /// Appends \c list with all labels found within this inset.
107 void getLabelList(Buffer const &, std::vector<std::string> & list) const;
109 size_t nargs() const { return tabular.getNumberOfCells(); }
111 boost::shared_ptr<InsetText const> cell(idx_type) const;
113 boost::shared_ptr<InsetText> cell(idx_type);
115 LyXText * getText(int) const;
120 // this should return true if we have a "normal" cell, otherwise true.
121 // "normal" means without width set!
122 bool forceDefaultParagraphs(InsetBase const * in) const;
125 void addPreview(lyx::graphics::PreviewLoader &) const;
128 Buffer const & buffer() const;
130 /// set the owning buffer
131 void buffer(Buffer const * buf);
132 /// lock cell with given index
133 void edit(LCursor & cur, bool left);
135 InsetBase * editXY(LCursor & cur, int x, int y);
136 /// can we go further down on mouse click?
137 bool descendable() const { return true; }
140 // Public structures and variables
142 mutable LyXTabular tabular;
146 InsetTabular(InsetTabular const &);
148 virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
150 bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
152 int scroll() const { return scx_; }
155 virtual std::auto_ptr<InsetBase> doClone() const;
158 void drawCellLines(Painter &, int x, int y, row_type row,
159 idx_type cell) const;
161 void setCursorFromCoordinates(LCursor & cur, int x, int y) const;
164 void moveNextCell(LCursor & cur);
166 void movePrevCell(LCursor & cur);
168 int getCellXPos(idx_type cell) const;
170 void resetPos(LCursor & cur) const;
172 void removeTabularRow();
174 bool hasPasteBuffer() const;
176 bool copySelection(LCursor & cur);
178 bool pasteSelection(LCursor & cur);
180 void cutSelection(LCursor & cur);
182 bool isRightToLeft(LCursor & cur) const;
184 void getSelection(LCursor & cur, row_type & rs, row_type & re,
185 col_type & cs, col_type & ce) const;
187 bool insertAsciiString(BufferView &, std::string const & buf, bool usePaste);
188 /// are we operating on several cells?
189 bool tablemode(LCursor & cur) const;
191 /// return the "Manhattan distance" to nearest corner
192 int dist(idx_type cell, int x, int y) const;
193 /// return the cell nearest to x, y
194 idx_type getNearestCell(int x, int y) const;
197 Buffer const * buffer_;
199 mutable idx_type first_visible_cell;
205 #include "mailinset.h"
208 class InsetTabularMailer : public MailInset {
211 InsetTabularMailer(InsetTabular const & inset);
213 virtual InsetBase & inset() const { return inset_; }
215 virtual std::string const & name() const { return name_; }
217 virtual std::string const inset2string(Buffer const &) const;
219 static void string2params(std::string const &, InsetTabular &);
221 static std::string const params2string(InsetTabular const &);
224 static std::string const name_;
226 InsetTabular & inset_;
229 std::string const featureAsString(LyXTabular::Feature feature);