]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
prepare for 1.1.6pre2
[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 #include <sigc++/signal_system.h>
58
59 #ifdef SIGC_CXX_NAMESPACES
60 using SigC::Signal0;
61 #endif
62
63 class LyXLex;
64 class Painter;
65 class BufferView;
66 class Buffer;
67
68 class InsetTabular : public UpdatableInset {
69 public:
70     ///
71     enum UpdateCodes {
72         NONE = 0,
73         CURSOR = 1,
74         CELL = 2,
75         SELECTION = 3,
76         FULL = 4,
77         INIT = 5
78     };
79     ///
80     InsetTabular(Buffer const &, int rows = 1, int columns = 1);
81     ///
82     InsetTabular(InsetTabular const &, Buffer const &);
83     ///
84     ~InsetTabular();
85     ///
86     Inset * Clone(Buffer const &) const;
87     ///
88     void Read(Buffer const *, LyXLex &);
89     ///
90     void Write(Buffer const *, std::ostream &) const;
91     ///
92     int ascent(BufferView *, LyXFont const &) const;
93     ///
94     int descent(BufferView *, LyXFont const &) const;
95     ///
96     int width(BufferView *, LyXFont const & f) const;
97     ///
98     void draw(BufferView *, const LyXFont &, int , float &, bool) const;
99     ///
100     void update(BufferView *, LyXFont const &, bool = false);
101     ///
102     string const EditMessage() const;
103     ///
104     void Edit(BufferView *, int x, int y, unsigned int);
105     ///
106     bool doClearArea() const { return !locked; };
107     ///
108     void InsetUnlock(BufferView *);
109     ///
110     void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty) const;
111     ///
112     bool LockInsetInInset(BufferView *, UpdatableInset *);
113     ///
114     bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
115     ///
116     bool UpdateInsetInInset(BufferView *, Inset *);
117     ///
118     unsigned int InsetInInsetY();
119     ///
120     UpdatableInset * GetLockingInset();
121     ///
122     UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
123     ///
124     bool InsertInset(BufferView *, Inset *);
125     ///
126     bool IsTextInset() const { return true; }
127     ///
128     bool display() const { return tabular->IsLongTabular(); }
129     ///
130     void InsetButtonRelease(BufferView *, int, int, int);
131     ///
132     void InsetButtonPress(BufferView *, int, int, int);
133     ///
134     void InsetMotionNotify(BufferView *, int, int, int);
135     ///
136     void InsetKeyPress(XKeyEvent *);
137     ///
138     UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
139     ///
140     int Latex(Buffer const *, std::ostream &, bool, bool) const;
141     ///
142     int Ascii(Buffer const *, std::ostream &, int linelen) const;
143     ///
144     int Linuxdoc(Buffer const *, std::ostream &) const;
145     ///
146     int DocBook(Buffer const *, std::ostream &) const;
147     ///
148     void Validate(LaTeXFeatures & features) const;
149     ///
150     Inset::Code LyxCode() const { return Inset::TABULAR_CODE; }
151     ///
152     void GetCursorPos(BufferView *, int & x, int & y) const;
153     ///
154     void ToggleInsetCursor(BufferView *);
155     ///
156     bool TabularFeatures(BufferView * bv, string const & what);
157     ///
158     void TabularFeatures(BufferView * bv, LyXTabular::Feature feature,
159                          string const & val = string());
160     ///
161     int GetActCell() const { return actcell; }
162     ///
163     void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
164     ///
165     int getMaxWidth(Painter & pain, UpdatableInset const *) const;
166     ///
167     Buffer * BufferOwner() const { return const_cast<Buffer *>(buffer); }
168     ///
169     LyXText * getLyXText(BufferView *) const;
170     ///
171     void resizeLyXText(BufferView *) const;
172     ///
173     void OpenLayoutDialog(BufferView *) const;
174     ///
175     LyXFunc::func_status getStatus(string const & argument) const;
176
177     //
178     // Public structures and variables
179     ///
180     LyXTabular * tabular;
181         ///
182         Signal0<void> hideDialog;
183
184 private:
185     ///
186     bool calculate_dimensions_of_cells(BufferView *, LyXFont const &,
187                                        bool = false) const;
188     ///
189     void DrawCellLines(Painter &, int x, int baseline,
190                        int row, int cell) const;
191     ///
192     void DrawCellSelection(Painter &, int x, int baseline,
193                            int row, int column, int cell) const;
194     ///
195     void ShowInsetCursor(BufferView *, bool show=true);
196     ///
197     void HideInsetCursor(BufferView *);
198     ///
199     void setPos(BufferView *, int x, int y) const;
200     ///
201     UpdatableInset::RESULT moveRight(BufferView *, bool lock = true);
202     ///
203     UpdatableInset::RESULT moveLeft(BufferView *, bool lock = true);
204     ///
205     UpdatableInset::RESULT moveUp(BufferView *);
206     ///
207     UpdatableInset::RESULT moveDown(BufferView *);
208     ///
209     bool moveNextCell(BufferView *);
210     ///
211     bool movePrevCell(BufferView *);
212     ///
213     bool Delete();
214     ///
215     int getCellXPos(int cell) const;
216     ///
217     void resetPos(BufferView *) const;
218     ///
219     void RemoveTabularRow();
220     ///
221     bool hasSelection() const { return ((sel_pos_start != sel_pos_end) ||
222                                        (sel_cell_start != sel_cell_end));}
223     ///
224     void clearSelection() const {
225         sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
226     }
227     ///
228     bool ActivateCellInset(BufferView *, int x = 0, int y = 0, int button = 0,
229                            bool behind = false);
230     ///
231     bool InsetHit(BufferView * bv, int x, int y) const;
232     ///
233     int GetMaxWidthOfCell(Painter &, int cell) const;
234     ///
235     bool hasPasteBuffer() const;
236     ///
237     bool copySelection(BufferView *);
238     ///
239     bool pasteSelection(BufferView *);
240     ///
241     bool cutSelection();
242
243     //
244     // Private structures and variables
245     ///
246     InsetText * the_locking_inset;
247     ///
248     Buffer const * buffer;
249     ///
250     mutable LyXCursor cursor;
251     ///
252     mutable LyXCursor old_cursor;
253     ///
254     mutable LyXParagraph::size_type inset_pos;
255     ///
256     mutable unsigned int inset_x;
257     ///
258     mutable unsigned int inset_y;
259     ///
260     mutable LyXParagraph::size_type sel_pos_start;
261     ///
262     mutable LyXParagraph::size_type sel_pos_end;
263     ///
264     mutable int sel_cell_start;
265     ///
266     mutable int sel_cell_end;
267     ///
268     mutable int actcell;
269     ///
270     mutable int oldcell;
271     ///
272     mutable int actcol;
273     ///
274     mutable int actrow;
275     ///
276     bool no_selection;
277     ///
278     mutable bool locked;
279     ///
280     mutable UpdateCodes need_update;
281 };
282 #endif