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>
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_MIDDLE = 2
166 // we have this header type (is set in the getLT... functions)
168 // double borders on top
170 // double borders on bottom
172 // used for FirstHeader & LastFooter and if this is true
173 // all the rows marked as FirstHeader or LastFooter are
174 // ignored in the output and it is set to be empty!
178 /// type for row numbers
179 typedef size_t row_type;
180 /// type for column numbers
181 typedef size_t col_type;
182 /// type for cell indices
183 typedef size_t idx_type;
184 /// index indicating an invalid position
185 static const idx_type npos = static_cast<idx_type>(-1);
188 LyXTabular(BufferParams const &, col_type columns_arg,
189 row_type rows_arg, BufferView const *);
191 /// Returns true if there is a topline, returns false if not
192 bool topLine(idx_type cell, bool onlycolumn = false) const;
193 /// Returns true if there is a topline, returns false if not
194 bool bottomLine(idx_type cell, bool onlycolumn = false) const;
195 /// Returns true if there is a topline, returns false if not
196 bool leftLine(idx_type cell, bool onlycolumn = false) const;
197 /// Returns true if there is a topline, returns false if not
198 bool rightLine(idx_type cell, bool onlycolumn = false) const;
201 bool topAlreadyDrawn(idx_type cell) const;
203 bool leftAlreadyDrawn(idx_type cell) const;
205 bool isLastRow(idx_type cell) const;
208 int getAdditionalHeight(row_type row) const;
210 int getAdditionalWidth(idx_type cell) const;
212 /* returns the maximum over all rows */
214 int getWidthOfColumn(idx_type cell) const;
216 int getWidthOfTabular() const;
218 int getAscentOfRow(row_type row) const;
220 int getDescentOfRow(row_type row) const;
222 int getHeightOfTabular() const;
224 void setAscentOfRow(row_type row, int height);
226 void setDescentOfRow(row_type row, int height);
228 void setWidthOfCell(idx_type cell, int new_width);
230 void setAllLines(idx_type cell, bool line);
232 void setTopLine(idx_type cell, bool line, bool onlycolumn = false);
234 void setBottomLine(idx_type cell, bool line, bool onlycolumn = false);
236 void setLeftLine(idx_type cell, bool line, bool onlycolumn = false);
238 void setRightLine(idx_type cell, bool line, bool onlycolumn = false);
240 void setAlignment(idx_type cell, LyXAlignment align,
241 bool onlycolumn = false);
243 void setVAlignment(idx_type cell, VAlignment align,
244 bool onlycolumn = false);
246 void setColumnPWidth(LCursor &, idx_type, LyXLength const &);
248 bool setMColumnPWidth(LCursor &, idx_type, LyXLength const &);
250 void setAlignSpecial(idx_type cell, std::string const & special,
253 LyXAlignment getAlignment(idx_type cell,
254 bool onlycolumn = false) const;
256 VAlignment getVAlignment(idx_type cell,
257 bool onlycolumn = false) const;
259 LyXLength const getPWidth(idx_type cell) const;
261 LyXLength const getColumnPWidth(idx_type cell) const;
263 LyXLength const getMColumnPWidth(idx_type cell) const;
265 std::string const getAlignSpecial(idx_type cell, int what) const;
267 int getWidthOfCell(idx_type cell) const;
269 int getBeginningOfTextInCell(idx_type cell) const;
271 void appendRow(BufferParams const &, idx_type cell);
273 void deleteRow(row_type row);
275 void appendColumn(BufferParams const &, idx_type cell);
277 void deleteColumn(col_type column);
279 bool isFirstCellInRow(idx_type cell) const;
281 idx_type getFirstCellInRow(row_type row) const;
283 bool isLastCellInRow(idx_type cell) const;
285 idx_type getLastCellInRow(row_type row) const;
287 idx_type getNumberOfCells() const;
289 idx_type numberOfCellsInRow(idx_type cell) const;
291 void write(Buffer const &, std::ostream &) const;
293 void read(Buffer const &, LyXLex &);
295 int latex(Buffer const &, std::ostream &,
296 OutputParams const &) const;
298 int linuxdoc(Buffer const & buf, std::ostream & os,
299 OutputParams const &) const;
301 int docbook(Buffer const & buf, std::ostream & os,
302 OutputParams const &) const;
304 int plaintext(Buffer const &, std::ostream &,
305 OutputParams const & runparams,
307 bool onlydata, unsigned char delim) const;
309 bool isMultiColumn(idx_type cell) const;
311 bool isMultiColumnReal(idx_type cell) const;
313 void setMultiColumn(Buffer *, idx_type cell, idx_type number);
315 idx_type unsetMultiColumn(idx_type cell); // returns number of new cells
317 bool isPartOfMultiColumn(row_type row, col_type column) const;
319 row_type row_of_cell(idx_type cell) const;
321 col_type column_of_cell(idx_type cell) const;
323 col_type right_column_of_cell(idx_type cell) const;
325 void setLongTabular(bool);
327 bool isLongTabular() const;
329 void setRotateTabular(bool);
331 bool getRotateTabular() const;
333 void setRotateCell(idx_type cell, bool);
335 bool getRotateCell(idx_type cell) const;
337 bool needRotating() const;
339 bool isLastCell(idx_type cell) const;
341 idx_type getCellAbove(idx_type cell) const;
343 idx_type getCellBelow(idx_type cell) const;
345 idx_type getLastCellAbove(idx_type cell) const;
347 idx_type getLastCellBelow(idx_type cell) const;
349 idx_type getCellNumber(row_type row, col_type column) const;
351 void setUsebox(idx_type cell, BoxType);
353 BoxType getUsebox(idx_type cell) const;
355 // Long Tabular Options support functions
357 bool checkLTType(row_type row, ltType const &) const;
359 void setLTHead(row_type row, bool flag, ltType const &, bool first);
361 bool getRowOfLTHead(row_type row, ltType &) const;
363 bool getRowOfLTFirstHead(row_type row, ltType &) const;
365 void setLTFoot(row_type row, bool flag, ltType const &, bool last);
367 bool getRowOfLTFoot(row_type row, ltType &) const;
369 bool getRowOfLTLastFoot(row_type row, ltType &) const;
371 void setLTNewPage(row_type row, bool what);
373 bool getLTNewPage(row_type row) const;
375 bool haveLTHead() const;
377 bool haveLTFirstHead() const;
379 bool haveLTFoot() const;
381 bool haveLTLastFoot() const;
383 // end longtable support
385 boost::shared_ptr<InsetText> getCellInset(idx_type cell) const;
387 boost::shared_ptr<InsetText> getCellInset(row_type row,
388 col_type column) const;
390 void setCellInset(row_type row, col_type column,
391 boost::shared_ptr<InsetText>) const;
392 /// Search for \param inset in the tabular, with the
394 idx_type getCellFromInset(InsetBase const * inset) const;
396 row_type rows() const { return rows_; }
398 col_type columns() const { return columns_;}
400 void validate(LaTeXFeatures &) const;
407 cellstruct(BufferParams const &, BufferView 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, BufferView const *);
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