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