LibreOffice Module sw (master)  1
DocumentFieldsManager.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  */
20 #include <config_features.h>
21 #include <config_fuzzers.h>
22 #include <doc.hxx>
23 #include <IDocumentUndoRedo.hxx>
24 #include <IDocumentState.hxx>
26 #include <redline.hxx>
27 #include <rootfrm.hxx>
28 #include <dbmgr.hxx>
29 #include <chpfld.hxx>
30 #include <dbfld.hxx>
31 #include <reffld.hxx>
32 #include <flddropdown.hxx>
33 #include <strings.hrc>
34 #include <SwUndoField.hxx>
35 #include <flddat.hxx>
36 #include <cntfrm.hxx>
37 #include <section.hxx>
38 #include <docufld.hxx>
39 #include <calbck.hxx>
40 #include <cellatr.hxx>
41 #include <swtable.hxx>
42 #include <frmfmt.hxx>
43 #include <fmtfld.hxx>
44 #include <ndtxt.hxx>
45 #include <txtfld.hxx>
46 #include <docfld.hxx>
47 #include <hints.hxx>
48 #include <docary.hxx>
49 #include <fldbas.hxx>
50 #include <expfld.hxx>
51 #include <ddefld.hxx>
52 #include <swddetbl.hxx>
53 #include <authfld.hxx>
54 #include <usrfld.hxx>
55 #include <ndindex.hxx>
56 #include <pam.hxx>
57 #include <o3tl/deleter.hxx>
58 #include <osl/diagnose.h>
61 #include <com/sun/star/uno/Any.hxx>
62 
63 using namespace ::com::sun::star::uno;
64 
65 namespace sw
66 {
68  SwTextField const& rTextField)
69  {
71  SwPosition const pos(rTextField.GetTextNode(),
72  rTextField.GetStart());
73  SwRangeRedline const*const pRedline(rIDRA.GetRedline(pos, &tmp));
74  return (pRedline
75  && pRedline->GetType() == RedlineType::Delete
76  && *pRedline->GetPoint() != *pRedline->GetMark());
77  }
78 }
79 
80 namespace
81 {
82 #if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
83 
84  OUString lcl_GetDBVarName( SwDoc& rDoc, SwDBNameInfField& rDBField )
85  {
86  SwDBData aDBData( rDBField.GetDBData( &rDoc ));
87  OUString sDBNumNm;
88  SwDBData aDocData = rDoc.GetDBData();
89 
90  if( aDBData != aDocData )
91  {
92  sDBNumNm = aDBData.sDataSource + OUStringChar(DB_DELIM)
93  + aDBData.sCommand + OUStringChar(DB_DELIM);
94  }
96 
97  return sDBNumNm;
98  }
99 
100 #endif
101 
102  bool IsFieldDeleted(IDocumentRedlineAccess const& rIDRA,
103  SwRootFrame const& rLayout, SwTextField const& rTextField)
104  {
105  SwTextNode const& rNode(rTextField.GetTextNode());
106  bool const isInBody(
107  rNode.GetNodes().GetEndOfExtras().GetIndex() < rNode.GetIndex());
108  if (!isInBody && nullptr == rNode.getLayoutFrame(&rLayout))
109  { // see SwDocUpdateField::GetBodyNode() - fields in hidden sections
110  // don't have layout frames but must be updated, so use the same
111  // check as there, but do it again because GetBodyNode() checks
112  // for *any* layout...
113  return true;
114  }
115  return sw::IsFieldDeletedInModel(rIDRA, rTextField);
116  }
117 
118  void lcl_CalcField( SwDoc& rDoc, SwCalc& rCalc, const SetGetExpField& rSGEField,
119  SwDBManager* pMgr, SwRootFrame const*const pLayout)
120  {
121  const SwTextField* pTextField = rSGEField.GetTextField();
122  if( !pTextField )
123  return ;
124 
125  if (pLayout && pLayout->IsHideRedlines()
126  && IsFieldDeleted(rDoc.getIDocumentRedlineAccess(), *pLayout, *pTextField))
127  {
128  return;
129  }
130 
131  const SwField* pField = pTextField->GetFormatField().GetField();
132  const SwFieldIds nFieldWhich = pField->GetTyp()->Which();
133 
134  if( SwFieldIds::SetExp == nFieldWhich )
135  {
136  SwSbxValue aValue;
137  if( nsSwGetSetExpType::GSE_EXPR & pField->GetSubType() )
138  aValue.PutDouble( static_cast<const SwSetExpField*>(pField)->GetValue(pLayout) );
139  else
140  // Extension to calculate with Strings
141  aValue.PutString( static_cast<const SwSetExpField*>(pField)->GetExpStr(pLayout) );
142 
143  // set the new value in Calculator
144  rCalc.VarChange( pField->GetTyp()->GetName(), aValue );
145  }
146  else if( pMgr )
147  {
148  #if !HAVE_FEATURE_DBCONNECTIVITY || ENABLE_FUZZERS
149  (void) rDoc;
150  #else
151  switch( nFieldWhich )
152  {
154  {
155  SwDBNumSetField* pDBField = const_cast<SwDBNumSetField*>(static_cast<const SwDBNumSetField*>(pField));
156 
157  SwDBData aDBData(pDBField->GetDBData(&rDoc));
158 
159  if( pDBField->IsCondValid() &&
160  pMgr->OpenDataSource( aDBData.sDataSource, aDBData.sCommand ))
161  rCalc.VarChange( lcl_GetDBVarName( rDoc, *pDBField),
162  pDBField->GetFormat() );
163  }
164  break;
166  {
167  SwDBNextSetField* pDBField = const_cast<SwDBNextSetField*>(static_cast<const SwDBNextSetField*>(pField));
168  SwDBData aDBData(pDBField->GetDBData(&rDoc));
169  if( !pDBField->IsCondValid() ||
170  !pMgr->OpenDataSource( aDBData.sDataSource, aDBData.sCommand ))
171  break;
172 
173  OUString sDBNumNm(lcl_GetDBVarName( rDoc, *pDBField));
174  SwCalcExp* pExp = rCalc.VarLook( sDBNumNm );
175  if( pExp )
176  rCalc.VarChange( sDBNumNm, pExp->nValue.GetLong() + 1 );
177  }
178  break;
179 
180  default: break;
181  }
182  #endif
183  }
184  }
185 }
186 
187 namespace sw
188 {
189 
191  mbNewFieldLst(true),
192  mpUpdateFields(new SwDocUpdateField(m_rDoc)),
193  mpFieldTypes( new SwFieldTypes ),
194  mnLockExpField( 0 )
195 {
196 }
197 
199 {
200  return mpFieldTypes.get();
201 }
202 
209 {
210  const SwFieldTypes::size_type nSize = mpFieldTypes->size();
211  const SwFieldIds nFieldWhich = rFieldTyp.Which();
212 
213  SwFieldTypes::size_type i = INIT_FLDTYPES;
214 
215  switch( nFieldWhich )
216  {
217  case SwFieldIds::SetExp:
218  //JP 29.01.96: SequenceFields start at INIT_FLDTYPES - 3!!
219  // Or we get doubble number circles!!
220  //MIB 14.03.95: From now on also the SW3-Reader relies on this, when
221  //constructing string pools and when reading SetExp fields
222  if( nsSwGetSetExpType::GSE_SEQ & static_cast<const SwSetExpFieldType&>(rFieldTyp).GetType() )
223  i -= INIT_SEQ_FLDTYPES;
224  [[fallthrough]];
226  case SwFieldIds::User:
227  case SwFieldIds::Dde:
228  {
229  const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore();
230  OUString sFieldNm( rFieldTyp.GetName() );
231  for( ; i < nSize; ++i )
232  if( nFieldWhich == (*mpFieldTypes)[i]->Which() &&
233  rSCmp.isEqual( sFieldNm, (*mpFieldTypes)[i]->GetName() ))
234  return (*mpFieldTypes)[i].get();
235  }
236  break;
237 
239  for( ; i < nSize; ++i )
240  if( nFieldWhich == (*mpFieldTypes)[i]->Which() )
241  return (*mpFieldTypes)[i].get();
242  break;
243 
244  default:
245  for( i = 0; i < nSize; ++i )
246  if( nFieldWhich == (*mpFieldTypes)[i]->Which() )
247  return (*mpFieldTypes)[i].get();
248  }
249 
250  std::unique_ptr<SwFieldType> pNew = rFieldTyp.Copy();
251  switch( nFieldWhich )
252  {
253  case SwFieldIds::Dde:
254  static_cast<SwDDEFieldType*>(pNew.get())->SetDoc( &m_rDoc );
255  break;
256 
258  case SwFieldIds::Table:
260  case SwFieldIds::GetExp:
261  static_cast<SwValueFieldType*>(pNew.get())->SetDoc( &m_rDoc );
262  break;
263 
264  case SwFieldIds::User:
265  case SwFieldIds::SetExp:
266  static_cast<SwValueFieldType*>(pNew.get())->SetDoc( &m_rDoc );
267  // JP 29.07.96: Optionally prepare FieldList for Calculator:
268  mpUpdateFields->InsertFieldType( *pNew );
269  break;
271  static_cast<SwAuthorityFieldType*>(pNew.get())->SetDoc( &m_rDoc );
272  break;
273  default: break;
274  }
275 
276  mpFieldTypes->insert( mpFieldTypes->begin() + nSize, std::move(pNew) );
278 
279  return (*mpFieldTypes)[ nSize ].get();
280 }
281 
284 {
285  for( SwFieldTypes::size_type i = 0; i < INIT_FLDTYPES; ++i )
286  if( eWhich == (*mpFieldTypes)[i]->Which() )
287  return (*mpFieldTypes)[i].get();
288  return nullptr;
289 }
290 
293  SwFieldIds nResId,
294  const OUString& rName,
295  bool bDbFieldMatching // used in some UNO calls for SwFieldIds::Database to use different string matching code #i51815#
296  ) const
297 {
298  const SwFieldTypes::size_type nSize = mpFieldTypes->size();
299  SwFieldTypes::size_type i {0};
300  const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore();
301 
302  switch( nResId )
303  {
304  case SwFieldIds::SetExp:
305  //JP 29.01.96: SequenceFields start at INIT_FLDTYPES - 3!!
306  // Or we get doubble number circles!!
307  //MIB 14.03.95: From now on also the SW3-Reader relies on this, when
308  //constructing string pools and when reading SetExp fields
310  break;
311 
313  case SwFieldIds::User:
314  case SwFieldIds::Dde:
316  i = INIT_FLDTYPES;
317  break;
318  default: break;
319  }
320 
321  SwFieldType* pRet = nullptr;
322  for( ; i < nSize; ++i )
323  {
324  SwFieldType* pFieldType = (*mpFieldTypes)[i].get();
325 
326  if (nResId == pFieldType->Which())
327  {
328  OUString aFieldName( pFieldType->GetName() );
329  if (bDbFieldMatching && nResId == SwFieldIds::Database) // #i51815#
330  aFieldName = aFieldName.replace(DB_DELIM, '.');
331 
332  if (rSCmp.isEqual( rName, aFieldName ))
333  {
334  pRet = pFieldType;
335  break;
336  }
337  }
338  }
339  return pRet;
340 }
341 
344 {
345  OSL_ENSURE( INIT_FLDTYPES <= nField, "don't remove InitFields" );
346  /*
347  * Dependent fields present -> ErrRaise
348  */
349  if(nField >= mpFieldTypes->size())
350  return;
351 
352  SwFieldType* pTmp = (*mpFieldTypes)[nField].get();
353 
354  // JP 29.07.96: Optionally prepare FieldList for Calculator
355  SwFieldIds nWhich = pTmp->Which();
356  switch( nWhich )
357  {
358  case SwFieldIds::SetExp:
359  case SwFieldIds::User:
360  mpUpdateFields->RemoveFieldType( *pTmp );
361  [[fallthrough]];
362  case SwFieldIds::Dde:
363  if( pTmp->HasWriterListeners() && !m_rDoc.IsUsed( *pTmp ) )
364  {
365  if( SwFieldIds::SetExp == nWhich )
366  static_cast<SwSetExpFieldType*>(pTmp)->SetDeleted( true );
367  else if( SwFieldIds::User == nWhich )
368  static_cast<SwUserFieldType*>(pTmp)->SetDeleted( true );
369  else
370  static_cast<SwDDEFieldType*>(pTmp)->SetDeleted( true );
371  nWhich = SwFieldIds::Database;
372  }
373  break;
374  default: break;
375  }
376 
377  if( nWhich != SwFieldIds::Database )
378  {
379  OSL_ENSURE( !pTmp->HasWriterListeners(), "Dependent fields present!" );
380  }
381  else
382  (*mpFieldTypes)[nField].release(); // DB fields are ref-counted and delete themselves
383 
384  mpFieldTypes->erase( mpFieldTypes->begin() + nField );
386 }
387 
388 // All have to be re-evaluated.
390 {
391  // Tell all types to update their fields
392  for(auto const& pFieldType: *mpFieldTypes)
393  pFieldType->UpdateFields();
394 
395  if(!IsExpFieldsLocked())
396  UpdateExpFields(nullptr, false); // update expression fields
397 
398  // Tables
399  UpdateTableFields(nullptr);
400 
401  // References
402  UpdateRefFields();
403  if(bCloseDB)
404  {
405 #if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
407 #endif
408  }
409  // Only evaluate on full update
411 }
412 
414 {
415  // The FieldType was marked as deleted and removed from the array.
416  // One has to look this up again, now.
417  // - If it's not present, it can be re-inserted.
418  // - If the same type is found, the deleted one has to be renamed.
419 
420  const SwFieldTypes::size_type nSize = mpFieldTypes->size();
421  const SwFieldIds nFieldWhich = rFieldTyp.Which();
422 
423  OSL_ENSURE( SwFieldIds::SetExp == nFieldWhich ||
424  SwFieldIds::User == nFieldWhich ||
425  SwFieldIds::Dde == nFieldWhich, "Wrong FieldType" );
426 
427  const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore();
428  const OUString& rFieldNm = rFieldTyp.GetName();
429 
430  for( SwFieldTypes::size_type i = INIT_FLDTYPES; i < nSize; ++i )
431  {
432  SwFieldType* pFnd = (*mpFieldTypes)[i].get();
433  if( nFieldWhich == pFnd->Which() &&
434  rSCmp.isEqual( rFieldNm, pFnd->GetName() ) )
435  {
436  // find new name
437  SwFieldTypes::size_type nNum = 1;
438  do {
439  OUString sSrch = rFieldNm + OUString::number( nNum );
440  for( i = INIT_FLDTYPES; i < nSize; ++i )
441  {
442  pFnd = (*mpFieldTypes)[i].get();
443  if( nFieldWhich == pFnd->Which() &&
444  rSCmp.isEqual( sSrch, pFnd->GetName() ) )
445  break;
446  }
447  if( i >= nSize ) // not found
448  {
449  const_cast<OUString&>(rFieldNm) = sSrch;
450  break; // exit while loop
451  }
452  ++nNum;
453  } while( true );
454  break;
455  }
456  }
457 
458  // not found, so insert, and updated deleted flag
459  mpFieldTypes->insert( mpFieldTypes->begin() + nSize, std::unique_ptr<SwFieldType>(&rFieldTyp) );
460  switch( nFieldWhich )
461  {
462  case SwFieldIds::SetExp:
463  static_cast<SwSetExpFieldType&>(rFieldTyp).SetDeleted( false );
464  break;
465  case SwFieldIds::User:
466  static_cast<SwUserFieldType&>(rFieldTyp).SetDeleted( false );
467  break;
468  case SwFieldIds::Dde:
469  static_cast<SwDDEFieldType&>(rFieldTyp).SetDeleted( false );
470  break;
471  default: break;
472  }
473 }
474 
476  const Any& rVal, sal_uInt16 nWhich)
477 {
478  Any aOldVal;
479  SwField * pField = GetFieldAtPos(rPos);
480 
482  pField->QueryValue(aOldVal, nWhich))
483  {
485  std::make_unique<SwUndoFieldFromAPI>(rPos, aOldVal, rVal, nWhich));
486  }
487 
488  pField->PutValue(rVal, nWhich);
489 }
490 
491 bool DocumentFieldsManager::UpdateField(SwTextField * pDstTextField, SwField & rSrcField,
492  SwMsgPoolItem * pMsgHint,
493  bool bUpdateFields)
494 {
495  OSL_ENSURE(pDstTextField, "no field to update!");
496 
497  bool bTableSelBreak = false;
498 
499  SwFormatField * pDstFormatField = const_cast<SwFormatField*>(&pDstTextField->GetFormatField());
500  SwField * pDstField = pDstFormatField->GetField();
501  SwFieldIds nFieldWhich = rSrcField.GetTyp()->Which();
502  SwNodeIndex aTableNdIdx(pDstTextField->GetTextNode());
503 
504  if (pDstField->GetTyp()->Which() ==
505  rSrcField.GetTyp()->Which())
506  {
508  {
509  SwPosition aPosition( pDstTextField->GetTextNode() );
510  aPosition.nContent = pDstTextField->GetStart();
511 
513  std::make_unique<SwUndoFieldFromDoc>( aPosition, *pDstField, rSrcField, pMsgHint, bUpdateFields) );
514  }
515 
516  pDstFormatField->SetField(rSrcField.CopyField());
517  SwField* pNewField = pDstFormatField->GetField();
518 
519  switch( nFieldWhich )
520  {
521  case SwFieldIds::SetExp:
522  case SwFieldIds::GetExp:
525  UpdateExpFields( pDstTextField, true );
526  break;
527 
528  case SwFieldIds::Table:
529  {
530  const SwTableNode* pTableNd =
531  m_rDoc.IsIdxInTable(aTableNdIdx);
532  if( pTableNd )
533  {
534  SwTableFormulaUpdate aTableUpdate( &pTableNd->
535  GetTable() );
536  if (bUpdateFields)
537  UpdateTableFields( &aTableUpdate );
538  else
539  pNewField->GetTyp()->CallSwClientNotify(sw::LegacyModifyHint(nullptr, &aTableUpdate));
540 
541  if (! bUpdateFields)
542  bTableSelBreak = true;
543  }
544  }
545  break;
546 
547  case SwFieldIds::Macro:
548  if( bUpdateFields && pDstTextField->GetpTextNode() )
549  pDstTextField->GetpTextNode()->TriggerNodeUpdate(sw::LegacyModifyHint(nullptr, pDstFormatField));
550  break;
551 
556  m_rDoc.ChgDBData(static_cast<SwDBNameInfField*>( pNewField)->GetRealDBData());
557  pNewField->GetTyp()->UpdateFields();
558 
559  break;
560 
562 #if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
563  {
564  // JP 10.02.96: call ChgValue, so that the style change sets the
565  // ContentString correctly
566  SwDBField* pDBField = static_cast<SwDBField*>(pNewField);
567  if (pDBField->IsInitialized())
568  pDBField->ChgValue( pDBField->GetValue(), true );
569 
570  pDBField->ClearInitialized();
571  pDBField->InitContent();
572  }
573 #endif
574  [[fallthrough]];
575 
576  default:
577  pDstFormatField->UpdateTextNode(nullptr, pMsgHint);
578  }
579 
580  // The fields we can calculate here are being triggered for an update
581  // here explicitly.
582  if( nFieldWhich == SwFieldIds::User )
583  UpdateUsrFields();
584  }
585 
586  return bTableSelBreak;
587 }
588 
591 {
592  for(auto const& pFieldType: *mpFieldTypes)
593  if(SwFieldIds::GetRef == pFieldType->Which())
594  static_cast<SwGetRefFieldType*>(pFieldType.get())->UpdateGetReferences();
595 }
596 
598 {
599  OSL_ENSURE( !pHt || RES_TABLEFML_UPDATE == pHt->Which(),
600  "What MessageItem is this?" );
601 
602  auto pFieldType = GetFieldType( SwFieldIds::Table, OUString(), false );
603  if(pFieldType)
604  {
605  std::vector<SwFormatField*> vFields;
606  pFieldType->GatherFields(vFields);
607  SwTableFormulaUpdate* pUpdateField = nullptr;
608  if( pHt && RES_TABLEFML_UPDATE == pHt->Which() )
609  pUpdateField = static_cast<SwTableFormulaUpdate*>(pHt);
610  for(auto pFormatField : vFields)
611  {
612  SwTableField* pField = static_cast<SwTableField*>(pFormatField->GetField());
613  if( pUpdateField )
614  {
615  // table where this field is located
616  const SwTableNode* pTableNd;
617  const SwTextNode& rTextNd = pFormatField->GetTextField()->GetTextNode();
618  pTableNd = rTextNd.FindTableNode();
619  if (pTableNd == nullptr)
620  continue;
621 
622  switch( pUpdateField->m_eFlags )
623  {
624  case TBL_CALC:
625  // re-set the value flag
626  // JP 17.06.96: internal representation of all formulas
627  // (reference to other table!!!)
628  if( nsSwExtendedSubType::SUB_CMD & pField->GetSubType() )
629  pField->PtrToBoxNm( pUpdateField->m_pTable );
630  else
631  pField->ChgValid( false );
632  break;
633  case TBL_BOXNAME:
634  // is this the wanted table?
635  if( &pTableNd->GetTable() == pUpdateField->m_pTable )
636  // to the external representation
637  pField->PtrToBoxNm( pUpdateField->m_pTable );
638  break;
639  case TBL_BOXPTR:
640  // to the internal representation
641  // JP 17.06.96: internal representation on all formulas
642  // (reference to other table!!!)
643  pField->BoxNmToPtr( &pTableNd->GetTable() );
644  break;
645  case TBL_RELBOXNAME:
646  // is this the wanted table?
647  if( &pTableNd->GetTable() == pUpdateField->m_pTable )
648  // to the relative representation
649  pField->ToRelBoxNm( pUpdateField->m_pTable );
650  break;
651  default:
652  break;
653  }
654  }
655  else
656  // reset the value flag for all
657  pField->ChgValid( false );
658  }
659  }
660  // process all table box formulas
662  {
663  auto pBoxFormula = dynamic_cast<const SwTableBoxFormula*>(pItem);
664  if( pBoxFormula && pBoxFormula->GetDefinedIn() )
665  {
666  const_cast<SwTableBoxFormula*>(pBoxFormula)->ChangeState( pHt );
667  }
668  }
669 
670  SwRootFrame const* pLayout(nullptr);
671  for (SwRootFrame const*const pLay : m_rDoc.GetAllLayouts())
672  {
673  assert(!pLayout || pLay->IsHideRedlines() == pLayout->IsHideRedlines()); // TODO
674  pLayout = pLay;
675  }
676 
677  // all fields/boxes are now invalid, so we can start to calculate
678  if( pHt && ( RES_TABLEFML_UPDATE != pHt->Which() ||
679  TBL_CALC != static_cast<SwTableFormulaUpdate*>(pHt)->m_eFlags ))
680  return ;
681 
682  std::unique_ptr<SwCalc, o3tl::default_delete<SwCalc>> pCalc;
683 
684  if( pFieldType )
685  {
686  std::vector<SwFormatField*> vFields;
687  pFieldType->GatherFields(vFields);
688  for(SwFormatField* pFormatField: vFields)
689  {
690  // start calculation at the end
691  // new fields are inserted at the beginning of the modify chain
692  // that gives faster calculation on import
693  // mba: do we really need this "optimization"? Is it still valid?
694  SwTableField *const pField(static_cast<SwTableField*>(pFormatField->GetField()));
696  continue;
697 
698  // needs to be recalculated
699  if( !pField->IsValid() )
700  {
701  // table where this field is located
702  const SwTextNode& rTextNd = pFormatField->GetTextField()->GetTextNode();
703  const SwTableNode* pTableNd = rTextNd.FindTableNode();
704  if( !pTableNd )
705  continue;
706 
707  // if this field is not in the to-be-updated table, skip it
708  if( pHt && &pTableNd->GetTable() !=
709  static_cast<SwTableFormulaUpdate*>(pHt)->m_pTable )
710  continue;
711 
712  if( !pCalc )
713  pCalc.reset(new SwCalc( m_rDoc ));
714 
715  // get the values of all SetExpression fields that are valid
716  // until the table
717  SwFrame* pFrame = nullptr;
718  if( pTableNd->GetIndex() < m_rDoc.GetNodes().GetEndOfExtras().GetIndex() )
719  {
720  // is in the special section, that's expensive!
721  Point aPt; // return the first frame of the layout - Tab.Headline!!
722  std::pair<Point, bool> const tmp(aPt, true);
723  pFrame = rTextNd.getLayoutFrame(pLayout, nullptr, &tmp);
724  if( pFrame )
725  {
726  SwPosition aPos( *pTableNd );
727  if( GetBodyTextNode( m_rDoc, aPos, *pFrame ) )
728  FieldsToCalc( *pCalc, SetGetExpField(
729  aPos.nNode, pFormatField->GetTextField(),
730  &aPos.nContent), pLayout);
731  else
732  pFrame = nullptr;
733  }
734  }
735  if( !pFrame )
736  {
737  // create index to determine the TextNode
738  SwNodeIndex aIdx( rTextNd );
739  FieldsToCalc( *pCalc,
740  SetGetExpField(aIdx, pFormatField->GetTextField()),
741  pLayout);
742  }
743 
744  SwTableCalcPara aPara(*pCalc, pTableNd->GetTable(), pLayout);
745  pField->CalcField( aPara );
746  if( aPara.IsStackOverflow() )
747  {
748  bool const bResult = aPara.CalcWithStackOverflow();
749  if (bResult)
750  {
751  pField->CalcField( aPara );
752  }
753  OSL_ENSURE(bResult,
754  "the chained formula could no be calculated");
755  }
756  pCalc->SetCalcError( SwCalcError::NONE );
757  }
758  pFormatField->UpdateTextNode(nullptr, pHt);
759  }
760  }
761 
762  // calculate the formula at the boxes
764  {
765  auto pFormula = const_cast<SwTableBoxFormula*>(dynamic_cast<const SwTableBoxFormula*>(pItem));
766  if( pFormula && pFormula->GetDefinedIn() && !pFormula->IsValid() )
767  {
768  SwTableBox* pBox = pFormula->GetTableBox();
769  if( pBox && pBox->GetSttNd() &&
770  pBox->GetSttNd()->GetNodes().IsDocNodes() )
771  {
772  const SwTableNode* pTableNd = pBox->GetSttNd()->FindTableNode();
773  if( !pHt || &pTableNd->GetTable() ==
774  static_cast<SwTableFormulaUpdate*>(pHt)->m_pTable )
775  {
776  double nValue;
777  if( !pCalc )
778  pCalc.reset(new SwCalc( m_rDoc ));
779 
780  // get the values of all SetExpression fields that are valid
781  // until the table
782  SwFrame* pFrame = nullptr;
783  if( pTableNd->GetIndex() < m_rDoc.GetNodes().GetEndOfExtras().GetIndex() )
784  {
785  // is in the special section, that's expensive!
786  SwNodeIndex aCNdIdx( *pTableNd, +2 );
787  SwContentNode* pCNd = aCNdIdx.GetNode().GetContentNode();
788  if( !pCNd )
789  pCNd = m_rDoc.GetNodes().GoNext( &aCNdIdx );
790 
791  if (pCNd)
792  {
793  Point aPt; // return the first frame of the layout - Tab.Headline!!
794  std::pair<Point, bool> const tmp(aPt, true);
795  pFrame = pCNd->getLayoutFrame(pLayout, nullptr, &tmp);
796  if( pFrame )
797  {
798  SwPosition aPos( *pCNd );
799  if( GetBodyTextNode( m_rDoc, aPos, *pFrame ) )
800  FieldsToCalc(*pCalc, SetGetExpField(aPos.nNode),
801  pLayout);
802  else
803  pFrame = nullptr;
804  }
805  }
806  }
807  if( !pFrame )
808  {
809  // create index to determine the TextNode
810  SwNodeIndex aIdx( *pTableNd );
811  FieldsToCalc(*pCalc, SetGetExpField(aIdx), pLayout);
812  }
813 
814  SwTableCalcPara aPara(*pCalc, pTableNd->GetTable(), pLayout);
815  pFormula->Calc( aPara, nValue );
816 
817  if( aPara.IsStackOverflow() )
818  {
819  bool const bResult = aPara.CalcWithStackOverflow();
820  if (bResult)
821  {
822  pFormula->Calc( aPara, nValue );
823  }
824  OSL_ENSURE(bResult,
825  "the chained formula could no be calculated");
826  }
827 
828  SwFrameFormat* pFormat = pBox->ClaimFrameFormat();
830 
831  if( pCalc->IsCalcError() )
832  nValue = DBL_MAX;
833  aTmp.Put( SwTableBoxValue( nValue ));
834  if( SfxItemState::SET != pFormat->GetItemState( RES_BOXATR_FORMAT ))
835  aTmp.Put( SwTableBoxNumFormat( 0 ));
836  pFormat->SetFormatAttr( aTmp );
837 
838  pCalc->SetCalcError( SwCalcError::NONE );
839  }
840  }
841  }
842  }
843 }
844 
845 void DocumentFieldsManager::UpdateExpFields( SwTextField* pUpdateField, bool bUpdRefFields )
846 {
848  return;
849 
850  bool bOldInUpdateFields = mpUpdateFields->IsInUpdateFields();
851  mpUpdateFields->SetInUpdateFields( true );
852 
853  mpUpdateFields->MakeFieldList( m_rDoc, true, GETFLD_ALL );
854  mbNewFieldLst = false;
855 
856  if (mpUpdateFields->GetSortList()->empty())
857  {
858  if( bUpdRefFields )
859  UpdateRefFields();
860 
861  mpUpdateFields->SetInUpdateFields( bOldInUpdateFields );
862  mpUpdateFields->SetFieldsDirty( false );
863  return ;
864  }
865 
866  SwRootFrame const* pLayout(nullptr);
867  SwRootFrame const* pLayoutRLHidden(nullptr);
868  for (SwRootFrame const*const pLay : m_rDoc.GetAllLayouts())
869  {
870  if (pLay->IsHideRedlines())
871  {
872  pLayoutRLHidden = pLay;
873  }
874  else
875  {
876  pLayout = pLay;
877  }
878  }
879  if (pLayout || !pLayoutRLHidden) // always calc *something*...
880  {
881  UpdateExpFieldsImpl(pUpdateField, pLayout);
882  }
883  if (pLayoutRLHidden)
884  {
885  UpdateExpFieldsImpl(pUpdateField, pLayoutRLHidden);
886  }
887 
888  // update reference fields
889  if( bUpdRefFields )
890  UpdateRefFields();
891 
892  mpUpdateFields->SetInUpdateFields( bOldInUpdateFields );
893  mpUpdateFields->SetFieldsDirty( false );
894 }
895 
897  SwTextField * pUpdateField, SwRootFrame const*const pLayout)
898 {
899  SwFieldIds nWhich;
900 
901  // Hash table for all string replacements is filled on-the-fly.
902  // Try to fabricate an uneven number.
903  const SwFieldTypes::size_type nHashSize {(( mpFieldTypes->size() / 7 ) + 1 ) * 7};
904  const sal_uInt16 nStrFormatCnt = o3tl::narrowing<sal_uInt16>(nHashSize);
905  OSL_ENSURE( nStrFormatCnt == nHashSize, "Downcasting to sal_uInt16 lost information!" );
906  SwHashTable<HashStr> aHashStrTable(nStrFormatCnt);
907 
908  {
909  const SwFieldType* pFieldType;
910  // process separately:
911  for( auto n = mpFieldTypes->size(); n; )
912  {
913  pFieldType = (*mpFieldTypes)[ --n ].get();
914  switch( pFieldType->Which() )
915  {
916  case SwFieldIds::User:
917  {
918  // Entry present?
919  sal_uInt16 nPos;
920  const OUString& rNm = pFieldType->GetName();
921  OUString sExpand(const_cast<SwUserFieldType*>(static_cast<const SwUserFieldType*>(pFieldType))->Expand(nsSwGetSetExpType::GSE_STRING, 0, LANGUAGE_SYSTEM));
922  SwHash* pFnd = aHashStrTable.Find( rNm, &nPos );
923  if( pFnd )
924  // modify entry in the hash table
925  static_cast<HashStr*>(pFnd)->aSetStr = sExpand;
926  else
927  // insert the new entry
928  aHashStrTable[nPos].reset( new HashStr( rNm, sExpand,
929  aHashStrTable[nPos].release() ) );
930  }
931  break;
932  default: break;
933  }
934  }
935  }
936 
937  // The array is filled with all fields; start calculation.
938  SwCalc aCalc( m_rDoc );
939 
940 #if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
942 
943  // already set the current record number
944  SwDBManager* pMgr = m_rDoc.GetDBManager();
945  pMgr->CloseAll( false );
946 
947  SvtSysLocale aSysLocale;
948  const LocaleDataWrapper* pLclData = &aSysLocale.GetLocaleData();
949  const LanguageType nLang = pLclData->getLanguageTag().getLanguageType();
950  bool bCanFill = pMgr->FillCalcWithMergeData( m_rDoc.GetNumberFormatter(), nLang, aCalc );
951 #endif
952 
953  // Make sure we don't hide all content, which would lead to a crash. First, count how many visible sections we have.
954  int nShownSections = 0;
957  SwSectionFormats& rSectFormats = m_rDoc.GetSections();
958  for( SwSectionFormats::size_type n = 0; n<rSectFormats.size(); ++n )
959  {
960  SwSectionFormat& rSectFormat = *rSectFormats[ n ];
961  SwSectionNode* pSectionNode = rSectFormat.GetSectionNode();
962  SwSection* pSect = rSectFormat.GetSection();
963 
964  // Usually some of the content is not in a section: count that as a virtual section, so that all real sections can be hidden.
965  // Only look for section gaps at the lowest level, ignoring sub-sections.
966  if ( pSectionNode && !rSectFormat.GetParent() )
967  {
968  SwNodeIndex aNextIdx( *pSectionNode->EndOfSectionNode(), 1 );
969  if ( n == 0 && pSectionNode->GetIndex() != nContentStart )
970  nShownSections++; //document does not start with a section
971  if ( n == rSectFormats.size() - 1 )
972  {
973  if ( aNextIdx.GetIndex() != nContentEnd )
974  nShownSections++; //document does not end in a section
975  }
976  else if ( !aNextIdx.GetNode().IsSectionNode() )
977  nShownSections++; //section is not immediately followed by another section
978  }
979 
980  // count only visible sections
981  if ( pSect && !pSect->CalcHiddenFlag())
982  nShownSections++;
983  }
984 
986  std::unordered_map<SwSetExpFieldType const*, SwTextNode const*> SetExpOutlineNodeMap;
987 
988  for (std::unique_ptr<SetGetExpField> const& it : *mpUpdateFields->GetSortList())
989  {
990  SwSection* pSect = const_cast<SwSection*>(it->GetSection());
991  if( pSect )
992  {
993  SwSbxValue aValue = aCalc.Calculate(
994  pSect->GetCondition() );
995  if(!aValue.IsVoidValue())
996  {
997  // Do we want to hide this one?
998  bool bHide = aValue.GetBool();
999  if (bHide && !pSect->IsCondHidden())
1000  {
1001  // This section will be hidden, but it wasn't before
1002  if (nShownSections == 1)
1003  {
1004  // This would be the last section, so set its condition to false, and avoid hiding it.
1005  pSect->SetCondition("0");
1006  bHide = false;
1007  }
1008  nShownSections--;
1009  }
1010  pSect->SetCondHidden( bHide );
1011  }
1012  continue;
1013  }
1014  ::sw::mark::IBookmark *const pBookmark(
1015  const_cast<::sw::mark::IBookmark *>(it->GetBookmark()));
1016  if (pBookmark)
1017  {
1018  SwSbxValue const aValue(aCalc.Calculate(pBookmark->GetHideCondition()));
1019  if (!aValue.IsVoidValue())
1020  {
1021  pBookmark->Hide(aValue.GetBool());
1022  }
1023  continue;
1024  }
1025 
1026  SwTextField* pTextField = const_cast<SwTextField*>(it->GetTextField());
1027  if( !pTextField )
1028  {
1029  OSL_ENSURE( false, "what's wrong now'" );
1030  continue;
1031  }
1032 
1033  if (pLayout && pLayout->IsHideRedlines()
1034  && IsFieldDeleted(rIDRA, *pLayout, *pTextField))
1035  {
1036  continue;
1037  }
1038 
1039  SwFormatField* pFormatField = const_cast<SwFormatField*>(&pTextField->GetFormatField());
1040  const SwField* pField = pFormatField->GetField();
1041 
1042  nWhich = pField->GetTyp()->Which();
1043  switch( nWhich )
1044  {
1046  {
1047  SwHiddenTextField* pHField = const_cast<SwHiddenTextField*>(static_cast<const SwHiddenTextField*>(pField));
1048  SwSbxValue aValue = aCalc.Calculate( pHField->GetPar1() );
1049  bool bValue = !aValue.GetBool();
1050  if(!aValue.IsVoidValue())
1051  {
1052  pHField->SetValue( bValue );
1053  // evaluate field
1054  pHField->Evaluate(m_rDoc);
1055  }
1056  }
1057  break;
1059  {
1060  SwHiddenParaField* pHPField = const_cast<SwHiddenParaField*>(static_cast<const SwHiddenParaField*>(pField));
1061  SwSbxValue aValue = aCalc.Calculate( pHPField->GetPar1() );
1062  bool bValue = aValue.GetBool();
1063  if(!aValue.IsVoidValue())
1064  pHPField->SetHidden( bValue );
1065  }
1066  break;
1068 #if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
1069  {
1070  const_cast<SwDBSetNumberField*>(static_cast<const SwDBSetNumberField*>(pField))->Evaluate(m_rDoc);
1071  aCalc.VarChange( sDBNumNm, static_cast<const SwDBSetNumberField*>(pField)->GetSetNumber());
1072  pField->ExpandField(m_rDoc.IsClipBoard(), nullptr);
1073  }
1074 #endif
1075  break;
1076  case SwFieldIds::DbNextSet:
1077  case SwFieldIds::DbNumSet:
1078 #if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
1079  {
1080  UpdateDBNumFields( *const_cast<SwDBNameInfField*>(static_cast<const SwDBNameInfField*>(pField)), aCalc );
1081  if( bCanFill )
1082  bCanFill = pMgr->FillCalcWithMergeData( m_rDoc.GetNumberFormatter(), nLang, aCalc );
1083  }
1084 #endif
1085  break;
1086  case SwFieldIds::Database:
1087  {
1088 #if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
1089  // evaluate field
1090  const_cast<SwDBField*>(static_cast<const SwDBField*>(pField))->Evaluate();
1091 
1092  SwDBData aTmpDBData(static_cast<const SwDBField*>(pField)->GetDBData());
1093 
1094  if( pMgr->IsDataSourceOpen(aTmpDBData.sDataSource, aTmpDBData.sCommand, false))
1095  aCalc.VarChange( sDBNumNm, pMgr->GetSelectedRecordId(aTmpDBData.sDataSource, aTmpDBData.sCommand, aTmpDBData.nCommandType));
1096 
1097  const OUString& rName = pField->GetTyp()->GetName();
1098 
1099  // Add entry to hash table
1100  // Entry present?
1101  sal_uInt16 nPos;
1102  HashStr* pFnd = aHashStrTable.Find( rName, &nPos );
1103  OUString const value(pField->ExpandField(m_rDoc.IsClipBoard(), nullptr));
1104  if( pFnd )
1105  {
1106  // Modify entry in the hash table
1107  pFnd->aSetStr = value;
1108  }
1109  else
1110  {
1111  // insert new entry
1112  aHashStrTable[nPos].reset( new HashStr( rName,
1113  value, aHashStrTable[nPos].release()) );
1114  }
1115 #endif
1116  }
1117  break;
1118  case SwFieldIds::GetExp:
1119  case SwFieldIds::SetExp:
1120  {
1121  if( nsSwGetSetExpType::GSE_STRING & pField->GetSubType() ) // replace String
1122  {
1123  if( SwFieldIds::GetExp == nWhich )
1124  {
1125  SwGetExpField* pGField = const_cast<SwGetExpField*>(static_cast<const SwGetExpField*>(pField));
1126 
1127  if( (!pUpdateField || pUpdateField == pTextField )
1128  && pGField->IsInBodyText() )
1129  {
1130  OUString aNew = LookString( aHashStrTable, pGField->GetFormula() );
1131  pGField->ChgExpStr( aNew, pLayout );
1132  }
1133  }
1134  else
1135  {
1136  SwSetExpField* pSField = const_cast<SwSetExpField*>(static_cast<const SwSetExpField*>(pField));
1137  // is the "formula" a field?
1138  OUString aNew = LookString( aHashStrTable, pSField->GetFormula() );
1139 
1140  if( aNew.isEmpty() ) // nothing found then the formula is the new value
1141  aNew = pSField->GetFormula();
1142 
1143  // only update one field
1144  if( !pUpdateField || pUpdateField == pTextField )
1145  pSField->ChgExpStr( aNew, pLayout );
1146 
1147  // lookup the field's name
1148  aNew = static_cast<SwSetExpFieldType*>(pSField->GetTyp())->GetSetRefName();
1149  // Entry present?
1150  sal_uInt16 nPos;
1151  HashStr* pFnd = aHashStrTable.Find( aNew, &nPos );
1152  if( pFnd )
1153  // Modify entry in the hash table
1154  pFnd->aSetStr = pSField->GetExpStr(pLayout);
1155  else
1156  {
1157  // insert new entry
1158  aHashStrTable[nPos].reset( new HashStr( aNew,
1159  pSField->GetExpStr(pLayout),
1160  aHashStrTable[nPos].release() ) );
1161  pFnd = aHashStrTable[nPos].get();
1162  }
1163 
1164  // Extension for calculation with Strings
1165  SwSbxValue aValue;
1166  aValue.PutString( pFnd->aSetStr );
1167  aCalc.VarChange( aNew, aValue );
1168  }
1169  }
1170  else // recalculate formula
1171  {
1172  if( SwFieldIds::GetExp == nWhich )
1173  {
1174  SwGetExpField* pGField = const_cast<SwGetExpField*>(static_cast<const SwGetExpField*>(pField));
1175 
1176  if( (!pUpdateField || pUpdateField == pTextField )
1177  && pGField->IsInBodyText() )
1178  {
1179  SwSbxValue aValue = aCalc.Calculate(
1180  pGField->GetFormula());
1181  if(!aValue.IsVoidValue())
1182  pGField->SetValue(aValue.GetDouble(), pLayout);
1183  }
1184  }
1185  else
1186  {
1187  SwSetExpField* pSField = const_cast<SwSetExpField*>(static_cast<const SwSetExpField*>(pField));
1188  SwSetExpFieldType* pSFieldTyp = static_cast<SwSetExpFieldType*>(pField->GetTyp());
1189  OUString aNew = pSFieldTyp->GetName();
1190 
1191  SwNode* pSeqNd = nullptr;
1192 
1193  if( pSField->IsSequenceField() )
1194  {
1195  const sal_uInt8 nLvl = pSFieldTyp->GetOutlineLvl();
1196  if( MAXLEVEL > nLvl )
1197  {
1198  // test if the Number needs to be updated
1199  pSeqNd = m_rDoc.GetNodes()[ it->GetNode() ];
1200 
1201  const SwTextNode* pOutlNd = pSeqNd->
1202  FindOutlineNodeOfLevel(nLvl, pLayout);
1203  auto const iter(SetExpOutlineNodeMap.find(pSFieldTyp));
1204  if (iter == SetExpOutlineNodeMap.end()
1205  || iter->second != pOutlNd)
1206  {
1207  SetExpOutlineNodeMap[pSFieldTyp] = pOutlNd;
1208  aCalc.VarChange( aNew, 0 );
1209  }
1210  }
1211  }
1212 
1213  aNew += "=" + pSField->GetFormula();
1214 
1215  SwSbxValue aValue = aCalc.Calculate( aNew );
1216  if (!aCalc.IsCalcError())
1217  {
1218  double nErg = aValue.GetDouble();
1219  // only update one field
1220  if( !aValue.IsVoidValue() && (!pUpdateField || pUpdateField == pTextField) )
1221  {
1222  pSField->SetValue(nErg, pLayout);
1223 
1224  if( pSeqNd )
1225  pSFieldTyp->SetChapter(*pSField, *pSeqNd, pLayout);
1226  }
1227  }
1228  }
1229  }
1230  }
1231  break;
1232  default: break;
1233  } // switch
1234 
1235  {
1236  // avoid calling ReplaceText() for input fields, it is pointless
1237  // here and moves the cursor if it's inside the field ...
1238  SwTextInputField *const pInputField(
1239  pUpdateField == pTextField // ... except once, when the dialog
1240  ? nullptr // is used to change content via UpdateOneField()
1241  : dynamic_cast<SwTextInputField *>(pTextField));
1242  if (pInputField)
1243  {
1244  bool const tmp = pInputField->LockNotifyContentChange();
1245  (void) tmp;
1246  assert(tmp && "should not be locked here?");
1247  }
1248  ::comphelper::ScopeGuard g([pInputField]()
1249  {
1250  if (pInputField)
1251  {
1252  pInputField->UnlockNotifyContentChange();
1253  }
1254  });
1255  pFormatField->UpdateTextNode(nullptr, nullptr); // trigger formatting
1256  }
1257 
1258  if (pUpdateField == pTextField) // if only this one is updated
1259  {
1260  if( SwFieldIds::GetExp == nWhich || // only GetField or
1261  SwFieldIds::HiddenText == nWhich || // HiddenText?
1262  SwFieldIds::HiddenPara == nWhich) // HiddenParaField?
1263  break; // quit
1264  pUpdateField = nullptr; // update all from here on
1265  }
1266  }
1267 
1268 #if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
1269  pMgr->CloseAll(false);
1270 #endif
1271 }
1272 
1275 {
1276  SwCalc* pCalc = nullptr;
1277  for( SwFieldTypes::size_type i = INIT_FLDTYPES; i < mpFieldTypes->size(); ++i )
1278  {
1279  const SwFieldType* pFieldType = (*mpFieldTypes)[i].get();
1280  if( SwFieldIds::User == pFieldType->Which() )
1281  {
1282  if( !pCalc )
1283  pCalc = new SwCalc( m_rDoc );
1284  const_cast<SwUserFieldType*>(static_cast<const SwUserFieldType*>(pFieldType))->GetValue( *pCalc );
1285  }
1286  }
1287 
1288  if( pCalc )
1289  {
1290  delete pCalc;
1292  }
1293 }
1294 
1296 {
1297  sal_Int32 nRecords = 1;
1298 
1299  mpUpdateFields->MakeFieldList( m_rDoc, true, GETFLD_ALL );
1300  if (mpUpdateFields->GetSortList()->empty())
1301  return nRecords;
1302 
1303  for (std::unique_ptr<SetGetExpField> const& it : *mpUpdateFields->GetSortList())
1304  {
1305  const SwTextField *pTextField = it->GetTextField();
1306  if( !pTextField )
1307  continue;
1308 
1309  const SwFormatField &pFormatField = pTextField->GetFormatField();
1310  const SwField* pField = pFormatField.GetField();
1311 
1312  switch( pField->GetTyp()->Which() )
1313  {
1314  case SwFieldIds::DbNextSet:
1315  case SwFieldIds::DbNumSet:
1316  nRecords++;
1317  break;
1318  default:
1319  break;
1320  }
1321  }
1322 
1323  return nRecords;
1324 }
1325 
1327 {
1328  for( SwFieldTypes::size_type i = 0; i < INIT_FLDTYPES; ++i )
1329  {
1330  SwFieldType* pFieldType = (*mpFieldTypes)[ i ].get();
1331  switch( pFieldType->Which() )
1332  {
1334  case SwFieldIds::Chapter:
1335  case SwFieldIds::GetExp:
1337  pFieldType->CallSwClientNotify(sw::LegacyModifyHint(nullptr, pMsgHint));
1338  break;
1339  case SwFieldIds::DocStat:
1340  pFieldType->CallSwClientNotify(sw::LegacyModifyHint(nullptr, nullptr));
1341  break;
1342  default: break;
1343  }
1344  }
1345  SetNewFieldLst(true);
1346 }
1347 
1349 {
1350  ++mnLockExpField;
1351 }
1352 
1354 {
1355  assert(mnLockExpField != 0);
1356  if( mnLockExpField )
1357  --mnLockExpField;
1358 }
1359 
1361 {
1362  return 0 != mnLockExpField;
1363 }
1364 
1366 {
1367  return *mpUpdateFields;
1368 }
1369 
1371 {
1372  // See if the supplied nodes actually contain fields.
1373  // If they don't, the flag doesn't need to be changed.
1374  bool bFieldsFnd = false;
1375  if( b && pChk && !GetUpdateFields().IsFieldsDirty() && !m_rDoc.IsInDtor()
1376  // ?? what's up with Undo, this is also wanted there!
1377  /*&& &pChk->GetNodes() == &GetNodes()*/ )
1378  {
1379  b = false;
1380  if( !nLen )
1381  ++nLen;
1382  SwNodeOffset nStt = pChk->GetIndex();
1383  const SwNodes& rNds = pChk->GetNodes();
1384  while( nLen-- )
1385  {
1386  const SwTextNode* pTNd = rNds[ nStt++ ]->GetTextNode();
1387  if( pTNd )
1388  {
1389  if( pTNd->GetAttrOutlineLevel() != 0 )
1390  // update chapter fields
1391  b = true;
1392  else if( pTNd->GetpSwpHints() && pTNd->GetSwpHints().Count() )
1393  {
1394  const size_t nEnd = pTNd->GetSwpHints().Count();
1395  for( size_t n = 0 ; n < nEnd; ++n )
1396  {
1397  const SwTextAttr* pAttr = pTNd->GetSwpHints().Get(n);
1398  if ( pAttr->Which() == RES_TXTATR_FIELD
1399  || pAttr->Which() == RES_TXTATR_INPUTFIELD)
1400  {
1401  b = true;
1402  break;
1403  }
1404  }
1405  }
1406 
1407  if( b )
1408  break;
1409  }
1410  }
1411  bFieldsFnd = b;
1412  }
1414  return bFieldsFnd;
1415 }
1416 
1418 {
1419  bool bIsModified = m_rDoc.getIDocumentState().IsModified();
1420 
1421  sal_Int32 nDate;
1422  sal_Int64 nTime;
1423  if( pNewDateTime )
1424  {
1425  nDate = pNewDateTime->GetDate();
1426  nTime = pNewDateTime->GetTime();
1427  }
1428  else
1429  {
1430  DateTime aDateTime( DateTime::SYSTEM );
1431  nDate = aDateTime.GetDate();
1432  nTime = aDateTime.GetTime();
1433  }
1434 
1435  SwFieldIds const aTypes[] {
1436  /*0*/ SwFieldIds::DocInfo,
1437  /*1*/ SwFieldIds::Author,
1438  /*2*/ SwFieldIds::ExtUser,
1439  /*3*/ SwFieldIds::Filename,
1440  /*4*/ SwFieldIds::DateTime }; // MUST be at the end!
1441 
1442  for(SwFieldIds aType : aTypes)
1443  {
1444  std::vector<SwFormatField*> vFields;
1445  GetSysFieldType(aType)->GatherFields(vFields);
1446  for(auto pFormatField: vFields)
1447  {
1448  if (pFormatField->GetTextField())
1449  {
1450  bool bChgd = false;
1451  switch( aType )
1452  {
1453  case SwFieldIds::DocInfo:
1454  if( static_cast<SwDocInfoField*>(pFormatField->GetField())->IsFixed() )
1455  {
1456  bChgd = true;
1457  SwDocInfoField* pDocInfField = static_cast<SwDocInfoField*>(pFormatField->GetField());
1458  pDocInfField->SetExpansion( static_cast<SwDocInfoFieldType*>(
1459  pDocInfField->GetTyp())->Expand(
1460  pDocInfField->GetSubType(),
1461  pDocInfField->GetFormat(),
1462  pDocInfField->GetLanguage(),
1463  pDocInfField->GetName() ) );
1464  }
1465  break;
1466 
1467  case SwFieldIds::Author:
1468  if( static_cast<SwAuthorField*>(pFormatField->GetField())->IsFixed() )
1469  {
1470  bChgd = true;
1471  SwAuthorField* pAuthorField = static_cast<SwAuthorField*>(pFormatField->GetField());
1472  pAuthorField->SetExpansion( SwAuthorFieldType::Expand( pAuthorField->GetFormat() ) );
1473  }
1474  break;
1475 
1476  case SwFieldIds::ExtUser:
1477  if( static_cast<SwExtUserField*>(pFormatField->GetField())->IsFixed() )
1478  {
1479  bChgd = true;
1480  SwExtUserField* pExtUserField = static_cast<SwExtUserField*>(pFormatField->GetField());
1481  pExtUserField->SetExpansion( SwExtUserFieldType::Expand(pExtUserField->GetSubType()) );
1482  }
1483  break;
1484 
1485  case SwFieldIds::DateTime:
1486  if( static_cast<SwDateTimeField*>(pFormatField->GetField())->IsFixed() )
1487  {
1488  bChgd = true;
1489  static_cast<SwDateTimeField*>(pFormatField->GetField())->SetDateTime(
1490  DateTime(Date(nDate), tools::Time(nTime)) );
1491  }
1492  break;
1493 
1494  case SwFieldIds::Filename:
1495  if( static_cast<SwFileNameField*>(pFormatField->GetField())->IsFixed() )
1496  {
1497  bChgd = true;
1498  SwFileNameField* pFileNameField =
1499  static_cast<SwFileNameField*>(pFormatField->GetField());
1500  pFileNameField->SetExpansion( static_cast<SwFileNameFieldType*>(
1501  pFileNameField->GetTyp())->Expand(
1502  pFileNameField->GetFormat() ) );
1503  }
1504  break;
1505  default: break;
1506  }
1507 
1508  // Trigger formatting
1509  if( bChgd )
1510  pFormatField->UpdateTextNode(nullptr, nullptr);
1511  }
1512  }
1513  }
1514 
1515  if( !bIsModified )
1517 }
1518 
1520  const SetGetExpField& rToThisField, SwRootFrame const*const pLayout)
1521 {
1522  // create the sorted list of all SetFields
1523  mpUpdateFields->MakeFieldList( m_rDoc, mbNewFieldLst, GETFLD_CALC );
1524  mbNewFieldLst = false;
1525 
1526 #if !HAVE_FEATURE_DBCONNECTIVITY || ENABLE_FUZZERS
1527  SwDBManager* pMgr = NULL;
1528 #else
1529  SwDBManager* pMgr = m_rDoc.GetDBManager();
1530  pMgr->CloseAll(false);
1531 #endif
1532 
1533  if (!mpUpdateFields->GetSortList()->empty())
1534  {
1535  SetGetExpFields::const_iterator const itLast =
1536  mpUpdateFields->GetSortList()->upper_bound(
1537  &rToThisField);
1538  for (auto it = mpUpdateFields->GetSortList()->begin(); it != itLast; ++it)
1539  {
1540  lcl_CalcField(m_rDoc, rCalc, **it, pMgr, pLayout);
1541  }
1542  }
1543 #if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
1544  pMgr->CloseAll(false);
1545 #endif
1546 }
1547 
1549  SwNodeOffset const nLastNd, sal_Int32 const nLastCnt)
1550 {
1551  // create the sorted list of all SetFields
1552  mpUpdateFields->MakeFieldList( m_rDoc, mbNewFieldLst, GETFLD_CALC );
1553  mbNewFieldLst = false;
1554 
1555 #if !HAVE_FEATURE_DBCONNECTIVITY || ENABLE_FUZZERS
1556  SwDBManager* pMgr = NULL;
1557 #else
1558  SwDBManager* pMgr = m_rDoc.GetDBManager();
1559  pMgr->CloseAll(false);
1560 #endif
1561 
1562  SwRootFrame const* pLayout(nullptr);
1563  SwRootFrame const* pLayoutRLHidden(nullptr);
1564  for (SwRootFrame const*const pLay : m_rDoc.GetAllLayouts())
1565  {
1566  if (pLay->IsHideRedlines())
1567  {
1568  pLayoutRLHidden = pLay;
1569  }
1570  else
1571  {
1572  pLayout = pLay;
1573  }
1574  }
1575 
1576  // note this is not duplicate of the other FieldsToCalc because there is
1577  // (currently) no SetGetExpField that compares only a position
1578  for(auto it = mpUpdateFields->GetSortList()->begin();
1579  it != mpUpdateFields->GetSortList()->end() &&
1580  ( (*it)->GetNode() < nLastNd ||
1581  ( (*it)->GetNode() == nLastNd && (*it)->GetContent() <= nLastCnt )
1582  );
1583  ++it )
1584  {
1585  if (pLayout || !pLayoutRLHidden) // always calc *something*...
1586  {
1587  lcl_CalcField( m_rDoc, rCalc, **it, pMgr, pLayout );
1588  }
1589  if (pLayoutRLHidden)
1590  {
1591  lcl_CalcField( m_rDoc, rCalc, **it, pMgr, pLayoutRLHidden );
1592  }
1593  }
1594 
1595 #if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
1596  pMgr->CloseAll(false);
1597 #endif
1598 }
1599 
1601  const SetGetExpField& rToThisField, SwRootFrame const& rLayout)
1602 {
1603  // create the sorted list of all SetFields
1604  mpUpdateFields->MakeFieldList( m_rDoc, mbNewFieldLst, GETFLD_EXPAND );
1605  mbNewFieldLst = false;
1606 
1608 
1609  // Hash table for all string replacements is filled on-the-fly.
1610  // Try to fabricate an uneven number.
1611  sal_uInt16 nTableSize = ((mpUpdateFields->GetSortList()->size() / 7) + 1) * 7;
1612  rHashTable.resize(nTableSize);
1613 
1614  SetGetExpFields::const_iterator const itLast =
1615  mpUpdateFields->GetSortList()->upper_bound(&rToThisField);
1616 
1617  for (auto it = mpUpdateFields->GetSortList()->begin(); it != itLast; ++it)
1618  {
1619  const SwTextField* pTextField = (*it)->GetTextField();
1620  if( !pTextField )
1621  continue;
1622 
1623  if (rLayout.IsHideRedlines()
1624  && IsFieldDeleted(rIDRA, rLayout, *pTextField))
1625  {
1626  continue;
1627  }
1628 
1629  const SwField* pField = pTextField->GetFormatField().GetField();
1630  switch( pField->GetTyp()->Which() )
1631  {
1632  case SwFieldIds::SetExp:
1633  if( nsSwGetSetExpType::GSE_STRING & pField->GetSubType() )
1634  {
1635  // set the new value in the hash table
1636  // is the formula a field?
1637  SwSetExpField* pSField = const_cast<SwSetExpField*>(static_cast<const SwSetExpField*>(pField));
1638  OUString aNew = LookString( rHashTable, pSField->GetFormula() );
1639 
1640  if( aNew.isEmpty() ) // nothing found, then the formula is
1641  aNew = pSField->GetFormula(); // the new value
1642 
1643  // #i3141# - update expression of field as in method
1644  // <SwDoc::UpdateExpFields(..)> for string/text fields
1645  pSField->ChgExpStr(aNew, &rLayout);
1646 
1647  // look up the field's name
1648  aNew = static_cast<SwSetExpFieldType*>(pSField->GetTyp())->GetSetRefName();
1649  // Entry present?
1650  sal_uInt16 nPos;
1651  SwHash* pFnd = rHashTable.Find( aNew, &nPos );
1652  if( pFnd )
1653  // modify entry in the hash table
1654  static_cast<HashStr*>(pFnd)->aSetStr = pSField->GetExpStr(&rLayout);
1655  else
1656  // insert the new entry
1657  rHashTable[nPos].reset( new HashStr( aNew,
1658  pSField->GetExpStr(&rLayout), rHashTable[nPos].release()));
1659  }
1660  break;
1661  case SwFieldIds::Database:
1662  {
1663  const OUString& rName = pField->GetTyp()->GetName();
1664 
1665  // Insert entry in the hash table
1666  // Entry present?
1667  sal_uInt16 nPos;
1668  HashStr* pFnd = rHashTable.Find( rName, &nPos );
1669  OUString const value(pField->ExpandField(m_rDoc.IsClipBoard(), nullptr));
1670  if( pFnd )
1671  {
1672  // modify entry in the hash table
1673  pFnd->aSetStr = value;
1674  }
1675  else
1676  {
1677  // insert the new entry
1678  rHashTable[nPos].reset( new HashStr( rName,
1679  value, rHashTable[nPos].release()) );
1680  }
1681  }
1682  break;
1683  default: break;
1684  }
1685  }
1686 }
1687 
1688 
1690 {
1691  return mbNewFieldLst;
1692 }
1693 
1695 {
1696  mbNewFieldLst = bFlag;
1697 }
1698 
1700 {
1701  if (!mbNewFieldLst && !m_rDoc.IsInDtor())
1702  mpUpdateFields->InsDelFieldInFieldLst( bIns, rField );
1703 }
1704 
1706 {
1707  SwTextField * const pAttr = GetTextFieldAtPos(rPos);
1708 
1709  return pAttr ? const_cast<SwField *>( pAttr->GetFormatField().GetField() ) : nullptr;
1710 }
1711 
1713 {
1714  SwTextNode * const pNode = rPos.nNode.GetNode().GetTextNode();
1715 
1716  return (pNode != nullptr)
1717  ? pNode->GetFieldTextAttrAt( rPos.nContent.GetIndex(), true )
1718  : nullptr;
1719 }
1720 
1724 {
1725  std::vector<SwFormatField*> vFields;
1726  for (auto const& pFieldType: *mpFieldTypes)
1727  {
1728  pFieldType->GatherFields(vFields);
1729  if(vFields.size()>0)
1730  return true;
1731  }
1732  return false;
1733 }
1734 
1737 {
1738  for( auto n = mpFieldTypes->size(); n > INIT_FLDTYPES; )
1739  if( !(*mpFieldTypes)[ --n ]->HasWriterListeners() )
1740  RemoveFieldType( n );
1741 }
1742 
1743 void DocumentFieldsManager::InitFieldTypes() // is being called by the CTOR
1744 {
1745  // Field types
1746  mpFieldTypes->emplace_back( new SwDateTimeFieldType(&m_rDoc) );
1747  mpFieldTypes->emplace_back( new SwChapterFieldType );
1748  mpFieldTypes->emplace_back( new SwPageNumberFieldType );
1749  mpFieldTypes->emplace_back( new SwAuthorFieldType );
1750  mpFieldTypes->emplace_back( new SwFileNameFieldType(m_rDoc) );
1751  mpFieldTypes->emplace_back( new SwDBNameFieldType(&m_rDoc) );
1752  mpFieldTypes->emplace_back( new SwGetExpFieldType(&m_rDoc) );
1753  mpFieldTypes->emplace_back( new SwGetRefFieldType(m_rDoc) );
1754  mpFieldTypes->emplace_back( new SwHiddenTextFieldType );
1755  mpFieldTypes->emplace_back( new SwPostItFieldType(m_rDoc) );
1756  mpFieldTypes->emplace_back( new SwDocStatFieldType(m_rDoc) );
1757  mpFieldTypes->emplace_back( new SwDocInfoFieldType(&m_rDoc) );
1758  mpFieldTypes->emplace_back( new SwInputFieldType( &m_rDoc ) );
1759  mpFieldTypes->emplace_back( new SwTableFieldType( &m_rDoc ) );
1760  mpFieldTypes->emplace_back( new SwMacroFieldType(m_rDoc) );
1761  mpFieldTypes->emplace_back( new SwHiddenParaFieldType );
1762  mpFieldTypes->emplace_back( new SwDBNextSetFieldType );
1763  mpFieldTypes->emplace_back( new SwDBNumSetFieldType );
1764  mpFieldTypes->emplace_back( new SwDBSetNumberFieldType );
1765  mpFieldTypes->emplace_back( new SwTemplNameFieldType(m_rDoc) );
1766  mpFieldTypes->emplace_back( new SwTemplNameFieldType(m_rDoc) );
1767  mpFieldTypes->emplace_back( new SwExtUserFieldType );
1768  mpFieldTypes->emplace_back( new SwRefPageSetFieldType );
1769  mpFieldTypes->emplace_back( new SwRefPageGetFieldType(m_rDoc) );
1770  mpFieldTypes->emplace_back( new SwJumpEditFieldType(m_rDoc) );
1771  mpFieldTypes->emplace_back( new SwScriptFieldType(m_rDoc) );
1772  mpFieldTypes->emplace_back( new SwCombinedCharFieldType );
1773  mpFieldTypes->emplace_back( new SwDropDownFieldType );
1774 
1775  // Types have to be at the end!
1776  // We expect this in the InsertFieldType!
1777  // MIB 14.04.95: In Sw3StringPool::Setup (sw3imp.cxx) and
1778  // lcl_sw3io_InSetExpField (sw3field.cxx) now also
1779  mpFieldTypes->emplace_back( new SwSetExpFieldType(&m_rDoc,
1780  SwResId(STR_POOLCOLL_LABEL_ABB), nsSwGetSetExpType::GSE_SEQ) );
1781  mpFieldTypes->emplace_back( new SwSetExpFieldType(&m_rDoc,
1782  SwResId(STR_POOLCOLL_LABEL_TABLE), nsSwGetSetExpType::GSE_SEQ) );
1783  mpFieldTypes->emplace_back( new SwSetExpFieldType(&m_rDoc,
1784  SwResId(STR_POOLCOLL_LABEL_FRAME), nsSwGetSetExpType::GSE_SEQ) );
1785  mpFieldTypes->emplace_back( new SwSetExpFieldType(&m_rDoc,
1786  SwResId(STR_POOLCOLL_LABEL_DRAWING), nsSwGetSetExpType::GSE_SEQ) );
1787  mpFieldTypes->emplace_back( new SwSetExpFieldType(&m_rDoc,
1788  SwResId(STR_POOLCOLL_LABEL_FIGURE), nsSwGetSetExpType::GSE_SEQ) );
1789 
1790  assert( mpFieldTypes->size() == INIT_FLDTYPES );
1791 }
1792 
1794 {
1795  mpFieldTypes->erase( mpFieldTypes->begin() + INIT_FLDTYPES, mpFieldTypes->end() );
1796 }
1797 
1799 {
1800 #if !HAVE_FEATURE_DBCONNECTIVITY || ENABLE_FUZZERS
1801  (void) rDBField;
1802  (void) rCalc;
1803 #else
1804  SwDBManager* pMgr = m_rDoc.GetDBManager();
1805 
1806  SwFieldIds nFieldType = rDBField.Which();
1807 
1808  bool bPar1 = rCalc.Calculate( rDBField.GetPar1() ).GetBool();
1809 
1810  if( SwFieldIds::DbNextSet == nFieldType )
1811  static_cast<SwDBNextSetField&>(rDBField).SetCondValid( bPar1 );
1812  else
1813  static_cast<SwDBNumSetField&>(rDBField).SetCondValid( bPar1 );
1814 
1815  if( !rDBField.GetRealDBData().sDataSource.isEmpty() )
1816  {
1817  // Edit a certain database
1818  if( SwFieldIds::DbNextSet == nFieldType )
1819  static_cast<SwDBNextSetField&>(rDBField).Evaluate(m_rDoc);
1820  else
1821  static_cast<SwDBNumSetField&>(rDBField).Evaluate(m_rDoc);
1822 
1823  SwDBData aTmpDBData( rDBField.GetDBData(&m_rDoc) );
1824 
1825  if( pMgr->OpenDataSource( aTmpDBData.sDataSource, aTmpDBData.sCommand ))
1826  rCalc.VarChange( lcl_GetDBVarName( m_rDoc, rDBField),
1827  pMgr->GetSelectedRecordId(aTmpDBData.sDataSource, aTmpDBData.sCommand, aTmpDBData.nCommandType) );
1828  }
1829  else
1830  {
1831  OSL_FAIL("TODO: what should happen with unnamed DBFields?");
1832  }
1833 #endif
1834 }
1835 
1837 {
1838  mpUpdateFields.reset();
1839  mpFieldTypes.reset();
1840 }
1841 
1842 }
1843 
1844 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool UpdateField(SwTextField *rDstFormatField, SwField &rSrcField, SwMsgPoolItem *pMsgHint, bool bUpdateTableFields) override
Updates a field.
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:242
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:686
void SetValue(bool bHidden)
Definition: docufld.hxx:331
Base class of the Writer layout elements.
Definition: frame.hxx:315
const ::utl::TransliterationWrapper & GetAppCmpStrIgnore()
Definition: init.cxx:783
bool CalcWithStackOverflow()
Definition: cellfml.cxx:287
std::unique_ptr< SwFieldTypes > mpFieldTypes
virtual sal_uInt16 GetSubType() const override
Definition: tblcalc.cxx:118
Definition: calc.hxx:192
Definition: calc.hxx:132
void ChgValue(double d, bool bVal)
For calculations in expressions.
Definition: dbfld.cxx:237
bool IsCondValid() const
Definition: dbfld.hxx:182
virtual void UpdateExpFields(SwTextField *pField, bool bUpdateRefFields) override
bool IsUsed(const sw::BroadcastingModify &) const
Definition: poolfmt.cxx:86
sal_Int32 nCommandType
Definition: swdbdata.hxx:32
void CalcField(SwTableCalcPara &rCalcPara)
Definition: tblcalc.cxx:43
The shared part of a user field.
Definition: usrfld.hxx:34
constexpr TypedWhichId< SwTableFormulaUpdate > RES_TABLEFML_UPDATE(170)
void ChgDBData(const SwDBData &rNewData)
Definition: doc.cxx:453
Marks a position in the document model.
Definition: pam.hxx:36
virtual bool IsNewFieldLst() const override
virtual void UpdateRefFields() override
Update reference and table fields.
const SwField * GetField() const
Definition: fmtfld.hxx:116
LanguageType GetLanguage() const
Language at field position.
Definition: fldbas.hxx:406
virtual void LockExpFields() override
constexpr TypedWhichId< SwTableBoxNumFormat > RES_BOXATR_FORMAT(RES_BOXATR_BEGIN)
virtual void SetNewFieldLst(bool bFlag) override
virtual SwFieldType * InsertFieldType(const SwFieldType &) override
Insert field types.
sal_uInt32 GetFormat() const
Query parameters for dialog and for BASIC.
Definition: fldbas.hxx:401
SwpHints * GetpSwpHints()
Definition: ndtxt.hxx:226
virtual sal_uInt16 GetSubType() const override
Definition: docufld.cxx:2019
SvNumberFormatter * GetNumberFormatter(bool bCreate=true)
Definition: doc.hxx:1411
void TriggerNodeUpdate(const sw::LegacyModifyHint &)
for hanging TextFormatCollections somewhere else (Outline-Numbering!)
Definition: ndtxt.cxx:5209
SwNodeOffset StartOfSectionIndex() const
Definition: node.hxx:677
void ChgExpStr(const OUString &rExpand, SwRootFrame const *pLayout)
Definition: expfld.cxx:541
SwNodeIndex nNode
Definition: pam.hxx:38
LanguageType getLanguageType(bool bResolveSystem=true) const
virtual std::unique_ptr< SwFieldType > Copy() const =0
const int GETFLD_ALL
Definition: docfld.hxx:134
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
bool OpenDataSource(const OUString &rDataSource, const OUString &rTableOrQuery)
open the source while fields are updated - for the calculator only!
Definition: dbmgr.cxx:2285
virtual void SetModified()=0
Must be called manually at changes of format.
bool IsInitialized() const
Definition: dbfld.hxx:95
OUString sDataSource
Definition: swdbdata.hxx:30
virtual void SetValue(const double &rVal) override
Definition: expfld.cxx:939
const OUString & GetExpStr(SwRootFrame const *pLayout) const
Definition: expfld.cxx:536
Base class of all fields.
Definition: fldbas.hxx:293
bool IsCalcError() const
Definition: calc.hxx:247
virtual void SetFixFields(const DateTime *pNewDateTime) override
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1210
OUString LookString(SwHashTable< HashStr > const &rTable, std::u16string_view rName)
Look up the Name, if it is present, return its String, otherwise return an empty String.
Definition: docfld.cxx:362
sal_Int64 n
Definition: doc.hxx:188
constexpr sal_uInt16 RES_BOXATR_END(153)
constexpr sal_uInt8 MAXLEVEL
Definition: swtypes.hxx:93
std::unique_ptr< SwField > CopyField() const
Definition: fldbas.cxx:495
virtual bool SetFieldsDirty(bool b, const SwNode *pChk, SwNodeOffset nLen) override
sal_Int32 GetLong() const
SwNode & GetNode() const
Definition: ndindex.hxx:121
SwTextNode * GetpTextNode() const
Definition: txtfld.hxx:49
const SwDBData & GetDBData() const
Definition: dbfld.hxx:128
static SwField * GetFieldAtPos(const SwPosition &rPos)
Returns the field at a certain position.
Dialog to specify the properties of date form field.
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:144
const OUString & GetName() const
Definition: docufld.hxx:538
sal_uInt16 Which() const
Definition: txatbase.hxx:114
static const OUString & GetTypeStr(SwFieldTypesEnum nTypeId)
Definition: fldbas.cxx:122
bool HasWriterListeners() const
Definition: calbck.hxx:203
The root element of a Writer document layout.
Definition: rootfrm.hxx:82
For old documents the Field-Which IDs must be preserved !!!
bool IsCondHidden() const
Definition: section.hxx:192
virtual void UpdatePageFields(SfxPoolItem *) override
int GetAttrOutlineLevel() const
Returns outline level of this text node.
Definition: ndtxt.cxx:3983
OUString const & GetCondition() const
Definition: section.hxx:198
static LanguageType nLang
Definition: srtdlg.cxx:51
void GatherFields(std::vector< SwFormatField * > &rvFormatFields, bool bCollectOnlyInDocNodes=true) const
Definition: fldbas.cxx:208
Array of Undo-history.
Definition: docary.hxx:192
void UpdateFields() const
Definition: fldbas.cxx:149
void SetChapter(SwSetExpField &rField, const SwNode &rNd, SwRootFrame const *pLayout)
Definition: expfld.cxx:643
void UpdateExpFieldsImpl(SwTextField *pField, SwRootFrame const *pLayout)
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:165
virtual OUString GetPar1() const
Definition: fldbas.cxx:326
SwDoc & m_rDoc
Definition: docbm.cxx:1204
virtual const OUString & GetHideCondition() const =0
const LocaleDataWrapper & GetLocaleData() const
return NULL
void BoxNmToPtr(const SwTable *pTable)
create from the external formula the internal
Definition: cellfml.cxx:605
SwIndex nContent
Definition: pam.hxx:39
void VarChange(const OUString &rStr, const SwSbxValue &rValue)
Definition: calc.cxx:590
virtual void UpdateFields(bool bCloseDB) override
size_t pos
SwSectionNode * GetSectionNode()
Definition: section.cxx:952
void ChgExpStr(const OUString &rExpand, SwRootFrame const *pLayout)
Definition: expfld.cxx:297
A wrapper around SfxPoolItem to store the start position of (usually) a text portion, with an optional end.
Definition: txatbase.hxx:41
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId)
Definition: fldbas.cxx:369
virtual sal_uInt16 GetSubType() const override
Definition: docufld.cxx:1135
const SwTable * m_pTable
Pointer to the current table.
Definition: hints.hxx:261
sal_Int32 GetStart() const
Definition: txatbase.hxx:86
Field type for dropdown boxes.
Definition: flddropdown.hxx:31
virtual void UpdateTableFields(SfxPoolItem *pHt) override
void SetField(std::unique_ptr< SwField > pField)
Sets current field.
Definition: atrfld.cxx:175
virtual void SetValue(const double &rVal) override
Definition: expfld.cxx:902
void SetExpansion(const OUString &rStr)
Definition: docufld.hxx:198
const SwTable & GetTable() const
Definition: node.hxx:500
virtual bool IsExpFieldsLocked() const override
Implementation in tblcalc.cxx.
Definition: expfld.hxx:368
sal_Int32 GetDate() const
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:195
o3tl::sorted_vector< SwRootFrame * > GetAllLayouts()
Definition: doclay.cxx:1670
virtual OUString GetName() const override
virtual void FieldsToCalc(SwCalc &rCalc, SwNodeOffset nLastNd, sal_Int32 nLastCnt) override
virtual bool DoesUndo() const =0
Is Undo enabled?
void SetExpansion(const OUString &rStr)
Definition: docufld.hxx:540
virtual SwDocUpdateField & GetUpdateFields() const override
const SwGetSetExpType GSE_EXPR
Expression.
Definition: fldbas.hxx:205
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhichId) const
Definition: fldbas.cxx:356
void PtrToBoxNm(const SwTable *pTable)
create from the internal formula (for CORE) the external formula (for UI)
Definition: cellfml.cxx:580
#define INIT_SEQ_FLDTYPES
Definition: swtypes.hxx:110
static SwTextField * GetTextFieldAtPos(const SwPosition &rPos)
Returns the field at a certain position.
virtual OUString GetPar1() const override
Query, set condition.
Definition: docufld.cxx:1705
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:161
virtual void RemoveFieldType(size_t nField) override
Remove field type.
SwSbxValue nValue
Definition: calc.hxx:142
double GetDouble() const
Definition: calc.cxx:1452
virtual void Hide(bool hide)=0
virtual void AppendUndo(std::unique_ptr< SwUndo > pUndo)=0
Add new Undo action.
constexpr TypedWhichId< SwFormatField > RES_TXTATR_FIELD(RES_TXTATR_NOEND_BEGIN)
Style of a layout element.
Definition: frmfmt.hxx:59
size_t Count() const
Definition: ndhints.hxx:142
void SetExpansion(const OUString &rStr)
Definition: docufld.hxx:224
SwTextAttr * Get(size_t nPos) const
Definition: ndhints.hxx:144
SwDBData const & GetDBData()
Definition: docfld.cxx:371
int i
const SwExtendedSubType SUB_CMD
Show command.
Definition: fldbas.hxx:213
std::vector< SwSectionFormat * >::size_type size_type
Definition: docary.hxx:67
void SetCondHidden(bool const bFlag)
Definition: section.cxx:532
bool IsValid() const
Definition: cellfml.hxx:135
virtual ~DocumentFieldsManager() override
virtual bool IsModified() const =0
Changes of document?
bool IsSequenceField() const
Definition: expfld.hxx:269
void Evaluate(SwDoc &rDoc)
get current field value and cache it
Definition: docufld.cxx:1325
void Evaluate()
Get the evaluation via DBManager string.
Definition: dbfld.cxx:303
#define LANGUAGE_SYSTEM
SwContentNode * GetContentNode()
Definition: node.hxx:619
SwNodeOffset GetIndex() const
Definition: node.hxx:292
vector_type::size_type size_type
Definition: docary.hxx:223
SwFieldIds
Definition: fldbas.hxx:46
virtual void FieldsToExpand(SwHashTable< HashStr > &rTable, const SetGetExpField &rToThisField, SwRootFrame const &rLayout) override
bool IsVoidValue() const
Definition: calc.hxx:124
bool IsInBodyText() const
Called by formatting.
Definition: expfld.hxx:136
size_t size() const
Definition: docary.hxx:88
void CloseAll(bool bIncludingMerge=true)
close all data sources - after fields were updated
Definition: dbmgr.cxx:2398
virtual SwFieldType * GetFieldType(SwFieldIds nResId, const OUString &rName, bool bDbFieldMatching) const override
Find first type with ResId and name.
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:394
virtual OUString GetFormula() const override
Definition: fldbas.cxx:757
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
Definition: format.cxx:388
constexpr sal_uInt16 RES_BOXATR_BEGIN(RES_GRFATR_END)
double GetValue(SwCalc &rCalc)
Definition: usrfld.cxx:236
Marks a node in the document model.
Definition: ndindex.hxx:32
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:697
T * Find(const OUString &rStr, sal_uInt16 *pPos=nullptr) const
Definition: calc.hxx:160
SwpHints & GetSwpHints()
getters for SwpHints
Definition: ndtxt.hxx:822
SwTextField * GetFieldTextAttrAt(const sal_Int32 nIndex, const bool bIncludeInputFieldAtStart=false) const
Definition: ndtxt.cxx:1735
sal_uInt8 GetOutlineLvl() const
Definition: expfld.hxx:180
void InitContent()
Evaluation for header and footer.
Definition: dbfld.cxx:177
const SvXMLTokenMapEntry aTypes[]
#define DB_DELIM
Definition: swtypes.hxx:131
virtual sal_uInt16 GetSubType() const
Definition: fldbas.cxx:347
bool IsInReading() const
Definition: doc.hxx:954
virtual SwFieldType * GetSysFieldType(const SwFieldIds eWhich) const override
virtual void UnlockExpFields() override
SwFieldType * GetTyp() const
Definition: fldbas.hxx:396
virtual OUString GetName() const override
Only in derived classes.
Definition: expfld.cxx:531
SwSectionFormat * GetParent() const
Definition: section.hxx:356
virtual const SwRangeRedline * GetRedline(const SwPosition &rPos, SwRedlineTable::size_type *pFndPos) const =0
bool CalcHiddenFlag() const
Definition: section.cxx:332
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:450
void resize(size_t nSize)
Definition: calc.hxx:158
void UpdateDBNumFields(SwDBNameInfField &rDBField, SwCalc &rCalc)
bool FillCalcWithMergeData(SvNumberFormatter *pDocFormatter, LanguageType nLanguage, SwCalc &aCalc)
Definition: dbmgr.cxx:2101
Fields containing values that have to be formatted via number formatter.
Definition: fldbas.hxx:412
SwSbxValue Calculate(const OUString &rStr)
Definition: calc.cxx:356
const int GETFLD_EXPAND
Definition: docfld.hxx:136
#define INIT_FLDTYPES
Definition: swtypes.hxx:106
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
OUString ExpandField(bool bCached, SwRootFrame const *pLayout) const
expand the field.
Definition: fldbas.cxx:475
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:335
const SwGetSetExpType GSE_SEQ
Sequence.
Definition: fldbas.hxx:206
const SwStartNode * GetSttNd() const
Definition: swtable.hxx:464
const LanguageTag & getLanguageTag() const
SwFieldIds Which() const
ResId.
Definition: fldbas.cxx:255
OUString aSetStr
Definition: docfld.hxx:118
void ChgValid(bool bNew)
Definition: cellfml.hxx:136
void SetFieldsDirty(bool b)
Definition: docfld.hxx:172
virtual OUString GetName() const
Only in derived classes.
Definition: fldbas.cxx:137
sal_uInt32 GetSelectedRecordId(const OUString &rDataSource, const OUString &rTableOrQuery, sal_Int32 nCommandType=-1)
Definition: dbmgr.cxx:2353
bool IsFieldDeletedInModel(IDocumentRedlineAccess const &rIDRA, SwTextField const &rTextField)
SwTableNode * IsIdxInTable(const SwNodeIndex &rIdx)
Definition: ndtbl.cxx:213
unsigned char sal_uInt8
static OUString Expand(sal_uInt16 nSubType)
Definition: docufld.cxx:1962
virtual const SwFieldTypes * GetFieldTypes() const override
static OUString Expand(sal_uLong)
Definition: docufld.cxx:313
sal_Int32 GetIndex() const
Definition: index.hxx:91
bool PutString(const OUString &)
bool IsClipBoard() const
Definition: doc.hxx:963
SwNodes & GetNodes()
Definition: doc.hxx:409
constexpr TypedWhichId< SwTableBoxFormula > RES_BOXATR_FORMULA(151)
Item2Range GetItemSurrogates(sal_uInt16 nWhich) const
bool PutDouble(double)
void ClearInitialized()
Definition: dbfld.hxx:96
bool LockNotifyContentChange()
Definition: atrfld.cxx:647
void ToRelBoxNm(const SwTable *pTable)
create from the external/internal formula the relative formula
Definition: cellfml.cxx:630
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:411
bool GetBool() const
Definition: calc.cxx:1446
sal_Int64 GetTime() const
virtual sal_Int32 GetRecordsPerDocument() const override
Any value
bool IsHideRedlines() const
Replacement for sw::DocumentRedlineManager::GetRedlineFlags() (this is layout-level redline hiding)...
Definition: rootfrm.hxx:422
Get reference.
Definition: reffld.hxx:65
bool IsCondValid() const
Definition: dbfld.hxx:228
SwFrameFormat * ClaimFrameFormat()
Definition: swtable.cxx:1806
constexpr TypedWhichId< SwFormatField > RES_TXTATR_INPUTFIELD(55)
void SetExpansion(const OUString &rStr)
Definition: docufld.hxx:569
SwCalcExp * VarLook(const OUString &rStr, bool bIns=false)
Definition: calc.cxx:422
const SwDBData & GetRealDBData() const
DBName.
Definition: dbfld.hxx:135
virtual void CallSwClientNotify(const SfxHint &rHint) const override
Definition: calbck.cxx:326
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:357
bool IsDataSourceOpen(const OUString &rDataSource, const OUString &rTableOrQuery, bool bMergeShell)
check if a data source is open
Definition: dbmgr.cxx:1998
void UnlockNotifyContentChange()
Definition: atrfld.cxx:657
void Evaluate(const SwDoc &)
Definition: dbfld.cxx:809
bool IsInDtor() const
Definition: doc.hxx:404
const SwTextField * GetTextField() const
Definition: docfld.hxx:88
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc...
Definition: nodes.cxx:2330
const SwGetSetExpType GSE_STRING
String.
Definition: fldbas.hxx:204
void UpdateTextNode(const SfxPoolItem *pOld, const SfxPoolItem *pNew)
Definition: atrfld.cxx:292
virtual void PutValueToField(const SwPosition &rPos, const css::uno::Any &rVal, sal_uInt16 nWhich) override
Puts a value into a field at a certain position.
TableFormulaUpdateFlags m_eFlags
Definition: hints.hxx:268
std::unique_ptr< SwDocUpdateField > mpUpdateFields
SwTextNode & GetTextNode() const
Definition: txtfld.hxx:53
SwSection * GetSection() const
Definition: section.cxx:669
SwNode & GetEndOfExtras() const
This is the last EndNode of a special section.
Definition: ndarr.hxx:159
SwSectionFormats & GetSections()
Definition: doc.hxx:1338
void GCFieldTypes()
Remove all unreferenced field types of a document.
void SetHidden(bool bHidden)
Definition: docufld.hxx:375
const int GETFLD_CALC
Definition: docfld.hxx:135
SwFieldIds Which() const
Definition: fldbas.hxx:274
virtual double GetValue() const
Definition: fldbas.cxx:736
OUString sCommand
Definition: swdbdata.hxx:31
SwContentNode * GoNext(SwNodeIndex *) const
Definition: nodes.cxx:1299
sal_uInt16 Which() const
virtual void InsDeletedFieldType(SwFieldType &) override
T should be a subclass of SwHash.
Definition: calc.hxx:151
SwDBManager * GetDBManager() const
Definition: doc.hxx:670
sal_uInt16 nPos
virtual void InsDelFieldInFieldLst(bool bIns, const SwTextField &rField) override
std::vector< std::unique_ptr< SetGetExpField > >::const_iterator const_iterator
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1319
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:856
void SetCondition(OUString const &rNew)
Definition: section.hxx:199
sal_Int16 nValue
virtual OUString GetPar1() const override
Definition: docufld.cxx:1412
virtual void UpdateUsrFields() override
Insert field type that was marked as deleted.
virtual void ResetModified()=0
Base class of the Writer document model elements.
Definition: node.hxx:81
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo