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

Generated by: LCOV version 1.10