]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
* src/LyXAction.C: mark goto-clear-bookmark as working without buffer
[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 #include "mailinset.h"
38
39 namespace lyx {
40
41 class FuncStatus;
42 class LyXLex;
43 class BufferView;
44 class Buffer;
45 class BufferParams;
46 class Paragraph;
47 class CursorSlice;
48
49 namespace frontend { class Painter; }
50
51 class InsetTabular : public InsetOld {
52 public:
53         ///
54         InsetTabular(Buffer const &, row_type rows = 1,
55                      col_type columns = 1);
56         ///
57         ~InsetTabular();
58         ///
59         void read(Buffer const &, LyXLex &);
60         ///
61         void write(Buffer const &, std::ostream &) const;
62         ///
63         bool metrics(MetricsInfo &, Dimension &) const;
64         ///
65         void draw(PainterInfo & pi, int x, int y) const;
66         ///
67         void drawSelection(PainterInfo & pi, int x, int y) const;
68         ///
69         virtual docstring const editMessage() const;
70         ///
71         EDITABLE editable() const { return HIGHLY_EDITABLE; }
72         ///
73         bool insetAllowed(InsetBase::Code) const { return true; }
74         ///
75         bool allowSpellCheck() const { return true; }
76         ///
77         bool canTrackChanges() 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 &, odocstream &,
86                   OutputParams const &) const;
87         ///
88         int plaintext(Buffer const &, odocstream &,
89                   OutputParams const &) const;
90         ///
91         int docbook(Buffer const &, odocstream &,
92                     OutputParams const &) const;
93         ///
94         void validate(LaTeXFeatures & features) const;
95         ///
96         Code lyxCode() const { return InsetBase::TABULAR_CODE; }
97         /// get offset of this cursor slice relative to our upper left corner
98         void cursorPos(BufferView const & bv, CursorSlice const & sl,
99                 bool boundary, int & x, int & y) const;
100         ///
101         bool tabularFeatures(LCursor & cur, std::string const & what);
102         ///
103         void tabularFeatures(LCursor & cur, LyXTabular::Feature feature,
104                              std::string const & val = std::string());
105         ///
106         void openLayoutDialog(BufferView *) const;
107         ///
108         bool showInsetDialog(BufferView *) const;
109         /// number of cells
110         size_t nargs() const { return tabular.getNumberOfCells(); }
111         ///
112         boost::shared_ptr<InsetText const> cell(idx_type) const;
113         ///
114         boost::shared_ptr<InsetText> cell(idx_type);
115         ///
116         LyXText * getText(int) const;
117
118         /// set the change for the entire inset
119         void setChange(Change const & change);
120         /// accept the changes within the inset
121         void acceptChanges();
122         /// reject the changes within the inset
123         void rejectChanges();
124
125         // this should return true if we have a "normal" cell, otherwise false.
126         // "normal" means without width set!
127         /// should all paragraphs be output with "Standard" layout?
128         bool forceDefaultParagraphs(idx_type cell = 0) const;
129
130         ///
131         void addPreview(graphics::PreviewLoader &) const;
132
133         ///
134         Buffer const & buffer() const;
135
136         /// set the owning buffer
137         void buffer(Buffer const * buf);
138         /// lock cell with given index
139         void edit(LCursor & cur, bool left);
140         ///
141         InsetBase * editXY(LCursor & cur, int x, int y);
142         /// can we go further down on mouse click?
143         bool descendable() const { return true; }
144
145         //
146         // Public structures and variables
147         ///
148         mutable LyXTabular tabular;
149
150 protected:
151         ///
152         InsetTabular(InsetTabular const &);
153         ///
154         virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
155         ///
156         bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
157         ///
158         int scroll() const { return scx_; }
159
160 private:
161         virtual std::auto_ptr<InsetBase> doClone() const;
162
163         ///
164         void drawCellLines(frontend::Painter &, int x, int y, row_type row,
165                            idx_type cell, bool erased) const;
166         ///
167         void setCursorFromCoordinates(LCursor & cur, int x, int y) const;
168
169         ///
170         void moveNextCell(LCursor & cur);
171         ///
172         void movePrevCell(LCursor & cur);
173         ///
174         int getCellXPos(idx_type cell) const;
175         ///
176         void resetPos(LCursor & cur) const;
177         ///
178         void removeTabularRow();
179         ///
180         bool copySelection(LCursor & cur);
181         ///
182         bool pasteSelection(LCursor & cur);
183         ///
184         void cutSelection(LCursor & cur);
185         ///
186         bool isRightToLeft(LCursor & cur) const;
187         ///
188         void getSelection(LCursor & cur, row_type & rs, row_type & re,
189                           col_type & cs, col_type & ce) const;
190         ///
191         bool insertPlaintextString(BufferView &, docstring const & buf, bool usePaste);
192         /// are we operating on several cells?
193         bool tablemode(LCursor & cur) const;
194
195         /// return the "Manhattan distance" to nearest corner
196         int dist(BufferView &, idx_type cell, int x, int y) const;
197         /// return the cell nearest to x, y
198         idx_type getNearestCell(BufferView &, int x, int y) const;
199
200         ///
201         Buffer const * buffer_;
202         ///
203         mutable idx_type first_visible_cell;
204         ///
205         mutable int scx_;
206 };
207
208
209 class InsetTabularMailer : public MailInset {
210 public:
211         ///
212         InsetTabularMailer(InsetTabular const & inset);
213         ///
214         virtual InsetBase & inset() const { return inset_; }
215         ///
216         virtual std::string const & name() const { return name_; }
217         ///
218         virtual std::string const inset2string(Buffer const &) const;
219         ///
220         static void string2params(std::string const &, InsetTabular &);
221         ///
222         static std::string const params2string(InsetTabular const &);
223 private:
224         ///
225         static std::string const name_;
226         ///
227         InsetTabular & inset_;
228 };
229
230 std::string const featureAsString(LyXTabular::Feature feature);
231
232 } // namespace lyx
233
234 #endif