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

Generated by: LCOV version 1.10