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