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 <com/sun/star/uri/UriReferenceFactory.hpp>
21 
22 #include <unotools/charclass.hxx>
23 #include <osl/diagnose.h>
24 #include <tools/urlobj.hxx>
26 #include <txtfld.hxx>
27 #include <doc.hxx>
29 #include <IDocumentMarkAccess.hxx>
30 #include <cntfrm.hxx>
31 #include <txtfrm.hxx>
32 #include <rootfrm.hxx>
33 #include <modeltoviewhelper.hxx>
34 #include <node.hxx>
35 #include <pam.hxx>
36 #include <txttxmrk.hxx>
37 #include <frmfmt.hxx>
38 #include <fmtfld.hxx>
39 #include <txmsrt.hxx>
40 #include <ndtxt.hxx>
41 #include <swtable.hxx>
42 #include <expfld.hxx>
43 #include <authfld.hxx>
44 #include <toxwrap.hxx>
45 
46 #include <strings.hrc>
47 #include <reffld.hxx>
48 #include <docsh.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  return;
146 
147  sal_Int32 n = 0;
148  if( pTextMark )
149  n = pTextMark->GetStart();
150  SwTOXSource aTmp( pNd, n, pTextMark && pTextMark->GetTOXMark().IsMainEntry() );
151  aTOXSources.push_back(aTmp);
152 
153  nPos = pNd->GetIndex();
154 
155  switch( nTyp )
156  {
157  case TOX_SORT_CONTENT:
158  case TOX_SORT_PARA:
159  case TOX_SORT_TABLE:
160  // If they are in a special areas, we should get the position at the
161  // body
162  if( nPos < pNd->GetNodes().GetEndOfExtras().GetIndex() )
163  {
164  // Then get the 'anchor' (body) position
165  Point aPt;
166  std::pair<Point, bool> tmp(aPt, false);
167  const SwContentFrame *const pFrame = pNd->getLayoutFrame(
169  nullptr, &tmp);
170  if( pFrame )
171  {
172  SwPosition aPos( *pNd );
173  const SwDoc& rDoc = pNd->GetDoc();
174  bool const bResult = GetBodyTextNode( rDoc, aPos, *pFrame );
175  OSL_ENSURE(bResult, "where is the text node");
176  nPos = aPos.nNode.GetIndex();
177  nCntPos = aPos.nContent.GetIndex();
178  }
179  }
180  else
181  nCntPos = n;
182  break;
183  default: break;
184  }
185 }
186 
187 std::pair<OUString, bool> SwTOXSortTabBase::GetURL(SwRootFrame const*const pLayout) const
188 {
189  OUString typeName;
190  SwTOXType const& rType(*pTextMark->GetTOXMark().GetTOXType());
191  switch (rType.GetType())
192  {
193  case TOX_INDEX:
194  typeName = "A";
195  break;
196  case TOX_CONTENT:
197  typeName = "C";
198  break;
199  case TOX_USER:
200  typeName = "U" + rType.GetTypeName();
201  break;
202  default:
203  assert(false); // other tox can't have toxmarks as source
204  break;
205  }
206  OUString const decodedUrl( // counter will be added by caller!
207  OUStringChar(toxMarkSeparator) + pTextMark->GetTOXMark().GetText(pLayout)
208  + OUStringChar(toxMarkSeparator) + typeName
209  + OUStringChar(cMarkSeparator) + "toxmark" );
210 
211  return std::make_pair(decodedUrl, true);
212 }
213 
215 {
216  return false;
217 }
218 
219 void SwTOXSortTabBase::FillText( SwTextNode& rNd, const SwIndex& rInsPos,
220  sal_uInt16, SwRootFrame const*const) const
221 {
222  rNd.InsertText( GetText().sText, rInsPos );
223 }
224 
226 {
227  bool bRet = nPos == rCmp.nPos && nCntPos == rCmp.nCntPos &&
228  (!aTOXSources[0].pNd || !rCmp.aTOXSources[0].pNd ||
229  aTOXSources[0].pNd == rCmp.aTOXSources[0].pNd );
230 
231  if( TOX_SORT_CONTENT == nType )
232  {
233  bRet = bRet && pTextMark && rCmp.pTextMark &&
234  pTextMark->GetStart() == rCmp.pTextMark->GetStart();
235 
236  if( bRet )
237  {
238  // Both pointers exist -> compare text
239  // else -> compare AlternativeText
240  const sal_Int32 *pEnd = pTextMark->End();
241  const sal_Int32 *pEndCmp = rCmp.pTextMark->End();
242 
243  bRet = ( ( pEnd && pEndCmp ) || ( !pEnd && !pEndCmp ) ) &&
245  rCmp.GetText(), rCmp.GetLocale() );
246  }
247  }
248  return bRet;
249 }
250 
252 {
253  if( nPos < rCmp.nPos )
254  return true;
255 
256  if( nPos == rCmp.nPos )
257  {
258  if( nCntPos < rCmp.nCntPos )
259  return true;
260 
261  if( nCntPos == rCmp.nCntPos )
262  {
263  const SwNode* pFirst = aTOXSources[0].pNd;
264  const SwNode* pNext = rCmp.aTOXSources[0].pNd;
265 
266  if( pFirst && pFirst == pNext )
267  {
268  if( TOX_SORT_CONTENT == nType && pTextMark && rCmp.pTextMark )
269  {
270  if( pTextMark->GetStart() < rCmp.pTextMark->GetStart() )
271  return true;
272 
273  if( pTextMark->GetStart() == rCmp.pTextMark->GetStart() )
274  {
275  const sal_Int32 *pEnd = pTextMark->End();
276  const sal_Int32 *pEndCmp = rCmp.pTextMark->End();
277 
278  // Both pointers exist -> compare text
279  // else -> compare AlternativeText
280  if( ( pEnd && pEndCmp ) || ( !pEnd && !pEndCmp ) )
281  {
282  return pTOXIntl->IsLess( GetText(), GetLocale(),
283  rCmp.GetText(), rCmp.GetLocale() );
284  }
285  if( pEnd && !pEndCmp )
286  return true;
287  }
288  }
289  }
290  else if( pFirst && pFirst->IsTextNode() &&
291  pNext && pNext->IsTextNode() )
292  return ::IsFrameBehind( *static_cast<const SwTextNode*>(pNext), nCntPos,
293  *static_cast<const SwTextNode*>(pFirst), nCntPos );
294  }
295  }
296  return false;
297 }
298 
299 // Sorted keyword entry
301  const SwTextTOXMark* pMark, SwTOIOptions nOptions,
302  sal_uInt8 nKyLevel,
303  const SwTOXInternational& rIntl,
304  const lang::Locale& rLocale )
305  : SwTOXSortTabBase( TOX_SORT_INDEX, &rNd, pMark, &rIntl, &rLocale ),
306  nKeyLevel(nKyLevel)
307 {
308  nPos = rNd.GetIndex();
309  nOpt = nOptions;
310 }
311 
312 // Compare keywords. Only relates to the text.
313 
315 {
316  const SwTOXIndex& rCmp = static_cast<const SwTOXIndex&>(rCmpBase);
317 
318  // Respect case taking dependencies into account
319  if(GetLevel() != rCmp.GetLevel() || nKeyLevel != rCmp.nKeyLevel)
320  return false;
321 
322  OSL_ENSURE(pTextMark, "pTextMark == 0, No keyword");
323 
324  bool bRet = pTOXIntl->IsEqual( GetText(), GetLocale(),
325  rCmp.GetText(), rCmp.GetLocale() );
326 
327  // If we don't summarize we need to evaluate the Pos
328  if(bRet && !(GetOptions() & SwTOIOptions::SameEntry))
329  bRet = nPos == rCmp.nPos;
330 
331  return bRet;
332 }
333 
334 // operator, only depends on the text
335 
337 {
338  OSL_ENSURE(pTextMark, "pTextMark == 0, No keyword");
339 
340  const TextAndReading aMyTaR(GetText());
341  const TextAndReading aOtherTaR(rCmpBase.GetText());
342 
343  bool bRet = GetLevel() == rCmpBase.GetLevel() &&
344  pTOXIntl->IsLess( aMyTaR, GetLocale(),
345  aOtherTaR, rCmpBase.GetLocale() );
346 
347  // If we don't summarize we need to evaluate the Pos
348  if( !bRet && !(GetOptions() & SwTOIOptions::SameEntry) )
349  {
350  bRet = pTOXIntl->IsEqual( aMyTaR, GetLocale(),
351  aOtherTaR, rCmpBase.GetLocale() ) &&
352  nPos < rCmpBase.nPos;
353  }
354 
355  return bRet;
356 }
357 
358 // The keyword itself
359 
361 {
362  OSL_ENSURE(pTextMark, "pTextMark == 0, No keyword");
363  const SwTOXMark& rTOXMark = pTextMark->GetTOXMark();
364 
365  TextAndReading aRet;
366  switch(nKeyLevel)
367  {
368  case FORM_PRIMARY_KEY :
369  {
370  aRet.sText = rTOXMark.GetPrimaryKey();
371  aRet.sReading = rTOXMark.GetPrimaryKeyReading();
372  }
373  break;
374  case FORM_SECONDARY_KEY :
375  {
376  aRet.sText = rTOXMark.GetSecondaryKey();
377  aRet.sReading = rTOXMark.GetSecondaryKeyReading();
378  }
379  break;
380  case FORM_ENTRY :
381  {
382  aRet.sText = rTOXMark.GetText(pLayout);
383  aRet.sReading = rTOXMark.GetTextReading();
384  }
385  break;
386  }
387  // if SwTOIOptions::InitialCaps is set, first character is to be capitalized
388  if( SwTOIOptions::InitialCaps & nOpt && pTOXIntl && !aRet.sText.isEmpty())
389  {
390  aRet.sText = pTOXIntl->ToUpper( aRet.sText, 0 ) + aRet.sText.subView(1);
391  }
392 
393  return aRet;
394 }
395 
396 void SwTOXIndex::FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16,
397  SwRootFrame const*const pLayout) const
398 {
399  assert(!"sw_redlinehide: this is dead code, Bibliography only has SwTOXAuthority");
400  const sal_Int32* pEnd = pTextMark->End();
401 
402  TextAndReading aRet;
403  if( pEnd && !pTextMark->GetTOXMark().IsAlternativeText() &&
405  {
406  aRet.sText = static_cast<const SwTextNode*>(aTOXSources[0].pNd)->GetExpandText(
407  pLayout,
408  pTextMark->GetStart(),
409  *pEnd - pTextMark->GetStart(),
410  false, false, false,
412  | (pLayout && pLayout->IsHideRedlines()
414  : ExpandMode(0)));
415  if(SwTOIOptions::InitialCaps & nOpt && pTOXIntl && !aRet.sText.isEmpty())
416  {
417  aRet.sText = pTOXIntl->ToUpper( aRet.sText, 0 ) + aRet.sText.subView(1);
418  }
419  }
420  else
421  aRet = GetText();
422 
423  rNd.InsertText( aRet.sText, rInsPos );
424 }
425 
426 sal_uInt16 SwTOXIndex::GetLevel() const
427 {
428  OSL_ENSURE(pTextMark, "pTextMark == 0, No keyword");
429 
430  sal_uInt16 nForm = FORM_PRIMARY_KEY;
431 
433  !pTextMark->GetTOXMark().GetPrimaryKey().isEmpty() )
434  {
435  nForm = FORM_SECONDARY_KEY;
436  if( !pTextMark->GetTOXMark().GetSecondaryKey().isEmpty() )
437  nForm = FORM_ENTRY;
438  }
439  return nForm;
440 }
441 
442 // Key and separator
444  sal_uInt16 nLevel,
445  const SwTOXInternational& rIntl,
446  const lang::Locale& rLocale )
447  : SwTOXSortTabBase( TOX_SORT_CUSTOM, nullptr, nullptr, &rIntl, &rLocale ),
448  m_aKey(rKey), nLev(nLevel)
449 {
450 }
451 
453 {
454  return GetLevel() == rCmpBase.GetLevel() &&
456  rCmpBase.GetText(), rCmpBase.GetLocale() );
457 }
458 
460 {
461  return GetLevel() <= rCmpBase.GetLevel() &&
463  rCmpBase.GetText(), rCmpBase.GetLocale() );
464 }
465 
466 sal_uInt16 SwTOXCustom::GetLevel() const
467 {
468  return nLev;
469 }
470 
472 {
473  return m_aKey;
474 }
475 
476 // Sorts the TOX entries
478  const SwTOXInternational& rIntl)
479  : SwTOXSortTabBase( TOX_SORT_CONTENT, &rNd, pMark, &rIntl )
480 {
481 }
482 
483 // The content's text
484 
486 {
487  const sal_Int32* pEnd = pTextMark->End();
488  if( pEnd && !pTextMark->GetTOXMark().IsAlternativeText() )
489  {
490  return TextAndReading(
491  static_cast<const SwTextNode*>(aTOXSources[0].pNd)->GetExpandText(
492  pLayout,
493  pTextMark->GetStart(),
494  *pEnd - pTextMark->GetStart(),
495  false, false, false,
497  | (pLayout && pLayout->IsHideRedlines()
499  : ExpandMode(0))),
501  }
502 
503  return TextAndReading(pTextMark->GetTOXMark().GetAlternativeText(), OUString());
504 }
505 
506 void SwTOXContent::FillText(SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16,
507  SwRootFrame const*const pLayout) const
508 {
509  assert(!"sw_redlinehide: this is dead code, Bibliography only has SwTOXAuthority");
510  const sal_Int32* pEnd = pTextMark->End();
511  if( pEnd && !pTextMark->GetTOXMark().IsAlternativeText() )
512  // sw_redlinehide: this probably won't HideDeletions
513  static_cast<const SwTextNode*>(aTOXSources[0].pNd)->CopyExpandText(
514  rNd, &rInsPos, pTextMark->GetStart(),
515  *pEnd - pTextMark->GetStart(), pLayout);
516  else
517  {
518  rNd.InsertText( GetText().sText, rInsPos );
519  }
520 }
521 
522 // The level for displaying it
523 
524 sal_uInt16 SwTOXContent::GetLevel() const
525 {
526  return pTextMark->GetTOXMark().GetLevel();
527 }
528 
529 // TOX assembled from paragraphs
530 // Watch out for OLE/graphics when sorting!
531 // The position must not come from the document, but from the "anchor"!
532 SwTOXPara::SwTOXPara(SwContentNode& rNd, SwTOXElement eT, sal_uInt16 nLevel, const OUString& sSeqName)
533  : SwTOXSortTabBase( TOX_SORT_PARA, &rNd, nullptr, nullptr ),
534  eType( eT ),
535  m_nLevel(nLevel),
536  nStartIndex(0),
537  nEndIndex(-1),
538  m_sSequenceName( sSeqName )
539 {
540  // tdf#123313 create any missing bookmarks *before* generating ToX nodes!
541  switch (eType)
542  {
545  assert(rNd.IsTextNode());
548  break;
549  default:
550  break;
551  }
552 }
553 
555 {
556  const SwContentNode* pNd = aTOXSources[0].pNd;
557  switch( eType )
558  {
560  if (nStartIndex != 0 || nEndIndex != -1)
561  {
562  // sw_redlinehide: "captions" are a rather fuzzily defined concept anyway
563  return TextAndReading(static_cast<const SwTextNode*>(pNd)->GetExpandText(
564  pLayout,
565  nStartIndex,
566  nEndIndex == -1 ? -1 : nEndIndex - nStartIndex,
567  false, false, false,
568  pLayout && pLayout->IsHideRedlines()
570  : ExpandMode(0)),
571  OUString());
572  }
573  BOOST_FALLTHROUGH;
576  {
577  assert(nStartIndex == 0);
578  assert(nEndIndex == -1);
580  pLayout, *static_cast<const SwTextNode*>(pNd),
582  OUString());
583  }
584  break;
585 
586  case SwTOXElement::Ole:
588  case SwTOXElement::Frame:
589  {
590  // Find the FlyFormat; the object/graphic name is there
591  SwFrameFormat* pFly = pNd->GetFlyFormat();
592  if( pFly )
593  return TextAndReading(pFly->GetName(), OUString());
594 
595  OSL_ENSURE( false, "Graphic/object without name" );
596  const char* pId = SwTOXElement::Ole == eType
597  ? STR_OBJECT_DEFNAME
599  ? STR_GRAPHIC_DEFNAME
600  : STR_FRAME_DEFNAME;
601  return TextAndReading(SwResId(pId), OUString());
602  }
603  break;
604  default: break;
605  }
606  return TextAndReading();
607 }
608 
609 void SwTOXPara::FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16,
610  SwRootFrame const*const pLayout) const
611 {
612  assert(!"sw_redlinehide: this is dead code, Bibliography only has SwTOXAuthority");
614  {
615  const SwTextNode* pSrc = static_cast<const SwTextNode*>(aTOXSources[0].pNd);
617  && (nStartIndex != 0 || nEndIndex != -1))
618  {
619  pSrc->CopyExpandText( rNd, &rInsPos, nStartIndex,
620  nEndIndex == -1 ? -1 : nEndIndex - nStartIndex,
621  pLayout, false, false, true );
622  }
623  else
624  {
625  assert(nStartIndex == 0);
626  assert(nEndIndex == -1);
627  // sw_redlinehide: this probably won't HideDeletions
628  pSrc->CopyExpandText( rNd, &rInsPos, 0, -1,
629  pLayout, false, false, true );
630  if (pLayout && pLayout->HasMergedParas())
631  {
632  if (SwTextFrame const*const pFrame = static_cast<SwTextFrame*>(pSrc->getLayoutFrame(pLayout)))
633  {
634  if (sw::MergedPara const*const pMerged = pFrame->GetMergedPara())
635  {
636  // pSrc already copied above
637  assert(pSrc == pMerged->pParaPropsNode);
638  for (sal_uLong i = pSrc->GetIndex() + 1;
639  i <= pMerged->pLastNode->GetIndex(); ++i)
640  {
641  SwNode *const pTmp(pSrc->GetNodes()[i]);
642  if (pTmp->GetRedlineMergeFlag() == SwNode::Merge::NonFirst)
643  {
644 
645  pTmp->GetTextNode()->CopyExpandText(
646  rNd, &rInsPos, 0, -1,
647  pLayout, false, false, false );
648  }
649  }
650  }
651  }
652  }
653  }
654  }
655  else
656  {
657  rNd.InsertText( GetText().sText.replace('\t', ' '), rInsPos );
658  }
659 }
660 
661 sal_uInt16 SwTOXPara::GetLevel() const
662 {
663  sal_uInt16 nRet = m_nLevel;
664  const SwContentNode* pNd = aTOXSources[0].pNd;
665 
666  if( SwTOXElement::OutlineLevel == eType && pNd->GetTextNode() )
667  {
668  const int nTmp = static_cast<const SwTextNode*>(pNd)->GetAttrOutlineLevel();
669  if(nTmp != 0 )
670  nRet = static_cast<sal_uInt16>(nTmp);
671  }
672  return nRet;
673 }
674 
675 std::pair<OUString, bool> SwTOXPara::GetURL(SwRootFrame const*const) const
676 {
677  OUString aText;
678  const SwContentNode* pNd = aTOXSources[0].pNd;
679  switch( eType )
680  {
683  {
684  const SwTextNode * pTextNd = pNd->GetTextNode();
685 
686  SwDoc& rDoc = const_cast<SwDoc&>( pTextNd->GetDoc() );
687  // tdf#123313: this *must not* create a bookmark, its Undo would
688  // be screwed! create it as preparatory step, in ctor!
689  ::sw::mark::IMark const * const pMark = rDoc.getIDocumentMarkAccess()->getMarkForTextNode(
690  *pTextNd,
692  aText = "#" + pMark->GetName();
693  }
694  break;
695 
696  case SwTOXElement::Ole:
698  case SwTOXElement::Frame:
699  {
700  // Find the FlyFormat; the object/graphic name is there
701  SwFrameFormat* pFly = pNd->GetFlyFormat();
702  if( pFly )
703  {
704  aText = "#" + pFly->GetName() + OUStringChar(cMarkSeparator);
705  const char* pStr;
706  switch( eType )
707  {
708  case SwTOXElement::Ole: pStr = "ole"; break;
709  case SwTOXElement::Graphic: pStr = "graphic"; break;
710  case SwTOXElement::Frame: pStr = "frame"; break;
711  default: pStr = nullptr;
712  }
713  if( pStr )
714  aText += OUString::createFromAscii( pStr );
715  }
716  }
717  break;
719  {
720  aText = "#" + m_sSequenceName + OUStringChar(cMarkSeparator)
721  + "sequence";
722  }
723  break;
724  default: break;
725  }
726  return std::make_pair(aText, false);
727 }
728 
730 {
731  switch (eType)
732  {
736  return nStartIndex == 0 && nEndIndex == -1;
737  default:
738  return false;
739  }
740 }
741 
742 // Table
744  : SwTOXSortTabBase( TOX_SORT_TABLE, &rNd, nullptr, nullptr ),
745  nLevel(FORM_ALPHA_DELIMITER)
746 {
747 }
748 
750 {
751  const SwNode* pNd = aTOXSources[0].pNd;
752  if( pNd )
753  {
754  const SwTableNode* pTableNd =
755  reinterpret_cast<const SwTableNode*>(pNd->FindTableNode());
756  if (pTableNd)
757  {
758  return TextAndReading(pTableNd->GetTable().GetFrameFormat()->GetName(), OUString());
759  }
760  }
761 
762  OSL_ENSURE( false, "Where's my table?" );
763  return TextAndReading(SwResId( STR_TABLE_DEFNAME ), OUString());
764 }
765 
766 sal_uInt16 SwTOXTable::GetLevel() const
767 {
768  return nLevel;
769 }
770 
771 std::pair<OUString, bool> SwTOXTable::GetURL(SwRootFrame const*const) const
772 {
773  const SwNode* pNd = aTOXSources[0].pNd;
774  if (!pNd)
775  return std::make_pair(OUString(), false);
776 
777  pNd = pNd->FindTableNode();
778  if (!pNd)
779  return std::make_pair(OUString(), false);
780 
781  const OUString sName = static_cast<const SwTableNode*>(pNd)->GetTable().GetFrameFormat()->GetName();
782  if ( sName.isEmpty() )
783  return std::make_pair(OUString(), false);
784 
785  return std::make_pair("#" + sName + OUStringChar(cMarkSeparator) + "table", false);
786 }
787 
789  SwFormatField& rField, const SwTOXInternational& rIntl ) :
790  SwTOXSortTabBase( TOX_SORT_AUTHORITY, &rNd, nullptr, &rIntl ),
791  m_rField(rField)
792 {
793  if(rField.GetTextField())
794  nCntPos = rField.GetTextField()->GetStart();
795 }
796 
797 sal_uInt16 SwTOXAuthority::GetLevel() const
798 {
799  OUString sText(static_cast<SwAuthorityField*>(m_rField.GetField())->GetFieldText(AUTH_FIELD_AUTHORITY_TYPE));
800  //#i18655# the level '0' is the heading level therefore the values are incremented here
801  sal_uInt16 nRet = 1;
802  if( pTOXIntl->IsNumeric( sText ) )
803  {
804  nRet = sText.toUInt32();
805  nRet++;
806  }
807  //illegal values are also set to 'ARTICLE' as non-numeric values are
808  if(nRet > AUTH_TYPE_END)
809  nRet = 1;
810  return nRet;
811 }
812 
813 static OUString lcl_GetText(SwFormatField const& rField, SwRootFrame const*const pLayout)
814 {
815  return rField.GetField()->ExpandField(true, pLayout);
816 }
817 
819 {
820  return TextAndReading(lcl_GetText(m_rField, pLayout), OUString());
821 }
822 
823 OUString SwTOXAuthority::GetText(sal_uInt16 nAuthField, const SwRootFrame* pLayout) const
824 {
825  SwAuthorityField* pField = static_cast<SwAuthorityField*>(m_rField.GetField());
826  OUString sText;
827  if(AUTH_FIELD_IDENTIFIER == nAuthField)
828  {
829  sText = lcl_GetText(m_rField, pLayout);
830  const SwAuthorityFieldType* pType = static_cast<const SwAuthorityFieldType*>(pField->GetTyp());
831  sal_Unicode cChar = pType->GetPrefix();
832  if(cChar && cChar != ' ')
833  sText = sText.copy(1);
834  cChar = pType->GetSuffix();
835  if(cChar && cChar != ' ')
836  sText = sText.copy(0, sText.getLength() - 1);
837  }
838  else if(AUTH_FIELD_AUTHORITY_TYPE == nAuthField)
839  {
840  sal_uInt16 nLevel = GetLevel();
841  if(nLevel)
842  sText = SwAuthorityFieldType::GetAuthTypeName(static_cast<ToxAuthorityType>(--nLevel));
843  }
844  else
845  sText = pField->GetFieldText(static_cast<ToxAuthorityField>(nAuthField));
846  return sText;
847 }
848 
849 OUString SwTOXAuthority::GetSourceURL(const OUString& rText)
850 {
851  OUString aText = rText;
852 
853  uno::Reference<uri::XUriReferenceFactory> xUriReferenceFactory
854  = uri::UriReferenceFactory::create(comphelper::getProcessComponentContext());
855  uno::Reference<uri::XUriReference> xUriRef;
856  try
857  {
858  xUriRef = xUriReferenceFactory->parse(aText);
859  }
860  catch (const uno::Exception& rException)
861  {
862  SAL_WARN("sw.core",
863  "SwTOXAuthority::GetSourceURL: failed to parse url: " << rException.Message);
864  }
865  if (xUriRef.is() && xUriRef->getFragment().startsWith("page="))
866  {
867  xUriRef->clearFragment();
868  aText = xUriRef->getUriReference();
869  }
870 
871  return aText;
872 }
873 
874 void SwTOXAuthority::FillText(SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField,
875  SwRootFrame const* const pLayout) const
876 {
877  OUString aText = GetText(nAuthField, pLayout);
878  if (nAuthField == AUTH_FIELD_URL)
879  {
880  aText = GetSourceURL(aText);
881  }
882 
883  rNd.InsertText(aText, rInsPos);
884 }
885 
887 {
888  if (nType != rCmp.nType)
889  {
890  return false;
891  }
892 
893  // Compare our SwAuthEntry and rCmp's SwAuthEntry, but the URL is considered equivalent, as long
894  // as it only differs in a page number, as that's still the same source.
895  const SwAuthEntry* pThis = static_cast<SwAuthorityField*>(m_rField.GetField())->GetAuthEntry();
896  const SwAuthEntry* pOther = static_cast<SwAuthorityField*>(
897  static_cast<const SwTOXAuthority&>(rCmp).m_rField.GetField())
898  ->GetAuthEntry();
899  if (pThis == pOther)
900  {
901  return true;
902  }
903 
904  for (int i = 0; i < AUTH_FIELD_END; ++i)
905  {
906  auto eField = static_cast<ToxAuthorityField>(i);
907  if (eField == AUTH_FIELD_URL)
908  {
911  {
912  return false;
913  }
914  continue;
915  }
916 
917  if (pThis->GetAuthorField(eField) != pOther->GetAuthorField(eField))
918  {
919  return false;
920  }
921  }
922 
923  return true;
924 }
925 
927 {
928  bool bRet = false;
929  SwAuthorityField* pField = static_cast<SwAuthorityField*>(m_rField.GetField());
930  SwAuthorityFieldType* pType = static_cast<SwAuthorityFieldType*>(
931  pField->GetTyp());
932  if(pType->IsSortByDocument())
933  bRet = SwTOXSortTabBase::sort_lt(rBase);
934  else
935  {
936  SwAuthorityField* pCmpField =
937  static_cast<SwAuthorityField*>(static_cast<const SwTOXAuthority&>(rBase).m_rField.GetField());
938 
939  for(sal_uInt16 i = 0; i < pType->GetSortKeyCount(); i++)
940  {
941  const SwTOXSortKey* pKey = pType->GetSortKey(i);
942  const TextAndReading aMy(pField->GetFieldText(pKey->eField), OUString());
943  const TextAndReading aOther(pCmpField->GetFieldText(pKey->eField), OUString());
944 
945  sal_Int32 nComp = pTOXIntl->Compare( aMy, GetLocale(),
946  aOther, rBase.GetLocale() );
947 
948  if( nComp )
949  {
950  bRet = (-1 == nComp) == pKey->bSortAscending;
951  break;
952  }
953  }
954  }
955  return bRet;
956 }
957 
958 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_uInt16 GetLevel() const override
Definition: txmsrt.cxx:466
OUString const & GetAuthorField(ToxAuthorityField ePos) const
Definition: authfld.hxx:194
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:121
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:157
SwTOXElement eType
Definition: txmsrt.hxx:259
virtual sal_uInt16 GetLevel() const override
Definition: txmsrt.cxx:426
sal_uLong GetIndex() const
Definition: node.hxx:291
virtual TextAndReading GetText_Impl(SwRootFrame const *pLayout) const override
Definition: txmsrt.cxx:485
bool IsAlternativeText() const
Definition: tox.hxx:590
OUString const & GetSecondaryKeyReading() const
Definition: tox.hxx:673
SwTOIOptions
Definition: tox.hxx:389
OUString sReading
Definition: txmsrt.hxx:61
virtual const OUString & GetName() const =0
Marks a position in the document model.
Definition: pam.hxx:35
const SwField * GetField() const
Definition: fmtfld.hxx:110
virtual const SwRootFrame * GetCurrentLayout() const =0
OUString const & GetPrimaryKey() const
Definition: tox.hxx:649
virtual std::pair< OUString, bool > GetURL(SwRootFrame const *const pLayout) const override
Definition: txmsrt.cxx:675
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:1212
sal_Int64 n
Definition: doc.hxx:187
sal_Int32 nStartIndex
Definition: txmsrt.hxx:261
virtual bool sort_lt(const SwTOXSortTabBase &) override
Definition: txmsrt.cxx:336
SwTOXIndex(const SwTextNode &, const SwTextTOXMark *, SwTOIOptions nOptions, sal_uInt8 nKeyLevel, const SwTOXInternational &rIntl, const css::lang::Locale &rLocale)
Definition: txmsrt.cxx:300
LanguageType m_eLang
Definition: txmsrt.hxx:75
IDocumentMarkAccess * getIDocumentMarkAccess()
Definition: docbm.cxx:1794
virtual bool equivalent(const SwTOXSortTabBase &) override
Definition: txmsrt.cxx:314
virtual void FillText(SwTextNode &rNd, const SwIndex &rInsPos, sal_uInt16 nAuthField, SwRootFrame const *pLayout) const override
Definition: txmsrt.cxx:874
const SwTOXType * GetTOXType() const
Definition: tox.hxx:587
static OUString GetSourceURL(const OUString &rText)
Gets the URL of the underlying SwAuthEntry, ignoring its page number.
Definition: txmsrt.cxx:849
#define FORM_SECONDARY_KEY
Definition: tox.hxx:211
virtual TextAndReading GetText_Impl(SwRootFrame const *pLayout) const override
Definition: txmsrt.cxx:471
The root element of a Writer document layout.
Definition: rootfrm.hxx:82
OUString GetFollowingText(bool bMorePages) const
Definition: txmsrt.cxx:127
static OUString const & GetAuthTypeName(ToxAuthorityType eType)
Definition: initui.cxx:277
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:203
sal_uInt16 nLevel
Definition: txmsrt.hxx:279
virtual sal_uInt16 GetLevel() const override
Definition: txmsrt.cxx:524
static LanguageType nLang
Definition: srtdlg.cxx:51
SwTOXAuthority(const SwContentNode &rNd, SwFormatField &rField, const SwTOXInternational &rIntl)
Definition: txmsrt.cxx:788
virtual bool IsFullPara() const
Definition: txmsrt.cxx:214
sal_uInt16 sal_Unicode
OUString const & GetPrimaryKeyReading() const
Definition: tox.hxx:667
const SwTOXSortKey * GetSortKey(sal_uInt16 nIdx) const
Definition: authfld.cxx:435
virtual sal_uInt16 GetLevel() const override
Definition: txmsrt.cxx:766
OUString typeName
sal_Unicode GetPrefix() const
Definition: authfld.hxx:119
const SwTOXMark & GetTOXMark() const
Definition: txatbase.hxx:216
sal_uInt8 nKeyLevel
Definition: txmsrt.hxx:205
invariant for SwAuthorityField is that it is always registered at its SwAuthorityFieldType via AddFie...
Definition: authfld.hxx:153
SwIndex nContent
Definition: pam.hxx:38
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
const SwTextField * GetTextField() const
Definition: fmtfld.hxx:128
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:506
TOXSortType
Definition: txmsrt.hxx:36
virtual bool equivalent(const SwTOXSortTabBase &)
Definition: txmsrt.cxx:225
bool IsNumeric(const OUString &rStr) const
Definition: txmsrt.cxx:107
const OUString & GetName() const
Definition: format.hxx:115
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:452
eField
virtual bool equivalent(const SwTOXSortTabBase &) override
Definition: txmsrt.cxx:886
sal_Int32 GetStart() const
Definition: txatbase.hxx:86
const SwTable & GetTable() const
Definition: node.hxx:501
Describes parts of multiple text nodes, which will form a text frame, even when redlines are hidden a...
Definition: txtfrm.hxx:953
virtual TextAndReading GetText_Impl(SwRootFrame const *pLayout) const override
Definition: txmsrt.cxx:818
OUString ToUpper(const OUString &rStr, sal_Int32 nPos) const
Definition: txmsrt.cxx:102
const char * sName
For sorting by text.
Definition: txmsrt.hxx:190
virtual TextAndReading GetText_Impl(SwRootFrame const *pLayout) const override
Definition: txmsrt.cxx:554
DocumentType eType
sal_Int32 m_nLevel
const OUString & GetAlternativeText() const
Definition: tox.hxx:578
sal_Int32 nCntPos
Definition: txmsrt.hxx:131
OUString m_sSortAlgorithm
Definition: txmsrt.hxx:76
Style of a layout element.
Definition: frmfmt.hxx:58
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
int i
SwTOXElement
Definition: tox.hxx:367
SwDoc & GetDoc()
Definition: node.hxx:212
sal_Unicode const toxMarkSeparator
separator for toxmarks: #%19%19|toxmark
Definition: swtypes.hxx:133
sal_uInt16 GetLevel() const
Definition: tox.hxx:643
virtual TextAndReading GetText_Impl(SwRootFrame const *pLayout) const override
Definition: txmsrt.cxx:749
sal_Unicode GetSuffix() const
Definition: authfld.hxx:120
OUString GetText(SwRootFrame const *pLayout) const
Definition: tox.cxx:192
Marks a character position inside a document model node.
Definition: index.hxx:33
SwTOXTable(const SwContentNode &rNd)
Definition: txmsrt.cxx:743
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:609
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:697
virtual std::pair< OUString, bool > GetURL(SwRootFrame const *const pLayout) const
Definition: txmsrt.cxx:187
OUString SwResId(const char *pId)
Definition: swmodule.cxx:166
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:661
bool bSortAscending
Definition: authfld.hxx:53
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:405
virtual bool sort_lt(const SwTOXSortTabBase &) override
Definition: txmsrt.cxx:459
virtual TextAndReading GetText_Impl(SwRootFrame const *pLayout) const override
Definition: txmsrt.cxx:360
SwFieldType * GetTyp() const
Definition: fldbas.hxx:392
ToxAuthorityField
Definition: toxe.hxx:82
sal_uLong nPos
Definition: txmsrt.hxx:130
virtual sal_uInt16 GetLevel() const override
Definition: txmsrt.cxx:797
OUString InsertText(const OUString &rStr, const SwIndex &rIdx, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
insert text content
Definition: ndtxt.cxx:2283
SwTOIOptions m_nOptions
Definition: txmsrt.hxx:77
SwTOXPara(SwContentNode &, SwTOXElement, sal_uInt16 nLevel=FORM_ALPHA_DELIMITER, const OUString &sSeqName=OUString())
Definition: txmsrt.cxx:532
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:463
SwTOXCustom(const TextAndReading &rKey, sal_uInt16 nLevel, const SwTOXInternational &rIntl, const css::lang::Locale &rLocale)
Definition: txmsrt.cxx:443
TextAndReading m_aKey
Definition: txmsrt.hxx:221
ToxAuthorityField eField
Definition: authfld.hxx:52
OUString const & GetSecondaryKey() const
Definition: tox.hxx:655
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
virtual std::pair< OUString, bool > GetURL(SwRootFrame const *const pLayout) const override
Definition: txmsrt.cxx:771
sal_Int32 GetIndex() const
Definition: index.hxx:91
const sal_Int32 * End() const
Definition: txatbase.hxx:152
#define FORM_ALPHA_DELIMITER
Definition: tox.hxx:209
Reference< XComponentContext > getProcessComponentContext()
QPRO_FUNC_TYPE nType
Sequence< sal_Int8 > aSeq
#define FORM_ENTRY
Definition: tox.hxx:212
virtual bool IsFullPara() const override
Definition: txmsrt.cxx:729
bool IsHideRedlines() const
Replacement for sw::DocumentRedlineManager::GetRedlineFlags() (this is layout-level redline hiding)...
Definition: rootfrm.hxx:420
OUString m_sSequenceName
Definition: txmsrt.hxx:263
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:357
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:3426
virtual sal_uInt16 GetLevel() const override
Definition: txmsrt.cxx:661
bool IsMainEntry() const
Definition: tox.hxx:157
#define SAL_WARN(area, stream)
static SwTOIOptions GetOptions()
Definition: txmsrt.hxx:143
#define FORM_PRIMARY_KEY
Definition: tox.hxx:210
bool IsSortByDocument() const
Definition: authfld.hxx:122
bool IsFrameBehind(const SwTextNode &rMyNd, sal_Int32 nMySttPos, const SwTextNode &rBehindNd, sal_Int32 nSttPos)
Definition: reffld.cxx:99
bool HasMergedParas() const
Definition: rootfrm.hxx:424
SwFormatField & m_rField
Definition: txmsrt.hxx:286
virtual void FillText(SwTextNode &rNd, const SwIndex &rInsPos, sal_uInt16 nAuthField, SwRootFrame const *pLayout) const
Definition: txmsrt.cxx:219
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:813
TextAndReading const & GetText() const
Definition: txmsrt.hxx:176
virtual bool sort_lt(const SwTOXSortTabBase &)
Definition: txmsrt.cxx:251
bool IsTextNode() const
Definition: node.hxx:640
Class for sorting directories.
Definition: txmsrt.hxx:120
const OUString & GetFieldText(ToxAuthorityField eField) const
Definition: authfld.cxx:544
SwFrameFormat * GetFlyFormat() const
If node is in a fly return the respective format.
Definition: node.cxx:719
SwTOXContent(const SwTextNode &, const SwTextTOXMark *, const SwTOXInternational &rIntl)
Definition: txmsrt.cxx:477
std::vector< SwTOXSource > aTOXSources
Definition: txmsrt.hxx:125
sal_uInt16 GetSortKeyCount() const
Definition: authfld.cxx:430
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:187
virtual bool sort_lt(const SwTOXSortTabBase &) override
Definition: txmsrt.cxx:926
sal_uInt16 nPos
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:845
virtual void FillText(SwTextNode &rNd, const SwIndex &rInsPos, sal_uInt16 nAuthField, SwRootFrame const *pLayout) const override
Definition: txmsrt.cxx:396
Represents one row in the bibliography table.
Definition: txmsrt.hxx:283
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:80