MWAWTable.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
00002 
00003 /* libmwaw
00004 * Version: MPL 2.0 / LGPLv2+
00005 *
00006 * The contents of this file are subject to the Mozilla Public License Version
00007 * 2.0 (the "License"); you may not use this file except in compliance with
00008 * the License or as specified alternatively below. You may obtain a copy of
00009 * the License at http://www.mozilla.org/MPL/
00010 *
00011 * Software distributed under the License is distributed on an "AS IS" basis,
00012 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013 * for the specific language governing rights and limitations under the
00014 * License.
00015 *
00016 * Major Contributor(s):
00017 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
00018 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
00019 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00020 * Copyright (C) 2006, 2007 Andrew Ziem
00021 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
00022 *
00023 *
00024 * All Rights Reserved.
00025 *
00026 * For minor contributions see the git repository.
00027 *
00028 * Alternatively, the contents of this file may be used under the terms of
00029 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00030 * in which case the provisions of the LGPLv2+ are applicable
00031 * instead of those above.
00032 */
00033 
00034 /*
00035  * Structure to store and construct a table from an unstructured list
00036  * of cell
00037  *
00038  */
00039 
00040 #ifndef MWAW_TABLE
00041 #  define MWAW_TABLE
00042 
00043 #include <iostream>
00044 #include <vector>
00045 
00046 #include "libmwaw_internal.hxx"
00047 
00048 #include "MWAWCell.hxx"
00049 
00051 class MWAWTable
00052 {
00053 public:
00055   enum DataSet {
00056     CellPositionBit=1, BoxBit=2, SizeBit=4, TableDimBit=8, TablePosToCellBit=0x10
00057   };
00061   enum Alignment {
00062     Paragraph, Left, Center, Right
00063   };
00065   MWAWTable(uint32_t givenData=BoxBit) :
00066     m_givenData(givenData), m_setData(givenData), m_mergeBorders(true), m_cellsList(),
00067     m_numRows(0), m_numCols(0), m_rowsSize(), m_colsSize(), m_alignment(Paragraph), m_leftMargin(0), m_rightMargin(0),
00068     m_posToCellId(), m_hasExtraLines(false) {}
00069 
00071   virtual ~MWAWTable();
00072 
00074   void add(shared_ptr<MWAWCell> cell)
00075   {
00076     if (!cell) {
00077       MWAW_DEBUG_MSG(("MWAWTable::add: must be called with a cell\n"));
00078       return;
00079     }
00080     m_cellsList.push_back(cell);
00081   }
00083   bool mergeBorders() const
00084   {
00085     return m_mergeBorders;
00086   }
00088   bool setMergeBorders(bool val)
00089   {
00090     return m_mergeBorders=val;
00091   }
00094   void setAlignment(Alignment align, float leftMargin=0, float rightMargin=0)
00095   {
00096     m_alignment = align;
00097     m_leftMargin = leftMargin;
00098     m_rightMargin = rightMargin;
00099   }
00101   int numCells() const
00102   {
00103     return int(m_cellsList.size());
00104   }
00106   std::vector<float> const &getRowsSize() const
00107   {
00108     return m_rowsSize;
00109   }
00111   void setRowsSize(std::vector<float> const &rSize)
00112   {
00113     m_rowsSize=rSize;
00114   }
00116   std::vector<float> const &getColsSize() const
00117   {
00118     return m_colsSize;
00119   }
00121   void setColsSize(std::vector<float> const &cSize)
00122   {
00123     m_colsSize=cSize;
00124   }
00125 
00127   shared_ptr<MWAWCell> get(int id);
00128 
00130   bool updateTable();
00132   bool hasExtraLines()
00133   {
00134     if (!updateTable()) return false;
00135     return m_hasExtraLines;
00136   }
00137 
00142   bool sendTable(MWAWListenerPtr listener, bool inFrame=true);
00143 
00145   bool sendAsText(MWAWListenerPtr listener);
00146 
00147   // interface with the content listener
00148 
00150   void addTablePropertiesTo(librevenge::RVNGPropertyList &propList) const;
00151 
00152 protected:
00154   int getCellIdPos(int col, int row) const
00155   {
00156     if (col<0||col>=int(m_numCols))
00157       return -1;
00158     if (row<0||row>=int(m_numRows))
00159       return -1;
00160     return col*int(m_numRows)+row;
00161   }
00163   bool buildStructures();
00165   bool buildDims();
00167   bool buildPosToCellId();
00169   void sendExtraLines(MWAWListenerPtr listener) const;
00170 
00171 protected:
00173   uint32_t m_givenData;
00175   uint32_t m_setData;
00177   bool m_mergeBorders;
00179   std::vector<shared_ptr<MWAWCell> > m_cellsList;
00181   size_t m_numRows;
00183   size_t m_numCols;
00185   std::vector<float> m_rowsSize;
00187   std::vector<float> m_colsSize;
00189   Alignment m_alignment;
00191   float m_leftMargin;
00193   float m_rightMargin;
00194 
00196   std::vector<int> m_posToCellId;
00198   bool m_hasExtraLines;
00199 };
00200 
00201 #endif
00202 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: