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