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 <unoidx.hxx>
21 : #include <unoidxcoll.hxx>
22 :
23 : #include <com/sun/star/beans/PropertyAttribute.hpp>
24 : #include <com/sun/star/container/XIndexReplace.hpp>
25 : #include <com/sun/star/frame/XModel.hpp>
26 : #include <com/sun/star/text/ChapterFormat.hpp>
27 : #include <com/sun/star/text/ReferenceFieldPart.hpp>
28 : #include <com/sun/star/text/BibliographyDataField.hpp>
29 : #include <com/sun/star/text/XTextDocument.hpp>
30 :
31 : #include <osl/mutex.hxx>
32 : #include <cppuhelper/interfacecontainer.h>
33 : #include <vcl/svapp.hxx>
34 : #include <editeng/unolingu.hxx>
35 : #include <hints.hxx>
36 : #include <cmdid.h>
37 : #include <swtypes.hxx>
38 : #include <shellres.hxx>
39 : #include <viewsh.hxx>
40 : #include <doc.hxx>
41 : #include <docary.hxx>
42 : #include <poolfmt.hxx>
43 : #include <poolfmt.hrc>
44 : #include <pagedesc.hxx>
45 : #include <fmtcntnt.hxx>
46 : #include <unomap.hxx>
47 : #include <unotextrange.hxx>
48 : #include <unotextcursor.hxx>
49 : #include <unosection.hxx>
50 : #include <doctxm.hxx>
51 : #include <txttxmrk.hxx>
52 : #include <unocrsr.hxx>
53 : #include <unostyle.hxx>
54 : #include <ndtxt.hxx>
55 : #include <docsh.hxx>
56 : #include <chpfld.hxx>
57 : #include <SwStyleNameMapper.hxx>
58 : #include <comphelper/servicehelper.hxx>
59 : #include <comphelper/string.hxx>
60 :
61 :
62 : using namespace ::com::sun::star;
63 :
64 : static OUString
65 737 : lcl_AnyToString(uno::Any const& rVal) throw (lang::IllegalArgumentException)
66 : {
67 737 : OUString sRet;
68 737 : if(!(rVal >>= sRet))
69 : {
70 0 : throw lang::IllegalArgumentException();
71 : }
72 737 : return sRet;
73 : }
74 :
75 : static sal_Int16
76 6 : lcl_AnyToInt16(uno::Any const& rVal) throw (lang::IllegalArgumentException)
77 : {
78 6 : sal_Int16 nRet = 0;
79 6 : if(!(rVal >>= nRet))
80 : {
81 0 : throw lang::IllegalArgumentException();
82 : }
83 6 : return nRet;
84 : }
85 :
86 : static sal_Bool
87 204 : lcl_AnyToBool(uno::Any const& rVal) throw (lang::IllegalArgumentException)
88 : {
89 204 : sal_Bool bRet = sal_False;
90 204 : if(!(rVal >>= bRet))
91 : {
92 0 : throw lang::IllegalArgumentException();
93 : }
94 204 : return bRet;
95 : }
96 :
97 : static void
98 51 : lcl_AnyToBitMask(uno::Any const& rValue,
99 : sal_uInt16 & rBitMask, const sal_uInt16 nBit)
100 : throw (lang::IllegalArgumentException)
101 : {
102 51 : rBitMask = lcl_AnyToBool(rValue)
103 : ? (rBitMask | nBit)
104 51 : : (rBitMask & ~nBit);
105 51 : }
106 :
107 : static void
108 35 : lcl_BitMaskToAny(uno::Any & o_rValue,
109 : const sal_uInt16 nBitMask, const sal_uInt16 nBit)
110 : {
111 35 : const sal_Bool bRet = 0 != (nBitMask & nBit);
112 35 : o_rValue <<= bRet;
113 35 : }
114 :
115 : static void
116 0 : lcl_ReAssignTOXType(SwDoc* pDoc, SwTOXBase& rTOXBase, const OUString& rNewName)
117 : {
118 0 : const sal_uInt16 nUserCount = pDoc->GetTOXTypeCount( TOX_USER );
119 0 : const SwTOXType* pNewType = 0;
120 0 : for(sal_uInt16 nUser = 0; nUser < nUserCount; nUser++)
121 : {
122 0 : const SwTOXType* pType = pDoc->GetTOXType( TOX_USER, nUser );
123 0 : if(pType->GetTypeName().Equals((String)rNewName))
124 : {
125 0 : pNewType = pType;
126 0 : break;
127 : }
128 : }
129 0 : if(!pNewType)
130 : {
131 0 : SwTOXType aNewType(TOX_USER, rNewName);
132 0 : pNewType = pDoc->InsertTOXType( aNewType );
133 : }
134 :
135 0 : rTOXBase.RegisterToTOXType( *((SwTOXType*)pNewType) );
136 0 : }
137 :
138 : static const char cUserDefined[] = "User-Defined";
139 : static const char cUserSuffix[] = " (user)";
140 : #define USER_LEN 12
141 : #define USER_AND_SUFFIXLEN 19
142 :
143 1 : static void lcl_ConvertTOUNameToProgrammaticName(OUString& rTmp)
144 : {
145 1 : ShellResource* pShellRes = ViewShell::GetShellRes();
146 :
147 1 : if(rTmp.equals(pShellRes->aTOXUserName))
148 : {
149 1 : rTmp = cUserDefined;
150 : }
151 : // if the version is not English but the alternative index's name is
152 : // "User-Defined" a " (user)" is appended
153 0 : else if(rTmp.equalsAscii(cUserDefined))
154 : {
155 0 : rTmp += cUserSuffix;
156 : }
157 1 : }
158 :
159 : static void
160 2 : lcl_ConvertTOUNameToUserName(OUString& rTmp)
161 : {
162 2 : ShellResource* pShellRes = ViewShell::GetShellRes();
163 2 : if(rTmp.equalsAscii(cUserDefined))
164 : {
165 2 : rTmp = pShellRes->aTOXUserName;
166 : }
167 0 : else if(!pShellRes->aTOXUserName.EqualsAscii(cUserDefined) &&
168 0 : USER_AND_SUFFIXLEN == rTmp.getLength())
169 : {
170 : //make sure that in non-English versions the " (user)" suffix is removed
171 0 : if (rTmp.matchAsciiL(cUserDefined, sizeof(cUserDefined)) &&
172 0 : rTmp.matchAsciiL(cUserSuffix, sizeof(cUserSuffix), USER_LEN))
173 : {
174 0 : rTmp = cUserDefined;
175 : }
176 : }
177 2 : }
178 :
179 : typedef ::cppu::WeakImplHelper2
180 : < lang::XServiceInfo
181 : , container::XIndexReplace
182 : > SwXDocumentIndexStyleAccess_Base;
183 :
184 : class SwXDocumentIndex::StyleAccess_Impl
185 : : public SwXDocumentIndexStyleAccess_Base
186 : {
187 :
188 : private:
189 : /// can be destroyed threadsafely, so no UnoImplPtr here
190 : ::rtl::Reference<SwXDocumentIndex> m_xParent;
191 :
192 : virtual ~StyleAccess_Impl();
193 :
194 : public:
195 : StyleAccess_Impl(SwXDocumentIndex& rParentIdx);
196 :
197 : // XServiceInfo
198 : virtual OUString SAL_CALL getImplementationName()
199 : throw (uno::RuntimeException);
200 : virtual sal_Bool SAL_CALL
201 : supportsService(const OUString& rServiceName)
202 : throw (uno::RuntimeException);
203 : virtual uno::Sequence< OUString > SAL_CALL
204 : getSupportedServiceNames() throw (uno::RuntimeException);
205 :
206 : // XElementAccess
207 : virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException);
208 : virtual sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException);
209 :
210 : // XIndexAccess
211 : virtual sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException);
212 : virtual uno::Any SAL_CALL getByIndex(sal_Int32 nIndex)
213 : throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException,
214 : uno::RuntimeException);
215 :
216 : // XIndexReplace
217 : virtual void SAL_CALL
218 : replaceByIndex(sal_Int32 Index, const uno::Any& rElement)
219 : throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException,
220 : lang::WrappedTargetException, uno::RuntimeException);
221 :
222 : };
223 :
224 : typedef ::cppu::WeakImplHelper2
225 : < lang::XServiceInfo
226 : , container::XIndexReplace
227 : > SwXDocumentIndexTokenAccess_Base;
228 :
229 : class SwXDocumentIndex::TokenAccess_Impl
230 : : public SwXDocumentIndexTokenAccess_Base
231 : {
232 :
233 : private:
234 : /// can be destroyed threadsafely, so no UnoImplPtr here
235 : ::rtl::Reference<SwXDocumentIndex> m_xParent;
236 :
237 : virtual ~TokenAccess_Impl();
238 :
239 : public:
240 :
241 : TokenAccess_Impl(SwXDocumentIndex& rParentIdx);
242 :
243 : // XServiceInfo
244 : virtual OUString SAL_CALL getImplementationName()
245 : throw (uno::RuntimeException);
246 : virtual sal_Bool SAL_CALL
247 : supportsService(const OUString& rServiceName)
248 : throw (uno::RuntimeException);
249 : virtual uno::Sequence< OUString > SAL_CALL
250 : getSupportedServiceNames() throw (uno::RuntimeException);
251 :
252 : // XElementAccess
253 : virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException);
254 : virtual sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException);
255 :
256 : // XIndexAccess
257 : virtual sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException);
258 : virtual uno::Any SAL_CALL getByIndex(sal_Int32 nIndex)
259 : throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException,
260 : uno::RuntimeException);
261 :
262 : // XIndexReplace
263 : virtual void SAL_CALL
264 : replaceByIndex(sal_Int32 Index, const uno::Any& rElement)
265 : throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException,
266 : lang::WrappedTargetException, uno::RuntimeException);
267 :
268 : };
269 :
270 : /******************************************************************
271 : * SwXDocumentIndex
272 : ******************************************************************/
273 21 : class SwDocIndexDescriptorProperties_Impl
274 : {
275 : private:
276 : ::std::auto_ptr<SwTOXBase> m_pTOXBase;
277 : OUString m_sUserTOXTypeName;
278 :
279 : public:
280 : SwDocIndexDescriptorProperties_Impl(SwTOXType const*const pType);
281 :
282 44 : SwTOXBase & GetTOXBase() { return *m_pTOXBase; }
283 2 : const OUString& GetTypeName() const { return m_sUserTOXTypeName; }
284 0 : void SetTypeName(const OUString& rSet) { m_sUserTOXTypeName = rSet; }
285 : };
286 :
287 21 : SwDocIndexDescriptorProperties_Impl::SwDocIndexDescriptorProperties_Impl(
288 21 : SwTOXType const*const pType)
289 : {
290 21 : SwForm aForm(pType->GetType());
291 : m_pTOXBase.reset(new SwTOXBase(pType, aForm,
292 21 : nsSwTOXElement::TOX_MARK, pType->GetTypeName()));
293 21 : if(pType->GetType() == TOX_CONTENT || pType->GetType() == TOX_USER)
294 : {
295 7 : m_pTOXBase->SetLevel(MAXLEVEL);
296 : }
297 21 : m_sUserTOXTypeName = pType->GetTypeName();
298 21 : }
299 :
300 : static sal_uInt16
301 35 : lcl_TypeToPropertyMap_Index(const TOXTypes eType)
302 : {
303 35 : switch (eType)
304 : {
305 8 : case TOX_INDEX: return PROPERTY_MAP_INDEX_IDX;
306 7 : case TOX_CONTENT: return PROPERTY_MAP_INDEX_CNTNT;
307 4 : case TOX_TABLES: return PROPERTY_MAP_INDEX_TABLES;
308 4 : case TOX_ILLUSTRATIONS: return PROPERTY_MAP_INDEX_ILLUSTRATIONS;
309 4 : case TOX_OBJECTS: return PROPERTY_MAP_INDEX_OBJECTS;
310 4 : case TOX_AUTHORITIES: return PROPERTY_MAP_BIBLIOGRAPHY;
311 : //case TOX_USER:
312 : default:
313 4 : return PROPERTY_MAP_INDEX_USER;
314 : }
315 : }
316 :
317 70 : class SwXDocumentIndex::Impl
318 : : public SwClient
319 : {
320 : private:
321 : ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper
322 :
323 : public:
324 : SwXDocumentIndex & m_rThis;
325 : ::cppu::OMultiTypeInterfaceContainerHelper m_Listeners;
326 : SfxItemPropertySet const& m_rPropSet;
327 : const TOXTypes m_eTOXType;
328 : bool m_bIsDescriptor;
329 : SwDoc * m_pDoc;
330 : ::std::auto_ptr<SwDocIndexDescriptorProperties_Impl> m_pProps;
331 : uno::WeakReference<container::XIndexReplace> m_wStyleAccess;
332 : uno::WeakReference<container::XIndexReplace> m_wTokenAccess;
333 :
334 35 : Impl( SwXDocumentIndex & rThis,
335 : SwDoc & rDoc,
336 : const TOXTypes eType,
337 : SwTOXBaseSection const*const pBaseSection)
338 14 : : SwClient((pBaseSection) ? pBaseSection->GetFmt() : 0)
339 : , m_rThis(rThis)
340 : , m_Listeners(m_Mutex)
341 : , m_rPropSet(
342 35 : *aSwMapProvider.GetPropertySet(lcl_TypeToPropertyMap_Index(eType)))
343 : , m_eTOXType(eType)
344 : // #i111177# unxsols4 (Sun C++ 5.9 SunOS_sparc) may generate wrong code
345 : , m_bIsDescriptor((0 == pBaseSection) ? true : false)
346 : , m_pDoc(&rDoc)
347 : , m_pProps((m_bIsDescriptor)
348 21 : ? new SwDocIndexDescriptorProperties_Impl(rDoc.GetTOXType(eType, 0))
349 105 : : 0)
350 : {
351 35 : }
352 :
353 1009 : SwSectionFmt * GetSectionFmt() const {
354 : return static_cast<SwSectionFmt *>(
355 1009 : const_cast<SwModify *>(GetRegisteredIn()));
356 : }
357 :
358 412 : SwTOXBase & GetTOXSectionOrThrow() const
359 : {
360 412 : SwSectionFmt *const pSectionFmt(GetSectionFmt());
361 : SwTOXBase *const pTOXSection( (m_bIsDescriptor)
362 2 : ? &m_pProps->GetTOXBase()
363 : : ((pSectionFmt)
364 410 : ? static_cast<SwTOXBaseSection*>(pSectionFmt->GetSection())
365 824 : : 0));
366 412 : if (!pTOXSection)
367 : {
368 : throw uno::RuntimeException(OUString(
369 0 : "SwXDocumentIndex: disposed or invalid"), 0);
370 : }
371 412 : return *pTOXSection;
372 : }
373 :
374 21 : sal_Int32 GetFormMax() const
375 : {
376 21 : SwTOXBase & rSection( GetTOXSectionOrThrow() );
377 : return (m_bIsDescriptor)
378 0 : ? SwForm::GetFormMaxLevel(m_eTOXType)
379 21 : : rSection.GetTOXForm().GetFormMax();
380 : }
381 : protected:
382 : // SwClient
383 : virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew);
384 :
385 : };
386 :
387 81 : void SwXDocumentIndex::Impl::Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew)
388 : {
389 81 : ClientModify(this, pOld, pNew);
390 :
391 81 : if (!GetRegisteredIn())
392 : {
393 20 : lang::EventObject const ev(static_cast< ::cppu::OWeakObject&>(m_rThis));
394 20 : m_Listeners.disposeAndClear(ev);
395 : }
396 81 : }
397 :
398 14 : SwXDocumentIndex::SwXDocumentIndex(
399 : SwTOXBaseSection const& rBaseSection, SwDoc & rDoc)
400 : : m_pImpl( new SwXDocumentIndex::Impl( *this,
401 14 : rDoc, rBaseSection.SwTOXBase::GetType(), & rBaseSection) )
402 : {
403 14 : }
404 :
405 21 : SwXDocumentIndex::SwXDocumentIndex(const TOXTypes eType, SwDoc& rDoc)
406 21 : : m_pImpl( new SwXDocumentIndex::Impl( *this, rDoc, eType, 0) )
407 : {
408 21 : }
409 :
410 70 : SwXDocumentIndex::~SwXDocumentIndex()
411 : {
412 70 : }
413 :
414 : uno::Reference<text::XDocumentIndex>
415 46 : SwXDocumentIndex::CreateXDocumentIndex(
416 : SwDoc & rDoc, SwTOXBaseSection const& rSection)
417 : {
418 : // re-use existing SwXDocumentIndex
419 : // #i105557#: do not iterate over the registered clients: race condition
420 46 : SwSectionFmt *const pFmt = rSection.GetFmt();
421 46 : uno::Reference<text::XDocumentIndex> xIndex(pFmt->GetXObject(),
422 46 : uno::UNO_QUERY);
423 46 : if (!xIndex.is())
424 : {
425 14 : SwXDocumentIndex *const pIndex(new SwXDocumentIndex(rSection, rDoc));
426 14 : xIndex.set(pIndex);
427 14 : pFmt->SetXObject(uno::Reference<uno::XInterface>(xIndex));
428 : }
429 46 : return xIndex;
430 : }
431 :
432 : namespace
433 : {
434 : class theSwXDocumentIndexUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXDocumentIndexUnoTunnelId > {};
435 : }
436 :
437 121 : const uno::Sequence< sal_Int8 > & SwXDocumentIndex::getUnoTunnelId()
438 : {
439 121 : return theSwXDocumentIndexUnoTunnelId::get().getSeq();
440 : }
441 :
442 : sal_Int64 SAL_CALL
443 121 : SwXDocumentIndex::getSomething(const uno::Sequence< sal_Int8 >& rId)
444 : throw (uno::RuntimeException)
445 : {
446 121 : return ::sw::UnoTunnelImpl<SwXDocumentIndex>(rId, this);
447 : }
448 :
449 : OUString SAL_CALL
450 0 : SwXDocumentIndex::getImplementationName() throw (uno::RuntimeException)
451 : {
452 0 : return OUString("SwXDocumentIndex");
453 : }
454 :
455 : sal_Bool SAL_CALL
456 2 : SwXDocumentIndex::supportsService(const OUString& rServiceName)
457 : throw (uno::RuntimeException)
458 : {
459 2 : SolarMutexGuard g;
460 :
461 2 : return rServiceName == "com.sun.star.text.BaseIndex"
462 1 : || ((TOX_INDEX == m_pImpl->m_eTOXType) && rServiceName == "com.sun.star.text.DocumentIndex")
463 0 : || ((TOX_CONTENT == m_pImpl->m_eTOXType) && rServiceName == "com.sun.star.text.ContentIndex")
464 0 : || ((TOX_USER == m_pImpl->m_eTOXType) && rServiceName == "com.sun.star.text.UserDefinedIndex")
465 0 : || ((TOX_ILLUSTRATIONS == m_pImpl->m_eTOXType) && rServiceName == "com.sun.star.text.IllustrationsIndex")
466 0 : || ((TOX_TABLES == m_pImpl->m_eTOXType) && rServiceName == "com.sun.star.text.TableIndex")
467 0 : || ((TOX_OBJECTS == m_pImpl->m_eTOXType) && rServiceName == "com.sun.star.text.ObjectIndex")
468 2 : || ((TOX_AUTHORITIES == m_pImpl->m_eTOXType) && rServiceName == "com.sun.star.text.Bibliography");
469 : }
470 :
471 : uno::Sequence< OUString > SAL_CALL
472 0 : SwXDocumentIndex::getSupportedServiceNames() throw (uno::RuntimeException)
473 : {
474 0 : SolarMutexGuard g;
475 :
476 0 : uno::Sequence< OUString > aRet(2);
477 0 : OUString* pArray = aRet.getArray();
478 0 : pArray[0] = "com.sun.star.text.BaseIndex";
479 0 : switch (m_pImpl->m_eTOXType)
480 : {
481 : case TOX_INDEX:
482 0 : pArray[1] = "com.sun.star.text.DocumentIndex";
483 0 : break;
484 : case TOX_CONTENT:
485 0 : pArray[1] = "com.sun.star.text.ContentIndex";
486 0 : break;
487 : case TOX_TABLES:
488 0 : pArray[1] = "com.sun.star.text.TableIndex";
489 0 : break;
490 : case TOX_ILLUSTRATIONS:
491 0 : pArray[1] = "com.sun.star.text.IllustrationsIndex";
492 0 : break;
493 : case TOX_OBJECTS:
494 0 : pArray[1] = "com.sun.star.text.ObjectIndex";
495 0 : break;
496 : case TOX_AUTHORITIES:
497 0 : pArray[1] = "com.sun.star.text.Bibliography";
498 0 : break;
499 : //case TOX_USER:
500 : default:
501 0 : pArray[1] = "com.sun.star.text.UserDefinedIndex";
502 : }
503 0 : return aRet;
504 : }
505 :
506 15 : OUString SAL_CALL SwXDocumentIndex::getServiceName()
507 : throw (uno::RuntimeException)
508 : {
509 15 : SolarMutexGuard g;
510 :
511 15 : sal_uInt16 nObjectType = SW_SERVICE_TYPE_INDEX;
512 15 : switch (m_pImpl->m_eTOXType)
513 : {
514 : // case TOX_INDEX: break;
515 2 : case TOX_USER: nObjectType = SW_SERVICE_USER_INDEX;
516 2 : break;
517 2 : case TOX_CONTENT: nObjectType = SW_SERVICE_CONTENT_INDEX;
518 2 : break;
519 2 : case TOX_ILLUSTRATIONS: nObjectType = SW_SERVICE_INDEX_ILLUSTRATIONS;
520 2 : break;
521 2 : case TOX_OBJECTS: nObjectType = SW_SERVICE_INDEX_OBJECTS;
522 2 : break;
523 2 : case TOX_TABLES: nObjectType = SW_SERVICE_INDEX_TABLES;
524 2 : break;
525 2 : case TOX_AUTHORITIES: nObjectType = SW_SERVICE_INDEX_BIBLIOGRAPHY;
526 2 : break;
527 : default:
528 3 : break;
529 : }
530 15 : return SwXServiceProvider::GetProviderName(nObjectType);
531 : }
532 :
533 3 : void SAL_CALL SwXDocumentIndex::update() throw (uno::RuntimeException)
534 : {
535 3 : return refresh(); // update is from deprecated XDocumentIndex
536 : }
537 :
538 : uno::Reference< beans::XPropertySetInfo > SAL_CALL
539 90 : SwXDocumentIndex::getPropertySetInfo() throw (uno::RuntimeException)
540 : {
541 90 : SolarMutexGuard g;
542 :
543 : const uno::Reference< beans::XPropertySetInfo > xRef =
544 90 : m_pImpl->m_rPropSet.getPropertySetInfo();
545 90 : return xRef;
546 : }
547 :
548 : void SAL_CALL
549 213 : SwXDocumentIndex::setPropertyValue(
550 : const OUString& rPropertyName, const uno::Any& rValue)
551 : throw (beans::UnknownPropertyException, beans::PropertyVetoException,
552 : lang::IllegalArgumentException, lang::WrappedTargetException,
553 : uno::RuntimeException)
554 : {
555 213 : SolarMutexGuard aGuard;
556 :
557 : SfxItemPropertySimpleEntry const*const pEntry =
558 213 : m_pImpl->m_rPropSet.getPropertyMap().getByName(rPropertyName);
559 213 : if (!pEntry)
560 : {
561 : throw beans::UnknownPropertyException(
562 : OUString("Unknown property: ")
563 0 : + rPropertyName,
564 0 : static_cast<cppu::OWeakObject *>(this));
565 : }
566 213 : if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
567 : {
568 : throw beans::PropertyVetoException(
569 : OUString("Property is read-only: " )
570 4 : + rPropertyName,
571 6 : static_cast<cppu::OWeakObject *>(this));
572 : }
573 :
574 211 : SwSectionFmt *const pSectionFmt(m_pImpl->GetSectionFmt());
575 211 : SwTOXBase & rTOXBase( m_pImpl->GetTOXSectionOrThrow() );
576 :
577 211 : sal_uInt16 nCreate = rTOXBase.GetCreateType();
578 211 : sal_uInt16 nTOIOptions = 0;
579 211 : sal_uInt16 nOLEOptions = rTOXBase.GetOLEOptions();
580 211 : const TOXTypes eTxBaseType = rTOXBase.GetTOXType()->GetType();
581 211 : if (eTxBaseType == TOX_INDEX)
582 : {
583 67 : nTOIOptions = rTOXBase.GetOptions();
584 : }
585 422 : SwForm aForm(rTOXBase.GetTOXForm());
586 211 : bool bForm = false;
587 211 : switch (pEntry->nWID)
588 : {
589 : case WID_IDX_TITLE:
590 : {
591 15 : OUString sNewName;
592 15 : if (!(rValue >>= sNewName))
593 : {
594 0 : throw lang::IllegalArgumentException();
595 : }
596 15 : rTOXBase.SetTitle(sNewName);
597 : }
598 15 : break;
599 : case WID_IDX_NAME:
600 : {
601 14 : OUString sNewName;
602 14 : if (!(rValue >>= sNewName))
603 : {
604 0 : throw lang::IllegalArgumentException();
605 : }
606 14 : rTOXBase.SetTOXName(sNewName);
607 : }
608 14 : break;
609 : case WID_USER_IDX_NAME:
610 : {
611 2 : OUString sNewName;
612 2 : if (!(rValue >>= sNewName))
613 : {
614 0 : throw lang::IllegalArgumentException();
615 : }
616 2 : lcl_ConvertTOUNameToUserName(sNewName);
617 : OSL_ENSURE(TOX_USER == eTxBaseType,
618 : "tox type name can only be changed for user indexes");
619 2 : if (pSectionFmt)
620 : {
621 2 : OUString sTmp = rTOXBase.GetTOXType()->GetTypeName();
622 2 : if (sTmp != sNewName)
623 : {
624 : lcl_ReAssignTOXType(pSectionFmt->GetDoc(),
625 0 : rTOXBase, sNewName);
626 2 : }
627 : }
628 : else
629 : {
630 0 : m_pImpl->m_pProps->SetTypeName(sNewName);
631 2 : }
632 : }
633 2 : break;
634 : case WID_IDX_LOCALE:
635 : {
636 3 : lang::Locale aLocale;
637 3 : if (!(rValue>>= aLocale))
638 : {
639 0 : throw lang::IllegalArgumentException();
640 : }
641 3 : rTOXBase.SetLanguage( LanguageTag(aLocale).getLanguageType());
642 : }
643 3 : break;
644 : case WID_IDX_SORT_ALGORITHM:
645 : {
646 3 : OUString sTmp;
647 3 : if (!(rValue >>= sTmp))
648 : {
649 0 : throw lang::IllegalArgumentException();
650 : }
651 3 : rTOXBase.SetSortAlgorithm(sTmp);
652 : }
653 3 : break;
654 : case WID_LEVEL:
655 : {
656 2 : rTOXBase.SetLevel(lcl_AnyToInt16(rValue));
657 : }
658 2 : break;
659 : case WID_CREATE_FROM_MARKS:
660 4 : lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_MARK);
661 4 : break;
662 : case WID_CREATE_FROM_OUTLINE:
663 4 : lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_OUTLINELEVEL);
664 4 : break;
665 : // case WID_PARAGRAPH_STYLE_NAMES :OSL_FAIL("not implemented")
666 : // break;
667 : case WID_CREATE_FROM_CHAPTER:
668 13 : rTOXBase.SetFromChapter(lcl_AnyToBool(rValue));
669 13 : break;
670 : case WID_CREATE_FROM_LABELS:
671 4 : rTOXBase.SetFromObjectNames(! lcl_AnyToBool(rValue));
672 4 : break;
673 : case WID_PROTECTED:
674 : {
675 15 : sal_Bool bSet = lcl_AnyToBool(rValue);
676 15 : rTOXBase.SetProtected(bSet);
677 15 : if (pSectionFmt)
678 : {
679 15 : static_cast<SwTOXBaseSection &>(rTOXBase).SetProtect(bSet);
680 : }
681 : }
682 15 : break;
683 : case WID_USE_ALPHABETICAL_SEPARATORS:
684 : lcl_AnyToBitMask(rValue, nTOIOptions,
685 3 : nsSwTOIOptions::TOI_ALPHA_DELIMITTER);
686 3 : break;
687 : case WID_USE_KEY_AS_ENTRY:
688 : lcl_AnyToBitMask(rValue, nTOIOptions,
689 3 : nsSwTOIOptions::TOI_KEY_AS_ENTRY);
690 3 : break;
691 : case WID_USE_COMBINED_ENTRIES:
692 : lcl_AnyToBitMask(rValue, nTOIOptions,
693 3 : nsSwTOIOptions::TOI_SAME_ENTRY);
694 3 : break;
695 : case WID_IS_CASE_SENSITIVE:
696 : lcl_AnyToBitMask(rValue, nTOIOptions,
697 3 : nsSwTOIOptions::TOI_CASE_SENSITIVE);
698 3 : break;
699 : case WID_USE_P_P:
700 3 : lcl_AnyToBitMask(rValue, nTOIOptions, nsSwTOIOptions::TOI_FF);
701 3 : break;
702 : case WID_USE_DASH:
703 3 : lcl_AnyToBitMask(rValue, nTOIOptions, nsSwTOIOptions::TOI_DASH);
704 3 : break;
705 : case WID_USE_UPPER_CASE:
706 : lcl_AnyToBitMask(rValue, nTOIOptions,
707 3 : nsSwTOIOptions::TOI_INITIAL_CAPS);
708 3 : break;
709 : case WID_IS_COMMA_SEPARATED:
710 2 : bForm = true;
711 2 : aForm.SetCommaSeparated(lcl_AnyToBool(rValue));
712 2 : break;
713 : case WID_LABEL_CATEGORY:
714 : {
715 : // convert file-format/API/external programmatic english name
716 : // to internal UI name before usage
717 : String aName( SwStyleNameMapper::GetSpecialExtraUIName(
718 4 : lcl_AnyToString(rValue) ) );
719 4 : rTOXBase.SetSequenceName( aName );
720 : }
721 4 : break;
722 : case WID_LABEL_DISPLAY_TYPE:
723 : {
724 4 : const sal_Int16 nVal = lcl_AnyToInt16(rValue);
725 4 : sal_uInt16 nSet = CAPTION_COMPLETE;
726 4 : switch (nVal)
727 : {
728 : case text::ReferenceFieldPart::TEXT:
729 4 : nSet = CAPTION_COMPLETE;
730 4 : break;
731 : case text::ReferenceFieldPart::CATEGORY_AND_NUMBER:
732 0 : nSet = CAPTION_NUMBER;
733 0 : break;
734 : case text::ReferenceFieldPart::ONLY_CAPTION:
735 0 : nSet = CAPTION_TEXT;
736 0 : break;
737 : default:
738 0 : throw lang::IllegalArgumentException();
739 : }
740 4 : rTOXBase.SetCaptionDisplay(static_cast<SwCaptionDisplay>(nSet));
741 : }
742 4 : break;
743 : case WID_USE_LEVEL_FROM_SOURCE:
744 2 : rTOXBase.SetLevelFromChapter(lcl_AnyToBool(rValue));
745 2 : break;
746 : case WID_MAIN_ENTRY_CHARACTER_STYLE_NAME:
747 : {
748 1 : String aString;
749 : SwStyleNameMapper::FillUIName(lcl_AnyToString(rValue),
750 1 : aString, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true);
751 1 : rTOXBase.SetMainEntryCharStyle( aString );
752 : }
753 1 : break;
754 : case WID_CREATE_FROM_TABLES:
755 2 : lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_TABLE);
756 2 : break;
757 : case WID_CREATE_FROM_TEXT_FRAMES:
758 2 : lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_FRAME);
759 2 : break;
760 : case WID_CREATE_FROM_GRAPHIC_OBJECTS:
761 2 : lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_GRAPHIC);
762 2 : break;
763 : case WID_CREATE_FROM_EMBEDDED_OBJECTS:
764 2 : lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_OLE);
765 2 : break;
766 : case WID_CREATE_FROM_STAR_MATH:
767 2 : lcl_AnyToBitMask(rValue, nOLEOptions, nsSwTOOElements::TOO_MATH);
768 2 : break;
769 : case WID_CREATE_FROM_STAR_CHART:
770 2 : lcl_AnyToBitMask(rValue, nOLEOptions, nsSwTOOElements::TOO_CHART);
771 2 : break;
772 : case WID_CREATE_FROM_STAR_CALC:
773 2 : lcl_AnyToBitMask(rValue, nOLEOptions, nsSwTOOElements::TOO_CALC);
774 2 : break;
775 : case WID_CREATE_FROM_STAR_DRAW:
776 : lcl_AnyToBitMask(rValue, nOLEOptions,
777 2 : nsSwTOOElements::TOO_DRAW_IMPRESS);
778 2 : break;
779 : case WID_CREATE_FROM_OTHER_EMBEDDED_OBJECTS:
780 2 : lcl_AnyToBitMask(rValue, nOLEOptions, nsSwTOOElements::TOO_OTHER);
781 2 : break;
782 : case WID_PARA_HEAD:
783 : {
784 15 : String aString;
785 : SwStyleNameMapper::FillUIName( lcl_AnyToString(rValue),
786 15 : aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, true);
787 15 : bForm = true;
788 : // Header is on Pos 0
789 15 : aForm.SetTemplate( 0, aString );
790 : }
791 15 : break;
792 : case WID_IS_RELATIVE_TABSTOPS:
793 12 : bForm = true;
794 12 : aForm.SetRelTabPos(lcl_AnyToBool(rValue));
795 12 : break;
796 : case WID_PARA_SEP:
797 : {
798 1 : String aString;
799 1 : bForm = true;
800 : SwStyleNameMapper::FillUIName( lcl_AnyToString(rValue),
801 1 : aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, true);
802 1 : aForm.SetTemplate( 1, aString );
803 : }
804 1 : break;
805 : case WID_CREATE_FROM_PARAGRAPH_STYLES:
806 4 : lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_TEMPLATE);
807 4 : break;
808 :
809 : case WID_PARA_LEV1:
810 : case WID_PARA_LEV2:
811 : case WID_PARA_LEV3:
812 : case WID_PARA_LEV4:
813 : case WID_PARA_LEV5:
814 : case WID_PARA_LEV6:
815 : case WID_PARA_LEV7:
816 : case WID_PARA_LEV8:
817 : case WID_PARA_LEV9:
818 : case WID_PARA_LEV10:
819 : {
820 3 : bForm = true;
821 : // in sdbcx::Index Label 1 begins at Pos 2 otherwise at Pos 1
822 3 : const sal_uInt16 nLPos = rTOXBase.GetType() == TOX_INDEX ? 2 : 1;
823 3 : String aString;
824 : SwStyleNameMapper::FillUIName( lcl_AnyToString(rValue),
825 3 : aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, true);
826 3 : aForm.SetTemplate(nLPos + pEntry->nWID - WID_PARA_LEV1, aString );
827 : }
828 3 : break;
829 : default:
830 : //this is for items only
831 45 : if (WID_PRIMARY_KEY > pEntry->nWID)
832 : {
833 : const SwAttrSet& rSet =
834 44 : m_pImpl->m_pDoc->GetTOXBaseAttrSet(rTOXBase);
835 44 : SfxItemSet aAttrSet(rSet);
836 44 : m_pImpl->m_rPropSet.setPropertyValue(
837 44 : rPropertyName, rValue, aAttrSet);
838 :
839 44 : const SwSectionFmts& rSects = m_pImpl->m_pDoc->GetSections();
840 284 : for (sal_uInt16 i = 0; i < rSects.size(); i++)
841 : {
842 284 : const SwSectionFmt* pTmpFmt = rSects[ i ];
843 284 : if (pTmpFmt == pSectionFmt)
844 : {
845 : SwSectionData tmpData(
846 44 : static_cast<SwTOXBaseSection&>(rTOXBase));
847 44 : m_pImpl->m_pDoc->UpdateSection(i, tmpData, & aAttrSet);
848 44 : break;
849 : }
850 44 : }
851 : }
852 : }
853 211 : rTOXBase.SetCreate(nCreate);
854 211 : rTOXBase.SetOLEOptions(nOLEOptions);
855 211 : if (rTOXBase.GetTOXType()->GetType() == TOX_INDEX)
856 : {
857 67 : rTOXBase.SetOptions(nTOIOptions);
858 : }
859 211 : if (bForm)
860 : {
861 33 : rTOXBase.SetTOXForm(aForm);
862 213 : }
863 211 : }
864 :
865 : uno::Any SAL_CALL
866 341 : SwXDocumentIndex::getPropertyValue(const OUString& rPropertyName)
867 : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
868 : uno::RuntimeException)
869 : {
870 341 : SolarMutexGuard aGuard;
871 :
872 341 : uno::Any aRet;
873 : SfxItemPropertySimpleEntry const*const pEntry =
874 341 : m_pImpl->m_rPropSet.getPropertyMap().getByName(rPropertyName);
875 341 : if (!pEntry)
876 : {
877 : throw beans::UnknownPropertyException(
878 : OUString("Unknown property: ")
879 0 : + rPropertyName,
880 0 : static_cast< cppu::OWeakObject * >(this));
881 : }
882 :
883 341 : SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() );
884 341 : SwTOXBase* pTOXBase = 0;
885 341 : if (pSectionFmt)
886 : {
887 341 : pTOXBase = static_cast<SwTOXBaseSection*>(pSectionFmt->GetSection());
888 : }
889 0 : else if (m_pImpl->m_bIsDescriptor)
890 : {
891 0 : pTOXBase = &m_pImpl->m_pProps->GetTOXBase();
892 : }
893 341 : if(pTOXBase)
894 : {
895 341 : const sal_uInt16 nCreate = pTOXBase->GetCreateType();
896 341 : const sal_uInt16 nOLEOptions = pTOXBase->GetOLEOptions();
897 : const sal_uInt16 nTOIOptions =
898 341 : (pTOXBase->GetTOXType()->GetType() == TOX_INDEX)
899 : ? pTOXBase->GetOptions()
900 341 : : 0U;
901 341 : const SwForm& rForm = pTOXBase->GetTOXForm();
902 341 : switch(pEntry->nWID)
903 : {
904 : case WID_IDX_CONTENT_SECTION:
905 : case WID_IDX_HEADER_SECTION :
906 59 : if(WID_IDX_CONTENT_SECTION == pEntry->nWID)
907 : {
908 : const uno::Reference <text::XTextSection> xContentSect =
909 30 : SwXTextSection::CreateXTextSection( pSectionFmt );
910 30 : aRet <<= xContentSect;
911 : }
912 : else
913 : {
914 29 : SwSections aSectArr;
915 : pSectionFmt->GetChildSections(aSectArr,
916 29 : SORTSECT_NOT, sal_False);
917 29 : for(sal_uInt16 i = 0; i < aSectArr.size(); i++)
918 : {
919 28 : SwSection* pSect = aSectArr[i];
920 28 : if(pSect->GetType() == TOX_HEADER_SECTION)
921 : {
922 : const uno::Reference <text::XTextSection> xHeader =
923 : SwXTextSection::CreateXTextSection(
924 28 : pSect->GetFmt() );
925 28 : aRet <<= xHeader;
926 28 : break;
927 : }
928 29 : }
929 : }
930 59 : break;
931 : case WID_IDX_TITLE :
932 : {
933 9 : OUString uRet(pTOXBase->GetTitle());
934 9 : aRet <<= uRet;
935 9 : break;
936 : }
937 : case WID_IDX_NAME:
938 7 : aRet <<= OUString(pTOXBase->GetTOXName());
939 7 : break;
940 : case WID_USER_IDX_NAME:
941 : {
942 1 : OUString sTmp;
943 1 : if (!m_pImpl->m_bIsDescriptor)
944 : {
945 1 : sTmp = pTOXBase->GetTOXType()->GetTypeName();
946 : }
947 : else
948 : {
949 0 : sTmp = m_pImpl->m_pProps->GetTypeName();
950 : }
951 : //I18N
952 1 : lcl_ConvertTOUNameToProgrammaticName(sTmp);
953 1 : aRet <<= sTmp;
954 : }
955 1 : break;
956 : case WID_IDX_LOCALE:
957 3 : aRet <<= LanguageTag(pTOXBase->GetLanguage()).getLocale();
958 3 : break;
959 : case WID_IDX_SORT_ALGORITHM:
960 3 : aRet <<= OUString(pTOXBase->GetSortAlgorithm());
961 3 : break;
962 : case WID_LEVEL :
963 1 : aRet <<= static_cast<sal_Int16>(pTOXBase->GetLevel());
964 1 : break;
965 : case WID_CREATE_FROM_MARKS:
966 2 : lcl_BitMaskToAny(aRet, nCreate, nsSwTOXElement::TOX_MARK);
967 2 : break;
968 : case WID_CREATE_FROM_OUTLINE:
969 : lcl_BitMaskToAny(aRet, nCreate,
970 1 : nsSwTOXElement::TOX_OUTLINELEVEL);
971 1 : break;
972 : case WID_CREATE_FROM_CHAPTER:
973 : {
974 8 : const sal_Bool bRet = pTOXBase->IsFromChapter();
975 8 : aRet <<= bRet;
976 : }
977 8 : break;
978 : case WID_CREATE_FROM_LABELS:
979 : {
980 2 : const sal_Bool bRet = ! pTOXBase->IsFromObjectNames();
981 2 : aRet <<= bRet;
982 : }
983 2 : break;
984 : case WID_PROTECTED:
985 : {
986 9 : const sal_Bool bRet = pTOXBase->IsProtected();
987 9 : aRet <<= bRet;
988 : }
989 9 : break;
990 : case WID_USE_ALPHABETICAL_SEPARATORS:
991 : lcl_BitMaskToAny(aRet, nTOIOptions,
992 3 : nsSwTOIOptions::TOI_ALPHA_DELIMITTER);
993 3 : break;
994 : case WID_USE_KEY_AS_ENTRY:
995 : lcl_BitMaskToAny(aRet, nTOIOptions,
996 3 : nsSwTOIOptions::TOI_KEY_AS_ENTRY);
997 3 : break;
998 : case WID_USE_COMBINED_ENTRIES:
999 : lcl_BitMaskToAny(aRet, nTOIOptions,
1000 3 : nsSwTOIOptions::TOI_SAME_ENTRY);
1001 3 : break;
1002 : case WID_IS_CASE_SENSITIVE:
1003 : lcl_BitMaskToAny(aRet, nTOIOptions,
1004 3 : nsSwTOIOptions::TOI_CASE_SENSITIVE);
1005 3 : break;
1006 : case WID_USE_P_P:
1007 3 : lcl_BitMaskToAny(aRet, nTOIOptions, nsSwTOIOptions::TOI_FF);
1008 3 : break;
1009 : case WID_USE_DASH:
1010 3 : lcl_BitMaskToAny(aRet, nTOIOptions, nsSwTOIOptions::TOI_DASH);
1011 3 : break;
1012 : case WID_USE_UPPER_CASE:
1013 : lcl_BitMaskToAny(aRet, nTOIOptions,
1014 3 : nsSwTOIOptions::TOI_INITIAL_CAPS);
1015 3 : break;
1016 : case WID_IS_COMMA_SEPARATED:
1017 : {
1018 1 : const sal_Bool bRet = rForm.IsCommaSeparated();
1019 1 : aRet <<= bRet;
1020 : }
1021 1 : break;
1022 : case WID_LABEL_CATEGORY:
1023 : {
1024 : // convert internal UI name to
1025 : // file-format/API/external programmatic english name
1026 : // before usage
1027 : String aName( SwStyleNameMapper::GetSpecialExtraProgName(
1028 2 : pTOXBase->GetSequenceName() ) );
1029 2 : aRet <<= OUString( aName );
1030 : }
1031 2 : break;
1032 : case WID_LABEL_DISPLAY_TYPE:
1033 : {
1034 2 : sal_Int16 nSet = text::ReferenceFieldPart::TEXT;
1035 2 : switch (pTOXBase->GetCaptionDisplay())
1036 : {
1037 : case CAPTION_COMPLETE:
1038 2 : nSet = text::ReferenceFieldPart::TEXT;
1039 2 : break;
1040 : case CAPTION_NUMBER:
1041 0 : nSet = text::ReferenceFieldPart::CATEGORY_AND_NUMBER;
1042 0 : break;
1043 : case CAPTION_TEXT:
1044 0 : nSet = text::ReferenceFieldPart::ONLY_CAPTION;
1045 0 : break;
1046 : }
1047 2 : aRet <<= nSet;
1048 : }
1049 2 : break;
1050 : case WID_USE_LEVEL_FROM_SOURCE:
1051 : {
1052 1 : const sal_Bool bRet = pTOXBase->IsLevelFromChapter();
1053 1 : aRet <<= bRet;
1054 : }
1055 1 : break;
1056 : case WID_LEVEL_FORMAT:
1057 : {
1058 : uno::Reference< container::XIndexReplace > xTokenAccess(
1059 107 : m_pImpl->m_wTokenAccess);
1060 107 : if (!xTokenAccess.is())
1061 : {
1062 106 : xTokenAccess = new TokenAccess_Impl(*this);
1063 106 : m_pImpl->m_wTokenAccess = xTokenAccess;
1064 : }
1065 107 : aRet <<= xTokenAccess;
1066 : }
1067 107 : break;
1068 : case WID_LEVEL_PARAGRAPH_STYLES:
1069 : {
1070 : uno::Reference< container::XIndexReplace > xStyleAccess(
1071 2 : m_pImpl->m_wStyleAccess);
1072 2 : if (!xStyleAccess.is())
1073 : {
1074 2 : xStyleAccess = new StyleAccess_Impl(*this);
1075 2 : m_pImpl->m_wStyleAccess = xStyleAccess;
1076 : }
1077 2 : aRet <<= xStyleAccess;
1078 : }
1079 2 : break;
1080 : case WID_MAIN_ENTRY_CHARACTER_STYLE_NAME:
1081 : {
1082 3 : String aString;
1083 : SwStyleNameMapper::FillProgName(
1084 3 : pTOXBase->GetMainEntryCharStyle(),
1085 : aString,
1086 : nsSwGetPoolIdFromName::GET_POOLID_CHRFMT,
1087 3 : true);
1088 3 : aRet <<= OUString( aString );
1089 : }
1090 3 : break;
1091 : case WID_CREATE_FROM_TABLES:
1092 1 : lcl_BitMaskToAny(aRet, nCreate, nsSwTOXElement::TOX_TABLE);
1093 1 : break;
1094 : case WID_CREATE_FROM_TEXT_FRAMES:
1095 1 : lcl_BitMaskToAny(aRet, nCreate, nsSwTOXElement::TOX_FRAME);
1096 1 : break;
1097 : case WID_CREATE_FROM_GRAPHIC_OBJECTS:
1098 1 : lcl_BitMaskToAny(aRet, nCreate, nsSwTOXElement::TOX_GRAPHIC);
1099 1 : break;
1100 : case WID_CREATE_FROM_EMBEDDED_OBJECTS:
1101 1 : lcl_BitMaskToAny(aRet, nCreate, nsSwTOXElement::TOX_OLE);
1102 1 : break;
1103 : case WID_CREATE_FROM_STAR_MATH:
1104 1 : lcl_BitMaskToAny(aRet, nOLEOptions, nsSwTOOElements::TOO_MATH);
1105 1 : break;
1106 : case WID_CREATE_FROM_STAR_CHART:
1107 1 : lcl_BitMaskToAny(aRet, nOLEOptions, nsSwTOOElements::TOO_CHART);
1108 1 : break;
1109 : case WID_CREATE_FROM_STAR_CALC:
1110 1 : lcl_BitMaskToAny(aRet, nOLEOptions, nsSwTOOElements::TOO_CALC);
1111 1 : break;
1112 : case WID_CREATE_FROM_STAR_DRAW:
1113 : lcl_BitMaskToAny(aRet, nOLEOptions,
1114 1 : nsSwTOOElements::TOO_DRAW_IMPRESS);
1115 1 : break;
1116 : case WID_CREATE_FROM_OTHER_EMBEDDED_OBJECTS:
1117 1 : lcl_BitMaskToAny(aRet, nOLEOptions, nsSwTOOElements::TOO_OTHER);
1118 1 : break;
1119 : case WID_CREATE_FROM_PARAGRAPH_STYLES:
1120 2 : lcl_BitMaskToAny(aRet, nCreate, nsSwTOXElement::TOX_TEMPLATE);
1121 2 : break;
1122 : case WID_PARA_HEAD:
1123 : {
1124 : //Header steht an Pos 0
1125 9 : String aString;
1126 9 : SwStyleNameMapper::FillProgName(rForm.GetTemplate( 0 ), aString,
1127 9 : nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, true );
1128 9 : aRet <<= OUString( aString );
1129 : }
1130 9 : break;
1131 : case WID_PARA_SEP:
1132 : {
1133 3 : String aString;
1134 : SwStyleNameMapper::FillProgName(
1135 3 : rForm.GetTemplate( 1 ),
1136 : aString,
1137 : nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL,
1138 3 : true);
1139 3 : aRet <<= OUString( aString );
1140 : }
1141 3 : break;
1142 : case WID_PARA_LEV1:
1143 : case WID_PARA_LEV2:
1144 : case WID_PARA_LEV3:
1145 : case WID_PARA_LEV4:
1146 : case WID_PARA_LEV5:
1147 : case WID_PARA_LEV6:
1148 : case WID_PARA_LEV7:
1149 : case WID_PARA_LEV8:
1150 : case WID_PARA_LEV9:
1151 : case WID_PARA_LEV10:
1152 : {
1153 : // in sdbcx::Index Label 1 begins at Pos 2 otherwise at Pos 1
1154 54 : sal_uInt16 nLPos = pTOXBase->GetType() == TOX_INDEX ? 2 : 1;
1155 54 : String aString;
1156 : SwStyleNameMapper::FillProgName(
1157 54 : rForm.GetTemplate(nLPos + pEntry->nWID - WID_PARA_LEV1),
1158 : aString,
1159 : nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL,
1160 54 : true);
1161 54 : aRet <<= OUString( aString );
1162 : }
1163 54 : break;
1164 : case WID_IS_RELATIVE_TABSTOPS:
1165 : {
1166 6 : const sal_Bool bRet = rForm.IsRelTabPos();
1167 6 : aRet <<= bRet;
1168 : }
1169 6 : break;
1170 : case WID_INDEX_MARKS:
1171 : {
1172 2 : SwTOXMarks aMarks;
1173 2 : const SwTOXType* pType = pTOXBase->GetTOXType();
1174 2 : SwTOXMark::InsertTOXMarks( aMarks, *pType );
1175 4 : uno::Sequence< uno::Reference<text::XDocumentIndexMark> > aXMarks(aMarks.size());
1176 2 : uno::Reference<text::XDocumentIndexMark>* pxMarks = aXMarks.getArray();
1177 2 : for(sal_uInt16 i = 0; i < aMarks.size(); i++)
1178 : {
1179 0 : SwTOXMark* pMark = aMarks[i];
1180 0 : pxMarks[i] = SwXDocumentIndexMark::CreateXDocumentIndexMark(
1181 0 : *m_pImpl->m_pDoc,
1182 0 : *const_cast<SwTOXType*>(pType), *pMark);
1183 : }
1184 4 : aRet <<= aXMarks;
1185 : }
1186 2 : break;
1187 : default:
1188 : //this is for items only
1189 12 : if(WID_PRIMARY_KEY > pEntry->nWID)
1190 : {
1191 : const SwAttrSet& rSet =
1192 12 : m_pImpl->m_pDoc->GetTOXBaseAttrSet(*pTOXBase);
1193 24 : aRet = m_pImpl->m_rPropSet.getPropertyValue(
1194 12 : rPropertyName, rSet);
1195 : }
1196 : }
1197 : }
1198 341 : return aRet;
1199 : }
1200 :
1201 : void SAL_CALL
1202 0 : SwXDocumentIndex::addPropertyChangeListener(
1203 : const OUString& /*rPropertyName*/,
1204 : const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
1205 : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1206 : uno::RuntimeException)
1207 : {
1208 : OSL_FAIL("SwXDocumentIndex::addPropertyChangeListener(): not implemented");
1209 0 : }
1210 :
1211 : void SAL_CALL
1212 0 : SwXDocumentIndex::removePropertyChangeListener(
1213 : const OUString& /*rPropertyName*/,
1214 : const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
1215 : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1216 : uno::RuntimeException)
1217 : {
1218 : OSL_FAIL("SwXDocumentIndex::removePropertyChangeListener(): not implemented");
1219 0 : }
1220 :
1221 : void SAL_CALL
1222 0 : SwXDocumentIndex::addVetoableChangeListener(
1223 : const OUString& /*rPropertyName*/,
1224 : const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
1225 : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1226 : uno::RuntimeException)
1227 : {
1228 : OSL_FAIL("SwXDocumentIndex::addVetoableChangeListener(): not implemented");
1229 0 : }
1230 :
1231 : void SAL_CALL
1232 0 : SwXDocumentIndex::removeVetoableChangeListener(
1233 : const OUString& /*rPropertyName*/,
1234 : const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
1235 : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1236 : uno::RuntimeException)
1237 : {
1238 : OSL_FAIL("SwXDocumentIndex::removeVetoableChangeListener(): not implemented");
1239 0 : }
1240 :
1241 : // XRefreshable
1242 7 : void SAL_CALL SwXDocumentIndex::refresh() throw (uno::RuntimeException)
1243 : {
1244 : {
1245 7 : SolarMutexGuard g;
1246 :
1247 7 : SwSectionFmt *const pFmt = m_pImpl->GetSectionFmt();
1248 : SwTOXBaseSection *const pTOXBase = (pFmt) ?
1249 7 : static_cast<SwTOXBaseSection*>(pFmt->GetSection()) : 0;
1250 7 : if (!pTOXBase)
1251 : {
1252 : throw uno::RuntimeException(
1253 : "SwXDocumentIndex::refresh: must be in attached state",
1254 0 : static_cast< ::cppu::OWeakObject*>(this));
1255 : }
1256 7 : pTOXBase->Update();
1257 : // page numbers
1258 7 : pTOXBase->UpdatePageNum();
1259 : }
1260 :
1261 : ::cppu::OInterfaceContainerHelper *const pContainer(
1262 7 : m_pImpl->m_Listeners.getContainer(
1263 14 : util::XRefreshListener::static_type()));
1264 7 : if (pContainer)
1265 : {
1266 6 : lang::EventObject const event(static_cast< ::cppu::OWeakObject*>(this));
1267 6 : pContainer->notifyEach(& util::XRefreshListener::refreshed, event);
1268 : }
1269 7 : }
1270 :
1271 2 : void SAL_CALL SwXDocumentIndex::addRefreshListener(
1272 : const uno::Reference<util::XRefreshListener>& xListener)
1273 : throw (uno::RuntimeException)
1274 : {
1275 : // no need to lock here as m_pImpl is const and container threadsafe
1276 2 : m_pImpl->m_Listeners.addInterface(
1277 4 : util::XRefreshListener::static_type(), xListener);
1278 2 : }
1279 :
1280 0 : void SAL_CALL SwXDocumentIndex::removeRefreshListener(
1281 : const uno::Reference<util::XRefreshListener>& xListener)
1282 : throw (uno::RuntimeException)
1283 : {
1284 : // no need to lock here as m_pImpl is const and container threadsafe
1285 0 : m_pImpl->m_Listeners.removeInterface(
1286 0 : util::XRefreshListener::static_type(), xListener);
1287 0 : }
1288 :
1289 : void SAL_CALL
1290 21 : SwXDocumentIndex::attach(const uno::Reference< text::XTextRange > & xTextRange)
1291 : throw (lang::IllegalArgumentException, uno::RuntimeException)
1292 : {
1293 21 : SolarMutexGuard aGuard;
1294 :
1295 21 : if (!m_pImpl->m_bIsDescriptor)
1296 : {
1297 0 : throw uno::RuntimeException();
1298 : }
1299 42 : const uno::Reference<XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
1300 : SwXTextRange *const pRange =
1301 21 : ::sw::UnoTunnelGetImplementation<SwXTextRange>(xRangeTunnel);
1302 : OTextCursorHelper *const pCursor =
1303 21 : ::sw::UnoTunnelGetImplementation<OTextCursorHelper>(xRangeTunnel);
1304 :
1305 : SwDoc *const pDoc =
1306 21 : (pRange) ? pRange->GetDoc() : ((pCursor) ? pCursor->GetDoc() : 0);
1307 21 : if (!pDoc)
1308 : {
1309 0 : throw lang::IllegalArgumentException();
1310 : }
1311 :
1312 42 : SwUnoInternalPaM aPam(*pDoc);
1313 : //das muss jetzt sal_True liefern
1314 21 : ::sw::XTextRangeToSwPaM(aPam, xTextRange);
1315 :
1316 21 : const SwTOXBase* pOld = pDoc->GetCurTOX( *aPam.Start() );
1317 21 : if (pOld)
1318 : {
1319 0 : throw lang::IllegalArgumentException();
1320 : }
1321 :
1322 42 : UnoActionContext aAction(pDoc);
1323 21 : if (aPam.HasMark())
1324 : {
1325 0 : pDoc->DeleteAndJoin(aPam);
1326 : }
1327 :
1328 21 : SwTOXBase & rTOXBase = m_pImpl->m_pProps->GetTOXBase();
1329 21 : SwTOXType const*const pTOXType = rTOXBase.GetTOXType();
1330 65 : if ((TOX_USER == pTOXType->GetType()) &&
1331 27 : !m_pImpl->m_pProps->GetTypeName().equals(pTOXType->GetTypeName()))
1332 : {
1333 0 : lcl_ReAssignTOXType(pDoc, rTOXBase, m_pImpl->m_pProps->GetTypeName());
1334 : }
1335 : //TODO: apply Section attributes (columns and background)
1336 : SwTOXBaseSection const*const pTOX =
1337 21 : pDoc->InsertTableOf( *aPam.GetPoint(), rTOXBase, 0, false );
1338 :
1339 21 : pDoc->SetTOXBaseName(*pTOX, m_pImpl->m_pProps->GetTOXBase().GetTOXName());
1340 :
1341 : // update page numbers
1342 21 : pTOX->GetFmt()->Add(m_pImpl.get());
1343 21 : pTOX->GetFmt()->SetXObject(static_cast< ::cppu::OWeakObject*>(this));
1344 21 : const_cast<SwTOXBaseSection*>(pTOX)->UpdatePageNum();
1345 :
1346 21 : m_pImpl->m_pProps.reset();
1347 21 : m_pImpl->m_pDoc = pDoc;
1348 42 : m_pImpl->m_bIsDescriptor = sal_False;
1349 21 : }
1350 :
1351 : uno::Reference< text::XTextRange > SAL_CALL
1352 7 : SwXDocumentIndex::getAnchor() throw (uno::RuntimeException)
1353 : {
1354 7 : SolarMutexGuard aGuard;
1355 :
1356 7 : SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() );
1357 7 : if (!pSectionFmt)
1358 : {
1359 0 : throw uno::RuntimeException();
1360 : }
1361 :
1362 7 : uno::Reference< text::XTextRange > xRet;
1363 7 : SwNodeIndex const*const pIdx( pSectionFmt->GetCntnt().GetCntntIdx() );
1364 7 : if (pIdx && pIdx->GetNode().GetNodes().IsDocNodes())
1365 : {
1366 7 : SwPaM aPaM(*pIdx);
1367 7 : aPaM.Move( fnMoveForward, fnGoCntnt );
1368 7 : aPaM.SetMark();
1369 7 : aPaM.GetPoint()->nNode = *pIdx->GetNode().EndOfSectionNode();
1370 7 : aPaM.Move( fnMoveBackward, fnGoCntnt );
1371 14 : xRet = SwXTextRange::CreateXTextRange(*pSectionFmt->GetDoc(),
1372 21 : *aPaM.GetMark(), aPaM.GetPoint());
1373 : }
1374 7 : return xRet;
1375 : }
1376 :
1377 3 : void SAL_CALL SwXDocumentIndex::dispose() throw (uno::RuntimeException)
1378 : {
1379 3 : SolarMutexGuard aGuard;
1380 :
1381 3 : SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() );
1382 3 : if (pSectionFmt)
1383 : {
1384 : pSectionFmt->GetDoc()->DeleteTOX(
1385 3 : *static_cast<SwTOXBaseSection*>(pSectionFmt->GetSection()),
1386 3 : true);
1387 3 : }
1388 3 : }
1389 :
1390 : void SAL_CALL
1391 2 : SwXDocumentIndex::addEventListener(
1392 : const uno::Reference< lang::XEventListener > & xListener)
1393 : throw (uno::RuntimeException)
1394 : {
1395 : // no need to lock here as m_pImpl is const and container threadsafe
1396 2 : m_pImpl->m_Listeners.addInterface(
1397 4 : lang::XEventListener::static_type(), xListener);
1398 2 : }
1399 :
1400 : void SAL_CALL
1401 1 : SwXDocumentIndex::removeEventListener(
1402 : const uno::Reference< lang::XEventListener > & xListener)
1403 : throw (uno::RuntimeException)
1404 : {
1405 : // no need to lock here as m_pImpl is const and container threadsafe
1406 1 : m_pImpl->m_Listeners.removeInterface(
1407 2 : lang::XEventListener::static_type(), xListener);
1408 1 : }
1409 :
1410 0 : OUString SAL_CALL SwXDocumentIndex::getName() throw (uno::RuntimeException)
1411 : {
1412 0 : SolarMutexGuard g;
1413 :
1414 0 : OUString uRet;
1415 0 : SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() );
1416 0 : if (m_pImpl->m_bIsDescriptor)
1417 : {
1418 0 : uRet = OUString(m_pImpl->m_pProps->GetTOXBase().GetTOXName());
1419 : }
1420 0 : else if(pSectionFmt)
1421 : {
1422 0 : uRet = OUString(pSectionFmt->GetSection()->GetSectionName());
1423 : }
1424 : else
1425 : {
1426 0 : throw uno::RuntimeException();
1427 : }
1428 0 : return uRet;
1429 : }
1430 :
1431 : void SAL_CALL
1432 0 : SwXDocumentIndex::setName(const OUString& rName) throw (uno::RuntimeException)
1433 : {
1434 0 : SolarMutexGuard g;
1435 :
1436 0 : if (rName.isEmpty())
1437 : {
1438 0 : throw uno::RuntimeException();
1439 : }
1440 :
1441 0 : SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() );
1442 0 : if (m_pImpl->m_bIsDescriptor)
1443 : {
1444 0 : m_pImpl->m_pProps->GetTOXBase().SetTOXName(rName);
1445 : }
1446 0 : else if (pSectionFmt)
1447 : {
1448 : const bool bSuccess = pSectionFmt->GetDoc()->SetTOXBaseName(
1449 0 : *static_cast<SwTOXBaseSection*>(pSectionFmt->GetSection()), rName);
1450 0 : if (!bSuccess)
1451 : {
1452 0 : throw uno::RuntimeException();
1453 : }
1454 : }
1455 : else
1456 : {
1457 0 : throw uno::RuntimeException();
1458 0 : }
1459 0 : }
1460 :
1461 : // MetadatableMixin
1462 28 : ::sfx2::Metadatable* SwXDocumentIndex::GetCoreObject()
1463 : {
1464 28 : SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() );
1465 28 : return pSectionFmt;
1466 : }
1467 :
1468 0 : uno::Reference<frame::XModel> SwXDocumentIndex::GetModel()
1469 : {
1470 0 : SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() );
1471 0 : if (pSectionFmt)
1472 : {
1473 0 : SwDocShell const*const pShell( pSectionFmt->GetDoc()->GetDocShell() );
1474 0 : return (pShell) ? pShell->GetModel() : 0;
1475 : }
1476 0 : return 0;
1477 : }
1478 :
1479 :
1480 : /******************************************************************
1481 : * SwXDocumentIndexMark
1482 : ******************************************************************/
1483 : static sal_uInt16
1484 67 : lcl_TypeToPropertyMap_Mark(const TOXTypes eType)
1485 : {
1486 67 : switch (eType)
1487 : {
1488 67 : case TOX_INDEX: return PROPERTY_MAP_INDEX_MARK;
1489 0 : case TOX_CONTENT: return PROPERTY_MAP_CNTIDX_MARK;
1490 : //case TOX_USER:
1491 : default:
1492 0 : return PROPERTY_MAP_USER_MARK;
1493 : }
1494 : }
1495 :
1496 134 : class SwXDocumentIndexMark::Impl
1497 : : public SwClient
1498 : {
1499 : private:
1500 : ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper
1501 : SwXDocumentIndexMark & m_rThis;
1502 : bool m_bInReplaceMark;
1503 :
1504 : public:
1505 :
1506 : SfxItemPropertySet const& m_rPropSet;
1507 : const TOXTypes m_eTOXType;
1508 : ::cppu::OInterfaceContainerHelper m_EventListeners;
1509 : bool m_bIsDescriptor;
1510 : SwDepend m_TypeDepend;
1511 : const SwTOXMark * m_pTOXMark;
1512 : SwDoc * m_pDoc;
1513 :
1514 : sal_Bool m_bMainEntry;
1515 : sal_uInt16 m_nLevel;
1516 : OUString m_sAltText;
1517 : OUString m_sPrimaryKey;
1518 : OUString m_sSecondaryKey;
1519 : OUString m_sTextReading;
1520 : OUString m_sPrimaryKeyReading;
1521 : OUString m_sSecondaryKeyReading;
1522 : OUString m_sUserIndexName;
1523 :
1524 67 : Impl( SwXDocumentIndexMark & rThis,
1525 : SwDoc *const pDoc,
1526 : const enum TOXTypes eType,
1527 : SwTOXType *const pType, SwTOXMark const*const pMark)
1528 : : SwClient(const_cast<SwTOXMark*>(pMark))
1529 : , m_rThis(rThis)
1530 : , m_bInReplaceMark(false)
1531 : , m_rPropSet(
1532 67 : *aSwMapProvider.GetPropertySet(lcl_TypeToPropertyMap_Mark(eType)))
1533 : , m_eTOXType(eType)
1534 : , m_EventListeners(m_Mutex)
1535 : // #i112513#: unxsols4 (Sun C++ 5.9 SunOS_sparc) generates wrong code for this
1536 : // , m_bIsDescriptor(0 == pMark)
1537 : , m_bIsDescriptor((0 == pMark) ? true : false)
1538 : , m_TypeDepend(this, pType)
1539 : , m_pTOXMark(pMark)
1540 : , m_pDoc(pDoc)
1541 : , m_bMainEntry(sal_False)
1542 134 : , m_nLevel(0)
1543 : {
1544 67 : }
1545 :
1546 91 : SwTOXType * GetTOXType() const {
1547 : return static_cast<SwTOXType*>(
1548 91 : const_cast<SwModify *>(m_TypeDepend.GetRegisteredIn()));
1549 : }
1550 :
1551 5 : void DeleteTOXMark()
1552 : {
1553 5 : m_pDoc->DeleteTOXMark(m_pTOXMark); // calls Invalidate() via Modify!
1554 5 : m_pTOXMark = 0;
1555 5 : }
1556 :
1557 : void InsertTOXMark(SwTOXType & rTOXType, SwTOXMark & rMark, SwPaM & rPam,
1558 : SwXTextCursor const*const pTextCursor);
1559 :
1560 4 : void ReplaceTOXMark(SwTOXType & rTOXType, SwTOXMark & rMark, SwPaM & rPam)
1561 : {
1562 4 : m_bInReplaceMark = true;
1563 4 : DeleteTOXMark();
1564 4 : m_bInReplaceMark = false;
1565 : try {
1566 4 : InsertTOXMark(rTOXType, rMark, rPam, 0);
1567 0 : } catch (...) {
1568 : OSL_FAIL("ReplaceTOXMark() failed!");
1569 : lang::EventObject const ev(
1570 0 : static_cast< ::cppu::OWeakObject&>(m_rThis));
1571 0 : m_EventListeners.disposeAndClear(ev);
1572 0 : throw;
1573 : }
1574 4 : }
1575 :
1576 : void Invalidate();
1577 : protected:
1578 : // SwClient
1579 : virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew);
1580 : };
1581 :
1582 71 : void SwXDocumentIndexMark::Impl::Invalidate()
1583 : {
1584 71 : if (GetRegisteredIn())
1585 : {
1586 0 : const_cast<SwModify*>(GetRegisteredIn())->Remove(this);
1587 0 : if (m_TypeDepend.GetRegisteredIn())
1588 : {
1589 0 : const_cast<SwModify*>(m_TypeDepend.GetRegisteredIn())->Remove(
1590 0 : &m_TypeDepend);
1591 : }
1592 : }
1593 71 : if (!m_bInReplaceMark) // #i109983# only dispose on delete, not on replace!
1594 : {
1595 67 : lang::EventObject const ev(static_cast< ::cppu::OWeakObject&>(m_rThis));
1596 67 : m_EventListeners.disposeAndClear(ev);
1597 : }
1598 71 : m_pDoc = 0;
1599 71 : m_pTOXMark = 0;
1600 71 : }
1601 :
1602 71 : void SwXDocumentIndexMark::Impl::Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew)
1603 : {
1604 71 : ClientModify(this, pOld, pNew);
1605 :
1606 71 : if (!GetRegisteredIn()) // removed => dispose
1607 : {
1608 71 : Invalidate();
1609 : }
1610 71 : }
1611 :
1612 35 : SwXDocumentIndexMark::SwXDocumentIndexMark(const TOXTypes eToxType)
1613 35 : : m_pImpl( new SwXDocumentIndexMark::Impl(*this, 0, eToxType, 0, 0) )
1614 : {
1615 35 : }
1616 :
1617 32 : SwXDocumentIndexMark::SwXDocumentIndexMark(SwDoc & rDoc,
1618 : SwTOXType & rType, SwTOXMark & rMark)
1619 : : m_pImpl( new SwXDocumentIndexMark::Impl(*this, &rDoc, rType.GetType(),
1620 32 : &rType, &rMark) )
1621 : {
1622 32 : }
1623 :
1624 134 : SwXDocumentIndexMark::~SwXDocumentIndexMark()
1625 : {
1626 134 : }
1627 :
1628 : uno::Reference<text::XDocumentIndexMark>
1629 45 : SwXDocumentIndexMark::CreateXDocumentIndexMark(
1630 : SwDoc & rDoc, SwTOXType & rType, SwTOXMark & rMark)
1631 : {
1632 : // re-use existing SwXDocumentIndexMark
1633 : // NB: xmloff depends on this caching to generate ID from the address!
1634 : // #i105557#: do not iterate over the registered clients: race condition
1635 45 : uno::Reference< text::XDocumentIndexMark > xTOXMark(rMark.GetXTOXMark());
1636 45 : if (!xTOXMark.is())
1637 : {
1638 : SwXDocumentIndexMark *const pNew =
1639 32 : new SwXDocumentIndexMark(rDoc, rType, rMark);
1640 32 : xTOXMark.set(pNew);
1641 32 : rMark.SetXTOXMark(xTOXMark);
1642 : }
1643 45 : return xTOXMark;
1644 : }
1645 :
1646 : namespace
1647 : {
1648 : class theSwXDocumentIndexMarkUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXDocumentIndexMarkUnoTunnelId > {};
1649 : }
1650 :
1651 2680 : const uno::Sequence< sal_Int8 > & SwXDocumentIndexMark::getUnoTunnelId()
1652 : {
1653 2680 : return theSwXDocumentIndexMarkUnoTunnelId::get().getSeq();
1654 : }
1655 :
1656 : sal_Int64 SAL_CALL
1657 48 : SwXDocumentIndexMark::getSomething(const uno::Sequence< sal_Int8 >& rId)
1658 : throw (uno::RuntimeException)
1659 : {
1660 48 : return ::sw::UnoTunnelImpl<SwXDocumentIndexMark>(rId, this);
1661 : }
1662 :
1663 : static const sal_Char cBaseMark[] = "com.sun.star.text.BaseIndexMark";
1664 : static const sal_Char cContentMark[] = "com.sun.star.text.ContentIndexMark";
1665 : static const sal_Char cIdxMark[] = "com.sun.star.text.DocumentIndexMark";
1666 : static const sal_Char cIdxMarkAsian[] = "com.sun.star.text.DocumentIndexMarkAsian";
1667 : static const sal_Char cUserMark[] = "com.sun.star.text.UserIndexMark";
1668 : static const sal_Char cTextContent[] = "com.sun.star.text.TextContent";
1669 :
1670 : OUString SAL_CALL
1671 0 : SwXDocumentIndexMark::getImplementationName() throw (uno::RuntimeException)
1672 : {
1673 0 : return OUString("SwXDocumentIndexMark");
1674 : }
1675 :
1676 : sal_Bool SAL_CALL
1677 3 : SwXDocumentIndexMark::supportsService(const OUString& rServiceName)
1678 : throw (uno::RuntimeException)
1679 : {
1680 3 : SolarMutexGuard g;
1681 :
1682 3 : return rServiceName.equalsAscii(cBaseMark)
1683 2 : || rServiceName.equalsAscii(cTextContent)
1684 1 : || ((m_pImpl->m_eTOXType == TOX_USER)
1685 0 : && rServiceName.equalsAscii(cUserMark))
1686 1 : || ((m_pImpl->m_eTOXType == TOX_CONTENT)
1687 0 : && rServiceName.equalsAscii(cContentMark))
1688 1 : || ((m_pImpl->m_eTOXType == TOX_INDEX)
1689 1 : && rServiceName.equalsAscii(cIdxMark))
1690 6 : || ((m_pImpl->m_eTOXType == TOX_INDEX)
1691 3 : && rServiceName.equalsAscii(cIdxMarkAsian));
1692 : }
1693 :
1694 : uno::Sequence< OUString > SAL_CALL
1695 0 : SwXDocumentIndexMark::getSupportedServiceNames() throw (uno::RuntimeException)
1696 : {
1697 0 : SolarMutexGuard g;
1698 :
1699 0 : const sal_Int32 nCnt = (m_pImpl->m_eTOXType == TOX_INDEX) ? 4 : 3;
1700 0 : uno::Sequence< OUString > aRet(nCnt);
1701 0 : OUString* pArray = aRet.getArray();
1702 0 : pArray[0] = cBaseMark;
1703 0 : pArray[1] = cTextContent;
1704 0 : switch (m_pImpl->m_eTOXType)
1705 : {
1706 : case TOX_USER:
1707 0 : pArray[2] = cUserMark;
1708 0 : break;
1709 : case TOX_CONTENT:
1710 0 : pArray[2] = cContentMark;
1711 0 : break;
1712 : case TOX_INDEX:
1713 0 : pArray[2] = cIdxMark;
1714 0 : pArray[3] = cIdxMarkAsian;
1715 0 : break;
1716 :
1717 : default:
1718 : ;
1719 : }
1720 0 : return aRet;
1721 : }
1722 :
1723 : OUString SAL_CALL
1724 0 : SwXDocumentIndexMark::getMarkEntry() throw (uno::RuntimeException)
1725 : {
1726 0 : SolarMutexGuard aGuard;
1727 :
1728 0 : OUString sRet;
1729 0 : SwTOXType *const pType = m_pImpl->GetTOXType();
1730 0 : if (pType && m_pImpl->m_pTOXMark)
1731 : {
1732 0 : sRet = OUString(m_pImpl->m_pTOXMark->GetAlternativeText());
1733 : }
1734 0 : else if (m_pImpl->m_bIsDescriptor)
1735 : {
1736 0 : sRet = m_pImpl->m_sAltText;
1737 : }
1738 : else
1739 : {
1740 0 : throw uno::RuntimeException();
1741 : }
1742 0 : return sRet;
1743 : }
1744 :
1745 : void SAL_CALL
1746 0 : SwXDocumentIndexMark::setMarkEntry(const OUString& rIndexEntry)
1747 : throw (uno::RuntimeException)
1748 : {
1749 0 : SolarMutexGuard aGuard;
1750 :
1751 0 : SwTOXType *const pType = m_pImpl->GetTOXType();
1752 0 : if (pType && m_pImpl->m_pTOXMark)
1753 : {
1754 0 : SwTOXMark aMark(*m_pImpl->m_pTOXMark);
1755 0 : aMark.SetAlternativeText(rIndexEntry);
1756 : SwTxtTOXMark const*const pTxtMark =
1757 0 : m_pImpl->m_pTOXMark->GetTxtTOXMark();
1758 0 : SwPaM aPam(pTxtMark->GetTxtNode(), *pTxtMark->GetStart());
1759 0 : aPam.SetMark();
1760 0 : if(pTxtMark->GetEnd())
1761 : {
1762 0 : aPam.GetPoint()->nContent = *pTxtMark->GetEnd();
1763 : }
1764 : else
1765 0 : aPam.GetPoint()->nContent++;
1766 :
1767 0 : m_pImpl->ReplaceTOXMark(*pType, aMark, aPam);
1768 : }
1769 0 : else if (m_pImpl->m_bIsDescriptor)
1770 : {
1771 0 : m_pImpl->m_sAltText = rIndexEntry;
1772 : }
1773 : else
1774 : {
1775 0 : throw uno::RuntimeException();
1776 0 : }
1777 0 : }
1778 :
1779 : void SAL_CALL
1780 35 : SwXDocumentIndexMark::attach(
1781 : const uno::Reference< text::XTextRange > & xTextRange)
1782 : throw (lang::IllegalArgumentException, uno::RuntimeException)
1783 : {
1784 35 : SolarMutexGuard aGuard;
1785 :
1786 35 : if (!m_pImpl->m_bIsDescriptor)
1787 : {
1788 0 : throw uno::RuntimeException();
1789 : }
1790 :
1791 70 : const uno::Reference<XUnoTunnel> xRangeTunnel(xTextRange, uno::UNO_QUERY);
1792 : SwXTextRange *const pRange =
1793 35 : ::sw::UnoTunnelGetImplementation<SwXTextRange>(xRangeTunnel);
1794 : OTextCursorHelper *const pCursor =
1795 35 : ::sw::UnoTunnelGetImplementation<OTextCursorHelper>(xRangeTunnel);
1796 : SwDoc *const pDoc =
1797 35 : (pRange) ? pRange->GetDoc() : ((pCursor) ? pCursor->GetDoc() : 0);
1798 35 : if (!pDoc)
1799 : {
1800 0 : throw lang::IllegalArgumentException();
1801 : }
1802 :
1803 35 : const SwTOXType* pTOXType = 0;
1804 35 : switch (m_pImpl->m_eTOXType)
1805 : {
1806 : case TOX_INDEX:
1807 : case TOX_CONTENT:
1808 35 : pTOXType = pDoc->GetTOXType( m_pImpl->m_eTOXType, 0 );
1809 35 : break;
1810 : case TOX_USER:
1811 : {
1812 0 : if (m_pImpl->m_sUserIndexName.isEmpty())
1813 : {
1814 0 : pTOXType = pDoc->GetTOXType( m_pImpl->m_eTOXType, 0 );
1815 : }
1816 : else
1817 : {
1818 : const sal_uInt16 nCount =
1819 0 : pDoc->GetTOXTypeCount(m_pImpl->m_eTOXType);
1820 0 : for (sal_uInt16 i = 0; i < nCount; i++)
1821 : {
1822 : SwTOXType const*const pTemp =
1823 0 : pDoc->GetTOXType( m_pImpl->m_eTOXType, i );
1824 0 : if (m_pImpl->m_sUserIndexName ==
1825 0 : OUString(pTemp->GetTypeName()))
1826 : {
1827 0 : pTOXType = pTemp;
1828 0 : break;
1829 : }
1830 : }
1831 0 : if (!pTOXType)
1832 : {
1833 0 : SwTOXType aUserType(TOX_USER, m_pImpl->m_sUserIndexName);
1834 0 : pTOXType = pDoc->InsertTOXType(aUserType);
1835 : }
1836 : }
1837 : }
1838 0 : break;
1839 :
1840 : default:
1841 0 : break;
1842 : }
1843 35 : if (!pTOXType)
1844 : {
1845 0 : throw lang::IllegalArgumentException();
1846 : }
1847 :
1848 35 : SwUnoInternalPaM aPam(*pDoc);
1849 : //which must now return sal_True
1850 35 : ::sw::XTextRangeToSwPaM(aPam, xTextRange);
1851 70 : SwTOXMark aMark (pTOXType);
1852 35 : if (!m_pImpl->m_sAltText.isEmpty())
1853 : {
1854 0 : aMark.SetAlternativeText(m_pImpl->m_sAltText);
1855 : }
1856 35 : switch (m_pImpl->m_eTOXType)
1857 : {
1858 : case TOX_INDEX:
1859 35 : if (!m_pImpl->m_sPrimaryKey.isEmpty())
1860 : {
1861 32 : aMark.SetPrimaryKey(m_pImpl->m_sPrimaryKey);
1862 : }
1863 35 : if (!m_pImpl->m_sSecondaryKey.isEmpty())
1864 : {
1865 0 : aMark.SetSecondaryKey(m_pImpl->m_sSecondaryKey);
1866 : }
1867 35 : if (!m_pImpl->m_sTextReading.isEmpty())
1868 : {
1869 0 : aMark.SetTextReading(m_pImpl->m_sTextReading);
1870 : }
1871 35 : if (!m_pImpl->m_sPrimaryKeyReading.isEmpty())
1872 : {
1873 0 : aMark.SetPrimaryKeyReading(m_pImpl->m_sPrimaryKeyReading);
1874 : }
1875 35 : if (!m_pImpl->m_sSecondaryKeyReading.isEmpty())
1876 : {
1877 0 : aMark.SetSecondaryKeyReading(m_pImpl->m_sSecondaryKeyReading);
1878 : }
1879 35 : aMark.SetMainEntry(m_pImpl->m_bMainEntry);
1880 35 : break;
1881 : case TOX_USER:
1882 : case TOX_CONTENT:
1883 0 : if (USHRT_MAX != m_pImpl->m_nLevel)
1884 : {
1885 0 : aMark.SetLevel(m_pImpl->m_nLevel+1);
1886 : }
1887 0 : break;
1888 :
1889 : default:
1890 0 : break;
1891 : }
1892 :
1893 : m_pImpl->InsertTOXMark(*const_cast<SwTOXType *>(pTOXType), aMark, aPam,
1894 35 : dynamic_cast<SwXTextCursor const*>(pCursor));
1895 :
1896 105 : m_pImpl->m_bIsDescriptor = sal_False;
1897 35 : }
1898 :
1899 : template<typename T> struct NotContainedIn
1900 : {
1901 : ::std::vector<T> const& m_rVector;
1902 28 : explicit NotContainedIn(::std::vector<T> const& rVector)
1903 28 : : m_rVector(rVector) { }
1904 28 : bool operator() (T const& rT) {
1905 28 : return ::std::find(m_rVector.begin(), m_rVector.end(), rT)
1906 56 : == m_rVector.end();
1907 : }
1908 : };
1909 :
1910 39 : void SwXDocumentIndexMark::Impl::InsertTOXMark(
1911 : SwTOXType & rTOXType, SwTOXMark & rMark, SwPaM & rPam,
1912 : SwXTextCursor const*const pTextCursor)
1913 : {
1914 39 : SwDoc *const pDoc( rPam.GetDoc() );
1915 39 : UnoActionContext aAction(pDoc);
1916 39 : bool bMark = *rPam.GetPoint() != *rPam.GetMark();
1917 : // n.b.: toxmarks must have either alternative text or an extent
1918 39 : if (bMark && rMark.GetAlternativeText().Len())
1919 : {
1920 0 : rPam.Normalize(true);
1921 0 : rPam.DeleteMark();
1922 0 : bMark = false;
1923 : }
1924 : // Marks ohne Alternativtext ohne selektierten Text koennen nicht eingefuegt werden,
1925 : // deshalb hier ein Leerzeichen - ob das die ideale Loesung ist?
1926 39 : if (!bMark && !rMark.GetAlternativeText().Len())
1927 : {
1928 21 : rMark.SetAlternativeText( OUString(' ') );
1929 : }
1930 :
1931 64 : const bool bForceExpandHints( (!bMark && pTextCursor)
1932 58 : ? pTextCursor->IsAtEndOfMeta() : false );
1933 : const SetAttrMode nInsertFlags = (bForceExpandHints)
1934 : ? ( nsSetAttrMode::SETATTR_FORCEHINTEXPAND
1935 : | nsSetAttrMode::SETATTR_DONTEXPAND)
1936 39 : : nsSetAttrMode::SETATTR_DONTEXPAND;
1937 :
1938 78 : ::std::vector<SwTxtAttr *> oldMarks;
1939 39 : if (bMark)
1940 : {
1941 28 : oldMarks = rPam.GetNode()->GetTxtNode()->GetTxtAttrsAt(
1942 28 : rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_TOXMARK);
1943 : }
1944 :
1945 39 : pDoc->InsertPoolItem(rPam, rMark, nInsertFlags);
1946 39 : if (bMark && *rPam.GetPoint() > *rPam.GetMark())
1947 : {
1948 13 : rPam.Exchange();
1949 : }
1950 :
1951 : // rMark was copied into the document pool; now retrieve real format...
1952 39 : SwTxtAttr * pTxtAttr(0);
1953 39 : if (bMark)
1954 : {
1955 : // #i107672#
1956 : // ensure that we do not retrieve a different mark at the same position
1957 : ::std::vector<SwTxtAttr *> const newMarks(
1958 : rPam.GetNode()->GetTxtNode()->GetTxtAttrsAt(
1959 14 : rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_TOXMARK));
1960 : ::std::vector<SwTxtAttr *>::const_iterator const iter(
1961 : ::std::find_if(newMarks.begin(), newMarks.end(),
1962 14 : NotContainedIn<SwTxtAttr *>(oldMarks)));
1963 : OSL_ASSERT(newMarks.end() != iter);
1964 14 : if (newMarks.end() != iter)
1965 : {
1966 14 : pTxtAttr = *iter;
1967 14 : }
1968 : }
1969 : else
1970 : {
1971 : pTxtAttr = rPam.GetNode()->GetTxtNode()->GetTxtAttrForCharAt(
1972 25 : rPam.GetPoint()->nContent.GetIndex()-1, RES_TXTATR_TOXMARK );
1973 : }
1974 :
1975 39 : if (!pTxtAttr)
1976 : {
1977 : throw uno::RuntimeException(OUString(
1978 : "SwXDocumentIndexMark::InsertTOXMark(): cannot insert attribute"),
1979 0 : 0);
1980 : }
1981 :
1982 39 : m_pDoc = pDoc;
1983 39 : m_pTOXMark = & pTxtAttr->GetTOXMark();
1984 39 : const_cast<SwTOXMark*>(m_pTOXMark)->Add(this);
1985 78 : const_cast<SwTOXType &>(rTOXType).Add(& m_TypeDepend);
1986 39 : }
1987 :
1988 : uno::Reference< text::XTextRange > SAL_CALL
1989 1 : SwXDocumentIndexMark::getAnchor() throw (uno::RuntimeException)
1990 : {
1991 1 : SolarMutexGuard aGuard;
1992 :
1993 1 : SwTOXType *const pType = m_pImpl->GetTOXType();
1994 1 : if (!pType || !m_pImpl->m_pTOXMark)
1995 : {
1996 0 : throw uno::RuntimeException();
1997 : }
1998 1 : if (!m_pImpl->m_pTOXMark->GetTxtTOXMark())
1999 : {
2000 0 : throw uno::RuntimeException();
2001 : }
2002 1 : const SwTxtTOXMark* pTxtMark = m_pImpl->m_pTOXMark->GetTxtTOXMark();
2003 2 : SwPaM aPam(pTxtMark->GetTxtNode(), *pTxtMark->GetStart());
2004 1 : aPam.SetMark();
2005 1 : if(pTxtMark->GetEnd())
2006 : {
2007 0 : aPam.GetPoint()->nContent = *pTxtMark->GetEnd();
2008 : }
2009 : else
2010 : {
2011 1 : aPam.GetPoint()->nContent++;
2012 : }
2013 : const uno::Reference< frame::XModel > xModel =
2014 2 : m_pImpl->m_pDoc->GetDocShell()->GetBaseModel();
2015 2 : const uno::Reference< text::XTextDocument > xTDoc(xModel, uno::UNO_QUERY);
2016 : const uno::Reference< text::XTextRange > xRet =
2017 1 : new SwXTextRange(aPam, xTDoc->getText());
2018 :
2019 2 : return xRet;
2020 : }
2021 :
2022 : void SAL_CALL
2023 1 : SwXDocumentIndexMark::dispose() throw (uno::RuntimeException)
2024 : {
2025 1 : SolarMutexGuard aGuard;
2026 :
2027 1 : SwTOXType *const pType = m_pImpl->GetTOXType();
2028 1 : if (pType && m_pImpl->m_pTOXMark)
2029 : {
2030 1 : m_pImpl->DeleteTOXMark(); // call Invalidate() via modify!
2031 1 : }
2032 1 : }
2033 :
2034 : void SAL_CALL
2035 2 : SwXDocumentIndexMark::addEventListener(
2036 : const uno::Reference< lang::XEventListener > & xListener)
2037 : throw (uno::RuntimeException)
2038 : {
2039 : // no need to lock here as m_pImpl is const and container threadsafe
2040 2 : m_pImpl->m_EventListeners.addInterface(xListener);
2041 2 : }
2042 :
2043 : void SAL_CALL
2044 1 : SwXDocumentIndexMark::removeEventListener(
2045 : const uno::Reference< lang::XEventListener > & xListener)
2046 : throw (uno::RuntimeException)
2047 : {
2048 : // no need to lock here as m_pImpl is const and container threadsafe
2049 1 : m_pImpl->m_EventListeners.removeInterface(xListener);
2050 1 : }
2051 :
2052 : uno::Reference< beans::XPropertySetInfo > SAL_CALL
2053 14 : SwXDocumentIndexMark::getPropertySetInfo() throw (uno::RuntimeException)
2054 : {
2055 14 : SolarMutexGuard g;
2056 :
2057 15 : static uno::Reference< beans::XPropertySetInfo > xInfos[3];
2058 14 : int nPos = 0;
2059 14 : switch (m_pImpl->m_eTOXType)
2060 : {
2061 14 : case TOX_INDEX: nPos = 0; break;
2062 0 : case TOX_CONTENT: nPos = 1; break;
2063 0 : case TOX_USER: nPos = 2; break;
2064 : default:
2065 : ;
2066 : }
2067 14 : if(!xInfos[nPos].is())
2068 : {
2069 : const uno::Reference< beans::XPropertySetInfo > xInfo =
2070 1 : m_pImpl->m_rPropSet.getPropertySetInfo();
2071 : // extend PropertySetInfo!
2072 2 : const uno::Sequence<beans::Property> aPropSeq = xInfo->getProperties();
2073 2 : xInfos[nPos] = new SfxExtItemPropertySetInfo(
2074 : aSwMapProvider.GetPropertyMapEntries(
2075 : PROPERTY_MAP_PARAGRAPH_EXTENSIONS),
2076 3 : aPropSeq );
2077 : }
2078 14 : return xInfos[nPos];
2079 : }
2080 :
2081 : void SAL_CALL
2082 39 : SwXDocumentIndexMark::setPropertyValue(
2083 : const OUString& rPropertyName, const uno::Any& rValue)
2084 : throw (beans::UnknownPropertyException, beans::PropertyVetoException,
2085 : lang::IllegalArgumentException, lang::WrappedTargetException,
2086 : uno::RuntimeException)
2087 : {
2088 39 : SolarMutexGuard aGuard;
2089 :
2090 : SfxItemPropertySimpleEntry const*const pEntry =
2091 39 : m_pImpl->m_rPropSet.getPropertyMap().getByName(rPropertyName);
2092 39 : if (!pEntry)
2093 : {
2094 : throw beans::UnknownPropertyException(
2095 : OUString("Unknown property: ")
2096 0 : + rPropertyName,
2097 0 : static_cast<cppu::OWeakObject *>(this));
2098 : }
2099 39 : if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
2100 : {
2101 : throw beans::PropertyVetoException(
2102 : OUString("Property is read-only: ")
2103 6 : + rPropertyName,
2104 9 : static_cast<cppu::OWeakObject *>(this));
2105 : }
2106 :
2107 36 : SwTOXType *const pType = m_pImpl->GetTOXType();
2108 36 : if (pType && m_pImpl->m_pTOXMark)
2109 : {
2110 4 : SwTOXMark aMark(*m_pImpl->m_pTOXMark);
2111 4 : switch(pEntry->nWID)
2112 : {
2113 : case WID_ALT_TEXT:
2114 1 : aMark.SetAlternativeText(lcl_AnyToString(rValue));
2115 1 : break;
2116 : case WID_LEVEL:
2117 : aMark.SetLevel(std::min( static_cast<sal_Int8>( MAXLEVEL ),
2118 0 : static_cast<sal_Int8>(lcl_AnyToInt16(rValue)+1)));
2119 0 : break;
2120 : case WID_PRIMARY_KEY :
2121 1 : aMark.SetPrimaryKey(lcl_AnyToString(rValue));
2122 1 : break;
2123 : case WID_SECONDARY_KEY:
2124 1 : aMark.SetSecondaryKey(lcl_AnyToString(rValue));
2125 1 : break;
2126 : case WID_MAIN_ENTRY:
2127 1 : aMark.SetMainEntry(lcl_AnyToBool(rValue));
2128 1 : break;
2129 : case WID_TEXT_READING:
2130 0 : aMark.SetTextReading(lcl_AnyToString(rValue));
2131 0 : break;
2132 : case WID_PRIMARY_KEY_READING:
2133 0 : aMark.SetPrimaryKeyReading(lcl_AnyToString(rValue));
2134 0 : break;
2135 : case WID_SECONDARY_KEY_READING:
2136 0 : aMark.SetSecondaryKeyReading(lcl_AnyToString(rValue));
2137 0 : break;
2138 : }
2139 : SwTxtTOXMark const*const pTxtMark =
2140 4 : m_pImpl->m_pTOXMark->GetTxtTOXMark();
2141 4 : SwPaM aPam(pTxtMark->GetTxtNode(), *pTxtMark->GetStart());
2142 4 : aPam.SetMark();
2143 4 : if(pTxtMark->GetEnd())
2144 : {
2145 0 : aPam.GetPoint()->nContent = *pTxtMark->GetEnd();
2146 : }
2147 : else
2148 : {
2149 4 : aPam.GetPoint()->nContent++;
2150 : }
2151 :
2152 4 : m_pImpl->ReplaceTOXMark(*pType, aMark, aPam);
2153 : }
2154 32 : else if (m_pImpl->m_bIsDescriptor)
2155 : {
2156 32 : switch(pEntry->nWID)
2157 : {
2158 : case WID_ALT_TEXT:
2159 0 : m_pImpl->m_sAltText = lcl_AnyToString(rValue);
2160 0 : break;
2161 : case WID_LEVEL:
2162 : {
2163 0 : const sal_Int16 nVal = lcl_AnyToInt16(rValue);
2164 0 : if(nVal >= 0 && nVal < MAXLEVEL)
2165 : {
2166 0 : m_pImpl->m_nLevel = nVal;
2167 : }
2168 : else
2169 : {
2170 0 : throw lang::IllegalArgumentException();
2171 : }
2172 : }
2173 0 : break;
2174 : case WID_PRIMARY_KEY:
2175 32 : m_pImpl->m_sPrimaryKey = lcl_AnyToString(rValue);
2176 32 : break;
2177 : case WID_SECONDARY_KEY:
2178 0 : m_pImpl->m_sSecondaryKey = lcl_AnyToString(rValue);
2179 0 : break;
2180 : case WID_TEXT_READING:
2181 0 : m_pImpl->m_sTextReading = lcl_AnyToString(rValue);
2182 0 : break;
2183 : case WID_PRIMARY_KEY_READING:
2184 0 : m_pImpl->m_sPrimaryKeyReading = lcl_AnyToString(rValue);
2185 0 : break;
2186 : case WID_SECONDARY_KEY_READING:
2187 0 : m_pImpl->m_sSecondaryKeyReading = lcl_AnyToString(rValue);
2188 0 : break;
2189 : case WID_USER_IDX_NAME:
2190 : {
2191 0 : OUString sTmp(lcl_AnyToString(rValue));
2192 0 : lcl_ConvertTOUNameToUserName(sTmp);
2193 0 : m_pImpl->m_sUserIndexName = sTmp;
2194 : }
2195 0 : break;
2196 : case WID_MAIN_ENTRY:
2197 0 : m_pImpl->m_bMainEntry = lcl_AnyToBool(rValue);
2198 0 : break;
2199 : }
2200 : }
2201 : else
2202 : {
2203 0 : throw uno::RuntimeException();
2204 39 : }
2205 36 : }
2206 :
2207 : uno::Any SAL_CALL
2208 59 : SwXDocumentIndexMark::getPropertyValue(const OUString& rPropertyName)
2209 : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2210 : uno::RuntimeException)
2211 : {
2212 59 : SolarMutexGuard aGuard;
2213 :
2214 59 : uno::Any aRet;
2215 : SfxItemPropertySimpleEntry const*const pEntry =
2216 59 : m_pImpl->m_rPropSet.getPropertyMap().getByName(rPropertyName);
2217 59 : if (!pEntry)
2218 : {
2219 : throw beans::UnknownPropertyException(
2220 : OUString("Unknown property: ")
2221 0 : + rPropertyName,
2222 0 : static_cast<cppu::OWeakObject *>(this));
2223 : }
2224 59 : if (::sw::GetDefaultTextContentValue(aRet, rPropertyName, pEntry->nWID))
2225 : {
2226 6 : return aRet;
2227 : }
2228 :
2229 53 : SwTOXType *const pType = m_pImpl->GetTOXType();
2230 53 : if (pType && m_pImpl->m_pTOXMark)
2231 : {
2232 53 : switch(pEntry->nWID)
2233 : {
2234 : case WID_ALT_TEXT:
2235 2 : aRet <<= OUString(m_pImpl->m_pTOXMark->GetAlternativeText());
2236 2 : break;
2237 : case WID_LEVEL:
2238 0 : aRet <<= static_cast<sal_Int16>(
2239 0 : m_pImpl->m_pTOXMark->GetLevel() - 1);
2240 0 : break;
2241 : case WID_PRIMARY_KEY :
2242 47 : aRet <<= OUString(m_pImpl->m_pTOXMark->GetPrimaryKey());
2243 47 : break;
2244 : case WID_SECONDARY_KEY:
2245 2 : aRet <<= OUString(m_pImpl->m_pTOXMark->GetSecondaryKey());
2246 2 : break;
2247 : case WID_TEXT_READING:
2248 0 : aRet <<= OUString(m_pImpl->m_pTOXMark->GetTextReading());
2249 0 : break;
2250 : case WID_PRIMARY_KEY_READING:
2251 0 : aRet <<= OUString(m_pImpl->m_pTOXMark->GetPrimaryKeyReading());
2252 0 : break;
2253 : case WID_SECONDARY_KEY_READING:
2254 0 : aRet <<= OUString(
2255 0 : m_pImpl->m_pTOXMark->GetSecondaryKeyReading());
2256 0 : break;
2257 : case WID_USER_IDX_NAME :
2258 : {
2259 0 : OUString sTmp(pType->GetTypeName());
2260 0 : lcl_ConvertTOUNameToProgrammaticName(sTmp);
2261 0 : aRet <<= sTmp;
2262 : }
2263 0 : break;
2264 : case WID_MAIN_ENTRY:
2265 : {
2266 2 : const sal_Bool bTemp = m_pImpl->m_pTOXMark->IsMainEntry();
2267 2 : aRet <<= bTemp;
2268 : }
2269 2 : break;
2270 : }
2271 : }
2272 0 : else if (m_pImpl->m_bIsDescriptor)
2273 : {
2274 0 : switch(pEntry->nWID)
2275 : {
2276 : case WID_ALT_TEXT:
2277 0 : aRet <<= m_pImpl->m_sAltText;
2278 0 : break;
2279 : case WID_LEVEL:
2280 0 : aRet <<= static_cast<sal_Int16>(m_pImpl->m_nLevel);
2281 0 : break;
2282 : case WID_PRIMARY_KEY:
2283 0 : aRet <<= m_pImpl->m_sPrimaryKey;
2284 0 : break;
2285 : case WID_SECONDARY_KEY:
2286 0 : aRet <<= m_pImpl->m_sSecondaryKey;
2287 0 : break;
2288 : case WID_TEXT_READING:
2289 0 : aRet <<= m_pImpl->m_sTextReading;
2290 0 : break;
2291 : case WID_PRIMARY_KEY_READING:
2292 0 : aRet <<= m_pImpl->m_sPrimaryKeyReading;
2293 0 : break;
2294 : case WID_SECONDARY_KEY_READING:
2295 0 : aRet <<= m_pImpl->m_sSecondaryKeyReading;
2296 0 : break;
2297 : case WID_USER_IDX_NAME :
2298 0 : aRet <<= m_pImpl->m_sUserIndexName;
2299 0 : break;
2300 : case WID_MAIN_ENTRY:
2301 : {
2302 0 : aRet <<= static_cast<sal_Bool>(m_pImpl->m_bMainEntry);
2303 : }
2304 0 : break;
2305 : }
2306 : }
2307 : else
2308 : {
2309 0 : throw uno::RuntimeException();
2310 : }
2311 53 : return aRet;
2312 : }
2313 :
2314 : void SAL_CALL
2315 0 : SwXDocumentIndexMark::addPropertyChangeListener(
2316 : const OUString& /*rPropertyName*/,
2317 : const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
2318 : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2319 : uno::RuntimeException)
2320 : {
2321 : OSL_FAIL("SwXDocumentIndexMark::addPropertyChangeListener(): not implemented");
2322 0 : }
2323 :
2324 : void SAL_CALL
2325 0 : SwXDocumentIndexMark::removePropertyChangeListener(
2326 : const OUString& /*rPropertyName*/,
2327 : const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
2328 : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2329 : uno::RuntimeException)
2330 : {
2331 : OSL_FAIL("SwXDocumentIndexMark::removePropertyChangeListener(): not implemented");
2332 0 : }
2333 :
2334 : void SAL_CALL
2335 0 : SwXDocumentIndexMark::addVetoableChangeListener(
2336 : const OUString& /*rPropertyName*/,
2337 : const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
2338 : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2339 : uno::RuntimeException)
2340 : {
2341 : OSL_FAIL("SwXDocumentIndexMark::addVetoableChangeListener(): not implemented");
2342 0 : }
2343 :
2344 : void SAL_CALL
2345 0 : SwXDocumentIndexMark::removeVetoableChangeListener(
2346 : const OUString& /*rPropertyName*/,
2347 : const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
2348 : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2349 : uno::RuntimeException)
2350 : {
2351 : OSL_FAIL("SwXDocumentIndexMark::removeVetoableChangeListener(): not implemented");
2352 0 : }
2353 :
2354 : /******************************************************************
2355 : * SwXDocumentIndexes
2356 : ******************************************************************/
2357 344 : SwXDocumentIndexes::SwXDocumentIndexes(SwDoc *const _pDoc)
2358 344 : : SwUnoCollection(_pDoc)
2359 : {
2360 344 : }
2361 :
2362 688 : SwXDocumentIndexes::~SwXDocumentIndexes()
2363 : {
2364 688 : }
2365 :
2366 : OUString SAL_CALL
2367 0 : SwXDocumentIndexes::getImplementationName() throw (uno::RuntimeException)
2368 : {
2369 0 : return OUString("SwXDocumentIndexes");
2370 : }
2371 :
2372 : static char const*const g_ServicesDocumentIndexes[] =
2373 : {
2374 : "com.sun.star.text.DocumentIndexes",
2375 : };
2376 :
2377 : sal_Bool SAL_CALL
2378 0 : SwXDocumentIndexes::supportsService(const OUString& rServiceName)
2379 : throw (uno::RuntimeException)
2380 : {
2381 : return ::sw::SupportsServiceImpl(
2382 : SAL_N_ELEMENTS(g_ServicesDocumentIndexes),
2383 0 : g_ServicesDocumentIndexes, rServiceName);
2384 : }
2385 :
2386 : uno::Sequence< OUString > SAL_CALL
2387 0 : SwXDocumentIndexes::getSupportedServiceNames() throw (uno::RuntimeException)
2388 : {
2389 : return ::sw::GetSupportedServiceNamesImpl(
2390 0 : SAL_N_ELEMENTS(g_ServicesDocumentIndexes), g_ServicesDocumentIndexes);
2391 : }
2392 :
2393 : sal_Int32 SAL_CALL
2394 359 : SwXDocumentIndexes::getCount() throw (uno::RuntimeException)
2395 : {
2396 359 : SolarMutexGuard aGuard;
2397 :
2398 359 : if(!IsValid())
2399 0 : throw uno::RuntimeException();
2400 :
2401 359 : sal_uInt32 nRet = 0;
2402 359 : const SwSectionFmts& rFmts = GetDoc()->GetSections();
2403 371 : for( sal_uInt16 n = 0; n < rFmts.size(); ++n )
2404 : {
2405 12 : const SwSection* pSect = rFmts[ n ]->GetSection();
2406 15 : if( TOX_CONTENT_SECTION == pSect->GetType() &&
2407 3 : pSect->GetFmt()->GetSectionNode() )
2408 : {
2409 3 : ++nRet;
2410 : }
2411 : }
2412 359 : return nRet;
2413 : }
2414 :
2415 : uno::Any SAL_CALL
2416 4 : SwXDocumentIndexes::getByIndex(sal_Int32 nIndex)
2417 : throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException,
2418 : uno::RuntimeException)
2419 : {
2420 4 : SolarMutexGuard aGuard;
2421 :
2422 4 : if(!IsValid())
2423 0 : throw uno::RuntimeException();
2424 :
2425 4 : sal_Int32 nIdx = 0;
2426 :
2427 4 : const SwSectionFmts& rFmts = GetDoc()->GetSections();
2428 5 : for( sal_uInt16 n = 0; n < rFmts.size(); ++n )
2429 : {
2430 4 : const SwSection* pSect = rFmts[ n ]->GetSection();
2431 12 : if( TOX_CONTENT_SECTION == pSect->GetType() &&
2432 8 : pSect->GetFmt()->GetSectionNode() &&
2433 4 : nIdx++ == nIndex )
2434 : {
2435 : const uno::Reference< text::XDocumentIndex > xTmp =
2436 : SwXDocumentIndex::CreateXDocumentIndex(
2437 3 : *GetDoc(), static_cast<SwTOXBaseSection const&>(*pSect));
2438 6 : uno::Any aRet;
2439 3 : aRet <<= xTmp;
2440 9 : return aRet;
2441 : }
2442 : }
2443 :
2444 4 : throw lang::IndexOutOfBoundsException();
2445 : }
2446 :
2447 : uno::Any SAL_CALL
2448 16 : SwXDocumentIndexes::getByName(const OUString& rName)
2449 : throw (container::NoSuchElementException, lang::WrappedTargetException,
2450 : uno::RuntimeException)
2451 : {
2452 16 : SolarMutexGuard aGuard;
2453 :
2454 16 : if(!IsValid())
2455 0 : throw uno::RuntimeException();
2456 :
2457 32 : String sToFind(rName);
2458 16 : const SwSectionFmts& rFmts = GetDoc()->GetSections();
2459 129 : for( sal_uInt16 n = 0; n < rFmts.size(); ++n )
2460 : {
2461 128 : const SwSection* pSect = rFmts[ n ]->GetSection();
2462 314 : if( TOX_CONTENT_SECTION == pSect->GetType() &&
2463 186 : pSect->GetFmt()->GetSectionNode() &&
2464 58 : (static_cast<SwTOXBaseSection const*>(pSect)->GetTOXName()
2465 58 : == sToFind))
2466 : {
2467 : const uno::Reference< text::XDocumentIndex > xTmp =
2468 : SwXDocumentIndex::CreateXDocumentIndex(
2469 15 : *GetDoc(), static_cast<SwTOXBaseSection const&>(*pSect));
2470 30 : uno::Any aRet;
2471 15 : aRet <<= xTmp;
2472 45 : return aRet;
2473 : }
2474 : }
2475 17 : throw container::NoSuchElementException();
2476 : }
2477 :
2478 : uno::Sequence< OUString > SAL_CALL
2479 1 : SwXDocumentIndexes::getElementNames() throw (uno::RuntimeException)
2480 : {
2481 1 : SolarMutexGuard aGuard;
2482 :
2483 1 : if(!IsValid())
2484 0 : throw uno::RuntimeException();
2485 :
2486 1 : const SwSectionFmts& rFmts = GetDoc()->GetSections();
2487 1 : sal_Int32 nCount = 0;
2488 : sal_uInt16 n;
2489 2 : for( n = 0; n < rFmts.size(); ++n )
2490 : {
2491 1 : SwSection const*const pSect = rFmts[ n ]->GetSection();
2492 2 : if( TOX_CONTENT_SECTION == pSect->GetType() &&
2493 1 : pSect->GetFmt()->GetSectionNode() )
2494 : {
2495 1 : ++nCount;
2496 : }
2497 : }
2498 :
2499 1 : uno::Sequence< OUString > aRet(nCount);
2500 1 : OUString* pArray = aRet.getArray();
2501 : sal_uInt16 nCnt;
2502 2 : for( n = 0, nCnt = 0; n < rFmts.size(); ++n )
2503 : {
2504 1 : SwSection const*const pSect = rFmts[ n ]->GetSection();
2505 2 : if( TOX_CONTENT_SECTION == pSect->GetType() &&
2506 1 : pSect->GetFmt()->GetSectionNode())
2507 : {
2508 2 : pArray[nCnt++] = OUString(
2509 2 : static_cast<SwTOXBaseSection const*>(pSect)->GetTOXName());
2510 : }
2511 : }
2512 1 : return aRet;
2513 : }
2514 :
2515 : sal_Bool SAL_CALL
2516 2 : SwXDocumentIndexes::hasByName(const OUString& rName)
2517 : throw (uno::RuntimeException)
2518 : {
2519 2 : SolarMutexGuard aGuard;
2520 :
2521 2 : if(!IsValid())
2522 0 : throw uno::RuntimeException();
2523 :
2524 4 : String sToFind(rName);
2525 2 : const SwSectionFmts& rFmts = GetDoc()->GetSections();
2526 3 : for( sal_uInt16 n = 0; n < rFmts.size(); ++n )
2527 : {
2528 2 : SwSection const*const pSect = rFmts[ n ]->GetSection();
2529 4 : if( TOX_CONTENT_SECTION == pSect->GetType() &&
2530 2 : pSect->GetFmt()->GetSectionNode())
2531 : {
2532 4 : if (static_cast<SwTOXBaseSection const*>(pSect)->GetTOXName()
2533 2 : == sToFind)
2534 : {
2535 1 : return sal_True;
2536 : }
2537 : }
2538 : }
2539 3 : return sal_False;
2540 : }
2541 :
2542 : uno::Type SAL_CALL
2543 1 : SwXDocumentIndexes::getElementType() throw (uno::RuntimeException)
2544 : {
2545 1 : return text::XDocumentIndex::static_type();
2546 : }
2547 :
2548 : sal_Bool SAL_CALL
2549 1 : SwXDocumentIndexes::hasElements() throw (uno::RuntimeException)
2550 : {
2551 1 : return 0 != getCount();
2552 : }
2553 :
2554 : /******************************************************************
2555 : * SwXDocumentIndex::StyleAccess_Impl
2556 : ******************************************************************/
2557 2 : SwXDocumentIndex::StyleAccess_Impl::StyleAccess_Impl(
2558 : SwXDocumentIndex& rParentIdx)
2559 2 : : m_xParent(&rParentIdx)
2560 : {
2561 2 : }
2562 :
2563 4 : SwXDocumentIndex::StyleAccess_Impl::~StyleAccess_Impl()
2564 : {
2565 4 : }
2566 :
2567 : OUString SAL_CALL
2568 0 : SwXDocumentIndex::StyleAccess_Impl::getImplementationName()
2569 : throw (uno::RuntimeException)
2570 : {
2571 0 : return OUString("SwXDocumentIndex::StyleAccess_Impl");
2572 : }
2573 :
2574 : static char const*const g_ServicesIndexStyleAccess[] =
2575 : {
2576 : "com.sun.star.text.DocumentIndexParagraphStyles",
2577 : };
2578 :
2579 : sal_Bool SAL_CALL
2580 0 : SwXDocumentIndex::StyleAccess_Impl::supportsService(
2581 : const OUString& rServiceName)
2582 : throw (uno::RuntimeException)
2583 : {
2584 : return ::sw::SupportsServiceImpl(
2585 : SAL_N_ELEMENTS(g_ServicesIndexStyleAccess),
2586 0 : g_ServicesIndexStyleAccess, rServiceName);
2587 : }
2588 :
2589 : uno::Sequence< OUString > SAL_CALL
2590 0 : SwXDocumentIndex::StyleAccess_Impl::getSupportedServiceNames()
2591 : throw (uno::RuntimeException)
2592 : {
2593 : return ::sw::GetSupportedServiceNamesImpl(
2594 : SAL_N_ELEMENTS(g_ServicesIndexStyleAccess),
2595 0 : g_ServicesIndexStyleAccess);
2596 : }
2597 :
2598 : void SAL_CALL
2599 0 : SwXDocumentIndex::StyleAccess_Impl::replaceByIndex(
2600 : sal_Int32 nIndex, const uno::Any& rElement)
2601 : throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException,
2602 : lang::WrappedTargetException, uno::RuntimeException)
2603 : {
2604 0 : SolarMutexGuard aGuard;
2605 :
2606 0 : if(nIndex < 0 || nIndex > MAXLEVEL)
2607 : {
2608 0 : throw lang::IndexOutOfBoundsException();
2609 : }
2610 :
2611 0 : SwTOXBase & rTOXBase( m_xParent->m_pImpl->GetTOXSectionOrThrow() );
2612 :
2613 0 : uno::Sequence<OUString> aSeq;
2614 0 : if(!(rElement >>= aSeq))
2615 : {
2616 0 : throw lang::IllegalArgumentException();
2617 : }
2618 :
2619 0 : const sal_Int32 nStyles = aSeq.getLength();
2620 0 : const OUString* pStyles = aSeq.getConstArray();
2621 0 : String sSetStyles;
2622 0 : String aString;
2623 0 : for(sal_Int32 i = 0; i < nStyles; i++)
2624 : {
2625 0 : if(i)
2626 : {
2627 0 : sSetStyles += TOX_STYLE_DELIMITER;
2628 : }
2629 0 : SwStyleNameMapper::FillUIName(pStyles[i], aString,
2630 0 : nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, true);
2631 0 : sSetStyles += aString;
2632 : }
2633 0 : rTOXBase.SetStyleNames(sSetStyles, static_cast<sal_uInt16>(nIndex));
2634 0 : }
2635 :
2636 : sal_Int32 SAL_CALL
2637 2 : SwXDocumentIndex::StyleAccess_Impl::getCount() throw (uno::RuntimeException)
2638 : {
2639 2 : return MAXLEVEL;
2640 : }
2641 :
2642 : uno::Any SAL_CALL
2643 20 : SwXDocumentIndex::StyleAccess_Impl::getByIndex(sal_Int32 nIndex)
2644 : throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException,
2645 : uno::RuntimeException)
2646 : {
2647 20 : SolarMutexGuard aGuard;
2648 :
2649 20 : if(nIndex < 0 || nIndex > MAXLEVEL)
2650 : {
2651 0 : throw lang::IndexOutOfBoundsException();
2652 : }
2653 :
2654 20 : SwTOXBase & rTOXBase( m_xParent->m_pImpl->GetTOXSectionOrThrow() );
2655 :
2656 : const String& rStyles =
2657 20 : rTOXBase.GetStyleNames(static_cast<sal_uInt16>(nIndex));
2658 20 : const sal_uInt16 nStyles = comphelper::string::getTokenCount(rStyles, TOX_STYLE_DELIMITER);
2659 40 : uno::Sequence<OUString> aStyles(nStyles);
2660 20 : OUString* pStyles = aStyles.getArray();
2661 40 : String aString;
2662 20 : for(sal_uInt16 i = 0; i < nStyles; i++)
2663 : {
2664 : SwStyleNameMapper::FillProgName(
2665 : rStyles.GetToken(i, TOX_STYLE_DELIMITER),
2666 : aString,
2667 : nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL,
2668 0 : true);
2669 0 : pStyles[i] = OUString( aString );
2670 : }
2671 20 : uno::Any aRet(&aStyles, ::getCppuType((uno::Sequence<OUString>*)0));
2672 40 : return aRet;
2673 : }
2674 :
2675 : uno::Type SAL_CALL
2676 0 : SwXDocumentIndex::StyleAccess_Impl::getElementType()
2677 : throw (uno::RuntimeException)
2678 : {
2679 0 : return ::getCppuType((uno::Sequence<OUString>*)0);
2680 : }
2681 :
2682 : sal_Bool SAL_CALL
2683 0 : SwXDocumentIndex::StyleAccess_Impl::hasElements() throw (uno::RuntimeException)
2684 : {
2685 0 : return sal_True;
2686 : }
2687 :
2688 : /******************************************************************
2689 : * SwXDocumentIndex::TokenAccess_Impl
2690 : ******************************************************************/
2691 106 : SwXDocumentIndex::TokenAccess_Impl::TokenAccess_Impl(
2692 : SwXDocumentIndex& rParentIdx)
2693 106 : : m_xParent(&rParentIdx)
2694 : {
2695 106 : }
2696 :
2697 212 : SwXDocumentIndex::TokenAccess_Impl::~TokenAccess_Impl()
2698 : {
2699 212 : }
2700 :
2701 : OUString SAL_CALL
2702 0 : SwXDocumentIndex::TokenAccess_Impl::getImplementationName()
2703 : throw (uno::RuntimeException)
2704 : {
2705 0 : return OUString("SwXDocumentIndex::TokenAccess_Impl");
2706 : }
2707 :
2708 : static char const*const g_ServicesIndexTokenAccess[] =
2709 : {
2710 : "com.sun.star.text.DocumentIndexLevelFormat",
2711 : };
2712 :
2713 : sal_Bool SAL_CALL
2714 0 : SwXDocumentIndex::TokenAccess_Impl::supportsService(
2715 : const OUString& rServiceName)
2716 : throw (uno::RuntimeException)
2717 : {
2718 : return ::sw::SupportsServiceImpl(
2719 : SAL_N_ELEMENTS(g_ServicesIndexTokenAccess),
2720 0 : g_ServicesIndexTokenAccess, rServiceName);
2721 : }
2722 :
2723 : uno::Sequence< OUString > SAL_CALL
2724 0 : SwXDocumentIndex::TokenAccess_Impl::getSupportedServiceNames()
2725 : throw (uno::RuntimeException)
2726 : {
2727 : return ::sw::GetSupportedServiceNamesImpl(
2728 : SAL_N_ELEMENTS(g_ServicesIndexTokenAccess),
2729 0 : g_ServicesIndexTokenAccess);
2730 : }
2731 :
2732 : struct TokenType {
2733 : const char *pName;
2734 : enum FormTokenType eTokenType;
2735 : };
2736 :
2737 : static const struct TokenType g_TokenTypes[] =
2738 : {
2739 : { "TokenEntryNumber", TOKEN_ENTRY_NO },
2740 : { "TokenEntryText", TOKEN_ENTRY_TEXT },
2741 : { "TokenTabStop", TOKEN_TAB_STOP },
2742 : { "TokenText", TOKEN_TEXT },
2743 : { "TokenPageNumber", TOKEN_PAGE_NUMS },
2744 : { "TokenChapterInfo", TOKEN_CHAPTER_INFO },
2745 : { "TokenHyperlinkStart", TOKEN_LINK_START },
2746 : { "TokenHyperlinkEnd", TOKEN_LINK_END },
2747 : { "TokenBibliographyDataField", TOKEN_AUTHORITY },
2748 : { 0, static_cast<enum FormTokenType>(0) }
2749 : };
2750 :
2751 : void SAL_CALL
2752 99 : SwXDocumentIndex::TokenAccess_Impl::replaceByIndex(
2753 : sal_Int32 nIndex, const uno::Any& rElement)
2754 : throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException,
2755 : lang::WrappedTargetException, uno::RuntimeException)
2756 : {
2757 99 : SolarMutexGuard aGuard;
2758 :
2759 99 : SwTOXBase & rTOXBase( m_xParent->m_pImpl->GetTOXSectionOrThrow() );
2760 :
2761 99 : if ((nIndex < 0) || (nIndex > rTOXBase.GetTOXForm().GetFormMax()))
2762 : {
2763 0 : throw lang::IndexOutOfBoundsException();
2764 : }
2765 :
2766 198 : uno::Sequence<beans::PropertyValues> aSeq;
2767 99 : if(!(rElement >>= aSeq))
2768 : {
2769 0 : throw lang::IllegalArgumentException();
2770 : }
2771 :
2772 198 : String sPattern;
2773 99 : const sal_Int32 nTokens = aSeq.getLength();
2774 99 : const beans::PropertyValues* pTokens = aSeq.getConstArray();
2775 590 : for(sal_Int32 i = 0; i < nTokens; i++)
2776 : {
2777 491 : const beans::PropertyValue* pProperties = pTokens[i].getConstArray();
2778 491 : const sal_Int32 nProperties = pTokens[i].getLength();
2779 : //create an invalid token
2780 491 : SwFormToken aToken(TOKEN_END);
2781 1451 : for(sal_Int32 j = 0; j < nProperties; j++)
2782 : {
2783 960 : if ( pProperties[j].Name == "TokenType" )
2784 : {
2785 : const OUString sTokenType =
2786 491 : lcl_AnyToString(pProperties[j].Value);
2787 2684 : for (TokenType const* pTokenType = g_TokenTypes;
2788 : pTokenType->pName; ++pTokenType)
2789 : {
2790 2684 : if (sTokenType.equalsAscii(pTokenType->pName))
2791 : {
2792 491 : aToken.eTokenType = pTokenType->eTokenType;
2793 491 : break;
2794 : }
2795 491 : }
2796 : }
2797 469 : else if ( pProperties[j].Name == "CharacterStyleName" )
2798 : {
2799 0 : String sCharStyleName;
2800 : SwStyleNameMapper::FillUIName(
2801 0 : lcl_AnyToString(pProperties[j].Value),
2802 : sCharStyleName,
2803 : nsSwGetPoolIdFromName::GET_POOLID_CHRFMT,
2804 0 : true);
2805 0 : aToken.sCharStyleName = sCharStyleName;
2806 : aToken.nPoolId = SwStyleNameMapper::GetPoolIdFromUIName (
2807 0 : sCharStyleName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
2808 : }
2809 469 : else if ( pProperties[j].Name == "TabStopRightAligned" )
2810 : {
2811 52 : const sal_Bool bRight = lcl_AnyToBool(pProperties[j].Value);
2812 : aToken.eTabAlign = bRight ?
2813 52 : SVX_TAB_ADJUST_END : SVX_TAB_ADJUST_LEFT;
2814 : }
2815 417 : else if ( pProperties[j].Name == "TabStopPosition" )
2816 : {
2817 0 : sal_Int32 nPosition = 0;
2818 0 : if (!(pProperties[j].Value >>= nPosition))
2819 : {
2820 0 : throw lang::IllegalArgumentException();
2821 : }
2822 0 : nPosition = MM100_TO_TWIP(nPosition);
2823 0 : if(nPosition < 0)
2824 : {
2825 0 : throw lang::IllegalArgumentException();
2826 : }
2827 0 : aToken.nTabStopPosition = nPosition;
2828 : }
2829 417 : else if ( pProperties[j].Name == "TabStopFillCharacter" )
2830 : {
2831 : const OUString sFillChar =
2832 52 : lcl_AnyToString(pProperties[j].Value);
2833 52 : if (sFillChar.getLength() > 1)
2834 : {
2835 0 : throw lang::IllegalArgumentException();
2836 : }
2837 : aToken.cTabFillChar =
2838 52 : sFillChar.isEmpty() ? ' ' : sFillChar[0];
2839 : }
2840 365 : else if ( pProperties[j].Name == "Text" )
2841 : {
2842 135 : const OUString sText = lcl_AnyToString(pProperties[j].Value);
2843 135 : aToken.sText = sText;
2844 : }
2845 230 : else if ( pProperties[j].Name == "ChapterFormat" )
2846 : {
2847 0 : sal_Int16 nFormat = lcl_AnyToInt16(pProperties[j].Value);
2848 0 : switch(nFormat)
2849 : {
2850 : case text::ChapterFormat::NUMBER:
2851 0 : nFormat = CF_NUMBER;
2852 0 : break;
2853 : case text::ChapterFormat::NAME:
2854 0 : nFormat = CF_TITLE;
2855 0 : break;
2856 : case text::ChapterFormat::NAME_NUMBER:
2857 0 : nFormat = CF_NUM_TITLE;
2858 0 : break;
2859 : case text::ChapterFormat::NO_PREFIX_SUFFIX:
2860 0 : nFormat = CF_NUMBER_NOPREPST;
2861 0 : break;
2862 : case text::ChapterFormat::DIGIT:
2863 0 : nFormat = CF_NUM_NOPREPST_TITLE;
2864 0 : break;
2865 : default:
2866 0 : throw lang::IllegalArgumentException();
2867 : }
2868 0 : aToken.nChapterFormat = nFormat;
2869 : }
2870 : // #i53420#
2871 230 : else if ( pProperties[j].Name == "ChapterLevel" )
2872 : {
2873 0 : const sal_Int16 nLevel = lcl_AnyToInt16(pProperties[j].Value);
2874 0 : if( nLevel < 1 || nLevel > MAXLEVEL )
2875 : {
2876 0 : throw lang::IllegalArgumentException();
2877 : }
2878 0 : aToken.nOutlineLevel = nLevel;
2879 : }
2880 230 : else if ( pProperties[j].Name == "BibliographyDataField" )
2881 : {
2882 178 : sal_Int16 nType = 0;
2883 178 : pProperties[j].Value >>= nType;
2884 178 : if(nType < 0 || nType > text::BibliographyDataField::ISBN)
2885 : {
2886 0 : lang::IllegalArgumentException aExcept;
2887 0 : aExcept.Message = "BibliographyDataField - wrong value";
2888 0 : aExcept.ArgumentPosition = static_cast< sal_Int16 >(j);
2889 0 : throw aExcept;
2890 : }
2891 178 : aToken.nAuthorityField = nType;
2892 : }
2893 : // #i21237#
2894 52 : else if ( pProperties[j].Name == "WithTab" )
2895 : {
2896 52 : aToken.bWithTab = lcl_AnyToBool(pProperties[j].Value);
2897 : }
2898 :
2899 : }
2900 : //exception if wrong TokenType
2901 491 : if(TOKEN_END <= aToken.eTokenType )
2902 : {
2903 0 : throw lang::IllegalArgumentException();
2904 : }
2905 : // set TokenType from TOKEN_ENTRY_TEXT to TOKEN_ENTRY if it is
2906 : // not a content index
2907 546 : if(TOKEN_ENTRY_TEXT == aToken.eTokenType &&
2908 55 : (TOX_CONTENT != rTOXBase.GetType()))
2909 : {
2910 35 : aToken.eTokenType = TOKEN_ENTRY;
2911 : }
2912 : // #i53420#
2913 : // check for chapter format allowed values if it was TOKEN_ENTRY_NO type
2914 : // only allowed value are CF_NUMBER and CF_NUM_NOPREPST_TITLE
2915 : // reading from file
2916 491 : if( TOKEN_ENTRY_NO == aToken.eTokenType )
2917 : {
2918 20 : switch(aToken.nChapterFormat)
2919 : {
2920 : case CF_NUMBER:
2921 : case CF_NUM_NOPREPST_TITLE:
2922 20 : break;
2923 : default:
2924 0 : throw lang::IllegalArgumentException();
2925 : }
2926 : }
2927 491 : sPattern += aToken.GetString();
2928 491 : }
2929 99 : SwForm aForm(rTOXBase.GetTOXForm());
2930 99 : aForm.SetPattern(static_cast<sal_uInt16>(nIndex), sPattern);
2931 198 : rTOXBase.SetTOXForm(aForm);
2932 99 : }
2933 :
2934 : sal_Int32 SAL_CALL
2935 21 : SwXDocumentIndex::TokenAccess_Impl::getCount() throw (uno::RuntimeException)
2936 : {
2937 21 : SolarMutexGuard aGuard;
2938 :
2939 21 : const sal_Int32 nRet = m_xParent->m_pImpl->GetFormMax();
2940 21 : return nRet;
2941 : }
2942 :
2943 : uno::Any SAL_CALL
2944 61 : SwXDocumentIndex::TokenAccess_Impl::getByIndex(sal_Int32 nIndex)
2945 : throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException,
2946 : uno::RuntimeException)
2947 : {
2948 61 : SolarMutexGuard aGuard;
2949 :
2950 61 : SwTOXBase & rTOXBase( m_xParent->m_pImpl->GetTOXSectionOrThrow() );
2951 :
2952 61 : if ((nIndex < 0) || (nIndex > rTOXBase.GetTOXForm().GetFormMax()))
2953 : {
2954 0 : throw lang::IndexOutOfBoundsException();
2955 : }
2956 :
2957 : // #i21237#
2958 61 : SwFormTokens aPattern = rTOXBase.GetTOXForm().
2959 183 : GetPattern(static_cast<sal_uInt16>(nIndex));
2960 61 : SwFormTokens::iterator aIt = aPattern.begin();
2961 :
2962 61 : sal_uInt16 nTokenCount = 0;
2963 122 : uno::Sequence< beans::PropertyValues > aRetSeq;
2964 122 : String aString;
2965 389 : while(aIt != aPattern.end()) // #i21237#
2966 : {
2967 267 : nTokenCount++;
2968 267 : aRetSeq.realloc(nTokenCount);
2969 267 : beans::PropertyValues* pTokenProps = aRetSeq.getArray();
2970 267 : SwFormToken aToken = *aIt; // #i21237#
2971 :
2972 : uno::Sequence< beans::PropertyValue >& rCurTokenSeq =
2973 267 : pTokenProps[nTokenCount-1];
2974 : SwStyleNameMapper::FillProgName(
2975 : aToken.sCharStyleName,
2976 : aString,
2977 : nsSwGetPoolIdFromName::GET_POOLID_CHRFMT,
2978 267 : true );
2979 534 : const OUString aProgCharStyle( aString );
2980 267 : switch(aToken.eTokenType)
2981 : {
2982 : case TOKEN_ENTRY_NO:
2983 : {
2984 : // #i53420#
2985 : // writing to file (from doc to properties)
2986 10 : sal_Int32 nElements = 2;
2987 10 : sal_Int32 nCurrentElement = 0;
2988 :
2989 : // check for default value
2990 10 : if (aToken.nChapterFormat != CF_NUMBER)
2991 : {
2992 0 : nElements++;//we need the element
2993 : }
2994 10 : if( aToken.nOutlineLevel != MAXLEVEL )
2995 : {
2996 0 : nElements++;
2997 : }
2998 :
2999 10 : rCurTokenSeq.realloc( nElements );
3000 :
3001 10 : beans::PropertyValue* pArr = rCurTokenSeq.getArray();
3002 :
3003 10 : pArr[nCurrentElement].Name = "TokenType";
3004 20 : pArr[nCurrentElement++].Value <<=
3005 10 : OUString("TokenEntryNumber");
3006 :
3007 10 : pArr[nCurrentElement].Name = "CharacterStyleName";
3008 10 : pArr[nCurrentElement++].Value <<= aProgCharStyle;
3009 10 : if( aToken.nChapterFormat != CF_NUMBER )
3010 : {
3011 0 : pArr[nCurrentElement].Name = "ChapterFormat";
3012 : sal_Int16 nVal;
3013 : // the allowed values for chapter format, when used as entry number,
3014 : // are CF_NUMBER and CF_NUM_NOPREPST_TITLE only, all else forced to
3015 : //CF_NUMBER
3016 0 : switch(aToken.nChapterFormat)
3017 : {
3018 : default:
3019 : case CF_NUMBER:
3020 0 : nVal = text::ChapterFormat::NUMBER;
3021 0 : break;
3022 : case CF_NUM_NOPREPST_TITLE:
3023 0 : nVal = text::ChapterFormat::DIGIT;
3024 0 : break;
3025 : }
3026 0 : pArr[nCurrentElement++].Value <<= nVal;
3027 : }
3028 :
3029 : // only a ChapterLevel != MAXLEVEL is registered
3030 10 : if (aToken.nOutlineLevel != MAXLEVEL)
3031 : {
3032 0 : pArr[nCurrentElement].Name = "ChapterLevel";
3033 0 : pArr[nCurrentElement].Value <<= aToken.nOutlineLevel;
3034 : }
3035 : }
3036 10 : break;
3037 : case TOKEN_ENTRY: // no difference between Entry and Entry Text
3038 : case TOKEN_ENTRY_TEXT:
3039 : {
3040 37 : rCurTokenSeq.realloc( 2 );
3041 37 : beans::PropertyValue* pArr = rCurTokenSeq.getArray();
3042 :
3043 37 : pArr[0].Name = "TokenType";
3044 37 : pArr[0].Value <<= OUString("TokenEntryText");
3045 :
3046 37 : pArr[1].Name = "CharacterStyleName";
3047 37 : pArr[1].Value <<= aProgCharStyle;
3048 : }
3049 37 : break;
3050 : case TOKEN_TAB_STOP:
3051 : {
3052 32 : rCurTokenSeq.realloc(5); // #i21237#
3053 32 : beans::PropertyValue* pArr = rCurTokenSeq.getArray();
3054 :
3055 32 : pArr[0].Name = "TokenType";
3056 32 : pArr[0].Value <<= OUString("TokenTabStop");
3057 :
3058 32 : if(SVX_TAB_ADJUST_END == aToken.eTabAlign)
3059 : {
3060 32 : pArr[1].Name = "TabStopRightAligned";
3061 32 : sal_Bool bTemp = sal_True;
3062 32 : pArr[1].Value.setValue(&bTemp, ::getCppuBooleanType());
3063 : }
3064 : else
3065 : {
3066 0 : pArr[1].Name = "TabStopPosition";
3067 0 : sal_Int32 nPos = (TWIP_TO_MM100(aToken.nTabStopPosition));
3068 0 : if(nPos < 0)
3069 0 : nPos = 0;
3070 0 : pArr[1].Value <<= (sal_Int32)nPos;
3071 : }
3072 32 : pArr[2].Name = "TabStopFillCharacter";
3073 32 : pArr[2].Value <<= OUString(aToken.cTabFillChar);
3074 32 : pArr[3].Name = "CharacterStyleName";
3075 32 : pArr[3].Value <<= aProgCharStyle;
3076 : // #i21237#
3077 32 : pArr[4].Name = "WithTab";
3078 32 : pArr[4].Value <<= static_cast<sal_Bool>(aToken.bWithTab);
3079 : }
3080 32 : break;
3081 : case TOKEN_TEXT:
3082 : {
3083 67 : rCurTokenSeq.realloc( 3 );
3084 67 : beans::PropertyValue* pArr = rCurTokenSeq.getArray();
3085 :
3086 67 : pArr[0].Name = "TokenType";
3087 67 : pArr[0].Value <<= OUString("TokenText");
3088 :
3089 67 : pArr[1].Name = "CharacterStyleName";
3090 67 : pArr[1].Value <<= aProgCharStyle;
3091 :
3092 67 : pArr[2].Name = "Text";
3093 67 : pArr[2].Value <<= OUString(aToken.sText);
3094 : }
3095 67 : break;
3096 : case TOKEN_PAGE_NUMS:
3097 : {
3098 32 : rCurTokenSeq.realloc( 2 );
3099 32 : beans::PropertyValue* pArr = rCurTokenSeq.getArray();
3100 :
3101 32 : pArr[0].Name = "TokenType";
3102 32 : pArr[0].Value <<= OUString("TokenPageNumber");
3103 :
3104 32 : pArr[1].Name = "CharacterStyleName";
3105 32 : pArr[1].Value <<= aProgCharStyle;
3106 : }
3107 32 : break;
3108 : case TOKEN_CHAPTER_INFO:
3109 : {
3110 0 : rCurTokenSeq.realloc( 4 );
3111 0 : beans::PropertyValue* pArr = rCurTokenSeq.getArray();
3112 :
3113 0 : pArr[0].Name = "TokenType";
3114 0 : pArr[0].Value <<= OUString("TokenChapterInfo");
3115 :
3116 0 : pArr[1].Name = "CharacterStyleName";
3117 0 : pArr[1].Value <<= aProgCharStyle;
3118 :
3119 0 : pArr[2].Name = "ChapterFormat";
3120 0 : sal_Int16 nVal = text::ChapterFormat::NUMBER;
3121 0 : switch(aToken.nChapterFormat)
3122 : {
3123 : case CF_NUMBER:
3124 0 : nVal = text::ChapterFormat::NUMBER;
3125 0 : break;
3126 : case CF_TITLE:
3127 0 : nVal = text::ChapterFormat::NAME;
3128 0 : break;
3129 : case CF_NUM_TITLE:
3130 0 : nVal = text::ChapterFormat::NAME_NUMBER;
3131 0 : break;
3132 : case CF_NUMBER_NOPREPST:
3133 0 : nVal = text::ChapterFormat::NO_PREFIX_SUFFIX;
3134 0 : break;
3135 : case CF_NUM_NOPREPST_TITLE:
3136 0 : nVal = text::ChapterFormat::DIGIT;
3137 0 : break;
3138 : }
3139 0 : pArr[2].Value <<= nVal;
3140 : // #i53420#
3141 0 : pArr[3].Name = "ChapterLevel";
3142 0 : pArr[3].Value <<= aToken.nOutlineLevel;
3143 : }
3144 0 : break;
3145 : case TOKEN_LINK_START:
3146 : {
3147 0 : rCurTokenSeq.realloc( 2 );
3148 0 : beans::PropertyValue* pArr = rCurTokenSeq.getArray();
3149 :
3150 0 : pArr[0].Name = "TokenType";
3151 0 : pArr[0].Value <<=
3152 0 : OUString("TokenHyperlinkStart");
3153 0 : pArr[1].Name = "CharacterStyleName";
3154 0 : pArr[1].Value <<= aProgCharStyle;
3155 : }
3156 0 : break;
3157 : case TOKEN_LINK_END:
3158 : {
3159 0 : rCurTokenSeq.realloc( 1 );
3160 0 : beans::PropertyValue* pArr = rCurTokenSeq.getArray();
3161 :
3162 0 : pArr[0].Name = "TokenType";
3163 0 : pArr[0].Value <<=
3164 0 : OUString("TokenHyperlinkEnd");
3165 : }
3166 0 : break;
3167 : case TOKEN_AUTHORITY:
3168 : {
3169 89 : rCurTokenSeq.realloc( 3 );
3170 89 : beans::PropertyValue* pArr = rCurTokenSeq.getArray();
3171 :
3172 89 : pArr[0].Name = "TokenType";
3173 178 : pArr[0].Value <<=
3174 89 : OUString("TokenBibliographyDataField");
3175 :
3176 89 : pArr[1].Name = "CharacterStyleName";
3177 89 : pArr[1].Value <<= aProgCharStyle;
3178 :
3179 89 : pArr[2].Name = "BibliographyDataField";
3180 89 : pArr[2].Value <<= sal_Int16(aToken.nAuthorityField);
3181 : }
3182 89 : break;
3183 :
3184 : default:
3185 : ;
3186 : }
3187 :
3188 267 : ++aIt; // #i21237#
3189 267 : }
3190 :
3191 61 : uno::Any aRet;
3192 61 : aRet <<= aRetSeq;
3193 122 : return aRet;
3194 : }
3195 :
3196 : uno::Type SAL_CALL
3197 0 : SwXDocumentIndex::TokenAccess_Impl::getElementType()
3198 : throw (uno::RuntimeException)
3199 : {
3200 0 : return ::getCppuType((uno::Sequence< beans::PropertyValues >*)0);
3201 : }
3202 :
3203 : sal_Bool SAL_CALL
3204 0 : SwXDocumentIndex::TokenAccess_Impl::hasElements()
3205 : throw (uno::RuntimeException)
3206 : {
3207 0 : return sal_True;
3208 99 : }
3209 :
3210 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|