]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
the ascent/descent/width -> dimensions() change
[lyx.git] / src / insets / insettabular.h
1 // -*- C++ -*-
2 /**
3  * \file insettabular.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Jürgen Vigna
8  *
9  * Full author contact details are available in file CREDITS
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 "inset.h"
49 #include "tabular.h"
50 #include "LString.h"
51 #include "lyxcursor.h"
52 #include "FuncStatus.h"
53 #include "frontends/mouse_state.h"
54
55 #include <boost/scoped_ptr.hpp>
56 #include <boost/weak_ptr.hpp>
57
58 class LyXLex;
59 class Painter;
60 class BufferView;
61 class Buffer;
62 class BufferParams;
63 class Paragraph;
64
65 class InsetTabular : public UpdatableInset {
66 public:
67         ///
68         enum UpdateCodes {
69                 NONE = 0,
70                 CURSOR = 1,
71                 CELL = 2,
72                 SELECTION = 3,
73                 FULL = 4,
74                 INIT = 5
75         };
76         ///
77         InsetTabular(Buffer const &, int rows = 1, int columns = 1);
78         ///
79         InsetTabular(InsetTabular const &, Buffer const &, bool same_id = false);
80         ///
81         ~InsetTabular();
82         ///
83         Inset * clone(Buffer const &, bool same_id = false) const;
84         ///
85         void read(Buffer const *, LyXLex &);
86         ///
87         void write(Buffer const *, std::ostream &) const;
88         ///
89         void dimension(BufferView *, LyXFont const &, Dimension &) const;
90         ///
91         void draw(BufferView *, const LyXFont &, int , float &) const;
92         ///
93         void update(BufferView *, bool = false);
94         ///
95         string const editMessage() const;
96         //
97         void insetUnlock(BufferView *);
98         ///
99         void updateLocal(BufferView *, UpdateCodes) const;
100         ///
101         bool lockInsetInInset(BufferView *, UpdatableInset *);
102         ///
103         bool unlockInsetInInset(BufferView *, UpdatableInset *,
104                                 bool lr = false);
105         ///
106         bool updateInsetInInset(BufferView *, Inset *);
107         ///
108         int insetInInsetY() const;
109         ///
110         UpdatableInset * getLockingInset() const;
111         ///
112         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
113         ///
114         bool insertInset(BufferView *, Inset *);
115         ///
116         bool insetAllowed(Inset::Code code) const;
117         ///
118         bool isTextInset() const { return true; }
119         /** returns true if, when outputing LaTeX, font changes should
120             be closed before generating this inset. This is needed for
121             insets that may contain several paragraphs */
122         bool noFontChange() const { return true; }
123         ///
124         bool display() const { return tabular->IsLongTabular(); }
125         ///
126         RESULT localDispatch(FuncRequest const &);
127         ///
128         int latex(Buffer const *, std::ostream &, bool, bool) const;
129         ///
130         int ascii(Buffer const *, std::ostream &, int linelen) const;
131         ///
132         int linuxdoc(Buffer const *, std::ostream &) const;
133         ///
134         int docbook(Buffer const *, std::ostream &, bool mixcont) const;
135         ///
136         void validate(LaTeXFeatures & features) const;
137         ///
138         Inset::Code lyxCode() const { return Inset::TABULAR_CODE; }
139         /// FIXME, document
140         void getCursorPos(BufferView *, int & x, int & y) const;
141         /// Get the absolute document x,y of the cursor
142         virtual void getCursor(BufferView &, int &, int &) const;
143         ///
144         bool tabularFeatures(BufferView * bv, string const & what);
145         ///
146         void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
147                              string const & val = string());
148         ///
149         int getActCell() const { return actcell; }
150         ///
151         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
152                      bool selectall = false);
153         ///
154         int getMaxWidth(BufferView *, UpdatableInset const *) const;
155         ///
156         Buffer * bufferOwner() const { return const_cast<Buffer *>(buffer); }
157         ///
158         LyXText * getLyXText(BufferView const *,
159                              bool const recursive = false) const;
160         ///
161         void deleteLyXText(BufferView *, bool recursive = true) const;
162         ///
163         void resizeLyXText(BufferView *, bool force = false) const;
164         ///
165         void openLayoutDialog(BufferView *) const;
166         ///
167         bool showInsetDialog(BufferView *) const;
168         ///
169         FuncStatus getStatus(string const & argument) const;
170         ///
171         std::vector<string> const getLabelList() const;
172         ///
173         void nodraw(bool b) const {
174                 UpdatableInset::nodraw(b);
175         }
176         bool nodraw() const;
177         ///
178         int scroll(bool recursive=true) const;
179         ///
180         void scroll(BufferView *bv, float sx) const {
181                 UpdatableInset::scroll(bv, sx);
182         }
183         ///
184         void scroll(BufferView *bv, int offset) const {
185                 UpdatableInset::scroll(bv, offset);
186         }
187         ///
188         Inset * getInsetFromID(int id) const;
189         ///
190         ParagraphList * getParagraphs(int) const;
191         ///
192         LyXCursor const & cursor(BufferView *) const;
193         ///
194         bool allowSpellcheck() const { return true; }
195         ///
196         WordLangTuple const
197         selectNextWordToSpellcheck(BufferView *, float & value) const;
198         ///
199         void selectSelectedWord(BufferView *);
200         ///
201         void toggleSelection(BufferView *, bool kill_selection);
202
203         void markErased();
204
205         /// find next change
206         bool nextChange(BufferView *, lyx::pos_type & length);
207         ///
208         bool searchForward(BufferView *, string const &,
209                            bool = true, bool = false);
210         bool searchBackward(BufferView *, string const &,
211                             bool = true, bool = false);
212
213         // this should return true if we have a "normal" cell, otherwise true.
214         // "normal" means without width set!
215         bool forceDefaultParagraphs(Inset const * in) const;
216
217         ///
218         void addPreview(grfx::PreviewLoader &) const;
219
220         //
221         // Public structures and variables
222         ///
223         boost::scoped_ptr<LyXTabular> tabular;
224
225         /// are some cells selected ?
226         bool hasSelection() const {
227                 return has_selection;
228         }
229
230         ///
231         virtual BufferView * view() const;
232 private:
233         ///
234         void lfunMousePress(FuncRequest const &);
235         ///
236         // the bool return is used to see if we opened a dialog so that we can
237         // check this from an outer inset and open the dialog of the outer inset
238         // if that one has one!
239         ///
240         bool lfunMouseRelease(FuncRequest const &);
241         ///
242         void lfunMouseMotion(FuncRequest const &);
243         ///
244         bool calculate_dimensions_of_cells(BufferView *, bool = false) const;
245         ///
246         void drawCellLines(Painter &, int x, int baseline,
247                            int row, int cell) const;
248         ///
249         void drawCellSelection(Painter &, int x, int baseline,
250                                int row, int column, int cell) const;
251         ///
252         void fitInsetCursor(BufferView *) const;
253         ///
254         void setPos(BufferView *, int x, int y) const;
255         ///
256         RESULT moveRight(BufferView *, bool lock = true);
257         ///
258         RESULT moveLeft(BufferView *, bool lock = true);
259         ///
260         RESULT moveUp(BufferView *, bool lock = true);
261         ///
262         RESULT moveDown(BufferView *, bool lock = true);
263         ///
264         bool moveNextCell(BufferView *, bool lock = false);
265         ///
266         bool movePrevCell(BufferView *, bool lock = false);
267         ///
268         int getCellXPos(int cell) const;
269         ///
270         void resetPos(BufferView *) const;
271         ///
272         void removeTabularRow();
273         ///
274         void clearSelection() const {
275                 sel_cell_start = sel_cell_end = 0;
276                 has_selection = false;
277         }
278         void setSelection(int start, int end) const {
279                 sel_cell_start = start;
280                 sel_cell_end = end;
281                 has_selection = true;
282         }
283         ///
284         bool activateCellInset(BufferView *, int x = 0, int y = 0,
285                                mouse_button::state button = mouse_button::none,
286                                bool behind = false);
287         ///
288         bool activateCellInsetAbs(BufferView *, int x = 0, int y = 0,
289                                   mouse_button::state button = mouse_button::none);
290         ///
291         bool insetHit(BufferView * bv, int x, int y) const;
292         ///
293         int getMaxWidthOfCell(BufferView * bv, int cell) const;
294         ///
295         bool hasPasteBuffer() const;
296         ///
297         bool copySelection(BufferView *);
298         ///
299         bool pasteSelection(BufferView *);
300         ///
301         bool cutSelection(BufferParams const & bp);
302         ///
303         bool isRightToLeft(BufferView *);
304         ///
305         void getSelection(int & scol, int & ecol,
306                           int & srow, int & erow) const;
307         ///
308         WordLangTuple selectNextWordInt(BufferView *, float & value) const;
309         ///
310         bool insertAsciiString(BufferView *, string const & buf, bool usePaste);
311
312         //
313         // Private structures and variables
314         ///
315         InsetText * the_locking_inset;
316         ///
317         InsetText * old_locking_inset;
318         ///
319         Buffer const * buffer;
320         ///
321         mutable LyXCursor cursor_;
322         ///
323         mutable unsigned int inset_x;
324         ///
325         mutable unsigned int inset_y;
326         /// true if a set of cells are selected
327         mutable bool has_selection;
328         /// the starting cell selection nr
329         mutable int sel_cell_start;
330         /// the ending cell selection nr
331         mutable int sel_cell_end;
332         ///
333         mutable int actcell;
334         ///
335         mutable int oldcell;
336         ///
337         mutable int actcol;
338         ///
339         mutable int actrow;
340         ///
341         mutable int first_visible_cell;
342         ///
343         bool no_selection;
344         ///
345         mutable bool locked;
346         ///
347         mutable UpdateCodes need_update;
348         ///
349         bool in_update;
350         ///
351         mutable int in_reset_pos;
352 };
353
354
355 #include "mailinset.h"
356
357
358 class InsetTabularMailer : public MailInset {
359 public:
360         ///
361         InsetTabularMailer(InsetTabular & inset);
362         ///
363         virtual InsetBase & inset() const { return inset_; }
364         ///
365         virtual string const & name() const { return name_; }
366         ///
367         virtual string const inset2string() const;
368         /// Returns the active cell if successful, else -1.
369         static int string2params(string const &, InsetTabular &);
370         ///
371         static string const params2string(InsetTabular const &);
372 private:
373         ///
374         static string const name_;
375         ///
376         InsetTabular & inset_;
377 };
378
379 string const featureAsString(LyXTabular::Feature feature);
380
381 #endif