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"
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_CENTER = 2
164 // we have this header type (is set in the GetLT... functions)
166 // double borders on top
168 // double borders on bottom
170 // used for FirstHeader & LastFooter and if this is true
171 // all the rows marked as FirstHeader or LastFooter are
172 // ignored in the output and it is set to be empty!
178 LyXTabular(BufferParams const &,
179 InsetTabular *, int columns_arg, int rows_arg);
181 LyXTabular(BufferParams const &,
182 InsetTabular *, LyXTabular const &, bool same_id = false);
185 LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
187 LyXTabular & operator=(LyXTabular const &);
189 LyXTabular * clone(BufferParams const &,
190 InsetTabular *, bool same_id = false);
192 /// Returns true if there is a topline, returns false if not
193 bool TopLine(int cell, bool onlycolumn = false) const;
194 /// Returns true if there is a topline, returns false if not
195 bool BottomLine(int cell, bool onlycolumn = false) const;
196 /// Returns true if there is a topline, returns false if not
197 bool LeftLine(int cell, bool onlycolumn = false) const;
198 /// Returns true if there is a topline, returns false if not
199 bool RightLine(int cell, bool onlycolumn = false) const;
202 bool topAlreadyDrawn(int cell) const;
204 bool leftAlreadyDrawn(int cell) const;
206 bool IsLastRow(int cell) const;
209 int GetAdditionalHeight(int row) const;
211 int GetAdditionalWidth(int cell) const;
213 /* returns the maximum over all rows */
215 int GetWidthOfColumn(int cell) const;
217 int GetWidthOfTabular() const;
219 int GetAscentOfRow(int row) const;
221 int GetDescentOfRow(int row) const;
223 int GetHeightOfTabular() const;
224 /// Returns true if a complete update is necessary, otherwise false
225 bool SetAscentOfRow(int row, int height);
226 /// Returns true if a complete update is necessary, otherwise false
227 bool SetDescentOfRow(int row, int height);
228 /// Returns true if a complete update is necessary, otherwise false
229 bool SetWidthOfCell(int cell, int new_width);
230 /// Returns true if a complete update is necessary, otherwise false
231 bool SetAllLines(int cell, bool line);
232 /// Returns true if a complete update is necessary, otherwise false
233 bool SetTopLine(int cell, bool line, bool onlycolumn = false);
234 /// Returns true if a complete update is necessary, otherwise false
235 bool SetBottomLine(int cell, bool line, bool onlycolumn = false);
236 /// Returns true if a complete update is necessary, otherwise false
237 bool SetLeftLine(int cell, bool line, bool onlycolumn = false);
238 /// Returns true if a complete update is necessary, otherwise false
239 bool SetRightLine(int cell, bool line, bool onlycolumn = false);
240 /// Returns true if a complete update is necessary, otherwise false
241 bool SetAlignment(int cell, LyXAlignment align,
242 bool onlycolumn = false);
243 /// Returns true if a complete update is necessary, otherwise false
244 bool SetVAlignment(int cell, VAlignment align,
245 bool onlycolumn = false);
247 bool SetColumnPWidth(int cell, LyXLength const & width);
249 bool SetMColumnPWidth(int cell, LyXLength const & width);
251 bool SetAlignSpecial(int cell, string const & special, Feature what);
253 LyXAlignment GetAlignment(int cell, bool onlycolumn = false) const;
255 VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
257 LyXLength const GetPWidth(int cell) const;
259 LyXLength const GetColumnPWidth(int cell) const;
261 LyXLength const GetMColumnPWidth(int cell) const;
263 string const GetAlignSpecial(int cell, int what) const;
265 int GetWidthOfCell(int cell) const;
267 int GetBeginningOfTextInCell(int cell) const;
269 void AppendRow(BufferParams const &, int cell);
271 void DeleteRow(int row);
273 void AppendColumn(BufferParams const &, int cell);
275 void DeleteColumn(int column);
277 bool IsFirstCellInRow(int cell) const;
279 int GetFirstCellInRow(int row) const;
281 bool IsLastCellInRow(int cell) const;
283 int GetLastCellInRow(int row) const;
285 int GetNumberOfCells() const;
287 int NumberOfCellsInRow(int cell) const;
289 void Write(Buffer const *, std::ostream &) const;
291 void Read(Buffer const *, LyXLex &);
293 int latex(Buffer const *, std::ostream &, bool, bool) 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 InsetTabular * owner() const { return owner_; }
387 void Validate(LaTeXFeatures &) const;
389 std::vector<string> const getLabelList() const;
391 /// recalculate the widths/heights only!
394 mutable int cur_cell;
399 cellstruct(BufferParams const &);
407 LyXAlignment alignment;
409 VAlignment valignment;
423 string align_special;
425 LyXLength p_width; // this is only set for multicolumn!!!
430 typedef std::vector<cellstruct> cell_vector;
432 typedef std::vector<cell_vector> cell_vvector;
446 /// This are for longtabulars only
449 /// a row of endfirsthead
453 /// row of endlastfoot
455 /// row for a pagebreak
459 typedef std::vector<rowstruct> row_vector;
462 struct columnstruct {
466 LyXAlignment alignment;
468 VAlignment valignment;
478 string align_special;
481 typedef std::vector<columnstruct> column_vector;
484 void read(Buffer const * buf, std::istream & is,
485 LyXLex & lex, string const & l, int const version);
494 std::vector<int> rowofcell;
496 std::vector<int> columnofcell;
500 column_vector column_info;
502 mutable cell_vvector cell_info;
504 int width_of_tabular;
510 bool is_long_tabular;
513 /// endfirsthead data
521 InsetTabular * owner_;
524 void Init(BufferParams const &,
525 int columns_arg, int rows_arg, LyXTabular const * lt = 0);
527 void Reinit(bool reset_widths = true);
529 void set_row_column_number_info(bool oldformat = false);
530 /// Returns true if a complete update is necessary, otherwise false
531 bool SetWidthOfMulticolCell(int cell, int new_width);
533 void recalculateMulticolumnsOfColumn(int column);
534 /// Returns true if change
535 bool calculate_width_of_column(int column);
537 bool calculate_width_of_column_NMC(int column); // no multi cells
539 void calculate_width_of_tabular();
541 cellstruct * cellinfo_of_cell(int cell) const;
543 void delete_column(int column);
545 int cells_in_multicolumn(int cell) const;
547 BoxType UseParbox(int cell) const;
549 void setHeaderFooterRows(int header, int fheader, int footer, int lfooter);
551 // helper function for Latex returns number of newlines
553 int TeXTopHLine(std::ostream &, int row) const;
555 int TeXBottomHLine(std::ostream &, int row) const;
557 int TeXCellPreamble(std::ostream &, int cell) const;
559 int TeXCellPostamble(std::ostream &, int cell) const;
561 int TeXLongtableHeaderFooter(std::ostream &, Buffer const * buf,
562 bool fragile, bool fp) const;
564 bool isValidRow(int const row) const;
566 int TeXRow(std::ostream &, int const row, Buffer const * buf,
567 bool fragile, bool fp) const;
569 // helper function for ASCII returns number of newlines
571 int asciiTopHLine(std::ostream &, int row,
572 std::vector<unsigned int> const &) const;
574 int asciiBottomHLine(std::ostream &, int row,
575 std::vector<unsigned int> const &) const;
577 int asciiPrintCell(Buffer const *, std::ostream &,
578 int cell, int row, int column,
579 std::vector<unsigned int> const &,
580 bool onlydata) const;
581 /// auxiliary function for docbook
582 int docbookRow(Buffer const * buf, std::ostream & os, int row) const;