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!
176 LyXTabular(BufferParams const &, int columns_arg, int rows_arg);
178 /// Returns true if there is a topline, returns false if not
179 bool topLine(int cell, bool onlycolumn = false) const;
180 /// Returns true if there is a topline, returns false if not
181 bool bottomLine(int cell, bool onlycolumn = false) const;
182 /// Returns true if there is a topline, returns false if not
183 bool leftLine(int cell, bool onlycolumn = false) const;
184 /// Returns true if there is a topline, returns false if not
185 bool rightLine(int cell, bool onlycolumn = false) const;
188 bool topAlreadyDrawn(int cell) const;
190 bool leftAlreadyDrawn(int cell) const;
192 bool isLastRow(int cell) const;
195 int getAdditionalHeight(int row) const;
197 int getAdditionalWidth(int cell) const;
199 /* returns the maximum over all rows */
201 int getWidthOfColumn(int cell) const;
203 int getWidthOfTabular() const;
205 int getAscentOfRow(int row) const;
207 int getDescentOfRow(int row) const;
209 int getHeightOfTabular() const;
211 void setAscentOfRow(int row, int height);
213 void setDescentOfRow(int row, int height);
215 void setWidthOfCell(int cell, int new_width);
217 void setAllLines(int cell, bool line);
219 void setTopLine(int cell, bool line, bool onlycolumn = false);
221 void setBottomLine(int cell, bool line, bool onlycolumn = false);
223 void setLeftLine(int cell, bool line, bool onlycolumn = false);
225 void setRightLine(int cell, bool line, bool onlycolumn = false);
227 void setAlignment(int cell, LyXAlignment align,
228 bool onlycolumn = false);
230 void setVAlignment(int cell, VAlignment align,
231 bool onlycolumn = false);
233 void setColumnPWidth(int cell, LyXLength const & width);
235 bool setMColumnPWidth(int cell, LyXLength const & width);
237 void setAlignSpecial(int cell, std::string const & special, Feature what);
239 LyXAlignment getAlignment(int cell, bool onlycolumn = false) const;
241 VAlignment getVAlignment(int cell, bool onlycolumn = false) const;
243 LyXLength const getPWidth(int cell) const;
245 LyXLength const getColumnPWidth(int cell) const;
247 LyXLength const getMColumnPWidth(int cell) const;
249 std::string const getAlignSpecial(int cell, int what) const;
251 int getWidthOfCell(int cell) const;
253 int getBeginningOfTextInCell(int cell) const;
255 void appendRow(BufferParams const &, int cell);
257 void deleteRow(int row);
259 void appendColumn(BufferParams const &, int cell);
261 void deleteColumn(int column);
263 bool isFirstCellInRow(int cell) const;
265 int getFirstCellInRow(int row) const;
267 bool isLastCellInRow(int cell) const;
269 int getLastCellInRow(int row) const;
271 int getNumberOfCells() const;
273 int numberOfCellsInRow(int cell) const;
275 void write(Buffer const &, std::ostream &) const;
277 void read(Buffer const &, LyXLex &);
279 int latex(Buffer const &, std::ostream &,
280 OutputParams const &) const;
282 int linuxdoc(Buffer const & buf, std::ostream & os,
283 OutputParams const &) const;
285 int docbook(Buffer const & buf, std::ostream & os,
286 OutputParams const &) const;
288 int plaintext(Buffer const &, std::ostream &,
289 OutputParams const & runparams,
291 bool onlydata, unsigned char delim) const;
293 bool isMultiColumn(int cell) const;
295 bool isMultiColumnReal(int cell) const;
297 void setMultiColumn(Buffer *, int cell, int number);
299 int unsetMultiColumn(int cell); // returns number of new cells
301 bool isPartOfMultiColumn(int row, int column) const;
303 int row_of_cell(int cell) const;
305 int column_of_cell(int cell) const;
307 int right_column_of_cell(int cell) const;
309 void setLongTabular(bool);
311 bool isLongTabular() const;
313 void setRotateTabular(bool);
315 bool getRotateTabular() const;
317 void setRotateCell(int cell, bool);
319 bool getRotateCell(int cell) const;
321 bool needRotating() const;
323 bool isLastCell(int cell) const;
325 int getCellAbove(int cell) const;
327 int getCellBelow(int cell) const;
329 int getLastCellAbove(int cell) const;
331 int getLastCellBelow(int cell) const;
333 int getCellNumber(int row, int column) const;
335 void setUsebox(int cell, BoxType);
337 BoxType getUsebox(int cell) const;
339 // Long Tabular Options support functions
341 bool checkLTType(int row, ltType const &) const;
343 void setLTHead(int row, bool flag, ltType const &, bool first);
345 bool getRowOfLTHead(int row, ltType &) const;
347 bool getRowOfLTFirstHead(int row, ltType &) const;
349 void setLTFoot(int row, bool flag, ltType const &, bool last);
351 bool getRowOfLTFoot(int row, ltType &) const;
353 bool getRowOfLTLastFoot(int row, ltType &) const;
355 void setLTNewPage(int row, bool what);
357 bool getLTNewPage(int row) const;
359 bool haveLTHead() const;
361 bool haveLTFirstHead() const;
363 bool haveLTFoot() const;
365 bool haveLTLastFoot() const;
367 // end longtable support
369 boost::shared_ptr<InsetText> getCellInset(int cell) const;
371 boost::shared_ptr<InsetText> getCellInset(int row, int column) const;
372 /// Search for \param inset in the tabular, with the
374 int getCellFromInset(InsetBase const * inset) const;
376 int rows() const { return rows_; }
378 int columns() const { return columns_;}
380 void validate(LaTeXFeatures &) const;
381 /// Appends \c list with all labels found within this inset.
382 void getLabelList(Buffer const &, std::vector<std::string> & list) const;
388 cellstruct(BufferParams const &);
390 cellstruct(cellstruct const &);
392 cellstruct & operator=(cellstruct);
394 void swap(cellstruct & rhs);
402 LyXAlignment alignment;
404 VAlignment valignment;
418 std::string align_special;
420 LyXLength p_width; // this is only set for multicolumn!!!
422 boost::shared_ptr<InsetText> inset;
424 cellstruct & cellinfo_of_cell(int cell) const;
426 typedef std::vector<cellstruct> cell_vector;
428 typedef std::vector<cell_vector> cell_vvector;
442 /// This are for longtabulars only
445 /// a row of endfirsthead
449 /// row of endlastfoot
451 /// row for a pagebreak
455 typedef std::vector<rowstruct> row_vector;
458 struct columnstruct {
462 LyXAlignment alignment;
464 VAlignment valignment;
474 std::string align_special;
477 typedef std::vector<columnstruct> column_vector;
486 std::vector<int> rowofcell;
488 std::vector<int> columnofcell;
492 column_vector column_info;
494 mutable cell_vvector cell_info;
496 int width_of_tabular;
502 bool is_long_tabular;
505 /// endfirsthead data
513 void init(BufferParams const &, int rows_arg, int columns_arg);
515 void set_row_column_number_info();
516 /// Returns true if a complete update is necessary, otherwise false
517 bool setWidthOfMulticolCell(int cell, int new_width);
519 void recalculateMulticolumnsOfColumn(int column);
520 /// Returns true if change
521 void calculate_width_of_column(int column);
523 bool calculate_width_of_column_NMC(int column); // no multi cells
525 void calculate_width_of_tabular();
527 void delete_column(int column);
529 int cells_in_multicolumn(int cell) const;
531 BoxType useParbox(int cell) const;
533 void setHeaderFooterRows(int header, int fheader, int footer, int lfooter);
535 // helper function for Latex returns number of newlines
537 int TeXTopHLine(std::ostream &, int row) const;
539 int TeXBottomHLine(std::ostream &, int row) const;
541 int TeXCellPreamble(std::ostream &, int cell) const;
543 int TeXCellPostamble(std::ostream &, int cell) const;
545 int TeXLongtableHeaderFooter(std::ostream &, Buffer const & buf,
546 OutputParams const &) const;
548 bool isValidRow(int const row) const;
550 int TeXRow(std::ostream &, int const row, Buffer const & buf,
551 OutputParams const &) const;
553 // helper function for ASCII returns number of newlines
555 int asciiTopHLine(std::ostream &, int row,
556 std::vector<unsigned int> const &) const;
558 int asciiBottomHLine(std::ostream &, int row,
559 std::vector<unsigned int> const &) const;
561 int asciiPrintCell(Buffer const &, std::ostream &,
562 OutputParams const &,
563 int cell, int row, int column,
564 std::vector<unsigned int> const &,
565 bool onlydata) const;
566 /// auxiliary function for docbook
567 int docbookRow(Buffer const & buf, std::ostream & os, int,
568 OutputParams const &) const;
571 /// renumber cells after structural changes