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