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