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 * ====================================================== */
17 #include "lyxlength.h"
19 #include "insets/insettext.h"
31 /* 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!
179 LyXTabular(BufferParams const &,
180 InsetTabular *, int columns_arg, int rows_arg);
182 LyXTabular(BufferParams const &,
183 InsetTabular *, LyXTabular const &, bool same_id = false);
186 LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
188 LyXTabular & operator=(LyXTabular const &);
190 LyXTabular * clone(BufferParams const &,
191 InsetTabular *, bool same_id = false);
193 /// Returns true if there is a topline, returns false if not
194 bool TopLine(int cell, bool onlycolumn = false) const;
195 /// Returns true if there is a topline, returns false if not
196 bool BottomLine(int cell, bool onlycolumn = false) const;
197 /// Returns true if there is a topline, returns false if not
198 bool LeftLine(int cell, bool onlycolumn = false) const;
199 /// Returns true if there is a topline, returns false if not
200 bool RightLine(int cell, bool onlycolumn = false) const;
203 bool topAlreadyDrawn(int cell) const;
205 bool leftAlreadyDrawn(int cell) const;
207 bool IsLastRow(int cell) const;
210 int GetAdditionalHeight(int row) const;
212 int GetAdditionalWidth(int cell) const;
214 /* returns the maximum over all rows */
216 int GetWidthOfColumn(int cell) const;
218 int GetWidthOfTabular() const;
220 int GetAscentOfRow(int row) const;
222 int GetDescentOfRow(int row) const;
224 int GetHeightOfTabular() const;
225 /// Returns true if a complete update is necessary, otherwise false
226 bool SetAscentOfRow(int row, int height);
227 /// Returns true if a complete update is necessary, otherwise false
228 bool SetDescentOfRow(int row, int height);
229 /// Returns true if a complete update is necessary, otherwise false
230 bool SetWidthOfCell(int cell, int new_width);
231 /// Returns true if a complete update is necessary, otherwise false
232 bool SetAllLines(int cell, bool line);
233 /// Returns true if a complete update is necessary, otherwise false
234 bool SetTopLine(int cell, bool line, bool onlycolumn = false);
235 /// Returns true if a complete update is necessary, otherwise false
236 bool SetBottomLine(int cell, bool line, bool onlycolumn = false);
237 /// Returns true if a complete update is necessary, otherwise false
238 bool SetLeftLine(int cell, bool line, bool onlycolumn = false);
239 /// Returns true if a complete update is necessary, otherwise false
240 bool SetRightLine(int cell, bool line, bool onlycolumn = false);
241 /// Returns true if a complete update is necessary, otherwise false
242 bool SetAlignment(int cell, LyXAlignment align,
243 bool onlycolumn = false);
244 /// Returns true if a complete update is necessary, otherwise false
245 bool SetVAlignment(int cell, VAlignment align,
246 bool onlycolumn = false);
248 bool SetColumnPWidth(int cell, LyXLength const & width);
250 bool SetMColumnPWidth(int cell, LyXLength const & width);
252 bool SetAlignSpecial(int cell, string const & special, Feature what);
254 LyXAlignment GetAlignment(int cell, bool onlycolumn = false) const;
256 VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
258 LyXLength const GetPWidth(int cell) const;
260 LyXLength const GetColumnPWidth(int cell) const;
262 LyXLength const GetMColumnPWidth(int cell) const;
264 string const GetAlignSpecial(int cell, int what) const;
266 int GetWidthOfCell(int cell) const;
268 int GetBeginningOfTextInCell(int cell) const;
270 void AppendRow(BufferParams const &, int cell);
272 void DeleteRow(int row);
274 void AppendColumn(BufferParams const &, int cell);
276 void DeleteColumn(int column);
278 bool IsFirstCellInRow(int cell) const;
280 int GetFirstCellInRow(int row) const;
282 bool IsLastCellInRow(int cell) const;
284 int GetLastCellInRow(int row) const;
286 int GetNumberOfCells() const;
288 int NumberOfCellsInRow(int cell) const;
290 void Write(Buffer const *, std::ostream &) const;
292 void Read(Buffer const *, LyXLex &);
294 int latex(Buffer const *, std::ostream &, LatexRunParams const &, bool, bool) const;
296 int docbook(Buffer const * buf, std::ostream & os, bool mixcont) 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(Buffer *, 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;
378 /// Search for \param inset in the tabular, with the
379 /// additional hint that it could be at \param maybe_cell
380 int GetCellFromInset(Inset const * inset, int maybe_cell = -1) const;
382 int rows() const { return rows_; }
384 int columns() const { return columns_;}
386 InsetTabular * owner() const { return owner_; }
388 void Validate(LaTeXFeatures &) const;
390 std::vector<string> const getLabelList() const;
392 /// recalculate the widths/heights only!
395 mutable int cur_cell;
400 cellstruct(BufferParams const &);
408 LyXAlignment alignment;
410 VAlignment valignment;
424 string align_special;
426 LyXLength p_width; // this is only set for multicolumn!!!
431 typedef std::vector<cellstruct> cell_vector;
433 typedef std::vector<cell_vector> cell_vvector;
447 /// This are for longtabulars only
450 /// a row of endfirsthead
454 /// row of endlastfoot
456 /// row for a pagebreak
460 typedef std::vector<rowstruct> row_vector;
463 struct columnstruct {
467 LyXAlignment alignment;
469 VAlignment valignment;
479 string align_special;
482 typedef std::vector<columnstruct> column_vector;
485 void read(Buffer const * buf, std::istream & is,
486 LyXLex & lex, string const & l, int const version);
495 std::vector<int> rowofcell;
497 std::vector<int> columnofcell;
501 column_vector column_info;
503 mutable cell_vvector cell_info;
505 int width_of_tabular;
511 bool is_long_tabular;
514 /// endfirsthead data
522 InsetTabular * owner_;
525 void Init(BufferParams const &,
526 int columns_arg, int rows_arg, LyXTabular const * lt = 0);
528 void Reinit(bool reset_widths = true);
530 void set_row_column_number_info(bool oldformat = false);
531 /// Returns true if a complete update is necessary, otherwise false
532 bool SetWidthOfMulticolCell(int cell, int new_width);
534 void recalculateMulticolumnsOfColumn(int column);
535 /// Returns true if change
536 bool calculate_width_of_column(int column);
538 bool calculate_width_of_column_NMC(int column); // no multi cells
540 void calculate_width_of_tabular();
542 cellstruct * cellinfo_of_cell(int cell) const;
544 void delete_column(int column);
546 int cells_in_multicolumn(int cell) const;
548 BoxType UseParbox(int cell) const;
550 void setHeaderFooterRows(int header, int fheader, int footer, int lfooter);
552 // helper function for Latex returns number of newlines
554 int TeXTopHLine(std::ostream &, int row) const;
556 int TeXBottomHLine(std::ostream &, int row) const;
558 int TeXCellPreamble(std::ostream &, int cell) const;
560 int TeXCellPostamble(std::ostream &, int cell) const;
562 int TeXLongtableHeaderFooter(std::ostream &, Buffer const * buf,
563 LatexRunParams const &, bool fragile, bool fp) const;
565 bool isValidRow(int const row) const;
567 int TeXRow(std::ostream &, int const row, Buffer const * buf,
568 LatexRunParams const &, bool fragile, bool fp) const;
570 // helper function for ASCII returns number of newlines
572 int asciiTopHLine(std::ostream &, int row,
573 std::vector<unsigned int> const &) const;
575 int asciiBottomHLine(std::ostream &, int row,
576 std::vector<unsigned int> const &) const;
578 int asciiPrintCell(Buffer const *, std::ostream &,
579 int cell, int row, int column,
580 std::vector<unsigned int> const &,
581 bool onlydata) const;
582 /// auxiliary function for docbook
583 int docbookRow(Buffer const * buf, std::ostream & os, int row) const;