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