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