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"
27 /* The features the text class offers for tables */
101 UNSET_ROTATE_TABULAR,
134 CELL_BEGIN_OF_MULTICOLUMN,
136 CELL_PART_OF_MULTICOLUMN
144 LYX_VALIGN_BOTTOM = 1,
146 LYX_VALIGN_MIDDLE = 2
161 // we have this header type (is set in the getLT... functions)
163 // double borders on top
165 // double borders on bottom
167 // used for FirstHeader & LastFooter and if this is true
168 // all the rows marked as FirstHeader or LastFooter are
169 // ignored in the output and it is set to be empty!
174 LyXTabular(BufferParams const &, int columns_arg, int rows_arg);
176 void setOwner(InsetTabular * inset);
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;
210 /// Returns true if a complete update is necessary, otherwise false
211 void setAscentOfRow(int row, int height);
212 /// Returns true if a complete update is necessary, otherwise false
213 void setDescentOfRow(int row, int height);
214 /// Returns true if a complete update is necessary, otherwise false
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 LatexRunParams const &) const;
282 int linuxdoc(Buffer const & buf, std::ostream & os) const;
284 int docbook(Buffer const & buf, std::ostream & os, bool mixcont) const;
286 int ascii(Buffer const &, std::ostream &, int const depth,
287 bool onlydata, unsigned char delim) const;
289 bool isMultiColumn(int cell) const;
291 bool isMultiColumnReal(int cell) const;
293 void setMultiColumn(Buffer *, int cell, int number);
295 int unsetMultiColumn(int cell); // returns number of new cells
297 bool isPartOfMultiColumn(int row, int column) const;
299 int row_of_cell(int cell) const;
301 int column_of_cell(int cell) const;
303 int right_column_of_cell(int cell) const;
305 void setLongTabular(bool);
307 bool isLongTabular() const;
309 void setRotateTabular(bool);
311 bool getRotateTabular() const;
313 void setRotateCell(int cell, bool);
315 bool getRotateCell(int cell) const;
317 bool needRotating() const;
319 bool isLastCell(int cell) const;
321 int getCellAbove(int cell) const;
323 int getCellBelow(int cell) const;
325 int getLastCellAbove(int cell) const;
327 int getLastCellBelow(int cell) const;
329 int getCellNumber(int row, int column) const;
331 void setUsebox(int cell, BoxType);
333 BoxType getUsebox(int cell) const;
335 // Long Tabular Options support functions
337 bool checkLTType(int row, ltType const &) const;
339 void setLTHead(int row, bool flag, ltType const &, bool first);
341 bool getRowOfLTHead(int row, ltType &) const;
343 bool getRowOfLTFirstHead(int row, ltType &) const;
345 void setLTFoot(int row, bool flag, ltType const &, bool last);
347 bool getRowOfLTFoot(int row, ltType &) const;
349 bool getRowOfLTLastFoot(int row, ltType &) const;
351 void setLTNewPage(int row, bool what);
353 bool getLTNewPage(int row) const;
355 bool haveLTHead() const;
357 bool haveLTFirstHead() const;
359 bool haveLTFoot() const;
361 bool haveLTLastFoot() const;
363 // end longtable support
365 InsetText & getCellInset(int cell) const;
367 InsetText & getCellInset(int row, int column) const;
368 /// Search for \param inset in the tabular, with the
370 int getCellFromInset(InsetOld const * inset) const;
372 int rows() const { return rows_; }
374 int columns() const { return columns_;}
376 void validate(LaTeXFeatures &) const;
377 /// Appends \c list with all labels found within this inset.
378 void getLabelList(Buffer const &, std::vector<std::string> & list) const;
384 cellstruct(BufferParams const &);
392 LyXAlignment alignment;
394 VAlignment valignment;
408 std::string align_special;
410 LyXLength p_width; // this is only set for multicolumn!!!
414 cellstruct & cellinfo_of_cell(int cell) const;
416 typedef std::vector<cellstruct> cell_vector;
418 typedef std::vector<cell_vector> cell_vvector;
432 /// This are for longtabulars only
435 /// a row of endfirsthead
439 /// row of endlastfoot
441 /// row for a pagebreak
445 typedef std::vector<rowstruct> row_vector;
448 struct columnstruct {
452 LyXAlignment alignment;
454 VAlignment valignment;
464 std::string align_special;
467 typedef std::vector<columnstruct> column_vector;
476 std::vector<int> rowofcell;
478 std::vector<int> columnofcell;
482 column_vector column_info;
484 mutable cell_vvector cell_info;
486 int width_of_tabular;
492 bool is_long_tabular;
495 /// endfirsthead data
503 void init(BufferParams const &, int rows_arg, int columns_arg);
505 void set_row_column_number_info(bool oldformat = false);
506 /// Returns true if a complete update is necessary, otherwise false
507 bool setWidthOfMulticolCell(int cell, int new_width);
509 void recalculateMulticolumnsOfColumn(int column);
510 /// Returns true if change
511 void calculate_width_of_column(int column);
513 bool calculate_width_of_column_NMC(int column); // no multi cells
515 void calculate_width_of_tabular();
517 void delete_column(int column);
519 int cells_in_multicolumn(int cell) const;
521 BoxType useParbox(int cell) const;
523 void setHeaderFooterRows(int header, int fheader, int footer, int lfooter);
525 // helper function for Latex returns number of newlines
527 int TeXTopHLine(std::ostream &, int row) const;
529 int TeXBottomHLine(std::ostream &, int row) const;
531 int TeXCellPreamble(std::ostream &, int cell) const;
533 int TeXCellPostamble(std::ostream &, int cell) const;
535 int TeXLongtableHeaderFooter(std::ostream &, Buffer const & buf,
536 LatexRunParams const &) const;
538 bool isValidRow(int const row) const;
540 int TeXRow(std::ostream &, int const row, Buffer const & buf,
541 LatexRunParams const &) const;
543 // helper function for ASCII returns number of newlines
545 int asciiTopHLine(std::ostream &, int row,
546 std::vector<unsigned int> const &) const;
548 int asciiBottomHLine(std::ostream &, int row,
549 std::vector<unsigned int> const &) const;
551 int asciiPrintCell(Buffer const &, std::ostream &,
552 int cell, int row, int column,
553 std::vector<unsigned int> const &,
554 bool onlydata) const;
555 /// auxiliary function for docbook
556 int docbookRow(Buffer const & buf, std::ostream & os, int row) const;