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
37 #include "mailinset.h"
49 namespace frontend { class Painter; }
51 class InsetTabular : public InsetOld {
54 InsetTabular(Buffer const &, row_type rows = 1,
55 col_type columns = 1);
59 void read(Buffer const &, LyXLex &);
61 void write(Buffer const &, std::ostream &) const;
63 void metrics(MetricsInfo &, Dimension &) const;
65 void draw(PainterInfo & pi, int x, int y) const;
67 void drawSelection(PainterInfo & pi, int x, int y) const;
69 virtual docstring const editMessage() const;
71 EDITABLE editable() const { return HIGHLY_EDITABLE; }
73 bool insetAllowed(InsetBase::Code) const { return true; }
75 bool allowSpellCheck() const { return true; }
77 bool canTrackChanges() const { return true; }
78 /** returns true if, when outputing LaTeX, font changes should
79 be closed before generating this inset. This is needed for
80 insets that may contain several paragraphs */
81 bool noFontChange() const { return true; }
83 bool display() const { return tabular.isLongTabular(); }
85 int latex(Buffer const &, odocstream &,
86 OutputParams const &) const;
88 int plaintext(Buffer const &, odocstream &,
89 OutputParams const &) const;
91 int docbook(Buffer const &, odocstream &,
92 OutputParams const &) const;
94 void validate(LaTeXFeatures & features) const;
96 Code lyxCode() const { return InsetBase::TABULAR_CODE; }
97 /// get offset of this cursor slice relative to our upper left corner
98 void cursorPos(BufferView const & bv, CursorSlice const & sl,
99 bool boundary, int & x, int & y) const;
101 bool tabularFeatures(LCursor & cur, std::string const & what);
103 void tabularFeatures(LCursor & cur, LyXTabular::Feature feature,
104 std::string const & val = std::string());
106 void openLayoutDialog(BufferView *) const;
108 bool showInsetDialog(BufferView *) const;
110 size_t nargs() const { return tabular.getNumberOfCells(); }
112 boost::shared_ptr<InsetText const> cell(idx_type) const;
114 boost::shared_ptr<InsetText> cell(idx_type);
116 LyXText * getText(int) const;
118 /// set the change for the entire inset
119 void setChange(Change const & change);
121 // this should return true if we have a "normal" cell, otherwise false.
122 // "normal" means without width set!
123 /// should all paragraphs be output with "Standard" layout?
124 bool forceDefaultParagraphs(idx_type cell = 0) const;
127 void addPreview(graphics::PreviewLoader &) const;
130 Buffer const & buffer() const;
132 /// set the owning buffer
133 void buffer(Buffer const * buf);
134 /// lock cell with given index
135 void edit(LCursor & cur, bool left);
137 InsetBase * editXY(LCursor & cur, int x, int y);
138 /// can we go further down on mouse click?
139 bool descendable() const { return true; }
142 // Public structures and variables
144 mutable LyXTabular tabular;
148 InsetTabular(InsetTabular const &);
150 virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
152 bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
154 int scroll() const { return scx_; }
157 virtual std::auto_ptr<InsetBase> doClone() const;
160 void drawCellLines(frontend::Painter &, int x, int y, row_type row,
161 idx_type cell, bool erased) const;
163 void setCursorFromCoordinates(LCursor & cur, int x, int y) const;
166 void moveNextCell(LCursor & cur);
168 void movePrevCell(LCursor & cur);
170 int getCellXPos(idx_type cell) const;
172 void resetPos(LCursor & cur) const;
174 void removeTabularRow();
176 bool hasPasteBuffer() const;
178 bool copySelection(LCursor & cur);
180 bool pasteSelection(LCursor & cur);
182 void cutSelection(LCursor & cur);
184 bool isRightToLeft(LCursor & cur) const;
186 void getSelection(LCursor & cur, row_type & rs, row_type & re,
187 col_type & cs, col_type & ce) const;
189 bool insertAsciiString(BufferView &, docstring const & buf, bool usePaste);
190 /// are we operating on several cells?
191 bool tablemode(LCursor & cur) const;
193 /// return the "Manhattan distance" to nearest corner
194 int dist(BufferView &, idx_type cell, int x, int y) const;
195 /// return the cell nearest to x, y
196 idx_type getNearestCell(BufferView &, int x, int y) const;
199 Buffer const * buffer_;
201 mutable idx_type first_visible_cell;
207 class InsetTabularMailer : public MailInset {
210 InsetTabularMailer(InsetTabular const & inset);
212 virtual InsetBase & inset() const { return inset_; }
214 virtual std::string const & name() const { return name_; }
216 virtual std::string const inset2string(Buffer const &) const;
218 static void string2params(std::string const &, InsetTabular &);
220 static std::string const params2string(InsetTabular const &);
223 static std::string const name_;
225 InsetTabular & inset_;
228 std::string const featureAsString(LyXTabular::Feature feature);