Line data Source code
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 _DOCFLD_HXX
21 : #define _DOCFLD_HXX
22 :
23 : #include <calc.hxx>
24 : #include <doc.hxx>
25 : #include <o3tl/sorted_vector.hxx>
26 :
27 : class SwTxtFld;
28 : class SwIndex;
29 : class SwNodeIndex;
30 : class SwCntntFrm;
31 : class SwSectionNode;
32 : class SwSection;
33 : class SwTxtTOXMark;
34 : class SwTableBox;
35 : class SwTxtINetFmt;
36 : class SwFlyFrmFmt;
37 : class SwDoc;
38 : class SwNode;
39 : struct SwPosition;
40 :
41 : // Update expression fields
42 : class _SetGetExpFld
43 : {
44 : sal_uLong nNode;
45 : xub_StrLen nCntnt;
46 : union {
47 : const SwTxtFld* pTxtFld;
48 : const SwSection* pSection;
49 : const SwPosition* pPos;
50 : const SwTxtTOXMark* pTxtTOX;
51 : const SwTableBox* pTBox;
52 : const SwTxtINetFmt* pTxtINet;
53 : const SwFlyFrmFmt* pFlyFmt;
54 : } CNTNT;
55 : enum _SetGetExpFldType
56 : {
57 : TEXTFIELD, TEXTTOXMARK, SECTIONNODE, CRSRPOS, TABLEBOX,
58 : TEXTINET, FLYFRAME
59 : } eSetGetExpFldType;
60 :
61 : public:
62 : _SetGetExpFld( const SwNodeIndex& rNdIdx, const SwTxtFld* pFld = 0,
63 : const SwIndex* pIdx = 0 );
64 :
65 : _SetGetExpFld( const SwNodeIndex& rNdIdx, const SwTxtINetFmt& rINet,
66 : const SwIndex* pIdx = 0 );
67 :
68 : _SetGetExpFld( const SwSectionNode& rSectNode,
69 : const SwPosition* pPos = 0 );
70 :
71 : _SetGetExpFld( const SwTableBox& rTableBox,
72 : const SwPosition* pPos = 0 );
73 :
74 : _SetGetExpFld( const SwNodeIndex& rNdIdx, const SwTxtTOXMark& rTOX,
75 : const SwIndex* pIdx );
76 :
77 : _SetGetExpFld( const SwPosition& rPos );
78 :
79 : _SetGetExpFld( const SwFlyFrmFmt& rFlyFmt, const SwPosition* pPos = 0 );
80 :
81 0 : bool operator==( const _SetGetExpFld& rFld ) const
82 : { return nNode == rFld.nNode && nCntnt == rFld.nCntnt &&
83 0 : ( !CNTNT.pTxtFld || !rFld.CNTNT.pTxtFld ||
84 0 : CNTNT.pTxtFld == rFld.CNTNT.pTxtFld ); }
85 : bool operator<( const _SetGetExpFld& rFld ) const;
86 :
87 0 : const SwTxtFld* GetFld() const
88 0 : { return TEXTFIELD == eSetGetExpFldType ? CNTNT.pTxtFld : 0; }
89 : const SwTxtTOXMark* GetTOX() const
90 : { return TEXTTOXMARK == eSetGetExpFldType ? CNTNT.pTxtTOX : 0; }
91 2 : const SwSection* GetSection() const
92 2 : { return SECTIONNODE == eSetGetExpFldType ? CNTNT.pSection : 0; }
93 : const SwTableBox* GetTableBox() const
94 : { return TABLEBOX == eSetGetExpFldType ? CNTNT.pTBox : 0; }
95 0 : const SwTxtINetFmt* GetINetFmt() const
96 0 : { return TEXTINET == eSetGetExpFldType ? CNTNT.pTxtINet : 0; }
97 0 : const SwFlyFrmFmt* GetFlyFmt() const
98 0 : { return FLYFRAME == eSetGetExpFldType ? CNTNT.pFlyFmt : 0; }
99 :
100 0 : sal_uLong GetNode() const { return nNode; }
101 0 : xub_StrLen GetCntnt() const { return nCntnt; }
102 0 : const void* GetPointer() const { return CNTNT.pTxtFld; }
103 :
104 : void GetPos( SwPosition& rPos ) const;
105 : void GetPosOfContent( SwPosition& rPos ) const;
106 :
107 : const SwNode* GetNodeFromCntnt() const;
108 : xub_StrLen GetCntPosFromCntnt() const;
109 :
110 : void SetBodyPos( const SwCntntFrm& rFrm );
111 : };
112 :
113 4 : class _SetGetExpFlds : public o3tl::sorted_vector<_SetGetExpFld*, o3tl::less_ptr_to<_SetGetExpFld> >
114 : {
115 : public:
116 0 : ~_SetGetExpFlds() { DeleteAndDestroyAll(); }
117 : };
118 :
119 : // struct for saving strings from the SetExp's string fields
120 2 : struct _HashStr : public SwHash
121 : {
122 : String aSetStr;
123 : _HashStr( const String& rName, const String& rText, _HashStr* = 0 );
124 : };
125 :
126 0 : struct SwCalcFldType : public SwHash
127 : {
128 : const SwFieldType* pFldType;
129 :
130 2 : SwCalcFldType( const String& rStr, const SwFieldType* pFldTyp )
131 2 : : SwHash( rStr ), pFldType( pFldTyp )
132 2 : {}
133 : };
134 :
135 : // search for the string that was saved under rName in the hash table
136 : void LookString( SwHash** ppTbl, sal_uInt16 nSize, const String& rName,
137 : String& rRet, sal_uInt16* pPos = 0 );
138 :
139 : const int GETFLD_ALL = 3; // combine flags via OR
140 : const int GETFLD_CALC = 1;
141 : const int GETFLD_EXPAND = 2;
142 :
143 : class SwDocUpdtFld
144 : {
145 : _SetGetExpFlds* pFldSortLst; // current field list for calculation
146 : SwCalcFldType* aFldTypeTable[ TBLSZ ];
147 :
148 : sal_uLong nNodes; // if the node count is different
149 : sal_uInt8 nFldLstGetMode;
150 : SwDoc* pDocument;
151 :
152 : bool bInUpdateFlds : 1; // currently there is an UpdateFlds
153 : bool bFldsDirty : 1; // some fields are invalid
154 :
155 : void _MakeFldList( SwDoc& pDoc, int eGetMode );
156 : void GetBodyNode( const SwTxtFld& , sal_uInt16 nFldWhich );
157 : void GetBodyNode( const SwSectionNode&);
158 :
159 : public:
160 : SwDocUpdtFld(SwDoc* pDocument);
161 : ~SwDocUpdtFld();
162 :
163 10 : const _SetGetExpFlds* GetSortLst() const { return pFldSortLst; }
164 :
165 : void MakeFldList( SwDoc& rDoc, int bAll, int eGetMode );
166 :
167 : void InsDelFldInFldLst( bool bIns, const SwTxtFld& rFld );
168 :
169 : void InsertFldType( const SwFieldType& rType );
170 : void RemoveFldType( const SwFieldType& rType );
171 :
172 7 : bool IsInUpdateFlds() const { return bInUpdateFlds; }
173 14 : void SetInUpdateFlds( bool b ) { bInUpdateFlds = b; }
174 :
175 88 : bool IsFieldsDirty() const { return bFldsDirty; }
176 110 : void SetFieldsDirty( bool b )
177 : {
178 110 : bFldsDirty = b;
179 :
180 110 : if (b)
181 : {
182 48 : pDocument->StartBackgroundJobs();
183 : }
184 110 : }
185 :
186 4 : SwHash** GetFldTypeTable() const { return (SwHash**)aFldTypeTable; }
187 : };
188 :
189 : #endif
190 :
191 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|