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