IWORKTable.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /*
00003  * This file is part of the libetonyek project.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  */
00009 
00010 #ifndef IWORKTABLE_H_INCLUDED
00011 #define IWORKTABLE_H_INCLUDED
00012 
00013 #include <boost/optional.hpp>
00014 #include <boost/shared_ptr.hpp>
00015 
00016 #include <deque>
00017 
00018 #include "IWORKStyle_fwd.h"
00019 #include "IWORKTypes.h"
00020 #include "IWORKOutputElements.h"
00021 
00022 namespace libetonyek
00023 {
00024 
00025 class IWORKText;
00026 class IWORKTableRecorder;
00027 
00028 class IWORKTable
00029 {
00030   struct Cell
00031   {
00032     IWORKOutputElements m_content;
00033     unsigned m_columnSpan;
00034     unsigned m_rowSpan;
00035     bool m_covered;
00036     boost::optional<IWORKFormula> m_formula;
00037     IWORKStylePtr_t m_style;
00038     IWORKCellType m_type;
00039     boost::optional<std::string> m_value;
00040 
00041     Cell();
00042   };
00043 
00044   typedef std::deque<Cell> Row_t;
00045   typedef std::deque<Row_t> Table_t;
00046 
00047 public:
00048   enum CellType
00049   {
00050     CELL_TYPE_BODY,
00051     CELL_TYPE_ALTERNATE_BODY,
00052     CELL_TYPE_COLUMN_HEADER,
00053     CELL_TYPE_ROW_HEADER,
00054     CELL_TYPE_ROW_FOOTER
00055   };
00056 
00057 public:
00058   explicit IWORKTable(const IWORKTableNameMapPtr_t &tableNameMap);
00059 
00060   void setRecorder(const boost::shared_ptr<IWORKTableRecorder> &recorder);
00061   const boost::shared_ptr<IWORKTableRecorder> &getRecorder() const;
00062 
00063   void setSize(unsigned columns, unsigned rows);
00064   void setHeaders(unsigned headerColumns, unsigned headerRows, unsigned footerRows);
00065   void setBandedRows(bool banded = true);
00066   void setRepeated(bool columns, bool rows);
00067 
00068   void setStyle(const IWORKStylePtr_t &style);
00069   void setSizes(const IWORKColumnSizes_t &columnSizes, const IWORKRowSizes_t &rowSizes);
00070   void setBorders(const IWORKGridLineList_t &verticalLines, const IWORKGridLineList_t &horizontalLines);
00071   void insertCell(unsigned column, unsigned row,
00072                   const boost::optional<std::string> &value = boost::none,
00073                   const boost::shared_ptr<IWORKText> &text = boost::shared_ptr<IWORKText>(),
00074                   unsigned columnSpan = 1, unsigned rowSpan = 1,
00075                   const boost::optional<IWORKFormula> &formula = boost::none,
00076                   const IWORKStylePtr_t &style = IWORKStylePtr_t(),
00077                   IWORKCellType type = IWORK_CELL_TYPE_TEXT);
00078   void insertCoveredCell(unsigned column, unsigned row);
00079 
00080   void draw(const librevenge::RVNGPropertyList &tableProps, IWORKOutputElements &elements);
00081 
00082   void setDefaultCellStyle(CellType type, const IWORKStylePtr_t &style);
00083   void setDefaultLayoutStyle(CellType type, const IWORKStylePtr_t &style);
00084   void setDefaultParagraphStyle(CellType type, const IWORKStylePtr_t &style);
00085 
00086   IWORKStylePtr_t getDefaultCellStyle(unsigned column, unsigned row) const;
00087   IWORKStylePtr_t getDefaultLayoutStyle(unsigned column, unsigned row) const;
00088   IWORKStylePtr_t getDefaultParagraphStyle(unsigned column, unsigned row) const;
00089 
00090 private:
00091   IWORKStylePtr_t getDefaultStyle(unsigned column, unsigned row, const IWORKStylePtr_t *group) const;
00092 
00093 private:
00094   const IWORKTableNameMapPtr_t m_tableNameMap;
00095 
00096   Table_t m_table;
00097   IWORKStylePtr_t m_style;
00098   IWORKColumnSizes_t m_columnSizes;
00099   IWORKRowSizes_t m_rowSizes;
00100   IWORKGridLineList_t m_verticalLines;
00101   IWORKGridLineList_t m_horizontalLines;
00102 
00103   unsigned m_rows;
00104   unsigned m_columns;
00105   unsigned m_headerRows;
00106   unsigned m_footerRows;
00107   unsigned m_headerColumns;
00108   bool m_bandedRows;
00109   bool m_headerRowsRepeated;
00110   bool m_headerColumnsRepeated;
00111 
00112   IWORKStylePtr_t m_defaultCellStyles[5];
00113   IWORKStylePtr_t m_defaultLayoutStyles[5];
00114   IWORKStylePtr_t m_defaultParaStyles[5];
00115 
00116   boost::shared_ptr<IWORKTableRecorder> m_recorder;
00117 };
00118 
00119 }
00120 
00121 #endif // IWORKTABLE_H_INCLUDED
00122 
00123 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */