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