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