LCOV - code coverage report
Current view: top level - sc/source/filter/oox - worksheetfragment.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 123 371 33.2 %
Date: 2014-04-11 Functions: 15 38 39.5 %
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             : #include "worksheetfragment.hxx"
      21             : 
      22             : #include "oox/core/filterbase.hxx"
      23             : #include "oox/core/relations.hxx"
      24             : #include "oox/helper/attributelist.hxx"
      25             : #include "addressconverter.hxx"
      26             : #include "autofilterbuffer.hxx"
      27             : #include "autofiltercontext.hxx"
      28             : #include "biffinputstream.hxx"
      29             : #include "commentsfragment.hxx"
      30             : #include "condformatcontext.hxx"
      31             : #include "drawingfragment.hxx"
      32             : #include "drawingmanager.hxx"
      33             : #include "externallinkbuffer.hxx"
      34             : #include "pagesettings.hxx"
      35             : #include "pivottablefragment.hxx"
      36             : #include "querytablefragment.hxx"
      37             : #include "scenariobuffer.hxx"
      38             : #include "scenariocontext.hxx"
      39             : #include "sheetdatabuffer.hxx"
      40             : #include "sheetdatacontext.hxx"
      41             : #include "tablefragment.hxx"
      42             : #include "extlstcontext.hxx"
      43             : #include "viewsettings.hxx"
      44             : #include "workbooksettings.hxx"
      45             : #include "worksheetsettings.hxx"
      46             : 
      47             : namespace oox {
      48             : namespace xls {
      49             : 
      50             : using namespace ::com::sun::star::table;
      51             : using namespace ::com::sun::star::uno;
      52             : using namespace ::oox::core;
      53             : 
      54             : 
      55             : namespace {
      56             : 
      57             : const sal_uInt16 BIFF_COLINFO_HIDDEN        = 0x0001;
      58             : const sal_uInt16 BIFF_COLINFO_SHOWPHONETIC  = 0x0008;
      59             : const sal_uInt16 BIFF_COLINFO_COLLAPSED     = 0x1000;
      60             : 
      61             : const sal_uInt16 BIFF_DEFROW_CUSTOMHEIGHT   = 0x0001;
      62             : const sal_uInt16 BIFF_DEFROW_HIDDEN         = 0x0002;
      63             : const sal_uInt16 BIFF_DEFROW_THICKTOP       = 0x0004;
      64             : const sal_uInt16 BIFF_DEFROW_THICKBOTTOM    = 0x0008;
      65             : 
      66             : const sal_uInt32 BIFF_DATAVAL_STRINGLIST    = 0x00000080;
      67             : const sal_uInt32 BIFF_DATAVAL_ALLOWBLANK    = 0x00000100;
      68             : const sal_uInt32 BIFF_DATAVAL_NODROPDOWN    = 0x00000200;
      69             : const sal_uInt32 BIFF_DATAVAL_SHOWINPUT     = 0x00040000;
      70             : const sal_uInt32 BIFF_DATAVAL_SHOWERROR     = 0x00080000;
      71             : 
      72             : const sal_Int32 BIFF12_OLEOBJECT_ICON       = 4;
      73             : const sal_Int32 BIFF12_OLEOBJECT_ALWAYS     = 1;
      74             : const sal_uInt16 BIFF12_OLEOBJECT_LINKED    = 0x0001;
      75             : const sal_uInt16 BIFF12_OLEOBJECT_AUTOLOAD  = 0x0002;
      76             : 
      77             : } // namespace
      78             : 
      79           0 : DataValidationsContext::DataValidationsContext( WorksheetFragmentBase& rFragment ) :
      80           0 :     WorksheetContextBase( rFragment )
      81             : {
      82           0 : }
      83             : 
      84           0 : ContextHandlerRef DataValidationsContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
      85             : {
      86           0 :     switch( getCurrentElement() )
      87             :     {
      88             :         case XLS_TOKEN( dataValidations ):
      89           0 :             if( nElement == XLS_TOKEN( dataValidation ) )
      90             :             {
      91           0 :                 importDataValidation( rAttribs );
      92           0 :                 return this;
      93             :             }
      94           0 :         break;
      95             :         case XLS_TOKEN( dataValidation ):
      96           0 :             switch( nElement )
      97             :             {
      98             :                 case XLS_TOKEN( formula1 ):
      99             :                 case XLS_TOKEN( formula2 ):
     100           0 :                     return this;    // collect formulas in onCharacters()
     101             :             }
     102           0 :         break;
     103             :     }
     104           0 :     return 0;
     105             : }
     106             : 
     107           0 : void DataValidationsContext::onCharacters( const OUString& rChars )
     108             : {
     109           0 :     if( mxValModel.get() ) switch( getCurrentElement() )
     110             :     {
     111             :         case XLS_TOKEN( formula1 ):
     112           0 :             mxValModel->maTokens1 = getFormulaParser().importFormula( mxValModel->maRanges.getBaseAddress(), rChars );
     113             :             // process string list of a list validation (convert to list of string tokens)
     114           0 :             if( mxValModel->mnType == XML_list )
     115           0 :                 getFormulaParser().convertStringToStringList( mxValModel->maTokens1, ',', true );
     116           0 :         break;
     117             :         case XLS_TOKEN( formula2 ):
     118           0 :             mxValModel->maTokens2 = getFormulaParser().importFormula( mxValModel->maRanges.getBaseAddress(), rChars );
     119           0 :         break;
     120             :     }
     121           0 : }
     122             : 
     123           0 : void DataValidationsContext::onEndElement()
     124             : {
     125           0 :     if( isCurrentElement( XLS_TOKEN( dataValidation ) ) && mxValModel.get() )
     126             :     {
     127           0 :         setValidation( *mxValModel );
     128           0 :         mxValModel.reset();
     129             :     }
     130           0 : }
     131             : 
     132             : 
     133           0 : ContextHandlerRef DataValidationsContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
     134             : {
     135           0 :     if( nRecId == BIFF12_ID_DATAVALIDATION )
     136           0 :         importDataValidation( rStrm );
     137           0 :     return 0;
     138             : }
     139             : 
     140           0 : void DataValidationsContext::importDataValidation( const AttributeList& rAttribs )
     141             : {
     142           0 :     mxValModel.reset( new ValidationModel );
     143           0 :     getAddressConverter().convertToCellRangeList( mxValModel->maRanges, rAttribs.getString( XML_sqref, OUString() ), getSheetIndex(), true );
     144           0 :     mxValModel->msRef          = rAttribs.getString( XML_sqref, OUString() );
     145           0 :     mxValModel->maInputTitle   = rAttribs.getXString( XML_promptTitle, OUString() );
     146           0 :     mxValModel->maInputMessage = rAttribs.getXString( XML_prompt, OUString() );
     147           0 :     mxValModel->maErrorTitle   = rAttribs.getXString( XML_errorTitle, OUString() );
     148           0 :     mxValModel->maErrorMessage = rAttribs.getXString( XML_error, OUString() );
     149           0 :     mxValModel->mnType         = rAttribs.getToken( XML_type, XML_none );
     150           0 :     mxValModel->mnOperator     = rAttribs.getToken( XML_operator, XML_between );
     151           0 :     mxValModel->mnErrorStyle   = rAttribs.getToken( XML_errorStyle, XML_stop );
     152           0 :     mxValModel->mbShowInputMsg = rAttribs.getBool( XML_showInputMessage, false );
     153           0 :     mxValModel->mbShowErrorMsg = rAttribs.getBool( XML_showErrorMessage, false );
     154             :     /*  The attribute showDropDown@dataValidation is in fact a "suppress
     155             :         dropdown" flag, as it was in the BIFF format! ECMA specification
     156             :         and attribute name are plain wrong! */
     157           0 :     mxValModel->mbNoDropDown   = rAttribs.getBool( XML_showDropDown, false );
     158           0 :     mxValModel->mbAllowBlank   = rAttribs.getBool( XML_allowBlank, false );
     159           0 : }
     160             : 
     161           0 : void DataValidationsContext::importDataValidation( SequenceInputStream& rStrm )
     162             : {
     163           0 :     ValidationModel aModel;
     164             : 
     165             :     sal_uInt32 nFlags;
     166           0 :     BinRangeList aRanges;
     167           0 :     rStrm >> nFlags >> aRanges >> aModel.maErrorTitle >> aModel.maErrorMessage >> aModel.maInputTitle >> aModel.maInputMessage;
     168             : 
     169             :     // equal flags in all BIFFs
     170           0 :     aModel.setBiffType( extractValue< sal_uInt8 >( nFlags, 0, 4 ) );
     171           0 :     aModel.setBiffOperator( extractValue< sal_uInt8 >( nFlags, 20, 4 ) );
     172           0 :     aModel.setBiffErrorStyle( extractValue< sal_uInt8 >( nFlags, 4, 3 ) );
     173           0 :     aModel.mbAllowBlank   = getFlag( nFlags, BIFF_DATAVAL_ALLOWBLANK );
     174           0 :     aModel.mbNoDropDown   = getFlag( nFlags, BIFF_DATAVAL_NODROPDOWN );
     175           0 :     aModel.mbShowInputMsg = getFlag( nFlags, BIFF_DATAVAL_SHOWINPUT );
     176           0 :     aModel.mbShowErrorMsg = getFlag( nFlags, BIFF_DATAVAL_SHOWERROR );
     177             : 
     178             :     // cell range list
     179           0 :     getAddressConverter().convertToCellRangeList( aModel.maRanges, aRanges, getSheetIndex(), true );
     180             : 
     181             :     // condition formula(s)
     182           0 :     FormulaParser& rParser = getFormulaParser();
     183           0 :     CellAddress aBaseAddr = aModel.maRanges.getBaseAddress();
     184           0 :     aModel.maTokens1 = rParser.importFormula( aBaseAddr, FORMULATYPE_VALIDATION, rStrm );
     185           0 :     aModel.maTokens2 = rParser.importFormula( aBaseAddr, FORMULATYPE_VALIDATION, rStrm );
     186             :     // process string list of a list validation (convert to list of string tokens)
     187           0 :     if( (aModel.mnType == XML_list) && getFlag( nFlags, BIFF_DATAVAL_STRINGLIST ) )
     188           0 :         rParser.convertStringToStringList( aModel.maTokens1, ',', true );
     189             : 
     190             :     // set validation data
     191           0 :     setValidation( aModel );
     192           0 : }
     193             : 
     194          85 : WorksheetFragment::WorksheetFragment( const WorksheetHelper& rHelper, const OUString& rFragmentPath ) :
     195          85 :     WorksheetFragmentBase( rHelper, rFragmentPath )
     196             : {
     197             :     // import data tables related to this worksheet
     198          85 :     RelationsRef xTableRels = getRelations().getRelationsFromTypeFromOfficeDoc( "table" );
     199          85 :     for( Relations::const_iterator aIt = xTableRels->begin(), aEnd = xTableRels->end(); aIt != aEnd; ++aIt )
     200           0 :         importOoxFragment( new TableFragment( *this, getFragmentPathFromRelation( aIt->second ) ) );
     201             : 
     202             :     // import comments related to this worksheet
     203         170 :     OUString aCommentsFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( "comments" );
     204          85 :     if( !aCommentsFragmentPath.isEmpty() )
     205          86 :         importOoxFragment( new CommentsFragment( *this, aCommentsFragmentPath ) );
     206          85 : }
     207             : 
     208        1258 : ContextHandlerRef WorksheetFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
     209             : {
     210        1258 :     switch( getCurrentElement() )
     211             :     {
     212          85 :         case XML_ROOT_CONTEXT: switch( getSheetType() )
     213             :         {
     214          85 :             case SHEETTYPE_WORKSHEET:   return (nElement == XLS_TOKEN( worksheet )) ? this : 0;
     215           0 :             case SHEETTYPE_CHARTSHEET:  return 0;
     216           0 :             case SHEETTYPE_MACROSHEET:  return (nElement == XM_TOKEN( macrosheet )) ? this : 0;
     217           0 :             case SHEETTYPE_DIALOGSHEET: return (nElement == XLS_TOKEN( dialogsheet )) ? this : 0;
     218           0 :             case SHEETTYPE_MODULESHEET: return 0;
     219           0 :             case SHEETTYPE_EMPTYSHEET:  return 0;
     220             :         }
     221           0 :         break;
     222             : 
     223             :         case XLS_TOKEN( worksheet ):
     224             :         case XM_TOKEN( macrosheet ):
     225             :         case XLS_TOKEN( dialogsheet ):
     226         754 :             switch( nElement )
     227             :             {
     228          85 :                 case XLS_TOKEN( sheetData ):                return new SheetDataContext( *this );
     229          47 :                 case XLS_TOKEN( conditionalFormatting ):    return new CondFormatContext( *this );
     230           0 :                 case XLS_TOKEN( dataValidations ):          return new DataValidationsContext( *this );
     231           1 :                 case XLS_TOKEN( autoFilter ):               return new AutoFilterContext( *this, getAutoFilters().createAutoFilter() );
     232           0 :                 case XLS_TOKEN( scenarios ):                return new ScenariosContext( *this );
     233           1 :                 case XLS_TOKEN( extLst ):                   return new ExtLstGlobalContext( *this );
     234             : 
     235             :                 case XLS_TOKEN( sheetViews ):
     236             :                 case XLS_TOKEN( cols ):
     237             :                 case XLS_TOKEN( mergeCells ):
     238             :                 case XLS_TOKEN( hyperlinks ):
     239             :                 case XLS_TOKEN( rowBreaks ):
     240             :                 case XLS_TOKEN( colBreaks ):
     241             :                 case XLS_TOKEN( oleObjects ):
     242         144 :                 case XLS_TOKEN( controls ):         return this;
     243             : 
     244          53 :                 case XLS_TOKEN( sheetPr ):          getWorksheetSettings().importSheetPr( rAttribs );               return this;
     245          85 :                 case XLS_TOKEN( dimension ):        importDimension( rAttribs );                                    break;
     246          73 :                 case XLS_TOKEN( sheetFormatPr ):    importSheetFormatPr( rAttribs );                                break;
     247           4 :                 case XLS_TOKEN( sheetProtection ):  getWorksheetSettings().importSheetProtection( rAttribs );       break;
     248           1 :                 case XLS_TOKEN( protectedRanges ):  getWorksheetSettings().importProtectedRanges( rAttribs );       return this;
     249           6 :                 case XLS_TOKEN( phoneticPr ):       getWorksheetSettings().importPhoneticPr( rAttribs );            break;
     250          44 :                 case XLS_TOKEN( printOptions ):     getPageSettings().importPrintOptions( rAttribs );               break;
     251          85 :                 case XLS_TOKEN( pageMargins ):      getPageSettings().importPageMargins( rAttribs );                break;
     252          54 :                 case XLS_TOKEN( pageSetup ):        getPageSettings().importPageSetup( getRelations(), rAttribs );  break;
     253          52 :                 case XLS_TOKEN( headerFooter ):     getPageSettings().importHeaderFooter( rAttribs );               return this;
     254           0 :                 case XLS_TOKEN( picture ):          getPageSettings().importPicture( getRelations(), rAttribs );    break;
     255          16 :                 case XLS_TOKEN( drawing ):          importDrawing( rAttribs );                                      break;
     256           3 :                 case XLS_TOKEN( legacyDrawing ):    importLegacyDrawing( rAttribs );                                break;
     257             :             }
     258         370 :         break;
     259             : 
     260             :         case XLS_TOKEN( sheetPr ):
     261          75 :             switch( nElement )
     262             :             {
     263          32 :                 case XLS_TOKEN( tabColor ):         getWorksheetSettings().importTabColor( rAttribs );              break;
     264           0 :                 case XLS_TOKEN( outlinePr ):        getWorksheetSettings().importOutlinePr( rAttribs );             break;
     265          43 :                 case XLS_TOKEN( pageSetUpPr ):      importPageSetUpPr( rAttribs );                                  break;
     266             :             }
     267          75 :         break;
     268             : 
     269             :         case XLS_TOKEN( sheetViews ):
     270          85 :             switch( nElement )
     271             :             {
     272          85 :                 case XLS_TOKEN( sheetView ):        getSheetViewSettings().importSheetView( rAttribs );             return this;
     273             :             }
     274           0 :         break;
     275             :         case XLS_TOKEN( sheetView ):
     276          67 :             switch( nElement )
     277             :             {
     278           0 :                 case XLS_TOKEN( pane ):             getSheetViewSettings().importPane( rAttribs );                  break;
     279          67 :                 case XLS_TOKEN( selection ):        getSheetViewSettings().importSelection( rAttribs );             break;
     280             :             }
     281          67 :         break;
     282             : 
     283             :         case XLS_TOKEN( cols ):
     284          89 :             if( nElement == XLS_TOKEN( col ) ) importCol( rAttribs );
     285          89 :         break;
     286             :         case XLS_TOKEN( mergeCells ):
     287           2 :             if( nElement == XLS_TOKEN( mergeCell ) ) importMergeCell( rAttribs );
     288           2 :         break;
     289             :         case XLS_TOKEN( hyperlinks ):
     290           3 :             if( nElement == XLS_TOKEN( hyperlink ) ) importHyperlink( rAttribs );
     291           3 :         break;
     292             :         case XLS_TOKEN( rowBreaks ):
     293           0 :             if( nElement == XLS_TOKEN( brk ) ) importBrk( rAttribs, true );
     294           0 :         break;
     295             :         case XLS_TOKEN( colBreaks ):
     296           0 :             if( nElement == XLS_TOKEN( brk ) ) importBrk( rAttribs, false );
     297           0 :         break;
     298             : 
     299             :         case XLS_TOKEN( protectedRanges ):
     300           5 :             switch( nElement )
     301             :             {
     302           5 :                 case XLS_TOKEN( protectedRange ):   getWorksheetSettings().importProtectedRange( rAttribs );    return this;
     303             :             }
     304           0 :         break;
     305             : 
     306             :         case XLS_TOKEN( headerFooter ):
     307          92 :             switch( nElement )
     308             :             {
     309             :                 case XLS_TOKEN( firstHeader ):
     310             :                 case XLS_TOKEN( firstFooter ):
     311             :                 case XLS_TOKEN( oddHeader ):
     312             :                 case XLS_TOKEN( oddFooter ):
     313             :                 case XLS_TOKEN( evenHeader ):
     314          92 :                 case XLS_TOKEN( evenFooter ):       return this;    // collect h/f contents in onCharacters()
     315             :             }
     316           0 :         break;
     317             :         // Only process an oleObject or control if outside a mc:AlternateContent
     318             :         // element OR if within a mc:Fallback. I suppose ideally we
     319             :         // should process the stuff within 'mc:Choice'
     320             :         case XLS_TOKEN( controls ):
     321             :         case XLS_TOKEN( oleObjects ):
     322           1 :             if ( getCurrentElement() == XLS_TOKEN( controls ) )
     323             :             {
     324           1 :                 if( aMceState.empty() || ( !aMceState.empty() && aMceState.back() == MCE_STARTED ) )
     325             :                 {
     326           0 :                     if ( getCurrentElement() == XLS_TOKEN( oleObjects ) ) importOleObject( rAttribs );
     327             :                     else
     328           0 :                         importControl( rAttribs );
     329             :                 }
     330           1 :                 else if ( !aMceState.empty() && aMceState.back() == MCE_FOUND_CHOICE )
     331             :                 {
     332             :                     // reset the handling within 'Choice'
     333             :                     // this will force attempted handling in Fallback
     334           1 :                     aMceState.back() = MCE_STARTED;
     335             :                 }
     336             :             }
     337           1 :         break;
     338             :     }
     339         607 :     return 0;
     340             : }
     341             : 
     342          56 : void WorksheetFragment::onCharacters( const OUString& rChars )
     343             : {
     344          56 :     switch( getCurrentElement() )
     345             :     {
     346             :         case XLS_TOKEN( firstHeader ):
     347             :         case XLS_TOKEN( firstFooter ):
     348             :         case XLS_TOKEN( oddHeader ):
     349             :         case XLS_TOKEN( oddFooter ):
     350             :         case XLS_TOKEN( evenHeader ):
     351             :         case XLS_TOKEN( evenFooter ):
     352          56 :             getPageSettings().importHeaderFooterCharacters( rChars, getCurrentElement() );
     353          56 :         break;
     354             :     }
     355          56 : }
     356             : 
     357           0 : ContextHandlerRef WorksheetFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
     358             : {
     359           0 :     switch( getCurrentElement() )
     360             :     {
     361             :         case XML_ROOT_CONTEXT:
     362           0 :             if( nRecId == BIFF12_ID_WORKSHEET ) return this;
     363           0 :         break;
     364             : 
     365             :         case BIFF12_ID_WORKSHEET:
     366           0 :             switch( nRecId )
     367             :             {
     368           0 :                 case BIFF12_ID_SHEETDATA:       return new SheetDataContext( *this );
     369           0 :                 case BIFF12_ID_CONDFORMATTING:  return new CondFormatContext( *this );
     370           0 :                 case BIFF12_ID_DATAVALIDATIONS: return new DataValidationsContext( *this );
     371           0 :                 case BIFF12_ID_AUTOFILTER:      return new AutoFilterContext( *this, getAutoFilters().createAutoFilter() );
     372           0 :                 case BIFF12_ID_SCENARIOS:       return new ScenariosContext( *this );
     373             : 
     374             :                 case BIFF12_ID_SHEETVIEWS:
     375             :                 case BIFF12_ID_COLS:
     376             :                 case BIFF12_ID_MERGECELLS:
     377             :                 case BIFF12_ID_ROWBREAKS:
     378             :                 case BIFF12_ID_COLBREAKS:
     379             :                 case BIFF12_ID_OLEOBJECTS:
     380           0 :                 case BIFF12_ID_CONTROLS:        return this;
     381             : 
     382           0 :                 case BIFF12_ID_SHEETPR:         getWorksheetSettings().importSheetPr( rStrm );              break;
     383           0 :                 case BIFF12_ID_DIMENSION:       importDimension( rStrm );                                   break;
     384           0 :                 case BIFF12_ID_SHEETFORMATPR:   importSheetFormatPr( rStrm );                               break;
     385           0 :                 case BIFF12_ID_HYPERLINK:       importHyperlink( rStrm );                                   break;
     386           0 :                 case BIFF12_ID_PAGEMARGINS:     getPageSettings().importPageMargins( rStrm );               break;
     387           0 :                 case BIFF12_ID_PAGESETUP:       getPageSettings().importPageSetup( getRelations(), rStrm ); break;
     388           0 :                 case BIFF12_ID_PRINTOPTIONS:    getPageSettings().importPrintOptions( rStrm );              break;
     389           0 :                 case BIFF12_ID_HEADERFOOTER:    getPageSettings().importHeaderFooter( rStrm );              break;
     390           0 :                 case BIFF12_ID_PICTURE:         getPageSettings().importPicture( getRelations(), rStrm );   break;
     391           0 :                 case BIFF12_ID_SHEETPROTECTION: getWorksheetSettings().importSheetProtection( rStrm );      break;
     392           0 :                 case BIFF12_ID_PHONETICPR:      getWorksheetSettings().importPhoneticPr( rStrm );           break;
     393           0 :                 case BIFF12_ID_DRAWING:         importDrawing( rStrm );                                     break;
     394           0 :                 case BIFF12_ID_LEGACYDRAWING:   importLegacyDrawing( rStrm );                               break;
     395             :             }
     396           0 :         break;
     397             : 
     398             :         case BIFF12_ID_SHEETVIEWS:
     399           0 :             switch( nRecId )
     400             :             {
     401           0 :                 case BIFF12_ID_SHEETVIEW:       getSheetViewSettings().importSheetView( rStrm );            return this;
     402             :             }
     403           0 :         break;
     404             :         case BIFF12_ID_SHEETVIEW:
     405           0 :             switch( nRecId )
     406             :             {
     407           0 :                 case BIFF12_ID_PANE:            getSheetViewSettings().importPane( rStrm );                 break;
     408           0 :                 case BIFF12_ID_SELECTION:       getSheetViewSettings().importSelection( rStrm );            break;
     409             :             }
     410           0 :         break;
     411             : 
     412             :         case BIFF12_ID_COLS:
     413           0 :             if( nRecId == BIFF12_ID_COL ) importCol( rStrm );
     414           0 :         break;
     415             :         case BIFF12_ID_MERGECELLS:
     416           0 :             if( nRecId == BIFF12_ID_MERGECELL ) importMergeCell( rStrm );
     417           0 :         break;
     418             :         case BIFF12_ID_ROWBREAKS:
     419           0 :             if( nRecId == BIFF12_ID_BRK ) importBrk( rStrm, true );
     420           0 :         break;
     421             :         case BIFF12_ID_COLBREAKS:
     422           0 :             if( nRecId == BIFF12_ID_BRK ) importBrk( rStrm, false );
     423           0 :         break;
     424             :         case BIFF12_ID_OLEOBJECTS:
     425           0 :             if( nRecId == BIFF12_ID_OLEOBJECT ) importOleObject( rStrm );
     426           0 :         break;
     427             :         case BIFF12_ID_CONTROLS:
     428           0 :             if( nRecId == BIFF12_ID_CONTROL ) importControl( rStrm );
     429           0 :         break;
     430             :     }
     431           0 :     return 0;
     432             : }
     433             : 
     434           0 : const RecordInfo* WorksheetFragment::getRecordInfos() const
     435             : {
     436             :     static const RecordInfo spRecInfos[] =
     437             :     {
     438             :         { BIFF12_ID_AUTOFILTER,         BIFF12_ID_AUTOFILTER + 1        },
     439             :         { BIFF12_ID_CFRULE,             BIFF12_ID_CFRULE + 1            },
     440             :         { BIFF12_ID_COLBREAKS,          BIFF12_ID_COLBREAKS + 1         },
     441             :         { BIFF12_ID_COLORSCALE,         BIFF12_ID_COLORSCALE + 1        },
     442             :         { BIFF12_ID_COLS,               BIFF12_ID_COLS + 1              },
     443             :         { BIFF12_ID_CONDFORMATTING,     BIFF12_ID_CONDFORMATTING + 1    },
     444             :         { BIFF12_ID_CONTROLS,           BIFF12_ID_CONTROLS + 2          },
     445             :         { BIFF12_ID_CUSTOMFILTERS,      BIFF12_ID_CUSTOMFILTERS + 1     },
     446             :         { BIFF12_ID_CUSTOMSHEETVIEW,    BIFF12_ID_CUSTOMSHEETVIEW + 1   },
     447             :         { BIFF12_ID_CUSTOMSHEETVIEWS,   BIFF12_ID_CUSTOMSHEETVIEWS + 3  },
     448             :         { BIFF12_ID_DATABAR,            BIFF12_ID_DATABAR + 1           },
     449             :         { BIFF12_ID_DATAVALIDATIONS,    BIFF12_ID_DATAVALIDATIONS + 1   },
     450             :         { BIFF12_ID_DISCRETEFILTERS,    BIFF12_ID_DISCRETEFILTERS + 1   },
     451             :         { BIFF12_ID_FILTERCOLUMN,       BIFF12_ID_FILTERCOLUMN + 1      },
     452             :         { BIFF12_ID_HEADERFOOTER,       BIFF12_ID_HEADERFOOTER + 1      },
     453             :         { BIFF12_ID_ICONSET,            BIFF12_ID_ICONSET + 1           },
     454             :         { BIFF12_ID_MERGECELLS,         BIFF12_ID_MERGECELLS + 1        },
     455             :         { BIFF12_ID_OLEOBJECTS,         BIFF12_ID_OLEOBJECTS + 2        },
     456             :         { BIFF12_ID_ROW,                -1                              },
     457             :         { BIFF12_ID_ROWBREAKS,          BIFF12_ID_ROWBREAKS + 1         },
     458             :         { BIFF12_ID_SCENARIO,           BIFF12_ID_SCENARIO + 1          },
     459             :         { BIFF12_ID_SCENARIOS,          BIFF12_ID_SCENARIOS + 1         },
     460             :         { BIFF12_ID_SHEETDATA,          BIFF12_ID_SHEETDATA + 1         },
     461             :         { BIFF12_ID_SHEETVIEW,          BIFF12_ID_SHEETVIEW + 1         },
     462             :         { BIFF12_ID_SHEETVIEWS,         BIFF12_ID_SHEETVIEWS + 1        },
     463             :         { BIFF12_ID_TABLEPARTS,         BIFF12_ID_TABLEPARTS + 2        },
     464             :         { BIFF12_ID_WORKSHEET,          BIFF12_ID_WORKSHEET + 1         },
     465             :         { -1,                           -1                              }
     466             :     };
     467           0 :     return spRecInfos;
     468             : }
     469             : 
     470          85 : void WorksheetFragment::initializeImport()
     471             : {
     472             :     // initial processing in base class WorksheetHelper
     473          85 :     initializeWorksheetImport();
     474             : 
     475             :     // import query table fragments related to this worksheet
     476          85 :     RelationsRef xQueryRels = getRelations().getRelationsFromTypeFromOfficeDoc( "queryTable" );
     477          85 :     for( Relations::const_iterator aIt = xQueryRels->begin(), aEnd = xQueryRels->end(); aIt != aEnd; ++aIt )
     478           0 :         importOoxFragment( new QueryTableFragment( *this, getFragmentPathFromRelation( aIt->second ) ) );
     479             : 
     480             :     // import pivot table fragments related to this worksheet
     481         170 :     RelationsRef xPivotRels = getRelations().getRelationsFromTypeFromOfficeDoc( "pivotTable" );
     482          85 :     for( Relations::const_iterator aIt = xPivotRels->begin(), aEnd = xPivotRels->end(); aIt != aEnd; ++aIt )
     483          85 :         importOoxFragment( new PivotTableFragment( *this, getFragmentPathFromRelation( aIt->second ) ) );
     484          85 : }
     485             : 
     486          85 : void WorksheetFragment::finalizeImport()
     487             : {
     488             :     // final processing in base class WorksheetHelper
     489          85 :     finalizeWorksheetImport();
     490          85 : }
     491             : 
     492             : // private --------------------------------------------------------------------
     493             : 
     494          43 : void WorksheetFragment::importPageSetUpPr( const AttributeList& rAttribs )
     495             : {
     496             :     // for whatever reason, this flag is still stored separated from the page settings
     497          43 :     getPageSettings().setFitToPagesMode( rAttribs.getBool( XML_fitToPage, false ) );
     498          43 : }
     499             : 
     500          85 : void WorksheetFragment::importDimension( const AttributeList& rAttribs )
     501             : {
     502          85 :     CellRangeAddress aRange;
     503          85 :     getAddressConverter().convertToCellRangeUnchecked( aRange, rAttribs.getString( XML_ref, OUString() ), getSheetIndex() );
     504             :     /*  OOXML stores the used area, if existing, or "A1" if the sheet is empty.
     505             :         In case of "A1", the dimension at the WorksheetHelper object will not
     506             :         be set. If the cell A1 exists, the used area will be updated while
     507             :         importing the cell. */
     508          85 :     if( (aRange.EndColumn > 0) || (aRange.EndRow > 0) )
     509             :     {
     510          59 :         extendUsedArea( aRange );
     511             :     }
     512          85 : }
     513             : 
     514          73 : void WorksheetFragment::importSheetFormatPr( const AttributeList& rAttribs )
     515             : {
     516             :     // default column settings
     517          73 :     setBaseColumnWidth( rAttribs.getInteger( XML_baseColWidth, 8 ) );
     518          73 :     setDefaultColumnWidth( rAttribs.getDouble( XML_defaultColWidth, 0.0 ) );
     519             :     // default row settings
     520             :     setDefaultRowSettings(
     521             :         rAttribs.getDouble( XML_defaultRowHeight, 0.0 ),
     522          73 :         rAttribs.getBool( XML_customHeight, false ),
     523          73 :         rAttribs.getBool( XML_zeroHeight, false ),
     524          73 :         rAttribs.getBool( XML_thickTop, false ),
     525         292 :         rAttribs.getBool( XML_thickBottom, false ) );
     526          73 : }
     527             : 
     528          89 : void WorksheetFragment::importCol( const AttributeList& rAttribs )
     529             : {
     530          89 :     ColumnModel aModel;
     531          89 :     aModel.maRange.mnFirst = rAttribs.getInteger( XML_min, -1 );
     532          89 :     aModel.maRange.mnLast  = rAttribs.getInteger( XML_max, -1 );
     533          89 :     aModel.mfWidth         = rAttribs.getDouble( XML_width, 0.0 );
     534          89 :     aModel.mnXfId          = rAttribs.getInteger( XML_style, -1 );
     535          89 :     aModel.mnLevel         = rAttribs.getInteger( XML_outlineLevel, 0 );
     536          89 :     aModel.mbShowPhonetic  = rAttribs.getBool( XML_phonetic, false );
     537          89 :     aModel.mbHidden        = rAttribs.getBool( XML_hidden, false );
     538          89 :     aModel.mbCollapsed     = rAttribs.getBool( XML_collapsed, false );
     539             :     // set column properties in the current sheet
     540          89 :     setColumnModel( aModel );
     541          89 : }
     542             : 
     543           2 : void WorksheetFragment::importMergeCell( const AttributeList& rAttribs )
     544             : {
     545           2 :     CellRangeAddress aRange;
     546           2 :     if( getAddressConverter().convertToCellRange( aRange, rAttribs.getString( XML_ref, OUString() ), getSheetIndex(), true, true ) )
     547           2 :         getSheetData().setMergedRange( aRange );
     548           2 : }
     549             : 
     550           3 : void WorksheetFragment::importHyperlink( const AttributeList& rAttribs )
     551             : {
     552           3 :     HyperlinkModel aModel;
     553           3 :     if( getAddressConverter().convertToCellRange( aModel.maRange, rAttribs.getString( XML_ref, OUString() ), getSheetIndex(), true, true ) )
     554             :     {
     555           3 :         aModel.maTarget   = getRelations().getExternalTargetFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
     556           3 :         aModel.maLocation = rAttribs.getXString( XML_location, OUString() );
     557           3 :         aModel.maDisplay  = rAttribs.getXString( XML_display, OUString() );
     558           3 :         aModel.maTooltip  = rAttribs.getXString( XML_tooltip, OUString() );
     559           3 :         setHyperlink( aModel );
     560           3 :     }
     561           3 : }
     562             : 
     563           0 : void WorksheetFragment::importBrk( const AttributeList& rAttribs, bool bRowBreak )
     564             : {
     565           0 :     PageBreakModel aModel;
     566           0 :     aModel.mnColRow = rAttribs.getInteger( XML_id, 0 );
     567           0 :     aModel.mnMin    = rAttribs.getInteger( XML_min, aModel.mnColRow );
     568           0 :     aModel.mnMax    = rAttribs.getInteger( XML_max, aModel.mnColRow );
     569           0 :     aModel.mbManual = rAttribs.getBool( XML_man, false );
     570           0 :     setPageBreak( aModel, bRowBreak );
     571           0 : }
     572             : 
     573          16 : void WorksheetFragment::importDrawing( const AttributeList& rAttribs )
     574             : {
     575          16 :     setDrawingPath( getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) ) );
     576          16 : }
     577             : 
     578           3 : void WorksheetFragment::importLegacyDrawing( const AttributeList& rAttribs )
     579             : {
     580           3 :     setVmlDrawingPath( getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) ) );
     581           3 : }
     582             : 
     583           0 : void WorksheetFragment::importOleObject( const AttributeList& rAttribs )
     584             : {
     585           0 :     ::oox::vml::OleObjectInfo aInfo;
     586           0 :     aInfo.setShapeId( rAttribs.getInteger( XML_shapeId, 0 ) );
     587             :     OSL_ENSURE( rAttribs.hasAttribute( XML_link ) != rAttribs.hasAttribute( R_TOKEN( id ) ),
     588             :         "WorksheetFragment::importOleObject - OLE object must be either linked or embedded" );
     589           0 :     aInfo.mbLinked = rAttribs.hasAttribute( XML_link );
     590           0 :     if( aInfo.mbLinked )
     591           0 :         aInfo.maTargetLink = getFormulaParser().importOleTargetLink( rAttribs.getString( XML_link, OUString() ) );
     592           0 :     else if( rAttribs.hasAttribute( R_TOKEN( id ) ) )
     593           0 :         importEmbeddedOleData( aInfo.maEmbeddedData, rAttribs.getString( R_TOKEN( id ), OUString() ) );
     594           0 :     aInfo.maProgId = rAttribs.getString( XML_progId, OUString() );
     595           0 :     aInfo.mbShowAsIcon = rAttribs.getToken( XML_dvAspect, XML_DVASPECT_CONTENT ) == XML_DVASPECT_ICON;
     596           0 :     aInfo.mbAutoUpdate = rAttribs.getToken( XML_oleUpdate, XML_OLEUPDATE_ONCALL ) == XML_OLEUPDATE_ALWAYS;
     597           0 :     aInfo.mbAutoLoad = rAttribs.getBool( XML_autoLoad, false );
     598           0 :     getVmlDrawing().registerOleObject( aInfo );
     599           0 : }
     600             : 
     601           0 : void WorksheetFragment::importControl( const AttributeList& rAttribs )
     602             : {
     603           0 :     ::oox::vml::ControlInfo aInfo;
     604           0 :     aInfo.setShapeId( rAttribs.getInteger( XML_shapeId, 0 ) );
     605           0 :     aInfo.maFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
     606           0 :     aInfo.maName = rAttribs.getString( XML_name, OUString() );
     607           0 :     getVmlDrawing().registerControl( aInfo );
     608           0 : }
     609             : 
     610           0 : void WorksheetFragment::importDimension( SequenceInputStream& rStrm )
     611             : {
     612           0 :     BinRange aBinRange;
     613           0 :     aBinRange.read( rStrm );
     614           0 :     CellRangeAddress aRange;
     615           0 :     getAddressConverter().convertToCellRangeUnchecked( aRange, aBinRange, getSheetIndex() );
     616             :     /*  BIFF12 stores the used area, if existing, or "A1" if the sheet is
     617             :         empty. In case of "A1", the dimension at the WorksheetHelper object
     618             :         will not be set. If the cell A1 exists, the used area will be updated
     619             :         while importing the cell. */
     620           0 :     if( (aRange.EndColumn > 0) || (aRange.EndRow > 0) )
     621           0 :         extendUsedArea( aRange );
     622           0 : }
     623             : 
     624           0 : void WorksheetFragment::importSheetFormatPr( SequenceInputStream& rStrm )
     625             : {
     626             :     sal_Int32 nDefaultWidth;
     627             :     sal_uInt16 nBaseWidth, nDefaultHeight, nFlags;
     628           0 :     rStrm >> nDefaultWidth >> nBaseWidth >> nDefaultHeight >> nFlags;
     629             : 
     630             :     // base column with
     631           0 :     setBaseColumnWidth( nBaseWidth );
     632             :     // default width is stored as 1/256th of a character in BIFF12, convert to entire character
     633           0 :     setDefaultColumnWidth( static_cast< double >( nDefaultWidth ) / 256.0 );
     634             :     // row height is in twips in BIFF12, convert to points; equal flags in all BIFFs
     635             :     setDefaultRowSettings(
     636             :         nDefaultHeight / 20.0,
     637           0 :         getFlag( nFlags, BIFF_DEFROW_CUSTOMHEIGHT ),
     638           0 :         getFlag( nFlags, BIFF_DEFROW_HIDDEN ),
     639           0 :         getFlag( nFlags, BIFF_DEFROW_THICKTOP ),
     640           0 :         getFlag( nFlags, BIFF_DEFROW_THICKBOTTOM ) );
     641           0 : }
     642             : 
     643           0 : void WorksheetFragment::importCol( SequenceInputStream& rStrm )
     644             : {
     645           0 :     ColumnModel aModel;
     646             : 
     647             :     sal_Int32 nWidth;
     648             :     sal_uInt16 nFlags;
     649           0 :     rStrm >> aModel.maRange.mnFirst >> aModel.maRange.mnLast >> nWidth >> aModel.mnXfId >> nFlags;
     650             : 
     651             :     // column indexes are 0-based in BIFF12, but ColumnModel expects 1-based
     652           0 :     ++aModel.maRange.mnFirst;
     653           0 :     ++aModel.maRange.mnLast;
     654             :     // width is stored as 1/256th of a character in BIFF12, convert to entire character
     655           0 :     aModel.mfWidth        = static_cast< double >( nWidth ) / 256.0;
     656             :     // equal flags in all BIFFs
     657           0 :     aModel.mnLevel        = extractValue< sal_Int32 >( nFlags, 8, 3 );
     658           0 :     aModel.mbShowPhonetic = getFlag( nFlags, BIFF_COLINFO_SHOWPHONETIC );
     659           0 :     aModel.mbHidden       = getFlag( nFlags, BIFF_COLINFO_HIDDEN );
     660           0 :     aModel.mbCollapsed    = getFlag( nFlags, BIFF_COLINFO_COLLAPSED );
     661             :     // set column properties in the current sheet
     662           0 :     setColumnModel( aModel );
     663           0 : }
     664             : 
     665           0 : void WorksheetFragment::importMergeCell( SequenceInputStream& rStrm )
     666             : {
     667           0 :     BinRange aBinRange;
     668           0 :     rStrm >> aBinRange;
     669           0 :     CellRangeAddress aRange;
     670           0 :     if( getAddressConverter().convertToCellRange( aRange, aBinRange, getSheetIndex(), true, true ) )
     671           0 :         getSheetData().setMergedRange( aRange );
     672           0 : }
     673             : 
     674           0 : void WorksheetFragment::importHyperlink( SequenceInputStream& rStrm )
     675             : {
     676           0 :     BinRange aBinRange;
     677           0 :     rStrm >> aBinRange;
     678           0 :     HyperlinkModel aModel;
     679           0 :     if( getAddressConverter().convertToCellRange( aModel.maRange, aBinRange, getSheetIndex(), true, true ) )
     680             :     {
     681           0 :         aModel.maTarget = getRelations().getExternalTargetFromRelId( BiffHelper::readString( rStrm ) );
     682           0 :         rStrm >> aModel.maLocation >> aModel.maTooltip >> aModel.maDisplay;
     683           0 :         setHyperlink( aModel );
     684           0 :     }
     685           0 : }
     686             : 
     687           0 : void WorksheetFragment::importBrk( SequenceInputStream& rStrm, bool bRowBreak )
     688             : {
     689           0 :     PageBreakModel aModel;
     690             :     sal_Int32 nManual;
     691           0 :     rStrm >> aModel.mnColRow >> aModel.mnMin >> aModel.mnMax >> nManual;
     692           0 :     aModel.mbManual = nManual != 0;
     693           0 :     setPageBreak( aModel, bRowBreak );
     694           0 : }
     695             : 
     696           0 : void WorksheetFragment::importDrawing( SequenceInputStream& rStrm )
     697             : {
     698           0 :     setDrawingPath( getFragmentPathFromRelId( BiffHelper::readString( rStrm ) ) );
     699           0 : }
     700             : 
     701           0 : void WorksheetFragment::importLegacyDrawing( SequenceInputStream& rStrm )
     702             : {
     703           0 :     setVmlDrawingPath( getFragmentPathFromRelId( BiffHelper::readString( rStrm ) ) );
     704           0 : }
     705             : 
     706           0 : void WorksheetFragment::importOleObject( SequenceInputStream& rStrm )
     707             : {
     708           0 :     ::oox::vml::OleObjectInfo aInfo;
     709             :     sal_Int32 nAspect, nUpdateMode, nShapeId;
     710             :     sal_uInt16 nFlags;
     711           0 :     rStrm >> nAspect >> nUpdateMode >> nShapeId >> nFlags >> aInfo.maProgId;
     712           0 :     aInfo.mbLinked = getFlag( nFlags, BIFF12_OLEOBJECT_LINKED );
     713           0 :     if( aInfo.mbLinked )
     714           0 :         aInfo.maTargetLink = getFormulaParser().importOleTargetLink( rStrm );
     715             :     else
     716           0 :         importEmbeddedOleData( aInfo.maEmbeddedData, BiffHelper::readString( rStrm ) );
     717           0 :     aInfo.setShapeId( nShapeId );
     718           0 :     aInfo.mbShowAsIcon = nAspect == BIFF12_OLEOBJECT_ICON;
     719           0 :     aInfo.mbAutoUpdate = nUpdateMode == BIFF12_OLEOBJECT_ALWAYS;
     720           0 :     aInfo.mbAutoLoad = getFlag( nFlags, BIFF12_OLEOBJECT_AUTOLOAD );
     721           0 :     getVmlDrawing().registerOleObject( aInfo );
     722           0 : }
     723             : 
     724           0 : void WorksheetFragment::importControl( SequenceInputStream& rStrm )
     725             : {
     726           0 :     ::oox::vml::ControlInfo aInfo;
     727           0 :     aInfo.setShapeId( rStrm.readInt32() );
     728           0 :     aInfo.maFragmentPath = getFragmentPathFromRelId( BiffHelper::readString( rStrm ) );
     729           0 :     rStrm >> aInfo.maName;
     730           0 :     getVmlDrawing().registerControl( aInfo );
     731           0 : }
     732             : 
     733           0 : void WorksheetFragment::importEmbeddedOleData( StreamDataSequence& orEmbeddedData, const OUString& rRelId )
     734             : {
     735           0 :     OUString aFragmentPath = getFragmentPathFromRelId( rRelId );
     736           0 :     if( !aFragmentPath.isEmpty() )
     737           0 :         getBaseFilter().importBinaryData( orEmbeddedData, aFragmentPath );
     738           0 : }
     739             : 
     740             : } // namespace xls
     741          18 : } // namespace oox
     742             : 
     743             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10