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 &,
175 InsetTabular *, int columns_arg, int rows_arg);
176 /// sort of copy constructor
177 LyXTabular(BufferParams const &,
178 InsetTabular *, LyXTabular const &);
181 LyXTabular(Buffer const &, InsetTabular *, LyXLex & lex);
183 /// Returns true if there is a topline, returns false if not
184 bool topLine(int cell, bool onlycolumn = false) const;
185 /// Returns true if there is a topline, returns false if not
186 bool bottomLine(int cell, bool onlycolumn = false) const;
187 /// Returns true if there is a topline, returns false if not
188 bool leftLine(int cell, bool onlycolumn = false) const;
189 /// Returns true if there is a topline, returns false if not
190 bool rightLine(int cell, bool onlycolumn = false) const;
193 bool topAlreadyDrawn(int cell) const;
195 bool leftAlreadyDrawn(int cell) const;
197 bool isLastRow(int cell) const;
200 int getAdditionalHeight(int row) const;
202 int getAdditionalWidth(int cell) const;
204 /* returns the maximum over all rows */
206 int getWidthOfColumn(int cell) const;
208 int getWidthOfTabular() const;
210 int getAscentOfRow(int row) const;
212 int getDescentOfRow(int row) const;
214 int getHeightOfTabular() const;
215 /// Returns true if a complete update is necessary, otherwise false
216 void setAscentOfRow(int row, int height);
217 /// Returns true if a complete update is necessary, otherwise false
218 void setDescentOfRow(int row, int height);
219 /// Returns true if a complete update is necessary, otherwise false
220 void setWidthOfCell(int cell, int new_width);
222 void setAllLines(int cell, bool line);
224 void setTopLine(int cell, bool line, bool onlycolumn = false);
226 void setBottomLine(int cell, bool line, bool onlycolumn = false);
228 void setLeftLine(int cell, bool line, bool onlycolumn = false);
230 void setRightLine(int cell, bool line, bool onlycolumn = false);
232 void setAlignment(int cell, LyXAlignment align,
233 bool onlycolumn = false);
235 void setVAlignment(int cell, VAlignment align,
236 bool onlycolumn = false);
238 void setColumnPWidth(int cell, LyXLength const & width);
240 bool setMColumnPWidth(int cell, LyXLength const & width);
242 void setAlignSpecial(int cell, string const & special, Feature what);
244 LyXAlignment getAlignment(int cell, bool onlycolumn = false) const;
246 VAlignment getVAlignment(int cell, bool onlycolumn = false) const;
248 LyXLength const getPWidth(int cell) const;
250 LyXLength const getColumnPWidth(int cell) const;
252 LyXLength const getMColumnPWidth(int cell) const;
254 string const getAlignSpecial(int cell, int what) const;
256 int getWidthOfCell(int cell) const;
258 int getBeginningOfTextInCell(int cell) const;
260 void appendRow(BufferParams const &, int cell);
262 void deleteRow(int row);
264 void appendColumn(BufferParams const &, int cell);
266 void deleteColumn(int column);
268 bool isFirstCellInRow(int cell) const;
270 int getFirstCellInRow(int row) const;
272 bool isLastCellInRow(int cell) const;
274 int getLastCellInRow(int row) const;
276 int getNumberOfCells() const;
278 int numberOfCellsInRow(int cell) const;
280 void write(Buffer const &, std::ostream &) const;
282 void read(Buffer const &, LyXLex &);
284 int latex(Buffer const &, std::ostream &,
285 LatexRunParams const &) const;
287 int linuxdoc(Buffer const & buf, std::ostream & os) const;
289 int docbook(Buffer const & buf, std::ostream & os, bool mixcont) const;
291 int ascii(Buffer const &, std::ostream &, int const depth,
292 bool onlydata, unsigned char delim) const;
294 bool isMultiColumn(int cell, bool real = false) const;
296 void setMultiColumn(Buffer *, int cell, int number);
298 int unsetMultiColumn(int cell); // returns number of new cells
300 bool isPartOfMultiColumn(int row, int column) const;
302 int row_of_cell(int cell) const;
304 int column_of_cell(int cell) const;
306 int right_column_of_cell(int cell) const;
308 void setLongTabular(bool);
310 bool isLongTabular() const;
312 void setRotateTabular(bool);
314 bool getRotateTabular() const;
316 void setRotateCell(int cell, bool);
318 bool getRotateCell(int cell) const;
320 bool needRotating() const;
322 bool isLastCell(int cell) const;
324 int getCellAbove(int cell) const;
326 int getCellBelow(int cell) const;
328 int getLastCellAbove(int cell) const;
330 int getLastCellBelow(int cell) const;
332 int getCellNumber(int row, int column) const;
334 void setUsebox(int cell, BoxType);
336 BoxType getUsebox(int cell) const;
338 // Long Tabular Options support functions
340 bool checkLTType(int row, ltType const &) const;
342 void setLTHead(int row, bool flag, ltType const &, bool first);
344 bool getRowOfLTHead(int row, ltType &) const;
346 bool getRowOfLTFirstHead(int row, ltType &) const;
348 void setLTFoot(int row, bool flag, ltType const &, bool last);
350 bool getRowOfLTFoot(int row, ltType &) const;
352 bool getRowOfLTLastFoot(int row, ltType &) const;
354 void setLTNewPage(int row, bool what);
356 bool getLTNewPage(int row) const;
358 bool haveLTHead() const;
360 bool haveLTFirstHead() const;
362 bool haveLTFoot() const;
364 bool haveLTLastFoot() const;
366 // end longtable support
368 InsetText & getCellInset(int cell) const;
370 InsetText & getCellInset(int row, int column) const;
371 /// Search for \param inset in the tabular, with the
372 /// additional hint that it could be at \param maybe_cell
373 int getCellFromInset(InsetOld const * inset, int maybe_cell = -1) const;
375 int rows() const { return rows_; }
377 int columns() const { return columns_;}
379 void validate(LaTeXFeatures &) const;
381 void getLabelList(std::vector<string> &) const;
383 /// recalculate the widths/heights only!
388 mutable int cur_cell;
392 cellstruct(BufferParams const &);
400 LyXAlignment alignment;
402 VAlignment valignment;
416 string align_special;
418 LyXLength p_width; // this is only set for multicolumn!!!
422 cellstruct & cellinfo_of_cell(int cell) const;
424 typedef std::vector<cellstruct> cell_vector;
426 typedef std::vector<cell_vector> cell_vvector;
440 /// This are for longtabulars only
443 /// a row of endfirsthead
447 /// row of endlastfoot
449 /// row for a pagebreak
453 typedef std::vector<rowstruct> row_vector;
456 struct columnstruct {
460 LyXAlignment alignment;
462 VAlignment valignment;
472 string align_special;
475 typedef std::vector<columnstruct> column_vector;
484 std::vector<int> rowofcell;
486 std::vector<int> columnofcell;
490 column_vector column_info;
492 mutable cell_vvector cell_info;
494 int width_of_tabular;
500 bool is_long_tabular;
503 /// endfirsthead data
511 InsetTabular * owner_;
514 void init(BufferParams const &,
515 int columns_arg, int rows_arg, LyXTabular const * lt = 0);
517 void Reinit(bool reset_widths = true);
519 void set_row_column_number_info(bool oldformat = false);
520 /// Returns true if a complete update is necessary, otherwise false
521 bool setWidthOfMulticolCell(int cell, int new_width);
523 void recalculateMulticolumnsOfColumn(int column);
524 /// Returns true if change
525 void calculate_width_of_column(int column);
527 bool calculate_width_of_column_NMC(int column); // no multi cells
529 void calculate_width_of_tabular();
531 void delete_column(int column);
533 int cells_in_multicolumn(int cell) const;
535 BoxType useParbox(int cell) const;
537 void setHeaderFooterRows(int header, int fheader, int footer, int lfooter);
539 // helper function for Latex returns number of newlines
541 int TeXTopHLine(std::ostream &, int row) const;
543 int TeXBottomHLine(std::ostream &, int row) const;
545 int TeXCellPreamble(std::ostream &, int cell) const;
547 int TeXCellPostamble(std::ostream &, int cell) const;
549 int TeXLongtableHeaderFooter(std::ostream &, Buffer const & buf,
550 LatexRunParams const &) const;
552 bool isValidRow(int const row) const;
554 int TeXRow(std::ostream &, int const row, Buffer const & buf,
555 LatexRunParams const &) const;
557 // helper function for ASCII returns number of newlines
559 int asciiTopHLine(std::ostream &, int row,
560 std::vector<unsigned int> const &) const;
562 int asciiBottomHLine(std::ostream &, int row,
563 std::vector<unsigned int> const &) const;
565 int asciiPrintCell(Buffer const &, std::ostream &,
566 int cell, int row, int column,
567 std::vector<unsigned int> const &,
568 bool onlydata) const;
569 /// auxiliary function for docbook
570 int docbookRow(Buffer const & buf, std::ostream & os, int row) const;