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 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 &, std::ostream &,
86 OutputParams const &) const;
88 int plaintext(Buffer const &, std::ostream &,
89 OutputParams const &) const;
91 int linuxdoc(Buffer const &, std::ostream &,
92 OutputParams const &) const;
94 int docbook(Buffer const &, std::ostream &,
95 OutputParams const &) const;
97 void validate(LaTeXFeatures & features) const;
99 Code lyxCode() const { return InsetBase::TABULAR_CODE; }
100 /// get offset of this cursor slice relative to our upper left corner
101 void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
103 bool tabularFeatures(LCursor & cur, std::string const & what);
105 void tabularFeatures(LCursor & cur, LyXTabular::Feature feature,
106 std::string const & val = std::string());
108 void openLayoutDialog(BufferView *) const;
110 bool showInsetDialog(BufferView *) const;
112 size_t nargs() const { return tabular.getNumberOfCells(); }
114 boost::shared_ptr<InsetText const> cell(idx_type) const;
116 boost::shared_ptr<InsetText> cell(idx_type);
118 LyXText * getText(int) const;
121 void markErased(bool);
123 // this should return true if we have a "normal" cell, otherwise false.
124 // "normal" means without width set!
125 /// should all paragraphs be output with "Standard" layout?
126 bool forceDefaultParagraphs(idx_type cell = 0) const;
129 void addPreview(lyx::graphics::PreviewLoader &) const;
132 Buffer const & buffer() const;
134 /// set the owning buffer
135 void buffer(Buffer const * buf);
136 /// lock cell with given index
137 void edit(LCursor & cur, bool left);
139 InsetBase * editXY(LCursor & cur, int x, int y);
140 /// can we go further down on mouse click?
141 bool descendable() const { return true; }
144 // Public structures and variables
146 mutable LyXTabular tabular;
150 InsetTabular(InsetTabular const &);
152 virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
154 bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
156 int scroll() const { return scx_; }
159 virtual std::auto_ptr<InsetBase> doClone() const;
162 void drawCellLines(lyx::frontend::Painter &, int x, int y, row_type row,
163 idx_type cell, bool erased) const;
165 void setCursorFromCoordinates(LCursor & cur, int x, int y) const;
168 void moveNextCell(LCursor & cur);
170 void movePrevCell(LCursor & cur);
172 int getCellXPos(idx_type cell) const;
174 void resetPos(LCursor & cur) const;
176 void removeTabularRow();
178 bool hasPasteBuffer() const;
180 bool copySelection(LCursor & cur);
182 bool pasteSelection(LCursor & cur);
184 void cutSelection(LCursor & cur);
186 bool isRightToLeft(LCursor & cur) const;
188 void getSelection(LCursor & cur, row_type & rs, row_type & re,
189 col_type & cs, col_type & ce) const;
191 bool insertAsciiString(BufferView &, std::string const & buf, bool usePaste);
192 /// are we operating on several cells?
193 bool tablemode(LCursor & cur) const;
195 /// return the "Manhattan distance" to nearest corner
196 int dist(idx_type cell, int x, int y) const;
197 /// return the cell nearest to x, y
198 idx_type getNearestCell(int x, int y) const;
201 Buffer const * buffer_;
203 mutable idx_type first_visible_cell;
209 #include "mailinset.h"
212 class InsetTabularMailer : public MailInset {
215 InsetTabularMailer(InsetTabular const & inset);
217 virtual InsetBase & inset() const { return inset_; }
219 virtual std::string const & name() const { return name_; }
221 virtual std::string const inset2string(Buffer const &) const;
223 static void string2params(std::string const &, InsetTabular &);
225 static std::string const params2string(InsetTabular const &);
228 static std::string const name_;
230 InsetTabular & inset_;
233 std::string const featureAsString(LyXTabular::Feature feature);