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);
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 cell) 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, bool onlycolumn = false);
218 /// Returns true if a complete update is necessary, otherwise false
219 bool SetVAlignment(int cell, VAlignment align, bool onlycolumn = false);
221 bool SetColumnPWidth(int cell, string const & width);
223 bool SetMColumnPWidth(int cell, string const & width);
225 bool SetAlignSpecial(int cell, string const & special, Feature what);
227 LyXAlignment GetAlignment(int cell, bool onlycolumn = false) const;
229 VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
231 string const GetPWidth(int cell) const;
233 string const GetColumnPWidth(int cell) const;
235 string const GetMColumnPWidth(int cell) const;
237 string const GetAlignSpecial(int cell, int what) const;
239 int GetWidthOfCell(int cell) const;
241 int GetBeginningOfTextInCell(int cell) const;
243 void AppendRow(int cell);
245 void DeleteRow(int row);
247 void AppendColumn(int cell);
249 void DeleteColumn(int column);
251 bool IsFirstCellInRow(int cell) const;
253 int GetFirstCellInRow(int row) const;
255 bool IsLastCellInRow(int cell) const;
257 int GetLastCellInRow(int row) const;
259 int GetNumberOfCells() const;
261 int NumberOfCellsInRow(int cell) const;
263 void Write(Buffer const *, std::ostream &) const;
265 void Read(Buffer const *, LyXLex &);
267 void OldFormatRead(LyXLex &, string const &);
269 // helper function for Latex returns number of newlines
271 int TeXTopHLine(std::ostream &, int row) const;
273 int TeXBottomHLine(std::ostream &, int row) const;
275 int TeXCellPreamble(std::ostream &, int cell) const;
277 int TeXCellPostamble(std::ostream &, int cell) const;
279 int Latex(Buffer const *, std::ostream &, bool, bool) const;
281 int DocBook(Buffer const * buf, std::ostream & os) const;
283 // helper function for Latex returns number of newlines
285 int AsciiTopHLine(std::ostream &, int row,
286 std::vector<unsigned int> const &) const;
288 int AsciiBottomHLine(std::ostream &, int row,
289 std::vector<unsigned int> const &) const;
291 int AsciiPrintCell(Buffer const *, std::ostream &, int cell, int row,
292 int column, std::vector<unsigned int> const &) const;
294 int Ascii(Buffer const *, std::ostream &) const;
296 bool IsMultiColumn(int cell, bool real = false) const;
298 void SetMultiColumn(int cell, int number);
300 int UnsetMultiColumn(int cell); // returns number of new cells
302 bool IsPartOfMultiColumn(int row, int column) const;
304 int row_of_cell(int cell) const;
306 int column_of_cell(int cell) const;
308 int right_column_of_cell(int cell) const;
310 void SetLongTabular(bool);
312 bool IsLongTabular() const;
314 void SetRotateTabular(bool);
316 bool GetRotateTabular() const;
318 void SetRotateCell(int cell, bool);
320 bool GetRotateCell(int cell) const;
322 bool NeedRotating() const;
324 bool IsLastCell(int cell) const;
326 int GetCellAbove(int cell) const;
328 int GetCellBelow(int cell) const;
330 int GetLastCellAbove(int cell) const;
332 int GetLastCellBelow(int cell) const;
334 int GetCellNumber(int row, int column) const;
336 void SetUsebox(int cell, BoxType);
338 BoxType GetUsebox(int cell) const;
340 // Long Tabular Options
342 void SetLTHead(int cell, bool first);
344 bool GetRowOfLTHead(int cell, int & row) const;
346 bool GetRowOfLTFirstHead(int cell, int & row) const;
348 void SetLTFoot(int cell, bool last);
350 bool GetRowOfLTFoot(int cell, int & row) const;
352 bool GetRowOfLTLastFoot(int cell, int & row) const;
354 void SetLTNewPage(int cell, bool what);
356 bool GetLTNewPage(int cell) const;
358 InsetText * GetCellInset(int cell) const;
360 InsetText * GetCellInset(int row, int column) const;
362 int rows() const { return rows_; }
364 int columns() const { return columns_;}
366 InsetTabular * owner() const { return owner_; }
368 void Validate(LaTeXFeatures &) const;
370 private: //////////////////////////////////////////////////////////////////
382 LyXAlignment alignment;
384 VAlignment valignment;
398 string align_special;
400 string p_width; // this is only set for multicolumn!!!
405 typedef std::vector<cellstruct> cell_vector;
407 typedef std::vector<cell_vector> cell_vvector;
421 /// This are for longtabulars only
425 typedef std::vector<rowstruct> row_vector;
428 struct columnstruct {
432 LyXAlignment alignment;
434 VAlignment valignment;
444 string align_special;
447 typedef std::vector<columnstruct> column_vector;
450 void ReadNew(Buffer const * buf, std::istream & is,
451 LyXLex & lex, string const & l);
453 void ReadOld(Buffer const * buf, std::istream & is,
454 LyXLex & lex, string const & l);
462 std::vector<int> rowofcell;
464 std::vector<int> columnofcell;
468 column_vector column_info;
470 mutable cell_vvector cell_info;
472 int width_of_tabular;
478 bool is_long_tabular;
481 /// row of endfirsthead
485 /// row of endlastfoot
488 InsetTabular * owner_;
491 void Init(int columns_arg, int rows_arg);
495 void set_row_column_number_info(bool oldformat = false);
496 /// Returns true if a complete update is necessary, otherwise false
497 bool SetWidthOfMulticolCell(int cell, int new_width);
499 void recalculateMulticolCells(int cell, int new_width);
500 /// Returns true if change
501 bool calculate_width_of_column(int column);
503 bool calculate_width_of_column_NMC(int column); // no multi cells
505 void calculate_width_of_tabular();
507 cellstruct * cellinfo_of_cell(int cell) const;
509 void delete_column(int column);
511 int cells_in_multicolumn(int cell) const;
513 BoxType UseParbox(int cell) const;