]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
9d4a7eac5097114aa7af666790df5f841da50d45
[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         ///
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 const & cmd);
155 private:
156         ///
157         void drawCellLines(Painter &, int x, int baseline,
158                 int row, int cell) const;
159         ///
160         void drawCellSelection(PainterInfo &, int x, int baseline,
161                 int row, int column, int cell) const;
162         ///
163         InsetBase * setPos(LCursor & cur, int x, int y) const;
164
165         ///
166         void moveNextCell(LCursor & cur);
167         ///
168         void movePrevCell(LCursor & cur);
169         ///
170         int getCellXPos(int cell) const;
171         ///
172         void resetPos(LCursor & cur) const;
173         ///
174         void removeTabularRow();
175         ///
176         bool hasPasteBuffer() const;
177         ///
178         bool copySelection(LCursor & cur);
179         ///
180         bool pasteSelection(LCursor & cur);
181         ///
182         void cutSelection(LCursor & cur);
183         ///
184         bool isRightToLeft(LCursor & cur);
185         ///
186         void getSelection(LCursor & cur,
187                 int & rs, int & re, int & cs, int & ce) const;
188         ///
189         bool insertAsciiString(BufferView &, std::string const & buf, bool usePaste);
190         /// are we operating on several cells?
191         bool tablemode(LCursor & cur) const;
192
193         ///
194         Buffer const * buffer_;
195         ///
196         mutable int cursorx_;
197         ///
198         mutable int first_visible_cell;
199 };
200
201
202 #include "mailinset.h"
203
204
205 class InsetTabularMailer : public MailInset {
206 public:
207         ///
208         InsetTabularMailer(InsetTabular const & inset);
209         ///
210         virtual InsetBase & inset() const { return inset_; }
211         ///
212         virtual std::string const & name() const { return name_; }
213         ///
214         virtual std::string const inset2string(Buffer const &) const;
215         /// Returns the active cell if successful, else -1.
216         static int string2params(std::string const &, InsetTabular &);
217         ///
218         static std::string const params2string(InsetTabular const &);
219 private:
220         ///
221         static std::string const name_;
222         ///
223         InsetTabular & inset_;
224 };
225
226 std::string const featureAsString(LyXTabular::Feature feature);
227
228 #endif