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