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