LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/writerfilter/inc/resourcemodel - TableManager.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 269 295 91.2 %
Date: 2013-07-09 Functions: 65 149 43.6 %
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_TABLE_MANAGER_HXX
      21             : #define INCLUDED_TABLE_MANAGER_HXX
      22             : 
      23             : #include <resourcemodel/TableData.hxx>
      24             : 
      25             : #include <resourcemodel/WW8ResourceModel.hxx>
      26             : 
      27             : #include <doctok/sprmids.hxx>
      28             : 
      29             : #include <boost/shared_ptr.hpp>
      30             : #include <stack>
      31             : #include "util.hxx"
      32             : #include "TagLogger.hxx"
      33             : 
      34             : #if OSL_DEBUG_LEVEL > 0
      35             : #   include <rtl/strbuf.hxx>
      36             : #endif
      37             : 
      38             : namespace writerfilter
      39             : {
      40             : 
      41             : using namespace ::std;
      42             : 
      43             : /**
      44             :    Class to handle events generated by TableManager::resolveCurrentTable
      45             :  */
      46             : template <typename T, typename PropertiesPointer>
      47         356 : class TableDataHandler
      48             : {
      49             : public:
      50             :     typedef boost::shared_ptr<TableDataHandler> Pointer_t;
      51             : 
      52             :     /**
      53             :        Handle start of table.
      54             : 
      55             :        @param nRows   number of rows in the table
      56             :        @param nDepth  depth of the table in surrounding table hierarchy
      57             :        @param pProps  properties of the table
      58             :      */
      59             :     virtual void startTable(unsigned int nRows, unsigned int nDepth,
      60             :                             PropertiesPointer pProps) = 0;
      61             : 
      62             :     /**
      63             :        Handle end of table.
      64             :      */
      65             :     virtual void endTable(unsigned int nestedTableLevel) = 0;
      66             : 
      67             :     /**
      68             :        Handle start of row.
      69             : 
      70             :        @param nCols    number of columns in the table
      71             :        @param pProps   properties of the row
      72             :      */
      73             :     virtual void startRow(unsigned int nCols,
      74             :                           PropertiesPointer pProps) = 0;
      75             : 
      76             :     /**
      77             :        Handle end of row.
      78             :     */
      79             :     virtual void endRow() = 0;
      80             : 
      81             :     /**
      82             :        Handle start of cell.
      83             : 
      84             :        @param rT     start handle of the cell
      85             :        @param pProps properties of the cell
      86             :     */
      87             :     virtual void startCell(const T & rT, PropertiesPointer pProps) = 0;
      88             : 
      89             :     /**
      90             :         Handle end of cell.
      91             : 
      92             :         @param rT    end handle of cell
      93             :     */
      94             :     virtual void endCell(const T & rT) = 0;
      95             : 
      96             : protected:
      97         356 :     ~TableDataHandler() {}
      98             : };
      99             : 
     100             : template <typename T, typename PropertiesPointer>
     101             : /**
     102             :    The table manager.
     103             : 
     104             :    This class gets forwarded events from the tokenizer. It gathers the
     105             :    table data and after ending the table generates events for the
     106             :    table structure. The events have to be handles by a TableDataHandler.
     107             : 
     108             :  */
     109             : class TableManager
     110             : {
     111             : #ifdef DEBUG_TABLE
     112             :     TagLogger::Pointer_t mpTableLogger;
     113             : #endif
     114             : 
     115             :     class TableManagerState
     116             :     {
     117             :         /**
     118             :          properties at the current point in document
     119             :          */
     120             :         PropertiesPointer mpProps;
     121             : 
     122             :         /**
     123             :          properties of the current cell
     124             :          */
     125             :         PropertiesPointer mpCellProps;
     126             : 
     127             :         /**
     128             :          properties of the current row
     129             :          */
     130             :         PropertiesPointer mpRowProps;
     131             : 
     132             :         /**
     133             :          properties of the current table
     134             :          */
     135             :         stack<PropertiesPointer> mTableProps;
     136             : 
     137             :         /**
     138             :          true if at the end of a row
     139             :          */
     140             :         bool mbRowEnd;
     141             : 
     142             :         /**
     143             :          true when in a cell
     144             :          */
     145             :         bool mbInCell;
     146             : 
     147             :         /**
     148             :          true when at the end of a cell
     149             :          */
     150             :         bool mbCellEnd;
     151             : 
     152             :     public:
     153             :         /**
     154             :          Constructor
     155             :          */
     156         540 :         TableManagerState()
     157         540 :         : mbRowEnd(false), mbInCell(false), mbCellEnd(false)
     158             :         {
     159         540 :         }
     160             : 
     161         540 :         virtual ~TableManagerState()
     162             :         {
     163         540 :         }
     164             : 
     165         638 :         void startLevel()
     166             :         {
     167         638 :             PropertiesPointer pProps;
     168         638 :             mTableProps.push(pProps);
     169         638 :         }
     170             : 
     171         637 :         void endLevel()
     172             :         {
     173         637 :             mTableProps.pop();
     174         637 :         }
     175             : 
     176             :         /**
     177             :          Reset to initial state at beginning of row.
     178             :          */
     179        2307 :         void resetCellSpecifics()
     180             :         {
     181        2307 :             mbRowEnd = false;
     182        2307 :             mbInCell = false;
     183        2307 :             mbCellEnd = false;
     184        2307 :         }
     185             : 
     186             :         void resetProps()
     187             :         {
     188             :             mpProps.reset();
     189             :         }
     190             : 
     191           0 :         void setProps(PropertiesPointer pProps)
     192             :         {
     193           0 :             mpProps = pProps;
     194           0 :         }
     195             : 
     196             :         PropertiesPointer getProps()
     197             :         {
     198             :             return mpProps;
     199             :         }
     200             : 
     201         946 :         void resetCellProps()
     202             :         {
     203         946 :             mpCellProps.reset();
     204         946 :         }
     205             : 
     206         533 :         void setCellProps(PropertiesPointer pProps)
     207             :         {
     208         533 :             mpCellProps = pProps;
     209         533 :         }
     210             : 
     211        2202 :         PropertiesPointer getCellProps()
     212             :         {
     213        2202 :             return mpCellProps;
     214             :         }
     215             : 
     216         205 :         void resetRowProps()
     217             :         {
     218         205 :             mpRowProps.reset();
     219         205 :         }
     220             : 
     221         191 :         void setRowProps(PropertiesPointer pProps)
     222             :         {
     223         191 :             mpRowProps = pProps;
     224         191 :         }
     225             : 
     226         484 :         PropertiesPointer getRowProps()
     227             :         {
     228         484 :             return mpRowProps;
     229             :         }
     230             : 
     231         637 :         void resetTableProps()
     232             :         {
     233         637 :             if (mTableProps.size() > 0)
     234         637 :                 mTableProps.top().reset();
     235         637 :         }
     236             : 
     237          99 :         void setTableProps(PropertiesPointer pProps)
     238             :         {
     239          99 :             if (mTableProps.size() > 0)
     240          99 :                 mTableProps.top() = pProps;
     241          99 :         }
     242             : 
     243        1054 :         PropertiesPointer getTableProps()
     244             :         {
     245        1054 :             PropertiesPointer pResult;
     246             : 
     247        1054 :             if (mTableProps.size() > 0)
     248        1054 :                 pResult = mTableProps.top();
     249             : 
     250        1054 :             return pResult;
     251             :         }
     252             : 
     253        2052 :         void setInCell(bool bInCell)
     254             :         {
     255        2052 :             mbInCell = bInCell;
     256        2052 :         }
     257             : 
     258         750 :         bool isInCell() const
     259             :         {
     260         750 :             return mbInCell;
     261             :         }
     262             : 
     263        1265 :         void setCellEnd(bool bCellEnd)
     264             :         {
     265        1265 :             mbCellEnd = bCellEnd;
     266        1265 :         }
     267             : 
     268         741 :         bool isCellEnd() const
     269             :         {
     270         741 :             return mbCellEnd;
     271             :         }
     272             : 
     273         747 :         void setRowEnd(bool bRowEnd)
     274             :         {
     275         747 :             mbRowEnd = bRowEnd;
     276         747 :         }
     277             : 
     278        4092 :         bool isRowEnd() const
     279             :         {
     280        4092 :             return mbRowEnd;
     281             :         }
     282             :     };
     283             : 
     284             :     /**
     285             :      handle for the current position in document
     286             :      */
     287             :     T mCurHandle;
     288             : 
     289             :     TableManagerState mState;
     290             : 
     291             : protected:
     292             :     PropertiesPointer getProps()
     293             :     {
     294             :         return mState.getProps();
     295             :     }
     296             : 
     297           0 :     void setProps(PropertiesPointer pProps)
     298             :     {
     299           0 :         mState.setProps(pProps);
     300           0 :     }
     301             : 
     302             :     void resetProps()
     303             :     {
     304             :         mState.resetProps();
     305             :     }
     306             : 
     307        2202 :     PropertiesPointer getCellProps()
     308             :     {
     309        2202 :         return mState.getCellProps();
     310             :     }
     311             : 
     312         533 :     void setCellProps(PropertiesPointer pProps)
     313             :     {
     314         533 :         mState.setCellProps(pProps);
     315         533 :     }
     316             : 
     317         946 :     void resetCellProps()
     318             :     {
     319         946 :         mState.resetCellProps();
     320         946 :     }
     321             : 
     322         484 :     PropertiesPointer getRowProps()
     323             :     {
     324         484 :         return mState.getRowProps();
     325             :     }
     326             : 
     327         191 :     void setRowProps(PropertiesPointer pProps)
     328             :     {
     329         191 :         mState.setRowProps(pProps);
     330         191 :     }
     331             : 
     332         205 :     void resetRowProps()
     333             :     {
     334         205 :         mState.resetRowProps();
     335         205 :     }
     336             : 
     337        2052 :     void setInCell(bool bInCell)
     338             :     {
     339        2052 :         mState.setInCell(bInCell);
     340        2052 :     }
     341             : 
     342         750 :     bool isInCell() const
     343             :     {
     344         750 :         return mState.isInCell();
     345             :     }
     346             : 
     347        1265 :     void setCellEnd(bool bCellEnd)
     348             :     {
     349        1265 :         mState.setCellEnd(bCellEnd);
     350        1265 :     }
     351             : 
     352         741 :     bool isCellEnd() const
     353             :     {
     354         741 :         return mState.isCellEnd();
     355             :     }
     356             : 
     357         747 :     void setRowEnd(bool bRowEnd)
     358             :     {
     359         747 :         mState.setRowEnd(bRowEnd);
     360         747 :     }
     361             : 
     362        4092 :     bool isRowEnd() const
     363             :     {
     364        4092 :         return mState.isRowEnd();
     365             :     }
     366             : 
     367        1054 :     PropertiesPointer getTableProps()
     368             :     {
     369        1054 :         return mState.getTableProps();
     370             :     }
     371             : 
     372          99 :     void setTableProps(PropertiesPointer pProps)
     373             :     {
     374          99 :         mState.setTableProps(pProps);
     375          99 :     }
     376             : 
     377         637 :     void resetTableProps()
     378             :     {
     379         637 :         mState.resetTableProps();
     380         637 :     }
     381             : 
     382        1505 :     T getHandle()
     383             :     {
     384        1505 :         return mCurHandle;
     385             :     }
     386             : 
     387        1605 :     void setHandle(const T & rHandle)
     388             :     {
     389        1605 :         mCurHandle = rHandle;
     390        1605 :     }
     391             : 
     392             : private:
     393             :     typedef boost::shared_ptr<T> T_p;
     394             : 
     395             :     /**
     396             :        depth of the current cell
     397             :     */
     398             :     sal_uInt32 mnTableDepthNew;
     399             : 
     400             :     /**
     401             :         depth of the previous cell
     402             :     */
     403             :     sal_uInt32 mnTableDepth;
     404             : 
     405             :     /**
     406             :        stack of table data
     407             : 
     408             :        for each level of nested tables there is one frame in the stack
     409             :      */
     410             :     stack<typename TableData<T, PropertiesPointer>::Pointer_t > mTableDataStack;
     411             :     typename RowData<T, PropertiesPointer>::Pointer_t mpUnfinishedRow;
     412             :     bool mbKeepUnfinishedRow;
     413             : 
     414             :     typedef typename TableDataHandler<T, PropertiesPointer>::Pointer_t TableDataHandlerPointer_t;
     415             : 
     416             :     /**
     417             :        handler for resolveCurrentTable
     418             :      */
     419             :     TableDataHandlerPointer_t mpTableDataHandler;
     420             : 
     421             :     /**
     422             :        Set flag which indicates the current handle is in a cell.
     423             :      */
     424             :     void inCell();
     425             : 
     426             :     /**
     427             :        Set flag which indicate the current handle is at the end of a cell.
     428             :     */
     429             :     void endCell();
     430             : 
     431             :     /**
     432             :        Set the table depth of the current cell.
     433             : 
     434             :        @param nDepth     the cell depth
     435             :      */
     436             :     void cellDepth(sal_uInt32 nDepth);
     437             : 
     438             :     /**
     439             :        Set flag indication the current handle is at the end of a row.
     440             :     */
     441             :     void endRow();
     442             : 
     443             :     /**
     444             :        Resolve the current table to the TableDataHandler.
     445             :      */
     446             :     void resolveCurrentTable();
     447             : 
     448             :     /**
     449             :      Open a cell at current level.
     450             :      */
     451             : 
     452             :     void openCell(const T & handle, PropertiesPointer pProps);
     453             : 
     454             :     /**
     455             :      Close a cell at current level.
     456             :      */
     457             :     void closeCell(const T & handle);
     458             : 
     459             :     /**
     460             :      Ensure a cell is open at the current level.
     461             :     */
     462             :     void ensureOpenCell(PropertiesPointer pProps);
     463             : 
     464             : protected:
     465             : 
     466             :     /**
     467             :        Return current table depth.
     468             :      */
     469           0 :     sal_uInt32 getTableDepthNew() { return mnTableDepthNew; }
     470             : 
     471             :     /**
     472             :        Return the current table difference, i.e. 1 if we are in the first cell of a new table, etc.
     473             :      */
     474         545 :     sal_uInt32 getTableDepthDifference() { return mnTableDepthNew - mnTableDepth; }
     475             : 
     476             :     /**
     477             :        Action to be carried out at the end of the last paragraph of a
     478             :        cell.
     479             :      */
     480             :     virtual void endOfCellAction();
     481             : 
     482             :     /**
     483             :        Action to be carried out at the end of the "table row"
     484             :        paragraph.
     485             :      */
     486             :     virtual void endOfRowAction();
     487             :     /** let the derived class clear their table related data
     488             :      */
     489             :     virtual void clearData();
     490             : 
     491             :     /** Should we keep the unfinished row in endLevel to initialize the table
     492             :         data in the following startLevel.
     493             :       */
     494           2 :     void setKeepUnfinishedRow(bool bKeep)
     495             :     {
     496           2 :         mbKeepUnfinishedRow = bKeep;
     497           2 :     }
     498             : 
     499             : 
     500             : public:
     501             :     TableManager();
     502         540 :     virtual ~TableManager(){}
     503             : 
     504             :     /**
     505             :        Set handler for resolveCurrentTable.
     506             : 
     507             :        @param pTableDataHandler     the handler
     508             :      */
     509             :     void setHandler(TableDataHandlerPointer_t pTableDataHandler);
     510             : 
     511             :     /**
     512             :        Set the current handle.
     513             : 
     514             :        @param rHandle     the handle
     515             :      */
     516             :     virtual void handle(const T & rHandle);
     517             : 
     518             :     /**
     519             :        Start a new table level.
     520             : 
     521             :        A new context is pushed onto the table data stack,
     522             :      */
     523             :     virtual void startLevel();
     524             : 
     525             :     /**
     526             :        End a table level.
     527             : 
     528             :        The current table is resolved and the context is popped from
     529             :        the stack.
     530             :      */
     531             :     virtual void endLevel();
     532             : 
     533             :     /**
     534             :        Tells whether a table has been started or not
     535             :       */
     536             :     bool isInTable();
     537             : 
     538             :     /**
     539             :        Handle the start of a paragraph group.
     540             :      */
     541             :     virtual void startParagraphGroup();
     542             : 
     543             :     /**
     544             :        Handle the end of a paragraph group.
     545             :     */
     546             :     virtual void endParagraphGroup();
     547             : 
     548             :     /**
     549             :        Handle an SPRM at curent handle.
     550             : 
     551             :        @param rSprm   the SPRM
     552             :      */
     553             :     virtual bool sprm(Sprm & rSprm);
     554             : 
     555             :     /**
     556             :        Handle properties at current handle.
     557             : 
     558             :        @param pProps   the properites
     559             :      */
     560             :     virtual void props(PropertiesPointer pProps);
     561             : 
     562             :     /**
     563             :        Handle occurrence of character 0x7.
     564             :      */
     565             :     virtual void handle0x7();
     566             : 
     567             :     /**
     568             :        Handle 8 bit text at current handle.
     569             : 
     570             :        @param data    array of characters
     571             :        @param len     number of characters to handle
     572             :      */
     573             :     virtual void text(const sal_uInt8 * data, size_t len);
     574             : 
     575             :     /**
     576             :        Handle 16 bit text at current handle.
     577             : 
     578             :        @param data    array of characters
     579             :        @param len     number of characters to handle
     580             :      */
     581             :     virtual void utext(const sal_uInt8 * data, size_t len);
     582             : 
     583             :     /**
     584             :        Handle properties of the current cell.
     585             : 
     586             :        @param pProps   the properties
     587             :      */
     588             :     virtual void cellProps(PropertiesPointer pProps);
     589             : 
     590             :     /**
     591             :        Handle properties of a certain cell in the current row.
     592             : 
     593             :        @paran i        index of the cell in the current row
     594             :        @param pProps   the properties
     595             :      */
     596             :     virtual void cellPropsByCell(unsigned int i, PropertiesPointer pProps);
     597             : 
     598             :     /**
     599             :        Handle properties of the current row.
     600             : 
     601             :        @param pProps   the properties
     602             :      */
     603             :     virtual void insertRowProps(PropertiesPointer pProps);
     604             : 
     605             :     /**
     606             :        Handle properties of the current table.
     607             : 
     608             :        @param pProps   the properties
     609             :      */
     610             :     virtual void insertTableProps(PropertiesPointer pProps);
     611             : 
     612             :     /**
     613             :        Return if table manager has detected paragraph to ignore.
     614             : 
     615             :        If this function returns true the current paragraph contains
     616             :        only control information, e.g. end of row.
     617             :      */
     618             :     virtual bool isIgnore() const;
     619             : 
     620             : 
     621             : #ifdef DEBUG_TABLE
     622             :     void setTagLogger(TagLogger::Pointer_t _tagLogger)
     623             :     {
     624             :         mpTableLogger = _tagLogger;
     625             :     }
     626             : #endif
     627             : };
     628             : 
     629             : template <typename T, typename PropertiesPointer>
     630         540 : TableManager<T, PropertiesPointer>::TableManager()
     631         540 : : mnTableDepthNew(0), mnTableDepth(0), mbKeepUnfinishedRow( false )
     632             : {
     633         540 :     setRowEnd(false);
     634         540 :     setInCell(false);
     635         540 :     setCellEnd(false);
     636         540 : }
     637             : 
     638             : template <typename T, typename PropertiesPointer>
     639        1428 : void TableManager<T, PropertiesPointer>::cellDepth(sal_uInt32 nDepth)
     640             : {
     641             : #ifdef DEBUG_TABLE
     642             :     if (mpTableLogger != NULL)
     643             :     {
     644             :         mpTableLogger->startElement("tablemanager.cellDepth");
     645             :         mpTableLogger->attribute("depth", nDepth);
     646             :         mpTableLogger->endElement();
     647             :     }
     648             : #endif
     649             : 
     650        1428 :     mnTableDepthNew = nDepth;
     651        1428 : }
     652             : 
     653             : template <typename T, typename PropertiesPointer>
     654        1512 : void TableManager<T, PropertiesPointer>::inCell()
     655             : {
     656             : #ifdef DEBUG_TABLE
     657             :     if (mpTableLogger != NULL)
     658             :         mpTableLogger->element("tablemanager.inCell");
     659             : #endif
     660        1512 :     setInCell(true);
     661             : 
     662        1512 :     if (mnTableDepthNew < 1)
     663         197 :         mnTableDepthNew = 1;
     664        1512 : }
     665             : 
     666             : template <typename T, typename PropertiesPointer>
     667         725 : void TableManager<T, PropertiesPointer>::endCell()
     668             : {
     669             : #ifdef DEBUG_TABLE
     670             :     if (mpTableLogger != NULL)
     671             :         mpTableLogger->element("tablemanager.endCell");
     672             : #endif
     673             : 
     674         725 :     setCellEnd(true);
     675         725 : }
     676             : 
     677             : template <typename T, typename PropertiesPointer>
     678         207 : void TableManager<T, PropertiesPointer>::endRow()
     679             : {
     680             : #ifdef DEBUG_TABLE
     681             :     if (mpTableLogger != NULL)
     682             :         mpTableLogger->element("tablemanager.endRow");
     683             : #endif
     684             : 
     685         207 :     setRowEnd(true);
     686         207 : }
     687             : 
     688             : template <typename T, typename PropertiesPointer>
     689         539 : void TableManager<T, PropertiesPointer>::setHandler
     690             : (typename TableDataHandler<T, PropertiesPointer>::Pointer_t pTableDataHandler)
     691             : {
     692         539 :     mpTableDataHandler = pTableDataHandler;
     693         539 : }
     694             : 
     695             : template <typename T, typename PropertiesPointer>
     696        1605 : void TableManager<T, PropertiesPointer>::handle(const T & rHandle)
     697             : {
     698             : #ifdef DEBUG_TABLE
     699             :     if (mpTableLogger)
     700             :     {
     701             :         mpTableLogger->startElement("tablemanager.handle");
     702             :         mpTableLogger->chars(toString(rHandle));
     703             :         mpTableLogger->endElement();
     704             :     }
     705             : #endif
     706             : 
     707        1605 :     setHandle(rHandle);
     708        1605 : }
     709             : 
     710             : template <typename T, typename PropertiesPointer>
     711          16 : bool TableManager<T, PropertiesPointer>::isInTable()
     712             : {
     713          16 :     bool bInTable = false;
     714          16 :     if ( !mTableDataStack.empty() )
     715          16 :         bInTable = mTableDataStack.top()->getDepth() > 0;
     716          16 :     return bInTable;
     717             : }
     718             : 
     719             : template <typename T, typename PropertiesPointer>
     720         638 : void TableManager<T, PropertiesPointer>::startLevel()
     721             : {
     722             : #ifdef DEBUG_TABLE
     723             :     if (mpTableLogger != NULL)
     724             :     {
     725             :         typename TableData<T, PropertiesPointer>::Pointer_t pTableData;
     726             : 
     727             :         if (mTableDataStack.size() > 0)
     728             :             pTableData = mTableDataStack.top();
     729             : 
     730             :         mpTableLogger->startElement("tablemanager.startLevel");
     731             :         mpTableLogger->attribute("level", mTableDataStack.size());
     732             : 
     733             :         if (pTableData.get() != NULL)
     734             :             mpTableLogger->attribute("openCell",
     735             :                                      pTableData->isCellOpen() ? "yes" : "no");
     736             : 
     737             :         mpTableLogger->endElement();
     738             :     }
     739             : #endif
     740             : 
     741             :     typename TableData<T, PropertiesPointer>::Pointer_t pTableData
     742         638 :         (new TableData<T, PropertiesPointer>(mTableDataStack.size()));
     743             : 
     744             :     // If we have an unfinished row stored here, then push it to the new TableData
     745         638 :     if ( mpUnfinishedRow )
     746             :     {
     747           3 :         for (unsigned int i = 0; i < mpUnfinishedRow->getCellCount(); ++i)
     748             :         {
     749           2 :             pTableData->addCell( mpUnfinishedRow->getCellStart(i),
     750             :                                  mpUnfinishedRow->getCellProperties(i) );
     751           2 :             pTableData->endCell( mpUnfinishedRow->getCellEnd(i) );
     752             :         }
     753           1 :         mpUnfinishedRow.reset();
     754             :     }
     755             : 
     756         638 :     mTableDataStack.push(pTableData);
     757         638 :     mState.startLevel();
     758         638 : }
     759             : 
     760             : template <typename T, typename PropertiesPointer>
     761         637 : void TableManager<T, PropertiesPointer>::endLevel()
     762             : {
     763         637 :     if (mpTableDataHandler.get() != NULL)
     764         637 :         resolveCurrentTable();
     765             : 
     766             :     // Store the unfinished row as it will be used for the next table
     767         637 :     if ( mbKeepUnfinishedRow )
     768           1 :         mpUnfinishedRow = mTableDataStack.top()->getCurrentRow();
     769         637 :     mState.endLevel();
     770         637 :     mTableDataStack.pop();
     771             : 
     772             : #ifdef DEBUG_TABLE
     773             :     if (mpTableLogger != NULL)
     774             :     {
     775             :         typename TableData<T, PropertiesPointer>::Pointer_t pTableData;
     776             : 
     777             :         if (mTableDataStack.size() > 0)
     778             :             pTableData = mTableDataStack.top();
     779             : 
     780             :         mpTableLogger->startElement("tablemanager.endLevel");
     781             :         mpTableLogger->attribute("level", mTableDataStack.size());
     782             : 
     783             :         if (pTableData.get() != NULL)
     784             :             mpTableLogger->attribute("openCell",
     785             :                                      pTableData->isCellOpen() ? "yes" : "no");
     786             : 
     787             :         mpTableLogger->endElement();
     788             :     }
     789             : #endif
     790         637 : }
     791             : 
     792             : template <typename T, typename PropertiesPointer>
     793        2307 : void TableManager<T, PropertiesPointer>::startParagraphGroup()
     794             : {
     795        2307 :     mState.resetCellSpecifics();
     796        2307 :     mnTableDepthNew = 0;
     797        2307 : }
     798             : 
     799             : template <typename T, typename PropertiesPointer>
     800        2226 : void TableManager<T, PropertiesPointer>::endParagraphGroup()
     801             : {
     802        2226 :     sal_Int32 nTableDepthDifference = mnTableDepthNew - mnTableDepth;
     803             : 
     804        2226 :     PropertiesPointer pEmptyProps;
     805             : 
     806        4550 :     while (nTableDepthDifference > 0)
     807             :     {
     808          98 :         ensureOpenCell(pEmptyProps);
     809          98 :         startLevel();
     810             : 
     811          98 :         --nTableDepthDifference;
     812             :     }
     813        4549 :     while (nTableDepthDifference < 0)
     814             :     {
     815          97 :         endLevel();
     816             : 
     817          97 :         ++nTableDepthDifference;
     818             :     }
     819             : 
     820        2226 :     mnTableDepth = mnTableDepthNew;
     821             : 
     822        2226 :     if (mnTableDepth > 0)
     823             :     {
     824             :         typename TableData<T, PropertiesPointer>::Pointer_t pTableData =
     825         946 :         mTableDataStack.top();
     826             : 
     827         946 :         if (isRowEnd())
     828             :         {
     829         205 :             endOfRowAction();
     830         205 :             mTableDataStack.top()->endRow(getRowProps());
     831         205 :             resetRowProps();
     832             :         }
     833             : 
     834         741 :         else if (isInCell())
     835             :         {
     836         741 :             ensureOpenCell(getCellProps());
     837             : 
     838         741 :             if (isCellEnd())
     839             :             {
     840         725 :                 endOfCellAction();
     841         725 :                 closeCell(getHandle());
     842             :             }
     843             :         }
     844         946 :         resetCellProps();
     845        2226 :     }
     846        2226 : }
     847             : 
     848             : template <typename T, typename PropertiesPointer>
     849       35961 : bool TableManager<T, PropertiesPointer>::sprm(Sprm & rSprm)
     850             : {
     851       35961 :     bool bRet = true;
     852       35961 :     switch (rSprm.getId())
     853             :     {
     854             :     case NS_sprm::LN_PTableDepth:
     855             :         {
     856        1428 :             Value::Pointer_t pValue = rSprm.getValue();
     857             : 
     858        1428 :             cellDepth(pValue->getInt());
     859             :         }
     860        1428 :         break;
     861             :     case NS_sprm::LN_PFInTable:
     862        1512 :         inCell();
     863        1512 :         break;
     864             :     case NS_sprm::LN_PCell:
     865         725 :         endCell();
     866         725 :         break;
     867             :     case NS_sprm::LN_PFTtp:
     868             :     case NS_sprm::LN_PRow:
     869         198 :         endRow();
     870         198 :         break;
     871             :     default:
     872       32098 :         bRet = false;
     873             :     }
     874       35961 :     return bRet;
     875             : }
     876             : template <typename T, typename PropertiesPointer>
     877           0 : void TableManager<T, PropertiesPointer>::props(PropertiesPointer pProps)
     878             : {
     879           0 :     setProps(pProps);
     880           0 : }
     881             : 
     882             : template <typename T, typename PropertiesPointer>
     883           9 : void TableManager<T, PropertiesPointer>::handle0x7()
     884             : {
     885             : #ifdef DEBUG_TABLE
     886             :     if (mpTableLogger != NULL)
     887             :         mpTableLogger->startElement("tablemanager.handle0x7");
     888             : #endif
     889             : 
     890           9 :     if (mnTableDepthNew < 1)
     891           7 :         mnTableDepthNew = 1;
     892             : 
     893           9 :     if (isInCell())
     894           0 :         endCell();
     895             :     else
     896           9 :         endRow();
     897             : 
     898             : #ifdef DEBUG_TABLE
     899             :     if (mpTableLogger != NULL)
     900             :         mpTableLogger->endElement();
     901             : #endif
     902           9 : }
     903             : 
     904             : template <typename T, typename PropertiesPointer>
     905           0 : void TableManager<T, PropertiesPointer>::text(const sal_uInt8 * data, size_t len)
     906             : {
     907             :     // optimization: cell/row end characters are the last characters in a run
     908           0 :     if (len > 0)
     909             :     {
     910           0 :         if (data[len - 1] == 0x7)
     911           0 :             handle0x7();
     912             :     }
     913           0 : }
     914             : 
     915             : template <typename T, typename PropertiesPointer>
     916        6139 : void TableManager<T, PropertiesPointer>::utext(const sal_uInt8 * data, size_t len)
     917             : {
     918             :     // optimization: cell/row end characters are the last characters in a run
     919             : 
     920        6139 :     if (len > 0)
     921             :     {
     922        6139 :         sal_Unicode nChar = data[(len - 1) * 2] + (data[(len - 1) * 2 + 1] << 8);
     923        6139 :         if (nChar == 0x7)
     924           9 :             handle0x7();
     925             :     }
     926        6139 : }
     927             : 
     928             : template <typename T, typename PropertiesPointer>
     929         997 : void TableManager<T, PropertiesPointer>::cellProps(PropertiesPointer pProps)
     930             : {
     931             : #ifdef DEBUG_TABLE
     932             :     if (mpTableLogger != NULL)
     933             :         mpTableLogger->startElement("tablemanager.cellProps");
     934             : #endif
     935             : 
     936         997 :     if(getCellProps().get())
     937         464 :         getCellProps()->InsertProps(pProps);
     938             :     else
     939         533 :         setCellProps(pProps);
     940             : 
     941             : #ifdef DEBUG_TABLE
     942             :     if (mpTableLogger != NULL)
     943             :         mpTableLogger->endElement();
     944             : #endif
     945         997 : }
     946             : 
     947             : template <typename T, typename PropertiesPointer>
     948           0 : void TableManager<T, PropertiesPointer>::cellPropsByCell
     949             : (unsigned int i, PropertiesPointer pProps)
     950             : {
     951             : #ifdef DEBUG_TABLE
     952             :     if (mpTableLogger != NULL)
     953             :         mpTableLogger->startElement("tablemanager.cellPropsByCell");
     954             : #endif
     955             : 
     956           0 :     mTableDataStack.top()->insertCellProperties(i, pProps);
     957             : 
     958             : #ifdef DEBUG_TABLE
     959             :     if (mpTableLogger != NULL)
     960             :         mpTableLogger->endElement();
     961             : #endif
     962           0 : }
     963             : 
     964             : template <typename T, typename PropertiesPointer>
     965         235 : void TableManager<T, PropertiesPointer>::insertRowProps(PropertiesPointer pProps)
     966             : {
     967             : #ifdef DEBUG_TABLE
     968             :     if (mpTableLogger != NULL)
     969             :         mpTableLogger->startElement("tablemanager.insertRowProps");
     970             : #endif
     971             : 
     972         235 :     if( getRowProps().get() )
     973          44 :         getRowProps()->InsertProps(pProps);
     974             :     else
     975         191 :         setRowProps(pProps);
     976             : 
     977             : #ifdef DEBUG_TABLE
     978             :     if (mpTableLogger != NULL)
     979             :         mpTableLogger->endElement();
     980             : #endif
     981         235 : }
     982             : 
     983             : template <typename T, typename PropertiesPointer>
     984         205 : void TableManager<T, PropertiesPointer>::insertTableProps(PropertiesPointer pProps)
     985             : {
     986             : #ifdef DEBUG_TABLE
     987             :     if (mpTableLogger != NULL)
     988             :         mpTableLogger->startElement("tablemanager.insertTableProps");
     989             : #endif
     990             : 
     991         205 :     if( getTableProps().get() && getTableProps() != pProps)
     992         106 :         getTableProps()->InsertProps(pProps);
     993             :     else
     994          99 :         setTableProps(pProps);
     995             : 
     996             : #ifdef DEBUG_TABLE
     997             :     if (mpTableLogger != NULL)
     998             :         mpTableLogger->endElement();
     999             : #endif
    1000         205 : }
    1001             : 
    1002             : template <typename T, typename PropertiesPointer>
    1003         637 : void TableManager<T, PropertiesPointer>::resolveCurrentTable()
    1004             : {
    1005             : #ifdef DEBUG_TABLE
    1006             :     if (mpTableLogger != NULL)
    1007             :         mpTableLogger->startElement("tablemanager.resolveCurrentTable");
    1008             : #endif
    1009             : 
    1010         637 :     if (mpTableDataHandler.get() != NULL)
    1011             :     {
    1012             :         try
    1013             :         {
    1014             :             typename TableData<T, PropertiesPointer>::Pointer_t
    1015         637 :                 pTableData = mTableDataStack.top();
    1016             : 
    1017         637 :             unsigned int nRows = pTableData->getRowCount();
    1018             : 
    1019         637 :             mpTableDataHandler->startTable(nRows, pTableData->getDepth(), getTableProps());
    1020             : 
    1021         842 :             for (unsigned int nRow = 0; nRow < nRows; ++nRow)
    1022             :             {
    1023         205 :                 typename RowData<T, PropertiesPointer>::Pointer_t pRowData = pTableData->getRow(nRow);
    1024             : 
    1025         205 :                 unsigned int nCells = pRowData->getCellCount();
    1026             : 
    1027         205 :                 mpTableDataHandler->startRow(nCells, pRowData->getProperties());
    1028             : 
    1029         930 :                 for (unsigned int nCell = 0; nCell < nCells; ++nCell)
    1030             :                 {
    1031         725 :                     mpTableDataHandler->startCell
    1032             :                         (pRowData->getCellStart(nCell),
    1033             :                         pRowData->getCellProperties(nCell));
    1034             : 
    1035         725 :                     mpTableDataHandler->endCell(pRowData->getCellEnd(nCell));
    1036             :                 }
    1037             : 
    1038         205 :                 mpTableDataHandler->endRow();
    1039             :             }
    1040             : 
    1041         637 :             mpTableDataHandler->endTable(mTableDataStack.size() - 1);
    1042             :         }
    1043           0 :         catch (uno::Exception const& e)
    1044             :         {
    1045             :             (void) e;
    1046             : #if OSL_DEBUG_LEVEL > 0
    1047             :             SAL_WARN("writerfilter", "resolving of current table failed with: " << e.Message);
    1048             : #endif
    1049             :         }
    1050             :     }
    1051         637 :     resetTableProps();
    1052         637 :     clearData();
    1053             : 
    1054             : #ifdef DEBUG_TABLE
    1055             :     if (mpTableLogger != NULL)
    1056             :         mpTableLogger->endElement();
    1057             : #endif
    1058         637 : }
    1059             : 
    1060             : template <typename T, typename PropertiesPointer>
    1061           0 : void TableManager<T, PropertiesPointer>::endOfCellAction()
    1062             : {
    1063           0 : }
    1064             : 
    1065             : template <typename T, typename PropertiesPointer>
    1066           0 : void TableManager<T, PropertiesPointer>::endOfRowAction()
    1067             : {
    1068           0 : }
    1069             : 
    1070             : template <typename T, typename PropertiesPointer>
    1071        3146 : bool TableManager<T, PropertiesPointer>::isIgnore() const
    1072             : {
    1073        3146 :     return isRowEnd();
    1074             : }
    1075             : 
    1076             : template <typename T, typename PropertiesPointer>
    1077           0 : void  TableManager<T, PropertiesPointer>::clearData()
    1078             : {
    1079           0 : }
    1080             : 
    1081             : template <typename T, typename PropertiesPointer>
    1082         780 : void  TableManager<T, PropertiesPointer>::openCell
    1083             : (const T & rHandle, PropertiesPointer pProps)
    1084             : {
    1085             : #ifdef DEBUG_TABLE
    1086             :     mpTableLogger->startElement("tablemanager.openCell");
    1087             :     mpTableLogger->chars(toString(rHandle));
    1088             :     mpTableLogger->endElement();
    1089             : #endif
    1090             : 
    1091         780 :     if (mTableDataStack.size() > 0)
    1092             :     {
    1093             :         typename TableData<T, PropertiesPointer>::Pointer_t
    1094         780 :         pTableData = mTableDataStack.top();
    1095             : 
    1096         780 :         pTableData->addCell(rHandle, pProps);
    1097             :     }
    1098         780 : }
    1099             : 
    1100             : template <typename T, typename PropertiesPointer>
    1101         725 : void  TableManager<T, PropertiesPointer>::closeCell
    1102             : (const T & rHandle)
    1103             : {
    1104             : #ifdef DEBUG_TABLE
    1105             :     mpTableLogger->startElement("tablemanager.closeCell");
    1106             :     mpTableLogger->chars(toString(rHandle));
    1107             :     mpTableLogger->endElement();
    1108             : #endif
    1109             : 
    1110         725 :     if (mTableDataStack.size() > 0)
    1111             :     {
    1112             :         typename TableData<T, PropertiesPointer>::Pointer_t
    1113         725 :         pTableData = mTableDataStack.top();
    1114             : 
    1115         725 :         pTableData->endCell(rHandle);
    1116             :     }
    1117         725 : }
    1118             : 
    1119             : template <typename T, typename PropertiesPointer>
    1120         839 : void  TableManager<T, PropertiesPointer>::ensureOpenCell(PropertiesPointer pProps)
    1121             : {
    1122             : #ifdef DEBUG_TABLE
    1123             :     mpTableLogger->startElement("tablemanager.ensureOpenCell");
    1124             : #endif
    1125             : 
    1126         839 :     if (mTableDataStack.size() > 0)
    1127             :     {
    1128             :         typename TableData<T, PropertiesPointer>::Pointer_t
    1129         839 :         pTableData = mTableDataStack.top();
    1130             : 
    1131         839 :         if (pTableData.get() != NULL)
    1132             :         {
    1133         839 :             if (!pTableData->isCellOpen())
    1134         780 :                 openCell(getHandle(), pProps);
    1135             :             else
    1136          59 :                 pTableData->insertCellProperties(pProps);
    1137         839 :         }
    1138             :     }
    1139             : #ifdef DEBUG_TABLE
    1140             :     mpTableLogger->endElement();
    1141             : #endif
    1142         839 : }
    1143             : 
    1144             : }
    1145             : 
    1146             : #endif // INCLUDED_TABLE_MANAGER_HXX
    1147             : 
    1148             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10