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