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