1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27 #include <tools/resid.hxx>
28 #include <hintids.hxx>
29 #include <swtypes.hxx>
30 #include <errhdl.hxx>
31 #include <txtatr.hxx>
32 #include <ndtxt.hxx>
33 #include <txttxmrk.hxx>
34 #include <tox.hxx>
35 #include <poolfmt.hrc>
36 #include <doc.hxx>
37 #include <docary.hxx>
38 #include <paratr.hxx>
39 #include <editeng/tstpitem.hxx>
40 #include <SwStyleNameMapper.hxx>
41 #include <hints.hxx> // SwPtrMsgPoolItem
42 #include <algorithm>
43 #include <functional>
44 #include <switerator.hxx>
45
46 using namespace std;
47
48 const sal_Char* SwForm::aFormEntry = "<E>";
49 const sal_Char* SwForm::aFormTab = "<T>";
50 const sal_Char* SwForm::aFormPageNums = "<#>";
51 const sal_Char* SwForm::aFormLinkStt = "<LS>";
52 const sal_Char* SwForm::aFormLinkEnd = "<LE>";
53 const sal_Char* SwForm::aFormEntryNum = "<E#>";
54 const sal_Char* SwForm::aFormEntryTxt = "<ET>";
55 const sal_Char* SwForm::aFormChapterMark= "<C>";
56 const sal_Char* SwForm::aFormText = "<X>";
57 const sal_Char* SwForm::aFormAuth = "<A>";
58 sal_uInt8 SwForm::nFormTabLen = 3;
59 sal_uInt8 SwForm::nFormEntryLen = 3;
60 sal_uInt8 SwForm::nFormPageNumsLen = 3;
61 sal_uInt8 SwForm::nFormLinkSttLen = 4;
62 sal_uInt8 SwForm::nFormLinkEndLen = 4;
63 sal_uInt8 SwForm::nFormEntryNumLen = 4;
64 sal_uInt8 SwForm::nFormEntryTxtLen = 4;
65 sal_uInt8 SwForm::nFormChapterMarkLen = 3;
66 sal_uInt8 SwForm::nFormTextLen = 3;
67 sal_uInt8 SwForm::nFormAuthLen = 5;
68
69 SV_IMPL_PTRARR(SwTOXMarks, SwTOXMark*)
70
71 TYPEINIT2( SwTOXMark, SfxPoolItem, SwClient ); // fuers rtti
72
73 struct PatternIni
74 {
75 sal_uInt16 n1;
76 sal_uInt16 n2;
77 sal_uInt16 n3;
78 sal_uInt16 n4;
79 sal_uInt16 n5;
80 };
81 const PatternIni aPatternIni[] =
82 {
83 {USHRT_MAX, USHRT_MAX, USHRT_MAX, USHRT_MAX, USHRT_MAX}, //Header - no pattern
84 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_ARTICLE,
85 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_BOOK,
86 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_BOOKLET,
87 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_CONFERENCE,
88 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_INBOOK,
89 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_INCOLLECTION,
90 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_INPROCEEDINGS,
91 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_JOURNAL,
92 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_MANUAL,
93 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_MASTERSTHESIS,
94 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_MISC,
95 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_PHDTHESIS,
96 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_PROCEEDINGS,
97 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_TECHREPORT,
98 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_UNPUBLISHED,
99 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_EMAIL,
100 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, AUTH_FIELD_URL, USHRT_MAX},//AUTH_TYPE_WWW,
101 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_CUSTOM1,
102 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_CUSTOM2,
103 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_CUSTOM3,
104 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_CUSTOM4,
105 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_TYPE_CUSTOM5,
106 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_FIELD_YEAR,
107 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_FIELD_URL,
108 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_FIELD_CUSTOM1,
109 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_FIELD_CUSTOM2,
110 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_FIELD_CUSTOM3,
111 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_FIELD_CUSTOM4,
112 {AUTH_FIELD_AUTHOR, AUTH_FIELD_TITLE, AUTH_FIELD_YEAR, USHRT_MAX, USHRT_MAX}, //AUTH_FIELD_CUSTOM5,
113 {USHRT_MAX, USHRT_MAX, USHRT_MAX, USHRT_MAX, USHRT_MAX}
114 };
115
lcl_GetAuthPattern(sal_uInt16 nTypeId)116 SwFormTokens lcl_GetAuthPattern(sal_uInt16 nTypeId)
117 {
118 SwFormTokens aRet;
119
120 PatternIni aIni = aPatternIni[nTypeId];
121 sal_uInt16 nVals[5];
122 nVals[0] = aIni.n1;
123 nVals[1] = aIni.n2;
124 nVals[2] = aIni.n3;
125 nVals[3] = aIni.n4;
126 nVals[4] = aIni.n5;
127
128 SwFormToken aStartToken( TOKEN_AUTHORITY );
129 aStartToken.nAuthorityField = AUTH_FIELD_IDENTIFIER;
130 aRet.push_back( aStartToken );
131 SwFormToken aSeparatorToken( TOKEN_TEXT );
132 aSeparatorToken.sText = String::CreateFromAscii( ": " );
133 aRet.push_back( aSeparatorToken );
134 SwFormToken aTextToken( TOKEN_TEXT );
135 aTextToken.sText = String::CreateFromAscii( ", " );
136
137 for(sal_uInt16 i = 0; i < 5 ; i++)
138 {
139 if(nVals[i] == USHRT_MAX)
140 break;
141 if( i > 0 )
142 aRet.push_back( aTextToken );
143
144 // -> #i21237#
145 SwFormToken aToken(TOKEN_AUTHORITY);
146
147 aToken.nAuthorityField = nVals[i];
148 aRet.push_back(aToken);
149 // <- #i21237#
150 }
151
152 return aRet;
153 }
154 /*--------------------------------------------------------------------
155 Beschreibung: Verzeichnis-Markierungen D/Ctor
156 --------------------------------------------------------------------*/
157
158
159 /// pool default constructor
SwTOXMark()160 SwTOXMark::SwTOXMark()
161 : SfxPoolItem( RES_TXTATR_TOXMARK )
162 , SwModify( 0 )
163 ,
164 pTxtAttr( 0 ),
165 bAutoGenerated(sal_False),
166 bMainEntry(sal_False)
167 {
168 }
169
170
SwTOXMark(const SwTOXType * pTyp)171 SwTOXMark::SwTOXMark( const SwTOXType* pTyp )
172 : SfxPoolItem( RES_TXTATR_TOXMARK )
173 , SwModify( const_cast<SwTOXType*>(pTyp) )
174 ,
175 pTxtAttr( 0 ), nLevel( 0 ),
176 bAutoGenerated(sal_False),
177 bMainEntry(sal_False)
178 {
179 }
180
181
SwTOXMark(const SwTOXMark & rCopy)182 SwTOXMark::SwTOXMark( const SwTOXMark& rCopy )
183 : SfxPoolItem( RES_TXTATR_TOXMARK )
184 , SwModify(rCopy.GetRegisteredInNonConst())
185 ,
186 aPrimaryKey( rCopy.aPrimaryKey ), aSecondaryKey( rCopy.aSecondaryKey ),
187 aTextReading( rCopy.aTextReading ),
188 aPrimaryKeyReading( rCopy.aPrimaryKeyReading ),
189 aSecondaryKeyReading( rCopy.aSecondaryKeyReading ),
190 pTxtAttr( 0 ), nLevel( rCopy.nLevel ),
191 bAutoGenerated( rCopy.bAutoGenerated),
192 bMainEntry(rCopy.bMainEntry)
193 {
194 // AlternativString kopieren
195 aAltText = rCopy.aAltText;
196 }
197
198
~SwTOXMark()199 SwTOXMark::~SwTOXMark()
200 {
201 }
202
203
RegisterToTOXType(SwTOXType & rMark)204 void SwTOXMark::RegisterToTOXType( SwTOXType& rMark )
205 {
206 rMark.Add(this);
207 }
208
operator ==(const SfxPoolItem & rAttr) const209 int SwTOXMark::operator==( const SfxPoolItem& rAttr ) const
210 {
211 ASSERT( SfxPoolItem::operator==( rAttr ), "keine gleichen Attribute" );
212 return GetRegisteredIn() == ((SwTOXMark&)rAttr).GetRegisteredIn();
213 }
214
215
Clone(SfxItemPool *) const216 SfxPoolItem* SwTOXMark::Clone( SfxItemPool* ) const
217 {
218 return new SwTOXMark( *this );
219 }
220
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)221 void SwTOXMark::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew)
222 {
223 NotifyClients(pOld, pNew);
224 if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which()))
225 { // invalidate cached uno object
226 SetXTOXMark(::com::sun::star::uno::Reference<
227 ::com::sun::star::text::XDocumentIndexMark>(0));
228 }
229 }
230
InvalidateTOXMark()231 void SwTOXMark::InvalidateTOXMark()
232 {
233 SwPtrMsgPoolItem aMsgHint( RES_REMOVE_UNO_OBJECT,
234 &static_cast<SwModify&>(*this) ); // cast to base class!
235 NotifyClients(&aMsgHint, &aMsgHint);
236 }
237
GetText() const238 String SwTOXMark::GetText() const
239 {
240 String aStr;
241 if( aAltText.Len() )
242 aStr = aAltText;
243 else if( pTxtAttr && pTxtAttr->GetpTxtNd() )
244 {
245 const xub_StrLen* pEndIdx = pTxtAttr->GetEnd();
246 ASSERT( pEndIdx, "TOXMark ohne Mark!!");
247 if( pEndIdx )
248 {
249 const xub_StrLen nStt = *pTxtAttr->GetStart();
250 aStr = pTxtAttr->GetpTxtNd()->GetExpandTxt( nStt, *pEndIdx-nStt );
251 }
252 }
253 return aStr;
254 }
255
InsertTOXMarks(SwTOXMarks & aMarks,const SwTOXType & rType)256 void SwTOXMark::InsertTOXMarks( SwTOXMarks& aMarks, const SwTOXType& rType )
257 {
258 SwIterator<SwTOXMark,SwTOXType> aIter(rType);
259 SwTOXMark* pMark = aIter.First();
260 while( pMark )
261 {
262 if(pMark->GetTxtTOXMark())
263 aMarks.C40_INSERT(SwTOXMark, pMark, aMarks.Count());
264 pMark = aIter.Next();
265 }
266 }
267
268 /*--------------------------------------------------------------------
269 Beschreibung: Typen von Verzeichnissen verwalten
270 --------------------------------------------------------------------*/
271
SwTOXType(TOXTypes eTyp,const String & rName)272 SwTOXType::SwTOXType( TOXTypes eTyp, const String& rName )
273 : SwModify(0),
274 aName(rName),
275 eType(eTyp)
276 {
277 }
278
279
SwTOXType(const SwTOXType & rCopy)280 SwTOXType::SwTOXType(const SwTOXType& rCopy)
281 : SwModify( (SwModify*)rCopy.GetRegisteredIn() ),
282 aName(rCopy.aName),
283 eType(rCopy.eType)
284 {
285 }
286
287 /*--------------------------------------------------------------------
288 Beschreibung: Formen bearbeiten
289 --------------------------------------------------------------------*/
290
SwForm(TOXTypes eTyp)291 SwForm::SwForm( TOXTypes eTyp ) // #i21237#
292 : eType( eTyp ), nFormMaxLevel( SwForm::GetFormMaxLevel( eTyp )),
293 // nFirstTabPos( lNumIndent ),
294 bCommaSeparated(sal_False)
295 {
296 //bHasFirstTabPos =
297 bGenerateTabPos = sal_False;
298 bIsRelTabPos = sal_True;
299
300 // Inhaltsverzeichnis hat entsprechend Anzahl Headlines + Ueberschrift
301 // Benutzer hat 10 Ebenen + Ueberschrift
302 // Stichwort hat 3 Ebenen + Ueberschrift + Trenner
303 // indexes of tables, objects illustrations and authorities consist of a heading and one level
304
305 sal_uInt16 nPoolId;
306 switch( eType )
307 {
308 case TOX_INDEX: nPoolId = STR_POOLCOLL_TOX_IDXH; break;
309 case TOX_USER: nPoolId = STR_POOLCOLL_TOX_USERH; break;
310 case TOX_CONTENT: nPoolId = STR_POOLCOLL_TOX_CNTNTH; break;
311 case TOX_ILLUSTRATIONS: nPoolId = STR_POOLCOLL_TOX_ILLUSH; break;
312 case TOX_OBJECTS : nPoolId = STR_POOLCOLL_TOX_OBJECTH; break;
313 case TOX_TABLES : nPoolId = STR_POOLCOLL_TOX_TABLESH; break;
314 case TOX_AUTHORITIES : nPoolId = STR_POOLCOLL_TOX_AUTHORITIESH; break;
315 default:
316 ASSERT( sal_False, "invalid TOXType");
317 return ;
318 }
319
320 SwFormTokens aTokens;
321 if (TOX_CONTENT == eType)
322 {
323 aTokens.push_back(SwFormToken(TOKEN_ENTRY_NO));
324 aTokens.push_back(SwFormToken(TOKEN_ENTRY_TEXT));
325 }
326 else
327 aTokens.push_back(SwFormToken(TOKEN_ENTRY));
328
329 if (TOX_AUTHORITIES != eType)
330 {
331 SwFormToken aToken(TOKEN_TAB_STOP);
332 aToken.nTabStopPosition = 0;
333
334 // --> FME 2004-12-10 #i36870# right aligned tab for all
335 aToken.cTabFillChar = '.';
336 aToken.eTabAlign = SVX_TAB_ADJUST_END;
337 // <--
338
339 aTokens.push_back(aToken);
340 aTokens.push_back(SwFormToken(TOKEN_PAGE_NUMS));
341 }
342
343 SetTemplate( 0, SW_RESSTR( nPoolId++ ));
344
345 if(TOX_INDEX == eType)
346 {
347 for( sal_uInt16 i = 1; i < 5; ++i )
348 {
349 if(1 == i)
350 {
351 SwFormTokens aTmpTokens;
352 SwFormToken aTmpToken(TOKEN_ENTRY);
353 aTmpTokens.push_back(aTmpToken);
354
355 SetPattern( i, aTmpTokens );
356 SetTemplate( i, SW_RESSTR( STR_POOLCOLL_TOX_IDXBREAK ));
357 }
358 else
359 {
360 SetPattern( i, aTokens );
361 SetTemplate( i, SW_RESSTR( STR_POOLCOLL_TOX_IDX1 + i - 2 ));
362 }
363 }
364 }
365 else
366 for( sal_uInt16 i = 1; i < GetFormMax(); ++i, ++nPoolId ) // Nr 0 ist der Titel
367 {
368 if(TOX_AUTHORITIES == eType)
369 SetPattern(i, lcl_GetAuthPattern(i));
370 else
371 SetPattern( i, aTokens );
372
373 if( TOX_CONTENT == eType && 6 == i )
374 nPoolId = STR_POOLCOLL_TOX_CNTNT6;
375 else if( TOX_USER == eType && 6 == i )
376 nPoolId = STR_POOLCOLL_TOX_USER6;
377 else if( TOX_AUTHORITIES == eType )
378 nPoolId = STR_POOLCOLL_TOX_AUTHORITIES1;
379 SetTemplate( i, SW_RESSTR( nPoolId ) );
380 }
381 }
382
383
SwForm(const SwForm & rForm)384 SwForm::SwForm(const SwForm& rForm)
385 : eType( rForm.eType )
386 {
387 *this = rForm;
388 }
389
390
operator =(const SwForm & rForm)391 SwForm& SwForm::operator=(const SwForm& rForm)
392 {
393 eType = rForm.eType;
394 nFormMaxLevel = rForm.nFormMaxLevel;
395 // nFirstTabPos = rForm.nFirstTabPos;
396 // bHasFirstTabPos = rForm.bHasFirstTabPos;
397 bGenerateTabPos = rForm.bGenerateTabPos;
398 bIsRelTabPos = rForm.bIsRelTabPos;
399 bCommaSeparated = rForm.bCommaSeparated;
400 for(sal_uInt16 i=0; i < nFormMaxLevel; ++i)
401 {
402 aPattern[i] = rForm.aPattern[i];
403 aTemplate[i] = rForm.aTemplate[i];
404 }
405 return *this;
406 }
407
GetFormMaxLevel(TOXTypes eTOXType)408 sal_uInt16 SwForm::GetFormMaxLevel( TOXTypes eTOXType )
409 {
410 sal_uInt16 nRet = 0;
411 switch( eTOXType )
412 {
413 case TOX_INDEX: nRet = 5; break;
414 case TOX_USER: nRet = MAXLEVEL+1; break;
415 case TOX_CONTENT: nRet = MAXLEVEL+1; break;
416 case TOX_ILLUSTRATIONS:
417 case TOX_OBJECTS :
418 case TOX_TABLES : nRet = 2; break;
419 case TOX_AUTHORITIES : nRet = AUTH_TYPE_END + 1; break;
420 }
421 return nRet;
422 }
423
424 // #i21237#
operator ==(const SwFormToken & rToken,FormTokenType eType)425 bool operator == (const SwFormToken & rToken, FormTokenType eType)
426 {
427 return rToken.eTokenType == eType;
428 }
429
430 //-----------------------------------------------------------------------------
AdjustTabStops(SwDoc & rDoc)431 void SwForm::AdjustTabStops( SwDoc& rDoc ) // #i21237#
432 {
433 const sal_uInt16 nFormMaxLevel = GetFormMax();
434 for ( sal_uInt16 nLevel = 1; nLevel < nFormMaxLevel; ++nLevel )
435 {
436 SwTxtFmtColl* pColl = rDoc.FindTxtFmtCollByName( GetTemplate(nLevel) );
437 if( pColl == NULL )
438 {
439 // Paragraph Style for this level has not been created.
440 // --> No need to propagate default values
441 continue;
442 }
443
444 const SvxTabStopItem* pTabStops = pColl != NULL ? &pColl->GetTabStops(sal_False) : 0;
445 const sal_uInt16 nTabCount = pTabStops != NULL ? pTabStops->Count() : 0;
446 if( pTabStops != NULL
447 && nTabCount != 0 )
448 {
449 SwFormTokens aCurrentPattern = GetPattern(nLevel);
450 SwFormTokens::iterator aIt = aCurrentPattern.begin();
451
452 bool bChanged = false;
453 for(sal_uInt16 nTab = 0; nTab < nTabCount; ++nTab)
454 {
455 const SvxTabStop& rTab = (*pTabStops)[nTab];
456
457 if ( rTab.GetAdjustment() == SVX_TAB_ADJUST_DEFAULT )
458 continue; // ignore the default tab stop
459
460 aIt = find_if( aIt, aCurrentPattern.end(), SwFormTokenEqualToFormTokenType(TOKEN_TAB_STOP) );
461 if ( aIt != aCurrentPattern.end() )
462 {
463 bChanged = true;
464 aIt->nTabStopPosition = rTab.GetTabPos();
465 aIt->eTabAlign =
466 ( nTab == nTabCount - 1
467 && rTab.GetAdjustment() == SVX_TAB_ADJUST_RIGHT )
468 ? SVX_TAB_ADJUST_END
469 : rTab.GetAdjustment();
470 aIt->cTabFillChar = rTab.GetFill();
471 ++aIt;
472 }
473 else
474 break; // no more tokens to replace
475 }
476
477 if ( bChanged )
478 SetPattern( nLevel, aCurrentPattern );
479 }
480 }
481 }
482 /*--------------------------------------------------------------------
483 Beschreibung: Ctor TOXBase
484 --------------------------------------------------------------------*/
485
486
SwTOXBase(const SwTOXType * pTyp,const SwForm & rForm,sal_uInt16 nCreaType,const String & rTitle)487 SwTOXBase::SwTOXBase(const SwTOXType* pTyp, const SwForm& rForm,
488 sal_uInt16 nCreaType, const String& rTitle )
489 : SwClient((SwModify*)pTyp)
490 , aForm(rForm)
491 , aTitle(rTitle)
492 , eLanguage((LanguageType)::GetAppLanguage())
493 , nCreateType(nCreaType)
494 , nOLEOptions(0)
495 , eCaptionDisplay(CAPTION_COMPLETE)
496 , bProtected( sal_True )
497 , bFromChapter(sal_False)
498 , bFromObjectNames(sal_False)
499 , bLevelFromChapter(sal_False)
500 , maMSTOCExpression()
501 , mbKeepExpression(sal_True)
502 {
503 aData.nOptions = 0;
504 }
505
506
SwTOXBase(const SwTOXBase & rSource,SwDoc * pDoc)507 SwTOXBase::SwTOXBase( const SwTOXBase& rSource, SwDoc* pDoc )
508 : SwClient( rSource.GetRegisteredInNonConst() )
509 , mbKeepExpression(sal_True)
510 {
511 CopyTOXBase( pDoc, rSource );
512 }
513
RegisterToTOXType(SwTOXType & rType)514 void SwTOXBase::RegisterToTOXType( SwTOXType& rType )
515 {
516 rType.Add( this );
517 }
518
CopyTOXBase(SwDoc * pDoc,const SwTOXBase & rSource)519 SwTOXBase& SwTOXBase::CopyTOXBase( SwDoc* pDoc, const SwTOXBase& rSource )
520 {
521 maMSTOCExpression = rSource.maMSTOCExpression;
522 SwTOXType* pType = (SwTOXType*)rSource.GetTOXType();
523 if( pDoc && USHRT_MAX == pDoc->GetTOXTypes().GetPos( pType ))
524 {
525 // type not in pDoc, so create it now
526 const SwTOXTypes& rTypes = pDoc->GetTOXTypes();
527 sal_Bool bFound = sal_False;
528 for( sal_uInt16 n = rTypes.Count(); n; )
529 {
530 const SwTOXType* pCmp = rTypes[ --n ];
531 if( pCmp->GetType() == pType->GetType() &&
532 pCmp->GetTypeName() == pType->GetTypeName() )
533 {
534 pType = (SwTOXType*)pCmp;
535 bFound = sal_True;
536 break;
537 }
538 }
539
540 if( !bFound )
541 pType = (SwTOXType*)pDoc->InsertTOXType( *pType );
542 }
543 pType->Add( this );
544
545 nCreateType = rSource.nCreateType;
546 aTitle = rSource.aTitle;
547 aForm = rSource.aForm;
548 bProtected = rSource.bProtected;
549 bFromChapter = rSource.bFromChapter;
550 bFromObjectNames = rSource.bFromObjectNames;
551 sMainEntryCharStyle = rSource.sMainEntryCharStyle;
552 sSequenceName = rSource.sSequenceName;
553 eCaptionDisplay = rSource.eCaptionDisplay;
554 nOLEOptions = rSource.nOLEOptions;
555 eLanguage = rSource.eLanguage;
556 sSortAlgorithm = rSource.sSortAlgorithm;
557
558 for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
559 aStyleNames[i] = rSource.aStyleNames[i];
560
561 // its the same data type!
562 aData.nOptions = rSource.aData.nOptions;
563
564 if( !pDoc || pDoc->IsCopyIsMove() )
565 aName = rSource.GetTOXName();
566 else
567 aName = pDoc->GetUniqueTOXBaseName( *pType, &rSource.GetTOXName() );
568
569 return *this;
570 }
571
572 /*--------------------------------------------------------------------
573 Beschreibung: Verzeichnisspezifische Funktionen
574 --------------------------------------------------------------------*/
575
~SwTOXBase()576 SwTOXBase::~SwTOXBase()
577 {
578 // if( GetTOXType()->GetType() == TOX_USER )
579 // delete aData.pTemplateName;
580 }
581
SetTitle(const String & rTitle)582 void SwTOXBase::SetTitle(const String& rTitle)
583 { aTitle = rTitle; }
584
585
operator =(const SwTOXBase & rSource)586 SwTOXBase & SwTOXBase::operator = (const SwTOXBase & rSource)
587 {
588 ByteString aTmpStr(aTitle, RTL_TEXTENCODING_ASCII_US);
589 ByteString aTmpStr1(rSource.aTitle, RTL_TEXTENCODING_ASCII_US);
590
591 aForm = rSource.aForm;
592 aName = rSource.aName;
593 aTitle = rSource.aTitle;
594 sMainEntryCharStyle = rSource.sMainEntryCharStyle;
595 for(sal_uInt16 nLevel = 0; nLevel < MAXLEVEL; nLevel++)
596 aStyleNames[nLevel] = rSource.aStyleNames[nLevel];
597 sSequenceName = rSource.sSequenceName;
598 eLanguage = rSource.eLanguage;
599 sSortAlgorithm = rSource.sSortAlgorithm;
600 aData = rSource.aData;
601 nCreateType = rSource.nCreateType;
602 nOLEOptions = rSource.nOLEOptions;
603 eCaptionDisplay = rSource.eCaptionDisplay;
604 bProtected = rSource.bProtected;
605 bFromChapter = rSource.bFromChapter;
606 bFromObjectNames = rSource.bFromObjectNames;
607 bLevelFromChapter = rSource.bLevelFromChapter;
608
609 if (rSource.GetAttrSet())
610 SetAttrSet(*rSource.GetAttrSet());
611
612 return *this;
613 }
614
615 /* -----------------16.07.99 16:02-------------------
616
617 SwTOXBase & SwTOXBase::operator = (const SwTOXBase & rSource)
618 {
619 aForm = rSource.aForm;
620 aName = rSource.aName;
621 aTitle = rSource.aTitle;
622 sMainEntryCharStyle = rSource.sMainEntryCharStyle;
623 sSequenceName = rSource.sSequenceName;
624 eLanguage = rSource.eLanguage;
625 sSortAlgorithm = rSource.sSortAlgorithm;
626 aData = rSource.aData;
627 nCreateType = rSource.nCreateType;
628 nOLEOptions = rSource.nOLEOptions;
629 eCaptionDisplay = rSource.eCaptionDisplay;
630 bProtected = rSource.bProtected;
631 bFromChapter = rSource.bFromChapter;
632 bFromObjectNames = rSource.bFromObjectNames;
633 bLevelFromChapter = rSource.bLevelFromChapter;
634
635 if (rSource.GetAttrSet())
636 SetAttrSet(*rSource.GetAttrSet());
637
638 return *this;
639 }
640
641 --------------------------------------------------*/
642
GetString() const643 String SwFormToken::GetString() const
644 {
645 String sRet;
646
647 sal_Bool bAppend = sal_True;
648 switch( eTokenType )
649 {
650 case TOKEN_ENTRY_NO:
651 sRet.AssignAscii( SwForm::aFormEntryNum );
652 break;
653 case TOKEN_ENTRY_TEXT:
654 sRet.AssignAscii( SwForm::aFormEntryTxt );
655 break;
656 case TOKEN_ENTRY:
657 sRet.AssignAscii( SwForm::aFormEntry );
658 break;
659 case TOKEN_TAB_STOP:
660 sRet.AssignAscii( SwForm::aFormTab );
661 break;
662 case TOKEN_TEXT:
663 sRet.AssignAscii( SwForm::aFormText );
664 break;
665 case TOKEN_PAGE_NUMS:
666 sRet.AssignAscii( SwForm::aFormPageNums );
667 break;
668 case TOKEN_CHAPTER_INFO:
669 sRet.AssignAscii( SwForm::aFormChapterMark );
670 break;
671 case TOKEN_LINK_START:
672 sRet.AssignAscii( SwForm::aFormLinkStt );
673 break;
674 case TOKEN_LINK_END:
675 sRet.AssignAscii( SwForm::aFormLinkEnd );
676 break;
677 case TOKEN_AUTHORITY:
678 {
679 sRet.AssignAscii( SwForm::aFormAuth );
680 String sTmp( String::CreateFromInt32( nAuthorityField ));
681 if( sTmp.Len() < 2 )
682 sTmp.Insert('0', 0);
683 sRet.Insert( sTmp, 2 );
684 }
685 break;
686 case TOKEN_END:
687 break;
688 }
689 sRet.Erase( sRet.Len() - 1 );
690 sRet += ' ';
691 sRet += sCharStyleName;
692 sRet += ',';
693 sRet += String::CreateFromInt32( nPoolId );
694 sRet += ',';
695
696 // TabStopPosition and TabAlign or ChapterInfoFormat
697 if(TOKEN_TAB_STOP == eTokenType)
698 {
699 sRet += String::CreateFromInt32( nTabStopPosition );
700 sRet += ',';
701 sRet += String::CreateFromInt32( static_cast< sal_Int32 >(eTabAlign) );
702 sRet += ',';
703 sRet += cTabFillChar;
704 sRet += ',';
705 sRet += String::CreateFromInt32( bWithTab );
706 }
707 else if(TOKEN_CHAPTER_INFO == eTokenType)
708 {
709 sRet += String::CreateFromInt32( nChapterFormat );
710 //add maximum permetted level
711 sRet += ',';
712 sRet += String::CreateFromInt32( nOutlineLevel );
713 }
714 else if(TOKEN_TEXT == eTokenType)
715 {
716 //append Text if Len() > 0 only!
717 if( sText.Len() )
718 {
719 sRet += TOX_STYLE_DELIMITER;
720 String sTmp( sText );
721 sTmp.EraseAllChars( TOX_STYLE_DELIMITER );
722 sRet += sTmp;
723 sRet += TOX_STYLE_DELIMITER;
724 }
725 else
726 bAppend = sal_False;
727 }
728 else if(TOKEN_ENTRY_NO == eTokenType)
729 {
730 sRet += String::CreateFromInt32( nChapterFormat );
731 //add maximum permitted level
732 sRet += ',';
733 sRet += String::CreateFromInt32( nOutlineLevel );
734 }
735
736 if(bAppend)
737 {
738 sRet += '>';
739 }
740 else
741 {
742 // don't append empty text tokens
743 sRet.Erase();
744 }
745
746 return sRet;
747 }
748
749 // -> #i21237#
SwFormTokensHelper(const String & rPattern)750 SwFormTokensHelper::SwFormTokensHelper(const String & rPattern)
751 {
752 xub_StrLen nCurPatternPos = 0;
753 xub_StrLen nCurPatternLen = 0;
754
755 while (nCurPatternPos < rPattern.Len())
756 {
757 nCurPatternPos = nCurPatternPos + nCurPatternLen;
758
759 SwFormToken aToken = BuildToken(rPattern, nCurPatternPos);
760 aTokens.push_back(aToken);
761 }
762 }
763
BuildToken(const String & sPattern,xub_StrLen & nCurPatternPos) const764 SwFormToken SwFormTokensHelper::BuildToken( const String & sPattern,
765 xub_StrLen & nCurPatternPos ) const
766 {
767 String sToken( SearchNextToken(sPattern, nCurPatternPos) );
768 nCurPatternPos = nCurPatternPos + sToken.Len();
769 xub_StrLen nTokenLen;
770 FormTokenType eTokenType = GetTokenType(sToken, &nTokenLen);
771
772 // at this point sPattern contains the
773 // character style name, the PoolId, tab stop position, tab stop alignment, chapter info format
774 // the form is: CharStyleName, PoolId[, TabStopPosition|ChapterInfoFormat[, TabStopAlignment[, TabFillChar]]]
775 // in text tokens the form differs from the others: CharStyleName, PoolId[,\0xffinserted text\0xff]
776 SwFormToken eRet( eTokenType );
777 String sAuthFieldEnum = sToken.Copy( 2, 2 );
778 sToken = sToken.Copy( nTokenLen, sToken.Len() - nTokenLen - 1);
779
780 eRet.sCharStyleName = sToken.GetToken( 0, ',');
781 String sTmp( sToken.GetToken( 1, ',' ));
782 if( sTmp.Len() )
783 eRet.nPoolId = static_cast<sal_uInt16>(sTmp.ToInt32());
784
785 switch( eTokenType )
786 {
787 //i53420
788 case TOKEN_ENTRY_NO:
789 if( (sTmp = sToken.GetToken( 2, ',' ) ).Len() )
790 eRet.nChapterFormat = static_cast<sal_uInt16>(sTmp.ToInt32());
791 if( (sTmp = sToken.GetToken( 3, ',' ) ).Len() )
792 eRet.nOutlineLevel = static_cast<sal_uInt16>(sTmp.ToInt32()); //the maximum outline level to examine
793 break;
794
795 case TOKEN_TEXT:
796 {
797 xub_StrLen nStartText = sToken.Search( TOX_STYLE_DELIMITER );
798 if( STRING_NOTFOUND != nStartText )
799 {
800 xub_StrLen nEndText = sToken.Search( TOX_STYLE_DELIMITER,
801 nStartText + 1);
802 if( STRING_NOTFOUND != nEndText )
803 {
804 eRet.sText = sToken.Copy( nStartText + 1,
805 nEndText - nStartText - 1);
806 }
807 }
808 }
809 break;
810
811 case TOKEN_TAB_STOP:
812 if( (sTmp = sToken.GetToken( 2, ',' ) ).Len() )
813 eRet.nTabStopPosition = sTmp.ToInt32();
814
815 if( (sTmp = sToken.GetToken( 3, ',' ) ).Len() )
816 eRet.eTabAlign = static_cast<SvxTabAdjust>(sTmp.ToInt32());
817
818 if( (sTmp = sToken.GetToken( 4, ',' ) ).Len() )
819 eRet.cTabFillChar = sTmp.GetChar(0);
820
821 if( (sTmp = sToken.GetToken( 5, ',' ) ).Len() )
822 eRet.bWithTab = 0 != sTmp.ToInt32();
823 break;
824
825 case TOKEN_CHAPTER_INFO:
826 if( (sTmp = sToken.GetToken( 2, ',' ) ).Len() )
827 eRet.nChapterFormat = static_cast<sal_uInt16>(sTmp.ToInt32()); //SwChapterFormat;
828 //i53420
829 if( (sTmp = sToken.GetToken( 3, ',' ) ).Len() )
830 eRet.nOutlineLevel = static_cast<sal_uInt16>(sTmp.ToInt32()); //the maximum outline level to examine
831
832 break;
833
834 case TOKEN_AUTHORITY:
835 eRet.nAuthorityField = static_cast<sal_uInt16>(sAuthFieldEnum.ToInt32());
836 break;
837 default: break;
838 }
839 return eRet;
840 }
841
SearchNextToken(const String & sPattern,xub_StrLen nStt) const842 String SwFormTokensHelper::SearchNextToken( const String & sPattern,
843 xub_StrLen nStt ) const
844 {
845 //it's not so easy - it doesn't work if the text part contains a '>'
846 //sal_uInt16 nTokenEnd = sPattern.Search('>');
847
848 String aResult;
849
850 xub_StrLen nEnd = sPattern.Search( '>', nStt );
851 if( STRING_NOTFOUND == nEnd )
852 {
853 nEnd = sPattern.Len();
854 }
855 else
856 {
857 xub_StrLen nTextSeparatorFirst = sPattern.Search( TOX_STYLE_DELIMITER, nStt );
858 if( STRING_NOTFOUND != nTextSeparatorFirst )
859 {
860 xub_StrLen nTextSeparatorSecond = sPattern.Search( TOX_STYLE_DELIMITER,
861 nTextSeparatorFirst + 1 );
862 if( STRING_NOTFOUND != nTextSeparatorSecond &&
863 nEnd > nTextSeparatorFirst )
864 nEnd = sPattern.Search( '>', nTextSeparatorSecond );
865 }
866
867 ++nEnd;
868
869 aResult = sPattern.Copy( nStt, nEnd - nStt );
870 }
871
872 return aResult;
873 }
874
GetTokenType(const String & sToken,xub_StrLen * pTokenLen) const875 FormTokenType SwFormTokensHelper::GetTokenType(const String & sToken,
876 xub_StrLen * pTokenLen) const
877 {
878 static struct
879 {
880 const sal_Char* pNm;
881 sal_uInt16 nLen;
882 sal_uInt16 nOffset;
883 FormTokenType eToken;
884 } __READONLY_DATA aTokenArr[] = {
885 { SwForm::aFormTab, SwForm::nFormEntryLen, 1, TOKEN_TAB_STOP },
886 { SwForm::aFormPageNums, SwForm::nFormPageNumsLen, 1, TOKEN_PAGE_NUMS },
887 { SwForm::aFormLinkStt, SwForm::nFormLinkSttLen, 1, TOKEN_LINK_START },
888 { SwForm::aFormLinkEnd, SwForm::nFormLinkEndLen, 1, TOKEN_LINK_END },
889 { SwForm::aFormEntryNum, SwForm::nFormEntryNumLen, 1, TOKEN_ENTRY_NO },
890 { SwForm::aFormEntryTxt, SwForm::nFormEntryTxtLen, 1, TOKEN_ENTRY_TEXT },
891 { SwForm::aFormChapterMark,SwForm::nFormChapterMarkLen,1,TOKEN_CHAPTER_INFO },
892 { SwForm::aFormText, SwForm::nFormTextLen, 1, TOKEN_TEXT },
893 { SwForm::aFormEntry, SwForm::nFormEntryLen, 1, TOKEN_ENTRY },
894 { SwForm::aFormAuth, SwForm::nFormAuthLen, 3, TOKEN_AUTHORITY },
895 { 0, 0, 0, TOKEN_END }
896 };
897
898 FormTokenType eTokenType = TOKEN_TEXT;
899 xub_StrLen nTokenLen = 0;
900 const sal_Char* pNm;
901 for( int i = 0; 0 != ( pNm = aTokenArr[ i ].pNm ); ++i )
902 if( COMPARE_EQUAL == sToken.CompareToAscii( pNm,
903 aTokenArr[ i ].nLen - aTokenArr[ i ].nOffset ))
904 {
905 eTokenType = aTokenArr[ i ].eToken;
906 nTokenLen = aTokenArr[ i ].nLen;
907 break;
908 }
909
910 ASSERT( pNm, "wrong token" );
911 if (pTokenLen)
912 *pTokenLen = nTokenLen;
913
914 return eTokenType;
915 }
916
917 // <- #i21237#
918
SetPattern(sal_uInt16 nLevel,const SwFormTokens & rTokens)919 void SwForm::SetPattern(sal_uInt16 nLevel, const SwFormTokens& rTokens)
920 {
921 ASSERT(nLevel < GetFormMax(), "Index >= FORM_MAX");
922 aPattern[nLevel] = rTokens;
923 }
924
SetPattern(sal_uInt16 nLevel,const String & rStr)925 void SwForm::SetPattern(sal_uInt16 nLevel, const String & rStr)
926 {
927 ASSERT(nLevel < GetFormMax(), "Index >= FORM_MAX");
928
929 SwFormTokensHelper aHelper(rStr);
930 aPattern[nLevel] = aHelper.GetTokens();
931 }
932
GetPattern(sal_uInt16 nLevel) const933 const SwFormTokens& SwForm::GetPattern(sal_uInt16 nLevel) const
934 {
935 ASSERT(nLevel < GetFormMax(), "Index >= FORM_MAX");
936 return aPattern[nLevel];
937 }
938
939