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
163 // we have this header type (is set in the getLT... functions)
165 // double borders on top
167 // double borders on bottom
169 // used for FirstHeader & LastFooter and if this is true
170 // all the rows marked as FirstHeader or LastFooter are
171 // ignored in the output and it is set to be empty!
175 /// type for row numbers
176 typedef size_t row_type;
177 /// type for column numbers
178 typedef size_t col_type;
179 /// type for cell indices
180 typedef size_t idx_type;
181 /// index indicating an invalid position
182 static const idx_type npos = static_cast<idx_type>(-1);
185 LyXTabular(BufferParams const &, col_type columns_arg,
188 /// Returns true if there is a topline, returns false if not
189 bool topLine(idx_type cell, bool onlycolumn = false) const;
190 /// Returns true if there is a topline, returns false if not
191 bool bottomLine(idx_type cell, bool onlycolumn = false) const;
192 /// Returns true if there is a topline, returns false if not
193 bool leftLine(idx_type cell, bool onlycolumn = false) const;
194 /// Returns true if there is a topline, returns false if not
195 bool rightLine(idx_type cell, bool onlycolumn = false) const;
198 bool topAlreadyDrawn(idx_type cell) const;
200 bool leftAlreadyDrawn(idx_type cell) const;
202 bool isLastRow(idx_type cell) const;
205 int getAdditionalHeight(row_type row) const;
207 int getAdditionalWidth(idx_type cell) const;
209 /* returns the maximum over all rows */
211 int getWidthOfColumn(idx_type cell) const;
213 int getWidthOfTabular() const;
215 int getAscentOfRow(row_type row) const;
217 int getDescentOfRow(row_type row) const;
219 int getHeightOfTabular() const;
221 void setAscentOfRow(row_type row, int height);
223 void setDescentOfRow(row_type row, int height);
225 void setWidthOfCell(idx_type cell, int new_width);
227 void setAllLines(idx_type cell, bool line);
229 void setTopLine(idx_type cell, bool line, bool onlycolumn = false);
231 void setBottomLine(idx_type cell, bool line, bool onlycolumn = false);
233 void setLeftLine(idx_type cell, bool line, bool onlycolumn = false);
235 void setRightLine(idx_type cell, bool line, bool onlycolumn = false);
237 void setAlignment(idx_type cell, LyXAlignment align,
238 bool onlycolumn = false);
240 void setVAlignment(idx_type cell, VAlignment align,
241 bool onlycolumn = false);
243 void setColumnPWidth(idx_type cell, LyXLength const & width);
245 bool setMColumnPWidth(idx_type cell, LyXLength const & width);
247 void setAlignSpecial(idx_type cell, std::string const & special,
250 LyXAlignment getAlignment(idx_type cell,
251 bool onlycolumn = false) const;
253 VAlignment getVAlignment(idx_type cell,
254 bool onlycolumn = false) const;
256 LyXLength const getPWidth(idx_type cell) const;
258 LyXLength const getColumnPWidth(idx_type cell) const;
260 LyXLength const getMColumnPWidth(idx_type cell) const;
262 std::string const getAlignSpecial(idx_type cell, int what) const;
264 int getWidthOfCell(idx_type cell) const;
266 int getBeginningOfTextInCell(idx_type cell) const;
268 void appendRow(BufferParams const &, idx_type cell);
270 void deleteRow(row_type row);
272 void appendColumn(BufferParams const &, idx_type cell);
274 void deleteColumn(col_type column);
276 bool isFirstCellInRow(idx_type cell) const;
278 idx_type getFirstCellInRow(row_type row) const;
280 bool isLastCellInRow(idx_type cell) const;
282 idx_type getLastCellInRow(row_type row) const;
284 idx_type getNumberOfCells() const;
286 idx_type numberOfCellsInRow(idx_type cell) const;
288 void write(Buffer const &, std::ostream &) const;
290 void read(Buffer const &, LyXLex &);
292 int latex(Buffer const &, std::ostream &,
293 OutputParams const &) const;
295 int linuxdoc(Buffer const & buf, std::ostream & os,
296 OutputParams const &) const;
298 int docbook(Buffer const & buf, std::ostream & os,
299 OutputParams const &) const;
301 int plaintext(Buffer const &, std::ostream &,
302 OutputParams const & runparams,
304 bool onlydata, unsigned char delim) const;
306 bool isMultiColumn(idx_type cell) const;
308 bool isMultiColumnReal(idx_type cell) const;
310 void setMultiColumn(Buffer *, idx_type cell, idx_type number);
312 idx_type unsetMultiColumn(idx_type cell); // returns number of new cells
314 bool isPartOfMultiColumn(row_type row, col_type column) const;
316 row_type row_of_cell(idx_type cell) const;
318 col_type column_of_cell(idx_type cell) const;
320 col_type right_column_of_cell(idx_type cell) const;
322 void setLongTabular(bool);
324 bool isLongTabular() const;
326 void setRotateTabular(bool);
328 bool getRotateTabular() const;
330 void setRotateCell(idx_type cell, bool);
332 bool getRotateCell(idx_type cell) const;
334 bool needRotating() const;
336 bool isLastCell(idx_type cell) const;
338 idx_type getCellAbove(idx_type cell) const;
340 idx_type getCellBelow(idx_type cell) const;
342 idx_type getLastCellAbove(idx_type cell) const;
344 idx_type getLastCellBelow(idx_type cell) const;
346 idx_type getCellNumber(row_type row, col_type column) const;
348 void setUsebox(idx_type cell, BoxType);
350 BoxType getUsebox(idx_type cell) const;
352 // Long Tabular Options support functions
354 bool checkLTType(row_type row, ltType const &) const;
356 void setLTHead(row_type row, bool flag, ltType const &, bool first);
358 bool getRowOfLTHead(row_type row, ltType &) const;
360 bool getRowOfLTFirstHead(row_type row, ltType &) const;
362 void setLTFoot(row_type row, bool flag, ltType const &, bool last);
364 bool getRowOfLTFoot(row_type row, ltType &) const;
366 bool getRowOfLTLastFoot(row_type row, ltType &) const;
368 void setLTNewPage(row_type row, bool what);
370 bool getLTNewPage(row_type row) const;
372 bool haveLTHead() const;
374 bool haveLTFirstHead() const;
376 bool haveLTFoot() const;
378 bool haveLTLastFoot() const;
380 // end longtable support
382 boost::shared_ptr<InsetText> getCellInset(idx_type cell) const;
384 boost::shared_ptr<InsetText> getCellInset(row_type row,
385 col_type column) const;
386 /// Search for \param inset in the tabular, with the
388 idx_type getCellFromInset(InsetBase const * inset) const;
390 row_type rows() const { return rows_; }
392 col_type columns() const { return columns_;}
394 void validate(LaTeXFeatures &) const;
395 /// Appends \c list with all labels found within this inset.
396 void getLabelList(Buffer const &, std::vector<std::string> & list) const;
402 cellstruct(BufferParams const &);
404 cellstruct(cellstruct const &);
406 cellstruct & operator=(cellstruct);
408 void swap(cellstruct & rhs);
416 LyXAlignment alignment;
418 VAlignment valignment;
432 std::string align_special;
434 LyXLength p_width; // this is only set for multicolumn!!!
436 boost::shared_ptr<InsetText> inset;
438 cellstruct & cellinfo_of_cell(idx_type cell) const;
440 typedef std::vector<cellstruct> cell_vector;
442 typedef std::vector<cell_vector> cell_vvector;
456 /// This are for longtabulars only
459 /// a row of endfirsthead
463 /// row of endlastfoot
465 /// row for a pagebreak
469 typedef std::vector<rowstruct> row_vector;
472 struct columnstruct {
476 LyXAlignment alignment;
478 VAlignment valignment;
488 std::string align_special;
491 typedef std::vector<columnstruct> column_vector;
498 idx_type numberofcells;
500 std::vector<row_type> rowofcell;
502 std::vector<col_type> columnofcell;
506 column_vector column_info;
508 mutable cell_vvector cell_info;
510 int width_of_tabular;
516 bool is_long_tabular;
519 /// endfirsthead data
527 void init(BufferParams const &, row_type rows_arg,
528 col_type columns_arg);
530 void set_row_column_number_info();
531 /// Returns true if a complete update is necessary, otherwise false
532 bool setWidthOfMulticolCell(idx_type cell, int new_width);
534 void recalculateMulticolumnsOfColumn(col_type column);
535 /// Returns true if change
536 void calculate_width_of_column(col_type column);
538 bool calculate_width_of_column_NMC(col_type column); // no multi cells
540 void calculate_width_of_tabular();
542 void delete_column(col_type column);
544 idx_type cells_in_multicolumn(idx_type cell) const;
546 BoxType useParbox(idx_type cell) const;
548 // helper function for Latex returns number of newlines
550 int TeXTopHLine(std::ostream &, row_type row) const;
552 int TeXBottomHLine(std::ostream &, row_type row) const;
554 int TeXCellPreamble(std::ostream &, idx_type cell) const;
556 int TeXCellPostamble(std::ostream &, idx_type cell) const;
558 int TeXLongtableHeaderFooter(std::ostream &, Buffer const & buf,
559 OutputParams const &) const;
561 bool isValidRow(row_type const row) const;
563 int TeXRow(std::ostream &, row_type const row, Buffer const & buf,
564 OutputParams const &) const;
566 // helper function for ASCII returns number of newlines
568 int asciiTopHLine(std::ostream &, row_type row,
569 std::vector<unsigned int> const &) const;
571 int asciiBottomHLine(std::ostream &, row_type row,
572 std::vector<unsigned int> const &) const;
574 int asciiPrintCell(Buffer const &, std::ostream &,
575 OutputParams const &,
576 idx_type cell, row_type row, col_type column,
577 std::vector<unsigned int> const &,
578 bool onlydata) const;
579 /// auxiliary function for docbook
580 int docbookRow(Buffer const & buf, std::ostream & os, row_type,
581 OutputParams const &) const;
584 /// renumber cells after structural changes