]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
partial fix for cursor movement in tables
[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
12
13 // This is the rewrite of the tabular (table) support.
14
15 // Ideally the tabular support should do as the mathed and use
16 // LaTeX in the .lyx file too.
17
18 // Things to think of when designing the new tabular support:
19 // - color support (colortbl, color)
20 // - decimal alignment (dcloumn)
21 // - custom lines (hhline)
22 // - rotation
23 // - multicolumn
24 // - multirow
25 // - column styles
26
27 // This is what I have written about tabular support in the LyX3-Tasks file:
28 //
29 //  o rewrite of table code. Should probably be written as some
30 //          kind of an inset. At least get the code out of the kernel.
31 //                - colortbl  -multirow
32 //                - hhline    -multicolumn
33 //                - dcolumn
34 // o enhance longtable support
35
36 // Lgb
37
38 #ifndef INSETTABULAR_H
39 #define INSETTABULAR_H
40
41 #include "inset.h"
42 #include "tabular.h"
43
44 class FuncStatus;
45 class LyXLex;
46 class Painter;
47 class BufferView;
48 class Buffer;
49 class BufferParams;
50 class Paragraph;
51 class CursorSlice;
52
53
54 class InsetTabular : public UpdatableInset {
55 public:
56         ///
57         InsetTabular(Buffer const &, int rows = 1, int columns = 1);
58         ///
59         InsetTabular(InsetTabular const &);
60         ///
61         ~InsetTabular();
62         ///
63         virtual std::auto_ptr<InsetBase> clone() const;
64         ///
65         void read(Buffer const &, LyXLex &);
66         ///
67         void write(Buffer const &, std::ostream &) const;
68         ///
69         void metrics(MetricsInfo &, Dimension &) const;
70         ///
71         void draw(PainterInfo & pi, int x, int y) const;
72         ///
73         std::string const editMessage() const;
74         ///
75         bool insetAllowed(InsetOld::Code) const { return true; }
76         ///
77         bool isTextInset() const { return true; }
78         /** returns true if, when outputing LaTeX, font changes should
79             be closed before generating this inset. This is needed for
80             insets that may contain several paragraphs */
81         bool noFontChange() const { return true; }
82         ///
83         bool display() const { return tabular.isLongTabular(); }
84         ///
85         int latex(Buffer const &, std::ostream &,
86                   OutputParams const &) const;
87         ///
88         int plaintext(Buffer const &, std::ostream &,
89                   OutputParams const &) const;
90         ///
91         int linuxdoc(Buffer const &, std::ostream &,
92                      OutputParams const &) const;
93         ///
94         int docbook(Buffer const &, std::ostream &,
95                     OutputParams const &) const;
96         ///
97         void validate(LaTeXFeatures & features) const;
98         ///
99         InsetOld::Code lyxCode() const { return InsetOld::TABULAR_CODE; }
100         /// get the absolute screen x,y of the cursor
101         void getCursorPos(CursorSlice const & cur, int & x, int & y) const;
102         ///
103         bool tabularFeatures(LCursor & cur, std::string const & what);
104         ///
105         void tabularFeatures(LCursor & cur, LyXTabular::Feature feature,
106                              std::string const & val = std::string());
107         ///
108         void openLayoutDialog(BufferView *) const;
109         ///
110         bool showInsetDialog(BufferView *) const;
111         /// Appends \c list with all labels found within this inset.
112         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
113         /// number of cells
114         size_t nargs() const;
115         ///
116         InsetText const & cell(int) const;
117         ///
118         InsetText & cell(int);
119         ///
120         LyXText * getText(int) const;
121
122         ///
123         void markErased();
124
125         // this should return true if we have a "normal" cell, otherwise true.
126         // "normal" means without width set!
127         bool forceDefaultParagraphs(InsetBase const * in) const;
128
129         ///
130         void addPreview(lyx::graphics::PreviewLoader &) const;
131
132         ///
133         Buffer const & buffer() const;
134
135         /// set the owning buffer
136         void buffer(Buffer * buf);
137         /// lock cell with given index
138         void edit(LCursor & cur, bool left);
139         ///
140         InsetBase * editXY(LCursor & cur, int x, int y);
141         /// can we go further down on mouse click?
142         bool descendable() const { return true; }
143
144         //
145         // Public structures and variables
146         ///
147         mutable LyXTabular tabular;
148
149 protected:
150         ///
151         void priv_dispatch(LCursor & cur, FuncRequest & cmd);
152         ///
153         bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
154 private:
155         ///
156         void drawCellLines(Painter &, int x, int baseline,
157                 int row, int cell) const;
158         ///
159         void drawCellSelection(PainterInfo &, int x, int baseline,
160                 int row, int column, int cell) const;
161         ///
162         InsetBase * setPos(LCursor & cur, int x, int y) const;
163
164         ///
165         void moveNextCell(LCursor & cur);
166         ///
167         void movePrevCell(LCursor & cur);
168         ///
169         int getCellXPos(int cell) const;
170         ///
171         void resetPos(LCursor & cur) const;
172         ///
173         void removeTabularRow();
174         ///
175         bool hasPasteBuffer() const;
176         ///
177         bool copySelection(LCursor & cur);
178         ///
179         bool pasteSelection(LCursor & cur);
180         ///
181         void cutSelection(LCursor & cur);
182         ///
183         bool isRightToLeft(LCursor & cur);
184         ///
185         void getSelection(LCursor & cur,
186                 int & rs, int & re, int & cs, int & ce) const;
187         ///
188         bool insertAsciiString(BufferView &, std::string const & buf, bool usePaste);
189         /// are we operating on several cells?
190         bool tablemode(LCursor & cur) const;
191
192         ///
193         Buffer const * buffer_;
194         ///
195         mutable int cursorx_;
196         ///
197         mutable int first_visible_cell;
198 };
199
200
201 #include "mailinset.h"
202
203
204 class InsetTabularMailer : public MailInset {
205 public:
206         ///
207         InsetTabularMailer(InsetTabular const & inset);
208         ///
209         virtual InsetBase & inset() const { return inset_; }
210         ///
211         virtual std::string const & name() const { return name_; }
212         ///
213         virtual std::string const inset2string(Buffer const &) const;
214         /// Returns the active cell if successful, else -1.
215         static int string2params(std::string const &, InsetTabular &);
216         ///
217         static std::string const params2string(InsetTabular const &);
218 private:
219         ///
220         static std::string const name_;
221         ///
222         InsetTabular & inset_;
223 };
224
225 std::string const featureAsString(LyXTabular::Feature feature);
226
227 #endif