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 * ====================================================== */
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);
164 LyXTabular & operator=(LyXTabular const &);
166 LyXTabular * clone(InsetTabular *);
168 /// Returns true if there is a topline, returns false if not
169 bool TopLine(int cell, bool onlycolumn = false) const;
170 /// Returns true if there is a topline, returns false if not
171 bool BottomLine(int cell, bool onlycolumn = false) const;
172 /// Returns true if there is a topline, returns false if not
173 bool LeftLine(int cell, bool onlycolumn = false) const;
174 /// Returns true if there is a topline, returns false if not
175 bool RightLine(int cell, bool onlycolumn = false) const;
178 bool TopAlreadyDrawed(int cell) const;
180 bool LeftAlreadyDrawed(int cell) const;
182 bool IsLastRow(int cell) const;
185 int GetAdditionalHeight(int row) const;
187 int GetAdditionalWidth(int cell) const;
189 /* returns the maximum over all rows */
191 int GetWidthOfColumn(int cell) const;
193 int GetWidthOfTabular() const;
195 int GetAscentOfRow(int row) const;
197 int GetDescentOfRow(int row) const;
199 int GetHeightOfTabular() const;
200 /// Returns true if a complete update is necessary, otherwise false
201 bool SetAscentOfRow(int row, int height);
202 /// Returns true if a complete update is necessary, otherwise false
203 bool SetDescentOfRow(int row, int height);
204 /// Returns true if a complete update is necessary, otherwise false
205 bool SetWidthOfCell(int cell, int new_width);
206 /// Returns true if a complete update is necessary, otherwise false
207 bool SetAllLines(int cell, bool line);
208 /// Returns true if a complete update is necessary, otherwise false
209 bool SetTopLine(int cell, bool line, bool onlycolumn = false);
210 /// Returns true if a complete update is necessary, otherwise false
211 bool SetBottomLine(int cell, bool line, bool onlycolumn = false);
212 /// Returns true if a complete update is necessary, otherwise false
213 bool SetLeftLine(int cell, bool line, bool onlycolumn = false);
214 /// Returns true if a complete update is necessary, otherwise false
215 bool SetRightLine(int cell, bool line, bool onlycolumn = false);
216 /// Returns true if a complete update is necessary, otherwise false
217 bool SetAlignment(int cell, LyXAlignment align,
218 bool onlycolumn = false);
219 /// Returns true if a complete update is necessary, otherwise false
220 bool SetVAlignment(int cell, VAlignment align,
221 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 &,
294 int cell, int row, int column,
295 std::vector<unsigned int> const &) const;
297 int Ascii(Buffer const *, std::ostream &) const;
299 bool IsMultiColumn(int cell, bool real = false) const;
301 void SetMultiColumn(int cell, int number);
303 int UnsetMultiColumn(int cell); // returns number of new cells
305 bool IsPartOfMultiColumn(int row, int column) const;
307 int row_of_cell(int cell) const;
309 int column_of_cell(int cell) const;
311 int right_column_of_cell(int cell) const;
313 void SetLongTabular(bool);
315 bool IsLongTabular() const;
317 void SetRotateTabular(bool);
319 bool GetRotateTabular() const;
321 void SetRotateCell(int cell, bool);
323 bool GetRotateCell(int cell) const;
325 bool NeedRotating() const;
327 bool IsLastCell(int cell) const;
329 int GetCellAbove(int cell) const;
331 int GetCellBelow(int cell) const;
333 int GetLastCellAbove(int cell) const;
335 int GetLastCellBelow(int cell) const;
337 int GetCellNumber(int row, int column) const;
339 void SetUsebox(int cell, BoxType);
341 BoxType GetUsebox(int cell) const;
343 // Long Tabular Options
345 void SetLTHead(int cell, bool first);
347 bool GetRowOfLTHead(int cell, int & row) const;
349 bool GetRowOfLTFirstHead(int cell, int & row) const;
351 void SetLTFoot(int cell, bool last);
353 bool GetRowOfLTFoot(int cell, int & row) const;
355 bool GetRowOfLTLastFoot(int cell, int & row) const;
357 void SetLTNewPage(int cell, bool what);
359 bool GetLTNewPage(int cell) const;
361 InsetText * GetCellInset(int cell) const;
363 InsetText * GetCellInset(int row, int column) const;
365 int rows() const { return rows_; }
367 int columns() const { return columns_;}
369 InsetTabular * owner() const { return owner_; }
371 void Validate(LaTeXFeatures &) const;
373 std::vector<string> const getLabelList() const;
375 mutable int cur_cell;
388 LyXAlignment alignment;
390 VAlignment valignment;
404 string align_special;
406 string p_width; // this is only set for multicolumn!!!
411 typedef std::vector<cellstruct> cell_vector;
413 typedef std::vector<cell_vector> cell_vvector;
427 /// This are for longtabulars only
431 typedef std::vector<rowstruct> row_vector;
434 struct columnstruct {
438 LyXAlignment alignment;
440 VAlignment valignment;
450 string align_special;
453 typedef std::vector<columnstruct> column_vector;
456 void ReadNew(Buffer const * buf, std::istream & is,
457 LyXLex & lex, string const & l);
459 void ReadOld(Buffer const * buf, std::istream & is,
460 LyXLex & lex, string const & l);
468 std::vector<int> rowofcell;
470 std::vector<int> columnofcell;
474 column_vector column_info;
476 mutable cell_vvector cell_info;
478 int width_of_tabular;
484 bool is_long_tabular;
487 /// row of endfirsthead
491 /// row of endlastfoot
494 InsetTabular * owner_;
497 void Init(int columns_arg, int rows_arg, LyXTabular const * lt = 0);
501 void set_row_column_number_info(bool oldformat = false);
502 /// Returns true if a complete update is necessary, otherwise false
503 bool SetWidthOfMulticolCell(int cell, int new_width);
505 void recalculateMulticolCells(int cell, int new_width);
506 /// Returns true if change
507 bool calculate_width_of_column(int column);
509 bool calculate_width_of_column_NMC(int column); // no multi cells
511 void calculate_width_of_tabular();
513 cellstruct * cellinfo_of_cell(int cell) const;
515 void delete_column(int column);
517 int cells_in_multicolumn(int cell) const;
519 BoxType UseParbox(int cell) const;