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 <tools/resid.hxx>
22 : #include <unotools/charclass.hxx>
23 : #include <com/sun/star/i18n/CollatorOptions.hpp>
24 : #include <editeng/unolingu.hxx>
25 : #include <txtfld.hxx>
26 : #include <doc.hxx>
27 : #include <docary.hxx>
28 : #include <cntfrm.hxx>
29 : #include <node.hxx>
30 : #include <frmatr.hxx>
31 : #include <pam.hxx>
32 : #include <txttxmrk.hxx>
33 : #include <frmfmt.hxx>
34 : #include <fmtfld.hxx>
35 : #include <txmsrt.hxx>
36 : #include <ndtxt.hxx>
37 : #include <txtatr.hxx>
38 : #include <swtable.hxx>
39 : #include <expfld.hxx>
40 : #include <authfld.hxx>
41 : #include <toxwrap.hxx>
42 :
43 : #include <comcore.hrc>
44 : #include <numrule.hxx>
45 :
46 : extern bool IsFrameBehind( const SwTxtNode& rMyNd, xub_StrLen nMySttPos,
47 : const SwTxtNode& rBehindNd, xub_StrLen nSttPos );
48 :
49 : using namespace ::com::sun::star;
50 : using namespace ::com::sun::star::uno;
51 : using ::rtl::OUString;
52 : /*--------------------------------------------------------------------
53 : Initialize strings
54 : --------------------------------------------------------------------*/
55 :
56 : sal_uInt16 SwTOXSortTabBase::nOpt = 0;
57 :
58 0 : SwTOXInternational::SwTOXInternational( LanguageType nLang, sal_uInt16 nOpt,
59 : const String& rSortAlgorithm ) :
60 : eLang( nLang ),
61 : sSortAlgorithm(rSortAlgorithm),
62 0 : nOptions( nOpt )
63 : {
64 0 : Init();
65 0 : }
66 :
67 0 : SwTOXInternational::SwTOXInternational( const SwTOXInternational& rIntl ) :
68 : eLang( rIntl.eLang ),
69 : sSortAlgorithm(rIntl.sSortAlgorithm),
70 0 : nOptions( rIntl.nOptions )
71 : {
72 0 : Init();
73 0 : }
74 :
75 0 : void SwTOXInternational::Init()
76 : {
77 0 : pIndexWrapper = new IndexEntrySupplierWrapper();
78 :
79 0 : const lang::Locale aLcl( LanguageTag( eLang ).getLocale() );
80 0 : pIndexWrapper->SetLocale( aLcl );
81 :
82 0 : if(!sSortAlgorithm.Len())
83 : {
84 0 : Sequence < OUString > aSeq( pIndexWrapper->GetAlgorithmList( aLcl ));
85 0 : if(aSeq.getLength())
86 0 : sSortAlgorithm = aSeq.getConstArray()[0];
87 : }
88 :
89 0 : if ( nOptions & nsSwTOIOptions::TOI_CASE_SENSITIVE )
90 0 : pIndexWrapper->LoadAlgorithm( aLcl, sSortAlgorithm, 0 );
91 : else
92 0 : pIndexWrapper->LoadAlgorithm( aLcl, sSortAlgorithm, SW_COLLATOR_IGNORES );
93 :
94 0 : pCharClass = new CharClass( LanguageTag( aLcl ));
95 :
96 0 : }
97 :
98 0 : SwTOXInternational::~SwTOXInternational()
99 : {
100 0 : delete pCharClass;
101 0 : delete pIndexWrapper;
102 0 : }
103 :
104 0 : String SwTOXInternational::ToUpper( const String& rStr, xub_StrLen nPos ) const
105 : {
106 0 : return pCharClass->uppercase( rStr, nPos, 1 );
107 : }
108 0 : inline sal_Bool SwTOXInternational::IsNumeric( const String& rStr ) const
109 : {
110 0 : return pCharClass->isNumeric( rStr );
111 : }
112 :
113 0 : sal_Int32 SwTOXInternational::Compare( const String& rTxt1, const String& rTxtReading1,
114 : const lang::Locale& rLocale1,
115 : const String& rTxt2, const String& rTxtReading2,
116 : const lang::Locale& rLocale2 ) const
117 : {
118 : return pIndexWrapper->CompareIndexEntry( rTxt1, rTxtReading1, rLocale1,
119 0 : rTxt2, rTxtReading2, rLocale2 );
120 : }
121 :
122 0 : String SwTOXInternational::GetIndexKey( const String& rTxt, const String& rTxtReading,
123 : const lang::Locale& rLocale ) const
124 : {
125 0 : return pIndexWrapper->GetIndexKey( rTxt, rTxtReading, rLocale );
126 : }
127 :
128 0 : String SwTOXInternational::GetFollowingText( sal_Bool bMorePages ) const
129 : {
130 0 : return pIndexWrapper->GetFollowingText( bMorePages );
131 : }
132 :
133 : /*--------------------------------------------------------------------
134 : SortElement for TOX entries
135 : --------------------------------------------------------------------*/
136 :
137 :
138 0 : SwTOXSortTabBase::SwTOXSortTabBase( TOXSortType nTyp, const SwCntntNode* pNd,
139 : const SwTxtTOXMark* pMark,
140 : const SwTOXInternational* pInter,
141 : const lang::Locale* pLocale )
142 : : pTOXNd( 0 ), pTxtMark( pMark ), pTOXIntl( pInter ),
143 0 : nPos( 0 ), nCntPos( 0 ), nType( static_cast<sal_uInt16>(nTyp) ), bValidTxt( sal_False )
144 : {
145 0 : if ( pLocale )
146 0 : aLocale = *pLocale;
147 :
148 0 : if( pNd )
149 : {
150 0 : xub_StrLen n = 0;
151 0 : if( pTxtMark )
152 0 : n = *pTxtMark->GetStart();
153 : SwTOXSource aTmp( pNd, n,
154 0 : pTxtMark ? pTxtMark->GetTOXMark().IsMainEntry() : sal_False );
155 0 : aTOXSources.push_back(aTmp);
156 :
157 0 : nPos = pNd->GetIndex();
158 :
159 0 : switch( nTyp )
160 : {
161 : case TOX_SORT_CONTENT:
162 : case TOX_SORT_PARA:
163 : case TOX_SORT_TABLE:
164 : // If they are in a special areas, we should get the position at the
165 : // body
166 0 : if( nPos < pNd->GetNodes().GetEndOfExtras().GetIndex() )
167 : {
168 : // Then get the 'anchor' (body) position
169 0 : Point aPt;
170 0 : const SwCntntFrm* pFrm = pNd->getLayoutFrm( pNd->GetDoc()->GetCurrentLayout(), &aPt, 0, sal_False );
171 0 : if( pFrm )
172 : {
173 0 : SwPosition aPos( *pNd );
174 0 : const SwDoc& rDoc = *pNd->GetDoc();
175 0 : bool const bResult = GetBodyTxtNode( rDoc, aPos, *pFrm );
176 : OSL_ENSURE(bResult, "where is the text node");
177 : (void) bResult; // unused in non-debug
178 0 : nPos = aPos.nNode.GetIndex();
179 0 : nCntPos = aPos.nContent.GetIndex();
180 : }
181 : }
182 : else
183 0 : nCntPos = n;
184 0 : break;
185 0 : default: break;
186 : }
187 : }
188 0 : }
189 :
190 :
191 0 : String SwTOXSortTabBase::GetURL() const
192 : {
193 0 : return aEmptyStr;
194 : }
195 :
196 0 : void SwTOXSortTabBase::FillText( SwTxtNode& rNd, const SwIndex& rInsPos,
197 : sal_uInt16 ) const
198 : {
199 0 : String sMyTxt;
200 0 : String sMyTxtReading;
201 :
202 0 : GetTxt( sMyTxt, sMyTxtReading );
203 :
204 0 : rNd.InsertText( sMyTxt, rInsPos );
205 0 : }
206 :
207 0 : bool SwTOXSortTabBase::operator==( const SwTOXSortTabBase& rCmp )
208 : {
209 : bool bRet = nPos == rCmp.nPos && nCntPos == rCmp.nCntPos &&
210 0 : (!aTOXSources[0].pNd || !rCmp.aTOXSources[0].pNd ||
211 0 : aTOXSources[0].pNd == rCmp.aTOXSources[0].pNd );
212 :
213 0 : if( TOX_SORT_CONTENT == nType )
214 : {
215 : bRet = bRet && pTxtMark && rCmp.pTxtMark &&
216 0 : *pTxtMark->GetStart() == *rCmp.pTxtMark->GetStart();
217 :
218 0 : if( bRet )
219 : {
220 : // Both pointers exist -> compare text
221 : // else -> compare AlternativeText
222 0 : const xub_StrLen *pEnd = pTxtMark->GetEnd(),
223 0 : *pEndCmp = rCmp.pTxtMark->GetEnd();
224 :
225 0 : String sMyTxt;
226 0 : String sMyTxtReading;
227 0 : GetTxt( sMyTxt, sMyTxtReading );
228 :
229 0 : String sOtherTxt;
230 0 : String sOtherTxtReading;
231 0 : rCmp.GetTxt( sOtherTxt, sOtherTxtReading );
232 :
233 : bRet = ( ( pEnd && pEndCmp ) || ( !pEnd && !pEndCmp ) ) &&
234 0 : pTOXIntl->IsEqual( sMyTxt, sMyTxtReading, GetLocale(),
235 0 : sOtherTxt, sOtherTxtReading, rCmp.GetLocale() );
236 : }
237 : }
238 0 : return bRet;
239 : }
240 :
241 0 : bool SwTOXSortTabBase::operator<( const SwTOXSortTabBase& rCmp )
242 : {
243 0 : if( nPos < rCmp.nPos )
244 0 : return true;
245 :
246 0 : if( nPos == rCmp.nPos )
247 : {
248 0 : if( nCntPos < rCmp.nCntPos )
249 0 : return true;
250 :
251 0 : if( nCntPos == rCmp.nCntPos )
252 : {
253 0 : const SwNode* pFirst = aTOXSources[0].pNd;
254 0 : const SwNode* pNext = rCmp.aTOXSources[0].pNd;
255 :
256 0 : if( pFirst && pFirst == pNext )
257 : {
258 0 : if( TOX_SORT_CONTENT == nType && pTxtMark && rCmp.pTxtMark )
259 : {
260 0 : if( *pTxtMark->GetStart() < *rCmp.pTxtMark->GetStart() )
261 0 : return true;
262 :
263 0 : if( *pTxtMark->GetStart() == *rCmp.pTxtMark->GetStart() )
264 : {
265 0 : const xub_StrLen *pEnd = pTxtMark->GetEnd(),
266 0 : *pEndCmp = rCmp.pTxtMark->GetEnd();
267 :
268 0 : String sMyTxt;
269 0 : String sMyTxtReading;
270 0 : GetTxt( sMyTxt, sMyTxtReading );
271 :
272 0 : String sOtherTxt;
273 0 : String sOtherTxtReading;
274 0 : rCmp.GetTxt( sOtherTxt, sOtherTxtReading );
275 :
276 : // Both pointers exist -> compare text
277 : // else -> compare AlternativeText
278 0 : if( ( pEnd && pEndCmp ) || ( !pEnd && !pEndCmp ) )
279 0 : pTOXIntl->IsEqual( sMyTxt, sMyTxtReading, GetLocale(),
280 0 : sOtherTxt, sOtherTxtReading, rCmp.GetLocale() );
281 :
282 0 : if( pEnd && !pEndCmp )
283 0 : return true;
284 : }
285 0 : }
286 : }
287 0 : else if( pFirst && pFirst->IsTxtNode() &&
288 0 : pNext && pNext->IsTxtNode() )
289 : return ::IsFrameBehind( *(SwTxtNode*)pNext, nCntPos,
290 0 : *(SwTxtNode*)pFirst, nCntPos );
291 : }
292 : }
293 0 : return false;
294 : }
295 :
296 : /*--------------------------------------------------------------------
297 : Sorted keyword entry
298 : --------------------------------------------------------------------*/
299 :
300 :
301 0 : SwTOXIndex::SwTOXIndex( const SwTxtNode& rNd,
302 : const SwTxtTOXMark* pMark, sal_uInt16 nOptions,
303 : sal_uInt8 nKyLevel,
304 : const SwTOXInternational& rIntl,
305 : const lang::Locale& rLocale )
306 : : SwTOXSortTabBase( TOX_SORT_INDEX, &rNd, pMark, &rIntl, &rLocale ),
307 0 : nKeyLevel(nKyLevel)
308 : {
309 0 : nPos = rNd.GetIndex();
310 0 : nOpt = nOptions;
311 0 : }
312 :
313 : //
314 : // Compare keywords. Only relates to the text.
315 : //
316 :
317 :
318 0 : bool SwTOXIndex::operator==( const SwTOXSortTabBase& rCmpBase )
319 : {
320 0 : SwTOXIndex& rCmp = (SwTOXIndex&)rCmpBase;
321 :
322 : // Respect case taking dependencies into account
323 0 : if(GetLevel() != rCmp.GetLevel() || nKeyLevel != rCmp.nKeyLevel)
324 0 : return false;
325 :
326 : OSL_ENSURE(pTxtMark, "pTxtMark == 0, No keyword");
327 :
328 0 : String sMyTxt;
329 0 : String sMyTxtReading;
330 0 : GetTxt( sMyTxt, sMyTxtReading );
331 :
332 0 : String sOtherTxt;
333 0 : String sOtherTxtReading;
334 0 : rCmp.GetTxt( sOtherTxt, sOtherTxtReading );
335 :
336 0 : bool bRet = pTOXIntl->IsEqual( sMyTxt, sMyTxtReading, GetLocale(),
337 0 : sOtherTxt, sOtherTxtReading, rCmp.GetLocale() );
338 :
339 : // If we don't summarize we need to evaluate the Pos
340 0 : if(bRet && !(GetOptions() & nsSwTOIOptions::TOI_SAME_ENTRY))
341 0 : bRet = nPos == rCmp.nPos;
342 :
343 0 : return bRet;
344 : }
345 :
346 : //
347 : // operator, only depends on the text
348 :
349 0 : bool SwTOXIndex::operator<( const SwTOXSortTabBase& rCmpBase )
350 : {
351 0 : SwTOXIndex& rCmp = (SwTOXIndex&)rCmpBase;
352 :
353 : OSL_ENSURE(pTxtMark, "pTxtMark == 0, No keyword");
354 :
355 0 : String sMyTxt;
356 0 : String sMyTxtReading;
357 0 : GetTxt( sMyTxt, sMyTxtReading );
358 :
359 0 : String sOtherTxt;
360 0 : String sOtherTxtReading;
361 0 : rCmp.GetTxt( sOtherTxt, sOtherTxtReading );
362 :
363 0 : bool bRet = GetLevel() == rCmp.GetLevel() &&
364 0 : pTOXIntl->IsLess( sMyTxt, sMyTxtReading, GetLocale(),
365 0 : sOtherTxt, sOtherTxtReading, rCmp.GetLocale() );
366 :
367 : // If we don't summarize we need to evaluate the Pos
368 0 : if( !bRet && !(GetOptions() & nsSwTOIOptions::TOI_SAME_ENTRY) )
369 : {
370 0 : bRet = pTOXIntl->IsEqual( sMyTxt, sMyTxtReading, GetLocale(),
371 0 : sOtherTxt, sOtherTxtReading, rCmp.GetLocale() ) &&
372 0 : nPos < rCmp.nPos;
373 : }
374 :
375 0 : return bRet;
376 : }
377 :
378 : //
379 : // The keyword itself
380 :
381 0 : void SwTOXIndex::GetText_Impl( String& rTxt, String& rTxtReading ) const
382 : {
383 : OSL_ENSURE(pTxtMark, "pTxtMark == 0, No keyword");
384 0 : const SwTOXMark& rTOXMark = pTxtMark->GetTOXMark();
385 0 : switch(nKeyLevel)
386 : {
387 : case FORM_PRIMARY_KEY :
388 : {
389 0 : rTxt = rTOXMark.GetPrimaryKey();
390 0 : rTxtReading = rTOXMark.GetPrimaryKeyReading();
391 : }
392 0 : break;
393 : case FORM_SECONDARY_KEY :
394 : {
395 0 : rTxt = rTOXMark.GetSecondaryKey();
396 0 : rTxtReading = rTOXMark.GetSecondaryKeyReading();
397 : }
398 0 : break;
399 : case FORM_ENTRY :
400 : {
401 0 : rTxt = rTOXMark.GetText();
402 0 : rTxtReading = rTOXMark.GetTextReading();
403 : }
404 0 : break;
405 : }
406 : // if TOI_INITIAL_CAPS is set, first character is to be capitalized
407 0 : if( nsSwTOIOptions::TOI_INITIAL_CAPS & nOpt && pTOXIntl )
408 : {
409 0 : String sUpper( pTOXIntl->ToUpper( rTxt, 0 ));
410 0 : rTxt.Erase( 0, 1 ).Insert( sUpper, 0 );
411 : }
412 0 : }
413 :
414 0 : void SwTOXIndex::FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 ) const
415 : {
416 0 : const xub_StrLen* pEnd = pTxtMark->GetEnd();
417 0 : String sTmp;
418 0 : String sTmpReading;
419 0 : if( pEnd && !pTxtMark->GetTOXMark().IsAlternativeText() &&
420 0 : 0 == (GetOptions() & nsSwTOIOptions::TOI_KEY_AS_ENTRY))
421 : {
422 0 : sTmp = ((SwTxtNode*)aTOXSources[0].pNd)->GetExpandTxt(
423 0 : *pTxtMark->GetStart(),
424 0 : *pEnd - *pTxtMark->GetStart());
425 0 : if(nsSwTOIOptions::TOI_INITIAL_CAPS&nOpt && pTOXIntl)
426 : {
427 0 : String sUpper( pTOXIntl->ToUpper( sTmp, 0 ));
428 0 : sTmp.Erase( 0, 1 ).Insert( sUpper, 0 );
429 : }
430 : }
431 : else
432 0 : GetTxt( sTmp, sTmpReading );
433 :
434 0 : rNd.InsertText( sTmp, rInsPos );
435 0 : }
436 :
437 :
438 :
439 0 : sal_uInt16 SwTOXIndex::GetLevel() const
440 : {
441 : OSL_ENSURE(pTxtMark, "pTxtMark == 0, No keyword");
442 :
443 0 : sal_uInt16 nForm = FORM_PRIMARY_KEY;
444 :
445 0 : if( 0 == (GetOptions() & nsSwTOIOptions::TOI_KEY_AS_ENTRY)&&
446 0 : pTxtMark->GetTOXMark().GetPrimaryKey().Len() )
447 : {
448 0 : nForm = FORM_SECONDARY_KEY;
449 0 : if( pTxtMark->GetTOXMark().GetSecondaryKey().Len() )
450 0 : nForm = FORM_ENTRY;
451 : }
452 0 : return nForm;
453 : }
454 :
455 : /*--------------------------------------------------------------------
456 : Key and separator
457 : --------------------------------------------------------------------*/
458 :
459 :
460 0 : SwTOXCustom::SwTOXCustom(const String& rStr, const String& rReading,
461 : sal_uInt16 nLevel,
462 : const SwTOXInternational& rIntl,
463 : const lang::Locale& rLocale )
464 : : SwTOXSortTabBase( TOX_SORT_CUSTOM, 0, 0, &rIntl, &rLocale ),
465 0 : aKey(rStr), sReading(rReading), nLev(nLevel)
466 : {
467 0 : }
468 :
469 :
470 0 : bool SwTOXCustom::operator==(const SwTOXSortTabBase& rCmpBase)
471 : {
472 0 : String sMyTxt;
473 0 : String sMyTxtReading;
474 0 : GetTxt( sMyTxt, sMyTxtReading );
475 :
476 0 : String sOtherTxt;
477 0 : String sOtherTxtReading;
478 0 : rCmpBase.GetTxt( sOtherTxt, sOtherTxtReading );
479 :
480 0 : return GetLevel() == rCmpBase.GetLevel() &&
481 0 : pTOXIntl->IsEqual( sMyTxt, sMyTxtReading, GetLocale(),
482 0 : sOtherTxt, sOtherTxtReading, rCmpBase.GetLocale() );
483 : }
484 :
485 :
486 0 : bool SwTOXCustom::operator < (const SwTOXSortTabBase& rCmpBase)
487 : {
488 0 : String sMyTxt;
489 0 : String sMyTxtReading;
490 0 : GetTxt( sMyTxt, sMyTxtReading );
491 :
492 0 : String sOtherTxt;
493 0 : String sOtherTxtReading;
494 0 : rCmpBase.GetTxt( sOtherTxt, sOtherTxtReading );
495 :
496 0 : return GetLevel() <= rCmpBase.GetLevel() &&
497 0 : pTOXIntl->IsLess( sMyTxt, sMyTxtReading, GetLocale(),
498 0 : sOtherTxt, sOtherTxtReading, rCmpBase.GetLocale() );
499 : }
500 :
501 :
502 0 : sal_uInt16 SwTOXCustom::GetLevel() const
503 : {
504 0 : return nLev;
505 : }
506 :
507 :
508 0 : void SwTOXCustom::GetText_Impl( String& rTxt, String &rTxtReading ) const
509 : {
510 0 : rTxt = aKey;
511 0 : rTxtReading = sReading;
512 0 : }
513 :
514 :
515 : /*--------------------------------------------------------------------
516 : Sorts the TOX entries
517 : --------------------------------------------------------------------*/
518 :
519 :
520 0 : SwTOXContent::SwTOXContent( const SwTxtNode& rNd, const SwTxtTOXMark* pMark,
521 : const SwTOXInternational& rIntl)
522 0 : : SwTOXSortTabBase( TOX_SORT_CONTENT, &rNd, pMark, &rIntl )
523 : {
524 0 : }
525 :
526 :
527 : // The content's text
528 :
529 0 : void SwTOXContent::GetText_Impl( String& rTxt, String& rTxtReading ) const
530 : {
531 0 : const xub_StrLen* pEnd = pTxtMark->GetEnd();
532 0 : if( pEnd && !pTxtMark->GetTOXMark().IsAlternativeText() )
533 : {
534 0 : rTxt = ((SwTxtNode*)aTOXSources[0].pNd)->GetExpandTxt(
535 0 : *pTxtMark->GetStart(),
536 0 : *pEnd - *pTxtMark->GetStart() );
537 :
538 0 : rTxtReading = pTxtMark->GetTOXMark().GetTextReading();
539 : }
540 : else
541 0 : rTxt = pTxtMark->GetTOXMark().GetAlternativeText();
542 0 : }
543 :
544 0 : void SwTOXContent::FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 ) const
545 : {
546 0 : const xub_StrLen* pEnd = pTxtMark->GetEnd();
547 0 : if( pEnd && !pTxtMark->GetTOXMark().IsAlternativeText() )
548 0 : ((SwTxtNode*)aTOXSources[0].pNd)->GetExpandTxt( rNd, &rInsPos,
549 0 : *pTxtMark->GetStart(),
550 0 : *pEnd - *pTxtMark->GetStart() );
551 : else
552 : {
553 0 : String sTmp, sTmpReading;
554 0 : GetTxt( sTmp, sTmpReading );
555 0 : rNd.InsertText( sTmp, rInsPos );
556 : }
557 0 : }
558 :
559 : //
560 : // The level for displaying it
561 : //
562 :
563 :
564 0 : sal_uInt16 SwTOXContent::GetLevel() const
565 : {
566 0 : return pTxtMark->GetTOXMark().GetLevel();
567 : }
568 :
569 : /*--------------------------------------------------------------------
570 : TOX assembled from paragraphs
571 : Watch out for OLE/graphics when sorting!
572 : The position must not come from the document, but from the "anchor"!
573 : --------------------------------------------------------------------*/
574 :
575 0 : SwTOXPara::SwTOXPara( const SwCntntNode& rNd, SwTOXElement eT, sal_uInt16 nLevel )
576 : : SwTOXSortTabBase( TOX_SORT_PARA, &rNd, 0, 0 ),
577 : eType( eT ),
578 : m_nLevel(nLevel),
579 : nStartIndex(0),
580 0 : nEndIndex(STRING_LEN)
581 : {
582 0 : }
583 :
584 :
585 0 : void SwTOXPara::GetText_Impl( String& rTxt, String& ) const
586 : {
587 0 : const SwCntntNode* pNd = aTOXSources[0].pNd;
588 0 : switch( eType )
589 : {
590 : case nsSwTOXElement::TOX_SEQUENCE:
591 : case nsSwTOXElement::TOX_TEMPLATE:
592 : case nsSwTOXElement::TOX_OUTLINELEVEL:
593 : {
594 0 : xub_StrLen nStt = nStartIndex;
595 : rTxt = ((SwTxtNode*)pNd)->GetExpandTxt(
596 : nStt,
597 0 : STRING_NOTFOUND == nEndIndex ? STRING_LEN : nEndIndex - nStt);
598 : }
599 0 : break;
600 :
601 : case nsSwTOXElement::TOX_OLE:
602 : case nsSwTOXElement::TOX_GRAPHIC:
603 : case nsSwTOXElement::TOX_FRAME:
604 : {
605 : // Find the FlyFormat; the object/graphic name is there
606 0 : SwFrmFmt* pFly = pNd->GetFlyFmt();
607 0 : if( pFly )
608 0 : rTxt = pFly->GetName();
609 : else
610 : {
611 : OSL_ENSURE( !this, "Graphic/object without name" );
612 : sal_uInt16 nId = nsSwTOXElement::TOX_OLE == eType
613 : ? STR_OBJECT_DEFNAME
614 : : nsSwTOXElement::TOX_GRAPHIC == eType
615 : ? STR_GRAPHIC_DEFNAME
616 0 : : STR_FRAME_DEFNAME;
617 0 : rTxt = SW_RESSTR( nId );
618 : }
619 : }
620 0 : break;
621 0 : default: break;
622 : }
623 0 : }
624 :
625 0 : void SwTOXPara::FillText( SwTxtNode& rNd, const SwIndex& rInsPos, sal_uInt16 ) const
626 : {
627 0 : if( nsSwTOXElement::TOX_TEMPLATE == eType || nsSwTOXElement::TOX_SEQUENCE == eType || nsSwTOXElement::TOX_OUTLINELEVEL == eType)
628 : {
629 0 : SwTxtNode* pSrc = (SwTxtNode*)aTOXSources[0].pNd;
630 0 : xub_StrLen nStt = nStartIndex;
631 : pSrc->GetExpandTxt( rNd, &rInsPos, nStt,
632 : nEndIndex == STRING_LEN ? STRING_LEN : nEndIndex - nStt,
633 0 : sal_False, sal_False, sal_True );
634 : }
635 : else
636 : {
637 0 : String sTmp, sTmpReading;
638 0 : GetTxt( sTmp, sTmpReading );
639 0 : sTmp.SearchAndReplaceAll('\t', ' ');
640 0 : rNd.InsertText( sTmp, rInsPos );
641 : }
642 0 : }
643 :
644 :
645 0 : sal_uInt16 SwTOXPara::GetLevel() const
646 : {
647 0 : sal_uInt16 nRet = m_nLevel;
648 0 : const SwCntntNode* pNd = aTOXSources[0].pNd;
649 :
650 0 : if( nsSwTOXElement::TOX_OUTLINELEVEL == eType && pNd->GetTxtNode() )
651 : {
652 0 : const int nTmp = ((SwTxtNode*)pNd)->GetAttrOutlineLevel();
653 0 : if(nTmp != 0 )
654 0 : nRet = static_cast<sal_uInt16>(nTmp);
655 : }
656 0 : return nRet;
657 : }
658 :
659 :
660 0 : String SwTOXPara::GetURL() const
661 : {
662 0 : String aTxt;
663 0 : const SwCntntNode* pNd = aTOXSources[0].pNd;
664 0 : switch( eType )
665 : {
666 : case nsSwTOXElement::TOX_TEMPLATE:
667 : case nsSwTOXElement::TOX_OUTLINELEVEL:
668 : {
669 0 : const SwTxtNode * pTxtNd = static_cast<const SwTxtNode *>(pNd);
670 :
671 0 : SwDoc* pDoc = const_cast<SwDoc*>( pTxtNd->GetDoc() );
672 0 : ::sw::mark::IMark const * const pMark = pDoc->getIDocumentMarkAccess()->getMarkForTxtNode(
673 : *(pTxtNd),
674 0 : IDocumentMarkAccess::CROSSREF_HEADING_BOOKMARK);
675 0 : aTxt = '#';
676 0 : const String aMarkName( pMark->GetName() );
677 0 : aTxt += aMarkName;
678 : }
679 0 : break;
680 :
681 : case nsSwTOXElement::TOX_OLE:
682 : case nsSwTOXElement::TOX_GRAPHIC:
683 : case nsSwTOXElement::TOX_FRAME:
684 : {
685 : // Find the FlyFormat; the object/graphic name is there
686 0 : SwFrmFmt* pFly = pNd->GetFlyFmt();
687 0 : if( pFly )
688 : {
689 0 : (( aTxt = '#' ) += pFly->GetName() ) += cMarkSeperator;
690 : const sal_Char* pStr;
691 0 : switch( eType )
692 : {
693 0 : case nsSwTOXElement::TOX_OLE: pStr = pMarkToOLE; break;
694 0 : case nsSwTOXElement::TOX_GRAPHIC: pStr = pMarkToGraphic; break;
695 0 : case nsSwTOXElement::TOX_FRAME: pStr = pMarkToFrame; break;
696 0 : default: pStr = 0;
697 : }
698 0 : if( pStr )
699 0 : aTxt.AppendAscii( pStr );
700 : }
701 : }
702 0 : break;
703 0 : default: break;
704 : }
705 0 : return aTxt;
706 : }
707 :
708 :
709 : /*--------------------------------------------------------------------
710 : Table
711 : --------------------------------------------------------------------*/
712 :
713 :
714 0 : SwTOXTable::SwTOXTable( const SwCntntNode& rNd )
715 : : SwTOXSortTabBase( TOX_SORT_TABLE, &rNd, 0, 0 ),
716 0 : nLevel(FORM_ALPHA_DELIMITTER)
717 : {
718 0 : }
719 :
720 :
721 0 : void SwTOXTable::GetText_Impl( String& rTxt, String& ) const
722 : {
723 0 : const SwNode* pNd = aTOXSources[0].pNd;
724 0 : if( pNd && 0 != ( pNd = pNd->FindTableNode() ) )
725 : {
726 0 : rTxt = ((SwTableNode*)pNd)->GetTable().GetFrmFmt()->GetName();
727 : }
728 : else
729 : {
730 : OSL_ENSURE( !this, "Where's my table?" );
731 0 : rTxt = SW_RESSTR( STR_TABLE_DEFNAME );
732 : }
733 0 : }
734 :
735 0 : sal_uInt16 SwTOXTable::GetLevel() const
736 : {
737 0 : return nLevel;
738 : }
739 :
740 :
741 0 : String SwTOXTable::GetURL() const
742 : {
743 0 : String aTxt;
744 0 : const SwNode* pNd = aTOXSources[0].pNd;
745 0 : if( pNd && 0 != ( pNd = pNd->FindTableNode() ) )
746 : {
747 0 : aTxt = ((SwTableNode*)pNd)->GetTable().GetFrmFmt()->GetName();
748 0 : if( aTxt.Len() )
749 : {
750 0 : ( aTxt.Insert( '#', 0 ) += cMarkSeperator ).
751 0 : AppendAscii( pMarkToTable );
752 : }
753 : }
754 0 : return aTxt;
755 : }
756 :
757 0 : SwTOXAuthority::SwTOXAuthority( const SwCntntNode& rNd,
758 : SwFmtFld& rField, const SwTOXInternational& rIntl ) :
759 : SwTOXSortTabBase( TOX_SORT_AUTHORITY, &rNd, 0, &rIntl ),
760 0 : m_rField(rField)
761 : {
762 0 : if(rField.GetTxtFld())
763 0 : nCntPos = *rField.GetTxtFld()->GetStart();
764 0 : }
765 :
766 0 : sal_uInt16 SwTOXAuthority::GetLevel() const
767 : {
768 0 : String sText(((SwAuthorityField*)m_rField.GetFld())->
769 0 : GetFieldText(AUTH_FIELD_AUTHORITY_TYPE));
770 : //#i18655# the level '0' is the heading level therefor the values are incremented here
771 0 : sal_uInt16 nRet = 1;
772 0 : if( pTOXIntl->IsNumeric( sText ) )
773 : {
774 0 : nRet = (sal_uInt16)sText.ToInt32();
775 0 : nRet++;
776 : }
777 : //illegal values are also set to 'ARTICLE' as non-numeric values are
778 0 : if(nRet > AUTH_TYPE_END)
779 0 : nRet = 1;
780 0 : return nRet;
781 : }
782 :
783 0 : static String lcl_GetText(SwFmtFld const& rField)
784 : {
785 0 : return rField.GetFld()->ExpandField(true);
786 : }
787 :
788 0 : void SwTOXAuthority::GetText_Impl( String& rTxt, String& ) const
789 : {
790 0 : rTxt = lcl_GetText(m_rField);
791 0 : }
792 :
793 0 : void SwTOXAuthority::FillText( SwTxtNode& rNd,
794 : const SwIndex& rInsPos, sal_uInt16 nAuthField ) const
795 : {
796 0 : SwAuthorityField* pField = (SwAuthorityField*)m_rField.GetFld();
797 0 : String sText;
798 0 : if(AUTH_FIELD_IDENTIFIER == nAuthField)
799 : {
800 0 : sText = lcl_GetText(m_rField);
801 0 : const SwAuthorityFieldType* pType = (const SwAuthorityFieldType*)pField->GetTyp();
802 0 : sal_Unicode cChar = pType->GetPrefix();
803 0 : if(cChar && cChar != ' ')
804 0 : sText.Erase(0, 1);
805 0 : cChar = pType->GetSuffix();
806 0 : if(cChar && cChar != ' ')
807 0 : sText.Erase(sText.Len() - 1, 1);
808 : }
809 0 : else if(AUTH_FIELD_AUTHORITY_TYPE == nAuthField)
810 : {
811 0 : sal_uInt16 nLevel = GetLevel();
812 0 : if(nLevel)
813 0 : sText = SwAuthorityFieldType::GetAuthTypeName((ToxAuthorityType) --nLevel);
814 : }
815 : else
816 0 : sText = (pField->GetFieldText((ToxAuthorityField) nAuthField));
817 0 : rNd.InsertText( sText, rInsPos );
818 0 : }
819 :
820 0 : bool SwTOXAuthority::operator==( const SwTOXSortTabBase& rCmp)
821 : {
822 : return nType == rCmp.nType &&
823 0 : ((SwAuthorityField*)m_rField.GetFld())->GetHandle() ==
824 0 : ((SwAuthorityField*)((SwTOXAuthority&)rCmp).m_rField.GetFld())->GetHandle();
825 : }
826 :
827 0 : bool SwTOXAuthority::operator<( const SwTOXSortTabBase& rBase)
828 : {
829 0 : bool bRet = false;
830 0 : SwAuthorityField* pField = (SwAuthorityField*)m_rField.GetFld();
831 : SwAuthorityFieldType* pType = (SwAuthorityFieldType*)
832 0 : pField->GetTyp();
833 0 : if(pType->IsSortByDocument())
834 0 : bRet = SwTOXSortTabBase::operator<(rBase);
835 : else
836 : {
837 : SwAuthorityField* pCmpField = (SwAuthorityField*)
838 0 : ((SwTOXAuthority&)rBase).m_rField.GetFld();
839 :
840 :
841 0 : for(sal_uInt16 i = 0; i < pType->GetSortKeyCount(); i++)
842 : {
843 0 : const SwTOXSortKey* pKey = pType->GetSortKey(i);
844 0 : String sMyTxt = pField->GetFieldText(pKey->eField);
845 0 : String sMyTxtReading;
846 0 : String sOtherTxt = pCmpField->GetFieldText(pKey->eField);
847 0 : String sOtherTxtReading;
848 :
849 0 : sal_Int32 nComp = pTOXIntl->Compare( sMyTxt, sMyTxtReading, GetLocale(),
850 0 : sOtherTxt, sOtherTxtReading, rBase.GetLocale() );
851 :
852 0 : if( nComp )
853 : {
854 0 : bRet = (-1 == nComp) == pKey->bSortAscending;
855 : break;
856 : }
857 0 : }
858 : }
859 0 : return bRet;
860 : }
861 :
862 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|