update dev300-m58
[ooovba.git] / sw / source / core / unocore / unoidx.cxx
blobe2d0612eaa2b9e5178960e2c83ce515ccbcec87a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unoidx.cxx,v $
10 * $Revision: 1.68 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <hints.hxx>
36 #include <tools/debug.hxx>
37 #include <vos/mutex.hxx>
38 #include <vcl/svapp.hxx>
39 #include <svx/unolingu.hxx>
40 #include <com/sun/star/text/ChapterFormat.hpp>
41 #include <com/sun/star/text/ReferenceFieldPart.hpp>
42 #include <com/sun/star/text/BibliographyDataField.hpp>
43 #include <com/sun/star/frame/XModel.hpp>
44 #include <com/sun/star/text/XTextDocument.hpp>
45 #include <com/sun/star/beans/PropertyAttribute.hpp>
46 #ifndef _CMDID_H
47 #include <cmdid.h>
48 #endif
49 #include <swtypes.hxx>
50 #include <shellres.hxx>
51 #include <viewsh.hxx>
52 #include <doc.hxx>
53 #include <docary.hxx>
54 #include <poolfmt.hxx>
55 #ifndef _POOLFMT_HRC
56 #include <poolfmt.hrc>
57 #endif
58 #include <pagedesc.hxx>
59 #include <unomap.hxx>
60 #include <unoobj.hxx>
61 #include <doctxm.hxx>
62 #include <txttxmrk.hxx>
63 #include <unocrsr.hxx>
64 #include <unostyle.hxx>
65 #include <ndtxt.hxx>
66 #include <unoidx.hxx>
67 #ifndef _DOCSH_HXX //autogen
68 #include <docsh.hxx>
69 #endif
70 #include <chpfld.hxx>
71 #include <SwStyleNameMapper.hxx>
73 using namespace ::com::sun::star;
74 using ::rtl::OUString;
76 //-----------------------------------------------------------------------------
77 String lcl_AnyToString(uno::Any rVal) throw(lang::IllegalArgumentException)
79 OUString sRet;
80 if(!(rVal >>= sRet))
81 throw lang::IllegalArgumentException();
82 return sRet;
84 //-----------------------------------------------------------------------------
85 sal_Int16 lcl_AnyToInt16(uno::Any rVal) throw(lang::IllegalArgumentException)
87 sal_Int16 nRet = 0;
88 if(!(rVal >>= nRet))
89 throw lang::IllegalArgumentException();
90 return nRet;
92 //-----------------------------------------------------------------------------
93 sal_Bool lcl_AnyToBool(uno::Any rVal) throw(lang::IllegalArgumentException)
95 sal_Bool bRet = sal_False;
96 if(!(rVal >>= bRet))
97 throw lang::IllegalArgumentException();
98 return bRet;
100 /******************************************************************************
102 ******************************************************************************/
103 //-----------------------------------------------------------------------------
104 void lcl_ReAssignTOXType(SwDoc* pDoc, SwTOXBase& rTOXBase, const OUString& rNewName)
106 sal_uInt16 nUserCount = pDoc->GetTOXTypeCount( TOX_USER );
107 const SwTOXType* pNewType = 0;
108 for(sal_uInt16 nUser = 0; nUser < nUserCount; nUser++)
110 const SwTOXType* pType = pDoc->GetTOXType( TOX_USER, nUser );
111 if(pType->GetTypeName().Equals((String)rNewName))
113 pNewType = pType;
114 break;
117 if(!pNewType)
119 SwTOXType aNewType(TOX_USER, rNewName);
120 pNewType = pDoc->InsertTOXType( aNewType );
122 //has to be non-const-casted
123 ((SwTOXType*)pNewType)->Add(&rTOXBase);
125 //-----------------------------------------------------------------------------
126 static const char cUserDefined[] = "User-Defined";
127 static const char cUserSuffix[] = " (user)";
128 #define USER_LEN 12
129 #define USER_AND_SUFFIXLEN 19
131 void lcl_ConvertTOUNameToProgrammaticName(OUString& rTmp)
133 ShellResource* pShellRes = ViewShell::GetShellRes();
135 if(rTmp.equals(pShellRes->aTOXUserName))
136 rTmp = OUString(C2U(cUserDefined));
137 //if the version is not English but the alternative index's name is "User-Defined"
138 //a " (user)" is appended
139 else if(rTmp.equalsAscii(cUserDefined))
140 rTmp += C2U(cUserSuffix);
142 //-----------------------------------------------------------------------------
143 void lcl_ConvertTOUNameToUserName(OUString& rTmp)
145 ShellResource* pShellRes = ViewShell::GetShellRes();
146 if(rTmp.equalsAscii(cUserDefined))
148 rTmp = pShellRes->aTOXUserName;
150 else if(!pShellRes->aTOXUserName.EqualsAscii(cUserDefined) &&
151 USER_AND_SUFFIXLEN == rTmp.getLength())
153 String sToChange(rTmp);
154 //make sure that in non-English versions the " (user)" suffix is removed
155 if(!sToChange.SearchAscii(cUserDefined) && USER_LEN == sToChange.SearchAscii(cUserSuffix))
156 rTmp = C2U(cUserDefined);
160 /******************************************************************
161 * SwXDocumentIndex
162 ******************************************************************/
163 /* -----------------20.06.98 11:06-------------------
165 * --------------------------------------------------*/
166 class SwDocIdxProperties_Impl
168 SwTOXBase* pTOXBase;
169 OUString sUserTOXTypeName;
170 public:
171 SwTOXBase& GetTOXBase() {return *pTOXBase;}
172 SwDocIdxProperties_Impl(const SwTOXType* pType);
173 ~SwDocIdxProperties_Impl(){delete pTOXBase;}
175 const OUString& GetTypeName()const {return sUserTOXTypeName;}
176 void SetTypeName(const OUString& rSet) {sUserTOXTypeName = rSet;}
178 /* -----------------20.06.98 11:41-------------------
180 * --------------------------------------------------*/
181 SwDocIdxProperties_Impl::SwDocIdxProperties_Impl(const SwTOXType* pType)
183 SwForm aForm(pType->GetType());
184 pTOXBase = new SwTOXBase(pType, aForm,
185 nsSwTOXElement::TOX_MARK, pType->GetTypeName());
186 if(pType->GetType() == TOX_CONTENT || pType->GetType() == TOX_USER)
187 pTOXBase->SetLevel(MAXLEVEL);
188 sUserTOXTypeName = pType->GetTypeName();
190 /* -----------------------------10.03.00 18:02--------------------------------
192 ---------------------------------------------------------------------------*/
193 const uno::Sequence< sal_Int8 > & SwXDocumentIndex::getUnoTunnelId()
195 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
196 return aSeq;
198 /* -----------------------------10.03.00 18:04--------------------------------
200 ---------------------------------------------------------------------------*/
201 sal_Int64 SAL_CALL SwXDocumentIndex::getSomething( const uno::Sequence< sal_Int8 >& rId )
202 throw(uno::RuntimeException)
204 if( rId.getLength() == 16
205 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
206 rId.getConstArray(), 16 ) )
208 return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
210 return 0;
212 /* -----------------------------06.04.00 15:01--------------------------------
214 ---------------------------------------------------------------------------*/
215 OUString SwXDocumentIndex::getImplementationName(void) throw( uno::RuntimeException )
217 return C2U("SwXDocumentIndex");
219 /* -----------------------------06.04.00 15:01--------------------------------
221 ---------------------------------------------------------------------------*/
222 BOOL SwXDocumentIndex::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
224 return C2U("com.sun.star.text.BaseIndex") == rServiceName ||
225 ( TOX_INDEX == eTOXType && C2U("com.sun.star.text.DocumentIndex") == rServiceName) ||
226 ( TOX_CONTENT == eTOXType && C2U("com.sun.star.text.ContentIndex") == rServiceName) ||
227 ( TOX_USER == eTOXType && C2U("com.sun.star.text.UserDefinedIndex") == rServiceName) ||
228 ( TOX_ILLUSTRATIONS == eTOXType && C2U("com.sun.star.text.IllustrationsIndex") == rServiceName) ||
229 ( TOX_TABLES == eTOXType && C2U("com.sun.star.text.TableIndex") == rServiceName) ||
230 ( TOX_OBJECTS == eTOXType && C2U("com.sun.star.text.ObjectIndex") == rServiceName) ||
231 ( TOX_AUTHORITIES == eTOXType && C2U("com.sun.star.text.Bibliography") == rServiceName);
233 /* -----------------------------06.04.00 15:01--------------------------------
235 ---------------------------------------------------------------------------*/
236 uno::Sequence< OUString > SwXDocumentIndex::getSupportedServiceNames(void) throw( uno::RuntimeException )
238 uno::Sequence< OUString > aRet(2);
239 OUString* pArray = aRet.getArray();
240 pArray[0] = C2U("com.sun.star.text.BaseIndex");
241 switch( eTOXType )
243 case TOX_INDEX: pArray[1] = C2U("com.sun.star.text.DocumentIndex");break;
244 case TOX_CONTENT: pArray[1] = C2U("com.sun.star.text.ContentIndex");break;
245 case TOX_TABLES: pArray[1] = C2U("com.sun.star.text.TableIndex");break;
246 case TOX_ILLUSTRATIONS: pArray[1] = C2U("com.sun.star.text.IllustrationsIndex");break;
247 case TOX_OBJECTS: pArray[1] = C2U("com.sun.star.text.ObjectIndex");break;
248 case TOX_AUTHORITIES : pArray[1] = C2U("com.sun.star.text.Bibliography");break;
249 //case TOX_USER:
250 default:
251 pArray[1] = C2U("com.sun.star.text.UserDefinedIndex");
253 return aRet;
255 /*-- 14.12.98 09:35:03---------------------------------------------------
257 -----------------------------------------------------------------------*/
258 TYPEINIT1(SwXDocumentIndex, SwClient)
259 SwXDocumentIndex::SwXDocumentIndex(const SwTOXBaseSection* pB, SwDoc* pDc) :
260 aLstnrCntnr( (text::XTextContent*)this),
261 m_pPropSet(0),
262 m_pDoc(pDc),
263 pBase(pB),
264 eTOXType(TOX_USER),
265 bIsDescriptor(sal_False),
266 pProps(0),
267 pStyleAccess(0),
268 pTokenAccess(0)
270 if(pBase && m_pDoc)
272 pBase->GetFmt()->Add(this);
273 sal_uInt16 PropertyId;
274 eTOXType = pBase->SwTOXBase::GetType();
275 switch( eTOXType )
277 case TOX_INDEX: PropertyId = PROPERTY_MAP_INDEX_IDX; break;
278 case TOX_CONTENT: PropertyId = PROPERTY_MAP_INDEX_CNTNT; break;
279 case TOX_TABLES: PropertyId = PROPERTY_MAP_INDEX_TABLES; break;
280 case TOX_ILLUSTRATIONS: PropertyId = PROPERTY_MAP_INDEX_ILLUSTRATIONS; break;
281 case TOX_OBJECTS: PropertyId = PROPERTY_MAP_INDEX_OBJECTS; break;
282 case TOX_AUTHORITIES : PropertyId = PROPERTY_MAP_BIBLIOGRAPHY; break;
283 //case TOX_USER:
284 default:
285 PropertyId = PROPERTY_MAP_INDEX_USER;
287 m_pPropSet = aSwMapProvider.GetPropertySet(PropertyId);
290 /* -----------------15.01.99 14:59-------------------
292 * --------------------------------------------------*/
293 SwXDocumentIndex::SwXDocumentIndex(TOXTypes eType, SwDoc& rDoc) :
294 aLstnrCntnr( (text::XTextContent*)this),
295 m_pDoc(0),
296 pBase(0),
297 eTOXType(eType),
298 bIsDescriptor(sal_True),
299 pProps(new SwDocIdxProperties_Impl(rDoc.GetTOXType(eType, 0))),
300 pStyleAccess(0),
301 pTokenAccess(0)
303 sal_uInt16 PropertyId;
304 switch(eType)
306 case TOX_INDEX: PropertyId = PROPERTY_MAP_INDEX_IDX; break;
307 case TOX_CONTENT: PropertyId = PROPERTY_MAP_INDEX_CNTNT; break;
308 case TOX_TABLES: PropertyId = PROPERTY_MAP_INDEX_TABLES; break;
309 case TOX_ILLUSTRATIONS: PropertyId = PROPERTY_MAP_INDEX_ILLUSTRATIONS; break;
310 case TOX_OBJECTS: PropertyId = PROPERTY_MAP_INDEX_OBJECTS; break;
311 case TOX_AUTHORITIES : PropertyId = PROPERTY_MAP_BIBLIOGRAPHY; break;
312 //case TOX_USER:
313 default:
314 PropertyId = PROPERTY_MAP_INDEX_USER;
316 m_pPropSet = aSwMapProvider.GetPropertySet(PropertyId);
319 /*-- 14.12.98 09:35:04---------------------------------------------------
321 -----------------------------------------------------------------------*/
322 SwXDocumentIndex::~SwXDocumentIndex()
324 delete pProps;
326 /*-- 14.12.98 09:35:05---------------------------------------------------
328 -----------------------------------------------------------------------*/
329 OUString SwXDocumentIndex::getServiceName(void) throw( uno::RuntimeException )
331 USHORT nObjectType = SW_SERVICE_TYPE_INDEX;
332 switch(eTOXType)
334 // case TOX_INDEX: break;
335 case TOX_USER: nObjectType = SW_SERVICE_USER_INDEX;break;
336 case TOX_CONTENT: nObjectType = SW_SERVICE_CONTENT_INDEX;break;
337 case TOX_ILLUSTRATIONS: nObjectType = SW_SERVICE_INDEX_ILLUSTRATIONS;break;
338 case TOX_OBJECTS: nObjectType = SW_SERVICE_INDEX_OBJECTS;break;
339 case TOX_TABLES: nObjectType = SW_SERVICE_INDEX_TABLES;break;
340 case TOX_AUTHORITIES: nObjectType = SW_SERVICE_INDEX_BIBLIOGRAPHY;break;
341 default:
344 return SwXServiceProvider::GetProviderName(nObjectType);
346 /*-- 14.12.98 09:35:05---------------------------------------------------
348 -----------------------------------------------------------------------*/
349 void SwXDocumentIndex::update(void) throw( uno::RuntimeException )
351 vos::OGuard aGuard(Application::GetSolarMutex());
352 SwSectionFmt *pFmt = GetFmt();
353 SwTOXBase* pTOXBase = pFmt ? (SwTOXBaseSection*)pFmt->GetSection() : 0;
354 if(!pTOXBase)
355 throw uno::RuntimeException();
356 ((SwTOXBaseSection*)pTOXBase)->Update();
357 // Seitennummern eintragen
358 ((SwTOXBaseSection*)pTOXBase)->UpdatePageNum();
360 /*-- 14.12.98 09:35:05---------------------------------------------------
362 -----------------------------------------------------------------------*/
363 uno::Reference< beans::XPropertySetInfo > SwXDocumentIndex::getPropertySetInfo(void) throw( uno::RuntimeException )
365 uno::Reference< beans::XPropertySetInfo > aRef = m_pPropSet->getPropertySetInfo();
366 return aRef;
368 /*-- 14.12.98 09:35:05---------------------------------------------------
370 -----------------------------------------------------------------------*/
371 void SwXDocumentIndex::setPropertyValue(const OUString& rPropertyName,
372 const uno::Any& aValue)
373 throw( beans::UnknownPropertyException, beans::PropertyVetoException,
374 lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
376 vos::OGuard aGuard(Application::GetSolarMutex());
377 const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap()->getByName(rPropertyName);
378 if (!pEntry)
379 throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
380 if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
381 throw beans::PropertyVetoException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
383 SwTOXBase* pTOXBase = 0;
384 if(GetFmt())
385 pTOXBase = (SwTOXBaseSection*)GetFmt()->GetSection();
386 else if(bIsDescriptor)
387 pTOXBase = &pProps->GetTOXBase();
388 if(pTOXBase)
390 sal_uInt16 nCreate = pTOXBase->GetCreateType();
391 sal_uInt16 nTOIOptions = 0;
392 sal_uInt16 nOLEOptions = pTOXBase->GetOLEOptions();
393 TOXTypes eTxBaseType = pTOXBase->GetTOXType()->GetType();
394 if( eTxBaseType == TOX_INDEX )
395 nTOIOptions = pTOXBase->GetOptions();
396 SwForm aForm(pTOXBase->GetTOXForm());
397 sal_Bool bForm = sal_False;
398 SfxItemSet* pAttrSet = 0;
399 switch(pEntry->nWID)
401 case WID_IDX_TITLE :
403 OUString sNewName;
404 aValue >>= sNewName;
405 pTOXBase->SetTitle(sNewName);
407 break;
408 case WID_IDX_NAME:
410 OUString sNewName;
411 aValue >>= sNewName;
412 pTOXBase->SetTOXName(sNewName);
414 break;
415 case WID_USER_IDX_NAME:
417 OUString sNewName;
418 aValue >>= sNewName;
419 lcl_ConvertTOUNameToUserName(sNewName);
420 DBG_ASSERT(TOX_USER == eTxBaseType, "tox type name can only be changed for user indexes");
421 if(GetFmt())
423 OUString sTmp = pTOXBase->GetTOXType()->GetTypeName();
424 if(sTmp != sNewName)
426 lcl_ReAssignTOXType(GetFmt()->GetDoc(), *pTOXBase, sNewName);
429 else
430 pProps->SetTypeName(sNewName);
432 break;
433 case WID_IDX_LOCALE:
435 lang::Locale aLocale;
436 if(aValue>>= aLocale)
437 pTOXBase->SetLanguage(SvxLocaleToLanguage(aLocale));
438 else
439 throw lang::IllegalArgumentException();
441 break;
442 case WID_IDX_SORT_ALGORITHM:
444 OUString sTmp;
445 if(aValue >>= sTmp)
446 pTOXBase->SetSortAlgorithm(sTmp);
447 else
448 throw lang::IllegalArgumentException();
450 break;
451 case WID_LEVEL :
452 pTOXBase->SetLevel(lcl_AnyToInt16(aValue));
453 break;
454 case WID_CREATE_FROM_MARKS :
455 nCreate = lcl_AnyToBool(aValue) ? nCreate | nsSwTOXElement::TOX_MARK: nCreate & ~nsSwTOXElement::TOX_MARK;
456 break;
457 case WID_CREATE_FROM_OUTLINE :
458 nCreate = lcl_AnyToBool(aValue) ? nCreate | nsSwTOXElement::TOX_OUTLINELEVEL: nCreate & ~nsSwTOXElement::TOX_OUTLINELEVEL;
459 break;
460 // case WID_PARAGRAPH_STYLE_NAMES :DBG_ERROR("not implemented")
461 // break;
462 case WID_CREATE_FROM_CHAPTER :
463 pTOXBase->SetFromChapter(lcl_AnyToBool(aValue));
464 break;
465 case WID_CREATE_FROM_LABELS :
466 pTOXBase->SetFromObjectNames(! lcl_AnyToBool(aValue));
467 break;
468 case WID_PROTECTED :
470 sal_Bool bSet = lcl_AnyToBool(aValue);
471 pTOXBase->SetProtected(bSet);
472 if(GetFmt())
473 ((SwTOXBaseSection*)pTOXBase)->SetProtect(bSet);
475 break;
476 case WID_USE_ALPHABETICAL_SEPARATORS:
477 nTOIOptions = lcl_AnyToBool(aValue) ?
478 nTOIOptions | nsSwTOIOptions::TOI_ALPHA_DELIMITTER : nTOIOptions & ~nsSwTOIOptions::TOI_ALPHA_DELIMITTER;
479 break;
480 case WID_USE_KEY_AS_ENTRY :
481 nTOIOptions = lcl_AnyToBool(aValue) ?
482 nTOIOptions | nsSwTOIOptions::TOI_KEY_AS_ENTRY : nTOIOptions & ~nsSwTOIOptions::TOI_KEY_AS_ENTRY;
483 break;
484 case WID_USE_COMBINED_ENTRIES :
485 nTOIOptions = lcl_AnyToBool(aValue) ?
486 nTOIOptions | nsSwTOIOptions::TOI_SAME_ENTRY : nTOIOptions & ~nsSwTOIOptions::TOI_SAME_ENTRY;
487 break;
488 case WID_IS_CASE_SENSITIVE :
489 nTOIOptions = lcl_AnyToBool(aValue) ?
490 nTOIOptions | nsSwTOIOptions::TOI_CASE_SENSITIVE : nTOIOptions & ~nsSwTOIOptions::TOI_CASE_SENSITIVE;
491 break;
492 case WID_USE_P_P :
493 nTOIOptions = lcl_AnyToBool(aValue) ?
494 nTOIOptions | nsSwTOIOptions::TOI_FF : nTOIOptions & ~nsSwTOIOptions::TOI_FF;
495 break;
496 case WID_USE_DASH :
497 nTOIOptions = lcl_AnyToBool(aValue) ?
498 nTOIOptions | nsSwTOIOptions::TOI_DASH : nTOIOptions & ~nsSwTOIOptions::TOI_DASH;
499 break;
500 case WID_USE_UPPER_CASE :
501 nTOIOptions = lcl_AnyToBool(aValue) ?
502 nTOIOptions | nsSwTOIOptions::TOI_INITIAL_CAPS : nTOIOptions & ~nsSwTOIOptions::TOI_INITIAL_CAPS;
503 break;
504 case WID_IS_COMMA_SEPARATED :
505 bForm = sal_True;
506 aForm.SetCommaSeparated(lcl_AnyToBool(aValue));
507 break;
508 case WID_LABEL_CATEGORY :
510 // convert file-format/API/external programmatic english name
511 // to internal UI name before usage
512 String aName( SwStyleNameMapper::GetSpecialExtraUIName(
513 lcl_AnyToString(aValue) ) );
514 pTOXBase->SetSequenceName( aName );
516 break;
517 case WID_LABEL_DISPLAY_TYPE :
519 sal_Int16 nVal = lcl_AnyToInt16(aValue);
520 sal_uInt16 nSet = CAPTION_COMPLETE;
521 switch (nVal)
523 case text::ReferenceFieldPart::TEXT: nSet = CAPTION_COMPLETE;
524 break;
525 case text::ReferenceFieldPart::CATEGORY_AND_NUMBER : nSet = CAPTION_NUMBER;
526 break;
527 case text::ReferenceFieldPart::ONLY_CAPTION : nSet = CAPTION_TEXT;
528 break;
529 default:
530 throw lang::IllegalArgumentException();
532 pTOXBase->SetCaptionDisplay((SwCaptionDisplay)nSet);
534 break;
535 case WID_USE_LEVEL_FROM_SOURCE :
536 pTOXBase->SetLevelFromChapter(lcl_AnyToBool(aValue));
537 break;
538 case WID_MAIN_ENTRY_CHARACTER_STYLE_NAME :
540 String aString;
541 SwStyleNameMapper::FillUIName(lcl_AnyToString(aValue), aString, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True);
542 pTOXBase->SetMainEntryCharStyle( aString );
544 break;
545 case WID_CREATE_FROM_TABLES :
546 nCreate = lcl_AnyToBool(aValue) ? nCreate | nsSwTOXElement::TOX_TABLE : nCreate & ~nsSwTOXElement::TOX_TABLE;
547 break;
548 case WID_CREATE_FROM_TEXT_FRAMES :
549 nCreate = lcl_AnyToBool(aValue) ? nCreate | nsSwTOXElement::TOX_FRAME : nCreate & ~nsSwTOXElement::TOX_FRAME;
550 break;
551 case WID_CREATE_FROM_GRAPHIC_OBJECTS :
552 nCreate = lcl_AnyToBool(aValue) ? nCreate | nsSwTOXElement::TOX_GRAPHIC : nCreate & ~nsSwTOXElement::TOX_GRAPHIC;
553 break;
554 case WID_CREATE_FROM_EMBEDDED_OBJECTS :
555 if(lcl_AnyToBool(aValue))
556 nCreate |= nsSwTOXElement::TOX_OLE;
557 else
558 nCreate &= ~nsSwTOXElement::TOX_OLE;
559 break;
560 case WID_CREATE_FROM_STAR_MATH:
561 nOLEOptions = lcl_AnyToBool(aValue) ? nOLEOptions | nsSwTOOElements::TOO_MATH : nOLEOptions & ~nsSwTOOElements::TOO_MATH;
562 break;
563 case WID_CREATE_FROM_STAR_CHART :
564 nOLEOptions = lcl_AnyToBool(aValue) ? nOLEOptions | nsSwTOOElements::TOO_CHART : nOLEOptions & ~nsSwTOOElements::TOO_CHART;
565 break;
566 case WID_CREATE_FROM_STAR_CALC :
567 nOLEOptions = lcl_AnyToBool(aValue) ? nOLEOptions | nsSwTOOElements::TOO_CALC : nOLEOptions & ~nsSwTOOElements::TOO_CALC;
568 break;
569 case WID_CREATE_FROM_STAR_DRAW :
570 nOLEOptions = lcl_AnyToBool(aValue) ? nOLEOptions | nsSwTOOElements::TOO_DRAW_IMPRESS : nOLEOptions & ~nsSwTOOElements::TOO_DRAW_IMPRESS;
571 break;
572 case WID_CREATE_FROM_OTHER_EMBEDDED_OBJECTS:
573 nOLEOptions = lcl_AnyToBool(aValue) ? nOLEOptions | nsSwTOOElements::TOO_OTHER : nOLEOptions & ~nsSwTOOElements::TOO_OTHER;
574 break;
575 case WID_PARA_HEAD :
577 String aString;
578 SwStyleNameMapper::FillUIName( lcl_AnyToString(aValue), aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True);
579 bForm = sal_True;
580 //Header steht an Pos 0
581 aForm.SetTemplate( 0, aString );
583 break;
584 case WID_IS_RELATIVE_TABSTOPS:
585 bForm = sal_True;
586 aForm.SetRelTabPos(lcl_AnyToBool(aValue));
587 break;
588 case WID_PARA_SEP :
590 String aString;
591 bForm = sal_True;
592 SwStyleNameMapper::FillUIName( lcl_AnyToString(aValue), aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True);
593 aForm.SetTemplate( 1, aString );
595 break;
596 case WID_CREATE_FROM_PARAGRAPH_STYLES:
597 nCreate = lcl_AnyToBool(aValue) ?
598 (nCreate | nsSwTOXElement::TOX_TEMPLATE) : (nCreate & ~nsSwTOXElement::TOX_TEMPLATE);
599 break;
601 case WID_PARA_LEV1 :
602 case WID_PARA_LEV2 :
603 case WID_PARA_LEV3 :
604 case WID_PARA_LEV4 :
605 case WID_PARA_LEV5 :
606 case WID_PARA_LEV6 :
607 case WID_PARA_LEV7 :
608 case WID_PARA_LEV8 :
609 case WID_PARA_LEV9 :
610 case WID_PARA_LEV10 :
612 bForm = sal_True;
613 // im sdbcx::Index beginnt Lebel 1 bei Pos 2 sonst bei Pos 1
614 sal_uInt16 nLPos = pTOXBase->GetType() == TOX_INDEX ? 2 : 1;
615 String aString;
616 SwStyleNameMapper::FillUIName( lcl_AnyToString(aValue), aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True);
617 aForm.SetTemplate(nLPos + pEntry->nWID - WID_PARA_LEV1, aString );
619 break;
620 default:
621 //this is for items only
622 if(WID_PRIMARY_KEY > pEntry->nWID)
624 const SwAttrSet& rSet = m_pDoc->GetTOXBaseAttrSet(*pTOXBase);
625 pAttrSet = new SfxItemSet(rSet);
626 m_pPropSet->setPropertyValue(rPropertyName, aValue, *pAttrSet);
628 const SwSectionFmts& rSects = m_pDoc->GetSections();
629 const SwSectionFmt* pOwnFmt = GetFmt();
630 for(sal_uInt16 i = 0; i < rSects.Count(); i++)
632 const SwSectionFmt* pTmpFmt = rSects[ i ];
633 if(pTmpFmt == pOwnFmt)
635 m_pDoc->ChgSection( i, *(SwTOXBaseSection*)pTOXBase, pAttrSet );
636 break;
641 pTOXBase->SetCreate(nCreate);
642 pTOXBase->SetOLEOptions(nOLEOptions);
643 if(pTOXBase->GetTOXType()->GetType() == TOX_INDEX)
644 pTOXBase->SetOptions(nTOIOptions);
645 if(bForm)
646 pTOXBase->SetTOXForm(aForm);
647 delete pAttrSet;
649 else
650 throw uno::RuntimeException();
653 /*-- 14.12.98 09:35:05---------------------------------------------------
655 -----------------------------------------------------------------------*/
656 uno::Any SwXDocumentIndex::getPropertyValue(const OUString& rPropertyName)
657 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
659 vos::OGuard aGuard(Application::GetSolarMutex());
660 uno::Any aRet;
661 const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap()->getByName(rPropertyName);
662 if (!pEntry)
663 throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
664 SwTOXBase* pTOXBase = 0;
665 if(GetFmt())
666 pTOXBase = (SwTOXBaseSection*)GetFmt()->GetSection();
667 else if(bIsDescriptor)
668 pTOXBase = &pProps->GetTOXBase();
669 if(pTOXBase)
671 sal_uInt16 nCreate = pTOXBase->GetCreateType();
672 sal_uInt16 nTOIOptions = 0;
673 sal_uInt16 nOLEOptions = pTOXBase->GetOLEOptions();
674 if(pTOXBase->GetTOXType()->GetType() == TOX_INDEX)
675 nTOIOptions = pTOXBase->GetOptions();
676 const SwForm& rForm = pTOXBase->GetTOXForm();
677 sal_Bool bBOOL = sal_True;
678 sal_Bool bRet = sal_False;
679 switch(pEntry->nWID)
681 case WID_IDX_CONTENT_SECTION:
682 case WID_IDX_HEADER_SECTION :
683 bBOOL = sal_False;
684 if(WID_IDX_CONTENT_SECTION == pEntry->nWID)
686 uno::Reference <text::XTextSection> xContentSect = SwXTextSections::GetObject( *GetFmt() );
687 aRet <<= xContentSect;
689 else
691 SwSections aSectArr;
692 GetFmt()->GetChildSections( aSectArr, SORTSECT_NOT, FALSE);
693 for(USHORT i = 0; i < aSectArr.Count(); i++)
695 SwSection* pSect = aSectArr[i];
696 if(pSect->GetType() == TOX_HEADER_SECTION)
698 uno::Reference <text::XTextSection> xHeaderSect = SwXTextSections::GetObject( *pSect->GetFmt() );
699 aRet <<= xHeaderSect;
700 break;
704 break;
705 case WID_IDX_TITLE :
707 bBOOL = sal_False;
708 OUString uRet(pTOXBase->GetTitle());
709 aRet <<= uRet;
710 break;
712 case WID_IDX_NAME:
713 bBOOL = sal_False;
714 aRet <<= OUString(pTOXBase->GetTOXName());
715 break;
716 case WID_USER_IDX_NAME:
718 bBOOL = sal_False;
719 OUString sTmp;
720 if(!IsDescriptor())
721 sTmp = pTOXBase->GetTOXType()->GetTypeName();
722 else
723 sTmp = pProps->GetTypeName();
724 //I18N
725 lcl_ConvertTOUNameToProgrammaticName(sTmp);
726 aRet <<= sTmp;
728 break;
729 case WID_IDX_LOCALE:
730 bBOOL = sal_False;
731 aRet <<= SvxCreateLocale(pTOXBase->GetLanguage());
732 break;
733 case WID_IDX_SORT_ALGORITHM:
734 bBOOL = sal_False;
735 aRet <<= OUString(pTOXBase->GetSortAlgorithm());
736 break;
737 case WID_LEVEL :
738 bBOOL = sal_False;
739 aRet <<= (sal_Int16)pTOXBase->GetLevel();
740 break;
741 case WID_CREATE_FROM_MARKS :
742 bRet = 0 != (nCreate & nsSwTOXElement::TOX_MARK);
743 break;
744 case WID_CREATE_FROM_OUTLINE :
745 bRet = 0 != (nCreate & nsSwTOXElement::TOX_OUTLINELEVEL);
746 break;
747 case WID_CREATE_FROM_CHAPTER :
748 bRet = pTOXBase->IsFromChapter();
749 break;
750 case WID_CREATE_FROM_LABELS :
751 bRet = ! pTOXBase->IsFromObjectNames();
752 break;
753 case WID_PROTECTED :
754 bRet = pTOXBase->IsProtected();
755 break;
756 case WID_USE_ALPHABETICAL_SEPARATORS:
757 bRet = 0 != (nTOIOptions & nsSwTOIOptions::TOI_ALPHA_DELIMITTER);
758 break;
759 case WID_USE_KEY_AS_ENTRY :
760 bRet = 0 != (nTOIOptions & nsSwTOIOptions::TOI_KEY_AS_ENTRY);
761 break;
762 case WID_USE_COMBINED_ENTRIES :
763 bRet = 0 != (nTOIOptions & nsSwTOIOptions::TOI_SAME_ENTRY);
764 break;
765 case WID_IS_CASE_SENSITIVE :
766 bRet = 0 != (nTOIOptions & nsSwTOIOptions::TOI_CASE_SENSITIVE);
767 break;
768 case WID_USE_P_P:
769 bRet = 0 != (nTOIOptions & nsSwTOIOptions::TOI_FF);
770 break;
771 case WID_USE_DASH :
772 bRet = 0 != (nTOIOptions & nsSwTOIOptions::TOI_DASH);
773 break;
774 case WID_USE_UPPER_CASE :
775 bRet = 0 != (nTOIOptions & nsSwTOIOptions::TOI_INITIAL_CAPS);
776 break;
777 case WID_IS_COMMA_SEPARATED :
778 bRet = rForm.IsCommaSeparated();
779 break;
780 case WID_LABEL_CATEGORY :
782 // convert internal UI name to
783 // file-format/API/external programmatic english name
784 // before usage
785 String aName( SwStyleNameMapper::GetSpecialExtraProgName(
786 pTOXBase->GetSequenceName() ) );
787 aRet <<= OUString( aName );
788 bBOOL = sal_False;
790 break;
791 case WID_LABEL_DISPLAY_TYPE :
793 bBOOL = sal_False;
794 sal_Int16 nSet = text::ReferenceFieldPart::TEXT;
795 switch (pTOXBase->GetCaptionDisplay())
797 case CAPTION_COMPLETE: nSet = text::ReferenceFieldPart::TEXT;break;
798 case CAPTION_NUMBER : nSet = text::ReferenceFieldPart::CATEGORY_AND_NUMBER; break;
799 case CAPTION_TEXT : nSet = text::ReferenceFieldPart::ONLY_CAPTION; break;
801 aRet <<= nSet;
803 break;
804 case WID_USE_LEVEL_FROM_SOURCE :
805 bRet = pTOXBase->IsLevelFromChapter();
806 break;
807 case WID_LEVEL_FORMAT :
809 uno::Reference< container::XIndexReplace > xTokenAcc =
810 ((SwXDocumentIndex*)this)->GetTokenAccess();
811 if(!xTokenAcc.is())
812 xTokenAcc = new SwXIndexTokenAccess_Impl(*
813 (SwXDocumentIndex*)this);
814 aRet.setValue(&xTokenAcc, ::getCppuType((const uno::Reference<container::XIndexReplace>*)0));
815 bBOOL = sal_False;
817 break;
818 case WID_LEVEL_PARAGRAPH_STYLES :
820 uno::Reference< container::XIndexReplace > xStyleAcc =
821 ((SwXDocumentIndex*)this)->GetStyleAccess();
822 if(!xStyleAcc.is())
823 xStyleAcc = new SwXIndexStyleAccess_Impl(*
824 (SwXDocumentIndex*)this);
825 aRet.setValue(&xStyleAcc, ::getCppuType((const uno::Reference<container::XIndexReplace>*)0));
826 bBOOL = sal_False;
828 break;
829 case WID_MAIN_ENTRY_CHARACTER_STYLE_NAME :
831 bBOOL = sal_False;
832 String aString;
833 SwStyleNameMapper::FillProgName(
834 pTOXBase->GetMainEntryCharStyle(),
835 aString,
836 nsSwGetPoolIdFromName::GET_POOLID_CHRFMT,
837 sal_True);
838 aRet <<= OUString( aString );
840 break;
841 case WID_CREATE_FROM_TABLES :
842 bRet = 0 != (nCreate & nsSwTOXElement::TOX_TABLE);
843 break;
844 case WID_CREATE_FROM_TEXT_FRAMES :
845 bRet = 0 != (nCreate & nsSwTOXElement::TOX_FRAME);
846 break;
847 case WID_CREATE_FROM_GRAPHIC_OBJECTS :
848 bRet = 0 != (nCreate & nsSwTOXElement::TOX_GRAPHIC);
849 break;
850 case WID_CREATE_FROM_EMBEDDED_OBJECTS :
851 bRet = 0 != (nCreate & nsSwTOXElement::TOX_OLE);
852 break;
853 case WID_CREATE_FROM_STAR_MATH:
854 bRet = 0 != (nOLEOptions & nsSwTOOElements::TOO_MATH);
855 break;
856 case WID_CREATE_FROM_STAR_CHART :
857 bRet = 0 != (nOLEOptions & nsSwTOOElements::TOO_CHART);
858 break;
859 case WID_CREATE_FROM_STAR_CALC :
860 bRet = 0 != (nOLEOptions & nsSwTOOElements::TOO_CALC);
861 break;
862 case WID_CREATE_FROM_STAR_DRAW :
863 bRet = 0 != (nOLEOptions & nsSwTOOElements::TOO_DRAW_IMPRESS);
864 break;
865 case WID_CREATE_FROM_OTHER_EMBEDDED_OBJECTS:
866 bRet = 0 != (nOLEOptions & nsSwTOOElements::TOO_OTHER);
867 break;
868 case WID_CREATE_FROM_PARAGRAPH_STYLES:
869 bRet = 0 != (nCreate & nsSwTOXElement::TOX_TEMPLATE);
870 break;
871 case WID_PARA_HEAD :
873 //Header steht an Pos 0
874 String aString;
875 SwStyleNameMapper::FillProgName(rForm.GetTemplate( 0 ), aString,
876 nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True );
877 aRet <<= OUString( aString );
878 bBOOL = sal_False;
880 break;
881 case WID_PARA_SEP :
883 String aString;
884 SwStyleNameMapper::FillProgName(
885 rForm.GetTemplate( 1 ),
886 aString,
887 nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL,
888 sal_True);
889 aRet <<= OUString( aString );
890 bBOOL = sal_False;
892 break;
893 case WID_PARA_LEV1 :
894 case WID_PARA_LEV2 :
895 case WID_PARA_LEV3 :
896 case WID_PARA_LEV4 :
897 case WID_PARA_LEV5 :
898 case WID_PARA_LEV6 :
899 case WID_PARA_LEV7 :
900 case WID_PARA_LEV8 :
901 case WID_PARA_LEV9 :
902 case WID_PARA_LEV10 :
904 // im sdbcx::Index beginnt Lebel 1 bei Pos 2 sonst bei Pos 1
905 sal_uInt16 nLPos = pTOXBase->GetType() == TOX_INDEX ? 2 : 1;
906 String aString;
907 SwStyleNameMapper::FillProgName(
908 rForm.GetTemplate(nLPos + pEntry->nWID - WID_PARA_LEV1),
909 aString,
910 nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL,
911 sal_True);
912 aRet <<= OUString( aString );
913 bBOOL = sal_False;
915 break;
916 case WID_IS_RELATIVE_TABSTOPS:
917 bRet = rForm.IsRelTabPos();
918 break;
919 case WID_INDEX_MARKS:
921 SwTOXMarks aMarks;
922 const SwTOXType* pType = pTOXBase->GetTOXType();
923 SwClientIter aIter(*(SwTOXType*)pType);
924 SwTOXMark* pMark = (SwTOXMark*)aIter.First(TYPE(SwTOXMark));
925 while( pMark )
927 if(pMark->GetTxtTOXMark())
928 aMarks.C40_INSERT(SwTOXMark, pMark, aMarks.Count());
929 pMark = (SwTOXMark*)aIter.Next();
931 uno::Sequence< uno::Reference < text::XDocumentIndexMark > > aXMarks(aMarks.Count());
932 uno::Reference<text::XDocumentIndexMark>* pxMarks = aXMarks.getArray();
933 for(USHORT i = 0; i < aMarks.Count(); i++)
935 pMark = aMarks.GetObject(i);
936 pxMarks[i] = SwXDocumentIndexMark::GetObject((SwTOXType*)pType, pMark, m_pDoc);
938 aRet.setValue(&aXMarks, ::getCppuType((uno::Sequence< uno::Reference< text::XDocumentIndexMark > >*)0));
939 bBOOL = sal_False;
941 break;
942 default:
943 //this is for items only
944 bBOOL = sal_False;
945 if(WID_PRIMARY_KEY > pEntry->nWID)
947 const SwAttrSet& rSet = m_pDoc->GetTOXBaseAttrSet(*pTOXBase);
948 aRet = m_pPropSet->getPropertyValue(rPropertyName, rSet);
951 if(bBOOL)
952 aRet.setValue(&bRet, ::getCppuBooleanType());
954 return aRet;
956 /*-- 14.12.98 09:35:06---------------------------------------------------
958 -----------------------------------------------------------------------*/
959 void SwXDocumentIndex::addPropertyChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
961 DBG_WARNING("not implemented");
963 /*-- 14.12.98 09:35:06---------------------------------------------------
965 -----------------------------------------------------------------------*/
966 void SwXDocumentIndex::removePropertyChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
968 DBG_WARNING("not implemented");
970 /*-- 14.12.98 09:35:06---------------------------------------------------
972 -----------------------------------------------------------------------*/
973 void SwXDocumentIndex::addVetoableChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
975 DBG_WARNING("not implemented");
977 /*-- 14.12.98 09:35:07---------------------------------------------------
979 -----------------------------------------------------------------------*/
980 void SwXDocumentIndex::removeVetoableChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
982 DBG_WARNING("not implemented");
984 /*-- 14.12.98 09:35:07---------------------------------------------------
986 -----------------------------------------------------------------------*/
987 void SwXDocumentIndex::Modify( SfxPoolItem *pOld, SfxPoolItem *pNew)
989 BOOL bRemove = FALSE;
990 switch( pOld ? pOld->Which() : 0 )
992 case RES_REMOVE_UNO_OBJECT:
993 case RES_OBJECTDYING:
994 bRemove = (void*)GetRegisteredIn() == ((SwPtrMsgPoolItem *)pOld)->pObject;
995 break;
996 case RES_FMT_CHG:
997 // wurden wir an das neue umgehaengt und wird das alte geloscht?
998 bRemove = ((SwFmtChg*)pNew)->pChangedFmt == GetRegisteredIn() &&
999 ((SwFmtChg*)pOld)->pChangedFmt->IsFmtInDTOR();
1000 break;
1002 if( bRemove )
1004 ((SwModify*)GetRegisteredIn())->Remove( this );
1005 aLstnrCntnr.Disposing();
1008 /* -----------------18.02.99 13:39-------------------
1010 * --------------------------------------------------*/
1011 void SwXDocumentIndex::attachToRange(const uno::Reference< text::XTextRange > & xTextRange)
1012 throw( lang::IllegalArgumentException, uno::RuntimeException )
1014 if(!bIsDescriptor)
1015 throw uno::RuntimeException();
1016 uno::Reference<XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
1017 SwXTextRange* pRange = 0;
1018 OTextCursorHelper* pCursor = 0;
1019 if(xRangeTunnel.is())
1021 pRange = reinterpret_cast< SwXTextRange * >(
1022 sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXTextRange::getUnoTunnelId()) ));
1023 pCursor = reinterpret_cast< OTextCursorHelper * >(
1024 sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
1027 SwDoc* pDoc = pRange ? (SwDoc*)pRange->GetDoc() : pCursor ? (SwDoc*)pCursor->GetDoc() : 0;
1028 if(pDoc )
1030 SwUnoInternalPaM aPam(*pDoc);
1031 //das muss jetzt sal_True liefern
1032 SwXTextRange::XTextRangeToSwPaM(aPam, xTextRange);
1034 const SwTOXBase* pOld = pDoc->GetCurTOX( *aPam.Start() );
1035 if(!pOld)
1037 UnoActionContext aAction(pDoc);
1038 if(aPam.HasMark())
1039 pDoc->DeleteAndJoin(aPam);
1041 SwTOXBase& rTOXBase = pProps->GetTOXBase();
1042 const SwTOXType* pTOXType = rTOXBase.GetTOXType();
1043 if(TOX_USER == pTOXType->GetType() && !pProps->GetTypeName().equals(pTOXType->GetTypeName()))
1045 lcl_ReAssignTOXType(pDoc, rTOXBase, pProps->GetTypeName());
1047 //TODO: apply Section attributes (columns and background)
1048 const SwTOXBaseSection* pTOX = pDoc->InsertTableOf(
1049 *aPam.GetPoint(), rTOXBase, 0, sal_False );
1051 pDoc->SetTOXBaseName( *pTOX, pProps->GetTOXBase().GetTOXName() );
1053 // Seitennummern eintragen
1054 pBase = (const SwTOXBaseSection*)pTOX;
1055 pBase->GetFmt()->Add(this);
1056 ((SwTOXBaseSection*)pTOX)->UpdatePageNum();
1058 else
1059 throw lang::IllegalArgumentException();
1061 DELETEZ(pProps);
1062 m_pDoc = pDoc;
1063 bIsDescriptor = sal_False;
1066 /*-- 15.01.99 14:23:51---------------------------------------------------
1068 -----------------------------------------------------------------------*/
1069 void SwXDocumentIndex::attach(const uno::Reference< text::XTextRange > & xTextRange)
1070 throw( lang::IllegalArgumentException, uno::RuntimeException )
1072 vos::OGuard aGuard(Application::GetSolarMutex());
1073 attachToRange( xTextRange );
1075 /*-- 15.01.99 14:23:56---------------------------------------------------
1077 -----------------------------------------------------------------------*/
1078 uno::Reference< text::XTextRange > SwXDocumentIndex::getAnchor(void) throw( uno::RuntimeException )
1080 vos::OGuard aGuard(Application::GetSolarMutex());
1081 uno::Reference< text::XTextRange > xRet;
1082 if(GetRegisteredIn())
1084 SwSectionFmt* pSectFmt = GetFmt();
1085 const SwNodeIndex* pIdx;
1086 if( 0 != ( pIdx = pSectFmt->GetCntnt().GetCntntIdx() ) &&
1087 pIdx->GetNode().GetNodes().IsDocNodes() )
1089 SwPaM aPaM(*pIdx);
1090 aPaM.Move( fnMoveForward, fnGoCntnt );
1091 aPaM.SetMark();
1092 aPaM.GetPoint()->nNode = *pIdx->GetNode().EndOfSectionNode();
1093 aPaM.Move( fnMoveBackward, fnGoCntnt );
1094 xRet = SwXTextRange::CreateTextRangeFromPosition(pSectFmt->GetDoc(),
1095 *aPaM.GetMark(), aPaM.GetPoint());
1098 else
1099 throw uno::RuntimeException();
1100 return xRet;
1102 /*-- 15.01.99 15:46:48---------------------------------------------------
1104 -----------------------------------------------------------------------*/
1105 void lcl_RemoveChildSections(SwSectionFmt& rParentFmt)
1107 SwSections aTmpArr;
1108 SwDoc* pDoc = rParentFmt.GetDoc();
1109 sal_uInt16 nCnt = rParentFmt.GetChildSections(aTmpArr,SORTSECT_POS);
1110 if( nCnt )
1112 for( sal_uInt16 n = 0; n < nCnt; ++n )
1113 if( aTmpArr[n]->GetFmt()->IsInNodesArr() )
1115 SwSectionFmt* pFmt = aTmpArr[n]->GetFmt();
1116 lcl_RemoveChildSections(*pFmt);
1117 pDoc->DelSectionFmt( pFmt );
1121 void SwXDocumentIndex::dispose(void) throw( uno::RuntimeException )
1123 vos::OGuard aGuard(Application::GetSolarMutex());
1124 if(GetRegisteredIn())
1126 SwSectionFmt* pSectFmt = GetFmt();
1127 pSectFmt->GetDoc()->DeleteTOX( *(SwTOXBaseSection*)pSectFmt->GetSection(), sal_True);
1129 else
1130 throw uno::RuntimeException();
1132 /*-- 15.01.99 15:46:49---------------------------------------------------
1134 -----------------------------------------------------------------------*/
1135 void SwXDocumentIndex::addEventListener(const uno::Reference< lang::XEventListener > & aListener) throw( uno::RuntimeException )
1137 if(!GetRegisteredIn())
1138 throw uno::RuntimeException();
1139 aLstnrCntnr.AddListener(aListener);
1141 /*-- 15.01.99 15:46:54---------------------------------------------------
1143 -----------------------------------------------------------------------*/
1144 void SwXDocumentIndex::removeEventListener(const uno::Reference< lang::XEventListener > & aListener) throw( uno::RuntimeException )
1146 if(!GetRegisteredIn() || !aLstnrCntnr.RemoveListener(aListener))
1147 throw uno::RuntimeException();
1149 /* -----------------30.07.99 11:28-------------------
1151 --------------------------------------------------*/
1152 OUString SwXDocumentIndex::getName(void) throw( uno::RuntimeException )
1154 SwSectionFmt* pSectionFmt = GetFmt();
1155 OUString uRet;
1156 if(bIsDescriptor)
1158 uRet = OUString(pProps->GetTOXBase().GetTOXName());
1160 else if(pSectionFmt)
1162 uRet = OUString(pSectionFmt->GetSection()->GetName());
1164 else
1165 throw uno::RuntimeException();
1166 return uRet;
1168 /* -----------------30.07.99 11:28-------------------
1170 --------------------------------------------------*/
1171 void SwXDocumentIndex::setName(const OUString& rName) throw( uno::RuntimeException )
1173 SwSectionFmt* pSectionFmt = GetFmt();
1174 String sNewName(rName);
1175 sal_Bool bExcept = sal_False;
1176 if(!sNewName.Len())
1177 bExcept = sal_True;
1178 if(bIsDescriptor)
1180 pProps->GetTOXBase().SetTOXName(sNewName);
1182 else if(!pSectionFmt ||
1183 !pSectionFmt->GetDoc()->SetTOXBaseName(
1184 *(SwTOXBaseSection*)pSectionFmt->GetSection(), sNewName))
1185 bExcept = sal_True;
1187 if(bExcept)
1188 throw uno::RuntimeException();
1191 /******************************************************************
1192 * SwXDocumentIndexMark
1193 ******************************************************************/
1194 /* -----------------------------10.03.00 18:02--------------------------------
1196 ---------------------------------------------------------------------------*/
1197 const uno::Sequence< sal_Int8 > & SwXDocumentIndexMark::getUnoTunnelId()
1199 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
1200 return aSeq;
1202 /* -----------------------------10.03.00 18:04--------------------------------
1204 ---------------------------------------------------------------------------*/
1205 sal_Int64 SAL_CALL SwXDocumentIndexMark::getSomething( const uno::Sequence< sal_Int8 >& rId )
1206 throw(uno::RuntimeException)
1208 if( rId.getLength() == 16
1209 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
1210 rId.getConstArray(), 16 ) )
1212 return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
1214 return 0;
1217 TYPEINIT1(SwXDocumentIndexMark, SwClient)
1218 const sal_Char cBaseMark[] = "com.sun.star.text.BaseIndexMark";
1219 const sal_Char cContentMark[] = "com.sun.star.text.ContentIndexMark";
1220 const sal_Char cIdxMark[] = "com.sun.star.text.DocumentIndexMark";
1221 const sal_Char cIdxMarkAsian[] = "com.sun.star.text.DocumentIndexMarkAsian";
1222 const sal_Char cUserMark[] = "com.sun.star.text.UserIndexMark";
1223 const sal_Char cTextContent[] = "com.sun.star.text.TextContent";
1224 /* -----------------------------06.04.00 15:07--------------------------------
1226 ---------------------------------------------------------------------------*/
1227 OUString SwXDocumentIndexMark::getImplementationName(void) throw( uno::RuntimeException )
1229 return C2U("SwXDocumentIndexMark");
1231 /* -----------------------------06.04.00 15:07--------------------------------
1233 ---------------------------------------------------------------------------*/
1234 BOOL SwXDocumentIndexMark::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
1236 return !rServiceName.compareToAscii(cBaseMark)||
1237 !rServiceName.compareToAscii(cTextContent) ||
1238 (eType == TOX_USER && !rServiceName.compareToAscii(cUserMark)) ||
1239 (eType == TOX_CONTENT && !rServiceName.compareToAscii(cContentMark)) ||
1240 (eType == TOX_INDEX && !rServiceName.compareToAscii(cIdxMark)) ||
1241 (eType == TOX_INDEX && !rServiceName.compareToAscii(cIdxMarkAsian));
1243 /* -----------------------------06.04.00 15:07--------------------------------
1245 ---------------------------------------------------------------------------*/
1246 uno::Sequence< OUString > SwXDocumentIndexMark::getSupportedServiceNames(void) throw( uno::RuntimeException )
1248 INT32 nCnt = (eType == TOX_INDEX) ? 4 : 3;
1249 uno::Sequence< OUString > aRet(nCnt);
1250 OUString* pArray = aRet.getArray();
1251 pArray[0] = C2U(cBaseMark);
1252 pArray[1] = C2U(cTextContent);
1253 switch(eType)
1255 case TOX_USER:
1256 pArray[2] = C2U(cUserMark);
1257 break;
1258 case TOX_CONTENT:
1259 pArray[2] = C2U(cContentMark);
1260 break;
1261 case TOX_INDEX:
1262 pArray[2] = C2U(cIdxMark);
1263 pArray[3] = C2U(cIdxMarkAsian);
1264 break;
1266 default:
1269 return aRet;
1271 /*-- 14.12.98 10:25:43---------------------------------------------------
1273 -----------------------------------------------------------------------*/
1274 SwXDocumentIndexMark::SwXDocumentIndexMark(TOXTypes eToxType) :
1275 aLstnrCntnr( (text::XTextContent*)this),
1276 aTypeDepend(this, 0),
1277 m_pDoc(0),
1278 m_pTOXMark(0),
1279 bIsDescriptor(sal_True),
1280 bMainEntry(sal_False),
1281 eType(eToxType),
1282 nLevel(0)
1284 InitMap(eToxType);
1286 /*-- 14.12.98 10:25:44---------------------------------------------------
1288 -----------------------------------------------------------------------*/
1289 SwXDocumentIndexMark::SwXDocumentIndexMark(const SwTOXType* pType,
1290 const SwTOXMark* pMark,
1291 SwDoc* pDc) :
1292 aLstnrCntnr( (text::XTextContent*)this),
1293 aTypeDepend(this, (SwTOXType*)pType),
1294 m_pDoc(pDc),
1295 m_pTOXMark(pMark),
1296 bIsDescriptor(sal_False),
1297 bMainEntry(sal_False),
1298 eType(pType->GetType()),
1299 nLevel(0)
1301 m_pDoc->GetUnoCallBack()->Add(this);
1302 InitMap(eType);
1304 /*-- 14.12.98 10:25:44---------------------------------------------------
1306 -----------------------------------------------------------------------*/
1307 SwXDocumentIndexMark::~SwXDocumentIndexMark()
1311 /* -----------------21.04.99 09:36-------------------
1313 * --------------------------------------------------*/
1314 void SwXDocumentIndexMark::InitMap(TOXTypes eToxType)
1316 sal_uInt16 nMapId = PROPERTY_MAP_USER_MARK; //case TOX_USER:
1317 switch( eToxType )
1319 case TOX_INDEX:
1320 nMapId = PROPERTY_MAP_INDEX_MARK ;
1321 break;
1322 case TOX_CONTENT:
1323 nMapId = PROPERTY_MAP_CNTIDX_MARK;
1324 break;
1325 //case TOX_USER:
1327 default:
1330 m_pPropSet = aSwMapProvider.GetPropertySet(nMapId);
1332 /*-- 14.12.98 10:25:45---------------------------------------------------
1334 -----------------------------------------------------------------------*/
1335 OUString SwXDocumentIndexMark::getMarkEntry(void) throw( uno::RuntimeException )
1337 vos::OGuard aGuard(Application::GetSolarMutex());
1338 SwTOXType* pType = ((SwXDocumentIndexMark*)this)->GetTOXType();
1339 OUString sRet;
1340 if(pType && m_pTOXMark)
1342 sRet = OUString(m_pTOXMark->GetAlternativeText());
1344 else if(bIsDescriptor)
1345 sRet = sAltText;
1346 else
1347 throw uno::RuntimeException();
1348 return sRet;
1350 /*-- 14.12.98 10:25:45---------------------------------------------------
1352 -----------------------------------------------------------------------*/
1353 void SwXDocumentIndexMark::setMarkEntry(const OUString& rIndexEntry) throw( uno::RuntimeException )
1355 vos::OGuard aGuard(Application::GetSolarMutex());
1356 SwTOXType* pType = ((SwXDocumentIndexMark*)this)->GetTOXType();
1357 if(pType && m_pTOXMark)
1359 SwTOXMark aMark(*m_pTOXMark);
1360 aMark.SetAlternativeText(rIndexEntry);
1361 const SwTxtTOXMark* pTxtMark = m_pTOXMark->GetTxtTOXMark();
1362 SwPaM aPam(pTxtMark->GetTxtNode(), *pTxtMark->GetStart());
1363 aPam.SetMark();
1364 if(pTxtMark->GetEnd())
1366 aPam.GetPoint()->nContent = *pTxtMark->GetEnd();
1368 else
1369 aPam.GetPoint()->nContent++;
1371 //die alte Marke loeschen
1372 m_pDoc->Delete(m_pTOXMark);
1373 m_pTOXMark = 0;
1375 SwTxtAttr* pTxtAttr = 0;
1376 sal_Bool bInsAtPos = aMark.IsAlternativeText();
1377 const SwPosition *pStt = aPam.Start(),
1378 *pEnd = aPam.End();
1379 if( bInsAtPos )
1381 SwPaM aTmp( *pStt );
1382 m_pDoc->Insert( aTmp, aMark, 0 );
1383 pTxtAttr = pStt->nNode.GetNode().GetTxtNode()->GetTxtAttr(
1384 pStt->nContent.GetIndex()-1, RES_TXTATR_TOXMARK);
1386 else if( *pEnd != *pStt )
1388 m_pDoc->Insert( aPam, aMark, nsSetAttrMode::SETATTR_DONTEXPAND );
1389 pTxtAttr = pStt->nNode.GetNode().GetTxtNode()->GetTxtAttr(
1390 pStt->nContent, RES_TXTATR_TOXMARK);
1392 //und sonst - Marke geloescht?
1393 if(pTxtAttr)
1394 m_pTOXMark = &pTxtAttr->GetTOXMark();
1396 else if(bIsDescriptor)
1398 sAltText = rIndexEntry;
1400 else
1401 throw uno::RuntimeException();
1403 /* -----------------18.02.99 13:40-------------------
1405 * --------------------------------------------------*/
1406 void SwXDocumentIndexMark::attachToRange(const uno::Reference< text::XTextRange > & xTextRange)
1407 throw( lang::IllegalArgumentException, uno::RuntimeException )
1409 vos::OGuard aGuard(Application::GetSolarMutex());
1410 if(!bIsDescriptor)
1411 throw uno::RuntimeException();
1413 uno::Reference<XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
1414 SwXTextRange* pRange = 0;
1415 OTextCursorHelper* pCursor = 0;
1416 if(xRangeTunnel.is())
1418 pRange = reinterpret_cast< SwXTextRange * >(
1419 sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXTextRange::getUnoTunnelId()) ));
1420 pCursor = reinterpret_cast< OTextCursorHelper * >(
1421 sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( OTextCursorHelper::getUnoTunnelId()) ));
1424 SwDoc* pDoc = pRange ? (SwDoc*)pRange->GetDoc() : pCursor ? (SwDoc*)pCursor->GetDoc() : 0;
1426 if(pDoc )
1428 const SwTOXType* pTOXType = 0;
1429 switch(eType)
1431 case TOX_INDEX:
1432 case TOX_CONTENT:
1433 pTOXType = pDoc->GetTOXType( eType, 0 );
1434 break;
1435 case TOX_USER:
1437 if(!sUserIndexName.Len())
1438 pTOXType = pDoc->GetTOXType( eType, 0 );
1439 else
1441 sal_uInt16 nCount = pDoc->GetTOXTypeCount( eType);
1442 for(sal_uInt16 i = 0; i < nCount; i++)
1444 const SwTOXType* pTemp = pDoc->GetTOXType( eType, i );
1445 if(sUserIndexName == pTemp->GetTypeName())
1447 pTOXType = pTemp;
1448 break;
1451 if(!pTOXType)
1453 SwTOXType aUserType(TOX_USER, sUserIndexName);
1454 pTOXType = pDoc->InsertTOXType(aUserType);
1458 break;
1460 default:
1463 if(!pTOXType)
1464 throw lang::IllegalArgumentException();
1465 pDoc->GetUnoCallBack()->Add(this);
1466 ((SwTOXType*)pTOXType)->Add(&aTypeDepend);
1468 SwUnoInternalPaM aPam(*pDoc);
1469 //das muss jetzt sal_True liefern
1470 SwXTextRange::XTextRangeToSwPaM(aPam, xTextRange);
1471 SwTOXMark aMark (pTOXType);
1472 if(sAltText.Len())
1473 aMark.SetAlternativeText(sAltText);
1474 switch(eType)
1476 case TOX_INDEX:
1477 if(sPrimaryKey.Len())
1478 aMark.SetPrimaryKey(sPrimaryKey);
1479 if(sSecondaryKey.Len())
1480 aMark.SetSecondaryKey(sSecondaryKey);
1481 if(sTextReading.Len())
1482 aMark.SetTextReading(sTextReading);
1483 if(sPrimaryKeyReading.Len())
1484 aMark.SetPrimaryKeyReading(sPrimaryKeyReading);
1485 if(sSecondaryKeyReading.Len())
1486 aMark.SetSecondaryKeyReading(sSecondaryKeyReading);
1487 aMark.SetMainEntry(bMainEntry);
1488 break;
1489 case TOX_USER:
1490 case TOX_CONTENT:
1491 if(USHRT_MAX != nLevel)
1492 aMark.SetLevel(nLevel+1);
1493 break;
1495 default:
1498 UnoActionContext aAction(pDoc);
1499 sal_Bool bMark = *aPam.GetPoint() != *aPam.GetMark();
1500 // Marks ohne Alternativtext ohne selektierten Text koennen nicht eingefuegt werden,
1501 // deshalb hier ein Leerzeichen - ob das die ideale Loesung ist?
1502 if(!bMark && !aMark.GetAlternativeText().Len())
1503 aMark.SetAlternativeText( String(' ') );
1504 pDoc->Insert(aPam, aMark, nsSetAttrMode::SETATTR_DONTEXPAND);
1505 if( bMark && *aPam.GetPoint() > *aPam.GetMark())
1506 aPam.Exchange();
1508 SwTxtAttr* pTxtAttr = 0;
1509 if( bMark )
1510 pTxtAttr = aPam.GetNode()->GetTxtNode()->GetTxtAttr(
1511 aPam.GetPoint()->nContent, RES_TXTATR_TOXMARK );
1512 else
1513 pTxtAttr = aPam.GetNode()->GetTxtNode()->GetTxtAttr(
1514 aPam.GetPoint()->nContent.GetIndex()-1, RES_TXTATR_TOXMARK );
1516 if(pTxtAttr)
1518 m_pTOXMark = &pTxtAttr->GetTOXMark();
1519 m_pDoc = pDoc;
1520 bIsDescriptor = sal_False;
1522 else
1523 throw uno::RuntimeException();
1526 /*-- 14.12.98 10:25:45---------------------------------------------------
1528 -----------------------------------------------------------------------*/
1529 void SwXDocumentIndexMark::attach(const uno::Reference< text::XTextRange > & xTextRange)
1530 throw( lang::IllegalArgumentException, uno::RuntimeException )
1532 vos::OGuard aGuard(Application::GetSolarMutex());
1533 attachToRange( xTextRange );
1535 /*-- 14.12.98 10:25:45---------------------------------------------------
1537 -----------------------------------------------------------------------*/
1538 uno::Reference< text::XTextRange > SwXDocumentIndexMark::getAnchor(void) throw( uno::RuntimeException )
1540 vos::OGuard aGuard(Application::GetSolarMutex());
1541 uno::Reference< text::XTextRange > aRet;
1542 SwTOXType* pType = ((SwXDocumentIndexMark*)this)->GetTOXType();
1543 if(pType && m_pTOXMark)
1545 if( m_pTOXMark->GetTxtTOXMark() )
1547 const SwTxtTOXMark* pTxtMark = m_pTOXMark->GetTxtTOXMark();
1548 SwPaM aPam(pTxtMark->GetTxtNode(), *pTxtMark->GetStart());
1549 aPam.SetMark();
1550 if(pTxtMark->GetEnd())
1552 aPam.GetPoint()->nContent = *pTxtMark->GetEnd();
1554 else
1555 aPam.GetPoint()->nContent++;
1556 uno::Reference< frame::XModel > xModel = m_pDoc->GetDocShell()->GetBaseModel();
1557 uno::Reference< text::XTextDocument > xTDoc(xModel, uno::UNO_QUERY);
1558 aRet = new SwXTextRange(aPam, xTDoc->getText());
1561 if(!aRet.is())
1562 throw uno::RuntimeException();
1563 return aRet;
1565 /*-- 14.12.98 10:25:45---------------------------------------------------
1567 -----------------------------------------------------------------------*/
1568 void SwXDocumentIndexMark::dispose(void) throw( uno::RuntimeException )
1570 vos::OGuard aGuard(Application::GetSolarMutex());
1571 SwTOXType* pType = ((SwXDocumentIndexMark*)this)->GetTOXType();
1572 if(pType && m_pTOXMark)
1574 m_pDoc->Delete(m_pTOXMark);
1576 else
1577 throw uno::RuntimeException();
1579 /*-- 14.12.98 10:25:45---------------------------------------------------
1581 -----------------------------------------------------------------------*/
1582 void SwXDocumentIndexMark::addEventListener(const uno::Reference< lang::XEventListener > & aListener)
1583 throw( uno::RuntimeException )
1585 if(!GetRegisteredIn())
1586 throw uno::RuntimeException();
1587 aLstnrCntnr.AddListener(aListener);
1589 /*-- 14.12.98 10:25:46---------------------------------------------------
1591 -----------------------------------------------------------------------*/
1592 void SwXDocumentIndexMark::removeEventListener(const uno::Reference< lang::XEventListener > & aListener)
1593 throw( uno::RuntimeException )
1595 if(!GetRegisteredIn() || !aLstnrCntnr.RemoveListener(aListener))
1596 throw uno::RuntimeException();
1598 /*-- 14.12.98 10:25:46---------------------------------------------------
1600 -----------------------------------------------------------------------*/
1601 uno::Reference< beans::XPropertySetInfo > SwXDocumentIndexMark::getPropertySetInfo(void)
1602 throw( uno::RuntimeException )
1604 static uno::Reference< beans::XPropertySetInfo > xInfos[3];
1605 int nPos = 0;
1606 switch(eType)
1608 case TOX_INDEX: nPos = 0; break;
1609 case TOX_CONTENT: nPos = 1; break;
1610 case TOX_USER: nPos = 2; break;
1611 default:
1614 if(!xInfos[nPos].is())
1616 uno::Reference< beans::XPropertySetInfo > xInfo = m_pPropSet->getPropertySetInfo();
1617 // extend PropertySetInfo!
1618 const uno::Sequence<beans::Property> aPropSeq = xInfo->getProperties();
1619 xInfos[nPos] = new SfxExtItemPropertySetInfo(
1620 aSwMapProvider.GetPropertyMapEntries(PROPERTY_MAP_PARAGRAPH_EXTENSIONS),
1621 aPropSeq );
1623 return xInfos[nPos];
1625 /*-- 14.12.98 10:25:46---------------------------------------------------
1627 -----------------------------------------------------------------------*/
1628 void SwXDocumentIndexMark::setPropertyValue(const OUString& rPropertyName,
1629 const uno::Any& aValue)
1630 throw( beans::UnknownPropertyException, beans::PropertyVetoException,
1631 lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException )
1633 vos::OGuard aGuard(Application::GetSolarMutex());
1634 SwTOXType* pType = ((SwXDocumentIndexMark*)this)->GetTOXType();
1635 const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap()->getByName(rPropertyName);
1636 if (!pEntry)
1637 throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
1638 if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
1639 throw beans::PropertyVetoException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
1640 if(pType && m_pTOXMark)
1642 SwDoc* pLocalDoc = m_pDoc;
1644 SwTOXMark aMark(*m_pTOXMark);
1645 switch(pEntry->nWID)
1647 case WID_ALT_TEXT:
1648 aMark.SetAlternativeText(lcl_AnyToString(aValue));
1649 break;
1650 case WID_LEVEL:
1651 aMark.SetLevel(Min( (sal_Int8) ( MAXLEVEL ),
1652 (sal_Int8)(lcl_AnyToInt16(aValue)+1)));
1653 break;
1654 case WID_PRIMARY_KEY :
1655 aMark.SetPrimaryKey(lcl_AnyToString(aValue));
1656 break;
1657 case WID_SECONDARY_KEY:
1658 aMark.SetSecondaryKey(lcl_AnyToString(aValue));
1659 break;
1660 case WID_MAIN_ENTRY:
1661 aMark.SetMainEntry(lcl_AnyToBool(aValue));
1662 break;
1663 case WID_TEXT_READING:
1664 aMark.SetTextReading(lcl_AnyToString(aValue));
1665 break;
1666 case WID_PRIMARY_KEY_READING:
1667 aMark.SetPrimaryKeyReading(lcl_AnyToString(aValue));
1668 break;
1669 case WID_SECONDARY_KEY_READING:
1670 aMark.SetSecondaryKeyReading(lcl_AnyToString(aValue));
1671 break;
1673 const SwTxtTOXMark* pTxtMark = m_pTOXMark->GetTxtTOXMark();
1674 SwPaM aPam(pTxtMark->GetTxtNode(), *pTxtMark->GetStart());
1675 aPam.SetMark();
1676 if(pTxtMark->GetEnd())
1678 aPam.GetPoint()->nContent = *pTxtMark->GetEnd();
1680 else
1681 aPam.GetPoint()->nContent++;
1683 //delete the old mark
1684 pLocalDoc->Delete(m_pTOXMark);
1685 m_pTOXMark = 0;
1687 sal_Bool bInsAtPos = aMark.IsAlternativeText();
1688 const SwPosition *pStt = aPam.Start(),
1689 *pEnd = aPam.End();
1691 SwTxtAttr* pTxtAttr = 0;
1692 if( bInsAtPos )
1694 SwPaM aTmp( *pStt );
1695 pLocalDoc->Insert( aTmp, aMark, 0 );
1696 pTxtAttr = pStt->nNode.GetNode().GetTxtNode()->GetTxtAttr(
1697 pStt->nContent.GetIndex()-1, RES_TXTATR_TOXMARK );
1699 else if( *pEnd != *pStt )
1701 pLocalDoc->Insert( aPam, aMark, nsSetAttrMode::SETATTR_DONTEXPAND );
1702 pTxtAttr = pStt->nNode.GetNode().GetTxtNode()->GetTxtAttr(
1703 pStt->nContent, RES_TXTATR_TOXMARK );
1705 m_pDoc = pLocalDoc;
1707 if(pTxtAttr)
1709 m_pTOXMark = &pTxtAttr->GetTOXMark();
1710 m_pDoc->GetUnoCallBack()->Add(this);
1711 pType->Add(&aTypeDepend);
1714 else if(bIsDescriptor)
1716 switch(pEntry->nWID)
1718 case WID_ALT_TEXT:
1719 sAltText = lcl_AnyToString(aValue);
1720 break;
1721 case WID_LEVEL:
1723 sal_Int16 nVal = lcl_AnyToInt16(aValue);
1724 if(nVal >= 0 && nVal < MAXLEVEL)
1725 nLevel = nVal;
1726 else
1727 throw lang::IllegalArgumentException();
1729 break;
1730 case WID_PRIMARY_KEY :
1731 sPrimaryKey = lcl_AnyToString(aValue);
1732 break;
1733 case WID_SECONDARY_KEY:
1734 sSecondaryKey = lcl_AnyToString(aValue);
1735 break;
1736 case WID_TEXT_READING:
1737 sTextReading = lcl_AnyToString(aValue);
1738 break;
1739 case WID_PRIMARY_KEY_READING:
1740 sPrimaryKeyReading = lcl_AnyToString(aValue);
1741 break;
1742 case WID_SECONDARY_KEY_READING:
1743 sSecondaryKeyReading = lcl_AnyToString(aValue);
1744 break;
1745 case WID_USER_IDX_NAME :
1747 OUString sTmp(lcl_AnyToString(aValue));
1748 lcl_ConvertTOUNameToUserName(sTmp);
1749 sUserIndexName = sTmp;
1751 break;
1752 case WID_MAIN_ENTRY:
1753 bMainEntry = lcl_AnyToBool(aValue);
1754 break;
1757 else
1758 throw uno::RuntimeException();
1760 /*-- 14.12.98 10:25:46---------------------------------------------------
1762 -----------------------------------------------------------------------*/
1763 uno::Any SwXDocumentIndexMark::getPropertyValue(const OUString& rPropertyName)
1764 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1766 vos::OGuard aGuard(Application::GetSolarMutex());
1767 uno::Any aRet;
1768 SwTOXType* pType = ((SwXDocumentIndexMark*)this)->GetTOXType();
1769 const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap()->getByName(rPropertyName);
1770 if (!pEntry)
1771 throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
1772 if(SwXParagraph::getDefaultTextContentValue(aRet, rPropertyName, pEntry->nWID))
1773 return aRet;
1774 if(pType && m_pTOXMark)
1776 switch(pEntry->nWID)
1778 case WID_ALT_TEXT:
1779 aRet <<= OUString(m_pTOXMark->GetAlternativeText());
1780 break;
1781 case WID_LEVEL:
1782 aRet <<= (sal_Int16)(m_pTOXMark->GetLevel() - 1);
1783 break;
1784 case WID_PRIMARY_KEY :
1785 aRet <<= OUString(m_pTOXMark->GetPrimaryKey());
1786 break;
1787 case WID_SECONDARY_KEY:
1788 aRet <<= OUString(m_pTOXMark->GetSecondaryKey());
1789 break;
1790 case WID_TEXT_READING:
1791 aRet <<= OUString(m_pTOXMark->GetTextReading());
1792 break;
1793 case WID_PRIMARY_KEY_READING:
1794 aRet <<= OUString(m_pTOXMark->GetPrimaryKeyReading());
1795 break;
1796 case WID_SECONDARY_KEY_READING:
1797 aRet <<= OUString(m_pTOXMark->GetSecondaryKeyReading());
1798 break;
1799 case WID_USER_IDX_NAME :
1801 OUString sTmp(pType->GetTypeName());
1802 lcl_ConvertTOUNameToProgrammaticName(sTmp);
1803 aRet <<= sTmp;
1805 break;
1806 case WID_MAIN_ENTRY:
1808 sal_Bool bTemp = m_pTOXMark->IsMainEntry();
1809 aRet.setValue(&bTemp, ::getBooleanCppuType());
1811 break;
1814 else if(bIsDescriptor)
1816 switch(pEntry->nWID)
1818 case WID_ALT_TEXT:
1819 aRet <<= OUString(sAltText);
1820 break;
1821 case WID_LEVEL:
1822 aRet <<= (sal_Int16)nLevel;
1823 break;
1824 case WID_PRIMARY_KEY :
1825 aRet <<= OUString(sPrimaryKey);
1826 break;
1827 case WID_SECONDARY_KEY:
1828 aRet <<= OUString(sSecondaryKey);
1829 break;
1830 case WID_TEXT_READING:
1831 aRet <<= OUString(sTextReading);
1832 break;
1833 case WID_PRIMARY_KEY_READING:
1834 aRet <<= OUString(sPrimaryKeyReading);
1835 break;
1836 case WID_SECONDARY_KEY_READING:
1837 aRet <<= OUString(sSecondaryKeyReading);
1838 break;
1839 case WID_USER_IDX_NAME :
1840 aRet <<= OUString(sUserIndexName);
1841 break;
1842 case WID_MAIN_ENTRY:
1844 aRet.setValue(&bMainEntry, ::getBooleanCppuType());
1846 break;
1849 else
1850 throw uno::RuntimeException();
1851 return aRet;
1853 /*-- 14.12.98 10:25:46---------------------------------------------------
1855 -----------------------------------------------------------------------*/
1856 void SwXDocumentIndexMark::addPropertyChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1858 DBG_WARNING("not implemented");
1860 /*-- 14.12.98 10:25:46---------------------------------------------------
1862 -----------------------------------------------------------------------*/
1863 void SwXDocumentIndexMark::removePropertyChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1865 DBG_WARNING("not implemented");
1867 /*-- 14.12.98 10:25:47---------------------------------------------------
1869 -----------------------------------------------------------------------*/
1870 void SwXDocumentIndexMark::addVetoableChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1872 DBG_WARNING("not implemented");
1874 /*-- 14.12.98 10:25:47---------------------------------------------------
1876 -----------------------------------------------------------------------*/
1877 void SwXDocumentIndexMark::removeVetoableChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
1879 DBG_WARNING("not implemented");
1881 /*-- 14.12.98 10:25:47---------------------------------------------------
1883 -----------------------------------------------------------------------*/
1884 SwXDocumentIndexMark* SwXDocumentIndexMark::GetObject(SwTOXType* pType,
1885 const SwTOXMark* pMark, SwDoc* pDoc)
1887 SwClientIter aIter(*pType);
1888 SwXDocumentIndexMark* pxMark = (SwXDocumentIndexMark*)
1889 aIter.First(TYPE(SwXDocumentIndexMark));
1890 while( pxMark )
1892 if(pxMark->m_pTOXMark == pMark)
1893 return pxMark;
1894 pxMark = (SwXDocumentIndexMark*)aIter.Next();
1896 return new SwXDocumentIndexMark(pType, pMark, pDoc);
1898 /*-- 14.12.98 10:25:47---------------------------------------------------
1900 -----------------------------------------------------------------------*/
1901 void SwXDocumentIndexMark::Modify( SfxPoolItem *pOld, SfxPoolItem *pNew)
1903 switch( pOld ? pOld->Which() : 0 )
1905 case RES_REMOVE_UNO_OBJECT:
1906 case RES_OBJECTDYING:
1907 if( (void*)GetRegisteredIn() == ((SwPtrMsgPoolItem *)pOld)->pObject )
1908 Invalidate();
1909 break;
1911 case RES_FMT_CHG:
1912 // wurden wir an das neue umgehaengt und wird das alte geloscht?
1913 if( ((SwFmtChg*)pNew)->pChangedFmt == GetRegisteredIn() &&
1914 ((SwFmtChg*)pOld)->pChangedFmt->IsFmtInDTOR() )
1915 Invalidate();
1916 break;
1917 case RES_TOXMARK_DELETED:
1918 if( (void*)m_pTOXMark == ((SwPtrMsgPoolItem *)pOld)->pObject )
1919 Invalidate();
1920 break;
1923 /* -----------------------------16.10.00 11:24--------------------------------
1925 ---------------------------------------------------------------------------*/
1926 void SwXDocumentIndexMark::Invalidate()
1928 if(GetRegisteredIn())
1930 ((SwModify*)GetRegisteredIn())->Remove(this);
1931 if(aTypeDepend.GetRegisteredIn())
1932 ((SwModify*)aTypeDepend.GetRegisteredIn())->Remove(&aTypeDepend);
1933 aLstnrCntnr.Disposing();
1934 m_pTOXMark = 0;
1935 m_pDoc = 0;
1938 /* -----------------------------06.04.00 15:08--------------------------------
1940 ---------------------------------------------------------------------------*/
1941 OUString SwXDocumentIndexes::getImplementationName(void) throw( uno::RuntimeException )
1943 return C2U("SwXDocumentIndexes");
1945 /* -----------------------------06.04.00 15:08--------------------------------
1947 ---------------------------------------------------------------------------*/
1948 BOOL SwXDocumentIndexes::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
1950 return C2U("com.sun.star.text.DocumentIndexes") == rServiceName;
1952 /* -----------------------------06.04.00 15:08--------------------------------
1954 ---------------------------------------------------------------------------*/
1955 uno::Sequence< OUString > SwXDocumentIndexes::getSupportedServiceNames(void) throw( uno::RuntimeException )
1957 uno::Sequence< OUString > aRet(1);
1958 OUString* pArray = aRet.getArray();
1959 pArray[0] = C2U("com.sun.star.text.DocumentIndexes");
1960 return aRet;
1962 /*-- 05.05.99 13:14:59---------------------------------------------------
1964 -----------------------------------------------------------------------*/
1965 SwXDocumentIndexes::SwXDocumentIndexes(SwDoc* _pDoc) :
1966 SwUnoCollection(_pDoc)
1969 /*-- 05.05.99 13:15:00---------------------------------------------------
1971 -----------------------------------------------------------------------*/
1972 SwXDocumentIndexes::~SwXDocumentIndexes()
1975 /*-- 05.05.99 13:15:01---------------------------------------------------
1977 -----------------------------------------------------------------------*/
1978 sal_Int32 SwXDocumentIndexes::getCount(void) throw( uno::RuntimeException )
1980 vos::OGuard aGuard(Application::GetSolarMutex());
1981 if(!IsValid())
1982 throw uno::RuntimeException();
1984 sal_uInt32 nRet = 0;
1985 const SwSectionFmts& rFmts = GetDoc()->GetSections();
1986 for( sal_uInt16 n = 0; n < rFmts.Count(); ++n )
1988 const SwSection* pSect = rFmts[ n ]->GetSection();
1989 if( TOX_CONTENT_SECTION == pSect->GetType() &&
1990 pSect->GetFmt()->GetSectionNode() )
1991 ++nRet;
1993 return nRet;
1995 /*-- 05.05.99 13:15:01---------------------------------------------------
1997 -----------------------------------------------------------------------*/
1998 uno::Any SwXDocumentIndexes::getByIndex(sal_Int32 nIndex)
1999 throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException )
2001 vos::OGuard aGuard(Application::GetSolarMutex());
2002 if(!IsValid())
2003 throw uno::RuntimeException();
2005 uno::Any aRet;
2006 sal_Int32 nIdx = 0;
2008 const SwSectionFmts& rFmts = GetDoc()->GetSections();
2009 for( sal_uInt16 n = 0; n < rFmts.Count(); ++n )
2011 const SwSection* pSect = rFmts[ n ]->GetSection();
2012 if( TOX_CONTENT_SECTION == pSect->GetType() &&
2013 pSect->GetFmt()->GetSectionNode() &&
2014 nIdx++ == nIndex )
2016 uno::Reference< text::XDocumentIndex > xTmp = new SwXDocumentIndex(
2017 (SwTOXBaseSection*)pSect, GetDoc() );
2018 aRet.setValue(&xTmp, ::getCppuType((uno::Reference<text::XDocumentIndex>*)0));
2019 return aRet;
2023 throw lang::IndexOutOfBoundsException();
2026 /*-- 31.01.00 10:12:31---------------------------------------------------
2028 -----------------------------------------------------------------------*/
2029 uno::Any SwXDocumentIndexes::getByName(const OUString& rName)
2030 throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
2032 vos::OGuard aGuard(Application::GetSolarMutex());
2033 if(!IsValid())
2034 throw uno::RuntimeException();
2036 uno::Any aRet;
2038 String sToFind(rName);
2039 const SwSectionFmts& rFmts = GetDoc()->GetSections();
2040 for( sal_uInt16 n = 0; n < rFmts.Count(); ++n )
2042 const SwSection* pSect = rFmts[ n ]->GetSection();
2043 if( TOX_CONTENT_SECTION == pSect->GetType() &&
2044 pSect->GetFmt()->GetSectionNode() &&
2045 ((SwTOXBaseSection*)pSect)->GetTOXName() == sToFind)
2047 uno::Reference< text::XDocumentIndex > xTmp = new SwXDocumentIndex(
2048 (SwTOXBaseSection*)pSect, GetDoc() );
2049 aRet.setValue(&xTmp, ::getCppuType((uno::Reference<text::XDocumentIndex>*)0));
2050 return aRet;
2053 throw container::NoSuchElementException();
2055 /*-- 31.01.00 10:12:31---------------------------------------------------
2057 -----------------------------------------------------------------------*/
2058 uno::Sequence< OUString > SwXDocumentIndexes::getElementNames(void)
2059 throw( uno::RuntimeException )
2061 vos::OGuard aGuard(Application::GetSolarMutex());
2062 if(!IsValid())
2063 throw uno::RuntimeException();
2065 const SwSectionFmts& rFmts = GetDoc()->GetSections();
2066 sal_Int32 nCount = 0;
2067 sal_uInt16 n;
2068 for( n = 0; n < rFmts.Count(); ++n )
2070 const SwSection* pSect = rFmts[ n ]->GetSection();
2071 if( TOX_CONTENT_SECTION == pSect->GetType() &&
2072 pSect->GetFmt()->GetSectionNode() )
2073 ++nCount;
2076 uno::Sequence< OUString > aRet(nCount);
2077 OUString* pArray = aRet.getArray();
2078 sal_uInt16 nCnt;
2079 for( n = 0, nCnt = 0; n < rFmts.Count(); ++n )
2081 const SwSection* pSect = rFmts[ n ]->GetSection();
2082 if( TOX_CONTENT_SECTION == pSect->GetType() &&
2083 pSect->GetFmt()->GetSectionNode())
2085 pArray[nCnt++] = OUString(((SwTOXBaseSection*)pSect)->GetTOXName());
2088 return aRet;
2090 /*-- 31.01.00 10:12:31---------------------------------------------------
2092 -----------------------------------------------------------------------*/
2093 sal_Bool SwXDocumentIndexes::hasByName(const OUString& rName)
2094 throw( uno::RuntimeException )
2096 vos::OGuard aGuard(Application::GetSolarMutex());
2097 if(!IsValid())
2098 throw uno::RuntimeException();
2100 String sToFind(rName);
2101 const SwSectionFmts& rFmts = GetDoc()->GetSections();
2102 for( sal_uInt16 n = 0; n < rFmts.Count(); ++n )
2104 const SwSection* pSect = rFmts[ n ]->GetSection();
2105 if( TOX_CONTENT_SECTION == pSect->GetType() &&
2106 pSect->GetFmt()->GetSectionNode())
2108 if(((SwTOXBaseSection*)pSect)->GetTOXName() == sToFind)
2109 return sal_True;
2112 return sal_False;
2114 /*-- 05.05.99 13:15:01---------------------------------------------------
2116 -----------------------------------------------------------------------*/
2117 uno::Type SwXDocumentIndexes::getElementType(void) throw( uno::RuntimeException )
2119 return ::getCppuType((uno::Reference< text::XDocumentIndex> *)0);
2121 /*-- 05.05.99 13:15:02---------------------------------------------------
2123 -----------------------------------------------------------------------*/
2124 sal_Bool SwXDocumentIndexes::hasElements(void) throw( uno::RuntimeException )
2126 vos::OGuard aGuard(Application::GetSolarMutex());
2127 if(!IsValid())
2128 throw uno::RuntimeException();
2129 return 0 != getCount();
2132 SwXDocumentIndex* SwXDocumentIndexes::GetObject(const SwTOXBaseSection* pTOX)
2134 SwSectionFmt* pFmt = pTOX->GetFmt();
2135 SwClientIter aIter(*pFmt);
2136 SwXDocumentIndex* pxIdx = (SwXDocumentIndex*)aIter.First(TYPE(SwXDocumentIndex));
2137 if(pxIdx)
2138 return pxIdx;
2139 else
2140 return new SwXDocumentIndex(pTOX, pFmt->GetDoc());
2143 /* -----------------------------06.04.00 15:08--------------------------------
2145 ---------------------------------------------------------------------------*/
2146 OUString SwXIndexStyleAccess_Impl::getImplementationName(void) throw( uno::RuntimeException )
2148 return C2U("SwXIndexStyleAccess_Impl");
2150 /* -----------------------------06.04.00 15:08--------------------------------
2152 ---------------------------------------------------------------------------*/
2153 BOOL SwXIndexStyleAccess_Impl::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
2155 return C2U("com.sun.star.text.DocumentIndexParagraphStyles") == rServiceName;
2157 /* -----------------------------06.04.00 15:08--------------------------------
2159 ---------------------------------------------------------------------------*/
2160 uno::Sequence< OUString > SwXIndexStyleAccess_Impl::getSupportedServiceNames(void) throw( uno::RuntimeException )
2162 uno::Sequence< OUString > aRet(1);
2163 OUString* pArray = aRet.getArray();
2164 pArray[0] = C2U("com.sun.star.text.DocumentIndexParagraphStyles");
2165 return aRet;
2167 /*-- 13.09.99 16:52:28---------------------------------------------------
2169 -----------------------------------------------------------------------*/
2170 SwXIndexStyleAccess_Impl::SwXIndexStyleAccess_Impl(SwXDocumentIndex& rParentIdx) :
2171 rParent(rParentIdx),
2172 xParent(&rParentIdx)
2174 vos::OGuard aGuard(Application::GetSolarMutex());
2175 rParent.SetStyleAccess(this);
2177 /*-- 13.09.99 16:52:29---------------------------------------------------
2179 -----------------------------------------------------------------------*/
2180 SwXIndexStyleAccess_Impl::~SwXIndexStyleAccess_Impl()
2182 vos::OGuard aGuard(Application::GetSolarMutex());
2183 rParent.SetStyleAccess(0);
2185 /*-- 13.09.99 16:52:29---------------------------------------------------
2187 -----------------------------------------------------------------------*/
2188 void SwXIndexStyleAccess_Impl::replaceByIndex(sal_Int32 nIndex, const uno::Any& rElement)
2189 throw( lang::IllegalArgumentException, lang::IndexOutOfBoundsException,
2190 lang::WrappedTargetException, uno::RuntimeException)
2192 vos::OGuard aGuard(Application::GetSolarMutex());
2193 const sal_Bool bDescriptor = rParent.IsDescriptor();
2194 SwSectionFmt* pSectFmt = rParent.GetFmt();
2195 if(!pSectFmt && !bDescriptor)
2196 throw uno::RuntimeException();
2197 if(nIndex < 0 || nIndex > MAXLEVEL)
2198 throw lang::IndexOutOfBoundsException();
2199 SwTOXBase* pTOXBase = bDescriptor ? &rParent.GetProperties_Impl()->GetTOXBase() :
2200 (SwTOXBaseSection*)pSectFmt->GetSection();
2202 uno::Sequence<OUString> aSeq;
2203 if(!(rElement >>= aSeq))
2204 throw lang::IllegalArgumentException();
2206 sal_Int32 nStyles = aSeq.getLength();
2207 const OUString* pStyles = aSeq.getConstArray();
2208 String sSetStyles;
2209 String aString;
2210 for(sal_Int32 i = 0; i < nStyles; i++)
2212 if(i)
2213 sSetStyles += TOX_STYLE_DELIMITER;
2214 SwStyleNameMapper::FillUIName(pStyles[i], aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True);
2215 sSetStyles += aString;
2217 pTOXBase->SetStyleNames(sSetStyles, (sal_uInt16) nIndex);
2219 /*-- 13.09.99 16:52:29---------------------------------------------------
2221 -----------------------------------------------------------------------*/
2222 sal_Int32 SwXIndexStyleAccess_Impl::getCount(void) throw( uno::RuntimeException )
2224 return MAXLEVEL;
2226 /*-- 13.09.99 16:52:30---------------------------------------------------
2228 -----------------------------------------------------------------------*/
2229 uno::Any SwXIndexStyleAccess_Impl::getByIndex(sal_Int32 nIndex)
2230 throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException,
2231 uno::RuntimeException)
2233 vos::OGuard aGuard(Application::GetSolarMutex());
2234 const sal_Bool bDescriptor = rParent.IsDescriptor();
2235 SwSectionFmt* pSectFmt = rParent.GetFmt();
2236 if(!pSectFmt && !bDescriptor)
2237 throw uno::RuntimeException();
2238 if(nIndex < 0 || nIndex > MAXLEVEL)
2239 throw lang::IndexOutOfBoundsException();
2240 SwTOXBase* pTOXBase = bDescriptor ? &rParent.GetProperties_Impl()->GetTOXBase() :
2241 (SwTOXBaseSection*)pSectFmt->GetSection();
2243 const String& rStyles = pTOXBase->GetStyleNames((sal_uInt16) nIndex);
2244 sal_uInt16 nStyles = rStyles.GetTokenCount(TOX_STYLE_DELIMITER);
2245 uno::Sequence<OUString> aStyles(nStyles);
2246 OUString* pStyles = aStyles.getArray();
2247 String aString;
2248 for(sal_uInt16 i = 0; i < nStyles; i++)
2250 SwStyleNameMapper::FillProgName(
2251 rStyles.GetToken(i, TOX_STYLE_DELIMITER),
2252 aString,
2253 nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL,
2254 sal_True);
2255 pStyles[i] = OUString( aString );
2257 uno::Any aRet(&aStyles, ::getCppuType((uno::Sequence<OUString>*)0));
2258 return aRet;
2260 /*-- 13.09.99 16:52:30---------------------------------------------------
2262 -----------------------------------------------------------------------*/
2263 uno::Type SwXIndexStyleAccess_Impl::getElementType(void)
2264 throw( uno::RuntimeException )
2266 return ::getCppuType((uno::Sequence<OUString>*)0);
2268 /*-- 13.09.99 16:52:30---------------------------------------------------
2270 -----------------------------------------------------------------------*/
2271 sal_Bool SwXIndexStyleAccess_Impl::hasElements(void) throw( uno::RuntimeException )
2273 return sal_True;
2276 /* -----------------13.09.99 16:51-------------------
2278 --------------------------------------------------*/
2279 /* -----------------------------06.04.00 15:08--------------------------------
2281 ---------------------------------------------------------------------------*/
2282 OUString SwXIndexTokenAccess_Impl::getImplementationName(void) throw( uno::RuntimeException )
2284 return C2U("SwXIndexTokenAccess_Impl");
2286 /* -----------------------------06.04.00 15:08--------------------------------
2288 ---------------------------------------------------------------------------*/
2289 BOOL SwXIndexTokenAccess_Impl::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
2291 return C2U("com.sun.star.text.DocumentIndexLevelFormat") == rServiceName;
2293 /* -----------------------------06.04.00 15:08--------------------------------
2295 ---------------------------------------------------------------------------*/
2296 uno::Sequence< OUString > SwXIndexTokenAccess_Impl::getSupportedServiceNames(void) throw( uno::RuntimeException )
2298 uno::Sequence< OUString > aRet(1);
2299 OUString* pArray = aRet.getArray();
2300 pArray[0] = C2U("com.sun.star.text.DocumentIndexLevelFormat");
2301 return aRet;
2303 /*-- 13.09.99 16:52:28---------------------------------------------------
2305 -----------------------------------------------------------------------*/
2306 SwXIndexTokenAccess_Impl::SwXIndexTokenAccess_Impl(SwXDocumentIndex& rParentIdx) :
2307 rParent(rParentIdx),
2308 xParent(&rParentIdx),
2309 nCount(SwForm::GetFormMaxLevel(rParent.GetTOXType()))
2311 vos::OGuard aGuard(Application::GetSolarMutex());
2312 rParent.SetTokenAccess(this);
2314 /*-- 13.09.99 16:52:29---------------------------------------------------
2316 -----------------------------------------------------------------------*/
2317 SwXIndexTokenAccess_Impl::~SwXIndexTokenAccess_Impl()
2319 vos::OGuard aGuard(Application::GetSolarMutex());
2320 rParent.SetTokenAccess(0);
2322 /*-- 13.09.99 16:52:29---------------------------------------------------
2324 -----------------------------------------------------------------------*/
2325 void SwXIndexTokenAccess_Impl::replaceByIndex(sal_Int32 nIndex, const uno::Any& rElement)
2326 throw( lang::IllegalArgumentException, lang::IndexOutOfBoundsException,
2327 lang::WrappedTargetException, uno::RuntimeException)
2329 vos::OGuard aGuard(Application::GetSolarMutex());
2330 const sal_Bool bDescriptor = rParent.IsDescriptor();
2331 SwSectionFmt* pSectFmt = rParent.GetFmt();
2332 if(!pSectFmt && !bDescriptor)
2333 throw uno::RuntimeException();
2335 SwTOXBase* pTOXBase = bDescriptor ? &rParent.GetProperties_Impl()->GetTOXBase() :
2336 (SwTOXBaseSection*)pSectFmt->GetSection();
2337 if(nIndex < 0 ||
2338 (nIndex > pTOXBase->GetTOXForm().GetFormMax()))
2339 throw lang::IndexOutOfBoundsException();
2341 uno::Sequence<beans::PropertyValues> aSeq;
2342 if(!(rElement >>= aSeq))
2343 throw lang::IllegalArgumentException();
2345 String sPattern;
2346 sal_Int32 nTokens = aSeq.getLength();
2347 const beans::PropertyValues* pTokens = aSeq.getConstArray();
2348 for(sal_Int32 i = 0; i < nTokens; i++)
2350 const beans::PropertyValue* pProperties = pTokens[i].getConstArray();
2351 sal_Int32 nProperties = pTokens[i].getLength();
2352 //create an invalid token
2353 SwFormToken aToken(TOKEN_END);
2354 for(sal_Int32 j = 0; j < nProperties; j++)
2356 if( COMPARE_EQUAL == pProperties[j].Name.compareToAscii("TokenType"))
2358 const String sTokenType =
2359 lcl_AnyToString(pProperties[j].Value);
2360 if(sTokenType.EqualsAscii("TokenEntryNumber"))
2361 aToken.eTokenType = TOKEN_ENTRY_NO;
2362 else if(sTokenType.EqualsAscii("TokenEntryText" ))
2363 aToken.eTokenType = TOKEN_ENTRY_TEXT;
2364 else if(sTokenType.EqualsAscii("TokenTabStop" ))
2365 aToken.eTokenType = TOKEN_TAB_STOP;
2366 else if(sTokenType.EqualsAscii("TokenText" ))
2367 aToken.eTokenType = TOKEN_TEXT;
2368 else if(sTokenType.EqualsAscii("TokenPageNumber"))
2369 aToken.eTokenType = TOKEN_PAGE_NUMS;
2370 else if(sTokenType.EqualsAscii("TokenChapterInfo" ))
2371 aToken.eTokenType = TOKEN_CHAPTER_INFO;
2372 else if(sTokenType.EqualsAscii("TokenHyperlinkStart" ))
2373 aToken.eTokenType = TOKEN_LINK_START;
2374 else if(sTokenType.EqualsAscii("TokenHyperlinkEnd"))
2375 aToken.eTokenType = TOKEN_LINK_END;
2376 else if(sTokenType.EqualsAscii("TokenBibliographyDataField" ))
2377 aToken.eTokenType = TOKEN_AUTHORITY;
2379 else if( pProperties[j].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("CharacterStyleName" ) ))
2381 String sCharStyleName;
2382 SwStyleNameMapper::FillUIName(
2383 lcl_AnyToString(pProperties[j].Value),
2384 sCharStyleName,
2385 nsSwGetPoolIdFromName::GET_POOLID_CHRFMT,
2386 sal_True);
2387 aToken.sCharStyleName = sCharStyleName;
2388 aToken.nPoolId = SwStyleNameMapper::GetPoolIdFromUIName (
2389 sCharStyleName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
2391 else if( pProperties[j].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("TabStopRightAligned") ))
2393 sal_Bool bRight = lcl_AnyToBool(pProperties[j].Value);
2394 aToken.eTabAlign = bRight ?
2395 SVX_TAB_ADJUST_END : SVX_TAB_ADJUST_LEFT;
2397 else if( pProperties[j].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("TabStopPosition" )))
2399 sal_Int32 nPosition = 0;
2400 if(pProperties[j].Value.getValueType() != ::getCppuType((sal_Int32*)0))
2401 throw lang::IllegalArgumentException();
2402 pProperties[j].Value >>= nPosition;
2403 nPosition = MM100_TO_TWIP(nPosition);
2404 if(nPosition < 0)
2405 throw lang::IllegalArgumentException();
2406 aToken.nTabStopPosition = nPosition;
2408 else if( pProperties[j].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("TabStopFillCharacter" )))
2410 const String sFillChar =
2411 lcl_AnyToString(pProperties[j].Value);
2412 if(sFillChar.Len() > 1)
2413 throw lang::IllegalArgumentException();
2414 aToken.cTabFillChar = sFillChar.Len() ?
2415 sFillChar.GetChar(0) : ' ';
2417 else if( pProperties[j].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Text" )))
2419 const String sText =
2420 lcl_AnyToString(pProperties[j].Value);
2421 aToken.sText = sText;
2423 else if( pProperties[j].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ChapterFormat" )))
2425 sal_Int16 nFormat = lcl_AnyToInt16(pProperties[j].Value);
2426 switch(nFormat)
2428 case text::ChapterFormat::NUMBER: nFormat = CF_NUMBER;
2429 break;
2430 case text::ChapterFormat::NAME: nFormat = CF_TITLE;
2431 break;
2432 case text::ChapterFormat::NAME_NUMBER: nFormat = CF_NUM_TITLE;
2433 break;
2434 case text::ChapterFormat::NO_PREFIX_SUFFIX:nFormat = CF_NUMBER_NOPREPST;
2435 break;
2436 case text::ChapterFormat::DIGIT: nFormat = CF_NUM_NOPREPST_TITLE;
2437 break;
2438 default:
2439 throw lang::IllegalArgumentException();
2441 aToken.nChapterFormat = nFormat;
2443 //--->i53420
2444 else if( pProperties[j].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ChapterLevel")) )
2446 const sal_Int16 nLevel = lcl_AnyToInt16(pProperties[j].Value);
2447 if( nLevel < 1 || nLevel > MAXLEVEL )
2448 throw lang::IllegalArgumentException();
2449 aToken.nOutlineLevel = nLevel;
2451 //<---
2452 else if( pProperties[j].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("BibliographyDataField")))
2454 sal_Int16 nType = 0;
2455 pProperties[j].Value >>= nType;
2456 if(nType < 0 || nType > text::BibliographyDataField::ISBN)
2458 lang::IllegalArgumentException aExcept;
2459 aExcept.Message = C2U("BibliographyDataField - wrong value");
2460 aExcept.ArgumentPosition = static_cast< sal_Int16 >(j);
2461 throw aExcept;
2463 aToken.nAuthorityField = nType;
2465 // #i21237#
2466 else if ( pProperties[j].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("WithTab")))
2468 aToken.bWithTab = lcl_AnyToBool(pProperties[j].Value);
2472 //exception if wrong TokenType
2473 if(TOKEN_END <= aToken.eTokenType )
2474 throw lang::IllegalArgumentException();
2475 // set TokenType from TOKEN_ENTRY_TEXT to TOKEN_ENTRY if it is
2476 // not a content index
2477 if(TOKEN_ENTRY_TEXT == aToken.eTokenType &&
2478 TOX_CONTENT != pTOXBase->GetType())
2479 aToken.eTokenType = TOKEN_ENTRY;
2480 //---> i53420
2481 // check for chapter format allowed values if it was TOKEN_ENTRY_NO type
2482 // only allowed value are CF_NUMBER and CF_NUM_NOPREPST_TITLE
2483 // reading from file
2484 if( TOKEN_ENTRY_NO == aToken.eTokenType )
2485 switch(aToken.nChapterFormat)
2487 case CF_NUMBER:
2488 case CF_NUM_NOPREPST_TITLE:
2489 break;
2490 default:
2491 throw lang::IllegalArgumentException();
2493 //<---
2494 sPattern += aToken.GetString();
2496 SwForm aForm(pTOXBase->GetTOXForm());
2497 aForm.SetPattern((sal_uInt16) nIndex, sPattern);
2498 pTOXBase->SetTOXForm(aForm);
2500 /*-- 13.09.99 16:52:29---------------------------------------------------
2502 -----------------------------------------------------------------------*/
2503 sal_Int32 SwXIndexTokenAccess_Impl::getCount(void) throw( uno::RuntimeException )
2505 vos::OGuard aGuard(Application::GetSolarMutex());
2506 const sal_Bool bDescriptor = rParent.IsDescriptor();
2507 SwSectionFmt* pSectFmt = rParent.GetFmt();
2508 if(!pSectFmt && !bDescriptor)
2509 throw uno::RuntimeException();
2510 sal_Int32 nRet = bDescriptor ?
2511 nCount :
2512 ((SwTOXBaseSection*)pSectFmt->GetSection())->
2513 GetTOXForm().GetFormMax();
2514 return nRet;
2516 /*-- 13.09.99 16:52:30---------------------------------------------------
2518 -----------------------------------------------------------------------*/
2519 uno::Any SwXIndexTokenAccess_Impl::getByIndex(sal_Int32 nIndex)
2520 throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException,
2521 uno::RuntimeException)
2523 vos::OGuard aGuard(Application::GetSolarMutex());
2524 const sal_Bool bDescriptor = rParent.IsDescriptor();
2525 SwSectionFmt* pSectFmt = rParent.GetFmt();
2526 if(!pSectFmt && !bDescriptor)
2527 throw uno::RuntimeException();
2528 SwTOXBase* pTOXBase = bDescriptor ? &rParent.GetProperties_Impl()->GetTOXBase() :
2529 (SwTOXBaseSection*)pSectFmt->GetSection();
2530 if(nIndex < 0 ||
2531 (nIndex > pTOXBase->GetTOXForm().GetFormMax()))
2532 throw lang::IndexOutOfBoundsException();
2534 // #i21237#
2535 SwFormTokens aPattern = pTOXBase->GetTOXForm().
2536 GetPattern((sal_uInt16) nIndex);
2537 SwFormTokens::iterator aIt = aPattern.begin();
2539 sal_uInt16 nTokenCount = 0;
2540 uno::Sequence< beans::PropertyValues > aRetSeq;
2541 String aString;
2542 while(aIt != aPattern.end()) // #i21237#
2544 nTokenCount++;
2545 aRetSeq.realloc(nTokenCount);
2546 beans::PropertyValues* pTokenProps = aRetSeq.getArray();
2547 SwFormToken aToken = *aIt; // #i21237#
2549 uno::Sequence< beans::PropertyValue >& rCurTokenSeq = pTokenProps[nTokenCount-1];
2550 SwStyleNameMapper::FillProgName(
2551 aToken.sCharStyleName,
2552 aString,
2553 nsSwGetPoolIdFromName::GET_POOLID_CHRFMT,
2554 sal_True );
2555 const OUString aProgCharStyle( aString );
2556 switch(aToken.eTokenType)
2558 case TOKEN_ENTRY_NO :
2560 //--->i53420
2561 // writing to file (from doc to properties)
2562 sal_Int32 nElements = 2;
2563 sal_Int32 nCurrentElement = 0;
2565 if( aToken.nChapterFormat != CF_NUMBER )//check for default value
2566 nElements++;//we need the element
2567 if( aToken.nOutlineLevel != MAXLEVEL )
2568 nElements++;
2570 rCurTokenSeq.realloc( nElements );
2572 beans::PropertyValue* pArr = rCurTokenSeq.getArray();
2574 pArr[nCurrentElement].Name = C2U("TokenType");
2575 pArr[nCurrentElement++].Value <<= OUString::createFromAscii("TokenEntryNumber");
2576 // pArr[0].Value <<= C2U("TokenEntryNumber");
2578 pArr[nCurrentElement].Name = C2U("CharacterStyleName");
2579 pArr[nCurrentElement++].Value <<= aProgCharStyle;
2580 if( aToken.nChapterFormat != CF_NUMBER )
2582 pArr[nCurrentElement].Name = C2U("ChapterFormat");
2583 sal_Int16 nVal;
2584 //! the allowed values for chapter format, when used as entry number, are CF_NUMBER and CF_NUM_NOPREPST_TITLE only, all else forced to
2585 //CF_NUMBER
2586 switch(aToken.nChapterFormat)
2588 default:
2589 case CF_NUMBER: nVal = text::ChapterFormat::NUMBER; break;
2590 case CF_NUM_NOPREPST_TITLE: nVal = text::ChapterFormat::DIGIT; break;
2592 pArr[nCurrentElement++].Value <<= (sal_Int16)nVal;
2595 if( aToken.nOutlineLevel != MAXLEVEL ) //only a ChapterLevel != MAXLEVEL is registered
2597 pArr[nCurrentElement].Name = C2U("ChapterLevel");
2598 pArr[nCurrentElement].Value <<= aToken.nOutlineLevel;
2600 //<---
2602 break;
2603 case TOKEN_ENTRY : // no difference between Entry and Entry Text
2604 case TOKEN_ENTRY_TEXT :
2606 rCurTokenSeq.realloc( 2 );
2607 beans::PropertyValue* pArr = rCurTokenSeq.getArray();
2609 pArr[0].Name = C2U("TokenType");
2610 pArr[0].Value <<= OUString::createFromAscii("TokenEntryText");
2612 pArr[1].Name = C2U("CharacterStyleName");
2613 pArr[1].Value <<= aProgCharStyle;
2615 break;
2616 case TOKEN_TAB_STOP :
2618 rCurTokenSeq.realloc(5); // #i21237#
2619 beans::PropertyValue* pArr = rCurTokenSeq.getArray();
2621 pArr[0].Name = C2U("TokenType");
2622 pArr[0].Value <<= OUString::createFromAscii("TokenTabStop");
2625 if(SVX_TAB_ADJUST_END == aToken.eTabAlign)
2627 pArr[1].Name = C2U("TabStopRightAligned");
2628 BOOL bTemp = sal_True;
2629 pArr[1].Value.setValue(&bTemp, ::getCppuBooleanType());
2631 else
2633 pArr[1].Name = C2U("TabStopPosition");
2634 sal_Int32 nPos = (TWIP_TO_MM100(aToken.nTabStopPosition));
2635 if(nPos < 0)
2636 nPos = 0;
2637 pArr[1].Value <<= (sal_Int32)nPos;
2639 pArr[2].Name = C2U("TabStopFillCharacter");
2640 pArr[2].Value <<= OUString(aToken.cTabFillChar);
2641 pArr[3].Name = C2U("CharacterStyleName");
2642 pArr[3].Value <<= aProgCharStyle;
2643 // #i21237#
2644 pArr[4].Name = C2U("WithTab");
2645 pArr[4].Value.setValue(&aToken.bWithTab, ::getCppuBooleanType());
2647 break;
2648 case TOKEN_TEXT :
2650 rCurTokenSeq.realloc( 3 );
2651 beans::PropertyValue* pArr = rCurTokenSeq.getArray();
2653 pArr[0].Name = C2U("TokenType");
2654 pArr[0].Value <<= OUString::createFromAscii("TokenText");
2656 pArr[1].Name = C2U("CharacterStyleName");
2657 pArr[1].Value <<= aProgCharStyle;
2659 pArr[2].Name = C2U("Text");
2660 pArr[2].Value <<= OUString(aToken.sText);
2662 break;
2663 case TOKEN_PAGE_NUMS :
2665 rCurTokenSeq.realloc( 2 );
2666 beans::PropertyValue* pArr = rCurTokenSeq.getArray();
2668 pArr[0].Name = C2U("TokenType");
2669 pArr[0].Value <<= OUString::createFromAscii("TokenPageNumber");
2671 pArr[1].Name = C2U("CharacterStyleName");
2672 pArr[1].Value <<= aProgCharStyle;
2674 break;
2675 case TOKEN_CHAPTER_INFO :
2677 rCurTokenSeq.realloc( 4 );
2678 beans::PropertyValue* pArr = rCurTokenSeq.getArray();
2680 pArr[0].Name = C2U("TokenType");
2681 pArr[0].Value <<= OUString::createFromAscii("TokenChapterInfo");
2683 pArr[1].Name = C2U("CharacterStyleName");
2684 pArr[1].Value <<= aProgCharStyle;
2686 pArr[2].Name = C2U("ChapterFormat");
2687 sal_Int16 nVal = text::ChapterFormat::NUMBER;
2688 switch(aToken.nChapterFormat)
2690 case CF_NUMBER: nVal = text::ChapterFormat::NUMBER; break;
2691 case CF_TITLE: nVal = text::ChapterFormat::NAME; break;
2692 case CF_NUM_TITLE: nVal = text::ChapterFormat::NAME_NUMBER; break;
2693 case CF_NUMBER_NOPREPST: nVal = text::ChapterFormat::NO_PREFIX_SUFFIX; break;
2694 case CF_NUM_NOPREPST_TITLE: nVal = text::ChapterFormat::DIGIT; break;
2696 pArr[2].Value <<= (sal_Int16)nVal;
2697 //--->i53420
2698 pArr[3].Name = C2U("ChapterLevel");
2700 pArr[3].Value <<= aToken.nOutlineLevel;
2701 //<---
2703 break;
2704 case TOKEN_LINK_START :
2706 rCurTokenSeq.realloc( 2 );
2707 beans::PropertyValue* pArr = rCurTokenSeq.getArray();
2709 pArr[0].Name = C2U("TokenType");
2710 pArr[0].Value <<= OUString::createFromAscii("TokenHyperlinkStart");
2711 pArr[1].Name = C2U("CharacterStyleName");
2712 pArr[1].Value <<= aProgCharStyle;
2714 break;
2715 case TOKEN_LINK_END :
2717 rCurTokenSeq.realloc( 1 );
2718 beans::PropertyValue* pArr = rCurTokenSeq.getArray();
2720 pArr[0].Name = C2U("TokenType");
2721 pArr[0].Value <<= OUString::createFromAscii("TokenHyperlinkEnd");
2723 break;
2724 case TOKEN_AUTHORITY :
2726 rCurTokenSeq.realloc( 3 );
2727 beans::PropertyValue* pArr = rCurTokenSeq.getArray();
2729 pArr[0].Name = C2U("TokenType");
2730 pArr[0].Value <<= OUString::createFromAscii("TokenBibliographyDataField");
2732 pArr[1].Name = C2U("CharacterStyleName");
2733 pArr[1].Value <<= aProgCharStyle;
2735 pArr[2].Name = C2U("BibliographyDataField");
2736 pArr[2].Value <<= sal_Int16(aToken.nAuthorityField);
2738 break;
2740 default:
2744 aIt++; // #i21237#
2747 uno::Any aRet(&aRetSeq, ::getCppuType((uno::Sequence< beans::PropertyValues >*)0));
2749 return aRet;
2751 /*-- 13.09.99 16:52:30---------------------------------------------------
2753 -----------------------------------------------------------------------*/
2754 uno::Type SwXIndexTokenAccess_Impl::getElementType(void)
2755 throw( uno::RuntimeException )
2757 return ::getCppuType((uno::Sequence< beans::PropertyValues >*)0);
2759 /*-- 13.09.99 16:52:30---------------------------------------------------
2761 -----------------------------------------------------------------------*/
2762 sal_Bool SwXIndexTokenAccess_Impl::hasElements(void) throw( uno::RuntimeException )
2764 return sal_True;