update dev300-m58
[ooovba.git] / sw / source / ui / uno / unoatxt.cxx
bloba2133bea181f3fbde4ef495593357a3057a4e1e2
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 |= (true == pxCursor->GetDoc()->Copy( *pUnoCrsr, aPos, false ));
421 else
423 const ::sw::mark::IMark* const pBkmk = pxRange->GetBookmark();
424 if(pBkmk && pBkmk->IsExpanded())
426 SwPaM aTmp(pBkmk->GetOtherMarkPos(), pBkmk->GetMarkPos());
427 bRet |= (true == pxRange->GetDoc()->Copy(aTmp, aPos, false));
432 pInsDoc->UnlockExpFlds();
433 if( !pInsDoc->IsExpFldsLocked() )
434 pInsDoc->UpdateExpFlds(NULL, true);
436 return bRet;
438 /*-- 21.12.98 12:42:25---------------------------------------------------
440 -----------------------------------------------------------------------*/
441 uno::Reference< text::XAutoTextEntry > SwXAutoTextGroup::insertNewByName(const OUString& aName,
442 const OUString& aTitle, const uno::Reference< text::XTextRange > & xTextRange)
443 throw( container::ElementExistException, uno::RuntimeException )
445 ::vos::OGuard aGuard(Application::GetSolarMutex());
446 if(hasByName(aName))
447 throw container::ElementExistException();
448 if(!xTextRange.is())
449 throw uno::RuntimeException();
451 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0;
452 String sShortName(aName);
453 String sLongName(aTitle);
454 if(pGlosGroup && !pGlosGroup->GetError())
456 /*if( pGlosGroup->IsOld() && pGlosGroup->ConvertToNew())
458 throw uno::RuntimeException();
459 } */
460 uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
461 SwXTextRange* pxRange = 0;
462 OTextCursorHelper* pxCursor = 0;
463 if(xRangeTunnel.is())
465 pxRange = reinterpret_cast<SwXTextRange*>(xRangeTunnel->getSomething(
466 SwXTextRange::getUnoTunnelId()));
467 pxCursor = reinterpret_cast<OTextCursorHelper*>(xRangeTunnel->getSomething(
468 OTextCursorHelper::getUnoTunnelId()));
471 String sOnlyTxt;
472 String* pOnlyTxt = 0;
473 sal_Bool bNoAttr = !pxCursor && !pxRange;
474 if(bNoAttr)
476 sOnlyTxt = UniString(xTextRange->getString());
477 pOnlyTxt = &sOnlyTxt;
480 const SvxAutoCorrCfg* pCfg = SvxAutoCorrCfg::Get();
482 SwDoc* pGDoc = pGlosGroup->GetDoc();
484 // Bis es eine Option dafuer gibt, base util::URL loeschen
485 if(pCfg->IsSaveRelFile())
487 INetURLObject aTemp(pGlosGroup->GetFileName());
488 pGlosGroup->SetBaseURL( aTemp.GetMainURL(INetURLObject::NO_DECODE));
490 else
491 pGlosGroup->SetBaseURL( aEmptyStr );
493 sal_uInt16 nRet;
494 if( pOnlyTxt )
495 nRet = pGlosGroup->PutText( sShortName, sLongName, *pOnlyTxt );
496 else
498 pGlosGroup->ClearDoc();
499 if( pGlosGroup->BeginPutDoc( sShortName, sLongName ) )
501 pGDoc->SetRedlineMode_intern( nsRedlineMode_t::REDLINE_DELETE_REDLINES );
502 lcl_CopySelToDoc( pGDoc, pxCursor, pxRange );
503 pGDoc->SetRedlineMode_intern((RedlineMode_t)( 0 ));
504 nRet = pGlosGroup->PutDoc();
506 else
507 nRet = (sal_uInt16) -1;
510 if(nRet == (sal_uInt16) -1 )
512 throw uno::RuntimeException();
514 pGlossaries->PutGroupDoc( pGlosGroup );
517 uno::Reference< text::XAutoTextEntry > xEntry = pGlossaries->GetAutoTextEntry( m_sGroupName, sName, sShortName, true );
518 DBG_ASSERT( xEntry.is(), "SwXAutoTextGroup::insertNewByName: no UNO object created? How this?" );
519 // we just inserted the entry into the group, so why doesn't it exist?
521 return xEntry;
523 /*-- 21.12.98 12:42:25---------------------------------------------------
525 -----------------------------------------------------------------------*/
526 void SwXAutoTextGroup::removeByName(const OUString& aEntryName) throw( container::NoSuchElementException, uno::RuntimeException )
528 ::vos::OGuard aGuard(Application::GetSolarMutex());
529 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0;
530 if(pGlosGroup && !pGlosGroup->GetError())
532 sal_uInt16 nIdx = pGlosGroup->GetIndex(aEntryName);
533 if ( nIdx != USHRT_MAX )
534 pGlosGroup->Delete(nIdx);
535 delete pGlosGroup;
537 else
538 throw container::NoSuchElementException();
540 /*-- 21.12.98 12:42:25---------------------------------------------------
542 -----------------------------------------------------------------------*/
543 OUString SwXAutoTextGroup::getName(void) throw( uno::RuntimeException )
545 ::vos::OGuard aGuard(Application::GetSolarMutex());
546 return sName;
548 /*-- 21.12.98 12:42:25---------------------------------------------------
550 -----------------------------------------------------------------------*/
551 void SwXAutoTextGroup::setName(const OUString& rName) throw( uno::RuntimeException )
553 ::vos::OGuard aGuard(Application::GetSolarMutex());
554 if( !pGlossaries )
555 throw uno::RuntimeException();
557 sal_Int32 nNewDelimPos = rName.lastIndexOf( GLOS_DELIM );
558 sal_Int32 nOldDelimPos = sName.lastIndexOf( GLOS_DELIM );
560 OUString aNewSuffix;
561 if (nNewDelimPos > -1)
562 aNewSuffix = rName.copy( nNewDelimPos + 1 );
563 OUString aOldSuffix;
564 if (nOldDelimPos > -1)
565 aOldSuffix = sName.copy( nOldDelimPos + 1 );
567 sal_Int32 nNewNumeric = aNewSuffix.toInt32();
568 sal_Int32 nOldNumeric = aOldSuffix.toInt32();
570 OUString aNewPrefix( (nNewDelimPos > 1) ? rName.copy( 0, nNewDelimPos ) : rName );
571 OUString aOldPrefix( (nOldDelimPos > 1) ? sName.copy( 0, nOldDelimPos ) : sName );
573 if ( sName == rName ||
574 ( nNewNumeric == nOldNumeric && aNewPrefix == aOldPrefix ) )
575 return;
576 String sNewGroup(rName);
577 if(STRING_NOTFOUND == sNewGroup.Search(GLOS_DELIM))
579 sNewGroup += GLOS_DELIM;
580 sNewGroup += UniString::CreateFromInt32(0);
583 //the name must be saved, the group may be invalidated while in RenameGroupDoc()
584 SwGlossaries* pTempGlossaries = pGlossaries;
586 String sPreserveTitle( pGlossaries->GetGroupTitle( sName ) );
587 if ( !pGlossaries->RenameGroupDoc( sName, sNewGroup, sPreserveTitle ) )
588 throw uno::RuntimeException();
589 else
591 sName = rName;
592 m_sGroupName = sNewGroup;
593 pGlossaries = pTempGlossaries;
596 /*-- 21.12.98 12:42:26---------------------------------------------------
598 -----------------------------------------------------------------------*/
599 sal_Int32 SwXAutoTextGroup::getCount(void) throw( uno::RuntimeException )
601 ::vos::OGuard aGuard(Application::GetSolarMutex());
602 int nCount = 0;
603 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0;
604 if(pGlosGroup && !pGlosGroup->GetError())
605 nCount = pGlosGroup->GetCount();
606 else
607 throw uno::RuntimeException();
608 delete pGlosGroup;
609 return nCount;
611 /*-- 21.12.98 12:42:26---------------------------------------------------
613 -----------------------------------------------------------------------*/
614 uno::Any SwXAutoTextGroup::getByIndex(sal_Int32 nIndex)
615 throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException )
617 ::vos::OGuard aGuard(Application::GetSolarMutex());
618 uno::Any aRet;
619 sal_uInt16 nCount = 0;
620 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0;
621 if(pGlosGroup && !pGlosGroup->GetError())
622 nCount = pGlosGroup->GetCount();
623 else
624 throw uno::RuntimeException();
625 if(0 <= nIndex && nIndex < nCount)
626 aRet = getByName(pGlosGroup->GetShortName((sal_uInt16) nIndex));
627 else
628 throw lang::IndexOutOfBoundsException();
629 delete pGlosGroup;
630 return aRet;
632 /*-- 21.12.98 12:42:26---------------------------------------------------
634 -----------------------------------------------------------------------*/
635 uno::Type SwXAutoTextGroup::getElementType(void) throw( uno::RuntimeException )
637 return ::getCppuType((uno::Reference<text::XAutoTextEntry>*)0);
640 /*-- 21.12.98 12:42:26---------------------------------------------------
642 -----------------------------------------------------------------------*/
643 sal_Bool SwXAutoTextGroup::hasElements(void) throw( uno::RuntimeException )
645 ::vos::OGuard aGuard(Application::GetSolarMutex());
646 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0;
647 sal_uInt16 nCount = 0;
648 if(pGlosGroup && !pGlosGroup->GetError())
649 nCount = pGlosGroup->GetCount();
650 else
651 throw uno::RuntimeException();
652 delete pGlosGroup;
653 return nCount > 0;
656 /*-- 21.12.98 12:42:27---------------------------------------------------
658 -----------------------------------------------------------------------*/
659 uno::Any SwXAutoTextGroup::getByName(const OUString& _rName)
660 throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
662 ::vos::OGuard aGuard(Application::GetSolarMutex());
663 uno::Reference< text::XAutoTextEntry > xEntry = pGlossaries->GetAutoTextEntry( m_sGroupName, sName, _rName, true );
664 DBG_ASSERT( xEntry.is(), "SwXAutoTextGroup::getByName: GetAutoTextEntry is fractious!" );
665 // we told it to create the object, so why didn't it?
666 return makeAny( xEntry );
668 /*-- 21.12.98 12:42:27---------------------------------------------------
670 -----------------------------------------------------------------------*/
671 uno::Sequence< OUString > SwXAutoTextGroup::getElementNames(void)
672 throw( uno::RuntimeException )
674 ::vos::OGuard aGuard(Application::GetSolarMutex());
675 sal_uInt16 nCount = 0;
676 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0;
677 if(pGlosGroup && !pGlosGroup->GetError())
678 nCount = pGlosGroup->GetCount();
679 else
680 throw uno::RuntimeException();
682 uno::Sequence< OUString > aEntryNames(nCount);
683 OUString *pArr = aEntryNames.getArray();
685 for ( sal_uInt16 i = 0; i < nCount; i++ )
686 pArr[i] = pGlosGroup->GetShortName(i);
687 delete pGlosGroup;
688 return aEntryNames;
690 /*-- 21.12.98 12:42:27---------------------------------------------------
692 -----------------------------------------------------------------------*/
693 sal_Bool SwXAutoTextGroup::hasByName(const OUString& rName)
694 throw( uno::RuntimeException )
696 ::vos::OGuard aGuard(Application::GetSolarMutex());
697 sal_Bool bRet = sal_False;
698 sal_uInt16 nCount = 0;
699 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0;
700 if(pGlosGroup && !pGlosGroup->GetError())
701 nCount = pGlosGroup->GetCount();
702 else
703 throw uno::RuntimeException();
705 for( sal_uInt16 i = 0; i < nCount; i++ )
707 String sCompare(pGlosGroup->GetShortName(i));
708 if(COMPARE_EQUAL == sCompare.CompareIgnoreCaseToAscii(String(rName)))
710 bRet = sal_True;
711 break;
714 delete pGlosGroup;
715 return bRet;
718 /*-- 09.02.00 15:33:30---------------------------------------------------
720 -----------------------------------------------------------------------*/
721 uno::Reference< beans::XPropertySetInfo > SwXAutoTextGroup::getPropertySetInfo(void)
722 throw( uno::RuntimeException )
724 static uno::Reference< beans::XPropertySetInfo > xRet = pPropSet->getPropertySetInfo();
725 return xRet;
727 /*-- 09.02.00 15:33:31---------------------------------------------------
729 -----------------------------------------------------------------------*/
730 void SwXAutoTextGroup::setPropertyValue(
731 const OUString& rPropertyName, const uno::Any& aValue)
732 throw( beans::UnknownPropertyException, beans::PropertyVetoException,
733 lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
735 ::vos::OGuard aGuard(Application::GetSolarMutex());
736 const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap()->getByName( rPropertyName );
738 if(!pEntry)
739 throw beans::UnknownPropertyException();
741 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0;
742 if(!pGlosGroup || pGlosGroup->GetError())
743 throw uno::RuntimeException();
744 switch(pEntry->nWID)
746 case WID_GROUP_TITLE:
748 OUString sNewTitle;
749 aValue >>= sNewTitle;
750 if(!sNewTitle.getLength())
751 throw lang::IllegalArgumentException();
752 sal_Bool bChanged = !sNewTitle.equals(pGlosGroup->GetName());
753 pGlosGroup->SetName(sNewTitle);
754 if(bChanged && HasGlossaryList())
755 GetGlossaryList()->ClearGroups();
757 break;
759 delete pGlosGroup;
761 /*-- 09.02.00 15:33:31---------------------------------------------------
763 -----------------------------------------------------------------------*/
764 uno::Any SwXAutoTextGroup::getPropertyValue(const OUString& rPropertyName)
765 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
767 ::vos::OGuard aGuard(Application::GetSolarMutex());
768 const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap()->getByName( rPropertyName);
770 if(!pEntry)
771 throw beans::UnknownPropertyException();
772 SwTextBlocks* pGlosGroup = pGlossaries ? pGlossaries->GetGroupDoc(m_sGroupName, sal_False) : 0;
773 if(!pGlosGroup || pGlosGroup->GetError())
774 throw uno::RuntimeException();
776 uno::Any aAny;
777 switch(pEntry->nWID)
779 case WID_GROUP_PATH:
780 aAny <<= OUString(pGlosGroup->GetFileName());
781 break;
782 case WID_GROUP_TITLE:
783 aAny <<= OUString(pGlosGroup->GetName());
784 break;
786 delete pGlosGroup;
787 return aAny;
789 /*-- 09.02.00 15:33:31---------------------------------------------------
791 -----------------------------------------------------------------------*/
792 void SwXAutoTextGroup::addPropertyChangeListener(
793 const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/)
794 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
797 /*-- 09.02.00 15:33:31---------------------------------------------------
799 -----------------------------------------------------------------------*/
800 void SwXAutoTextGroup::removePropertyChangeListener(
801 const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/)
802 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
805 /*-- 09.02.00 15:33:32---------------------------------------------------
807 -----------------------------------------------------------------------*/
808 void SwXAutoTextGroup::addVetoableChangeListener(
809 const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/)
810 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
813 /*-- 09.02.00 15:33:32---------------------------------------------------
815 -----------------------------------------------------------------------*/
816 void SwXAutoTextGroup::removeVetoableChangeListener(
817 const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/)
818 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
821 /*-- 21.12.98 12:42:27---------------------------------------------------
823 -----------------------------------------------------------------------*/
824 void SwXAutoTextGroup::Invalidate()
826 pGlossaries = 0;
827 sName = aEmptyStr;
828 m_sGroupName = aEmptyStr;
830 /* -----------------------------06.04.00 11:11--------------------------------
832 ---------------------------------------------------------------------------*/
833 OUString SwXAutoTextGroup::getImplementationName(void) throw( uno::RuntimeException )
835 return C2U("SwXAutoTextGroup");
837 /* -----------------------------06.04.00 11:11--------------------------------
839 ---------------------------------------------------------------------------*/
840 BOOL SwXAutoTextGroup::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
842 return C2U("com.sun.star.text.AutoTextGroup") == rServiceName;
844 /* -----------------------------06.04.00 11:11--------------------------------
846 ---------------------------------------------------------------------------*/
847 uno::Sequence< OUString > SwXAutoTextGroup::getSupportedServiceNames(void) throw( uno::RuntimeException )
849 uno::Sequence< OUString > aRet(1);
850 OUString* pArray = aRet.getArray();
851 pArray[0] = C2U("com.sun.star.text.AutoTextGroup");
852 return aRet;
854 /******************************************************************
856 ******************************************************************/
857 /* -----------------------------10.03.00 18:02--------------------------------
859 ---------------------------------------------------------------------------*/
860 const uno::Sequence< sal_Int8 > & SwXAutoTextEntry::getUnoTunnelId()
862 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
863 return aSeq;
865 /* -----------------------------10.03.00 18:04--------------------------------
867 ---------------------------------------------------------------------------*/
868 sal_Int64 SAL_CALL SwXAutoTextEntry::getSomething( const uno::Sequence< sal_Int8 >& rId )
869 throw(uno::RuntimeException)
871 if( rId.getLength() == 16
872 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
873 rId.getConstArray(), 16 ) )
875 return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ));
877 return 0;
879 /*-- 21.12.98 12:42:33---------------------------------------------------
881 -----------------------------------------------------------------------*/
882 SwXAutoTextEntry::SwXAutoTextEntry(SwGlossaries* pGlss, const String& rGroupName,
883 const String& rEntryName) :
884 pGlossaries(pGlss),
885 sGroupName(rGroupName),
886 sEntryName(rEntryName),
887 pBodyText ( NULL )
890 /*-- 21.12.98 12:42:33---------------------------------------------------
892 -----------------------------------------------------------------------*/
893 SwXAutoTextEntry::~SwXAutoTextEntry()
896 ::vos::OGuard aGuard(Application::GetSolarMutex());
898 // ensure that any pending modifications are written
899 implFlushDocument( true );
901 //! Bug #96559
902 // DocShell must be cleared before mutex is lost.
903 // Needs to be done explicitly since xDocSh is a class member.
904 // Thus, an own block here, guarded by the SolarMutex
908 //---------------------------------------------------------------------
909 //--- 03.03.2003 13:24:58 -----------------------------------------------
911 void SwXAutoTextEntry::implFlushDocument( bool _bCloseDoc )
913 if ( xDocSh.Is() )
915 if ( xDocSh->GetDoc()->IsModified () )
916 xDocSh->Save();
918 if ( _bCloseDoc )
920 // stop listening at the document
921 EndListening( *&xDocSh );
923 xDocSh->DoClose();
924 xDocSh.Clear();
929 //-----------------------------------------------------------------------
930 //--- 03.03.2003 15:51:52 -----------------------------------------------
932 void SwXAutoTextEntry::Notify( SfxBroadcaster& _rBC, const SfxHint& _rHint )
934 if ( &_rBC == &xDocSh )
935 { // it's our document
936 if ( _rHint.ISA( SfxSimpleHint ) )
938 if ( SFX_HINT_DEINITIALIZING == static_cast< const SfxSimpleHint& >( _rHint ).GetId() )
940 // our document is dying (possibly because we're shuting down, and the document was notified
941 // earlier than we are?)
942 // stop listening at the docu
943 EndListening( *&xDocSh );
944 // and release our reference
945 xDocSh.Clear();
948 else if(_rHint.ISA(SfxEventHint))
950 if(SFX_EVENT_PREPARECLOSEDOC == static_cast< const SfxEventHint& >( _rHint ).GetEventId())
952 implFlushDocument( sal_False );
953 xBodyText = 0;
954 xDocSh.Clear();
960 void SwXAutoTextEntry::GetBodyText ()
962 ::vos::OGuard aGuard(Application::GetSolarMutex());
964 xDocSh = pGlossaries->EditGroupDoc ( sGroupName, sEntryName, FALSE );
965 DBG_ASSERT( xDocSh.Is(), "SwXAutoTextEntry::GetBodyText: unexpected: no doc returned by EditGroupDoc!" );
967 // start listening at the document
968 StartListening( *&xDocSh );
970 pBodyText = new SwXBodyText ( xDocSh->GetDoc() );
971 xBodyText = uno::Reference < lang::XServiceInfo > ( *pBodyText, uno::UNO_QUERY);
974 uno::Reference< text::XTextCursor > SwXAutoTextEntry::createTextCursor(void) throw( uno::RuntimeException )
976 ::vos::OGuard aGuard(Application::GetSolarMutex());
977 EnsureBodyText();
978 return pBodyText->createTextCursor();
980 /*-- 21.12.98 12:42:34---------------------------------------------------
982 -----------------------------------------------------------------------*/
983 uno::Reference< text::XTextCursor > SwXAutoTextEntry::createTextCursorByRange(
984 const uno::Reference< text::XTextRange > & aTextPosition) throw( uno::RuntimeException )
986 ::vos::OGuard aGuard(Application::GetSolarMutex());
987 EnsureBodyText();
988 return pBodyText->createTextCursorByRange ( aTextPosition );
990 /*-- 21.12.98 12:42:34---------------------------------------------------
992 -----------------------------------------------------------------------*/
993 void SwXAutoTextEntry::insertString(const uno::Reference< text::XTextRange > & xRange, const OUString& aString, sal_Bool bAbsorb) throw( uno::RuntimeException )
995 ::vos::OGuard aGuard(Application::GetSolarMutex());
996 EnsureBodyText();
997 pBodyText->insertString ( xRange, aString, bAbsorb );
999 /*-- 21.12.98 12:42:34---------------------------------------------------
1001 -----------------------------------------------------------------------*/
1002 void SwXAutoTextEntry::insertControlCharacter(const uno::Reference< text::XTextRange > & xRange,
1003 sal_Int16 nControlCharacter, sal_Bool bAbsorb)
1004 throw( lang::IllegalArgumentException, uno::RuntimeException )
1006 ::vos::OGuard aGuard(Application::GetSolarMutex());
1007 EnsureBodyText();
1008 pBodyText->insertControlCharacter ( xRange, nControlCharacter, bAbsorb );
1010 /*-- 21.12.98 12:42:34---------------------------------------------------
1012 -----------------------------------------------------------------------*/
1013 void SwXAutoTextEntry::insertTextContent(
1014 const uno::Reference< text::XTextRange > & xRange,
1015 const uno::Reference< text::XTextContent > & xContent, sal_Bool bAbsorb)
1016 throw( lang::IllegalArgumentException, uno::RuntimeException )
1018 ::vos::OGuard aGuard(Application::GetSolarMutex());
1019 EnsureBodyText();
1020 pBodyText->insertTextContent ( xRange, xContent, bAbsorb );
1022 /*-- 21.12.98 12:42:34---------------------------------------------------
1024 -----------------------------------------------------------------------*/
1025 void SwXAutoTextEntry::removeTextContent(
1026 const uno::Reference< text::XTextContent > & xContent)
1027 throw( container::NoSuchElementException, uno::RuntimeException )
1029 ::vos::OGuard aGuard(Application::GetSolarMutex());
1030 EnsureBodyText();
1031 pBodyText->removeTextContent ( xContent );
1033 /*-- 21.12.98 12:42:35---------------------------------------------------
1035 -----------------------------------------------------------------------*/
1036 uno::Reference< text::XText > SwXAutoTextEntry::getText(void) throw( uno::RuntimeException )
1038 ::vos::OGuard aGuard(Application::GetSolarMutex());
1039 uno::Reference< text::XText > xRet = (text::XText*)this;
1040 return xRet;
1042 /*-- 21.12.98 12:42:35---------------------------------------------------
1044 -----------------------------------------------------------------------*/
1045 uno::Reference< text::XTextRange > SwXAutoTextEntry::getStart(void) throw( uno::RuntimeException )
1047 ::vos::OGuard aGuard(Application::GetSolarMutex());
1048 EnsureBodyText();
1049 return pBodyText->getStart();
1051 /*-- 21.12.98 12:42:36---------------------------------------------------
1053 -----------------------------------------------------------------------*/
1054 uno::Reference< text::XTextRange > SwXAutoTextEntry::getEnd(void) throw( uno::RuntimeException )
1056 ::vos::OGuard aGuard(Application::GetSolarMutex());
1057 EnsureBodyText();
1058 return pBodyText->getEnd();
1060 /*-- 21.12.98 12:42:36---------------------------------------------------
1062 -----------------------------------------------------------------------*/
1063 OUString SwXAutoTextEntry::getString(void) throw( uno::RuntimeException )
1065 ::vos::OGuard aGuard(Application::GetSolarMutex());
1066 EnsureBodyText();
1067 return pBodyText->getString();
1069 /*-- 21.12.98 12:42:36---------------------------------------------------
1071 -----------------------------------------------------------------------*/
1072 void SwXAutoTextEntry::setString(const OUString& aString) throw( uno::RuntimeException )
1074 ::vos::OGuard aGuard(Application::GetSolarMutex());
1075 EnsureBodyText();
1076 pBodyText->setString( aString );
1078 /* -----------------15.07.99 10:11-------------------
1080 --------------------------------------------------*/
1081 void SwXAutoTextEntry::applyTo(const uno::Reference< text::XTextRange > & xTextRange)throw( uno::RuntimeException )
1083 ::vos::OGuard aGuard(Application::GetSolarMutex());
1085 // ensure that any pending modifications are written
1086 // reason is that we're holding the _copy_ of the auto text, while the real auto text
1087 // is stored somewhere. And below, we're not working with our copy, but only tell the target
1088 // TextRange to work with the stored version.
1089 // #96380# - 2003-03-03 - fs@openoffice.org
1090 implFlushDocument( false );
1091 // TODO: think about if we should pass "true" here
1092 // The difference would be that when the next modification is made to this instance here, then
1093 // we would be forced to open the document again, instead of working on our current copy.
1094 // This means that we would reflect any changes which were done to the AutoText by foreign instances
1095 // in the meantime
1097 uno::Reference<lang::XUnoTunnel> xTunnel( xTextRange, uno::UNO_QUERY);
1098 SwXTextRange* pRange = 0;
1099 OTextCursorHelper* pCursor = 0;
1100 SwXText *pText = 0;
1102 if(xTunnel.is())
1104 pRange = reinterpret_cast < SwXTextRange* >
1105 ( xTunnel->getSomething( SwXTextRange::getUnoTunnelId() ) );
1106 pCursor = reinterpret_cast < OTextCursorHelper*>
1107 ( xTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() ) );
1108 pText = reinterpret_cast < SwXText* >
1109 ( xTunnel->getSomething( SwXText::getUnoTunnelId() ) );
1112 SwDoc* pDoc = 0;
1113 if ( pRange && pRange->GetBookmark())
1114 pDoc = pRange->GetDoc();
1115 else if ( pCursor )
1116 pDoc = pCursor->GetDoc();
1117 else if ( pText && pText->GetDoc() )
1119 xTunnel = uno::Reference < lang::XUnoTunnel > (pText->getStart(), uno::UNO_QUERY);
1120 if (xTunnel.is())
1122 pCursor = reinterpret_cast < OTextCursorHelper* >
1123 ( xTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() ) );
1124 if (pCursor)
1125 pDoc = pText->GetDoc();
1129 if(!pDoc)
1130 throw uno::RuntimeException();
1131 SwPaM* pInsertPaM = 0;
1132 if(pRange)
1134 const ::sw::mark::IMark* const pBkmk = pRange->GetBookmark();
1135 if(pBkmk->IsExpanded())
1136 pInsertPaM = new SwPaM(pBkmk->GetOtherMarkPos(), pBkmk->GetMarkPos());
1137 else
1138 pInsertPaM = new SwPaM(pBkmk->GetMarkPos());
1140 else
1142 SwPaM* pCrsr = pCursor->GetPaM();
1143 if(pCrsr->HasMark())
1144 pInsertPaM = new SwPaM(*pCrsr->GetPoint(), *pCrsr->GetMark());
1145 else
1146 pInsertPaM = new SwPaM(*pCrsr->GetPoint());
1149 SwTextBlocks* pBlock = pGlossaries->GetGroupDoc(sGroupName);
1150 sal_Bool bResult = pBlock && !pBlock->GetError() &&
1151 pDoc->InsertGlossary( *pBlock, sEntryName, *pInsertPaM);
1152 delete pBlock;
1153 delete pInsertPaM;
1155 if(!bResult)
1156 throw uno::RuntimeException();
1158 /* -----------------------------06.04.00 11:11--------------------------------
1160 ---------------------------------------------------------------------------*/
1161 OUString SwXAutoTextEntry::getImplementationName(void) throw( uno::RuntimeException )
1163 return C2U("SwXAutoTextEntry");
1165 /* -----------------------------06.04.00 11:11--------------------------------
1167 ---------------------------------------------------------------------------*/
1168 BOOL SwXAutoTextEntry::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
1170 return C2U("com.sun.star.text.AutoTextEntry") == rServiceName;
1172 /* -----------------------------06.04.00 11:11--------------------------------
1174 ---------------------------------------------------------------------------*/
1175 uno::Sequence< OUString > SwXAutoTextEntry::getSupportedServiceNames(void) throw( uno::RuntimeException )
1177 uno::Sequence< OUString > aRet(1);
1178 OUString* pArray = aRet.getArray();
1179 pArray[0] = C2U("com.sun.star.text.AutoTextEntry");
1180 return aRet;
1182 /* -----------------------------06.04.00 11:11--------------------------------
1184 ---------------------------------------------------------------------------*/
1185 uno::Reference< container::XNameReplace > SwXAutoTextEntry::getEvents()
1186 throw( uno::RuntimeException )
1188 return new SwAutoTextEventDescriptor( *this );
1190 /* -----------------------------30.01.01 18:40--------------------------------
1192 ---------------------------------------------------------------------------*/
1193 const struct SvEventDescription aAutotextEvents[] =
1195 { SW_EVENT_START_INS_GLOSSARY, "OnInsertStart" },
1196 { SW_EVENT_END_INS_GLOSSARY, "OnInsertDone" },
1197 { 0, NULL }
1200 /* -----------------------------30.01.01 18:40--------------------------------
1202 ---------------------------------------------------------------------------*/
1203 SwAutoTextEventDescriptor::SwAutoTextEventDescriptor(
1204 SwXAutoTextEntry& rAutoText ) :
1205 SvBaseEventDescriptor(aAutotextEvents),
1206 sSwAutoTextEventDescriptor(RTL_CONSTASCII_USTRINGPARAM(
1207 "SwAutoTextEventDescriptor")),
1208 rAutoTextEntry(rAutoText)
1211 /* -----------------------------30.01.01 18:40--------------------------------
1213 ---------------------------------------------------------------------------*/
1214 SwAutoTextEventDescriptor::~SwAutoTextEventDescriptor()
1217 /* -----------------------------30.01.01 18:40--------------------------------
1219 ---------------------------------------------------------------------------*/
1220 OUString SwAutoTextEventDescriptor::getImplementationName()
1221 throw( uno::RuntimeException )
1223 return sSwAutoTextEventDescriptor;
1225 /* -----------------------------30.01.01 18:40--------------------------------
1227 ---------------------------------------------------------------------------*/
1228 void SwAutoTextEventDescriptor::replaceByName(
1229 const USHORT nEvent,
1230 const SvxMacro& rMacro)
1231 throw(
1232 lang::IllegalArgumentException,
1233 container::NoSuchElementException,
1234 lang::WrappedTargetException,
1235 uno::RuntimeException)
1237 DBG_ASSERT( NULL != rAutoTextEntry.GetGlossaries(),
1238 "Strangely enough, the AutoText vanished!" );
1239 DBG_ASSERT( (nEvent == SW_EVENT_END_INS_GLOSSARY) ||
1240 (nEvent == SW_EVENT_START_INS_GLOSSARY) ,
1241 "Unknown event ID" );
1243 const SwGlossaries* pGlossaries = rAutoTextEntry.GetGlossaries();
1244 SwTextBlocks* pBlocks =
1245 pGlossaries->GetGroupDoc( rAutoTextEntry.GetGroupName() );
1246 DBG_ASSERT( NULL != pBlocks,
1247 "can't get autotext group; SwAutoTextEntry has illegal name?");
1249 if( pBlocks && !pBlocks->GetError())
1251 USHORT nIndex = pBlocks->GetIndex( rAutoTextEntry.GetEntryName() );
1252 if( nIndex != USHRT_MAX )
1254 SvxMacroTableDtor aMacroTable;
1255 if( pBlocks->GetMacroTable( nIndex, aMacroTable ) )
1257 SvxMacro* pNewMacro = new SvxMacro(rMacro);
1258 aMacroTable.Replace( nEvent, pNewMacro );
1259 pBlocks->SetMacroTable( nIndex, aMacroTable );
1263 delete pBlocks;
1265 // else: ignore
1267 /* -----------------------------30.01.01 18:40--------------------------------
1269 ---------------------------------------------------------------------------*/
1270 void SwAutoTextEventDescriptor::getByName(
1271 SvxMacro& rMacro,
1272 const USHORT nEvent )
1273 throw(
1274 container::NoSuchElementException,
1275 lang::WrappedTargetException,
1276 uno::RuntimeException)
1278 DBG_ASSERT( NULL != rAutoTextEntry.GetGlossaries(), "no AutoText" );
1279 DBG_ASSERT( (nEvent == SW_EVENT_END_INS_GLOSSARY) ||
1280 (nEvent == SW_EVENT_START_INS_GLOSSARY) ,
1281 "Unknown event ID" );
1283 const SwGlossaries* pGlossaries = rAutoTextEntry.GetGlossaries();
1284 SwTextBlocks* pBlocks =
1285 pGlossaries->GetGroupDoc( rAutoTextEntry.GetGroupName() );
1286 DBG_ASSERT( NULL != pBlocks,
1287 "can't get autotext group; SwAutoTextEntry has illegal name?");
1289 // return empty macro, unless macro is found
1290 OUString sEmptyStr;
1291 SvxMacro aEmptyMacro(sEmptyStr, sEmptyStr);
1292 rMacro = aEmptyMacro;
1294 if ( pBlocks && !pBlocks->GetError())
1296 USHORT nIndex = pBlocks->GetIndex( rAutoTextEntry.GetEntryName() );
1297 if( nIndex != USHRT_MAX )
1299 SvxMacroTableDtor aMacroTable;
1300 if( pBlocks->GetMacroTable( nIndex, aMacroTable ) )
1302 SvxMacro *pMacro = aMacroTable.Get( nEvent );
1303 if( pMacro )
1304 rMacro = *pMacro;
1308 delete pBlocks;