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>
30 /* The features the text class offers for tables */
104 UNSET_ROTATE_TABULAR,
147 CELL_BEGIN_OF_MULTICOLUMN,
149 CELL_PART_OF_MULTICOLUMN
157 LYX_VALIGN_BOTTOM = 1,
159 LYX_VALIGN_MIDDLE = 2
175 // we have this header type (is set in the getLT... functions)
177 // double borders on top
179 // double borders on bottom
181 // used for FirstHeader & LastFooter and if this is true
182 // all the rows marked as FirstHeader or LastFooter are
183 // ignored in the output and it is set to be empty!
187 /// type for row numbers
188 typedef size_t row_type;
189 /// type for column numbers
190 typedef size_t col_type;
191 /// type for cell indices
192 typedef size_t idx_type;
193 /// index indicating an invalid position
194 static const idx_type npos = static_cast<idx_type>(-1);
197 LyXTabular(BufferParams const &, col_type columns_arg,
200 /// Returns true if there is a topline, returns false if not
201 bool topLine(idx_type cell, bool onlycolumn = false) const;
202 /// Returns true if there is a topline, returns false if not
203 bool bottomLine(idx_type cell, bool onlycolumn = false) const;
204 /// Returns true if there is a topline, returns false if not
205 bool leftLine(idx_type cell, bool onlycolumn = false) const;
206 /// Returns true if there is a topline, returns false if not
207 bool rightLine(idx_type cell, bool onlycolumn = false) const;
210 bool topAlreadyDrawn(idx_type cell) const;
212 bool leftAlreadyDrawn(idx_type cell) const;
214 bool isLastRow(idx_type cell) const;
216 /// return space occupied by the second horizontal line and
217 /// interline space above row \p row in pixels
218 int getAdditionalHeight(row_type row) const;
220 int getAdditionalWidth(idx_type cell) const;
222 /* returns the maximum over all rows */
224 int getWidthOfColumn(idx_type cell) const;
226 int getWidthOfTabular() const;
228 int getAscentOfRow(row_type row) const;
230 int getDescentOfRow(row_type row) const;
232 int getHeightOfTabular() const;
234 void setAscentOfRow(row_type row, int height);
236 void setDescentOfRow(row_type row, int height);
238 void setWidthOfCell(idx_type cell, int new_width);
240 void setAllLines(idx_type cell, bool line);
242 void setTopLine(idx_type cell, bool line, bool onlycolumn = false);
244 void setBottomLine(idx_type cell, bool line, bool onlycolumn = false);
246 void setLeftLine(idx_type cell, bool line, bool onlycolumn = false);
248 void setRightLine(idx_type cell, bool line, bool onlycolumn = false);
250 void setAlignment(idx_type cell, LyXAlignment align,
251 bool onlycolumn = false);
253 void setVAlignment(idx_type cell, VAlignment align,
254 bool onlycolumn = false);
256 void setColumnPWidth(LCursor &, idx_type, LyXLength const &);
258 bool setMColumnPWidth(LCursor &, idx_type, LyXLength const &);
260 void setAlignSpecial(idx_type cell, std::string const & special,
263 LyXAlignment getAlignment(idx_type cell,
264 bool onlycolumn = false) const;
266 VAlignment getVAlignment(idx_type cell,
267 bool onlycolumn = false) const;
269 LyXLength const getPWidth(idx_type cell) const;
271 LyXLength const getColumnPWidth(idx_type cell) const;
273 LyXLength const getMColumnPWidth(idx_type cell) const;
275 std::string const getAlignSpecial(idx_type cell, int what) const;
277 int getWidthOfCell(idx_type cell) const;
279 int getBeginningOfTextInCell(idx_type cell) const;
281 void appendRow(BufferParams const &, idx_type cell);
283 void deleteRow(row_type row);
285 void appendColumn(BufferParams const &, idx_type cell);
287 void deleteColumn(col_type column);
289 bool isFirstCellInRow(idx_type cell) const;
291 idx_type getFirstCellInRow(row_type row) const;
293 bool isLastCellInRow(idx_type cell) const;
295 idx_type getLastCellInRow(row_type row) const;
297 idx_type getNumberOfCells() const;
299 idx_type numberOfCellsInRow(idx_type cell) const;
301 void write(Buffer const &, std::ostream &) const;
303 void read(Buffer const &, LyXLex &);
305 int latex(Buffer const &, std::ostream &,
306 OutputParams const &) const;
308 int linuxdoc(Buffer const & buf, std::ostream & os,
309 OutputParams const &) const;
311 int docbook(Buffer const & buf, std::ostream & os,
312 OutputParams const &) const;
314 int plaintext(Buffer const &, std::ostream &,
315 OutputParams const & runparams,
317 bool onlydata, unsigned char delim) const;
319 bool isMultiColumn(idx_type cell) const;
321 bool isMultiColumnReal(idx_type cell) const;
323 void setMultiColumn(Buffer *, idx_type cell, idx_type number);
325 idx_type unsetMultiColumn(idx_type cell); // returns number of new cells
327 bool isPartOfMultiColumn(row_type row, col_type column) const;
329 row_type row_of_cell(idx_type cell) const;
331 col_type column_of_cell(idx_type cell) const;
333 col_type right_column_of_cell(idx_type cell) const;
335 void setBookTabs(bool);
337 bool useBookTabs() const;
339 void setLongTabular(bool);
341 bool isLongTabular() const;
343 void setRotateTabular(bool);
345 bool getRotateTabular() const;
347 void setRotateCell(idx_type cell, bool);
349 bool getRotateCell(idx_type cell) const;
351 bool needRotating() const;
353 bool isLastCell(idx_type cell) const;
355 idx_type getCellAbove(idx_type cell) const;
357 idx_type getCellBelow(idx_type cell) const;
359 idx_type getLastCellAbove(idx_type cell) const;
361 idx_type getLastCellBelow(idx_type cell) const;
363 idx_type getCellNumber(row_type row, col_type column) const;
365 void setUsebox(idx_type cell, BoxType);
367 BoxType getUsebox(idx_type cell) const;
369 // Long Tabular Options support functions
371 bool checkLTType(row_type row, ltType const &) const;
373 void setLTHead(row_type row, bool flag, ltType const &, bool first);
375 bool getRowOfLTHead(row_type row, ltType &) const;
377 bool getRowOfLTFirstHead(row_type row, ltType &) const;
379 void setLTFoot(row_type row, bool flag, ltType const &, bool last);
381 bool getRowOfLTFoot(row_type row, ltType &) const;
383 bool getRowOfLTLastFoot(row_type row, ltType &) const;
385 void setLTNewPage(row_type row, bool what);
387 bool getLTNewPage(row_type row) const;
389 bool haveLTHead() const;
391 bool haveLTFirstHead() const;
393 bool haveLTFoot() const;
395 bool haveLTLastFoot() const;
397 // end longtable support
399 boost::shared_ptr<InsetText> getCellInset(idx_type cell) const;
401 boost::shared_ptr<InsetText> getCellInset(row_type row,
402 col_type column) const;
404 void setCellInset(row_type row, col_type column,
405 boost::shared_ptr<InsetText>) const;
406 /// Search for \param inset in the tabular, with the
408 idx_type getCellFromInset(InsetBase const * inset) const;
410 row_type rows() const { return rows_; }
412 col_type columns() const { return columns_;}
414 void validate(LaTeXFeatures &) const;
421 cellstruct(BufferParams const &);
423 cellstruct(cellstruct const &);
425 cellstruct & operator=(cellstruct);
427 void swap(cellstruct & rhs);
435 LyXAlignment alignment;
437 VAlignment valignment;
451 std::string align_special;
453 LyXLength p_width; // this is only set for multicolumn!!!
455 boost::shared_ptr<InsetText> inset;
457 cellstruct & cellinfo_of_cell(idx_type cell) const;
459 typedef std::vector<cellstruct> cell_vector;
461 typedef std::vector<cell_vector> cell_vvector;
476 /// Extra space between the top line and this row
478 /// Ignore top_space if true and use the default top space
479 bool top_space_default;
480 /// Extra space between this row and the bottom line
481 LyXLength bottom_space;
482 /// Ignore bottom_space if true and use the default bottom space
483 bool bottom_space_default;
484 /// Extra space between the bottom line and the next top line
485 LyXLength interline_space;
486 /// Ignore interline_space if true and use the default interline space
487 bool interline_space_default;
488 /// This are for longtabulars only
491 /// a row of endfirsthead
495 /// row of endlastfoot
497 /// row for a pagebreak
501 typedef std::vector<rowstruct> row_vector;
509 LyXAlignment alignment;
511 VAlignment valignment;
521 std::string align_special;
524 typedef std::vector<columnstruct> column_vector;
531 idx_type numberofcells;
533 std::vector<row_type> rowofcell;
535 std::vector<col_type> columnofcell;
539 column_vector column_info;
541 mutable cell_vvector cell_info;
543 int width_of_tabular;
551 bool is_long_tabular;
554 /// endfirsthead data
562 void init(BufferParams const &, row_type rows_arg,
563 col_type columns_arg);
565 void set_row_column_number_info();
566 /// Returns true if a complete update is necessary, otherwise false
567 bool setWidthOfMulticolCell(idx_type cell, int new_width);
569 void recalculateMulticolumnsOfColumn(col_type column);
570 /// Returns true if change
571 void calculate_width_of_column(col_type column);
573 bool calculate_width_of_column_NMC(col_type column); // no multi cells
575 void calculate_width_of_tabular();
577 void delete_column(col_type column);
579 idx_type cells_in_multicolumn(idx_type cell) const;
581 BoxType useParbox(idx_type cell) const;
583 // helper function for Latex returns number of newlines
585 int TeXTopHLine(std::ostream &, row_type row) const;
587 int TeXBottomHLine(std::ostream &, row_type row) const;
589 int TeXCellPreamble(std::ostream &, idx_type cell) const;
591 int TeXCellPostamble(std::ostream &, idx_type cell) const;
593 int TeXLongtableHeaderFooter(std::ostream &, Buffer const & buf,
594 OutputParams const &) const;
596 bool isValidRow(row_type const row) const;
598 int TeXRow(std::ostream &, row_type const row, Buffer const & buf,
599 OutputParams const &) const;
601 // helper function for ASCII returns number of newlines
603 int asciiTopHLine(std::ostream &, row_type row,
604 std::vector<unsigned int> const &) const;
606 int asciiBottomHLine(std::ostream &, row_type row,
607 std::vector<unsigned int> const &) const;
609 int asciiPrintCell(Buffer const &, std::ostream &,
610 OutputParams const &,
611 idx_type cell, row_type row, col_type column,
612 std::vector<unsigned int> const &,
613 bool onlydata) const;
614 /// auxiliary function for docbook
615 int docbookRow(Buffer const & buf, std::ostream & os, row_type,
616 OutputParams const &) const;
619 /// renumber cells after structural changes