]> git.lyx.org Git - features.git/blob - src/tabular.h
Commiting my changes till now. Mainly (only?) changes to make text-insets 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
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);
72     ///
73     ///
74     LyXTabular(LyXTabular const &, Buffer *buf);
75     ///
76     explicit
77     LyXTabular(LyXLex & lex, Buffer *buf);
78     ///
79     ~LyXTabular();
80     ///
81     LyXTabular & operator=(LyXTabular const &);
82     ///
83     LyXTabular * Clone(Buffer * buf);
84     
85     /// Returns true if there is a topline, returns false if not
86     bool TopLine(int cell) const;
87     /// Returns true if there is a topline, returns false if not
88     bool BottomLine(int cell) const;
89     /// Returns true if there is a topline, returns false if not
90     bool LeftLine(int cell) const;
91     /// Returns true if there is a topline, returns false if not
92     bool RightLine(int cell) const;
93     
94     ///
95     bool TopAlreadyDrawed(int cell) const;
96     ///
97     bool LeftAlreadyDrawed(int cell) const;
98     ///
99     bool IsLastRow(int cell) const;
100     
101     ///
102     int GetAdditionalHeight(int cell) const;
103     ///
104     int GetAdditionalWidth(int cell) const;
105     
106     /* returns the maximum over all rows */
107     ///
108     int GetWidthOfColumn(int cell) const;
109     ///
110     int GetWidthOfTabular() const;
111     ///
112     int GetAscentOfRow(int row) const;
113     ///
114     int GetDescentOfRow(int row) const;
115     ///
116     int GetHeightOfTabular() const;
117     ///
118     void SetAscentOfRow(int row, int height);
119     ///
120     void SetDescentOfRow(int row, int height);
121     /// Returns true if a complete update is necessary, otherwise false
122     bool SetWidthOfCell(int cell, int new_width);
123     /// Returns true if a complete update is necessary, otherwise false
124     bool SetAllLines(int cell, bool line);
125     /// Returns true if a complete update is necessary, otherwise false
126     bool SetTopLine(int cell, bool line);
127     /// Returns true if a complete update is necessary, otherwise false
128     bool SetBottomLine(int cell, bool line);
129     /// Returns true if a complete update is necessary, otherwise false
130     bool SetLeftLine(int cell, bool line);
131     /// Returns true if a complete update is necessary, otherwise false
132     bool SetRightLine(int cell, bool line);
133     /// Returns true if a complete update is necessary, otherwise false
134     bool SetAlignment(int cell, char align);
135     ///
136     bool SetPWidth(int cell, string width);
137     ///
138     bool SetAlignSpecial(int cell, string special, int what);
139     ///
140     char GetAlignment(int cell) const; // add approp. signedness
141     ///
142     string GetPWidth(int cell) const;
143     ///
144     string GetAlignSpecial(int cell, int what) const;
145     ///
146     int GetWidthOfCell(int cell) const;
147     ///
148     int GetBeginningOfTextInCell(int cell) const;
149     ///
150     void AppendRow(int cell);
151     ///
152     void DeleteRow(int cell);
153     ///
154     void AppendColumn(int cell);
155     ///
156     void DeleteColumn(int cell);
157     ///
158     bool IsFirstCellInRow(int cell) const;
159     ///
160     bool IsLastCellInRow(int cell) const;
161     ///
162     int GetNumberOfCells() const;
163     ///
164     int AppendCellAfterCell(int append_cell, int question_cell);
165     ///
166     int DeleteCellIfColumnIsDeleted(int cell, int delete_column_cell);
167     ///
168     int NumberOfCellsInRow(int cell) const;
169     ///
170     void Reinit();
171     ///
172     void Init(int columns_arg, int rows_arg);
173     ///
174     void Write(std::ostream &) const;
175     ///
176     void Read(LyXLex &);
177     ///
178     void OldFormatRead(std::istream &, string);
179     ///
180     int Latex(std::ostream &) const;
181
182     // cell <0 will tex the preamble
183     // returns the number of printed newlines
184     ///
185     int TexEndOfCell(std::ostream &, int cell) 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     void SetLongTabular(int what);
209     ///
210     bool IsLongTabular() const;
211     ///
212     void SetRotateTabular(int what);
213     ///
214     bool GetRotateTabular() const;
215     ///
216     void SetRotateCell(int cell, int what);
217     ///
218     bool GetRotateCell(int cell) const;
219     ///
220     bool NeedRotating() const;
221     ///
222     bool IsLastCell(int cell) const;
223     ///
224     int GetCellAbove(int cell) const;
225     ///
226     int GetCellNumber(int column, int row) const;
227     ///
228     void SetLinebreaks(int cell, bool what);
229     ///
230     bool GetLinebreaks(int cell) const;
231     ///
232     /// Long Tabular Options
233     ///
234     void SetLTHead(int cell, bool first);
235     ///
236     bool GetRowOfLTHead(int cell) const;
237     ///
238     bool GetRowOfLTFirstHead(int cell) const;
239     ///
240     void SetLTFoot(int cell, bool last);
241     ///
242     bool GetRowOfLTFoot(int cell) const;
243     ///
244     bool GetRowOfLTLastFoot(int cell) const;
245     ///
246     void SetLTNewPage(int cell, bool what);
247     ///
248     bool GetLTNewPage(int cell) const;
249     ///
250     InsetText * GetCellInset(int cell) const;
251     ///
252     int rows() const { return rows_; }
253     ///
254     int columns() const { return columns_;}
255
256 private: //////////////////////////////////////////////////////////////////
257     ///
258     struct cellstruct {
259         ///
260         cellstruct(Buffer * buf);
261         ///
262         ~cellstruct();
263         ///
264         cellstruct & operator=(cellstruct const &);
265         ///
266         int cellno;
267         ///
268         int width_of_cell;
269         ///
270         int  multicolumn; // add approp. signedness
271         ///
272         int alignment; // add approp. signedness
273         ///
274         bool top_line;
275         ///
276         bool bottom_line;
277         ///
278         bool linebreaks;
279         ///
280         int rotate;
281         ///
282         string align_special;
283         ///
284         string p_width; // this is only set for multicolumn!!!
285         ///
286         InsetText *inset;
287     };
288     ///
289     struct rowstruct {
290         ///
291         rowstruct();
292         ///
293         ~rowstruct();
294         ///
295         rowstruct & operator=(rowstruct const &);
296         ///
297         bool top_line;
298         bool bottom_line;
299         int ascent_of_row;
300         int descent_of_row;
301         /// This are for longtabulars only
302         bool newpage;
303     };
304     ///
305     struct columnstruct {
306         ///
307         columnstruct();
308         ///
309         ~columnstruct();
310         ///
311         columnstruct & operator=(columnstruct const &);
312         ///
313         int alignment; // add approp. signedness
314         bool left_line;
315         bool right_line;
316         int  width_of_column;
317         string p_width;
318         string align_special;
319     };
320     ///
321     int rows_;
322     ///
323     int columns_;
324     ///
325     int numberofcells;
326     ///
327     int * rowofcell;
328     ///
329     int * columnofcell;
330     ///
331     rowstruct * row_info;
332     ///
333     columnstruct * column_info;
334     ///
335     cellstruct ** cell_info;
336     ///
337     int width_of_tabular;
338     ///
339     /// for long tabulars
340     ///
341     int endhead; // row of endhead
342     int endfirsthead; // row of endfirsthead
343     int endfoot; // row of endfoot
344     int endlastfoot; // row of endlastfoot
345     ///
346     Buffer *buffer;
347    
348     ///
349     void set_row_column_number_info();
350     /// Returns true if a complete update is necessary, otherwise false
351     bool SetWidthOfMulticolCell(int cell, int new_width);
352     void recalculateMulticolCells(int cell, int new_width);
353     /// Returns true if change
354     bool calculate_width_of_column(int column);
355     bool calculate_width_of_column_NMC(int column); // no multi cells
356     ///
357     void calculate_width_of_tabular();
358
359     ///
360     int right_column_of_cell(int cell) const;
361
362     ///
363     cellstruct * cellinfo_of_cell(int cell) const;
364
365     ///
366     void delete_column(int column);
367
368     ///
369     int cells_in_multicolumn(int cell) const;
370     ///
371     int is_long_tabular;
372     ///
373     int rotate;
374 };
375
376 #endif