2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000 The LyX Team.
9 * @author: Jürgen Vigna
11 * ====================================================== */
24 #include "insets/insettext.h"
30 /* The features the text class offers for tables */
102 UNSET_ROTATE_TABULAR,
131 CELL_BEGIN_OF_MULTICOLUMN,
133 CELL_PART_OF_MULTICOLUMN
141 LYX_VALIGN_BOTTOM = 1,
143 LYX_VALIGN_CENTER = 2
157 LyXTabular(InsetTabular *, int columns_arg, int rows_arg);
159 LyXTabular(InsetTabular *, LyXTabular const &);
162 LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
166 LyXTabular & operator=(LyXTabular const &);
168 LyXTabular * Clone(InsetTabular *);
170 /// Returns true if there is a topline, returns false if not
171 bool TopLine(int cell, bool onlycolumn=false) const;
172 /// Returns true if there is a topline, returns false if not
173 bool BottomLine(int cell, bool onlycolumn=false) const;
174 /// Returns true if there is a topline, returns false if not
175 bool LeftLine(int cell, bool onlycolumn=false) const;
176 /// Returns true if there is a topline, returns false if not
177 bool RightLine(int cell, bool onlycolumn=false) const;
180 bool TopAlreadyDrawed(int cell) const;
182 bool LeftAlreadyDrawed(int cell) const;
184 bool IsLastRow(int cell) const;
187 int GetAdditionalHeight(int cell) const;
189 int GetAdditionalWidth(int cell) const;
191 /* returns the maximum over all rows */
193 int GetWidthOfColumn(int cell) const;
195 int GetWidthOfTabular() const;
197 int GetAscentOfRow(int row) const;
199 int GetDescentOfRow(int row) const;
201 int GetHeightOfTabular() const;
202 /// Returns true if a complete update is necessary, otherwise false
203 bool SetAscentOfRow(int row, int height);
204 /// Returns true if a complete update is necessary, otherwise false
205 bool SetDescentOfRow(int row, int height);
206 /// Returns true if a complete update is necessary, otherwise false
207 bool SetWidthOfCell(int cell, int new_width);
208 /// Returns true if a complete update is necessary, otherwise false
209 bool SetAllLines(int cell, bool line);
210 /// Returns true if a complete update is necessary, otherwise false
211 bool SetTopLine(int cell, bool line, bool onlycolumn=false);
212 /// Returns true if a complete update is necessary, otherwise false
213 bool SetBottomLine(int cell, bool line, bool onlycolumn=false);
214 /// Returns true if a complete update is necessary, otherwise false
215 bool SetLeftLine(int cell, bool line, bool onlycolumn=false);
216 /// Returns true if a complete update is necessary, otherwise false
217 bool SetRightLine(int cell, bool line, bool onlycolumn=false);
218 /// Returns true if a complete update is necessary, otherwise false
219 bool SetAlignment(int cell, LyXAlignment align, bool onlycolumn = false);
220 /// Returns true if a complete update is necessary, otherwise false
221 bool SetVAlignment(int cell, VAlignment align, bool onlycolumn = false);
223 bool SetColumnPWidth(int cell, string const & width);
225 bool SetMColumnPWidth(int cell, string const & width);
227 bool SetAlignSpecial(int cell, string const & special, Feature what);
229 LyXAlignment GetAlignment(int cell, bool onlycolumn = false) const;
231 VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
233 string const GetPWidth(int cell) const;
235 string const GetColumnPWidth(int cell) const;
237 string const GetMColumnPWidth(int cell) const;
239 string const GetAlignSpecial(int cell, int what) const;
241 int GetWidthOfCell(int cell) const;
243 int GetBeginningOfTextInCell(int cell) const;
245 void AppendRow(int cell);
247 void DeleteRow(int cell);
249 void AppendColumn(int cell);
251 void DeleteColumn(int cell);
253 bool IsFirstCellInRow(int cell) const;
255 int GetFirstCellInRow(int row) const;
257 bool IsLastCellInRow(int cell) const;
259 int GetLastCellInRow(int row) const;
261 int GetNumberOfCells() const;
263 int NumberOfCellsInRow(int cell) const;
265 void Write(Buffer const *, std::ostream &) const;
267 void Read(Buffer const *, LyXLex &);
269 void OldFormatRead(LyXLex &, string const &);
271 // helper function for Latex returns number of newlines
273 int TeXTopHLine(std::ostream &, int row) const;
275 int TeXBottomHLine(std::ostream &, int row) const;
277 int TeXCellPreamble(std::ostream &, int cell) const;
279 int TeXCellPostamble(std::ostream &, int cell) const;
281 int Latex(Buffer const *, std::ostream &, bool, bool) const;
283 int DocBookEndOfCell(std::ostream &, int cell, int & depth) const;
286 int RoffEndOfCell(std::ostream &, int cell);
289 string const GetDocBookAlign(int cell, bool isColumn = false) const;
292 bool IsMultiColumn(int cell, bool real = false) const;
294 void SetMultiColumn(int cell, int number);
296 int UnsetMultiColumn(int cell); // returns number of new cells
298 bool IsPartOfMultiColumn(int row, int column) const;
300 int row_of_cell(int cell) const;
302 int column_of_cell(int cell) const;
304 int right_column_of_cell(int cell) const;
306 void SetLongTabular(bool);
308 bool IsLongTabular() const;
310 void SetRotateTabular(bool);
312 bool GetRotateTabular() const;
314 void SetRotateCell(int cell, bool);
316 bool GetRotateCell(int cell) const;
318 bool NeedRotating() const;
320 bool IsLastCell(int cell) const;
322 int GetCellAbove(int cell) const;
324 int GetCellBelow(int cell) const;
326 int GetLastCellAbove(int cell) const;
328 int GetLastCellBelow(int cell) const;
330 int GetCellNumber(int row, int column) const;
332 void SetUsebox(int cell, BoxType);
334 BoxType GetUsebox(int cell) const;
336 // Long Tabular Options
338 void SetLTHead(int cell, bool first);
340 bool GetRowOfLTHead(int cell, int & row) const;
342 bool GetRowOfLTFirstHead(int cell, int & row) const;
344 void SetLTFoot(int cell, bool last);
346 bool GetRowOfLTFoot(int cell, int & row) const;
348 bool GetRowOfLTLastFoot(int cell, int & row) const;
350 void SetLTNewPage(int cell, bool what);
352 bool GetLTNewPage(int cell) const;
354 InsetText * GetCellInset(int cell) const;
356 int rows() const { return rows_; }
358 int columns() const { return columns_;}
360 InsetTabular * owner() const { return owner_; }
362 void Validate(LaTeXFeatures &) const;
364 private: //////////////////////////////////////////////////////////////////
376 LyXAlignment alignment;
378 VAlignment valignment;
392 string align_special;
394 string p_width; // this is only set for multicolumn!!!
399 typedef std::vector<cellstruct> cell_vector;
401 typedef std::vector<cell_vector> cell_vvector;
415 /// This are for longtabulars only
419 typedef std::vector<rowstruct> row_vector;
422 struct columnstruct {
426 LyXAlignment alignment;
428 VAlignment valignment;
438 string align_special;
441 typedef std::vector<columnstruct> column_vector;
456 column_vector column_info;
458 mutable cell_vvector cell_info;
460 int width_of_tabular;
466 bool is_long_tabular;
469 /// row of endfirsthead
473 /// row of endlastfoot
476 InsetTabular * owner_;
479 void Init(int columns_arg, int rows_arg);
483 void set_row_column_number_info(bool oldformat=false);
484 /// Returns true if a complete update is necessary, otherwise false
485 bool SetWidthOfMulticolCell(int cell, int new_width);
487 void recalculateMulticolCells(int cell, int new_width);
488 /// Returns true if change
489 bool calculate_width_of_column(int column);
491 bool calculate_width_of_column_NMC(int column); // no multi cells
493 void calculate_width_of_tabular();
495 cellstruct * cellinfo_of_cell(int cell) const;
497 void delete_column(int column);
499 int cells_in_multicolumn(int cell) const;
501 BoxType UseParbox(int cell) const;