]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
more IU
[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
51 #include "frontends/mouse_state.h"
52
53
54 class FuncStatus;
55 class LyXLex;
56 class Painter;
57 class BufferView;
58 class Buffer;
59 class BufferParams;
60 class Paragraph;
61 class CursorSlice;
62
63
64 class InsetTabular : public UpdatableInset {
65 public:
66         ///
67         InsetTabular(Buffer const &, int rows = 1, int columns = 1);
68         ///
69         InsetTabular(InsetTabular const &);
70         ///
71         ~InsetTabular();
72         ///
73         virtual std::auto_ptr<InsetBase> clone() const;
74         ///
75         void read(Buffer const &, LyXLex &);
76         ///
77         void write(Buffer const &, std::ostream &) const;
78         ///
79         void metrics(MetricsInfo &, Dimension &) const;
80         ///
81         void draw(PainterInfo & pi, int x, int y) const;
82         ///
83         std::string const editMessage() const;
84         ///
85         void updateLocal(LCursor & cur) const;
86         ///
87         bool insetAllowed(InsetOld::Code) const { return true; }
88         ///
89         bool isTextInset() const { return true; }
90         /** returns true if, when outputing LaTeX, font changes should
91             be closed before generating this inset. This is needed for
92             insets that may contain several paragraphs */
93         bool noFontChange() const { return true; }
94         ///
95         bool display() const { return tabular.isLongTabular(); }
96         ///
97         int latex(Buffer const &, std::ostream &,
98                   OutputParams const &) const;
99         ///
100         int plaintext(Buffer const &, std::ostream &,
101                   OutputParams const &) const;
102         ///
103         int linuxdoc(Buffer const &, std::ostream &,
104                      OutputParams const &) const;
105         ///
106         int docbook(Buffer const &, std::ostream &,
107                     OutputParams const &) const;
108         ///
109         void validate(LaTeXFeatures & features) const;
110         ///
111         InsetOld::Code lyxCode() const { return InsetOld::TABULAR_CODE; }
112         /// get the absolute screen x,y of the cursor
113         void getCursorPos(CursorSlice const & cur, int & x, int & y) const;
114         ///
115         bool tabularFeatures(LCursor & cur, std::string const & what);
116         ///
117         void tabularFeatures(LCursor & cur, LyXTabular::Feature feature,
118                              std::string const & val = std::string());
119         ///
120         void openLayoutDialog(BufferView *) const;
121         ///
122         bool showInsetDialog(BufferView *) const;
123         ///
124         FuncStatus getStatus(std::string const & argument, int cell) const;
125         /// Appends \c list with all labels found within this inset.
126         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
127         ///
128         int numParagraphs() const;
129         ///
130         LyXText * getText(int) const;
131
132         ///
133         void markErased();
134
135         // this should return true if we have a "normal" cell, otherwise true.
136         // "normal" means without width set!
137         bool forceDefaultParagraphs(InsetBase const * in) const;
138
139         ///
140         void addPreview(lyx::graphics::PreviewLoader &) const;
141
142         /// are some cells selected ?
143         bool hasSelection() const { return has_selection; }
144         ///
145         Buffer const & buffer() const;
146
147         /// set the owning buffer
148         void buffer(Buffer * buf);
149         /// lock cell with given index
150         void edit(LCursor & cur, bool);
151         ///
152         void edit(LCursor & cur, int, int);
153         /// can we go further down on mouse click?
154         bool descendable() const { return true; }
155
156         //
157         // Public structures and variables
158         ///
159         mutable LyXTabular tabular;
160
161 protected:
162         ///
163         virtual
164         DispatchResult
165         priv_dispatch(LCursor & cur, FuncRequest const & cmd);
166 private:
167         ///
168         void lfunMousePress(LCursor & cur, FuncRequest const & cmd);
169         ///
170         void lfunMouseRelease(LCursor & cur, FuncRequest const & cmd);
171         ///
172         void lfunMouseMotion(LCursor & cur, FuncRequest const & cmd);
173         ///
174         void calculate_dimensions_of_cells(MetricsInfo & mi) const;
175         ///
176         void drawCellLines(Painter &, int x, int baseline,
177                            int row, int cell) const;
178         ///
179         void drawCellSelection(Painter &, int x, int baseline,
180                                int row, int column, int cell) const;
181         ///
182         void setPos(BufferView &, int x, int y) const;
183         ///
184         bool moveRight(LCursor & cur);
185         ///
186         bool moveLeft(LCursor & cur);
187         ///
188         bool moveUp(LCursor & cur);
189         ///
190         bool moveDown(LCursor & cur);
191
192         ///
193         bool moveRightLock(LCursor & cur);
194         ///
195         bool moveLeftLock(LCursor & cur);
196         ///
197         bool moveUpLock(LCursor & cur);
198         ///
199         bool moveDownLock(LCursor & cur);
200
201         ///
202         bool moveNextCell(LCursor & cur);
203         ///
204         bool movePrevCell(LCursor & cur);
205
206
207         ///
208         int getCellXPos(int cell) const;
209         ///
210         void resetPos(LCursor & cur) const;
211         ///
212         void removeTabularRow();
213         ///
214         void clearSelection() const;
215         ///
216         void setSelection(int start, int end) const;
217         ///
218         void activateCellInset(LCursor &, int cell, int x, int y);
219         ///
220         void activateCellInset(LCursor &, int cell, bool behind);
221         ///
222         bool hasPasteBuffer() const;
223         ///
224         bool copySelection(BufferView &);
225         ///
226         bool pasteSelection(BufferView &);
227         ///
228         bool cutSelection(BufferParams const & bp);
229         ///
230         bool isRightToLeft(LCursor & cur);
231         ///
232         void getSelection(int cell,
233                 int & scol, int & ecol, int & srow, int & erow) const;
234         ///
235         bool insertAsciiString(BufferView &, std::string const & buf, bool usePaste);
236
237         //
238         // Private structures and variables
239         ///
240         Buffer const * buffer_;
241         ///
242         mutable int cursorx_;
243         ///
244         mutable int cursory_;
245         /// true if a set of cells are selected
246         mutable bool has_selection;
247         /// the starting cell selection nr
248         mutable int sel_cell_start;
249         /// the ending cell selection nr
250         mutable int sel_cell_end;
251         ///
252         mutable int first_visible_cell;
253         ///
254         mutable int in_reset_pos;
255         /// tablemode == true  means we operate on the table as such,
256         // i.e. select cells instead of characters in a cell etc.
257         // tablemode == false directs most LFUN handling to the 'current' cell.
258         mutable bool tablemode;
259 };
260
261
262 #include "mailinset.h"
263
264
265 class InsetTabularMailer : public MailInset {
266 public:
267         ///
268         InsetTabularMailer(InsetTabular const & inset);
269         ///
270         virtual InsetBase & inset() const { return inset_; }
271         ///
272         virtual std::string const & name() const { return name_; }
273         ///
274         virtual std::string const inset2string(Buffer const &) const;
275         /// Returns the active cell if successful, else -1.
276         static int string2params(std::string const &, InsetTabular &);
277         ///
278         static std::string const params2string(InsetTabular const &);
279 private:
280         ///
281         static std::string const name_;
282         ///
283         InsetTabular & inset_;
284 };
285
286 std::string const featureAsString(LyXTabular::Feature feature);
287
288 #endif