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