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