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