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

Generated by: LCOV version 1.10