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 row) const;
188 int GetAdditionalWidth(int cell) const;
190 /* returns the maximum over all rows */
192 int GetWidthOfColumn(int cell) const;
194 int GetWidthOfTabular() const;
196 int GetAscentOfRow(int row) const;
198 int GetDescentOfRow(int row) const;
200 int GetHeightOfTabular() const;
201 /// Returns true if a complete update is necessary, otherwise false
202 bool SetAscentOfRow(int row, int height);
203 /// Returns true if a complete update is necessary, otherwise false
204 bool SetDescentOfRow(int row, int height);
205 /// Returns true if a complete update is necessary, otherwise false
206 bool SetWidthOfCell(int cell, int new_width);
207 /// Returns true if a complete update is necessary, otherwise false
208 bool SetAllLines(int cell, bool line);
209 /// Returns true if a complete update is necessary, otherwise false
210 bool SetTopLine(int cell, bool line, bool onlycolumn = false);
211 /// Returns true if a complete update is necessary, otherwise false
212 bool SetBottomLine(int cell, bool line, bool onlycolumn = false);
213 /// Returns true if a complete update is necessary, otherwise false
214 bool SetLeftLine(int cell, bool line, bool onlycolumn = false);
215 /// Returns true if a complete update is necessary, otherwise false
216 bool SetRightLine(int cell, bool line, bool onlycolumn = false);
217 /// Returns true if a complete update is necessary, otherwise false
218 bool SetAlignment(int cell, LyXAlignment align,
219 bool onlycolumn = false);
220 /// Returns true if a complete update is necessary, otherwise false
221 bool SetVAlignment(int cell, VAlignment align,
222 bool onlycolumn = false);
224 bool SetColumnPWidth(int cell, string const & width);
226 bool SetMColumnPWidth(int cell, string const & width);
228 bool SetAlignSpecial(int cell, string const & special, Feature what);
230 LyXAlignment GetAlignment(int cell, bool onlycolumn = false) const;
232 VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
234 string const GetPWidth(int cell) const;
236 string const GetColumnPWidth(int cell) const;
238 string const GetMColumnPWidth(int cell) const;
240 string const GetAlignSpecial(int cell, int what) const;
242 int GetWidthOfCell(int cell) const;
244 int GetBeginningOfTextInCell(int cell) const;
246 void AppendRow(int cell);
248 void DeleteRow(int row);
250 void AppendColumn(int cell);
252 void DeleteColumn(int column);
254 bool IsFirstCellInRow(int cell) const;
256 int GetFirstCellInRow(int row) const;
258 bool IsLastCellInRow(int cell) const;
260 int GetLastCellInRow(int row) const;
262 int GetNumberOfCells() const;
264 int NumberOfCellsInRow(int cell) const;
266 void Write(Buffer const *, std::ostream &) const;
268 void Read(Buffer const *, LyXLex &);
270 void OldFormatRead(LyXLex &, string const &);
272 // helper function for Latex returns number of newlines
274 int TeXTopHLine(std::ostream &, int row) const;
276 int TeXBottomHLine(std::ostream &, int row) const;
278 int TeXCellPreamble(std::ostream &, int cell) const;
280 int TeXCellPostamble(std::ostream &, int cell) const;
282 int Latex(Buffer const *, std::ostream &, bool, bool) const;
284 int DocBook(Buffer const * buf, std::ostream & os) const;
286 // helper function for Latex returns number of newlines
288 int AsciiTopHLine(std::ostream &, int row,
289 std::vector<unsigned int> const &) const;
291 int AsciiBottomHLine(std::ostream &, int row,
292 std::vector<unsigned int> const &) const;
294 int AsciiPrintCell(Buffer const *, std::ostream &,
295 int cell, int row, int column,
296 std::vector<unsigned int> const &) const;
298 int Ascii(Buffer const *, std::ostream &) const;
300 bool IsMultiColumn(int cell, bool real = false) const;
302 void SetMultiColumn(int cell, int number);
304 int UnsetMultiColumn(int cell); // returns number of new cells
306 bool IsPartOfMultiColumn(int row, int column) const;
308 int row_of_cell(int cell) const;
310 int column_of_cell(int cell) const;
312 int right_column_of_cell(int cell) const;
314 void SetLongTabular(bool);
316 bool IsLongTabular() const;
318 void SetRotateTabular(bool);
320 bool GetRotateTabular() const;
322 void SetRotateCell(int cell, bool);
324 bool GetRotateCell(int cell) const;
326 bool NeedRotating() const;
328 bool IsLastCell(int cell) const;
330 int GetCellAbove(int cell) const;
332 int GetCellBelow(int cell) const;
334 int GetLastCellAbove(int cell) const;
336 int GetLastCellBelow(int cell) const;
338 int GetCellNumber(int row, int column) const;
340 void SetUsebox(int cell, BoxType);
342 BoxType GetUsebox(int cell) const;
344 // Long Tabular Options
346 void SetLTHead(int cell, bool first);
348 bool GetRowOfLTHead(int cell, int & row) const;
350 bool GetRowOfLTFirstHead(int cell, int & row) const;
352 void SetLTFoot(int cell, bool last);
354 bool GetRowOfLTFoot(int cell, int & row) const;
356 bool GetRowOfLTLastFoot(int cell, int & row) const;
358 void SetLTNewPage(int cell, bool what);
360 bool GetLTNewPage(int cell) const;
362 InsetText * GetCellInset(int cell) const;
364 InsetText * GetCellInset(int row, int column) const;
366 int rows() const { return rows_; }
368 int columns() const { return columns_;}
370 InsetTabular * owner() const { return owner_; }
372 void Validate(LaTeXFeatures &) const;
374 std::vector<string> const getLabelList() const;
387 LyXAlignment alignment;
389 VAlignment valignment;
403 string align_special;
405 string p_width; // this is only set for multicolumn!!!
410 typedef std::vector<cellstruct> cell_vector;
412 typedef std::vector<cell_vector> cell_vvector;
426 /// This are for longtabulars only
430 typedef std::vector<rowstruct> row_vector;
433 struct columnstruct {
437 LyXAlignment alignment;
439 VAlignment valignment;
449 string align_special;
452 typedef std::vector<columnstruct> column_vector;
455 void ReadNew(Buffer const * buf, std::istream & is,
456 LyXLex & lex, string const & l);
458 void ReadOld(Buffer const * buf, std::istream & is,
459 LyXLex & lex, string const & l);
467 std::vector<int> rowofcell;
469 std::vector<int> columnofcell;
473 column_vector column_info;
475 mutable cell_vvector cell_info;
477 int width_of_tabular;
483 bool is_long_tabular;
486 /// row of endfirsthead
490 /// row of endlastfoot
493 InsetTabular * owner_;
496 void Init(int columns_arg, int rows_arg, LyXTabular const * lt = 0);
500 void set_row_column_number_info(bool oldformat = false);
501 /// Returns true if a complete update is necessary, otherwise false
502 bool SetWidthOfMulticolCell(int cell, int new_width);
504 void recalculateMulticolCells(int cell, int new_width);
505 /// Returns true if change
506 bool calculate_width_of_column(int column);
508 bool calculate_width_of_column_NMC(int column); // no multi cells
510 void calculate_width_of_tabular();
512 cellstruct * cellinfo_of_cell(int cell) const;
514 void delete_column(int column);
516 int cells_in_multicolumn(int cell) const;
518 BoxType UseParbox(int cell) const;