LibreOffice Module sw (master)  1
txmsrt.cxx
Go to the documentation of this file.
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 #include <unotools/charclass.hxx>
21 #include <txtfld.hxx>
22 #include <doc.hxx>
24 #include <IDocumentMarkAccess.hxx>
25 #include <cntfrm.hxx>
26 #include <txtfrm.hxx>
27 #include <rootfrm.hxx>
28 #include <modeltoviewhelper.hxx>
29 #include <node.hxx>
30 #include <pam.hxx>
31 #include <txttxmrk.hxx>
32 #include <frmfmt.hxx>
33 #include <fmtfld.hxx>
34 #include <txmsrt.hxx>
35 #include <ndtxt.hxx>
36 #include <swtable.hxx>
37 #include <expfld.hxx>
38 #include <authfld.hxx>
39 #include <toxwrap.hxx>
40 
41 #include <strings.hrc>
42 #include <reffld.hxx>
43 
44 using namespace ::com::sun::star;
45 using namespace ::com::sun::star::uno;
46 
47 // Initialize strings
49 
51  const OUString& rSortAlgorithm ) :
52  m_eLang( nLang ),
53  m_sSortAlgorithm(rSortAlgorithm),
54  m_nOptions( nOpt )
55 {
56  Init();
57 }
58 
60  m_eLang( rIntl.m_eLang ),
61  m_sSortAlgorithm(rIntl.m_sSortAlgorithm),
62  m_nOptions( rIntl.m_nOptions )
63 {
64  Init();
65 }
66 
68 {
70 
71  const lang::Locale aLcl( LanguageTag::convertToLocale( m_eLang ) );
72  m_pIndexWrapper->SetLocale( aLcl );
73 
74  if(m_sSortAlgorithm.isEmpty())
75  {
76  Sequence < OUString > aSeq( m_pIndexWrapper->GetAlgorithmList( aLcl ));
77  if(aSeq.hasElements())
78  m_sSortAlgorithm = aSeq.getConstArray()[0];
79  }
80 
82  m_pIndexWrapper->LoadAlgorithm( aLcl, m_sSortAlgorithm, 0 );
83  else
84  m_pIndexWrapper->LoadAlgorithm( aLcl, m_sSortAlgorithm, SW_COLLATOR_IGNORES );
85 
86  m_pCharClass.reset( new CharClass( LanguageTag( aLcl )) );
87 
88 }
89 
91 {
92  m_pCharClass.reset();
93  m_pIndexWrapper.reset();
94 }
95 
96 OUString SwTOXInternational::ToUpper( const OUString& rStr, sal_Int32 nPos ) const
97 {
98  return m_pCharClass->uppercase( rStr, nPos, 1 );
99 }
100 
101 inline bool SwTOXInternational::IsNumeric( const OUString& rStr ) const
102 {
103  return m_pCharClass->isNumeric( rStr );
104 }
105 
107  const lang::Locale& rLocale1,
108  const TextAndReading& rTaR2,
109  const lang::Locale& rLocale2 ) const
110 {
111  return m_pIndexWrapper->CompareIndexEntry( rTaR1.sText, rTaR1.sReading, rLocale1,
112  rTaR2.sText, rTaR2.sReading, rLocale2 );
113 }
114 
116  const lang::Locale& rLocale ) const
117 {
118  return m_pIndexWrapper->GetIndexKey( rTaR.sText, rTaR.sReading, rLocale );
119 }
120 
121 OUString SwTOXInternational::GetFollowingText( bool bMorePages ) const
122 {
123  return m_pIndexWrapper->GetFollowingText( bMorePages );
124 }
125 
126 // SortElement for TOX entries
128  const SwTextTOXMark* pMark,
129  const SwTOXInternational* pInter,
130  const lang::Locale* pLocale )
131  : pTOXNd( nullptr ), pTextMark( pMark ), pTOXIntl( pInter ),
132  nPos( 0 ), nCntPos( 0 ), nType( static_cast<sal_uInt16>(nTyp) )
133  , m_bValidText( false )
134 {
135  if ( pLocale )
136  aLocale = *pLocale;
137 
138  if( !pNd )
139  return;
140 
141  sal_Int32 n = 0;
142  if( pTextMark )
143  n = pTextMark->GetStart();
144  SwTOXSource aTmp( pNd, n, pTextMark && pTextMark->GetTOXMark().IsMainEntry() );
145  aTOXSources.push_back(aTmp);
146 
147  nPos = pNd->GetIndex();
148 
149  switch( nTyp )
150  {
151  case TOX_SORT_CONTENT:
152  case TOX_SORT_PARA:
153  case TOX_SORT_TABLE:
154  // If they are in a special areas, we should get the position at the
155  // body
156  if( nPos < pNd->GetNodes().GetEndOfExtras().GetIndex() )
157  {
158  // Then get the 'anchor' (body) position
159  Point aPt;
160  std::pair<Point, bool> tmp(aPt, false);
161  const SwContentFrame *const pFrame = pNd->getLayoutFrame(
163  nullptr, &tmp);
164  if( pFrame )
165  {
166  SwPosition aPos( *pNd );
167  const SwDoc& rDoc = pNd->GetDoc();
168  bool const bResult = GetBodyTextNode( rDoc, aPos, *pFrame );
169  OSL_ENSURE(bResult, "where is the text node");
170  nPos = aPos.nNode.GetIndex();
171  nCntPos = aPos.nContent.GetIndex();
172  }
173  }
174  else
175  nCntPos = n;
176  break;
177  default: break;
178  }
179 }
180 
181 OUString SwTOXSortTabBase::GetURL() const
182 {
183  return OUString();
184 }
185 
187 {
188  return false;
189 }
190 
191 void SwTOXSortTabBase::FillText( SwTextNode& rNd, const SwIndex& rInsPos,
192  sal_uInt16, SwRootFrame const*const) const
193 {
194  rNd.InsertText( GetText().sText, rInsPos );
195 }
196 
198 {
199  bool bRet = nPos == rCmp.nPos && nCntPos == rCmp.nCntPos &&
200  (!aTOXSources[0].pNd || !rCmp.aTOXSources[0].pNd ||
201  aTOXSources[0].pNd == rCmp.aTOXSources[0].pNd );
202 
203  if( TOX_SORT_CONTENT == nType )
204  {
205  bRet = bRet && pTextMark && rCmp.pTextMark &&
206  pTextMark->GetStart() == rCmp.pTextMark->GetStart();
207 
208  if( bRet )
209  {
210  // Both pointers exist -> compare text
211  // else -> compare AlternativeText
212  const sal_Int32 *pEnd = pTextMark->End();
213  const sal_Int32 *pEndCmp = rCmp.pTextMark->End();
214 
215  bRet = ( ( pEnd && pEndCmp ) || ( !pEnd && !pEndCmp ) ) &&
217  rCmp.GetText(), rCmp.GetLocale() );
218  }
219  }
220  return bRet;
221 }
222 
224 {
225  if( nPos < rCmp.nPos )
226  return true;
227 
228  if( nPos == rCmp.nPos )
229  {
230  if( nCntPos < rCmp.nCntPos )
231  return true;
232 
233  if( nCntPos == rCmp.nCntPos )
234  {
235  const SwNode* pFirst = aTOXSources[0].pNd;
236  const SwNode* pNext = rCmp.aTOXSources[0].pNd;
237 
238  if( pFirst && pFirst == pNext )
239  {
240  if( TOX_SORT_CONTENT == nType && pTextMark && rCmp.pTextMark )
241  {
242  if( pTextMark->GetStart() < rCmp.pTextMark->GetStart() )
243  return true;
244 
245  if( pTextMark->GetStart() == rCmp.pTextMark->GetStart() )
246  {
247  const sal_Int32 *pEnd = pTextMark->End();
248  const sal_Int32 *pEndCmp = rCmp.pTextMark->End();
249 
250  // Both pointers exist -> compare text
251  // else -> compare AlternativeText
252  if( ( pEnd && pEndCmp ) || ( !pEnd && !pEndCmp ) )
253  {
254  return pTOXIntl->IsLess( GetText(), GetLocale(),
255  rCmp.GetText(), rCmp.GetLocale() );
256  }
257  if( pEnd && !pEndCmp )
258  return true;
259  }
260  }
261  }
262  else if( pFirst && pFirst->IsTextNode() &&
263  pNext && pNext->IsTextNode() )
264  return ::IsFrameBehind( *static_cast<const SwTextNode*>(pNext), nCntPos,
265  *static_cast<const SwTextNode*>(pFirst), nCntPos );
266  }
267  }
268  return false;
269 }
270 
271 // Sorted keyword entry
273  const SwTextTOXMark* pMark, SwTOIOptions nOptions,
274  sal_uInt8 nKyLevel,
275  const SwTOXInternational& rIntl,
276  const lang::Locale& rLocale )
277  : SwTOXSortTabBase( TOX_SORT_INDEX, &rNd, pMark, &rIntl, &rLocale ),
278  nKeyLevel(nKyLevel)
279 {
280  nPos = rNd.GetIndex();
281  nOpt = nOptions;
282 }
283 
284 // Compare keywords. Only relates to the text.
285 
287 {
288  const SwTOXIndex& rCmp = static_cast<const SwTOXIndex&>(rCmpBase);
289 
290  // Respect case taking dependencies into account
291  if(GetLevel() != rCmp.GetLevel() || nKeyLevel != rCmp.nKeyLevel)
292  return false;
293 
294  OSL_ENSURE(pTextMark, "pTextMark == 0, No keyword");
295 
296  bool bRet = pTOXIntl->IsEqual( GetText(), GetLocale(),
297  rCmp.GetText(), rCmp.GetLocale() );
298 
299  // If we don't summarize we need to evaluate the Pos
300  if(bRet && !(GetOptions() & SwTOIOptions::SameEntry))
301  bRet = nPos == rCmp.nPos;
302 
303  return bRet;
304 }
305 
306 // operator, only depends on the text
307 
309 {
310  OSL_ENSURE(pTextMark, "pTextMark == 0, No keyword");
311 
312  const TextAndReading aMyTaR(GetText());
313  const TextAndReading aOtherTaR(rCmpBase.GetText());
314 
315  bool bRet = GetLevel() == rCmpBase.GetLevel() &&
316  pTOXIntl->IsLess( aMyTaR, GetLocale(),
317  aOtherTaR, rCmpBase.GetLocale() );
318 
319  // If we don't summarize we need to evaluate the Pos
320  if( !bRet && !(GetOptions() & SwTOIOptions::SameEntry) )
321  {
322  bRet = pTOXIntl->IsEqual( aMyTaR, GetLocale(),
323  aOtherTaR, rCmpBase.GetLocale() ) &&
324  nPos < rCmpBase.nPos;
325  }
326 
327  return bRet;
328 }
329 
330 // The keyword itself
331 
333 {
334  OSL_ENSURE(pTextMark, "pTextMark == 0, No keyword");
335  const SwTOXMark& rTOXMark = pTextMark->GetTOXMark();
336 
337  TextAndReading aRet;
338  switch(nKeyLevel)
339  {
340  case FORM_PRIMARY_KEY :
341  {
342  aRet.sText = rTOXMark.GetPrimaryKey();
343  aRet.sReading = rTOXMark.GetPrimaryKeyReading();
344  }
345  break;
346  case FORM_SECONDARY_KEY :
347  {
348  aRet.sText = rTOXMark.GetSecondaryKey();
349  aRet.sReading = rTOXMark.GetSecondaryKeyReading();
350  }
351  break;
352  case FORM_ENTRY :
353  {
354  aRet.sText = rTOXMark.GetText(pLayout);
355  aRet.sReading = rTOXMark.GetTextReading();
356  }
357  break;
358  }
359  // if SwTOIOptions::InitialCaps is set, first character is to be capitalized
360  if( SwTOIOptions::InitialCaps & nOpt && pTOXIntl && !aRet.sText.isEmpty())
361  {
362  aRet.sText = pTOXIntl->ToUpper( aRet.sText, 0 ) + aRet.sText.copy(1);
363  }
364 
365  return aRet;
366 }
367 
368 void SwTOXIndex::FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16,
369  SwRootFrame const*const pLayout) const
370 {
371  assert(!"sw_redlinehide: this is dead code, Bibliography only has SwTOXAuthority");
372  const sal_Int32* pEnd = pTextMark->End();
373 
374  TextAndReading aRet;
375  if( pEnd && !pTextMark->GetTOXMark().IsAlternativeText() &&
377  {
378  aRet.sText = static_cast<const SwTextNode*>(aTOXSources[0].pNd)->GetExpandText(
379  pLayout,
380  pTextMark->GetStart(),
381  *pEnd - pTextMark->GetStart(),
382  false, false, false,
384  | (pLayout && pLayout->IsHideRedlines()
386  : ExpandMode(0)));
387  if(SwTOIOptions::InitialCaps & nOpt && pTOXIntl && !aRet.sText.isEmpty())
388  {
389  aRet.sText = pTOXIntl->ToUpper( aRet.sText, 0 ) + aRet.sText.copy(1);
390  }
391  }
392  else
393  aRet = GetText();
394 
395  rNd.InsertText( aRet.sText, rInsPos );
396 }
397 
398 sal_uInt16 SwTOXIndex::GetLevel() const
399 {
400  OSL_ENSURE(pTextMark, "pTextMark == 0, No keyword");
401 
402  sal_uInt16 nForm = FORM_PRIMARY_KEY;
403 
405  !pTextMark->GetTOXMark().GetPrimaryKey().isEmpty() )
406  {
407  nForm = FORM_SECONDARY_KEY;
408  if( !pTextMark->GetTOXMark().GetSecondaryKey().isEmpty() )
409  nForm = FORM_ENTRY;
410  }
411  return nForm;
412 }
413 
414 // Key and separator
416  sal_uInt16 nLevel,
417  const SwTOXInternational& rIntl,
418  const lang::Locale& rLocale )
419  : SwTOXSortTabBase( TOX_SORT_CUSTOM, nullptr, nullptr, &rIntl, &rLocale ),
420  m_aKey(rKey), nLev(nLevel)
421 {
422 }
423 
425 {
426  return GetLevel() == rCmpBase.GetLevel() &&
428  rCmpBase.GetText(), rCmpBase.GetLocale() );
429 }
430 
432 {
433  return GetLevel() <= rCmpBase.GetLevel() &&
435  rCmpBase.GetText(), rCmpBase.GetLocale() );
436 }
437 
438 sal_uInt16 SwTOXCustom::GetLevel() const
439 {
440  return nLev;
441 }
442 
444 {
445  return m_aKey;
446 }
447 
448 // Sorts the TOX entries
450  const SwTOXInternational& rIntl)
451  : SwTOXSortTabBase( TOX_SORT_CONTENT, &rNd, pMark, &rIntl )
452 {
453 }
454 
455 // The content's text
456 
458 {
459  const sal_Int32* pEnd = pTextMark->End();
460  if( pEnd && !pTextMark->GetTOXMark().IsAlternativeText() )
461  {
462  return TextAndReading(
463  static_cast<const SwTextNode*>(aTOXSources[0].pNd)->GetExpandText(
464  pLayout,
465  pTextMark->GetStart(),
466  *pEnd - pTextMark->GetStart(),
467  false, false, false,
469  | (pLayout && pLayout->IsHideRedlines()
471  : ExpandMode(0))),
473  }
474 
475  return TextAndReading(pTextMark->GetTOXMark().GetAlternativeText(), OUString());
476 }
477 
478 void SwTOXContent::FillText(SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16,
479  SwRootFrame const*const pLayout) const
480 {
481  assert(!"sw_redlinehide: this is dead code, Bibliography only has SwTOXAuthority");
482  const sal_Int32* pEnd = pTextMark->End();
483  if( pEnd && !pTextMark->GetTOXMark().IsAlternativeText() )
484  // sw_redlinehide: this probably won't HideDeletions
485  static_cast<const SwTextNode*>(aTOXSources[0].pNd)->CopyExpandText(
486  rNd, &rInsPos, pTextMark->GetStart(),
487  *pEnd - pTextMark->GetStart(), pLayout);
488  else
489  {
490  rNd.InsertText( GetText().sText, rInsPos );
491  }
492 }
493 
494 // The level for displaying it
495 
496 sal_uInt16 SwTOXContent::GetLevel() const
497 {
498  return pTextMark->GetTOXMark().GetLevel();
499 }
500 
501 // TOX assembled from paragraphs
502 // Watch out for OLE/graphics when sorting!
503 // The position must not come from the document, but from the "anchor"!
504 SwTOXPara::SwTOXPara(SwContentNode& rNd, SwTOXElement eT, sal_uInt16 nLevel, const OUString& sSeqName)
505  : SwTOXSortTabBase( TOX_SORT_PARA, &rNd, nullptr, nullptr ),
506  eType( eT ),
507  m_nLevel(nLevel),
508  nStartIndex(0),
509  nEndIndex(-1),
510  m_sSequenceName( sSeqName )
511 {
512  // tdf#123313 create any missing bookmarks *before* generating ToX nodes!
513  switch (eType)
514  {
517  assert(rNd.IsTextNode());
520  break;
521  default:
522  break;
523  }
524 }
525 
527 {
528  const SwContentNode* pNd = aTOXSources[0].pNd;
529  switch( eType )
530  {
532  if (nStartIndex != 0 || nEndIndex != -1)
533  {
534  // sw_redlinehide: "captions" are a rather fuzzily defined concept anyway
535  return TextAndReading(static_cast<const SwTextNode*>(pNd)->GetExpandText(
536  pLayout,
537  nStartIndex,
538  nEndIndex == -1 ? -1 : nEndIndex - nStartIndex,
539  false, false, false,
540  pLayout && pLayout->IsHideRedlines()
542  : ExpandMode(0)),
543  OUString());
544  }
545  BOOST_FALLTHROUGH;
548  {
549  assert(nStartIndex == 0);
550  assert(nEndIndex == -1);
552  pLayout, *static_cast<const SwTextNode*>(pNd),
553  false, false, ExpandMode(0)),
554  OUString());
555  }
556  break;
557 
558  case SwTOXElement::Ole:
560  case SwTOXElement::Frame:
561  {
562  // Find the FlyFormat; the object/graphic name is there
563  SwFrameFormat* pFly = pNd->GetFlyFormat();
564  if( pFly )
565  return TextAndReading(pFly->GetName(), OUString());
566 
567  OSL_ENSURE( false, "Graphic/object without name" );
568  const char* pId = SwTOXElement::Ole == eType
569  ? STR_OBJECT_DEFNAME
571  ? STR_GRAPHIC_DEFNAME
572  : STR_FRAME_DEFNAME;
573  return TextAndReading(SwResId(pId), OUString());
574  }
575  break;
576  default: break;
577  }
578  return TextAndReading();
579 }
580 
581 void SwTOXPara::FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16,
582  SwRootFrame const*const pLayout) const
583 {
584  assert(!"sw_redlinehide: this is dead code, Bibliography only has SwTOXAuthority");
586  {
587  const SwTextNode* pSrc = static_cast<const SwTextNode*>(aTOXSources[0].pNd);
589  && (nStartIndex != 0 || nEndIndex != -1))
590  {
591  pSrc->CopyExpandText( rNd, &rInsPos, nStartIndex,
592  nEndIndex == -1 ? -1 : nEndIndex - nStartIndex,
593  pLayout, false, false, true );
594  }
595  else
596  {
597  assert(nStartIndex == 0);
598  assert(nEndIndex == -1);
599  // sw_redlinehide: this probably won't HideDeletions
600  pSrc->CopyExpandText( rNd, &rInsPos, 0, -1,
601  pLayout, false, false, true );
602  if (pLayout && pLayout->IsHideRedlines())
603  {
604  if (SwTextFrame const*const pFrame = static_cast<SwTextFrame*>(pSrc->getLayoutFrame(pLayout)))
605  {
606  if (sw::MergedPara const*const pMerged = pFrame->GetMergedPara())
607  {
608  // pSrc already copied above
609  assert(pSrc == pMerged->pParaPropsNode);
610  for (sal_uLong i = pSrc->GetIndex() + 1;
611  i <= pMerged->pLastNode->GetIndex(); ++i)
612  {
613  SwNode *const pTmp(pSrc->GetNodes()[i]);
614  if (pTmp->GetRedlineMergeFlag() == SwNode::Merge::NonFirst)
615  {
616 
617  pTmp->GetTextNode()->CopyExpandText(
618  rNd, &rInsPos, 0, -1,
619  pLayout, false, false, false );
620  }
621  }
622  }
623  }
624  }
625  }
626  }
627  else
628  {
629  rNd.InsertText( GetText().sText.replace('\t', ' '), rInsPos );
630  }
631 }
632 
633 sal_uInt16 SwTOXPara::GetLevel() const
634 {
635  sal_uInt16 nRet = m_nLevel;
636  const SwContentNode* pNd = aTOXSources[0].pNd;
637 
638  if( SwTOXElement::OutlineLevel == eType && pNd->GetTextNode() )
639  {
640  const int nTmp = static_cast<const SwTextNode*>(pNd)->GetAttrOutlineLevel();
641  if(nTmp != 0 )
642  nRet = static_cast<sal_uInt16>(nTmp);
643  }
644  return nRet;
645 }
646 
647 OUString SwTOXPara::GetURL() const
648 {
649  OUString aText;
650  const SwContentNode* pNd = aTOXSources[0].pNd;
651  switch( eType )
652  {
655  {
656  const SwTextNode * pTextNd = pNd->GetTextNode();
657 
658  SwDoc& rDoc = const_cast<SwDoc&>( pTextNd->GetDoc() );
659  // tdf#123313: this *must not* create a bookmark, its Undo would
660  // be screwed! create it as preparatory step, in ctor!
661  ::sw::mark::IMark const * const pMark = rDoc.getIDocumentMarkAccess()->getMarkForTextNode(
662  *pTextNd,
664  aText = "#" + pMark->GetName();
665  }
666  break;
667 
668  case SwTOXElement::Ole:
670  case SwTOXElement::Frame:
671  {
672  // Find the FlyFormat; the object/graphic name is there
673  SwFrameFormat* pFly = pNd->GetFlyFormat();
674  if( pFly )
675  {
676  aText = "#" + pFly->GetName() + OUStringChar(cMarkSeparator);
677  const char* pStr;
678  switch( eType )
679  {
680  case SwTOXElement::Ole: pStr = "ole"; break;
681  case SwTOXElement::Graphic: pStr = "graphic"; break;
682  case SwTOXElement::Frame: pStr = "frame"; break;
683  default: pStr = nullptr;
684  }
685  if( pStr )
686  aText += OUString::createFromAscii( pStr );
687  }
688  }
689  break;
691  {
692  aText = "#" + m_sSequenceName + OUStringChar(cMarkSeparator)
693  + "sequence";
694  }
695  break;
696  default: break;
697  }
698  return aText;
699 }
700 
702 {
703  switch (eType)
704  {
708  return nStartIndex == 0 && nEndIndex == -1;
709  default:
710  return false;
711  }
712 }
713 
714 // Table
716  : SwTOXSortTabBase( TOX_SORT_TABLE, &rNd, nullptr, nullptr ),
717  nLevel(FORM_ALPHA_DELIMITER)
718 {
719 }
720 
722 {
723  const SwNode* pNd = aTOXSources[0].pNd;
724  if( pNd )
725  {
726  const SwTableNode* pTableNd =
727  reinterpret_cast<const SwTableNode*>(pNd->FindTableNode());
728  if (pTableNd)
729  {
730  return TextAndReading(pTableNd->GetTable().GetFrameFormat()->GetName(), OUString());
731  }
732  }
733 
734  OSL_ENSURE( false, "Where's my table?" );
735  return TextAndReading(SwResId( STR_TABLE_DEFNAME ), OUString());
736 }
737 
738 sal_uInt16 SwTOXTable::GetLevel() const
739 {
740  return nLevel;
741 }
742 
743 OUString SwTOXTable::GetURL() const
744 {
745  const SwNode* pNd = aTOXSources[0].pNd;
746  if (!pNd)
747  return OUString();
748 
749  pNd = pNd->FindTableNode();
750  if (!pNd)
751  return OUString();
752 
753  const OUString sName = static_cast<const SwTableNode*>(pNd)->GetTable().GetFrameFormat()->GetName();
754  if ( sName.isEmpty() )
755  return OUString();
756 
757  return "#" + sName + OUStringChar(cMarkSeparator) + "table";
758 }
759 
761  SwFormatField& rField, const SwTOXInternational& rIntl ) :
762  SwTOXSortTabBase( TOX_SORT_AUTHORITY, &rNd, nullptr, &rIntl ),
763  m_rField(rField)
764 {
765  if(rField.GetTextField())
766  nCntPos = rField.GetTextField()->GetStart();
767 }
768 
769 sal_uInt16 SwTOXAuthority::GetLevel() const
770 {
771  OUString sText(static_cast<SwAuthorityField*>(m_rField.GetField())->GetFieldText(AUTH_FIELD_AUTHORITY_TYPE));
772  //#i18655# the level '0' is the heading level therefore the values are incremented here
773  sal_uInt16 nRet = 1;
774  if( pTOXIntl->IsNumeric( sText ) )
775  {
776  nRet = sText.toUInt32();
777  nRet++;
778  }
779  //illegal values are also set to 'ARTICLE' as non-numeric values are
780  if(nRet > AUTH_TYPE_END)
781  nRet = 1;
782  return nRet;
783 }
784 
785 static OUString lcl_GetText(SwFormatField const& rField, SwRootFrame const*const pLayout)
786 {
787  return rField.GetField()->ExpandField(true, pLayout);
788 }
789 
791 {
792  return TextAndReading(lcl_GetText(m_rField, pLayout), OUString());
793 }
794 
796  const SwIndex& rInsPos, sal_uInt16 nAuthField,
797  SwRootFrame const*const pLayout) const
798 {
799  SwAuthorityField* pField = static_cast<SwAuthorityField*>(m_rField.GetField());
800  OUString sText;
801  if(AUTH_FIELD_IDENTIFIER == nAuthField)
802  {
803  sText = lcl_GetText(m_rField, pLayout);
804  const SwAuthorityFieldType* pType = static_cast<const SwAuthorityFieldType*>(pField->GetTyp());
805  sal_Unicode cChar = pType->GetPrefix();
806  if(cChar && cChar != ' ')
807  sText = sText.copy(1);
808  cChar = pType->GetSuffix();
809  if(cChar && cChar != ' ')
810  sText = sText.copy(0, sText.getLength() - 1);
811  }
812  else if(AUTH_FIELD_AUTHORITY_TYPE == nAuthField)
813  {
814  sal_uInt16 nLevel = GetLevel();
815  if(nLevel)
816  sText = SwAuthorityFieldType::GetAuthTypeName(static_cast<ToxAuthorityType>(--nLevel));
817  }
818  else
819  sText = pField->GetFieldText(static_cast<ToxAuthorityField>(nAuthField));
820  rNd.InsertText( sText, rInsPos );
821 }
822 
824 {
825  return nType == rCmp.nType &&
826  static_cast<SwAuthorityField*>(m_rField.GetField())->GetAuthEntry() ==
827  static_cast<SwAuthorityField*>(static_cast<const SwTOXAuthority&>(rCmp).m_rField.GetField())->GetAuthEntry();
828 }
829 
831 {
832  bool bRet = false;
833  SwAuthorityField* pField = static_cast<SwAuthorityField*>(m_rField.GetField());
834  SwAuthorityFieldType* pType = static_cast<SwAuthorityFieldType*>(
835  pField->GetTyp());
836  if(pType->IsSortByDocument())
837  bRet = SwTOXSortTabBase::sort_lt(rBase);
838  else
839  {
840  SwAuthorityField* pCmpField =
841  static_cast<SwAuthorityField*>(static_cast<const SwTOXAuthority&>(rBase).m_rField.GetField());
842 
843  for(sal_uInt16 i = 0; i < pType->GetSortKeyCount(); i++)
844  {
845  const SwTOXSortKey* pKey = pType->GetSortKey(i);
846  const TextAndReading aMy(pField->GetFieldText(pKey->eField), OUString());
847  const TextAndReading aOther(pCmpField->GetFieldText(pKey->eField), OUString());
848 
849  sal_Int32 nComp = pTOXIntl->Compare( aMy, GetLocale(),
850  aOther, rBase.GetLocale() );
851 
852  if( nComp )
853  {
854  bRet = (-1 == nComp) == pKey->bSortAscending;
855  break;
856  }
857  }
858  }
859  return bRet;
860 }
861 
862 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_uInt16 GetLevel() const override
Definition: txmsrt.cxx:438
static SwTOIOptions nOpt
Definition: txmsrt.hxx:133
sal_uInt16 m_nLevel
Definition: txmsrt.hxx:260
const css::lang::Locale & GetLocale() const
Definition: txmsrt.hxx:182
OUString GetIndexKey(const TextAndReading &rTaR, const css::lang::Locale &rLcl) const
Definition: txmsrt.cxx:115
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:151
SwTOXElement eType
Definition: txmsrt.hxx:259
virtual sal_uInt16 GetLevel() const override
Definition: txmsrt.cxx:398
sal_uLong GetIndex() const
Definition: node.hxx:290
virtual TextAndReading GetText_Impl(SwRootFrame const *pLayout) const override
Definition: txmsrt.cxx:457
bool IsAlternativeText() const
Definition: tox.hxx:581
OUString const & GetSecondaryKeyReading() const
Definition: tox.hxx:664
SwTOIOptions
Definition: tox.hxx:387
OUString sReading
Definition: txmsrt.hxx:61
virtual const OUString & GetName() const =0
Marks a position in the document model.
Definition: pam.hxx:35
virtual OUString GetURL() const
Definition: txmsrt.cxx:181
const SwField * GetField() const
Definition: fmtfld.hxx:111
virtual const SwRootFrame * GetCurrentLayout() const =0
OUString const & GetPrimaryKey() const
Definition: tox.hxx:640
virtual OUString GetURL() const override
Definition: txmsrt.cxx:743
SwNodeIndex nNode
Definition: pam.hxx:37
const SwTextNode * GetBodyTextNode(const SwDoc &rDoc, SwPosition &rPos, const SwFrame &rFrame)
Forward declaration: get "BodyTextNode" for exp.fld in Fly's headers/footers/footnotes.
Definition: expfld.cxx:163
sal_uIntPtr sal_uLong
virtual sal_uInt16 GetLevel() const =0
std::unique_ptr< IndexEntrySupplierWrapper > m_pIndexWrapper
Definition: txmsrt.hxx:73
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1192
sal_Int64 n
Definition: doc.hxx:184
sal_Int32 nStartIndex
Definition: txmsrt.hxx:261
virtual bool sort_lt(const SwTOXSortTabBase &) override
Definition: txmsrt.cxx:308
SwTOXIndex(const SwTextNode &, const SwTextTOXMark *, SwTOIOptions nOptions, sal_uInt8 nKeyLevel, const SwTOXInternational &rIntl, const css::lang::Locale &rLocale)
Definition: txmsrt.cxx:272
LanguageType m_eLang
Definition: txmsrt.hxx:75
IDocumentMarkAccess * getIDocumentMarkAccess()
Definition: docbm.cxx:1682
virtual bool equivalent(const SwTOXSortTabBase &) override
Definition: txmsrt.cxx:286
virtual void FillText(SwTextNode &rNd, const SwIndex &rInsPos, sal_uInt16 nAuthField, SwRootFrame const *pLayout) const override
Definition: txmsrt.cxx:795
#define FORM_SECONDARY_KEY
Definition: tox.hxx:209
virtual TextAndReading GetText_Impl(SwRootFrame const *pLayout) const override
Definition: txmsrt.cxx:443
The root element of a Writer document layout.
Definition: rootfrm.hxx:80
OUString GetFollowingText(bool bMorePages) const
Definition: txmsrt.cxx:121
static OUString const & GetAuthTypeName(ToxAuthorityType eType)
Definition: initui.cxx:277
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:202
sal_uInt16 nLevel
Definition: txmsrt.hxx:278
virtual sal_uInt16 GetLevel() const override
Definition: txmsrt.cxx:496
static LanguageType nLang
Definition: srtdlg.cxx:51
SwTOXAuthority(const SwContentNode &rNd, SwFormatField &rField, const SwTOXInternational &rIntl)
Definition: txmsrt.cxx:760
virtual bool IsFullPara() const
Definition: txmsrt.cxx:186
sal_uInt16 sal_Unicode
OUString const & GetPrimaryKeyReading() const
Definition: tox.hxx:658
const SwTOXSortKey * GetSortKey(sal_uInt16 nIdx) const
Definition: authfld.cxx:426
virtual sal_uInt16 GetLevel() const override
Definition: txmsrt.cxx:738
sal_Unicode GetPrefix() const
Definition: authfld.hxx:114
const SwTOXMark & GetTOXMark() const
Definition: txatbase.hxx:212
sal_uInt8 nKeyLevel
Definition: txmsrt.hxx:205
invariant for SwAuthorityField is that it is always registered at its SwAuthorityFieldType via AddFie...
Definition: authfld.hxx:148
SwIndex nContent
Definition: pam.hxx:38
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
const SwTextField * GetTextField() const
Definition: fmtfld.hxx:129
sal_Int32 nEndIndex
Definition: txmsrt.hxx:262
virtual void FillText(SwTextNode &rNd, const SwIndex &rInsPos, sal_uInt16 nAuthField, SwRootFrame const *pLayout) const override
Definition: txmsrt.cxx:478
TOXSortType
Definition: txmsrt.hxx:36
virtual bool equivalent(const SwTOXSortTabBase &)
Definition: txmsrt.cxx:197
bool IsNumeric(const OUString &rStr) const
Definition: txmsrt.cxx:101
const OUString & GetName() const
Definition: format.hxx:111
bool IsEqual(const TextAndReading &rTaR1, const css::lang::Locale &rLocale1, const TextAndReading &rTaR2, const css::lang::Locale &rLocale2) const
Definition: txmsrt.hxx:92
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
virtual bool equivalent(const SwTOXSortTabBase &) override
Definition: txmsrt.cxx:424
virtual bool equivalent(const SwTOXSortTabBase &) override
Definition: txmsrt.cxx:823
sal_Int32 GetStart() const
Definition: txatbase.hxx:82
const SwTable & GetTable() const
Definition: node.hxx:505
Describes parts of multiple text nodes, which will form a text frame, even when redlines are hidden a...
Definition: txtfrm.hxx:947
virtual TextAndReading GetText_Impl(SwRootFrame const *pLayout) const override
Definition: txmsrt.cxx:790
OUString ToUpper(const OUString &rStr, sal_Int32 nPos) const
Definition: txmsrt.cxx:96
const char * sName
For sorting by text.
Definition: txmsrt.hxx:190
virtual TextAndReading GetText_Impl(SwRootFrame const *pLayout) const override
Definition: txmsrt.cxx:526
DocumentType eType
sal_Int32 m_nLevel
virtual OUString GetURL() const override
Definition: txmsrt.cxx:647
const OUString & GetAlternativeText() const
Definition: tox.hxx:569
sal_Int32 nCntPos
Definition: txmsrt.hxx:131
OUString m_sSortAlgorithm
Definition: txmsrt.hxx:76
Style of a layout element.
Definition: frmfmt.hxx:57
OUString GetExpandTextMerged(SwRootFrame const *const pLayout, SwTextNode const &rNode, bool const bWithNumber, bool const bWithSpacesForLevel, ExpandMode const i_mode)
SwTOXInternational(LanguageType nLang, SwTOIOptions nOptions, const OUString &rSortAlgorithm)
Definition: txmsrt.cxx:50
int i
SwTOXElement
Definition: tox.hxx:365
SwDoc & GetDoc()
Definition: node.hxx:211
sal_uInt16 GetLevel() const
Definition: tox.hxx:634
virtual TextAndReading GetText_Impl(SwRootFrame const *pLayout) const override
Definition: txmsrt.cxx:721
sal_Unicode GetSuffix() const
Definition: authfld.hxx:115
OUString GetText(SwRootFrame const *pLayout) const
Definition: tox.cxx:193
Marks a character position inside a document model node.
Definition: index.hxx:33
SwTOXTable(const SwContentNode &rNd)
Definition: txmsrt.cxx:715
const SwTOXInternational * pTOXIntl
Definition: txmsrt.hxx:129
virtual void FillText(SwTextNode &rNd, const SwIndex &rInsPos, sal_uInt16 nAuthField, SwRootFrame const *pLayout) const override
Definition: txmsrt.cxx:581
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:701
OUString SwResId(const char *pId)
Definition: swmodule.cxx:165
const SwTextTOXMark * pTextMark
Definition: txmsrt.hxx:128
sal_uInt16 nLev
Definition: txmsrt.hxx:222
const sal_Unicode cMarkSeparator
Definition: swtypes.hxx:129
OUString const & GetTextReading() const
Definition: tox.hxx:652
bool bSortAscending
Definition: authfld.hxx:49
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:405
virtual bool sort_lt(const SwTOXSortTabBase &) override
Definition: txmsrt.cxx:431
virtual TextAndReading GetText_Impl(SwRootFrame const *pLayout) const override
Definition: txmsrt.cxx:332
SwFieldType * GetTyp() const
Definition: fldbas.hxx:396
sal_uLong nPos
Definition: txmsrt.hxx:130
virtual sal_uInt16 GetLevel() const override
Definition: txmsrt.cxx:769
OUString InsertText(const OUString &rStr, const SwIndex &rIdx, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
insert text content
Definition: ndtxt.cxx:2249
SwTOIOptions m_nOptions
Definition: txmsrt.hxx:77
SwTOXPara(SwContentNode &, SwTOXElement, sal_uInt16 nLevel=FORM_ALPHA_DELIMITER, const OUString &sSeqName=OUString())
Definition: txmsrt.cxx:504
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
ExpandMode
Some helpers for converting model strings to view strings.
OUString sText
Definition: txmsrt.hxx:60
OUString ExpandField(bool bCached, SwRootFrame const *pLayout) const
expand the field.
Definition: fldbas.cxx:443
SwTOXCustom(const TextAndReading &rKey, sal_uInt16 nLevel, const SwTOXInternational &rIntl, const css::lang::Locale &rLocale)
Definition: txmsrt.cxx:415
TextAndReading m_aKey
Definition: txmsrt.hxx:221
ToxAuthorityField eField
Definition: authfld.hxx:48
OUString const & GetSecondaryKey() const
Definition: tox.hxx:646
virtual ::sw::mark::IMark * getMarkForTextNode(const SwTextNode &rTextNode, MarkType eMark)=0
Returns a mark in the document for a paragraph.
bool IsLess(const TextAndReading &rTaR1, const css::lang::Locale &rLocale1, const TextAndReading &rTaR2, const css::lang::Locale &rLocale2) const
Definition: txmsrt.hxx:100
unsigned char sal_uInt8
css::lang::Locale aLocale
Definition: txmsrt.hxx:126
sal_Int32 GetIndex() const
Definition: index.hxx:91
const sal_Int32 * End() const
Definition: txatbase.hxx:148
#define FORM_ALPHA_DELIMITER
Definition: tox.hxx:207
QPRO_FUNC_TYPE nType
Sequence< sal_Int8 > aSeq
#define FORM_ENTRY
Definition: tox.hxx:210
virtual bool IsFullPara() const override
Definition: txmsrt.cxx:701
bool IsHideRedlines() const
Replacement for sw::DocumentRedlineManager::GetRedlineFlags() (this is layout-level redline hiding)...
Definition: rootfrm.hxx:417
OUString m_sSequenceName
Definition: txmsrt.hxx:263
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:352
bool CopyExpandText(SwTextNode &rDestNd, const SwIndex *pDestIdx, sal_Int32 nIdx, sal_Int32 nLen, SwRootFrame const *pLayout, bool bWithNum=false, bool bWithFootnote=true, bool bReplaceTabsWithSpaces=false) const
Definition: ndtxt.cxx:3401
virtual sal_uInt16 GetLevel() const override
Definition: txmsrt.cxx:633
bool IsMainEntry() const
Definition: tox.hxx:157
static SwTOIOptions GetOptions()
Definition: txmsrt.hxx:143
#define FORM_PRIMARY_KEY
Definition: tox.hxx:208
bool IsSortByDocument() const
Definition: authfld.hxx:117
bool IsFrameBehind(const SwTextNode &rMyNd, sal_Int32 nMySttPos, const SwTextNode &rBehindNd, sal_Int32 nSttPos)
Definition: reffld.cxx:99
SwFormatField & m_rField
Definition: txmsrt.hxx:284
virtual void FillText(SwTextNode &rNd, const SwIndex &rInsPos, sal_uInt16 nAuthField, SwRootFrame const *pLayout) const
Definition: txmsrt.cxx:191
sal_uInt16 nType
Definition: txmsrt.hxx:132
std::unique_ptr< CharClass > m_pCharClass
Definition: txmsrt.hxx:74
static OUString lcl_GetText(SwFormatField const &rField, SwRootFrame const *const pLayout)
Definition: txmsrt.cxx:785
TextAndReading const & GetText() const
Definition: txmsrt.hxx:176
virtual bool sort_lt(const SwTOXSortTabBase &)
Definition: txmsrt.cxx:223
bool IsTextNode() const
Definition: node.hxx:644
Class for sorting directories.
Definition: txmsrt.hxx:120
const OUString & GetFieldText(ToxAuthorityField eField) const
Definition: authfld.cxx:535
SwFrameFormat * GetFlyFormat() const
If node is in a fly return the respective format.
Definition: node.cxx:714
SwTOXContent(const SwTextNode &, const SwTextTOXMark *, const SwTOXInternational &rIntl)
Definition: txmsrt.cxx:449
std::vector< SwTOXSource > aTOXSources
Definition: txmsrt.hxx:125
sal_uInt16 GetSortKeyCount() const
Definition: authfld.cxx:421
sal_Int32 Compare(const TextAndReading &rTaR1, const css::lang::Locale &rLocale1, const TextAndReading &rTaR2, const css::lang::Locale &rLocale2) const
Definition: txmsrt.cxx:106
#define SW_COLLATOR_IGNORES
Definition: swtypes.hxx:185
virtual bool sort_lt(const SwTOXSortTabBase &) override
Definition: txmsrt.cxx:830
sal_uInt16 nPos
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:844
virtual void FillText(SwTextNode &rNd, const SwIndex &rInsPos, sal_uInt16 nAuthField, SwRootFrame const *pLayout) const override
Definition: txmsrt.cxx:368
static css::lang::Locale convertToLocale(LanguageType nLangID, bool bResolveSystem=true)
SwTOXSortTabBase(TOXSortType nType, const SwContentNode *pTOXSrc, const SwTextTOXMark *pTextMark, const SwTOXInternational *pIntl, const css::lang::Locale *pLocale=nullptr)
Definition: txmsrt.cxx:127
Base class of the Writer document model elements.
Definition: node.hxx:79