LCOV - code coverage report
Current view: top level - sw/source/filter/ww8 - WW8TableInfo.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 4 21 19.0 %
Date: 2014-04-11 Functions: 2 13 15.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_SW_SOURCE_FILTER_WW8_WW8TABLEINFO_HXX
      21             : #define INCLUDED_SW_SOURCE_FILTER_WW8_WW8TABLEINFO_HXX
      22             : #include <boost/unordered_map.hpp>
      23             : #include <string>
      24             : #include <map>
      25             : #include <set>
      26             : #include <functional>
      27             : #include <boost/shared_ptr.hpp>
      28             : #include <vector>
      29             : #include <sal/types.h>
      30             : #include <swrect.hxx>
      31             : 
      32             : class SwTable;
      33             : class SwTableLine;
      34             : class SwTableBox;
      35             : class SwNode;
      36             : class AttributeOutputBase;
      37             : 
      38             : namespace ww8
      39             : {
      40             : using namespace ::std;
      41             : 
      42             : const unsigned int MAXTABLECELLS = 63;
      43             : 
      44             : class WW8TableNodeInfo;
      45             : typedef boost::shared_ptr<SwRect> SwRectPtr;
      46             : typedef ::std::vector<const SwTableBox *> TableBoxVector;
      47             : typedef boost::shared_ptr<TableBoxVector> TableBoxVectorPtr;
      48             : typedef ::std::vector<sal_uInt32> GridCols;
      49             : typedef boost::shared_ptr<GridCols> GridColsPtr;
      50             : typedef ::std::vector<sal_uInt32> RowSpans;
      51             : typedef boost::shared_ptr<RowSpans> RowSpansPtr;
      52             : typedef ::std::vector<sal_uInt32> Widths;
      53             : typedef boost::shared_ptr<Widths> WidthsPtr;
      54             : 
      55             : class WW8TableNodeInfoInner
      56             : {
      57             :     WW8TableNodeInfo * mpParent;
      58             :     sal_uInt32 mnDepth;
      59             :     sal_uInt32 mnCell;
      60             :     sal_uInt32 mnRow;
      61             :     sal_uInt32 mnShadowsBefore;
      62             :     sal_uInt32 mnShadowsAfter;
      63             :     bool mbEndOfLine;
      64             :     bool mbEndOfCell;
      65             :     bool mbFirstInTable;
      66             :     bool mbVertMerge;
      67             :     const SwTableBox * mpTableBox;
      68             :     const SwTable * mpTable;
      69             :     SwRect maRect;
      70             : 
      71             : public:
      72             :     typedef boost::shared_ptr<WW8TableNodeInfoInner> Pointer_t;
      73             : 
      74             :     WW8TableNodeInfoInner(WW8TableNodeInfo * pParent);
      75             :     ~WW8TableNodeInfoInner();
      76             : 
      77             :     void setDepth(sal_uInt32 nDepth);
      78             :     void setCell(sal_uInt32 nCell);
      79             :     void setRow(sal_uInt32 nRow);
      80             :     void setShadowsBefore(sal_uInt32 nShadowsBefore);
      81             :     void setShadowsAfter(sal_uInt32 nShadowsAfter);
      82             :     void setEndOfLine(bool bEndOfLine);
      83             :     void setEndOfCell(bool bEndOfCell);
      84             :     void setFirstInTable(bool bFirstInTable);
      85             :     void setVertMerge(bool bVertMErge);
      86             :     void setTableBox(const SwTableBox * pTableBox);
      87             :     void setTable(const SwTable * pTable);
      88             :     void setRect(const SwRect & rRect);
      89             : 
      90             :     sal_uInt32 getDepth() const;
      91             :     sal_uInt32 getCell() const;
      92             :     sal_uInt32 getRow() const;
      93             :     sal_uInt32 getShadowsBefore() const;
      94             :     sal_uInt32 getShadowsAfter() const;
      95             :     bool isEndOfCell() const;
      96             :     bool isEndOfLine() const;
      97             :     bool isFirstInTable() const;
      98             :     bool isVertMerge() const;
      99             :     const SwTableBox * getTableBox() const;
     100             :     const SwTable * getTable() const;
     101             :     const SwRect & getRect() const;
     102             : 
     103             :     const SwNode * getNode() const;
     104             : 
     105             :     TableBoxVectorPtr getTableBoxesOfRow();
     106             :     WidthsPtr getWidthsOfRow();
     107             :     WidthsPtr getColumnWidthsBasedOnAllRows();
     108             :     GridColsPtr getGridColsOfRow(AttributeOutputBase & rBase, bool calculateColumnsFromAllRows = false);
     109             :     RowSpansPtr getRowSpansOfRow();
     110             : 
     111             : #ifdef DBG_UTIL
     112             :     ::std::string toString() const;
     113             : #endif
     114             : };
     115             : 
     116             : class CellInfo
     117             : {
     118             :     SwRect m_aRect;
     119             :     WW8TableNodeInfo * m_pNodeInfo;
     120             :     unsigned long m_nFmtFrmWidth;
     121             : 
     122             : public:
     123             :     CellInfo(const SwRect & aRect, WW8TableNodeInfo * pNodeInfo);
     124             : 
     125           0 :     CellInfo(const CellInfo & aRectAndTableInfo)
     126             :         : m_aRect(aRectAndTableInfo.m_aRect),
     127             :           m_pNodeInfo(aRectAndTableInfo.m_pNodeInfo),
     128           0 :           m_nFmtFrmWidth(aRectAndTableInfo.m_nFmtFrmWidth)
     129             :     {
     130           0 :     }
     131             : 
     132           0 :     ~CellInfo() {}
     133             : 
     134             :     bool operator < (const CellInfo & aCellInfo) const;
     135             : 
     136           0 :     long top() const { return m_aRect.Top(); }
     137           0 :     long bottom() const { return m_aRect.Bottom(); }
     138           0 :     long left() const { return m_aRect.Left(); }
     139             :     long right() const { return m_aRect.Right(); }
     140           0 :     long width() const { return m_aRect.Width(); }
     141           0 :     long height() const { return m_aRect.Height(); }
     142           0 :     SwRect getRect() const { return m_aRect; }
     143           0 :     WW8TableNodeInfo * getTableNodeInfo() const
     144           0 :     { return m_pNodeInfo; }
     145           0 :     unsigned long getFmtFrmWidth() const
     146             :     {
     147           0 :         return m_nFmtFrmWidth;
     148             :     }
     149             : 
     150           0 :     void setFmtFrmWidth(unsigned long nFmtFrmWidth)
     151             :     {
     152           0 :         m_nFmtFrmWidth = nFmtFrmWidth;
     153           0 :     }
     154             : 
     155             : #ifdef DBG_UTIL
     156             :     ::std::string toString() const;
     157             : #endif
     158             : };
     159             : 
     160             : typedef ::std::multiset<CellInfo, less<CellInfo> > CellInfoMultiSet;
     161             : typedef boost::shared_ptr<CellInfoMultiSet> CellInfoMultiSetPtr;
     162             : 
     163             : class WW8TableInfo;
     164             : class WW8TableNodeInfo
     165             : {
     166             : public:
     167             :     typedef map<sal_uInt32, WW8TableNodeInfoInner::Pointer_t,
     168             :                 greater<sal_uInt32> > Inners_t;
     169             : 
     170             : private:
     171             :     WW8TableInfo * mpParent;
     172             :     sal_uInt32 mnDepth;
     173             :     const SwNode * mpNode;
     174             :     Inners_t mInners;
     175             :     WW8TableNodeInfo * mpNext;
     176             :     const SwNode * mpNextNode;
     177             : 
     178             : public:
     179             :     typedef boost::shared_ptr<WW8TableNodeInfo> Pointer_t;
     180             : 
     181             :     WW8TableNodeInfo(WW8TableInfo * pParent, const SwNode * pTxtNode);
     182             :     virtual ~WW8TableNodeInfo();
     183             : 
     184             :     void setDepth(sal_uInt32 nDepth);
     185             :     void setEndOfLine(bool bEndOfLine);
     186             :     void setEndOfCell(bool bEndOfCell);
     187             :     void setFirstInTable(bool bFirstInTable);
     188             :     void setVertMerge(bool bVertMerge);
     189             :     void setTableBox(const SwTableBox *pTableBox);
     190             :     void setTable(const SwTable * pTable);
     191             :     void setCell(sal_uInt32 nCell);
     192             :     void setRow(sal_uInt32 nRow);
     193             :     void setShadowsBefore(sal_uInt32 nShadowsBefore);
     194             :     void setShadowsAfter(sal_uInt32 nShadowsAfter);
     195             :     void setNext(WW8TableNodeInfo * pNext);
     196             :     void setNextNode(const SwNode * pNode);
     197             :     void setRect(const SwRect & rRect);
     198             : 
     199             :     WW8TableInfo * getParent() const;
     200             :     sal_uInt32 getDepth() const;
     201             :     bool isEndOfLine() const;
     202             :     bool isEndOfCell() const;
     203             :     bool isFirstInTable() const;
     204             :     const SwNode * getNode() const;
     205             :     const SwTableBox * getTableBox() const;
     206             :     WW8TableNodeInfo * getNext() const;
     207             :     const SwNode * getNextNode() const;
     208             :     const SwRect & getRect() const;
     209             : 
     210             :     const Inners_t & getInners() const;
     211             :     const WW8TableNodeInfoInner::Pointer_t getFirstInner() const;
     212             :     const WW8TableNodeInfoInner::Pointer_t getInnerForDepth(sal_uInt32 nDepth) const;
     213             : 
     214             :     sal_uInt32 getCell() const;
     215             :     sal_uInt32 getRow() const;
     216             : 
     217             : #ifdef DBG_UTIL
     218             :     ::std::string toString() const;
     219             : #endif
     220             : 
     221             :     bool operator < (const WW8TableNodeInfo & rInfo) const;
     222             : };
     223             : 
     224             : struct hashNode
     225             : {
     226       31122 :     size_t operator()(const SwNode * pNode) const
     227       31122 :     { return reinterpret_cast<size_t>(pNode); }
     228             : };
     229             : 
     230             : struct hashTable
     231             : {
     232        4671 :     size_t operator()(const SwTable * pTable) const
     233        4671 :     { return reinterpret_cast<size_t>(pTable); }
     234             : };
     235             : 
     236             : class WW8TableCellGridRow
     237             : {
     238             :     CellInfoMultiSetPtr m_pCellInfos;
     239             :     TableBoxVectorPtr m_pTableBoxVector;
     240             :     WidthsPtr m_pWidths;
     241             :     RowSpansPtr m_pRowSpans;
     242             : 
     243             : public:
     244             :     typedef boost::shared_ptr<WW8TableCellGridRow> Pointer_t;
     245             :     WW8TableCellGridRow();
     246             :     ~WW8TableCellGridRow();
     247             : 
     248             :     void insert(const CellInfo & rCellInfo);
     249             :     CellInfoMultiSet::const_iterator begin() const;
     250             :     CellInfoMultiSet::const_iterator end() const;
     251             : 
     252             :     void setTableBoxVector(TableBoxVectorPtr pTableBoxVector);
     253             :     void setWidths(WidthsPtr pGridCols);
     254             :     void setRowSpans(RowSpansPtr pRowSpans);
     255             : 
     256             :     TableBoxVectorPtr getTableBoxVector() const;
     257             :     WidthsPtr getWidths() const;
     258             :     RowSpansPtr getRowSpans() const;
     259             : };
     260             : 
     261             : class WW8TableCellGrid
     262             : {
     263             :     typedef ::std::set<long> RowTops_t;
     264             :     typedef ::std::map<long, WW8TableCellGridRow::Pointer_t> Rows_t;
     265             : 
     266             :     RowTops_t m_aRowTops;
     267             :     Rows_t m_aRows;
     268             : 
     269             :     WW8TableCellGridRow::Pointer_t getRow(long nTop, bool bCreate = true);
     270             :     RowTops_t::const_iterator getRowTopsBegin() const;
     271             :     RowTops_t::const_iterator getRowTopsEnd() const;
     272             :     CellInfoMultiSet::const_iterator getCellsBegin(long nTop);
     273             :     CellInfoMultiSet::const_iterator getCellsEnd(long nTop);
     274             : 
     275             : public:
     276             :     typedef ::boost::shared_ptr<WW8TableCellGrid> Pointer_t;
     277             : 
     278             :     WW8TableCellGrid();
     279             :     ~WW8TableCellGrid();
     280             : 
     281             :     void insert(const SwRect & rRect, WW8TableNodeInfo * pNodeInfo,
     282             :                 unsigned long * pFmtFrmWidth = NULL);
     283             :     void addShadowCells();
     284             :     WW8TableNodeInfo * connectCells();
     285             : 
     286             : #ifdef DBG_UTIL
     287             :     ::std::string toString();
     288             : #endif
     289             : 
     290             :     TableBoxVectorPtr getTableBoxesOfRow(WW8TableNodeInfoInner * pNodeInfo);
     291             :     WidthsPtr getWidthsOfRow(WW8TableNodeInfoInner * pNodeInfo);
     292             :     RowSpansPtr getRowSpansOfRow(WW8TableNodeInfoInner * pNodeInfo);
     293             : };
     294             : 
     295             : class WW8TableInfo
     296             : {
     297             :     friend class WW8TableNodeInfoInner;
     298             :     typedef boost::unordered_map<const SwNode *, WW8TableNodeInfo::Pointer_t, hashNode > Map_t;
     299             :     Map_t mMap;
     300             : 
     301             :     typedef boost::unordered_map<const SwTable *, WW8TableCellGrid::Pointer_t, hashTable > CellGridMap_t;
     302             :     CellGridMap_t mCellGridMap;
     303             : 
     304             :     typedef boost::unordered_map<const SwTable *, const SwNode *, hashTable > FirstInTableMap_t;
     305             :     FirstInTableMap_t mFirstInTableMap;
     306             : 
     307             :     WW8TableNodeInfo *
     308             :     processTableLine(const SwTable * pTable,
     309             :                      const SwTableLine * pTableLine,
     310             :                      sal_uInt32 nRow,
     311             :                      sal_uInt32 nDepth, WW8TableNodeInfo * pPrev);
     312             : 
     313             :     WW8TableNodeInfo *
     314             :     processTableBox(const SwTable * pTable,
     315             :                     const SwTableBox * pTableBox,
     316             :                     sal_uInt32 nRow,
     317             :                     sal_uInt32 nCell,
     318             :                     sal_uInt32 nDepth, bool bEndOfLine, WW8TableNodeInfo * pPrev);
     319             : 
     320             :     WW8TableNodeInfo::Pointer_t
     321             :     processTableBoxLines(const SwTableBox * pBox,
     322             :                          const SwTable * pTable,
     323             :                          const SwTableBox * pBoxToSet,
     324             :                          sal_uInt32 nRow,
     325             :                          sal_uInt32 nCell,
     326             :                          sal_uInt32 nDepth);
     327             : 
     328             :     WW8TableNodeInfo::Pointer_t
     329             :     insertTableNodeInfo(const SwNode * pNode,
     330             :                         const SwTable * pTable,
     331             :                         const SwTableBox * pTableBox,
     332             :                         sal_uInt32 nRow,
     333             :                         sal_uInt32 nCell,
     334             :                         sal_uInt32 nDepth,
     335             :                         SwRect * pRect = NULL);
     336             : 
     337             :     WW8TableCellGrid::Pointer_t getCellGridForTable(const SwTable * pTable,
     338             :                                                     bool bCreate = true);
     339             : 
     340             : public:
     341             :     typedef boost::shared_ptr<WW8TableInfo> Pointer_t;
     342             : 
     343             :     WW8TableInfo();
     344             :     virtual ~WW8TableInfo();
     345             : 
     346             :     void processSwTable(const SwTable * pTable);
     347             :     WW8TableNodeInfo * processSwTableByLayout(const SwTable * pTable);
     348             :     WW8TableNodeInfo::Pointer_t getTableNodeInfo(const SwNode * pNode);
     349             :     const SwNode * getNextNode(const SwNode * pNode);
     350             :     const WW8TableNodeInfo * getFirstTableNodeInfo() const;
     351             : 
     352             :     WW8TableNodeInfo * reorderByLayout(const SwTable * pTable);
     353             : };
     354             : 
     355             : }
     356             : #endif // INCLUDED_SW_SOURCE_FILTER_WW8_WW8TABLEINFO_HXX
     357             : 
     358             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10