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