2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000 The LyX Team.
9 * @author: Jürgen Vigna
11 * ====================================================== */
24 #include "insets/insettext.h"
30 /* The features the text class offers for tables */
102 UNSET_ROTATE_TABULAR,
131 CELL_BEGIN_OF_MULTICOLUMN,
133 CELL_PART_OF_MULTICOLUMN
141 LYX_VALIGN_BOTTOM = 1,
143 LYX_VALIGN_CENTER = 2
157 LyXTabular(InsetTabular *, int columns_arg, int rows_arg);
159 LyXTabular(InsetTabular *, LyXTabular const &);
162 LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
166 LyXTabular & operator=(LyXTabular const &);
168 LyXTabular * Clone(InsetTabular *);
170 /// Returns true if there is a topline, returns false if not
171 bool TopLine(int cell, bool onlycolumn = false) const;
172 /// Returns true if there is a topline, returns false if not
173 bool BottomLine(int cell, bool onlycolumn = false) const;
174 /// Returns true if there is a topline, returns false if not
175 bool LeftLine(int cell, bool onlycolumn = false) const;
176 /// Returns true if there is a topline, returns false if not
177 bool RightLine(int cell, bool onlycolumn = false) const;
180 bool TopAlreadyDrawed(int cell) const;
182 bool LeftAlreadyDrawed(int cell) const;
184 bool IsLastRow(int cell) const;
187 int GetAdditionalHeight(int cell) const;
189 int GetAdditionalWidth(int cell) const;
191 /* returns the maximum over all rows */
193 int GetWidthOfColumn(int cell) const;
195 int GetWidthOfTabular() const;
197 int GetAscentOfRow(int row) const;
199 int GetDescentOfRow(int row) const;
201 int GetHeightOfTabular() const;
202 /// Returns true if a complete update is necessary, otherwise false
203 bool SetAscentOfRow(int row, int height);
204 /// Returns true if a complete update is necessary, otherwise false
205 bool SetDescentOfRow(int row, int height);
206 /// Returns true if a complete update is necessary, otherwise false
207 bool SetWidthOfCell(int cell, int new_width);
208 /// Returns true if a complete update is necessary, otherwise false
209 bool SetAllLines(int cell, bool line);
210 /// Returns true if a complete update is necessary, otherwise false
211 bool SetTopLine(int cell, bool line, bool onlycolumn=false);
212 /// Returns true if a complete update is necessary, otherwise false
213 bool SetBottomLine(int cell, bool line, bool onlycolumn=false);
214 /// Returns true if a complete update is necessary, otherwise false
215 bool SetLeftLine(int cell, bool line, bool onlycolumn=false);
216 /// Returns true if a complete update is necessary, otherwise false
217 bool SetRightLine(int cell, bool line, bool onlycolumn=false);
218 /// Returns true if a complete update is necessary, otherwise false
219 bool SetAlignment(int cell, LyXAlignment align, bool onlycolumn = false);
220 /// Returns true if a complete update is necessary, otherwise false
221 bool SetVAlignment(int cell, VAlignment align, bool onlycolumn = false);
223 bool SetColumnPWidth(int cell, string const & width);
225 bool SetMColumnPWidth(int cell, string const & width);
227 bool SetAlignSpecial(int cell, string const & special, Feature what);
229 LyXAlignment GetAlignment(int cell, bool onlycolumn = false) const;
231 VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
233 string const GetPWidth(int cell) const;
235 string const GetColumnPWidth(int cell) const;
237 string const GetMColumnPWidth(int cell) const;
239 string const GetAlignSpecial(int cell, int what) const;
241 int GetWidthOfCell(int cell) const;
243 int GetBeginningOfTextInCell(int cell) const;
245 void AppendRow(int cell);
247 void DeleteRow(int row);
249 void AppendColumn(int cell);
251 void DeleteColumn(int column);
253 bool IsFirstCellInRow(int cell) const;
255 int GetFirstCellInRow(int row) const;
257 bool IsLastCellInRow(int cell) const;
259 int GetLastCellInRow(int row) const;
261 int GetNumberOfCells() const;
263 int NumberOfCellsInRow(int cell) const;
265 void Write(Buffer const *, std::ostream &) const;
267 void Read(Buffer const *, LyXLex &);
269 void OldFormatRead(LyXLex &, string const &);
271 // helper function for Latex returns number of newlines
273 int TeXTopHLine(std::ostream &, int row) const;
275 int TeXBottomHLine(std::ostream &, int row) const;
277 int TeXCellPreamble(std::ostream &, int cell) const;
279 int TeXCellPostamble(std::ostream &, int cell) const;
281 int Latex(Buffer const *, std::ostream &, bool, bool) const;
283 int DocBook(Buffer const * buf, std::ostream & os) const;
285 // helper function for Latex returns number of newlines
287 int AsciiTopHLine(std::ostream &, int row,
288 std::vector<unsigned int> const &) const;
290 int AsciiBottomHLine(std::ostream &, int row,
291 std::vector<unsigned int> const &) const;
293 int AsciiPrintCell(Buffer const *, std::ostream &, int cell, int row,
294 int column, std::vector<unsigned int> const &) const;
296 int Ascii(Buffer const *, std::ostream &) const;
298 int DocBookEndOfCell(std::ostream &, int cell, int & depth) const;
301 int RoffEndOfCell(std::ostream &, int cell);
304 string const GetDocBookAlign(int cell, bool isColumn = false) const;
307 bool IsMultiColumn(int cell, bool real = false) const;
309 void SetMultiColumn(int cell, int number);
311 int UnsetMultiColumn(int cell); // returns number of new cells
313 bool IsPartOfMultiColumn(int row, int column) const;
315 int row_of_cell(int cell) const;
317 int column_of_cell(int cell) const;
319 int right_column_of_cell(int cell) const;
321 void SetLongTabular(bool);
323 bool IsLongTabular() const;
325 void SetRotateTabular(bool);
327 bool GetRotateTabular() const;
329 void SetRotateCell(int cell, bool);
331 bool GetRotateCell(int cell) const;
333 bool NeedRotating() const;
335 bool IsLastCell(int cell) const;
337 int GetCellAbove(int cell) const;
339 int GetCellBelow(int cell) const;
341 int GetLastCellAbove(int cell) const;
343 int GetLastCellBelow(int cell) const;
345 int GetCellNumber(int row, int column) const;
347 void SetUsebox(int cell, BoxType);
349 BoxType GetUsebox(int cell) const;
351 // Long Tabular Options
353 void SetLTHead(int cell, bool first);
355 bool GetRowOfLTHead(int cell, int & row) const;
357 bool GetRowOfLTFirstHead(int cell, int & row) const;
359 void SetLTFoot(int cell, bool last);
361 bool GetRowOfLTFoot(int cell, int & row) const;
363 bool GetRowOfLTLastFoot(int cell, int & row) const;
365 void SetLTNewPage(int cell, bool what);
367 bool GetLTNewPage(int cell) const;
369 InsetText * GetCellInset(int cell) const;
371 int rows() const { return rows_; }
373 int columns() const { return columns_;}
375 InsetTabular * owner() const { return owner_; }
377 void Validate(LaTeXFeatures &) const;
379 private: //////////////////////////////////////////////////////////////////
391 LyXAlignment alignment;
393 VAlignment valignment;
407 string align_special;
409 string p_width; // this is only set for multicolumn!!!
414 typedef std::vector<cellstruct> cell_vector;
416 typedef std::vector<cell_vector> cell_vvector;
430 /// This are for longtabulars only
434 typedef std::vector<rowstruct> row_vector;
437 struct columnstruct {
441 LyXAlignment alignment;
443 VAlignment valignment;
453 string align_special;
456 typedef std::vector<columnstruct> column_vector;
471 column_vector column_info;
473 mutable cell_vvector cell_info;
475 int width_of_tabular;
481 bool is_long_tabular;
484 /// row of endfirsthead
488 /// row of endlastfoot
491 InsetTabular * owner_;
494 void Init(int columns_arg, int rows_arg);
498 void set_row_column_number_info(bool oldformat = false);
499 /// Returns true if a complete update is necessary, otherwise false
500 bool SetWidthOfMulticolCell(int cell, int new_width);
502 void recalculateMulticolCells(int cell, int new_width);
503 /// Returns true if change
504 bool calculate_width_of_column(int column);
506 bool calculate_width_of_column_NMC(int column); // no multi cells
508 void calculate_width_of_tabular();
510 cellstruct * cellinfo_of_cell(int cell) const;
512 void delete_column(int column);
514 int cells_in_multicolumn(int cell) const;
516 BoxType UseParbox(int cell) const;