]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
Various fixes to Tabular, InsetTabular and InsetText. Fixed left border for
[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 #include <sigc++/signal_system.h>
49 #include <boost/smart_ptr.hpp>
50
51 #ifdef __GNUG__
52 #pragma interface
53 #endif
54
55 #include "lyxinset.h"
56 #include "tabular.h"
57 #include "LString.h"
58 #include "lyxcursor.h"
59 #include "lyxfunc.h"
60
61 class LyXLex;
62 class Painter;
63 class BufferView;
64 class Buffer;
65
66 class InsetTabular : public UpdatableInset {
67 public:
68         ///
69         enum UpdateCodes {
70                 NONE = 0,
71                 CURSOR = 1,
72                 CELL = 2,
73                 SELECTION = 3,
74                 FULL = 4,
75                 INIT = 5
76         };
77         ///
78         InsetTabular(Buffer const &, int rows = 1, int columns = 1);
79         ///
80         InsetTabular(InsetTabular const &, Buffer const &);
81         ///
82         ~InsetTabular();
83         ///
84         Inset * Clone(Buffer const &) const;
85         ///
86         void Read(Buffer const *, LyXLex &);
87         ///
88         void Write(Buffer const *, std::ostream &) const;
89         ///
90         int ascent(BufferView *, LyXFont const &) const;
91         ///
92         int descent(BufferView *, LyXFont const &) const;
93         ///
94         int width(BufferView *, LyXFont const & f) const;
95         ///
96         void draw(BufferView *, const LyXFont &, int , float &, bool) const;
97         ///
98         void update(BufferView *, LyXFont const &, bool = false);
99         ///
100         string const EditMessage() const;
101         ///
102         void Edit(BufferView *, int x, int y, unsigned int);
103         ///
104         bool doClearArea() const;
105         ///
106         void InsetUnlock(BufferView *);
107         ///
108         void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty) const;
109         ///
110         bool LockInsetInInset(BufferView *, UpdatableInset *);
111         ///
112         bool UnlockInsetInInset(BufferView *, UpdatableInset *,
113                                 bool lr = false);
114         ///
115         bool UpdateInsetInInset(BufferView *, Inset *);
116         ///
117         unsigned int InsetInInsetY();
118         ///
119         UpdatableInset * GetLockingInset();
120         ///
121         UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
122         ///
123         bool InsertInset(BufferView *, Inset *);
124         ///
125         bool IsTextInset() const { return true; }
126         ///
127         bool display() const { return tabular->IsLongTabular(); }
128         ///
129         void InsetButtonRelease(BufferView *, int, int, int);
130         ///
131         void InsetButtonPress(BufferView *, int, int, int);
132         ///
133         void InsetMotionNotify(BufferView *, int, int, int);
134         ///
135         void InsetKeyPress(XKeyEvent *);
136         ///
137         UpdatableInset::RESULT LocalDispatch(BufferView *, kb_action,
138                                              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                      bool selectall = false);
165         ///
166         int getMaxWidth(BufferView *, UpdatableInset const *) const;
167         ///
168         Buffer * BufferOwner() const { return const_cast<Buffer *>(buffer); }
169         ///
170         LyXText * getLyXText(BufferView const *,
171                              bool const recursive = false) const;
172         ///
173         void resizeLyXText(BufferView *) const;
174         ///
175         void OpenLayoutDialog(BufferView *) const;
176         ///
177         bool ShowInsetDialog(BufferView *) const;
178         ///
179         LyXFunc::func_status getStatus(string const & argument) const;
180         ///
181         std::vector<string> const getLabelList() const;
182         ///
183         void nodraw(bool b) {
184                 UpdatableInset::nodraw(b);
185         }
186         bool nodraw() const;
187         ///
188         int scroll(bool recursive=true) const;
189         void scroll(BufferView *bv, float sx) const {
190                 UpdatableInset::scroll(bv, sx);
191         }
192         void scroll(BufferView *bv, int offset) const {
193                 UpdatableInset::scroll(bv, offset);
194         }
195
196         //
197         // Public structures and variables
198         ///
199         //LyXTabular * tabular;
200         boost::scoped_ptr<LyXTabular> tabular;
201         ///
202         SigC::Signal0<void> hideDialog;
203
204 private:
205         ///
206         bool calculate_dimensions_of_cells(BufferView *, LyXFont const &,
207                                            bool = false) const;
208         ///
209         void DrawCellLines(Painter &, int x, int baseline,
210                            int row, int cell) const;
211         ///
212         void DrawCellSelection(Painter &, int x, int baseline,
213                                int row, int column, int cell) const;
214         ///
215         void ShowInsetCursor(BufferView *, bool show=true);
216         ///
217         void HideInsetCursor(BufferView *);
218         ///
219         void setPos(BufferView *, int x, int y) const;
220         ///
221         UpdatableInset::RESULT moveRight(BufferView *, bool lock = true);
222         ///
223         UpdatableInset::RESULT moveLeft(BufferView *, bool lock = true);
224         ///
225         UpdatableInset::RESULT moveUp(BufferView *, bool lock = true);
226         ///
227         UpdatableInset::RESULT moveDown(BufferView *, bool lock = true);
228         ///
229         bool moveNextCell(BufferView *, bool lock = false);
230         ///
231         bool movePrevCell(BufferView *, bool lock = false);
232         ///
233         bool Delete();
234         ///
235         int getCellXPos(int cell) const;
236         ///
237         void resetPos(BufferView *) const;
238         ///
239         void RemoveTabularRow();
240         ///
241         bool hasSelection() const {
242                 return sel_cell_start != sel_cell_end;
243         }
244         ///
245         void clearSelection() const {
246         sel_cell_start = sel_cell_end = 0;
247         }
248         ///
249         bool ActivateCellInset(BufferView *, int x = 0, int y = 0,
250                                int button = 0,
251                                bool behind = false);
252         ///
253         bool ActivateCellInsetAbs(BufferView *, int x = 0, int y = 0,
254                                   int button = 0);
255         ///
256         bool InsetHit(BufferView * bv, int x, int y) const;
257         ///
258         int GetMaxWidthOfCell(BufferView * bv, int cell) const;
259         ///
260         bool hasPasteBuffer() const;
261         ///
262         bool copySelection(BufferView *);
263         ///
264         bool pasteSelection(BufferView *);
265         ///
266         bool cutSelection();
267         ///
268         bool isRightToLeft(BufferView *);
269         ///
270         void getSelection(int & scol, int & ecol, int & srow, int & erow) const;
271
272         //
273         // Private structures and variables
274         ///
275         InsetText * the_locking_inset;
276         ///
277         InsetText * old_locking_inset;
278         ///
279         Buffer const * buffer;
280         ///
281         mutable LyXCursor cursor;
282         ///
283         mutable unsigned int inset_x;
284         ///
285         mutable unsigned int inset_y;
286         ///
287         mutable int sel_cell_start;
288         ///
289         mutable int sel_cell_end;
290         ///
291         mutable int actcell;
292         ///
293         mutable int oldcell;
294         ///
295         mutable int actcol;
296         ///
297         mutable int actrow;
298         ///
299         mutable int first_visible_cell;
300         ///
301         bool no_selection;
302         ///
303         mutable bool locked;
304         ///
305         mutable UpdateCodes need_update;
306 };
307 #endif