LCOV - code coverage report
Current view: top level - sc/source/filter/oox - defnamesbuffer.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 107 246 43.5 %
Date: 2015-06-13 12:38:46 Functions: 21 35 60.0 %
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 "defnamesbuffer.hxx"
      21             : 
      22             : #include <com/sun/star/sheet/ComplexReference.hpp>
      23             : #include <com/sun/star/sheet/ExternalReference.hpp>
      24             : #include <com/sun/star/sheet/NamedRangeFlag.hpp>
      25             : #include <com/sun/star/sheet/ReferenceFlags.hpp>
      26             : #include <com/sun/star/sheet/SingleReference.hpp>
      27             : #include <com/sun/star/sheet/XFormulaTokens.hpp>
      28             : #include <com/sun/star/sheet/XPrintAreas.hpp>
      29             : #include <osl/diagnose.h>
      30             : #include <rtl/ustrbuf.hxx>
      31             : #include <oox/helper/attributelist.hxx>
      32             : #include <oox/helper/propertyset.hxx>
      33             : #include "addressconverter.hxx"
      34             : #include "biffinputstream.hxx"
      35             : #include "externallinkbuffer.hxx"
      36             : #include "formulaparser.hxx"
      37             : #include "worksheetbuffer.hxx"
      38             : #include "tokenarray.hxx"
      39             : #include "tokenuno.hxx"
      40             : #include "compiler.hxx"
      41             : 
      42             : namespace oox {
      43             : namespace xls {
      44             : 
      45             : using namespace ::com::sun::star::sheet;
      46             : using namespace ::com::sun::star::table;
      47             : using namespace ::com::sun::star::uno;
      48             : 
      49             : namespace {
      50             : 
      51             : const sal_uInt32 BIFF12_DEFNAME_HIDDEN      = 0x00000001;
      52             : const sal_uInt32 BIFF12_DEFNAME_FUNC        = 0x00000002;
      53             : const sal_uInt32 BIFF12_DEFNAME_VBNAME      = 0x00000004;
      54             : const sal_uInt32 BIFF12_DEFNAME_MACRO       = 0x00000008;
      55             : const sal_uInt32 BIFF12_DEFNAME_BUILTIN     = 0x00000020;
      56             : 
      57             : const sal_uInt16 BIFF_REFFLAG_COL1REL       = 0x0001;
      58             : const sal_uInt16 BIFF_REFFLAG_ROW1REL       = 0x0002;
      59             : const sal_uInt16 BIFF_REFFLAG_COL2REL       = 0x0004;
      60             : const sal_uInt16 BIFF_REFFLAG_ROW2REL       = 0x0008;
      61             : 
      62             : const sal_Char* const spcOoxPrefix = "_xlnm.";
      63             : 
      64             : const sal_Char* const sppcBaseNames[] =
      65             : {
      66             :     "Consolidate_Area",
      67             :     "Auto_Open",
      68             :     "Auto_Close",
      69             :     "Extract",
      70             :     "Database",
      71             :     "Criteria",
      72             :     "Print_Area",
      73             :     "Print_Titles",
      74             :     "Recorder",
      75             :     "Data_Form",
      76             :     "Auto_Activate",
      77             :     "Auto_Deactivate",
      78             :     "Sheet_Title",
      79             :     "_FilterDatabase"
      80             : };
      81             : 
      82          15 : OUString lclGetBaseName( sal_Unicode cBuiltinId )
      83             : {
      84             :     OSL_ENSURE( cBuiltinId < SAL_N_ELEMENTS( sppcBaseNames ), "lclGetBaseName - unsupported built-in identifier" );
      85          15 :     OUStringBuffer aBuffer;
      86          15 :     if( cBuiltinId < SAL_N_ELEMENTS( sppcBaseNames ) )
      87          15 :         aBuffer.appendAscii( sppcBaseNames[ cBuiltinId ] );
      88             :     else
      89           0 :         aBuffer.append( static_cast< sal_Int32 >( cBuiltinId ) );
      90          15 :     return aBuffer.makeStringAndClear();
      91             : }
      92             : 
      93           1 : OUString lclGetPrefixedName( sal_Unicode cBuiltinId )
      94             : {
      95           1 :     return OUStringBuffer().appendAscii( spcOoxPrefix ).append( lclGetBaseName( cBuiltinId ) ).makeStringAndClear();
      96             : }
      97             : 
      98             : /** returns the built-in name identifier from a perfixed built-in name, e.g. '_xlnm.Print_Area'. */
      99          11 : sal_Unicode lclGetBuiltinIdFromPrefixedName( const OUString& rModelName )
     100             : {
     101          11 :     OUString aPrefix = OUString::createFromAscii( spcOoxPrefix );
     102          11 :     sal_Int32 nPrefixLen = aPrefix.getLength();
     103          11 :     if( rModelName.matchIgnoreAsciiCase( aPrefix ) )
     104             :     {
     105          14 :         for( sal_Unicode cBuiltinId = 0; cBuiltinId < SAL_N_ELEMENTS( sppcBaseNames ); ++cBuiltinId )
     106             :         {
     107          14 :             OUString aBaseName = lclGetBaseName( cBuiltinId );
     108          14 :             sal_Int32 nBaseNameLen = aBaseName.getLength();
     109          14 :             if( (rModelName.getLength() == nPrefixLen + nBaseNameLen) && rModelName.matchIgnoreAsciiCase( aBaseName, nPrefixLen ) )
     110           1 :                 return cBuiltinId;
     111          13 :         }
     112             :     }
     113          10 :     return BIFF_DEFNAME_UNKNOWN;
     114             : }
     115             : 
     116             : /** returns the built-in name identifier from a built-in base name, e.g. 'Print_Area'. */
     117           0 : sal_Unicode lclGetBuiltinIdFromBaseName( const OUString& rModelName )
     118             : {
     119           0 :     for( sal_Unicode cBuiltinId = 0; cBuiltinId < SAL_N_ELEMENTS( sppcBaseNames ); ++cBuiltinId )
     120           0 :         if( rModelName.equalsIgnoreAsciiCaseAscii( sppcBaseNames[ cBuiltinId ] ) )
     121           0 :             return cBuiltinId;
     122           0 :     return BIFF_DEFNAME_UNKNOWN;
     123             : }
     124             : 
     125          11 : OUString lclGetUpcaseModelName( const OUString& rModelName )
     126             : {
     127             :     // TODO: i18n?
     128          11 :     return rModelName.toAsciiUpperCase();
     129             : }
     130             : 
     131           0 : void lclConvertRefFlags( sal_Int32& ornFlags, sal_Int32& ornAbsPos, sal_Int32& ornRelPos, sal_Int32 nBasePos, sal_Int32 nApiRelFlag, bool bRel )
     132             : {
     133           0 :     if( getFlag( ornFlags, nApiRelFlag ) && !bRel )
     134             :     {
     135             :         // convert relative to absolute
     136           0 :         setFlag( ornFlags, nApiRelFlag, false );
     137           0 :         ornAbsPos = nBasePos + ornRelPos;
     138             :     }
     139           0 :     else if( !getFlag( ornFlags, nApiRelFlag ) && bRel )
     140             :     {
     141             :         // convert absolute to relative
     142           0 :         setFlag( ornFlags, nApiRelFlag, true );
     143           0 :         ornRelPos = ornAbsPos - nBasePos;
     144             :     }
     145           0 : }
     146             : 
     147           0 : void lclConvertSingleRefFlags( SingleReference& orApiRef, const CellAddress& rBaseAddr, bool bColRel, bool bRowRel )
     148             : {
     149             :     using namespace ::com::sun::star::sheet::ReferenceFlags;
     150             :     lclConvertRefFlags(
     151             :         orApiRef.Flags, orApiRef.Column, orApiRef.RelativeColumn,
     152           0 :         rBaseAddr.Column, COLUMN_RELATIVE, bColRel );
     153             :     lclConvertRefFlags(
     154             :         orApiRef.Flags, orApiRef.Row, orApiRef.RelativeRow,
     155           0 :         rBaseAddr.Row, ROW_RELATIVE, bRowRel );
     156           0 : }
     157             : 
     158           0 : Any lclConvertReference( const Any& rRefAny, const CellAddress& rBaseAddr, sal_uInt16 nRelFlags )
     159             : {
     160           0 :     if( rRefAny.has< SingleReference >() && !getFlag( nRelFlags, BIFF_REFFLAG_COL2REL ) && !getFlag( nRelFlags, BIFF_REFFLAG_ROW2REL ) )
     161             :     {
     162           0 :         SingleReference aApiRef;
     163           0 :         rRefAny >>= aApiRef;
     164           0 :         lclConvertSingleRefFlags( aApiRef, rBaseAddr, getFlag( nRelFlags, BIFF_REFFLAG_COL1REL ), getFlag( nRelFlags, BIFF_REFFLAG_ROW1REL ) );
     165           0 :         return Any( aApiRef );
     166             :     }
     167           0 :     if( rRefAny.has< ComplexReference >() )
     168             :     {
     169           0 :         ComplexReference aApiRef;
     170           0 :         rRefAny >>= aApiRef;
     171           0 :         lclConvertSingleRefFlags( aApiRef.Reference1, rBaseAddr, getFlag( nRelFlags, BIFF_REFFLAG_COL1REL ), getFlag( nRelFlags, BIFF_REFFLAG_ROW1REL ) );
     172           0 :         lclConvertSingleRefFlags( aApiRef.Reference2, rBaseAddr, getFlag( nRelFlags, BIFF_REFFLAG_COL2REL ), getFlag( nRelFlags, BIFF_REFFLAG_ROW2REL ) );
     173           0 :         return Any( aApiRef );
     174             :     }
     175           0 :     return Any();
     176             : }
     177             : 
     178             : } // namespace
     179             : 
     180          11 : DefinedNameModel::DefinedNameModel() :
     181             :     mnSheet( -1 ),
     182             :     mnFuncGroupId( -1 ),
     183             :     mbMacro( false ),
     184             :     mbFunction( false ),
     185             :     mbVBName( false ),
     186          11 :     mbHidden( false )
     187             : {
     188          11 : }
     189             : 
     190          11 : DefinedNameBase::DefinedNameBase( const WorkbookHelper& rHelper ) :
     191          11 :     WorkbookHelper( rHelper )
     192             : {
     193          11 : }
     194             : 
     195          11 : const OUString& DefinedNameBase::getUpcaseModelName() const
     196             : {
     197          11 :     if( maUpModelName.isEmpty() )
     198          11 :         maUpModelName = lclGetUpcaseModelName( maModel.maName );
     199          11 :     return maUpModelName;
     200             : }
     201             : 
     202           0 : Any DefinedNameBase::getReference( const CellAddress& rBaseAddr ) const
     203             : {
     204           0 :     if( maRefAny.hasValue() && (maModel.maName.getLength() >= 2) && (maModel.maName[ 0 ] == '\x01') )
     205             :     {
     206           0 :         sal_Unicode cFlagsChar = getUpcaseModelName()[ 1 ];
     207           0 :         if( ('A' <= cFlagsChar) && (cFlagsChar <= 'P') )
     208             :         {
     209           0 :             sal_uInt16 nRelFlags = static_cast< sal_uInt16 >( cFlagsChar - 'A' );
     210           0 :             if( maRefAny.has< ExternalReference >() )
     211             :             {
     212           0 :                 ExternalReference aApiExtRef;
     213           0 :                 maRefAny >>= aApiExtRef;
     214           0 :                 Any aRefAny = lclConvertReference( aApiExtRef.Reference, rBaseAddr, nRelFlags );
     215           0 :                 if( aRefAny.hasValue() )
     216             :                 {
     217           0 :                     aApiExtRef.Reference <<= aRefAny;
     218           0 :                     return Any( aApiExtRef );
     219           0 :                 }
     220             :             }
     221             :             else
     222             :             {
     223           0 :                 return lclConvertReference( maRefAny, rBaseAddr, nRelFlags );
     224             :             }
     225             :         }
     226             :     }
     227           0 :     return Any();
     228             : }
     229             : 
     230           0 : ApiTokenSequence DefinedNameBase::importOoxFormula( sal_Int16 nBaseSheet )
     231             : {
     232           0 :     return (!maModel.maFormula.isEmpty()) ?
     233           0 :         getFormulaParser().importFormula( CellAddress( nBaseSheet, 0, 0 ), maModel.maFormula ) :
     234           0 :         getFormulaParser().convertErrorToFormula( BIFF_ERR_NAME );
     235             : }
     236             : 
     237           0 : ApiTokenSequence DefinedNameBase::importBiff12Formula( sal_Int16 nBaseSheet, SequenceInputStream& rStrm )
     238             : {
     239           0 :     return getFormulaParser().importFormula( CellAddress( nBaseSheet, 0, 0 ), FORMULATYPE_DEFINEDNAME, rStrm );
     240             : }
     241             : 
     242           0 : ApiTokenSequence DefinedNameBase::importBiffFormula( sal_Int16 nBaseSheet, BiffInputStream& rStrm, const sal_uInt16* pnFmlaSize )
     243             : {
     244           0 :     return (!pnFmlaSize || (*pnFmlaSize > 0)) ?
     245           0 :         getFormulaParser().importFormula( CellAddress( nBaseSheet, 0, 0 ), FORMULATYPE_DEFINEDNAME, rStrm, pnFmlaSize ) :
     246           0 :         getFormulaParser().convertErrorToFormula( BIFF_ERR_NAME );
     247             : }
     248             : 
     249          11 : DefinedName::DefinedName( const WorkbookHelper& rHelper ) :
     250             :     DefinedNameBase( rHelper ),
     251             :     mpScRangeData(NULL),
     252             :     mnTokenIndex( -1 ),
     253             :     mnCalcSheet( 0 ),
     254             :     mcBuiltinId( BIFF_DEFNAME_UNKNOWN ),
     255          11 :     mnFmlaSize( 0 )
     256             : {
     257          11 : }
     258             : 
     259          11 : void DefinedName::importDefinedName( const AttributeList& rAttribs )
     260             : {
     261          11 :     maModel.maName        = rAttribs.getXString( XML_name, OUString() );
     262          11 :     maModel.mnSheet       = rAttribs.getInteger( XML_localSheetId, -1 );
     263          11 :     maModel.mnFuncGroupId = rAttribs.getInteger( XML_functionGroupId, -1 );
     264          11 :     maModel.mbMacro       = rAttribs.getBool( XML_xlm, false );
     265          11 :     maModel.mbFunction    = rAttribs.getBool( XML_function, false );
     266          11 :     maModel.mbVBName      = rAttribs.getBool( XML_vbProcedure, false );
     267          11 :     maModel.mbHidden      = rAttribs.getBool( XML_hidden, false );
     268          11 :     mnCalcSheet = (maModel.mnSheet >= 0) ? getWorksheets().getCalcSheetIndex( maModel.mnSheet ) : -1;
     269             : 
     270             :     /*  Detect built-in state from name itself, there is no built-in flag.
     271             :         Built-in names are prexixed with '_xlnm.' instead. */
     272          11 :     mcBuiltinId = lclGetBuiltinIdFromPrefixedName( maModel.maName );
     273          11 : }
     274             : 
     275          11 : void DefinedName::setFormula( const OUString& rFormula )
     276             : {
     277          11 :     maModel.maFormula = rFormula;
     278          11 : }
     279             : 
     280           0 : void DefinedName::importDefinedName( SequenceInputStream& rStrm )
     281             : {
     282             :     sal_uInt32 nFlags;
     283           0 :     nFlags = rStrm.readuInt32();
     284           0 :     rStrm.skip( 1 );    // keyboard shortcut
     285           0 :     maModel.mnSheet = rStrm.readInt32();
     286           0 :     rStrm >> maModel.maName;
     287           0 :     mnCalcSheet = (maModel.mnSheet >= 0) ? getWorksheets().getCalcSheetIndex( maModel.mnSheet ) : -1;
     288             : 
     289             :     // macro function/command, hidden flag
     290           0 :     maModel.mnFuncGroupId = extractValue< sal_Int32 >( nFlags, 6, 9 );
     291           0 :     maModel.mbMacro       = getFlag( nFlags, BIFF12_DEFNAME_MACRO );
     292           0 :     maModel.mbFunction    = getFlag( nFlags, BIFF12_DEFNAME_FUNC );
     293           0 :     maModel.mbVBName      = getFlag( nFlags, BIFF12_DEFNAME_VBNAME );
     294           0 :     maModel.mbHidden      = getFlag( nFlags, BIFF12_DEFNAME_HIDDEN );
     295             : 
     296             :     // get built-in name index from name
     297           0 :     if( getFlag( nFlags, BIFF12_DEFNAME_BUILTIN ) )
     298           0 :         mcBuiltinId = lclGetBuiltinIdFromBaseName( maModel.maName );
     299             : 
     300             :     // store token array data
     301           0 :     sal_Int64 nRecPos = rStrm.tell();
     302           0 :     sal_Int32 nFmlaSize = rStrm.readInt32();
     303           0 :     rStrm.skip( nFmlaSize );
     304           0 :     sal_Int32 nAddDataSize = rStrm.readInt32();
     305           0 :     if( !rStrm.isEof() && (nFmlaSize > 0) && (nAddDataSize >= 0) && (rStrm.getRemaining() >= nAddDataSize) )
     306             :     {
     307           0 :         sal_Int32 nTotalSize = 8 + nFmlaSize + nAddDataSize;
     308           0 :         mxFormula.reset( new StreamDataSequence );
     309           0 :         rStrm.seek( nRecPos );
     310           0 :         rStrm.readData( *mxFormula, nTotalSize );
     311             :     }
     312           0 : }
     313             : 
     314          11 : void DefinedName::createNameObject( sal_Int32 nIndex )
     315             : {
     316             :     // do not create names for (macro) functions or VBA procedures
     317             :     // #163146# do not ignore hidden names (may be regular names created by VBA scripts)
     318          11 :     if( /*maModel.mbHidden ||*/ maModel.mbFunction || maModel.mbVBName )
     319           0 :         return;
     320             : 
     321             :     // skip BIFF names without stream position (e.g. BIFF3-BIFF4 internal 3D references)
     322          11 :     if( (getFilterType() == FILTER_BIFF) && !mxBiffStrm.get() )
     323           0 :         return;
     324             : 
     325             :     // convert original name to final Calc name (TODO: filter invalid characters from model name)
     326          11 :     maCalcName = isBuiltinName() ? lclGetPrefixedName( mcBuiltinId ) : maModel.maName;
     327             : 
     328             :     // #163146# do not rename sheet-local names by default, this breaks VBA scripts
     329             : 
     330             :     // special flags for this name
     331          11 :     sal_Int32 nNameFlags = 0;
     332             :     using namespace ::com::sun::star::sheet::NamedRangeFlag;
     333          11 :     if( !isGlobalName() ) switch( mcBuiltinId )
     334             :     {
     335           0 :         case BIFF_DEFNAME_CRITERIA:     nNameFlags = FILTER_CRITERIA;               break;
     336           0 :         case BIFF_DEFNAME_PRINTAREA:    nNameFlags = PRINT_AREA;                    break;
     337           0 :         case BIFF_DEFNAME_PRINTTITLES:  nNameFlags = COLUMN_HEADER | ROW_HEADER;    break;
     338             :     }
     339             : 
     340             :     // create the name and insert it into the document, maCalcName will be changed to the resulting name
     341          11 :     if (maModel.mnSheet >= 0)
     342           5 :         mpScRangeData = createLocalNamedRangeObject( maCalcName, ApiTokenSequence(), nIndex, nNameFlags, maModel.mnSheet );
     343             :     else
     344           6 :         mpScRangeData = createNamedRangeObject( maCalcName, ApiTokenSequence(), nIndex, nNameFlags );
     345          11 :     mnTokenIndex = nIndex;
     346             : }
     347             : 
     348             : ApiTokenSequence
     349           0 : DefinedName::getTokens()
     350             : {
     351             :     // convert and set formula of the defined name
     352           0 :     ApiTokenSequence aTokens;
     353           0 :     switch( getFilterType() )
     354             :     {
     355             :         case FILTER_OOXML:
     356             :         {
     357           0 :             if( mxFormula.get() )
     358             :             {
     359           0 :                 SequenceInputStream aStrm( *mxFormula );
     360           0 :                 aTokens = importBiff12Formula( mnCalcSheet, aStrm );
     361             :             }
     362             :             else
     363           0 :                 aTokens = importOoxFormula( mnCalcSheet );
     364             :         }
     365           0 :         break;
     366             :         case FILTER_BIFF:
     367             :         {
     368             :             OSL_ENSURE( mxBiffStrm.get(), "DefinedName::convertFormula - missing BIFF stream" );
     369           0 :             if( mxBiffStrm.get() )
     370             :             {
     371           0 :                 BiffInputStream& rStrm = mxBiffStrm->getStream();
     372           0 :                 BiffInputStreamPosGuard aStrmGuard( rStrm );
     373           0 :                 if( mxBiffStrm->restorePosition() )
     374           0 :                     aTokens = importBiffFormula( mnCalcSheet, rStrm, &mnFmlaSize );
     375             :             }
     376             :         }
     377           0 :         break;
     378             :         case FILTER_UNKNOWN:
     379           0 :         break;
     380             :     }
     381           0 :     return aTokens;
     382             : }
     383             : 
     384          11 : std::unique_ptr<ScTokenArray> DefinedName::getScTokens()
     385             : {
     386          11 :     ScTokenArray aTokenArray;
     387          22 :     ScCompiler aCompiler(&getScDocument(), ScAddress(0, 0, mnCalcSheet));
     388          11 :     aCompiler.SetGrammar(formula::FormulaGrammar::GRAM_OOXML);
     389          11 :     std::unique_ptr<ScTokenArray> pArray(aCompiler.CompileString(maModel.maFormula));
     390             : 
     391          22 :     return pArray;
     392             : }
     393             : 
     394          11 : void DefinedName::convertFormula()
     395             : {
     396             :     // macro function or vba procedure
     397          11 :     if(!mpScRangeData)
     398          11 :         return;
     399             : 
     400             :     // convert and set formula of the defined name
     401          11 :     if ( getFilterType() == FILTER_OOXML )
     402             :     {
     403          11 :         std::unique_ptr<ScTokenArray> pTokenArray = getScTokens();
     404          11 :         mpScRangeData->SetCode( *pTokenArray );
     405             :     }
     406             : 
     407          11 :     ScTokenArray* pTokenArray = mpScRangeData->GetCode();
     408          11 :     Sequence< FormulaToken > aFTokenSeq;
     409          11 :     (void)ScTokenConversion::ConvertToTokenSequence( this->getScDocument(), aFTokenSeq, *pTokenArray );
     410             :     // set built-in names (print ranges, repeated titles, filter ranges)
     411          11 :     if( !isGlobalName() ) switch( mcBuiltinId )
     412             :     {
     413             :         case BIFF_DEFNAME_PRINTAREA:
     414             :         {
     415           0 :             Reference< XPrintAreas > xPrintAreas( getSheetFromDoc( mnCalcSheet ), UNO_QUERY );
     416           0 :             ApiCellRangeList aPrintRanges;
     417           0 :             getFormulaParser().extractCellRangeList( aPrintRanges, aFTokenSeq, false, mnCalcSheet );
     418           0 :             if( xPrintAreas.is() && !aPrintRanges.empty() )
     419           0 :                 xPrintAreas->setPrintAreas( aPrintRanges.toSequence() );
     420             :         }
     421           0 :         break;
     422             :         case BIFF_DEFNAME_PRINTTITLES:
     423             :         {
     424           0 :             Reference< XPrintAreas > xPrintAreas( getSheetFromDoc( mnCalcSheet ), UNO_QUERY );
     425           0 :             ApiCellRangeList aTitleRanges;
     426           0 :             getFormulaParser().extractCellRangeList( aTitleRanges, aFTokenSeq, false, mnCalcSheet );
     427           0 :             if( xPrintAreas.is() && !aTitleRanges.empty() )
     428             :             {
     429           0 :                 bool bHasRowTitles = false;
     430           0 :                 bool bHasColTitles = false;
     431           0 :                 const CellAddress& rMaxPos = getAddressConverter().getMaxAddress();
     432           0 :                 for( ::std::vector< CellRangeAddress >::const_iterator aIt = aTitleRanges.begin(), aEnd = aTitleRanges.end(); (aIt != aEnd) && (!bHasRowTitles || !bHasColTitles); ++aIt )
     433             :                 {
     434           0 :                     bool bFullRow = (aIt->StartColumn == 0) && (aIt->EndColumn >= rMaxPos.Column);
     435           0 :                     bool bFullCol = (aIt->StartRow == 0) && (aIt->EndRow >= rMaxPos.Row);
     436           0 :                     if( !bHasRowTitles && bFullRow && !bFullCol )
     437             :                     {
     438           0 :                         xPrintAreas->setTitleRows( *aIt );
     439           0 :                         xPrintAreas->setPrintTitleRows( sal_True );
     440           0 :                         bHasRowTitles = true;
     441             :                     }
     442           0 :                     else if( !bHasColTitles && bFullCol && !bFullRow )
     443             :                     {
     444           0 :                         xPrintAreas->setTitleColumns( *aIt );
     445           0 :                         xPrintAreas->setPrintTitleColumns( sal_True );
     446           0 :                         bHasColTitles = true;
     447             :                     }
     448             :                 }
     449           0 :             }
     450             :         }
     451           0 :         break;
     452          11 :     }
     453             : }
     454             : 
     455           1 : bool DefinedName::getAbsoluteRange( CellRangeAddress& orRange ) const
     456             : {
     457           1 :     ScTokenArray* pTokenArray = mpScRangeData->GetCode();
     458           1 :     Sequence< FormulaToken > aFTokenSeq;
     459           1 :     ScTokenConversion::ConvertToTokenSequence(getScDocument(), aFTokenSeq, *pTokenArray);
     460           1 :     return getFormulaParser().extractCellRange( orRange, aFTokenSeq, false );
     461             : }
     462             : 
     463         145 : DefinedNamesBuffer::DefinedNamesBuffer( const WorkbookHelper& rHelper ) :
     464         145 :     WorkbookHelper( rHelper )
     465             : {
     466         145 : }
     467             : 
     468          11 : DefinedNameRef DefinedNamesBuffer::importDefinedName( const AttributeList& rAttribs )
     469             : {
     470          11 :     DefinedNameRef xDefName = createDefinedName();
     471          11 :     xDefName->importDefinedName( rAttribs );
     472          11 :     return xDefName;
     473             : }
     474             : 
     475           0 : void DefinedNamesBuffer::importDefinedName( SequenceInputStream& rStrm )
     476             : {
     477           0 :     createDefinedName()->importDefinedName( rStrm );
     478           0 : }
     479             : 
     480         145 : void DefinedNamesBuffer::finalizeImport()
     481             : {
     482             :     // first insert all names without formula definition into the document, and insert them into the maps
     483         145 :     int index = 0;
     484         156 :     for( DefNameVector::iterator aIt = maDefNames.begin(), aEnd = maDefNames.end(); aIt != aEnd; ++aIt )
     485             :     {
     486          11 :         DefinedNameRef xDefName = *aIt;
     487          11 :         xDefName->createNameObject( ++index );
     488             :         // map by sheet index and original model name
     489          11 :         maModelNameMap[ SheetNameKey( xDefName->getLocalCalcSheet(), xDefName->getUpcaseModelName() ) ] = xDefName;
     490             :         // map by sheet index and built-in identifier
     491          11 :         if( !xDefName->isGlobalName() && xDefName->isBuiltinName() )
     492           1 :             maBuiltinMap[ BuiltinKey( xDefName->getLocalCalcSheet(), xDefName->getBuiltinId() ) ] = xDefName;
     493             :         // map by API formula token identifier
     494          11 :         sal_Int32 nTokenIndex = xDefName->getTokenIndex();
     495          11 :         if( nTokenIndex >= 0 )
     496          11 :             maTokenIdMap[ nTokenIndex ] = xDefName;
     497          11 :     }
     498             : 
     499             :     /*  Now convert all name formulas, so that the formula parser can find all
     500             :         names in case of circular dependencies. */
     501         145 :     maDefNames.forEachMem( &DefinedName::convertFormula );
     502         145 : }
     503             : 
     504           0 : DefinedNameRef DefinedNamesBuffer::getByIndex( sal_Int32 nIndex ) const
     505             : {
     506           0 :     return maDefNames.get( nIndex );
     507             : }
     508             : 
     509           0 : DefinedNameRef DefinedNamesBuffer::getByTokenIndex( sal_Int32 nIndex ) const
     510             : {
     511           0 :     return maTokenIdMap.get( nIndex );
     512             : }
     513             : 
     514           0 : DefinedNameRef DefinedNamesBuffer::getByModelName( const OUString& rModelName, sal_Int16 nCalcSheet ) const
     515             : {
     516           0 :     OUString aUpcaseName = lclGetUpcaseModelName( rModelName );
     517           0 :     DefinedNameRef xDefName = maModelNameMap.get( SheetNameKey( nCalcSheet, aUpcaseName ) );
     518             :     // lookup global name, if no local name exists
     519           0 :     if( !xDefName && (nCalcSheet >= 0) )
     520           0 :         xDefName = maModelNameMap.get( SheetNameKey( -1, aUpcaseName ) );
     521           0 :     return xDefName;
     522             : }
     523             : 
     524         269 : DefinedNameRef DefinedNamesBuffer::getByBuiltinId( sal_Unicode cBuiltinId, sal_Int16 nCalcSheet ) const
     525             : {
     526         269 :     return maBuiltinMap.get( BuiltinKey( nCalcSheet, cBuiltinId ) );
     527             : }
     528             : 
     529          11 : DefinedNameRef DefinedNamesBuffer::createDefinedName()
     530             : {
     531          11 :     DefinedNameRef xDefName( new DefinedName( *this ) );
     532          11 :     maDefNames.push_back( xDefName );
     533          11 :     return xDefName;
     534             : }
     535             : 
     536             : } // namespace xls
     537          30 : } // namespace oox
     538             : 
     539             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11