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