]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
Reduce Michael's buglist.
[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 #include <sigc++/signal_system.h>
49 #include <boost/smart_ptr.hpp>
50
51 #ifdef __GNUG__
52 #pragma interface
53 #endif
54
55 #include "inset.h"
56 #include "tabular.h"
57 #include "LString.h"
58 #include "lyxcursor.h"
59 #include "func_status.h"
60
61 class LyXLex;
62 class Painter;
63 class BufferView;
64 class Buffer;
65 class Paragraph;
66
67 class InsetTabular : public UpdatableInset {
68 public:
69         ///
70         enum UpdateCodes {
71                 NONE = 0,
72                 CURSOR = 1,
73                 CELL = 2,
74                 SELECTION = 3,
75                 FULL = 4,
76                 INIT = 5
77         };
78         ///
79         InsetTabular(Buffer const &, int rows = 1, int columns = 1);
80         ///
81         InsetTabular(InsetTabular const &, Buffer const &, bool same_id = false);
82         ///
83         ~InsetTabular();
84         ///
85         Inset * clone(Buffer const &, bool same_id = false) const;
86         ///
87         void read(Buffer const *, LyXLex &);
88         ///
89         void write(Buffer const *, std::ostream &) const;
90         ///
91         int ascent(BufferView *, LyXFont const &) const;
92         ///
93         int descent(BufferView *, LyXFont const &) const;
94         ///
95         int width(BufferView *, LyXFont const & f) const;
96         ///
97         void draw(BufferView *, const LyXFont &, int , float &, bool) const;
98         ///
99         void update(BufferView *, LyXFont const &, bool = false);
100         ///
101         string const editMessage() const;
102         ///
103         void edit(BufferView *, int x, int y, unsigned int);
104         ///
105         void edit(BufferView * bv, bool front = true);
106         ///
107         bool doClearArea() const;
108         ///
109         void insetUnlock(BufferView *);
110         ///
111         void updateLocal(BufferView *, UpdateCodes, bool mark_dirty) const;
112         ///
113         bool lockInsetInInset(BufferView *, UpdatableInset *);
114         ///
115         bool unlockInsetInInset(BufferView *, UpdatableInset *,
116                                 bool lr = false);
117         ///
118         bool updateInsetInInset(BufferView *, Inset *);
119         ///
120         unsigned int insetInInsetY();
121         ///
122         UpdatableInset * getLockingInset() const;
123         ///
124         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
125         ///
126         bool insertInset(BufferView *, Inset *);
127         ///
128         bool insetAllowed(Inset::Code code) const;
129         ///
130         bool isTextInset() const { return true; }
131         ///
132         bool display() const { return tabular->IsLongTabular(); }
133         ///
134         void insetButtonRelease(BufferView *, int, int, int);
135         ///
136         void insetButtonPress(BufferView *, int, int, int);
137         ///
138         void insetMotionNotify(BufferView *, int, int, int);
139         ///
140         void insetKeyPress(XKeyEvent *);
141         ///
142         UpdatableInset::RESULT localDispatch(BufferView *, kb_action,
143                                              string const &);
144         ///
145         int latex(Buffer const *, std::ostream &, bool, bool) const;
146         ///
147         int ascii(Buffer const *, std::ostream &, int linelen) const;
148         ///
149         int linuxdoc(Buffer const *, std::ostream &) const;
150         ///
151         int docbook(Buffer const *, std::ostream &) const;
152         ///
153         void validate(LaTeXFeatures & features) const;
154         ///
155         Inset::Code lyxCode() const { return Inset::TABULAR_CODE; }
156         ///
157         void getCursorPos(BufferView *, int & x, int & y) const;
158         ///
159         void toggleInsetCursor(BufferView *);
160         ///
161         bool tabularFeatures(BufferView * bv, string const & what);
162         ///
163         void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
164                              string const & val = string());
165         ///
166         int getActCell() const { return actcell; }
167         ///
168         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
169                      bool selectall = false);
170         ///
171         int getMaxWidth(BufferView *, UpdatableInset const *) const;
172         ///
173         Buffer * bufferOwner() const { return const_cast<Buffer *>(buffer); }
174         ///
175         LyXText * getLyXText(BufferView const *,
176                              bool const recursive = false) const;
177         ///
178         void deleteLyXText(BufferView *, bool recursive = true) const;
179         ///
180         void resizeLyXText(BufferView *, bool force = false) const;
181         ///
182         void openLayoutDialog(BufferView *) const;
183         ///
184         bool showInsetDialog(BufferView *) const;
185         ///
186         func_status::value_type getStatus(string const & argument) const;
187         ///
188         std::vector<string> const getLabelList() const;
189         ///
190         void nodraw(bool b) const {
191                 UpdatableInset::nodraw(b);
192         }
193         bool nodraw() const;
194         ///
195         int scroll(bool recursive=true) const;
196         ///
197         void scroll(BufferView *bv, float sx) const {
198                 UpdatableInset::scroll(bv, sx);
199         }
200         ///
201         void scroll(BufferView *bv, int offset) const {
202                 UpdatableInset::scroll(bv, offset);
203         }
204         ///
205         Paragraph * getParFromID(int id) const;
206         ///
207         Inset * getInsetFromID(int id) const;
208         ///
209         Paragraph * firstParagraph() const;
210         ///
211         Paragraph * getFirstParagraph(int) const;
212         ///
213         LyXCursor const & cursor(BufferView *) const;
214         ///
215         bool allowSpellcheck() { return true; }
216         string const selectNextWordToSpellcheck(BufferView *, float & value) const;
217         void selectSelectedWord(BufferView *);
218         void toggleSelection(BufferView *, bool kill_selection);
219         ///
220         bool searchForward(BufferView *, string const &,
221                            bool const & = true, bool const & = false);
222         bool searchBackward(BufferView *, string const &,
223                             bool const & = true, bool const & = false);
224
225         //
226         // Public structures and variables
227         ///
228         boost::scoped_ptr<LyXTabular> tabular;
229         ///
230         SigC::Signal0<void> hideDialog;
231
232 private:
233         ///
234         bool calculate_dimensions_of_cells(BufferView *, LyXFont const &,
235                                            bool = false) const;
236         ///
237         void drawCellLines(Painter &, int x, int baseline,
238                            int row, int cell) const;
239         ///
240         void drawCellSelection(Painter &, int x, int baseline,
241                                int row, int column, int cell) const;
242         ///
243         void showInsetCursor(BufferView *, bool show=true);
244         ///
245         void hideInsetCursor(BufferView *);
246         ///
247         void fitInsetCursor(BufferView *) const;
248         ///
249         void setPos(BufferView *, int x, int y) const;
250         ///
251         UpdatableInset::RESULT moveRight(BufferView *, bool lock = true);
252         ///
253         UpdatableInset::RESULT moveLeft(BufferView *, bool lock = true);
254         ///
255         UpdatableInset::RESULT moveUp(BufferView *, bool lock = true);
256         ///
257         UpdatableInset::RESULT moveDown(BufferView *, bool lock = true);
258         ///
259         bool moveNextCell(BufferView *, bool lock = false);
260         ///
261         bool movePrevCell(BufferView *, bool lock = false);
262         ///
263         bool deletable() const;
264         ///
265         int getCellXPos(int cell) const;
266         ///
267         void resetPos(BufferView *) const;
268         ///
269         void removeTabularRow();
270         ///
271         bool hasSelection() const {
272                 return sel_cell_start != sel_cell_end;
273         }
274         ///
275         void clearSelection() const {
276         sel_cell_start = sel_cell_end = 0;
277         }
278         ///
279         bool activateCellInset(BufferView *, int x = 0, int y = 0,
280                                int button = 0,
281                                bool behind = false);
282         ///
283         bool activateCellInsetAbs(BufferView *, int x = 0, int y = 0,
284                                   int button = 0);
285         ///
286         bool insetHit(BufferView * bv, int x, int y) const;
287         ///
288         int getMaxWidthOfCell(BufferView * bv, int cell) const;
289         ///
290         bool hasPasteBuffer() const;
291         ///
292         bool copySelection(BufferView *);
293         ///
294         bool pasteSelection(BufferView *);
295         ///
296         bool cutSelection();
297         ///
298         bool isRightToLeft(BufferView *);
299         ///
300         void getSelection(int & scol, int & ecol,
301                           int & srow, int & erow) const;
302         ///
303         string selectNextWordInt(BufferView *, float & value) const;
304
305         //
306         // Private structures and variables
307         ///
308         InsetText * the_locking_inset;
309         ///
310         InsetText * old_locking_inset;
311         ///
312         Buffer const * buffer;
313         ///
314         mutable LyXCursor cursor_;
315         ///
316         mutable unsigned int inset_x;
317         ///
318         mutable unsigned int inset_y;
319         ///
320         mutable int sel_cell_start;
321         ///
322         mutable int sel_cell_end;
323         ///
324         mutable int actcell;
325         ///
326         mutable int oldcell;
327         ///
328         mutable int actcol;
329         ///
330         mutable int actrow;
331         ///
332         mutable int first_visible_cell;
333         ///
334         bool no_selection;
335         ///
336         mutable bool locked;
337         ///
338         mutable UpdateCodes need_update;
339         ///
340         bool in_update;
341         ///
342         mutable bool in_reset_pos;
343 };
344 #endif