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