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>
33 /* The features the text class offers for tables */
111 UNSET_ROTATE_TABULAR,
154 CELL_BEGIN_OF_MULTICOLUMN,
156 CELL_PART_OF_MULTICOLUMN
164 LYX_VALIGN_BOTTOM = 1,
166 LYX_VALIGN_MIDDLE = 2
182 // we have this header type (is set in the getLT... functions)
184 // double borders on top
186 // double borders on bottom
188 // used for FirstHeader & LastFooter and if this is true
189 // all the rows marked as FirstHeader or LastFooter are
190 // ignored in the output and it is set to be empty!
194 /// type for row numbers
195 typedef size_t row_type;
196 /// type for column numbers
197 typedef size_t col_type;
198 /// type for cell indices
199 typedef size_t idx_type;
200 /// index indicating an invalid position
201 static const idx_type npos = static_cast<idx_type>(-1);
204 LyXTabular(BufferParams const &, col_type columns_arg,
207 /// Returns true if there is a topline, returns false if not
208 bool topLine(idx_type cell, bool onlycolumn = false) const;
209 /// Returns true if there is a topline, returns false if not
210 bool bottomLine(idx_type cell, bool onlycolumn = false) const;
211 /// Returns true if there is a topline, returns false if not
212 bool leftLine(idx_type cell, bool onlycolumn = false) const;
213 /// Returns true if there is a topline, returns false if not
214 bool rightLine(idx_type cell, bool onlycolumn = false) const;
217 bool topAlreadyDrawn(idx_type cell) const;
219 bool leftAlreadyDrawn(idx_type cell) const;
221 bool isLastRow(idx_type cell) const;
223 /// return space occupied by the second horizontal line and
224 /// interline space above row \p row in pixels
225 int getAdditionalHeight(row_type row) const;
227 int getAdditionalWidth(idx_type cell) const;
229 /* returns the maximum over all rows */
231 int getWidthOfColumn(idx_type cell) const;
233 int getWidthOfTabular() const;
235 int getAscentOfRow(row_type row) const;
237 int getDescentOfRow(row_type row) const;
239 int getHeightOfTabular() const;
241 void setAscentOfRow(row_type row, int height);
243 void setDescentOfRow(row_type row, int height);
245 void setWidthOfCell(idx_type cell, int new_width);
247 void setAllLines(idx_type cell, bool line);
249 void setTopLine(idx_type cell, bool line, bool onlycolumn = false);
251 void setBottomLine(idx_type cell, bool line, bool onlycolumn = false);
253 void setLeftLine(idx_type cell, bool line, bool onlycolumn = false);
255 void setRightLine(idx_type cell, bool line, bool onlycolumn = false);
257 void setAlignment(idx_type cell, LyXAlignment align,
258 bool onlycolumn = false);
260 void setVAlignment(idx_type cell, VAlignment align,
261 bool onlycolumn = false);
263 void setColumnPWidth(LCursor &, idx_type, LyXLength const &);
265 bool setMColumnPWidth(LCursor &, idx_type, LyXLength const &);
267 void setAlignSpecial(idx_type cell, std::string const & special,
270 LyXAlignment getAlignment(idx_type cell,
271 bool onlycolumn = false) const;
273 VAlignment getVAlignment(idx_type cell,
274 bool onlycolumn = false) const;
276 LyXLength const getPWidth(idx_type cell) const;
278 LyXLength const getColumnPWidth(idx_type cell) const;
280 LyXLength const getMColumnPWidth(idx_type cell) const;
282 std::string const getAlignSpecial(idx_type cell, int what) const;
284 int getWidthOfCell(idx_type cell) const;
286 int getBeginningOfTextInCell(idx_type cell) const;
288 void appendRow(BufferParams const &, idx_type cell);
290 void deleteRow(row_type row);
292 void copyRow(BufferParams const &, row_type);
294 void appendColumn(BufferParams const &, idx_type cell);
296 void deleteColumn(col_type column);
298 void copyColumn(BufferParams const &, col_type);
300 bool isFirstCellInRow(idx_type cell) const;
302 idx_type getFirstCellInRow(row_type row) const;
304 bool isLastCellInRow(idx_type cell) const;
306 idx_type getLastCellInRow(row_type row) const;
308 idx_type getNumberOfCells() const;
310 idx_type numberOfCellsInRow(idx_type cell) const;
312 void write(Buffer const &, std::ostream &) const;
314 void read(Buffer const &, LyXLex &);
316 int latex(Buffer const &, odocstream &, OutputParams const &) const;
318 int docbook(Buffer const & buf, odocstream & os, OutputParams const &) const;
320 int plaintext(Buffer const &, odocstream &,
321 OutputParams const & runparams,
323 bool onlydata, unsigned char delim) const;
325 bool isMultiColumn(idx_type cell) const;
327 bool isMultiColumnReal(idx_type cell) const;
329 void setMultiColumn(Buffer *, idx_type cell, idx_type number);
331 idx_type unsetMultiColumn(idx_type cell); // returns number of new cells
333 bool isPartOfMultiColumn(row_type row, col_type column) const;
335 row_type row_of_cell(idx_type cell) const;
337 col_type column_of_cell(idx_type cell) const;
339 col_type right_column_of_cell(idx_type cell) const;
341 void setBookTabs(bool);
343 bool useBookTabs() const;
345 void setLongTabular(bool);
347 bool isLongTabular() const;
349 void setRotateTabular(bool);
351 bool getRotateTabular() const;
353 void setRotateCell(idx_type cell, bool);
355 bool getRotateCell(idx_type cell) const;
357 bool needRotating() const;
359 bool isLastCell(idx_type cell) const;
361 idx_type getCellAbove(idx_type cell) const;
363 idx_type getCellBelow(idx_type cell) const;
365 idx_type getLastCellAbove(idx_type cell) const;
367 idx_type getLastCellBelow(idx_type cell) const;
369 idx_type getCellNumber(row_type row, col_type column) const;
371 void setUsebox(idx_type cell, BoxType);
373 BoxType getUsebox(idx_type cell) const;
375 // Long Tabular Options support functions
377 bool checkLTType(row_type row, ltType const &) const;
379 void setLTHead(row_type row, bool flag, ltType const &, bool first);
381 bool getRowOfLTHead(row_type row, ltType &) const;
383 bool getRowOfLTFirstHead(row_type row, ltType &) const;
385 void setLTFoot(row_type row, bool flag, ltType const &, bool last);
387 bool getRowOfLTFoot(row_type row, ltType &) const;
389 bool getRowOfLTLastFoot(row_type row, ltType &) const;
391 void setLTNewPage(row_type row, bool what);
393 bool getLTNewPage(row_type row) const;
395 bool haveLTHead() const;
397 bool haveLTFirstHead() const;
399 bool haveLTFoot() const;
401 bool haveLTLastFoot() const;
403 // end longtable support
405 boost::shared_ptr<InsetText> getCellInset(idx_type cell) const;
407 boost::shared_ptr<InsetText> getCellInset(row_type row,
408 col_type column) const;
410 void setCellInset(row_type row, col_type column,
411 boost::shared_ptr<InsetText>) const;
412 /// Search for \param inset in the tabular, with the
414 idx_type getCellFromInset(InsetBase const * inset) const;
416 row_type rows() const { return rows_; }
418 col_type columns() const { return columns_;}
420 void validate(LaTeXFeatures &) const;
427 cellstruct(BufferParams const &);
429 cellstruct(cellstruct const &);
431 cellstruct & operator=(cellstruct);
433 void swap(cellstruct & rhs);
441 LyXAlignment alignment;
443 VAlignment valignment;
457 std::string align_special;
459 LyXLength p_width; // this is only set for multicolumn!!!
461 boost::shared_ptr<InsetText> inset;
463 cellstruct & cellinfo_of_cell(idx_type cell) const;
465 typedef std::vector<cellstruct> cell_vector;
467 typedef std::vector<cell_vector> cell_vvector;
482 /// Extra space between the top line and this row
484 /// Ignore top_space if true and use the default top space
485 bool top_space_default;
486 /// Extra space between this row and the bottom line
487 LyXLength bottom_space;
488 /// Ignore bottom_space if true and use the default bottom space
489 bool bottom_space_default;
490 /// Extra space between the bottom line and the next top line
491 LyXLength interline_space;
492 /// Ignore interline_space if true and use the default interline space
493 bool interline_space_default;
494 /// This are for longtabulars only
497 /// a row of endfirsthead
501 /// row of endlastfoot
503 /// row for a pagebreak
507 typedef std::vector<rowstruct> row_vector;
515 LyXAlignment alignment;
517 VAlignment valignment;
527 std::string align_special;
530 typedef std::vector<columnstruct> column_vector;
537 idx_type numberofcells;
539 std::vector<row_type> rowofcell;
541 std::vector<col_type> columnofcell;
545 column_vector column_info;
547 mutable cell_vvector cell_info;
549 int width_of_tabular;
557 bool is_long_tabular;
560 /// endfirsthead data
568 void init(BufferParams const &, row_type rows_arg,
569 col_type columns_arg);
571 void set_row_column_number_info();
572 /// Returns true if a complete update is necessary, otherwise false
573 bool setWidthOfMulticolCell(idx_type cell, int new_width);
575 void recalculateMulticolumnsOfColumn(col_type column);
576 /// Returns true if change
577 void calculate_width_of_column(col_type column);
579 bool calculate_width_of_column_NMC(col_type column); // no multi cells
581 void calculate_width_of_tabular();
583 void delete_column(col_type column);
585 idx_type cells_in_multicolumn(idx_type cell) const;
587 BoxType useParbox(idx_type cell) const;
589 // helper function for Latex returns number of newlines
591 int TeXTopHLine(odocstream &, row_type row) const;
593 int TeXBottomHLine(odocstream &, row_type row) const;
595 int TeXCellPreamble(odocstream &, idx_type cell) const;
597 int TeXCellPostamble(odocstream &, idx_type cell) const;
599 int TeXLongtableHeaderFooter(odocstream &, Buffer const & buf,
600 OutputParams const &) const;
602 bool isValidRow(row_type const row) const;
604 int TeXRow(odocstream &, row_type const row, Buffer const & buf,
605 OutputParams const &) const;
607 // helper function for ASCII returns number of newlines
609 int asciiTopHLine(odocstream &, row_type row,
610 std::vector<unsigned int> const &) const;
612 int asciiBottomHLine(odocstream &, row_type row,
613 std::vector<unsigned int> const &) const;
615 int asciiPrintCell(Buffer const &, odocstream &,
616 OutputParams const &,
617 idx_type cell, row_type row, col_type column,
618 std::vector<unsigned int> const &,
619 bool onlydata) const;
620 /// auxiliary function for docbook
621 int docbookRow(Buffer const & buf, odocstream & os, row_type,
622 OutputParams const &) const;
625 /// renumber cells after structural changes