2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000-2001 The LyX Team.
9 * @author: Jürgen Vigna
11 * ====================================================== */
15 #include "lyxlength.h"
16 #include "insets/insettext.h"
24 /* The features the text class offers for tables */
131 CELL_BEGIN_OF_MULTICOLUMN,
133 CELL_PART_OF_MULTICOLUMN
141 LYX_VALIGN_BOTTOM = 1,
143 LYX_VALIGN_CENTER = 2
158 // we have this header type (is set in the getLT... functions)
160 // double borders on top
162 // double borders on bottom
164 // used for FirstHeader & LastFooter and if this is true
165 // all the rows marked as FirstHeader or LastFooter are
166 // ignored in the output and it is set to be empty!
171 LyXTabular(BufferParams const &,
172 InsetTabular *, int columns_arg, int rows_arg);
173 /// sort of copy constructor
174 LyXTabular(BufferParams const &,
175 InsetTabular *, LyXTabular const &);
178 LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
180 /// Returns true if there is a topline, returns false if not
181 bool topLine(int cell, bool onlycolumn = false) const;
182 /// Returns true if there is a topline, returns false if not
183 bool bottomLine(int cell, bool onlycolumn = false) const;
184 /// Returns true if there is a topline, returns false if not
185 bool leftLine(int cell, bool onlycolumn = false) const;
186 /// Returns true if there is a topline, returns false if not
187 bool rightLine(int cell, bool onlycolumn = false) const;
190 bool topAlreadyDrawn(int cell) const;
192 bool leftAlreadyDrawn(int cell) const;
194 bool isLastRow(int cell) const;
197 int getAdditionalHeight(int row) const;
199 int getAdditionalWidth(int cell) const;
201 /* returns the maximum over all rows */
203 int getWidthOfColumn(int cell) const;
205 int getWidthOfTabular() const;
207 int getAscentOfRow(int row) const;
209 int getDescentOfRow(int row) const;
211 int getHeightOfTabular() const;
212 /// Returns true if a complete update is necessary, otherwise false
213 bool setAscentOfRow(int row, int height);
214 /// Returns true if a complete update is necessary, otherwise false
215 bool setDescentOfRow(int row, int height);
216 /// Returns true if a complete update is necessary, otherwise false
217 bool setWidthOfCell(int cell, int new_width);
219 void setAllLines(int cell, bool line);
221 void setTopLine(int cell, bool line, bool onlycolumn = false);
223 void setBottomLine(int cell, bool line, bool onlycolumn = false);
225 void setLeftLine(int cell, bool line, bool onlycolumn = false);
227 void setRightLine(int cell, bool line, bool onlycolumn = false);
229 void setAlignment(int cell, LyXAlignment align,
230 bool onlycolumn = false);
232 void setVAlignment(int cell, VAlignment align,
233 bool onlycolumn = false);
235 void setColumnPWidth(int cell, LyXLength const & width);
237 bool setMColumnPWidth(int cell, LyXLength const & width);
239 void setAlignSpecial(int cell, string const & special, Feature what);
241 LyXAlignment getAlignment(int cell, bool onlycolumn = false) const;
243 VAlignment getVAlignment(int cell, bool onlycolumn = false) const;
245 LyXLength const getPWidth(int cell) const;
247 LyXLength const getColumnPWidth(int cell) const;
249 LyXLength const getMColumnPWidth(int cell) const;
251 string const getAlignSpecial(int cell, int what) const;
253 int getWidthOfCell(int cell) const;
255 int getBeginningOfTextInCell(int cell) const;
257 void appendRow(BufferParams const &, int cell);
259 void deleteRow(int row);
261 void appendColumn(BufferParams const &, int cell);
263 void deleteColumn(int column);
265 bool isFirstCellInRow(int cell) const;
267 int getFirstCellInRow(int row) const;
269 bool isLastCellInRow(int cell) const;
271 int getLastCellInRow(int row) const;
273 int getNumberOfCells() const;
275 int numberOfCellsInRow(int cell) const;
277 void write(Buffer const *, std::ostream &) const;
279 void read(Buffer const *, LyXLex &);
281 int latex(Buffer const *, std::ostream &,
282 LatexRunParams const &) 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, bool real = false) const;
291 void setMultiColumn(Buffer *, int cell, int number);
293 int unsetMultiColumn(int cell); // returns number of new cells
295 bool isPartOfMultiColumn(int row, int column) const;
297 int row_of_cell(int cell) const;
299 int column_of_cell(int cell) const;
301 int right_column_of_cell(int cell) const;
303 void setLongTabular(bool);
305 bool isLongTabular() const;
307 void setRotateTabular(bool);
309 bool getRotateTabular() const;
311 void setRotateCell(int cell, bool);
313 bool getRotateCell(int cell) const;
315 bool needRotating() const;
317 bool isLastCell(int cell) const;
319 int getCellAbove(int cell) const;
321 int getCellBelow(int cell) const;
323 int getLastCellAbove(int cell) const;
325 int getLastCellBelow(int cell) const;
327 int getCellNumber(int row, int column) const;
329 void setUsebox(int cell, BoxType);
331 BoxType getUsebox(int cell) const;
333 // Long Tabular Options support functions
335 bool checkLTType(int row, ltType const &) const;
337 void setLTHead(int row, bool flag, ltType const &, bool first);
339 bool getRowOfLTHead(int row, ltType &) const;
341 bool getRowOfLTFirstHead(int row, ltType &) const;
343 void setLTFoot(int row, bool flag, ltType const &, bool last);
345 bool getRowOfLTFoot(int row, ltType &) const;
347 bool getRowOfLTLastFoot(int row, ltType &) const;
349 void setLTNewPage(int row, bool what);
351 bool getLTNewPage(int row) const;
353 bool haveLTHead() const;
355 bool haveLTFirstHead() const;
357 bool haveLTFoot() const;
359 bool haveLTLastFoot() const;
361 // end longtable support
363 InsetText & getCellInset(int cell) const;
365 InsetText & getCellInset(int row, int column) const;
366 /// Search for \param inset in the tabular, with the
367 /// additional hint that it could be at \param maybe_cell
368 int getCellFromInset(Inset const * inset, int maybe_cell = -1) const;
370 int rows() const { return rows_; }
372 int columns() const { return columns_;}
374 void validate(LaTeXFeatures &) const;
376 void getLabelList(std::vector<string> &) const;
378 /// recalculate the widths/heights only!
383 mutable int cur_cell;
387 cellstruct(BufferParams const &);
395 LyXAlignment alignment;
397 VAlignment valignment;
411 string align_special;
413 LyXLength p_width; // this is only set for multicolumn!!!
417 cellstruct & cellinfo_of_cell(int cell) const;
419 typedef std::vector<cellstruct> cell_vector;
421 typedef std::vector<cell_vector> cell_vvector;
435 /// This are for longtabulars only
438 /// a row of endfirsthead
442 /// row of endlastfoot
444 /// row for a pagebreak
448 typedef std::vector<rowstruct> row_vector;
451 struct columnstruct {
455 LyXAlignment alignment;
457 VAlignment valignment;
467 string align_special;
470 typedef std::vector<columnstruct> column_vector;
479 std::vector<int> rowofcell;
481 std::vector<int> columnofcell;
485 column_vector column_info;
487 mutable cell_vvector cell_info;
489 int width_of_tabular;
495 bool is_long_tabular;
498 /// endfirsthead data
506 InsetTabular * owner_;
509 void init(BufferParams const &,
510 int columns_arg, int rows_arg, LyXTabular const * lt = 0);
512 void Reinit(bool reset_widths = true);
514 void set_row_column_number_info(bool oldformat = false);
515 /// Returns true if a complete update is necessary, otherwise false
516 bool setWidthOfMulticolCell(int cell, int new_width);
518 void recalculateMulticolumnsOfColumn(int column);
519 /// Returns true if change
520 void calculate_width_of_column(int column);
522 bool calculate_width_of_column_NMC(int column); // no multi cells
524 void calculate_width_of_tabular();
526 void delete_column(int column);
528 int cells_in_multicolumn(int cell) const;
530 BoxType useParbox(int cell) const;
532 void setHeaderFooterRows(int header, int fheader, int footer, int lfooter);
534 // helper function for Latex returns number of newlines
536 int TeXTopHLine(std::ostream &, int row) const;
538 int TeXBottomHLine(std::ostream &, int row) const;
540 int TeXCellPreamble(std::ostream &, int cell) const;
542 int TeXCellPostamble(std::ostream &, int cell) const;
544 int TeXLongtableHeaderFooter(std::ostream &, Buffer const * buf,
545 LatexRunParams const &) const;
547 bool isValidRow(int const row) const;
549 int TeXRow(std::ostream &, int const row, Buffer const * buf,
550 LatexRunParams const &) const;
552 // helper function for ASCII returns number of newlines
554 int asciiTopHLine(std::ostream &, int row,
555 std::vector<unsigned int> const &) const;
557 int asciiBottomHLine(std::ostream &, int row,
558 std::vector<unsigned int> const &) const;
560 int asciiPrintCell(Buffer const *, std::ostream &,
561 int cell, int row, int column,
562 std::vector<unsigned int> const &,
563 bool onlydata) const;
564 /// auxiliary function for docbook
565 int docbookRow(Buffer const * buf, std::ostream & os, int row) const;