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));
497 OSL_ENSURE(pDstTextField,
"no field to update!");
499 bool bTableSelBreak =
false;
512 m_rDoc.
GetIDocumentUndoRedo().AppendUndo(std::make_unique<SwUndoFieldFromDoc>(aPosition, *pDstField, rSrcField, bUpdateFields));
518 switch( nFieldWhich )
539 bTableSelBreak =
true;
559#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
583 return bTableSelBreak;
599 std::vector<SwFormatField*> vFields;
600 pFieldType->GatherFields(vFields);
601 for(
auto pFormatField : vFields)
603 if(!pFormatField->GetTextField()->GetTextNode().FindTableNode())
620 if(pBoxFormula && pBoxFormula->GetDefinedIn())
631 std::optional<SwCalc> oCalc;
635 std::vector<SwFormatField*> vFields;
636 pFieldType->GatherFields(vFields);
657 if(pTable && &pTableNd->
GetTable() != pTable)
670 std::pair<Point, bool>
const tmp(aPt,
true);
678 aPos.
GetNode(), pFormatField->GetTextField(),
707 "the chained formula could no be calculated");
711 pFormatField->ForceUpdateTextNode();
719 if(!pFormula || !pFormula->GetDefinedIn() || pFormula->IsValid())
725 if(pTable && &pTableNd->
GetTable() != pTable)
745 std::pair<Point, bool>
const tmp(aPt,
true);
771 pFormula->Calc( aPara,
nValue );
778 pFormula->Calc( aPara,
nValue );
781 "the chained formula could no be calculated");
787 if( oCalc->IsCalcError() )
823 if (pLay->IsHideRedlines())
825 pLayoutRLHidden = pLay;
832 if (pLayout || !pLayoutRLHidden)
856 const SwFieldTypes::size_type nHashSize {((
mpFieldTypes->size() / 7 ) + 1 ) * 7};
857 const sal_uInt16 nStrFormatCnt = o3tl::narrowing<sal_uInt16>(nHashSize);
858 OSL_ENSURE( nStrFormatCnt == nHashSize,
"Downcasting to sal_uInt16 lost information!" );
866 pFieldType = (*mpFieldTypes)[ --
n ].get();
867 switch( pFieldType->
Which() )
873 const OUString& rNm = pFieldType->
GetName();
878 static_cast<HashStr*
>(pFnd)->aSetStr = sExpand;
881 aHashStrTable[
nPos].reset(
new HashStr( rNm, sExpand,
882 aHashStrTable[
nPos].release() ) );
893#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
907 int nShownSections = 0;
919 if ( pSectionNode && !rSectFormat.
GetParent() )
922 if (
n == 0 && pSectionNode->
GetIndex() != nContentStart )
924 if (
n == rSectFormats.
size() - 1 )
926 if ( aNextIdx.
GetIndex() != nContentEnd )
939 std::unordered_map<SwSetExpFieldType const*, SwTextNode const*> SetExpOutlineNodeMap;
941 for (std::unique_ptr<SetGetExpField>
const& it : *
mpUpdateFields->GetSortList())
955 if (nShownSections == 1)
982 OSL_ENSURE(
false,
"what's wrong now'" );
987 && IsFieldDeleted(rIDRA, *pLayout, *pTextField))
1002 bool bValue = !aValue.
GetBool();
1015 bool bValue = aValue.
GetBool();
1021#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
1031#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
1041#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
1066 value, aHashStrTable[
nPos].release()) );
1080 if( (!pUpdateField || pUpdateField == pTextField )
1093 if( aNew.isEmpty() )
1097 if( !pUpdateField || pUpdateField == pTextField )
1113 aHashStrTable[
nPos].release() ) );
1114 pFnd = aHashStrTable[
nPos].get();
1129 if( (!pUpdateField || pUpdateField == pTextField )
1142 OUString aNew = pSFieldTyp->
GetName();
1144 SwNode* pSeqNd =
nullptr;
1155 FindOutlineNodeOfLevel(nLvl, pLayout);
1156 auto const iter(SetExpOutlineNodeMap.find(pSFieldTyp));
1157 if (iter == SetExpOutlineNodeMap.end()
1158 || iter->second != pOutlNd)
1160 SetExpOutlineNodeMap[pSFieldTyp] = pOutlNd;
1173 if( !aValue.
IsVoidValue() && (!pUpdateField || pUpdateField == pTextField) )
1178 pSFieldTyp->
SetChapter(*pSField, *pSeqNd, pLayout);
1192 pUpdateField == pTextField
1199 assert(tmp &&
"should not be locked here?");
1211 if (pUpdateField == pTextField)
1217 pUpdateField =
nullptr;
1221#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
1232 const SwFieldType* pFieldType = (*mpFieldTypes)[
i].get();
1250 sal_Int32 nRecords = 1;
1256 for (std::unique_ptr<SetGetExpField>
const& it : *
mpUpdateFields->GetSortList())
1258 const SwTextField *pTextField = it->GetTextField();
1284 switch(pFieldType->
Which())
1327 bool bFieldsFnd =
false;
1339 const SwTextNode* pTNd = rNds[ nStt++ ]->GetTextNode();
1348 for(
size_t n = 0 ;
n < nEnd; ++
n )
1378 nDate = pNewDateTime->
GetDate();
1379 nTime = pNewDateTime->
GetTime();
1397 std::vector<SwFormatField*> vFields;
1399 for(
auto pFormatField: vFields)
1401 if (pFormatField->GetTextField())
1430 if(
static_cast<SwExtUserField*
>(pFormatField->GetField())->IsFixed() )
1439 if(
static_cast<SwDateTimeField*
>(pFormatField->GetField())->IsFixed() )
1448 if(
static_cast<SwFileNameField*
>(pFormatField->GetField())->IsFixed() )
1463 pFormatField->ForceUpdateTextNode();
1479#if !HAVE_FEATURE_DBCONNECTIVITY || ENABLE_FUZZERS
1491 for (
auto it =
mpUpdateFields->GetSortList()->begin(); it != itLast; ++it)
1493 lcl_CalcField(
m_rDoc, rCalc, **it, pMgr, pLayout);
1496#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
1508#if !HAVE_FEATURE_DBCONNECTIVITY || ENABLE_FUZZERS
1519 if (pLay->IsHideRedlines())
1521 pLayoutRLHidden = pLay;
1533 ( (*it)->GetNode() < nLastNd ||
1534 ( (*it)->GetNode() == nLastNd && (*it)->GetContent() <= nLastCnt )
1538 if (pLayout || !pLayoutRLHidden)
1540 lcl_CalcField(
m_rDoc, rCalc, **it, pMgr, pLayout );
1542 if (pLayoutRLHidden)
1544 lcl_CalcField(
m_rDoc, rCalc, **it, pMgr, pLayoutRLHidden );
1548#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
1564 sal_uInt16 nTableSize = ((
mpUpdateFields->GetSortList()->size() / 7) + 1) * 7;
1565 rHashTable.
resize(nTableSize);
1570 for (
auto it =
mpUpdateFields->GetSortList()->begin(); it != itLast; ++it)
1572 const SwTextField* pTextField = (*it)->GetTextField();
1577 && IsFieldDeleted(rIDRA, rLayout, *pTextField))
1593 if( aNew.isEmpty() )
1669 return (pNode !=
nullptr)
1678 std::vector<SwFormatField*> vFields;
1681 pFieldType->GatherFields(vFields);
1682 if(vFields.size()>0)
1753#if !HAVE_FEATURE_DBCONNECTIVITY || ENABLE_FUZZERS
1784 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
SwTable is one table in the document model, containing rows (which contain cells).
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 InsDelFieldInFieldLst(bool bIns, const SwTextField &rField) override
virtual SwFieldType * GetSysFieldType(const SwFieldIds eWhich) const override
std::unique_ptr< SwFieldTypes > mpFieldTypes
virtual bool UpdateField(SwTextField *rDstFormatField, SwField &rSrcField, bool bUpdateTableFields) override
Updates a field.
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 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 UpdateTableFields(const SwTable *pTable) override
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< 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