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