]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
Added using directive.
[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
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 &);
81         ///
82         ~InsetTabular();
83         ///
84         Inset * clone(Buffer const &) 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, unsigned int);
103         ///
104         bool doClearArea() const;
105         ///
106         void insetUnlock(BufferView *);
107         ///
108         void updateLocal(BufferView *, UpdateCodes, bool mark_dirty) const;
109         ///
110         bool lockInsetInInset(BufferView *, UpdatableInset *);
111         ///
112         bool unlockInsetInInset(BufferView *, UpdatableInset *,
113                                 bool lr = false);
114         ///
115         bool updateInsetInInset(BufferView *, Inset *);
116         ///
117         unsigned int insetInInsetY();
118         ///
119         UpdatableInset * getLockingInset();
120         ///
121         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
122         ///
123         bool insertInset(BufferView *, Inset *);
124         ///
125         bool isTextInset() const { return true; }
126         ///
127         bool display() const { return tabular->IsLongTabular(); }
128         ///
129         void insetButtonRelease(BufferView *, int, int, int);
130         ///
131         void insetButtonPress(BufferView *, int, int, int);
132         ///
133         void insetMotionNotify(BufferView *, int, int, int);
134         ///
135         void insetKeyPress(XKeyEvent *);
136         ///
137         UpdatableInset::RESULT localDispatch(BufferView *, kb_action,
138                                              string const &);
139         ///
140         int latex(Buffer const *, std::ostream &, bool, bool) const;
141         ///
142         int ascii(Buffer const *, std::ostream &, int linelen) const;
143         ///
144         int linuxdoc(Buffer const *, std::ostream &) const;
145         ///
146         int docBook(Buffer const *, std::ostream &) const;
147         ///
148         void validate(LaTeXFeatures & features) const;
149         ///
150         Inset::Code lyxCode() const { return Inset::TABULAR_CODE; }
151         ///
152         void getCursorPos(BufferView *, int & x, int & y) const;
153         ///
154         void toggleInsetCursor(BufferView *);
155         ///
156         bool tabularFeatures(BufferView * bv, string const & what);
157         ///
158         void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
159                              string const & val = string());
160         ///
161         int getActCell() const { return actcell; }
162         ///
163         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
164                      bool selectall = false);
165         ///
166         int getMaxWidth(BufferView *, UpdatableInset const *) const;
167         ///
168         Buffer * bufferOwner() const { return const_cast<Buffer *>(buffer); }
169         ///
170         LyXText * getLyXText(BufferView const *,
171                              bool const recursive = false) const;
172         ///
173         void deleteLyXText(BufferView *, bool recursive = true) const;
174         ///
175         void resizeLyXText(BufferView *, bool force = false) const;
176         ///
177         void openLayoutDialog(BufferView *) const;
178         ///
179         bool showInsetDialog(BufferView *) const;
180         ///
181         func_status::value_type getStatus(string const & argument) const;
182         ///
183         std::vector<string> const getLabelList() const;
184         ///
185         void nodraw(bool b) {
186                 UpdatableInset::nodraw(b);
187         }
188         bool nodraw() const;
189         ///
190         int scroll(bool recursive=true) const;
191         ///
192         void scroll(BufferView *bv, float sx) const {
193                 UpdatableInset::scroll(bv, sx);
194         }
195         ///
196         void scroll(BufferView *bv, int offset) const {
197                 UpdatableInset::scroll(bv, offset);
198         }
199
200         //
201         // Public structures and variables
202         ///
203         boost::scoped_ptr<LyXTabular> tabular;
204         ///
205         SigC::Signal0<void> hideDialog;
206
207 private:
208         ///
209         bool calculate_dimensions_of_cells(BufferView *, LyXFont const &,
210                                            bool = false) const;
211         ///
212         void drawCellLines(Painter &, int x, int baseline,
213                            int row, int cell) const;
214         ///
215         void drawCellSelection(Painter &, int x, int baseline,
216                                int row, int column, int cell) const;
217         ///
218         void showInsetCursor(BufferView *, bool show=true);
219         ///
220         void hideInsetCursor(BufferView *);
221         ///
222         void setPos(BufferView *, int x, int y) const;
223         ///
224         UpdatableInset::RESULT moveRight(BufferView *, bool lock = true);
225         ///
226         UpdatableInset::RESULT moveLeft(BufferView *, bool lock = true);
227         ///
228         UpdatableInset::RESULT moveUp(BufferView *, bool lock = true);
229         ///
230         UpdatableInset::RESULT moveDown(BufferView *, bool lock = true);
231         ///
232         bool moveNextCell(BufferView *, bool lock = false);
233         ///
234         bool movePrevCell(BufferView *, bool lock = false);
235         /// Delete what?
236         bool Delete();
237         ///
238         int getCellXPos(int cell) const;
239         ///
240         void resetPos(BufferView *) const;
241         ///
242         void removeTabularRow();
243         ///
244         bool hasSelection() const {
245                 return sel_cell_start != sel_cell_end;
246         }
247         ///
248         void clearSelection() const {
249         sel_cell_start = sel_cell_end = 0;
250         }
251         ///
252         bool activateCellInset(BufferView *, int x = 0, int y = 0,
253                                int button = 0,
254                                bool behind = false);
255         ///
256         bool activateCellInsetAbs(BufferView *, int x = 0, int y = 0,
257                                   int button = 0);
258         ///
259         bool insetHit(BufferView * bv, int x, int y) const;
260         ///
261         int getMaxWidthOfCell(BufferView * bv, int cell) const;
262         ///
263         bool hasPasteBuffer() const;
264         ///
265         bool copySelection(BufferView *);
266         ///
267         bool pasteSelection(BufferView *);
268         ///
269         bool cutSelection();
270         ///
271         bool isRightToLeft(BufferView *);
272         ///
273         void getSelection(int & scol, int & ecol, int & srow, int & erow) const;
274
275         //
276         // Private structures and variables
277         ///
278         InsetText * the_locking_inset;
279         ///
280         InsetText * old_locking_inset;
281         ///
282         Buffer const * buffer;
283         ///
284         mutable LyXCursor cursor;
285         ///
286         mutable unsigned int inset_x;
287         ///
288         mutable unsigned int inset_y;
289         ///
290         mutable int sel_cell_start;
291         ///
292         mutable int sel_cell_end;
293         ///
294         mutable int actcell;
295         ///
296         mutable int oldcell;
297         ///
298         mutable int actcol;
299         ///
300         mutable int actrow;
301         ///
302         mutable int first_visible_cell;
303         ///
304         bool no_selection;
305         ///
306         mutable bool locked;
307         ///
308         mutable UpdateCodes need_update;
309 };
310 #endif