4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Matthias Ettrich
10 * \author Jürgen Vigna
12 * Full author contact details are available in file CREDITS.
18 #include "lyxlength.h"
19 #include "insets/insettext.h"
21 #include <boost/shared_ptr.hpp>
29 /* The features the text class offers for tables */
103 UNSET_ROTATE_TABULAR,
136 CELL_BEGIN_OF_MULTICOLUMN,
138 CELL_PART_OF_MULTICOLUMN
146 LYX_VALIGN_BOTTOM = 1,
148 LYX_VALIGN_MIDDLE = 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 /// type for row numbers
177 typedef size_t row_type;
178 /// type for column numbers
179 typedef size_t col_type;
180 /// type for cell indices
181 typedef size_t idx_type;
182 /// index indicating an invalid position
183 static const idx_type npos = static_cast<idx_type>(-1);
186 LyXTabular(BufferParams const &, col_type columns_arg,
189 /// Returns true if there is a topline, returns false if not
190 bool topLine(idx_type cell, bool onlycolumn = false) const;
191 /// Returns true if there is a topline, returns false if not
192 bool bottomLine(idx_type cell, bool onlycolumn = false) const;
193 /// Returns true if there is a topline, returns false if not
194 bool leftLine(idx_type cell, bool onlycolumn = false) const;
195 /// Returns true if there is a topline, returns false if not
196 bool rightLine(idx_type cell, bool onlycolumn = false) const;
199 bool topAlreadyDrawn(idx_type cell) const;
201 bool leftAlreadyDrawn(idx_type cell) const;
203 bool isLastRow(idx_type cell) const;
206 int getAdditionalHeight(row_type row) const;
208 int getAdditionalWidth(idx_type cell) const;
210 /* returns the maximum over all rows */
212 int getWidthOfColumn(idx_type cell) const;
214 int getWidthOfTabular() const;
216 int getAscentOfRow(row_type row) const;
218 int getDescentOfRow(row_type row) const;
220 int getHeightOfTabular() const;
222 void setAscentOfRow(row_type row, int height);
224 void setDescentOfRow(row_type row, int height);
226 void setWidthOfCell(idx_type cell, int new_width);
228 void setAllLines(idx_type cell, bool line);
230 void setTopLine(idx_type cell, bool line, bool onlycolumn = false);
232 void setBottomLine(idx_type cell, bool line, bool onlycolumn = false);
234 void setLeftLine(idx_type cell, bool line, bool onlycolumn = false);
236 void setRightLine(idx_type cell, bool line, bool onlycolumn = false);
238 void setAlignment(idx_type cell, LyXAlignment align,
239 bool onlycolumn = false);
241 void setVAlignment(idx_type cell, VAlignment align,
242 bool onlycolumn = false);
244 void setColumnPWidth(idx_type cell, LyXLength const & width);
246 bool setMColumnPWidth(idx_type cell, LyXLength const & width);
248 void setAlignSpecial(idx_type cell, std::string const & special,
251 LyXAlignment getAlignment(idx_type cell,
252 bool onlycolumn = false) const;
254 VAlignment getVAlignment(idx_type cell,
255 bool onlycolumn = false) const;
257 LyXLength const getPWidth(idx_type cell) const;
259 LyXLength const getColumnPWidth(idx_type cell) const;
261 LyXLength const getMColumnPWidth(idx_type cell) const;
263 std::string const getAlignSpecial(idx_type cell, int what) const;
265 int getWidthOfCell(idx_type cell) const;
267 int getBeginningOfTextInCell(idx_type cell) const;
269 void appendRow(BufferParams const &, idx_type cell);
271 void deleteRow(row_type row);
273 void appendColumn(BufferParams const &, idx_type cell);
275 void deleteColumn(col_type column);
277 bool isFirstCellInRow(idx_type cell) const;
279 idx_type getFirstCellInRow(row_type row) const;
281 bool isLastCellInRow(idx_type cell) const;
283 idx_type getLastCellInRow(row_type row) const;
285 idx_type getNumberOfCells() const;
287 idx_type numberOfCellsInRow(idx_type cell) const;
289 void write(Buffer const &, std::ostream &) const;
291 void read(Buffer const &, LyXLex &);
293 int latex(Buffer const &, std::ostream &,
294 OutputParams const &) const;
296 int linuxdoc(Buffer const & buf, std::ostream & os,
297 OutputParams const &) const;
299 int docbook(Buffer const & buf, std::ostream & os,
300 OutputParams const &) const;
302 int plaintext(Buffer const &, std::ostream &,
303 OutputParams const & runparams,
305 bool onlydata, unsigned char delim) const;
307 bool isMultiColumn(idx_type cell) const;
309 bool isMultiColumnReal(idx_type cell) const;
311 void setMultiColumn(Buffer *, idx_type cell, idx_type number);
313 idx_type unsetMultiColumn(idx_type cell); // returns number of new cells
315 bool isPartOfMultiColumn(row_type row, col_type column) const;
317 row_type row_of_cell(idx_type cell) const;
319 col_type column_of_cell(idx_type cell) const;
321 col_type right_column_of_cell(idx_type cell) const;
323 void setLongTabular(bool);
325 bool isLongTabular() const;
327 void setRotateTabular(bool);
329 bool getRotateTabular() const;
331 void setRotateCell(idx_type cell, bool);
333 bool getRotateCell(idx_type cell) const;
335 bool needRotating() const;
337 bool isLastCell(idx_type cell) const;
339 idx_type getCellAbove(idx_type cell) const;
341 idx_type getCellBelow(idx_type cell) const;
343 idx_type getLastCellAbove(idx_type cell) const;
345 idx_type getLastCellBelow(idx_type cell) const;
347 idx_type getCellNumber(row_type row, col_type column) const;
349 void setUsebox(idx_type cell, BoxType);
351 BoxType getUsebox(idx_type cell) const;
353 // Long Tabular Options support functions
355 bool checkLTType(row_type row, ltType const &) const;
357 void setLTHead(row_type row, bool flag, ltType const &, bool first);
359 bool getRowOfLTHead(row_type row, ltType &) const;
361 bool getRowOfLTFirstHead(row_type row, ltType &) const;
363 void setLTFoot(row_type row, bool flag, ltType const &, bool last);
365 bool getRowOfLTFoot(row_type row, ltType &) const;
367 bool getRowOfLTLastFoot(row_type row, ltType &) const;
369 void setLTNewPage(row_type row, bool what);
371 bool getLTNewPage(row_type row) const;
373 bool haveLTHead() const;
375 bool haveLTFirstHead() const;
377 bool haveLTFoot() const;
379 bool haveLTLastFoot() const;
381 // end longtable support
383 boost::shared_ptr<InsetText> getCellInset(idx_type cell) const;
385 boost::shared_ptr<InsetText> getCellInset(row_type row,
386 col_type column) const;
388 void setCellInset(row_type row, col_type column,
389 boost::shared_ptr<InsetText>) const;
390 /// Search for \param inset in the tabular, with the
392 idx_type getCellFromInset(InsetBase const * inset) const;
394 row_type rows() const { return rows_; }
396 col_type columns() const { return columns_;}
398 void validate(LaTeXFeatures &) const;
399 /// Appends \c list with all labels found within this inset.
400 void getLabelList(Buffer const &, std::vector<std::string> & list) const;
407 cellstruct(BufferParams const &);
409 cellstruct(cellstruct const &);
411 cellstruct & operator=(cellstruct);
413 void swap(cellstruct & rhs);
421 LyXAlignment alignment;
423 VAlignment valignment;
437 std::string align_special;
439 LyXLength p_width; // this is only set for multicolumn!!!
441 boost::shared_ptr<InsetText> inset;
443 cellstruct & cellinfo_of_cell(idx_type cell) const;
445 typedef std::vector<cellstruct> cell_vector;
447 typedef std::vector<cell_vector> cell_vvector;
462 /// This are for longtabulars only
465 /// a row of endfirsthead
469 /// row of endlastfoot
471 /// row for a pagebreak
475 typedef std::vector<rowstruct> row_vector;
483 LyXAlignment alignment;
485 VAlignment valignment;
495 std::string align_special;
498 typedef std::vector<columnstruct> column_vector;
505 idx_type numberofcells;
507 std::vector<row_type> rowofcell;
509 std::vector<col_type> columnofcell;
513 column_vector column_info;
515 mutable cell_vvector cell_info;
517 int width_of_tabular;
523 bool is_long_tabular;
526 /// endfirsthead data
534 void init(BufferParams const &, row_type rows_arg,
535 col_type columns_arg);
537 void set_row_column_number_info();
538 /// Returns true if a complete update is necessary, otherwise false
539 bool setWidthOfMulticolCell(idx_type cell, int new_width);
541 void recalculateMulticolumnsOfColumn(col_type column);
542 /// Returns true if change
543 void calculate_width_of_column(col_type column);
545 bool calculate_width_of_column_NMC(col_type column); // no multi cells
547 void calculate_width_of_tabular();
549 void delete_column(col_type column);
551 idx_type cells_in_multicolumn(idx_type cell) const;
553 BoxType useParbox(idx_type cell) const;
555 // helper function for Latex returns number of newlines
557 int TeXTopHLine(std::ostream &, row_type row) const;
559 int TeXBottomHLine(std::ostream &, row_type row) const;
561 int TeXCellPreamble(std::ostream &, idx_type cell) const;
563 int TeXCellPostamble(std::ostream &, idx_type cell) const;
565 int TeXLongtableHeaderFooter(std::ostream &, Buffer const & buf,
566 OutputParams const &) const;
568 bool isValidRow(row_type const row) const;
570 int TeXRow(std::ostream &, row_type const row, Buffer const & buf,
571 OutputParams const &) const;
573 // helper function for ASCII returns number of newlines
575 int asciiTopHLine(std::ostream &, row_type row,
576 std::vector<unsigned int> const &) const;
578 int asciiBottomHLine(std::ostream &, row_type row,
579 std::vector<unsigned int> const &) const;
581 int asciiPrintCell(Buffer const &, std::ostream &,
582 OutputParams const &,
583 idx_type cell, row_type row, col_type column,
584 std::vector<unsigned int> const &,
585 bool onlydata) const;
586 /// auxiliary function for docbook
587 int docbookRow(Buffer const & buf, std::ostream & os, row_type,
588 OutputParams const &) const;
591 /// renumber cells after structural changes