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 * ====================================================== */
25 #include "insets/insettext.h"
26 #include "lyxlength.h"
32 /* The features the text class offers for tables */
104 UNSET_ROTATE_TABULAR,
137 CELL_BEGIN_OF_MULTICOLUMN,
139 CELL_PART_OF_MULTICOLUMN
147 LYX_VALIGN_BOTTOM = 1,
149 LYX_VALIGN_CENTER = 2
164 // we have this header type (is set in the GetLT... functions)
166 // double borders on top
168 // double borders on bottom
170 // used for FirstHeader & LastFooter and if this is true
171 // all the rows marked as FirstHeader or LastFooter are
172 // ignored in the output and it is set to be empty!
176 typedef struct lttype ltType;
180 LyXTabular(InsetTabular *, int columns_arg, int rows_arg);
182 LyXTabular(InsetTabular *, LyXTabular const &, bool same_id = false);
185 LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
187 LyXTabular & operator=(LyXTabular const &);
189 LyXTabular * clone(InsetTabular *, bool same_id = false);
191 /// Returns true if there is a topline, returns false if not
192 bool TopLine(int cell, bool onlycolumn = false) const;
193 /// Returns true if there is a topline, returns false if not
194 bool BottomLine(int cell, bool onlycolumn = false) const;
195 /// Returns true if there is a topline, returns false if not
196 bool LeftLine(int cell, bool onlycolumn = false) const;
197 /// Returns true if there is a topline, returns false if not
198 bool RightLine(int cell, bool onlycolumn = false) const;
201 bool TopAlreadyDrawed(int cell) const;
203 bool LeftAlreadyDrawed(int cell) const;
205 bool IsLastRow(int cell) const;
208 int GetAdditionalHeight(int row) const;
210 int GetAdditionalWidth(int cell) const;
212 /* returns the maximum over all rows */
214 int GetWidthOfColumn(int cell) const;
216 int GetWidthOfTabular() const;
218 int GetAscentOfRow(int row) const;
220 int GetDescentOfRow(int row) const;
222 int GetHeightOfTabular() const;
223 /// Returns true if a complete update is necessary, otherwise false
224 bool SetAscentOfRow(int row, int height);
225 /// Returns true if a complete update is necessary, otherwise false
226 bool SetDescentOfRow(int row, int height);
227 /// Returns true if a complete update is necessary, otherwise false
228 bool SetWidthOfCell(int cell, int new_width);
229 /// Returns true if a complete update is necessary, otherwise false
230 bool SetAllLines(int cell, bool line);
231 /// Returns true if a complete update is necessary, otherwise false
232 bool SetTopLine(int cell, bool line, bool onlycolumn = false);
233 /// Returns true if a complete update is necessary, otherwise false
234 bool SetBottomLine(int cell, bool line, bool onlycolumn = false);
235 /// Returns true if a complete update is necessary, otherwise false
236 bool SetLeftLine(int cell, bool line, bool onlycolumn = false);
237 /// Returns true if a complete update is necessary, otherwise false
238 bool SetRightLine(int cell, bool line, bool onlycolumn = false);
239 /// Returns true if a complete update is necessary, otherwise false
240 bool SetAlignment(int cell, LyXAlignment align,
241 bool onlycolumn = false);
242 /// Returns true if a complete update is necessary, otherwise false
243 bool SetVAlignment(int cell, VAlignment align,
244 bool onlycolumn = false);
246 bool SetColumnPWidth(int cell, LyXLength const & width);
248 bool SetMColumnPWidth(int cell, LyXLength const & width);
250 bool SetAlignSpecial(int cell, string const & special, Feature what);
252 LyXAlignment GetAlignment(int cell, bool onlycolumn = false) const;
254 VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
256 LyXLength const GetPWidth(int cell) const;
258 LyXLength const GetColumnPWidth(int cell) const;
260 LyXLength const GetMColumnPWidth(int cell) const;
262 string const GetAlignSpecial(int cell, int what) const;
264 int GetWidthOfCell(int cell) const;
266 int GetBeginningOfTextInCell(int cell) const;
268 void AppendRow(int cell);
270 void DeleteRow(int row);
272 void AppendColumn(int cell);
274 void DeleteColumn(int column);
276 bool IsFirstCellInRow(int cell) const;
278 int GetFirstCellInRow(int row) const;
280 bool IsLastCellInRow(int cell) const;
282 int GetLastCellInRow(int row) const;
284 int GetNumberOfCells() const;
286 int NumberOfCellsInRow(int cell) const;
288 void Write(Buffer const *, std::ostream &) const;
290 void Read(Buffer const *, LyXLex &);
292 void OldFormatRead(LyXLex &, string const &);
294 int latex(Buffer const *, std::ostream &, bool, bool) const;
296 int docBook(Buffer const * buf, std::ostream & os) const;
298 int ascii(Buffer const *, std::ostream &, int const depth,
299 bool onlydata, unsigned char delim) const;
301 bool IsMultiColumn(int cell, bool real = false) const;
303 void SetMultiColumn(int cell, int number);
305 int UnsetMultiColumn(int cell); // returns number of new cells
307 bool IsPartOfMultiColumn(int row, int column) const;
309 int row_of_cell(int cell) const;
311 int column_of_cell(int cell) const;
313 int right_column_of_cell(int cell) const;
315 void SetLongTabular(bool);
317 bool IsLongTabular() const;
319 void SetRotateTabular(bool);
321 bool GetRotateTabular() const;
323 void SetRotateCell(int cell, bool);
325 bool GetRotateCell(int cell) const;
327 bool NeedRotating() const;
329 bool IsLastCell(int cell) const;
331 int GetCellAbove(int cell) const;
333 int GetCellBelow(int cell) const;
335 int GetLastCellAbove(int cell) const;
337 int GetLastCellBelow(int cell) const;
339 int GetCellNumber(int row, int column) const;
341 void SetUsebox(int cell, BoxType);
343 BoxType GetUsebox(int cell) const;
345 // Long Tabular Options support functions
347 bool checkLTType(int row, ltType const &) const;
349 void SetLTHead(int row, bool flag, ltType const &, bool first);
351 bool GetRowOfLTHead(int row, ltType &) const;
353 bool GetRowOfLTFirstHead(int row, ltType &) const;
355 void SetLTFoot(int row, bool flag, ltType const &, bool last);
357 bool GetRowOfLTFoot(int row, ltType &) const;
359 bool GetRowOfLTLastFoot(int row, ltType &) const;
361 void SetLTNewPage(int row, bool what);
363 bool GetLTNewPage(int row) const;
365 bool haveLTHead() const;
367 bool haveLTFirstHead() const;
369 bool haveLTFoot() const;
371 bool haveLTLastFoot() const;
373 // end longtable support
375 InsetText * GetCellInset(int cell) const;
377 InsetText * GetCellInset(int row, int column) const;
379 int rows() const { return rows_; }
381 int columns() const { return columns_;}
383 InsetTabular * owner() const { return owner_; }
385 void Validate(LaTeXFeatures &) const;
387 std::vector<string> const getLabelList() const;
389 /// recalculate the widths/heights only!
392 mutable int cur_cell;
405 LyXAlignment alignment;
407 VAlignment valignment;
421 string align_special;
423 LyXLength p_width; // this is only set for multicolumn!!!
428 typedef std::vector<cellstruct> cell_vector;
430 typedef std::vector<cell_vector> cell_vvector;
444 /// This are for longtabulars only
447 /// a row of endfirsthead
451 /// row of endlastfoot
453 /// row for a pagebreak
457 typedef std::vector<rowstruct> row_vector;
460 struct columnstruct {
464 LyXAlignment alignment;
466 VAlignment valignment;
476 string align_special;
479 typedef std::vector<columnstruct> column_vector;
482 void ReadNew(Buffer const * buf, std::istream & is,
483 LyXLex & lex, string const & l, int const version);
485 void ReadOld(Buffer const * buf, std::istream & is,
486 LyXLex & lex, string const & l);
494 std::vector<int> rowofcell;
496 std::vector<int> columnofcell;
500 column_vector column_info;
502 mutable cell_vvector cell_info;
504 int width_of_tabular;
510 bool is_long_tabular;
513 /// endfirsthead data
521 InsetTabular * owner_;
524 void Init(int columns_arg, int rows_arg, LyXTabular const * lt = 0);
526 void Reinit(bool reset_widths = true);
528 void set_row_column_number_info(bool oldformat = false);
529 /// Returns true if a complete update is necessary, otherwise false
530 bool SetWidthOfMulticolCell(int cell, int new_width);
532 void recalculateMulticolCells(int cell, int new_width);
533 /// Returns true if change
534 bool calculate_width_of_column(int column);
536 bool calculate_width_of_column_NMC(int column); // no multi cells
538 void calculate_width_of_tabular();
540 cellstruct * cellinfo_of_cell(int cell) const;
542 void delete_column(int column);
544 int cells_in_multicolumn(int cell) const;
546 BoxType UseParbox(int cell) const;
548 void setHeaderFooterRows(int header, int fheader, int footer, int lfooter);
550 // helper function for Latex returns number of newlines
552 int TeXTopHLine(std::ostream &, int row) const;
554 int TeXBottomHLine(std::ostream &, int row) const;
556 int TeXCellPreamble(std::ostream &, int cell) const;
558 int TeXCellPostamble(std::ostream &, int cell) const;
560 int TeXLongtableHeaderFooter(std::ostream &, Buffer const * buf,
561 bool fragile, bool fp) const;
563 bool isValidRow(int const row) const;
565 int TeXRow(std::ostream &, int const row, Buffer const * buf,
566 bool fragile, bool fp) const;
568 // helper function for ASCII returns number of newlines
570 int asciiTopHLine(std::ostream &, int row,
571 std::vector<unsigned int> const &) const;
573 int asciiBottomHLine(std::ostream &, int row,
574 std::vector<unsigned int> const &) const;
576 int asciiPrintCell(Buffer const *, std::ostream &,
577 int cell, int row, int column,
578 std::vector<unsigned int> const &,
579 bool onlydata) const;
580 /// auxiliary function for docbook
581 int docbookRow(Buffer const * buf, std::ostream & os, int row) const;