]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
457852a066b1cd6cb6a09e782d44f12110572053
[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 // This is the rewrite of the tabular (table) support.
12
13 // It will probably be a lot of work.
14
15 // One first goal could be to make the inset read the old table format
16 // and just output it again... no viewing at all.
17
18 // When making the internal structure of tabular support I really think
19 // that STL containers should be used. This will separate the container from
20 // the rest of the code, which is a good thing.
21
22 // Ideally the tabular support should do as the mathed and use
23 // LaTeX in the .lyx file too.
24
25 // Things to think of when desingning the new tabular support:
26 // - color support (colortbl, color)
27 // - decimal alignment (dcloumn)
28 // - custom lines (hhline)
29 // - rotation
30 // - multicolumn
31 // - multirow
32 // - column styles
33
34 // This is what I have written about tabular support in the LyX3-Tasks file:
35 //
36 //  o rewrite of table code. Should probably be written as some
37 //          kind of an inset. At least get the code out of the kernel.
38 //                - colortbl  -multirow
39 //                - hhline    -multicolumn
40 //                - dcolumn
41 // o enhance longtable support
42
43 // Lgb
44
45 #ifndef INSETTABULAR_H
46 #define INSETTABULAR_H
47
48 #include "inset.h"
49 #include "tabular.h"
50 #include "frontends/mouse_state.h"
51
52 class FuncStatus;
53 class LyXLex;
54 class Painter;
55 class BufferView;
56 class Buffer;
57 class BufferParams;
58 class Paragraph;
59
60 class InsetTabular : public UpdatableInset {
61 public:
62         ///
63         InsetTabular(Buffer const &, int rows = 1, int columns = 1);
64         ///
65         InsetTabular(InsetTabular const &);
66         ///
67         ~InsetTabular();
68         ///
69         virtual std::auto_ptr<InsetBase> clone() const;
70         ///
71         void read(Buffer const &, LyXLex &);
72         ///
73         void write(Buffer const &, std::ostream &) const;
74         ///
75         void metrics(MetricsInfo &, Dimension &) const;
76         ///
77         void draw(PainterInfo & pi, int x, int y) const;
78         ///
79         std::string const editMessage() const;
80         ///
81         void updateLocal(BufferView *) const;
82         ///
83         bool insetAllowed(InsetOld::Code code) const;
84         ///
85         bool isTextInset() const { return true; }
86         /** returns true if, when outputing LaTeX, font changes should
87             be closed before generating this inset. This is needed for
88             insets that may contain several paragraphs */
89         bool noFontChange() const { return true; }
90         ///
91         bool display() const { return tabular.isLongTabular(); }
92         ///
93         int latex(Buffer const &, std::ostream &,
94                   OutputParams const &) const;
95         ///
96         int plaintext(Buffer const &, std::ostream &,
97                   OutputParams const &) const;
98         ///
99         int linuxdoc(Buffer const &, std::ostream &,
100                      OutputParams const &) const;
101         ///
102         int docbook(Buffer const &, std::ostream &,
103                     OutputParams const &) const;
104         ///
105         void validate(LaTeXFeatures & features) const;
106         ///
107         InsetOld::Code lyxCode() const { return InsetOld::TABULAR_CODE; }
108         /// get the absolute screen x,y of the cursor
109         void getCursorPos(int & x, int & y) const;
110         ///
111         bool tabularFeatures(BufferView * bv, std::string const & what);
112         ///
113         void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
114                              std::string const & val = std::string());
115         ///
116         int getActCell() const { return actcell; }
117         ///
118         void openLayoutDialog(BufferView *) const;
119         ///
120         bool showInsetDialog(BufferView *) const;
121         ///
122         FuncStatus getStatus(std::string const & argument) const;
123         /// Appends \c list with all labels found within this inset.
124         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
125         ///
126         int numParagraphs() const;
127         ///
128         LyXText * getText(int) const;
129
130         ///
131         void markErased();
132
133         // this should return true if we have a "normal" cell, otherwise true.
134         // "normal" means without width set!
135         bool forceDefaultParagraphs(InsetOld const * in) const;
136
137         ///
138         void addPreview(lyx::graphics::PreviewLoader &) const;
139
140         /// are some cells selected ?
141         bool hasSelection() const { return has_selection; }
142         ///
143         Buffer const & buffer() const;
144
145         /// set the owning buffer
146         void buffer(Buffer * buf);
147         /// lock cell with given index
148         void edit(BufferView * bv, bool);
149         ///
150         void edit(BufferView * bv, int, int);
151         /// can we go further down on mouse click?
152         bool descendable() const { return true; }
153
154         //
155         // Public structures and variables
156         ///
157         mutable LyXTabular tabular;
158
159 protected:
160         ///
161         virtual
162         DispatchResult
163         priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
164 private:
165         ///
166         void lfunMousePress(FuncRequest const &);
167         ///
168         void lfunMouseRelease(FuncRequest const &);
169         ///
170         void lfunMouseMotion(FuncRequest const &);
171         ///
172         void calculate_dimensions_of_cells(MetricsInfo & mi) const;
173         ///
174         void drawCellLines(Painter &, int x, int baseline,
175                            int row, int cell) const;
176         ///
177         void drawCellSelection(Painter &, int x, int baseline,
178                                int row, int column, int cell) const;
179         ///
180         void setPos(BufferView *, int x, int y) const;
181         ///
182         DispatchResult moveRight(BufferView *);
183         ///
184         DispatchResult moveLeft(BufferView *);
185         ///
186         DispatchResult moveUp(BufferView *);
187         ///
188         DispatchResult moveDown(BufferView *);
189
190         ///
191         DispatchResult moveRightLock(BufferView *);
192         ///
193         DispatchResult moveLeftLock(BufferView *);
194         ///
195         DispatchResult moveUpLock(BufferView *);
196         ///
197         DispatchResult moveDownLock(BufferView *);
198
199         ///
200         bool moveNextCell(BufferView *);
201         ///
202         bool movePrevCell(BufferView *);
203
204
205         ///
206         int getCellXPos(int cell) const;
207         ///
208         void resetPos(BufferView *) const;
209         ///
210         void removeTabularRow();
211         ///
212         void clearSelection() const {
213                 sel_cell_start = sel_cell_end = 0;
214                 has_selection = false;
215         }
216         void setSelection(int start, int end) const {
217                 sel_cell_start = start;
218                 sel_cell_end = end;
219                 has_selection = true;
220         }
221         ///
222         void activateCellInset(BufferView *, int cell, int x, int y);
223         ///
224         void activateCellInset(BufferView *, int cell, bool behind);
225         ///
226         bool hasPasteBuffer() const;
227         ///
228         bool copySelection(BufferView *);
229         ///
230         bool pasteSelection(BufferView *);
231         ///
232         bool cutSelection(BufferParams const & bp);
233         ///
234         bool isRightToLeft(BufferView *);
235         ///
236         void getSelection(int & scol, int & ecol, int & srow, int & erow) const;
237         ///
238         bool insertAsciiString(BufferView *, std::string const & buf, bool usePaste);
239
240         //
241         // Private structures and variables
242         ///
243         Buffer const * buffer_;
244         ///
245         mutable int cursorx_;
246         ///
247         mutable int cursory_;
248         /// true if a set of cells are selected
249         mutable bool has_selection;
250         /// the starting cell selection nr
251         mutable int sel_cell_start;
252         /// the ending cell selection nr
253         mutable int sel_cell_end;
254         ///
255         mutable int actcell;
256         ///
257         mutable int actcol;
258         ///
259         mutable int actrow;
260         ///
261         mutable int first_visible_cell;
262         ///
263         mutable int in_reset_pos;
264 };
265
266
267 #include "mailinset.h"
268
269
270 class InsetTabularMailer : public MailInset {
271 public:
272         ///
273         InsetTabularMailer(InsetTabular const & inset);
274         ///
275         virtual InsetBase & inset() const { return inset_; }
276         ///
277         virtual std::string const & name() const { return name_; }
278         ///
279         virtual std::string const inset2string(Buffer const &) const;
280         /// Returns the active cell if successful, else -1.
281         static int string2params(std::string const &, InsetTabular &);
282         ///
283         static std::string const params2string(InsetTabular const &);
284 private:
285         ///
286         static std::string const name_;
287         ///
288         InsetTabular & inset_;
289 };
290
291 std::string const featureAsString(LyXTabular::Feature feature);
292
293 #endif