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