]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
use more specific smart_ptr headers
[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 <sigc++/signal_system.h>
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, unsigned int);
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         ///
133         bool display() const { return tabular->IsLongTabular(); }
134         ///
135         bool insetButtonRelease(BufferView *, int, int, int);
136         ///
137         void insetButtonPress(BufferView *, int, int, int);
138         ///
139         void insetMotionNotify(BufferView *, int, int, int);
140         ///
141         void insetKeyPress(XKeyEvent *);
142         ///
143         UpdatableInset::RESULT localDispatch(BufferView *, kb_action,
144                                              string const &);
145         ///
146         int latex(Buffer const *, std::ostream &, bool, bool) const;
147         ///
148         int ascii(Buffer const *, std::ostream &, int linelen) const;
149         ///
150         int linuxdoc(Buffer const *, std::ostream &) const;
151         ///
152         int docbook(Buffer const *, std::ostream &) const;
153         ///
154         void validate(LaTeXFeatures & features) const;
155         ///
156         Inset::Code lyxCode() const { return Inset::TABULAR_CODE; }
157         ///
158         void getCursorPos(BufferView *, int & x, int & y) const;
159         ///
160         void toggleInsetCursor(BufferView *);
161         ///
162         bool tabularFeatures(BufferView * bv, string const & what);
163         ///
164         void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
165                              string const & val = string());
166         ///
167         int getActCell() const { return actcell; }
168         ///
169         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
170                      bool selectall = false);
171         ///
172         int getMaxWidth(BufferView *, UpdatableInset const *) const;
173         ///
174         Buffer * bufferOwner() const { return const_cast<Buffer *>(buffer); }
175         ///
176         LyXText * getLyXText(BufferView const *,
177                              bool const recursive = false) const;
178         ///
179         void deleteLyXText(BufferView *, bool recursive = true) const;
180         ///
181         void resizeLyXText(BufferView *, bool force = false) const;
182         ///
183         void openLayoutDialog(BufferView *) const;
184         ///
185         bool showInsetDialog(BufferView *) const;
186         ///
187         FuncStatus getStatus(string const & argument) const;
188         ///
189         std::vector<string> const getLabelList() const;
190         ///
191         void nodraw(bool b) const {
192                 UpdatableInset::nodraw(b);
193         }
194         bool nodraw() const;
195         ///
196         int scroll(bool recursive=true) const;
197         ///
198         void scroll(BufferView *bv, float sx) const {
199                 UpdatableInset::scroll(bv, sx);
200         }
201         ///
202         void scroll(BufferView *bv, int offset) const {
203                 UpdatableInset::scroll(bv, offset);
204         }
205         ///
206         Paragraph * getParFromID(int id) const;
207         ///
208         Inset * getInsetFromID(int id) const;
209         ///
210         Paragraph * firstParagraph() const;
211         ///
212         Paragraph * getFirstParagraph(int) const;
213         ///
214         LyXCursor const & cursor(BufferView *) const;
215         ///
216         bool allowSpellcheck() { return true; }
217         string const selectNextWordToSpellcheck(BufferView *, float & value) const;
218         void selectSelectedWord(BufferView *);
219         void toggleSelection(BufferView *, bool kill_selection);
220         ///
221         bool searchForward(BufferView *, string const &,
222                            bool = true, bool = false);
223         bool searchBackward(BufferView *, string const &,
224                             bool = true, bool = false);
225
226         // this should return true if we have a "normal" cell, otherwise true.
227         // "normal" means without width set!
228         bool forceDefaultParagraphs(Inset const * in) const;
229
230         //
231         // Public structures and variables
232         ///
233         boost::scoped_ptr<LyXTabular> tabular;
234         ///
235         SigC::Signal0<void> hideDialog;
236
237 private:
238         ///
239         bool calculate_dimensions_of_cells(BufferView *, LyXFont const &,
240                                            bool = false) const;
241         ///
242         void drawCellLines(Painter &, int x, int baseline,
243                            int row, int cell) const;
244         ///
245         void drawCellSelection(Painter &, int x, int baseline,
246                                int row, int column, int cell) const;
247         ///
248         void showInsetCursor(BufferView *, bool show=true);
249         ///
250         void hideInsetCursor(BufferView *);
251         ///
252         void fitInsetCursor(BufferView *) const;
253         ///
254         void setPos(BufferView *, int x, int y) const;
255         ///
256         UpdatableInset::RESULT moveRight(BufferView *, bool lock = true);
257         ///
258         UpdatableInset::RESULT moveLeft(BufferView *, bool lock = true);
259         ///
260         UpdatableInset::RESULT moveUp(BufferView *, bool lock = true);
261         ///
262         UpdatableInset::RESULT moveDown(BufferView *, bool lock = true);
263         ///
264         bool moveNextCell(BufferView *, bool lock = false);
265         ///
266         bool movePrevCell(BufferView *, bool lock = false);
267         ///
268         bool deletable() const;
269         ///
270         int getCellXPos(int cell) const;
271         ///
272         void resetPos(BufferView *) const;
273         ///
274         void removeTabularRow();
275         ///
276         bool hasSelection() const {
277                 return has_selection;
278         }
279         ///
280         void clearSelection() const {
281                 sel_cell_start = sel_cell_end = 0;
282                 has_selection = false;
283         }
284         void setSelection(int start, int end) const {
285                 sel_cell_start = start;
286                 sel_cell_end = end;
287                 has_selection = true;
288         }
289         ///
290         bool activateCellInset(BufferView *, int x = 0, int y = 0,
291                                int button = 0,
292                                bool behind = false);
293         ///
294         bool activateCellInsetAbs(BufferView *, int x = 0, int y = 0,
295                                   int button = 0);
296         ///
297         bool insetHit(BufferView * bv, int x, int y) const;
298         ///
299         int getMaxWidthOfCell(BufferView * bv, int cell) const;
300         ///
301         bool hasPasteBuffer() const;
302         ///
303         bool copySelection(BufferView *);
304         ///
305         bool pasteSelection(BufferView *);
306         ///
307         bool cutSelection();
308         ///
309         bool isRightToLeft(BufferView *);
310         ///
311         void getSelection(int & scol, int & ecol,
312                           int & srow, int & erow) const;
313         ///
314         string selectNextWordInt(BufferView *, float & value) const;
315         ///
316         bool insertAsciiString(BufferView *, string const & buf, bool usePaste);
317
318         //
319         // Private structures and variables
320         ///
321         InsetText * the_locking_inset;
322         ///
323         InsetText * old_locking_inset;
324         ///
325         Buffer const * buffer;
326         ///
327         mutable LyXCursor cursor_;
328         ///
329         mutable unsigned int inset_x;
330         ///
331         mutable unsigned int inset_y;
332         /// true if a set of cells are selected
333         mutable bool has_selection;
334         /// the starting cell selection nr
335         mutable int sel_cell_start;
336         /// the ending cell selection nr
337         mutable int sel_cell_end;
338         ///
339         mutable int actcell;
340         ///
341         mutable int oldcell;
342         ///
343         mutable int actcol;
344         ///
345         mutable int actrow;
346         ///
347         mutable int first_visible_cell;
348         ///
349         bool no_selection;
350         ///
351         mutable bool locked;
352         ///
353         mutable UpdateCodes need_update;
354         ///
355         bool in_update;
356         ///
357         mutable bool in_reset_pos;
358 };
359 #endif