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