|
[ source navigation ] [ diff markup ] [ identifier search ] [ general search ] |
|||||
|
||||||
001 /************************************************************************* 002 * 003 * OpenOffice.org - a multi-platform office productivity suite 004 * 005 * $RCSfile: unoatxt.cxx,v $ 006 * 007 * $Revision: 1.38 $ 008 * 009 * last change: $Author: hr $ $Date: 2007/09/27 12:41:52 $ 010 * 011 * The Contents of this file are made available subject to 012 * the terms of GNU Lesser General Public License Version 2.1. 013 * 014 * 015 * GNU Lesser General Public License Version 2.1 016 * ============================================= 017 * Copyright 2005 by Sun Microsystems, Inc. 018 * 901 San Antonio Road, Palo Alto, CA 94303, USA 019 * 020 * This library is free software; you can redistribute it and/or 021 * modify it under the terms of the GNU Lesser General Public 022 * License version 2.1, as published by the Free Software Foundation. 023 * 024 * This library is distributed in the hope that it will be useful, 025 * but WITHOUT ANY WARRANTY; without even the implied warranty of 026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 027 * Lesser General Public License for more details. 028 * 029 * You should have received a copy of the GNU Lesser General Public 030 * License along with this library; if not, write to the Free Software 031 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 032 * MA 02111-1307 USA 033 * 034 ************************************************************************/ 035 036 // MARKER(update_precomp.py): autogen include statement, do not remove 037 #include "precompiled_sw.hxx" 038 039 040 #define _SVSTDARR_STRINGS 041 042 043 #ifndef _COM_SUN_STAR_BEANS_PropertyAttribute_HPP_ 044 #include <com/sun/star/beans/PropertyAttribute.hpp> 045 #endif 046 #ifndef _VOS_MUTEX_HXX_ //autogen 047 #include <vos/mutex.hxx> 048 #endif 049 #ifndef _TOOLS_DEBUG_HXX 050 #include <tools/debug.hxx> 051 #endif 052 #ifndef _SV_SVAPP_HXX //autogen 053 #include <vcl/svapp.hxx> 054 #endif 055 #include <svtools/svstdarr.hxx> 056 #ifndef _SVTOOLS_UNOEVENT_HXX_ 057 #include <svtools/unoevent.hxx> 058 #endif 059 #ifndef SVTOOLS_URIHELPER_HXX 060 #include <svtools/urihelper.hxx> 061 #endif 062 #ifndef _SFXEVENT_HXX 063 #include <sfx2/event.hxx> 064 #endif 065 #ifndef _SWTYPES_HXX 066 #include <swtypes.hxx> 067 #endif 068 #ifndef _GLOSDOC_HXX 069 #include <glosdoc.hxx> 070 #endif 071 #ifndef _SHELLIO_HXX 072 #include <shellio.hxx> 073 #endif 074 #ifndef _INITUI_HXX 075 #include <initui.hxx> 076 #endif 077 #ifndef _GLOSLST_HXX 078 #include <gloslst.hxx> 079 #endif 080 #ifndef _UNOATXT_HXX 081 #include <unoatxt.hxx> 082 #endif 083 #ifndef _UNOMAP_HXX 084 #include <unomap.hxx> 085 #endif 086 #ifndef _UNOOBJ_HXX 087 #include <unoobj.hxx> 088 #endif 089 #ifndef _SWEVENT_HXX 090 #include <swevent.hxx> 091 #endif 092 #ifndef _DOC_HXX //autogen 093 #include <doc.hxx> 094 #endif 095 #ifndef _UNOCRSR_HXX //autogen 096 #include <unocrsr.hxx> 097 #endif 098 #ifndef _BOOKMRK_HXX //autogen 099 #include <bookmrk.hxx> 100 #endif 101 #ifndef _UNOPRNMS_HXX 102 #include <unoprnms.hxx> 103 #endif 104 #ifndef _SWDOCSH_HXX 105 #include <docsh.hxx> 106 #endif 107 #ifndef _SWUNODEF_HXX 108 #include <swunodef.hxx> 109 #endif 110 #ifndef _SWMODULE_HXX 111 #include <swmodule.hxx> 112 #endif 113 #ifndef _SFXSMPLHINT_HXX 114 #include <svtools/smplhint.hxx> 115 #endif 116 117 #include <svx/acorrcfg.hxx> 118 119 #include <memory> 120 121 SV_IMPL_REF ( SwDocShell ) 122 using namespace ::com::sun::star; 123 using namespace ::rtl; 124 125 /****************************************************************** 126 * 127 ******************************************************************/ 128 /* -----------------30.03.99 14:31------------------- 129 * 130 * --------------------------------------------------*/ 131 uno::Reference< uno::XInterface > SAL_CALL SwXAutoTextContainer_createInstance( 132 const uno::Reference< lang::XMultiServiceFactory > & ) throw( uno::Exception ) 133 { 134 //the module may not be loaded 135 ::vos::OGuard aGuard(Application::GetSolarMutex()); 136 SwDLL::Init(); 137 static uno::Reference< uno::XInterface > xAText = (cppu::OWeakObject*)new SwXAutoTextContainer();; 138 return xAText; 139 } 140 /* -----------------------------17.04.01 13:17-------------------------------- 141 142 ---------------------------------------------------------------------------*/ 143 uno::Sequence< OUString > SAL_CALL SwXAutoTextContainer_getSupportedServiceNames() throw() 144 { 145 OUString sService( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.AutoTextContainer")); 146 const uno::Sequence< OUString > aSeq( &sService, 1 ); 147 return aSeq; 148 } 149 /* -----------------------------17.04.01 13:18-------------------------------- 150 151 ---------------------------------------------------------------------------*/ 152 OUString SAL_CALL SwXAutoTextContainer_getImplementationName() throw() 153 { 154 return OUString( RTL_CONSTASCII_USTRINGPARAM("SwXAutoTextContainer" ) ); 155 } 156 157 /*-- 21.12.98 12:42:16--------------------------------------------------- 158 159 -----------------------------------------------------------------------*/ 160 SwXAutoTextContainer::SwXAutoTextContainer() 161 { 162 pGlossaries = ::GetGlossaries(); 163 164 } 165 /*-- 21.12.98 12:42:17--------------------------------------------------- 166 167 -----------------------------------------------------------------------*/ 168 SwXAutoTextContainer::~SwXAutoTextContainer() 169 { 170 171 } 172 /*-- 21.12.98 12:42:17--------------------------------------------------- 173 174 -----------------------------------------------------------------------*/ 175 sal_Int32 SwXAutoTextContainer::getCount(void) throw( uno::RuntimeException ) 176 { 177 return pGlossaries->GetGroupCnt(); 178 } 179 /*-- 21.12.98 12:42:18--------------------------------------------------- 180 181 -----------------------------------------------------------------------*/ 182 uno::Any SwXAutoTextContainer::getByIndex(sal_Int32 nIndex) 183 throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException ) 184 { 185 ::vos::OGuard aGuard(Application::GetSolarMutex()); 186 uno::Any aRet; 187 sal_uInt16 nCount = pGlossaries->GetGroupCnt(); 188 if ( 0 <= nIndex && nIndex < nCount ) 189 aRet = getByName(pGlossaries->GetGroupName( static_cast< USHORT >(nIndex) )); 190 else 191 throw lang::IndexOutOfBoundsException(); 192 return aRet; 193 } 194 /*-- 21.12.98 12:42:18--------------------------------------------------- 195 196 -----------------------------------------------------------------------*/ 197 uno::Type SwXAutoTextContainer::getElementType(void) throw( uno::RuntimeException ) 198 { 199 return ::getCppuType((const uno::Reference<text::XAutoTextGroup>*)0); 200 201 } 202 /*-- 21.12.98 12:42:18--------------------------------------------------- 203 204 -----------------------------------------------------------------------*/ 205 sal_Bool SwXAutoTextContainer::hasElements(void) throw( uno::RuntimeException ) 206 { 207 //zumindest Standard sollte es immer geben! 208 return sal_True; 209 } 210 /*-- 21.12.98 12:42:18--------------------------------------------------- 211 212 -----------------------------------------------------------------------*/ 213 uno::Any SwXAutoTextContainer::getByName(const OUString& GroupName) 214 throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException ) 215 { 216 ::vos::OGuard aGuard(Application::GetSolarMutex()); 217 218 uno::Reference< text::XAutoTextGroup > xGroup; 219 if ( pGlossaries && hasByName( GroupName ) ) // group name already known? 220 // TRUE = create group if not already available 221 xGroup = pGlossaries->GetAutoTextGroup( GroupName, TRUE ); 222 223 if ( !xGroup.is() ) 224 throw container::NoSuchElementException(); 225 226 return makeAny( xGroup ); 227 } 228 /*-- 21.12.98 12:42:19--------------------------------------------------- 229 230 -----------------------------------------------------------------------*/ 231 uno::Sequence< OUString > SwXAutoTextContainer::getElementNames(void) throw( uno::RuntimeException ) 232 { 233 ::vos::OGuard aGuard(Application::GetSolarMutex()); 234 sal_uInt16 nCount = pGlossaries->GetGroupCnt(); 235 236 uno::Sequence< OUString > aGroupNames(nCount); 237 OUString *pArr = aGroupNames.getArray(); 238 239 for ( sal_uInt16 i = 0; i < nCount; i++ ) 240 { 241 // Die Namen werden ohne Pfad-Extension weitergegeben 242 String sGroupName(pGlossaries->GetGroupName(i)); 243 pArr[i] = sGroupName.GetToken(0, GLOS_DELIM); 244 } 245 return aGroupNames; 246 } 247 /*-- 21.12.98 12:42:19--------------------------------------------------- 248 findet Gruppennamen mit und ohne Pfadindex 249 -----------------------------------------------------------------------*/ 250 sal_Bool SwXAutoTextContainer::hasByName(const OUString& Name) 251 throw( uno::RuntimeException ) 252 { 253 ::vos::OGuard aGuard(Application::GetSolarMutex()); 254 String sGroupName( pGlossaries->GetCompleteGroupName( Name ) ); 255 if(sGroupName.Len()) 256 return sal_True; 257 return sal_False; 258 } 259 /*-- 21.12.98 12:42:19--------------------------------------------------- 260 261 -----------------------------------------------------------------------*/ 262 uno::Reference< text::XAutoTextGroup > SwXAutoTextContainer::insertNewByName( 263 const OUString& aGroupName) 264 throw( lang::IllegalArgumentException, container::ElementExistException, uno::RuntimeException ) 265 { 266 ::vos::OGuard aGuard(Application::GetSolarMutex()); 267 if(hasByName(aGroupName)) 268 throw container::ElementExistException(); 269 //check for non-ASCII characters 270 if(!aGroupName.getLength()) 271 { 272 lang::IllegalArgumentException aIllegal; 273 aIllegal.Message = C2U("group name must not be empty"); 274 throw aIllegal; 275 } 276 for(sal_Int32 nPos = 0; nPos < aGroupName.getLength(); nPos++) 277 { 278 sal_Unicode cChar = aGroupName[nPos]; 279 if( ((cChar >= 'A') && (cChar <= 'Z')) || 280 ((cChar >= 'a') && (cChar <= 'z')) || 281 ((cChar >= '0') && (cChar <= '9')) || 282 (cChar == '_') || 283 (cChar == 0x20) || 284 (cChar == GLOS_DELIM) ) 285 { 286 continue; 287 } 288 lang::IllegalArgumentException aIllegal; 289 aIllegal.Message = C2U("group name must contain a-z, A-z, '_', ' ' only"); 290 throw aIllegal; 291 } 292 String sGroup(aGroupName); 293 if(STRING_NOTFOUND == sGroup.Search(GLOS_DELIM)) 294 { 295 sGroup += GLOS_DELIM; 296 sGroup += UniString::CreateFromInt32(0); 297 } 298 pGlossaries->NewGroupDoc(sGroup, sGroup.GetToken(0, GLOS_DELIM)); 299 300 uno::Reference< text::XAutoTextGroup > xGroup = pGlossaries->GetAutoTextGroup( sGroup, true ); 301 DBG_ASSERT( xGroup.is(), "SwXAutoTextContainer::insertNewByName: no UNO object created? How this?" ); 302 // we just inserted the group into the glossaries, so why doesn't it exist? 303 304 return xGroup; 305 } 306 /*-- 21.12.98 12:42:19--------------------------------------------------- 307 308 -----------------------------------------------------------------------*/ 309 void SwXAutoTextContainer::removeByName(const OUString& aGroupName) 310 throw( container::NoSuchElementException, uno::RuntimeException ) 311 { 312 ::vos::OGuard aGuard(Application::GetSolarMutex()); 313 //zunaechst den Namen mit Pfad-Extension finden 314 String sGroupName = pGlossaries->GetCompleteGroupName( aGroupName ); 315 if(!sGroupName.Len()) 316 throw container::NoSuchElementException(); 317 pGlossaries->DelGroupDoc(sGroupName); 318 } 319 /* -----------------------------06.04.00 11:11-------------------------------- 320 321 ---------------------------------------------------------------------------*/ 322 OUString SwXAutoTextContainer::getImplementationName(void) throw( uno::RuntimeException ) 323 { 324 return SwXAutoTextContainer_getImplementationName(); 325 } 326 /* -----------------------------06.04.00 11:11-------------------------------- 327 328 ---------------------------------------------------------------------------*/ 329 BOOL SwXAutoTextContainer::supportsService(const OUString& rServiceName) throw( uno::RuntimeException ) 330 { 331 const uno::Sequence< OUString > aNames = SwXAutoTextContainer_getSupportedServiceNames(); 332 for(sal_Int32 nService = 0; nService < aNames.getLength(); nService++) 333 { 334 if(aNames.getConstArray()[nService] == rServiceName) 335 return TRUE; 336 } 337 return FALSE; 338 } 339 /* -----------------------------06.04.00 11:11-------------------------------- 340 341 ---------------------------------------------------------------------------*/ 342 uno::Sequence< OUString > SwXAutoTextContainer::getSupportedServiceNames(void) throw( uno::RuntimeException ) 343 { 344 return SwXAutoTextContainer_getSupportedServiceNames(); 345 } 346 /****************************************************************** 347 * 348 ******************************************************************/ 349 /* -----------------------------10.03.00 18:02-------------------------------- 350 351 ---------------------------------------------------------------------------*/ 352 const uno::Sequence< sal_Int8 > & SwXAutoTextGroup::getUnoTunnelId() 353 { 354 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId(); 355 return aSeq; 356 } 357 /* -----------------------------10.03.00 18:04-------------------------------- 358 359 ---------------------------------------------------------------------------*/ 360 sal_Int64 SAL_CALL SwXAutoTextGroup::getSomething( const uno::Sequence< sal_Int8 >& rId ) 361 throw(uno::RuntimeException) 362 { 363 if( rId.getLength() == 16 364 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), 365 rId.getConstArray(), 16 ) ) 366 { 367 return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this )); 368 } 369 return 0; 370 } 371 372 /*-- 21.12.98 12:42:24--------------------------------------------------- 373 374 -----------------------------------------------------------------------*/ 375 SwXAutoTextGroup::SwXAutoTextGroup(const OUString& rName, 376 SwGlossaries* pGlos) : 377 aPropSet(aSwMapProvider.GetPropertyMap(PROPERTY_MAP_AUTO_TEXT_GROUP)), 378 pGlossaries(pGlos), 379 sName(rName), 380 m_sGroupName(rName) 381 { 382 DBG_ASSERT( -1 != rName.indexOf( GLOS_DELIM ), 383 "SwXAutoTextGroup::SwXAutoTextGroup: to be constructed with a complete name only!" ); 384 } 385 386 /*-- 21.12.98 12:42:24--------------------------------------------------- 387 388 -----------------------------------------------------------------------*/ 389 SwXAutoTextGroup::~SwXAutoTextGroup() 390 { 391 } 392 /*-- 21.12.98 12:42:24--------------------------------------------------- 393 394 -----------------------------------------------------------------------*/ 395 /*-- 21.12.98 12:42:25--------------------------------------------------- 396 397 -----------------------------------------------------------------------*/ 398 uno::Sequence< OUString > SwXAutoTextGroup::getTitles(void) throw( uno::RuntimeException ) 399 { 400 ::vos::OGuard aGuard(Application::GetSolarMutex()); 401 sal_uInt16 nCount = 0; 402 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0; 403 if(pGlosGroup && !pGlosGroup->GetError()) 404 nCount = pGlosGroup->GetCount(); 405 else 406 throw uno::RuntimeException(); 407 408 uno::Sequence< OUString > aEntryTitles(nCount); 409 OUString *pArr = aEntryTitles.getArray(); 410 411 for ( sal_uInt16 i = 0; i < nCount; i++ ) 412 pArr[i] = pGlosGroup->GetLongName(i); 413 delete pGlosGroup; 414 return aEntryTitles; 415 } 416 /*-- 21.12.98 12:42:25--------------------------------------------------- 417 418 -----------------------------------------------------------------------*/ 419 void SwXAutoTextGroup::renameByName(const OUString& aElementName, 420 const OUString& aNewElementName, const OUString& aNewElementTitle) 421 throw( lang::IllegalArgumentException, container::ElementExistException, io::IOException, 422 uno::RuntimeException) 423 { 424 ::vos::OGuard aGuard(Application::GetSolarMutex()); 425 // throw exception only if the programmatic name is to be changed into an existing name 426 if(aNewElementName != aElementName && hasByName(aNewElementName)) 427 throw container::ElementExistException(); 428 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0; 429 if(pGlosGroup && !pGlosGroup->GetError()) 430 { 431 sal_uInt16 nIdx = pGlosGroup->GetIndex( aElementName); 432 if(USHRT_MAX == nIdx) 433 throw lang::IllegalArgumentException(); 434 String aNewShort( aNewElementName); 435 String aNewName( aNewElementTitle); 436 sal_uInt16 nOldLongIdx = pGlosGroup->GetLongIndex( aNewShort ); 437 sal_uInt16 nOldIdx = pGlosGroup->GetIndex( aNewName ); 438 439 if( nIdx != USHRT_MAX && 440 (nOldLongIdx == USHRT_MAX || nOldLongIdx == nIdx )&& 441 (nOldIdx == USHRT_MAX || nOldIdx == nIdx )) 442 { 443 pGlosGroup->Rename( nIdx, &aNewShort, &aNewName ); 444 if(pGlosGroup->GetError() != 0) 445 throw io::IOException(); 446 } 447 delete pGlosGroup; 448 } 449 else 450 throw uno::RuntimeException(); 451 } 452 /* -----------------04.05.99 11:57------------------- 453 * 454 * --------------------------------------------------*/ 455 sal_Bool lcl_CopySelToDoc( SwDoc* pInsDoc, OTextCursorHelper* pxCursor, SwXTextRange* pxRange ) 456 { 457 ASSERT( pInsDoc, "kein Ins.Dokument" ); 458 459 SwNodes& rNds = pInsDoc->GetNodes(); 460 461 SwNodeIndex aIdx( rNds.GetEndOfContent(), -1 ); 462 SwCntntNode * pNd = aIdx.GetNode().GetCntntNode(); 463 SwPosition aPos( aIdx, SwIndex( pNd, pNd->Len() )); 464 465 sal_Bool bRet = sal_False; 466 pInsDoc->LockExpFlds(); 467 { 468 if(pxCursor) 469 { 470 SwPaM* pUnoCrsr = pxCursor->GetPaM(); 471 bRet |= (true == pxCursor->GetDoc()->Copy( *pUnoCrsr, aPos )); 472 } 473 else 474 { 475 SwBookmark* pBkm = pxRange->GetBookmark(); 476 if(pBkm->GetOtherPos()) 477 { 478 SwPaM aTmp(*pBkm->GetOtherPos(), pBkm->GetPos()); 479 bRet |= (true == pxRange->GetDoc()->Copy(aTmp, aPos)); 480 } 481 } 482 } 483 484 pInsDoc->UnlockExpFlds(); 485 if( !pInsDoc->IsExpFldsLocked() ) 486 pInsDoc->UpdateExpFlds(NULL, true); 487 488 return bRet; 489 } 490 /*-- 21.12.98 12:42:25--------------------------------------------------- 491 492 -----------------------------------------------------------------------*/ 493 uno::Reference< text::XAutoTextEntry > SwXAutoTextGroup::insertNewByName(const OUString& aName, 494 const OUString& aTitle, const uno::Reference< text::XTextRange > & xTextRange) 495 throw( container::ElementExistException, uno::RuntimeException ) 496 { 497 ::vos::OGuard aGuard(Application::GetSolarMutex()); 498 if(hasByName(aName)) 499 throw container::ElementExistException(); 500 if(!xTextRange.is()) 501 throw uno::RuntimeException(); 502 503 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0; 504 String sShortName(aName); 505 String sLongName(aTitle); 506 if(pGlosGroup && !pGlosGroup->GetError()) 507 { 508 /*if( pGlosGroup->IsOld() && pGlosGroup->ConvertToNew()) 509 { 510 throw uno::RuntimeException(); 511 } */ 512 uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY); 513 SwXTextRange* pxRange = 0; 514 OTextCursorHelper* pxCursor = 0; 515 if(xRangeTunnel.is()) 516 { 517 pxRange = reinterpret_cast<SwXTextRange*>(xRangeTunnel->getSomething( 518 SwXTextRange::getUnoTunnelId())); 519 pxCursor = reinterpret_cast<OTextCursorHelper*>(xRangeTunnel->getSomething( 520 OTextCursorHelper::getUnoTunnelId())); 521 } 522 523 String sOnlyTxt; 524 String* pOnlyTxt = 0; 525 sal_Bool bNoAttr = !pxCursor && !pxRange; 526 if(bNoAttr) 527 { 528 sOnlyTxt = UniString(xTextRange->getString()); 529 pOnlyTxt = &sOnlyTxt; 530 } 531 532 const SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get(); 533 534 SwDoc* pGDoc = pGlosGroup->GetDoc(); 535 536 // Bis es eine Option dafuer gibt, base util::URL loeschen 537 if(pCfg->IsSaveRelFile()) 538 { 539 INetURLObject aTemp(pGlosGroup->GetFileName()); 540 pGlosGroup->SetBaseURL( aTemp.GetMainURL(INetURLObject::NO_DECODE)); 541 } 542 else 543 pGlosGroup->SetBaseURL( aEmptyStr ); 544 545 sal_uInt16 nRet; 546 if( pOnlyTxt ) 547 nRet = pGlosGroup->PutText( sShortName, sLongName, *pOnlyTxt ); 548 else 549 { 550 pGlosGroup->ClearDoc(); 551 if( pGlosGroup->BeginPutDoc( sShortName, sLongName ) ) 552 { 553 pGDoc->SetRedlineMode_intern( nsRedlineMode_t::REDLINE_DELETE_REDLINES ); 554 lcl_CopySelToDoc( pGDoc, pxCursor, pxRange ); 555 pGDoc->SetRedlineMode_intern((RedlineMode_t)( 0 )); 556 nRet = pGlosGroup->PutDoc(); 557 } 558 else 559 nRet = (sal_uInt16) -1; 560 } 561 562 if(nRet == (sal_uInt16) -1 ) 563 { 564 throw uno::RuntimeException(); 565 } 566 pGlossaries->PutGroupDoc( pGlosGroup ); 567 } 568 569 uno::Reference< text::XAutoTextEntry > xEntry = pGlossaries->GetAutoTextEntry( m_sGroupName, sName, sShortName, true ); 570 DBG_ASSERT( xEntry.is(), "SwXAutoTextGroup::insertNewByName: no UNO object created? How this?" ); 571 // we just inserted the entry into the group, so why doesn't it exist? 572 573 return xEntry; 574 } 575 /*-- 21.12.98 12:42:25--------------------------------------------------- 576 577 -----------------------------------------------------------------------*/ 578 void SwXAutoTextGroup::removeByName(const OUString& aEntryName) throw( container::NoSuchElementException, uno::RuntimeException ) 579 { 580 ::vos::OGuard aGuard(Application::GetSolarMutex()); 581 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0; 582 if(pGlosGroup && !pGlosGroup->GetError()) 583 { 584 sal_uInt16 nIdx = pGlosGroup->GetIndex(aEntryName); 585 if ( nIdx != USHRT_MAX ) 586 pGlosGroup->Delete(nIdx); 587 delete pGlosGroup; 588 } 589 else 590 throw container::NoSuchElementException(); 591 } 592 /*-- 21.12.98 12:42:25--------------------------------------------------- 593 594 -----------------------------------------------------------------------*/ 595 OUString SwXAutoTextGroup::getName(void) throw( uno::RuntimeException ) 596 { 597 ::vos::OGuard aGuard(Application::GetSolarMutex()); 598 return sName; 599 } 600 /*-- 21.12.98 12:42:25--------------------------------------------------- 601 602 -----------------------------------------------------------------------*/ 603 void SwXAutoTextGroup::setName(const OUString& rName) throw( uno::RuntimeException ) 604 { 605 ::vos::OGuard aGuard(Application::GetSolarMutex()); 606 if( !pGlossaries ) 607 throw uno::RuntimeException(); 608 609 sal_Int32 nNewDelimPos = rName.lastIndexOf( GLOS_DELIM ); 610 sal_Int32 nOldDelimPos = sName.lastIndexOf( GLOS_DELIM ); 611 612 OUString aNewSuffix; 613 if (nNewDelimPos > -1) 614 aNewSuffix = rName.copy( nNewDelimPos + 1 ); 615 OUString aOldSuffix; 616 if (nOldDelimPos > -1) 617 aOldSuffix = sName.copy( nOldDelimPos + 1 ); 618 619 sal_Int32 nNewNumeric = aNewSuffix.toInt32(); 620 sal_Int32 nOldNumeric = aOldSuffix.toInt32(); 621 622 OUString aNewPrefix( (nNewDelimPos > 1) ? rName.copy( 0, nNewDelimPos ) : rName ); 623 OUString aOldPrefix( (nOldDelimPos > 1) ? sName.copy( 0, nOldDelimPos ) : sName ); 624 625 if ( sName == rName || 626 ( nNewNumeric == nOldNumeric && aNewPrefix == aOldPrefix ) ) 627 return; 628 String sNewGroup(rName); 629 if(STRING_NOTFOUND == sNewGroup.Search(GLOS_DELIM)) 630 { 631 sNewGroup += GLOS_DELIM; 632 sNewGroup += UniString::CreateFromInt32(0); 633 } 634 635 //the name must be saved, the group may be invalidated while in RenameGroupDoc() 636 SwGlossaries* pTempGlossaries = pGlossaries; 637 638 String sPreserveTitle( pGlossaries->GetGroupTitle( sName ) ); 639 if ( !pGlossaries->RenameGroupDoc( sName, sNewGroup, sPreserveTitle ) ) 640 throw uno::RuntimeException(); 641 else 642 { 643 sName = rName; 644 m_sGroupName = sNewGroup; 645 pGlossaries = pTempGlossaries; 646 } 647 } 648 /*-- 21.12.98 12:42:26--------------------------------------------------- 649 650 -----------------------------------------------------------------------*/ 651 sal_Int32 SwXAutoTextGroup::getCount(void) throw( uno::RuntimeException ) 652 { 653 ::vos::OGuard aGuard(Application::GetSolarMutex()); 654 int nCount = 0; 655 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0; 656 if(pGlosGroup && !pGlosGroup->GetError()) 657 nCount = pGlosGroup->