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