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 * ====================================================== */
25 #include "insets/insettext.h"
26 #include "lyxlength.h"
32 /* The features the text class offers for tables */
104 UNSET_ROTATE_TABULAR,
137 CELL_BEGIN_OF_MULTICOLUMN,
139 CELL_PART_OF_MULTICOLUMN
147 LYX_VALIGN_BOTTOM = 1,
149 LYX_VALIGN_CENTER = 2
164 // row of the header/footer type end definition
166 // double borders on top
168 // double borders on bottom
170 // used for FirstHeader & LastFooter and if this is true
175 typedef struct lttype ltType;
179 LyXTabular(InsetTabular *, int columns_arg, int rows_arg);
181 LyXTabular(InsetTabular *, LyXTabular const &, bool same_id = false);
184 LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
186 LyXTabular & operator=(LyXTabular const &);
188 LyXTabular * clone(InsetTabular *, bool same_id = false);
190 /// Returns true if there is a topline, returns false if not
191 bool TopLine(int cell, bool onlycolumn = false) const;
192 /// Returns true if there is a topline, returns false if not
193 bool BottomLine(int cell, bool onlycolumn = false) const;
194 /// Returns true if there is a topline, returns false if not
195 bool LeftLine(int cell, bool onlycolumn = false) const;
196 /// Returns true if there is a topline, returns false if not
197 bool RightLine(int cell, bool onlycolumn = false) const;
200 bool TopAlreadyDrawed(int cell) const;
202 bool LeftAlreadyDrawed(int cell) const;
204 bool IsLastRow(int cell) const;
207 int GetAdditionalHeight(int row) const;
209 int GetAdditionalWidth(int cell) const;
211 /* returns the maximum over all rows */
213 int GetWidthOfColumn(int cell) const;
215 int GetWidthOfTabular() const;
217 int GetAscentOfRow(int row) const;
219 int GetDescentOfRow(int row) const;
221 int GetHeightOfTabular() const;
222 /// Returns true if a complete update is necessary, otherwise false
223 bool SetAscentOfRow(int row, int height);
224 /// Returns true if a complete update is necessary, otherwise false
225 bool SetDescentOfRow(int row, int height);
226 /// Returns true if a complete update is necessary, otherwise false
227 bool SetWidthOfCell(int cell, int new_width);
228 /// Returns true if a complete update is necessary, otherwise false
229 bool SetAllLines(int cell, bool line);
230 /// Returns true if a complete update is necessary, otherwise false
231 bool SetTopLine(int cell, bool line, bool onlycolumn = false);
232 /// Returns true if a complete update is necessary, otherwise false
233 bool SetBottomLine(int cell, bool line, bool onlycolumn = false);
234 /// Returns true if a complete update is necessary, otherwise false
235 bool SetLeftLine(int cell, bool line, bool onlycolumn = false);
236 /// Returns true if a complete update is necessary, otherwise false
237 bool SetRightLine(int cell, bool line, bool onlycolumn = false);
238 /// Returns true if a complete update is necessary, otherwise false
239 bool SetAlignment(int cell, LyXAlignment align,
240 bool onlycolumn = false);
241 /// Returns true if a complete update is necessary, otherwise false
242 bool SetVAlignment(int cell, VAlignment align,
243 bool onlycolumn = false);
245 bool SetColumnPWidth(int cell, LyXLength const & width);
247 bool SetMColumnPWidth(int cell, LyXLength const & width);
249 bool SetAlignSpecial(int cell, string const & special, Feature what);
251 LyXAlignment GetAlignment(int cell, bool onlycolumn = false) const;
253 VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
255 LyXLength const GetPWidth(int cell) const;
257 LyXLength const GetColumnPWidth(int cell) const;
259 LyXLength const GetMColumnPWidth(int cell) const;
261 string const GetAlignSpecial(int cell, int what) const;
263 int GetWidthOfCell(int cell) const;
265 int GetBeginningOfTextInCell(int cell) const;
267 void AppendRow(int cell);
269 void DeleteRow(int row);
271 void AppendColumn(int cell);
273 void DeleteColumn(int column);
275 bool IsFirstCellInRow(int cell) const;
277 int GetFirstCellInRow(int row) const;
279 bool IsLastCellInRow(int cell) const;
281 int GetLastCellInRow(int row) const;
283 int GetNumberOfCells() const;
285 int NumberOfCellsInRow(int cell) const;
287 void Write(Buffer const *, std::ostream &) const;
289 void Read(Buffer const *, LyXLex &);
291 void OldFormatRead(LyXLex &, string const &);
293 // helper function for Latex returns number of newlines
295 int TeXTopHLine(std::ostream &, int row) const;
297 int TeXBottomHLine(std::ostream &, int row) const;
299 int TeXCellPreamble(std::ostream &, int cell) const;
301 int TeXCellPostamble(std::ostream &, int cell) const;
303 int Latex(Buffer const *, std::ostream &, bool, bool) const;
304 /// auxiliary function for docbook rows
305 int docbookRow(Buffer const * buf, std::ostream & os, int row) const;
307 int DocBook(Buffer const * buf, std::ostream & os) const;
309 // helper function for Latex returns number of newlines
311 int AsciiTopHLine(std::ostream &, int row,
312 std::vector<unsigned int> const &) const;
314 int AsciiBottomHLine(std::ostream &, int row,
315 std::vector<unsigned int> const &) const;
317 int AsciiPrintCell(Buffer const *, std::ostream &,
318 int cell, int row, int column,
319 std::vector<unsigned int> const &) const;
321 int Ascii(Buffer const *, std::ostream &) const;
323 bool IsMultiColumn(int cell, bool real = false) const;
325 void SetMultiColumn(int cell, int number);
327 int UnsetMultiColumn(int cell); // returns number of new cells
329 bool IsPartOfMultiColumn(int row, int column) const;
331 int row_of_cell(int cell) const;
333 int column_of_cell(int cell) const;
335 int right_column_of_cell(int cell) const;
337 void SetLongTabular(bool);
339 bool IsLongTabular() const;
341 void SetRotateTabular(bool);
343 bool GetRotateTabular() const;
345 void SetRotateCell(int cell, bool);
347 bool GetRotateCell(int cell) const;
349 bool NeedRotating() const;
351 bool IsLastCell(int cell) const;
353 int GetCellAbove(int cell) const;
355 int GetCellBelow(int cell) const;
357 int GetLastCellAbove(int cell) const;
359 int GetLastCellBelow(int cell) const;
361 int GetCellNumber(int row, int column) const;
363 void SetUsebox(int cell, BoxType);
365 BoxType GetUsebox(int cell) const;
367 // Long Tabular Options
369 bool checkLTType(int row, ltType const &) const;
371 void SetLTHead(ltType const &, bool first);
373 bool GetRowOfLTHead(int row, ltType &) const;
375 bool GetRowOfLTFirstHead(int row, ltType &) const;
377 void SetLTFoot(ltType const &, bool last);
379 bool GetRowOfLTFoot(int row, ltType &) const;
381 bool GetRowOfLTLastFoot(int row, ltType &) const;
383 void SetLTNewPage(int row, bool what);
385 bool GetLTNewPage(int row) const;
387 InsetText * GetCellInset(int cell) const;
389 InsetText * GetCellInset(int row, int column) const;
391 int rows() const { return rows_; }
393 int columns() const { return columns_;}
395 InsetTabular * owner() const { return owner_; }
397 void Validate(LaTeXFeatures &) const;
399 std::vector<string> const getLabelList() const;
401 /// recalculate the widths/heights only!
404 mutable int cur_cell;
417 LyXAlignment alignment;
419 VAlignment valignment;
433 string align_special;
435 LyXLength p_width; // this is only set for multicolumn!!!
440 typedef std::vector<cellstruct> cell_vector;
442 typedef std::vector<cell_vector> cell_vvector;
456 /// This are for longtabulars only
460 typedef std::vector<rowstruct> row_vector;
463 struct columnstruct {
467 LyXAlignment alignment;
469 VAlignment valignment;
479 string align_special;
482 typedef std::vector<columnstruct> column_vector;
485 void ReadNew(Buffer const * buf, std::istream & is,
486 LyXLex & lex, string const & l);
488 void ReadOld(Buffer const * buf, std::istream & is,
489 LyXLex & lex, string const & l);
497 std::vector<int> rowofcell;
499 std::vector<int> columnofcell;
503 column_vector column_info;
505 mutable cell_vvector cell_info;
507 int width_of_tabular;
513 bool is_long_tabular;
516 /// row of endfirsthead
520 /// row of endlastfoot
523 InsetTabular * owner_;
526 void Init(int columns_arg, int rows_arg, LyXTabular const * lt = 0);
528 void Reinit(bool reset_widths = true);
530 void set_row_column_number_info(bool oldformat = false);
531 /// Returns true if a complete update is necessary, otherwise false
532 bool SetWidthOfMulticolCell(int cell, int new_width);
534 void recalculateMulticolCells(int cell, int new_width);
535 /// Returns true if change
536 bool calculate_width_of_column(int column);
538 bool calculate_width_of_column_NMC(int column); // no multi cells
540 void calculate_width_of_tabular();
542 cellstruct * cellinfo_of_cell(int cell) const;
544 void delete_column(int column);
546 int cells_in_multicolumn(int cell) const;
548 BoxType UseParbox(int cell) const;