]> git.lyx.org Git - features.git/blob - src/table.h
clear()->erase() ; lots of using directives for cxx
[features.git] / src / table.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor
6  *       
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2000 The LyX Team.
9  *
10  * ====================================================== */
11 #ifndef TABLE_H
12 #define TABLE_H
13
14 #ifdef __GNUG__
15 #pragma interface
16 #endif
17
18 #include <iosfwd>
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 LyXTable  {
30 public:
31     // Are the values of these enums important? (Lgb)
32     enum {
33         APPEND_ROW = 0,
34         APPEND_COLUMN = 1,
35         DELETE_ROW = 2,
36         DELETE_COLUMN = 3,
37         TOGGLE_LINE_TOP = 4,
38         TOGGLE_LINE_BOTTOM = 5,
39         TOGGLE_LINE_LEFT = 6,
40         TOGGLE_LINE_RIGHT = 7,
41         ALIGN_LEFT = 8, // what are these alignment enums used for?
42         ALIGN_RIGHT = 9,
43         ALIGN_CENTER = 10,
44         DELETE_TABLE = 11,
45         MULTICOLUMN = 12,
46         SET_ALL_LINES = 13,
47         UNSET_ALL_LINES = 14,
48         SET_LONGTABLE = 15,
49         UNSET_LONGTABLE = 16,
50         SET_PWIDTH = 17,
51         APPEND_CONT_ROW = 18,
52         SET_ROTATE_TABLE = 19,
53         UNSET_ROTATE_TABLE = 20,
54         SET_ROTATE_CELL = 21,
55         UNSET_ROTATE_CELL = 22,
56         SET_LINEBREAKS = 23,
57         SET_LTHEAD = 24,
58         SET_LTFIRSTHEAD = 25,
59         SET_LTFOOT = 26,
60         SET_LTLASTFOOT = 27,
61         SET_LTNEWPAGE = 28,
62         SET_SPECIAL_COLUMN = 29,
63         SET_SPECIAL_MULTI = 30
64     };
65
66     enum {
67         CELL_NORMAL = 0,
68         CELL_BEGIN_OF_MULTICOLUMN = 1,
69         CELL_PART_OF_MULTICOLUMN = 2
70     };
71     /* konstruktor */
72     ///
73     LyXTable(int columns_arg, int rows_arg, Buffer *buf = 0);
74     ///
75     ///
76     LyXTable(LyXTable const &, Buffer *buf = 0);
77     ///
78     explicit
79     LyXTable(LyXLex & lex, Buffer *buf = 0);
80     ///
81     ~LyXTable();
82     ///
83     LyXTable & operator=(LyXTable const &);
84     ///
85     LyXTable * Clone();
86     
87     /// Returns true if there is a topline, returns false if not
88     bool TopLine(int cell);
89     /// Returns true if there is a topline, returns false if not
90     bool BottomLine(int cell);
91     /// Returns true if there is a topline, returns false if not
92     bool LeftLine(int cell);
93     /// Returns true if there is a topline, returns false if not
94     bool RightLine(int cell);
95     
96     ///
97     bool TopAlreadyDrawed(int cell);
98     ///
99     bool VeryLastRow(int cell);
100     
101     ///
102     int AdditionalHeight(int cell);
103     ///
104     int AdditionalWidth(int cell);
105     
106     /* returns the maximum over all rows */
107     ///
108     int WidthOfColumn(int cell);
109     ///
110     int WidthOfTable();
111     ///
112     int AscentOfRow(int row);
113     ///
114     int DescentOfRow(int row);
115     ///
116     int HeightOfTable();
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); // add approp. signedness
141     ///
142     string GetPWidth(int cell);
143     ///
144     string GetAlignSpecial(int cell, int what);
145     
146     ///
147     int GetWidthOfCell(int cell);
148     ///
149     int GetBeginningOfTextInCell(int cell);
150     
151     ///
152     void AppendRow(int cell);
153     ///
154     void DeleteRow(int cell);
155     
156     ///
157     void AppendColumn(int cell);
158     ///
159     void DeleteColumn(int cell);
160     
161     ///
162     bool IsFirstCell(int cell);
163     ///
164     bool IsLastCell(int cell);
165     
166     ///
167     int GetNumberOfCells();
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);
174     ///
175     void Reinit();
176
177         ///
178     void Init(int columns_arg, int rows_arg);
179
180     ///
181     void Write(std::ostream &, bool old_format=true);
182     ///
183     void Read(std::istream &);
184     ///
185     int Latex(std::ostream &);
186
187     // cell <0 will tex the preamble
188     // returns the number of printed newlines
189     ///
190     int TexEndOfCell(std::ostream &, int cell);
191     ///
192     int DocBookEndOfCell(std::ostream &, int cell, int & depth);
193 #if 0
194     ///
195     int RoffEndOfCell(std::ostream &, int cell);
196 #endif
197     ///
198     char const * getDocBookAlign(int cell, bool isColumn = false);
199
200     ///
201     bool IsMultiColumn(int cell);
202     ///
203     void SetMultiColumn(int cell, int number);
204     ///
205     int UnsetMultiColumn(int cell); // returns number of new cells
206     ///
207     bool IsPartOfMultiColumn(int row, int column);
208     ///
209     int row_of_cell(int cell) const;
210     ///
211     int column_of_cell(int cell) const;
212     ///
213     int rows;
214     ///
215     int columns;
216     ///
217     void SetLongTable(int what);
218     ///
219     bool IsLongTable();
220     ///
221     void SetRotateTable(int what);
222     ///
223     bool RotateTable();
224     ///
225     void SetRotateCell(int cell, int what);
226     ///
227     bool RotateCell(int cell);
228     ///
229     bool NeedRotating();
230     ///
231     void AppendContRow(int cell);
232     ///
233     bool IsContRow(int cell);
234     /// returns the number of the cell which continues
235     /// or -1 if no ContRow
236     int CellHasContRow(int cell);
237     ///
238     bool RowHasContRow(int cell);
239     ///
240     int FirstVirtualCell(int cell);
241     ///
242     int NextVirtualCell(int cell);
243     ///
244     bool ShouldBeVeryLastCell(int cell);
245     ///
246     bool ShouldBeVeryLastRow(int cell);
247     ///
248     int GetCellAbove(int cell);
249     ///
250     int GetCellNumber(int column, int row);
251     ///
252     void SetLinebreaks(int cell, bool what);
253     ///
254     bool Linebreaks(int cell);
255     ///
256     /// Long Table Options
257     ///
258     void SetLTHead(int cell, bool first);
259     ///
260     bool RowOfLTHead(int cell);
261     ///
262     bool RowOfLTFirstHead(int cell);
263     ///
264     void SetLTFoot(int cell, bool last);
265     ///
266     bool RowOfLTFoot(int cell);
267     ///
268     bool RowOfLTLastFoot(int cell);
269     ///
270     void SetLTNewPage(int cell, bool what);
271     ///
272     bool LTNewPage(int cell);
273     ///
274     InsetText * GetCellInset(int cell) const;
275     ///
276
277 private: //////////////////////////////////////////////////////////////////
278     ///
279     struct cellstruct {
280         ///
281         cellstruct(Buffer * buf = 0);
282         ///
283         ~cellstruct();
284         ///
285         cellstruct & operator=(cellstruct const &);
286         ///
287         void setBuffer(Buffer * buf);
288         ///
289         int cellno;
290         ///
291         int width_of_cell;
292         ///
293         int  multicolumn; // add approp. signedness
294         ///
295         int alignment; // add approp. signedness
296         ///
297         bool top_line;
298         ///
299         bool bottom_line;
300         ///
301         bool has_cont_row;
302         ///
303         bool linebreaks;
304         ///
305         int rotate;
306         ///
307         string align_special;
308         ///
309         string p_width; // this is only set for multicolumn!!!
310         ///
311         InsetText *inset;
312     };
313     ///
314     struct rowstruct {
315         ///
316         rowstruct();
317         ///
318         ~rowstruct();
319         ///
320         rowstruct & operator=(rowstruct const &);
321         ///
322         bool top_line;
323         bool bottom_line;
324         bool is_cont_row;
325         int ascent_of_row;
326         int descent_of_row;
327         /// This are for longtables only
328         bool newpage;
329     };
330     ///
331     struct columnstruct {
332         ///
333         columnstruct();
334         ///
335         ~columnstruct();
336         ///
337         columnstruct & operator=(columnstruct const &);
338         ///
339         int alignment; // add approp. signedness
340         bool left_line;
341         bool right_line;
342         int  width_of_column;
343         string p_width;
344         string align_special;
345     };
346     ///
347     int numberofcells;
348     ///
349     int * rowofcell;
350     ///
351     int * columnofcell;
352     ///
353     rowstruct * row_info;
354     ///
355     columnstruct * column_info;
356     ///
357     cellstruct ** cell_info;
358     ///
359     int width_of_table;
360     ///
361     /// for long tables
362     ///
363     int endhead; // row of endhead
364     int endfirsthead; // row of endfirsthead
365     int endfoot; // row of endfoot
366     int endlastfoot; // row of endlastfoot
367     ///
368     Buffer *buffer;
369    
370     ///
371     void set_row_column_number_info();
372     /// Returns true if a complete update is necessary, otherwise false
373     bool SetWidthOfMulticolCell(int cell, int new_width);
374     void recalculateMulticolCells(int cell, int new_width);
375     /// Returns true if change
376     bool calculate_width_of_column(int column);
377     bool calculate_width_of_column_NMC(int column); // no multi cells
378     ///
379     void calculate_width_of_table();
380
381     ///
382     int right_column_of_cell(int cell);
383
384     ///
385     cellstruct * cellinfo_of_cell(int cell);
386
387     ///
388     void delete_column(int column);
389
390     ///
391     int cells_in_multicolumn(int cell);
392     ///
393     int is_long_table;
394     ///
395     int rotate;
396 };
397
398 #endif