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