LCOV - code coverage report
Current view: top level - sw/source/core/uibase/uno - unoatxt.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 355 550 64.5 %
Date: 2014-04-11 Functions: 52 78 66.7 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10