]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
Added %x support in vspace.C (LyXLenght) and use it for the minipages.
[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 class LyXLex;
60 class Painter;
61 class BufferView;
62 class Buffer;
63
64 class InsetTabular : public UpdatableInset {
65 public:
66     ///
67     enum UpdateCodes {
68         NONE = 0,
69         CURSOR = 1,
70         CELL = 2,
71         SELECTION = 3,
72         FULL = 4,
73         INIT = 5
74     };
75     ///
76     InsetTabular(Buffer const &, int rows = 1, int columns = 1);
77     ///
78     InsetTabular(InsetTabular const &, Buffer const &);
79     ///
80     ~InsetTabular();
81     ///
82     Inset * Clone(Buffer const &) 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     unsigned 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 *, kb_action,
135                                          string const &);
136     ///
137     int Latex(Buffer const *, std::ostream &, bool, bool) const;
138     ///
139     int Ascii(Buffer const *, std::ostream &, int linelen) const;
140     ///
141     int Linuxdoc(Buffer const *, std::ostream &) const;
142     ///
143     int DocBook(Buffer const *, std::ostream &) const;
144     ///
145     void Validate(LaTeXFeatures & features) const;
146     ///
147     Inset::Code LyxCode() const { return Inset::TABULAR_CODE; }
148     ///
149     void GetCursorPos(BufferView *, int & x, int & y) const;
150     ///
151     void ToggleInsetCursor(BufferView *);
152     ///
153     bool TabularFeatures(BufferView * bv, string const & what);
154     ///
155     void TabularFeatures(BufferView * bv, LyXTabular::Feature feature,
156                          string const & val = string());
157     ///
158     int GetActCell() const { return actcell; }
159     ///
160     void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
161     ///
162     int getMaxWidth(BufferView *, UpdatableInset const *) const;
163     ///
164     Buffer * BufferOwner() const { return const_cast<Buffer *>(buffer); }
165     ///
166     LyXText * getLyXText(BufferView const *, bool const recursive = false) const;
167     ///
168     void resizeLyXText(BufferView *) const;
169     ///
170     void OpenLayoutDialog(BufferView *) const;
171     ///
172     bool ShowInsetDialog(BufferView *) const;
173     ///
174     LyXFunc::func_status getStatus(string const & argument) const;
175
176     //
177     // Public structures and variables
178     ///
179     LyXTabular * tabular;
180     ///
181     SigC::Signal0<void> hideDialog;
182
183 private:
184     ///
185     bool calculate_dimensions_of_cells(BufferView *, LyXFont const &,
186                                        bool = false) const;
187     ///
188     void DrawCellLines(Painter &, int x, int baseline,
189                        int row, int cell) const;
190     ///
191     void DrawCellSelection(Painter &, int x, int baseline,
192                            int row, int column, int cell) const;
193     ///
194     void ShowInsetCursor(BufferView *, bool show=true);
195     ///
196     void HideInsetCursor(BufferView *);
197     ///
198     void setPos(BufferView *, int x, int y) const;
199     ///
200     UpdatableInset::RESULT moveRight(BufferView *, bool lock = true);
201     ///
202     UpdatableInset::RESULT moveLeft(BufferView *, bool lock = true);
203     ///
204     UpdatableInset::RESULT moveUp(BufferView *, bool lock = true);
205     ///
206     UpdatableInset::RESULT moveDown(BufferView *, bool lock = true);
207     ///
208     bool moveNextCell(BufferView *, bool lock = false);
209     ///
210     bool movePrevCell(BufferView *, bool lock = false);
211     ///
212     bool Delete();
213     ///
214     int getCellXPos(int cell) const;
215     ///
216     void resetPos(BufferView *) const;
217     ///
218     void RemoveTabularRow();
219     ///
220     bool hasSelection() const {
221         return sel_cell_start != sel_cell_end;
222     }
223     ///
224     void clearSelection() const {
225         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 ActivateCellInsetAbs(BufferView *, int x = 0, int y = 0, int button = 0);
232     ///
233     bool InsetHit(BufferView * bv, int x, int y) const;
234     ///
235     int GetMaxWidthOfCell(BufferView * bv, int cell) const;
236     ///
237     bool hasPasteBuffer() const;
238     ///
239     bool copySelection(BufferView *);
240     ///
241     bool pasteSelection(BufferView *);
242     ///
243     bool cutSelection();
244     ///
245     bool isRightToLeft(BufferView *);
246
247     //
248     // Private structures and variables
249     ///
250     InsetText * the_locking_inset;
251     ///
252     InsetText * old_locking_inset;
253     ///
254     Buffer const * buffer;
255     ///
256     mutable LyXCursor cursor;
257     ///
258     mutable unsigned int inset_x;
259     ///
260     mutable unsigned int inset_y;
261     ///
262     mutable int sel_cell_start;
263     ///
264     mutable int sel_cell_end;
265     ///
266     mutable int actcell;
267     ///
268     mutable int oldcell;
269     ///
270     mutable int actcol;
271     ///
272     mutable int actrow;
273     ///
274     mutable int first_visible_cell;
275     ///
276     bool no_selection;
277     ///
278     bool no_draw;
279     ///
280     mutable bool locked;
281     ///
282     mutable UpdateCodes need_update;
283 };
284 #endif