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!
176 typedef struct lttype ltType;
180 LyXTabular(BufferParams const &,
181 InsetTabular *, int columns_arg, int rows_arg);
183 LyXTabular(BufferParams const &,
184 InsetTabular *, LyXTabular const &, bool same_id = false);
187 LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
189 LyXTabular & operator=(LyXTabular const &);
191 LyXTabular * clone(BufferParams const &,
192 InsetTabular *, bool same_id = false);
194 /// Returns true if there is a topline, returns false if not
195 bool TopLine(int cell, bool onlycolumn = false) const;
196 /// Returns true if there is a topline, returns false if not
197 bool BottomLine(int cell, bool onlycolumn = false) const;
198 /// Returns true if there is a topline, returns false if not
199 bool LeftLine(int cell, bool onlycolumn = false) const;
200 /// Returns true if there is a topline, returns false if not
201 bool RightLine(int cell, bool onlycolumn = false) const;
204 bool TopAlreadyDrawed(int cell) const;
206 bool LeftAlreadyDrawed(int cell) const;
208 bool IsLastRow(int cell) const;
211 int GetAdditionalHeight(int row) const;
213 int GetAdditionalWidth(int cell) const;
215 /* returns the maximum over all rows */
217 int GetWidthOfColumn(int cell) const;
219 int GetWidthOfTabular() const;
221 int GetAscentOfRow(int row) const;
223 int GetDescentOfRow(int row) const;
225 int GetHeightOfTabular() const;
226 /// Returns true if a complete update is necessary, otherwise false
227 bool SetAscentOfRow(int row, int height);
228 /// Returns true if a complete update is necessary, otherwise false
229 bool SetDescentOfRow(int row, int height);
230 /// Returns true if a complete update is necessary, otherwise false
231 bool SetWidthOfCell(int cell, int new_width);
232 /// Returns true if a complete update is necessary, otherwise false
233 bool SetAllLines(int cell, bool line);
234 /// Returns true if a complete update is necessary, otherwise false
235 bool SetTopLine(int cell, bool line, bool onlycolumn = false);
236 /// Returns true if a complete update is necessary, otherwise false
237 bool SetBottomLine(int cell, bool line, bool onlycolumn = false);
238 /// Returns true if a complete update is necessary, otherwise false
239 bool SetLeftLine(int cell, bool line, bool onlycolumn = false);
240 /// Returns true if a complete update is necessary, otherwise false
241 bool SetRightLine(int cell, bool line, bool onlycolumn = false);
242 /// Returns true if a complete update is necessary, otherwise false
243 bool SetAlignment(int cell, LyXAlignment align,
244 bool onlycolumn = false);
245 /// Returns true if a complete update is necessary, otherwise false
246 bool SetVAlignment(int cell, VAlignment align,
247 bool onlycolumn = false);
249 bool SetColumnPWidth(int cell, LyXLength const & width);
251 bool SetMColumnPWidth(int cell, LyXLength const & width);
253 bool SetAlignSpecial(int cell, string const & special, Feature what);
255 LyXAlignment GetAlignment(int cell, bool onlycolumn = false) const;
257 VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
259 LyXLength const GetPWidth(int cell) const;
261 LyXLength const GetColumnPWidth(int cell) const;
263 LyXLength const GetMColumnPWidth(int cell) const;
265 string const GetAlignSpecial(int cell, int what) const;
267 int GetWidthOfCell(int cell) const;
269 int GetBeginningOfTextInCell(int cell) const;
271 void AppendRow(BufferParams const &, int cell);
273 void DeleteRow(int row);
275 void AppendColumn(BufferParams const &, int cell);
277 void DeleteColumn(int column);
279 bool IsFirstCellInRow(int cell) const;
281 int GetFirstCellInRow(int row) const;
283 bool IsLastCellInRow(int cell) const;
285 int GetLastCellInRow(int row) const;
287 int GetNumberOfCells() const;
289 int NumberOfCellsInRow(int cell) const;
291 void Write(Buffer const *, std::ostream &) const;
293 void Read(Buffer const *, LyXLex &);
295 void OldFormatRead(BufferParams const &, LyXLex &, string const &);
297 int latex(Buffer const *, std::ostream &, bool, bool) const;
299 int docbook(Buffer const * buf, std::ostream & os, bool mixcont) const;
301 int ascii(Buffer const *, std::ostream &, int const depth,
302 bool onlydata, unsigned char delim) const;
304 bool IsMultiColumn(int cell, bool real = false) const;
306 void SetMultiColumn(Buffer const *, int cell, int number);
308 int UnsetMultiColumn(int cell); // returns number of new cells
310 bool IsPartOfMultiColumn(int row, int column) const;
312 int row_of_cell(int cell) const;
314 int column_of_cell(int cell) const;
316 int right_column_of_cell(int cell) const;
318 void SetLongTabular(bool);
320 bool IsLongTabular() const;
322 void SetRotateTabular(bool);
324 bool GetRotateTabular() const;
326 void SetRotateCell(int cell, bool);
328 bool GetRotateCell(int cell) const;
330 bool NeedRotating() const;
332 bool IsLastCell(int cell) const;
334 int GetCellAbove(int cell) const;
336 int GetCellBelow(int cell) const;
338 int GetLastCellAbove(int cell) const;
340 int GetLastCellBelow(int cell) const;
342 int GetCellNumber(int row, int column) const;
344 void SetUsebox(int cell, BoxType);
346 BoxType GetUsebox(int cell) const;
348 // Long Tabular Options support functions
350 bool checkLTType(int row, ltType const &) const;
352 void SetLTHead(int row, bool flag, ltType const &, bool first);
354 bool GetRowOfLTHead(int row, ltType &) const;
356 bool GetRowOfLTFirstHead(int row, ltType &) const;
358 void SetLTFoot(int row, bool flag, ltType const &, bool last);
360 bool GetRowOfLTFoot(int row, ltType &) const;
362 bool GetRowOfLTLastFoot(int row, ltType &) const;
364 void SetLTNewPage(int row, bool what);
366 bool GetLTNewPage(int row) const;
368 bool haveLTHead() const;
370 bool haveLTFirstHead() const;
372 bool haveLTFoot() const;
374 bool haveLTLastFoot() const;
376 // end longtable support
378 InsetText * GetCellInset(int cell) const;
380 InsetText * GetCellInset(int row, int column) const;
381 /// Search for \param inset in the tabular, with the
382 /// additional hint that it could be at \param maybe_cell
383 int GetCellFromInset(Inset const * inset, int maybe_cell = -1) const;
385 int rows() const { return rows_; }
387 int columns() const { return columns_;}
389 InsetTabular * owner() const { return owner_; }
391 void Validate(LaTeXFeatures &) const;
393 std::vector<string> const getLabelList() const;
395 /// recalculate the widths/heights only!
398 mutable int cur_cell;
403 cellstruct(BufferParams const &);
411 LyXAlignment alignment;
413 VAlignment valignment;
427 string align_special;
429 LyXLength p_width; // this is only set for multicolumn!!!
434 typedef std::vector<cellstruct> cell_vector;
436 typedef std::vector<cell_vector> cell_vvector;
450 /// This are for longtabulars only
453 /// a row of endfirsthead
457 /// row of endlastfoot
459 /// row for a pagebreak
463 typedef std::vector<rowstruct> row_vector;
466 struct columnstruct {
470 LyXAlignment alignment;
472 VAlignment valignment;
482 string align_special;
485 typedef std::vector<columnstruct> column_vector;
488 void ReadNew(Buffer const * buf, std::istream & is,
489 LyXLex & lex, string const & l, int const version);
491 void ReadOld(Buffer const * buf, std::istream & is,
492 LyXLex & lex, string const & l);
500 std::vector<int> rowofcell;
502 std::vector<int> columnofcell;
506 column_vector column_info;
508 mutable cell_vvector cell_info;
510 int width_of_tabular;
516 bool is_long_tabular;
519 /// endfirsthead data
527 InsetTabular * owner_;
530 void Init(BufferParams const &,
531 int columns_arg, int rows_arg, LyXTabular const * lt = 0);
533 void Reinit(bool reset_widths = true);
535 void set_row_column_number_info(bool oldformat = false);
536 /// Returns true if a complete update is necessary, otherwise false
537 bool SetWidthOfMulticolCell(int cell, int new_width);
539 void recalculateMulticolumnsOfColumn(int column);
540 /// Returns true if change
541 bool calculate_width_of_column(int column);
543 bool calculate_width_of_column_NMC(int column); // no multi cells
545 void calculate_width_of_tabular();
547 cellstruct * cellinfo_of_cell(int cell) const;
549 void delete_column(int column);
551 int cells_in_multicolumn(int cell) const;
553 BoxType UseParbox(int cell) const;
555 void setHeaderFooterRows(int header, int fheader, int footer, int lfooter);
557 // helper function for Latex returns number of newlines
559 int TeXTopHLine(std::ostream &, int row) const;
561 int TeXBottomHLine(std::ostream &, int row) const;
563 int TeXCellPreamble(std::ostream &, int cell) const;
565 int TeXCellPostamble(std::ostream &, int cell) const;
567 int TeXLongtableHeaderFooter(std::ostream &, Buffer const * buf,
568 bool fragile, bool fp) const;
570 bool isValidRow(int const row) const;
572 int TeXRow(std::ostream &, int const row, Buffer const * buf,
573 bool fragile, bool fp) const;
575 // helper function for ASCII returns number of newlines
577 int asciiTopHLine(std::ostream &, int row,
578 std::vector<unsigned int> const &) const;
580 int asciiBottomHLine(std::ostream &, int row,
581 std::vector<unsigned int> const &) const;
583 int asciiPrintCell(Buffer const *, std::ostream &,
584 int cell, int row, int column,
585 std::vector<unsigned int> const &,
586 bool onlydata) const;
587 /// auxiliary function for docbook
588 int docbookRow(Buffer const * buf, std::ostream & os, int row) const;