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 void setAscentOfRow(int row, int height);
214 /// Returns true if a complete update is necessary, otherwise false
215 void setDescentOfRow(int row, int height);
216 /// Returns true if a complete update is necessary, otherwise false
217 void 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 linuxdoc(Buffer const * buf, std::ostream & os) const;
286 int docbook(Buffer const * buf, std::ostream & os, bool mixcont) const;
288 int ascii(Buffer const *, std::ostream &, int const depth,
289 bool onlydata, unsigned char delim) const;
291 bool isMultiColumn(int cell, bool real = false) const;
293 void setMultiColumn(Buffer *, int cell, int number);
295 int unsetMultiColumn(int cell); // returns number of new cells
297 bool isPartOfMultiColumn(int row, int column) const;
299 int row_of_cell(int cell) const;
301 int column_of_cell(int cell) const;
303 int right_column_of_cell(int cell) const;
305 void setLongTabular(bool);
307 bool isLongTabular() const;
309 void setRotateTabular(bool);
311 bool getRotateTabular() const;
313 void setRotateCell(int cell, bool);
315 bool getRotateCell(int cell) const;
317 bool needRotating() const;
319 bool isLastCell(int cell) const;
321 int getCellAbove(int cell) const;
323 int getCellBelow(int cell) const;
325 int getLastCellAbove(int cell) const;
327 int getLastCellBelow(int cell) const;
329 int getCellNumber(int row, int column) const;
331 void setUsebox(int cell, BoxType);
333 BoxType getUsebox(int cell) const;
335 // Long Tabular Options support functions
337 bool checkLTType(int row, ltType const &) const;
339 void setLTHead(int row, bool flag, ltType const &, bool first);
341 bool getRowOfLTHead(int row, ltType &) const;
343 bool getRowOfLTFirstHead(int row, ltType &) const;
345 void setLTFoot(int row, bool flag, ltType const &, bool last);
347 bool getRowOfLTFoot(int row, ltType &) const;
349 bool getRowOfLTLastFoot(int row, ltType &) const;
351 void setLTNewPage(int row, bool what);
353 bool getLTNewPage(int row) const;
355 bool haveLTHead() const;
357 bool haveLTFirstHead() const;
359 bool haveLTFoot() const;
361 bool haveLTLastFoot() const;
363 // end longtable support
365 InsetText & getCellInset(int cell) const;
367 InsetText & getCellInset(int row, int column) const;
368 /// Search for \param inset in the tabular, with the
369 /// additional hint that it could be at \param maybe_cell
370 int getCellFromInset(InsetOld const * inset, int maybe_cell = -1) const;
372 int rows() const { return rows_; }
374 int columns() const { return columns_;}
376 void validate(LaTeXFeatures &) const;
378 void getLabelList(std::vector<string> &) const;
380 /// recalculate the widths/heights only!
385 mutable int cur_cell;
389 cellstruct(BufferParams const &);
397 LyXAlignment alignment;
399 VAlignment valignment;
413 string align_special;
415 LyXLength p_width; // this is only set for multicolumn!!!
419 cellstruct & cellinfo_of_cell(int cell) const;
421 typedef std::vector<cellstruct> cell_vector;
423 typedef std::vector<cell_vector> cell_vvector;
437 /// This are for longtabulars only
440 /// a row of endfirsthead
444 /// row of endlastfoot
446 /// row for a pagebreak
450 typedef std::vector<rowstruct> row_vector;
453 struct columnstruct {
457 LyXAlignment alignment;
459 VAlignment valignment;
469 string align_special;
472 typedef std::vector<columnstruct> column_vector;
481 std::vector<int> rowofcell;
483 std::vector<int> columnofcell;
487 column_vector column_info;
489 mutable cell_vvector cell_info;
491 int width_of_tabular;
497 bool is_long_tabular;
500 /// endfirsthead data
508 InsetTabular * owner_;
511 void init(BufferParams const &,
512 int columns_arg, int rows_arg, LyXTabular const * lt = 0);
514 void Reinit(bool reset_widths = true);
516 void set_row_column_number_info(bool oldformat = false);
517 /// Returns true if a complete update is necessary, otherwise false
518 bool setWidthOfMulticolCell(int cell, int new_width);
520 void recalculateMulticolumnsOfColumn(int column);
521 /// Returns true if change
522 void calculate_width_of_column(int column);
524 bool calculate_width_of_column_NMC(int column); // no multi cells
526 void calculate_width_of_tabular();
528 void delete_column(int column);
530 int cells_in_multicolumn(int cell) const;
532 BoxType useParbox(int cell) const;
534 void setHeaderFooterRows(int header, int fheader, int footer, int lfooter);
536 // helper function for Latex returns number of newlines
538 int TeXTopHLine(std::ostream &, int row) const;
540 int TeXBottomHLine(std::ostream &, int row) const;
542 int TeXCellPreamble(std::ostream &, int cell) const;
544 int TeXCellPostamble(std::ostream &, int cell) const;
546 int TeXLongtableHeaderFooter(std::ostream &, Buffer const * buf,
547 LatexRunParams const &) const;
549 bool isValidRow(int const row) const;
551 int TeXRow(std::ostream &, int const row, Buffer const * buf,
552 LatexRunParams const &) const;
554 // helper function for ASCII returns number of newlines
556 int asciiTopHLine(std::ostream &, int row,
557 std::vector<unsigned int> const &) const;
559 int asciiBottomHLine(std::ostream &, int row,
560 std::vector<unsigned int> const &) const;
562 int asciiPrintCell(Buffer const *, std::ostream &,
563 int cell, int row, int column,
564 std::vector<unsigned int> const &,
565 bool onlydata) const;
566 /// auxiliary function for docbook
567 int docbookRow(Buffer const * buf, std::ostream & os, int row) const;