]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
46e0ed4b19188c9ece5eb0b3ca4eb1cba335c9f6
[lyx.git] / src / insets / insettabular.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  * 
5  *           LyX, The Document Processor
6  *
7  *           Copyright 1995-2000 The LyX Team.
8  *
9  *======================================================
10  */
11 // This is the rewrite of the tabular (table) support.
12
13 // It will probably be a lot of work.
14
15 // One first goal could be to make the inset read the old table format
16 // and just output it again... no viewing at all.
17
18 // When making the internal structure of tabular support I really think
19 // that STL containers should be used. This will separate the container from
20 // the rest of the code, which is a good thing.
21
22 // Ideally the tabular support should do as the mathed and use
23 // LaTeX in the .lyx file too.
24
25 // Things to think of when desingning the new tabular support:
26 // - color support (colortbl, color)
27 // - decimal alignment (dcloumn)
28 // - custom lines (hhline)
29 // - rotation
30 // - multicolumn
31 // - multirow
32 // - column styles
33
34 // This is what I have written about tabular support in the LyX3-Tasks file:
35 //
36 //  o rewrite of table code. Should probably be written as some
37 //          kind of an inset. At least get the code out of the kernel.
38 //                - colortbl  -multirow
39 //                - hhline    -multicolumn
40 //                - dcolumn
41 // o enhance longtable support
42
43 // Lgb
44
45 #ifndef INSETTABULAR_H
46 #define INSETTABULAR_H
47
48 #ifdef __GNUG__
49 #pragma interface
50 #endif
51
52 #include "lyxinset.h"
53 #include "tabular.h"
54 #include "LString.h"
55 #include "lyxcursor.h"
56 #include "lyxfunc.h"
57
58 class LyXLex;
59 class Painter;
60 class BufferView;
61 class Buffer;
62 class Dialogs;
63
64 class InsetTabular : public UpdatableInset {
65 public:
66     ///
67     enum UpdateCodes {
68         NONE = 0,
69         INIT,
70         FULL,
71         CELL,
72         CURSOR,
73         SELECTION
74     };
75     ///
76     InsetTabular(Buffer *, int rows = 1, int columns = 1);
77     ///
78     InsetTabular(InsetTabular const &, Buffer *);
79     ///
80     ~InsetTabular();
81     ///
82     Inset * Clone() const;
83     ///
84     void Read(Buffer const *, LyXLex &);
85     ///
86     void Write(Buffer const *, std::ostream &) const;
87     ///
88     int ascent(BufferView *, LyXFont const &) const;
89     ///
90     int descent(BufferView *, LyXFont const &) const;
91     ///
92     int width(BufferView *, LyXFont const & f) const;
93     ///
94     void draw(BufferView *, const LyXFont &, int , float &, bool) const;
95     ///
96     void update(BufferView *, LyXFont const &, bool = false);
97     ///
98     string const EditMessage() const;
99     ///
100     void Edit(BufferView *, int x, int y, unsigned int);
101     ///
102     bool doClearArea() const { return !locked; };
103     ///
104     void InsetUnlock(BufferView *);
105     ///
106     void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty) const;
107     ///
108     bool LockInsetInInset(BufferView *, UpdatableInset *);
109     ///
110     bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
111     ///
112     bool UpdateInsetInInset(BufferView *, Inset *);
113     ///
114     int InsetInInsetY();
115     ///
116     UpdatableInset * GetLockingInset();
117     ///
118     UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
119     ///
120     bool InsertInset(BufferView *, Inset *);
121     ///
122     bool IsTextInset() const { return true; }
123     ///
124     bool display() const { return tabular->IsLongTabular(); }
125     ///
126     void InsetButtonRelease(BufferView *, int, int, int);
127     ///
128     void InsetButtonPress(BufferView *, int, int, int);
129     ///
130     void InsetMotionNotify(BufferView *, int, int, int);
131     ///
132     void InsetKeyPress(XKeyEvent *);
133     ///
134     UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
135     ///
136     int Latex(Buffer const *, std::ostream &, bool, bool) const;
137     ///
138     int Ascii(Buffer const *, std::ostream &) const;
139     ///
140     int Linuxdoc(Buffer const *, std::ostream &) const;
141     ///
142     int DocBook(Buffer const *, std::ostream &) const;
143     ///
144     void Validate(LaTeXFeatures & features) const;
145     ///
146     Inset::Code LyxCode() const { return Inset::TABULAR_CODE; }
147     ///
148     void GetCursorPos(BufferView *, int & x, int & y) const;
149     ///
150     void ToggleInsetCursor(BufferView *);
151     ///
152     bool TabularFeatures(BufferView * bv, string what);
153     ///
154     void TabularFeatures(BufferView * bv, int feature, string val = string());
155     ///
156     int GetActCell() { return actcell; }
157     ///
158     void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
159     ///
160     int getMaxWidth(Painter & pain, UpdatableInset const *) const;
161     ///
162     Buffer * BufferOwner() const { return buffer; }
163     ///
164     LyXText * getLyXText(BufferView *) const;
165     void resizeLyXText(BufferView *) const;
166     void OpenLayoutDialog(BufferView *) const;
167     LyXFunc::func_status getStatus(string argument) const;
168
169     //
170     // Public structures and variables
171     ///
172     LyXTabular * tabular;
173
174 private:
175     ///
176     bool calculate_dimensions_of_cells(BufferView *, LyXFont const &,
177                                        bool =false) const;
178     ///
179     void DrawCellLines(Painter &, int x, int baseline,
180                        int row, int cell) const;
181     ///
182     void DrawCellSelection(Painter &, int x, int baseline,
183                            int row, int column, int cell) const;
184     ///
185     void ShowInsetCursor(BufferView *);
186     ///
187     void HideInsetCursor(BufferView *);
188     ///
189     void setPos(BufferView *, int x, int y) const;
190     ///
191     UpdatableInset::RESULT moveRight(BufferView *, bool lock = true);
192     ///
193     UpdatableInset::RESULT moveLeft(BufferView *, bool lock = true);
194     ///
195     UpdatableInset::RESULT moveUp(BufferView *);
196     ///
197     UpdatableInset::RESULT moveDown(BufferView *);
198     ///
199     bool moveNextCell(BufferView *);
200     ///
201     bool movePrevCell(BufferView *);
202     ///
203     bool Delete();
204     ///
205     int getCellXPos(int cell) const;
206     ///
207     void resetPos(BufferView *) const;
208     ///
209     void RemoveTabularRow();
210     ///
211     bool hasSelection() const {return ((sel_pos_start != sel_pos_end) ||
212                                        (sel_cell_start != sel_cell_end));}
213     ///
214     bool ActivateCellInset(BufferView *, int x = 0, int y = 0, int button = 0,
215                            bool behind = false);
216     ///
217     bool InsetHit(BufferView * bv, int x, int y) const;
218     ///
219     int GetMaxWidthOfCell(Painter &, int cell) const;
220     ///
221     bool hasPasteBuffer() const { return (paste_tabular != 0); }
222     ///
223     bool copySelection();
224     ///
225     bool pasteSelection(BufferView *);
226     ///
227     bool cutSelection();
228
229     //
230     // Private structures and variables
231     ///
232     InsetText * the_locking_inset;
233     ///
234     Buffer * buffer;
235     ///
236     mutable LyXCursor cursor;
237     ///
238     mutable LyXCursor old_cursor;
239     ///
240     mutable int inset_pos;
241     ///
242     mutable int inset_x;
243     ///
244     mutable int inset_y;
245     ///
246     mutable int sel_pos_start;
247     ///
248     mutable int sel_pos_end;
249     ///
250     mutable int sel_cell_start;
251     ///
252     mutable int sel_cell_end;
253     ///
254     mutable int actcell;
255     ///
256     mutable int oldcell;
257     ///
258     mutable int actcol;
259     ///
260     mutable int actrow;
261     ///
262     bool no_selection;
263     ///
264     mutable bool locked;
265     ///
266     mutable UpdateCodes need_update;
267     ///
268     mutable Dialogs * dialogs_;
269     ///
270     LyXTabular * paste_tabular;
271 };
272 #endif