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