LCOV - code coverage report
Current view: top level - sc/source/ui/unoobj - nameuno.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 434 627 69.2 %
Date: 2014-04-11 Functions: 62 111 55.9 %
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 <svl/smplhint.hxx>
      21             : #include <vcl/svapp.hxx>
      22             : 
      23             : #include <com/sun/star/sheet/NamedRangeFlag.hpp>
      24             : #include <com/sun/star/awt/XBitmap.hpp>
      25             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      26             : 
      27             : #include <comphelper/servicehelper.hxx>
      28             : #include <cppuhelper/supportsservice.hxx>
      29             : 
      30             : using namespace ::com::sun::star;
      31             : using ::com::sun::star::uno::Reference;
      32             : using ::com::sun::star::uno::Any;
      33             : 
      34             : 
      35             : #include "nameuno.hxx"
      36             : #include "miscuno.hxx"
      37             : #include "cellsuno.hxx"
      38             : #include "convuno.hxx"
      39             : #include "targuno.hxx"
      40             : #include "tokenuno.hxx"
      41             : #include "tokenarray.hxx"
      42             : #include "docsh.hxx"
      43             : #include "docfunc.hxx"
      44             : #include "rangenam.hxx"
      45             : #include "unonames.hxx"
      46             : 
      47             : #include "scui_def.hxx"
      48             : 
      49           0 : static const SfxItemPropertyMapEntry* lcl_GetNamedRangeMap()
      50             : {
      51             :     static const SfxItemPropertyMapEntry aNamedRangeMap_Impl[] =
      52             :     {
      53           0 :         {OUString(SC_UNO_LINKDISPBIT),      0,  getCppuType((uno::Reference<awt::XBitmap>*)0), beans::PropertyAttribute::READONLY, 0 },
      54           0 :         {OUString(SC_UNO_LINKDISPNAME),     0,  getCppuType((OUString*)0),                beans::PropertyAttribute::READONLY, 0 },
      55           0 :         {OUString(SC_UNONAME_TOKENINDEX),   0,  getCppuType((sal_Int32*)0),                    beans::PropertyAttribute::READONLY, 0 },
      56           0 :         {OUString(SC_UNONAME_ISSHAREDFMLA), 0,  getBooleanCppuType(),                          0, 0 },
      57             :         { OUString(), 0, css::uno::Type(), 0, 0 }
      58           0 :     };
      59           0 :     return aNamedRangeMap_Impl;
      60             : }
      61             : 
      62           0 : static const SfxItemPropertyMapEntry* lcl_GetNamedRangesMap()
      63             : {
      64             :     static const SfxItemPropertyMapEntry aNamedRangesMap_Impl[] =
      65             :     {
      66           0 :         {OUString(SC_UNO_MODIFY_BROADCAST), 0,  getBooleanCppuType(), 0, 0 },
      67             :         { OUString(), 0, css::uno::Type(), 0, 0 }
      68           0 :     };
      69           0 :     return aNamedRangesMap_Impl;
      70             : }
      71             : 
      72             : #define SCNAMEDRANGEOBJ_SERVICE     "com.sun.star.sheet.NamedRange"
      73             : 
      74           0 : SC_SIMPLE_SERVICE_INFO( ScLabelRangeObj, "ScLabelRangeObj", "com.sun.star.sheet.LabelRange" )
      75           0 : SC_SIMPLE_SERVICE_INFO( ScLabelRangesObj, "ScLabelRangesObj", "com.sun.star.sheet.LabelRanges" )
      76           0 : SC_SIMPLE_SERVICE_INFO( ScNamedRangesObj, "ScNamedRangesObj", "com.sun.star.sheet.NamedRanges" )
      77             : 
      78         276 : static bool lcl_UserVisibleName(const ScRangeData& rData)
      79             : {
      80             :     //! as method to ScRangeData
      81             : 
      82         276 :     return !rData.HasType(RT_DATABASE);
      83             : }
      84             : 
      85         168 : ScNamedRangeObj::ScNamedRangeObj( rtl::Reference< ScNamedRangesObj > xParent, ScDocShell* pDocSh, const OUString& rNm, Reference<container::XNamed> xSheet):
      86             :     mxParent(xParent),
      87             :     pDocShell( pDocSh ),
      88             :     aName( rNm ),
      89         168 :     mxSheet( xSheet )
      90             : {
      91         168 :     pDocShell->GetDocument()->AddUnoObject(*this);
      92         168 : }
      93             : 
      94         504 : ScNamedRangeObj::~ScNamedRangeObj()
      95             : {
      96         168 :     if (pDocShell)
      97         162 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
      98         336 : }
      99             : 
     100          27 : void ScNamedRangeObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
     101             : {
     102             :     // reference update is of no interest
     103             : 
     104          27 :     if ( rHint.ISA( SfxSimpleHint ) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
     105           6 :         pDocShell = NULL;       // became invalid
     106          27 : }
     107             : 
     108             : // Helper functions
     109             : 
     110         162 : ScRangeData* ScNamedRangeObj::GetRangeData_Impl()
     111             : {
     112         162 :     ScRangeData* pRet = NULL;
     113         162 :     if (pDocShell)
     114             :     {
     115             :         ScRangeName* pNames;
     116         162 :         SCTAB nTab = GetTab_Impl();
     117         162 :         if (nTab >= 0)
     118           0 :             pNames = pDocShell->GetDocument()->GetRangeName(nTab);
     119             :         else
     120         162 :             pNames = pDocShell->GetDocument()->GetRangeName();
     121         162 :         if (pNames)
     122             :         {
     123         162 :             pRet = pNames->findByUpperName(ScGlobal::pCharClass->uppercase(aName));
     124         162 :             if (pRet)
     125         162 :                 pRet->ValidateTabRefs();        // adjust relative tab refs to valid tables
     126             :         }
     127             :     }
     128         162 :     return pRet;
     129             : }
     130             : 
     131         173 : SCTAB ScNamedRangeObj::GetTab_Impl()
     132             : {
     133         173 :     if (mxSheet.is())
     134             :     {
     135           0 :         if (!pDocShell)
     136           0 :             return -2;
     137           0 :         ScDocument* pDoc = pDocShell->GetDocument();
     138             :         SCTAB nTab;
     139           0 :         OUString sName = mxSheet->getName();
     140           0 :         pDoc->GetTable(sName, nTab);
     141           0 :         return nTab;
     142             :     }
     143             :     else
     144         173 :         return -1;//global range name
     145             : }
     146             : 
     147             : // sheet::XNamedRange
     148             : 
     149          11 : void ScNamedRangeObj::Modify_Impl( const OUString* pNewName, const ScTokenArray* pNewTokens, const OUString* pNewContent,
     150             :                                     const ScAddress* pNewPos, const sal_uInt16* pNewType,
     151             :                                     const formula::FormulaGrammar::Grammar eGrammar )
     152             : {
     153          11 :     if (!pDocShell)
     154           0 :         return;
     155             : 
     156          11 :     ScDocument* pDoc = pDocShell->GetDocument();
     157             :     ScRangeName* pNames;
     158          11 :     SCTAB nTab = GetTab_Impl();
     159          11 :     if (nTab >= 0)
     160           0 :         pNames = pDoc->GetRangeName(nTab);
     161             :     else
     162          11 :         pNames = pDoc->GetRangeName();
     163          11 :     if (!pNames)
     164           0 :         return;
     165             : 
     166          11 :     const ScRangeData* pOld = pNames->findByUpperName(ScGlobal::pCharClass->uppercase(aName));
     167          11 :     if (!pOld)
     168           0 :         return;
     169             : 
     170          11 :     ScRangeName* pNewRanges = new ScRangeName(*pNames);
     171             : 
     172          11 :     OUString aInsName = pOld->GetName();
     173          11 :     if (pNewName)
     174           2 :         aInsName = *pNewName;
     175             : 
     176          22 :     OUString aContent;                            // Content string based =>
     177          11 :     pOld->GetSymbol( aContent, eGrammar);   // no problems with changed positions and such.
     178          11 :     if (pNewContent)
     179           3 :         aContent = *pNewContent;
     180             : 
     181          11 :     ScAddress aPos = pOld->GetPos();
     182          11 :     if (pNewPos)
     183           1 :         aPos = *pNewPos;
     184             : 
     185          11 :     sal_uInt16 nType = pOld->GetType();
     186          11 :     if (pNewType)
     187           5 :         nType = *pNewType;
     188             : 
     189          11 :     ScRangeData* pNew = NULL;
     190          11 :     if (pNewTokens)
     191           0 :         pNew = new ScRangeData( pDoc, aInsName, *pNewTokens, aPos, nType );
     192             :     else
     193          11 :         pNew = new ScRangeData( pDoc, aInsName, aContent, aPos, nType, eGrammar );
     194             : 
     195          11 :     pNew->SetIndex( pOld->GetIndex() );
     196             : 
     197          11 :     pNewRanges->erase(*pOld);
     198          11 :     if (pNewRanges->insert(pNew))
     199             :     {
     200          11 :         pDocShell->GetDocFunc().SetNewRangeNames(pNewRanges, mxParent->IsModifyAndBroadcast(), nTab);
     201             : 
     202          11 :         aName = aInsName;   //! broadcast?
     203             :     }
     204             :     else
     205             :     {
     206           0 :         pNew = NULL;        //! uno::Exception/Error or something
     207           0 :         delete pNewRanges;
     208          11 :     }
     209             : }
     210             : 
     211             : 
     212          14 : OUString SAL_CALL ScNamedRangeObj::getName() throw(uno::RuntimeException, std::exception)
     213             : {
     214          14 :     SolarMutexGuard aGuard;
     215          14 :     return aName;
     216             : }
     217             : 
     218           2 : void SAL_CALL ScNamedRangeObj::setName( const OUString& aNewName )
     219             :     throw (uno::RuntimeException, std::exception)
     220             : {
     221           2 :     SolarMutexGuard aGuard;
     222             :     //! adapt formulas ?????
     223             : 
     224           4 :     OUString aNewStr(aNewName);
     225             :     // GRAM_PODF_A1 for API compatibility.
     226           2 :     Modify_Impl( &aNewStr, NULL, NULL, NULL, NULL,formula::FormulaGrammar::GRAM_PODF_A1 );
     227             : 
     228           2 :     if ( aName != aNewStr )                 // some error occurred...
     229           2 :         throw uno::RuntimeException();      // no other exceptions specified
     230           2 : }
     231             : 
     232          27 : OUString SAL_CALL ScNamedRangeObj::getContent() throw(uno::RuntimeException, std::exception)
     233             : {
     234          27 :     SolarMutexGuard aGuard;
     235          27 :     OUString aContent;
     236          27 :     ScRangeData* pData = GetRangeData_Impl();
     237          27 :     if (pData)
     238             :         // GRAM_PODF_A1 for API compatibility.
     239          27 :         pData->GetSymbol( aContent,formula::FormulaGrammar::GRAM_PODF_A1);
     240          27 :     return aContent;
     241             : }
     242             : 
     243           3 : void SAL_CALL ScNamedRangeObj::setContent( const OUString& aContent )
     244             :     throw (uno::RuntimeException, std::exception)
     245             : {
     246           3 :     SolarMutexGuard aGuard;
     247           6 :     OUString aContStr(aContent);
     248             :     // GRAM_PODF_A1 for API compatibility.
     249           6 :     Modify_Impl( NULL, NULL, &aContStr, NULL, NULL,formula::FormulaGrammar::GRAM_PODF_A1 );
     250           3 : }
     251             : 
     252           2 : table::CellAddress SAL_CALL ScNamedRangeObj::getReferencePosition()
     253             :                                                 throw(uno::RuntimeException, std::exception)
     254             : {
     255           2 :     SolarMutexGuard aGuard;
     256           2 :     ScAddress aPos;
     257           2 :     ScRangeData* pData = GetRangeData_Impl();
     258           2 :     if (pData)
     259           2 :         aPos = pData->GetPos();
     260           2 :     table::CellAddress aAddress;
     261           2 :     aAddress.Column = aPos.Col();
     262           2 :     aAddress.Row    = aPos.Row();
     263           2 :     aAddress.Sheet  = aPos.Tab();
     264           2 :     if (pDocShell)
     265             :     {
     266           2 :         SCTAB nDocTabs = pDocShell->GetDocument()->GetTableCount();
     267           2 :         if ( aAddress.Sheet >= nDocTabs && nDocTabs > 0 )
     268             :         {
     269             :             //  Even after ValidateTabRefs, the position can be invalid if
     270             :             //  the content points to preceding tables. The resulting string
     271             :             //  is invalid in any case, so the position is just shifted.
     272           0 :             aAddress.Sheet = nDocTabs - 1;
     273             :         }
     274             :     }
     275           2 :     return aAddress;
     276             : }
     277             : 
     278           1 : void SAL_CALL ScNamedRangeObj::setReferencePosition( const table::CellAddress& aReferencePosition )
     279             :     throw (uno::RuntimeException, std::exception)
     280             : {
     281           1 :     SolarMutexGuard aGuard;
     282           1 :     ScAddress aPos( (SCCOL)aReferencePosition.Column, (SCROW)aReferencePosition.Row, aReferencePosition.Sheet );
     283             :     // GRAM_PODF_A1 for API compatibility.
     284           1 :     Modify_Impl( NULL, NULL, NULL, &aPos, NULL,formula::FormulaGrammar::GRAM_PODF_A1 );
     285           1 : }
     286             : 
     287           6 : sal_Int32 SAL_CALL ScNamedRangeObj::getType() throw(uno::RuntimeException, std::exception)
     288             : {
     289           6 :     SolarMutexGuard aGuard;
     290           6 :     sal_Int32 nType=0;
     291           6 :     ScRangeData* pData = GetRangeData_Impl();
     292           6 :     if (pData)
     293             :     {
     294             :         // do not return internal RT_* flags
     295             :         // see property 'IsSharedFormula' for RT_SHARED
     296           6 :         if ( pData->HasType(RT_CRITERIA) )  nType |= sheet::NamedRangeFlag::FILTER_CRITERIA;
     297           6 :         if ( pData->HasType(RT_PRINTAREA) ) nType |= sheet::NamedRangeFlag::PRINT_AREA;
     298           6 :         if ( pData->HasType(RT_COLHEADER) ) nType |= sheet::NamedRangeFlag::COLUMN_HEADER;
     299           6 :         if ( pData->HasType(RT_ROWHEADER) ) nType |= sheet::NamedRangeFlag::ROW_HEADER;
     300             :     }
     301           6 :     return nType;
     302             : }
     303             : 
     304           5 : void SAL_CALL ScNamedRangeObj::setType( sal_Int32 nUnoType )
     305             :     throw (uno::RuntimeException, std::exception)
     306             : {
     307             :     // see property 'IsSharedFormula' for RT_SHARED
     308           5 :     SolarMutexGuard aGuard;
     309           5 :     sal_uInt16 nNewType = RT_NAME;
     310           5 :     if ( nUnoType & sheet::NamedRangeFlag::FILTER_CRITERIA )    nNewType |= RT_CRITERIA;
     311           5 :     if ( nUnoType & sheet::NamedRangeFlag::PRINT_AREA )         nNewType |= RT_PRINTAREA;
     312           5 :     if ( nUnoType & sheet::NamedRangeFlag::COLUMN_HEADER )      nNewType |= RT_COLHEADER;
     313           5 :     if ( nUnoType & sheet::NamedRangeFlag::ROW_HEADER )         nNewType |= RT_ROWHEADER;
     314             : 
     315             :     // GRAM_PODF_A1 for API compatibility.
     316           5 :     Modify_Impl( NULL, NULL, NULL, NULL, &nNewType,formula::FormulaGrammar::GRAM_PODF_A1 );
     317           5 : }
     318             : 
     319             : // XFormulaTokens
     320             : 
     321           0 : uno::Sequence<sheet::FormulaToken> SAL_CALL ScNamedRangeObj::getTokens()
     322             :     throw (uno::RuntimeException, std::exception)
     323             : {
     324           0 :     SolarMutexGuard aGuard;
     325           0 :     uno::Sequence<sheet::FormulaToken> aSequence;
     326           0 :     ScRangeData* pData = GetRangeData_Impl();
     327           0 :     if (pData && pDocShell)
     328             :     {
     329           0 :         ScTokenArray* pTokenArray = pData->GetCode();
     330           0 :         if ( pTokenArray )
     331           0 :             (void)ScTokenConversion::ConvertToTokenSequence( *pDocShell->GetDocument(), aSequence, *pTokenArray );
     332             :     }
     333           0 :     return aSequence;
     334             : }
     335             : 
     336           0 : void SAL_CALL ScNamedRangeObj::setTokens( const uno::Sequence<sheet::FormulaToken>& rTokens )
     337             :     throw (uno::RuntimeException, std::exception)
     338             : {
     339           0 :     SolarMutexGuard aGuard;
     340           0 :     if( pDocShell )
     341             :     {
     342           0 :         ScTokenArray aTokenArray;
     343           0 :         (void)ScTokenConversion::ConvertToTokenArray( *pDocShell->GetDocument(), aTokenArray, rTokens );
     344             :         // GRAM_PODF_A1 for API compatibility.
     345           0 :         Modify_Impl( NULL, &aTokenArray, NULL, NULL, NULL, formula::FormulaGrammar::GRAM_PODF_A1 );
     346           0 :     }
     347           0 : }
     348             : 
     349             : 
     350             : // XCellRangeSource
     351             : 
     352         119 : uno::Reference<table::XCellRange> SAL_CALL ScNamedRangeObj::getReferredCells()
     353             :                                                 throw(uno::RuntimeException, std::exception)
     354             : {
     355         119 :     SolarMutexGuard aGuard;
     356         119 :     ScRange aRange;
     357         119 :     ScRangeData* pData = GetRangeData_Impl();
     358         119 :     if ( pData && pData->IsValidReference( aRange ) )
     359             :     {
     360             :         //! static function to create ScCellObj/ScCellRangeObj at ScCellRangeObj ???
     361             : 
     362         113 :         if ( aRange.aStart == aRange.aEnd )
     363         107 :             return new ScCellObj( pDocShell, aRange.aStart );
     364             :         else
     365           6 :             return new ScCellRangeObj( pDocShell, aRange );
     366             :     }
     367           6 :     return NULL;
     368             : }
     369             : 
     370             : // beans::XPropertySet
     371             : 
     372           0 : uno::Reference<beans::XPropertySetInfo> SAL_CALL ScNamedRangeObj::getPropertySetInfo()
     373             :                                                         throw(uno::RuntimeException, std::exception)
     374             : {
     375           0 :     SolarMutexGuard aGuard;
     376           0 :     static uno::Reference< beans::XPropertySetInfo >  aRef(new SfxItemPropertySetInfo( lcl_GetNamedRangeMap() ));
     377           0 :     return aRef;
     378             : }
     379             : 
     380           0 : void SAL_CALL ScNamedRangeObj::setPropertyValue(
     381             :                         const OUString& rPropertyName, const uno::Any& /*aValue*/ )
     382             :                 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
     383             :                         lang::IllegalArgumentException, lang::WrappedTargetException,
     384             :                         uno::RuntimeException, std::exception)
     385             : {
     386           0 :     SolarMutexGuard aGuard;
     387           0 :     if ( rPropertyName == SC_UNONAME_ISSHAREDFMLA )
     388             :     {
     389             :         // Ignore this.
     390           0 :     }
     391           0 : }
     392             : 
     393           0 : uno::Any SAL_CALL ScNamedRangeObj::getPropertyValue( const OUString& rPropertyName )
     394             :                 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
     395             :                         uno::RuntimeException, std::exception)
     396             : {
     397           0 :     SolarMutexGuard aGuard;
     398           0 :     uno::Any aRet;
     399           0 :     if ( rPropertyName == SC_UNO_LINKDISPBIT )
     400             :     {
     401             :         //  no target bitmaps for individual entries (would be all equal)
     402             :         // ScLinkTargetTypeObj::SetLinkTargetBitmap( aRet, SC_LINKTARGETTYPE_RANGENAME );
     403             :     }
     404           0 :     else if ( rPropertyName == SC_UNO_LINKDISPNAME )
     405           0 :         aRet <<= OUString( aName );
     406           0 :     else if ( rPropertyName == SC_UNONAME_TOKENINDEX )
     407             :     {
     408             :         // get index for use in formula tokens (read-only)
     409           0 :         ScRangeData* pData = GetRangeData_Impl();
     410           0 :         if (pData)
     411           0 :             aRet <<= static_cast<sal_Int32>(pData->GetIndex());
     412             :     }
     413           0 :     else if ( rPropertyName == SC_UNONAME_ISSHAREDFMLA )
     414             :     {
     415           0 :         if (GetRangeData_Impl())
     416           0 :             aRet <<= false;
     417             :     }
     418           0 :     return aRet;
     419             : }
     420             : 
     421           0 : SC_IMPL_DUMMY_PROPERTY_LISTENER( ScNamedRangeObj )
     422             : 
     423             : // lang::XServiceInfo
     424             : 
     425           0 : OUString SAL_CALL ScNamedRangeObj::getImplementationName() throw(uno::RuntimeException, std::exception)
     426             : {
     427           0 :     return OUString( "ScNamedRangeObj" );
     428             : }
     429             : 
     430           0 : sal_Bool SAL_CALL ScNamedRangeObj::supportsService( const OUString& rServiceName )
     431             :                                                     throw(uno::RuntimeException, std::exception)
     432             : {
     433           0 :     return cppu::supportsService(this, rServiceName);
     434             : }
     435             : 
     436           0 : uno::Sequence<OUString> SAL_CALL ScNamedRangeObj::getSupportedServiceNames()
     437             :                                                     throw(uno::RuntimeException, std::exception)
     438             : {
     439           0 :     uno::Sequence<OUString> aRet(2);
     440           0 :     aRet[0] = OUString( SCNAMEDRANGEOBJ_SERVICE );
     441           0 :     aRet[1] = OUString( SCLINKTARGET_SERVICE );
     442           0 :     return aRet;
     443             : }
     444             : 
     445             : 
     446             : // XUnoTunnel
     447             : 
     448           0 : sal_Int64 SAL_CALL ScNamedRangeObj::getSomething(
     449             :                 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException, std::exception)
     450             : {
     451           0 :     if ( rId.getLength() == 16 &&
     452           0 :           0 == memcmp( getUnoTunnelId().getConstArray(),
     453           0 :                                     rId.getConstArray(), 16 ) )
     454             :     {
     455           0 :         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
     456             :     }
     457           0 :     return 0;
     458             : }
     459             : 
     460             : namespace
     461             : {
     462             :     class theScNamedRangeObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScNamedRangeObjUnoTunnelId> {};
     463             : }
     464             : 
     465           0 : const uno::Sequence<sal_Int8>& ScNamedRangeObj::getUnoTunnelId()
     466             : {
     467           0 :     return theScNamedRangeObjUnoTunnelId::get().getSeq();
     468             : }
     469             : 
     470        1413 : ScNamedRangesObj::ScNamedRangesObj(ScDocShell* pDocSh) :
     471             :     mbModifyAndBroadcast(true),
     472        1413 :     pDocShell( pDocSh )
     473             : {
     474        1413 :     pDocShell->GetDocument()->AddUnoObject(*this);
     475        1413 : }
     476             : 
     477        2826 : ScNamedRangesObj::~ScNamedRangesObj()
     478             : {
     479        1413 :     if (pDocShell)
     480        1406 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
     481        1413 : }
     482             : 
     483         221 : void ScNamedRangesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
     484             : {
     485             :     // reference update is of no interest
     486             : 
     487         442 :     if ( rHint.ISA( SfxSimpleHint ) &&
     488         221 :             ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
     489             :     {
     490           7 :         pDocShell = NULL;       // became invalid
     491             :     }
     492         221 : }
     493             : 
     494          11 : bool ScNamedRangesObj::IsModifyAndBroadcast() const
     495             : {
     496          11 :     return mbModifyAndBroadcast;
     497             : }
     498             : 
     499             : // sheet::XNamedRanges
     500             : 
     501          13 : void SAL_CALL ScNamedRangesObj::addNewByName( const OUString& aName,
     502             :     const OUString& aContent, const table::CellAddress& aPosition,
     503             :     sal_Int32 nUnoType )
     504             :         throw (uno::RuntimeException, std::exception)
     505             : {
     506          13 :     SolarMutexGuard aGuard;
     507          13 :     ScAddress aPos( (SCCOL)aPosition.Column, (SCROW)aPosition.Row, aPosition.Sheet );
     508             : 
     509          13 :     sal_uInt16 nNewType = RT_NAME;
     510          13 :     if ( nUnoType & sheet::NamedRangeFlag::FILTER_CRITERIA )    nNewType |= RT_CRITERIA;
     511          13 :     if ( nUnoType & sheet::NamedRangeFlag::PRINT_AREA )         nNewType |= RT_PRINTAREA;
     512          13 :     if ( nUnoType & sheet::NamedRangeFlag::COLUMN_HEADER )      nNewType |= RT_COLHEADER;
     513          13 :     if ( nUnoType & sheet::NamedRangeFlag::ROW_HEADER )         nNewType |= RT_ROWHEADER;
     514             : 
     515          13 :     sal_Bool bDone = false;
     516          13 :     if (pDocShell)
     517             :     {
     518          13 :         ScDocument* pDoc = pDocShell->GetDocument();
     519          13 :         ScRangeName* pNames = GetRangeName_Impl();
     520          13 :         if (pNames && !pNames->findByUpperName(ScGlobal::pCharClass->uppercase(aName)))
     521             :         {
     522          13 :             ScRangeName* pNewRanges = new ScRangeName( *pNames );
     523             :             // GRAM_PODF_A1 for API compatibility.
     524             :             ScRangeData* pNew = new ScRangeData( pDoc, aName, aContent,
     525          13 :                                                 aPos, nNewType,formula::FormulaGrammar::GRAM_PODF_A1 );
     526          13 :             if ( pNewRanges->insert(pNew) )
     527             :             {
     528          13 :                 pDocShell->GetDocFunc().SetNewRangeNames(pNewRanges, mbModifyAndBroadcast, GetTab_Impl());
     529          13 :                 bDone = true;
     530             :             }
     531             :             else
     532             :             {
     533           0 :                 pNew = NULL;
     534           0 :                 delete pNewRanges;
     535             :             }
     536             :         }
     537             :     }
     538             : 
     539          13 :     if (!bDone)
     540           0 :         throw uno::RuntimeException();      // no other exceptions specified
     541          13 : }
     542             : 
     543           2 : void SAL_CALL ScNamedRangesObj::addNewFromTitles( const table::CellRangeAddress& aSource,
     544             :                                     sheet::Border aBorder ) throw(uno::RuntimeException, std::exception)
     545             : {
     546           2 :     SolarMutexGuard aGuard;
     547             :     //! this cannot be an enum, because multiple bits can be set !!!
     548             : 
     549           2 :     sal_Bool bTop    = ( aBorder == sheet::Border_TOP );
     550           2 :     sal_Bool bLeft   = ( aBorder == sheet::Border_LEFT );
     551           2 :     sal_Bool bBottom = ( aBorder == sheet::Border_BOTTOM );
     552           2 :     sal_Bool bRight  = ( aBorder == sheet::Border_RIGHT );
     553             : 
     554           2 :     ScRange aRange;
     555           2 :     ScUnoConversion::FillScRange( aRange, aSource );
     556             : 
     557           2 :     sal_uInt16 nFlags = 0;
     558           2 :     if (bTop)    nFlags |= NAME_TOP;
     559           2 :     if (bLeft)   nFlags |= NAME_LEFT;
     560           2 :     if (bBottom) nFlags |= NAME_BOTTOM;
     561           2 :     if (bRight)  nFlags |= NAME_RIGHT;
     562             : 
     563           2 :     if (nFlags)
     564           2 :         pDocShell->GetDocFunc().CreateNames( aRange, nFlags, true, GetTab_Impl() );
     565           2 : }
     566             : 
     567           5 : void SAL_CALL ScNamedRangesObj::removeByName( const OUString& aName )
     568             :                                                 throw(uno::RuntimeException, std::exception)
     569             : {
     570           5 :     SolarMutexGuard aGuard;
     571           5 :     bool bDone = false;
     572           5 :     if (pDocShell)
     573             :     {
     574           5 :         ScRangeName* pNames = GetRangeName_Impl();
     575           5 :         if (pNames)
     576             :         {
     577           5 :             const ScRangeData* pData = pNames->findByUpperName(ScGlobal::pCharClass->uppercase(aName));
     578           5 :             if (pData && lcl_UserVisibleName(*pData))
     579             :             {
     580           5 :                 ScRangeName* pNewRanges = new ScRangeName(*pNames);
     581           5 :                 pNewRanges->erase(*pData);
     582           5 :                 pDocShell->GetDocFunc().SetNewRangeNames( pNewRanges, mbModifyAndBroadcast, GetTab_Impl());
     583           5 :                 bDone = true;
     584             :             }
     585             :         }
     586             :     }
     587             : 
     588           5 :     if (!bDone)
     589           0 :         throw uno::RuntimeException();      // no other exceptions specified
     590           5 : }
     591             : 
     592           4 : void SAL_CALL ScNamedRangesObj::outputList( const table::CellAddress& aOutputPosition )
     593             :                                                 throw(uno::RuntimeException, std::exception)
     594             : {
     595           4 :     SolarMutexGuard aGuard;
     596           4 :     ScAddress aPos( (SCCOL)aOutputPosition.Column, (SCROW)aOutputPosition.Row, aOutputPosition.Sheet );
     597           4 :     if (pDocShell)
     598           4 :         pDocShell->GetDocFunc().InsertNameList( aPos, true );
     599           4 : }
     600             : 
     601             : // container::XEnumerationAccess
     602             : 
     603           2 : uno::Reference<container::XEnumeration> SAL_CALL ScNamedRangesObj::createEnumeration()
     604             :                                                     throw(uno::RuntimeException, std::exception)
     605             : {
     606           2 :     SolarMutexGuard aGuard;
     607           2 :     return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.NamedRangesEnumeration"));
     608             : }
     609             : 
     610             : // container::XIndexAccess
     611             : 
     612          16 : sal_Int32 SAL_CALL ScNamedRangesObj::getCount() throw(uno::RuntimeException, std::exception)
     613             : {
     614          16 :     SolarMutexGuard aGuard;
     615          16 :     long nRet = 0;
     616          16 :     if (pDocShell)
     617             :     {
     618          16 :         ScRangeName* pNames = GetRangeName_Impl();
     619          16 :         if (pNames)
     620             :         {
     621          16 :             ScRangeName::const_iterator itr = pNames->begin(), itrEnd = pNames->end();
     622          48 :             for (; itr != itrEnd; ++itr)
     623          32 :                 if (lcl_UserVisibleName(*itr->second))
     624          32 :                     ++nRet;
     625             :         }
     626             :     }
     627          16 :     return nRet;
     628             : }
     629             : 
     630          12 : uno::Any SAL_CALL ScNamedRangesObj::getByIndex( sal_Int32 nIndex )
     631             :                             throw(lang::IndexOutOfBoundsException,
     632             :                                     lang::WrappedTargetException, uno::RuntimeException, std::exception)
     633             : {
     634          12 :     SolarMutexGuard aGuard;
     635          24 :     uno::Reference< sheet::XNamedRange >  xRange(GetObjectByIndex_Impl((sal_uInt16)nIndex));
     636          12 :     if ( xRange.is() )
     637          20 :         return uno::makeAny(xRange);
     638             :     else
     639          14 :         throw lang::IndexOutOfBoundsException();
     640             : }
     641             : 
     642           1 : uno::Type SAL_CALL ScNamedRangesObj::getElementType() throw(uno::RuntimeException, std::exception)
     643             : {
     644           1 :     SolarMutexGuard aGuard;
     645           1 :     return ::getCppuType((const uno::Reference< sheet::XNamedRange >*)0);   // must be suitable for getByIndex
     646             : }
     647             : 
     648           1 : sal_Bool SAL_CALL ScNamedRangesObj::hasElements() throw(uno::RuntimeException, std::exception)
     649             : {
     650           1 :     SolarMutexGuard aGuard;
     651           1 :     return ( getCount() != 0 );
     652             : }
     653             : 
     654           0 : Reference<beans::XPropertySetInfo> SAL_CALL ScNamedRangesObj::getPropertySetInfo()
     655             :                                                         throw(uno::RuntimeException, std::exception)
     656             : {
     657             :     static Reference<beans::XPropertySetInfo> aRef(
     658           0 :         new SfxItemPropertySetInfo(lcl_GetNamedRangesMap()));
     659           0 :     return aRef;
     660             : }
     661             : 
     662           0 : void SAL_CALL ScNamedRangesObj::setPropertyValue(
     663             :                         const OUString& rPropertyName, const uno::Any& aValue )
     664             :                 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
     665             :                         lang::IllegalArgumentException, lang::WrappedTargetException,
     666             :                         uno::RuntimeException, std::exception)
     667             : {
     668           0 :     if ( rPropertyName == SC_UNO_MODIFY_BROADCAST )
     669             :     {
     670           0 :         aValue >>= mbModifyAndBroadcast;
     671             :     }
     672           0 : }
     673             : 
     674           0 : Any SAL_CALL ScNamedRangesObj::getPropertyValue( const OUString& rPropertyName )
     675             :                 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
     676             :                         uno::RuntimeException, std::exception)
     677             : {
     678           0 :     Any aRet;
     679           0 :     if ( rPropertyName == SC_UNO_MODIFY_BROADCAST )
     680             :     {
     681           0 :         aRet <<= mbModifyAndBroadcast;
     682             :     }
     683             : 
     684           0 :     return aRet;
     685             : }
     686             : 
     687           0 : SC_IMPL_DUMMY_PROPERTY_LISTENER( ScNamedRangesObj )
     688             : 
     689         717 : uno::Any SAL_CALL ScNamedRangesObj::getByName( const OUString& aName )
     690             :             throw(container::NoSuchElementException,
     691             :                     lang::WrappedTargetException, uno::RuntimeException, std::exception)
     692             : {
     693         717 :     SolarMutexGuard aGuard;
     694        1434 :     uno::Reference< sheet::XNamedRange >  xRange(GetObjectByName_Impl(aName));
     695         717 :     if ( xRange.is() )
     696         316 :         return uno::makeAny(xRange);
     697             :     else
     698        1276 :         throw container::NoSuchElementException();
     699             : }
     700             : 
     701           1 : uno::Sequence<OUString> SAL_CALL ScNamedRangesObj::getElementNames()
     702             :                                                 throw(uno::RuntimeException, std::exception)
     703             : {
     704           1 :     SolarMutexGuard aGuard;
     705           1 :     if (pDocShell)
     706             :     {
     707           1 :         ScRangeName* pNames = GetRangeName_Impl();
     708           1 :         if (pNames)
     709             :         {
     710           1 :             long nVisCount = getCount();            // names with lcl_UserVisibleName
     711           1 :             uno::Sequence<OUString> aSeq(nVisCount);
     712           1 :             OUString* pAry = aSeq.getArray();
     713           1 :             sal_uInt16 nVisPos = 0;
     714           1 :             ScRangeName::const_iterator itr = pNames->begin(), itrEnd = pNames->end();
     715           2 :             for (; itr != itrEnd; ++itr)
     716             :             {
     717           1 :                 if (lcl_UserVisibleName(*itr->second))
     718           1 :                     pAry[nVisPos++] = itr->second->GetName();
     719             :             }
     720           1 :             return aSeq;
     721             :         }
     722             :     }
     723           0 :     return uno::Sequence<OUString>(0);
     724             : }
     725             : 
     726        2224 : sal_Bool SAL_CALL ScNamedRangesObj::hasByName( const OUString& aName )
     727             :                                         throw(uno::RuntimeException, std::exception)
     728             : {
     729        2224 :     SolarMutexGuard aGuard;
     730        2224 :     if (pDocShell)
     731             :     {
     732        2224 :         ScRangeName* pNames = GetRangeName_Impl();
     733        2224 :         if (pNames)
     734             :         {
     735        2224 :             const ScRangeData* pData = pNames->findByUpperName(ScGlobal::pCharClass->uppercase(aName));
     736        2224 :             if (pData && lcl_UserVisibleName(*pData))
     737         226 :                 return sal_True;
     738             :         }
     739             :     }
     740        1998 :     return false;
     741             : }
     742             : 
     743             : /** called from the XActionLockable interface methods on initial locking */
     744           0 : void ScNamedRangesObj::lock()
     745             : {
     746           0 :     pDocShell->GetDocument()->PreprocessRangeNameUpdate();
     747           0 : }
     748             : 
     749             : /** called from the XActionLockable interface methods on final unlock */
     750           0 : void ScNamedRangesObj::unlock()
     751             : {
     752           0 :     pDocShell->GetDocument()->PostprocessRangeNameUpdate();
     753           0 : }
     754             : 
     755             : // document::XActionLockable
     756             : 
     757           0 : sal_Bool ScNamedRangesObj::isActionLocked() throw(uno::RuntimeException, std::exception)
     758             : {
     759           0 :     SolarMutexGuard aGuard;
     760           0 :     return pDocShell->GetDocument()->GetNamedRangesLockCount() != 0;
     761             : }
     762             : 
     763           0 : void ScNamedRangesObj::addActionLock() throw(uno::RuntimeException, std::exception)
     764             : {
     765           0 :     SolarMutexGuard aGuard;
     766           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     767           0 :     sal_Int16 nLockCount = pDoc->GetNamedRangesLockCount();
     768           0 :     ++nLockCount;
     769           0 :     if ( nLockCount == 1 )
     770             :     {
     771           0 :         lock();
     772             :     }
     773           0 :     pDoc->SetNamedRangesLockCount( nLockCount );
     774           0 : }
     775             : 
     776           0 : void ScNamedRangesObj::removeActionLock() throw(uno::RuntimeException, std::exception)
     777             : {
     778           0 :     SolarMutexGuard aGuard;
     779           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     780           0 :     sal_Int16 nLockCount = pDoc->GetNamedRangesLockCount();
     781           0 :     if ( nLockCount > 0 )
     782             :     {
     783           0 :         --nLockCount;
     784           0 :         if ( nLockCount == 0 )
     785             :         {
     786           0 :             unlock();
     787             :         }
     788           0 :         pDoc->SetNamedRangesLockCount( nLockCount );
     789           0 :     }
     790           0 : }
     791             : 
     792           0 : void ScNamedRangesObj::setActionLocks( sal_Int16 nLock ) throw(uno::RuntimeException, std::exception)
     793             : {
     794           0 :     SolarMutexGuard aGuard;
     795           0 :     if ( nLock >= 0 )
     796             :     {
     797           0 :         ScDocument* pDoc = pDocShell->GetDocument();
     798           0 :         sal_Int16 nLockCount = pDoc->GetNamedRangesLockCount();
     799           0 :         if ( nLock == 0 && nLockCount > 0 )
     800             :         {
     801           0 :             unlock();
     802             :         }
     803           0 :         if ( nLock > 0 && nLockCount == 0 )
     804             :         {
     805           0 :             lock();
     806             :         }
     807           0 :         pDoc->SetNamedRangesLockCount( nLock );
     808           0 :     }
     809           0 : }
     810             : 
     811           0 : sal_Int16 ScNamedRangesObj::resetActionLocks() throw(uno::RuntimeException, std::exception)
     812             : {
     813           0 :     SolarMutexGuard aGuard;
     814           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     815           0 :     sal_Int16 nLockCount = pDoc->GetNamedRangesLockCount();
     816           0 :     if ( nLockCount > 0 )
     817             :     {
     818           0 :         unlock();
     819             :     }
     820           0 :     pDoc->SetNamedRangesLockCount( 0 );
     821           0 :     return nLockCount;
     822             : }
     823             : 
     824        1413 : ScGlobalNamedRangesObj::ScGlobalNamedRangesObj(ScDocShell* pDocSh)
     825        1413 :     : ScNamedRangesObj(pDocSh)
     826             : {
     827             : 
     828        1413 : }
     829             : 
     830        2826 : ScGlobalNamedRangesObj::~ScGlobalNamedRangesObj()
     831             : {
     832             : 
     833        2826 : }
     834             : 
     835          12 : ScNamedRangeObj* ScGlobalNamedRangesObj::GetObjectByIndex_Impl(sal_uInt16 nIndex)
     836             : {
     837          12 :     if (!pDocShell)
     838           0 :         return NULL;
     839             : 
     840          12 :     ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName();
     841          12 :     if (!pNames)
     842           0 :         return NULL;
     843             : 
     844          12 :     ScRangeName::const_iterator itr = pNames->begin(), itrEnd = pNames->end();
     845          12 :     sal_uInt16 nPos = 0;
     846          14 :     for (; itr != itrEnd; ++itr)
     847             :     {
     848          12 :         if (lcl_UserVisibleName(*itr->second))
     849             :         {
     850          12 :             if (nPos == nIndex)
     851          10 :                 return new ScNamedRangeObj(this, pDocShell, itr->second->GetName());
     852             :         }
     853           2 :         ++nPos;
     854             :     }
     855           2 :     return NULL;
     856             : }
     857             : 
     858         717 : ScNamedRangeObj* ScGlobalNamedRangesObj::GetObjectByName_Impl(const OUString& aName)
     859             : {
     860         717 :     if ( pDocShell && hasByName(aName) )
     861         158 :         return new ScNamedRangeObj(this, pDocShell, aName);
     862         559 :     return NULL;
     863             : }
     864             : 
     865        2259 : ScRangeName* ScGlobalNamedRangesObj::GetRangeName_Impl()
     866             : {
     867        2259 :     return pDocShell->GetDocument()->GetRangeName();
     868             : }
     869             : 
     870          20 : SCTAB ScGlobalNamedRangesObj::GetTab_Impl()
     871             : {
     872          20 :     return -1;
     873             : }
     874             : 
     875           0 : ScLocalNamedRangesObj::ScLocalNamedRangesObj( ScDocShell* pDocSh, uno::Reference<container::XNamed> xSheet )
     876             :     : ScNamedRangesObj(pDocSh),
     877           0 :     mxSheet(xSheet)
     878             : {
     879             : 
     880           0 : }
     881             : 
     882           0 : ScLocalNamedRangesObj::~ScLocalNamedRangesObj()
     883             : {
     884             : 
     885           0 : }
     886             : 
     887           0 : ScNamedRangeObj* ScLocalNamedRangesObj::GetObjectByName_Impl(const OUString& aName)
     888             : {
     889           0 :     if ( pDocShell && hasByName( aName ) )
     890           0 :         return new ScNamedRangeObj( this, pDocShell, aName, mxSheet);
     891           0 :     return NULL;
     892             : 
     893             : }
     894             : 
     895           0 : ScNamedRangeObj* ScLocalNamedRangesObj::GetObjectByIndex_Impl( sal_uInt16 nIndex )
     896             : {
     897           0 :     if (!pDocShell)
     898           0 :         return NULL;
     899             : 
     900           0 :     OUString aName = mxSheet->getName();
     901           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     902             :     SCTAB nTab;
     903           0 :     pDoc->GetTable( aName, nTab );
     904             : 
     905           0 :     ScRangeName* pNames = pDoc->GetRangeName( nTab );
     906           0 :     if (!pNames)
     907           0 :         return NULL;
     908             : 
     909           0 :     ScRangeName::const_iterator itr = pNames->begin(), itrEnd = pNames->end();
     910           0 :     sal_uInt16 nPos = 0;
     911           0 :     for (; itr != itrEnd; ++itr)
     912             :     {
     913           0 :         if (lcl_UserVisibleName(*itr->second))
     914             :         {
     915           0 :             if (nPos == nIndex)
     916           0 :                 return new ScNamedRangeObj(this, pDocShell, itr->second->GetName(), mxSheet);
     917             :         }
     918           0 :         ++nPos;
     919             :     }
     920           0 :     return NULL;
     921             : }
     922             : 
     923           0 : ScRangeName* ScLocalNamedRangesObj::GetRangeName_Impl()
     924             : {
     925           0 :     SCTAB nTab = GetTab_Impl();
     926           0 :     return pDocShell->GetDocument()->GetRangeName( nTab );
     927             : }
     928             : 
     929           0 : SCTAB ScLocalNamedRangesObj::GetTab_Impl()
     930             : {
     931             :     SCTAB nTab;
     932           0 :     pDocShell->GetDocument()->GetTable(mxSheet->getName(), nTab);
     933           0 :     return nTab;
     934             : }
     935             : 
     936           5 : ScLabelRangeObj::ScLabelRangeObj(ScDocShell* pDocSh, bool bCol, const ScRange& rR) :
     937             :     pDocShell( pDocSh ),
     938             :     bColumn( bCol ),
     939           5 :     aRange( rR )
     940             : {
     941           5 :     pDocShell->GetDocument()->AddUnoObject(*this);
     942           5 : }
     943             : 
     944          15 : ScLabelRangeObj::~ScLabelRangeObj()
     945             : {
     946           5 :     if (pDocShell)
     947           0 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
     948          10 : }
     949             : 
     950          13 : void ScLabelRangeObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
     951             : {
     952             :     //! Ref-Update !!!
     953             : 
     954          13 :     if ( rHint.ISA( SfxSimpleHint ) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
     955           5 :         pDocShell = NULL;       // became invalid
     956          13 : }
     957             : 
     958             : // Helper functions
     959             : 
     960           2 : ScRangePair* ScLabelRangeObj::GetData_Impl()
     961             : {
     962           2 :     ScRangePair* pRet = NULL;
     963           2 :     if (pDocShell)
     964             :     {
     965           2 :         ScDocument* pDoc = pDocShell->GetDocument();
     966           2 :         ScRangePairList* pList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges();
     967           2 :         if (pList)
     968           2 :             pRet = pList->Find( aRange );
     969             :     }
     970           2 :     return pRet;
     971             : }
     972             : 
     973           2 : void ScLabelRangeObj::Modify_Impl( const ScRange* pLabel, const ScRange* pData )
     974             : {
     975           2 :     if (pDocShell)
     976             :     {
     977           2 :         ScDocument* pDoc = pDocShell->GetDocument();
     978           2 :         ScRangePairList* pOldList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges();
     979           2 :         if (pOldList)
     980             :         {
     981           2 :             ScRangePairListRef xNewList(pOldList->Clone());
     982           2 :             ScRangePair* pEntry = xNewList->Find( aRange );
     983           2 :             if (pEntry)
     984             :             {
     985           2 :                 xNewList->Remove( pEntry );     // only removed from list, not deleted
     986             : 
     987           2 :                 if ( pLabel )
     988           1 :                     pEntry->GetRange(0) = *pLabel;
     989           2 :                 if ( pData )
     990           1 :                     pEntry->GetRange(1) = *pData;
     991             : 
     992           2 :                 xNewList->Join( *pEntry );
     993           2 :                 delete pEntry;
     994             : 
     995           2 :                 if (bColumn)
     996           2 :                     pDoc->GetColNameRangesRef() = xNewList;
     997             :                 else
     998           0 :                     pDoc->GetRowNameRangesRef() = xNewList;
     999             : 
    1000           2 :                 pDoc->CompileColRowNameFormula();
    1001           2 :                 pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID );
    1002           2 :                 pDocShell->SetDocumentModified();
    1003             : 
    1004             :                 //! Undo ?!?! (here and from dialog)
    1005             : 
    1006           2 :                 if ( pLabel )
    1007           1 :                     aRange = *pLabel;   // adapt object to find range again
    1008           2 :             }
    1009             :         }
    1010             :     }
    1011           2 : }
    1012             : 
    1013             : // sheet::XLabelRange
    1014             : 
    1015           1 : table::CellRangeAddress SAL_CALL ScLabelRangeObj::getLabelArea()
    1016             :                                                 throw(uno::RuntimeException, std::exception)
    1017             : {
    1018           1 :     SolarMutexGuard aGuard;
    1019           1 :     table::CellRangeAddress aRet;
    1020           1 :     ScRangePair* pData = GetData_Impl();
    1021           1 :     if (pData)
    1022           1 :         ScUnoConversion::FillApiRange( aRet, pData->GetRange(0) );
    1023           1 :     return aRet;
    1024             : }
    1025             : 
    1026           1 : void SAL_CALL ScLabelRangeObj::setLabelArea( const table::CellRangeAddress& aLabelArea )
    1027             :                                                 throw(uno::RuntimeException, std::exception)
    1028             : {
    1029           1 :     SolarMutexGuard aGuard;
    1030           1 :     ScRange aLabelRange;
    1031           1 :     ScUnoConversion::FillScRange( aLabelRange, aLabelArea );
    1032           1 :     Modify_Impl( &aLabelRange, NULL );
    1033           1 : }
    1034             : 
    1035           1 : table::CellRangeAddress SAL_CALL ScLabelRangeObj::getDataArea()
    1036             :                                                 throw(uno::RuntimeException, std::exception)
    1037             : {
    1038           1 :     SolarMutexGuard aGuard;
    1039           1 :     table::CellRangeAddress aRet;
    1040           1 :     ScRangePair* pData = GetData_Impl();
    1041           1 :     if (pData)
    1042           1 :         ScUnoConversion::FillApiRange( aRet, pData->GetRange(1) );
    1043           1 :     return aRet;
    1044             : }
    1045             : 
    1046           1 : void SAL_CALL ScLabelRangeObj::setDataArea( const table::CellRangeAddress& aDataArea )
    1047             :                                                 throw(uno::RuntimeException, std::exception)
    1048             : {
    1049           1 :     SolarMutexGuard aGuard;
    1050           1 :     ScRange aDataRange;
    1051           1 :     ScUnoConversion::FillScRange( aDataRange, aDataArea );
    1052           1 :     Modify_Impl( NULL, &aDataRange );
    1053           1 : }
    1054             : 
    1055          47 : ScLabelRangesObj::ScLabelRangesObj(ScDocShell* pDocSh, bool bCol) :
    1056             :     pDocShell( pDocSh ),
    1057          47 :     bColumn( bCol )
    1058             : {
    1059          47 :     pDocShell->GetDocument()->AddUnoObject(*this);
    1060          47 : }
    1061             : 
    1062         141 : ScLabelRangesObj::~ScLabelRangesObj()
    1063             : {
    1064          47 :     if (pDocShell)
    1065          36 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
    1066          94 : }
    1067             : 
    1068         334 : void ScLabelRangesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
    1069             : {
    1070             :     //  reference update is of no interest
    1071             : 
    1072         668 :     if ( rHint.ISA( SfxSimpleHint ) &&
    1073         334 :             ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
    1074             :     {
    1075          11 :         pDocShell = NULL;       // became invalid
    1076             :     }
    1077         334 : }
    1078             : 
    1079             : // sheet::XLabelRanges
    1080             : 
    1081           7 : ScLabelRangeObj* ScLabelRangesObj::GetObjectByIndex_Impl(size_t nIndex)
    1082             : {
    1083           7 :     if (pDocShell)
    1084             :     {
    1085           7 :         ScDocument* pDoc = pDocShell->GetDocument();
    1086           7 :         ScRangePairList* pList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges();
    1087           7 :         if ( pList && nIndex < pList->size() )
    1088             :         {
    1089           5 :             ScRangePair* pData = (*pList)[nIndex];
    1090           5 :             if (pData)
    1091           5 :                 return new ScLabelRangeObj( pDocShell, bColumn, pData->GetRange(0) );
    1092             :         }
    1093             :     }
    1094           2 :     return NULL;
    1095             : }
    1096             : 
    1097           4 : void SAL_CALL ScLabelRangesObj::addNew( const table::CellRangeAddress& aLabelArea,
    1098             :                                 const table::CellRangeAddress& aDataArea )
    1099             :                                                 throw(uno::RuntimeException, std::exception)
    1100             : {
    1101           4 :     SolarMutexGuard aGuard;
    1102           4 :     if (pDocShell)
    1103             :     {
    1104           4 :         ScDocument* pDoc = pDocShell->GetDocument();
    1105           4 :         ScRangePairList* pOldList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges();
    1106           4 :         if (pOldList)
    1107             :         {
    1108           4 :             ScRangePairListRef xNewList(pOldList->Clone());
    1109             : 
    1110           4 :             ScRange aLabelRange;
    1111           4 :             ScRange aDataRange;
    1112           4 :             ScUnoConversion::FillScRange( aLabelRange, aLabelArea );
    1113           4 :             ScUnoConversion::FillScRange( aDataRange,  aDataArea );
    1114           4 :             xNewList->Join( ScRangePair( aLabelRange, aDataRange ) );
    1115             : 
    1116           4 :             if (bColumn)
    1117           4 :                 pDoc->GetColNameRangesRef() = xNewList;
    1118             :             else
    1119           0 :                 pDoc->GetRowNameRangesRef() = xNewList;
    1120             : 
    1121           4 :             pDoc->CompileColRowNameFormula();
    1122           4 :             pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID );
    1123           4 :             pDocShell->SetDocumentModified();
    1124             : 
    1125             :             //! Undo ?!?! (here and from dialog)
    1126             :         }
    1127           4 :     }
    1128           4 : }
    1129             : 
    1130           2 : void SAL_CALL ScLabelRangesObj::removeByIndex( sal_Int32 nIndex )
    1131             :                                                 throw(uno::RuntimeException, std::exception)
    1132             : {
    1133           2 :     SolarMutexGuard aGuard;
    1134           2 :     sal_Bool bDone = false;
    1135           2 :     if (pDocShell)
    1136             :     {
    1137           2 :         ScDocument* pDoc = pDocShell->GetDocument();
    1138           2 :         ScRangePairList* pOldList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges();
    1139             : 
    1140           2 :         if ( pOldList && nIndex >= 0 && nIndex < (sal_Int32)pOldList->size() )
    1141             :         {
    1142           1 :             ScRangePairListRef xNewList(pOldList->Clone());
    1143             : 
    1144           1 :             ScRangePair* pEntry = (*xNewList)[nIndex];
    1145           1 :             if (pEntry)
    1146             :             {
    1147           1 :                 xNewList->Remove( pEntry );
    1148           1 :                 delete pEntry;
    1149             : 
    1150           1 :                 if (bColumn)
    1151           1 :                     pDoc->GetColNameRangesRef() = xNewList;
    1152             :                 else
    1153           0 :                     pDoc->GetRowNameRangesRef() = xNewList;
    1154             : 
    1155           1 :                 pDoc->CompileColRowNameFormula();
    1156           1 :                 pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID );
    1157           1 :                 pDocShell->SetDocumentModified();
    1158           1 :                 bDone = sal_True;
    1159             : 
    1160             :                 //! Undo ?!?! (here and from dialog)
    1161           1 :             }
    1162             :         }
    1163             :     }
    1164           2 :     if (!bDone)
    1165           1 :         throw uno::RuntimeException();      // no other exceptions specified
    1166           1 : }
    1167             : 
    1168             : // container::XEnumerationAccess
    1169             : 
    1170           2 : uno::Reference<container::XEnumeration> SAL_CALL ScLabelRangesObj::createEnumeration()
    1171             :                                                     throw(uno::RuntimeException, std::exception)
    1172             : {
    1173           2 :     SolarMutexGuard aGuard;
    1174           2 :     return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.LabelRangesEnumeration"));
    1175             : }
    1176             : 
    1177             : // container::XIndexAccess
    1178             : 
    1179          44 : sal_Int32 SAL_CALL ScLabelRangesObj::getCount() throw(uno::RuntimeException, std::exception)
    1180             : {
    1181          44 :     SolarMutexGuard aGuard;
    1182          44 :     if (pDocShell)
    1183             :     {
    1184          44 :         ScDocument* pDoc = pDocShell->GetDocument();
    1185          44 :         ScRangePairList* pList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges();
    1186          44 :         if (pList)
    1187          44 :             return pList->size();
    1188             :     }
    1189           0 :     return 0;
    1190             : }
    1191             : 
    1192           7 : uno::Any SAL_CALL ScLabelRangesObj::getByIndex( sal_Int32 nIndex )
    1193             :                             throw(lang::IndexOutOfBoundsException,
    1194             :                                     lang::WrappedTargetException, uno::RuntimeException, std::exception)
    1195             : {
    1196           7 :     SolarMutexGuard aGuard;
    1197          14 :     uno::Reference< sheet::XLabelRange >  xRange(GetObjectByIndex_Impl((sal_uInt16)nIndex));
    1198           7 :     if ( xRange.is() )
    1199          10 :         return uno::makeAny(xRange);
    1200             :     else
    1201           9 :         throw lang::IndexOutOfBoundsException();
    1202             : }
    1203             : 
    1204           1 : uno::Type SAL_CALL ScLabelRangesObj::getElementType() throw(uno::RuntimeException, std::exception)
    1205             : {
    1206           1 :     SolarMutexGuard aGuard;
    1207           1 :     return ::getCppuType((const uno::Reference< sheet::XLabelRange >*)0);   // must be suitable for getByIndex
    1208             : 
    1209             : }
    1210             : 
    1211           1 : sal_Bool SAL_CALL ScLabelRangesObj::hasElements() throw(uno::RuntimeException, std::exception)
    1212             : {
    1213           1 :     SolarMutexGuard aGuard;
    1214           1 :     return ( getCount() != 0 );
    1215             : }
    1216             : 
    1217             : 
    1218             : 
    1219             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10