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