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