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