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
53 class InsetTabular : public InsetOld {
56 InsetTabular(Buffer const &, row_type rows = 1,
57 col_type columns = 1);
61 void read(Buffer const &, LyXLex &);
63 void write(Buffer const &, std::ostream &) const;
65 void metrics(MetricsInfo &, Dimension &) const;
67 void draw(PainterInfo & pi, int x, int y) const;
69 void drawSelection(PainterInfo & pi, int x, int y) const;
71 std::string const editMessage() const;
73 EDITABLE editable() const { return HIGHLY_EDITABLE; }
75 bool insetAllowed(InsetBase::Code) const { return true; }
77 bool allowSpellCheck() const { return true; }
79 bool canTrackChanges() const { return true; }
80 /** returns true if, when outputing LaTeX, font changes should
81 be closed before generating this inset. This is needed for
82 insets that may contain several paragraphs */
83 bool noFontChange() const { return true; }
85 bool display() const { return tabular.isLongTabular(); }
87 int latex(Buffer const &, std::ostream &,
88 OutputParams const &) const;
90 int plaintext(Buffer const &, std::ostream &,
91 OutputParams const &) const;
93 int docbook(Buffer const &, std::ostream &,
94 OutputParams const &) const;
96 void validate(LaTeXFeatures & features) const;
98 Code lyxCode() const { return InsetBase::TABULAR_CODE; }
99 /// get offset of this cursor slice relative to our upper left corner
100 void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
102 bool tabularFeatures(LCursor & cur, std::string const & what);
104 void tabularFeatures(LCursor & cur, LyXTabular::Feature feature,
105 std::string const & val = std::string());
107 void openLayoutDialog(BufferView *) const;
109 bool showInsetDialog(BufferView *) const;
111 size_t nargs() const { return tabular.getNumberOfCells(); }
113 boost::shared_ptr<InsetText const> cell(idx_type) const;
115 boost::shared_ptr<InsetText> cell(idx_type);
117 LyXText * getText(int) const;
120 void markErased(bool);
122 // this should return true if we have a "normal" cell, otherwise false.
123 // "normal" means without width set!
124 /// should all paragraphs be output with "Standard" layout?
125 bool forceDefaultParagraphs(idx_type cell = 0) const;
128 void addPreview(lyx::graphics::PreviewLoader &) const;
131 Buffer const & buffer() const;
133 /// set the owning buffer
134 void buffer(Buffer const * buf);
135 /// lock cell with given index
136 void edit(LCursor & cur, bool left);
138 InsetBase * editXY(LCursor & cur, int x, int y);
139 /// can we go further down on mouse click?
140 bool descendable() const { return true; }
143 // Public structures and variables
145 mutable LyXTabular tabular;
149 InsetTabular(InsetTabular const &);
151 virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
153 bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
155 int scroll() const { return scx_; }
158 virtual std::auto_ptr<InsetBase> doClone() const;
161 void drawCellLines(lyx::frontend::Painter &, int x, int y, row_type row,
162 idx_type cell, bool erased) const;
164 void setCursorFromCoordinates(LCursor & cur, int x, int y) const;
167 void moveNextCell(LCursor & cur);
169 void movePrevCell(LCursor & cur);
171 int getCellXPos(idx_type cell) const;
173 void resetPos(LCursor & cur) const;
175 void removeTabularRow();
177 bool hasPasteBuffer() const;
179 bool copySelection(LCursor & cur);
181 bool pasteSelection(LCursor & cur);
183 void cutSelection(LCursor & cur);
185 bool isRightToLeft(LCursor & cur) const;
187 void getSelection(LCursor & cur, row_type & rs, row_type & re,
188 col_type & cs, col_type & ce) const;
190 bool insertAsciiString(BufferView &, lyx::docstring const & buf, bool usePaste);
191 /// are we operating on several cells?
192 bool tablemode(LCursor & cur) const;
194 /// return the "Manhattan distance" to nearest corner
195 int dist(idx_type cell, int x, int y) const;
196 /// return the cell nearest to x, y
197 idx_type getNearestCell(int x, int y) const;
200 Buffer const * buffer_;
202 mutable idx_type first_visible_cell;
208 #include "mailinset.h"
211 class InsetTabularMailer : public MailInset {
214 InsetTabularMailer(InsetTabular const & inset);
216 virtual InsetBase & inset() const { return inset_; }
218 virtual std::string const & name() const { return name_; }
220 virtual std::string const inset2string(Buffer const &) const;
222 static void string2params(std::string const &, InsetTabular &);
224 static std::string const params2string(InsetTabular const &);
227 static std::string const name_;
229 InsetTabular & inset_;
232 std::string const featureAsString(LyXTabular::Feature feature);