1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 32 #define _SVSTDARR_STRINGS 33 34 #include <com/sun/star/beans/PropertyAttribute.hpp> 35 #include <vos/mutex.hxx> 36 #include <tools/debug.hxx> 37 #include <vcl/svapp.hxx> 38 #include <svl/svstdarr.hxx> 39 #include <svtools/unoevent.hxx> 40 #include <svl/urihelper.hxx> 41 #include <sfx2/event.hxx> 42 #include <swtypes.hxx> 43 #include <glosdoc.hxx> 44 #include <shellio.hxx> 45 #include <initui.hxx> 46 #include <gloslst.hxx> 47 #include <unoatxt.hxx> 48 #include <unomap.hxx> 49 #include <unomid.h> 50 #include <unotextbodyhf.hxx> 51 #include <unotextrange.hxx> 52 #include <TextCursorHelper.hxx> 53 #include <swevent.hxx> 54 #include <doc.hxx> 55 #include <unocrsr.hxx> 56 #include <IMark.hxx> 57 #include <unoprnms.hxx> 58 #include <docsh.hxx> 59 #include <swunodef.hxx> 60 #include <swmodule.hxx> 61 #include <svl/smplhint.hxx> 62 #include <svl/macitem.hxx> 63 64 #include <editeng/acorrcfg.hxx> 65 66 #include <memory> 67 68 69 SV_IMPL_REF ( SwDocShell ) 70 using namespace ::com::sun::star; 71 using ::rtl::OUString; 72 73 /****************************************************************** 74 * 75 ******************************************************************/ 76 /* -----------------30.03.99 14:31------------------- 77 * 78 * --------------------------------------------------*/ 79 uno::Reference< uno::XInterface > SAL_CALL SwXAutoTextContainer_createInstance( 80 const uno::Reference< lang::XMultiServiceFactory > & ) throw( uno::Exception ) 81 { 82 //the module may not be loaded 83 ::vos::OGuard aGuard(Application::GetSolarMutex()); 84 SwDLL::Init(); 85 static uno::Reference< uno::XInterface > xAText = (cppu::OWeakObject*)new SwXAutoTextContainer();; 86 return xAText; 87 } 88 /* -----------------------------17.04.01 13:17-------------------------------- 89 90 ---------------------------------------------------------------------------*/ 91 uno::Sequence< OUString > SAL_CALL SwXAutoTextContainer_getSupportedServiceNames() throw() 92 { 93 OUString sService( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.AutoTextContainer")); 94 const uno::Sequence< OUString > aSeq( &sService, 1 ); 95 return aSeq; 96 } 97 /* -----------------------------17.04.01 13:18-------------------------------- 98 99 ---------------------------------------------------------------------------*/ 100 OUString SAL_CALL SwXAutoTextContainer_getImplementationName() throw() 101 { 102 return OUString( RTL_CONSTASCII_USTRINGPARAM("SwXAutoTextContainer" ) ); 103 } 104 105 /*-- 21.12.98 12:42:16--------------------------------------------------- 106 107 -----------------------------------------------------------------------*/ 108 SwXAutoTextContainer::SwXAutoTextContainer() 109 { 110 pGlossaries = ::GetGlossaries(); 111 112 } 113 /*-- 21.12.98 12:42:17--------------------------------------------------- 114 115 -----------------------------------------------------------------------*/ 116 SwXAutoTextContainer::~SwXAutoTextContainer() 117 { 118 119 } 120 /*-- 21.12.98 12:42:17--------------------------------------------------- 121 122 -----------------------------------------------------------------------*/ 123 sal_Int32 SwXAutoTextContainer::getCount(void) throw( uno::RuntimeException ) 124 { 125 return pGlossaries->GetGroupCnt(); 126 } 127 /*-- 21.12.98 12:42:18--------------------------------------------------- 128 129 -----------------------------------------------------------------------*/ 130 uno::Any SwXAutoTextContainer::getByIndex(sal_Int32 nIndex) 131 throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException ) 132 { 133 ::vos::OGuard aGuard(Application::GetSolarMutex()); 134 uno::Any aRet; 135 sal_uInt16 nCount = pGlossaries->GetGroupCnt(); 136 if ( 0 <= nIndex && nIndex < nCount ) 137 aRet = getByName(pGlossaries->GetGroupName( static_cast< sal_uInt16 >(nIndex) )); 138 else 139 throw lang::IndexOutOfBoundsException(); 140 return aRet; 141 } 142 /*-- 21.12.98 12:42:18--------------------------------------------------- 143 144 -----------------------------------------------------------------------*/ 145 uno::Type SwXAutoTextContainer::getElementType(void) throw( uno::RuntimeException ) 146 { 147 return ::getCppuType((const uno::Reference<text::XAutoTextGroup>*)0); 148 149 } 150 /*-- 21.12.98 12:42:18--------------------------------------------------- 151 152 -----------------------------------------------------------------------*/ 153 sal_Bool SwXAutoTextContainer::hasElements(void) throw( uno::RuntimeException ) 154 { 155 //zumindest Standard sollte es immer geben! 156 return sal_True; 157 } 158 /*-- 21.12.98 12:42:18--------------------------------------------------- 159 160 -----------------------------------------------------------------------*/ 161 uno::Any SwXAutoTextContainer::getByName(const OUString& GroupName) 162 throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException ) 163 { 164 ::vos::OGuard aGuard(Application::GetSolarMutex()); 165 166 uno::Reference< text::XAutoTextGroup > xGroup; 167 if ( pGlossaries && hasByName( GroupName ) ) // group name already known? 168 // sal_True = create group if not already available 169 xGroup = pGlossaries->GetAutoTextGroup( GroupName, sal_True ); 170 171 if ( !xGroup.is() ) 172 throw container::NoSuchElementException(); 173 174 return makeAny( xGroup ); 175 } 176 /*-- 21.12.98 12:42:19--------------------------------------------------- 177 178 -----------------------------------------------------------------------*/ 179 uno::Sequence< OUString > SwXAutoTextContainer::getElementNames(void) throw( uno::RuntimeException ) 180 { 181 ::vos::OGuard aGuard(Application::GetSolarMutex()); 182 sal_uInt16 nCount = pGlossaries->GetGroupCnt(); 183 184 uno::Sequence< OUString > aGroupNames(nCount); 185 OUString *pArr = aGroupNames.getArray(); 186 187 for ( sal_uInt16 i = 0; i < nCount; i++ ) 188 { 189 // Die Namen werden ohne Pfad-Extension weitergegeben 190 String sGroupName(pGlossaries->GetGroupName(i)); 191 pArr[i] = sGroupName.GetToken(0, GLOS_DELIM); 192 } 193 return aGroupNames; 194 } 195 /*-- 21.12.98 12:42:19--------------------------------------------------- 196 findet Gruppennamen mit und ohne Pfadindex 197 -----------------------------------------------------------------------*/ 198 sal_Bool SwXAutoTextContainer::hasByName(const OUString& Name) 199 throw( uno::RuntimeException ) 200 { 201 ::vos::OGuard aGuard(Application::GetSolarMutex()); 202 String sGroupName( pGlossaries->GetCompleteGroupName( Name ) ); 203 if(sGroupName.Len()) 204 return sal_True; 205 return sal_False; 206 } 207 /*-- 21.12.98 12:42:19--------------------------------------------------- 208 209 -----------------------------------------------------------------------*/ 210 uno::Reference< text::XAutoTextGroup > SwXAutoTextContainer::insertNewByName( 211 const OUString& aGroupName) 212 throw( lang::IllegalArgumentException, container::ElementExistException, uno::RuntimeException ) 213 { 214 ::vos::OGuard aGuard(Application::GetSolarMutex()); 215 if(hasByName(aGroupName)) 216 throw container::ElementExistException(); 217 //check for non-ASCII characters 218 if(!aGroupName.getLength()) 219 { 220 lang::IllegalArgumentException aIllegal; 221 aIllegal.Message = C2U("group name must not be empty"); 222 throw aIllegal; 223 } 224 for(sal_Int32 nPos = 0; nPos < aGroupName.getLength(); nPos++) 225 { 226 sal_Unicode cChar = aGroupName[nPos]; 227 if( ((cChar >= 'A') && (cChar <= 'Z')) || 228 ((cChar >= 'a') && (cChar <= 'z')) || 229 ((cChar >= '0') && (cChar <= '9')) || 230 (cChar == '_') || 231 (cChar == 0x20) || 232 (cChar == GLOS_DELIM) ) 233 { 234 continue; 235 } 236 lang::IllegalArgumentException aIllegal; 237 aIllegal.Message = C2U("group name must contain a-z, A-z, '_', ' ' only"); 238 throw aIllegal; 239 } 240 String sGroup(aGroupName); 241 if(STRING_NOTFOUND == sGroup.Search(GLOS_DELIM)) 242 { 243 sGroup += GLOS_DELIM; 244 sGroup += UniString::CreateFromInt32(0); 245 } 246 pGlossaries->NewGroupDoc(sGroup, sGroup.GetToken(0, GLOS_DELIM)); 247 248 uno::Reference< text::XAutoTextGroup > xGroup = pGlossaries->GetAutoTextGroup( sGroup, true ); 249 DBG_ASSERT( xGroup.is(), "SwXAutoTextContainer::insertNewByName: no UNO object created? How this?" ); 250 // we just inserted the group into the glossaries, so why doesn't it exist? 251 252 return xGroup; 253 } 254 /*-- 21.12.98 12:42:19--------------------------------------------------- 255 256 -----------------------------------------------------------------------*/ 257 void SwXAutoTextContainer::removeByName(const OUString& aGroupName) 258 throw( container::NoSuchElementException, uno::RuntimeException ) 259 { 260 ::vos::OGuard aGuard(Application::GetSolarMutex()); 261 //zunaechst den Namen mit Pfad-Extension finden 262 String sGroupName = pGlossaries->GetCompleteGroupName( aGroupName ); 263 if(!sGroupName.Len()) 264 throw container::NoSuchElementException(); 265 pGlossaries->DelGroupDoc(sGroupName); 266 } 267 /* -----------------------------06.04.00 11:11-------------------------------- 268 269 ---------------------------------------------------------------------------*/ 270 OUString SwXAutoTextContainer::getImplementationName(void) throw( uno::RuntimeException ) 271 { 272 return SwXAutoTextContainer_getImplementationName(); 273 } 274 /* -----------------------------06.04.00 11:11-------------------------------- 275 276 ---------------------------------------------------------------------------*/ 277 sal_Bool SwXAutoTextContainer::supportsService(const OUString& rServiceName) throw( uno::RuntimeException ) 278 { 279 const uno::Sequence< OUString > aNames = SwXAutoTextContainer_getSupportedServiceNames(); 280 for(sal_Int32 nService = 0; nService < aNames.getLength(); nService++) 281 { 282 if(aNames.getConstArray()[nService] == rServiceName) 283 return sal_True; 284 } 285 return sal_False; 286 } 287 /* -----------------------------06.04.00 11:11-------------------------------- 288 289 ---------------------------------------------------------------------------*/ 290 uno::Sequence< OUString > SwXAutoTextContainer::getSupportedServiceNames(void) throw( uno::RuntimeException ) 291 { 292 return SwXAutoTextContainer_getSupportedServiceNames(); 293 } 294 /****************************************************************** 295 * 296 ******************************************************************/ 297 /* -----------------------------10.03.00 18:02-------------------------------- 298 299 ---------------------------------------------------------------------------*/ 300 const uno::Sequence< sal_Int8 > & SwXAutoTextGroup::getUnoTunnelId() 301 { 302 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId(); 303 return aSeq; 304 } 305 /* -----------------------------10.03.00 18:04-------------------------------- 306 307 ---------------------------------------------------------------------------*/ 308 sal_Int64 SAL_CALL SwXAutoTextGroup::getSomething( const uno::Sequence< sal_Int8 >& rId ) 309 throw(uno::RuntimeException) 310 { 311 if( rId.getLength() == 16 312 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), 313 rId.getConstArray(), 16 ) ) 314 { 315 return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this )); 316 } 317 return 0; 318 } 319 320 /*-- 21.12.98 12:42:24--------------------------------------------------- 321 322 -----------------------------------------------------------------------*/ 323 SwXAutoTextGroup::SwXAutoTextGroup(const OUString& rName, 324 SwGlossaries* pGlos) : 325 pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_AUTO_TEXT_GROUP)), 326 pGlossaries(pGlos), 327 sName(rName), 328 m_sGroupName(rName) 329 { 330 DBG_ASSERT( -1 != rName.indexOf( GLOS_DELIM ), 331 "SwXAutoTextGroup::SwXAutoTextGroup: to be constructed with a complete name only!" ); 332 } 333 334 /*-- 21.12.98 12:42:24--------------------------------------------------- 335 336 -----------------------------------------------------------------------*/ 337 SwXAutoTextGroup::~SwXAutoTextGroup() 338 { 339 } 340 /*-- 21.12.98 12:42:24--------------------------------------------------- 341 342 -----------------------------------------------------------------------*/ 343 /*-- 21.12.98 12:42:25--------------------------------------------------- 344 345 -----------------------------------------------------------------------*/ 346 uno::Sequence< OUString > SwXAutoTextGroup::getTitles(void) throw( uno::RuntimeException ) 347 { 348 ::vos::OGuard aGuard(Application::GetSolarMutex()); 349 sal_uInt16 nCount = 0; 350 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0; 351 if(pGlosGroup && !pGlosGroup->GetError()) 352 nCount = pGlosGroup->GetCount(); 353 else 354 throw uno::RuntimeException(); 355 356 uno::Sequence< OUString > aEntryTitles(nCount); 357 OUString *pArr = aEntryTitles.getArray(); 358 359 for ( sal_uInt16 i = 0; i < nCount; i++ ) 360 pArr[i] = pGlosGroup->GetLongName(i); 361 delete pGlosGroup; 362 return aEntryTitles; 363 } 364 /*-- 21.12.98 12:42:25--------------------------------------------------- 365 366 -----------------------------------------------------------------------*/ 367 void SwXAutoTextGroup::renameByName(const OUString& aElementName, 368 const OUString& aNewElementName, const OUString& aNewElementTitle) 369 throw( lang::IllegalArgumentException, container::ElementExistException, io::IOException, 370 uno::RuntimeException) 371 { 372 ::vos::OGuard aGuard(Application::GetSolarMutex()); 373 // throw exception only if the programmatic name is to be changed into an existing name 374 if(aNewElementName != aElementName && hasByName(aNewElementName)) 375 throw container::ElementExistException(); 376 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0; 377 if(pGlosGroup && !pGlosGroup->GetError()) 378 { 379 sal_uInt16 nIdx = pGlosGroup->GetIndex( aElementName); 380 if(USHRT_MAX == nIdx) 381 throw lang::IllegalArgumentException(); 382 String aNewShort( aNewElementName); 383 String aNewName( aNewElementTitle); 384 sal_uInt16 nOldLongIdx = pGlosGroup->GetLongIndex( aNewShort ); 385 sal_uInt16 nOldIdx = pGlosGroup->GetIndex( aNewName ); 386 387 if( nIdx != USHRT_MAX && 388 (nOldLongIdx == USHRT_MAX || nOldLongIdx == nIdx )&& 389 (nOldIdx == USHRT_MAX || nOldIdx == nIdx )) 390 { 391 pGlosGroup->Rename( nIdx, &aNewShort, &aNewName ); 392 if(pGlosGroup->GetError() != 0) 393 throw io::IOException(); 394 } 395 delete pGlosGroup; 396 } 397 else 398 throw uno::RuntimeException(); 399 } 400 401 sal_Bool lcl_CopySelToDoc( SwDoc* pInsDoc, OTextCursorHelper* pxCursor, SwXTextRange* pxRange) 402 { 403 ASSERT( pInsDoc, "kein Ins.Dokument" ); 404 405 SwNodes& rNds = pInsDoc->GetNodes(); 406 407 SwNodeIndex aIdx( rNds.GetEndOfContent(), -1 ); 408 SwCntntNode * pNd = aIdx.GetNode().GetCntntNode(); 409 SwPosition aPos( aIdx, SwIndex( pNd, pNd->Len() )); 410 411 bool bRet = false; 412 pInsDoc->LockExpFlds(); 413 { 414 SwDoc *const pDoc((pxCursor) ? pxCursor->GetDoc() : pxRange->GetDoc()); 415 SwPaM aPam(pDoc->GetNodes()); 416 SwPaM * pPam(0); 417 if(pxCursor) 418 { 419 pPam = pxCursor->GetPaM(); 420 } 421 else 422 { 423 if (pxRange->GetPositions(aPam)) 424 { 425 pPam = & aPam; 426 } 427 } 428 if (!pPam) { return false; } 429 bRet = pDoc->CopyRange( *pPam, aPos, false ) || bRet; 430 } 431 432 pInsDoc->UnlockExpFlds(); 433 if( !pInsDoc->IsExpFldsLocked() ) 434 pInsDoc->UpdateExpFlds(NULL, true); 435 436 return bRet; 437 } 438 /*-- 21.12.98 12:42:25--------------------------------------------------- 439 440 -----------------------------------------------------------------------*/ 441 uno::Reference< text::XAutoTextEntry > SwXAutoTextGroup::insertNewByName(const OUString& aName, 442 const OUString& aTitle, const uno::Reference< text::XTextRange > & xTextRange) 443 throw( container::ElementExistException, uno::RuntimeException ) 444 { 445 ::vos::OGuard aGuard(Application::GetSolarMutex()); 446 if(hasByName(aName)) 447 throw container::ElementExistException(); 448 if(!xTextRange.is()) 449 throw uno::RuntimeException(); 450 451 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0; 452 String sShortName(aName); 453 String sLongName(aTitle); 454 if(pGlosGroup && !pGlosGroup->GetError()) 455 { 456 /*if( pGlosGroup->IsOld() && pGlosGroup->ConvertToNew()) 457 { 458 throw uno::RuntimeException(); 459 } */ 460 uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY); 461 SwXTextRange* pxRange = 0; 462 OTextCursorHelper* pxCursor = 0; 463 if(xRangeTunnel.is()) 464 { 465 pxRange = reinterpret_cast<SwXTextRange*>(xRangeTunnel->getSomething( 466 SwXTextRange::getUnoTunnelId())); 467 pxCursor = reinterpret_cast<OTextCursorHelper*>(xRangeTunnel->getSomething( 468 OTextCursorHelper::getUnoTunnelId())); 469 } 470 471 String sOnlyTxt; 472 String* pOnlyTxt = 0; 473 sal_Bool bNoAttr = !pxCursor && !pxRange; 474 if(bNoAttr) 475 { 476 sOnlyTxt = UniString(xTextRange->getString()); 477 pOnlyTxt = &sOnlyTxt; 478 } 479 480 const SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get(); 481 482 SwDoc* pGDoc = pGlosGroup->GetDoc(); 483 484 // Bis es eine Option dafuer gibt, base util::URL loeschen 485 if(pCfg->IsSaveRelFile()) 486 { 487 INetURLObject aTemp(pGlosGroup->GetFileName()); 488 pGlosGroup->SetBaseURL( aTemp.GetMainURL(INetURLObject::NO_DECODE)); 489 } 490 else 491 pGlosGroup->SetBaseURL( aEmptyStr ); 492 493 sal_uInt16 nRet; 494 if( pOnlyTxt ) 495 nRet = pGlosGroup->PutText( sShortName, sLongName, *pOnlyTxt ); 496 else 497 { 498 pGlosGroup->ClearDoc(); 499 if( pGlosGroup->BeginPutDoc( sShortName, sLongName ) ) 500 { 501 pGDoc->SetRedlineMode_intern( nsRedlineMode_t::REDLINE_DELETE_REDLINES ); 502 lcl_CopySelToDoc( pGDoc, pxCursor, pxRange ); 503 pGDoc->SetRedlineMode_intern((RedlineMode_t)( 0 )); 504 nRet = pGlosGroup->PutDoc(); 505 } 506 else 507 nRet = (sal_uInt16) -1; 508 } 509 510 if(nRet == (sal_uInt16) -1 ) 511 { 512 throw uno::RuntimeException(); 513 } 514 pGlossaries->PutGroupDoc( pGlosGroup ); 515 } 516 517 uno::Reference< text::XAutoTextEntry > xEntry = pGlossaries->GetAutoTextEntry( m_sGroupName, sName, sShortName, true ); 518 DBG_ASSERT( xEntry.is(), "SwXAutoTextGroup::insertNewByName: no UNO object created? How this?" ); 519 // we just inserted the entry into the group, so why doesn't it exist? 520 521 return xEntry; 522 } 523 /*-- 21.12.98 12:42:25--------------------------------------------------- 524 525 -----------------------------------------------------------------------*/ 526 void SwXAutoTextGroup::removeByName(const OUString& aEntryName) throw( container::NoSuchElementException, uno::RuntimeException ) 527 { 528 ::vos::OGuard aGuard(Application::GetSolarMutex()); 529 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0; 530 if(pGlosGroup && !pGlosGroup->GetError()) 531 { 532 sal_uInt16 nIdx = pGlosGroup->GetIndex(aEntryName); 533 if ( nIdx != USHRT_MAX ) 534 pGlosGroup->Delete(nIdx); 535 delete pGlosGroup; 536 } 537 else 538 throw container::NoSuchElementException(); 539 } 540 /*-- 21.12.98 12:42:25--------------------------------------------------- 541 542 -----------------------------------------------------------------------*/ 543 OUString SwXAutoTextGroup::getName(void) throw( uno::RuntimeException ) 544 { 545 ::vos::OGuard aGuard(Application::GetSolarMutex()); 546 return sName; 547 } 548 /*-- 21.12.98 12:42:25--------------------------------------------------- 549 550 -----------------------------------------------------------------------*/ 551 void SwXAutoTextGroup::setName(const OUString& rName) throw( uno::RuntimeException ) 552 { 553 ::vos::OGuard aGuard(Application::GetSolarMutex()); 554 if( !pGlossaries ) 555 throw uno::RuntimeException(); 556 557 sal_Int32 nNewDelimPos = rName.lastIndexOf( GLOS_DELIM ); 558 sal_Int32 nOldDelimPos = sName.lastIndexOf( GLOS_DELIM ); 559 560 OUString aNewSuffix; 561 if (nNewDelimPos > -1) 562 aNewSuffix = rName.copy( nNewDelimPos + 1 ); 563 OUString aOldSuffix; 564 if (nOldDelimPos > -1) 565 aOldSuffix = sName.copy( nOldDelimPos + 1 ); 566 567 sal_Int32 nNewNumeric = aNewSuffix.toInt32(); 568 sal_Int32 nOldNumeric = aOldSuffix.toInt32(); 569 570 OUString aNewPrefix( (nNewDelimPos > 1) ? rName.copy( 0, nNewDelimPos ) : rName ); 571 OUString aOldPrefix( (nOldDelimPos > 1) ? sName.copy( 0, nOldDelimPos ) : sName ); 572 573 if ( sName == rName || 574 ( nNewNumeric == nOldNumeric && aNewPrefix == aOldPrefix ) ) 575 return; 576 String sNewGroup(rName); 577 if(STRING_NOTFOUND == sNewGroup.Search(GLOS_DELIM)) 578 { 579 sNewGroup += GLOS_DELIM; 580 sNewGroup += UniString::CreateFromInt32(0); 581 } 582 583 //the name must be saved, the group may be invalidated while in RenameGroupDoc() 584 SwGlossaries* pTempGlossaries = pGlossaries; 585 586 String sPreserveTitle( pGlossaries->GetGroupTitle( sName ) ); 587 if ( !pGlossaries->RenameGroupDoc( sName, sNewGroup, sPreserveTitle ) ) 588 throw uno::RuntimeException(); 589 else 590 { 591 sName = rName; 592 m_sGroupName = sNewGroup; 593 pGlossaries = pTempGlossaries; 594 } 595 } 596 /*-- 21.12.98 12:42:26--------------------------------------------------- 597 598 -----------------------------------------------------------------------*/ 599 sal_Int32 SwXAutoTextGroup::getCount(void) throw( uno::RuntimeException ) 600 { 601 ::vos::OGuard aGuard(Application::GetSolarMutex()); 602 int nCount = 0; 603 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0; 604 if(pGlosGroup && !pGlosGroup->GetError()) 605 nCount = pGlosGroup->GetCount(); 606 else 607 throw uno::RuntimeException(); 608 delete pGlosGroup; 609 return nCount; 610 } 611 /*-- 21.12.98 12:42:26--------------------------------------------------- 612 613 -----------------------------------------------------------------------*/ 614 uno::Any SwXAutoTextGroup::getByIndex(sal_Int32 nIndex) 615 throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException ) 616 { 617 ::vos::OGuard aGuard(Application::GetSolarMutex()); 618 uno::Any aRet; 619 sal_uInt16 nCount = 0; 620 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0; 621 if(pGlosGroup && !pGlosGroup->GetError()) 622 nCount = pGlosGroup->GetCount(); 623 else 624 throw uno::RuntimeException(); 625 if(0 <= nIndex && nIndex < nCount) 626 aRet = getByName(pGlosGroup->GetShortName((sal_uInt16) nIndex)); 627 else 628 throw lang::IndexOutOfBoundsException(); 629 delete pGlosGroup; 630 return aRet; 631 } 632 /*-- 21.12.98 12:42:26--------------------------------------------------- 633 634 -----------------------------------------------------------------------*/ 635 uno::Type SwXAutoTextGroup::getElementType(void) throw( uno::RuntimeException ) 636 { 637 return ::getCppuType((uno::Reference<text::XAutoTextEntry>*)0); 638 639 } 640 /*-- 21.12.98 12:42:26--------------------------------------------------- 641 642 -----------------------------------------------------------------------*/ 643 sal_Bool SwXAutoTextGroup::hasElements(void) throw( uno::RuntimeException ) 644 { 645 ::vos::OGuard aGuard(Application::GetSolarMutex()); 646 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0; 647 sal_uInt16 nCount = 0; 648 if(pGlosGroup && !pGlosGroup->GetError()) 649 nCount = pGlosGroup->GetCount(); 650 else 651 throw uno::RuntimeException(); 652 delete pGlosGroup; 653 return nCount > 0; 654 655 } 656 /*-- 21.12.98 12:42:27--------------------------------------------------- 657 658 -----------------------------------------------------------------------*/ 659 uno::Any SwXAutoTextGroup::getByName(const OUString& _rName) 660 throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException ) 661 { 662 ::vos::OGuard aGuard(Application::GetSolarMutex()); 663 uno::Reference< text::XAutoTextEntry > xEntry = pGlossaries->GetAutoTextEntry( m_sGroupName, sName, _rName, true ); 664 DBG_ASSERT( xEntry.is(), "SwXAutoTextGroup::getByName: GetAutoTextEntry is fractious!" ); 665 // we told it to create the object, so why didn't it? 666 return makeAny( xEntry ); 667 } 668 /*-- 21.12.98 12:42:27--------------------------------------------------- 669 670 -----------------------------------------------------------------------*/ 671 uno::Sequence< OUString > SwXAutoTextGroup::getElementNames(void) 672 throw( uno::RuntimeException ) 673 { 674 ::vos::OGuard aGuard(Application::GetSolarMutex()); 675 sal_uInt16 nCount = 0; 676 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0; 677 if(pGlosGroup && !pGlosGroup->GetError()) 678 nCount = pGlosGroup->GetCount(); 679 else 680 throw uno::RuntimeException(); 681 682 uno::Sequence< OUString > aEntryNames(nCount); 683 OUString *pArr = aEntryNames.getArray(); 684 685 for ( sal_uInt16 i = 0; i < nCount; i++ ) 686 pArr[i] = pGlosGroup->GetShortName(i); 687 delete pGlosGroup; 688 return aEntryNames; 689 } 690 /*-- 21.12.98 12:42:27--------------------------------------------------- 691 692 -----------------------------------------------------------------------*/ 693 sal_Bool SwXAutoTextGroup::hasByName(const OUString& rName) 694 throw( uno::RuntimeException ) 695 { 696 ::vos::OGuard aGuard(Application::GetSolarMutex()); 697 sal_Bool bRet = sal_False; 698 sal_uInt16 nCount = 0; 699 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0; 700 if(pGlosGroup && !pGlosGroup->GetError()) 701 nCount = pGlosGroup->GetCount(); 702 else 703 throw uno::RuntimeException(); 704 705 for( sal_uInt16 i = 0; i < nCount; i++ ) 706 { 707 String sCompare(pGlosGroup->GetShortName(i)); 708 if(COMPARE_EQUAL == sCompare.CompareIgnoreCaseToAscii(String(rName))) 709 { 710 bRet = sal_True; 711 break; 712 } 713 } 714 delete pGlosGroup; 715 return bRet; 716 } 717 718 /*-- 09.02.00 15:33:30--------------------------------------------------- 719 720 -----------------------------------------------------------------------*/ 721 uno::Reference< beans::XPropertySetInfo > SwXAutoTextGroup::getPropertySetInfo(void) 722 throw( uno::RuntimeException ) 723 { 724 static uno::Reference< beans::XPropertySetInfo > xRet = pPropSet->getPropertySetInfo(); 725 return xRet; 726 } 727 /*-- 09.02.00 15:33:31--------------------------------------------------- 728 729 -----------------------------------------------------------------------*/ 730 void SwXAutoTextGroup::setPropertyValue( 731 const OUString& rPropertyName, const uno::Any& aValue) 732 throw( beans::UnknownPropertyException, beans::PropertyVetoException, 733 lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException) 734 { 735 ::vos::OGuard aGuard(Application::GetSolarMutex()); 736 const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap()->getByName( rPropertyName ); 737 738 if(!pEntry) 739 throw beans::UnknownPropertyException(); 740 741 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0; 742 if(!pGlosGroup || pGlosGroup->GetError()) 743 throw uno::RuntimeException(); 744 switch(pEntry->nWID) 745 { 746 case WID_GROUP_TITLE: 747 { 748 OUString sNewTitle; 749 aValue >>= sNewTitle; 750 if(!sNewTitle.getLength()) 751 throw lang::IllegalArgumentException(); 752 sal_Bool bChanged = !sNewTitle.equals(pGlosGroup->GetName()); 753 pGlosGroup->SetName(sNewTitle); 754 if(bChanged && HasGlossaryList()) 755 GetGlossaryList()->ClearGroups(); 756 } 757 break; 758 } 759 delete pGlosGroup; 760 } 761 /*-- 09.02.00 15:33:31--------------------------------------------------- 762 763 -----------------------------------------------------------------------*/ 764 uno::Any SwXAutoTextGroup::getPropertyValue(const OUString& rPropertyName) 765 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException ) 766 { 767 ::vos::OGuard aGuard(Application::GetSolarMutex()); 768 const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap()->getByName( rPropertyName); 769 770 if(!pEntry) 771 throw beans::UnknownPropertyException(); 772 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0; 773 if(!pGlosGroup || pGlosGroup->GetError()) 774 throw uno::RuntimeException(); 775 776 uno::Any aAny; 777 switch(pEntry->nWID) 778 { 779 case WID_GROUP_PATH: 780 aAny <<= OUString(pGlosGroup->GetFileName()); 781 break; 782 case WID_GROUP_TITLE: 783 aAny <<= OUString(pGlosGroup->GetName()); 784 break; 785 } 786 delete pGlosGroup; 787 return aAny; 788 } 789 /*-- 09.02.00 15:33:31--------------------------------------------------- 790 791 -----------------------------------------------------------------------*/ 792 void SwXAutoTextGroup::addPropertyChangeListener( 793 const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) 794 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException ) 795 { 796 } 797 /*-- 09.02.00 15:33:31--------------------------------------------------- 798 799 -----------------------------------------------------------------------*/ 800 void SwXAutoTextGroup::removePropertyChangeListener( 801 const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) 802 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException ) 803 { 804 } 805 /*-- 09.02.00 15:33:32--------------------------------------------------- 806 807 -----------------------------------------------------------------------*/ 808 void SwXAutoTextGroup::addVetoableChangeListener( 809 const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) 810 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException ) 811 { 812 } 813 /*-- 09.02.00 15:33:32--------------------------------------------------- 814 815 -----------------------------------------------------------------------*/ 816 void SwXAutoTextGroup::removeVetoableChangeListener( 817 const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) 818 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException ) 819 { 820 } 821 /*-- 21.12.98 12:42:27--------------------------------------------------- 822 823 -----------------------------------------------------------------------*/ 824 void SwXAutoTextGroup::Invalidate() 825 { 826 pGlossaries = 0; 827 sName = aEmptyStr; 828 m_sGroupName = aEmptyStr; 829 } 830 /* -----------------------------06.04.00 11:11-------------------------------- 831 832 ---------------------------------------------------------------------------*/ 833 OUString SwXAutoTextGroup::getImplementationName(void) throw( uno::RuntimeException ) 834 { 835 return C2U("SwXAutoTextGroup"); 836 } 837 /* -----------------------------06.04.00 11:11-------------------------------- 838 839 ---------------------------------------------------------------------------*/ 840 sal_Bool SwXAutoTextGroup::supportsService(const OUString& rServiceName) throw( uno::RuntimeException ) 841 { 842 return C2U("com.sun.star.text.AutoTextGroup") == rServiceName; 843 } 844 /* -----------------------------06.04.00 11:11-------------------------------- 845 846 ---------------------------------------------------------------------------*/ 847 uno::Sequence< OUString > SwXAutoTextGroup::getSupportedServiceNames(void) throw( uno::RuntimeException ) 848 { 849 uno::Sequence< OUString > aRet(1); 850 OUString* pArray = aRet.getArray(); 851 pArray[0] = C2U("com.sun.star.text.AutoTextGroup"); 852 return aRet; 853 } 854 /****************************************************************** 855 * 856 ******************************************************************/ 857 /* -----------------------------10.03.00 18:02-------------------------------- 858 859 ---------------------------------------------------------------------------*/ 860 const uno::Sequence< sal_Int8 > & SwXAutoTextEntry::getUnoTunnelId() 861 { 862 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId(); 863 return aSeq; 864 } 865 /* -----------------------------10.03.00 18:04-------------------------------- 866 867 ---------------------------------------------------------------------------*/ 868 sal_Int64 SAL_CALL SwXAutoTextEntry::getSomething( const uno::Sequence< sal_Int8 >& rId ) 869 throw(uno::RuntimeException) 870 { 871 if( rId.getLength() == 16 872 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), 873 rId.getConstArray(), 16 ) ) 874 { 875 return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this )); 876 } 877 return 0; 878 } 879 /*-- 21.12.98 12:42:33--------------------------------------------------- 880 881 -----------------------------------------------------------------------*/ 882 SwXAutoTextEntry::SwXAutoTextEntry(SwGlossaries* pGlss, const String& rGroupName, 883 const String& rEntryName) : 884 pGlossaries(pGlss), 885 sGroupName(rGroupName), 886 sEntryName(rEntryName), 887 pBodyText ( NULL ) 888 { 889 } 890 /*-- 21.12.98 12:42:33--------------------------------------------------- 891 892 -----------------------------------------------------------------------*/ 893 SwXAutoTextEntry::~SwXAutoTextEntry() 894 { 895 { 896 ::vos::OGuard aGuard(Application::GetSolarMutex()); 897 898 // ensure that any pending modifications are written 899 implFlushDocument( true ); 900 901 //! Bug #96559 902 // DocShell must be cleared before mutex is lost. 903 // Needs to be done explicitly since xDocSh is a class member. 904 // Thus, an own block here, guarded by the SolarMutex 905 } 906 } 907 908 //--------------------------------------------------------------------- 909 //--- 03.03.2003 13:24:58 ----------------------------------------------- 910 911 void SwXAutoTextEntry::implFlushDocument( bool _bCloseDoc ) 912 { 913 if ( xDocSh.Is() ) 914 { 915 if ( xDocSh->GetDoc()->IsModified () ) 916 xDocSh->Save(); 917 918 if ( _bCloseDoc ) 919 { 920 // stop listening at the document 921 EndListening( *&xDocSh ); 922 923 xDocSh->DoClose(); 924 xDocSh.Clear(); 925 } 926 } 927 } 928 929 //----------------------------------------------------------------------- 930 //--- 03.03.2003 15:51:52 ----------------------------------------------- 931 932 void SwXAutoTextEntry::Notify( SfxBroadcaster& _rBC, const SfxHint& _rHint ) 933 { 934 if ( &_rBC == &xDocSh ) 935 { // it's our document 936 if ( _rHint.ISA( SfxSimpleHint ) ) 937 { 938 if ( SFX_HINT_DEINITIALIZING == static_cast< const SfxSimpleHint& >( _rHint ).GetId() ) 939 { 940 // our document is dying (possibly because we're shuting down, and the document was notified 941 // earlier than we are?) 942 // stop listening at the docu 943 EndListening( *&xDocSh ); 944 // and release our reference 945 xDocSh.Clear(); 946 } 947 } 948 else if(_rHint.ISA(SfxEventHint)) 949 { 950 if(SFX_EVENT_PREPARECLOSEDOC == static_cast< const SfxEventHint& >( _rHint ).GetEventId()) 951 { 952 implFlushDocument( sal_False ); 953 xBodyText = 0; 954 xDocSh.Clear(); 955 } 956 } 957 } 958 } 959 960 void SwXAutoTextEntry::GetBodyText () 961 { 962 ::vos::OGuard aGuard(Application::GetSolarMutex()); 963 964 xDocSh = pGlossaries->EditGroupDoc ( sGroupName, sEntryName, sal_False ); 965 DBG_ASSERT( xDocSh.Is(), "SwXAutoTextEntry::GetBodyText: unexpected: no doc returned by EditGroupDoc!" ); 966 967 // start listening at the document 968 StartListening( *&xDocSh ); 969 970 pBodyText = new SwXBodyText ( xDocSh->GetDoc() ); 971 xBodyText = uno::Reference < lang::XServiceInfo > ( *pBodyText, uno::UNO_QUERY); 972 } 973 974 uno::Reference< text::XTextCursor > SwXAutoTextEntry::createTextCursor(void) throw( uno::RuntimeException ) 975 { 976 ::vos::OGuard aGuard(Application::GetSolarMutex()); 977 EnsureBodyText(); 978 return pBodyText->createTextCursor(); 979 } 980 /*-- 21.12.98 12:42:34--------------------------------------------------- 981 982 -----------------------------------------------------------------------*/ 983 uno::Reference< text::XTextCursor > SwXAutoTextEntry::createTextCursorByRange( 984 const uno::Reference< text::XTextRange > & aTextPosition) throw( uno::RuntimeException ) 985 { 986 ::vos::OGuard aGuard(Application::GetSolarMutex()); 987 EnsureBodyText(); 988 return pBodyText->createTextCursorByRange ( aTextPosition ); 989 } 990 /*-- 21.12.98 12:42:34--------------------------------------------------- 991 992 -----------------------------------------------------------------------*/ 993 void SwXAutoTextEntry::insertString(const uno::Reference< text::XTextRange > & xRange, const OUString& aString, sal_Bool bAbsorb) throw( uno::RuntimeException ) 994 { 995 ::vos::OGuard aGuard(Application::GetSolarMutex()); 996 EnsureBodyText(); 997 pBodyText->insertString ( xRange, aString, bAbsorb ); 998 } 999 /*-- 21.12.98 12:42:34--------------------------------------------------- 1000 1001 -----------------------------------------------------------------------*/ 1002 void SwXAutoTextEntry::insertControlCharacter(const uno::Reference< text::XTextRange > & xRange, 1003 sal_Int16 nControlCharacter, sal_Bool bAbsorb) 1004 throw( lang::IllegalArgumentException, uno::RuntimeException ) 1005 { 1006 ::vos::OGuard aGuard(Application::GetSolarMutex()); 1007 EnsureBodyText(); 1008 pBodyText->insertControlCharacter ( xRange, nControlCharacter, bAbsorb ); 1009 } 1010 /*-- 21.12.98 12:42:34--------------------------------------------------- 1011 1012 -----------------------------------------------------------------------*/ 1013 void SwXAutoTextEntry::insertTextContent( 1014 const uno::Reference< text::XTextRange > & xRange, 1015 const uno::Reference< text::XTextContent > & xContent, sal_Bool bAbsorb) 1016 throw( lang::IllegalArgumentException, uno::RuntimeException ) 1017 { 1018 ::vos::OGuard aGuard(Application::GetSolarMutex()); 1019 EnsureBodyText(); 1020 pBodyText->insertTextContent ( xRange, xContent, bAbsorb ); 1021 } 1022 /*-- 21.12.98 12:42:34--------------------------------------------------- 1023 1024 -----------------------------------------------------------------------*/ 1025 void SwXAutoTextEntry::removeTextContent( 1026 const uno::Reference< text::XTextContent > & xContent) 1027 throw( container::NoSuchElementException, uno::RuntimeException ) 1028 { 1029 ::vos::OGuard aGuard(Application::GetSolarMutex()); 1030 EnsureBodyText(); 1031 pBodyText->removeTextContent ( xContent ); 1032 } 1033 /*-- 21.12.98 12:42:35--------------------------------------------------- 1034 1035 -----------------------------------------------------------------------*/ 1036 uno::Reference< text::XText > SwXAutoTextEntry::getText(void) throw( uno::RuntimeException ) 1037 { 1038 ::vos::OGuard aGuard(Application::GetSolarMutex()); 1039 uno::Reference< text::XText > xRet = (text::XText*)this; 1040 return xRet; 1041 } 1042 /*-- 21.12.98 12:42:35--------------------------------------------------- 1043 1044 -----------------------------------------------------------------------*/ 1045 uno::Reference< text::XTextRange > SwXAutoTextEntry::getStart(void) throw( uno::RuntimeException ) 1046 { 1047 ::vos::OGuard aGuard(Application::GetSolarMutex()); 1048 EnsureBodyText(); 1049 return pBodyText->getStart(); 1050 } 1051 /*-- 21.12.98 12:42:36--------------------------------------------------- 1052 1053 -----------------------------------------------------------------------*/ 1054 uno::Reference< text::XTextRange > SwXAutoTextEntry::getEnd(void) throw( uno::RuntimeException ) 1055 { 1056 ::vos::OGuard aGuard(Application::GetSolarMutex()); 1057 EnsureBodyText(); 1058 return pBodyText->getEnd(); 1059 } 1060 /*-- 21.12.98 12:42:36--------------------------------------------------- 1061 1062 -----------------------------------------------------------------------*/ 1063 OUString SwXAutoTextEntry::getString(void) throw( uno::RuntimeException ) 1064 { 1065 ::vos::OGuard aGuard(Application::GetSolarMutex()); 1066 EnsureBodyText(); 1067 return pBodyText->getString(); 1068 } 1069 /*-- 21.12.98 12:42:36--------------------------------------------------- 1070 1071 -----------------------------------------------------------------------*/ 1072 void SwXAutoTextEntry::setString(const OUString& aString) throw( uno::RuntimeException ) 1073 { 1074 ::vos::OGuard aGuard(Application::GetSolarMutex()); 1075 EnsureBodyText(); 1076 pBodyText->setString( aString ); 1077 } 1078 /* -----------------15.07.99 10:11------------------- 1079 1080 --------------------------------------------------*/ 1081 void SwXAutoTextEntry::applyTo(const uno::Reference< text::XTextRange > & xTextRange)throw( uno::RuntimeException ) 1082 { 1083 ::vos::OGuard aGuard(Application::GetSolarMutex()); 1084 1085 // ensure that any pending modifications are written 1086 // reason is that we're holding the _copy_ of the auto text, while the real auto text 1087 // is stored somewhere. And below, we're not working with our copy, but only tell the target 1088 // TextRange to work with the stored version. 1089 // #96380# - 2003-03-03 - fs@openoffice.org 1090 implFlushDocument( false ); 1091 // TODO: think about if we should pass "true" here 1092 // The difference would be that when the next modification is made to this instance here, then 1093 // we would be forced to open the document again, instead of working on our current copy. 1094 // This means that we would reflect any changes which were done to the AutoText by foreign instances 1095 // in the meantime 1096 1097 uno::Reference<lang::XUnoTunnel> xTunnel( xTextRange, uno::UNO_QUERY); 1098 SwXTextRange* pRange = 0; 1099 OTextCursorHelper* pCursor = 0; 1100 SwXText *pText = 0; 1101 1102 if(xTunnel.is()) 1103 { 1104 pRange = reinterpret_cast < SwXTextRange* > 1105 ( xTunnel->getSomething( SwXTextRange::getUnoTunnelId() ) ); 1106 pCursor = reinterpret_cast < OTextCursorHelper*> 1107 ( xTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() ) ); 1108 pText = reinterpret_cast < SwXText* > 1109 ( xTunnel->getSomething( SwXText::getUnoTunnelId() ) ); 1110 } 1111 1112 SwDoc* pDoc = 0; 1113 if (pRange) 1114 pDoc = pRange->GetDoc(); 1115 else if ( pCursor ) 1116 pDoc = pCursor->GetDoc(); 1117 else if ( pText && pText->GetDoc() ) 1118 { 1119 xTunnel = uno::Reference < lang::XUnoTunnel > (pText->getStart(), uno::UNO_QUERY); 1120 if (xTunnel.is()) 1121 { 1122 pCursor = reinterpret_cast < OTextCursorHelper* > 1123 ( xTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() ) ); 1124 if (pCursor) 1125 pDoc = pText->GetDoc(); 1126 } 1127 } 1128 1129 if(!pDoc) 1130 throw uno::RuntimeException(); 1131 1132 SwPaM InsertPaM(pDoc->GetNodes()); 1133 if (pRange) 1134 { 1135 if (!pRange->GetPositions(InsertPaM)) 1136 { 1137 throw uno::RuntimeException(); 1138 } 1139 } 1140 else 1141 { 1142 InsertPaM = *pCursor->GetPaM(); 1143 } 1144 1145 ::std::auto_ptr<SwTextBlocks> pBlock(pGlossaries->GetGroupDoc(sGroupName)); 1146 const bool bResult = pBlock.get() && !pBlock->GetError() 1147 && pDoc->InsertGlossary( *pBlock, sEntryName, InsertPaM); 1148 1149 if(!bResult) 1150 throw uno::RuntimeException(); 1151 } 1152 /* -----------------------------06.04.00 11:11-------------------------------- 1153 1154 ---------------------------------------------------------------------------*/ 1155 OUString SwXAutoTextEntry::getImplementationName(void) throw( uno::RuntimeException ) 1156 { 1157 return C2U("SwXAutoTextEntry"); 1158 } 1159 /* -----------------------------06.04.00 11:11-------------------------------- 1160 1161 ---------------------------------------------------------------------------*/ 1162 sal_Bool SwXAutoTextEntry::supportsService(const OUString& rServiceName) throw( uno::RuntimeException ) 1163 { 1164 return C2U("com.sun.star.text.AutoTextEntry") == rServiceName; 1165 } 1166 /* -----------------------------06.04.00 11:11-------------------------------- 1167 1168 ---------------------------------------------------------------------------*/ 1169 uno::Sequence< OUString > SwXAutoTextEntry::getSupportedServiceNames(void) throw( uno::RuntimeException ) 1170 { 1171 uno::Sequence< OUString > aRet(1); 1172 OUString* pArray = aRet.getArray(); 1173 pArray[0] = C2U("com.sun.star.text.AutoTextEntry"); 1174 return aRet; 1175 } 1176 /* -----------------------------06.04.00 11:11-------------------------------- 1177 1178 ---------------------------------------------------------------------------*/ 1179 uno::Reference< container::XNameReplace > SwXAutoTextEntry::getEvents() 1180 throw( uno::RuntimeException ) 1181 { 1182 return new SwAutoTextEventDescriptor( *this ); 1183 } 1184 /* -----------------------------30.01.01 18:40-------------------------------- 1185 1186 ---------------------------------------------------------------------------*/ 1187 const struct SvEventDescription aAutotextEvents[] = 1188 { 1189 { SW_EVENT_START_INS_GLOSSARY, "OnInsertStart" }, 1190 { SW_EVENT_END_INS_GLOSSARY, "OnInsertDone" }, 1191 { 0, NULL } 1192 }; 1193 1194 /* -----------------------------30.01.01 18:40-------------------------------- 1195 1196 ---------------------------------------------------------------------------*/ 1197 SwAutoTextEventDescriptor::SwAutoTextEventDescriptor( 1198 SwXAutoTextEntry& rAutoText ) : 1199 SvBaseEventDescriptor(aAutotextEvents), 1200 sSwAutoTextEventDescriptor(RTL_CONSTASCII_USTRINGPARAM( 1201 "SwAutoTextEventDescriptor")), 1202 rAutoTextEntry(rAutoText) 1203 { 1204 } 1205 /* -----------------------------30.01.01 18:40-------------------------------- 1206 1207 ---------------------------------------------------------------------------*/ 1208 SwAutoTextEventDescriptor::~SwAutoTextEventDescriptor() 1209 { 1210 } 1211 /* -----------------------------30.01.01 18:40-------------------------------- 1212 1213 ---------------------------------------------------------------------------*/ 1214 OUString SwAutoTextEventDescriptor::getImplementationName() 1215 throw( uno::RuntimeException ) 1216 { 1217 return sSwAutoTextEventDescriptor; 1218 } 1219 /* -----------------------------30.01.01 18:40-------------------------------- 1220 1221 ---------------------------------------------------------------------------*/ 1222 void SwAutoTextEventDescriptor::replaceByName( 1223 const sal_uInt16 nEvent, 1224 const SvxMacro& rMacro) 1225 throw( 1226 lang::IllegalArgumentException, 1227 container::NoSuchElementException, 1228 lang::WrappedTargetException, 1229 uno::RuntimeException) 1230 { 1231 DBG_ASSERT( NULL != rAutoTextEntry.GetGlossaries(), 1232 "Strangely enough, the AutoText vanished!" ); 1233 DBG_ASSERT( (nEvent == SW_EVENT_END_INS_GLOSSARY) || 1234 (nEvent == SW_EVENT_START_INS_GLOSSARY) , 1235 "Unknown event ID" ); 1236 1237 const SwGlossaries* pGlossaries = rAutoTextEntry.GetGlossaries(); 1238 SwTextBlocks* pBlocks = 1239 pGlossaries->GetGroupDoc( rAutoTextEntry.GetGroupName() ); 1240 DBG_ASSERT( NULL != pBlocks, 1241 "can't get autotext group; SwAutoTextEntry has illegal name?"); 1242 1243 if( pBlocks && !pBlocks->GetError()) 1244 { 1245 sal_uInt16 nIndex = pBlocks->GetIndex( rAutoTextEntry.GetEntryName() ); 1246 if( nIndex != USHRT_MAX ) 1247 { 1248 SvxMacroTableDtor aMacroTable; 1249 if( pBlocks->GetMacroTable( nIndex, aMacroTable ) ) 1250 { 1251 SvxMacro* pNewMacro = new SvxMacro(rMacro); 1252 aMacroTable.Replace( nEvent, pNewMacro ); 1253 pBlocks->SetMacroTable( nIndex, aMacroTable ); 1254 } 1255 } 1256 1257 delete pBlocks; 1258 } 1259 // else: ignore 1260 } 1261 /* -----------------------------30.01.01 18:40-------------------------------- 1262 1263 ---------------------------------------------------------------------------*/ 1264 void SwAutoTextEventDescriptor::getByName( 1265 SvxMacro& rMacro, 1266 const sal_uInt16 nEvent ) 1267 throw( 1268 container::NoSuchElementException, 1269 lang::WrappedTargetException, 1270 uno::RuntimeException) 1271 { 1272 DBG_ASSERT( NULL != rAutoTextEntry.GetGlossaries(), "no AutoText" ); 1273 DBG_ASSERT( (nEvent == SW_EVENT_END_INS_GLOSSARY) || 1274 (nEvent == SW_EVENT_START_INS_GLOSSARY) , 1275 "Unknown event ID" ); 1276 1277 const SwGlossaries* pGlossaries = rAutoTextEntry.GetGlossaries(); 1278 SwTextBlocks* pBlocks = 1279 pGlossaries->GetGroupDoc( rAutoTextEntry.GetGroupName() ); 1280 DBG_ASSERT( NULL != pBlocks, 1281 "can't get autotext group; SwAutoTextEntry has illegal name?"); 1282 1283 // return empty macro, unless macro is found 1284 OUString sEmptyStr; 1285 SvxMacro aEmptyMacro(sEmptyStr, sEmptyStr); 1286 rMacro = aEmptyMacro; 1287 1288 if ( pBlocks && !pBlocks->GetError()) 1289 { 1290 sal_uInt16 nIndex = pBlocks->GetIndex( rAutoTextEntry.GetEntryName() ); 1291 if( nIndex != USHRT_MAX ) 1292 { 1293 SvxMacroTableDtor aMacroTable; 1294 if( pBlocks->GetMacroTable( nIndex, aMacroTable ) ) 1295 { 1296 SvxMacro *pMacro = aMacroTable.Get( nEvent ); 1297 if( pMacro ) 1298 rMacro = *pMacro; 1299 } 1300 } 1301 1302 delete pBlocks; 1303 } 1304 } 1305 1306 1307 1308 1309