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"
31 /* The features the text class offers for tables */
103 UNSET_ROTATE_TABULAR,
136 CELL_BEGIN_OF_MULTICOLUMN,
138 CELL_PART_OF_MULTICOLUMN
146 LYX_VALIGN_BOTTOM = 1,
148 LYX_VALIGN_CENTER = 2
163 // row of the header/footer type end definition
165 // double borders on top
167 // double borders on bottom
171 typedef struct lttype ltType;
175 LyXTabular(InsetTabular *, int columns_arg, int rows_arg);
177 LyXTabular(InsetTabular *, LyXTabular const &, bool same_id = false);
180 LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
182 LyXTabular & operator=(LyXTabular const &);
184 LyXTabular * clone(InsetTabular *, bool same_id = false);
186 /// Returns true if there is a topline, returns false if not
187 bool TopLine(int cell, bool onlycolumn = false) const;
188 /// Returns true if there is a topline, returns false if not
189 bool BottomLine(int cell, bool onlycolumn = false) const;
190 /// Returns true if there is a topline, returns false if not
191 bool LeftLine(int cell, bool onlycolumn = false) const;
192 /// Returns true if there is a topline, returns false if not
193 bool RightLine(int cell, bool onlycolumn = false) const;
196 bool TopAlreadyDrawed(int cell) const;
198 bool LeftAlreadyDrawed(int cell) const;
200 bool IsLastRow(int cell) const;
203 int GetAdditionalHeight(int row) const;
205 int GetAdditionalWidth(int cell) const;
207 /* returns the maximum over all rows */
209 int GetWidthOfColumn(int cell) const;
211 int GetWidthOfTabular() const;
213 int GetAscentOfRow(int row) const;
215 int GetDescentOfRow(int row) const;
217 int GetHeightOfTabular() const;
218 /// Returns true if a complete update is necessary, otherwise false
219 bool SetAscentOfRow(int row, int height);
220 /// Returns true if a complete update is necessary, otherwise false
221 bool SetDescentOfRow(int row, int height);
222 /// Returns true if a complete update is necessary, otherwise false
223 bool SetWidthOfCell(int cell, int new_width);
224 /// Returns true if a complete update is necessary, otherwise false
225 bool SetAllLines(int cell, bool line);
226 /// Returns true if a complete update is necessary, otherwise false
227 bool SetTopLine(int cell, bool line, bool onlycolumn = false);
228 /// Returns true if a complete update is necessary, otherwise false
229 bool SetBottomLine(int cell, bool line, bool onlycolumn = false);
230 /// Returns true if a complete update is necessary, otherwise false
231 bool SetLeftLine(int cell, bool line, bool onlycolumn = false);
232 /// Returns true if a complete update is necessary, otherwise false
233 bool SetRightLine(int cell, bool line, bool onlycolumn = false);
234 /// Returns true if a complete update is necessary, otherwise false
235 bool SetAlignment(int cell, LyXAlignment align,
236 bool onlycolumn = false);
237 /// Returns true if a complete update is necessary, otherwise false
238 bool SetVAlignment(int cell, VAlignment align,
239 bool onlycolumn = false);
241 bool SetColumnPWidth(int cell, string const & width);
243 bool SetMColumnPWidth(int cell, string const & width);
245 bool SetAlignSpecial(int cell, string const & special, Feature what);
247 LyXAlignment GetAlignment(int cell, bool onlycolumn = false) const;
249 VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
251 string const GetPWidth(int cell) const;
253 string const GetColumnPWidth(int cell) const;
255 string const GetMColumnPWidth(int cell) const;
257 string const GetAlignSpecial(int cell, int what) const;
259 int GetWidthOfCell(int cell) const;
261 int GetBeginningOfTextInCell(int cell) const;
263 void AppendRow(int cell);
265 void DeleteRow(int row);
267 void AppendColumn(int cell);
269 void DeleteColumn(int column);
271 bool IsFirstCellInRow(int cell) const;
273 int GetFirstCellInRow(int row) const;
275 bool IsLastCellInRow(int cell) const;
277 int GetLastCellInRow(int row) const;
279 int GetNumberOfCells() const;
281 int NumberOfCellsInRow(int cell) const;
283 void Write(Buffer const *, std::ostream &) const;
285 void Read(Buffer const *, LyXLex &);
287 void OldFormatRead(LyXLex &, string const &);
289 // helper function for Latex returns number of newlines
291 int TeXTopHLine(std::ostream &, int row) const;
293 int TeXBottomHLine(std::ostream &, int row) const;
295 int TeXCellPreamble(std::ostream &, int cell) const;
297 int TeXCellPostamble(std::ostream &, int cell) const;
299 int Latex(Buffer const *, std::ostream &, bool, bool) const;
300 /// auxiliary function for docbook rows
301 int docbookRow(Buffer const * buf, std::ostream & os, int row) const;
303 int DocBook(Buffer const * buf, std::ostream & os) const;
305 // helper function for Latex returns number of newlines
307 int AsciiTopHLine(std::ostream &, int row,
308 std::vector<unsigned int> const &) const;
310 int AsciiBottomHLine(std::ostream &, int row,
311 std::vector<unsigned int> const &) const;
313 int AsciiPrintCell(Buffer const *, std::ostream &,
314 int cell, int row, int column,
315 std::vector<unsigned int> const &) const;
317 int Ascii(Buffer const *, std::ostream &) const;
319 bool IsMultiColumn(int cell, bool real = false) const;
321 void SetMultiColumn(int cell, int number);
323 int UnsetMultiColumn(int cell); // returns number of new cells
325 bool IsPartOfMultiColumn(int row, int column) const;
327 int row_of_cell(int cell) const;
329 int column_of_cell(int cell) const;
331 int right_column_of_cell(int cell) const;
333 void SetLongTabular(bool);
335 bool IsLongTabular() const;
337 void SetRotateTabular(bool);
339 bool GetRotateTabular() const;
341 void SetRotateCell(int cell, bool);
343 bool GetRotateCell(int cell) const;
345 bool NeedRotating() const;
347 bool IsLastCell(int cell) const;
349 int GetCellAbove(int cell) const;
351 int GetCellBelow(int cell) const;
353 int GetLastCellAbove(int cell) const;
355 int GetLastCellBelow(int cell) const;
357 int GetCellNumber(int row, int column) const;
359 void SetUsebox(int cell, BoxType);
361 BoxType GetUsebox(int cell) const;
363 // Long Tabular Options
365 bool checkLTType(int row, ltType const &) const;
367 void SetLTHead(ltType const &, bool first);
369 bool GetRowOfLTHead(int row, ltType &) const;
371 bool GetRowOfLTFirstHead(int row, ltType &) const;
373 void SetLTFoot(ltType const &, bool last);
375 bool GetRowOfLTFoot(int row, ltType &) const;
377 bool GetRowOfLTLastFoot(int row, ltType &) const;
379 void SetLTNewPage(int cell, bool what);
381 bool GetLTNewPage(int cell) const;
383 InsetText * GetCellInset(int cell) const;
385 InsetText * GetCellInset(int row, int column) 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;
413 LyXAlignment alignment;
415 VAlignment valignment;
429 string align_special;
431 string 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
456 typedef std::vector<rowstruct> row_vector;
459 struct columnstruct {
463 LyXAlignment alignment;
465 VAlignment valignment;
475 string align_special;
478 typedef std::vector<columnstruct> column_vector;
481 void ReadNew(Buffer const * buf, std::istream & is,
482 LyXLex & lex, string const & l);
484 void ReadOld(Buffer const * buf, std::istream & is,
485 LyXLex & lex, string const & l);
493 std::vector<int> rowofcell;
495 std::vector<int> columnofcell;
499 column_vector column_info;
501 mutable cell_vvector cell_info;
503 int width_of_tabular;
509 bool is_long_tabular;
512 /// row of endfirsthead
516 /// row of endlastfoot
519 InsetTabular * owner_;
522 void Init(int columns_arg, int rows_arg, LyXTabular const * lt = 0);
524 void Reinit(bool reset_widths = true);
526 void set_row_column_number_info(bool oldformat = false);
527 /// Returns true if a complete update is necessary, otherwise false
528 bool SetWidthOfMulticolCell(int cell, int new_width);
530 void recalculateMulticolCells(int cell, int new_width);
531 /// Returns true if change
532 bool calculate_width_of_column(int column);
534 bool calculate_width_of_column_NMC(int column); // no multi cells
536 void calculate_width_of_tabular();
538 cellstruct * cellinfo_of_cell(int cell) const;
540 void delete_column(int column);
542 int cells_in_multicolumn(int cell) const;
544 BoxType UseParbox(int cell) const;