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