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>
30 /* The features the text class offers for tables */
104 UNSET_ROTATE_TABULAR,
137 CELL_BEGIN_OF_MULTICOLUMN,
139 CELL_PART_OF_MULTICOLUMN
147 LYX_VALIGN_BOTTOM = 1,
149 LYX_VALIGN_MIDDLE = 2
165 // we have this header type (is set in the getLT... functions)
167 // double borders on top
169 // double borders on bottom
171 // used for FirstHeader & LastFooter and if this is true
172 // all the rows marked as FirstHeader or LastFooter are
173 // ignored in the output and it is set to be empty!
177 /// type for row numbers
178 typedef size_t row_type;
179 /// type for column numbers
180 typedef size_t col_type;
181 /// type for cell indices
182 typedef size_t idx_type;
183 /// index indicating an invalid position
184 static const idx_type npos = static_cast<idx_type>(-1);
187 LyXTabular(BufferParams const &, col_type columns_arg,
190 /// Returns true if there is a topline, returns false if not
191 bool topLine(idx_type cell, bool onlycolumn = false) const;
192 /// Returns true if there is a topline, returns false if not
193 bool bottomLine(idx_type cell, bool onlycolumn = false) const;
194 /// Returns true if there is a topline, returns false if not
195 bool leftLine(idx_type cell, bool onlycolumn = false) const;
196 /// Returns true if there is a topline, returns false if not
197 bool rightLine(idx_type cell, bool onlycolumn = false) const;
200 bool topAlreadyDrawn(idx_type cell) const;
202 bool leftAlreadyDrawn(idx_type cell) const;
204 bool isLastRow(idx_type cell) const;
207 int getAdditionalHeight(row_type row) const;
209 int getAdditionalWidth(idx_type cell) const;
211 /* returns the maximum over all rows */
213 int getWidthOfColumn(idx_type cell) const;
215 int getWidthOfTabular() const;
217 int getAscentOfRow(row_type row) const;
219 int getDescentOfRow(row_type row) const;
221 int getHeightOfTabular() const;
223 void setAscentOfRow(row_type row, int height);
225 void setDescentOfRow(row_type row, int height);
227 void setWidthOfCell(idx_type cell, int new_width);
229 void setAllLines(idx_type cell, bool line);
231 void setTopLine(idx_type cell, bool line, bool onlycolumn = false);
233 void setBottomLine(idx_type cell, bool line, bool onlycolumn = false);
235 void setLeftLine(idx_type cell, bool line, bool onlycolumn = false);
237 void setRightLine(idx_type cell, bool line, bool onlycolumn = false);
239 void setAlignment(idx_type cell, LyXAlignment align,
240 bool onlycolumn = false);
242 void setVAlignment(idx_type cell, VAlignment align,
243 bool onlycolumn = false);
245 void setColumnPWidth(LCursor &, idx_type, LyXLength const &);
247 bool setMColumnPWidth(LCursor &, idx_type, LyXLength const &);
249 void setAlignSpecial(idx_type cell, std::string const & special,
252 LyXAlignment getAlignment(idx_type cell,
253 bool onlycolumn = false) const;
255 VAlignment getVAlignment(idx_type cell,
256 bool onlycolumn = false) const;
258 LyXLength const getPWidth(idx_type cell) const;
260 LyXLength const getColumnPWidth(idx_type cell) const;
262 LyXLength const getMColumnPWidth(idx_type cell) const;
264 std::string const getAlignSpecial(idx_type cell, int what) const;
266 int getWidthOfCell(idx_type cell) const;
268 int getBeginningOfTextInCell(idx_type cell) const;
270 void appendRow(BufferParams const &, idx_type cell);
272 void deleteRow(row_type row);
274 void appendColumn(BufferParams const &, idx_type cell);
276 void deleteColumn(col_type column);
278 bool isFirstCellInRow(idx_type cell) const;
280 idx_type getFirstCellInRow(row_type row) const;
282 bool isLastCellInRow(idx_type cell) const;
284 idx_type getLastCellInRow(row_type row) const;
286 idx_type getNumberOfCells() const;
288 idx_type numberOfCellsInRow(idx_type cell) const;
290 void write(Buffer const &, std::ostream &) const;
292 void read(Buffer const &, LyXLex &);
294 int latex(Buffer const &, std::ostream &,
295 OutputParams const &) const;
297 int linuxdoc(Buffer const & buf, std::ostream & os,
298 OutputParams const &) const;
300 int docbook(Buffer const & buf, std::ostream & os,
301 OutputParams const &) const;
303 int plaintext(Buffer const &, std::ostream &,
304 OutputParams const & runparams,
306 bool onlydata, unsigned char delim) const;
308 bool isMultiColumn(idx_type cell) const;
310 bool isMultiColumnReal(idx_type cell) const;
312 void setMultiColumn(Buffer *, idx_type cell, idx_type number);
314 idx_type unsetMultiColumn(idx_type cell); // returns number of new cells
316 bool isPartOfMultiColumn(row_type row, col_type column) const;
318 row_type row_of_cell(idx_type cell) const;
320 col_type column_of_cell(idx_type cell) const;
322 col_type right_column_of_cell(idx_type cell) const;
324 void setLongTabular(bool);
326 bool isLongTabular() const;
328 void setRotateTabular(bool);
330 bool getRotateTabular() const;
332 void setRotateCell(idx_type cell, bool);
334 bool getRotateCell(idx_type cell) const;
336 bool needRotating() const;
338 bool isLastCell(idx_type cell) const;
340 idx_type getCellAbove(idx_type cell) const;
342 idx_type getCellBelow(idx_type cell) const;
344 idx_type getLastCellAbove(idx_type cell) const;
346 idx_type getLastCellBelow(idx_type cell) const;
348 idx_type getCellNumber(row_type row, col_type column) const;
350 void setUsebox(idx_type cell, BoxType);
352 BoxType getUsebox(idx_type cell) const;
354 // Long Tabular Options support functions
356 bool checkLTType(row_type row, ltType const &) const;
358 void setLTHead(row_type row, bool flag, ltType const &, bool first);
360 bool getRowOfLTHead(row_type row, ltType &) const;
362 bool getRowOfLTFirstHead(row_type row, ltType &) const;
364 void setLTFoot(row_type row, bool flag, ltType const &, bool last);
366 bool getRowOfLTFoot(row_type row, ltType &) const;
368 bool getRowOfLTLastFoot(row_type row, ltType &) const;
370 void setLTNewPage(row_type row, bool what);
372 bool getLTNewPage(row_type row) const;
374 bool haveLTHead() const;
376 bool haveLTFirstHead() const;
378 bool haveLTFoot() const;
380 bool haveLTLastFoot() const;
382 // end longtable support
384 boost::shared_ptr<InsetText> getCellInset(idx_type cell) const;
386 boost::shared_ptr<InsetText> getCellInset(row_type row,
387 col_type column) const;
389 void setCellInset(row_type row, col_type column,
390 boost::shared_ptr<InsetText>) const;
391 /// Search for \param inset in the tabular, with the
393 idx_type getCellFromInset(InsetBase const * inset) const;
395 row_type rows() const { return rows_; }
397 col_type columns() const { return columns_;}
399 void validate(LaTeXFeatures &) const;
406 cellstruct(BufferParams const &);
408 cellstruct(cellstruct const &);
410 cellstruct & operator=(cellstruct);
412 void swap(cellstruct & rhs);
420 LyXAlignment alignment;
422 VAlignment valignment;
436 std::string align_special;
438 LyXLength p_width; // this is only set for multicolumn!!!
440 boost::shared_ptr<InsetText> inset;
442 cellstruct & cellinfo_of_cell(idx_type cell) const;
444 typedef std::vector<cellstruct> cell_vector;
446 typedef std::vector<cell_vector> cell_vvector;
461 /// This are for longtabulars only
464 /// a row of endfirsthead
468 /// row of endlastfoot
470 /// row for a pagebreak
474 typedef std::vector<rowstruct> row_vector;
482 LyXAlignment alignment;
484 VAlignment valignment;
494 std::string align_special;
497 typedef std::vector<columnstruct> column_vector;
504 idx_type numberofcells;
506 std::vector<row_type> rowofcell;
508 std::vector<col_type> columnofcell;
512 column_vector column_info;
514 mutable cell_vvector cell_info;
516 int width_of_tabular;
522 bool is_long_tabular;
525 /// endfirsthead data
533 void init(BufferParams const &, row_type rows_arg,
534 col_type columns_arg);
536 void set_row_column_number_info();
537 /// Returns true if a complete update is necessary, otherwise false
538 bool setWidthOfMulticolCell(idx_type cell, int new_width);
540 void recalculateMulticolumnsOfColumn(col_type column);
541 /// Returns true if change
542 void calculate_width_of_column(col_type column);
544 bool calculate_width_of_column_NMC(col_type column); // no multi cells
546 void calculate_width_of_tabular();
548 void delete_column(col_type column);
550 idx_type cells_in_multicolumn(idx_type cell) const;
552 BoxType useParbox(idx_type cell) const;
554 // helper function for Latex returns number of newlines
556 int TeXTopHLine(std::ostream &, row_type row) const;
558 int TeXBottomHLine(std::ostream &, row_type row) const;
560 int TeXCellPreamble(std::ostream &, idx_type cell) const;
562 int TeXCellPostamble(std::ostream &, idx_type cell) const;
564 int TeXLongtableHeaderFooter(std::ostream &, Buffer const & buf,
565 OutputParams const &) const;
567 bool isValidRow(row_type const row) const;
569 int TeXRow(std::ostream &, row_type const row, Buffer const & buf,
570 OutputParams const &) const;
572 // helper function for ASCII returns number of newlines
574 int asciiTopHLine(std::ostream &, row_type row,
575 std::vector<unsigned int> const &) const;
577 int asciiBottomHLine(std::ostream &, row_type row,
578 std::vector<unsigned int> const &) const;
580 int asciiPrintCell(Buffer const &, std::ostream &,
581 OutputParams const &,
582 idx_type cell, row_type row, col_type column,
583 std::vector<unsigned int> const &,
584 bool onlydata) const;
585 /// auxiliary function for docbook
586 int docbookRow(Buffer const & buf, std::ostream & os, row_type,
587 OutputParams const &) const;
590 /// renumber cells after structural changes