]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
Store an InsetBase & in MailInset.
[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
49 #include "inset.h"
50 #include "tabular.h"
51 #include "LString.h"
52 #include "lyxcursor.h"
53 #include "FuncStatus.h"
54
55 #include <boost/scoped_ptr.hpp>
56 #include <boost/weak_ptr.hpp>
57
58 class LyXLex;
59 class Painter;
60 class BufferView;
61 class Buffer;
62 class BufferParams;
63 class Paragraph;
64
65 class InsetTabular : public UpdatableInset {
66 public:
67         ///
68         enum UpdateCodes {
69                 NONE = 0,
70                 CURSOR = 1,
71                 CELL = 2,
72                 SELECTION = 3,
73                 FULL = 4,
74                 INIT = 5
75         };
76         ///
77         InsetTabular(Buffer const &, int rows = 1, int columns = 1);
78         ///
79         InsetTabular(InsetTabular const &, Buffer const &, bool same_id = false);
80         ///
81         ~InsetTabular();
82         ///
83         Inset * clone(Buffer const &, bool same_id = false) const;
84         ///
85         void read(Buffer const *, LyXLex &);
86         ///
87         void write(Buffer const *, std::ostream &) const;
88         ///
89         int ascent(BufferView *, LyXFont const &) const;
90         ///
91         int descent(BufferView *, LyXFont const &) const;
92         ///
93         int width(BufferView *, LyXFont const & f) const;
94         ///
95         void draw(BufferView *, const LyXFont &, int , float &, bool) const;
96         ///
97         void update(BufferView *, LyXFont const &, bool = false);
98         ///
99         string const editMessage() const;
100         ///
101         void edit(BufferView *, int x, int y, mouse_button::state);
102         ///
103         void edit(BufferView * bv, bool front = true);
104         ///
105         bool doClearArea() const;
106         ///
107         void insetUnlock(BufferView *);
108         ///
109         void updateLocal(BufferView *, UpdateCodes, bool mark_dirty) const;
110         ///
111         bool lockInsetInInset(BufferView *, UpdatableInset *);
112         ///
113         bool unlockInsetInInset(BufferView *, UpdatableInset *,
114                                 bool lr = false);
115         ///
116         bool updateInsetInInset(BufferView *, Inset *);
117         ///
118         int insetInInsetY() const;
119         ///
120         UpdatableInset * getLockingInset() const;
121         ///
122         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
123         ///
124         bool insertInset(BufferView *, Inset *);
125         ///
126         bool insetAllowed(Inset::Code code) const;
127         ///
128         bool isTextInset() const { return true; }
129         /** returns true if, when outputing LaTeX, font changes should
130             be closed before generating this inset. This is needed for
131             insets that may contain several paragraphs */
132         bool noFontChange() const { return true; }
133         ///
134         bool display() const { return tabular->IsLongTabular(); }
135         ///
136         RESULT localDispatch(FuncRequest const &);
137         ///
138         int latex(Buffer const *, std::ostream &, bool, bool) const;
139         ///
140         int ascii(Buffer const *, std::ostream &, int linelen) const;
141         ///
142         int linuxdoc(Buffer const *, std::ostream &) const;
143         ///
144         int docbook(Buffer const *, std::ostream &, bool mixcont) const;
145         ///
146         void validate(LaTeXFeatures & features) const;
147         ///
148         Inset::Code lyxCode() const { return Inset::TABULAR_CODE; }
149         ///
150         void getCursorPos(BufferView *, int & x, int & y) const;
151         ///
152         void toggleInsetCursor(BufferView *);
153         ///
154         bool tabularFeatures(BufferView * bv, string const & what);
155         ///
156         void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
157                              string const & val = string());
158         ///
159         int getActCell() const { return actcell; }
160         ///
161         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
162                      bool selectall = false);
163         ///
164         int getMaxWidth(BufferView *, UpdatableInset const *) const;
165         ///
166         Buffer * bufferOwner() const { return const_cast<Buffer *>(buffer); }
167         ///
168         LyXText * getLyXText(BufferView const *,
169                              bool const recursive = false) const;
170         ///
171         void deleteLyXText(BufferView *, bool recursive = true) const;
172         ///
173         void resizeLyXText(BufferView *, bool force = false) const;
174         ///
175         void openLayoutDialog(BufferView *) const;
176         ///
177         bool showInsetDialog(BufferView *) const;
178         ///
179         FuncStatus getStatus(string const & argument) const;
180         ///
181         std::vector<string> const getLabelList() const;
182         ///
183         void nodraw(bool b) const {
184                 UpdatableInset::nodraw(b);
185         }
186         bool nodraw() const;
187         ///
188         int scroll(bool recursive=true) const;
189         ///
190         void scroll(BufferView *bv, float sx) const {
191                 UpdatableInset::scroll(bv, sx);
192         }
193         ///
194         void scroll(BufferView *bv, int offset) const {
195                 UpdatableInset::scroll(bv, offset);
196         }
197         ///
198         Inset * getInsetFromID(int id) const;
199         ///
200         Paragraph * firstParagraph() const;
201         ///
202         Paragraph * getFirstParagraph(int) const;
203         ///
204         LyXCursor const & cursor(BufferView *) const;
205         ///
206         bool allowSpellcheck() const { return true; }
207         ///
208         WordLangTuple const
209         selectNextWordToSpellcheck(BufferView *, float & value) const;
210         ///
211         void selectSelectedWord(BufferView *);
212         ///
213         void toggleSelection(BufferView *, bool kill_selection);
214
215         void markErased();
216
217         /// find next change
218         bool nextChange(BufferView *, lyx::pos_type & length);
219         ///
220         bool searchForward(BufferView *, string const &,
221                            bool = true, bool = false);
222         bool searchBackward(BufferView *, string const &,
223                             bool = true, bool = false);
224
225         // this should return true if we have a "normal" cell, otherwise true.
226         // "normal" means without width set!
227         bool forceDefaultParagraphs(Inset const * in) const;
228
229         ///
230         void addPreview(grfx::PreviewLoader &) const;
231
232         //
233         // Public structures and variables
234         ///
235         boost::scoped_ptr<LyXTabular> tabular;
236
237         /// are some cells selected ?
238         bool hasSelection() const {
239                 return has_selection;
240         }
241
242         ///
243         virtual BufferView * view() const;
244 private:
245         ///
246         void lfunMousePress(FuncRequest const &);
247         ///
248         // the bool return is used to see if we opened a dialog so that we can
249         // check this from an outer inset and open the dialog of the outer inset
250         // if that one has one!
251         ///
252         bool lfunMouseRelease(FuncRequest const &);
253         ///
254         void lfunMouseMotion(FuncRequest const &);
255         ///
256         bool calculate_dimensions_of_cells(BufferView *, LyXFont const &,
257                                            bool = false) const;
258         ///
259         void drawCellLines(Painter &, int x, int baseline,
260                            int row, int cell) const;
261         ///
262         void drawCellSelection(Painter &, int x, int baseline,
263                                int row, int column, int cell) const;
264         ///
265         void showInsetCursor(BufferView *, bool show=true);
266         ///
267         void hideInsetCursor(BufferView *);
268         ///
269         void fitInsetCursor(BufferView *) const;
270         ///
271         void setPos(BufferView *, int x, int y) const;
272         ///
273         RESULT moveRight(BufferView *, bool lock = true);
274         ///
275         RESULT moveLeft(BufferView *, bool lock = true);
276         ///
277         RESULT moveUp(BufferView *, bool lock = true);
278         ///
279         RESULT moveDown(BufferView *, bool lock = true);
280         ///
281         bool moveNextCell(BufferView *, bool lock = false);
282         ///
283         bool movePrevCell(BufferView *, bool lock = false);
284         ///
285         int getCellXPos(int cell) const;
286         ///
287         void resetPos(BufferView *) const;
288         ///
289         void removeTabularRow();
290         ///
291         void clearSelection() const {
292                 sel_cell_start = sel_cell_end = 0;
293                 has_selection = false;
294         }
295         void setSelection(int start, int end) const {
296                 sel_cell_start = start;
297                 sel_cell_end = end;
298                 has_selection = true;
299         }
300         ///
301         bool activateCellInset(BufferView *, int x = 0, int y = 0,
302                                mouse_button::state button = mouse_button::none,
303                                bool behind = false);
304         ///
305         bool activateCellInsetAbs(BufferView *, int x = 0, int y = 0,
306                                   mouse_button::state button = mouse_button::none);
307         ///
308         bool insetHit(BufferView * bv, int x, int y) const;
309         ///
310         int getMaxWidthOfCell(BufferView * bv, int cell) const;
311         ///
312         bool hasPasteBuffer() const;
313         ///
314         bool copySelection(BufferView *);
315         ///
316         bool pasteSelection(BufferView *);
317         ///
318         bool cutSelection(BufferParams const & bp);
319         ///
320         bool isRightToLeft(BufferView *);
321         ///
322         void getSelection(int & scol, int & ecol,
323                           int & srow, int & erow) const;
324         ///
325         WordLangTuple selectNextWordInt(BufferView *, float & value) const;
326         ///
327         bool insertAsciiString(BufferView *, string const & buf, bool usePaste);
328
329         //
330         // Private structures and variables
331         ///
332         InsetText * the_locking_inset;
333         ///
334         InsetText * old_locking_inset;
335         ///
336         Buffer const * buffer;
337         ///
338         mutable LyXCursor cursor_;
339         ///
340         mutable unsigned int inset_x;
341         ///
342         mutable unsigned int inset_y;
343         /// true if a set of cells are selected
344         mutable bool has_selection;
345         /// the starting cell selection nr
346         mutable int sel_cell_start;
347         /// the ending cell selection nr
348         mutable int sel_cell_end;
349         ///
350         mutable int actcell;
351         ///
352         mutable int oldcell;
353         ///
354         mutable int actcol;
355         ///
356         mutable int actrow;
357         ///
358         mutable int first_visible_cell;
359         ///
360         bool no_selection;
361         ///
362         mutable bool locked;
363         ///
364         mutable UpdateCodes need_update;
365         ///
366         bool in_update;
367         ///
368         mutable int in_reset_pos;
369 };
370
371
372 #include "mailinset.h"
373
374
375 class InsetTabularMailer : public MailInset {
376 public:
377         ///
378         InsetTabularMailer(InsetTabular & inset);
379         ///
380         virtual InsetBase & inset() const { return inset_; }
381         ///
382         virtual string const & name() const { return name_; }
383         ///
384         virtual string const inset2string() const;
385         /// Returns the active cell if successful, else -1.
386         static int string2params(string const &, InsetTabular &);
387         ///
388         static string const params2string(InsetTabular const &);
389 private:
390         ///
391         static string const name_;
392         ///
393         InsetTabular & inset_;
394 };
395
396 string const featureAsString(LyXTabular::Feature feature);
397
398 #endif