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