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 docbook(Buffer const & buf, std::ostream & os,
309 OutputParams const &) const;
311 int plaintext(Buffer const &, std::ostream &,
312 OutputParams const & runparams,
314 bool onlydata, unsigned char delim) const;
316 bool isMultiColumn(idx_type cell) const;
318 bool isMultiColumnReal(idx_type cell) const;
320 void setMultiColumn(Buffer *, idx_type cell, idx_type number);
322 idx_type unsetMultiColumn(idx_type cell); // returns number of new cells
324 bool isPartOfMultiColumn(row_type row, col_type column) const;
326 row_type row_of_cell(idx_type cell) const;
328 col_type column_of_cell(idx_type cell) const;
330 col_type right_column_of_cell(idx_type cell) const;
332 void setBookTabs(bool);
334 bool useBookTabs() const;
336 void setLongTabular(bool);
338 bool isLongTabular() const;
340 void setRotateTabular(bool);
342 bool getRotateTabular() const;
344 void setRotateCell(idx_type cell, bool);
346 bool getRotateCell(idx_type cell) const;
348 bool needRotating() const;
350 bool isLastCell(idx_type cell) const;
352 idx_type getCellAbove(idx_type cell) const;
354 idx_type getCellBelow(idx_type cell) const;
356 idx_type getLastCellAbove(idx_type cell) const;
358 idx_type getLastCellBelow(idx_type cell) const;
360 idx_type getCellNumber(row_type row, col_type column) const;
362 void setUsebox(idx_type cell, BoxType);
364 BoxType getUsebox(idx_type cell) const;
366 // Long Tabular Options support functions
368 bool checkLTType(row_type row, ltType const &) const;
370 void setLTHead(row_type row, bool flag, ltType const &, bool first);
372 bool getRowOfLTHead(row_type row, ltType &) const;
374 bool getRowOfLTFirstHead(row_type row, ltType &) const;
376 void setLTFoot(row_type row, bool flag, ltType const &, bool last);
378 bool getRowOfLTFoot(row_type row, ltType &) const;
380 bool getRowOfLTLastFoot(row_type row, ltType &) const;
382 void setLTNewPage(row_type row, bool what);
384 bool getLTNewPage(row_type row) const;
386 bool haveLTHead() const;
388 bool haveLTFirstHead() const;
390 bool haveLTFoot() const;
392 bool haveLTLastFoot() const;
394 // end longtable support
396 boost::shared_ptr<InsetText> getCellInset(idx_type cell) const;
398 boost::shared_ptr<InsetText> getCellInset(row_type row,
399 col_type column) const;
401 void setCellInset(row_type row, col_type column,
402 boost::shared_ptr<InsetText>) const;
403 /// Search for \param inset in the tabular, with the
405 idx_type getCellFromInset(InsetBase const * inset) const;
407 row_type rows() const { return rows_; }
409 col_type columns() const { return columns_;}
411 void validate(LaTeXFeatures &) const;
418 cellstruct(BufferParams const &);
420 cellstruct(cellstruct const &);
422 cellstruct & operator=(cellstruct);
424 void swap(cellstruct & rhs);
432 LyXAlignment alignment;
434 VAlignment valignment;
448 std::string align_special;
450 LyXLength p_width; // this is only set for multicolumn!!!
452 boost::shared_ptr<InsetText> inset;
454 cellstruct & cellinfo_of_cell(idx_type cell) const;
456 typedef std::vector<cellstruct> cell_vector;
458 typedef std::vector<cell_vector> cell_vvector;
473 /// Extra space between the top line and this row
475 /// Ignore top_space if true and use the default top space
476 bool top_space_default;
477 /// Extra space between this row and the bottom line
478 LyXLength bottom_space;
479 /// Ignore bottom_space if true and use the default bottom space
480 bool bottom_space_default;
481 /// Extra space between the bottom line and the next top line
482 LyXLength interline_space;
483 /// Ignore interline_space if true and use the default interline space
484 bool interline_space_default;
485 /// This are for longtabulars only
488 /// a row of endfirsthead
492 /// row of endlastfoot
494 /// row for a pagebreak
498 typedef std::vector<rowstruct> row_vector;
506 LyXAlignment alignment;
508 VAlignment valignment;
518 std::string align_special;
521 typedef std::vector<columnstruct> column_vector;
528 idx_type numberofcells;
530 std::vector<row_type> rowofcell;
532 std::vector<col_type> columnofcell;
536 column_vector column_info;
538 mutable cell_vvector cell_info;
540 int width_of_tabular;
548 bool is_long_tabular;
551 /// endfirsthead data
559 void init(BufferParams const &, row_type rows_arg,
560 col_type columns_arg);
562 void set_row_column_number_info();
563 /// Returns true if a complete update is necessary, otherwise false
564 bool setWidthOfMulticolCell(idx_type cell, int new_width);
566 void recalculateMulticolumnsOfColumn(col_type column);
567 /// Returns true if change
568 void calculate_width_of_column(col_type column);
570 bool calculate_width_of_column_NMC(col_type column); // no multi cells
572 void calculate_width_of_tabular();
574 void delete_column(col_type column);
576 idx_type cells_in_multicolumn(idx_type cell) const;
578 BoxType useParbox(idx_type cell) const;
580 // helper function for Latex returns number of newlines
582 int TeXTopHLine(std::ostream &, row_type row) const;
584 int TeXBottomHLine(std::ostream &, row_type row) const;
586 int TeXCellPreamble(std::ostream &, idx_type cell) const;
588 int TeXCellPostamble(std::ostream &, idx_type cell) const;
590 int TeXLongtableHeaderFooter(std::ostream &, Buffer const & buf,
591 OutputParams const &) const;
593 bool isValidRow(row_type const row) const;
595 int TeXRow(std::ostream &, row_type const row, Buffer const & buf,
596 OutputParams const &) const;
598 // helper function for ASCII returns number of newlines
600 int asciiTopHLine(std::ostream &, row_type row,
601 std::vector<unsigned int> const &) const;
603 int asciiBottomHLine(std::ostream &, row_type row,
604 std::vector<unsigned int> const &) const;
606 int asciiPrintCell(Buffer const &, std::ostream &,
607 OutputParams const &,
608 idx_type cell, row_type row, col_type column,
609 std::vector<unsigned int> const &,
610 bool onlydata) const;
611 /// auxiliary function for docbook
612 int docbookRow(Buffer const & buf, std::ostream & os, row_type,
613 OutputParams const &) const;
616 /// renumber cells after structural changes