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