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 {
48  union {
51  const SwPosition* pPos;
53  const SwTableBox* pTBox;
57  } m_CNTNT;
58  sal_Int32 m_nContent;
60  {
62  TEXTINET, FLYFRAME
64 
65 public:
66  SetGetExpField( const SwNodeIndex& rNdIdx, const SwTextField* pField = nullptr,
67  const SwIndex* pIdx = nullptr );
68 
69  SetGetExpField( const SwNodeIndex& rNdIdx, const SwTextINetFormat& rINet );
70 
71  SetGetExpField( const SwSectionNode& rSectNode,
72  const SwPosition* pPos = nullptr );
73 
74  SetGetExpField( ::sw::mark::IBookmark const& rBookmark,
75  SwPosition const* pPos = nullptr );
76 
77  SetGetExpField( const SwTableBox& rTableBox );
78 
79  SetGetExpField( const SwNodeIndex& rNdIdx, const SwTextTOXMark& rTOX );
80 
81  SetGetExpField( const SwPosition& rPos );
82 
83  SetGetExpField( const SwFlyFrameFormat& rFlyFormat, const SwPosition* pPos );
84 
85  bool operator==( const SetGetExpField& rField ) const;
86  bool operator<( const SetGetExpField& rField ) const;
87 
88  const SwTextField* GetTextField() const
89  { return TEXTFIELD == m_eSetGetExpFieldType ? m_CNTNT.pTextField : nullptr; }
90  const SwSection* GetSection() const
91  { return SECTIONNODE == m_eSetGetExpFieldType ? m_CNTNT.pSection : nullptr; }
93  { return BOOKMARK == m_eSetGetExpFieldType ? m_CNTNT.pBookmark : nullptr; }
95  { return TEXTINET == m_eSetGetExpFieldType ? m_CNTNT.pTextINet : nullptr; }
97  { return FLYFRAME == m_eSetGetExpFieldType ? m_CNTNT.pFlyFormat : nullptr; }
98 
99  SwNodeOffset GetNode() const { return m_nNode; }
100  sal_Int32 GetContent() const { return m_nContent; }
101  const void* GetPointer() const { return m_CNTNT.pTextField; }
102 
103  void GetPosOfContent( SwPosition& rPos ) const;
104 
105  const SwNode* GetNodeFromContent() const;
106  sal_Int32 GetCntPosFromContent() const;
107 
108  void SetBodyPos( const SwContentFrame& rFrame );
109 };
110 
111 class SetGetExpFields : public o3tl::sorted_vector<std::unique_ptr<SetGetExpField>, o3tl::less_uniqueptr_to<SetGetExpField> >
112 {
113 };
114 
115 // struct for saving strings from the SetExp's string fields
116 struct HashStr final : public SwHash
117 {
118  OUString aSetStr;
119  HashStr( const OUString& rName, const OUString& rText, HashStr* );
120 };
121 
122 struct SwCalcFieldType final : public SwHash
123 {
125 
126  SwCalcFieldType( const OUString& rStr, const SwFieldType* pFieldTyp )
127  : SwHash( rStr ), pFieldType( pFieldTyp )
128  {}
129 };
130 
131 // search for the string that was saved under rName in the hash table
132 OUString LookString( SwHashTable<HashStr> const & rTable, std::u16string_view rName );
133 
134 const int GETFLD_ALL = 3; // combine flags via OR
135 const int GETFLD_CALC = 1;
136 const int GETFLD_EXPAND = 2;
137 
139 {
140  std::unique_ptr<SetGetExpFields> m_pFieldSortList;
142 
146 
147  bool m_bInUpdateFields : 1;
148  bool m_bFieldsDirty : 1;
149 
150  void MakeFieldList_( SwDoc& pDoc, int eGetMode );
151  void GetBodyNode( const SwTextField& , SwFieldIds nFieldWhich );
152  template<typename T>
153  void GetBodyNodeGeneric(SwNode const& rNode, T const&);
154 
155 public:
156  SwDocUpdateField(SwDoc& rDocument);
158 
159  const SetGetExpFields* GetSortList() const { return m_pFieldSortList.get(); }
160 
161  void MakeFieldList( SwDoc& rDoc, bool bAll, int eGetMode );
162 
163  void InsDelFieldInFieldLst( bool bIns, const SwTextField& rField );
164 
165  void InsertFieldType( const SwFieldType& rType );
166  void RemoveFieldType( const SwFieldType& rType );
167 
168  bool IsInUpdateFields() const { return m_bInUpdateFields; }
169  void SetInUpdateFields( bool b ) { m_bInUpdateFields = b; }
170 
171  bool IsFieldsDirty() const { return m_bFieldsDirty; }
172  void SetFieldsDirty( bool b )
173  {
174  m_bFieldsDirty = b;
175 
176  if (b)
177  {
179  }
180  }
181 
183 };
184 
185 #endif
186 
187 /* 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:143
Definition: calc.hxx:132
bool m_bInUpdateFields
currently in an UpdateFields call
Definition: docfld.hxx:147
Marks a position in the document model.
Definition: pam.hxx:36
sal_Int32 m_nContent
Definition: docfld.hxx:58
const SwTextTOXMark * pTextTOX
Definition: docfld.hxx:52
SetGetExpField(const SwNodeIndex &rNdIdx, const SwTextField *pField=nullptr, const SwIndex *pIdx=nullptr)
Definition: docfld.cxx:63
sal_Int32 GetContent() const
Definition: docfld.hxx:100
bool IsInUpdateFields() const
Definition: docfld.hxx:168
const int GETFLD_ALL
Definition: docfld.hxx:134
bool IsFieldsDirty() const
Definition: docfld.hxx:171
Definition: doc.hxx:188
SwDocUpdateField(SwDoc &rDocument)
Definition: docfld.cxx:1193
const void * GetPointer() const
Definition: docfld.hxx:101
SwNodeOffset m_nNode
Definition: docfld.hxx:47
const SwNode * GetNodeFromContent() const
Definition: docfld.cxx:279
SwNodeOffset GetNode() const
Definition: docfld.hxx:99
bool m_bFieldsDirty
some fields are invalid
Definition: docfld.hxx:148
virtual void StartIdling()=0
Start the idle task.
OUString LookString(SwHashTable< HashStr > const &rTable, std::u16string_view rName)
Look up the Name, if it is present, return its String, otherwise return an empty String.
Definition: docfld.cxx:362
void SetBodyPos(const SwContentFrame &rFrame)
Definition: docfld.cxx:196
const SwPosition * pPos
Definition: docfld.hxx:51
::sw::mark::IBookmark const * GetBookmark() const
Definition: docfld.hxx:92
void GetBodyNode(const SwTextField &, SwFieldIds nFieldWhich)
Definition: docfld.cxx:1025
void RemoveFieldType(const SwFieldType &rType)
Definition: docfld.cxx:1153
std::unique_ptr< SetGetExpFields > m_pFieldSortList
current field list for calculation
Definition: docfld.hxx:140
SwFieldIds
Definition: fldbas.hxx:45
void SetInUpdateFields(bool b)
Definition: docfld.hxx:169
Marks a character position inside a document model node.
Definition: index.hxx:33
sal_Int32 GetCntPosFromContent() const
Definition: docfld.cxx:327
const SwFlyFrameFormat * GetFlyFormat() const
Definition: docfld.hxx:96
Marks a node in the document model.
Definition: ndindex.hxx:32
const SwFieldType * pFieldType
Definition: docfld.hxx:124
const SwTableBox * pTBox
Definition: docfld.hxx:53
const SetGetExpFields * GetSortList() const
Definition: docfld.hxx:159
::sw::mark::IBookmark const * pBookmark
Definition: docfld.hxx:56
const SwSection * GetSection() const
Definition: docfld.hxx:90
bool operator<(const SetGetExpField &rField) const
Definition: docfld.cxx:221
const SwSection * pSection
Definition: docfld.hxx:50
const int GETFLD_EXPAND
Definition: docfld.hxx:136
SwHashTable< SwCalcFieldType > const & GetFieldTypeTable() const
Definition: docfld.hxx:182
void MakeFieldList_(SwDoc &pDoc, int eGetMode)
Definition: docfld.cxx:825
int m_nFieldListGetMode
Definition: docfld.hxx:144
OUString aSetStr
Definition: docfld.hxx:118
void SetFieldsDirty(bool b)
Definition: docfld.hxx:172
enum SetGetExpField::SetGetExpFieldType m_eSetGetExpFieldType
const SwTextINetFormat * pTextINet
Definition: docfld.hxx:54
const SwTextINetFormat * GetINetFormat() const
Definition: docfld.hxx:94
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:406
void GetBodyNodeGeneric(SwNode const &rNode, T const &)
Definition: docfld.cxx:1079
HashStr(const OUString &rName, const OUString &rText, HashStr *)
Definition: docfld.cxx:354
const SwTextField * GetTextField() const
Definition: docfld.hxx:88
SwCalcFieldType(const OUString &rStr, const SwFieldType *pFieldTyp)
Definition: docfld.hxx:126
void GetPosOfContent(SwPosition &rPos) const
Definition: docfld.cxx:178
const SwTextField * pTextField
Definition: docfld.hxx:49
void MakeFieldList(SwDoc &rDoc, bool bAll, int eGetMode)
Definition: docfld.cxx:815
void InsertFieldType(const SwFieldType &rType)
Definition: docfld.cxx:1120
const SwFlyFrameFormat * pFlyFormat
Definition: docfld.hxx:55
bool operator==(const SetGetExpField &rField) const
Definition: docfld.cxx:212
const int GETFLD_CALC
Definition: docfld.hxx:135
SwHashTable< SwCalcFieldType > m_FieldTypeTable
Definition: docfld.hxx:141
T should be a subclass of SwHash.
Definition: calc.hxx:151
IDocumentTimerAccess const & getIDocumentTimerAccess() const
Definition: doc.cxx:249
union SetGetExpField::@4 m_CNTNT
void InsDelFieldInFieldLst(bool bIns, const SwTextField &rField)
Definition: docfld.cxx:771
Base class of the Writer document model elements.
Definition: node.hxx:81
SwDoc & m_rDoc
Definition: docfld.hxx:145