]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
The speed patch: redraw only rows that have changed
[lyx.git] / src / insets / insettabular.h
1 // -*- C++ -*-
2 /**
3  * \file insettabular.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Jürgen Vigna
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12
13 // This is Juergen's rewrite of the tabular (table) support.
14
15 // Things to think of when designing the new tabular support:
16 // - color support (colortbl, color)
17 // - decimal alignment (dcloumn)
18 // - custom lines (hhline)
19 // - rotation
20 // - multicolumn
21 // - multirow
22 // - column styles
23
24 // This is what I have written about tabular support in the LyX3-Tasks file:
25 //
26 //  o rewrite of table code. Should probably be written as some
27 //    kind of an inset. [Done]
28 // o enhance longtable support
29
30 // Lgb
31
32 #ifndef INSETTABULAR_H
33 #define INSETTABULAR_H
34
35 #include "inset.h"
36 #include "tabular.h"
37
38 class FuncStatus;
39 class LyXLex;
40 class Painter;
41 class BufferView;
42 class Buffer;
43 class BufferParams;
44 class Paragraph;
45 class CursorSlice;
46
47
48 class InsetTabular : public InsetOld {
49 public:
50         ///
51         InsetTabular(Buffer const &, row_type rows = 1,
52                      col_type columns = 1);
53         ///
54         ~InsetTabular();
55         ///
56         void read(Buffer const &, LyXLex &);
57         ///
58         void write(Buffer const &, std::ostream &) const;
59         ///
60         void metrics(MetricsInfo &, Dimension &) const;
61         ///
62         void draw(PainterInfo & pi, int x, int y) const;
63         ///
64         void drawSelection(PainterInfo & pi, int x, int y) const;
65         ///
66         std::string const editMessage() const;
67         ///
68         EDITABLE editable() const { return HIGHLY_EDITABLE; }
69         ///
70         bool insetAllowed(InsetBase::Code) const { return true; }
71         ///
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; }
77         ///
78         bool display() const { return tabular.isLongTabular(); }
79         ///
80         int latex(Buffer const &, std::ostream &,
81                   OutputParams const &) const;
82         ///
83         int plaintext(Buffer const &, std::ostream &,
84                   OutputParams const &) const;
85         ///
86         int linuxdoc(Buffer const &, std::ostream &,
87                      OutputParams const &) const;
88         ///
89         int docbook(Buffer const &, std::ostream &,
90                     OutputParams const &) const;
91         ///
92         void validate(LaTeXFeatures & features) const;
93         ///
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;
97         ///
98         bool tabularFeatures(LCursor & cur, std::string const & what);
99         ///
100         void tabularFeatures(LCursor & cur, LyXTabular::Feature feature,
101                              std::string const & val = std::string());
102         ///
103         void openLayoutDialog(BufferView *) const;
104         ///
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;
108         /// number of cells
109         size_t nargs() const { return tabular.getNumberOfCells(); }
110         ///
111         boost::shared_ptr<InsetText const> cell(idx_type) const;
112         ///
113         boost::shared_ptr<InsetText> cell(idx_type);
114         ///
115         LyXText * getText(int) const;
116
117         ///
118         void markErased(bool);
119
120         // this should return true if we have a "normal" cell, otherwise false.
121         // "normal" means without width set!
122         /// should all paragraphs be output with "Standard" layout?
123         bool forceDefaultParagraphs(idx_type cell = 0) const;
124
125         ///
126         void addPreview(lyx::graphics::PreviewLoader &) const;
127
128         ///
129         Buffer const & buffer() const;
130
131         /// set the owning buffer
132         void buffer(Buffer const * buf);
133         /// lock cell with given index
134         void edit(LCursor & cur, bool left);
135         ///
136         InsetBase * editXY(LCursor & cur, int x, int y);
137         /// can we go further down on mouse click?
138         bool descendable() const { return true; }
139
140         //
141         // Public structures and variables
142         ///
143         mutable LyXTabular tabular;
144
145 protected:
146         ///
147         InsetTabular(InsetTabular const &);
148         ///
149         virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
150         ///
151         bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
152         ///
153         int scroll() const { return scx_; }
154
155 private:
156         virtual std::auto_ptr<InsetBase> doClone() const;
157
158         ///
159         void drawCellLines(Painter &, int x, int y, row_type row,
160                            idx_type cell, bool erased) const;
161         ///
162         void setCursorFromCoordinates(LCursor & cur, int x, int y) const;
163
164         ///
165         void moveNextCell(LCursor & cur);
166         ///
167         void movePrevCell(LCursor & cur);
168         ///
169         int getCellXPos(idx_type cell) const;
170         ///
171         void resetPos(LCursor & cur) const;
172         ///
173         void removeTabularRow();
174         ///
175         bool hasPasteBuffer() const;
176         ///
177         bool copySelection(LCursor & cur);
178         ///
179         bool pasteSelection(LCursor & cur);
180         ///
181         void cutSelection(LCursor & cur);
182         ///
183         bool isRightToLeft(LCursor & cur) const;
184         ///
185         void getSelection(LCursor & cur, row_type & rs, row_type & re,
186                           col_type & cs, col_type & ce) const;
187         ///
188         bool insertAsciiString(BufferView &, std::string const & buf, bool usePaste);
189         /// are we operating on several cells?
190         bool tablemode(LCursor & cur) const;
191
192         /// return the "Manhattan distance" to nearest corner
193         int dist(idx_type cell, int x, int y) const;
194         /// return the cell nearest to x, y
195         idx_type getNearestCell(int x, int y) const;
196
197         ///
198         Buffer const * buffer_;
199         ///
200         mutable idx_type first_visible_cell;
201         ///
202         mutable int scx_;
203 };
204
205
206 #include "mailinset.h"
207
208
209 class InsetTabularMailer : public MailInset {
210 public:
211         ///
212         InsetTabularMailer(InsetTabular const & inset);
213         ///
214         virtual InsetBase & inset() const { return inset_; }
215         ///
216         virtual std::string const & name() const { return name_; }
217         ///
218         virtual std::string const inset2string(Buffer const &) const;
219         ///
220         static void string2params(std::string const &, InsetTabular &);
221         ///
222         static std::string const params2string(InsetTabular const &);
223 private:
224         ///
225         static std::string const name_;
226         ///
227         InsetTabular & inset_;
228 };
229
230 std::string const featureAsString(LyXTabular::Feature feature);
231
232 #endif