1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sc.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <svl/smplhint.hxx> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <com/sun/star/sheet/NamedRangeFlag.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/awt/XBitmap.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir using namespace ::com::sun::star; 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #include "nameuno.hxx" 43*cdf0e10cSrcweir #include "miscuno.hxx" 44*cdf0e10cSrcweir #include "cellsuno.hxx" 45*cdf0e10cSrcweir #include "convuno.hxx" 46*cdf0e10cSrcweir #include "targuno.hxx" 47*cdf0e10cSrcweir #include "tokenuno.hxx" 48*cdf0e10cSrcweir #include "tokenarray.hxx" 49*cdf0e10cSrcweir #include "docsh.hxx" 50*cdf0e10cSrcweir #include "docfunc.hxx" 51*cdf0e10cSrcweir #include "rangenam.hxx" 52*cdf0e10cSrcweir //CHINA001 #include "namecrea.hxx" // NAME_TOP etc. 53*cdf0e10cSrcweir #include "unoguard.hxx" 54*cdf0e10cSrcweir #include "unonames.hxx" 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir #include "scui_def.hxx" //CHINA001 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir //------------------------------------------------------------------------ 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir const SfxItemPropertyMapEntry* lcl_GetNamedRangeMap() 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir static SfxItemPropertyMapEntry aNamedRangeMap_Impl[] = 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_LINKDISPBIT), 0, &getCppuType((uno::Reference<awt::XBitmap>*)0), beans::PropertyAttribute::READONLY, 0 }, 65*cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_LINKDISPNAME), 0, &getCppuType((rtl::OUString*)0), beans::PropertyAttribute::READONLY, 0 }, 66*cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNONAME_TOKENINDEX), 0, &getCppuType((sal_Int32*)0), beans::PropertyAttribute::READONLY, 0 }, 67*cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNONAME_ISSHAREDFMLA), 0, &getBooleanCppuType(), 0, 0 }, 68*cdf0e10cSrcweir {0,0,0,0,0,0} 69*cdf0e10cSrcweir }; 70*cdf0e10cSrcweir return aNamedRangeMap_Impl; 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir //------------------------------------------------------------------------ 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir #define SCNAMEDRANGEOBJ_SERVICE "com.sun.star.sheet.NamedRange" 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScLabelRangeObj, "ScLabelRangeObj", "com.sun.star.sheet.LabelRange" ) 78*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScLabelRangesObj, "ScLabelRangesObj", "com.sun.star.sheet.LabelRanges" ) 79*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScNamedRangesObj, "ScNamedRangesObj", "com.sun.star.sheet.NamedRanges" ) 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir //------------------------------------------------------------------------ 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir sal_Bool lcl_UserVisibleName( const ScRangeData* pData ) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir //! als Methode an ScRangeData 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir return ( pData && !pData->HasType( RT_DATABASE ) && !pData->HasType( RT_SHARED ) ); 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir //------------------------------------------------------------------------ 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir ScNamedRangeObj::ScNamedRangeObj(ScDocShell* pDocSh, const String& rNm) : 93*cdf0e10cSrcweir pDocShell( pDocSh ), 94*cdf0e10cSrcweir aName( rNm ) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir pDocShell->GetDocument()->AddUnoObject(*this); 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir ScNamedRangeObj::~ScNamedRangeObj() 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir if (pDocShell) 102*cdf0e10cSrcweir pDocShell->GetDocument()->RemoveUnoObject(*this); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir void ScNamedRangeObj::Notify( SfxBroadcaster&, const SfxHint& rHint ) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir // Ref-Update interessiert nicht 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir if ( rHint.ISA( SfxSimpleHint ) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) 110*cdf0e10cSrcweir pDocShell = NULL; // ungueltig geworden 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir // Hilfsfuntionen 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir ScRangeData* ScNamedRangeObj::GetRangeData_Impl() 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir ScRangeData* pRet = NULL; 118*cdf0e10cSrcweir if (pDocShell) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName(); 121*cdf0e10cSrcweir if (pNames) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir sal_uInt16 nPos = 0; 124*cdf0e10cSrcweir if (pNames->SearchName( aName, nPos )) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir pRet = (*pNames)[nPos]; 127*cdf0e10cSrcweir pRet->ValidateTabRefs(); // adjust relative tab refs to valid tables 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir return pRet; 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir // sheet::XNamedRange 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir void ScNamedRangeObj::Modify_Impl( const String* pNewName, const ScTokenArray* pNewTokens, const String* pNewContent, 137*cdf0e10cSrcweir const ScAddress* pNewPos, const sal_uInt16* pNewType, 138*cdf0e10cSrcweir const formula::FormulaGrammar::Grammar eGrammar ) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir if (pDocShell) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument(); 143*cdf0e10cSrcweir ScRangeName* pNames = pDoc->GetRangeName(); 144*cdf0e10cSrcweir if (pNames) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir sal_uInt16 nPos = 0; 147*cdf0e10cSrcweir if (pNames->SearchName( aName, nPos )) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir ScRangeName* pNewRanges = new ScRangeName( *pNames ); 150*cdf0e10cSrcweir ScRangeData* pOld = (*pNames)[nPos]; 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir String aInsName(pOld->GetName()); 153*cdf0e10cSrcweir if (pNewName) 154*cdf0e10cSrcweir aInsName = *pNewName; 155*cdf0e10cSrcweir String aContent; // Content string based => 156*cdf0e10cSrcweir pOld->GetSymbol( aContent, eGrammar); // no problems with changed positions and such. 157*cdf0e10cSrcweir if (pNewContent) 158*cdf0e10cSrcweir aContent = *pNewContent; 159*cdf0e10cSrcweir ScAddress aPos(pOld->GetPos()); 160*cdf0e10cSrcweir if (pNewPos) 161*cdf0e10cSrcweir aPos = *pNewPos; 162*cdf0e10cSrcweir sal_uInt16 nType = pOld->GetType(); 163*cdf0e10cSrcweir if (pNewType) 164*cdf0e10cSrcweir nType = *pNewType; 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir ScRangeData* pNew = NULL; 167*cdf0e10cSrcweir if ( pNewTokens ) 168*cdf0e10cSrcweir pNew = new ScRangeData( pDoc, aInsName, *pNewTokens, aPos, nType ); 169*cdf0e10cSrcweir else 170*cdf0e10cSrcweir pNew = new ScRangeData( pDoc, aInsName, aContent, aPos, nType, eGrammar ); 171*cdf0e10cSrcweir pNew->SetIndex( pOld->GetIndex() ); 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir pNewRanges->AtFree( nPos ); 174*cdf0e10cSrcweir if ( pNewRanges->Insert(pNew) ) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir ScDocFunc aFunc(*pDocShell); 177*cdf0e10cSrcweir aFunc.SetNewRangeNames( pNewRanges, sal_True ); 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir aName = aInsName; //! broadcast? 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir else 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir delete pNew; //! uno::Exception/Fehler oder so 184*cdf0e10cSrcweir delete pNewRanges; 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir rtl::OUString SAL_CALL ScNamedRangeObj::getName() throw(uno::RuntimeException) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir ScUnoGuard aGuard; 195*cdf0e10cSrcweir return aName; 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir void SAL_CALL ScNamedRangeObj::setName( const rtl::OUString& aNewName ) 199*cdf0e10cSrcweir throw(uno::RuntimeException) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir ScUnoGuard aGuard; 202*cdf0e10cSrcweir //! Formeln anpassen ????? 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir String aNewStr(aNewName); 205*cdf0e10cSrcweir // GRAM_PODF_A1 for API compatibility. 206*cdf0e10cSrcweir Modify_Impl( &aNewStr, NULL, NULL, NULL, NULL,formula::FormulaGrammar::GRAM_PODF_A1 ); 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir if ( aName != aNewStr ) // some error occured... 209*cdf0e10cSrcweir throw uno::RuntimeException(); // no other exceptions specified 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir rtl::OUString SAL_CALL ScNamedRangeObj::getContent() throw(uno::RuntimeException) 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir ScUnoGuard aGuard; 215*cdf0e10cSrcweir String aContent; 216*cdf0e10cSrcweir ScRangeData* pData = GetRangeData_Impl(); 217*cdf0e10cSrcweir if (pData) 218*cdf0e10cSrcweir // GRAM_PODF_A1 for API compatibility. 219*cdf0e10cSrcweir pData->GetSymbol( aContent,formula::FormulaGrammar::GRAM_PODF_A1); 220*cdf0e10cSrcweir return aContent; 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir void SAL_CALL ScNamedRangeObj::setContent( const rtl::OUString& aContent ) 224*cdf0e10cSrcweir throw(uno::RuntimeException) 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir ScUnoGuard aGuard; 227*cdf0e10cSrcweir String aContStr(aContent); 228*cdf0e10cSrcweir // GRAM_PODF_A1 for API compatibility. 229*cdf0e10cSrcweir Modify_Impl( NULL, NULL, &aContStr, NULL, NULL,formula::FormulaGrammar::GRAM_PODF_A1 ); 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir void ScNamedRangeObj::SetContentWithGrammar( const ::rtl::OUString& aContent, 233*cdf0e10cSrcweir const formula::FormulaGrammar::Grammar eGrammar ) 234*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir String aContStr(aContent); 237*cdf0e10cSrcweir Modify_Impl( NULL, NULL, &aContStr, NULL, NULL, eGrammar ); 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir table::CellAddress SAL_CALL ScNamedRangeObj::getReferencePosition() 241*cdf0e10cSrcweir throw(uno::RuntimeException) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir ScUnoGuard aGuard; 244*cdf0e10cSrcweir ScAddress aPos; 245*cdf0e10cSrcweir ScRangeData* pData = GetRangeData_Impl(); 246*cdf0e10cSrcweir if (pData) 247*cdf0e10cSrcweir aPos = pData->GetPos(); 248*cdf0e10cSrcweir table::CellAddress aAddress; 249*cdf0e10cSrcweir aAddress.Column = aPos.Col(); 250*cdf0e10cSrcweir aAddress.Row = aPos.Row(); 251*cdf0e10cSrcweir aAddress.Sheet = aPos.Tab(); 252*cdf0e10cSrcweir if (pDocShell) 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir SCTAB nDocTabs = pDocShell->GetDocument()->GetTableCount(); 255*cdf0e10cSrcweir if ( aAddress.Sheet >= nDocTabs && nDocTabs > 0 ) 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir // Even after ValidateTabRefs, the position can be invalid if 258*cdf0e10cSrcweir // the content points to preceding tables. The resulting string 259*cdf0e10cSrcweir // is invalid in any case, so the position is just shifted. 260*cdf0e10cSrcweir aAddress.Sheet = nDocTabs - 1; 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir return aAddress; 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir void SAL_CALL ScNamedRangeObj::setReferencePosition( const table::CellAddress& aReferencePosition ) 267*cdf0e10cSrcweir throw(uno::RuntimeException) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir ScUnoGuard aGuard; 270*cdf0e10cSrcweir ScAddress aPos( (SCCOL)aReferencePosition.Column, (SCROW)aReferencePosition.Row, aReferencePosition.Sheet ); 271*cdf0e10cSrcweir // GRAM_PODF_A1 for API compatibility. 272*cdf0e10cSrcweir Modify_Impl( NULL, NULL, NULL, &aPos, NULL,formula::FormulaGrammar::GRAM_PODF_A1 ); 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir sal_Int32 SAL_CALL ScNamedRangeObj::getType() throw(uno::RuntimeException) 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir ScUnoGuard aGuard; 278*cdf0e10cSrcweir sal_Int32 nType=0; 279*cdf0e10cSrcweir ScRangeData* pData = GetRangeData_Impl(); 280*cdf0e10cSrcweir if (pData) 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir // do not return internal RT_* flags 283*cdf0e10cSrcweir // see property 'IsSharedFormula' for RT_SHARED 284*cdf0e10cSrcweir if ( pData->HasType(RT_CRITERIA) ) nType |= sheet::NamedRangeFlag::FILTER_CRITERIA; 285*cdf0e10cSrcweir if ( pData->HasType(RT_PRINTAREA) ) nType |= sheet::NamedRangeFlag::PRINT_AREA; 286*cdf0e10cSrcweir if ( pData->HasType(RT_COLHEADER) ) nType |= sheet::NamedRangeFlag::COLUMN_HEADER; 287*cdf0e10cSrcweir if ( pData->HasType(RT_ROWHEADER) ) nType |= sheet::NamedRangeFlag::ROW_HEADER; 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir return nType; 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir void SAL_CALL ScNamedRangeObj::setType( sal_Int32 nUnoType ) throw(uno::RuntimeException) 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir // see property 'IsSharedFormula' for RT_SHARED 295*cdf0e10cSrcweir ScUnoGuard aGuard; 296*cdf0e10cSrcweir sal_uInt16 nNewType = RT_NAME; 297*cdf0e10cSrcweir if ( nUnoType & sheet::NamedRangeFlag::FILTER_CRITERIA ) nNewType |= RT_CRITERIA; 298*cdf0e10cSrcweir if ( nUnoType & sheet::NamedRangeFlag::PRINT_AREA ) nNewType |= RT_PRINTAREA; 299*cdf0e10cSrcweir if ( nUnoType & sheet::NamedRangeFlag::COLUMN_HEADER ) nNewType |= RT_COLHEADER; 300*cdf0e10cSrcweir if ( nUnoType & sheet::NamedRangeFlag::ROW_HEADER ) nNewType |= RT_ROWHEADER; 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir // GRAM_PODF_A1 for API compatibility. 303*cdf0e10cSrcweir Modify_Impl( NULL, NULL, NULL, NULL, &nNewType,formula::FormulaGrammar::GRAM_PODF_A1 ); 304*cdf0e10cSrcweir } 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir // XFormulaTokens 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir uno::Sequence<sheet::FormulaToken> SAL_CALL ScNamedRangeObj::getTokens() throw(uno::RuntimeException) 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir ScUnoGuard aGuard; 311*cdf0e10cSrcweir uno::Sequence<sheet::FormulaToken> aSequence; 312*cdf0e10cSrcweir ScRangeData* pData = GetRangeData_Impl(); 313*cdf0e10cSrcweir if (pData && pDocShell) 314*cdf0e10cSrcweir { 315*cdf0e10cSrcweir ScTokenArray* pTokenArray = pData->GetCode(); 316*cdf0e10cSrcweir if ( pTokenArray ) 317*cdf0e10cSrcweir (void)ScTokenConversion::ConvertToTokenSequence( *pDocShell->GetDocument(), aSequence, *pTokenArray ); 318*cdf0e10cSrcweir } 319*cdf0e10cSrcweir return aSequence; 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir void SAL_CALL ScNamedRangeObj::setTokens( const uno::Sequence<sheet::FormulaToken>& rTokens ) throw(uno::RuntimeException) 323*cdf0e10cSrcweir { 324*cdf0e10cSrcweir ScUnoGuard aGuard; 325*cdf0e10cSrcweir if( pDocShell ) 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir ScTokenArray aTokenArray; 328*cdf0e10cSrcweir (void)ScTokenConversion::ConvertToTokenArray( *pDocShell->GetDocument(), aTokenArray, rTokens ); 329*cdf0e10cSrcweir // GRAM_PODF_A1 for API compatibility. 330*cdf0e10cSrcweir Modify_Impl( NULL, &aTokenArray, NULL, NULL, NULL, formula::FormulaGrammar::GRAM_PODF_A1 ); 331*cdf0e10cSrcweir } 332*cdf0e10cSrcweir } 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir // XCellRangeSource 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir uno::Reference<table::XCellRange> SAL_CALL ScNamedRangeObj::getReferredCells() 338*cdf0e10cSrcweir throw(uno::RuntimeException) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir ScUnoGuard aGuard; 341*cdf0e10cSrcweir ScRange aRange; 342*cdf0e10cSrcweir ScRangeData* pData = GetRangeData_Impl(); 343*cdf0e10cSrcweir if ( pData && pData->IsValidReference( aRange ) ) 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir //! static Funktion um ScCellObj/ScCellRangeObj zu erzeugen am ScCellRangeObj ??? 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir if ( aRange.aStart == aRange.aEnd ) 348*cdf0e10cSrcweir return new ScCellObj( pDocShell, aRange.aStart ); 349*cdf0e10cSrcweir else 350*cdf0e10cSrcweir return new ScCellRangeObj( pDocShell, aRange ); 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir return NULL; 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir // beans::XPropertySet 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir uno::Reference<beans::XPropertySetInfo> SAL_CALL ScNamedRangeObj::getPropertySetInfo() 358*cdf0e10cSrcweir throw(uno::RuntimeException) 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir ScUnoGuard aGuard; 361*cdf0e10cSrcweir static uno::Reference< beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( lcl_GetNamedRangeMap() )); 362*cdf0e10cSrcweir return aRef; 363*cdf0e10cSrcweir } 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir void SAL_CALL ScNamedRangeObj::setPropertyValue( 366*cdf0e10cSrcweir const rtl::OUString& rPropertyName, const uno::Any& aValue ) 367*cdf0e10cSrcweir throw(beans::UnknownPropertyException, beans::PropertyVetoException, 368*cdf0e10cSrcweir lang::IllegalArgumentException, lang::WrappedTargetException, 369*cdf0e10cSrcweir uno::RuntimeException) 370*cdf0e10cSrcweir { 371*cdf0e10cSrcweir ScUnoGuard aGuard; 372*cdf0e10cSrcweir if ( rPropertyName.equalsAscii( SC_UNONAME_ISSHAREDFMLA ) ) 373*cdf0e10cSrcweir { 374*cdf0e10cSrcweir bool bIsShared = false; 375*cdf0e10cSrcweir if( aValue >>= bIsShared ) 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir sal_uInt16 nNewType = bIsShared ? RT_SHARED : RT_NAME; 378*cdf0e10cSrcweir Modify_Impl( NULL, NULL, NULL, NULL, &nNewType,formula::FormulaGrammar::GRAM_PODF_A1 ); 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir uno::Any SAL_CALL ScNamedRangeObj::getPropertyValue( const rtl::OUString& rPropertyName ) 384*cdf0e10cSrcweir throw(beans::UnknownPropertyException, lang::WrappedTargetException, 385*cdf0e10cSrcweir uno::RuntimeException) 386*cdf0e10cSrcweir { 387*cdf0e10cSrcweir ScUnoGuard aGuard; 388*cdf0e10cSrcweir uno::Any aRet; 389*cdf0e10cSrcweir if ( rPropertyName.equalsAscii( SC_UNO_LINKDISPBIT ) ) 390*cdf0e10cSrcweir { 391*cdf0e10cSrcweir // no target bitmaps for individual entries (would be all equal) 392*cdf0e10cSrcweir // ScLinkTargetTypeObj::SetLinkTargetBitmap( aRet, SC_LINKTARGETTYPE_RANGENAME ); 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir else if ( rPropertyName.equalsAscii( SC_UNO_LINKDISPNAME ) ) 395*cdf0e10cSrcweir aRet <<= rtl::OUString( aName ); 396*cdf0e10cSrcweir else if ( rPropertyName.equalsAscii( SC_UNONAME_TOKENINDEX ) ) 397*cdf0e10cSrcweir { 398*cdf0e10cSrcweir // get index for use in formula tokens (read-only) 399*cdf0e10cSrcweir ScRangeData* pData = GetRangeData_Impl(); 400*cdf0e10cSrcweir if (pData) 401*cdf0e10cSrcweir aRet <<= static_cast<sal_Int32>(pData->GetIndex()); 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir else if ( rPropertyName.equalsAscii( SC_UNONAME_ISSHAREDFMLA ) ) 404*cdf0e10cSrcweir { 405*cdf0e10cSrcweir if( ScRangeData* pData = GetRangeData_Impl() ) 406*cdf0e10cSrcweir aRet <<= static_cast< bool >( pData->HasType( RT_SHARED ) ); 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir return aRet; 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir SC_IMPL_DUMMY_PROPERTY_LISTENER( ScNamedRangeObj ) 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir // lang::XServiceInfo 414*cdf0e10cSrcweir 415*cdf0e10cSrcweir rtl::OUString SAL_CALL ScNamedRangeObj::getImplementationName() throw(uno::RuntimeException) 416*cdf0e10cSrcweir { 417*cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScNamedRangeObj" ) ); 418*cdf0e10cSrcweir } 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir sal_Bool SAL_CALL ScNamedRangeObj::supportsService( const rtl::OUString& rServiceName ) 421*cdf0e10cSrcweir throw(uno::RuntimeException) 422*cdf0e10cSrcweir { 423*cdf0e10cSrcweir return rServiceName.equalsAscii( SCNAMEDRANGEOBJ_SERVICE ) || 424*cdf0e10cSrcweir rServiceName.equalsAscii( SCLINKTARGET_SERVICE ); 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL ScNamedRangeObj::getSupportedServiceNames() 428*cdf0e10cSrcweir throw(uno::RuntimeException) 429*cdf0e10cSrcweir { 430*cdf0e10cSrcweir uno::Sequence<rtl::OUString> aRet(2); 431*cdf0e10cSrcweir aRet[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SCNAMEDRANGEOBJ_SERVICE ) ); 432*cdf0e10cSrcweir aRet[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SCLINKTARGET_SERVICE ) ); 433*cdf0e10cSrcweir return aRet; 434*cdf0e10cSrcweir } 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir // XUnoTunnel 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir sal_Int64 SAL_CALL ScNamedRangeObj::getSomething( 440*cdf0e10cSrcweir const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir if ( rId.getLength() == 16 && 443*cdf0e10cSrcweir 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), 444*cdf0e10cSrcweir rId.getConstArray(), 16 ) ) 445*cdf0e10cSrcweir { 446*cdf0e10cSrcweir return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this)); 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir return 0; 449*cdf0e10cSrcweir } 450*cdf0e10cSrcweir 451*cdf0e10cSrcweir // static 452*cdf0e10cSrcweir const uno::Sequence<sal_Int8>& ScNamedRangeObj::getUnoTunnelId() 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir static uno::Sequence<sal_Int8> * pSeq = 0; 455*cdf0e10cSrcweir if( !pSeq ) 456*cdf0e10cSrcweir { 457*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); 458*cdf0e10cSrcweir if( !pSeq ) 459*cdf0e10cSrcweir { 460*cdf0e10cSrcweir static uno::Sequence< sal_Int8 > aSeq( 16 ); 461*cdf0e10cSrcweir rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); 462*cdf0e10cSrcweir pSeq = &aSeq; 463*cdf0e10cSrcweir } 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir return *pSeq; 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir // static 469*cdf0e10cSrcweir ScNamedRangeObj* ScNamedRangeObj::getImplementation( const uno::Reference<uno::XInterface> xObj ) 470*cdf0e10cSrcweir { 471*cdf0e10cSrcweir ScNamedRangeObj* pRet = NULL; 472*cdf0e10cSrcweir uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); 473*cdf0e10cSrcweir if (xUT.is()) 474*cdf0e10cSrcweir pRet = reinterpret_cast<ScNamedRangeObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId()))); 475*cdf0e10cSrcweir return pRet; 476*cdf0e10cSrcweir } 477*cdf0e10cSrcweir 478*cdf0e10cSrcweir //------------------------------------------------------------------------ 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir ScNamedRangesObj::ScNamedRangesObj(ScDocShell* pDocSh) : 481*cdf0e10cSrcweir pDocShell( pDocSh ) 482*cdf0e10cSrcweir { 483*cdf0e10cSrcweir pDocShell->GetDocument()->AddUnoObject(*this); 484*cdf0e10cSrcweir } 485*cdf0e10cSrcweir 486*cdf0e10cSrcweir ScNamedRangesObj::~ScNamedRangesObj() 487*cdf0e10cSrcweir { 488*cdf0e10cSrcweir if (pDocShell) 489*cdf0e10cSrcweir pDocShell->GetDocument()->RemoveUnoObject(*this); 490*cdf0e10cSrcweir } 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir void ScNamedRangesObj::Notify( SfxBroadcaster&, const SfxHint& rHint ) 493*cdf0e10cSrcweir { 494*cdf0e10cSrcweir // Referenz-Update interessiert hier nicht 495*cdf0e10cSrcweir 496*cdf0e10cSrcweir if ( rHint.ISA( SfxSimpleHint ) && 497*cdf0e10cSrcweir ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) 498*cdf0e10cSrcweir { 499*cdf0e10cSrcweir pDocShell = NULL; // ungueltig geworden 500*cdf0e10cSrcweir } 501*cdf0e10cSrcweir } 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir // sheet::XNamedRanges 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir ScNamedRangeObj* ScNamedRangesObj::GetObjectByIndex_Impl(sal_uInt16 nIndex) 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir if (pDocShell) 508*cdf0e10cSrcweir { 509*cdf0e10cSrcweir ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName(); 510*cdf0e10cSrcweir if (pNames) 511*cdf0e10cSrcweir { 512*cdf0e10cSrcweir sal_uInt16 nCount = pNames->GetCount(); 513*cdf0e10cSrcweir sal_uInt16 nPos = 0; 514*cdf0e10cSrcweir for (sal_uInt16 i=0; i<nCount; i++) 515*cdf0e10cSrcweir { 516*cdf0e10cSrcweir ScRangeData* pData = (*pNames)[i]; 517*cdf0e10cSrcweir if (lcl_UserVisibleName(pData)) // interne weglassen 518*cdf0e10cSrcweir { 519*cdf0e10cSrcweir if ( nPos == nIndex ) 520*cdf0e10cSrcweir return new ScNamedRangeObj( pDocShell, pData->GetName() ); 521*cdf0e10cSrcweir ++nPos; 522*cdf0e10cSrcweir } 523*cdf0e10cSrcweir } 524*cdf0e10cSrcweir } 525*cdf0e10cSrcweir } 526*cdf0e10cSrcweir return NULL; 527*cdf0e10cSrcweir } 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir ScNamedRangeObj* ScNamedRangesObj::GetObjectByName_Impl(const rtl::OUString& aName) 530*cdf0e10cSrcweir { 531*cdf0e10cSrcweir if ( pDocShell && hasByName(aName) ) 532*cdf0e10cSrcweir return new ScNamedRangeObj( pDocShell, String(aName) ); 533*cdf0e10cSrcweir return NULL; 534*cdf0e10cSrcweir } 535*cdf0e10cSrcweir 536*cdf0e10cSrcweir void SAL_CALL ScNamedRangesObj::addNewByName( const rtl::OUString& aName, 537*cdf0e10cSrcweir const rtl::OUString& aContent, const table::CellAddress& aPosition, 538*cdf0e10cSrcweir sal_Int32 nUnoType ) throw(uno::RuntimeException) 539*cdf0e10cSrcweir { 540*cdf0e10cSrcweir ScUnoGuard aGuard; 541*cdf0e10cSrcweir String aNameStr(aName); 542*cdf0e10cSrcweir String aContStr(aContent); 543*cdf0e10cSrcweir ScAddress aPos( (SCCOL)aPosition.Column, (SCROW)aPosition.Row, aPosition.Sheet ); 544*cdf0e10cSrcweir 545*cdf0e10cSrcweir sal_uInt16 nNewType = RT_NAME; 546*cdf0e10cSrcweir if ( nUnoType & sheet::NamedRangeFlag::FILTER_CRITERIA ) nNewType |= RT_CRITERIA; 547*cdf0e10cSrcweir if ( nUnoType & sheet::NamedRangeFlag::PRINT_AREA ) nNewType |= RT_PRINTAREA; 548*cdf0e10cSrcweir if ( nUnoType & sheet::NamedRangeFlag::COLUMN_HEADER ) nNewType |= RT_COLHEADER; 549*cdf0e10cSrcweir if ( nUnoType & sheet::NamedRangeFlag::ROW_HEADER ) nNewType |= RT_ROWHEADER; 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir sal_Bool bDone = sal_False; 552*cdf0e10cSrcweir if (pDocShell) 553*cdf0e10cSrcweir { 554*cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument(); 555*cdf0e10cSrcweir ScRangeName* pNames = pDoc->GetRangeName(); 556*cdf0e10cSrcweir sal_uInt16 nIndex = 0; 557*cdf0e10cSrcweir if (pNames && !pNames->SearchName(aNameStr, nIndex)) 558*cdf0e10cSrcweir { 559*cdf0e10cSrcweir ScRangeName* pNewRanges = new ScRangeName( *pNames ); 560*cdf0e10cSrcweir // GRAM_PODF_A1 for API compatibility. 561*cdf0e10cSrcweir ScRangeData* pNew = new ScRangeData( pDoc, aNameStr, aContStr, 562*cdf0e10cSrcweir aPos, nNewType,formula::FormulaGrammar::GRAM_PODF_A1 ); 563*cdf0e10cSrcweir if ( pNewRanges->Insert(pNew) ) 564*cdf0e10cSrcweir { 565*cdf0e10cSrcweir ScDocFunc aFunc(*pDocShell); 566*cdf0e10cSrcweir aFunc.SetNewRangeNames( pNewRanges, sal_True ); 567*cdf0e10cSrcweir bDone = sal_True; 568*cdf0e10cSrcweir } 569*cdf0e10cSrcweir else 570*cdf0e10cSrcweir { 571*cdf0e10cSrcweir delete pNew; 572*cdf0e10cSrcweir delete pNewRanges; 573*cdf0e10cSrcweir } 574*cdf0e10cSrcweir } 575*cdf0e10cSrcweir } 576*cdf0e10cSrcweir 577*cdf0e10cSrcweir if (!bDone) 578*cdf0e10cSrcweir throw uno::RuntimeException(); // no other exceptions specified 579*cdf0e10cSrcweir } 580*cdf0e10cSrcweir 581*cdf0e10cSrcweir void SAL_CALL ScNamedRangesObj::addNewFromTitles( const table::CellRangeAddress& aSource, 582*cdf0e10cSrcweir sheet::Border aBorder ) throw(uno::RuntimeException) 583*cdf0e10cSrcweir { 584*cdf0e10cSrcweir ScUnoGuard aGuard; 585*cdf0e10cSrcweir //! das darf kein enum sein, weil mehrere Bits gesetzt sein koennen !!! 586*cdf0e10cSrcweir 587*cdf0e10cSrcweir sal_Bool bTop = ( aBorder == sheet::Border_TOP ); 588*cdf0e10cSrcweir sal_Bool bLeft = ( aBorder == sheet::Border_LEFT ); 589*cdf0e10cSrcweir sal_Bool bBottom = ( aBorder == sheet::Border_BOTTOM ); 590*cdf0e10cSrcweir sal_Bool bRight = ( aBorder == sheet::Border_RIGHT ); 591*cdf0e10cSrcweir 592*cdf0e10cSrcweir ScRange aRange; 593*cdf0e10cSrcweir ScUnoConversion::FillScRange( aRange, aSource ); 594*cdf0e10cSrcweir 595*cdf0e10cSrcweir sal_uInt16 nFlags = 0; 596*cdf0e10cSrcweir if (bTop) nFlags |= NAME_TOP; 597*cdf0e10cSrcweir if (bLeft) nFlags |= NAME_LEFT; 598*cdf0e10cSrcweir if (bBottom) nFlags |= NAME_BOTTOM; 599*cdf0e10cSrcweir if (bRight) nFlags |= NAME_RIGHT; 600*cdf0e10cSrcweir 601*cdf0e10cSrcweir if (nFlags) 602*cdf0e10cSrcweir { 603*cdf0e10cSrcweir ScDocFunc aFunc(*pDocShell); 604*cdf0e10cSrcweir aFunc.CreateNames( aRange, nFlags, sal_True ); 605*cdf0e10cSrcweir } 606*cdf0e10cSrcweir } 607*cdf0e10cSrcweir 608*cdf0e10cSrcweir void SAL_CALL ScNamedRangesObj::removeByName( const rtl::OUString& aName ) 609*cdf0e10cSrcweir throw(uno::RuntimeException) 610*cdf0e10cSrcweir { 611*cdf0e10cSrcweir ScUnoGuard aGuard; 612*cdf0e10cSrcweir sal_Bool bDone = sal_False; 613*cdf0e10cSrcweir if (pDocShell) 614*cdf0e10cSrcweir { 615*cdf0e10cSrcweir ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName(); 616*cdf0e10cSrcweir if (pNames) 617*cdf0e10cSrcweir { 618*cdf0e10cSrcweir String aString(aName); 619*cdf0e10cSrcweir sal_uInt16 nPos = 0; 620*cdf0e10cSrcweir if (pNames->SearchName( aString, nPos )) 621*cdf0e10cSrcweir if ( lcl_UserVisibleName((*pNames)[nPos]) ) 622*cdf0e10cSrcweir { 623*cdf0e10cSrcweir ScRangeName* pNewRanges = new ScRangeName(*pNames); 624*cdf0e10cSrcweir pNewRanges->AtFree(nPos); 625*cdf0e10cSrcweir ScDocFunc aFunc(*pDocShell); 626*cdf0e10cSrcweir aFunc.SetNewRangeNames( pNewRanges, sal_True ); 627*cdf0e10cSrcweir bDone = sal_True; 628*cdf0e10cSrcweir } 629*cdf0e10cSrcweir } 630*cdf0e10cSrcweir } 631*cdf0e10cSrcweir 632*cdf0e10cSrcweir if (!bDone) 633*cdf0e10cSrcweir throw uno::RuntimeException(); // no other exceptions specified 634*cdf0e10cSrcweir } 635*cdf0e10cSrcweir 636*cdf0e10cSrcweir void SAL_CALL ScNamedRangesObj::outputList( const table::CellAddress& aOutputPosition ) 637*cdf0e10cSrcweir throw(uno::RuntimeException) 638*cdf0e10cSrcweir { 639*cdf0e10cSrcweir ScUnoGuard aGuard; 640*cdf0e10cSrcweir ScAddress aPos( (SCCOL)aOutputPosition.Column, (SCROW)aOutputPosition.Row, aOutputPosition.Sheet ); 641*cdf0e10cSrcweir if (pDocShell) 642*cdf0e10cSrcweir { 643*cdf0e10cSrcweir ScDocFunc aFunc(*pDocShell); 644*cdf0e10cSrcweir aFunc.InsertNameList( aPos, sal_True ); 645*cdf0e10cSrcweir } 646*cdf0e10cSrcweir } 647*cdf0e10cSrcweir 648*cdf0e10cSrcweir // container::XEnumerationAccess 649*cdf0e10cSrcweir 650*cdf0e10cSrcweir uno::Reference<container::XEnumeration> SAL_CALL ScNamedRangesObj::createEnumeration() 651*cdf0e10cSrcweir throw(uno::RuntimeException) 652*cdf0e10cSrcweir { 653*cdf0e10cSrcweir ScUnoGuard aGuard; 654*cdf0e10cSrcweir return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.NamedRangesEnumeration"))); 655*cdf0e10cSrcweir } 656*cdf0e10cSrcweir 657*cdf0e10cSrcweir // container::XIndexAccess 658*cdf0e10cSrcweir 659*cdf0e10cSrcweir sal_Int32 SAL_CALL ScNamedRangesObj::getCount() throw(uno::RuntimeException) 660*cdf0e10cSrcweir { 661*cdf0e10cSrcweir ScUnoGuard aGuard; 662*cdf0e10cSrcweir long nRet = 0; 663*cdf0e10cSrcweir if (pDocShell) 664*cdf0e10cSrcweir { 665*cdf0e10cSrcweir ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName(); 666*cdf0e10cSrcweir if (pNames) 667*cdf0e10cSrcweir { 668*cdf0e10cSrcweir sal_uInt16 nCount = pNames->GetCount(); 669*cdf0e10cSrcweir for (sal_uInt16 i=0; i<nCount; i++) 670*cdf0e10cSrcweir if (lcl_UserVisibleName( (*pNames)[i] )) // interne weglassen 671*cdf0e10cSrcweir ++nRet; 672*cdf0e10cSrcweir } 673*cdf0e10cSrcweir } 674*cdf0e10cSrcweir return nRet; 675*cdf0e10cSrcweir } 676*cdf0e10cSrcweir 677*cdf0e10cSrcweir uno::Any SAL_CALL ScNamedRangesObj::getByIndex( sal_Int32 nIndex ) 678*cdf0e10cSrcweir throw(lang::IndexOutOfBoundsException, 679*cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 680*cdf0e10cSrcweir { 681*cdf0e10cSrcweir ScUnoGuard aGuard; 682*cdf0e10cSrcweir uno::Reference< sheet::XNamedRange > xRange(GetObjectByIndex_Impl((sal_uInt16)nIndex)); 683*cdf0e10cSrcweir if ( xRange.is() ) 684*cdf0e10cSrcweir return uno::makeAny(xRange); 685*cdf0e10cSrcweir else 686*cdf0e10cSrcweir throw lang::IndexOutOfBoundsException(); 687*cdf0e10cSrcweir // return uno::Any(); 688*cdf0e10cSrcweir } 689*cdf0e10cSrcweir 690*cdf0e10cSrcweir uno::Type SAL_CALL ScNamedRangesObj::getElementType() throw(uno::RuntimeException) 691*cdf0e10cSrcweir { 692*cdf0e10cSrcweir ScUnoGuard aGuard; 693*cdf0e10cSrcweir return ::getCppuType((const uno::Reference< sheet::XNamedRange >*)0); // muss zu getByIndex passen 694*cdf0e10cSrcweir } 695*cdf0e10cSrcweir 696*cdf0e10cSrcweir sal_Bool SAL_CALL ScNamedRangesObj::hasElements() throw(uno::RuntimeException) 697*cdf0e10cSrcweir { 698*cdf0e10cSrcweir ScUnoGuard aGuard; 699*cdf0e10cSrcweir return ( getCount() != 0 ); 700*cdf0e10cSrcweir } 701*cdf0e10cSrcweir 702*cdf0e10cSrcweir uno::Any SAL_CALL ScNamedRangesObj::getByName( const rtl::OUString& aName ) 703*cdf0e10cSrcweir throw(container::NoSuchElementException, 704*cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 705*cdf0e10cSrcweir { 706*cdf0e10cSrcweir ScUnoGuard aGuard; 707*cdf0e10cSrcweir uno::Reference< sheet::XNamedRange > xRange(GetObjectByName_Impl(aName)); 708*cdf0e10cSrcweir if ( xRange.is() ) 709*cdf0e10cSrcweir return uno::makeAny(xRange); 710*cdf0e10cSrcweir else 711*cdf0e10cSrcweir throw container::NoSuchElementException(); 712*cdf0e10cSrcweir // return uno::Any(); 713*cdf0e10cSrcweir } 714*cdf0e10cSrcweir 715*cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL ScNamedRangesObj::getElementNames() 716*cdf0e10cSrcweir throw(uno::RuntimeException) 717*cdf0e10cSrcweir { 718*cdf0e10cSrcweir ScUnoGuard aGuard; 719*cdf0e10cSrcweir if (pDocShell) 720*cdf0e10cSrcweir { 721*cdf0e10cSrcweir ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName(); 722*cdf0e10cSrcweir if (pNames) 723*cdf0e10cSrcweir { 724*cdf0e10cSrcweir long nVisCount = getCount(); // Namen mit lcl_UserVisibleName 725*cdf0e10cSrcweir uno::Sequence<rtl::OUString> aSeq(nVisCount); 726*cdf0e10cSrcweir rtl::OUString* pAry = aSeq.getArray(); 727*cdf0e10cSrcweir 728*cdf0e10cSrcweir sal_uInt16 nCount = pNames->GetCount(); 729*cdf0e10cSrcweir sal_uInt16 nVisPos = 0; 730*cdf0e10cSrcweir for (sal_uInt16 i=0; i<nCount; i++) 731*cdf0e10cSrcweir { 732*cdf0e10cSrcweir ScRangeData* pData = (*pNames)[i]; 733*cdf0e10cSrcweir if ( lcl_UserVisibleName(pData) ) 734*cdf0e10cSrcweir pAry[nVisPos++] = pData->GetName(); 735*cdf0e10cSrcweir } 736*cdf0e10cSrcweir // DBG_ASSERT(nVisPos == nVisCount, "huch, verzaehlt?"); 737*cdf0e10cSrcweir return aSeq; 738*cdf0e10cSrcweir } 739*cdf0e10cSrcweir } 740*cdf0e10cSrcweir return uno::Sequence<rtl::OUString>(0); 741*cdf0e10cSrcweir } 742*cdf0e10cSrcweir 743*cdf0e10cSrcweir sal_Bool SAL_CALL ScNamedRangesObj::hasByName( const rtl::OUString& aName ) 744*cdf0e10cSrcweir throw(uno::RuntimeException) 745*cdf0e10cSrcweir { 746*cdf0e10cSrcweir ScUnoGuard aGuard; 747*cdf0e10cSrcweir if (pDocShell) 748*cdf0e10cSrcweir { 749*cdf0e10cSrcweir ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName(); 750*cdf0e10cSrcweir if (pNames) 751*cdf0e10cSrcweir { 752*cdf0e10cSrcweir sal_uInt16 nPos = 0; 753*cdf0e10cSrcweir if (pNames->SearchName( String(aName), nPos )) 754*cdf0e10cSrcweir if ( lcl_UserVisibleName((*pNames)[nPos]) ) 755*cdf0e10cSrcweir return sal_True; 756*cdf0e10cSrcweir } 757*cdf0e10cSrcweir } 758*cdf0e10cSrcweir return sal_False; 759*cdf0e10cSrcweir } 760*cdf0e10cSrcweir 761*cdf0e10cSrcweir /** called from the XActionLockable interface methods on initial locking */ 762*cdf0e10cSrcweir void ScNamedRangesObj::lock() 763*cdf0e10cSrcweir { 764*cdf0e10cSrcweir pDocShell->GetDocument()->CompileNameFormula( sal_True ); // CreateFormulaString 765*cdf0e10cSrcweir } 766*cdf0e10cSrcweir 767*cdf0e10cSrcweir /** called from the XActionLockable interface methods on final unlock */ 768*cdf0e10cSrcweir void ScNamedRangesObj::unlock() 769*cdf0e10cSrcweir { 770*cdf0e10cSrcweir pDocShell->GetDocument()->CompileNameFormula( sal_False ); // CompileFormulaString 771*cdf0e10cSrcweir } 772*cdf0e10cSrcweir 773*cdf0e10cSrcweir // document::XActionLockable 774*cdf0e10cSrcweir 775*cdf0e10cSrcweir sal_Bool ScNamedRangesObj::isActionLocked() throw(uno::RuntimeException) 776*cdf0e10cSrcweir { 777*cdf0e10cSrcweir ScUnoGuard aGuard; 778*cdf0e10cSrcweir return pDocShell->GetDocument()->GetNamedRangesLockCount() != 0; 779*cdf0e10cSrcweir } 780*cdf0e10cSrcweir 781*cdf0e10cSrcweir void ScNamedRangesObj::addActionLock() throw(uno::RuntimeException) 782*cdf0e10cSrcweir { 783*cdf0e10cSrcweir ScUnoGuard aGuard; 784*cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument(); 785*cdf0e10cSrcweir sal_Int16 nLockCount = pDoc->GetNamedRangesLockCount(); 786*cdf0e10cSrcweir ++nLockCount; 787*cdf0e10cSrcweir if ( nLockCount == 1 ) 788*cdf0e10cSrcweir { 789*cdf0e10cSrcweir lock(); 790*cdf0e10cSrcweir } 791*cdf0e10cSrcweir pDoc->SetNamedRangesLockCount( nLockCount ); 792*cdf0e10cSrcweir } 793*cdf0e10cSrcweir 794*cdf0e10cSrcweir void ScNamedRangesObj::removeActionLock() throw(uno::RuntimeException) 795*cdf0e10cSrcweir { 796*cdf0e10cSrcweir ScUnoGuard aGuard; 797*cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument(); 798*cdf0e10cSrcweir sal_Int16 nLockCount = pDoc->GetNamedRangesLockCount(); 799*cdf0e10cSrcweir if ( nLockCount > 0 ) 800*cdf0e10cSrcweir { 801*cdf0e10cSrcweir --nLockCount; 802*cdf0e10cSrcweir if ( nLockCount == 0 ) 803*cdf0e10cSrcweir { 804*cdf0e10cSrcweir unlock(); 805*cdf0e10cSrcweir } 806*cdf0e10cSrcweir pDoc->SetNamedRangesLockCount( nLockCount ); 807*cdf0e10cSrcweir } 808*cdf0e10cSrcweir } 809*cdf0e10cSrcweir 810*cdf0e10cSrcweir void ScNamedRangesObj::setActionLocks( sal_Int16 nLock ) throw(uno::RuntimeException) 811*cdf0e10cSrcweir { 812*cdf0e10cSrcweir ScUnoGuard aGuard; 813*cdf0e10cSrcweir if ( nLock >= 0 ) 814*cdf0e10cSrcweir { 815*cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument(); 816*cdf0e10cSrcweir sal_Int16 nLockCount = pDoc->GetNamedRangesLockCount(); 817*cdf0e10cSrcweir if ( nLock == 0 && nLockCount > 0 ) 818*cdf0e10cSrcweir { 819*cdf0e10cSrcweir unlock(); 820*cdf0e10cSrcweir } 821*cdf0e10cSrcweir if ( nLock > 0 && nLockCount == 0 ) 822*cdf0e10cSrcweir { 823*cdf0e10cSrcweir lock(); 824*cdf0e10cSrcweir } 825*cdf0e10cSrcweir pDoc->SetNamedRangesLockCount( nLock ); 826*cdf0e10cSrcweir } 827*cdf0e10cSrcweir } 828*cdf0e10cSrcweir 829*cdf0e10cSrcweir sal_Int16 ScNamedRangesObj::resetActionLocks() throw(uno::RuntimeException) 830*cdf0e10cSrcweir { 831*cdf0e10cSrcweir ScUnoGuard aGuard; 832*cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument(); 833*cdf0e10cSrcweir sal_Int16 nLockCount = pDoc->GetNamedRangesLockCount(); 834*cdf0e10cSrcweir if ( nLockCount > 0 ) 835*cdf0e10cSrcweir { 836*cdf0e10cSrcweir unlock(); 837*cdf0e10cSrcweir } 838*cdf0e10cSrcweir pDoc->SetNamedRangesLockCount( 0 ); 839*cdf0e10cSrcweir return nLockCount; 840*cdf0e10cSrcweir } 841*cdf0e10cSrcweir 842*cdf0e10cSrcweir //------------------------------------------------------------------------ 843*cdf0e10cSrcweir 844*cdf0e10cSrcweir ScLabelRangeObj::ScLabelRangeObj(ScDocShell* pDocSh, sal_Bool bCol, const ScRange& rR) : 845*cdf0e10cSrcweir pDocShell( pDocSh ), 846*cdf0e10cSrcweir bColumn( bCol ), 847*cdf0e10cSrcweir aRange( rR ) 848*cdf0e10cSrcweir { 849*cdf0e10cSrcweir pDocShell->GetDocument()->AddUnoObject(*this); 850*cdf0e10cSrcweir } 851*cdf0e10cSrcweir 852*cdf0e10cSrcweir ScLabelRangeObj::~ScLabelRangeObj() 853*cdf0e10cSrcweir { 854*cdf0e10cSrcweir if (pDocShell) 855*cdf0e10cSrcweir pDocShell->GetDocument()->RemoveUnoObject(*this); 856*cdf0e10cSrcweir } 857*cdf0e10cSrcweir 858*cdf0e10cSrcweir void ScLabelRangeObj::Notify( SfxBroadcaster&, const SfxHint& rHint ) 859*cdf0e10cSrcweir { 860*cdf0e10cSrcweir //! Ref-Update !!! 861*cdf0e10cSrcweir 862*cdf0e10cSrcweir if ( rHint.ISA( SfxSimpleHint ) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) 863*cdf0e10cSrcweir pDocShell = NULL; // ungueltig geworden 864*cdf0e10cSrcweir } 865*cdf0e10cSrcweir 866*cdf0e10cSrcweir // Hilfsfuntionen 867*cdf0e10cSrcweir 868*cdf0e10cSrcweir ScRangePair* ScLabelRangeObj::GetData_Impl() 869*cdf0e10cSrcweir { 870*cdf0e10cSrcweir ScRangePair* pRet = NULL; 871*cdf0e10cSrcweir if (pDocShell) 872*cdf0e10cSrcweir { 873*cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument(); 874*cdf0e10cSrcweir ScRangePairList* pList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges(); 875*cdf0e10cSrcweir if (pList) 876*cdf0e10cSrcweir pRet = pList->Find( aRange ); 877*cdf0e10cSrcweir } 878*cdf0e10cSrcweir return pRet; 879*cdf0e10cSrcweir } 880*cdf0e10cSrcweir 881*cdf0e10cSrcweir void ScLabelRangeObj::Modify_Impl( const ScRange* pLabel, const ScRange* pData ) 882*cdf0e10cSrcweir { 883*cdf0e10cSrcweir if (pDocShell) 884*cdf0e10cSrcweir { 885*cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument(); 886*cdf0e10cSrcweir ScRangePairList* pOldList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges(); 887*cdf0e10cSrcweir if (pOldList) 888*cdf0e10cSrcweir { 889*cdf0e10cSrcweir ScRangePairListRef xNewList(pOldList->Clone()); 890*cdf0e10cSrcweir ScRangePair* pEntry = xNewList->Find( aRange ); 891*cdf0e10cSrcweir if (pEntry) 892*cdf0e10cSrcweir { 893*cdf0e10cSrcweir xNewList->Remove( pEntry ); // nur aus der Liste entfernt, nicht geloescht 894*cdf0e10cSrcweir 895*cdf0e10cSrcweir if ( pLabel ) 896*cdf0e10cSrcweir pEntry->GetRange(0) = *pLabel; 897*cdf0e10cSrcweir if ( pData ) 898*cdf0e10cSrcweir pEntry->GetRange(1) = *pData; 899*cdf0e10cSrcweir 900*cdf0e10cSrcweir xNewList->Join( *pEntry ); 901*cdf0e10cSrcweir delete pEntry; 902*cdf0e10cSrcweir 903*cdf0e10cSrcweir if (bColumn) 904*cdf0e10cSrcweir pDoc->GetColNameRangesRef() = xNewList; 905*cdf0e10cSrcweir else 906*cdf0e10cSrcweir pDoc->GetRowNameRangesRef() = xNewList; 907*cdf0e10cSrcweir 908*cdf0e10cSrcweir pDoc->CompileColRowNameFormula(); 909*cdf0e10cSrcweir pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID ); 910*cdf0e10cSrcweir pDocShell->SetDocumentModified(); 911*cdf0e10cSrcweir 912*cdf0e10cSrcweir //! Undo ?!?! (hier und aus Dialog) 913*cdf0e10cSrcweir 914*cdf0e10cSrcweir if ( pLabel ) 915*cdf0e10cSrcweir aRange = *pLabel; // Objekt anpassen, um Range wiederzufinden 916*cdf0e10cSrcweir } 917*cdf0e10cSrcweir } 918*cdf0e10cSrcweir } 919*cdf0e10cSrcweir } 920*cdf0e10cSrcweir 921*cdf0e10cSrcweir // sheet::XLabelRange 922*cdf0e10cSrcweir 923*cdf0e10cSrcweir table::CellRangeAddress SAL_CALL ScLabelRangeObj::getLabelArea() 924*cdf0e10cSrcweir throw(uno::RuntimeException) 925*cdf0e10cSrcweir { 926*cdf0e10cSrcweir ScUnoGuard aGuard; 927*cdf0e10cSrcweir table::CellRangeAddress aRet; 928*cdf0e10cSrcweir ScRangePair* pData = GetData_Impl(); 929*cdf0e10cSrcweir if (pData) 930*cdf0e10cSrcweir ScUnoConversion::FillApiRange( aRet, pData->GetRange(0) ); 931*cdf0e10cSrcweir return aRet; 932*cdf0e10cSrcweir } 933*cdf0e10cSrcweir 934*cdf0e10cSrcweir void SAL_CALL ScLabelRangeObj::setLabelArea( const table::CellRangeAddress& aLabelArea ) 935*cdf0e10cSrcweir throw(uno::RuntimeException) 936*cdf0e10cSrcweir { 937*cdf0e10cSrcweir ScUnoGuard aGuard; 938*cdf0e10cSrcweir ScRange aLabelRange; 939*cdf0e10cSrcweir ScUnoConversion::FillScRange( aLabelRange, aLabelArea ); 940*cdf0e10cSrcweir Modify_Impl( &aLabelRange, NULL ); 941*cdf0e10cSrcweir } 942*cdf0e10cSrcweir 943*cdf0e10cSrcweir table::CellRangeAddress SAL_CALL ScLabelRangeObj::getDataArea() 944*cdf0e10cSrcweir throw(uno::RuntimeException) 945*cdf0e10cSrcweir { 946*cdf0e10cSrcweir ScUnoGuard aGuard; 947*cdf0e10cSrcweir table::CellRangeAddress aRet; 948*cdf0e10cSrcweir ScRangePair* pData = GetData_Impl(); 949*cdf0e10cSrcweir if (pData) 950*cdf0e10cSrcweir ScUnoConversion::FillApiRange( aRet, pData->GetRange(1) ); 951*cdf0e10cSrcweir return aRet; 952*cdf0e10cSrcweir } 953*cdf0e10cSrcweir 954*cdf0e10cSrcweir void SAL_CALL ScLabelRangeObj::setDataArea( const table::CellRangeAddress& aDataArea ) 955*cdf0e10cSrcweir throw(uno::RuntimeException) 956*cdf0e10cSrcweir { 957*cdf0e10cSrcweir ScUnoGuard aGuard; 958*cdf0e10cSrcweir ScRange aDataRange; 959*cdf0e10cSrcweir ScUnoConversion::FillScRange( aDataRange, aDataArea ); 960*cdf0e10cSrcweir Modify_Impl( NULL, &aDataRange ); 961*cdf0e10cSrcweir } 962*cdf0e10cSrcweir 963*cdf0e10cSrcweir //------------------------------------------------------------------------ 964*cdf0e10cSrcweir 965*cdf0e10cSrcweir ScLabelRangesObj::ScLabelRangesObj(ScDocShell* pDocSh, sal_Bool bCol) : 966*cdf0e10cSrcweir pDocShell( pDocSh ), 967*cdf0e10cSrcweir bColumn( bCol ) 968*cdf0e10cSrcweir { 969*cdf0e10cSrcweir pDocShell->GetDocument()->AddUnoObject(*this); 970*cdf0e10cSrcweir } 971*cdf0e10cSrcweir 972*cdf0e10cSrcweir ScLabelRangesObj::~ScLabelRangesObj() 973*cdf0e10cSrcweir { 974*cdf0e10cSrcweir if (pDocShell) 975*cdf0e10cSrcweir pDocShell->GetDocument()->RemoveUnoObject(*this); 976*cdf0e10cSrcweir } 977*cdf0e10cSrcweir 978*cdf0e10cSrcweir void ScLabelRangesObj::Notify( SfxBroadcaster&, const SfxHint& rHint ) 979*cdf0e10cSrcweir { 980*cdf0e10cSrcweir // Referenz-Update interessiert hier nicht 981*cdf0e10cSrcweir 982*cdf0e10cSrcweir if ( rHint.ISA( SfxSimpleHint ) && 983*cdf0e10cSrcweir ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) 984*cdf0e10cSrcweir { 985*cdf0e10cSrcweir pDocShell = NULL; // ungueltig geworden 986*cdf0e10cSrcweir } 987*cdf0e10cSrcweir } 988*cdf0e10cSrcweir 989*cdf0e10cSrcweir // sheet::XLabelRanges 990*cdf0e10cSrcweir 991*cdf0e10cSrcweir ScLabelRangeObj* ScLabelRangesObj::GetObjectByIndex_Impl(sal_uInt16 nIndex) 992*cdf0e10cSrcweir { 993*cdf0e10cSrcweir if (pDocShell) 994*cdf0e10cSrcweir { 995*cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument(); 996*cdf0e10cSrcweir ScRangePairList* pList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges(); 997*cdf0e10cSrcweir if ( pList && nIndex < pList->Count() ) 998*cdf0e10cSrcweir { 999*cdf0e10cSrcweir ScRangePair* pData = pList->GetObject(nIndex); 1000*cdf0e10cSrcweir if (pData) 1001*cdf0e10cSrcweir return new ScLabelRangeObj( pDocShell, bColumn, pData->GetRange(0) ); 1002*cdf0e10cSrcweir } 1003*cdf0e10cSrcweir } 1004*cdf0e10cSrcweir return NULL; 1005*cdf0e10cSrcweir } 1006*cdf0e10cSrcweir 1007*cdf0e10cSrcweir void SAL_CALL ScLabelRangesObj::addNew( const table::CellRangeAddress& aLabelArea, 1008*cdf0e10cSrcweir const table::CellRangeAddress& aDataArea ) 1009*cdf0e10cSrcweir throw(uno::RuntimeException) 1010*cdf0e10cSrcweir { 1011*cdf0e10cSrcweir ScUnoGuard aGuard; 1012*cdf0e10cSrcweir if (pDocShell) 1013*cdf0e10cSrcweir { 1014*cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument(); 1015*cdf0e10cSrcweir ScRangePairList* pOldList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges(); 1016*cdf0e10cSrcweir if (pOldList) 1017*cdf0e10cSrcweir { 1018*cdf0e10cSrcweir ScRangePairListRef xNewList(pOldList->Clone()); 1019*cdf0e10cSrcweir 1020*cdf0e10cSrcweir ScRange aLabelRange; 1021*cdf0e10cSrcweir ScRange aDataRange; 1022*cdf0e10cSrcweir ScUnoConversion::FillScRange( aLabelRange, aLabelArea ); 1023*cdf0e10cSrcweir ScUnoConversion::FillScRange( aDataRange, aDataArea ); 1024*cdf0e10cSrcweir xNewList->Join( ScRangePair( aLabelRange, aDataRange ) ); 1025*cdf0e10cSrcweir 1026*cdf0e10cSrcweir if (bColumn) 1027*cdf0e10cSrcweir pDoc->GetColNameRangesRef() = xNewList; 1028*cdf0e10cSrcweir else 1029*cdf0e10cSrcweir pDoc->GetRowNameRangesRef() = xNewList; 1030*cdf0e10cSrcweir 1031*cdf0e10cSrcweir pDoc->CompileColRowNameFormula(); 1032*cdf0e10cSrcweir pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID ); 1033*cdf0e10cSrcweir pDocShell->SetDocumentModified(); 1034*cdf0e10cSrcweir 1035*cdf0e10cSrcweir //! Undo ?!?! (hier und aus Dialog) 1036*cdf0e10cSrcweir } 1037*cdf0e10cSrcweir } 1038*cdf0e10cSrcweir } 1039*cdf0e10cSrcweir 1040*cdf0e10cSrcweir void SAL_CALL ScLabelRangesObj::removeByIndex( sal_Int32 nIndex ) 1041*cdf0e10cSrcweir throw(uno::RuntimeException) 1042*cdf0e10cSrcweir { 1043*cdf0e10cSrcweir ScUnoGuard aGuard; 1044*cdf0e10cSrcweir sal_Bool bDone = sal_False; 1045*cdf0e10cSrcweir if (pDocShell) 1046*cdf0e10cSrcweir { 1047*cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument(); 1048*cdf0e10cSrcweir ScRangePairList* pOldList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges(); 1049*cdf0e10cSrcweir 1050*cdf0e10cSrcweir if ( pOldList && nIndex >= 0 && nIndex < (sal_Int32)pOldList->Count() ) 1051*cdf0e10cSrcweir { 1052*cdf0e10cSrcweir ScRangePairListRef xNewList(pOldList->Clone()); 1053*cdf0e10cSrcweir 1054*cdf0e10cSrcweir ScRangePair* pEntry = xNewList->GetObject( nIndex ); 1055*cdf0e10cSrcweir if (pEntry) 1056*cdf0e10cSrcweir { 1057*cdf0e10cSrcweir xNewList->Remove( pEntry ); 1058*cdf0e10cSrcweir delete pEntry; 1059*cdf0e10cSrcweir 1060*cdf0e10cSrcweir if (bColumn) 1061*cdf0e10cSrcweir pDoc->GetColNameRangesRef() = xNewList; 1062*cdf0e10cSrcweir else 1063*cdf0e10cSrcweir pDoc->GetRowNameRangesRef() = xNewList; 1064*cdf0e10cSrcweir 1065*cdf0e10cSrcweir pDoc->CompileColRowNameFormula(); 1066*cdf0e10cSrcweir pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID ); 1067*cdf0e10cSrcweir pDocShell->SetDocumentModified(); 1068*cdf0e10cSrcweir bDone = sal_True; 1069*cdf0e10cSrcweir 1070*cdf0e10cSrcweir //! Undo ?!?! (hier und aus Dialog) 1071*cdf0e10cSrcweir } 1072*cdf0e10cSrcweir } 1073*cdf0e10cSrcweir } 1074*cdf0e10cSrcweir if (!bDone) 1075*cdf0e10cSrcweir throw uno::RuntimeException(); // no other exceptions specified 1076*cdf0e10cSrcweir } 1077*cdf0e10cSrcweir 1078*cdf0e10cSrcweir // container::XEnumerationAccess 1079*cdf0e10cSrcweir 1080*cdf0e10cSrcweir uno::Reference<container::XEnumeration> SAL_CALL ScLabelRangesObj::createEnumeration() 1081*cdf0e10cSrcweir throw(uno::RuntimeException) 1082*cdf0e10cSrcweir { 1083*cdf0e10cSrcweir ScUnoGuard aGuard; 1084*cdf0e10cSrcweir return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.LabelRangesEnumeration"))); 1085*cdf0e10cSrcweir } 1086*cdf0e10cSrcweir 1087*cdf0e10cSrcweir // container::XIndexAccess 1088*cdf0e10cSrcweir 1089*cdf0e10cSrcweir sal_Int32 SAL_CALL ScLabelRangesObj::getCount() throw(uno::RuntimeException) 1090*cdf0e10cSrcweir { 1091*cdf0e10cSrcweir ScUnoGuard aGuard; 1092*cdf0e10cSrcweir if (pDocShell) 1093*cdf0e10cSrcweir { 1094*cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument(); 1095*cdf0e10cSrcweir ScRangePairList* pList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges(); 1096*cdf0e10cSrcweir if (pList) 1097*cdf0e10cSrcweir return pList->Count(); 1098*cdf0e10cSrcweir } 1099*cdf0e10cSrcweir return 0; 1100*cdf0e10cSrcweir } 1101*cdf0e10cSrcweir 1102*cdf0e10cSrcweir uno::Any SAL_CALL ScLabelRangesObj::getByIndex( sal_Int32 nIndex ) 1103*cdf0e10cSrcweir throw(lang::IndexOutOfBoundsException, 1104*cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 1105*cdf0e10cSrcweir { 1106*cdf0e10cSrcweir ScUnoGuard aGuard; 1107*cdf0e10cSrcweir uno::Reference< sheet::XLabelRange > xRange(GetObjectByIndex_Impl((sal_uInt16)nIndex)); 1108*cdf0e10cSrcweir if ( xRange.is() ) 1109*cdf0e10cSrcweir return uno::makeAny(xRange); 1110*cdf0e10cSrcweir else 1111*cdf0e10cSrcweir throw lang::IndexOutOfBoundsException(); 1112*cdf0e10cSrcweir // return uno::Any(); 1113*cdf0e10cSrcweir } 1114*cdf0e10cSrcweir 1115*cdf0e10cSrcweir uno::Type SAL_CALL ScLabelRangesObj::getElementType() throw(uno::RuntimeException) 1116*cdf0e10cSrcweir { 1117*cdf0e10cSrcweir ScUnoGuard aGuard; 1118*cdf0e10cSrcweir return ::getCppuType((const uno::Reference< sheet::XLabelRange >*)0); // muss zu getByIndex passen 1119*cdf0e10cSrcweir 1120*cdf0e10cSrcweir } 1121*cdf0e10cSrcweir 1122*cdf0e10cSrcweir sal_Bool SAL_CALL ScLabelRangesObj::hasElements() throw(uno::RuntimeException) 1123*cdf0e10cSrcweir { 1124*cdf0e10cSrcweir ScUnoGuard aGuard; 1125*cdf0e10cSrcweir return ( getCount() != 0 ); 1126*cdf0e10cSrcweir } 1127*cdf0e10cSrcweir 1128*cdf0e10cSrcweir //------------------------------------------------------------------------ 1129*cdf0e10cSrcweir 1130*cdf0e10cSrcweir 1131*cdf0e10cSrcweir 1132