1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SW_SOURCE_CORE_INC_DOCFLD_HXX
21 #define INCLUDED_SW_SOURCE_CORE_INC_DOCFLD_HXX
25 #include <IDocumentTimerAccess.hxx>
27 #include <o3tl/sorted_vector.hxx>
39 class SwTextINetFormat
;
40 class SwFlyFrameFormat
;
43 enum class SwFieldIds
: sal_uInt16
;
45 // Update expression fields
48 // TODO: in case of multiple layouts, storing this only once isn't going to work (although already a problem for cached field value)
49 sal_uInt16 m_nPageNumber
= 0;
52 const SwTextField
* pTextField
;
53 const SwSection
* pSection
;
54 const SwPosition
* pPos
;
55 const SwTextTOXMark
* pTextTOX
;
56 const SwTableBox
* pTBox
;
57 const SwTextINetFormat
* pTextINet
;
58 const SwFlyFrameFormat
* pFlyFormat
;
59 ::sw::mark::IBookmark
const* pBookmark
;
62 enum SetGetExpFieldType
64 TEXTFIELD
, TEXTTOXMARK
, SECTIONNODE
, BOOKMARK
, CRSRPOS
, TABLEBOX
,
66 } m_eSetGetExpFieldType
;
69 SetGetExpField( const SwNode
& rNd
, const SwTextField
* pField
= nullptr,
70 std::optional
<sal_Int32
> oContentIdx
= std::nullopt
,
71 sal_uInt16 nPageNumber
= 0);
73 SetGetExpField( const SwNode
& rNd
, const SwTextINetFormat
& rINet
);
75 SetGetExpField( const SwSectionNode
& rSectNode
,
76 const SwPosition
* pPos
= nullptr,
77 sal_uInt16 nPageNumber
= 0);
79 SetGetExpField( ::sw::mark::IBookmark
const& rBookmark
,
80 SwPosition
const* pPos
= nullptr,
81 sal_uInt16 nPageNumber
= 0);
83 SetGetExpField( const SwTableBox
& rTableBox
);
85 SetGetExpField( const SwNode
& rNd
, const SwTextTOXMark
& rTOX
);
87 SetGetExpField( const SwPosition
& rPos
);
89 SetGetExpField( const SwFlyFrameFormat
& rFlyFormat
, const SwPosition
* pPos
);
91 bool operator==( const SetGetExpField
& rField
) const;
92 bool operator<( const SetGetExpField
& rField
) const;
94 const SwTextField
* GetTextField() const
95 { return TEXTFIELD
== m_eSetGetExpFieldType
? m_CNTNT
.pTextField
: nullptr; }
96 const SwSection
* GetSection() const
97 { return SECTIONNODE
== m_eSetGetExpFieldType
? m_CNTNT
.pSection
: nullptr; }
98 ::sw::mark::IBookmark
const* GetBookmark() const
99 { return BOOKMARK
== m_eSetGetExpFieldType
? m_CNTNT
.pBookmark
: nullptr; }
100 const SwTextINetFormat
* GetINetFormat() const
101 { return TEXTINET
== m_eSetGetExpFieldType
? m_CNTNT
.pTextINet
: nullptr; }
102 const SwFlyFrameFormat
* GetFlyFormat() const
103 { return FLYFRAME
== m_eSetGetExpFieldType
? m_CNTNT
.pFlyFormat
: nullptr; }
105 SwNodeOffset
GetNode() const { return m_nNode
; }
106 sal_Int32
GetContent() const { return m_nContent
; }
107 const void* GetPointer() const { return m_CNTNT
.pTextField
; }
109 void GetPosOfContent( SwPosition
& rPos
) const;
111 const SwNode
* GetNodeFromContent() const;
112 sal_Int32
GetCntPosFromContent() const;
114 void SetBodyPos( const SwContentFrame
& rFrame
);
117 class SetGetExpFields
: public o3tl::sorted_vector
<std::unique_ptr
<SetGetExpField
>, o3tl::less_uniqueptr_to
<SetGetExpField
> >
121 // struct for saving strings from the SetExp's string fields
122 struct HashStr final
: public SwHash
125 HashStr( const OUString
& rName
, OUString aText
, HashStr
* );
128 struct SwCalcFieldType final
: public SwHash
130 const SwFieldType
* pFieldType
;
132 SwCalcFieldType( const OUString
& rStr
, const SwFieldType
* pFieldTyp
)
133 : SwHash( rStr
), pFieldType( pFieldTyp
)
137 // search for the string that was saved under rName in the hash table
138 OUString
LookString( SwHashTable
<HashStr
> const & rTable
, const OUString
& rName
);
140 const int GETFLD_ALL
= 3; // combine flags via OR
141 const int GETFLD_CALC
= 1;
142 const int GETFLD_EXPAND
= 2;
144 class SwDocUpdateField
146 std::unique_ptr
<SetGetExpFields
> m_pFieldSortList
; ///< current field list for calculation
147 SwHashTable
<SwCalcFieldType
> m_FieldTypeTable
;
149 SwNodeOffset m_nNodes
; ///< to check if the node count changed
150 int m_nFieldListGetMode
;
153 bool m_bInUpdateFields
: 1; ///< currently in an UpdateFields call
154 bool m_bFieldsDirty
: 1; ///< some fields are invalid
156 void MakeFieldList_( SwDoc
& pDoc
, int eGetMode
);
157 void GetBodyNode( const SwTextField
& , SwFieldIds nFieldWhich
);
159 void GetBodyNodeGeneric(SwNode
const& rNode
, T
const&);
162 SwDocUpdateField(SwDoc
& rDocument
);
165 const SetGetExpFields
* GetSortList() const { return m_pFieldSortList
.get(); }
167 void MakeFieldList( SwDoc
& rDoc
, bool bAll
, int eGetMode
);
169 void InsDelFieldInFieldLst( bool bIns
, const SwTextField
& rField
);
171 void InsertFieldType( const SwFieldType
& rType
);
172 void RemoveFieldType( const SwFieldType
& rType
);
174 bool IsInUpdateFields() const { return m_bInUpdateFields
; }
175 void SetInUpdateFields( bool b
) { m_bInUpdateFields
= b
; }
177 bool IsFieldsDirty() const { return m_bFieldsDirty
; }
178 void SetFieldsDirty( bool b
)
184 m_rDoc
.getIDocumentTimerAccess().StartIdling();
188 SwHashTable
<SwCalcFieldType
> const& GetFieldTypeTable() const { return m_FieldTypeTable
; }
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */