2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000 The LyX Team.
9 * ====================================================== */
22 #include "insets/insettext.h"
28 /* The features the text class offers for tables */
83 CELL_BEGIN_OF_MULTICOLUMN,
84 CELL_PART_OF_MULTICOLUMN
92 LYX_VALIGN_BOTTOM = 1,
99 LyXTabular(InsetTabular *, int columns_arg, int rows_arg);
102 LyXTabular(InsetTabular *, LyXTabular const &);
105 LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
109 LyXTabular & operator=(LyXTabular const &);
111 LyXTabular * Clone(InsetTabular *);
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;
123 bool TopAlreadyDrawed(int cell) const;
125 bool LeftAlreadyDrawed(int cell) const;
127 bool IsLastRow(int cell) const;
130 int GetAdditionalHeight(int cell) const;
132 int GetAdditionalWidth(int cell) const;
134 /* returns the maximum over all rows */
136 int GetWidthOfColumn(int cell) const;
138 int GetWidthOfTabular() const;
140 int GetAscentOfRow(int row) const;
142 int GetDescentOfRow(int row) const;
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);
166 bool SetColumnPWidth(int cell, string const & width);
168 bool SetMColumnPWidth(int cell, string const & width);
170 bool SetAlignSpecial(int cell, string const & special, int what);
172 char GetAlignment(int cell, bool onlycolumn = false) const;
174 char GetVAlignment(int cell, bool onlycolumn = false) const;
176 string GetPWidth(int cell) const;
178 string GetColumnPWidth(int cell) const;
180 string GetMColumnPWidth(int cell) const;
182 string GetAlignSpecial(int cell, int what) const;
184 int GetWidthOfCell(int cell) const;
186 int GetBeginningOfTextInCell(int cell) const;
188 void AppendRow(int cell);
190 void DeleteRow(int cell);
192 void AppendColumn(int cell);
194 void DeleteColumn(int cell);
196 bool IsFirstCellInRow(int cell) const;
198 int GetFirstCellInRow(int row) const;
200 bool IsLastCellInRow(int cell) const;
202 int GetLastCellInRow(int row) const;
204 int GetNumberOfCells() const;
206 int NumberOfCellsInRow(int cell) const;
208 void Write(Buffer const *, std::ostream &) const;
210 void Read(Buffer const *, LyXLex &);
212 void OldFormatRead(LyXLex &, string const &);
214 /// helper function for Latex returns number of newlines
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;
221 int Latex(Buffer const *, std::ostream &, bool, bool) const;
223 int DocBookEndOfCell(std::ostream &, int cell, int & depth) const;
226 int RoffEndOfCell(std::ostream &, int cell);
229 char const * GetDocBookAlign(int cell, bool isColumn = false) const;
232 bool IsMultiColumn(int cell) const;
234 void SetMultiColumn(int cell, int number);
236 int UnsetMultiColumn(int cell); // returns number of new cells
238 bool IsPartOfMultiColumn(int row, int column) const;
240 int row_of_cell(int cell) const;
242 int column_of_cell(int cell) const;
244 int right_column_of_cell(int cell) const;
246 void SetLongTabular(int what);
248 bool IsLongTabular() const;
250 void SetRotateTabular(int what);
252 bool GetRotateTabular() const;
254 void SetRotateCell(int cell, int what);
256 bool GetRotateCell(int cell) const;
258 bool NeedRotating() const;
260 bool IsLastCell(int cell) const;
262 int GetCellAbove(int cell) const;
264 int GetCellBelow(int cell) const;
266 int GetLastCellAbove(int cell) const;
268 int GetLastCellBelow(int cell) const;
270 int GetCellNumber(int row, int column) const;
272 void SetLinebreaks(int cell, bool what);
274 bool GetLinebreaks(int cell) const;
276 /// Long Tabular Options
278 void SetLTHead(int cell, bool first);
280 bool GetRowOfLTHead(int cell, int & row) const;
282 bool GetRowOfLTFirstHead(int cell, int & row) const;
284 void SetLTFoot(int cell, bool last);
286 bool GetRowOfLTFoot(int cell, int & row) const;
288 bool GetRowOfLTLastFoot(int cell, int & row) const;
290 void SetLTNewPage(int cell, bool what);
292 bool GetLTNewPage(int cell) const;
294 InsetText * GetCellInset(int cell) const;
296 int rows() const { return rows_; }
298 int columns() const { return columns_;}
300 InsetTabular * owner() const { return owner_; }
302 void Validate(LaTeXFeatures &) const;
304 private: //////////////////////////////////////////////////////////////////
313 cellstruct(cellstruct const &);
315 cellstruct & operator=(cellstruct const &);
340 string align_special;
342 string p_width; // this is only set for multicolumn!!!
346 typedef std::vector<cellstruct> cell_vector;
347 typedef std::vector<cell_vector> cell_vvector;
356 // rowstruct & operator=(rowstruct const &);
362 /// This are for longtabulars only
365 typedef std::vector<rowstruct> row_vector;
368 struct columnstruct {
374 //columnstruct & operator=(columnstruct const &);
382 string align_special;
384 typedef std::vector<columnstruct> column_vector;
399 column_vector column_info;
401 mutable cell_vvector cell_info;
403 int width_of_tabular;
405 /// for long tabulars
407 int endhead; // row of endhead
408 int endfirsthead; // row of endfirsthead
409 int endfoot; // row of endfoot
410 int endlastfoot; // row of endlastfoot
412 InsetTabular * owner_;
415 void Init(int columns_arg, int rows_arg);
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
427 void calculate_width_of_tabular();
430 cellstruct * cellinfo_of_cell(int cell) const;
433 void delete_column(int column);
436 int cells_in_multicolumn(int cell) const;