]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
4edfd18b12748d4c987436f47ed4add0a743c483
[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 insetUnlock(BufferView *);
82         ///
83         void updateLocal(BufferView *) const;
84         ///
85         bool lockInsetInInset(BufferView *, UpdatableInset *);
86         ///
87         bool unlockInsetInInset(BufferView *, UpdatableInset *,
88                                 bool lr = false);
89         ///
90         int insetInInsetY() const;
91         ///
92         UpdatableInset * getLockingInset() const;
93         ///
94         UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
95         ///
96         bool insertInset(BufferView *, InsetOld *);
97         ///
98         bool insetAllowed(InsetOld::Code code) const;
99         ///
100         bool isTextInset() const { return true; }
101         /** returns true if, when outputing LaTeX, font changes should
102             be closed before generating this inset. This is needed for
103             insets that may contain several paragraphs */
104         bool noFontChange() const { return true; }
105         ///
106         bool display() const { return tabular.isLongTabular(); }
107         ///
108         dispatch_result localDispatch(FuncRequest const &);
109         ///
110         int latex(Buffer const &, std::ostream &,
111                   LatexRunParams const &) const;
112         ///
113         int ascii(Buffer const &, std::ostream &, int linelen) const;
114         ///
115         int linuxdoc(Buffer const &, std::ostream &) const;
116         ///
117         int docbook(Buffer const &, std::ostream &, bool mixcont) const;
118         ///
119         void validate(LaTeXFeatures & features) const;
120         ///
121         InsetOld::Code lyxCode() const { return InsetOld::TABULAR_CODE; }
122         /// FIXME, document
123         void getCursorPos(BufferView *, int & x, int & y) const;
124         /// Get the absolute document x,y of the cursor
125         virtual void getCursor(BufferView &, int &, int &) const;
126         ///
127         bool tabularFeatures(BufferView * bv, std::string const & what);
128         ///
129         void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
130                              std::string const & val = std::string());
131         ///
132         int getActCell() const { return actcell; }
133         ///
134         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
135                      bool selectall = false);
136         ///
137         LyXText * getLyXText(BufferView const *,
138                              bool const recursive = false) const;
139         ///
140         void deleteLyXText(BufferView *, bool recursive = true) const;
141         ///
142         void openLayoutDialog(BufferView *) const;
143         ///
144         bool showInsetDialog(BufferView *) const;
145         ///
146         FuncStatus getStatus(std::string const & argument) const;
147         /// Appends \c list with all labels found within this inset.
148         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
149         ///
150         int scroll(bool recursive=true) const;
151         ///
152         void scroll(BufferView *bv, float sx) const {
153                 UpdatableInset::scroll(bv, sx);
154         }
155         ///
156         void scroll(BufferView *bv, int offset) const {
157                 UpdatableInset::scroll(bv, offset);
158         }
159         ///
160         InsetOld * getInsetFromID(int id) const;
161         ///
162         ParagraphList * getParagraphs(int) const;
163         ///
164         LyXText * getText(int) const;
165         ///
166         LyXCursor const & cursor(BufferView *) const;
167         ///
168         bool allowSpellcheck() const { return true; }
169         ///
170         WordLangTuple const
171         selectNextWordToSpellcheck(BufferView *, float & value) const;
172         ///
173         void selectSelectedWord(BufferView *);
174
175         void markErased();
176
177         /// find next change
178         bool nextChange(BufferView *, lyx::pos_type & length);
179         ///
180         bool searchForward(BufferView *, std::string const &,
181                            bool = true, bool = false);
182         bool searchBackward(BufferView *, std::string const &,
183                             bool = true, bool = false);
184
185         // this should return true if we have a "normal" cell, otherwise true.
186         // "normal" means without width set!
187         bool forceDefaultParagraphs(InsetOld const * in) const;
188
189         ///
190         void addPreview(lyx::graphics::PreviewLoader &) const;
191
192         //
193         // Public structures and variables
194         ///
195         mutable LyXTabular tabular;
196
197         /// are some cells selected ?
198         bool hasSelection() const {
199                 return has_selection;
200         }
201
202         ///
203         virtual BufferView * view() const;
204         ///
205         Buffer const & buffer() const;
206
207         /// set the owning buffer
208         void buffer(Buffer * buf);
209
210 private:
211         /// lock cell with given index
212         void edit(BufferView * bv, int index);
213         ///
214         void lfunMousePress(FuncRequest const &);
215         ///
216         // the bool return is used to see if we opened a dialog so that we can
217         // check this from an outer inset and open the dialog of the outer inset
218         // if that one has one!
219         ///
220         bool lfunMouseRelease(FuncRequest const &);
221         ///
222         void lfunMouseMotion(FuncRequest const &);
223         ///
224         void calculate_dimensions_of_cells(MetricsInfo & mi) const;
225         ///
226         void drawCellLines(Painter &, int x, int baseline,
227                            int row, int cell) const;
228         ///
229         void drawCellSelection(Painter &, int x, int baseline,
230                                int row, int column, int cell) const;
231         ///
232         void fitInsetCursor(BufferView *) const;
233         ///
234         void setPos(BufferView *, int x, int y) const;
235         ///
236         dispatch_result moveRight(BufferView *, bool lock = true);
237         ///
238         dispatch_result moveLeft(BufferView *, bool lock = true);
239         ///
240         dispatch_result moveUp(BufferView *, bool lock = true);
241         ///
242         dispatch_result moveDown(BufferView *, bool lock = true);
243         ///
244         bool moveNextCell(BufferView *, bool lock = false);
245         ///
246         bool movePrevCell(BufferView *, bool lock = false);
247         ///
248         int getCellXPos(int cell) const;
249         ///
250         void resetPos(BufferView *) const;
251         ///
252         void removeTabularRow();
253         ///
254         void clearSelection() const {
255                 sel_cell_start = sel_cell_end = 0;
256                 has_selection = false;
257         }
258         void setSelection(int start, int end) const {
259                 sel_cell_start = start;
260                 sel_cell_end = end;
261                 has_selection = true;
262         }
263         ///
264         bool activateCellInset(BufferView *, int x = 0, int y = 0,
265                                mouse_button::state button = mouse_button::none,
266                                bool behind = false);
267         ///
268         bool insetHit(BufferView * bv, int x, int y) const;
269         ///
270         bool hasPasteBuffer() const;
271         ///
272         bool copySelection(BufferView *);
273         ///
274         bool pasteSelection(BufferView *);
275         ///
276         bool cutSelection(BufferParams const & bp);
277         ///
278         bool isRightToLeft(BufferView *);
279         ///
280         void getSelection(int & scol, int & ecol,
281                           int & srow, int & erow) const;
282         ///
283         WordLangTuple selectNextWordInt(BufferView *, float & value) const;
284         ///
285         bool insertAsciiString(BufferView *, std::string const & buf, bool usePaste);
286
287         //
288         // Private structures and variables
289         ///
290         InsetText * the_locking_inset;
291         ///
292         InsetText * old_locking_inset;
293         ///
294         Buffer const * buffer_;
295         ///
296         mutable int cursorx_;
297         ///
298         mutable int cursory_;
299         ///
300         mutable unsigned int inset_x;
301         ///
302         mutable unsigned int inset_y;
303         /// true if a set of cells are selected
304         mutable bool has_selection;
305         /// the starting cell selection nr
306         mutable int sel_cell_start;
307         /// the ending cell selection nr
308         mutable int sel_cell_end;
309         ///
310         mutable int actcell;
311         ///
312         mutable int oldcell;
313         ///
314         mutable int actcol;
315         ///
316         mutable int actrow;
317         ///
318         mutable int first_visible_cell;
319         ///
320         bool no_selection;
321         ///
322         mutable bool locked;
323         ///
324         mutable int in_reset_pos;
325 };
326
327
328 #include "mailinset.h"
329
330
331 class InsetTabularMailer : public MailInset {
332 public:
333         ///
334         InsetTabularMailer(InsetTabular const & inset);
335         ///
336         virtual InsetBase & inset() const { return inset_; }
337         ///
338         virtual std::string const & name() const { return name_; }
339         ///
340         virtual std::string const inset2string(Buffer const &) const;
341         /// Returns the active cell if successful, else -1.
342         static int string2params(std::string const &, InsetTabular &);
343         ///
344         static std::string const params2string(InsetTabular const &);
345 private:
346         ///
347         static std::string const name_;
348         ///
349         InsetTabular & inset_;
350 };
351
352 std::string const featureAsString(LyXTabular::Feature feature);
353
354 #endif