]> git.lyx.org Git - lyx.git/blob - src/tabular.h
Fix small bug in reading \set_color in lyxrc
[lyx.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 #include "insets/insettext.h"
23
24 class InsetTabular;
25 class LaTeXFeatures;
26 class Buffer;
27
28 /* The features the text class offers for tables */ 
29
30 ///
31 class LyXTabular  {
32 public:
33
34     enum {
35         APPEND_ROW = 0,
36         APPEND_COLUMN,
37         DELETE_ROW,
38         DELETE_COLUMN,
39         TOGGLE_LINE_TOP,
40         TOGGLE_LINE_BOTTOM,
41         TOGGLE_LINE_LEFT,
42         TOGGLE_LINE_RIGHT,
43         ALIGN_LEFT,
44         ALIGN_RIGHT,
45         ALIGN_CENTER,
46         VALIGN_TOP,
47         VALIGN_BOTTOM,
48         VALIGN_CENTER,
49         M_TOGGLE_LINE_TOP,
50         M_TOGGLE_LINE_BOTTOM,
51         M_TOGGLE_LINE_LEFT,
52         M_TOGGLE_LINE_RIGHT,
53         M_ALIGN_LEFT,
54         M_ALIGN_RIGHT,
55         M_ALIGN_CENTER,
56         M_VALIGN_TOP,
57         M_VALIGN_BOTTOM,
58         M_VALIGN_CENTER,
59         DELETE_TABULAR,
60         MULTICOLUMN,
61         SET_ALL_LINES,
62         UNSET_ALL_LINES,
63         SET_LONGTABULAR,
64         UNSET_LONGTABULAR,
65         SET_PWIDTH,
66         SET_MPWIDTH,
67         SET_ROTATE_TABULAR,
68         UNSET_ROTATE_TABULAR,
69         SET_ROTATE_CELL,
70         UNSET_ROTATE_CELL,
71         SET_LINEBREAKS,
72         SET_LTHEAD,
73         SET_LTFIRSTHEAD,
74         SET_LTFOOT,
75         SET_LTLASTFOOT,
76         SET_LTNEWPAGE,
77         SET_SPECIAL_COLUMN,
78         SET_SPECIAL_MULTI
79     };
80
81     enum {
82         CELL_NORMAL = 0,
83         CELL_BEGIN_OF_MULTICOLUMN,
84         CELL_PART_OF_MULTICOLUMN
85     };
86
87     ///
88     enum VAlignment {
89         ///
90         LYX_VALIGN_TOP = 0,
91         ///
92         LYX_VALIGN_BOTTOM = 1,
93         ///
94         LYX_VALIGN_CENTER = 2
95     };
96
97     /* konstruktor */
98     ///
99     LyXTabular(InsetTabular *, int columns_arg, int rows_arg);
100     ///
101     ///
102     LyXTabular(InsetTabular *, LyXTabular const &);
103     ///
104     explicit
105     LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
106     ///
107     ~LyXTabular();
108     ///
109     LyXTabular & operator=(LyXTabular const &);
110     ///
111     LyXTabular * Clone(InsetTabular *);
112     
113     /// Returns true if there is a topline, returns false if not
114     bool TopLine(int cell, bool onlycolumn=false) const;
115     /// Returns true if there is a topline, returns false if not
116     bool BottomLine(int cell, bool onlycolumn=false) const;
117     /// Returns true if there is a topline, returns false if not
118     bool LeftLine(int cell, bool onlycolumn=false) const;
119     /// Returns true if there is a topline, returns false if not
120     bool RightLine(int cell, bool onlycolumn=false) const;
121     
122     ///
123     bool TopAlreadyDrawed(int cell) const;
124     ///
125     bool LeftAlreadyDrawed(int cell) const;
126     ///
127     bool IsLastRow(int cell) const;
128     
129     ///
130     int GetAdditionalHeight(int cell) const;
131     ///
132     int GetAdditionalWidth(int cell) const;
133     
134     /* returns the maximum over all rows */
135     ///
136     int GetWidthOfColumn(int cell) const;
137     ///
138     int GetWidthOfTabular() const;
139     ///
140     int GetAscentOfRow(int row) const;
141     ///
142     int GetDescentOfRow(int row) const;
143     ///
144     int GetHeightOfTabular() const;
145     /// Returns true if a complete update is necessary, otherwise false
146     bool SetAscentOfRow(int row, int height);
147     /// Returns true if a complete update is necessary, otherwise false
148     bool SetDescentOfRow(int row, int height);
149     /// Returns true if a complete update is necessary, otherwise false
150     bool SetWidthOfCell(int cell, int new_width);
151     /// Returns true if a complete update is necessary, otherwise false
152     bool SetAllLines(int cell, bool line);
153     /// Returns true if a complete update is necessary, otherwise false
154     bool SetTopLine(int cell, bool line, bool onlycolumn=false);
155     /// Returns true if a complete update is necessary, otherwise false
156     bool SetBottomLine(int cell, bool line, bool onlycolumn=false);
157     /// Returns true if a complete update is necessary, otherwise false
158     bool SetLeftLine(int cell, bool line, bool onlycolumn=false);
159     /// Returns true if a complete update is necessary, otherwise false
160     bool SetRightLine(int cell, bool line, bool onlycolumn=false);
161     /// Returns true if a complete update is necessary, otherwise false
162     bool SetAlignment(int cell, char align, bool onlycolumn = false);
163     /// Returns true if a complete update is necessary, otherwise false
164     bool SetVAlignment(int cell, char align, bool onlycolumn = false);
165     ///
166     bool SetColumnPWidth(int cell, string const & width);
167     ///
168     bool SetMColumnPWidth(int cell, string const & width);
169     ///
170     bool SetAlignSpecial(int cell, string const & special, int what);
171     ///
172     char GetAlignment(int cell, bool onlycolumn = false) const;
173     ///
174     char GetVAlignment(int cell, bool onlycolumn = false) const;
175     ///
176     string GetPWidth(int cell) const;
177     ///
178     string GetColumnPWidth(int cell) const;
179     ///
180     string GetMColumnPWidth(int cell) const;
181     ///
182     string GetAlignSpecial(int cell, int what) const;
183     ///
184     int GetWidthOfCell(int cell) const;
185     ///
186     int GetBeginningOfTextInCell(int cell) const;
187     ///
188     void AppendRow(int cell);
189     ///
190     void DeleteRow(int cell);
191     ///
192     void AppendColumn(int cell);
193     ///
194     void DeleteColumn(int cell);
195     ///
196     bool IsFirstCellInRow(int cell) const;
197     ///
198     int GetFirstCellInRow(int row) const;
199     ///
200     bool IsLastCellInRow(int cell) const;
201     ///
202     int GetLastCellInRow(int row) const;
203     ///
204     int GetNumberOfCells() const;
205     ///
206     int NumberOfCellsInRow(int cell) const;
207     ///
208     void Write(Buffer const *, std::ostream &) const;
209     ///
210     void Read(Buffer const *, LyXLex &);
211     ///
212     void OldFormatRead(LyXLex &, string const &);
213     ///
214     /// helper function for Latex returns number of newlines
215     ///
216     int TeXTopHLine(std::ostream &, int row) const;
217     int TeXBottomHLine(std::ostream &, int row) const;
218     int TeXCellPreamble(std::ostream &, int cell) const;
219     int TeXCellPostamble(std::ostream &, int cell) const;
220     ///
221     int Latex(Buffer const *, std::ostream &, bool, bool) const;
222     ///
223     int DocBookEndOfCell(std::ostream &, int cell, int & depth) const;
224 #if 0
225     ///
226     int RoffEndOfCell(std::ostream &, int cell);
227 #endif
228     ///
229     char const * GetDocBookAlign(int cell, bool isColumn = false) const;
230
231     ///
232     bool IsMultiColumn(int cell) const;
233     ///
234     void SetMultiColumn(int cell, int number);
235     ///
236     int UnsetMultiColumn(int cell); // returns number of new cells
237     ///
238     bool IsPartOfMultiColumn(int row, int column) const;
239     ///
240     int row_of_cell(int cell) const;
241     ///
242     int column_of_cell(int cell) const;
243     ///
244     int right_column_of_cell(int cell) const;
245     ///
246     void SetLongTabular(int what);
247     ///
248     bool IsLongTabular() const;
249     ///
250     void SetRotateTabular(int what);
251     ///
252     bool GetRotateTabular() const;
253     ///
254     void SetRotateCell(int cell, int what);
255     ///
256     bool GetRotateCell(int cell) const;
257     ///
258     bool NeedRotating() const;
259     ///
260     bool IsLastCell(int cell) const;
261     ///
262     int GetCellAbove(int cell) const;
263     ///
264     int GetCellBelow(int cell) const;
265     ///
266     int GetLastCellAbove(int cell) const;
267     ///
268     int GetLastCellBelow(int cell) const;
269     ///
270     int GetCellNumber(int row, int column) const;
271     ///
272     void SetLinebreaks(int cell, bool what);
273     ///
274     bool GetLinebreaks(int cell) const;
275     ///
276     /// Long Tabular Options
277     ///
278     void SetLTHead(int cell, bool first);
279     ///
280     bool GetRowOfLTHead(int cell, int & row) const;
281     ///
282     bool GetRowOfLTFirstHead(int cell, int & row) const;
283     ///
284     void SetLTFoot(int cell, bool last);
285     ///
286     bool GetRowOfLTFoot(int cell, int & row) const;
287     ///
288     bool GetRowOfLTLastFoot(int cell, int & row) const;
289     ///
290     void SetLTNewPage(int cell, bool what);
291     ///
292     bool GetLTNewPage(int cell) const;
293     ///
294     InsetText * GetCellInset(int cell) const;
295     ///
296     int rows() const { return rows_; }
297     ///
298     int columns() const { return columns_;}
299     ///
300     InsetTabular * owner() const { return owner_; }
301     ///
302     void Validate(LaTeXFeatures &) const;
303
304 private: //////////////////////////////////////////////////////////////////
305     ///
306     struct cellstruct {
307         ///
308         cellstruct();
309         ///
310 #ifdef INSET_POINTER
311         ~cellstruct();
312         ///
313         cellstruct(cellstruct const &);
314         ///
315         cellstruct & operator=(cellstruct const &);
316 #endif
317         ///
318         int cellno;
319         ///
320         int width_of_cell;
321         ///
322         int multicolumn;
323         ///
324         int alignment;
325         ///
326         int valignment;
327         ///
328         bool top_line;
329         ///
330         bool bottom_line;
331         ///
332         bool left_line;
333         ///
334         bool right_line;
335         ///
336         bool linebreaks;
337         ///
338         int rotate;
339         ///
340         string align_special;
341         ///
342         string p_width; // this is only set for multicolumn!!!
343         ///
344         InsetText inset;
345     };
346     typedef std::vector<cellstruct> cell_vector;
347     typedef std::vector<cell_vector> cell_vvector;
348
349     ///
350     struct rowstruct {
351         ///
352         rowstruct();
353         ///
354             //~rowstruct();
355         ///
356             // rowstruct & operator=(rowstruct const &);
357         ///
358         bool top_line;
359         bool bottom_line;
360         int ascent_of_row;
361         int descent_of_row;
362         /// This are for longtabulars only
363         bool newpage;
364     };
365     typedef std::vector<rowstruct> row_vector;
366
367     ///
368     struct columnstruct {
369         ///
370         columnstruct();
371         ///
372             //~columnstruct();
373         ///
374             //columnstruct & operator=(columnstruct const &);
375         ///
376         int alignment;
377         int valignment;
378         bool left_line;
379         bool right_line;
380         int  width_of_column;
381         string p_width;
382         string align_special;
383     };
384     typedef std::vector<columnstruct> column_vector;
385
386     ///
387     int rows_;
388     ///
389     int columns_;
390     ///
391     int numberofcells;
392     ///
393     int * rowofcell;
394     ///
395     int * columnofcell;
396     ///
397     row_vector row_info;
398     ///
399     column_vector column_info;
400     ///
401     mutable cell_vvector cell_info;
402     ///
403     int width_of_tabular;
404     ///
405     /// for long tabulars
406     ///
407     int endhead; // row of endhead
408     int endfirsthead; // row of endfirsthead
409     int endfoot; // row of endfoot
410     int endlastfoot; // row of endlastfoot
411     ///
412     InsetTabular * owner_;
413    
414     ///
415     void Init(int columns_arg, int rows_arg);
416     ///
417     void Reinit();
418     ///
419     void set_row_column_number_info();
420     /// Returns true if a complete update is necessary, otherwise false
421     bool SetWidthOfMulticolCell(int cell, int new_width);
422     void recalculateMulticolCells(int cell, int new_width);
423     /// Returns true if change
424     bool calculate_width_of_column(int column);
425     bool calculate_width_of_column_NMC(int column); // no multi cells
426     ///
427     void calculate_width_of_tabular();
428
429     ///
430     cellstruct * cellinfo_of_cell(int cell) const;
431
432     ///
433     void delete_column(int column);
434
435     ///
436     int cells_in_multicolumn(int cell) const;
437     ///
438     int is_long_tabular;
439     ///
440     int rotate;
441 };
442
443 #endif