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