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