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::Bookmark
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::Bookmark
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::Bookmark
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_ptr_to
>
122 //struct SwCalcFieldType final : public SwHash
124 // const SwFieldType* pFieldType;
126 // SwCalcFieldType( const OUString& rStr, const SwFieldType* pFieldTyp )
127 // : SwHash( rStr ), pFieldType( pFieldTyp )
131 // search for the string that was saved under rName in the hash table
132 OUString
LookString( std::unordered_map
<OUString
,OUString
> const & rTable
, const OUString
& rName
);
134 const int GETFLD_ALL
= 3; // combine flags via OR
135 const int GETFLD_CALC
= 1;
136 const int GETFLD_EXPAND
= 2;
138 class SwDocUpdateField
140 std::unique_ptr
<SetGetExpFields
> m_pFieldSortList
; ///< current field list for calculation
141 std::unordered_multimap
<OUString
, const SwFieldType
*> m_FieldTypeTable
;
143 SwNodeOffset m_nNodes
; ///< to check if the node count changed
144 int m_nFieldListGetMode
;
147 bool m_bInUpdateFields
: 1; ///< currently in an UpdateFields call
148 bool m_bFieldsDirty
: 1; ///< some fields are invalid
150 void MakeFieldList_( SwDoc
& pDoc
, int eGetMode
);
151 void GetBodyNode( const SwTextField
& , SwFieldIds nFieldWhich
);
153 void GetBodyNodeGeneric(SwNode
const& rNode
, T
const&);
156 SwDocUpdateField(SwDoc
& rDocument
);
159 const SetGetExpFields
* GetSortList() const { return m_pFieldSortList
.get(); }
161 void MakeFieldList( SwDoc
& rDoc
, bool bAll
, int eGetMode
);
163 void InsDelFieldInFieldLst( bool bIns
, const SwTextField
& rField
);
165 void InsertFieldType( const SwFieldType
& rType
);
166 void RemoveFieldType( const SwFieldType
& rType
);
168 bool IsInUpdateFields() const { return m_bInUpdateFields
; }
169 void SetInUpdateFields( bool b
) { m_bInUpdateFields
= b
; }
171 bool IsFieldsDirty() const { return m_bFieldsDirty
; }
172 void SetFieldsDirty( bool b
)
178 m_rDoc
.getIDocumentTimerAccess().StartIdling();
182 std::unordered_multimap
<OUString
, const SwFieldType
*> const& GetFieldTypeTable() const { return m_FieldTypeTable
; }
183 std::unordered_multimap
<OUString
, const SwFieldType
*> & GetFieldTypeTable() { return m_FieldTypeTable
; }
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */