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