]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.h
f47b2fee595519be0cf35e4bcc5cb48fa7a32bd1
[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(LyXLex &);
74     ///
75     void Write(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(Painter & pain, const LyXFont &, int , float &) const;
84     ///
85     const char * EditMessage() const;
86     ///
87     void Edit(BufferView *, int x, int y, unsigned int);
88     ///
89     void InsetUnlock(BufferView *);
90     ///
91     bool LockInsetInInset(UpdatableInset *);
92     ///
93     bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr=false);
94     ///
95     void UpdateLocal(BufferView *, bool flag = true);
96     ///
97     bool UpdateInsetInInset(BufferView *, Inset *);
98     ///
99     bool display() const { return tabular->IsLongTabular(); }
100     ///
101     void InsetButtonRelease(BufferView *, int, int, int);
102     ///
103     void InsetButtonPress(BufferView *, int, int, int);
104     ///
105     void InsetMotionNotify(BufferView *, int, int, int);
106     ///
107     void InsetKeyPress(XKeyEvent *);
108     ///
109     UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
110     ///
111     int Latex(std::ostream &, bool, bool) const;
112     ///
113     int Ascii(std::ostream &) const;
114     ///
115     int Linuxdoc(std::ostream &) const;
116     ///
117     int DocBook(std::ostream &) const;
118     ///
119     void Validate(LaTeXFeatures & features) const;
120     ///
121     Inset::Code LyxCode() const { return Inset::TABULAR_CODE; }
122     ///
123     void GetCursorPos(int & x, int & y);
124     ///
125     void ToggleInsetCursor(BufferView *);
126     ///
127     void TabularFeatures(int feature, string val="");
128     ///
129     int GetActCell() { return actcell; }
130     ///
131     void SetFont(LyXFont const &);
132     ///
133     /// Public structures and variables
134     ///
135     LyXTabular * tabular;
136
137 private:
138     void calculate_width_of_cells(Painter &, LyXFont const &) const;
139     ///
140     void DrawCellLines(Painter &, int x, int baseline, int row, int cell) const;
141     ///
142     void ShowInsetCursor(BufferView *);
143     ///
144     void HideInsetCursor(BufferView *);
145     ///
146     void setPos(Painter &, int x, int y) const;
147     ///
148     void setWidthOfCell(int pos, int cell, int row);
149     ///
150     UpdatableInset::RESULT moveRight(BufferView *);
151     UpdatableInset::RESULT moveLeft();
152     UpdatableInset::RESULT moveUp();
153     UpdatableInset::RESULT moveDown();
154     bool moveNextCell();
155     bool movePrevCell();
156     bool Delete();
157     ///
158     void resetPos(BufferView *);
159     ///
160     void RemoveTabularRow();
161     ///
162     bool hasCharSelection() const {return (sel_pos_start != sel_pos_end);}
163     bool hasCellSelection() const {return hasCharSelection() &&
164                                  (sel_cell_start != sel_cell_end);}
165     ///
166     /// Private structures and variables
167     ///
168     UpdatableInset
169         * the_locking_inset;
170     Buffer
171         * buffer;
172     mutable LyXCursor
173         cursor,
174         old_cursor;
175     mutable int
176         inset_pos,
177         inset_x, inset_y,
178         sel_pos_start,
179         sel_pos_end,
180         sel_cell_start,
181         sel_cell_end,
182         actcell,
183         actcol,
184         actrow;
185     bool
186         no_selection;
187     mutable bool
188         init;
189 };
190 #endif