]> git.lyx.org Git - features.git/blob - src/tabular.h
Various fixes and added some functionallity to insettabular.
[features.git] / src / tabular.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor
6  *       
7  *           Copyright 2000 The LyX Team.
8  *
9  * ====================================================== */
10 #ifndef TABULAR_H
11 #define TABULAR_H
12
13 #ifdef __GNUG__
14 #pragma interface
15 #endif
16
17 #include <iosfwd>
18 #include <vector>
19
20 #include "lyxlex.h"
21 #include "LString.h"
22
23 class InsetTabular;
24 class InsetText;
25 class LaTeXFeatures;
26
27 /* The features the text class offers for tables */ 
28
29 ///
30 class LyXTabular  {
31 public:
32     // Are the values of these enums important? (Lgb)
33     enum {
34         APPEND_ROW = 0,
35         APPEND_COLUMN,
36         DELETE_ROW,
37         DELETE_COLUMN,
38         TOGGLE_LINE_TOP,
39         TOGGLE_LINE_BOTTOM,
40         TOGGLE_LINE_LEFT,
41         TOGGLE_LINE_RIGHT,
42         ALIGN_LEFT, // what are these alignment enums used for?
43         ALIGN_RIGHT,
44         ALIGN_CENTER,
45         DELETE_TABULAR,
46         MULTICOLUMN,
47         SET_ALL_LINES,
48         UNSET_ALL_LINES,
49         SET_LONGTABULAR,
50         UNSET_LONGTABULAR,
51         SET_PWIDTH,
52         SET_ROTATE_TABULAR,
53         UNSET_ROTATE_TABULAR,
54         SET_ROTATE_CELL,
55         UNSET_ROTATE_CELL,
56         SET_LINEBREAKS,
57         SET_LTHEAD,
58         SET_LTFIRSTHEAD,
59         SET_LTFOOT,
60         SET_LTLASTFOOT,
61         SET_LTNEWPAGE,
62         SET_SPECIAL_COLUMN,
63         SET_SPECIAL_MULTI
64     };
65
66     enum {
67         CELL_NORMAL = 0,
68         CELL_BEGIN_OF_MULTICOLUMN,
69         CELL_PART_OF_MULTICOLUMN
70     };
71     /* konstruktor */
72     ///
73     LyXTabular(InsetTabular *, int columns_arg, int rows_arg);
74     ///
75     ///
76     LyXTabular(InsetTabular *, LyXTabular const &);
77     ///
78     explicit
79     LyXTabular(InsetTabular *, LyXLex & lex);
80     ///
81     ~LyXTabular();
82     ///
83     LyXTabular & operator=(LyXTabular const &);
84     ///
85     LyXTabular * Clone(InsetTabular *);
86     
87     /// Returns true if there is a topline, returns false if not
88     bool TopLine(int cell) const;
89     /// Returns true if there is a topline, returns false if not
90     bool BottomLine(int cell) const;
91     /// Returns true if there is a topline, returns false if not
92     bool LeftLine(int cell) const;
93     /// Returns true if there is a topline, returns false if not
94     bool RightLine(int cell) const;
95     
96     ///
97     bool TopAlreadyDrawed(int cell) const;
98     ///
99     bool LeftAlreadyDrawed(int cell) const;
100     ///
101     bool IsLastRow(int cell) const;
102     
103     ///
104     int GetAdditionalHeight(int cell) const;
105     ///
106     int GetAdditionalWidth(int cell) const;
107     
108     /* returns the maximum over all rows */
109     ///
110     int GetWidthOfColumn(int cell) const;
111     ///
112     int GetWidthOfTabular() const;
113     ///
114     int GetAscentOfRow(int row) const;
115     ///
116     int GetDescentOfRow(int row) const;
117     ///
118     int GetHeightOfTabular() const;
119     ///
120     void SetAscentOfRow(int row, int height);
121     ///
122     void SetDescentOfRow(int row, int height);
123     /// Returns true if a complete update is necessary, otherwise false
124     bool SetWidthOfCell(int cell, int new_width);
125     /// Returns true if a complete update is necessary, otherwise false
126     bool SetAllLines(int cell, bool line);
127     /// Returns true if a complete update is necessary, otherwise false
128     bool SetTopLine(int cell, bool line);
129     /// Returns true if a complete update is necessary, otherwise false
130     bool SetBottomLine(int cell, bool line);
131     /// Returns true if a complete update is necessary, otherwise false
132     bool SetLeftLine(int cell, bool line);
133     /// Returns true if a complete update is necessary, otherwise false
134     bool SetRightLine(int cell, bool line);
135     /// Returns true if a complete update is necessary, otherwise false
136     bool SetAlignment(int cell, char align);
137     ///
138     bool SetPWidth(int cell, string const & width);
139     ///
140     bool SetAlignSpecial(int cell, string const & special, int what);
141     ///
142     char GetAlignment(int cell) const; // add approp. signedness
143     ///
144     string GetPWidth(int cell) const;
145     ///
146     string GetAlignSpecial(int cell, int what) const;
147     ///
148     int GetWidthOfCell(int cell) const;
149     ///
150     int GetBeginningOfTextInCell(int cell) const;
151     ///
152     void AppendRow(int cell);
153     ///
154     void DeleteRow(int cell);
155     ///
156     void AppendColumn(int cell);
157     ///
158     void DeleteColumn(int cell);
159     ///
160     bool IsFirstCellInRow(int cell) const;
161     ///
162     int GetFirstCellInRow(int row) const;
163     ///
164     bool IsLastCellInRow(int cell) const;
165     ///
166     int GetLastCellInRow(int row) const;
167     ///
168     int GetNumberOfCells() const;
169     ///
170     int AppendCellAfterCell(int append_cell, int question_cell);
171     ///
172     int DeleteCellIfColumnIsDeleted(int cell, int delete_column_cell);
173     ///
174     int NumberOfCellsInRow(int cell) const;
175     ///
176     void Write(std::ostream &) const;
177     ///
178     void Read(LyXLex &);
179     ///
180     void OldFormatRead(LyXLex &, string const &);
181     ///
182     /// helper function for Latex returns number of newlines
183     ///
184     int TeXTopHLine(std::ostream &, int row) const;
185     int TeXBottomHLine(std::ostream &, int row) const;
186     int TeXCellPreamble(std::ostream &, int cell) const;
187     int TeXCellPostamble(std::ostream &, int cell) const;
188     ///
189     int Latex(std::ostream &, bool, bool) const;
190     ///
191     int DocBookEndOfCell(std::ostream &, int cell, int & depth) const;
192 #if 0
193     ///
194     int RoffEndOfCell(std::ostream &, int cell);
195 #endif
196     ///
197     char const * GetDocBookAlign(int cell, bool isColumn = false) const;
198
199     ///
200     bool IsMultiColumn(int cell) const;
201     ///
202     void SetMultiColumn(int cell, int number);
203     ///
204     int UnsetMultiColumn(int cell); // returns number of new cells
205     ///
206     bool IsPartOfMultiColumn(int row, int column) const;
207     ///
208     int row_of_cell(int cell) const;
209     ///
210     int column_of_cell(int cell) const;
211     ///
212     void SetLongTabular(int what);
213     ///
214     bool IsLongTabular() const;
215     ///
216     void SetRotateTabular(int what);
217     ///
218     bool GetRotateTabular() const;
219     ///
220     void SetRotateCell(int cell, int what);
221     ///
222     bool GetRotateCell(int cell) const;
223     ///
224     bool NeedRotating() const;
225     ///
226     bool IsLastCell(int cell) const;
227     ///
228     int GetCellAbove(int cell) const;
229     ///
230     int GetCellBelow(int cell) const;
231     ///
232     int GetCellNumber(int row, int column) const;
233     ///
234     void SetLinebreaks(int cell, bool what);
235     ///
236     bool GetLinebreaks(int cell) const;
237     ///
238     /// Long Tabular Options
239     ///
240     void SetLTHead(int cell, bool first);
241     ///
242     bool GetRowOfLTHead(int cell) const;
243     ///
244     bool GetRowOfLTFirstHead(int cell) const;
245     ///
246     void SetLTFoot(int cell, bool last);
247     ///
248     bool GetRowOfLTFoot(int cell) const;
249     ///
250     bool GetRowOfLTLastFoot(int cell) const;
251     ///
252     void SetLTNewPage(int cell, bool what);
253     ///
254     bool GetLTNewPage(int cell) const;
255     ///
256     InsetText * GetCellInset(int cell) const;
257     ///
258     int rows() const { return rows_; }
259     ///
260     int columns() const { return columns_;}
261     ///
262     InsetTabular * owner() const { return owner_; }
263     ///
264     void Validate(LaTeXFeatures &) const;
265
266 private: //////////////////////////////////////////////////////////////////
267     ///
268     struct cellstruct {
269         ///
270         cellstruct();
271         ///
272         ~cellstruct();
273         ///
274         cellstruct(cellstruct const &);
275         ///
276         cellstruct & operator=(cellstruct const &);
277         ///
278         int cellno;
279         ///
280         int width_of_cell;
281         ///
282         int  multicolumn; // add approp. signedness
283         ///
284         int alignment; // add approp. signedness
285         ///
286         bool top_line;
287         ///
288         bool bottom_line;
289         ///
290         bool linebreaks;
291         ///
292         int rotate;
293         ///
294         string align_special;
295         ///
296         string p_width; // this is only set for multicolumn!!!
297         ///
298         InsetText * inset;
299     };
300     ///
301     struct rowstruct {
302         ///
303         rowstruct();
304         ///
305             //~rowstruct();
306         ///
307             // rowstruct & operator=(rowstruct const &);
308         ///
309         bool top_line;
310         bool bottom_line;
311         int ascent_of_row;
312         int descent_of_row;
313         /// This are for longtabulars only
314         bool newpage;
315     };
316     ///
317     struct columnstruct {
318         ///
319         columnstruct();
320         ///
321             //~columnstruct();
322         ///
323             //columnstruct & operator=(columnstruct const &);
324         ///
325         int alignment; // add approp. signedness
326         bool left_line;
327         bool right_line;
328         int  width_of_column;
329         string p_width;
330         string align_special;
331     };
332     ///
333     int rows_;
334     ///
335     int columns_;
336     ///
337     int numberofcells;
338     ///
339     int * rowofcell;
340     ///
341     int * columnofcell;
342     ///
343     std::vector<rowstruct> row_info;
344     ///
345     std::vector<columnstruct> column_info;
346     ///
347     mutable std::vector< std::vector<cellstruct> > cell_info;
348     ///
349     int width_of_tabular;
350     ///
351     /// for long tabulars
352     ///
353     int endhead; // row of endhead
354     int endfirsthead; // row of endfirsthead
355     int endfoot; // row of endfoot
356     int endlastfoot; // row of endlastfoot
357     ///
358     InsetTabular * owner_;
359    
360     ///
361     void Init(int columns_arg, int rows_arg);
362     ///
363     void Reinit();
364     ///
365     void set_row_column_number_info();
366     /// Returns true if a complete update is necessary, otherwise false
367     bool SetWidthOfMulticolCell(int cell, int new_width);
368     void recalculateMulticolCells(int cell, int new_width);
369     /// Returns true if change
370     bool calculate_width_of_column(int column);
371     bool calculate_width_of_column_NMC(int column); // no multi cells
372     ///
373     void calculate_width_of_tabular();
374
375     ///
376     int right_column_of_cell(int cell) const;
377
378     ///
379     cellstruct * cellinfo_of_cell(int cell) const;
380
381     ///
382     void delete_column(int column);
383
384     ///
385     int cells_in_multicolumn(int cell) const;
386     ///
387     int is_long_tabular;
388     ///
389     int rotate;
390 };
391
392 #endif