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);
164 LyXTabular & operator=(LyXTabular const &);
166 LyXTabular * Clone(InsetTabular *);
168 /// Returns true if there is a topline, returns false if not
169 bool TopLine(int cell, bool onlycolumn = false) const;
170 /// Returns true if there is a topline, returns false if not
171 bool BottomLine(int cell, bool onlycolumn = false) const;
172 /// Returns true if there is a topline, returns false if not
173 bool LeftLine(int cell, bool onlycolumn = false) const;
174 /// Returns true if there is a topline, returns false if not
175 bool RightLine(int cell, bool onlycolumn = false) const;
178 bool TopAlreadyDrawed(int cell) const;
180 bool LeftAlreadyDrawed(int cell) const;
182 bool IsLastRow(int cell) const;
185 int GetAdditionalHeight(int cell) const;
187 int GetAdditionalWidth(int cell) const;
189 /* returns the maximum over all rows */
191 int GetWidthOfColumn(int cell) const;
193 int GetWidthOfTabular() const;
195 int GetAscentOfRow(int row) const;
197 int GetDescentOfRow(int row) const;
199 int GetHeightOfTabular() const;
200 /// Returns true if a complete update is necessary, otherwise false
201 bool SetAscentOfRow(int row, int height);
202 /// Returns true if a complete update is necessary, otherwise false
203 bool SetDescentOfRow(int row, int height);
204 /// Returns true if a complete update is necessary, otherwise false
205 bool SetWidthOfCell(int cell, int new_width);
206 /// Returns true if a complete update is necessary, otherwise false
207 bool SetAllLines(int cell, bool line);
208 /// Returns true if a complete update is necessary, otherwise false
209 bool SetTopLine(int cell, bool line, bool onlycolumn=false);
210 /// Returns true if a complete update is necessary, otherwise false
211 bool SetBottomLine(int cell, bool line, bool onlycolumn=false);
212 /// Returns true if a complete update is necessary, otherwise false
213 bool SetLeftLine(int cell, bool line, bool onlycolumn=false);
214 /// Returns true if a complete update is necessary, otherwise false
215 bool SetRightLine(int cell, bool line, bool onlycolumn=false);
216 /// Returns true if a complete update is necessary, otherwise false
217 bool SetAlignment(int cell, LyXAlignment align, bool onlycolumn = false);
218 /// Returns true if a complete update is necessary, otherwise false
219 bool SetVAlignment(int cell, VAlignment align, bool onlycolumn = false);
221 bool SetColumnPWidth(int cell, string const & width);
223 bool SetMColumnPWidth(int cell, string const & width);
225 bool SetAlignSpecial(int cell, string const & special, Feature what);
227 LyXAlignment GetAlignment(int cell, bool onlycolumn = false) const;
229 VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
231 string const GetPWidth(int cell) const;
233 string const GetColumnPWidth(int cell) const;
235 string const GetMColumnPWidth(int cell) const;
237 string const GetAlignSpecial(int cell, int what) const;
239 int GetWidthOfCell(int cell) const;
241 int GetBeginningOfTextInCell(int cell) const;
243 void AppendRow(int cell);
245 void DeleteRow(int row);
247 void AppendColumn(int cell);
249 void DeleteColumn(int column);
251 bool IsFirstCellInRow(int cell) const;
253 int GetFirstCellInRow(int row) const;
255 bool IsLastCellInRow(int cell) const;
257 int GetLastCellInRow(int row) const;
259 int GetNumberOfCells() const;
261 int NumberOfCellsInRow(int cell) const;
263 void Write(Buffer const *, std::ostream &) const;
265 void Read(Buffer const *, LyXLex &);
267 void OldFormatRead(LyXLex &, string const &);
269 // helper function for Latex returns number of newlines
271 int TeXTopHLine(std::ostream &, int row) const;
273 int TeXBottomHLine(std::ostream &, int row) const;
275 int TeXCellPreamble(std::ostream &, int cell) const;
277 int TeXCellPostamble(std::ostream &, int cell) const;
279 int Latex(Buffer const *, std::ostream &, bool, bool) const;
281 int DocBook(Buffer const * buf, std::ostream & os) const;
283 // helper function for Latex returns number of newlines
285 int AsciiTopHLine(std::ostream &, int row,
286 std::vector<unsigned int> const &) const;
288 int AsciiBottomHLine(std::ostream &, int row,
289 std::vector<unsigned int> const &) const;
291 int AsciiPrintCell(Buffer const *, std::ostream &, int cell, int row,
292 int column, std::vector<unsigned int> const &) const;
294 int Ascii(Buffer const *, std::ostream &) const;
296 int DocBookEndOfCell(std::ostream &, int cell, int & depth) const;
299 int RoffEndOfCell(std::ostream &, int cell);
302 string const GetDocBookAlign(int cell, bool isColumn = false) const;
305 bool IsMultiColumn(int cell, bool real = false) const;
307 void SetMultiColumn(int cell, int number);
309 int UnsetMultiColumn(int cell); // returns number of new cells
311 bool IsPartOfMultiColumn(int row, int column) const;
313 int row_of_cell(int cell) const;
315 int column_of_cell(int cell) const;
317 int right_column_of_cell(int cell) const;
319 void SetLongTabular(bool);
321 bool IsLongTabular() const;
323 void SetRotateTabular(bool);
325 bool GetRotateTabular() const;
327 void SetRotateCell(int cell, bool);
329 bool GetRotateCell(int cell) const;
331 bool NeedRotating() const;
333 bool IsLastCell(int cell) const;
335 int GetCellAbove(int cell) const;
337 int GetCellBelow(int cell) const;
339 int GetLastCellAbove(int cell) const;
341 int GetLastCellBelow(int cell) const;
343 int GetCellNumber(int row, int column) const;
345 void SetUsebox(int cell, BoxType);
347 BoxType GetUsebox(int cell) const;
349 // Long Tabular Options
351 void SetLTHead(int cell, bool first);
353 bool GetRowOfLTHead(int cell, int & row) const;
355 bool GetRowOfLTFirstHead(int cell, int & row) const;
357 void SetLTFoot(int cell, bool last);
359 bool GetRowOfLTFoot(int cell, int & row) const;
361 bool GetRowOfLTLastFoot(int cell, int & row) const;
363 void SetLTNewPage(int cell, bool what);
365 bool GetLTNewPage(int cell) const;
367 InsetText * GetCellInset(int cell) const;
368 InsetText * GetCellInset(int row, int column) const;
370 int rows() const { return rows_; }
372 int columns() const { return columns_;}
374 InsetTabular * owner() const { return owner_; }
376 void Validate(LaTeXFeatures &) const;
378 private: //////////////////////////////////////////////////////////////////
390 LyXAlignment alignment;
392 VAlignment valignment;
406 string align_special;
408 string p_width; // this is only set for multicolumn!!!
413 typedef std::vector<cellstruct> cell_vector;
415 typedef std::vector<cell_vector> cell_vvector;
429 /// This are for longtabulars only
433 typedef std::vector<rowstruct> row_vector;
436 struct columnstruct {
440 LyXAlignment alignment;
442 VAlignment valignment;
452 string align_special;
455 typedef std::vector<columnstruct> column_vector;
458 void ReadNew(Buffer const * buf, std::istream & is,
459 LyXLex & lex, string const & l);
461 void ReadOld(Buffer const * buf, std::istream & is,
462 LyXLex & lex, string const & l);
470 std::vector<int> rowofcell;
472 std::vector<int> columnofcell;
476 column_vector column_info;
478 mutable cell_vvector cell_info;
480 int width_of_tabular;
486 bool is_long_tabular;
489 /// row of endfirsthead
493 /// row of endlastfoot
496 InsetTabular * owner_;
499 void Init(int columns_arg, int rows_arg);
503 void set_row_column_number_info(bool oldformat = false);
504 /// Returns true if a complete update is necessary, otherwise false
505 bool SetWidthOfMulticolCell(int cell, int new_width);
507 void recalculateMulticolCells(int cell, int new_width);
508 /// Returns true if change
509 bool calculate_width_of_column(int column);
511 bool calculate_width_of_column_NMC(int column); // no multi cells
513 void calculate_width_of_tabular();
515 cellstruct * cellinfo_of_cell(int cell) const;
517 void delete_column(int column);
519 int cells_in_multicolumn(int cell) const;
521 BoxType UseParbox(int cell) const;