LCOV - code coverage report
Current view: top level - sc/source/filter/oox - pivotcachefragment.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 205 0.5 %
Date: 2012-08-25 Functions: 2 25 8.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 275 0.7 %

           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                 :            : #include "pivotcachefragment.hxx"
      30                 :            : 
      31                 :            : #include "oox/helper/attributelist.hxx"
      32                 :            : #include "addressconverter.hxx"
      33                 :            : #include "biffinputstream.hxx"
      34                 :            : #include "pivotcachebuffer.hxx"
      35                 :            : 
      36                 :            : namespace oox {
      37                 :            : namespace xls {
      38                 :            : 
      39                 :            : // ============================================================================
      40                 :            : 
      41                 :            : using namespace ::com::sun::star::uno;
      42                 :            : using namespace ::oox::core;
      43                 :            : 
      44                 :            : using ::rtl::OUString;
      45                 :            : 
      46                 :            : // ============================================================================
      47                 :            : 
      48                 :          0 : PivotCacheFieldContext::PivotCacheFieldContext( WorkbookFragmentBase& rFragment, PivotCacheField& rCacheField ) :
      49                 :            :     WorkbookContextBase( rFragment ),
      50                 :          0 :     mrCacheField( rCacheField )
      51                 :            : {
      52                 :          0 : }
      53                 :            : 
      54                 :          0 : ContextHandlerRef PivotCacheFieldContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
      55                 :            : {
      56   [ #  #  #  #  :          0 :     switch( getCurrentElement() )
                   #  # ]
      57                 :            :     {
      58                 :            :         case XLS_TOKEN( cacheField ):
      59         [ #  # ]:          0 :             if( nElement == XLS_TOKEN( sharedItems ) )  { mrCacheField.importSharedItems( rAttribs );   return this; }
      60         [ #  # ]:          0 :             if( nElement == XLS_TOKEN( fieldGroup ) )   { mrCacheField.importFieldGroup( rAttribs );    return this; }
      61                 :          0 :         break;
      62                 :            : 
      63                 :            :         case XLS_TOKEN( fieldGroup ):
      64   [ #  #  #  # ]:          0 :             switch( nElement )
      65                 :            :             {
      66                 :          0 :                 case XLS_TOKEN( rangePr ):      mrCacheField.importRangePr( rAttribs );     break;
      67                 :          0 :                 case XLS_TOKEN( discretePr ):   return this;
      68                 :          0 :                 case XLS_TOKEN( groupItems ):   return this;
      69                 :            :             }
      70                 :          0 :         break;
      71                 :            : 
      72                 :          0 :         case XLS_TOKEN( sharedItems ):  mrCacheField.importSharedItem( nElement, rAttribs );        break;
      73                 :          0 :         case XLS_TOKEN( discretePr ):   mrCacheField.importDiscretePrItem( nElement, rAttribs );    break;
      74                 :          0 :         case XLS_TOKEN( groupItems ):   mrCacheField.importGroupItem( nElement, rAttribs );         break;
      75                 :            :     }
      76                 :          0 :     return 0;
      77                 :            : }
      78                 :            : 
      79                 :          0 : void PivotCacheFieldContext::onStartElement( const AttributeList& rAttribs )
      80                 :            : {
      81         [ #  # ]:          0 :     if( isRootElement() )
      82                 :          0 :         mrCacheField.importCacheField( rAttribs );
      83                 :          0 : }
      84                 :            : 
      85                 :          0 : ContextHandlerRef PivotCacheFieldContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
      86                 :            : {
      87   [ #  #  #  #  :          0 :     switch( getCurrentElement() )
                   #  # ]
      88                 :            :     {
      89                 :            :         case BIFF12_ID_PCDFIELD:
      90      [ #  #  # ]:          0 :             switch( nRecId )
      91                 :            :             {
      92                 :          0 :                 case BIFF12_ID_PCDFSHAREDITEMS: mrCacheField.importPCDFSharedItems( rStrm );  return this;
      93                 :          0 :                 case BIFF12_ID_PCDFIELDGROUP:   mrCacheField.importPCDFieldGroup( rStrm );    return this;
      94                 :            :             }
      95                 :          0 :         break;
      96                 :            : 
      97                 :            :         case BIFF12_ID_PCDFIELDGROUP:
      98   [ #  #  #  # ]:          0 :             switch( nRecId )
      99                 :            :             {
     100                 :          0 :                 case BIFF12_ID_PCDFRANGEPR:     mrCacheField.importPCDFRangePr( rStrm );    break;
     101                 :          0 :                 case BIFF12_ID_PCDFDISCRETEPR:  return this;
     102                 :          0 :                 case BIFF12_ID_PCDFGROUPITEMS:  return this;
     103                 :            :             }
     104                 :          0 :         break;
     105                 :            : 
     106                 :          0 :         case BIFF12_ID_PCDFSHAREDITEMS: mrCacheField.importPCDFSharedItem( nRecId, rStrm );     break;
     107                 :          0 :         case BIFF12_ID_PCDFDISCRETEPR:  mrCacheField.importPCDFDiscretePrItem( nRecId, rStrm ); break;
     108                 :          0 :         case BIFF12_ID_PCDFGROUPITEMS:  mrCacheField.importPCDFGroupItem( nRecId, rStrm );      break;
     109                 :            :     }
     110                 :          0 :     return 0;
     111                 :            : }
     112                 :            : 
     113                 :          0 : void PivotCacheFieldContext::onStartRecord( SequenceInputStream& rStrm )
     114                 :            : {
     115         [ #  # ]:          0 :     if( isRootElement() )
     116                 :          0 :         mrCacheField.importPCDField( rStrm );
     117                 :          0 : }
     118                 :            : 
     119                 :            : // ============================================================================
     120                 :            : 
     121                 :          0 : PivotCacheDefinitionFragment::PivotCacheDefinitionFragment(
     122                 :            :         const WorkbookHelper& rHelper, const OUString& rFragmentPath, PivotCache& rPivotCache ) :
     123                 :            :     WorkbookFragmentBase( rHelper, rFragmentPath ),
     124                 :          0 :     mrPivotCache( rPivotCache )
     125                 :            : {
     126                 :          0 : }
     127                 :            : 
     128                 :          0 : ContextHandlerRef PivotCacheDefinitionFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
     129                 :            : {
     130   [ #  #  #  #  :          0 :     switch( getCurrentElement() )
                      # ]
     131                 :            :     {
     132                 :            :         case XML_ROOT_CONTEXT:
     133         [ #  # ]:          0 :             if( nElement == XLS_TOKEN( pivotCacheDefinition ) ) { mrPivotCache.importPivotCacheDefinition( rAttribs ); return this; }
     134                 :          0 :         break;
     135                 :            : 
     136                 :            :         case XLS_TOKEN( pivotCacheDefinition ):
     137      [ #  #  # ]:          0 :             switch( nElement )
     138                 :            :             {
     139                 :          0 :                 case XLS_TOKEN( cacheSource ):  mrPivotCache.importCacheSource( rAttribs ); return this;
     140                 :          0 :                 case XLS_TOKEN( cacheFields ):  return this;
     141                 :            :             }
     142                 :          0 :         break;
     143                 :            : 
     144                 :            :         case XLS_TOKEN( cacheSource ):
     145         [ #  # ]:          0 :             if( nElement == XLS_TOKEN( worksheetSource ) ) mrPivotCache.importWorksheetSource( rAttribs, getRelations() );
     146                 :          0 :         break;
     147                 :            : 
     148                 :            :         case XLS_TOKEN( cacheFields ):
     149 [ #  # ][ #  # ]:          0 :             if( nElement == XLS_TOKEN( cacheField ) ) return new PivotCacheFieldContext( *this, mrPivotCache.createCacheField() );
     150                 :          0 :         break;
     151                 :            :     }
     152                 :          0 :     return 0;
     153                 :            : }
     154                 :            : 
     155                 :          0 : ContextHandlerRef PivotCacheDefinitionFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
     156                 :            : {
     157   [ #  #  #  #  :          0 :     switch( getCurrentElement() )
                      # ]
     158                 :            :     {
     159                 :            :         case XML_ROOT_CONTEXT:
     160         [ #  # ]:          0 :             if( nRecId == BIFF12_ID_PCDEFINITION ) { mrPivotCache.importPCDefinition( rStrm ); return this; }
     161                 :          0 :         break;
     162                 :            : 
     163                 :            :         case BIFF12_ID_PCDEFINITION:
     164      [ #  #  # ]:          0 :             switch( nRecId )
     165                 :            :             {
     166                 :          0 :                 case BIFF12_ID_PCDSOURCE: mrPivotCache.importPCDSource( rStrm ); return this;
     167                 :          0 :                 case BIFF12_ID_PCDFIELDS: return this;
     168                 :            :             }
     169                 :          0 :         break;
     170                 :            : 
     171                 :            :         case BIFF12_ID_PCDSOURCE:
     172         [ #  # ]:          0 :             if( nRecId == BIFF12_ID_PCDSHEETSOURCE ) mrPivotCache.importPCDSheetSource( rStrm, getRelations() );
     173                 :          0 :         break;
     174                 :            : 
     175                 :            :         case BIFF12_ID_PCDFIELDS:
     176 [ #  # ][ #  # ]:          0 :             if( nRecId == BIFF12_ID_PCDFIELD ) return new PivotCacheFieldContext( *this, mrPivotCache.createCacheField() );
     177                 :          0 :         break;
     178                 :            :     }
     179                 :          0 :     return 0;
     180                 :            : }
     181                 :            : 
     182                 :          0 : const RecordInfo* PivotCacheDefinitionFragment::getRecordInfos() const
     183                 :            : {
     184                 :            :     static const RecordInfo spRecInfos[] =
     185                 :            :     {
     186                 :            :         { BIFF12_ID_PCDEFINITION,       BIFF12_ID_PCDEFINITION + 1      },
     187                 :            :         { BIFF12_ID_PCDFDISCRETEPR,     BIFF12_ID_PCDFDISCRETEPR + 1    },
     188                 :            :         { BIFF12_ID_PCDFGROUPITEMS,     BIFF12_ID_PCDFGROUPITEMS + 1    },
     189                 :            :         { BIFF12_ID_PCDFIELD,           BIFF12_ID_PCDFIELD + 1          },
     190                 :            :         { BIFF12_ID_PCDFIELDGROUP,      BIFF12_ID_PCDFIELDGROUP + 1     },
     191                 :            :         { BIFF12_ID_PCDFIELDS,          BIFF12_ID_PCDFIELDS + 1         },
     192                 :            :         { BIFF12_ID_PCDFRANGEPR,        BIFF12_ID_PCDFRANGEPR + 1       },
     193                 :            :         { BIFF12_ID_PCDFSHAREDITEMS,    BIFF12_ID_PCDFSHAREDITEMS + 1   },
     194                 :            :         { BIFF12_ID_PCITEM_ARRAY,       BIFF12_ID_PCITEM_ARRAY + 1      },
     195                 :            :         { BIFF12_ID_PCDSHEETSOURCE,     BIFF12_ID_PCDSHEETSOURCE + 1    },
     196                 :            :         { BIFF12_ID_PCDSOURCE,          BIFF12_ID_PCDSOURCE + 1         },
     197                 :            :         { -1,                           -1                              }
     198                 :            :     };
     199                 :          0 :     return spRecInfos;
     200                 :            : }
     201                 :            : 
     202                 :          0 : void PivotCacheDefinitionFragment::finalizeImport()
     203                 :            : {
     204                 :            :     // finalize the cache (check source range etc.)
     205                 :          0 :     mrPivotCache.finalizeImport();
     206                 :            : 
     207                 :            :     // load the cache records, if the cache is based on a deleted or an external worksheet
     208 [ #  # ][ #  # ]:          0 :     if( mrPivotCache.isValidDataSource() && mrPivotCache.isBasedOnDummySheet() )
                 [ #  # ]
     209                 :            :     {
     210 [ #  # ][ #  # ]:          0 :         OUString aRecFragmentPath = getRelations().getFragmentPathFromRelId( mrPivotCache.getRecordsRelId() );
     211         [ #  # ]:          0 :         if( !aRecFragmentPath.isEmpty() )
     212                 :            :         {
     213                 :          0 :             sal_Int16 nSheet = mrPivotCache.getSourceRange().Sheet;
     214 [ #  # ][ #  # ]:          0 :             WorksheetGlobalsRef xSheetGlob = WorksheetHelper::constructGlobals( *this, ISegmentProgressBarRef(), SHEETTYPE_WORKSHEET, nSheet );
                 [ #  # ]
     215         [ #  # ]:          0 :             if( xSheetGlob.get() )
     216 [ #  # ][ #  # ]:          0 :                 importOoxFragment( new PivotCacheRecordsFragment( *xSheetGlob, aRecFragmentPath, mrPivotCache ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     217                 :          0 :         }
     218                 :            :     }
     219                 :          0 : }
     220                 :            : 
     221                 :            : // ============================================================================
     222                 :            : 
     223                 :          0 : PivotCacheRecordsFragment::PivotCacheRecordsFragment( const WorksheetHelper& rHelper,
     224                 :            :         const OUString& rFragmentPath, const PivotCache& rPivotCache ) :
     225                 :            :     WorksheetFragmentBase( rHelper, rFragmentPath ),
     226                 :            :     mrPivotCache( rPivotCache ),
     227                 :            :     mnColIdx( 0 ),
     228                 :            :     mnRowIdx( 0 ),
     229                 :          0 :     mbInRecord( false )
     230                 :            : {
     231                 :            :     // prepare sheet: insert column header names into top row
     232         [ #  # ]:          0 :     rPivotCache.writeSourceHeaderCells( *this );
     233                 :          0 : }
     234                 :            : 
     235                 :          0 : ContextHandlerRef PivotCacheRecordsFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
     236                 :            : {
     237   [ #  #  #  # ]:          0 :     switch( getCurrentElement() )
     238                 :            :     {
     239                 :            :         case XML_ROOT_CONTEXT:
     240         [ #  # ]:          0 :             if( nElement == XLS_TOKEN( pivotCacheRecords ) ) return this;
     241                 :          0 :         break;
     242                 :            : 
     243                 :            :         case XLS_TOKEN( pivotCacheRecords ):
     244         [ #  # ]:          0 :             if( nElement == XLS_TOKEN( r ) ) { startCacheRecord(); return this; }
     245                 :          0 :         break;
     246                 :            : 
     247                 :            :         case XLS_TOKEN( r ):
     248                 :            :         {
     249         [ #  # ]:          0 :             PivotCacheItem aItem;
     250   [ #  #  #  #  :          0 :             switch( nElement )
             #  #  #  # ]
     251                 :            :             {
     252                 :          0 :                 case XLS_TOKEN( m ):                                                        break;
     253         [ #  # ]:          0 :                 case XLS_TOKEN( s ):    aItem.readString( rAttribs );                       break;
     254         [ #  # ]:          0 :                 case XLS_TOKEN( n ):    aItem.readNumeric( rAttribs );                      break;
     255         [ #  # ]:          0 :                 case XLS_TOKEN( d ):    aItem.readDate( rAttribs );                         break;
     256         [ #  # ]:          0 :                 case XLS_TOKEN( b ):    aItem.readBool( rAttribs );                         break;
     257 [ #  # ][ #  # ]:          0 :                 case XLS_TOKEN( e ):    aItem.readError( rAttribs, getUnitConverter() );    break;
     258         [ #  # ]:          0 :                 case XLS_TOKEN( x ):    aItem.readIndex( rAttribs );                        break;
     259                 :            :                 default:    OSL_FAIL( "OoxPivotCacheRecordsFragment::onCreateContext - unexpected element" );
     260                 :            :             }
     261         [ #  # ]:          0 :             mrPivotCache.writeSourceDataCell( *this, mnColIdx, mnRowIdx, aItem );
     262                 :          0 :             ++mnColIdx;
     263                 :            :         }
     264                 :          0 :         break;
     265                 :            :     }
     266                 :          0 :     return 0;
     267                 :            : }
     268                 :            : 
     269                 :          0 : ContextHandlerRef PivotCacheRecordsFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
     270                 :            : {
     271      [ #  #  # ]:          0 :     switch( getCurrentElement() )
     272                 :            :     {
     273                 :            :         case XML_ROOT_CONTEXT:
     274         [ #  # ]:          0 :             if( nRecId == BIFF12_ID_PCRECORDS ) return this;
     275                 :          0 :         break;
     276                 :            : 
     277                 :            :         case BIFF12_ID_PCRECORDS:
     278      [ #  #  # ]:          0 :             switch( nRecId )
     279                 :            :             {
     280                 :          0 :                 case BIFF12_ID_PCRECORD:    importPCRecord( rStrm );                break;
     281                 :          0 :                 case BIFF12_ID_PCRECORDDT:  startCacheRecord();                     break;
     282                 :          0 :                 default:                    importPCRecordItem( nRecId, rStrm );    break;
     283                 :            :             }
     284                 :          0 :         break;
     285                 :            :     }
     286                 :          0 :     return 0;
     287                 :            : }
     288                 :            : 
     289                 :          0 : const RecordInfo* PivotCacheRecordsFragment::getRecordInfos() const
     290                 :            : {
     291                 :            :     static const RecordInfo spRecInfos[] =
     292                 :            :     {
     293                 :            :         { BIFF12_ID_PCRECORDS,  BIFF12_ID_PCRECORDS + 1 },
     294                 :            :         { -1,                   -1                      }
     295                 :            :     };
     296                 :          0 :     return spRecInfos;
     297                 :            : }
     298                 :            : 
     299                 :            : // private --------------------------------------------------------------------
     300                 :            : 
     301                 :          0 : void PivotCacheRecordsFragment::startCacheRecord()
     302                 :            : {
     303                 :          0 :     mnColIdx = 0;
     304                 :          0 :     ++mnRowIdx;
     305                 :          0 :     mbInRecord = true;
     306                 :          0 : }
     307                 :            : 
     308                 :          0 : void PivotCacheRecordsFragment::importPCRecord( SequenceInputStream& rStrm )
     309                 :            : {
     310                 :          0 :     startCacheRecord();
     311                 :          0 :     mrPivotCache.importPCRecord( rStrm, *this, mnRowIdx );
     312                 :          0 :     mbInRecord = false;
     313                 :          0 : }
     314                 :            : 
     315                 :          0 : void PivotCacheRecordsFragment::importPCRecordItem( sal_Int32 nRecId, SequenceInputStream& rStrm )
     316                 :            : {
     317         [ #  # ]:          0 :     if( mbInRecord )
     318                 :            :     {
     319         [ #  # ]:          0 :         PivotCacheItem aItem;
     320   [ #  #  #  #  :          0 :         switch( nRecId )
             #  #  #  # ]
     321                 :            :         {
     322                 :          0 :             case BIFF12_ID_PCITEM_MISSING:                              break;
     323         [ #  # ]:          0 :             case BIFF12_ID_PCITEM_STRING:   aItem.readString( rStrm );  break;
     324         [ #  # ]:          0 :             case BIFF12_ID_PCITEM_DOUBLE:   aItem.readDouble( rStrm );  break;
     325         [ #  # ]:          0 :             case BIFF12_ID_PCITEM_DATE:     aItem.readDate( rStrm );    break;
     326         [ #  # ]:          0 :             case BIFF12_ID_PCITEM_BOOL:     aItem.readBool( rStrm );    break;
     327         [ #  # ]:          0 :             case BIFF12_ID_PCITEM_ERROR:    aItem.readError( rStrm );   break;
     328         [ #  # ]:          0 :             case BIFF12_ID_PCITEM_INDEX:    aItem.readIndex( rStrm );   break;
     329                 :            :             default:    OSL_FAIL( "OoxPivotCacheRecordsFragment::importPCRecordItem - unexpected record" );
     330                 :            :         }
     331         [ #  # ]:          0 :         mrPivotCache.writeSourceDataCell( *this, mnColIdx, mnRowIdx, aItem );
     332                 :          0 :         ++mnColIdx;
     333                 :            :     }
     334                 :          0 : }
     335                 :            : 
     336                 :            : // ============================================================================
     337                 :            : // ============================================================================
     338                 :            : 
     339                 :            : namespace {
     340                 :            : 
     341                 :          0 : bool lclSeekToPCDField( BiffInputStream& rStrm )
     342                 :            : {
     343                 :          0 :     sal_Int64 nRecHandle = rStrm.getRecHandle();
     344         [ #  # ]:          0 :     while( rStrm.startNextRecord() )
     345         [ #  # ]:          0 :         if( rStrm.getRecId() == BIFF_ID_PCDFIELD )
     346                 :          0 :             return true;
     347                 :          0 :     rStrm.startRecordByHandle( nRecHandle );
     348                 :          0 :     return false;
     349                 :            : }
     350                 :            : 
     351                 :            : } // namespace
     352                 :            : 
     353                 :            : // ----------------------------------------------------------------------------
     354                 :            : 
     355                 :          0 : BiffPivotCacheFragment::BiffPivotCacheFragment(
     356                 :            :         const WorkbookHelper& rHelper, const OUString& rStrmName, PivotCache& rPivotCache ) :
     357                 :            :     BiffWorkbookFragmentBase( rHelper, rStrmName, true ),
     358                 :          0 :     mrPivotCache( rPivotCache )
     359                 :            : {
     360                 :          0 : }
     361                 :            : 
     362                 :          0 : bool BiffPivotCacheFragment::importFragment()
     363                 :            : {
     364                 :          0 :     BiffInputStream& rStrm = getInputStream();
     365 [ #  # ][ #  # ]:          0 :     if( rStrm.startNextRecord() && (rStrm.getRecId() == BIFF_ID_PCDEFINITION) )
                 [ #  # ]
     366                 :            :     {
     367                 :            :         // read PCDEFINITION and optional PCDEFINITION2 records
     368                 :          0 :         mrPivotCache.importPCDefinition( rStrm );
     369                 :            : 
     370                 :            :         // read cache fields as long as another PCDFIELD record can be found
     371         [ #  # ]:          0 :         while( lclSeekToPCDField( rStrm ) )
     372                 :          0 :             mrPivotCache.createCacheField( true ).importPCDField( rStrm );
     373                 :            : 
     374                 :            :         // finalize the cache (check source range etc.)
     375                 :          0 :         mrPivotCache.finalizeImport();
     376                 :            : 
     377                 :            :         // load the cache records, if the cache is based on a deleted or an external worksheet
     378 [ #  # ][ #  # ]:          0 :         if( mrPivotCache.isValidDataSource() && mrPivotCache.isBasedOnDummySheet() )
                 [ #  # ]
     379                 :            :         {
     380                 :            :             /*  Last call of lclSeekToPCDField() failed and kept stream position
     381                 :            :                 unchanged. Stream should point to source data table now. */
     382                 :          0 :             sal_Int16 nSheet = mrPivotCache.getSourceRange().Sheet;
     383 [ #  # ][ #  # ]:          0 :             WorksheetGlobalsRef xSheetGlob = WorksheetHelper::constructGlobals( *this, ISegmentProgressBarRef(), SHEETTYPE_WORKSHEET, nSheet );
                 [ #  # ]
     384         [ #  # ]:          0 :             if( xSheetGlob.get() )
     385                 :            :             {
     386 [ #  # ][ #  # ]:          0 :                 BiffPivotCacheRecordsContext aContext( *xSheetGlob, mrPivotCache );
                 [ #  # ]
     387 [ #  # ][ #  # ]:          0 :                 while( rStrm.startNextRecord() && (rStrm.getRecId() != BIFF_ID_EOF) )
         [ #  # ][ #  # ]
     388 [ #  # ][ #  # ]:          0 :                     aContext.importRecord( rStrm );
     389         [ #  # ]:          0 :             }
     390                 :            :         }
     391                 :            :     }
     392                 :            : 
     393                 :          0 :     return rStrm.getRecId() == BIFF_ID_EOF;
     394                 :            : }
     395                 :            : 
     396                 :            : // ============================================================================
     397                 :            : 
     398                 :          0 : BiffPivotCacheRecordsContext::BiffPivotCacheRecordsContext( const WorksheetHelper& rHelper, const PivotCache& rPivotCache ) :
     399                 :            :     BiffWorksheetContextBase( rHelper ),
     400                 :            :     mrPivotCache( rPivotCache ),
     401                 :            :     mnColIdx( 0 ),
     402                 :            :     mnRowIdx( 0 ),
     403                 :            :     mbHasShared( false ),
     404         [ #  # ]:          0 :     mbInRow( false )
     405                 :            : {
     406                 :            :     // prepare sheet: insert column header names into top row
     407         [ #  # ]:          0 :     mrPivotCache.writeSourceHeaderCells( *this );
     408                 :            : 
     409                 :            :     // find all fields without shared items, remember column indexes in source data
     410 [ #  # ][ #  # ]:          0 :     for( sal_Int32 nFieldIdx = 0, nFieldCount = mrPivotCache.getCacheFieldCount(), nCol = 0; nFieldIdx < nFieldCount; ++nFieldIdx )
     411                 :            :     {
     412         [ #  # ]:          0 :         const PivotCacheField* pCacheField = mrPivotCache.getCacheField( nFieldIdx );
     413 [ #  # ][ #  # ]:          0 :         if( pCacheField && pCacheField->isDatabaseField() )
                 [ #  # ]
     414                 :            :         {
     415         [ #  # ]:          0 :             if( pCacheField->hasSharedItems() )
     416                 :          0 :                 mbHasShared = true;
     417                 :            :             else
     418         [ #  # ]:          0 :                 maUnsharedCols.push_back( nCol );
     419                 :          0 :             ++nCol;
     420                 :            :         }
     421                 :            :     }
     422                 :          0 : }
     423                 :            : 
     424                 :          0 : void BiffPivotCacheRecordsContext::importRecord( BiffInputStream& rStrm )
     425                 :            : {
     426         [ #  # ]:          0 :     if( rStrm.getRecId() == BIFF_ID_PCITEM_INDEXLIST )
     427                 :            :     {
     428                 :            :         OSL_ENSURE( mbHasShared, "BiffPivotCacheRecordsContext::importRecord - unexpected PCITEM_INDEXLIST record" );
     429                 :            :         // PCITEM_INDEXLIST record always in front of a new data row
     430                 :          0 :         startNextRow();
     431         [ #  # ]:          0 :         mrPivotCache.importPCItemIndexList( rStrm, *this, mnRowIdx );
     432                 :          0 :         mbInRow = !maUnsharedCols.empty();  // mbInRow remains true, if unshared items are expected
     433                 :            :         return;
     434                 :            :     }
     435                 :            : 
     436         [ #  # ]:          0 :     PivotCacheItem aItem;
     437   [ #  #  #  #  :          0 :     switch( rStrm.getRecId() )
             #  #  #  # ]
     438                 :            :     {
     439                 :          0 :         case BIFF_ID_PCITEM_MISSING:                                        break;
     440         [ #  # ]:          0 :         case BIFF_ID_PCITEM_STRING:     aItem.readString( rStrm, *this );   break;
     441         [ #  # ]:          0 :         case BIFF_ID_PCITEM_DOUBLE:     aItem.readDouble( rStrm );          break;
     442         [ #  # ]:          0 :         case BIFF_ID_PCITEM_INTEGER:    aItem.readInteger( rStrm );         break;
     443         [ #  # ]:          0 :         case BIFF_ID_PCITEM_DATE:       aItem.readDate( rStrm );            break;
     444         [ #  # ]:          0 :         case BIFF_ID_PCITEM_BOOL:       aItem.readBool( rStrm );            break;
     445         [ #  # ]:          0 :         case BIFF_ID_PCITEM_ERROR:      aItem.readError( rStrm );           break;
     446                 :            :         default:                        return; // unknown record, ignore
     447                 :            :     }
     448                 :            : 
     449                 :            :     // find next column index, might start new row if no fields with shared items exist
     450 [ #  # ][ #  # ]:          0 :     if( mbInRow && (mnColIdx == maUnsharedCols.size()) )
                 [ #  # ]
     451                 :            :     {
     452                 :            :         OSL_ENSURE( !mbHasShared, "BiffPivotCacheRecordsContext::importRecord - PCITEM_INDEXLIST record missing" );
     453                 :          0 :         mbInRow = mbHasShared;  // do not leave current row if PCITEM_INDEXLIST is expected
     454                 :            :     }
     455                 :            :     // start next row on first call, or on row wrap without shared items
     456         [ #  # ]:          0 :     if( !mbInRow )
     457                 :          0 :         startNextRow();
     458                 :            : 
     459                 :            :     // write the item data to the sheet cell
     460                 :            :     OSL_ENSURE( mnColIdx < maUnsharedCols.size(), "BiffPivotCacheRecordsContext::importRecord - invalid column index" );
     461         [ #  # ]:          0 :     if( mnColIdx < maUnsharedCols.size() )
     462 [ #  # ][ #  # ]:          0 :         mrPivotCache.writeSourceDataCell( *this, maUnsharedCols[ mnColIdx ], mnRowIdx, aItem );
     463         [ #  # ]:          0 :     ++mnColIdx;
     464                 :            : }
     465                 :            : 
     466                 :          0 : void BiffPivotCacheRecordsContext::startNextRow()
     467                 :            : {
     468                 :          0 :     mnColIdx = 0;
     469                 :          0 :     ++mnRowIdx;
     470                 :          0 :     mbInRow = true;
     471                 :          0 : }
     472                 :            : 
     473                 :            : // ============================================================================
     474                 :            : 
     475                 :            : } // namespace xls
     476 [ +  - ][ +  - ]:         24 : } // namespace oox
     477                 :            : 
     478                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10