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