20#include <config_features.h>
21#include <config_fuzzers.h>
58#include <osl/diagnose.h>
61#include <com/sun/star/uno/Any.hxx>
75 && pRedline->
GetType() == RedlineType::Delete
82#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
90 if( aDBData != aDocData )
93 + aDBData.sCommand + OUStringChar(
DB_DELIM);
107 rNode.GetNodes().GetEndOfExtras().GetIndex() < rNode.GetIndex());
108 if (!isInBody &&
nullptr == rNode.getLayoutFrame(&rLayout))
148 #if !HAVE_FEATURE_DBCONNECTIVITY || ENABLE_FUZZERS
151 switch( nFieldWhich )
161 rCalc.
VarChange( lcl_GetDBVarName( rDoc, *pDBField),
173 OUString sDBNumNm(lcl_GetDBVarName( rDoc, *pDBField));
210 const SwFieldTypes::size_type nSize =
mpFieldTypes->size();
215 switch( nFieldWhich )
230 OUString sFieldNm( rFieldTyp.
GetName() );
231 for( ;
i < nSize; ++
i )
239 for( ;
i < nSize; ++
i )
245 for(
i = 0;
i < nSize; ++
i )
250 std::unique_ptr<SwFieldType> pNew = rFieldTyp.
Copy();
251 switch( nFieldWhich )
294 const OUString& rName,
295 bool bDbFieldMatching
298 const SwFieldTypes::size_type nSize =
mpFieldTypes->size();
299 SwFieldTypes::size_type
i {0};
322 for( ;
i < nSize; ++
i )
326 if (nResId == pFieldType->
Which())
328 OUString aFieldName( pFieldType->
GetName() );
330 aFieldName = aFieldName.replace(
DB_DELIM,
'.');
332 if (rSCmp.isEqual( rName, aFieldName ))
345 OSL_ENSURE(
INIT_FLDTYPES <= nField,
"don't remove InitFields" );
363 if( pTmp->HasWriterListeners() && !
m_rDoc.
IsUsed( *pTmp ) )
379 OSL_ENSURE( !pTmp->HasWriterListeners(),
"Dependent fields present!" );
384 (*mpFieldTypes)[nField].release();
396 pFieldType->UpdateFields();
408#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
423 const SwFieldTypes::size_type nSize =
mpFieldTypes->size();
431 const OUString& rFieldNm = rFieldTyp.
GetName();
436 if( nFieldWhich == pFnd->
Which() &&
437 rSCmp.isEqual( rFieldNm, pFnd->
GetName() ) )
440 SwFieldTypes::size_type nNum = 1;
442 OUString sSrch = rFieldNm + OUString::number( nNum );
445 pFnd = (*mpFieldTypes)[
i].get();
446 if( nFieldWhich == pFnd->
Which() &&
447 rSCmp.isEqual( sSrch, pFnd->
GetName() ) )
452 const_cast<OUString&
>(rFieldNm) = sSrch;
463 switch( nFieldWhich )
479 const Any& rVal, sal_uInt16 nWhich)
488 std::make_unique<SwUndoFieldFromAPI>(rPos, aOldVal, rVal, nWhich));
498 OSL_ENSURE(pDstTextField,
"no field to update!");
500 bool bTableSelBreak =
false;
515 std::make_unique<SwUndoFieldFromDoc>( aPosition, *pDstField, rSrcField, pMsgHint, bUpdateFields) );
521 switch( nFieldWhich )
544 bTableSelBreak =
true;
564#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
588 return bTableSelBreak;
604 assert(!pHt || pUpdateField);
609 std::vector<SwFormatField*> vFields;
610 pFieldType->GatherFields(vFields);
611 for(
auto pFormatField : vFields)
613 if(!pFormatField->GetTextField()->GetTextNode().FindTableNode())
630 if(pBoxFormula && pBoxFormula->GetDefinedIn())
645 std::optional<SwCalc> oCalc;
649 std::vector<SwFormatField*> vFields;
650 pFieldType->GatherFields(vFields);
684 std::pair<Point, bool>
const tmp(aPt,
true);
692 aPos.
GetNode(), pFormatField->GetTextField(),
721 "the chained formula could no be calculated");
725 pFormatField->UpdateTextNode(
nullptr, pHt);
733 if(!pFormula || !pFormula->GetDefinedIn() || pFormula->IsValid())
759 std::pair<Point, bool>
const tmp(aPt,
true);
785 pFormula->Calc( aPara,
nValue );
792 pFormula->Calc( aPara,
nValue );
795 "the chained formula could no be calculated");
801 if( oCalc->IsCalcError() )
837 if (pLay->IsHideRedlines())
839 pLayoutRLHidden = pLay;
846 if (pLayout || !pLayoutRLHidden)
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!" );
880 pFieldType = (*mpFieldTypes)[ --
n ].get();
881 switch( pFieldType->
Which() )
887 const OUString& rNm = pFieldType->
GetName();
892 static_cast<HashStr*
>(pFnd)->aSetStr = sExpand;
895 aHashStrTable[
nPos].reset(
new HashStr( rNm, sExpand,
896 aHashStrTable[
nPos].release() ) );
907#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
921 int nShownSections = 0;
933 if ( pSectionNode && !rSectFormat.
GetParent() )
936 if (
n == 0 && pSectionNode->
GetIndex() != nContentStart )
938 if (
n == rSectFormats.
size() - 1 )
940 if ( aNextIdx.
GetIndex() != nContentEnd )
953 std::unordered_map<SwSetExpFieldType const*, SwTextNode const*> SetExpOutlineNodeMap;
955 for (std::unique_ptr<SetGetExpField>
const& it : *
mpUpdateFields->GetSortList())
969 if (nShownSections == 1)
996 OSL_ENSURE(
false,
"what's wrong now'" );
1001 && IsFieldDeleted(rIDRA, *pLayout, *pTextField))
1016 bool bValue = !aValue.
GetBool();
1029 bool bValue = aValue.
GetBool();
1035#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
1045#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
1055#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
1080 value, aHashStrTable[
nPos].release()) );
1094 if( (!pUpdateField || pUpdateField == pTextField )
1107 if( aNew.isEmpty() )
1111 if( !pUpdateField || pUpdateField == pTextField )
1127 aHashStrTable[
nPos].release() ) );
1128 pFnd = aHashStrTable[
nPos].get();
1143 if( (!pUpdateField || pUpdateField == pTextField )
1156 OUString aNew = pSFieldTyp->
GetName();
1158 SwNode* pSeqNd =
nullptr;
1169 FindOutlineNodeOfLevel(nLvl, pLayout);
1170 auto const iter(SetExpOutlineNodeMap.find(pSFieldTyp));
1171 if (iter == SetExpOutlineNodeMap.end()
1172 || iter->second != pOutlNd)
1174 SetExpOutlineNodeMap[pSFieldTyp] = pOutlNd;
1187 if( !aValue.
IsVoidValue() && (!pUpdateField || pUpdateField == pTextField) )
1192 pSFieldTyp->
SetChapter(*pSField, *pSeqNd, pLayout);
1206 pUpdateField == pTextField
1213 assert(tmp &&
"should not be locked here?");
1225 if (pUpdateField == pTextField)
1231 pUpdateField =
nullptr;
1235#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
1246 const SwFieldType* pFieldType = (*mpFieldTypes)[
i].get();
1264 sal_Int32 nRecords = 1;
1270 for (std::unique_ptr<SetGetExpField>
const& it : *
mpUpdateFields->GetSortList())
1272 const SwTextField *pTextField = it->GetTextField();
1298 switch(pFieldType->
Which())
1341 bool bFieldsFnd =
false;
1353 const SwTextNode* pTNd = rNds[ nStt++ ]->GetTextNode();
1362 for(
size_t n = 0 ;
n < nEnd; ++
n )
1392 nDate = pNewDateTime->
GetDate();
1393 nTime = pNewDateTime->
GetTime();
1411 std::vector<SwFormatField*> vFields;
1413 for(
auto pFormatField: vFields)
1415 if (pFormatField->GetTextField())
1444 if(
static_cast<SwExtUserField*
>(pFormatField->GetField())->IsFixed() )
1453 if(
static_cast<SwDateTimeField*
>(pFormatField->GetField())->IsFixed() )
1462 if(
static_cast<SwFileNameField*
>(pFormatField->GetField())->IsFixed() )
1477 pFormatField->ForceUpdateTextNode();
1493#if !HAVE_FEATURE_DBCONNECTIVITY || ENABLE_FUZZERS
1505 for (
auto it =
mpUpdateFields->GetSortList()->begin(); it != itLast; ++it)
1507 lcl_CalcField(
m_rDoc, rCalc, **it, pMgr, pLayout);
1510#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
1522#if !HAVE_FEATURE_DBCONNECTIVITY || ENABLE_FUZZERS
1533 if (pLay->IsHideRedlines())
1535 pLayoutRLHidden = pLay;
1547 ( (*it)->GetNode() < nLastNd ||
1548 ( (*it)->GetNode() == nLastNd && (*it)->GetContent() <= nLastCnt )
1552 if (pLayout || !pLayoutRLHidden)
1554 lcl_CalcField(
m_rDoc, rCalc, **it, pMgr, pLayout );
1556 if (pLayoutRLHidden)
1558 lcl_CalcField(
m_rDoc, rCalc, **it, pMgr, pLayoutRLHidden );
1562#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
1578 sal_uInt16 nTableSize = ((
mpUpdateFields->GetSortList()->size() / 7) + 1) * 7;
1579 rHashTable.
resize(nTableSize);
1584 for (
auto it =
mpUpdateFields->GetSortList()->begin(); it != itLast; ++it)
1586 const SwTextField* pTextField = (*it)->GetTextField();
1591 && IsFieldDeleted(rIDRA, rLayout, *pTextField))
1607 if( aNew.isEmpty() )
1683 return (pNode !=
nullptr)
1692 std::vector<SwFormatField*> vFields;
1695 pFieldType->GatherFields(vFields);
1696 if(vFields.size()>0)
1767#if !HAVE_FEATURE_DBCONNECTIVITY || ENABLE_FUZZERS
1798 OSL_FAIL(
"TODO: what should happen with unnamed DBFields?");
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 &)
sal_Int32 GetLong() const
const SwTextField * GetTextField() const
Item2Range GetItemSurrogates(sal_uInt16 nWhich) const
const LocaleDataWrapper & GetLocaleData() const
static OUString Expand(sal_uLong)
void SetExpansion(const OUString &rStr)
void VarChange(const OUString &rStr, const SwSbxValue &rValue)
SwSbxValue Calculate(const OUString &rStr)
SwCalcExp * VarLook(const OUString &rStr, bool bIns=false)
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
void ChgValue(double d, bool bVal)
For calculations in expressions.
void InitContent()
Evaluation for header and footer.
bool IsInitialized() const
void Evaluate()
Get the evaluation via DBManager string.
bool IsDataSourceOpen(const OUString &rDataSource, const OUString &rTableOrQuery, bool bMergeShell)
check if a data source is open
void CloseAll(bool bIncludingMerge=true)
close all data sources - after fields were updated
bool FillCalcWithMergeData(SvNumberFormatter *pDocFormatter, LanguageType nLanguage, SwCalc &aCalc)
bool OpenDataSource(const OUString &rDataSource, const OUString &rTableOrQuery)
open the source while fields are updated - for the calculator only!
sal_uInt32 GetSelectedRecordId(const OUString &rDataSource, const OUString &rTableOrQuery, sal_Int32 nCommandType=-1)
const SwDBData & GetDBData() const
const SwDBData & GetRealDBData() const
DBName.
void Evaluate(const SwDoc &)
tools::Long GetSetNumber() const
OUString Expand(sal_uInt16 nSubType, sal_uInt32 nFormat, LanguageType nLang, const OUString &rName) const
void SetExpansion(const OUString &rStr)
const OUString & GetName() const
virtual sal_uInt16 GetSubType() const override
void SetFieldsDirty(bool b)
SwDBData const & GetDBData()
SwSectionFormats & GetSections()
IDocumentState const & getIDocumentState() const
o3tl::sorted_vector< SwRootFrame * > GetAllLayouts()
bool IsUsed(const sw::BroadcastingModify &) const
static SwTableNode * IsIdxInTable(const SwNodeIndex &rIdx)
SwDBManager * GetDBManager() const
IDocumentUndoRedo & GetIDocumentUndoRedo()
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
const SwAttrPool & GetAttrPool() const
void ChgDBData(const SwDBData &rNewData)
SvNumberFormatter * GetNumberFormatter(bool bCreate=true)
Field type for dropdown boxes.
static OUString Expand(sal_uInt16 nSubType)
virtual sal_uInt16 GetSubType() const override
void SetExpansion(const OUString &rStr)
Instances of SwFields and those derived from it occur 0 to n times.
virtual void UpdateFields()
virtual OUString GetName() const
Only in derived classes.
static const OUString & GetTypeStr(SwFieldTypesEnum nTypeId)
void GatherFields(std::vector< SwFormatField * > &rvFormatFields, bool bCollectOnlyInDocNodes=true) const
void UpdateDocPos(const SwTwips nDocPos)
virtual std::unique_ptr< SwFieldType > Copy() const =0
Base class of all fields.
virtual OUString GetPar1() const
std::unique_ptr< SwField > CopyField() const
virtual sal_uInt16 GetSubType() const
sal_uInt32 GetFormat() const
Query parameters for dialog and for BASIC.
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhichId) const
OUString ExpandField(bool bCached, SwRootFrame const *pLayout) const
expand the field.
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId)
SwFieldType * GetTyp() const
SwFieldIds Which() const
ResId.
LanguageType GetLanguage() const
Language at field position.
void SetExpansion(const OUString &rStr)
Base class of the Writer layout elements.
sal_uInt16 GetPhyPageNum() const
void ChgExpStr(const OUString &rExpand, SwRootFrame const *pLayout)
bool IsInBodyText() const
Called by formatting.
virtual void SetValue(const double &rVal) override
T should be a subclass of SwHash.
T * Find(std::u16string_view aStr, sal_uInt32 *pPos=nullptr) const
void resize(size_t nSize)
void SetHidden(bool bHidden)
virtual OUString GetPar1() const override
Query, set condition.
void Evaluate(SwDoc &rDoc)
get current field value and cache it
virtual OUString GetPar1() const override
void SetValue(bool bHidden)
Marks a node in the document model.
SwNodeOffset GetIndex() const
Base class of the Writer document model elements.
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
SwNodeOffset GetIndex() const
SwNodes & GetNodes()
Node is in which nodes-array/doc?
SwNodeOffset StartOfSectionIndex() const
bool IsSectionNode() const
SwTableNode * FindTableNode()
Search table node, in which it is.
SwContentNode * GetContentNode()
const SwEndNode * EndOfSectionNode() const
SwNode & GetEndOfExtras() const
This is the last EndNode of a special section.
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc....
SwContentNode * GoNext(SwNodeIndex *) const
const SwPosition * GetMark() const
const SwPosition * GetPoint() const
RedlineType GetType(sal_uInt16 nPos=0) const
vector_type::size_type size_type
The root element of a Writer document layout.
bool IsHideRedlines() const
Replacement for sw::DocumentRedlineManager::GetRedlineFlags() (this is layout-level redline hiding).
A section node represents the start of a section on the UI, i.e.
OUString const & GetCondition() const
void SetCondHidden(bool const bFlag)
bool IsCondHidden() const
void SetCondition(OUString const &rNew)
bool CalcHiddenFlag() const
virtual OUString GetName() const override
Only in derived classes.
void SetChapter(SwSetExpField &rField, const SwNode &rNd, SwRootFrame const *pLayout)
sal_uInt8 GetOutlineLvl() const
virtual void SetValue(const double &rVal) override
void ChgExpStr(const OUString &rExpand, SwRootFrame const *pLayout)
bool IsSequenceField() const
const OUString & GetExpStr(SwRootFrame const *pLayout) const
SwTableBox is one table cell in the document model.
const SwStartNode * GetSttNd() const
SwFrameFormat * ClaimFrameFormat()
bool CalcWithStackOverflow()
bool IsStackOverflow() const
Implementation in tblcalc.cxx.
void CalcField(SwTableCalcPara &rCalcPara)
virtual sal_uInt16 GetSubType() const override
const SwTable & GetTable() const
A wrapper around SfxPoolItem to store the start position of (usually) a text portion,...
sal_Int32 GetStart() const
const SwFormatField & GetFormatField() const
SwTextNode & GetTextNode() const
SwTextNode * GetpTextNode() const
void UnlockNotifyContentChange()
bool LockNotifyContentChange()
SwTextNode is a paragraph in the document model.
SwTextField * GetFieldTextAttrAt(const sal_Int32 nIndex, ::sw::GetTextAttrMode const eMode=::sw::GetTextAttrMode::Expand) const
SwpHints & GetSwpHints()
getters for SwpHints
int GetAttrOutlineLevel() const
Returns outline level of this text node.
SwpHints * GetpSwpHints()
void TriggerNodeUpdate(const sw::LegacyModifyHint &)
for hanging TextFormatCollections somewhere else (Outline-Numbering!)
The shared part of a user field.
double GetValue(SwCalc &rCalc)
Fields containing values that have to be formatted via number formatter.
virtual double GetValue() const
std::vector< SwSectionFormat * >::size_type size_type
SwTextAttr * Get(size_t nPos) const
std::vector< Value >::const_iterator const_iterator
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
bool containsUpdatableFields()
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
DocumentFieldsManager(SwDoc &i_rSwdoc)
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
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.
const SwTextNode * GetBodyTextNode(const SwDoc &rDoc, SwPosition &rPos, const SwFrame &rFrame)
Forward declaration: get "BodyTextNode" for exp.fld in Fly's headers/footers/footnotes.
@ Database
For old documents the Field-Which IDs must be preserved !!!
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)
const ::utl::TransliterationWrapper & GetAppCmpStrIgnore()
const SwExtendedSubType SUB_CMD
Show command.
const SwGetSetExpType GSE_SEQ
Sequence.
const SwGetSetExpType GSE_EXPR
Expression.
const SwGetSetExpType GSE_STRING
String.
Dialog to specify the properties of date form field.
bool IsFieldDeletedInModel(IDocumentRedlineAccess const &rIDRA, SwTextField const &rTextField)
SwFrame const * FindNeighbourFrameForNode(SwNode const &rNode)
static LanguageType nLang
Marks a position in the document model.
sal_Int32 GetContentIndex() const
OUString SwResId(TranslateId aId)
#define INIT_SEQ_FLDTYPES
constexpr sal_uInt8 MAXLEVEL