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

Generated by: LCOV version 1.10