LCOV - code coverage report
Current view: top level - sc/source/filter/oox - defnamesbuffer.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 114 241 47.3 %
Date: 2014-04-11 Functions: 22 34 64.7 %
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 <rtl/ustrbuf.hxx>
      30             : #include "oox/helper/attributelist.hxx"
      31             : #include "oox/helper/containerhelper.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             : 
      41             : namespace oox {
      42             : namespace xls {
      43             : 
      44             : using namespace ::com::sun::star::sheet;
      45             : using namespace ::com::sun::star::table;
      46             : using namespace ::com::sun::star::uno;
      47             : 
      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 < STATIC_ARRAY_SIZE( sppcBaseNames ), "lclGetBaseName - unsupported built-in identifier" );
      85          15 :     OUStringBuffer aBuffer;
      86          15 :     if( cBuiltinId < STATIC_ARRAY_SIZE( 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 < STATIC_ARRAY_SIZE( 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 < STATIC_ARRAY_SIZE( 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          11 : ApiTokenSequence DefinedNameBase::importOoxFormula( sal_Int16 nBaseSheet )
     231             : {
     232          11 :     return (!maModel.maFormula.isEmpty()) ?
     233          11 :         getFormulaParser().importFormula( CellAddress( nBaseSheet, 0, 0 ), maModel.maFormula ) :
     234          22 :         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 :     rStrm >> nFlags;
     284           0 :     rStrm.skip( 1 );    // keyboard shortcut
     285           0 :     rStrm >> maModel.mnSheet >> maModel.maName;
     286           0 :     mnCalcSheet = (maModel.mnSheet >= 0) ? getWorksheets().getCalcSheetIndex( maModel.mnSheet ) : -1;
     287             : 
     288             :     // macro function/command, hidden flag
     289           0 :     maModel.mnFuncGroupId = extractValue< sal_Int32 >( nFlags, 6, 9 );
     290           0 :     maModel.mbMacro       = getFlag( nFlags, BIFF12_DEFNAME_MACRO );
     291           0 :     maModel.mbFunction    = getFlag( nFlags, BIFF12_DEFNAME_FUNC );
     292           0 :     maModel.mbVBName      = getFlag( nFlags, BIFF12_DEFNAME_VBNAME );
     293           0 :     maModel.mbHidden      = getFlag( nFlags, BIFF12_DEFNAME_HIDDEN );
     294             : 
     295             :     // get built-in name index from name
     296           0 :     if( getFlag( nFlags, BIFF12_DEFNAME_BUILTIN ) )
     297           0 :         mcBuiltinId = lclGetBuiltinIdFromBaseName( maModel.maName );
     298             : 
     299             :     // store token array data
     300           0 :     sal_Int64 nRecPos = rStrm.tell();
     301           0 :     sal_Int32 nFmlaSize = rStrm.readInt32();
     302           0 :     rStrm.skip( nFmlaSize );
     303           0 :     sal_Int32 nAddDataSize = rStrm.readInt32();
     304           0 :     if( !rStrm.isEof() && (nFmlaSize > 0) && (nAddDataSize >= 0) && (rStrm.getRemaining() >= nAddDataSize) )
     305             :     {
     306           0 :         sal_Int32 nTotalSize = 8 + nFmlaSize + nAddDataSize;
     307           0 :         mxFormula.reset( new StreamDataSequence );
     308           0 :         rStrm.seek( nRecPos );
     309           0 :         rStrm.readData( *mxFormula, nTotalSize );
     310             :     }
     311           0 : }
     312             : 
     313          11 : void DefinedName::createNameObject( sal_Int32 nIndex )
     314             : {
     315             :     // do not create names for (macro) functions or VBA procedures
     316             :     // #163146# do not ignore hidden names (may be regular names created by VBA scripts)
     317          11 :     if( /*maModel.mbHidden ||*/ maModel.mbFunction || maModel.mbVBName )
     318           0 :         return;
     319             : 
     320             :     // skip BIFF names without stream position (e.g. BIFF3-BIFF4 internal 3D references)
     321          11 :     if( (getFilterType() == FILTER_BIFF) && !mxBiffStrm.get() )
     322           0 :         return;
     323             : 
     324             :     // convert original name to final Calc name (TODO: filter invalid characters from model name)
     325          11 :     maCalcName = isBuiltinName() ? lclGetPrefixedName( mcBuiltinId ) : maModel.maName;
     326             : 
     327             :     // #163146# do not rename sheet-local names by default, this breaks VBA scripts
     328             : 
     329             :     // special flags for this name
     330          11 :     sal_Int32 nNameFlags = 0;
     331             :     using namespace ::com::sun::star::sheet::NamedRangeFlag;
     332          11 :     if( !isGlobalName() ) switch( mcBuiltinId )
     333             :     {
     334           0 :         case BIFF_DEFNAME_CRITERIA:     nNameFlags = FILTER_CRITERIA;               break;
     335           0 :         case BIFF_DEFNAME_PRINTAREA:    nNameFlags = PRINT_AREA;                    break;
     336           0 :         case BIFF_DEFNAME_PRINTTITLES:  nNameFlags = COLUMN_HEADER | ROW_HEADER;    break;
     337             :     }
     338             : 
     339             :     // create the name and insert it into the document, maCalcName will be changed to the resulting name
     340          11 :     if (maModel.mnSheet >= 0)
     341           5 :         mpScRangeData = createLocalNamedRangeObject( maCalcName, ApiTokenSequence(), nIndex, nNameFlags, maModel.mnSheet );
     342             :     else
     343           6 :         mpScRangeData = createNamedRangeObject( maCalcName, ApiTokenSequence(), nIndex, nNameFlags );
     344          11 :     mnTokenIndex = nIndex;
     345             : }
     346             : 
     347             : ApiTokenSequence
     348          11 : DefinedName::getTokens()
     349             : {
     350             :     // convert and set formula of the defined name
     351          11 :     ApiTokenSequence aTokens;
     352          11 :     switch( getFilterType() )
     353             :     {
     354             :         case FILTER_OOXML:
     355             :         {
     356          11 :             if( mxFormula.get() )
     357             :             {
     358           0 :                 SequenceInputStream aStrm( *mxFormula );
     359           0 :                 aTokens = importBiff12Formula( mnCalcSheet, aStrm );
     360             :             }
     361             :             else
     362          11 :                 aTokens = importOoxFormula( mnCalcSheet );
     363             :         }
     364          11 :         break;
     365             :         case FILTER_BIFF:
     366             :         {
     367             :             OSL_ENSURE( mxBiffStrm.get(), "DefinedName::convertFormula - missing BIFF stream" );
     368           0 :             if( mxBiffStrm.get() )
     369             :             {
     370           0 :                 BiffInputStream& rStrm = mxBiffStrm->getStream();
     371           0 :                 BiffInputStreamPosGuard aStrmGuard( rStrm );
     372           0 :                 if( mxBiffStrm->restorePosition() )
     373           0 :                     aTokens = importBiffFormula( mnCalcSheet, rStrm, &mnFmlaSize );
     374             :             }
     375             :         }
     376           0 :         break;
     377             :         case FILTER_UNKNOWN:
     378           0 :         break;
     379             :     }
     380          11 :     return aTokens;
     381             : }
     382             : 
     383          11 : void DefinedName::convertFormula()
     384             : {
     385             :     // macro function or vba procedure
     386          11 :     if(!mpScRangeData)
     387          11 :         return;
     388             : 
     389             :     // convert and set formula of the defined name
     390          11 :     if ( getFilterType() == FILTER_OOXML )
     391             :     {
     392          11 :         ApiTokenSequence aTokens = getTokens();
     393          22 :         ScTokenArray aTokenArray;
     394          11 :         (void)ScTokenConversion::ConvertToTokenArray( this->getScDocument(), aTokenArray, aTokens );
     395          22 :         mpScRangeData->SetCode( aTokenArray );
     396             :     }
     397             : 
     398          11 :     ScTokenArray* pTokenArray = mpScRangeData->GetCode();
     399          11 :     Sequence< FormulaToken > aFTokenSeq;
     400          11 :     (void)ScTokenConversion::ConvertToTokenSequence( this->getScDocument(), aFTokenSeq, *pTokenArray );
     401             :     // set built-in names (print ranges, repeated titles, filter ranges)
     402          11 :     if( !isGlobalName() ) switch( mcBuiltinId )
     403             :     {
     404             :         case BIFF_DEFNAME_PRINTAREA:
     405             :         {
     406           0 :             Reference< XPrintAreas > xPrintAreas( getSheetFromDoc( mnCalcSheet ), UNO_QUERY );
     407           0 :             ApiCellRangeList aPrintRanges;
     408           0 :             getFormulaParser().extractCellRangeList( aPrintRanges, aFTokenSeq, false, mnCalcSheet );
     409           0 :             if( xPrintAreas.is() && !aPrintRanges.empty() )
     410           0 :                 xPrintAreas->setPrintAreas( ContainerHelper::vectorToSequence( aPrintRanges ) );
     411             :         }
     412           0 :         break;
     413             :         case BIFF_DEFNAME_PRINTTITLES:
     414             :         {
     415           0 :             Reference< XPrintAreas > xPrintAreas( getSheetFromDoc( mnCalcSheet ), UNO_QUERY );
     416           0 :             ApiCellRangeList aTitleRanges;
     417           0 :             getFormulaParser().extractCellRangeList( aTitleRanges, aFTokenSeq, false, mnCalcSheet );
     418           0 :             if( xPrintAreas.is() && !aTitleRanges.empty() )
     419             :             {
     420           0 :                 bool bHasRowTitles = false;
     421           0 :                 bool bHasColTitles = false;
     422           0 :                 const CellAddress& rMaxPos = getAddressConverter().getMaxAddress();
     423           0 :                 for( ApiCellRangeList::const_iterator aIt = aTitleRanges.begin(), aEnd = aTitleRanges.end(); (aIt != aEnd) && (!bHasRowTitles || !bHasColTitles); ++aIt )
     424             :                 {
     425           0 :                     bool bFullRow = (aIt->StartColumn == 0) && (aIt->EndColumn >= rMaxPos.Column);
     426           0 :                     bool bFullCol = (aIt->StartRow == 0) && (aIt->EndRow >= rMaxPos.Row);
     427           0 :                     if( !bHasRowTitles && bFullRow && !bFullCol )
     428             :                     {
     429           0 :                         xPrintAreas->setTitleRows( *aIt );
     430           0 :                         xPrintAreas->setPrintTitleRows( sal_True );
     431           0 :                         bHasRowTitles = true;
     432             :                     }
     433           0 :                     else if( !bHasColTitles && bFullCol && !bFullRow )
     434             :                     {
     435           0 :                         xPrintAreas->setTitleColumns( *aIt );
     436           0 :                         xPrintAreas->setPrintTitleColumns( sal_True );
     437           0 :                         bHasColTitles = true;
     438             :                     }
     439             :                 }
     440           0 :             }
     441             :         }
     442           0 :         break;
     443          11 :     }
     444             : }
     445             : 
     446           1 : bool DefinedName::getAbsoluteRange( CellRangeAddress& orRange ) const
     447             : {
     448           1 :     ScTokenArray* pTokenArray = mpScRangeData->GetCode();
     449           1 :     Sequence< FormulaToken > aFTokenSeq;
     450           1 :     ScTokenConversion::ConvertToTokenSequence(getScDocument(), aFTokenSeq, *pTokenArray);
     451           1 :     return getFormulaParser().extractCellRange( orRange, aFTokenSeq, false );
     452             : }
     453             : 
     454          44 : DefinedNamesBuffer::DefinedNamesBuffer( const WorkbookHelper& rHelper ) :
     455          44 :     WorkbookHelper( rHelper )
     456             : {
     457          44 : }
     458             : 
     459          11 : DefinedNameRef DefinedNamesBuffer::importDefinedName( const AttributeList& rAttribs )
     460             : {
     461          11 :     DefinedNameRef xDefName = createDefinedName();
     462          11 :     xDefName->importDefinedName( rAttribs );
     463          11 :     return xDefName;
     464             : }
     465             : 
     466           0 : void DefinedNamesBuffer::importDefinedName( SequenceInputStream& rStrm )
     467             : {
     468           0 :     createDefinedName()->importDefinedName( rStrm );
     469           0 : }
     470             : 
     471          44 : void DefinedNamesBuffer::finalizeImport()
     472             : {
     473             :     // first insert all names without formula definition into the document, and insert them into the maps
     474          44 :     int index = 0;
     475          55 :     for( DefNameVector::iterator aIt = maDefNames.begin(), aEnd = maDefNames.end(); aIt != aEnd; ++aIt )
     476             :     {
     477          11 :         DefinedNameRef xDefName = *aIt;
     478          11 :         xDefName->createNameObject( ++index );
     479             :         // map by sheet index and original model name
     480          11 :         maModelNameMap[ SheetNameKey( xDefName->getLocalCalcSheet(), xDefName->getUpcaseModelName() ) ] = xDefName;
     481             :         // map by sheet index and built-in identifier
     482          11 :         if( !xDefName->isGlobalName() && xDefName->isBuiltinName() )
     483           1 :             maBuiltinMap[ BuiltinKey( xDefName->getLocalCalcSheet(), xDefName->getBuiltinId() ) ] = xDefName;
     484             :         // map by API formula token identifier
     485          11 :         sal_Int32 nTokenIndex = xDefName->getTokenIndex();
     486          11 :         if( nTokenIndex >= 0 )
     487          11 :             maTokenIdMap[ nTokenIndex ] = xDefName;
     488          11 :     }
     489             : 
     490             :     /*  Now convert all name formulas, so that the formula parser can find all
     491             :         names in case of circular dependencies. */
     492          44 :     maDefNames.forEachMem( &DefinedName::convertFormula );
     493          44 : }
     494             : 
     495           0 : DefinedNameRef DefinedNamesBuffer::getByIndex( sal_Int32 nIndex ) const
     496             : {
     497           0 :     return maDefNames.get( nIndex );
     498             : }
     499             : 
     500           0 : DefinedNameRef DefinedNamesBuffer::getByTokenIndex( sal_Int32 nIndex ) const
     501             : {
     502           0 :     return maTokenIdMap.get( nIndex );
     503             : }
     504             : 
     505           0 : DefinedNameRef DefinedNamesBuffer::getByModelName( const OUString& rModelName, sal_Int16 nCalcSheet ) const
     506             : {
     507           0 :     OUString aUpcaseName = lclGetUpcaseModelName( rModelName );
     508           0 :     DefinedNameRef xDefName = maModelNameMap.get( SheetNameKey( nCalcSheet, aUpcaseName ) );
     509             :     // lookup global name, if no local name exists
     510           0 :     if( !xDefName && (nCalcSheet >= 0) )
     511           0 :         xDefName = maModelNameMap.get( SheetNameKey( -1, aUpcaseName ) );
     512           0 :     return xDefName;
     513             : }
     514             : 
     515          85 : DefinedNameRef DefinedNamesBuffer::getByBuiltinId( sal_Unicode cBuiltinId, sal_Int16 nCalcSheet ) const
     516             : {
     517          85 :     return maBuiltinMap.get( BuiltinKey( nCalcSheet, cBuiltinId ) );
     518             : }
     519             : 
     520          11 : DefinedNameRef DefinedNamesBuffer::createDefinedName()
     521             : {
     522          11 :     DefinedNameRef xDefName( new DefinedName( *this ) );
     523          11 :     maDefNames.push_back( xDefName );
     524          11 :     return xDefName;
     525             : }
     526             : 
     527             : } // namespace xls
     528          18 : } // namespace oox
     529             : 
     530             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10