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 * ====================================================== */
25 #include "insets/insettext.h"
26 #include "lyxlength.h"
32 /* 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(InsetTabular *, int columns_arg, int rows_arg);
182 LyXTabular(InsetTabular *, LyXTabular const &, bool same_id = false);
185 LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
187 LyXTabular & operator=(LyXTabular const &);
189 LyXTabular * clone(InsetTabular *, bool same_id = false);
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 TopAlreadyDrawed(int cell) const;
203 bool LeftAlreadyDrawed(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(int cell);
270 void DeleteRow(int row);
272 void AppendColumn(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 void OldFormatRead(LyXLex &, string const &);
294 // helper function for Latex returns number of newlines
296 int TeXTopHLine(std::ostream &, int row) const;
298 int TeXBottomHLine(std::ostream &, int row) const;
300 int TeXCellPreamble(std::ostream &, int cell) const;
302 int TeXCellPostamble(std::ostream &, int cell) const;
304 int TeXLongtableHeaderFooter(std::ostream &, Buffer const * buf,
305 bool fragile, bool fp) const;
307 bool isValidRow(int const row) const;
309 int TeXRow(std::ostream &, int const row, Buffer const * buf,
310 bool fragile, bool fp) const;
312 int Latex(Buffer const *, std::ostream &, bool, bool) const;
313 /// auxiliary function for docbook rows
314 int docbookRow(Buffer const * buf, std::ostream & os, int row) const;
316 int DocBook(Buffer const * buf, std::ostream & os) const;
318 // helper function for Latex returns number of newlines
320 int AsciiTopHLine(std::ostream &, int row,
321 std::vector<unsigned int> const &) const;
323 int AsciiBottomHLine(std::ostream &, int row,
324 std::vector<unsigned int> const &) const;
326 int AsciiPrintCell(Buffer const *, std::ostream &,
327 int cell, int row, int column,
328 std::vector<unsigned int> const &) const;
330 int Ascii(Buffer const *, std::ostream &) const;
332 bool IsMultiColumn(int cell, bool real = false) const;
334 void SetMultiColumn(int cell, int number);
336 int UnsetMultiColumn(int cell); // returns number of new cells
338 bool IsPartOfMultiColumn(int row, int column) const;
340 int row_of_cell(int cell) const;
342 int column_of_cell(int cell) const;
344 int right_column_of_cell(int cell) const;
346 void SetLongTabular(bool);
348 bool IsLongTabular() const;
350 void SetRotateTabular(bool);
352 bool GetRotateTabular() const;
354 void SetRotateCell(int cell, bool);
356 bool GetRotateCell(int cell) const;
358 bool NeedRotating() const;
360 bool IsLastCell(int cell) const;
362 int GetCellAbove(int cell) const;
364 int GetCellBelow(int cell) const;
366 int GetLastCellAbove(int cell) const;
368 int GetLastCellBelow(int cell) const;
370 int GetCellNumber(int row, int column) const;
372 void SetUsebox(int cell, BoxType);
374 BoxType GetUsebox(int cell) const;
376 // Long Tabular Options support functions
378 bool checkLTType(int row, ltType const &) const;
380 void SetLTHead(int row, bool flag, ltType const &, bool first);
382 bool GetRowOfLTHead(int row, ltType &) const;
384 bool GetRowOfLTFirstHead(int row, ltType &) const;
386 void SetLTFoot(int row, bool flag, ltType const &, bool last);
388 bool GetRowOfLTFoot(int row, ltType &) const;
390 bool GetRowOfLTLastFoot(int row, ltType &) const;
392 void SetLTNewPage(int row, bool what);
394 bool GetLTNewPage(int row) const;
396 bool haveLTHead() const;
398 bool haveLTFirstHead() const;
400 bool haveLTFoot() const;
402 bool haveLTLastFoot() const;
404 // end longtable support
406 InsetText * GetCellInset(int cell) const;
408 InsetText * GetCellInset(int row, int column) const;
410 int rows() const { return rows_; }
412 int columns() const { return columns_;}
414 InsetTabular * owner() const { return owner_; }
416 void Validate(LaTeXFeatures &) const;
418 std::vector<string> const getLabelList() const;
420 /// recalculate the widths/heights only!
423 mutable int cur_cell;
436 LyXAlignment alignment;
438 VAlignment valignment;
452 string align_special;
454 LyXLength p_width; // this is only set for multicolumn!!!
459 typedef std::vector<cellstruct> cell_vector;
461 typedef std::vector<cell_vector> cell_vvector;
475 /// This are for longtabulars only
478 /// a row of endfirsthead
482 /// row of endlastfoot
484 /// row for a pagebreak
488 typedef std::vector<rowstruct> row_vector;
491 struct columnstruct {
495 LyXAlignment alignment;
497 VAlignment valignment;
507 string align_special;
510 typedef std::vector<columnstruct> column_vector;
513 void ReadNew(Buffer const * buf, std::istream & is,
514 LyXLex & lex, string const & l, int const version);
516 void ReadOld(Buffer const * buf, std::istream & is,
517 LyXLex & lex, string const & l);
525 std::vector<int> rowofcell;
527 std::vector<int> columnofcell;
531 column_vector column_info;
533 mutable cell_vvector cell_info;
535 int width_of_tabular;
541 bool is_long_tabular;
544 /// endfirsthead data
552 InsetTabular * owner_;
555 void Init(int columns_arg, int rows_arg, LyXTabular const * lt = 0);
557 void Reinit(bool reset_widths = true);
559 void set_row_column_number_info(bool oldformat = false);
560 /// Returns true if a complete update is necessary, otherwise false
561 bool SetWidthOfMulticolCell(int cell, int new_width);
563 void recalculateMulticolCells(int cell, int new_width);
564 /// Returns true if change
565 bool calculate_width_of_column(int column);
567 bool calculate_width_of_column_NMC(int column); // no multi cells
569 void calculate_width_of_tabular();
571 cellstruct * cellinfo_of_cell(int cell) const;
573 void delete_column(int column);
575 int cells_in_multicolumn(int cell) const;
577 BoxType UseParbox(int cell) const;
579 void setHeaderFooterRows(int header, int fheader, int footer, int lfooter);