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>
25 #include <IDocumentTimerAccess.hxx>
26 #include <IMark.hxx>
27 #include <o3tl/sorted_vector.hxx>
28 #include <memory>
29 
30 class SwTextField;
31 class SwIndex;
32 class SwNodeIndex;
33 class SwContentFrame;
34 class SwSectionNode;
35 class SwSection;
36 class SwTextTOXMark;
37 class SwTableBox;
38 class SwTextINetFormat;
39 class SwFlyFrameFormat;
40 class SwNode;
41 struct SwPosition;
42 enum class SwFieldIds : sal_uInt16;
43 
44 // Update expression fields
46 {
47  // TODO: in case of multiple layouts, storing this only once isn't going to work (although already a problem for cached field value)
48  sal_uInt16 m_nPageNumber = 0;
50  union {
53  const SwPosition* pPos;
55  const SwTableBox* pTBox;
59  } m_CNTNT;
60  sal_Int32 m_nContent;
62  {
64  TEXTINET, FLYFRAME
66 
67 public:
68  SetGetExpField( const SwNodeIndex& rNdIdx, const SwTextField* pField = nullptr,
69  const SwIndex* pIdx = nullptr,
70  sal_uInt16 nPageNumber = 0);
71 
72  SetGetExpField( const SwNodeIndex& rNdIdx, const SwTextINetFormat& rINet );
73 
74  SetGetExpField( const SwSectionNode& rSectNode,
75  const SwPosition* pPos = nullptr,
76  sal_uInt16 nPageNumber = 0);
77 
78  SetGetExpField( ::sw::mark::IBookmark const& rBookmark,
79  SwPosition const* pPos = nullptr,
80  sal_uInt16 nPageNumber = 0);
81 
82  SetGetExpField( const SwTableBox& rTableBox );
83 
84  SetGetExpField( const SwNodeIndex& rNdIdx, const SwTextTOXMark& rTOX );
85 
86  SetGetExpField( const SwPosition& rPos );
87 
88  SetGetExpField( const SwFlyFrameFormat& rFlyFormat, const SwPosition* pPos );
89 
90  bool operator==( const SetGetExpField& rField ) const;
91  bool operator<( const SetGetExpField& rField ) const;
92 
93  const SwTextField* GetTextField() const
94  { return TEXTFIELD == m_eSetGetExpFieldType ? m_CNTNT.pTextField : nullptr; }
95  const SwSection* GetSection() const
96  { return SECTIONNODE == m_eSetGetExpFieldType ? m_CNTNT.pSection : nullptr; }
98  { return BOOKMARK == m_eSetGetExpFieldType ? m_CNTNT.pBookmark : nullptr; }
100  { return TEXTINET == m_eSetGetExpFieldType ? m_CNTNT.pTextINet : nullptr; }
102  { return FLYFRAME == m_eSetGetExpFieldType ? m_CNTNT.pFlyFormat : nullptr; }
103 
104  SwNodeOffset GetNode() const { return m_nNode; }
105  sal_Int32 GetContent() const { return m_nContent; }
106  const void* GetPointer() const { return m_CNTNT.pTextField; }
107 
108  void GetPosOfContent( SwPosition& rPos ) const;
109 
110  const SwNode* GetNodeFromContent() const;
111  sal_Int32 GetCntPosFromContent() const;
112 
113  void SetBodyPos( const SwContentFrame& rFrame );
114 };
115 
116 class SetGetExpFields : public o3tl::sorted_vector<std::unique_ptr<SetGetExpField>, o3tl::less_uniqueptr_to<SetGetExpField> >
117 {
118 };
119 
120 // struct for saving strings from the SetExp's string fields
121 struct HashStr final : public SwHash
122 {
123  OUString aSetStr;
124  HashStr( const OUString& rName, const OUString& rText, HashStr* );
125 };
126 
127 struct SwCalcFieldType final : public SwHash
128 {
130 
131  SwCalcFieldType( const OUString& rStr, const SwFieldType* pFieldTyp )
132  : SwHash( rStr ), pFieldType( pFieldTyp )
133  {}
134 };
135 
136 // search for the string that was saved under rName in the hash table
137 OUString LookString( SwHashTable<HashStr> const & rTable, const OUString& rName );
138 
139 const int GETFLD_ALL = 3; // combine flags via OR
140 const int GETFLD_CALC = 1;
141 const int GETFLD_EXPAND = 2;
142 
144 {
145  std::unique_ptr<SetGetExpFields> m_pFieldSortList;
147 
151 
152  bool m_bInUpdateFields : 1;
153  bool m_bFieldsDirty : 1;
154 
155  void MakeFieldList_( SwDoc& pDoc, int eGetMode );
156  void GetBodyNode( const SwTextField& , SwFieldIds nFieldWhich );
157  template<typename T>
158  void GetBodyNodeGeneric(SwNode const& rNode, T const&);
159 
160 public:
161  SwDocUpdateField(SwDoc& rDocument);
163 
164  const SetGetExpFields* GetSortList() const { return m_pFieldSortList.get(); }
165 
166  void MakeFieldList( SwDoc& rDoc, bool bAll, int eGetMode );
167 
168  void InsDelFieldInFieldLst( bool bIns, const SwTextField& rField );
169 
170  void InsertFieldType( const SwFieldType& rType );
171  void RemoveFieldType( const SwFieldType& rType );
172 
173  bool IsInUpdateFields() const { return m_bInUpdateFields; }
174  void SetInUpdateFields( bool b ) { m_bInUpdateFields = b; }
175 
176  bool IsFieldsDirty() const { return m_bFieldsDirty; }
177  void SetFieldsDirty( bool b )
178  {
179  m_bFieldsDirty = b;
180 
181  if (b)
182  {
184  }
185  }
186 
188 };
189 
190 #endif
191 
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:241
SwNodeOffset m_nNodes
to check if the node count changed
Definition: docfld.hxx:148
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:375
Definition: calc.hxx:134
bool m_bInUpdateFields
currently in an UpdateFields call
Definition: docfld.hxx:152
Marks a position in the document model.
Definition: pam.hxx:36
sal_Int32 m_nContent
Definition: docfld.hxx:60
const SwTextTOXMark * pTextTOX
Definition: docfld.hxx:54
sal_Int32 GetContent() const
Definition: docfld.hxx:105
bool IsInUpdateFields() const
Definition: docfld.hxx:173
const int GETFLD_ALL
Definition: docfld.hxx:139
bool IsFieldsDirty() const
Definition: docfld.hxx:176
Definition: doc.hxx:187
SwDocUpdateField(SwDoc &rDocument)
Definition: docfld.cxx:1221
const void * GetPointer() const
Definition: docfld.hxx:106
SwNodeOffset m_nNode
Definition: docfld.hxx:49
const SwNode * GetNodeFromContent() const
Definition: docfld.cxx:292
SwNodeOffset GetNode() const
Definition: docfld.hxx:104
bool m_bFieldsDirty
some fields are invalid
Definition: docfld.hxx:153
virtual void StartIdling()=0
Start the idle task.
void SetBodyPos(const SwContentFrame &rFrame)
Definition: docfld.cxx:205
const SwPosition * pPos
Definition: docfld.hxx:53
::sw::mark::IBookmark const * GetBookmark() const
Definition: docfld.hxx:97
void GetBodyNode(const SwTextField &, SwFieldIds nFieldWhich)
Definition: docfld.cxx:1038
void RemoveFieldType(const SwFieldType &rType)
Definition: docfld.cxx:1181
std::unique_ptr< SetGetExpFields > m_pFieldSortList
current field list for calculation
Definition: docfld.hxx:145
SwFieldIds
Definition: fldbas.hxx:45
void SetInUpdateFields(bool b)
Definition: docfld.hxx:174
Marks a character position inside a document model node.
Definition: index.hxx:33
sal_Int32 GetCntPosFromContent() const
Definition: docfld.cxx:340
const SwFlyFrameFormat * GetFlyFormat() const
Definition: docfld.hxx:101
Marks a node in the document model.
Definition: ndindex.hxx:30
const SwFieldType * pFieldType
Definition: docfld.hxx:129
const SwTableBox * pTBox
Definition: docfld.hxx:55
const SetGetExpFields * GetSortList() const
Definition: docfld.hxx:164
::sw::mark::IBookmark const * pBookmark
Definition: docfld.hxx:58
const SwSection * GetSection() const
Definition: docfld.hxx:95
bool operator<(const SetGetExpField &rField) const
Definition: docfld.cxx:230
const SwSection * pSection
Definition: docfld.hxx:52
const int GETFLD_EXPAND
Definition: docfld.hxx:141
SwHashTable< SwCalcFieldType > const & GetFieldTypeTable() const
Definition: docfld.hxx:187
void MakeFieldList_(SwDoc &pDoc, int eGetMode)
Definition: docfld.cxx:838
int m_nFieldListGetMode
Definition: docfld.hxx:149
OUString aSetStr
Definition: docfld.hxx:123
void SetFieldsDirty(bool b)
Definition: docfld.hxx:177
enum SetGetExpField::SetGetExpFieldType m_eSetGetExpFieldType
const SwTextINetFormat * pTextINet
Definition: docfld.hxx:56
SetGetExpField(const SwNodeIndex &rNdIdx, const SwTextField *pField=nullptr, const SwIndex *pIdx=nullptr, sal_uInt16 nPageNumber=0)
Definition: docfld.cxx:66
const SwTextINetFormat * GetINetFormat() const
Definition: docfld.hxx:99
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:418
void GetBodyNodeGeneric(SwNode const &rNode, T const &)
Definition: docfld.cxx:1103
HashStr(const OUString &rName, const OUString &rText, HashStr *)
Definition: docfld.cxx:367
const SwTextField * GetTextField() const
Definition: docfld.hxx:93
SwCalcFieldType(const OUString &rStr, const SwFieldType *pFieldTyp)
Definition: docfld.hxx:131
void GetPosOfContent(SwPosition &rPos) const
Definition: docfld.cxx:187
const SwTextField * pTextField
Definition: docfld.hxx:51
void MakeFieldList(SwDoc &rDoc, bool bAll, int eGetMode)
Definition: docfld.cxx:828
void InsertFieldType(const SwFieldType &rType)
Definition: docfld.cxx:1148
const SwFlyFrameFormat * pFlyFormat
Definition: docfld.hxx:57
bool operator==(const SetGetExpField &rField) const
Definition: docfld.cxx:221
const int GETFLD_CALC
Definition: docfld.hxx:140
SwHashTable< SwCalcFieldType > m_FieldTypeTable
Definition: docfld.hxx:146
T should be a subclass of SwHash.
Definition: calc.hxx:153
IDocumentTimerAccess const & getIDocumentTimerAccess() const
Definition: doc.cxx:249
union SetGetExpField::@4 m_CNTNT
void InsDelFieldInFieldLst(bool bIns, const SwTextField &rField)
Definition: docfld.cxx:784
Base class of the Writer document model elements.
Definition: node.hxx:81
SwDoc & m_rDoc
Definition: docfld.hxx:150