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 * ====================================================== */
17 #include "lyxlength.h"
19 #include "insets/insettext.h"
31 /* The features the text class offers for tables */
105 UNSET_ROTATE_TABULAR,
138 CELL_BEGIN_OF_MULTICOLUMN,
140 CELL_PART_OF_MULTICOLUMN
148 LYX_VALIGN_BOTTOM = 1,
150 LYX_VALIGN_CENTER = 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!
178 LyXTabular(BufferParams const &,
179 InsetTabular *, int columns_arg, int rows_arg);
180 /// sort of copy constructor
181 LyXTabular(BufferParams const &,
182 InsetTabular *, LyXTabular const &);
185 LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
187 LyXTabular * clone(BufferParams const &, InsetTabular *);
189 /// Returns true if there is a topline, returns false if not
190 bool topLine(int cell, bool onlycolumn = false) const;
191 /// Returns true if there is a topline, returns false if not
192 bool bottomLine(int cell, bool onlycolumn = false) const;
193 /// Returns true if there is a topline, returns false if not
194 bool leftLine(int cell, bool onlycolumn = false) const;
195 /// Returns true if there is a topline, returns false if not
196 bool rightLine(int cell, bool onlycolumn = false) const;
199 bool topAlreadyDrawn(int cell) const;
201 bool leftAlreadyDrawn(int cell) const;
203 bool isLastRow(int cell) const;
206 int getAdditionalHeight(int row) const;
208 int getAdditionalWidth(int cell) const;
210 /* returns the maximum over all rows */
212 int getWidthOfColumn(int cell) const;
214 int getWidthOfTabular() const;
216 int getAscentOfRow(int row) const;
218 int getDescentOfRow(int row) const;
220 int getHeightOfTabular() const;
221 /// Returns true if a complete update is necessary, otherwise false
222 bool setAscentOfRow(int row, int height);
223 /// Returns true if a complete update is necessary, otherwise false
224 bool setDescentOfRow(int row, int height);
225 /// Returns true if a complete update is necessary, otherwise false
226 bool setWidthOfCell(int cell, int new_width);
227 /// Returns true if a complete update is necessary, otherwise false
228 bool setAllLines(int cell, bool line);
229 /// Returns true if a complete update is necessary, otherwise false
230 bool setTopLine(int cell, bool line, bool onlycolumn = false);
231 /// Returns true if a complete update is necessary, otherwise false
232 bool setBottomLine(int cell, bool line, bool onlycolumn = false);
233 /// Returns true if a complete update is necessary, otherwise false
234 bool setLeftLine(int cell, bool line, bool onlycolumn = false);
235 /// Returns true if a complete update is necessary, otherwise false
236 bool setRightLine(int cell, bool line, bool onlycolumn = false);
237 /// Returns true if a complete update is necessary, otherwise false
238 bool setAlignment(int cell, LyXAlignment align,
239 bool onlycolumn = false);
240 /// Returns true if a complete update is necessary, otherwise false
241 bool setVAlignment(int cell, VAlignment align,
242 bool onlycolumn = false);
244 bool setColumnPWidth(int cell, LyXLength const & width);
246 bool setMColumnPWidth(int cell, LyXLength const & width);
248 bool setAlignSpecial(int cell, string const & special, Feature what);
250 LyXAlignment getAlignment(int cell, bool onlycolumn = false) const;
252 VAlignment getVAlignment(int cell, bool onlycolumn = false) const;
254 LyXLength const getPWidth(int cell) const;
256 LyXLength const getColumnPWidth(int cell) const;
258 LyXLength const getMColumnPWidth(int cell) const;
260 string const getAlignSpecial(int cell, int what) const;
262 int getWidthOfCell(int cell) const;
264 int getBeginningOfTextInCell(int cell) const;
266 void appendRow(BufferParams const &, int cell);
268 void deleteRow(int row);
270 void appendColumn(BufferParams const &, int cell);
272 void deleteColumn(int column);
274 bool isFirstCellInRow(int cell) const;
276 int getFirstCellInRow(int row) const;
278 bool isLastCellInRow(int cell) const;
280 int getLastCellInRow(int row) const;
282 int getNumberOfCells() const;
284 int numberOfCellsInRow(int cell) const;
286 void write(Buffer const *, std::ostream &) const;
288 void read(Buffer const *, LyXLex &);
290 int latex(Buffer const *, std::ostream &,
291 LatexRunParams const &) const;
293 int docbook(Buffer const * buf, std::ostream & os, bool mixcont) const;
295 int ascii(Buffer const *, std::ostream &, int const depth,
296 bool onlydata, unsigned char delim) const;
298 bool isMultiColumn(int cell, bool real = false) const;
300 void setMultiColumn(Buffer *, int cell, int number);
302 int unsetMultiColumn(int cell); // returns number of new cells
304 bool isPartOfMultiColumn(int row, int column) const;
306 int row_of_cell(int cell) const;
308 int column_of_cell(int cell) const;
310 int right_column_of_cell(int cell) const;
312 void setLongTabular(bool);
314 bool isLongTabular() const;
316 void setRotateTabular(bool);
318 bool getRotateTabular() const;
320 void setRotateCell(int cell, bool);
322 bool getRotateCell(int cell) const;
324 bool needRotating() const;
326 bool isLastCell(int cell) const;
328 int getCellAbove(int cell) const;
330 int getCellBelow(int cell) const;
332 int getLastCellAbove(int cell) const;
334 int getLastCellBelow(int cell) const;
336 int getCellNumber(int row, int column) const;
338 void setUsebox(int cell, BoxType);
340 BoxType getUsebox(int cell) const;
342 // Long Tabular Options support functions
344 bool checkLTType(int row, ltType const &) const;
346 void setLTHead(int row, bool flag, ltType const &, bool first);
348 bool getRowOfLTHead(int row, ltType &) const;
350 bool getRowOfLTFirstHead(int row, ltType &) const;
352 void setLTFoot(int row, bool flag, ltType const &, bool last);
354 bool getRowOfLTFoot(int row, ltType &) const;
356 bool getRowOfLTLastFoot(int row, ltType &) const;
358 void setLTNewPage(int row, bool what);
360 bool getLTNewPage(int row) const;
362 bool haveLTHead() const;
364 bool haveLTFirstHead() const;
366 bool haveLTFoot() const;
368 bool haveLTLastFoot() const;
370 // end longtable support
372 InsetText * getCellInset(int cell) const;
374 InsetText * getCellInset(int row, int column) const;
375 /// Search for \param inset in the tabular, with the
376 /// additional hint that it could be at \param maybe_cell
377 int getCellFromInset(Inset const * inset, int maybe_cell = -1) const;
379 int rows() const { return rows_; }
381 int columns() const { return columns_;}
383 void validate(LaTeXFeatures &) const;
385 void getLabelList(std::vector<string> &) const;
387 /// recalculate the widths/heights only!
392 mutable int cur_cell;
396 cellstruct(BufferParams const &);
404 LyXAlignment alignment;
406 VAlignment valignment;
420 string align_special;
422 LyXLength p_width; // this is only set for multicolumn!!!
426 cellstruct * cellinfo_of_cell(int cell) const;
428 typedef std::vector<cellstruct> cell_vector;
430 typedef std::vector<cell_vector> cell_vvector;
444 /// This are for longtabulars only
447 /// a row of endfirsthead
451 /// row of endlastfoot
453 /// row for a pagebreak
457 typedef std::vector<rowstruct> row_vector;
460 struct columnstruct {
464 LyXAlignment alignment;
466 VAlignment valignment;
476 string align_special;
479 typedef std::vector<columnstruct> column_vector;
488 std::vector<int> rowofcell;
490 std::vector<int> columnofcell;
494 column_vector column_info;
496 mutable cell_vvector cell_info;
498 int width_of_tabular;
504 bool is_long_tabular;
507 /// endfirsthead data
515 InsetTabular * owner_;
518 void init(BufferParams const &,
519 int columns_arg, int rows_arg, LyXTabular const * lt = 0);
521 void Reinit(bool reset_widths = true);
523 LyXTabular & operator=(LyXTabular const &);
525 void set_row_column_number_info(bool oldformat = false);
526 /// Returns true if a complete update is necessary, otherwise false
527 bool setWidthOfMulticolCell(int cell, int new_width);
529 void recalculateMulticolumnsOfColumn(int column);
530 /// Returns true if change
531 bool calculate_width_of_column(int column);
533 bool calculate_width_of_column_NMC(int column); // no multi cells
535 void calculate_width_of_tabular();
537 void delete_column(int column);
539 int cells_in_multicolumn(int cell) const;
541 BoxType useParbox(int cell) const;
543 void setHeaderFooterRows(int header, int fheader, int footer, int lfooter);
545 // helper function for Latex returns number of newlines
547 int TeXTopHLine(std::ostream &, int row) const;
549 int TeXBottomHLine(std::ostream &, int row) const;
551 int TeXCellPreamble(std::ostream &, int cell) const;
553 int TeXCellPostamble(std::ostream &, int cell) const;
555 int TeXLongtableHeaderFooter(std::ostream &, Buffer const * buf,
556 LatexRunParams const &) const;
558 bool isValidRow(int const row) const;
560 int TeXRow(std::ostream &, int const row, Buffer const * buf,
561 LatexRunParams const &) const;
563 // helper function for ASCII returns number of newlines
565 int asciiTopHLine(std::ostream &, int row,
566 std::vector<unsigned int> const &) const;
568 int asciiBottomHLine(std::ostream &, int row,
569 std::vector<unsigned int> const &) const;
571 int asciiPrintCell(Buffer const *, std::ostream &,
572 int cell, int row, int column,
573 std::vector<unsigned int> const &,
574 bool onlydata) const;
575 /// auxiliary function for docbook
576 int docbookRow(Buffer const * buf, std::ostream & os, int row) const;