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 // double borders on top
166 // double borders on bottom
168 // used for FirstHeader & LastFooter and if this is true
173 typedef struct lttype ltType;
177 LyXTabular(InsetTabular *, int columns_arg, int rows_arg);
179 LyXTabular(InsetTabular *, LyXTabular const &, bool same_id = false);
182 LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
184 LyXTabular & operator=(LyXTabular const &);
186 LyXTabular * clone(InsetTabular *, bool same_id = false);
188 /// Returns true if there is a topline, returns false if not
189 bool TopLine(int cell, bool onlycolumn = false) const;
190 /// Returns true if there is a topline, returns false if not
191 bool BottomLine(int cell, bool onlycolumn = false) const;
192 /// Returns true if there is a topline, returns false if not
193 bool LeftLine(int cell, bool onlycolumn = false) const;
194 /// Returns true if there is a topline, returns false if not
195 bool RightLine(int cell, bool onlycolumn = false) const;
198 bool TopAlreadyDrawed(int cell) const;
200 bool LeftAlreadyDrawed(int cell) const;
202 bool IsLastRow(int cell) const;
205 int GetAdditionalHeight(int row) const;
207 int GetAdditionalWidth(int cell) const;
209 /* returns the maximum over all rows */
211 int GetWidthOfColumn(int cell) const;
213 int GetWidthOfTabular() const;
215 int GetAscentOfRow(int row) const;
217 int GetDescentOfRow(int row) const;
219 int GetHeightOfTabular() const;
220 /// Returns true if a complete update is necessary, otherwise false
221 bool SetAscentOfRow(int row, int height);
222 /// Returns true if a complete update is necessary, otherwise false
223 bool SetDescentOfRow(int row, int height);
224 /// Returns true if a complete update is necessary, otherwise false
225 bool SetWidthOfCell(int cell, int new_width);
226 /// Returns true if a complete update is necessary, otherwise false
227 bool SetAllLines(int cell, bool line);
228 /// Returns true if a complete update is necessary, otherwise false
229 bool SetTopLine(int cell, bool line, bool onlycolumn = false);
230 /// Returns true if a complete update is necessary, otherwise false
231 bool SetBottomLine(int cell, bool line, bool onlycolumn = false);
232 /// Returns true if a complete update is necessary, otherwise false
233 bool SetLeftLine(int cell, bool line, bool onlycolumn = false);
234 /// Returns true if a complete update is necessary, otherwise false
235 bool SetRightLine(int cell, bool line, bool onlycolumn = false);
236 /// Returns true if a complete update is necessary, otherwise false
237 bool SetAlignment(int cell, LyXAlignment align,
238 bool onlycolumn = false);
239 /// Returns true if a complete update is necessary, otherwise false
240 bool SetVAlignment(int cell, VAlignment align,
241 bool onlycolumn = false);
243 bool SetColumnPWidth(int cell, LyXLength const & width);
245 bool SetMColumnPWidth(int cell, LyXLength const & width);
247 bool SetAlignSpecial(int cell, string const & special, Feature what);
249 LyXAlignment GetAlignment(int cell, bool onlycolumn = false) const;
251 VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
253 LyXLength const GetPWidth(int cell) const;
255 LyXLength const GetColumnPWidth(int cell) const;
257 LyXLength const GetMColumnPWidth(int cell) const;
259 string const GetAlignSpecial(int cell, int what) const;
261 int GetWidthOfCell(int cell) const;
263 int GetBeginningOfTextInCell(int cell) const;
265 void AppendRow(int cell);
267 void DeleteRow(int row);
269 void AppendColumn(int cell);
271 void DeleteColumn(int column);
273 bool IsFirstCellInRow(int cell) const;
275 int GetFirstCellInRow(int row) const;
277 bool IsLastCellInRow(int cell) const;
279 int GetLastCellInRow(int row) const;
281 int GetNumberOfCells() const;
283 int NumberOfCellsInRow(int cell) const;
285 void Write(Buffer const *, std::ostream &) const;
287 void Read(Buffer const *, LyXLex &);
289 void OldFormatRead(LyXLex &, string const &);
291 // helper function for Latex returns number of newlines
293 int TeXTopHLine(std::ostream &, int row) const;
295 int TeXBottomHLine(std::ostream &, int row) const;
297 int TeXCellPreamble(std::ostream &, int cell) const;
299 int TeXCellPostamble(std::ostream &, int cell) const;
301 int Latex(Buffer const *, std::ostream &, bool, bool) const;
302 /// auxiliary function for docbook rows
303 int docbookRow(Buffer const * buf, std::ostream & os, int row) const;
305 int DocBook(Buffer const * buf, std::ostream & os) const;
307 // helper function for Latex returns number of newlines
309 int AsciiTopHLine(std::ostream &, int row,
310 std::vector<unsigned int> const &) const;
312 int AsciiBottomHLine(std::ostream &, int row,
313 std::vector<unsigned int> const &) const;
315 int AsciiPrintCell(Buffer const *, std::ostream &,
316 int cell, int row, int column,
317 std::vector<unsigned int> const &) const;
319 int Ascii(Buffer const *, std::ostream &) const;
321 bool IsMultiColumn(int cell, bool real = false) const;
323 void SetMultiColumn(int cell, int number);
325 int UnsetMultiColumn(int cell); // returns number of new cells
327 bool IsPartOfMultiColumn(int row, int column) const;
329 int row_of_cell(int cell) const;
331 int column_of_cell(int cell) const;
333 int right_column_of_cell(int cell) const;
335 void SetLongTabular(bool);
337 bool IsLongTabular() const;
339 void SetRotateTabular(bool);
341 bool GetRotateTabular() const;
343 void SetRotateCell(int cell, bool);
345 bool GetRotateCell(int cell) const;
347 bool NeedRotating() const;
349 bool IsLastCell(int cell) const;
351 int GetCellAbove(int cell) const;
353 int GetCellBelow(int cell) const;
355 int GetLastCellAbove(int cell) const;
357 int GetLastCellBelow(int cell) const;
359 int GetCellNumber(int row, int column) const;
361 void SetUsebox(int cell, BoxType);
363 BoxType GetUsebox(int cell) const;
365 // Long Tabular Options
367 bool checkLTType(int row, ltType const &) const;
369 void SetLTHead(int row, bool flag, ltType const &, bool first);
371 bool GetRowOfLTHead(int row, ltType &) const;
373 bool GetRowOfLTFirstHead(int row, ltType &) const;
375 void SetLTFoot(int row, bool flag, ltType const &, bool last);
377 bool GetRowOfLTFoot(int row, ltType &) const;
379 bool GetRowOfLTLastFoot(int row, ltType &) const;
381 void SetLTNewPage(int row, bool what);
383 bool GetLTNewPage(int row) const;
385 InsetText * GetCellInset(int cell) const;
387 InsetText * GetCellInset(int row, int column) 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;
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(int columns_arg, int rows_arg, LyXTabular const * lt = 0);
536 void Reinit(bool reset_widths = true);
538 void set_row_column_number_info(bool oldformat = false);
539 /// Returns true if a complete update is necessary, otherwise false
540 bool SetWidthOfMulticolCell(int cell, int new_width);
542 void recalculateMulticolCells(int cell, int new_width);
543 /// Returns true if change
544 bool calculate_width_of_column(int column);
546 bool calculate_width_of_column_NMC(int column); // no multi cells
548 void calculate_width_of_tabular();
550 cellstruct * cellinfo_of_cell(int cell) const;
552 void delete_column(int column);
554 int cells_in_multicolumn(int cell) const;
556 BoxType UseParbox(int cell) const;