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 * ====================================================== */
21 #include "lyxlength.h"
23 #include "insets/insettext.h"
34 /* The features the text class offers for tables */
106 UNSET_ROTATE_TABULAR,
139 CELL_BEGIN_OF_MULTICOLUMN,
141 CELL_PART_OF_MULTICOLUMN
149 LYX_VALIGN_BOTTOM = 1,
151 LYX_VALIGN_CENTER = 2
166 // we have this header type (is set in the GetLT... functions)
168 // double borders on top
170 // double borders on bottom
172 // used for FirstHeader & LastFooter and if this is true
173 // all the rows marked as FirstHeader or LastFooter are
174 // ignored in the output and it is set to be empty!
178 typedef struct lttype ltType;
182 LyXTabular(BufferParams const &,
183 InsetTabular *, int columns_arg, int rows_arg);
185 LyXTabular(BufferParams const &,
186 InsetTabular *, LyXTabular const &, bool same_id = false);
189 LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
191 LyXTabular & operator=(LyXTabular const &);
193 LyXTabular * clone(BufferParams const &,
194 InsetTabular *, bool same_id = false);
196 /// Returns true if there is a topline, returns false if not
197 bool TopLine(int cell, bool onlycolumn = false) const;
198 /// Returns true if there is a topline, returns false if not
199 bool BottomLine(int cell, bool onlycolumn = false) const;
200 /// Returns true if there is a topline, returns false if not
201 bool LeftLine(int cell, bool onlycolumn = false) const;
202 /// Returns true if there is a topline, returns false if not
203 bool RightLine(int cell, bool onlycolumn = false) const;
206 bool TopAlreadyDrawed(int cell) const;
208 bool LeftAlreadyDrawed(int cell) const;
210 bool IsLastRow(int cell) const;
213 int GetAdditionalHeight(int row) const;
215 int GetAdditionalWidth(int cell) const;
217 /* returns the maximum over all rows */
219 int GetWidthOfColumn(int cell) const;
221 int GetWidthOfTabular() const;
223 int GetAscentOfRow(int row) const;
225 int GetDescentOfRow(int row) const;
227 int GetHeightOfTabular() const;
228 /// Returns true if a complete update is necessary, otherwise false
229 bool SetAscentOfRow(int row, int height);
230 /// Returns true if a complete update is necessary, otherwise false
231 bool SetDescentOfRow(int row, int height);
232 /// Returns true if a complete update is necessary, otherwise false
233 bool SetWidthOfCell(int cell, int new_width);
234 /// Returns true if a complete update is necessary, otherwise false
235 bool SetAllLines(int cell, bool line);
236 /// Returns true if a complete update is necessary, otherwise false
237 bool SetTopLine(int cell, bool line, bool onlycolumn = false);
238 /// Returns true if a complete update is necessary, otherwise false
239 bool SetBottomLine(int cell, bool line, bool onlycolumn = false);
240 /// Returns true if a complete update is necessary, otherwise false
241 bool SetLeftLine(int cell, bool line, bool onlycolumn = false);
242 /// Returns true if a complete update is necessary, otherwise false
243 bool SetRightLine(int cell, bool line, bool onlycolumn = false);
244 /// Returns true if a complete update is necessary, otherwise false
245 bool SetAlignment(int cell, LyXAlignment align,
246 bool onlycolumn = false);
247 /// Returns true if a complete update is necessary, otherwise false
248 bool SetVAlignment(int cell, VAlignment align,
249 bool onlycolumn = false);
251 bool SetColumnPWidth(int cell, LyXLength const & width);
253 bool SetMColumnPWidth(int cell, LyXLength const & width);
255 bool SetAlignSpecial(int cell, string const & special, Feature what);
257 LyXAlignment GetAlignment(int cell, bool onlycolumn = false) const;
259 VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
261 LyXLength const GetPWidth(int cell) const;
263 LyXLength const GetColumnPWidth(int cell) const;
265 LyXLength const GetMColumnPWidth(int cell) const;
267 string const GetAlignSpecial(int cell, int what) const;
269 int GetWidthOfCell(int cell) const;
271 int GetBeginningOfTextInCell(int cell) const;
273 void AppendRow(BufferParams const &, int cell);
275 void DeleteRow(int row);
277 void AppendColumn(BufferParams const &, int cell);
279 void DeleteColumn(int column);
281 bool IsFirstCellInRow(int cell) const;
283 int GetFirstCellInRow(int row) const;
285 bool IsLastCellInRow(int cell) const;
287 int GetLastCellInRow(int row) const;
289 int GetNumberOfCells() const;
291 int NumberOfCellsInRow(int cell) const;
293 void Write(Buffer const *, std::ostream &) const;
295 void Read(Buffer const *, LyXLex &);
297 void OldFormatRead(BufferParams const &, LyXLex &, string const &);
299 int latex(Buffer const *, std::ostream &, bool, bool) const;
301 int docbook(Buffer const * buf, std::ostream & os, bool mixcont) const;
303 int ascii(Buffer const *, std::ostream &, int const depth,
304 bool onlydata, unsigned char delim) const;
306 bool IsMultiColumn(int cell, bool real = false) const;
308 void SetMultiColumn(Buffer const *, int cell, int number);
310 int UnsetMultiColumn(int cell); // returns number of new cells
312 bool IsPartOfMultiColumn(int row, int column) const;
314 int row_of_cell(int cell) const;
316 int column_of_cell(int cell) const;
318 int right_column_of_cell(int cell) const;
320 void SetLongTabular(bool);
322 bool IsLongTabular() const;
324 void SetRotateTabular(bool);
326 bool GetRotateTabular() const;
328 void SetRotateCell(int cell, bool);
330 bool GetRotateCell(int cell) const;
332 bool NeedRotating() const;
334 bool IsLastCell(int cell) const;
336 int GetCellAbove(int cell) const;
338 int GetCellBelow(int cell) const;
340 int GetLastCellAbove(int cell) const;
342 int GetLastCellBelow(int cell) const;
344 int GetCellNumber(int row, int column) const;
346 void SetUsebox(int cell, BoxType);
348 BoxType GetUsebox(int cell) const;
350 // Long Tabular Options support functions
352 bool checkLTType(int row, ltType const &) const;
354 void SetLTHead(int row, bool flag, ltType const &, bool first);
356 bool GetRowOfLTHead(int row, ltType &) const;
358 bool GetRowOfLTFirstHead(int row, ltType &) const;
360 void SetLTFoot(int row, bool flag, ltType const &, bool last);
362 bool GetRowOfLTFoot(int row, ltType &) const;
364 bool GetRowOfLTLastFoot(int row, ltType &) const;
366 void SetLTNewPage(int row, bool what);
368 bool GetLTNewPage(int row) const;
370 bool haveLTHead() const;
372 bool haveLTFirstHead() const;
374 bool haveLTFoot() const;
376 bool haveLTLastFoot() const;
378 // end longtable support
380 InsetText * GetCellInset(int cell) const;
382 InsetText * GetCellInset(int row, int column) const;
383 /// Search for \param inset in the tabular, with the
384 /// additional hint that it could be at \param maybe_cell
385 int GetCellFromInset(Inset const * inset, int maybe_cell = -1) const;
387 int rows() const { return rows_; }
389 int columns() const { return columns_;}
391 InsetTabular * owner() const { return owner_; }
393 void Validate(LaTeXFeatures &) const;
395 std::vector<string> const getLabelList() const;
397 /// recalculate the widths/heights only!
400 mutable int cur_cell;
405 cellstruct(BufferParams const &);
413 LyXAlignment alignment;
415 VAlignment valignment;
429 string align_special;
431 LyXLength p_width; // this is only set for multicolumn!!!
436 typedef std::vector<cellstruct> cell_vector;
438 typedef std::vector<cell_vector> cell_vvector;
452 /// This are for longtabulars only
455 /// a row of endfirsthead
459 /// row of endlastfoot
461 /// row for a pagebreak
465 typedef std::vector<rowstruct> row_vector;
468 struct columnstruct {
472 LyXAlignment alignment;
474 VAlignment valignment;
484 string align_special;
487 typedef std::vector<columnstruct> column_vector;
490 void ReadNew(Buffer const * buf, std::istream & is,
491 LyXLex & lex, string const & l, int const version);
493 void ReadOld(Buffer const * buf, std::istream & is,
494 LyXLex & lex, string const & l);
502 std::vector<int> rowofcell;
504 std::vector<int> columnofcell;
508 column_vector column_info;
510 mutable cell_vvector cell_info;
512 int width_of_tabular;
518 bool is_long_tabular;
521 /// endfirsthead data
529 InsetTabular * owner_;
532 void Init(BufferParams const &,
533 int columns_arg, int rows_arg, LyXTabular const * lt = 0);
535 void Reinit(bool reset_widths = true);
537 void set_row_column_number_info(bool oldformat = false);
538 /// Returns true if a complete update is necessary, otherwise false
539 bool SetWidthOfMulticolCell(int cell, int new_width);
541 void recalculateMulticolumnsOfColumn(int column);
542 /// Returns true if change
543 bool calculate_width_of_column(int column);
545 bool calculate_width_of_column_NMC(int column); // no multi cells
547 void calculate_width_of_tabular();
549 cellstruct * cellinfo_of_cell(int cell) const;
551 void delete_column(int column);
553 int cells_in_multicolumn(int cell) const;
555 BoxType UseParbox(int cell) const;
557 void setHeaderFooterRows(int header, int fheader, int footer, int lfooter);
559 // helper function for Latex returns number of newlines
561 int TeXTopHLine(std::ostream &, int row) const;
563 int TeXBottomHLine(std::ostream &, int row) const;
565 int TeXCellPreamble(std::ostream &, int cell) const;
567 int TeXCellPostamble(std::ostream &, int cell) const;
569 int TeXLongtableHeaderFooter(std::ostream &, Buffer const * buf,
570 bool fragile, bool fp) const;
572 bool isValidRow(int const row) const;
574 int TeXRow(std::ostream &, int const row, Buffer const * buf,
575 bool fragile, bool fp) const;
577 // helper function for ASCII returns number of newlines
579 int asciiTopHLine(std::ostream &, int row,
580 std::vector<unsigned int> const &) const;
582 int asciiBottomHLine(std::ostream &, int row,
583 std::vector<unsigned int> const &) const;
585 int asciiPrintCell(Buffer const *, std::ostream &,
586 int cell, int row, int column,
587 std::vector<unsigned int> const &,
588 bool onlydata) const;
589 /// auxiliary function for docbook
590 int docbookRow(Buffer const * buf, std::ostream & os, int row) const;