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