]> git.lyx.org Git - features.git/blob - src/insets/insettabular.h
split LyXFunc::getStatus() into inset specific chunks
[features.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         ///
112         FuncStatus getStatus(BufferView &, 
113                 std::string const & argument, int cell) const;
114         /// Appends \c list with all labels found within this inset.
115         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
116         /// number of cells
117         size_t nargs() const;
118         ///
119         InsetText const & cell(int) const;
120         ///
121         InsetText & cell(int);
122         ///
123         LyXText * getText(int) const;
124
125         ///
126         void markErased();
127
128         // this should return true if we have a "normal" cell, otherwise true.
129         // "normal" means without width set!
130         bool forceDefaultParagraphs(InsetBase const * in) const;
131
132         ///
133         void addPreview(lyx::graphics::PreviewLoader &) const;
134
135         ///
136         Buffer const & buffer() const;
137
138         /// set the owning buffer
139         void buffer(Buffer * buf);
140         /// lock cell with given index
141         void edit(LCursor & cur, bool left);
142         ///
143         InsetBase * editXY(LCursor & cur, int x, int y);
144         /// can we go further down on mouse click?
145         bool descendable() const { return true; }
146
147         //
148         // Public structures and variables
149         ///
150         mutable LyXTabular tabular;
151
152 protected:
153         ///
154         void priv_dispatch(LCursor & cur, FuncRequest & cmd);
155         ///
156         bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
157 private:
158         ///
159         void drawCellLines(Painter &, int x, int baseline,
160                 int row, int cell) const;
161         ///
162         void drawCellSelection(PainterInfo &, int x, int baseline,
163                 int row, int column, int cell) const;
164         ///
165         InsetBase * setPos(LCursor & cur, int x, int y) const;
166
167         ///
168         void moveNextCell(LCursor & cur);
169         ///
170         void movePrevCell(LCursor & cur);
171         ///
172         int getCellXPos(int cell) const;
173         ///
174         void resetPos(LCursor & cur) const;
175         ///
176         void removeTabularRow();
177         ///
178         bool hasPasteBuffer() const;
179         ///
180         bool copySelection(LCursor & cur);
181         ///
182         bool pasteSelection(LCursor & cur);
183         ///
184         void cutSelection(LCursor & cur);
185         ///
186         bool isRightToLeft(LCursor & cur);
187         ///
188         void getSelection(LCursor & cur,
189                 int & rs, int & re, int & cs, int & ce) const;
190         ///
191         bool insertAsciiString(BufferView &, std::string const & buf, bool usePaste);
192         /// are we operating on several cells?
193         bool tablemode(LCursor & cur) const;
194
195         ///
196         Buffer const * buffer_;
197         ///
198         mutable int cursorx_;
199         ///
200         mutable int first_visible_cell;
201 };
202
203
204 #include "mailinset.h"
205
206
207 class InsetTabularMailer : public MailInset {
208 public:
209         ///
210         InsetTabularMailer(InsetTabular const & inset);
211         ///
212         virtual InsetBase & inset() const { return inset_; }
213         ///
214         virtual std::string const & name() const { return name_; }
215         ///
216         virtual std::string const inset2string(Buffer const &) const;
217         /// Returns the active cell if successful, else -1.
218         static int string2params(std::string const &, InsetTabular &);
219         ///
220         static std::string const params2string(InsetTabular const &);
221 private:
222         ///
223         static std::string const name_;
224         ///
225         InsetTabular & inset_;
226 };
227
228 std::string const featureAsString(LyXTabular::Feature feature);
229
230 #endif