]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
e69f7621f829c571b36ee0a570225979a8de03d5
[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();
54         ///
55         void read(Buffer const &, LyXLex &);
56         ///
57         void write(Buffer const &, std::ostream &) const;
58         ///
59         void metrics(MetricsInfo &, Dimension &) const;
60         ///
61         void draw(PainterInfo & pi, int x, int y) const;
62         ///
63         void drawSelection(PainterInfo & pi, int x, int y) const;
64         ///
65         std::string const editMessage() const;
66         ///
67         bool insetAllowed(InsetBase::Code) const { return true; }
68         ///
69         bool isTextInset() const { return true; }
70         /** returns true if, when outputing LaTeX, font changes should
71             be closed before generating this inset. This is needed for
72             insets that may contain several paragraphs */
73         bool noFontChange() const { return true; }
74         ///
75         bool display() const { return tabular.isLongTabular(); }
76         ///
77         int latex(Buffer const &, std::ostream &,
78                   OutputParams const &) const;
79         ///
80         int plaintext(Buffer const &, std::ostream &,
81                   OutputParams const &) const;
82         ///
83         int linuxdoc(Buffer const &, std::ostream &,
84                      OutputParams const &) const;
85         ///
86         int docbook(Buffer const &, std::ostream &,
87                     OutputParams const &) const;
88         ///
89         void validate(LaTeXFeatures & features) const;
90         ///
91         Code lyxCode() const { return InsetBase::TABULAR_CODE; }
92         /// get offset of this cursor slice relative to our upper left corner
93         void getCursorPos(CursorSlice const & sl, int & x, int & y) const;
94         ///
95         bool tabularFeatures(LCursor & cur, std::string const & what);
96         ///
97         void tabularFeatures(LCursor & cur, LyXTabular::Feature feature,
98                              std::string const & val = std::string());
99         ///
100         void openLayoutDialog(BufferView *) const;
101         ///
102         bool showInsetDialog(BufferView *) const;
103         /// Appends \c list with all labels found within this inset.
104         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
105         /// number of cells
106         size_t nargs() const;
107         ///
108         boost::shared_ptr<InsetText const> cell(int) const;
109         ///
110         boost::shared_ptr<InsetText> cell(int);
111         ///
112         LyXText * getText(int) const;
113
114         ///
115         void markErased();
116
117         // this should return true if we have a "normal" cell, otherwise true.
118         // "normal" means without width set!
119         bool forceDefaultParagraphs(InsetBase const * in) const;
120
121         ///
122         void addPreview(lyx::graphics::PreviewLoader &) const;
123
124         ///
125         Buffer const & buffer() const;
126
127         /// set the owning buffer
128         void buffer(Buffer const * buf);
129         /// lock cell with given index
130         void edit(LCursor & cur, bool left);
131         ///
132         InsetBase * editXY(LCursor & cur, int x, int y) const;
133         /// can we go further down on mouse click?
134         bool descendable() const { return true; }
135
136         //
137         // Public structures and variables
138         ///
139         mutable LyXTabular tabular;
140
141 protected:
142         InsetTabular(InsetTabular const &);
143
144         virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
145
146         ///
147         bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
148 private:
149         virtual std::auto_ptr<InsetBase> doClone() const;
150
151         ///
152         void drawCellLines(Painter &, int x, int y, int row, int cell) const;
153         ///
154         InsetBase * setPos(LCursor & cur, int x, int y) const;
155
156         ///
157         void moveNextCell(LCursor & cur);
158         ///
159         void movePrevCell(LCursor & cur);
160         ///
161         int getCellXPos(int cell) const;
162         ///
163         void resetPos(LCursor & cur) const;
164         ///
165         void removeTabularRow();
166         ///
167         bool hasPasteBuffer() const;
168         ///
169         bool copySelection(LCursor & cur);
170         ///
171         bool pasteSelection(LCursor & cur);
172         ///
173         void cutSelection(LCursor & cur);
174         ///
175         bool isRightToLeft(LCursor & cur) const;
176         ///
177         void getSelection(LCursor & cur,
178                 int & rs, int & re, int & cs, int & ce) const;
179         ///
180         bool insertAsciiString(BufferView &, std::string const & buf, bool usePaste);
181         /// are we operating on several cells?
182         bool tablemode(LCursor & cur) const;
183
184         ///
185         Buffer const * buffer_;
186         ///
187         mutable int cursorx_;
188         ///
189         mutable int first_visible_cell;
190 };
191
192
193 #include "mailinset.h"
194
195
196 class InsetTabularMailer : public MailInset {
197 public:
198         ///
199         InsetTabularMailer(InsetTabular const & inset);
200         ///
201         virtual InsetBase & inset() const { return inset_; }
202         ///
203         virtual std::string const & name() const { return name_; }
204         ///
205         virtual std::string const inset2string(Buffer const &) const;
206         ///
207         static void string2params(std::string const &, InsetTabular &);
208         ///
209         static std::string const params2string(InsetTabular const &);
210 private:
211         ///
212         static std::string const name_;
213         ///
214         InsetTabular & inset_;
215 };
216
217 std::string const featureAsString(LyXTabular::Feature feature);
218
219 #endif