2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000-2001 The LyX Team.
9 * @author: Jürgen Vigna
11 * ====================================================== */
22 #include "lyxlength.h"
24 #include "insets/insettext.h"
33 /* The features the text class offers for tables */
105 UNSET_ROTATE_TABULAR,
138 CELL_BEGIN_OF_MULTICOLUMN,
140 CELL_PART_OF_MULTICOLUMN
148 LYX_VALIGN_BOTTOM = 1,
150 LYX_VALIGN_CENTER = 2
165 // we have this header type (is set in the GetLT... functions)
167 // double borders on top
169 // double borders on bottom
171 // used for FirstHeader & LastFooter and if this is true
172 // all the rows marked as FirstHeader or LastFooter are
173 // ignored in the output and it is set to be empty!
177 typedef struct lttype ltType;
181 LyXTabular(BufferParams const &,
182 InsetTabular *, int columns_arg, int rows_arg);
184 LyXTabular(BufferParams const &,
185 InsetTabular *, LyXTabular const &, bool same_id = false);
188 LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
190 LyXTabular & operator=(LyXTabular const &);
192 LyXTabular * clone(BufferParams const &,
193 InsetTabular *, bool same_id = false);
195 /// Returns true if there is a topline, returns false if not
196 bool TopLine(int cell, bool onlycolumn = false) const;
197 /// Returns true if there is a topline, returns false if not
198 bool BottomLine(int cell, bool onlycolumn = false) const;
199 /// Returns true if there is a topline, returns false if not
200 bool LeftLine(int cell, bool onlycolumn = false) const;
201 /// Returns true if there is a topline, returns false if not
202 bool RightLine(int cell, bool onlycolumn = false) const;
205 bool TopAlreadyDrawed(int cell) const;
207 bool LeftAlreadyDrawed(int cell) const;
209 bool IsLastRow(int cell) const;
212 int GetAdditionalHeight(int row) const;
214 int GetAdditionalWidth(int cell) const;
216 /* returns the maximum over all rows */
218 int GetWidthOfColumn(int cell) const;
220 int GetWidthOfTabular() const;
222 int GetAscentOfRow(int row) const;
224 int GetDescentOfRow(int row) const;
226 int GetHeightOfTabular() const;
227 /// Returns true if a complete update is necessary, otherwise false
228 bool SetAscentOfRow(int row, int height);
229 /// Returns true if a complete update is necessary, otherwise false
230 bool SetDescentOfRow(int row, int height);
231 /// Returns true if a complete update is necessary, otherwise false
232 bool SetWidthOfCell(int cell, int new_width);
233 /// Returns true if a complete update is necessary, otherwise false
234 bool SetAllLines(int cell, bool line);
235 /// Returns true if a complete update is necessary, otherwise false
236 bool SetTopLine(int cell, bool line, bool onlycolumn = false);
237 /// Returns true if a complete update is necessary, otherwise false
238 bool SetBottomLine(int cell, bool line, bool onlycolumn = false);
239 /// Returns true if a complete update is necessary, otherwise false
240 bool SetLeftLine(int cell, bool line, bool onlycolumn = false);
241 /// Returns true if a complete update is necessary, otherwise false
242 bool SetRightLine(int cell, bool line, bool onlycolumn = false);
243 /// Returns true if a complete update is necessary, otherwise false
244 bool SetAlignment(int cell, LyXAlignment align,
245 bool onlycolumn = false);
246 /// Returns true if a complete update is necessary, otherwise false
247 bool SetVAlignment(int cell, VAlignment align,
248 bool onlycolumn = false);
250 bool SetColumnPWidth(int cell, LyXLength const & width);
252 bool SetMColumnPWidth(int cell, LyXLength const & width);
254 bool SetAlignSpecial(int cell, string const & special, Feature what);
256 LyXAlignment GetAlignment(int cell, bool onlycolumn = false) const;
258 VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
260 LyXLength const GetPWidth(int cell) const;
262 LyXLength const GetColumnPWidth(int cell) const;
264 LyXLength const GetMColumnPWidth(int cell) const;
266 string const GetAlignSpecial(int cell, int what) const;
268 int GetWidthOfCell(int cell) const;
270 int GetBeginningOfTextInCell(int cell) const;
272 void AppendRow(BufferParams const &, int cell);
274 void DeleteRow(int row);
276 void AppendColumn(BufferParams const &, int cell);
278 void DeleteColumn(int column);
280 bool IsFirstCellInRow(int cell) const;
282 int GetFirstCellInRow(int row) const;
284 bool IsLastCellInRow(int cell) const;
286 int GetLastCellInRow(int row) const;
288 int GetNumberOfCells() const;
290 int NumberOfCellsInRow(int cell) const;
292 void Write(Buffer const *, std::ostream &) const;
294 void Read(Buffer const *, LyXLex &);
296 void OldFormatRead(BufferParams const &, LyXLex &, string const &);
298 int latex(Buffer const *, std::ostream &, bool, bool) const;
300 int docbook(Buffer const * buf, std::ostream & os, bool mixcont) const;
302 int ascii(Buffer const *, std::ostream &, int const depth,
303 bool onlydata, unsigned char delim) const;
305 bool IsMultiColumn(int cell, bool real = false) const;
307 void SetMultiColumn(Buffer const *, 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 support functions
351 bool checkLTType(int row, ltType const &) const;
353 void SetLTHead(int row, bool flag, ltType const &, bool first);
355 bool GetRowOfLTHead(int row, ltType &) const;
357 bool GetRowOfLTFirstHead(int row, ltType &) const;
359 void SetLTFoot(int row, bool flag, ltType const &, bool last);
361 bool GetRowOfLTFoot(int row, ltType &) const;
363 bool GetRowOfLTLastFoot(int row, ltType &) const;
365 void SetLTNewPage(int row, bool what);
367 bool GetLTNewPage(int row) const;
369 bool haveLTHead() const;
371 bool haveLTFirstHead() const;
373 bool haveLTFoot() const;
375 bool haveLTLastFoot() const;
377 // end longtable support
379 InsetText * GetCellInset(int cell) const;
381 InsetText * GetCellInset(int row, int column) const;
382 /// Search for \param inset in the tabular, with the
383 /// additional hint that it could be at \param maybe_cell
384 int GetCellFromInset(Inset const * inset, int maybe_cell = -1) const;
386 int rows() const { return rows_; }
388 int columns() const { return columns_;}
390 InsetTabular * owner() const { return owner_; }
392 void Validate(LaTeXFeatures &) const;
394 std::vector<string> const getLabelList() const;
396 /// recalculate the widths/heights only!
399 mutable int cur_cell;
404 cellstruct(BufferParams const &);
412 LyXAlignment alignment;
414 VAlignment valignment;
428 string align_special;
430 LyXLength p_width; // this is only set for multicolumn!!!
435 typedef std::vector<cellstruct> cell_vector;
437 typedef std::vector<cell_vector> cell_vvector;
451 /// This are for longtabulars only
454 /// a row of endfirsthead
458 /// row of endlastfoot
460 /// row for a pagebreak
464 typedef std::vector<rowstruct> row_vector;
467 struct columnstruct {
471 LyXAlignment alignment;
473 VAlignment valignment;
483 string align_special;
486 typedef std::vector<columnstruct> column_vector;
489 void ReadNew(Buffer const * buf, std::istream & is,
490 LyXLex & lex, string const & l, int const version);
492 void ReadOld(Buffer const * buf, std::istream & is,
493 LyXLex & lex, string const & l);
501 std::vector<int> rowofcell;
503 std::vector<int> columnofcell;
507 column_vector column_info;
509 mutable cell_vvector cell_info;
511 int width_of_tabular;
517 bool is_long_tabular;
520 /// endfirsthead data
528 InsetTabular * owner_;
531 void Init(BufferParams const &,
532 int columns_arg, int rows_arg, LyXTabular const * lt = 0);
534 void Reinit(bool reset_widths = true);
536 void set_row_column_number_info(bool oldformat = false);
537 /// Returns true if a complete update is necessary, otherwise false
538 bool SetWidthOfMulticolCell(int cell, int new_width);
540 void recalculateMulticolumnsOfColumn(int column);
541 /// Returns true if change
542 bool calculate_width_of_column(int column);
544 bool calculate_width_of_column_NMC(int column); // no multi cells
546 void calculate_width_of_tabular();
548 cellstruct * cellinfo_of_cell(int cell) const;
550 void delete_column(int column);
552 int cells_in_multicolumn(int cell) const;
554 BoxType UseParbox(int cell) const;
556 void setHeaderFooterRows(int header, int fheader, int footer, int lfooter);
558 // helper function for Latex returns number of newlines
560 int TeXTopHLine(std::ostream &, int row) const;
562 int TeXBottomHLine(std::ostream &, int row) const;
564 int TeXCellPreamble(std::ostream &, int cell) const;
566 int TeXCellPostamble(std::ostream &, int cell) const;
568 int TeXLongtableHeaderFooter(std::ostream &, Buffer const * buf,
569 bool fragile, bool fp) const;
571 bool isValidRow(int const row) const;
573 int TeXRow(std::ostream &, int const row, Buffer const * buf,
574 bool fragile, bool fp) const;
576 // helper function for ASCII returns number of newlines
578 int asciiTopHLine(std::ostream &, int row,
579 std::vector<unsigned int> const &) const;
581 int asciiBottomHLine(std::ostream &, int row,
582 std::vector<unsigned int> const &) const;
584 int asciiPrintCell(Buffer const *, std::ostream &,
585 int cell, int row, int column,
586 std::vector<unsigned int> const &,
587 bool onlydata) const;
588 /// auxiliary function for docbook
589 int docbookRow(Buffer const * buf, std::ostream & os, int row) const;