]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
simplificatons
[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) const {
129                 return the_locking_inset != 0;
130         }
131         ///
132         bool isTextInset() const { return true; }
133         ///
134         bool display() const { return tabular->IsLongTabular(); }
135         ///
136         void insetButtonRelease(BufferView *, int, int, int);
137         ///
138         void insetButtonPress(BufferView *, int, int, int);
139         ///
140         void insetMotionNotify(BufferView *, int, int, int);
141         ///
142         void insetKeyPress(XKeyEvent *);
143         ///
144         UpdatableInset::RESULT localDispatch(BufferView *, kb_action,
145                                              string 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 &) 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         func_status::value_type getStatus(string const & argument) const;
189         ///
190         std::vector<string> const getLabelList() const;
191         ///
192         void nodraw(bool b) {
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         LyXCursor const & cursor(BufferView *) const;
214         ///
215         string const selectNextWord(BufferView *, float & value) const;
216         void selectSelectedWord(BufferView *);
217         void toggleSelection(BufferView *, bool kill_selection);
218         ///
219         bool searchForward(BufferView *, string const &,
220                            bool const & = true, bool const & = false);
221         bool searchBackward(BufferView *, string const &,
222                             bool const & = true, bool const & = false);
223
224         //
225         // Public structures and variables
226         ///
227         boost::scoped_ptr<LyXTabular> tabular;
228         ///
229         SigC::Signal0<void> hideDialog;
230
231 private:
232         ///
233         bool calculate_dimensions_of_cells(BufferView *, LyXFont const &,
234                                            bool = false) const;
235         ///
236         void drawCellLines(Painter &, int x, int baseline,
237                            int row, int cell) const;
238         ///
239         void drawCellSelection(Painter &, int x, int baseline,
240                                int row, int column, int cell) const;
241         ///
242         void showInsetCursor(BufferView *, bool show=true);
243         ///
244         void hideInsetCursor(BufferView *);
245         ///
246         void setPos(BufferView *, int x, int y) const;
247         ///
248         UpdatableInset::RESULT moveRight(BufferView *, bool lock = true);
249         ///
250         UpdatableInset::RESULT moveLeft(BufferView *, bool lock = true);
251         ///
252         UpdatableInset::RESULT moveUp(BufferView *, bool lock = true);
253         ///
254         UpdatableInset::RESULT moveDown(BufferView *, bool lock = true);
255         ///
256         bool moveNextCell(BufferView *, bool lock = false);
257         ///
258         bool movePrevCell(BufferView *, bool lock = false);
259         ///
260         bool deletable();
261         ///
262         int getCellXPos(int cell) const;
263         ///
264         void resetPos(BufferView *) const;
265         ///
266         void removeTabularRow();
267         ///
268         bool hasSelection() const {
269                 return sel_cell_start != sel_cell_end;
270         }
271         ///
272         void clearSelection() const {
273         sel_cell_start = sel_cell_end = 0;
274         }
275         ///
276         bool activateCellInset(BufferView *, int x = 0, int y = 0,
277                                int button = 0,
278                                bool behind = false);
279         ///
280         bool activateCellInsetAbs(BufferView *, int x = 0, int y = 0,
281                                   int button = 0);
282         ///
283         bool insetHit(BufferView * bv, int x, int y) const;
284         ///
285         int getMaxWidthOfCell(BufferView * bv, int cell) const;
286         ///
287         bool hasPasteBuffer() const;
288         ///
289         bool copySelection(BufferView *);
290         ///
291         bool pasteSelection(BufferView *);
292         ///
293         bool cutSelection();
294         ///
295         bool isRightToLeft(BufferView *);
296         ///
297         void getSelection(int & scol, int & ecol,
298                           int & srow, int & erow) const;
299         ///
300         string selectNextWordInt(BufferView *, float & value) const;
301
302         //
303         // Private structures and variables
304         ///
305         InsetText * the_locking_inset;
306         ///
307         InsetText * old_locking_inset;
308         ///
309         Buffer const * buffer;
310         ///
311         mutable LyXCursor cursor_;
312         ///
313         mutable unsigned int inset_x;
314         ///
315         mutable unsigned int inset_y;
316         ///
317         mutable int sel_cell_start;
318         ///
319         mutable int sel_cell_end;
320         ///
321         mutable int actcell;
322         ///
323         mutable int oldcell;
324         ///
325         mutable int actcol;
326         ///
327         mutable int actrow;
328         ///
329         mutable int first_visible_cell;
330         ///
331         bool no_selection;
332         ///
333         mutable bool locked;
334         ///
335         mutable UpdateCodes need_update;
336 };
337 #endif