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