]> git.lyx.org Git - lyx.git/blob - src/tabular.h
5430545b83a8f1d7187cbec1784fd1a389e170b9
[lyx.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 NumberOfCellsInRow(int cell) const;
171     ///
172     void Write(std::ostream &) const;
173     ///
174     void Read(LyXLex &);
175     ///
176     void OldFormatRead(LyXLex &, string const &);
177     ///
178     /// helper function for Latex returns number of newlines
179     ///
180     int TeXTopHLine(std::ostream &, int row) const;
181     int TeXBottomHLine(std::ostream &, int row) const;
182     int TeXCellPreamble(std::ostream &, int cell) const;
183     int TeXCellPostamble(std::ostream &, int cell) const;
184     ///
185     int Latex(std::ostream &, bool, bool) const;
186     ///
187     int DocBookEndOfCell(std::ostream &, int cell, int & depth) const;
188 #if 0
189     ///
190     int RoffEndOfCell(std::ostream &, int cell);
191 #endif
192     ///
193     char const * GetDocBookAlign(int cell, bool isColumn = false) const;
194
195     ///
196     bool IsMultiColumn(int cell) const;
197     ///
198     void SetMultiColumn(int cell, int number);
199     ///
200     int UnsetMultiColumn(int cell); // returns number of new cells
201     ///
202     bool IsPartOfMultiColumn(int row, int column) const;
203     ///
204     int row_of_cell(int cell) const;
205     ///
206     int column_of_cell(int cell) const;
207     ///
208     int right_column_of_cell(int cell) const;
209     ///
210     void SetLongTabular(int what);
211     ///
212     bool IsLongTabular() const;
213     ///
214     void SetRotateTabular(int what);
215     ///
216     bool GetRotateTabular() const;
217     ///
218     void SetRotateCell(int cell, int what);
219     ///
220     bool GetRotateCell(int cell) const;
221     ///
222     bool NeedRotating() const;
223     ///
224     bool IsLastCell(int cell) const;
225     ///
226     int GetCellAbove(int cell) const;
227     ///
228     int GetCellBelow(int cell) const;
229     ///
230     int GetLastCellAbove(int cell) const;
231     ///
232     int GetLastCellBelow(int cell) const;
233     ///
234     int GetCellNumber(int row, int column) const;
235     ///
236     void SetLinebreaks(int cell, bool what);
237     ///
238     bool GetLinebreaks(int cell) const;
239     ///
240     /// Long Tabular Options
241     ///
242     void SetLTHead(int cell, bool first);
243     ///
244     bool GetRowOfLTHead(int cell) const;
245     ///
246     bool GetRowOfLTFirstHead(int cell) const;
247     ///
248     void SetLTFoot(int cell, bool last);
249     ///
250     bool GetRowOfLTFoot(int cell) const;
251     ///
252     bool GetRowOfLTLastFoot(int cell) const;
253     ///
254     void SetLTNewPage(int cell, bool what);
255     ///
256     bool GetLTNewPage(int cell) const;
257     ///
258     InsetText * GetCellInset(int cell) const;
259     ///
260     int rows() const { return rows_; }
261     ///
262     int columns() const { return columns_;}
263     ///
264     InsetTabular * owner() const { return owner_; }
265     ///
266     void Validate(LaTeXFeatures &) const;
267
268 private: //////////////////////////////////////////////////////////////////
269     ///
270     struct cellstruct {
271         ///
272         cellstruct();
273         ///
274         ~cellstruct();
275         ///
276         cellstruct(cellstruct const &);
277         ///
278         cellstruct & operator=(cellstruct const &);
279         ///
280         int cellno;
281         ///
282         int width_of_cell;
283         ///
284         int  multicolumn; // add approp. signedness
285         ///
286         int alignment; // add approp. signedness
287         ///
288         bool top_line;
289         ///
290         bool bottom_line;
291         ///
292         bool linebreaks;
293         ///
294         int rotate;
295         ///
296         string align_special;
297         ///
298         string p_width; // this is only set for multicolumn!!!
299         ///
300         InsetText * inset;
301     };
302     typedef std::vector<cellstruct> cell_vector;
303     typedef std::vector<cell_vector> cell_vvector;
304
305     ///
306     struct rowstruct {
307         ///
308         rowstruct();
309         ///
310             //~rowstruct();
311         ///
312             // rowstruct & operator=(rowstruct const &);
313         ///
314         bool top_line;
315         bool bottom_line;
316         int ascent_of_row;
317         int descent_of_row;
318         /// This are for longtabulars only
319         bool newpage;
320     };
321     typedef std::vector<rowstruct> row_vector;
322
323     ///
324     struct columnstruct {
325         ///
326         columnstruct();
327         ///
328             //~columnstruct();
329         ///
330             //columnstruct & operator=(columnstruct const &);
331         ///
332         int alignment; // add approp. signedness
333         bool left_line;
334         bool right_line;
335         int  width_of_column;
336         string p_width;
337         string align_special;
338     };
339     typedef std::vector<columnstruct> column_vector;
340
341     ///
342     int rows_;
343     ///
344     int columns_;
345     ///
346     int numberofcells;
347     ///
348     int * rowofcell;
349     ///
350     int * columnofcell;
351     ///
352     row_vector row_info;
353     ///
354     column_vector column_info;
355     ///
356     mutable cell_vvector cell_info;
357     ///
358     int width_of_tabular;
359     ///
360     /// for long tabulars
361     ///
362     int endhead; // row of endhead
363     int endfirsthead; // row of endfirsthead
364     int endfoot; // row of endfoot
365     int endlastfoot; // row of endlastfoot
366     ///
367     InsetTabular * owner_;
368    
369     ///
370     void Init(int columns_arg, int rows_arg);
371     ///
372     void Reinit();
373     ///
374     void set_row_column_number_info();
375     /// Returns true if a complete update is necessary, otherwise false
376     bool SetWidthOfMulticolCell(int cell, int new_width);
377     void recalculateMulticolCells(int cell, int new_width);
378     /// Returns true if change
379     bool calculate_width_of_column(int column);
380     bool calculate_width_of_column_NMC(int column); // no multi cells
381     ///
382     void calculate_width_of_tabular();
383
384     ///
385     cellstruct * cellinfo_of_cell(int cell) const;
386
387     ///
388     void delete_column(int column);
389
390     ///
391     int cells_in_multicolumn(int cell) const;
392     ///
393     int is_long_tabular;
394     ///
395     int rotate;
396 };
397
398 #endif