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 */
104 UNSET_ROTATE_TABULAR,
133 CELL_BEGIN_OF_MULTICOLUMN,
135 CELL_PART_OF_MULTICOLUMN
143 LYX_VALIGN_BOTTOM = 1,
145 LYX_VALIGN_CENTER = 2
159 LyXTabular(InsetTabular *, int columns_arg, int rows_arg);
161 LyXTabular(InsetTabular *, LyXTabular const &);
164 LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
168 LyXTabular & operator=(LyXTabular const &);
170 LyXTabular * Clone(InsetTabular *);
172 /// Returns true if there is a topline, returns false if not
173 bool TopLine(int cell, bool onlycolumn=false) const;
174 /// Returns true if there is a topline, returns false if not
175 bool BottomLine(int cell, bool onlycolumn=false) const;
176 /// Returns true if there is a topline, returns false if not
177 bool LeftLine(int cell, bool onlycolumn=false) const;
178 /// Returns true if there is a topline, returns false if not
179 bool RightLine(int cell, bool onlycolumn=false) const;
182 bool TopAlreadyDrawed(int cell) const;
184 bool LeftAlreadyDrawed(int cell) const;
186 bool IsLastRow(int cell) const;
189 int GetAdditionalHeight(int cell) const;
191 int GetAdditionalWidth(int cell) const;
193 /* returns the maximum over all rows */
195 int GetWidthOfColumn(int cell) const;
197 int GetWidthOfTabular() const;
199 int GetAscentOfRow(int row) const;
201 int GetDescentOfRow(int row) const;
203 int GetHeightOfTabular() const;
204 /// Returns true if a complete update is necessary, otherwise false
205 bool SetAscentOfRow(int row, int height);
206 /// Returns true if a complete update is necessary, otherwise false
207 bool SetDescentOfRow(int row, int height);
208 /// Returns true if a complete update is necessary, otherwise false
209 bool SetWidthOfCell(int cell, int new_width);
210 /// Returns true if a complete update is necessary, otherwise false
211 bool SetAllLines(int cell, bool line);
212 /// Returns true if a complete update is necessary, otherwise false
213 bool SetTopLine(int cell, bool line, bool onlycolumn=false);
214 /// Returns true if a complete update is necessary, otherwise false
215 bool SetBottomLine(int cell, bool line, bool onlycolumn=false);
216 /// Returns true if a complete update is necessary, otherwise false
217 bool SetLeftLine(int cell, bool line, bool onlycolumn=false);
218 /// Returns true if a complete update is necessary, otherwise false
219 bool SetRightLine(int cell, bool line, bool onlycolumn=false);
220 /// Returns true if a complete update is necessary, otherwise false
221 bool SetAlignment(int cell, char align, bool onlycolumn = false);
222 /// Returns true if a complete update is necessary, otherwise false
223 bool SetVAlignment(int cell, char align, bool onlycolumn = false);
225 bool SetColumnPWidth(int cell, string const & width);
227 bool SetMColumnPWidth(int cell, string const & width);
229 bool SetAlignSpecial(int cell, string const & special, int what);
231 char GetAlignment(int cell, bool onlycolumn = false) const;
233 char GetVAlignment(int cell, bool onlycolumn = false) const;
235 string const GetPWidth(int cell) const;
237 string const GetColumnPWidth(int cell) const;
239 string const GetMColumnPWidth(int cell) const;
241 string const GetAlignSpecial(int cell, int what) const;
243 int GetWidthOfCell(int cell) const;
245 int GetBeginningOfTextInCell(int cell) const;
247 void AppendRow(int cell);
249 void DeleteRow(int cell);
251 void AppendColumn(int cell);
253 void DeleteColumn(int cell);
255 bool IsFirstCellInRow(int cell) const;
257 int GetFirstCellInRow(int row) const;
259 bool IsLastCellInRow(int cell) const;
261 int GetLastCellInRow(int row) const;
263 int GetNumberOfCells() const;
265 int NumberOfCellsInRow(int cell) const;
267 void Write(Buffer const *, std::ostream &) const;
269 void Read(Buffer const *, LyXLex &);
271 void OldFormatRead(LyXLex &, string const &);
273 // helper function for Latex returns number of newlines
275 int TeXTopHLine(std::ostream &, int row) const;
277 int TeXBottomHLine(std::ostream &, int row) const;
279 int TeXCellPreamble(std::ostream &, int cell) const;
281 int TeXCellPostamble(std::ostream &, int cell) const;
283 int Latex(Buffer const *, std::ostream &, bool, bool) const;
285 int DocBookEndOfCell(std::ostream &, int cell, int & depth) const;
288 int RoffEndOfCell(std::ostream &, int cell);
291 string const GetDocBookAlign(int cell, bool isColumn = false) const;
294 bool IsMultiColumn(int cell, bool real = false) const;
296 void SetMultiColumn(int cell, int number);
298 int UnsetMultiColumn(int cell); // returns number of new cells
300 bool IsPartOfMultiColumn(int row, int column) const;
302 int row_of_cell(int cell) const;
304 int column_of_cell(int cell) const;
306 int right_column_of_cell(int cell) const;
308 void SetLongTabular(int what);
310 bool IsLongTabular() const;
312 void SetRotateTabular(bool);
314 bool GetRotateTabular() const;
316 void SetRotateCell(int cell, bool);
318 bool GetRotateCell(int cell) const;
320 bool NeedRotating() const;
322 bool IsLastCell(int cell) const;
324 int GetCellAbove(int cell) const;
326 int GetCellBelow(int cell) const;
328 int GetLastCellAbove(int cell) const;
330 int GetLastCellBelow(int cell) const;
332 int GetCellNumber(int row, int column) const;
334 void SetUsebox(int cell, BoxType);
336 int GetUsebox(int cell) const;
338 // Long Tabular Options
340 void SetLTHead(int cell, bool first);
342 bool GetRowOfLTHead(int cell, int & row) const;
344 bool GetRowOfLTFirstHead(int cell, int & row) const;
346 void SetLTFoot(int cell, bool last);
348 bool GetRowOfLTFoot(int cell, int & row) const;
350 bool GetRowOfLTLastFoot(int cell, int & row) const;
352 void SetLTNewPage(int cell, bool what);
354 bool GetLTNewPage(int cell) const;
356 InsetText * GetCellInset(int cell) const;
358 int rows() const { return rows_; }
360 int columns() const { return columns_;}
362 InsetTabular * owner() const { return owner_; }
364 void Validate(LaTeXFeatures &) const;
366 private: //////////////////////////////////////////////////////////////////
394 string align_special;
396 string p_width; // this is only set for multicolumn!!!
401 typedef std::vector<cellstruct> cell_vector;
403 typedef std::vector<cell_vector> cell_vvector;
417 /// This are for longtabulars only
421 typedef std::vector<rowstruct> row_vector;
424 struct columnstruct {
440 string align_special;
443 typedef std::vector<columnstruct> column_vector;
458 column_vector column_info;
460 mutable cell_vvector cell_info;
462 int width_of_tabular;
468 bool is_long_tabular;
471 /// row of endfirsthead
475 /// row of endlastfoot
478 InsetTabular * owner_;
481 void Init(int columns_arg, int rows_arg);
485 void set_row_column_number_info();
486 /// Returns true if a complete update is necessary, otherwise false
487 bool SetWidthOfMulticolCell(int cell, int new_width);
489 void recalculateMulticolCells(int cell, int new_width);
490 /// Returns true if change
491 bool calculate_width_of_column(int column);
493 bool calculate_width_of_column_NMC(int column); // no multi cells
495 void calculate_width_of_tabular();
497 cellstruct * cellinfo_of_cell(int cell) const;
499 void delete_column(int column);
501 int cells_in_multicolumn(int cell) const;
503 bool UseParbox(int cell) const;