LCOV - code coverage report
Current view: top level - sw/source/core/layout - layhelp.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 22 22 100.0 %
Date: 2012-08-25 Functions: 20 20 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 14 71.4 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef SW_LAYHELP_HXX
      30                 :            : #define SW_LAYHELP_HXX
      31                 :            : 
      32                 :            : #include <swrect.hxx>
      33                 :            : #include <vector>
      34                 :            : #include <deque>
      35                 :            : 
      36                 :            : class SwDoc;
      37                 :            : class SwFrm;
      38                 :            : class SwLayoutFrm;
      39                 :            : class SwPageFrm;
      40                 :            : class SwFlyFrm;
      41                 :            : class SwSectionFrm;
      42                 :            : class SwSectionNode;
      43                 :            : class SvStream;
      44                 :            : 
      45                 :            : /*************************************************************************
      46                 :            :  *                      class SwLayCacheImpl
      47                 :            :  * contains the page break information and the text frame positions
      48                 :            :  * of the document (after loading)
      49                 :            :  * and is used inside the constructor of the layout rootframe to
      50                 :            :  * insert content and text frames at the right pages.
      51                 :            :  * For every page of the main text (body content, no footnotes, text frames etc.)
      52                 :            :  * we have the nodeindex of the first content at the page,
      53                 :            :  * the type of content ( table or paragraph )
      54                 :            :  * and if it's not the first part of the table/paragraph,
      55                 :            :  * the row/character-offset inside the table/paragraph.
      56                 :            :  * The text frame positions are stored in the SwPageFlyCache array.
      57                 :            :  *************************************************************************/
      58                 :            : 
      59                 :            : class SwFlyCache;
      60                 :            : typedef boost::ptr_vector<SwFlyCache> SwPageFlyCache;
      61                 :            : 
      62         [ +  - ]:         12 : class SwLayCacheImpl : public std::vector<sal_uLong>
      63                 :            : {
      64                 :            :     std::deque<xub_StrLen> aOffset;
      65                 :            :     std::vector<sal_uInt16> aType;
      66                 :            :     SwPageFlyCache aFlyCache;
      67                 :            :     sal_Bool bUseFlyCache;
      68                 :            :     void Insert( sal_uInt16 nType, sal_uLong nIndex, xub_StrLen nOffset );
      69                 :            : 
      70                 :            : public:
      71 [ +  - ][ +  - ]:         12 :     SwLayCacheImpl() {}
                 [ +  - ]
      72                 :            :     sal_Bool Read( SvStream& rStream );
      73                 :            : 
      74                 :        206 :     sal_uLong GetBreakIndex( sal_uInt16 nIdx ) const { return std::vector<sal_uLong>::operator[]( nIdx ); }
      75                 :         18 :     xub_StrLen GetBreakOfst( size_t nIdx ) const { return aOffset[ nIdx ]; }
      76                 :         18 :     sal_uInt16 GetBreakType( sal_uInt16 nIdx ) const { return aType[ nIdx ]; }
      77                 :            : 
      78                 :         38 :     sal_uInt16 GetFlyCount() const { return aFlyCache.size(); }
      79                 :         44 :     SwFlyCache *GetFlyCache( sal_uInt16 nIdx ) { return &aFlyCache[ nIdx ]; }
      80                 :            : 
      81                 :          6 :     sal_Bool IsUseFlyCache() const { return bUseFlyCache; }
      82                 :            : };
      83                 :            : 
      84                 :            : /*************************************************************************
      85                 :            :  *                      class SwActualSection
      86                 :            :  * helps to create the sectionframes during the _InsertCnt-function
      87                 :            :  * by controlling nested sections.
      88                 :            :  *************************************************************************/
      89                 :            : 
      90                 :            : class SwActualSection
      91                 :            : {
      92                 :            :     SwActualSection *pUpper;
      93                 :            :     SwSectionFrm    *pSectFrm;
      94                 :            :     SwSectionNode   *pSectNode;
      95                 :            : public:
      96                 :            :     SwActualSection( SwActualSection *pUpper,
      97                 :            :                      SwSectionFrm    *pSect,
      98                 :            :                      SwSectionNode   *pNd );
      99                 :            : 
     100                 :         82 :     SwSectionFrm    *GetSectionFrm()                    { return pSectFrm; }
     101                 :         38 :     void             SetSectionFrm( SwSectionFrm *p )   { pSectFrm = p; }
     102                 :         36 :     SwSectionNode   *GetSectionNode()                   { return pSectNode;}
     103                 :        276 :     SwActualSection *GetUpper()                         { return pUpper; }
     104                 :            : };
     105                 :            : 
     106                 :            : /*************************************************************************
     107                 :            :  *                      class SwLayHelper
     108                 :            :  * helps during the _InsertCnt-function to create new pages.
     109                 :            :  * If there's a layoutcache available, this information is used.
     110                 :            :  *************************************************************************/
     111                 :            : 
     112                 :            : class SwLayHelper
     113                 :            : {
     114                 :            :     SwFrm* &rpFrm;
     115                 :            :     SwFrm* &rpPrv;
     116                 :            :     SwPageFrm* &rpPage;
     117                 :            :     SwLayoutFrm* &rpLay;
     118                 :            :     SwActualSection* &rpActualSection;
     119                 :            :     sal_Bool &rbBreakAfter;
     120                 :            :     SwDoc* pDoc;
     121                 :            :     SwLayCacheImpl* pImpl;
     122                 :            :     sal_uLong nMaxParaPerPage;
     123                 :            :     sal_uLong nParagraphCnt;
     124                 :            :     sal_uLong nStartOfContent;
     125                 :            :     sal_uInt16 nIndex;                      // the index in the page break array
     126                 :            :     sal_uInt16 nFlyIdx;                     // the index in the fly cache array
     127                 :            :     sal_Bool bFirst : 1;
     128                 :            :     void _CheckFlyCache( SwPageFrm* pPage );
     129                 :            : public:
     130                 :            :     SwLayHelper( SwDoc *pD, SwFrm* &rpF, SwFrm* &rpP, SwPageFrm* &rpPg,
     131                 :            :             SwLayoutFrm* &rpL, SwActualSection* &rpA, sal_Bool &rBrk,
     132                 :            :             sal_uLong nNodeIndex, sal_Bool bCache );
     133                 :            :     ~SwLayHelper();
     134                 :            :     sal_uLong CalcPageCount();
     135                 :            :     sal_Bool CheckInsert( sal_uLong nNodeIndex );
     136                 :            : 
     137                 :            :     sal_Bool BreakPage( xub_StrLen& rOffs, sal_uLong nNodeIndex );
     138                 :            :     sal_Bool CheckInsertPage();
     139                 :            : 
     140                 :            :     // Look for fresh text frames at this (new) page and set them to the right
     141                 :            :     // position, if they are in the fly cache.
     142                 :       1318 :     void CheckFlyCache( SwPageFrm* pPage )
     143 [ +  + ][ +  + ]:       1318 :     { if( pImpl && nFlyIdx < pImpl->GetFlyCount() ) _CheckFlyCache( pPage ); }
                 [ +  + ]
     144                 :            : 
     145                 :            :     // Look for this text frame and set it to the right position,
     146                 :            :     // if it's in the fly cache.
     147                 :            :     static sal_Bool CheckPageFlyCache( SwPageFrm* &rpPage, SwFlyFrm* pFly );
     148                 :            : };
     149                 :            : 
     150                 :            : /*************************************************************************
     151                 :            :  *                      class SwLayCacheIoImpl
     152                 :            :  * contains the data structures that are required to read and write a
     153                 :            :  * layout cache.
     154                 :            :  *************************************************************************/
     155                 :            : 
     156                 :            : #define SW_LAYCACHE_IO_REC_PAGES    'p'
     157                 :            : #define SW_LAYCACHE_IO_REC_PARA     'P'
     158                 :            : #define SW_LAYCACHE_IO_REC_TABLE    'T'
     159                 :            : #define SW_LAYCACHE_IO_REC_FLY      'F'
     160                 :            : 
     161                 :            : #define SW_LAYCACHE_IO_VERSION_MAJOR    1
     162                 :            : #define SW_LAYCACHE_IO_VERSION_MINOR    1
     163                 :            : 
     164                 :         16 : class SwLayCacheIoImpl
     165                 :            : {
     166                 :            : private:
     167                 :            :     struct RecTypeSize {
     168                 :            :         sal_uInt8 type;
     169                 :            :         sal_uLong size;
     170                 :         76 :         RecTypeSize(sal_uInt8 typ, sal_uLong siz) : type(typ), size(siz) {}
     171                 :            :     };
     172                 :            :     std::vector<RecTypeSize> aRecords;
     173                 :            : 
     174                 :            :     SvStream        *pStream;
     175                 :            : 
     176                 :            :     sal_uLong           nFlagRecEnd;
     177                 :            : 
     178                 :            :     sal_uInt16          nMajorVersion;
     179                 :            :     sal_uInt16          nMinorVersion;
     180                 :            : 
     181                 :            :     sal_Bool            bWriteMode : 1;
     182                 :            :     sal_Bool            bError : 1;
     183                 :            : 
     184                 :            : public:
     185                 :            :     SwLayCacheIoImpl( SvStream& rStrm, sal_Bool bWrtMd );
     186                 :            : 
     187                 :            :     // Get input or output stream
     188                 :         76 :     SvStream& GetStream() const { return *pStream; }
     189                 :            : 
     190                 :            :     // Open a record of type "nType"
     191                 :            :     sal_Bool OpenRec( sal_uInt8 nType );
     192                 :            : 
     193                 :            :     // Close a record of type "nType". This skips any unread data that
     194                 :            :     // remains in the record.
     195                 :            :     sal_Bool CloseRec( sal_uInt8 nType );
     196                 :            : 
     197                 :            :     // Return the number of bytes contained in the current record that
     198                 :            :     // haven't been read by now.
     199                 :            :     sal_uInt32 BytesLeft();
     200                 :            : 
     201                 :            :     // Return the current record's type
     202                 :            :     sal_uInt8 Peek();
     203                 :            : 
     204                 :            :     // Skip the current record
     205                 :            :     void SkipRec();
     206                 :            : 
     207                 :            :     // Open a flag record for reading. The uppermost four bits are flags,
     208                 :            :     // while the lowermost are the flag record's size. Flag records cannot
     209                 :            :     // be nested.
     210                 :            :     sal_uInt8 OpenFlagRec();
     211                 :            : 
     212                 :            :     // Open flag record for writing;
     213                 :            :     void OpenFlagRec( sal_uInt8 nFlags, sal_uInt8 nLen );
     214                 :            : 
     215                 :            :     // Close a flag record. Any bytes left are skipped.
     216                 :            :     void CloseFlagRec();
     217                 :            : 
     218                 :         62 :     sal_Bool HasError() const { return bError; }
     219                 :            : 
     220                 :         12 :     sal_uInt16 GetMajorVersion() const { return nMajorVersion; }
     221                 :         12 :     sal_uInt16 GetMinorVersion() const { return nMinorVersion; }
     222                 :            : };
     223                 :            : 
     224                 :            : // Stored information about text frames:
     225                 :            : class SwFlyCache : public SwRect // position and size
     226                 :            : {
     227                 :            : public:
     228                 :            :     sal_uLong nOrdNum;      // Id to recognize text frames
     229                 :            :     sal_uInt16 nPageNum;    // page number
     230                 :          8 :     SwFlyCache( sal_uInt16 nP, sal_uLong nO, long nXL, long nYL, long nWL, long nHL ) :
     231                 :          8 :         SwRect( nXL, nYL, nWL, nHL ), nOrdNum( nO ), nPageNum( nP ){}
     232                 :            : };
     233                 :            : 
     234                 :            : #endif
     235                 :            : 
     236                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10