LibreOffice Module sw (master)  1
authfld.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 <memory>
21 
22 #include <libxml/xmlwriter.h>
23 
24 #include <comphelper/string.hxx>
26 #include <o3tl/any.hxx>
27 #include <osl/diagnose.h>
28 #include <swtypes.hxx>
29 #include <strings.hrc>
30 #include <authfld.hxx>
31 #include <expfld.hxx>
32 #include <pam.hxx>
33 #include <cntfrm.hxx>
34 #include <rootfrm.hxx>
35 #include <tox.hxx>
36 #include <txmsrt.hxx>
37 #include <fmtfld.hxx>
38 #include <txtfld.hxx>
39 #include <ndtxt.hxx>
40 #include <doc.hxx>
43 #include <unofldmid.h>
44 #include <unoprnms.hxx>
45 
46 #include <com/sun/star/beans/PropertyValues.hpp>
47 
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::beans;
50 using namespace ::com::sun::star::lang;
51 
53  : SimpleReferenceObject()
54 {
55  for(int i = 0; i < AUTH_FIELD_END; ++i)
56  m_aAuthFields[i] = rCopy.m_aAuthFields[i];
57 }
58 
59 bool SwAuthEntry::operator==(const SwAuthEntry& rComp) const
60 {
61  for(int i = 0; i < AUTH_FIELD_END; ++i)
62  if(m_aAuthFields[i] != rComp.m_aAuthFields[i])
63  return false;
64  return true;
65 }
66 
69  m_pDoc(pDoc),
70  m_cPrefix('['),
71  m_cSuffix(']'),
72  m_bIsSequence(false),
73  m_bSortByDocument(true),
74  m_eLanguage(::GetAppLanguage())
75 {
76 }
77 
79 {
80 }
81 
82 std::unique_ptr<SwFieldType> SwAuthorityFieldType::Copy() const
83 {
84  return std::make_unique<SwAuthorityFieldType>(m_pDoc);
85 }
86 
88 {
89  for(SwAuthDataArr::size_type j = 0; j < m_DataArr.size(); ++j)
90  {
91  if(m_DataArr[j].get() == pEntry)
92  {
93  if (m_DataArr[j]->m_nCount <= 1)
94  {
95  m_DataArr.erase(m_DataArr.begin() + j);
96  //re-generate positions of the fields
98  }
99  return;
100  }
101  }
102  assert(false);
103  OSL_FAIL("Field unknown" );
104 }
105 
106 SwAuthEntry* SwAuthorityFieldType::AddField(const OUString& rFieldContents)
107 {
109  sal_Int32 nIdx{ 0 };
110  for( sal_Int32 i = 0; i < AUTH_FIELD_END; ++i )
111  pEntry->SetAuthorField( static_cast<ToxAuthorityField>(i),
112  rFieldContents.getToken( 0, TOX_STYLE_DELIMITER, nIdx ));
113 
114  for (auto &rpTemp : m_DataArr)
115  {
116  if (*rpTemp == *pEntry)
117  {
118  return rpTemp.get();
119  }
120  }
121 
122  //if it is a new Entry - insert
123  m_DataArr.push_back(std::move(pEntry));
124  //re-generate positions of the fields
126  return m_DataArr.back().get();
127 }
128 
130  std::vector<OUString>& rToFill )const
131 {
132  for (const auto & rpTemp : m_DataArr)
133  {
134  rToFill.push_back(rpTemp->GetAuthorField(AUTH_FIELD_IDENTIFIER));
135  }
136 }
137 
139  std::u16string_view rIdentifier)const
140 {
141  for (const auto &rpTemp : m_DataArr)
142  {
143  if (rIdentifier == rpTemp->GetAuthorField(AUTH_FIELD_IDENTIFIER))
144  {
145  return rpTemp.get();
146  }
147  }
148  return nullptr;
149 }
150 
152 {
153  for (auto &rpTemp : m_DataArr)
154  {
155  if (rpTemp->GetAuthorField(AUTH_FIELD_IDENTIFIER) ==
157  {
158  for(int i = 0; i < AUTH_FIELD_END; ++i)
159  {
160  rpTemp->SetAuthorField(static_cast<ToxAuthorityField>(i),
161  pNewEntry->GetAuthorField(static_cast<ToxAuthorityField>(i)));
162  }
163  return true;
164  }
165  }
166  return false;
167 }
168 
170 sal_uInt16 SwAuthorityFieldType::AppendField( const SwAuthEntry& rInsert )
171 {
172  for( SwAuthDataArr::size_type nRet = 0; nRet < m_DataArr.size(); ++nRet )
173  {
174  if( *m_DataArr[ nRet ] == rInsert )
175  return nRet;
176  }
177 
178  //if it is a new Entry - insert
179  m_DataArr.push_back(new SwAuthEntry(rInsert));
180  return m_DataArr.size()-1;
181 }
182 
183 std::unique_ptr<SwTOXInternational> SwAuthorityFieldType::CreateTOXInternational() const
184 {
185  return std::make_unique<SwTOXInternational>(m_eLanguage, SwTOIOptions::NONE, m_sSortAlgorithm);
186 }
187 
189  SwRootFrame const*const pLayout)
190 {
191  //find the field in a sorted array of handles,
192  if(!m_SequArr.empty() && m_SequArr.size() != m_DataArr.size())
194  if(m_SequArr.empty())
195  {
197  std::unique_ptr<SwTOXInternational> pIntl = CreateTOXInternational();
198  // sw_redlinehide: need 2 arrays because the sorting may be different,
199  // if multiple fields refer to the same entry and first one is deleted
200  std::vector<std::unique_ptr<SwTOXSortTabBase>> aSortArr;
201  std::vector<std::unique_ptr<SwTOXSortTabBase>> aSortArrRLHidden;
202  std::vector<SwFormatField*> vFields;
203  GatherFields(vFields);
204  for(SwFormatField* pFormatField : vFields)
205  {
206  const SwTextField* pTextField = pFormatField->GetTextField();
207  if(!pTextField || !pTextField->GetpTextNode())
208  {
209  continue;
210  }
211  const SwTextNode& rFieldTextNode = pTextField->GetTextNode();
212  SwPosition aFieldPos(rFieldTextNode);
213  SwDoc& rDoc = const_cast<SwDoc&>(rFieldTextNode.GetDoc());
214  SwContentFrame *pFrame = rFieldTextNode.getLayoutFrame( rDoc.getIDocumentLayoutAccess().GetCurrentLayout() );
215  const SwTextNode* pTextNode = nullptr;
216  if(pFrame && !pFrame->IsInDocBody())
217  pTextNode = GetBodyTextNode( rDoc, aFieldPos, *pFrame );
218  //if no text node could be found or the field is in the document
219  //body the directly available text node will be used
220  if(!pTextNode)
221  pTextNode = &rFieldTextNode;
222  if (pTextNode->GetText().isEmpty()
224  || !pTextNode->GetNodes().IsDocNodes())
225  {
226  continue;
227  }
228  auto const InsertImpl = [&pIntl, pTextNode, pFormatField]
229  (std::vector<std::unique_ptr<SwTOXSortTabBase>> & rSortArr)
230  {
231  std::unique_ptr<SwTOXAuthority> pNew(
232  new SwTOXAuthority(*pTextNode, *pFormatField, *pIntl));
233 
234  for (size_t i = 0; i < rSortArr.size(); ++i)
235  {
236  SwTOXSortTabBase* pOld = rSortArr[i].get();
237  if (pOld->equivalent(*pNew))
238  {
239  //only the first occurrence in the document
240  //has to be in the array
241  if (pOld->sort_lt(*pNew))
242  pNew.reset();
243  else // remove the old content
244  rSortArr.erase(rSortArr.begin() + i);
245  break;
246  }
247  }
248  //if it still exists - insert at the correct position
249  if (pNew)
250  {
251  size_t j {0};
252 
253  while (j < rSortArr.size())
254  {
255  SwTOXSortTabBase* pOld = rSortArr[j].get();
256  if (pNew->sort_lt(*pOld))
257  break;
258  ++j;
259  }
260  rSortArr.insert(rSortArr.begin() + j, std::move(pNew));
261  }
262  };
263  InsertImpl(aSortArr);
264  if (!sw::IsFieldDeletedInModel(rIDRA, *pTextField))
265  {
266  InsertImpl(aSortArrRLHidden);
267  }
268  }
269 
270  for(auto & pBase : aSortArr)
271  {
272  SwFormatField& rFormatField = static_cast<SwTOXAuthority&>(*pBase).GetFieldFormat();
273  SwAuthorityField* pAField = static_cast<SwAuthorityField*>(rFormatField.GetField());
274  m_SequArr.push_back(pAField->GetAuthEntry());
275  }
276  for (auto & pBase : aSortArrRLHidden)
277  {
278  SwFormatField& rFormatField = static_cast<SwTOXAuthority&>(*pBase).GetFieldFormat();
279  SwAuthorityField* pAField = static_cast<SwAuthorityField*>(rFormatField.GetField());
280  m_SequArrRLHidden.push_back(pAField->GetAuthEntry());
281  }
282  }
283  //find nHandle
284  auto const& rSequArr(pLayout && pLayout->IsHideRedlines() ? m_SequArrRLHidden : m_SequArr);
285  for (std::vector<sal_IntPtr>::size_type i = 0; i < rSequArr.size(); ++i)
286  {
287  if (rSequArr[i] == pAuthEntry)
288  {
289  return i + 1;
290  }
291  }
292  return 0;
293 }
294 
295 void SwAuthorityFieldType::QueryValue( Any& rVal, sal_uInt16 nWhichId ) const
296 {
297  switch( nWhichId )
298  {
299  case FIELD_PROP_PAR1:
300  case FIELD_PROP_PAR2:
301  {
302  OUString sVal;
303  sal_Unicode uRet = FIELD_PROP_PAR1 == nWhichId ? m_cPrefix : m_cSuffix;
304  if(uRet)
305  sVal = OUString(uRet);
306  rVal <<= sVal;
307  }
308  break;
309  case FIELD_PROP_PAR3:
310  rVal <<= GetSortAlgorithm();
311  break;
312 
313  case FIELD_PROP_BOOL1:
314  rVal <<= m_bIsSequence;
315  break;
316 
317  case FIELD_PROP_BOOL2:
318  rVal <<= m_bSortByDocument;
319  break;
320 
321  case FIELD_PROP_LOCALE:
322  rVal <<= LanguageTag(GetLanguage()).getLocale();
323  break;
324 
325  case FIELD_PROP_PROP_SEQ:
326  {
327  Sequence<PropertyValues> aRet(m_SortKeyArr.size());
328  PropertyValues* pValues = aRet.getArray();
329  for(SortKeyArr::size_type i = 0; i < m_SortKeyArr.size(); ++i)
330  {
331  const SwTOXSortKey* pKey = &m_SortKeyArr[i];
332  pValues[i].realloc(2);
333  PropertyValue* pValue = pValues[i].getArray();
334  pValue[0].Name = UNO_NAME_SORT_KEY;
335  pValue[0].Value <<= sal_Int16(pKey->eField);
336  pValue[1].Name = UNO_NAME_IS_SORT_ASCENDING;
337  pValue[1].Value <<= pKey->bSortAscending;
338  }
339  rVal <<= aRet;
340  }
341  break;
342  default:
343  assert(false);
344  }
345 }
346 
347 void SwAuthorityFieldType::PutValue( const Any& rAny, sal_uInt16 nWhichId )
348 {
349  switch( nWhichId )
350  {
351  case FIELD_PROP_PAR1:
352  case FIELD_PROP_PAR2:
353  {
354  OUString sTmp;
355  rAny >>= sTmp;
356  const sal_Unicode uSet = !sTmp.isEmpty() ? sTmp[0] : 0;
357  if( FIELD_PROP_PAR1 == nWhichId )
358  m_cPrefix = uSet;
359  else
360  m_cSuffix = uSet;
361  }
362  break;
363  case FIELD_PROP_PAR3:
364  {
365  OUString sTmp;
366  rAny >>= sTmp;
367  SetSortAlgorithm(sTmp);
368  break;
369  }
370  case FIELD_PROP_BOOL1:
371  m_bIsSequence = *o3tl::doAccess<bool>(rAny);
372  break;
373  case FIELD_PROP_BOOL2:
374  m_bSortByDocument = *o3tl::doAccess<bool>(rAny);
375  break;
376 
377  case FIELD_PROP_LOCALE:
378  {
379  css::lang::Locale aLocale;
380  if( rAny >>= aLocale )
382  }
383  break;
384 
385  case FIELD_PROP_PROP_SEQ:
386  {
387  Sequence<PropertyValues> aSeq;
388  if( rAny >>= aSeq )
389  {
390  m_SortKeyArr.clear();
391  const PropertyValues* pValues = aSeq.getConstArray();
392  //TODO: Limiting to the first SAL_MAX_UINT16 elements of aSeq so that size of
393  // m_SortKeyArr remains in range of sal_uInt16, as GetSortKeyCount and GetSortKey
394  // still expect m_SortKeyArr to be indexed by sal_uInt16:
395  auto nSize = std::min<sal_Int32>(aSeq.getLength(), SAL_MAX_UINT16);
396  for(sal_Int32 i = 0; i < nSize; i++)
397  {
398  SwTOXSortKey aSortKey;
399  for(const PropertyValue& rValue : pValues[i])
400  {
401  if(rValue.Name == UNO_NAME_SORT_KEY)
402  {
403  sal_Int16 nVal = -1; rValue.Value >>= nVal;
404  if(nVal >= 0 && nVal < AUTH_FIELD_END)
405  aSortKey.eField = static_cast<ToxAuthorityField>(nVal);
406  }
407  else if(rValue.Name == UNO_NAME_IS_SORT_ASCENDING)
408  {
409  aSortKey.bSortAscending = *o3tl::doAccess<bool>(rValue.Value);
410  }
411  }
412  m_SortKeyArr.push_back(aSortKey);
413  }
414  }
415  }
416  break;
417  default:
418  assert(false);
419  }
420 }
421 
423 {
424  //re-generate positions of the fields
426  CallSwClientNotify(rHint);
427 }
428 
430 {
431  return m_SortKeyArr.size();
432 }
433 
434 const SwTOXSortKey* SwAuthorityFieldType::GetSortKey(sal_uInt16 nIdx) const
435 {
436  if(m_SortKeyArr.size() > nIdx)
437  return &m_SortKeyArr[nIdx];
438  OSL_FAIL("Sort key not found");
439  return nullptr;
440 }
441 
442 void SwAuthorityFieldType::SetSortKeys(sal_uInt16 nKeyCount, SwTOXSortKey const aKeys[])
443 {
444  m_SortKeyArr.clear();
445  for(sal_uInt16 i = 0; i < nKeyCount; i++)
446  if(aKeys[i].eField < AUTH_FIELD_END)
447  m_SortKeyArr.push_back(aKeys[i]);
448 }
449 
451  const OUString& rFieldContents )
452  : SwField(pInitType)
453  , m_nTempSequencePos( -1 )
454  , m_nTempSequencePosRLHidden( -1 )
455 {
456  m_xAuthEntry = pInitType->AddField( rFieldContents );
457 }
458 
460  SwAuthEntry* pAuthEntry )
461  : SwField( pInitType )
462  , m_xAuthEntry( pAuthEntry )
463  , m_nTempSequencePos( -1 )
464  , m_nTempSequencePosRLHidden( -1 )
465 {
466 }
467 
469 {
470  static_cast<SwAuthorityFieldType* >(GetTyp())->RemoveField(m_xAuthEntry.get());
471 }
472 
473 OUString SwAuthorityField::ExpandImpl(SwRootFrame const*const pLayout) const
474 {
475  return ConditionalExpandAuthIdentifier(pLayout);
476 }
477 
479  SwRootFrame const*const pLayout) const
480 {
481  SwAuthorityFieldType* pAuthType = static_cast<SwAuthorityFieldType*>(GetTyp());
482  OUString sRet;
483  if(pAuthType->GetPrefix())
484  sRet = OUString(pAuthType->GetPrefix());
485 
486  if( pAuthType->IsSequence() )
487  {
488  sal_IntPtr & rnTempSequencePos(pLayout && pLayout->IsHideRedlines()
490  if(!pAuthType->GetDoc()->getIDocumentFieldsAccess().IsExpFieldsLocked())
491  rnTempSequencePos = pAuthType->GetSequencePos(m_xAuthEntry.get(), pLayout);
492  if (0 <= rnTempSequencePos)
493  sRet += OUString::number(rnTempSequencePos);
494  }
495  else
496  {
497  //TODO: Expand to: identifier, number sequence, ...
498  if(m_xAuthEntry)
499  {
500  OUString sIdentifier(m_xAuthEntry->GetAuthorField(AUTH_FIELD_IDENTIFIER));
501  // tdf#107784 Use title if it's a ooxml citation
502  if (sIdentifier.trim().startsWith("CITATION"))
503  return m_xAuthEntry->GetAuthorField(AUTH_FIELD_TITLE);
504  else
505  sRet += sIdentifier;
506  }
507  }
508  if(pAuthType->GetSuffix())
509  sRet += OUStringChar(pAuthType->GetSuffix());
510  return sRet;
511 }
512 
514  SwRootFrame const*const pLayout) const
515 {
516  SwAuthorityFieldType* pAuthType = static_cast<SwAuthorityFieldType*>(GetTyp());
517  OUString sRet;
518 
519  if( pAuthType->IsSequence() )
520  {
521  sal_IntPtr & rnTempSequencePos(pLayout && pLayout->IsHideRedlines()
523  if(!pAuthType->GetDoc()->getIDocumentFieldsAccess().IsExpFieldsLocked())
524  rnTempSequencePos = pAuthType->GetSequencePos(m_xAuthEntry.get(), pLayout);
525  if (0 <= rnTempSequencePos)
526  sRet += OUString::number(rnTempSequencePos);
527  }
528  else
529  {
530  //TODO: Expand to: identifier, number sequence, ...
531  if(m_xAuthEntry)
532  sRet += m_xAuthEntry->GetAuthorField(eField);
533  }
534  return sRet;
535 }
536 
537 std::unique_ptr<SwField> SwAuthorityField::Copy() const
538 {
539  SwAuthorityFieldType* pAuthType = static_cast<SwAuthorityFieldType*>(GetTyp());
540  return std::make_unique<SwAuthorityField>(pAuthType, m_xAuthEntry.get());
541 }
542 
544 {
545  return m_xAuthEntry->GetAuthorField( eField );
546 }
547 
548 void SwAuthorityField::SetPar1(const OUString& rStr)
549 {
550  SwAuthorityFieldType* pInitType = static_cast<SwAuthorityFieldType* >(GetTyp());
551  pInitType->RemoveField(m_xAuthEntry.get());
552  m_xAuthEntry = pInitType->AddField(rStr);
553 }
554 
556 {
557  return SwResId(STR_AUTHORITY_ENTRY);
558 }
559 
560 OUString SwAuthorityField::GetAuthority(const SwTextAttr* pTextAttr,
561  const SwRootFrame* pLayout) const
562 {
563  OUString aText;
564 
565  SwForm aForm(TOX_AUTHORITIES);
566  if (!pTextAttr)
567  {
568  return aText;
569  }
570 
571  auto& rFormatField = const_cast<SwFormatField&>(pTextAttr->GetFormatField());
572  SwTextField* pTextField = rFormatField.GetTextField();
573  if (!pTextField)
574  {
575  return aText;
576  }
577 
578  const SwTextNode& rNode = pTextField->GetTextNode();
579  const auto pFieldType = static_cast<const SwAuthorityFieldType*>(GetTyp());
580  std::unique_ptr<SwTOXInternational> pIntl(pFieldType->CreateTOXInternational());
581  SwTOXAuthority aAuthority(rNode, rFormatField, *pIntl);
582  sal_uInt16 nLevel = aAuthority.GetLevel();
583  SwFormTokens aPattern = aForm.GetPattern(nLevel);
584  aAuthority.InitText(pLayout);
585  for (const auto& rToken : aPattern)
586  {
587  switch (rToken.eTokenType)
588  {
589  case TOKEN_TEXT:
590  {
591  aText += rToken.sText;
592  break;
593  }
594  case TOKEN_AUTHORITY:
595  {
596  sal_uInt16 eField = rToken.nAuthorityField;
597  aText += aAuthority.GetText(eField, pLayout);
598  break;
599  }
600  default:
601  break;
602  }
603  }
604 
605  return aText;
606 }
607 
609 {
610  xmlTextWriterStartElement(pWriter, BAD_CAST("SwAuthorityField"));
611  SwField::dumpAsXml(pWriter);
612 
613  xmlTextWriterStartElement(pWriter, BAD_CAST("m_xAuthEntry"));
614  xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", m_xAuthEntry.get());
615  xmlTextWriterEndElement(pWriter);
616  xmlTextWriterStartElement(pWriter, BAD_CAST("m_nTempSequencePos"));
617  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"),
618  BAD_CAST(OString::number(m_nTempSequencePos).getStr()));
619  xmlTextWriterEndElement(pWriter);
620  xmlTextWriterStartElement(pWriter, BAD_CAST("m_nTempSequencePosRLHidden"));
621  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"),
622  BAD_CAST(OString::number(m_nTempSequencePosRLHidden).getStr()));
623  xmlTextWriterEndElement(pWriter);
624 
625  xmlTextWriterEndElement(pWriter);
626 }
627 
628 const char* const aFieldNames[] =
629 {
630  "Identifier",
631  "BibiliographicType",
632  "Address",
633  "Annote",
634  "Author",
635  "Booktitle",
636  "Chapter",
637  "Edition",
638  "Editor",
639  "Howpublished",
640  "Institution",
641  "Journal",
642  "Month",
643  "Note",
644  "Number",
645  "Organizations",
646  "Pages",
647  "Publisher",
648  "School",
649  "Series",
650  "Title",
651  "Report_Type",
652  "Volume",
653  "Year",
654  "URL",
655  "Custom1",
656  "Custom2",
657  "Custom3",
658  "Custom4",
659  "Custom5",
660  "ISBN"
661 };
662 
663 bool SwAuthorityField::QueryValue( Any& rAny, sal_uInt16 /*nWhichId*/ ) const
664 {
665  if(!GetTyp())
666  return false;
667  if(!m_xAuthEntry)
668  return false;
669  Sequence <PropertyValue> aRet(AUTH_FIELD_END);
670  PropertyValue* pValues = aRet.getArray();
671  for(int i = 0; i < AUTH_FIELD_END; ++i)
672  {
673  pValues[i].Name = OUString::createFromAscii(aFieldNames[i]);
674  const OUString& sField = m_xAuthEntry->GetAuthorField(static_cast<ToxAuthorityField>(i));
676  pValues[i].Value <<= sal_Int16(sField.toInt32());
677  else
678  pValues[i].Value <<= sField;
679  }
680  rAny <<= aRet;
681  /* FIXME: it is weird that we always return false here */
682  return false;
683 }
684 
685 static sal_Int32 lcl_Find(const OUString& rFieldName)
686 {
687  for(sal_Int32 i = 0; i < AUTH_FIELD_END; ++i)
688  if(rFieldName.equalsAscii(aFieldNames[i]))
689  return i;
690  return -1;
691 }
692 
693 bool SwAuthorityField::PutValue( const Any& rAny, sal_uInt16 /*nWhichId*/ )
694 {
695  if(!GetTyp() || !m_xAuthEntry)
696  return false;
697 
698  Sequence <PropertyValue> aParam;
699  if(!(rAny >>= aParam))
700  return false;
701 
702  OUStringBuffer sBuf;
704  OUString sToSet(sBuf.makeStringAndClear());
705  for(const PropertyValue& rParam : std::as_const(aParam))
706  {
707  const sal_Int32 nFound = lcl_Find(rParam.Name);
708  if(nFound >= 0)
709  {
710  OUString sContent;
711  if(AUTH_FIELD_AUTHORITY_TYPE == nFound)
712  {
713  sal_Int16 nVal = 0;
714  rParam.Value >>= nVal;
715  sContent = OUString::number(nVal);
716  }
717  else
718  rParam.Value >>= sContent;
719  sToSet = comphelper::string::setToken(sToSet, nFound, TOX_STYLE_DELIMITER, sContent);
720  }
721  }
722 
723  static_cast<SwAuthorityFieldType*>(GetTyp())->RemoveField(m_xAuthEntry.get());
724  m_xAuthEntry = static_cast<SwAuthorityFieldType*>(GetTyp())->AddField(sToSet);
725 
726  /* FIXME: it is weird that we always return false here */
727  return false;
728 }
729 
731 {
732  SwAuthorityFieldType* pSrcTyp = static_cast<SwAuthorityFieldType*>(GetTyp()),
733  * pDstTyp = static_cast<SwAuthorityFieldType*>(pFieldTyp);
734  if( pSrcTyp != pDstTyp )
735  {
736  const SwAuthEntry* pSrcEntry = m_xAuthEntry.get();
737  pDstTyp->AppendField( *pSrcEntry );
738  pSrcTyp->RemoveField( pSrcEntry );
739  SwField::ChgTyp( pFieldTyp );
740  }
741  return pSrcTyp;
742 }
743 
744 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:240
std::vector< SwFormToken > SwFormTokens
Vector of tokens.
Definition: tox.hxx:288
OUString const & GetAuthorField(ToxAuthorityField ePos) const
Definition: authfld.hxx:190
OUString ConditionalExpandAuthIdentifier(SwRootFrame const *pLayout) const
For internal use only, in general continue using ExpandField() instead.
Definition: authfld.cxx:478
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const override
Definition: authfld.cxx:473
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:823
Marks a position in the document model.
Definition: pam.hxx:35
const SwField * GetField() const
Definition: fmtfld.hxx:110
bool IsInDocBody() const
Definition: frame.hxx:924
#define UNO_NAME_SORT_KEY
Definition: unoprnms.hxx:524
const OUString & GetText() const
Definition: ndtxt.hxx:211
virtual const SwRootFrame * GetCurrentLayout() const =0
SwAuthDataArr m_DataArr
Definition: authfld.hxx:64
Definition: tox.hxx:315
void DelSequenceArray()
Definition: authfld.hxx:90
virtual ~SwAuthorityFieldType() override
Definition: authfld.cxx:78
virtual void SetPar1(const OUString &rStr) override
Definition: authfld.cxx:548
static LanguageType convertToLanguageType(const css::lang::Locale &rLocale, bool bResolveSystem=true)
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
void SetSortAlgorithm(const OUString &rSet)
Definition: authfld.hxx:140
Base class of all fields.
Definition: fldbas.hxx:289
#define TOX_STYLE_DELIMITER
Definition: tox.hxx:425
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1212
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhichId) const override
Definition: authfld.cxx:663
Definition: doc.hxx:187
virtual std::unique_ptr< SwField > Copy() const override
Definition: authfld.cxx:537
sal_Unicode m_cPrefix
Definition: authfld.hxx:68
std::map< sal_Int32, std::shared_ptr< SetItemPropertyStorage > > PropertyValues
SwTextNode * GetpTextNode() const
Definition: txtfld.hxx:49
sal_Unicode m_cSuffix
Definition: authfld.hxx:69
The root element of a Writer document layout.
Definition: rootfrm.hxx:82
sal_uInt16 AppendField(const SwAuthEntry &rInsert)
appends a new entry (if new) and returns the array position
Definition: authfld.cxx:170
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
void GatherFields(std::vector< SwFormatField * > &rvFormatFields, bool bCollectOnlyInDocNodes=true) const
Definition: fldbas.cxx:205
OUString m_aAuthFields[AUTH_FIELD_END]
Definition: authfld.hxx:38
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:357
css::uno::Any const & rValue
OUString GetAuthority(const SwTextAttr *pTextAttr, const SwRootFrame *pLayout) const
Returns the line matching the source's default row in the ToX.
Definition: authfld.cxx:560
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId) override
Definition: authfld.cxx:693
sal_uInt16 sal_Unicode
const SwTOXSortKey * GetSortKey(sal_uInt16 nIdx) const
Definition: authfld.cxx:434
sal_Unicode GetPrefix() const
Definition: authfld.hxx:118
invariant for SwAuthorityField is that it is always registered at its SwAuthorityFieldType via AddFie...
Definition: authfld.hxx:152
#define SAL_MAX_UINT16
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
A wrapper around SfxPoolItem to store the start position of (usually) a text portion, with an optional end.
Definition: txatbase.hxx:41
virtual bool equivalent(const SwTOXSortTabBase &)
Definition: txmsrt.cxx:220
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: authfld.cxx:608
eField
virtual bool IsExpFieldsLocked() const =0
virtual ~SwAuthorityField() override
Definition: authfld.cxx:468
virtual std::unique_ptr< SwFieldType > Copy() const override
Definition: authfld.cxx:82
LanguageType m_eLanguage
Definition: authfld.hxx:72
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:195
sal_IntPtr m_nTempSequencePos
Definition: authfld.hxx:155
SwAuthEntry * GetAuthEntry() const
Definition: authfld.hxx:180
SwAuthEntry()=default
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:381
rtl::Reference< SwAuthEntry > m_xAuthEntry
Definition: authfld.hxx:154
struct _xmlTextWriter * xmlTextWriterPtr
std::unique_ptr< SwTOXInternational > CreateTOXInternational() const
Definition: authfld.cxx:183
virtual void QueryValue(css::uno::Any &rVal, sal_uInt16 nWhichId) const override
Definition: authfld.cxx:295
SwAuthEntry * GetEntryByIdentifier(std::u16string_view rIdentifier) const
Definition: authfld.cxx:138
int i
SwDoc & GetDoc()
Definition: node.hxx:212
const SwFormTokens & GetPattern(sal_uInt16 nLevel) const
Definition: tox.cxx:950
SwDoc * GetDoc()
Definition: authfld.hxx:87
#define FIELD_PROP_BOOL2
Definition: unofldmid.h:29
sal_uInt16 GetSequencePos(const SwAuthEntry *pAuthEntry, SwRootFrame const *pLayout)
Definition: authfld.cxx:188
#define FIELD_PROP_LOCALE
Definition: unofldmid.h:40
SwFieldIds
Definition: fldbas.hxx:44
sal_Unicode GetSuffix() const
Definition: authfld.hxx:119
LanguageType GetLanguage() const
Definition: authfld.hxx:136
bool IsSequence() const
Definition: authfld.hxx:106
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:697
OUString SwResId(const char *pId)
Definition: swmodule.cxx:166
#define UNO_NAME_IS_SORT_ASCENDING
Definition: unoprnms.hxx:523
bool bSortAscending
Definition: authfld.hxx:52
void SetLanguage(LanguageType nLang)
Definition: authfld.hxx:137
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:405
#define FIELD_PROP_PAR3
Definition: unofldmid.h:25
SwFieldType * GetTyp() const
Definition: fldbas.hxx:392
void GetAllEntryIdentifiers(std::vector< OUString > &rToFill) const
Definition: authfld.cxx:129
virtual SwFieldType * ChgTyp(SwFieldType *) override
Set new type (used for copying among documents).
Definition: authfld.cxx:730
ToxAuthorityField
Definition: toxe.hxx:82
#define FIELD_PROP_BOOL1
Definition: unofldmid.h:28
sal_Int16 m_nCount
const PropertyValue * pValues
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
std::vector< SwAuthEntry * > m_SequArrRLHidden
hidden redlines
Definition: authfld.hxx:66
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:335
bool operator==(const SwAuthEntry &rComp) const
Definition: authfld.cxx:59
SwAuthEntry * AddField(const OUString &rFieldContents)
Definition: authfld.cxx:106
SwAuthorityFieldType(SwDoc *pDoc)
Definition: authfld.cxx:67
ToxAuthorityField eField
Definition: authfld.hxx:51
bool ChangeEntryContent(const SwAuthEntry *pNewEntry)
Definition: authfld.cxx:151
#define FIELD_PROP_PAR1
Definition: unofldmid.h:23
#define FIELD_PROP_PAR2
Definition: unofldmid.h:24
bool IsFieldDeletedInModel(IDocumentRedlineAccess const &rIDRA, SwTextField const &rTextField)
SwFormatField & GetFieldFormat()
Definition: txmsrt.hxx:294
sal_IntPtr m_nTempSequencePosRLHidden
hidden redlines
Definition: authfld.hxx:156
#define FIELD_PROP_PROP_SEQ
Definition: unofldmid.h:39
SortKeyArr m_SortKeyArr
Definition: authfld.hxx:67
LanguageType GetAppLanguage()
Definition: init.cxx:728
virtual void PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId) override
Definition: authfld.cxx:347
const OUString & GetSortAlgorithm() const
Definition: authfld.hxx:139
Sequence< sal_Int8 > aSeq
bool IsHideRedlines() const
Replacement for sw::DocumentRedlineManager::GetRedlineFlags() (this is layout-level redline hiding)...
Definition: rootfrm.hxx:420
void RemoveField(const SwAuthEntry *nHandle)
Definition: authfld.cxx:87
virtual void CallSwClientNotify(const SfxHint &rHint) const override
Definition: calbck.cxx:324
std::vector< SwAuthEntry * > m_SequArr
Definition: authfld.hxx:65
static sal_Int32 lcl_Find(const OUString &rFieldName)
Definition: authfld.cxx:685
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc...
Definition: nodes.cxx:2329
SwAuthorityField(SwAuthorityFieldType *pType, const OUString &rFieldContents)
Definition: authfld.cxx:450
const char *const aFieldNames[]
Definition: authfld.cxx:628
SwTextNode & GetTextNode() const
Definition: txtfld.hxx:53
OUString setToken(const OUString &rIn, sal_Int32 nToken, sal_Unicode cTok, const OUString &rNewToken)
virtual bool sort_lt(const SwTOXSortTabBase &)
Definition: txmsrt.cxx:246
OUString ExpandCitation(ToxAuthorityField eField, SwRootFrame const *pLayout) const
Definition: authfld.cxx:513
Class for sorting directories.
Definition: txmsrt.hxx:120
const OUString & GetFieldText(ToxAuthorityField eField) const
Definition: authfld.cxx:543
virtual OUString GetDescription() const override
Definition: authfld.cxx:555
sal_uInt16 GetSortKeyCount() const
Definition: authfld.cxx:429
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: authfld.cxx:422
void SetSortKeys(sal_uInt16 nKeyCount, SwTOXSortKey const nKeys[])
Definition: authfld.cxx:442
Represents one row in the bibliography table.
Definition: txmsrt.hxx:283
OUString m_sSortAlgorithm
Definition: authfld.hxx:73
OStringBuffer & padToLength(OStringBuffer &rBuffer, sal_Int32 nLength, char cFill= '\0')