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