merge the formfield patch from ooo-build
[ooovba.git] / sw / source / core / tox / tox.cxx
blob5a1795a23756c4a2a02fc12f379f67b7f868b50d
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: tox.cxx,v $
10 * $Revision: 1.22 $
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"
37 #include <tools/resid.hxx>
38 #include <hintids.hxx>
39 #include <swtypes.hxx>
40 #include <errhdl.hxx>
41 #include <txtatr.hxx>
42 #include <ndtxt.hxx>
43 #include <txttxmrk.hxx>
44 #include <tox.hxx>
45 #ifndef _POOLFMT_HRC
46 #include <poolfmt.hrc>
47 #endif
48 #include <doc.hxx>
49 #include <docary.hxx>
50 #include <paratr.hxx>
51 #include <svx/tstpitem.hxx>
52 #include <SwStyleNameMapper.hxx>
54 // -> #i21237#
55 #include <algorithm>
56 #include <functional>
58 using namespace std;
59 // <- #i21237#
61 const sal_Char* SwForm::aFormEntry = "<E>";
62 const sal_Char* SwForm::aFormTab = "<T>";
63 const sal_Char* SwForm::aFormPageNums = "<#>";
64 const sal_Char* SwForm::aFormLinkStt = "<LS>";
65 const sal_Char* SwForm::aFormLinkEnd = "<LE>";
66 const sal_Char* SwForm::aFormEntryNum = "<E#>";
67 const sal_Char* SwForm::aFormEntryTxt = "<ET>";
68 const sal_Char* SwForm::aFormChapterMark= "<C>";
69 const sal_Char* SwForm::aFormText = "<X>";
70 const sal_Char* SwForm::aFormAuth = "<A>";
71 BYTE SwForm::nFormTabLen = 3;
72 BYTE SwForm::nFormEntryLen = 3;
73 BYTE SwForm::nFormPageNumsLen = 3;
74 BYTE SwForm::nFormLinkSttLen = 4;
75 BYTE SwForm::nFormLinkEndLen = 4;
76 BYTE SwForm::nFormEntryNumLen = 4;
77 BYTE SwForm::nFormEntryTxtLen = 4;
78 BYTE SwForm::nFormChapterMarkLen = 3;
79 BYTE SwForm::nFormTextLen = 3;
80 BYTE SwForm::nFormAuthLen = 5;
82 SV_IMPL_PTRARR(SwTOXMarks, SwTOXMark*)
84 TYPEINIT2( SwTOXMark, SfxPoolItem, SwClient ); // fuers rtti
86 /* -----------------23.09.99 13:59-------------------
88 --------------------------------------------------*/
89 struct PatternIni
91 USHORT n1;
92 USHORT n2;
93 USHORT n3;
94 USHORT n4;
95 USHORT n5;
97 const PatternIni aPatternIni[] =
99 {USHRT_MAX, USHRT_MAX, USHRT_MAX, USHRT_MAX, USHRT_MAX}, //Header - no pattern
100 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_ARTICLE,
101 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_BOOK,
102 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_BOOKLET,
103 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_CONFERENCE,
104 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_INBOOK,
105 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_INCOLLECTION,
106 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_INPROCEEDINGS,
107 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_JOURNAL,
108 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_MANUAL,
109 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_MASTERSTHESIS,
110 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_MISC,
111 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_PHDTHESIS,
112 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_PROCEEDINGS,
113 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_TECHREPORT,
114 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_UNPUBLISHED,
115 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_EMAIL,
116 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, AUTH_FIELD_URL, USHRT_MAX},//AUTH_TYPE_WWW,
117 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_CUSTOM1,
118 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_CUSTOM2,
119 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_CUSTOM3,
120 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_CUSTOM4,
121 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_CUSTOM5,
122 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_FIELD_YEAR,
123 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_FIELD_URL,
124 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_FIELD_CUSTOM1,
125 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_FIELD_CUSTOM2,
126 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_FIELD_CUSTOM3,
127 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_FIELD_CUSTOM4,
128 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_FIELD_CUSTOM5,
129 {USHRT_MAX, USHRT_MAX, USHRT_MAX, USHRT_MAX, USHRT_MAX}
131 /* -----------------23.09.99 13:58-------------------
133 --------------------------------------------------*/
134 // -> #i21237#
135 SwFormTokens lcl_GetAuthPattern(USHORT nTypeId)
137 SwFormTokens aRet; // #i21237#
140 PatternIni aIni = aPatternIni[nTypeId];
141 USHORT nVals[5];
142 nVals[0] = aIni.n1;
143 nVals[1] = aIni.n2;
144 nVals[2] = aIni.n3;
145 nVals[3] = aIni.n4;
146 nVals[4] = aIni.n5;
148 SwFormToken aStartToken( TOKEN_AUTHORITY );
149 aStartToken.nAuthorityField = AUTH_FIELD_IDENTIFIER;
150 aRet.push_back( aStartToken );
151 SwFormToken aSeparatorToken( TOKEN_TEXT );
152 aSeparatorToken.sText = String::CreateFromAscii( ": " );
153 aRet.push_back( aSeparatorToken );
154 SwFormToken aTextToken( TOKEN_TEXT );
155 aTextToken.sText = String::CreateFromAscii( ", " );
157 for(USHORT i = 0; i < 5 ; i++)
159 if(nVals[i] == USHRT_MAX)
160 break;
161 if( i > 0 )
162 aRet.push_back( aTextToken );
164 // -> #i21237#
165 SwFormToken aToken(TOKEN_AUTHORITY);
167 aToken.nAuthorityField = nVals[i];
168 aRet.push_back(aToken);
169 // <- #i21237#
172 return aRet;
174 /*--------------------------------------------------------------------
175 Beschreibung: Verzeichnis-Markierungen D/Ctor
176 --------------------------------------------------------------------*/
179 // Konstruktor fuers Default vom Attribut-Pool
180 SwTOXMark::SwTOXMark()
181 : SfxPoolItem( RES_TXTATR_TOXMARK ),
182 SwClient( 0 ),
183 pTxtAttr( 0 ),
184 bAutoGenerated(FALSE),
185 bMainEntry(FALSE)
190 SwTOXMark::SwTOXMark( const SwTOXType* pTyp )
191 : SfxPoolItem( RES_TXTATR_TOXMARK ),
192 SwClient( (SwModify*)pTyp ),
193 pTxtAttr( 0 ), nLevel( 0 ),
194 bAutoGenerated(FALSE),
195 bMainEntry(FALSE)
200 SwTOXMark::SwTOXMark( const SwTOXMark& rCopy )
201 : SfxPoolItem( RES_TXTATR_TOXMARK ),
202 SwClient((SwModify*)rCopy.GetRegisteredIn()),
203 aPrimaryKey( rCopy.aPrimaryKey ), aSecondaryKey( rCopy.aSecondaryKey ),
204 aTextReading( rCopy.aTextReading ),
205 aPrimaryKeyReading( rCopy.aPrimaryKeyReading ),
206 aSecondaryKeyReading( rCopy.aSecondaryKeyReading ),
207 pTxtAttr( 0 ), nLevel( rCopy.nLevel ),
208 bAutoGenerated( rCopy.bAutoGenerated),
209 bMainEntry(rCopy.bMainEntry)
211 // AlternativString kopieren
212 aAltText = rCopy.aAltText;
216 SwTOXMark::~SwTOXMark()
221 int SwTOXMark::operator==( const SfxPoolItem& rAttr ) const
223 ASSERT( SfxPoolItem::operator==( rAttr ), "keine gleichen Attribute" );
224 return GetRegisteredIn() == ((SwTOXMark&)rAttr).GetRegisteredIn();
228 SfxPoolItem* SwTOXMark::Clone( SfxItemPool* ) const
230 return new SwTOXMark( *this );
234 String SwTOXMark::GetText() const
236 String aStr;
237 if( aAltText.Len() )
238 aStr = aAltText;
239 else if( pTxtAttr && pTxtAttr->GetpTxtNd() )
241 xub_StrLen* pEndIdx = pTxtAttr->GetEnd();
242 ASSERT( pEndIdx, "TOXMark ohne Mark!!");
243 if( pEndIdx )
245 const xub_StrLen nStt = *pTxtAttr->GetStart();
246 aStr = pTxtAttr->GetpTxtNd()->GetExpandTxt( nStt, *pEndIdx-nStt );
249 return aStr;
252 /*--------------------------------------------------------------------
253 Beschreibung: Typen von Verzeichnissen verwalten
254 --------------------------------------------------------------------*/
256 SwTOXType::SwTOXType( TOXTypes eTyp, const String& rName )
257 : SwModify(0),
258 aName(rName),
259 eType(eTyp)
264 SwTOXType::SwTOXType(const SwTOXType& rCopy)
265 : SwModify( (SwModify*)rCopy.GetRegisteredIn() ),
266 aName(rCopy.aName),
267 eType(rCopy.eType)
271 /*--------------------------------------------------------------------
272 Beschreibung: Formen bearbeiten
273 --------------------------------------------------------------------*/
275 SwForm::SwForm( TOXTypes eTyp ) // #i21237#
276 : eType( eTyp ), nFormMaxLevel( SwForm::GetFormMaxLevel( eTyp )),
277 // nFirstTabPos( lNumIndent ),
278 bCommaSeparated(FALSE)
280 //bHasFirstTabPos =
281 bGenerateTabPos = FALSE;
282 bIsRelTabPos = TRUE;
284 // Inhaltsverzeichnis hat entsprechend Anzahl Headlines + Ueberschrift
285 // Benutzer hat 10 Ebenen + Ueberschrift
286 // Stichwort hat 3 Ebenen + Ueberschrift + Trenner
287 // indexes of tables, objects illustrations and authorities consist of a heading and one level
289 USHORT nPoolId;
290 switch( eType )
292 case TOX_INDEX: nPoolId = STR_POOLCOLL_TOX_IDXH; break;
293 case TOX_USER: nPoolId = STR_POOLCOLL_TOX_USERH; break;
294 case TOX_CONTENT: nPoolId = STR_POOLCOLL_TOX_CNTNTH; break;
295 case TOX_ILLUSTRATIONS: nPoolId = STR_POOLCOLL_TOX_ILLUSH; break;
296 case TOX_OBJECTS : nPoolId = STR_POOLCOLL_TOX_OBJECTH; break;
297 case TOX_TABLES : nPoolId = STR_POOLCOLL_TOX_TABLESH; break;
298 case TOX_AUTHORITIES : nPoolId = STR_POOLCOLL_TOX_AUTHORITIESH; break;
299 default:
300 ASSERT( !this, "ungueltiger TOXTyp");
301 return ;
304 SwFormTokens aTokens;
305 if (TOX_CONTENT == eType)
307 aTokens.push_back(SwFormToken(TOKEN_ENTRY_NO));
308 aTokens.push_back(SwFormToken(TOKEN_ENTRY_TEXT));
310 else
311 aTokens.push_back(SwFormToken(TOKEN_ENTRY));
313 if (TOX_AUTHORITIES != eType)
315 SwFormToken aToken(TOKEN_TAB_STOP);
316 aToken.nTabStopPosition = 0;
318 // --> FME 2004-12-10 #i36870# right aligned tab for all
319 aToken.cTabFillChar = '.';
320 aToken.eTabAlign = SVX_TAB_ADJUST_END;
321 // <--
323 aTokens.push_back(aToken);
324 aTokens.push_back(SwFormToken(TOKEN_PAGE_NUMS));
327 SetTemplate( 0, SW_RESSTR( nPoolId++ ));
329 if(TOX_INDEX == eType)
331 for( USHORT i = 1; i < 5; ++i )
333 if(1 == i)
335 SwFormTokens aTmpTokens;
336 SwFormToken aTmpToken(TOKEN_ENTRY);
337 aTmpTokens.push_back(aTmpToken);
339 SetPattern( i, aTmpTokens );
340 SetTemplate( i, SW_RESSTR( STR_POOLCOLL_TOX_IDXBREAK ));
342 else
344 SetPattern( i, aTokens );
345 SetTemplate( i, SW_RESSTR( STR_POOLCOLL_TOX_IDX1 + i - 2 ));
349 else
350 for( USHORT i = 1; i < GetFormMax(); ++i, ++nPoolId ) // Nr 0 ist der Titel
352 if(TOX_AUTHORITIES == eType)
353 SetPattern(i, lcl_GetAuthPattern(i));
354 else
355 SetPattern( i, aTokens );
357 if( TOX_CONTENT == eType && 6 == i )
358 nPoolId = STR_POOLCOLL_TOX_CNTNT6;
359 else if( TOX_USER == eType && 6 == i )
360 nPoolId = STR_POOLCOLL_TOX_USER6;
361 else if( TOX_AUTHORITIES == eType )
362 nPoolId = STR_POOLCOLL_TOX_AUTHORITIES1;
363 SetTemplate( i, SW_RESSTR( nPoolId ) );
368 SwForm::SwForm(const SwForm& rForm)
369 : eType( rForm.eType )
371 *this = rForm;
375 SwForm& SwForm::operator=(const SwForm& rForm)
377 eType = rForm.eType;
378 nFormMaxLevel = rForm.nFormMaxLevel;
379 // nFirstTabPos = rForm.nFirstTabPos;
380 // bHasFirstTabPos = rForm.bHasFirstTabPos;
381 bGenerateTabPos = rForm.bGenerateTabPos;
382 bIsRelTabPos = rForm.bIsRelTabPos;
383 bCommaSeparated = rForm.bCommaSeparated;
384 for(USHORT i=0; i < nFormMaxLevel; ++i)
386 aPattern[i] = rForm.aPattern[i];
387 aTemplate[i] = rForm.aTemplate[i];
389 return *this;
392 USHORT SwForm::GetFormMaxLevel( TOXTypes eTOXType )
394 USHORT nRet = 0;
395 switch( eTOXType )
397 case TOX_INDEX: nRet = 5; break;
398 case TOX_USER: nRet = MAXLEVEL+1; break;
399 case TOX_CONTENT: nRet = MAXLEVEL+1; break;
400 case TOX_ILLUSTRATIONS:
401 case TOX_OBJECTS :
402 case TOX_TABLES : nRet = 2; break;
403 case TOX_AUTHORITIES : nRet = AUTH_TYPE_END + 1; break;
405 return nRet;
408 // #i21237#
409 bool operator == (const SwFormToken & rToken, FormTokenType eType)
411 return rToken.eTokenType == eType;
414 //-----------------------------------------------------------------------------
415 void SwForm::AdjustTabStops(SwDoc& rDoc, BOOL bInsertNewTapStops) // #i21237#
417 for(USHORT nLevel = 1; nLevel < GetFormMax(); nLevel++)
419 const String& sTemplateName = GetTemplate(nLevel);
421 SwTxtFmtColl* pColl = rDoc.FindTxtFmtCollByName( sTemplateName );
422 if( !pColl )
424 USHORT nId = SwStyleNameMapper::GetPoolIdFromUIName
425 ( sTemplateName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); // #i21237#
426 if( USHRT_MAX != nId )
427 pColl = rDoc.GetTxtCollFromPool( nId );
430 const SvxTabStopItem* pTabStops = 0;
431 USHORT nTabCount = 0;
432 if( pColl &&
433 0 != ( pTabStops = &pColl->GetTabStops(FALSE) ) &&
434 0 != ( nTabCount = pTabStops->Count() ) )
436 // #i21237#
437 SwFormTokens aCurrentPattern = GetPattern(nLevel);
438 SwFormTokens::iterator aIt = aCurrentPattern.begin();
440 BOOL bChanged = FALSE;
442 for(USHORT nTab = 0; nTab < nTabCount; ++nTab)
444 const SvxTabStop& rTab = (*pTabStops)[nTab];
446 // --> FME 2004-12-16 #i29178#
447 // For Word import, we do not want to replace exising tokens,
448 // we insert new tabstop tokens without a tabstop character:
449 if ( bInsertNewTapStops )
451 if ( SVX_TAB_ADJUST_DEFAULT != rTab.GetAdjustment() )
453 bChanged = TRUE;
454 SwFormToken aToken(TOKEN_TAB_STOP);
455 aToken.bWithTab = FALSE;
456 aToken.nTabStopPosition = rTab.GetTabPos();
457 aToken.eTabAlign = rTab.GetAdjustment();
458 aToken.cTabFillChar = rTab.GetFill();
459 aCurrentPattern.push_back(aToken);
462 // <--
463 else
465 aIt = find_if(aIt, aCurrentPattern.end(),
466 SwFormTokenEqualToFormTokenType
467 (TOKEN_TAB_STOP));
468 if ( aIt != aCurrentPattern.end() )
470 bChanged = TRUE;
471 aIt->nTabStopPosition = rTab.GetTabPos();
472 aIt->eTabAlign = nTab == nTabCount - 1 &&
473 SVX_TAB_ADJUST_RIGHT == rTab.GetAdjustment() ?
474 SVX_TAB_ADJUST_END :
475 rTab.GetAdjustment();
476 aIt->cTabFillChar = rTab.GetFill();
477 ++aIt;
479 else
480 break; // no more tokens to replace
483 // <--
485 if(bChanged)
486 SetPattern(nLevel, aCurrentPattern); // #i21237#
490 /*--------------------------------------------------------------------
491 Beschreibung: Ctor TOXBase
492 --------------------------------------------------------------------*/
495 SwTOXBase::SwTOXBase(const SwTOXType* pTyp, const SwForm& rForm,
496 USHORT nCreaType, const String& rTitle )
497 : SwClient((SwModify*)pTyp),
498 aForm(rForm),
499 aTitle(rTitle),
500 eLanguage((LanguageType)::GetAppLanguage()),
501 nCreateType(nCreaType),
502 nOLEOptions(0),
503 eCaptionDisplay(CAPTION_COMPLETE),
504 bProtected( TRUE ),
505 bFromChapter(FALSE),
506 bFromObjectNames(FALSE),
507 bLevelFromChapter(FALSE)
509 aData.nOptions = 0;
513 SwTOXBase::SwTOXBase( const SwTOXBase& rSource, SwDoc* pDoc )
514 : SwClient( rSource.pRegisteredIn )
516 CopyTOXBase( pDoc, rSource );
519 SwTOXBase& SwTOXBase::CopyTOXBase( SwDoc* pDoc, const SwTOXBase& rSource )
521 SwTOXType* pType = (SwTOXType*)rSource.GetTOXType();
522 if( pDoc && USHRT_MAX == pDoc->GetTOXTypes().GetPos( pType ))
524 // type not in pDoc, so create it now
525 const SwTOXTypes& rTypes = pDoc->GetTOXTypes();
526 BOOL bFound = FALSE;
527 for( USHORT n = rTypes.Count(); n; )
529 const SwTOXType* pCmp = rTypes[ --n ];
530 if( pCmp->GetType() == pType->GetType() &&
531 pCmp->GetTypeName() == pType->GetTypeName() )
533 pType = (SwTOXType*)pCmp;
534 bFound = TRUE;
535 break;
539 if( !bFound )
540 pType = (SwTOXType*)pDoc->InsertTOXType( *pType );
542 pType->Add( this );
544 nCreateType = rSource.nCreateType;
545 aTitle = rSource.aTitle;
546 aForm = rSource.aForm;
547 bProtected = rSource.bProtected;
548 bFromChapter = rSource.bFromChapter;
549 bFromObjectNames = rSource.bFromObjectNames;
550 sMainEntryCharStyle = rSource.sMainEntryCharStyle;
551 sSequenceName = rSource.sSequenceName;
552 eCaptionDisplay = rSource.eCaptionDisplay;
553 nOLEOptions = rSource.nOLEOptions;
554 eLanguage = rSource.eLanguage;
555 sSortAlgorithm = rSource.sSortAlgorithm;
557 for( USHORT i = 0; i < MAXLEVEL; ++i )
558 aStyleNames[i] = rSource.aStyleNames[i];
560 // its the same data type!
561 aData.nOptions = rSource.aData.nOptions;
563 if( !pDoc || pDoc->IsCopyIsMove() )
564 aName = rSource.GetTOXName();
565 else
566 aName = pDoc->GetUniqueTOXBaseName( *pType, &rSource.GetTOXName() );
568 return *this;
571 /*--------------------------------------------------------------------
572 Beschreibung: Verzeichnisspezifische Funktionen
573 --------------------------------------------------------------------*/
575 SwTOXBase::~SwTOXBase()
577 // if( GetTOXType()->GetType() == TOX_USER )
578 // delete aData.pTemplateName;
581 void SwTOXBase::SetTitle(const String& rTitle)
582 { aTitle = rTitle; }
585 SwTOXBase & SwTOXBase::operator = (const SwTOXBase & rSource)
587 ByteString aTmpStr(aTitle, RTL_TEXTENCODING_ASCII_US);
588 ByteString aTmpStr1(rSource.aTitle, RTL_TEXTENCODING_ASCII_US);
590 aForm = rSource.aForm;
591 aName = rSource.aName;
592 aTitle = rSource.aTitle;
593 sMainEntryCharStyle = rSource.sMainEntryCharStyle;
594 for(USHORT nLevel = 0; nLevel < MAXLEVEL; nLevel++)
595 aStyleNames[nLevel] = rSource.aStyleNames[nLevel];
596 sSequenceName = rSource.sSequenceName;
597 eLanguage = rSource.eLanguage;
598 sSortAlgorithm = rSource.sSortAlgorithm;
599 aData = rSource.aData;
600 nCreateType = rSource.nCreateType;
601 nOLEOptions = rSource.nOLEOptions;
602 eCaptionDisplay = rSource.eCaptionDisplay;
603 bProtected = rSource.bProtected;
604 bFromChapter = rSource.bFromChapter;
605 bFromObjectNames = rSource.bFromObjectNames;
606 bLevelFromChapter = rSource.bLevelFromChapter;
608 if (rSource.GetAttrSet())
609 SetAttrSet(*rSource.GetAttrSet());
611 return *this;
614 /* -----------------16.07.99 16:02-------------------
616 SwTOXBase & SwTOXBase::operator = (const SwTOXBase & rSource)
618 aForm = rSource.aForm;
619 aName = rSource.aName;
620 aTitle = rSource.aTitle;
621 sMainEntryCharStyle = rSource.sMainEntryCharStyle;
622 sSequenceName = rSource.sSequenceName;
623 eLanguage = rSource.eLanguage;
624 sSortAlgorithm = rSource.sSortAlgorithm;
625 aData = rSource.aData;
626 nCreateType = rSource.nCreateType;
627 nOLEOptions = rSource.nOLEOptions;
628 eCaptionDisplay = rSource.eCaptionDisplay;
629 bProtected = rSource.bProtected;
630 bFromChapter = rSource.bFromChapter;
631 bFromObjectNames = rSource.bFromObjectNames;
632 bLevelFromChapter = rSource.bLevelFromChapter;
634 if (rSource.GetAttrSet())
635 SetAttrSet(*rSource.GetAttrSet());
637 return *this;
640 --------------------------------------------------*/
642 String SwFormToken::GetString() const
644 String sRet;
646 BOOL bAppend = TRUE;
647 switch( eTokenType )
649 case TOKEN_ENTRY_NO:
650 sRet.AssignAscii( SwForm::aFormEntryNum );
651 break;
652 case TOKEN_ENTRY_TEXT:
653 sRet.AssignAscii( SwForm::aFormEntryTxt );
654 break;
655 case TOKEN_ENTRY:
656 sRet.AssignAscii( SwForm::aFormEntry );
657 break;
658 case TOKEN_TAB_STOP:
659 sRet.AssignAscii( SwForm::aFormTab );
660 break;
661 case TOKEN_TEXT:
662 sRet.AssignAscii( SwForm::aFormText );
663 break;
664 case TOKEN_PAGE_NUMS:
665 sRet.AssignAscii( SwForm::aFormPageNums );
666 break;
667 case TOKEN_CHAPTER_INFO:
668 sRet.AssignAscii( SwForm::aFormChapterMark );
669 break;
670 case TOKEN_LINK_START:
671 sRet.AssignAscii( SwForm::aFormLinkStt );
672 break;
673 case TOKEN_LINK_END:
674 sRet.AssignAscii( SwForm::aFormLinkEnd );
675 break;
676 case TOKEN_AUTHORITY:
678 sRet.AssignAscii( SwForm::aFormAuth );
679 String sTmp( String::CreateFromInt32( nAuthorityField ));
680 if( sTmp.Len() < 2 )
681 sTmp.Insert('0', 0);
682 sRet.Insert( sTmp, 2 );
684 break;
685 case TOKEN_END:
686 break;
688 sRet.Erase( sRet.Len() - 1 );
689 sRet += ' ';
690 sRet += sCharStyleName;
691 sRet += ',';
692 sRet += String::CreateFromInt32( nPoolId );
693 sRet += ',';
695 // TabStopPosition and TabAlign or ChapterInfoFormat
696 if(TOKEN_TAB_STOP == eTokenType)
698 sRet += String::CreateFromInt32( nTabStopPosition );
699 sRet += ',';
700 sRet += String::CreateFromInt32( static_cast< sal_Int32 >(eTabAlign) );
701 sRet += ',';
702 sRet += cTabFillChar;
703 sRet += ',';
704 sRet += String::CreateFromInt32( bWithTab );
706 else if(TOKEN_CHAPTER_INFO == eTokenType)
708 sRet += String::CreateFromInt32( nChapterFormat );
709 //add maximum permetted level
710 sRet += ',';
711 sRet += String::CreateFromInt32( nOutlineLevel );
713 else if(TOKEN_TEXT == eTokenType)
715 //append Text if Len() > 0 only!
716 if( sText.Len() )
718 sRet += TOX_STYLE_DELIMITER;
719 String sTmp( sText );
720 sTmp.EraseAllChars( TOX_STYLE_DELIMITER );
721 sRet += sTmp;
722 sRet += TOX_STYLE_DELIMITER;
724 else
725 bAppend = FALSE;
727 else if(TOKEN_ENTRY_NO == eTokenType)
729 sRet += String::CreateFromInt32( nChapterFormat );
730 //add maximum permitted level
731 sRet += ',';
732 sRet += String::CreateFromInt32( nOutlineLevel );
735 if(bAppend)
737 sRet += '>';
739 else
741 // don't append empty text tokens
742 sRet.Erase();
745 return sRet;
748 // -> #i21237#
749 SwFormTokensHelper::SwFormTokensHelper(const String & rPattern)
751 xub_StrLen nCurPatternPos = 0;
752 xub_StrLen nCurPatternLen = 0;
754 while (nCurPatternPos < rPattern.Len())
756 nCurPatternPos = nCurPatternPos + nCurPatternLen;
758 SwFormToken aToken = BuildToken(rPattern, nCurPatternPos);
759 aTokens.push_back(aToken);
763 SwFormToken SwFormTokensHelper::BuildToken( const String & sPattern,
764 xub_StrLen & nCurPatternPos ) const
766 String sToken( SearchNextToken(sPattern, nCurPatternPos) );
767 nCurPatternPos = nCurPatternPos + sToken.Len();
768 xub_StrLen nTokenLen;
769 FormTokenType eTokenType = GetTokenType(sToken, &nTokenLen);
771 // at this point sPattern contains the
772 // character style name, the PoolId, tab stop position, tab stop alignment, chapter info format
773 // the form is: CharStyleName, PoolId[, TabStopPosition|ChapterInfoFormat[, TabStopAlignment[, TabFillChar]]]
774 // in text tokens the form differs from the others: CharStyleName, PoolId[,\0xffinserted text\0xff]
775 SwFormToken eRet( eTokenType );
776 String sAuthFieldEnum = sToken.Copy( 2, 2 );
777 sToken = sToken.Copy( nTokenLen, sToken.Len() - nTokenLen - 1);
779 eRet.sCharStyleName = sToken.GetToken( 0, ',');
780 String sTmp( sToken.GetToken( 1, ',' ));
781 if( sTmp.Len() )
782 eRet.nPoolId = static_cast<USHORT>(sTmp.ToInt32());
784 switch( eTokenType )
786 //i53420
787 case TOKEN_ENTRY_NO:
788 if( (sTmp = sToken.GetToken( 2, ',' ) ).Len() )
789 eRet.nChapterFormat = static_cast<USHORT>(sTmp.ToInt32());
790 if( (sTmp = sToken.GetToken( 3, ',' ) ).Len() )
791 eRet.nOutlineLevel = static_cast<USHORT>(sTmp.ToInt32()); //the maximum outline level to examine
792 break;
794 case TOKEN_TEXT:
796 xub_StrLen nStartText = sToken.Search( TOX_STYLE_DELIMITER );
797 if( STRING_NOTFOUND != nStartText )
799 xub_StrLen nEndText = sToken.Search( TOX_STYLE_DELIMITER,
800 nStartText + 1);
801 if( STRING_NOTFOUND != nEndText )
803 eRet.sText = sToken.Copy( nStartText + 1,
804 nEndText - nStartText - 1);
808 break;
810 case TOKEN_TAB_STOP:
811 if( (sTmp = sToken.GetToken( 2, ',' ) ).Len() )
812 eRet.nTabStopPosition = sTmp.ToInt32();
814 if( (sTmp = sToken.GetToken( 3, ',' ) ).Len() )
815 eRet.eTabAlign = static_cast<SvxTabAdjust>(sTmp.ToInt32());
817 if( (sTmp = sToken.GetToken( 4, ',' ) ).Len() )
818 eRet.cTabFillChar = sTmp.GetChar(0);
820 if( (sTmp = sToken.GetToken( 5, ',' ) ).Len() )
821 eRet.bWithTab = 0 != sTmp.ToInt32();
822 break;
824 case TOKEN_CHAPTER_INFO:
825 if( (sTmp = sToken.GetToken( 2, ',' ) ).Len() )
826 eRet.nChapterFormat = static_cast<USHORT>(sTmp.ToInt32()); //SwChapterFormat;
827 //i53420
828 if( (sTmp = sToken.GetToken( 3, ',' ) ).Len() )
829 eRet.nOutlineLevel = static_cast<USHORT>(sTmp.ToInt32()); //the maximum outline level to examine
831 break;
833 case TOKEN_AUTHORITY:
834 eRet.nAuthorityField = static_cast<USHORT>(sAuthFieldEnum.ToInt32());
835 break;
836 default: break;
838 return eRet;
841 String SwFormTokensHelper::SearchNextToken( const String & sPattern,
842 xub_StrLen nStt ) const
844 //it's not so easy - it doesn't work if the text part contains a '>'
845 //USHORT nTokenEnd = sPattern.Search('>');
847 String aResult;
849 xub_StrLen nEnd = sPattern.Search( '>', nStt );
850 if( STRING_NOTFOUND == nEnd )
852 nEnd = sPattern.Len();
854 else
856 xub_StrLen nTextSeparatorFirst = sPattern.Search( TOX_STYLE_DELIMITER, nStt );
857 if( STRING_NOTFOUND != nTextSeparatorFirst )
859 xub_StrLen nTextSeparatorSecond = sPattern.Search( TOX_STYLE_DELIMITER,
860 nTextSeparatorFirst + 1 );
861 if( STRING_NOTFOUND != nTextSeparatorSecond &&
862 nEnd > nTextSeparatorFirst )
863 nEnd = sPattern.Search( '>', nTextSeparatorSecond );
866 ++nEnd;
868 aResult = sPattern.Copy( nStt, nEnd - nStt );
871 return aResult;
874 FormTokenType SwFormTokensHelper::GetTokenType(const String & sToken,
875 xub_StrLen * pTokenLen) const
877 static struct
879 const sal_Char* pNm;
880 USHORT nLen;
881 USHORT nOffset;
882 FormTokenType eToken;
883 } __READONLY_DATA aTokenArr[] = {
884 { SwForm::aFormTab, SwForm::nFormEntryLen, 1, TOKEN_TAB_STOP },
885 { SwForm::aFormPageNums, SwForm::nFormPageNumsLen, 1, TOKEN_PAGE_NUMS },
886 { SwForm::aFormLinkStt, SwForm::nFormLinkSttLen, 1, TOKEN_LINK_START },
887 { SwForm::aFormLinkEnd, SwForm::nFormLinkEndLen, 1, TOKEN_LINK_END },
888 { SwForm::aFormEntryNum, SwForm::nFormEntryNumLen, 1, TOKEN_ENTRY_NO },
889 { SwForm::aFormEntryTxt, SwForm::nFormEntryTxtLen, 1, TOKEN_ENTRY_TEXT },
890 { SwForm::aFormChapterMark,SwForm::nFormChapterMarkLen,1,TOKEN_CHAPTER_INFO },
891 { SwForm::aFormText, SwForm::nFormTextLen, 1, TOKEN_TEXT },
892 { SwForm::aFormEntry, SwForm::nFormEntryLen, 1, TOKEN_ENTRY },
893 { SwForm::aFormAuth, SwForm::nFormAuthLen, 3, TOKEN_AUTHORITY },
894 { 0, 0, 0, TOKEN_END }
897 FormTokenType eTokenType = TOKEN_TEXT;
898 xub_StrLen nTokenLen = 0;
899 const sal_Char* pNm;
900 for( int i = 0; 0 != ( pNm = aTokenArr[ i ].pNm ); ++i )
901 if( COMPARE_EQUAL == sToken.CompareToAscii( pNm,
902 aTokenArr[ i ].nLen - aTokenArr[ i ].nOffset ))
904 eTokenType = aTokenArr[ i ].eToken;
905 nTokenLen = aTokenArr[ i ].nLen;
906 break;
909 ASSERT( pNm, "wrong token" );
910 if (pTokenLen)
911 *pTokenLen = nTokenLen;
913 return eTokenType;
916 // <- #i21237#
918 void SwForm::SetPattern(USHORT nLevel, const SwFormTokens& rTokens)
920 ASSERT(nLevel < GetFormMax(), "Index >= FORM_MAX");
921 aPattern[nLevel] = rTokens;
924 void SwForm::SetPattern(USHORT nLevel, const String & rStr)
926 ASSERT(nLevel < GetFormMax(), "Index >= FORM_MAX");
928 SwFormTokensHelper aHelper(rStr);
929 aPattern[nLevel] = aHelper.GetTokens();
932 const SwFormTokens& SwForm::GetPattern(USHORT nLevel) const
934 ASSERT(nLevel < GetFormMax(), "Index >= FORM_MAX");
935 return aPattern[nLevel];