]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
Some more changes for updating text-insets.
[lyx.git] / src / insets / insettabular.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  * 
5  *           LyX, The Document Processor
6  *
7  *           Copyright (C) 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
57 class LyXLex;
58 class Painter;
59 class BufferView;
60 class Buffer;
61
62 class InsetTabular : public UpdatableInset {
63 public:
64     ///
65     enum UpdateCodes {
66         NONE = 0,
67         INIT,
68         FULL,
69         CELL,
70         CURSOR,
71         SELECTION
72     };
73     ///
74     InsetTabular(Buffer *, int rows=1, int columns=1);
75     ///
76     InsetTabular(InsetTabular const &, Buffer *);
77     ///
78     ~InsetTabular();
79     ///
80     Inset * Clone() const;
81     ///
82     void Read(Buffer const *, LyXLex &);
83     ///
84     void Write(Buffer const *, std::ostream &) const;
85     ///
86     int ascent(Painter &, LyXFont const &) const;
87     ///
88     int descent(Painter &, LyXFont const &) const;
89     ///
90     int width(Painter &, LyXFont const & f) const;
91     ///
92     void draw(BufferView *, const LyXFont &, int , float &, bool) const;
93     ///
94     void update(BufferView *, LyXFont const &, bool =false);
95     ///
96     const char * EditMessage() const;
97     ///
98     void Edit(BufferView *, int x, int y, unsigned int);
99     ///
100     bool doClearArea() const { return !locked; };
101     ///
102     void InsetUnlock(BufferView *);
103     ///
104     void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty);
105     ///
106     bool LockInsetInInset(BufferView *, UpdatableInset *);
107     ///
108     bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr=false);
109     ///
110     bool UpdateInsetInInset(BufferView *, Inset *);
111     ///
112     int InsetInInsetY();
113     ///
114     UpdatableInset * GetLockingInset();
115     ///
116     UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
117     ///
118     bool InsertInset(BufferView *, Inset *);
119     ///
120     bool display() const { return tabular->IsLongTabular(); }
121     ///
122     void InsetButtonRelease(BufferView *, int, int, int);
123     ///
124     void InsetButtonPress(BufferView *, int, int, int);
125     ///
126     void InsetMotionNotify(BufferView *, int, int, int);
127     ///
128     void InsetKeyPress(XKeyEvent *);
129     ///
130     UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
131     ///
132     int Latex(Buffer const *, std::ostream &, bool, bool) const;
133     ///
134     int Ascii(Buffer const *, std::ostream &) const;
135     ///
136     int Linuxdoc(Buffer const *, std::ostream &) const;
137     ///
138     int DocBook(Buffer const *, std::ostream &) const;
139     ///
140     void Validate(LaTeXFeatures & features) const;
141     ///
142     Inset::Code LyxCode() const { return Inset::TABULAR_CODE; }
143     ///
144     void GetCursorPos(BufferView *, int & x, int & y) const;
145     ///
146     void ToggleInsetCursor(BufferView *);
147     ///
148     void TabularFeatures(BufferView * bv, int feature, string val="");
149     ///
150     int GetActCell() { return actcell; }
151     ///
152     void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
153     ///
154     int getMaxWidth(Painter & pain, UpdatableInset const *) const;
155     ///
156     Buffer * BufferOwner() const { return buffer; }
157
158     ///
159     /// Public structures and variables
160     ///
161     LyXTabular * tabular;
162
163 private:
164     bool calculate_dimensions_of_cells(BufferView *, LyXFont const &, bool =false) const;
165     ///
166     void DrawCellLines(Painter &, int x, int baseline, int row, int cell)
167             const;
168     ///
169     void DrawCellSelection(Painter &, int x, int baseline,
170                            int row, int column, int cell) const;
171     ///
172     void ShowInsetCursor(BufferView *);
173     ///
174     void HideInsetCursor(BufferView *);
175     ///
176     void setPos(Painter &, int x, int y) const;
177     ///
178     UpdatableInset::RESULT moveRight(BufferView *, bool lock=true);
179     UpdatableInset::RESULT moveLeft(BufferView *, bool lock=true);
180     UpdatableInset::RESULT moveUp(BufferView *);
181     UpdatableInset::RESULT moveDown(BufferView *);
182     bool moveNextCell(BufferView *);
183     bool movePrevCell(BufferView *);
184     bool Delete();
185     ///
186     int getCellXPos(int cell) const;
187     void resetPos(Painter &) const;
188     ///
189     void RemoveTabularRow();
190     ///
191     bool hasSelection() const {return ((sel_pos_start != sel_pos_end) ||
192                                        (sel_cell_start != sel_cell_end));}
193     ///
194     bool ActivateCellInset(BufferView *, int x=0, int y=0, int button=0,
195                            bool behind = false);
196     ///
197     bool InsetHit(BufferView * bv, int x, int y) const;
198     ///
199     int GetMaxWidthOfCell(Painter &, int cell) const;
200     ///
201     void recomputeTextInsets(BufferView *, const LyXFont &) const;
202
203     ///
204     /// Private structures and variables
205     ///
206     InsetText
207         * the_locking_inset;
208     Buffer
209         * buffer;
210     mutable LyXCursor
211         cursor,
212         old_cursor;
213     mutable int
214         inset_pos,
215         inset_x, inset_y,
216         sel_pos_start,
217         sel_pos_end,
218         sel_cell_start,
219         sel_cell_end,
220         actcell,
221         oldcell,
222         actcol,
223         actrow;
224     bool no_selection;
225     mutable bool locked;
226     mutable UpdateCodes need_update;
227 };
228 #endif