LibreOffice Module sw (master) 1
docfld.hxx
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 */
19
20#ifndef INCLUDED_SW_SOURCE_CORE_INC_DOCFLD_HXX
21#define INCLUDED_SW_SOURCE_CORE_INC_DOCFLD_HXX
22
23#include <calc.hxx>
24#include <doc.hxx>
26#include <IMark.hxx>
28#include <memory>
29#include <optional>
30
31class SwTextField;
32class SwContentIndex;
33class SwNodeIndex;
34class SwContentFrame;
35class SwSectionNode;
36class SwSection;
37class SwTextTOXMark;
38class SwTableBox;
41class SwNode;
42struct SwPosition;
43enum class SwFieldIds : sal_uInt16;
44
45// Update expression fields
47{
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;
51 union {
61 sal_Int32 m_nContent;
63 {
67
68public:
69 SetGetExpField( const SwNode& rNd, const SwTextField* pField = nullptr,
70 std::optional<sal_Int32> oContentIdx = std::nullopt,
71 sal_uInt16 nPageNumber = 0);
72
73 SetGetExpField( const SwNode& rNd, const SwTextINetFormat& rINet );
74
75 SetGetExpField( const SwSectionNode& rSectNode,
76 const SwPosition* pPos = nullptr,
77 sal_uInt16 nPageNumber = 0);
78
79 SetGetExpField( ::sw::mark::IBookmark const& rBookmark,
80 SwPosition const* pPos = nullptr,
81 sal_uInt16 nPageNumber = 0);
82
83 SetGetExpField( const SwTableBox& rTableBox );
84
85 SetGetExpField( const SwNode& rNd, const SwTextTOXMark& rTOX );
86
87 SetGetExpField( const SwPosition& rPos );
88
89 SetGetExpField( const SwFlyFrameFormat& rFlyFormat, const SwPosition* pPos );
90
91 bool operator==( const SetGetExpField& rField ) const;
92 bool operator<( const SetGetExpField& rField ) const;
93
95 { return TEXTFIELD == m_eSetGetExpFieldType ? m_CNTNT.pTextField : nullptr; }
96 const SwSection* GetSection() const
97 { return SECTIONNODE == m_eSetGetExpFieldType ? m_CNTNT.pSection : nullptr; }
99 { return BOOKMARK == m_eSetGetExpFieldType ? m_CNTNT.pBookmark : nullptr; }
101 { return TEXTINET == m_eSetGetExpFieldType ? m_CNTNT.pTextINet : nullptr; }
103 { return FLYFRAME == m_eSetGetExpFieldType ? m_CNTNT.pFlyFormat : nullptr; }
104
105 SwNodeOffset GetNode() const { return m_nNode; }
106 sal_Int32 GetContent() const { return m_nContent; }
107 const void* GetPointer() const { return m_CNTNT.pTextField; }
108
109 void GetPosOfContent( SwPosition& rPos ) const;
110
111 const SwNode* GetNodeFromContent() const;
112 sal_Int32 GetCntPosFromContent() const;
113
114 void SetBodyPos( const SwContentFrame& rFrame );
115};
116
117class SetGetExpFields : public o3tl::sorted_vector<std::unique_ptr<SetGetExpField>, o3tl::less_uniqueptr_to<SetGetExpField> >
118{
119};
120
121// struct for saving strings from the SetExp's string fields
122struct HashStr final : public SwHash
123{
124 OUString aSetStr;
125 HashStr( const OUString& rName, OUString aText, HashStr* );
126};
127
128struct SwCalcFieldType final : public SwHash
129{
131
132 SwCalcFieldType( const OUString& rStr, const SwFieldType* pFieldTyp )
133 : SwHash( rStr ), pFieldType( pFieldTyp )
134 {}
135};
136
137// search for the string that was saved under rName in the hash table
138OUString LookString( SwHashTable<HashStr> const & rTable, const OUString& rName );
139
140const int GETFLD_ALL = 3; // combine flags via OR
141const int GETFLD_CALC = 1;
142const int GETFLD_EXPAND = 2;
143
145{
146 std::unique_ptr<SetGetExpFields> m_pFieldSortList;
148
152
154 bool m_bFieldsDirty : 1;
155
156 void MakeFieldList_( SwDoc& pDoc, int eGetMode );
157 void GetBodyNode( const SwTextField& , SwFieldIds nFieldWhich );
158 template<typename T>
159 void GetBodyNodeGeneric(SwNode const& rNode, T const&);
160
161public:
162 SwDocUpdateField(SwDoc& rDocument);
164
165 const SetGetExpFields* GetSortList() const { return m_pFieldSortList.get(); }
166
167 void MakeFieldList( SwDoc& rDoc, bool bAll, int eGetMode );
168
169 void InsDelFieldInFieldLst( bool bIns, const SwTextField& rField );
170
171 void InsertFieldType( const SwFieldType& rType );
172 void RemoveFieldType( const SwFieldType& rType );
173
174 bool IsInUpdateFields() const { return m_bInUpdateFields; }
175 void SetInUpdateFields( bool b ) { m_bInUpdateFields = b; }
176
177 bool IsFieldsDirty() const { return m_bFieldsDirty; }
178 void SetFieldsDirty( bool b )
179 {
180 m_bFieldsDirty = b;
181
182 if (b)
183 {
185 }
186 }
187
189};
190
191#endif
192
193/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void StartIdling()=0
Start the idle task.
SetGetExpField(const SwNode &rNd, const SwTextField *pField=nullptr, std::optional< sal_Int32 > oContentIdx=std::nullopt, sal_uInt16 nPageNumber=0)
Definition: docfld.cxx:67
sal_Int32 GetCntPosFromContent() const
Definition: docfld.cxx:342
sal_Int32 GetContent() const
Definition: docfld.hxx:106
const SwTextINetFormat * GetINetFormat() const
Definition: docfld.hxx:100
bool operator<(const SetGetExpField &rField) const
Definition: docfld.cxx:229
const SwTextField * GetTextField() const
Definition: docfld.hxx:94
::sw::mark::IBookmark const * GetBookmark() const
Definition: docfld.hxx:98
const SwSection * GetSection() const
Definition: docfld.hxx:96
::sw::mark::IBookmark const * pBookmark
Definition: docfld.hxx:59
const SwNode * GetNodeFromContent() const
Definition: docfld.cxx:294
const SwTableBox * pTBox
Definition: docfld.hxx:56
const SwPosition * pPos
Definition: docfld.hxx:54
void SetBodyPos(const SwContentFrame &rFrame)
Definition: docfld.cxx:204
void GetPosOfContent(SwPosition &rPos) const
Definition: docfld.cxx:188
union SetGetExpField::@4 m_CNTNT
const SwTextTOXMark * pTextTOX
Definition: docfld.hxx:55
enum SetGetExpField::SetGetExpFieldType m_eSetGetExpFieldType
SwNodeOffset m_nNode
Definition: docfld.hxx:50
const SwTextField * pTextField
Definition: docfld.hxx:52
bool operator==(const SetGetExpField &rField) const
Definition: docfld.cxx:220
SwNodeOffset GetNode() const
Definition: docfld.hxx:105
sal_uInt16 m_nPageNumber
Definition: docfld.hxx:49
const SwSection * pSection
Definition: docfld.hxx:53
sal_Int32 m_nContent
Definition: docfld.hxx:61
const SwTextINetFormat * pTextINet
Definition: docfld.hxx:57
const void * GetPointer() const
Definition: docfld.hxx:107
const SwFlyFrameFormat * GetFlyFormat() const
Definition: docfld.hxx:102
const SwFlyFrameFormat * pFlyFormat
Definition: docfld.hxx:58
SwContentFrame is the layout for content nodes: a common base class for text (paragraph) and non-text...
Definition: cntfrm.hxx:59
Marks a character position inside a document model content node (SwContentNode)
void MakeFieldList(SwDoc &rDoc, bool bAll, int eGetMode)
Definition: docfld.cxx:830
SwHashTable< SwCalcFieldType > m_FieldTypeTable
Definition: docfld.hxx:147
bool m_bFieldsDirty
some fields are invalid
Definition: docfld.hxx:154
SwDocUpdateField(SwDoc &rDocument)
Definition: docfld.cxx:1245
void MakeFieldList_(SwDoc &pDoc, int eGetMode)
Definition: docfld.cxx:840
bool IsInUpdateFields() const
Definition: docfld.hxx:174
const SetGetExpFields * GetSortList() const
Definition: docfld.hxx:165
void InsDelFieldInFieldLst(bool bIns, const SwTextField &rField)
Definition: docfld.cxx:786
void SetFieldsDirty(bool b)
Definition: docfld.hxx:178
int m_nFieldListGetMode
Definition: docfld.hxx:150
void SetInUpdateFields(bool b)
Definition: docfld.hxx:175
SwHashTable< SwCalcFieldType > const & GetFieldTypeTable() const
Definition: docfld.hxx:188
SwDoc & m_rDoc
Definition: docfld.hxx:151
void GetBodyNode(const SwTextField &, SwFieldIds nFieldWhich)
Definition: docfld.cxx:1064
bool m_bInUpdateFields
currently in an UpdateFields call
Definition: docfld.hxx:153
void InsertFieldType(const SwFieldType &rType)
Definition: docfld.cxx:1172
std::unique_ptr< SetGetExpFields > m_pFieldSortList
current field list for calculation
Definition: docfld.hxx:146
SwNodeOffset m_nNodes
to check if the node count changed
Definition: docfld.hxx:149
void RemoveFieldType(const SwFieldType &rType)
Definition: docfld.cxx:1205
void GetBodyNodeGeneric(SwNode const &rNode, T const &)
Definition: docfld.cxx:1127
bool IsFieldsDirty() const
Definition: docfld.hxx:177
Definition: doc.hxx:197
IDocumentTimerAccess const & getIDocumentTimerAccess() const
Definition: doc.cxx:263
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:247
T should be a subclass of SwHash.
Definition: calc.hxx:155
Marks a node in the document model.
Definition: ndindex.hxx:31
Base class of the Writer document model elements.
Definition: node.hxx:98
A section node represents the start of a section on the UI, i.e.
Definition: node.hxx:575
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:443
SwTextAttr subclass that tracks the location of the wrapped SwFormatURL.
Definition: txtinet.hxx:30
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:377
const int GETFLD_CALC
Definition: docfld.hxx:141
const int GETFLD_ALL
Definition: docfld.hxx:140
const int GETFLD_EXPAND
Definition: docfld.hxx:142
SwFieldIds
Definition: fldbas.hxx:49
OUString aSetStr
Definition: docfld.hxx:124
HashStr(const OUString &rName, OUString aText, HashStr *)
Definition: docfld.cxx:369
SwCalcFieldType(const OUString &rStr, const SwFieldType *pFieldTyp)
Definition: docfld.hxx:132
const SwFieldType * pFieldType
Definition: docfld.hxx:130
Definition: calc.hxx:136
Marks a position in the document model.
Definition: pam.hxx:38