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