merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / uno / unoatxt.cxx
blob4801259cd77faf870906a79aaeafbd972080dbfa
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unoatxt.cxx,v $
10 * $Revision: 1.42 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #define _SVSTDARR_STRINGS
38 #ifndef _COM_SUN_STAR_BEANS_PropertyAttribute_HPP_
39 #include <com/sun/star/beans/PropertyAttribute.hpp>
40 #endif
41 #include <vos/mutex.hxx>
42 #include <tools/debug.hxx>
43 #include <vcl/svapp.hxx>
44 #include <svtools/svstdarr.hxx>
45 #include <svtools/unoevent.hxx>
46 #include <svtools/urihelper.hxx>
47 #include <sfx2/event.hxx>
48 #include <swtypes.hxx>
49 #include <glosdoc.hxx>
50 #include <shellio.hxx>
51 #include <initui.hxx>
52 #include <gloslst.hxx>
53 #include <unoatxt.hxx>
54 #include <unomap.hxx>
55 #include <unoobj.hxx>
56 #include <swevent.hxx>
57 #include <doc.hxx>
58 #include <unocrsr.hxx>
59 #include <IMark.hxx>
60 #include <unoprnms.hxx>
61 #include <docsh.hxx>
62 #include <swunodef.hxx>
63 #include <swmodule.hxx>
64 #include <svtools/smplhint.hxx>
65 #include <svtools/macitem.hxx>
67 #include <svx/acorrcfg.hxx>
69 #include <memory>
71 SV_IMPL_REF ( SwDocShell )
72 using namespace ::com::sun::star;
73 using ::rtl::OUString;
75 /******************************************************************
77 ******************************************************************/
78 /* -----------------30.03.99 14:31-------------------
80 * --------------------------------------------------*/
81 uno::Reference< uno::XInterface > SAL_CALL SwXAutoTextContainer_createInstance(
82 const uno::Reference< lang::XMultiServiceFactory > & ) throw( uno::Exception )
84 //the module may not be loaded
85 ::vos::OGuard aGuard(Application::GetSolarMutex());
86 SwDLL::Init();
87 static uno::Reference< uno::XInterface > xAText = (cppu::OWeakObject*)new SwXAutoTextContainer();;
88 return xAText;
90 /* -----------------------------17.04.01 13:17--------------------------------
92 ---------------------------------------------------------------------------*/
93 uno::Sequence< OUString > SAL_CALL SwXAutoTextContainer_getSupportedServiceNames() throw()
95 OUString sService( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.AutoTextContainer"));
96 const uno::Sequence< OUString > aSeq( &sService, 1 );
97 return aSeq;
99 /* -----------------------------17.04.01 13:18--------------------------------
101 ---------------------------------------------------------------------------*/
102 OUString SAL_CALL SwXAutoTextContainer_getImplementationName() throw()
104 return OUString( RTL_CONSTASCII_USTRINGPARAM("SwXAutoTextContainer" ) );
107 /*-- 21.12.98 12:42:16---------------------------------------------------
109 -----------------------------------------------------------------------*/
110 SwXAutoTextContainer::SwXAutoTextContainer()
112 pGlossaries = ::GetGlossaries();
115 /*-- 21.12.98 12:42:17---------------------------------------------------
117 -----------------------------------------------------------------------*/
118 SwXAutoTextContainer::~SwXAutoTextContainer()
122 /*-- 21.12.98 12:42:17---------------------------------------------------
124 -----------------------------------------------------------------------*/
125 sal_Int32 SwXAutoTextContainer::getCount(void) throw( uno::RuntimeException )
127 return pGlossaries->GetGroupCnt();
129 /*-- 21.12.98 12:42:18---------------------------------------------------
131 -----------------------------------------------------------------------*/
132 uno::Any SwXAutoTextContainer::getByIndex(sal_Int32 nIndex)
133 throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException )
135 ::vos::OGuard aGuard(Application::GetSolarMutex());
136 uno::Any aRet;
137 sal_uInt16 nCount = pGlossaries->GetGroupCnt();
138 if ( 0 <= nIndex && nIndex < nCount )
139 aRet = getByName(pGlossaries->GetGroupName( static_cast< USHORT >(nIndex) ));
140 else
141 throw lang::IndexOutOfBoundsException();
142 return aRet;
144 /*-- 21.12.98 12:42:18---------------------------------------------------
146 -----------------------------------------------------------------------*/
147 uno::Type SwXAutoTextContainer::getElementType(void) throw( uno::RuntimeException )
149 return ::getCppuType((const uno::Reference<text::XAutoTextGroup>*)0);
152 /*-- 21.12.98 12:42:18---------------------------------------------------
154 -----------------------------------------------------------------------*/
155 sal_Bool SwXAutoTextContainer::hasElements(void) throw( uno::RuntimeException )
157 //zumindest Standard sollte es immer geben!
158 return sal_True;
160 /*-- 21.12.98 12:42:18---------------------------------------------------
162 -----------------------------------------------------------------------*/
163 uno::Any SwXAutoTextContainer::getByName(const OUString& GroupName)
164 throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
166 ::vos::OGuard aGuard(Application::GetSolarMutex());
168 uno::Reference< text::XAutoTextGroup > xGroup;
169 if ( pGlossaries && hasByName( GroupName ) ) // group name already known?
170 // TRUE = create group if not already available
171 xGroup = pGlossaries->GetAutoTextGroup( GroupName, TRUE );
173 if ( !xGroup.is() )
174 throw container::NoSuchElementException();
176 return makeAny( xGroup );
178 /*-- 21.12.98 12:42:19---------------------------------------------------
180 -----------------------------------------------------------------------*/
181 uno::Sequence< OUString > SwXAutoTextContainer::getElementNames(void) throw( uno::RuntimeException )
183 ::vos::OGuard aGuard(Application::GetSolarMutex());
184 sal_uInt16 nCount = pGlossaries->GetGroupCnt();
186 uno::Sequence< OUString > aGroupNames(nCount);
187 OUString *pArr = aGroupNames.getArray();
189 for ( sal_uInt16 i = 0; i < nCount; i++ )
191 // Die Namen werden ohne Pfad-Extension weitergegeben
192 String sGroupName(pGlossaries->GetGroupName(i));
193 pArr[i] = sGroupName.GetToken(0, GLOS_DELIM);
195 return aGroupNames;
197 /*-- 21.12.98 12:42:19---------------------------------------------------
198 findet Gruppennamen mit und ohne Pfadindex
199 -----------------------------------------------------------------------*/
200 sal_Bool SwXAutoTextContainer::hasByName(const OUString& Name)
201 throw( uno::RuntimeException )
203 ::vos::OGuard aGuard(Application::GetSolarMutex());
204 String sGroupName( pGlossaries->GetCompleteGroupName( Name ) );
205 if(sGroupName.Len())
206 return sal_True;
207 return sal_False;
209 /*-- 21.12.98 12:42:19---------------------------------------------------
211 -----------------------------------------------------------------------*/
212 uno::Reference< text::XAutoTextGroup > SwXAutoTextContainer::insertNewByName(
213 const OUString& aGroupName)
214 throw( lang::IllegalArgumentException, container::ElementExistException, uno::RuntimeException )
216 ::vos::OGuard aGuard(Application::GetSolarMutex());
217 if(hasByName(aGroupName))
218 throw container::ElementExistException();
219 //check for non-ASCII characters
220 if(!aGroupName.getLength())
222 lang::IllegalArgumentException aIllegal;
223 aIllegal.Message = C2U("group name must not be empty");
224 throw aIllegal;
226 for(sal_Int32 nPos = 0; nPos < aGroupName.getLength(); nPos++)
228 sal_Unicode cChar = aGroupName[nPos];
229 if( ((cChar >= 'A') && (cChar <= 'Z')) ||
230 ((cChar >= 'a') && (cChar <= 'z')) ||
231 ((cChar >= '0') && (cChar <= '9')) ||
232 (cChar == '_') ||
233 (cChar == 0x20) ||
234 (cChar == GLOS_DELIM) )
236 continue;
238 lang::IllegalArgumentException aIllegal;
239 aIllegal.Message = C2U("group name must contain a-z, A-z, '_', ' ' only");
240 throw aIllegal;
242 String sGroup(aGroupName);
243 if(STRING_NOTFOUND == sGroup.Search(GLOS_DELIM))
245 sGroup += GLOS_DELIM;
246 sGroup += UniString::CreateFromInt32(0);
248 pGlossaries->NewGroupDoc(sGroup, sGroup.GetToken(0, GLOS_DELIM));
250 uno::Reference< text::XAutoTextGroup > xGroup = pGlossaries->GetAutoTextGroup( sGroup, true );
251 DBG_ASSERT( xGroup.is(), "SwXAutoTextContainer::insertNewByName: no UNO object created? How this?" );
252 // we just inserted the group into the glossaries, so why doesn't it exist?
254 return xGroup;
256 /*-- 21.12.98 12:42:19---------------------------------------------------
258 -----------------------------------------------------------------------*/
259 void SwXAutoTextContainer::removeByName(const OUString& aGroupName)
260 throw( container::NoSuchElementException, uno::RuntimeException )
262 ::vos::OGuard aGuard(Application::GetSolarMutex());
263 //zunaechst den Namen mit Pfad-Extension finden
264 String sGroupName = pGlossaries->GetCompleteGroupName( aGroupName );
265 if(!sGroupName.Len())
266 throw container::NoSuchElementException();
267 pGlossaries->DelGroupDoc(sGroupName);
269 /* -----------------------------06.04.00 11:11--------------------------------
271 ---------------------------------------------------------------------------*/
272 OUString SwXAutoTextContainer::getImplementationName(void) throw( uno::RuntimeException )
274 return SwXAutoTextContainer_getImplementationName();
276 /* -----------------------------06.04.00 11:11--------------------------------
278 ---------------------------------------------------------------------------*/
279 BOOL SwXAutoTextContainer::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
281 const uno::Sequence< OUString > aNames = SwXAutoTextContainer_getSupportedServiceNames();
282 for(sal_Int32 nService = 0; nService < aNames.getLength(); nService++)
284 if(aNames.getConstArray()[nService] == rServiceName)
285 return TRUE;
287 return FALSE;
289 /* -----------------------------06.04.00 11:11--------------------------------
291 ---------------------------------------------------------------------------*/
292 uno::Sequence< OUString > SwXAutoTextContainer::getSupportedServiceNames(void) throw( uno::RuntimeException )
294 return SwXAutoTextContainer_getSupportedServiceNames();
296 /******************************************************************
298 ******************************************************************/
299 /* -----------------------------10.03.00 18:02--------------------------------
301 ---------------------------------------------------------------------------*/
302 const uno::Sequence< sal_Int8 > & SwXAutoTextGroup::getUnoTunnelId()
304 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
305 return aSeq;
307 /* -----------------------------10.03.00 18:04--------------------------------
309 ---------------------------------------------------------------------------*/
310 sal_Int64 SAL_CALL SwXAutoTextGroup::getSomething( const uno::Sequence< sal_Int8 >& rId )
311 throw(uno::RuntimeException)
313 if( rId.getLength() == 16
314 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
315 rId.getConstArray(), 16 ) )
317 return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ));
319 return 0;
322 /*-- 21.12.98 12:42:24---------------------------------------------------
324 -----------------------------------------------------------------------*/
325 SwXAutoTextGroup::SwXAutoTextGroup(const OUString& rName,
326 SwGlossaries* pGlos) :
327 pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_AUTO_TEXT_GROUP)),
328 pGlossaries(pGlos),
329 sName(rName),
330 m_sGroupName(rName)
332 DBG_ASSERT( -1 != rName.indexOf( GLOS_DELIM ),
333 "SwXAutoTextGroup::SwXAutoTextGroup: to be constructed with a complete name only!" );
336 /*-- 21.12.98 12:42:24---------------------------------------------------
338 -----------------------------------------------------------------------*/
339 SwXAutoTextGroup::~SwXAutoTextGroup()
342 /*-- 21.12.98 12:42:24---------------------------------------------------
344 -----------------------------------------------------------------------*/
345 /*-- 21.12.98 12:42:25---------------------------------------------------
347 -----------------------------------------------------------------------*/
348 uno::Sequence< OUString > SwXAutoTextGroup::getTitles(void) throw( uno::RuntimeException )
350 ::vos::OGuard aGuard(Application::GetSolarMutex());
351 sal_uInt16 nCount = 0;
352 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0;
353 if(pGlosGroup && !pGlosGroup->GetError())
354 nCount = pGlosGroup->GetCount();
355 else
356 throw uno::RuntimeException();
358 uno::Sequence< OUString > aEntryTitles(nCount);
359 OUString *pArr = aEntryTitles.getArray();
361 for ( sal_uInt16 i = 0; i < nCount; i++ )
362 pArr[i] = pGlosGroup->GetLongName(i);
363 delete pGlosGroup;
364 return aEntryTitles;
366 /*-- 21.12.98 12:42:25---------------------------------------------------
368 -----------------------------------------------------------------------*/
369 void SwXAutoTextGroup::renameByName(const OUString& aElementName,
370 const OUString& aNewElementName, const OUString& aNewElementTitle)
371 throw( lang::IllegalArgumentException, container::ElementExistException, io::IOException,
372 uno::RuntimeException)
374 ::vos::OGuard aGuard(Application::GetSolarMutex());
375 // throw exception only if the programmatic name is to be changed into an existing name
376 if(aNewElementName != aElementName && hasByName(aNewElementName))
377 throw container::ElementExistException();
378 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0;
379 if(pGlosGroup && !pGlosGroup->GetError())
381 sal_uInt16 nIdx = pGlosGroup->GetIndex( aElementName);
382 if(USHRT_MAX == nIdx)
383 throw lang::IllegalArgumentException();
384 String aNewShort( aNewElementName);
385 String aNewName( aNewElementTitle);
386 sal_uInt16 nOldLongIdx = pGlosGroup->GetLongIndex( aNewShort );
387 sal_uInt16 nOldIdx = pGlosGroup->GetIndex( aNewName );
389 if( nIdx != USHRT_MAX &&
390 (nOldLongIdx == USHRT_MAX || nOldLongIdx == nIdx )&&
391 (nOldIdx == USHRT_MAX || nOldIdx == nIdx ))
393 pGlosGroup->Rename( nIdx, &aNewShort, &aNewName );
394 if(pGlosGroup->GetError() != 0)
395 throw io::IOException();
397 delete pGlosGroup;
399 else
400 throw uno::RuntimeException();
403 sal_Bool lcl_CopySelToDoc( SwDoc* pInsDoc, OTextCursorHelper* pxCursor, SwXTextRange* pxRange)
405 ASSERT( pInsDoc, "kein Ins.Dokument" );
407 SwNodes& rNds = pInsDoc->GetNodes();
409 SwNodeIndex aIdx( rNds.GetEndOfContent(), -1 );
410 SwCntntNode * pNd = aIdx.GetNode().GetCntntNode();
411 SwPosition aPos( aIdx, SwIndex( pNd, pNd->Len() ));
413 sal_Bool bRet = sal_False;
414 pInsDoc->LockExpFlds();
416 if(pxCursor)
418 SwPaM* pUnoCrsr = pxCursor->GetPaM();
419 bRet = pxCursor->GetDoc()->CopyRange( *pUnoCrsr, aPos, false )
420 || bRet;
422 else
424 const ::sw::mark::IMark* const pBkmk = pxRange->GetBookmark();
425 if(pBkmk && pBkmk->IsExpanded())
427 SwPaM aTmp(pBkmk->GetOtherMarkPos(), pBkmk->GetMarkPos());
428 bRet = pxRange->GetDoc()->CopyRange(aTmp, aPos, false)
429 || bRet;
434 pInsDoc->UnlockExpFlds();
435 if( !pInsDoc->IsExpFldsLocked() )
436 pInsDoc->UpdateExpFlds(NULL, true);
438 return bRet;
440 /*-- 21.12.98 12:42:25---------------------------------------------------
442 -----------------------------------------------------------------------*/
443 uno::Reference< text::XAutoTextEntry > SwXAutoTextGroup::insertNewByName(const OUString& aName,
444 const OUString& aTitle, const uno::Reference< text::XTextRange > & xTextRange)
445 throw( container::ElementExistException, uno::RuntimeException )
447 ::vos::OGuard aGuard(Application::GetSolarMutex());
448 if(hasByName(aName))
449 throw container::ElementExistException();
450 if(!xTextRange.is())
451 throw uno::RuntimeException();
453 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0;
454 String sShortName(aName);
455 String sLongName(aTitle);
456 if(pGlosGroup && !pGlosGroup->GetError())
458 /*if( pGlosGroup->IsOld() && pGlosGroup->ConvertToNew())
460 throw uno::RuntimeException();
461 } */
462 uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
463 SwXTextRange* pxRange = 0;
464 OTextCursorHelper* pxCursor = 0;
465 if(xRangeTunnel.is())
467 pxRange = reinterpret_cast<SwXTextRange*>(xRangeTunnel->getSomething(
468 SwXTextRange::getUnoTunnelId()));
469 pxCursor = reinterpret_cast<OTextCursorHelper*>(xRangeTunnel->getSomething(
470 OTextCursorHelper::getUnoTunnelId()));
473 String sOnlyTxt;
474 String* pOnlyTxt = 0;
475 sal_Bool bNoAttr = !pxCursor && !pxRange;
476 if(bNoAttr)
478 sOnlyTxt = UniString(xTextRange->getString());
479 pOnlyTxt = &sOnlyTxt;
482 const SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get();
484 SwDoc* pGDoc = pGlosGroup->GetDoc();
486 // Bis es eine Option dafuer gibt, base util::URL loeschen
487 if(pCfg->IsSaveRelFile())
489 INetURLObject aTemp(pGlosGroup->GetFileName());
490 pGlosGroup->SetBaseURL( aTemp.GetMainURL(INetURLObject::NO_DECODE));
492 else
493 pGlosGroup->SetBaseURL( aEmptyStr );
495 sal_uInt16 nRet;
496 if( pOnlyTxt )
497 nRet = pGlosGroup->PutText( sShortName, sLongName, *pOnlyTxt );
498 else
500 pGlosGroup->ClearDoc();
501 if( pGlosGroup->BeginPutDoc( sShortName, sLongName ) )
503 pGDoc->SetRedlineMode_intern( nsRedlineMode_t::REDLINE_DELETE_REDLINES );
504 lcl_CopySelToDoc( pGDoc, pxCursor, pxRange );
505 pGDoc->SetRedlineMode_intern((RedlineMode_t)( 0 ));
506 nRet = pGlosGroup->PutDoc();
508 else
509 nRet = (sal_uInt16) -1;
512 if(nRet == (sal_uInt16) -1 )
514 throw uno::RuntimeException();
516 pGlossaries->PutGroupDoc( pGlosGroup );
519 uno::Reference< text::XAutoTextEntry > xEntry = pGlossaries->GetAutoTextEntry( m_sGroupName, sName, sShortName, true );
520 DBG_ASSERT( xEntry.is(), "SwXAutoTextGroup::insertNewByName: no UNO object created? How this?" );
521 // we just inserted the entry into the group, so why doesn't it exist?
523 return xEntry;
525 /*-- 21.12.98 12:42:25---------------------------------------------------
527 -----------------------------------------------------------------------*/
528 void SwXAutoTextGroup::removeByName(const OUString& aEntryName) throw( container::NoSuchElementException, uno::RuntimeException )
530 ::vos::OGuard aGuard(Application::GetSolarMutex());
531 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0;
532 if(pGlosGroup && !pGlosGroup->GetError())
534 sal_uInt16 nIdx = pGlosGroup->GetIndex(aEntryName);
535 if ( nIdx != USHRT_MAX )
536 pGlosGroup->Delete(nIdx);
537 delete pGlosGroup;
539 else
540 throw container::NoSuchElementException();
542 /*-- 21.12.98 12:42:25---------------------------------------------------
544 -----------------------------------------------------------------------*/
545 OUString SwXAutoTextGroup::getName(void) throw( uno::RuntimeException )
547 ::vos::OGuard aGuard(Application::GetSolarMutex());
548 return sName;
550 /*-- 21.12.98 12:42:25---------------------------------------------------
552 -----------------------------------------------------------------------*/
553 void SwXAutoTextGroup::setName(const OUString& rName) throw( uno::RuntimeException )
555 ::vos::OGuard aGuard(Application::GetSolarMutex());
556 if( !pGlossaries )
557 throw uno::RuntimeException();
559 sal_Int32 nNewDelimPos = rName.lastIndexOf( GLOS_DELIM );
560 sal_Int32 nOldDelimPos = sName.lastIndexOf( GLOS_DELIM );
562 OUString aNewSuffix;
563 if (nNewDelimPos > -1)
564 aNewSuffix = rName.copy( nNewDelimPos + 1 );
565 OUString aOldSuffix;
566 if (nOldDelimPos > -1)
567 aOldSuffix = sName.copy( nOldDelimPos + 1 );
569 sal_Int32 nNewNumeric = aNewSuffix.toInt32();
570 sal_Int32 nOldNumeric = aOldSuffix.toInt32();
572 OUString aNewPrefix( (nNewDelimPos > 1) ? rName.copy( 0, nNewDelimPos ) : rName );
573 OUString aOldPrefix( (nOldDelimPos > 1) ? sName.copy( 0, nOldDelimPos ) : sName );
575 if ( sName == rName ||
576 ( nNewNumeric == nOldNumeric && aNewPrefix == aOldPrefix ) )
577 return;
578 String sNewGroup(rName);
579 if(STRING_NOTFOUND == sNewGroup.Search(GLOS_DELIM))
581 sNewGroup += GLOS_DELIM;
582 sNewGroup += UniString::CreateFromInt32(0);
585 //the name must be saved, the group may be invalidated while in RenameGroupDoc()
586 SwGlossaries* pTempGlossaries = pGlossaries;
588 String sPreserveTitle( pGlossaries->GetGroupTitle( sName ) );
589 if ( !pGlossaries->RenameGroupDoc( sName, sNewGroup, sPreserveTitle ) )
590 throw uno::RuntimeException();
591 else
593 sName = rName;
594 m_sGroupName = sNewGroup;
595 pGlossaries = pTempGlossaries;
598 /*-- 21.12.98 12:42:26---------------------------------------------------
600 -----------------------------------------------------------------------*/
601 sal_Int32 SwXAutoTextGroup::getCount(void) throw( uno::RuntimeException )
603 ::vos::OGuard aGuard(Application::GetSolarMutex());
604 int nCount = 0;
605 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0;
606 if(pGlosGroup && !pGlosGroup->GetError())
607 nCount = pGlosGroup->GetCount();
608 else
609 throw uno::RuntimeException();
610 delete pGlosGroup;
611 return nCount;
613 /*-- 21.12.98 12:42:26---------------------------------------------------
615 -----------------------------------------------------------------------*/
616 uno::Any SwXAutoTextGroup::getByIndex(sal_Int32 nIndex)
617 throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException )
619 ::vos::OGuard aGuard(Application::GetSolarMutex());
620 uno::Any aRet;
621 sal_uInt16 nCount = 0;
622 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0;
623 if(pGlosGroup && !pGlosGroup->GetError())
624 nCount = pGlosGroup->GetCount();
625 else
626 throw uno::RuntimeException();
627 if(0 <= nIndex && nIndex < nCount)
628 aRet = getByName(pGlosGroup->GetShortName((sal_uInt16) nIndex));
629 else
630 throw lang::IndexOutOfBoundsException();
631 delete pGlosGroup;
632 return aRet;
634 /*-- 21.12.98 12:42:26---------------------------------------------------
636 -----------------------------------------------------------------------*/
637 uno::Type SwXAutoTextGroup::getElementType(void) throw( uno::RuntimeException )
639 return ::getCppuType((uno::Reference<text::XAutoTextEntry>*)0);
642 /*-- 21.12.98 12:42:26---------------------------------------------------
644 -----------------------------------------------------------------------*/
645 sal_Bool SwXAutoTextGroup::hasElements(void) throw( uno::RuntimeException )
647 ::vos::OGuard aGuard(Application::GetSolarMutex());
648 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0;
649 sal_uInt16 nCount = 0;
650 if(pGlosGroup && !pGlosGroup->GetError())
651 nCount = pGlosGroup->GetCount();
652 else
653 throw uno::RuntimeException();
654 delete pGlosGroup;
655 return nCount > 0;
658 /*-- 21.12.98 12:42:27---------------------------------------------------
660 -----------------------------------------------------------------------*/
661 uno::Any SwXAutoTextGroup::getByName(const OUString& _rName)
662 throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
664 ::vos::OGuard aGuard(Application::GetSolarMutex());
665 uno::Reference< text::XAutoTextEntry > xEntry = pGlossaries->GetAutoTextEntry( m_sGroupName, sName, _rName, true );
666 DBG_ASSERT( xEntry.is(), "SwXAutoTextGroup::getByName: GetAutoTextEntry is fractious!" );
667 // we told it to create the object, so why didn't it?
668 return makeAny( xEntry );
670 /*-- 21.12.98 12:42:27---------------------------------------------------
672 -----------------------------------------------------------------------*/
673 uno::Sequence< OUString > SwXAutoTextGroup::getElementNames(void)
674 throw( uno::RuntimeException )
676 ::vos::OGuard aGuard(Application::GetSolarMutex());
677 sal_uInt16 nCount = 0;
678 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0;
679 if(pGlosGroup && !pGlosGroup->GetError())
680 nCount = pGlosGroup->GetCount();
681 else
682 throw uno::RuntimeException();
684 uno::Sequence< OUString > aEntryNames(nCount);
685 OUString *pArr = aEntryNames.getArray();
687 for ( sal_uInt16 i = 0; i < nCount; i++ )
688 pArr[i] = pGlosGroup->GetShortName(i);
689 delete pGlosGroup;
690 return aEntryNames;
692 /*-- 21.12.98 12:42:27---------------------------------------------------
694 -----------------------------------------------------------------------*/
695 sal_Bool SwXAutoTextGroup::hasByName(const OUString& rName)
696 throw( uno::RuntimeException )
698 ::vos::OGuard aGuard(Application::GetSolarMutex());
699 sal_Bool bRet = sal_False;
700 sal_uInt16 nCount = 0;
701 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0;
702 if(pGlosGroup && !pGlosGroup->GetError())
703 nCount = pGlosGroup->GetCount();
704 else
705 throw uno::RuntimeException();
707 for( sal_uInt16 i = 0; i < nCount; i++ )
709 String sCompare(pGlosGroup->GetShortName(i));
710 if(COMPARE_EQUAL == sCompare.CompareIgnoreCaseToAscii(String(rName)))
712 bRet = sal_True;
713 break;
716 delete pGlosGroup;
717 return bRet;
720 /*-- 09.02.00 15:33:30---------------------------------------------------
722 -----------------------------------------------------------------------*/
723 uno::Reference< beans::XPropertySetInfo > SwXAutoTextGroup::getPropertySetInfo(void)
724 throw( uno::RuntimeException )
726 static uno::Reference< beans::XPropertySetInfo > xRet = pPropSet->getPropertySetInfo();
727 return xRet;
729 /*-- 09.02.00 15:33:31---------------------------------------------------
731 -----------------------------------------------------------------------*/
732 void SwXAutoTextGroup::setPropertyValue(
733 const OUString& rPropertyName, const uno::Any& aValue)
734 throw( beans::UnknownPropertyException, beans::PropertyVetoException,
735 lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
737 ::vos::OGuard aGuard(Application::GetSolarMutex());
738 const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap()->getByName( rPropertyName );
740 if(!pEntry)
741 throw beans::UnknownPropertyException();
743 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0;
744 if(!pGlosGroup || pGlosGroup->GetError())
745 throw uno::RuntimeException();
746 switch(pEntry->nWID)
748 case WID_GROUP_TITLE:
750 OUString sNewTitle;
751 aValue >>= sNewTitle;
752 if(!sNewTitle.getLength())
753 throw lang::IllegalArgumentException();
754 sal_Bool bChanged = !sNewTitle.equals(pGlosGroup->GetName());
755 pGlosGroup->SetName(sNewTitle);
756 if(bChanged && HasGlossaryList())
757 GetGlossaryList()->ClearGroups();
759 break;
761 delete pGlosGroup;
763 /*-- 09.02.00 15:33:31---------------------------------------------------
765 -----------------------------------------------------------------------*/
766 uno::Any SwXAutoTextGroup::getPropertyValue(const OUString& rPropertyName)
767 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
769 ::vos::OGuard aGuard(Application::GetSolarMutex());
770 const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap()->getByName( rPropertyName);
772 if(!pEntry)
773 throw beans::UnknownPropertyException();
774 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0;
775 if(!pGlosGroup || pGlosGroup->GetError())
776 throw uno::RuntimeException();
778 uno::Any aAny;
779 switch(pEntry->nWID)
781 case WID_GROUP_PATH:
782 aAny <<= OUString(pGlosGroup->GetFileName());
783 break;
784 case WID_GROUP_TITLE:
785 aAny <<= OUString(pGlosGroup->GetName());
786 break;
788 delete pGlosGroup;
789 return aAny;
791 /*-- 09.02.00 15:33:31---------------------------------------------------
793 -----------------------------------------------------------------------*/
794 void SwXAutoTextGroup::addPropertyChangeListener(
795 const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/)
796 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
799 /*-- 09.02.00 15:33:31---------------------------------------------------
801 -----------------------------------------------------------------------*/
802 void SwXAutoTextGroup::removePropertyChangeListener(
803 const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/)
804 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
807 /*-- 09.02.00 15:33:32---------------------------------------------------
809 -----------------------------------------------------------------------*/
810 void SwXAutoTextGroup::addVetoableChangeListener(
811 const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/)
812 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
815 /*-- 09.02.00 15:33:32---------------------------------------------------
817 -----------------------------------------------------------------------*/
818 void SwXAutoTextGroup::removeVetoableChangeListener(
819 const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/)
820 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
823 /*-- 21.12.98 12:42:27---------------------------------------------------
825 -----------------------------------------------------------------------*/
826 void SwXAutoTextGroup::Invalidate()
828 pGlossaries = 0;
829 sName = aEmptyStr;
830 m_sGroupName = aEmptyStr;
832 /* -----------------------------06.04.00 11:11--------------------------------
834 ---------------------------------------------------------------------------*/
835 OUString SwXAutoTextGroup::getImplementationName(void) throw( uno::RuntimeException )
837 return C2U("SwXAutoTextGroup");
839 /* -----------------------------06.04.00 11:11--------------------------------
841 ---------------------------------------------------------------------------*/
842 BOOL SwXAutoTextGroup::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
844 return C2U("com.sun.star.text.AutoTextGroup") == rServiceName;
846 /* -----------------------------06.04.00 11:11--------------------------------
848 ---------------------------------------------------------------------------*/
849 uno::Sequence< OUString > SwXAutoTextGroup::getSupportedServiceNames(void) throw( uno::RuntimeException )
851 uno::Sequence< OUString > aRet(1);
852 OUString* pArray = aRet.getArray();
853 pArray[0] = C2U("com.sun.star.text.AutoTextGroup");
854 return aRet;
856 /******************************************************************
858 ******************************************************************/
859 /* -----------------------------10.03.00 18:02--------------------------------
861 ---------------------------------------------------------------------------*/
862 const uno::Sequence< sal_Int8 > & SwXAutoTextEntry::getUnoTunnelId()
864 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
865 return aSeq;
867 /* -----------------------------10.03.00 18:04--------------------------------
869 ---------------------------------------------------------------------------*/
870 sal_Int64 SAL_CALL SwXAutoTextEntry::getSomething( const uno::Sequence< sal_Int8 >& rId )
871 throw(uno::RuntimeException)
873 if( rId.getLength() == 16
874 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
875 rId.getConstArray(), 16 ) )
877 return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ));
879 return 0;
881 /*-- 21.12.98 12:42:33---------------------------------------------------
883 -----------------------------------------------------------------------*/
884 SwXAutoTextEntry::SwXAutoTextEntry(SwGlossaries* pGlss, const String& rGroupName,
885 const String& rEntryName) :
886 pGlossaries(pGlss),
887 sGroupName(rGroupName),
888 sEntryName(rEntryName),
889 pBodyText ( NULL )
892 /*-- 21.12.98 12:42:33---------------------------------------------------
894 -----------------------------------------------------------------------*/
895 SwXAutoTextEntry::~SwXAutoTextEntry()
898 ::vos::OGuard aGuard(Application::GetSolarMutex());
900 // ensure that any pending modifications are written
901 implFlushDocument( true );
903 //! Bug #96559
904 // DocShell must be cleared before mutex is lost.
905 // Needs to be done explicitly since xDocSh is a class member.
906 // Thus, an own block here, guarded by the SolarMutex
910 //---------------------------------------------------------------------
911 //--- 03.03.2003 13:24:58 -----------------------------------------------
913 void SwXAutoTextEntry::implFlushDocument( bool _bCloseDoc )
915 if ( xDocSh.Is() )
917 if ( xDocSh->GetDoc()->IsModified () )
918 xDocSh->Save();
920 if ( _bCloseDoc )
922 // stop listening at the document
923 EndListening( *&xDocSh );
925 xDocSh->DoClose();
926 xDocSh.Clear();
931 //-----------------------------------------------------------------------
932 //--- 03.03.2003 15:51:52 -----------------------------------------------
934 void SwXAutoTextEntry::Notify( SfxBroadcaster& _rBC, const SfxHint& _rHint )
936 if ( &_rBC == &xDocSh )
937 { // it's our document
938 if ( _rHint.ISA( SfxSimpleHint ) )
940 if ( SFX_HINT_DEINITIALIZING == static_cast< const SfxSimpleHint& >( _rHint ).GetId() )
942 // our document is dying (possibly because we're shuting down, and the document was notified
943 // earlier than we are?)
944 // stop listening at the docu
945 EndListening( *&xDocSh );
946 // and release our reference
947 xDocSh.Clear();
950 else if(_rHint.ISA(SfxEventHint))
952 if(SFX_EVENT_PREPARECLOSEDOC == static_cast< const SfxEventHint& >( _rHint ).GetEventId())
954 implFlushDocument( sal_False );
955 xBodyText = 0;
956 xDocSh.Clear();
962 void SwXAutoTextEntry::GetBodyText ()
964 ::vos::OGuard aGuard(Application::GetSolarMutex());
966 xDocSh = pGlossaries->EditGroupDoc ( sGroupName, sEntryName, FALSE );
967 DBG_ASSERT( xDocSh.Is(), "SwXAutoTextEntry::GetBodyText: unexpected: no doc returned by EditGroupDoc!" );
969 // start listening at the document
970 StartListening( *&xDocSh );
972 pBodyText = new SwXBodyText ( xDocSh->GetDoc() );
973 xBodyText = uno::Reference < lang::XServiceInfo > ( *pBodyText, uno::UNO_QUERY);
976 uno::Reference< text::XTextCursor > SwXAutoTextEntry::createTextCursor(void) throw( uno::RuntimeException )
978 ::vos::OGuard aGuard(Application::GetSolarMutex());
979 EnsureBodyText();
980 return pBodyText->createTextCursor();
982 /*-- 21.12.98 12:42:34---------------------------------------------------
984 -----------------------------------------------------------------------*/
985 uno::Reference< text::XTextCursor > SwXAutoTextEntry::createTextCursorByRange(
986 const uno::Reference< text::XTextRange > & aTextPosition) throw( uno::RuntimeException )
988 ::vos::OGuard aGuard(Application::GetSolarMutex());
989 EnsureBodyText();
990 return pBodyText->createTextCursorByRange ( aTextPosition );
992 /*-- 21.12.98 12:42:34---------------------------------------------------
994 -----------------------------------------------------------------------*/
995 void SwXAutoTextEntry::insertString(const uno::Reference< text::XTextRange > & xRange, const OUString& aString, sal_Bool bAbsorb) throw( uno::RuntimeException )
997 ::vos::OGuard aGuard(Application::GetSolarMutex());
998 EnsureBodyText();
999 pBodyText->insertString ( xRange, aString, bAbsorb );
1001 /*-- 21.12.98 12:42:34---------------------------------------------------
1003 -----------------------------------------------------------------------*/
1004 void SwXAutoTextEntry::insertControlCharacter(const uno::Reference< text::XTextRange > & xRange,
1005 sal_Int16 nControlCharacter, sal_Bool bAbsorb)
1006 throw( lang::IllegalArgumentException, uno::RuntimeException )
1008 ::vos::OGuard aGuard(Application::GetSolarMutex());
1009 EnsureBodyText();
1010 pBodyText->insertControlCharacter ( xRange, nControlCharacter, bAbsorb );
1012 /*-- 21.12.98 12:42:34---------------------------------------------------
1014 -----------------------------------------------------------------------*/
1015 void SwXAutoTextEntry::insertTextContent(
1016 const uno::Reference< text::XTextRange > & xRange,
1017 const uno::Reference< text::XTextContent > & xContent, sal_Bool bAbsorb)
1018 throw( lang::IllegalArgumentException, uno::RuntimeException )
1020 ::vos::OGuard aGuard(Application::GetSolarMutex());
1021 EnsureBodyText();
1022 pBodyText->insertTextContent ( xRange, xContent, bAbsorb );
1024 /*-- 21.12.98 12:42:34---------------------------------------------------
1026 -----------------------------------------------------------------------*/
1027 void SwXAutoTextEntry::removeTextContent(
1028 const uno::Reference< text::XTextContent > & xContent)
1029 throw( container::NoSuchElementException, uno::RuntimeException )
1031 ::vos::OGuard aGuard(Application::GetSolarMutex());
1032 EnsureBodyText();
1033 pBodyText->removeTextContent ( xContent );
1035 /*-- 21.12.98 12:42:35---------------------------------------------------
1037 -----------------------------------------------------------------------*/
1038 uno::Reference< text::XText > SwXAutoTextEntry::getText(void) throw( uno::RuntimeException )
1040 ::vos::OGuard aGuard(Application::GetSolarMutex());
1041 uno::Reference< text::XText > xRet = (text::XText*)this;
1042 return xRet;
1044 /*-- 21.12.98 12:42:35---------------------------------------------------
1046 -----------------------------------------------------------------------*/
1047 uno::Reference< text::XTextRange > SwXAutoTextEntry::getStart(void) throw( uno::RuntimeException )
1049 ::vos::OGuard aGuard(Application::GetSolarMutex());
1050 EnsureBodyText();
1051 return pBodyText->getStart();
1053 /*-- 21.12.98 12:42:36---------------------------------------------------
1055 -----------------------------------------------------------------------*/
1056 uno::Reference< text::XTextRange > SwXAutoTextEntry::getEnd(void) throw( uno::RuntimeException )
1058 ::vos::OGuard aGuard(Application::GetSolarMutex());
1059 EnsureBodyText();
1060 return pBodyText->getEnd();
1062 /*-- 21.12.98 12:42:36---------------------------------------------------
1064 -----------------------------------------------------------------------*/
1065 OUString SwXAutoTextEntry::getString(void) throw( uno::RuntimeException )
1067 ::vos::OGuard aGuard(Application::GetSolarMutex());
1068 EnsureBodyText();
1069 return pBodyText->getString();
1071 /*-- 21.12.98 12:42:36---------------------------------------------------
1073 -----------------------------------------------------------------------*/
1074 void SwXAutoTextEntry::setString(const OUString& aString) throw( uno::RuntimeException )
1076 ::vos::OGuard aGuard(Application::GetSolarMutex());
1077 EnsureBodyText();
1078 pBodyText->setString( aString );
1080 /* -----------------15.07.99 10:11-------------------
1082 --------------------------------------------------*/
1083 void SwXAutoTextEntry::applyTo(const uno::Reference< text::XTextRange > & xTextRange)throw( uno::RuntimeException )
1085 ::vos::OGuard aGuard(Application::GetSolarMutex());
1087 // ensure that any pending modifications are written
1088 // reason is that we're holding the _copy_ of the auto text, while the real auto text
1089 // is stored somewhere. And below, we're not working with our copy, but only tell the target
1090 // TextRange to work with the stored version.
1091 // #96380# - 2003-03-03 - fs@openoffice.org
1092 implFlushDocument( false );
1093 // TODO: think about if we should pass "true" here
1094 // The difference would be that when the next modification is made to this instance here, then
1095 // we would be forced to open the document again, instead of working on our current copy.
1096 // This means that we would reflect any changes which were done to the AutoText by foreign instances
1097 // in the meantime
1099 uno::Reference<lang::XUnoTunnel> xTunnel( xTextRange, uno::UNO_QUERY);
1100 SwXTextRange* pRange = 0;
1101 OTextCursorHelper* pCursor = 0;
1102 SwXText *pText = 0;
1104 if(xTunnel.is())
1106 pRange = reinterpret_cast < SwXTextRange* >
1107 ( xTunnel->getSomething( SwXTextRange::getUnoTunnelId() ) );
1108 pCursor = reinterpret_cast < OTextCursorHelper*>
1109 ( xTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() ) );
1110 pText = reinterpret_cast < SwXText* >
1111 ( xTunnel->getSomething( SwXText::getUnoTunnelId() ) );
1114 SwDoc* pDoc = 0;
1115 if ( pRange && pRange->GetBookmark())
1116 pDoc = pRange->GetDoc();
1117 else if ( pCursor )
1118 pDoc = pCursor->GetDoc();
1119 else if ( pText && pText->GetDoc() )
1121 xTunnel = uno::Reference < lang::XUnoTunnel > (pText->getStart(), uno::UNO_QUERY);
1122 if (xTunnel.is())
1124 pCursor = reinterpret_cast < OTextCursorHelper* >
1125 ( xTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() ) );
1126 if (pCursor)
1127 pDoc = pText->GetDoc();
1131 if(!pDoc)
1132 throw uno::RuntimeException();
1133 SwPaM* pInsertPaM = 0;
1134 if(pRange)
1136 const ::sw::mark::IMark* const pBkmk = pRange->GetBookmark();
1137 if(pBkmk->IsExpanded())
1138 pInsertPaM = new SwPaM(pBkmk->GetOtherMarkPos(), pBkmk->GetMarkPos());
1139 else
1140 pInsertPaM = new SwPaM(pBkmk->GetMarkPos());
1142 else
1144 SwPaM* pCrsr = pCursor->GetPaM();
1145 if(pCrsr->HasMark())
1146 pInsertPaM = new SwPaM(*pCrsr->GetPoint(), *pCrsr->GetMark());
1147 else
1148 pInsertPaM = new SwPaM(*pCrsr->GetPoint());
1151 SwTextBlocks* pBlock = pGlossaries->GetGroupDoc(sGroupName);
1152 sal_Bool bResult = pBlock && !pBlock->GetError() &&
1153 pDoc->InsertGlossary( *pBlock, sEntryName, *pInsertPaM);
1154 delete pBlock;
1155 delete pInsertPaM;
1157 if(!bResult)
1158 throw uno::RuntimeException();
1160 /* -----------------------------06.04.00 11:11--------------------------------
1162 ---------------------------------------------------------------------------*/
1163 OUString SwXAutoTextEntry::getImplementationName(void) throw( uno::RuntimeException )
1165 return C2U("SwXAutoTextEntry");
1167 /* -----------------------------06.04.00 11:11--------------------------------
1169 ---------------------------------------------------------------------------*/
1170 BOOL SwXAutoTextEntry::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
1172 return C2U("com.sun.star.text.AutoTextEntry") == rServiceName;
1174 /* -----------------------------06.04.00 11:11--------------------------------
1176 ---------------------------------------------------------------------------*/
1177 uno::Sequence< OUString > SwXAutoTextEntry::getSupportedServiceNames(void) throw( uno::RuntimeException )
1179 uno::Sequence< OUString > aRet(1);
1180 OUString* pArray = aRet.getArray();
1181 pArray[0] = C2U("com.sun.star.text.AutoTextEntry");
1182 return aRet;
1184 /* -----------------------------06.04.00 11:11--------------------------------
1186 ---------------------------------------------------------------------------*/
1187 uno::Reference< container::XNameReplace > SwXAutoTextEntry::getEvents()
1188 throw( uno::RuntimeException )
1190 return new SwAutoTextEventDescriptor( *this );
1192 /* -----------------------------30.01.01 18:40--------------------------------
1194 ---------------------------------------------------------------------------*/
1195 const struct SvEventDescription aAutotextEvents[] =
1197 { SW_EVENT_START_INS_GLOSSARY, "OnInsertStart" },
1198 { SW_EVENT_END_INS_GLOSSARY, "OnInsertDone" },
1199 { 0, NULL }
1202 /* -----------------------------30.01.01 18:40--------------------------------
1204 ---------------------------------------------------------------------------*/
1205 SwAutoTextEventDescriptor::SwAutoTextEventDescriptor(
1206 SwXAutoTextEntry& rAutoText ) :
1207 SvBaseEventDescriptor(aAutotextEvents),
1208 sSwAutoTextEventDescriptor(RTL_CONSTASCII_USTRINGPARAM(
1209 "SwAutoTextEventDescriptor")),
1210 rAutoTextEntry(rAutoText)
1213 /* -----------------------------30.01.01 18:40--------------------------------
1215 ---------------------------------------------------------------------------*/
1216 SwAutoTextEventDescriptor::~SwAutoTextEventDescriptor()
1219 /* -----------------------------30.01.01 18:40--------------------------------
1221 ---------------------------------------------------------------------------*/
1222 OUString SwAutoTextEventDescriptor::getImplementationName()
1223 throw( uno::RuntimeException )
1225 return sSwAutoTextEventDescriptor;
1227 /* -----------------------------30.01.01 18:40--------------------------------
1229 ---------------------------------------------------------------------------*/
1230 void SwAutoTextEventDescriptor::replaceByName(
1231 const USHORT nEvent,
1232 const SvxMacro& rMacro)
1233 throw(
1234 lang::IllegalArgumentException,
1235 container::NoSuchElementException,
1236 lang::WrappedTargetException,
1237 uno::RuntimeException)
1239 DBG_ASSERT( NULL != rAutoTextEntry.GetGlossaries(),
1240 "Strangely enough, the AutoText vanished!" );
1241 DBG_ASSERT( (nEvent == SW_EVENT_END_INS_GLOSSARY) ||
1242 (nEvent == SW_EVENT_START_INS_GLOSSARY) ,
1243 "Unknown event ID" );
1245 const SwGlossaries* pGlossaries = rAutoTextEntry.GetGlossaries();
1246 SwTextBlocks* pBlocks =
1247 pGlossaries->GetGroupDoc( rAutoTextEntry.GetGroupName() );
1248 DBG_ASSERT( NULL != pBlocks,
1249 "can't get autotext group; SwAutoTextEntry has illegal name?");
1251 if( pBlocks && !pBlocks->GetError())
1253 USHORT nIndex = pBlocks->GetIndex( rAutoTextEntry.GetEntryName() );
1254 if( nIndex != USHRT_MAX )
1256 SvxMacroTableDtor aMacroTable;
1257 if( pBlocks->GetMacroTable( nIndex, aMacroTable ) )
1259 SvxMacro* pNewMacro = new SvxMacro(rMacro);
1260 aMacroTable.Replace( nEvent, pNewMacro );
1261 pBlocks->SetMacroTable( nIndex, aMacroTable );
1265 delete pBlocks;
1267 // else: ignore
1269 /* -----------------------------30.01.01 18:40--------------------------------
1271 ---------------------------------------------------------------------------*/
1272 void SwAutoTextEventDescriptor::getByName(
1273 SvxMacro& rMacro,
1274 const USHORT nEvent )
1275 throw(
1276 container::NoSuchElementException,
1277 lang::WrappedTargetException,
1278 uno::RuntimeException)
1280 DBG_ASSERT( NULL != rAutoTextEntry.GetGlossaries(), "no AutoText" );
1281 DBG_ASSERT( (nEvent == SW_EVENT_END_INS_GLOSSARY) ||
1282 (nEvent == SW_EVENT_START_INS_GLOSSARY) ,
1283 "Unknown event ID" );
1285 const SwGlossaries* pGlossaries = rAutoTextEntry.GetGlossaries();
1286 SwTextBlocks* pBlocks =
1287 pGlossaries->GetGroupDoc( rAutoTextEntry.GetGroupName() );
1288 DBG_ASSERT( NULL != pBlocks,
1289 "can't get autotext group; SwAutoTextEntry has illegal name?");
1291 // return empty macro, unless macro is found
1292 OUString sEmptyStr;
1293 SvxMacro aEmptyMacro(sEmptyStr, sEmptyStr);
1294 rMacro = aEmptyMacro;
1296 if ( pBlocks && !pBlocks->GetError())
1298 USHORT nIndex = pBlocks->GetIndex( rAutoTextEntry.GetEntryName() );
1299 if( nIndex != USHRT_MAX )
1301 SvxMacroTableDtor aMacroTable;
1302 if( pBlocks->GetMacroTable( nIndex, aMacroTable ) )
1304 SvxMacro *pMacro = aMacroTable.Get( nEvent );
1305 if( pMacro )
1306 rMacro = *pMacro;
1310 delete pBlocks;