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

Generated by: LCOV version 1.10