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