]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
The inset mailers' inset2string function now requires a Buffer const & arg.
[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         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 *, Inset *);
100         ///
101         int insetInInsetY() const;
102         ///
103         UpdatableInset * getLockingInset() const;
104         ///
105         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
106         ///
107         bool insertInset(BufferView *, Inset *);
108         ///
109         bool insetAllowed(Inset::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         Inset::Code lyxCode() const { return Inset::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         void nodraw(bool b) const {
164                 UpdatableInset::nodraw(b);
165         }
166         bool nodraw() const;
167         ///
168         int scroll(bool recursive=true) const;
169         ///
170         void scroll(BufferView *bv, float sx) const {
171                 UpdatableInset::scroll(bv, sx);
172         }
173         ///
174         void scroll(BufferView *bv, int offset) const {
175                 UpdatableInset::scroll(bv, offset);
176         }
177         ///
178         Inset * getInsetFromID(int id) const;
179         ///
180         ParagraphList * getParagraphs(int) const;
181         ///
182         LyXCursor const & cursor(BufferView *) const;
183         ///
184         bool allowSpellcheck() const { return true; }
185         ///
186         WordLangTuple const
187         selectNextWordToSpellcheck(BufferView *, float & value) const;
188         ///
189         void selectSelectedWord(BufferView *);
190         ///
191         void toggleSelection(BufferView *, bool kill_selection);
192
193         void markErased();
194
195         /// find next change
196         bool nextChange(BufferView *, lyx::pos_type & length);
197         ///
198         bool searchForward(BufferView *, string const &,
199                            bool = true, bool = false);
200         bool searchBackward(BufferView *, string const &,
201                             bool = true, bool = false);
202
203         // this should return true if we have a "normal" cell, otherwise true.
204         // "normal" means without width set!
205         bool forceDefaultParagraphs(Inset const * in) const;
206
207         ///
208         void addPreview(lyx::graphics::PreviewLoader &) const;
209
210         //
211         // Public structures and variables
212         ///
213         mutable LyXTabular tabular;
214
215         /// are some cells selected ?
216         bool hasSelection() const {
217                 return has_selection;
218         }
219
220         ///
221         virtual BufferView * view() const;
222         ///
223         Buffer const * buffer() const;
224
225         /// set the owning buffer
226         void buffer(Buffer * b);
227
228 private:
229         ///
230         void lfunMousePress(FuncRequest const &);
231         ///
232         // the bool return is used to see if we opened a dialog so that we can
233         // check this from an outer inset and open the dialog of the outer inset
234         // if that one has one!
235         ///
236         bool lfunMouseRelease(FuncRequest const &);
237         ///
238         void lfunMouseMotion(FuncRequest const &);
239         ///
240         void calculate_dimensions_of_cells(MetricsInfo & mi) const;
241         ///
242         void drawCellLines(Painter &, int x, int baseline,
243                            int row, int cell) const;
244         ///
245         void drawCellSelection(Painter &, int x, int baseline,
246                                int row, int column, int cell) const;
247         ///
248         void fitInsetCursor(BufferView *) const;
249         ///
250         void setPos(BufferView *, int x, int y) const;
251         ///
252         RESULT moveRight(BufferView *, bool lock = true);
253         ///
254         RESULT moveLeft(BufferView *, bool lock = true);
255         ///
256         RESULT moveUp(BufferView *, bool lock = true);
257         ///
258         RESULT moveDown(BufferView *, bool lock = true);
259         ///
260         bool moveNextCell(BufferView *, bool lock = false);
261         ///
262         bool movePrevCell(BufferView *, bool lock = false);
263         ///
264         int getCellXPos(int cell) const;
265         ///
266         void resetPos(BufferView *) const;
267         ///
268         void removeTabularRow();
269         ///
270         void clearSelection() const {
271                 sel_cell_start = sel_cell_end = 0;
272                 has_selection = false;
273         }
274         void setSelection(int start, int end) const {
275                 sel_cell_start = start;
276                 sel_cell_end = end;
277                 has_selection = true;
278         }
279         ///
280         bool activateCellInset(BufferView *, int x = 0, int y = 0,
281                                mouse_button::state button = mouse_button::none,
282                                bool behind = false);
283         ///
284         bool activateCellInsetAbs(BufferView *, int x = 0, int y = 0,
285                                   mouse_button::state button = mouse_button::none);
286         ///
287         bool insetHit(BufferView * bv, int x, int y) const;
288         ///
289         bool hasPasteBuffer() const;
290         ///
291         bool copySelection(BufferView *);
292         ///
293         bool pasteSelection(BufferView *);
294         ///
295         bool cutSelection(BufferParams const & bp);
296         ///
297         bool isRightToLeft(BufferView *);
298         ///
299         void getSelection(int & scol, int & ecol,
300                           int & srow, int & erow) const;
301         ///
302         WordLangTuple selectNextWordInt(BufferView *, float & value) const;
303         ///
304         bool insertAsciiString(BufferView *, string const & buf, bool usePaste);
305
306         //
307         // Private structures and variables
308         ///
309         InsetText * the_locking_inset;
310         ///
311         InsetText * old_locking_inset;
312         ///
313         Buffer const * buffer_;
314         ///
315         mutable int cursorx_;
316         ///
317         mutable int cursory_;
318         ///
319         mutable unsigned int inset_x;
320         ///
321         mutable unsigned int inset_y;
322         /// true if a set of cells are selected
323         mutable bool has_selection;
324         /// the starting cell selection nr
325         mutable int sel_cell_start;
326         /// the ending cell selection nr
327         mutable int sel_cell_end;
328         ///
329         mutable int actcell;
330         ///
331         mutable int oldcell;
332         ///
333         mutable int actcol;
334         ///
335         mutable int actrow;
336         ///
337         mutable int first_visible_cell;
338         ///
339         bool no_selection;
340         ///
341         mutable bool locked;
342         ///
343         mutable UpdateCodes need_update;
344         ///
345         mutable int in_reset_pos;
346 };
347
348
349 #include "mailinset.h"
350
351
352 class InsetTabularMailer : public MailInset {
353 public:
354         ///
355         InsetTabularMailer(InsetTabular const & inset);
356         ///
357         virtual InsetBase & inset() const { return inset_; }
358         ///
359         virtual string const & name() const { return name_; }
360         ///
361         virtual string const inset2string(Buffer const &) const;
362         /// Returns the active cell if successful, else -1.
363         static int string2params(string const &, InsetTabular &);
364         ///
365         static string const params2string(InsetTabular const &);
366 private:
367         ///
368         static string const name_;
369         ///
370         InsetTabular & inset_;
371 };
372
373 string const featureAsString(LyXTabular::Feature feature);
374
375 #endif