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