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