]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
Minor code shuffle.
[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         bool doClearArea() const;
106         ///
107         void insetUnlock(BufferView *);
108         ///
109         void updateLocal(BufferView *, UpdateCodes, bool mark_dirty) const;
110         ///
111         bool lockInsetInInset(BufferView *, UpdatableInset *);
112         ///
113         bool unlockInsetInInset(BufferView *, UpdatableInset *,
114                                 bool lr = false);
115         ///
116         bool updateInsetInInset(BufferView *, Inset *);
117         ///
118         unsigned int insetInInsetY();
119         ///
120         UpdatableInset * getLockingInset() const;
121         ///
122         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
123         ///
124         bool insertInset(BufferView *, Inset *);
125         ///
126         bool insertInsetAllowed(Inset *) const {
127                 return the_locking_inset != 0;
128         }
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) {
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         LyXCursor const & cursor(BufferView *) const;
212
213         //
214         // Public structures and variables
215         ///
216         boost::scoped_ptr<LyXTabular> tabular;
217         ///
218         SigC::Signal0<void> hideDialog;
219
220 private:
221         ///
222         bool calculate_dimensions_of_cells(BufferView *, LyXFont const &,
223                                            bool = false) const;
224         ///
225         void drawCellLines(Painter &, int x, int baseline,
226                            int row, int cell) const;
227         ///
228         void drawCellSelection(Painter &, int x, int baseline,
229                                int row, int column, int cell) const;
230         ///
231         void showInsetCursor(BufferView *, bool show=true);
232         ///
233         void hideInsetCursor(BufferView *);
234         ///
235         void setPos(BufferView *, int x, int y) const;
236         ///
237         UpdatableInset::RESULT moveRight(BufferView *, bool lock = true);
238         ///
239         UpdatableInset::RESULT moveLeft(BufferView *, bool lock = true);
240         ///
241         UpdatableInset::RESULT moveUp(BufferView *, bool lock = true);
242         ///
243         UpdatableInset::RESULT moveDown(BufferView *, bool lock = true);
244         ///
245         bool moveNextCell(BufferView *, bool lock = false);
246         ///
247         bool movePrevCell(BufferView *, bool lock = false);
248         /// Delete what?
249         bool Delete();
250         ///
251         int getCellXPos(int cell) const;
252         ///
253         void resetPos(BufferView *) const;
254         ///
255         void removeTabularRow();
256         ///
257         bool hasSelection() const {
258                 return sel_cell_start != sel_cell_end;
259         }
260         ///
261         void clearSelection() const {
262         sel_cell_start = sel_cell_end = 0;
263         }
264         ///
265         bool activateCellInset(BufferView *, int x = 0, int y = 0,
266                                int button = 0,
267                                bool behind = false);
268         ///
269         bool activateCellInsetAbs(BufferView *, int x = 0, int y = 0,
270                                   int button = 0);
271         ///
272         bool insetHit(BufferView * bv, int x, int y) const;
273         ///
274         int getMaxWidthOfCell(BufferView * bv, int cell) const;
275         ///
276         bool hasPasteBuffer() const;
277         ///
278         bool copySelection(BufferView *);
279         ///
280         bool pasteSelection(BufferView *);
281         ///
282         bool cutSelection();
283         ///
284         bool isRightToLeft(BufferView *);
285         ///
286         void getSelection(int & scol, int & ecol, int & srow, int & erow) const;
287
288         //
289         // Private structures and variables
290         ///
291         InsetText * the_locking_inset;
292         ///
293         InsetText * old_locking_inset;
294         ///
295         Buffer const * buffer;
296         ///
297         mutable LyXCursor cursor_;
298         ///
299         mutable unsigned int inset_x;
300         ///
301         mutable unsigned int inset_y;
302         ///
303         mutable int sel_cell_start;
304         ///
305         mutable int sel_cell_end;
306         ///
307         mutable int actcell;
308         ///
309         mutable int oldcell;
310         ///
311         mutable int actcol;
312         ///
313         mutable int actrow;
314         ///
315         mutable int first_visible_cell;
316         ///
317         bool no_selection;
318         ///
319         mutable bool locked;
320         ///
321         mutable UpdateCodes need_update;
322 };
323 #endif