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 constructir
181 LyXTabular(BufferParams const &,
182 InsetTabular *, LyXTabular const &);
185 LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
187 LyXTabular & operator=(LyXTabular const &);
189 LyXTabular * clone(BufferParams const &, InsetTabular *);
191 /// Returns true if there is a topline, returns false if not
192 bool topLine(int cell, bool onlycolumn = false) const;
193 /// Returns true if there is a topline, returns false if not
194 bool bottomLine(int cell, bool onlycolumn = false) const;
195 /// Returns true if there is a topline, returns false if not
196 bool leftLine(int cell, bool onlycolumn = false) const;
197 /// Returns true if there is a topline, returns false if not
198 bool rightLine(int cell, bool onlycolumn = false) const;
201 bool topAlreadyDrawn(int cell) const;
203 bool leftAlreadyDrawn(int cell) const;
205 bool isLastRow(int cell) const;
208 int getAdditionalHeight(int row) const;
210 int getAdditionalWidth(int cell) const;
212 /* returns the maximum over all rows */
214 int getWidthOfColumn(int cell) const;
216 int getWidthOfTabular() const;
218 int getAscentOfRow(int row) const;
220 int getDescentOfRow(int row) const;
222 int getHeightOfTabular() const;
223 /// Returns true if a complete update is necessary, otherwise false
224 bool setAscentOfRow(int row, int height);
225 /// Returns true if a complete update is necessary, otherwise false
226 bool setDescentOfRow(int row, int height);
227 /// Returns true if a complete update is necessary, otherwise false
228 bool setWidthOfCell(int cell, int new_width);
229 /// Returns true if a complete update is necessary, otherwise false
230 bool setAllLines(int cell, bool line);
231 /// Returns true if a complete update is necessary, otherwise false
232 bool setTopLine(int cell, bool line, bool onlycolumn = false);
233 /// Returns true if a complete update is necessary, otherwise false
234 bool setBottomLine(int cell, bool line, bool onlycolumn = false);
235 /// Returns true if a complete update is necessary, otherwise false
236 bool setLeftLine(int cell, bool line, bool onlycolumn = false);
237 /// Returns true if a complete update is necessary, otherwise false
238 bool setRightLine(int cell, bool line, bool onlycolumn = false);
239 /// Returns true if a complete update is necessary, otherwise false
240 bool setAlignment(int cell, LyXAlignment align,
241 bool onlycolumn = false);
242 /// Returns true if a complete update is necessary, otherwise false
243 bool setVAlignment(int cell, VAlignment align,
244 bool onlycolumn = false);
246 bool setColumnPWidth(int cell, LyXLength const & width);
248 bool setMColumnPWidth(int cell, LyXLength const & width);
250 bool setAlignSpecial(int cell, string const & special, Feature what);
252 LyXAlignment getAlignment(int cell, bool onlycolumn = false) const;
254 VAlignment getVAlignment(int cell, bool onlycolumn = false) const;
256 LyXLength const getPWidth(int cell) const;
258 LyXLength const getColumnPWidth(int cell) const;
260 LyXLength const getMColumnPWidth(int cell) const;
262 string const getAlignSpecial(int cell, int what) const;
264 int getWidthOfCell(int cell) const;
266 int getBeginningOfTextInCell(int cell) const;
268 void appendRow(BufferParams const &, int cell);
270 void deleteRow(int row);
272 void appendColumn(BufferParams const &, int cell);
274 void deleteColumn(int column);
276 bool isFirstCellInRow(int cell) const;
278 int getFirstCellInRow(int row) const;
280 bool isLastCellInRow(int cell) const;
282 int getLastCellInRow(int row) const;
284 int getNumberOfCells() const;
286 int numberOfCellsInRow(int cell) const;
288 void write(Buffer const *, std::ostream &) const;
290 void read(Buffer const *, LyXLex &);
292 int latex(Buffer const *, std::ostream &,
293 LatexRunParams const &) const;
295 int docbook(Buffer const * buf, std::ostream & os, bool mixcont) const;
297 int ascii(Buffer const *, std::ostream &, int const depth,
298 bool onlydata, unsigned char delim) const;
300 bool isMultiColumn(int cell, bool real = false) const;
302 void setMultiColumn(Buffer *, int cell, int number);
304 int unsetMultiColumn(int cell); // returns number of new cells
306 bool isPartOfMultiColumn(int row, int column) const;
308 int row_of_cell(int cell) const;
310 int column_of_cell(int cell) const;
312 int right_column_of_cell(int cell) const;
314 void setLongTabular(bool);
316 bool isLongTabular() const;
318 void setRotateTabular(bool);
320 bool getRotateTabular() const;
322 void setRotateCell(int cell, bool);
324 bool getRotateCell(int cell) const;
326 bool needRotating() const;
328 bool isLastCell(int cell) const;
330 int getCellAbove(int cell) const;
332 int getCellBelow(int cell) const;
334 int getLastCellAbove(int cell) const;
336 int getLastCellBelow(int cell) const;
338 int getCellNumber(int row, int column) const;
340 void setUsebox(int cell, BoxType);
342 BoxType getUsebox(int cell) const;
344 // Long Tabular Options support functions
346 bool checkLTType(int row, ltType const &) const;
348 void setLTHead(int row, bool flag, ltType const &, bool first);
350 bool getRowOfLTHead(int row, ltType &) const;
352 bool getRowOfLTFirstHead(int row, ltType &) const;
354 void setLTFoot(int row, bool flag, ltType const &, bool last);
356 bool getRowOfLTFoot(int row, ltType &) const;
358 bool getRowOfLTLastFoot(int row, ltType &) const;
360 void setLTNewPage(int row, bool what);
362 bool getLTNewPage(int row) const;
364 bool haveLTHead() const;
366 bool haveLTFirstHead() const;
368 bool haveLTFoot() const;
370 bool haveLTLastFoot() const;
372 // end longtable support
374 InsetText * getCellInset(int cell) const;
376 InsetText * getCellInset(int row, int column) const;
377 /// Search for \param inset in the tabular, with the
378 /// additional hint that it could be at \param maybe_cell
379 int getCellFromInset(Inset const * inset, int maybe_cell = -1) const;
381 int rows() const { return rows_; }
383 int columns() const { return columns_;}
385 void validate(LaTeXFeatures &) const;
387 std::vector<string> const getLabelList() const;
389 /// recalculate the widths/heights only!
393 mutable int cur_cell;
397 cellstruct(BufferParams const &);
405 LyXAlignment alignment;
407 VAlignment valignment;
421 string align_special;
423 LyXLength p_width; // this is only set for multicolumn!!!
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;
482 void read(Buffer const * buf, std::istream & is,
483 LyXLex & lex, string const & l, int const version);
492 std::vector<int> rowofcell;
494 std::vector<int> columnofcell;
498 column_vector column_info;
500 mutable cell_vvector cell_info;
502 int width_of_tabular;
508 bool is_long_tabular;
511 /// endfirsthead data
519 InsetTabular * owner_;
522 void init(BufferParams const &,
523 int columns_arg, int rows_arg, LyXTabular const * lt = 0);
525 void Reinit(bool reset_widths = true);
527 void set_row_column_number_info(bool oldformat = false);
528 /// Returns true if a complete update is necessary, otherwise false
529 bool setWidthOfMulticolCell(int cell, int new_width);
531 void recalculateMulticolumnsOfColumn(int column);
532 /// Returns true if change
533 bool calculate_width_of_column(int column);
535 bool calculate_width_of_column_NMC(int column); // no multi cells
537 void calculate_width_of_tabular();
539 cellstruct * cellinfo_of_cell(int cell) const;
541 void delete_column(int column);
543 int cells_in_multicolumn(int cell) const;
545 BoxType useParbox(int cell) const;
547 void setHeaderFooterRows(int header, int fheader, int footer, int lfooter);
549 // helper function for Latex returns number of newlines
551 int TeXTopHLine(std::ostream &, int row) const;
553 int TeXBottomHLine(std::ostream &, int row) const;
555 int TeXCellPreamble(std::ostream &, int cell) const;
557 int TeXCellPostamble(std::ostream &, int cell) const;
559 int TeXLongtableHeaderFooter(std::ostream &, Buffer const * buf,
560 LatexRunParams const &) const;
562 bool isValidRow(int const row) const;
564 int TeXRow(std::ostream &, int const row, Buffer const * buf,
565 LatexRunParams const &) const;
567 // helper function for ASCII returns number of newlines
569 int asciiTopHLine(std::ostream &, int row,
570 std::vector<unsigned int> const &) const;
572 int asciiBottomHLine(std::ostream &, int row,
573 std::vector<unsigned int> const &) const;
575 int asciiPrintCell(Buffer const *, std::ostream &,
576 int cell, int row, int column,
577 std::vector<unsigned int> const &,
578 bool onlydata) const;
579 /// auxiliary function for docbook
580 int docbookRow(Buffer const * buf, std::ostream & os, int row) const;