]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
fitCursor work
[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 updateLocal(BufferView *) const;
82         ///
83         int insetInInsetY() const;
84         ///
85         bool insertInset(BufferView *, InsetOld *);
86         ///
87         bool insetAllowed(InsetOld::Code code) const;
88         ///
89         bool isTextInset() const { return true; }
90         /** returns true if, when outputing LaTeX, font changes should
91             be closed before generating this inset. This is needed for
92             insets that may contain several paragraphs */
93         bool noFontChange() const { return true; }
94         ///
95         bool display() const { return tabular.isLongTabular(); }
96         ///
97         int latex(Buffer const &, std::ostream &,
98                   OutputParams const &) const;
99         ///
100         int plaintext(Buffer const &, std::ostream &,
101                   OutputParams const &) const;
102         ///
103         int linuxdoc(Buffer const &, std::ostream &,
104                      OutputParams const &) const;
105         ///
106         int docbook(Buffer const &, std::ostream &,
107                     OutputParams const &) const;
108         ///
109         void validate(LaTeXFeatures & features) const;
110         ///
111         InsetOld::Code lyxCode() const { return InsetOld::TABULAR_CODE; }
112         /// get the absolute screen x,y of the cursor
113         void getCursorPos(BufferView *, int & x, int & y) const;
114         ///
115         bool tabularFeatures(BufferView * bv, std::string const & what);
116         ///
117         void tabularFeatures(BufferView * bv, LyXTabular::Feature feature,
118                              std::string const & val = std::string());
119         ///
120         int getActCell() const { return actcell; }
121         ///
122         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
123                      bool selectall = false);
124         ///
125         void deleteLyXText(BufferView *) const;
126         ///
127         void openLayoutDialog(BufferView *) const;
128         ///
129         bool showInsetDialog(BufferView *) const;
130         ///
131         FuncStatus getStatus(std::string const & argument) const;
132         /// Appends \c list with all labels found within this inset.
133         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
134         ///
135         int scroll(bool recursive=true) const;
136         ///
137         void scroll(BufferView *bv, float sx) const {
138                 UpdatableInset::scroll(bv, sx);
139         }
140         ///
141         void scroll(BufferView *bv, int offset) const {
142                 UpdatableInset::scroll(bv, offset);
143         }
144         ///
145         ParagraphList * getParagraphs(int) const;
146         ///
147         int numParagraphs() const;
148         ///
149         LyXText * getText(int) const;
150
151         ///
152         void markErased();
153
154         // this should return true if we have a "normal" cell, otherwise true.
155         // "normal" means without width set!
156         bool forceDefaultParagraphs(InsetOld const * in) const;
157
158         ///
159         void addPreview(lyx::graphics::PreviewLoader &) const;
160
161         //
162         // Public structures and variables
163         ///
164         mutable LyXTabular tabular;
165
166         /// are some cells selected ?
167         bool hasSelection() const { return has_selection; }
168
169         ///
170         Buffer const & buffer() const;
171
172         /// set the owning buffer
173         void buffer(Buffer * buf);
174         /// lock cell with given index
175         void edit(BufferView * bv, bool);
176         ///
177         void edit(BufferView * bv, int, int);
178 protected:
179         ///
180         virtual
181         DispatchResult
182         priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
183 private:
184         ///
185         void lfunMousePress(FuncRequest const &);
186         ///
187         void lfunMouseRelease(FuncRequest const &);
188         ///
189         void lfunMouseMotion(FuncRequest const &);
190         ///
191         void calculate_dimensions_of_cells(MetricsInfo & mi) const;
192         ///
193         void drawCellLines(Painter &, int x, int baseline,
194                            int row, int cell) const;
195         ///
196         void drawCellSelection(Painter &, int x, int baseline,
197                                int row, int column, int cell) const;
198         ///
199         void setPos(BufferView *, int x, int y) const;
200         ///
201         DispatchResult moveRight(BufferView *, bool lock);
202         ///
203         DispatchResult moveLeft(BufferView *, bool lock);
204         ///
205         DispatchResult moveUp(BufferView *, bool lock);
206         ///
207         DispatchResult moveDown(BufferView *, bool lock);
208         ///
209         bool moveNextCell(BufferView *, bool lock = false);
210         ///
211         bool movePrevCell(BufferView *, bool lock = false);
212         ///
213         int getCellXPos(int cell) const;
214         ///
215         void resetPos(BufferView *) const;
216         ///
217         void removeTabularRow();
218         ///
219         void clearSelection() const {
220                 sel_cell_start = sel_cell_end = 0;
221                 has_selection = false;
222         }
223         void setSelection(int start, int end) const {
224                 sel_cell_start = start;
225                 sel_cell_end = end;
226                 has_selection = true;
227         }
228         ///
229         bool activateCellInset(BufferView *, int x = 0, int y = 0,
230                                bool behind = false);
231         ///
232         bool hasPasteBuffer() const;
233         ///
234         bool copySelection(BufferView *);
235         ///
236         bool pasteSelection(BufferView *);
237         ///
238         bool cutSelection(BufferParams const & bp);
239         ///
240         bool isRightToLeft(BufferView *);
241         ///
242         void getSelection(int & scol, int & ecol, int & srow, int & erow) const;
243         ///
244         bool insertAsciiString(BufferView *, std::string const & buf, bool usePaste);
245
246         //
247         // Private structures and variables
248         ///
249         InsetText * the_locking_inset;
250         ///
251         Buffer const * buffer_;
252         ///
253         mutable int cursorx_;
254         ///
255         mutable int cursory_;
256         /// true if a set of cells are selected
257         mutable bool has_selection;
258         /// the starting cell selection nr
259         mutable int sel_cell_start;
260         /// the ending cell selection nr
261         mutable int sel_cell_end;
262         ///
263         mutable int actcell;
264         ///
265         mutable int actcol;
266         ///
267         mutable int actrow;
268         ///
269         mutable int first_visible_cell;
270         ///
271         mutable int in_reset_pos;
272 };
273
274
275 #include "mailinset.h"
276
277
278 class InsetTabularMailer : public MailInset {
279 public:
280         ///
281         InsetTabularMailer(InsetTabular const & inset);
282         ///
283         virtual InsetBase & inset() const { return inset_; }
284         ///
285         virtual std::string const & name() const { return name_; }
286         ///
287         virtual std::string const inset2string(Buffer const &) const;
288         /// Returns the active cell if successful, else -1.
289         static int string2params(std::string const &, InsetTabular &);
290         ///
291         static std::string const params2string(InsetTabular const &);
292 private:
293         ///
294         static std::string const name_;
295         ///
296         InsetTabular & inset_;
297 };
298
299 std::string const featureAsString(LyXTabular::Feature feature);
300
301 #endif