summaryrefslogtreecommitdiff
path: root/sw/source/core/inc/docfld.hxx
blob: 33b9a19611083d59e0bc7e6874c4c52d71cf58e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_SW_SOURCE_CORE_INC_DOCFLD_HXX
#define INCLUDED_SW_SOURCE_CORE_INC_DOCFLD_HXX

#include <calc.hxx>
#include <doc.hxx>
#include <IDocumentTimerAccess.hxx>
#include <o3tl/sorted_vector.hxx>
#include <memory>

class SwTextField;
class SwIndex;
class SwNodeIndex;
class SwContentFrame;
class SwSectionNode;
class SwSection;
class SwTextTOXMark;
class SwTableBox;
class SwTextINetFormat;
class SwFlyFrameFormat;
class SwDoc;
class SwNode;
struct SwPosition;
enum class SwFieldIds : sal_uInt16;

// Update expression fields
class SetGetExpField
{
    sal_uLong nNode;
    sal_Int32 nContent;
    union {
        const SwTextField* pTextField;
        const SwSection* pSection;
        const SwPosition* pPos;
        const SwTextTOXMark* pTextTOX;
        const SwTableBox* pTBox;
        const SwTextINetFormat* pTextINet;
        const SwFlyFrameFormat* pFlyFormat;
    } CNTNT;
    enum SetGetExpFieldType
        {
            TEXTFIELD, TEXTTOXMARK, SECTIONNODE, CRSRPOS, TABLEBOX,
            TEXTINET, FLYFRAME
        } eSetGetExpFieldType;

public:
    SetGetExpField( const SwNodeIndex& rNdIdx, const SwTextField* pField = nullptr,
                    const SwIndex* pIdx = nullptr );

    SetGetExpField( const SwNodeIndex& rNdIdx, const SwTextINetFormat& rINet );

    SetGetExpField( const SwSectionNode& rSectNode,
                    const SwPosition* pPos = nullptr  );

    SetGetExpField( const SwTableBox& rTableBox  );

    SetGetExpField( const SwNodeIndex& rNdIdx, const SwTextTOXMark& rTOX );

    SetGetExpField( const SwPosition& rPos );

    SetGetExpField( const SwFlyFrameFormat& rFlyFormat, const SwPosition* pPos );

    bool operator==( const SetGetExpField& rField ) const;
    bool operator<( const SetGetExpField& rField ) const;

    const SwTextField* GetTextField() const
        { return TEXTFIELD == eSetGetExpFieldType ? CNTNT.pTextField : nullptr; }
    const SwSection* GetSection() const
        { return SECTIONNODE == eSetGetExpFieldType ? CNTNT.pSection : nullptr; }
    const SwTextINetFormat* GetINetFormat() const
        { return TEXTINET == eSetGetExpFieldType ? CNTNT.pTextINet : nullptr; }
    const SwFlyFrameFormat* GetFlyFormat() const
        { return FLYFRAME == eSetGetExpFieldType ? CNTNT.pFlyFormat : nullptr; }

    sal_uLong GetNode() const { return nNode; }
    sal_Int32 GetContent() const { return nContent; }
    const void* GetPointer() const { return CNTNT.pTextField; }

    void GetPosOfContent( SwPosition& rPos ) const;

    const SwNode* GetNodeFromContent() const;
    sal_Int32 GetCntPosFromContent() const;

    void SetBodyPos( const SwContentFrame& rFrame );
};

class SetGetExpFields : public o3tl::sorted_vector<SetGetExpField*, o3tl::less_ptr_to<SetGetExpField> >
{
public:
    ~SetGetExpFields() { DeleteAndDestroyAll(); }
};

// struct for saving strings from the SetExp's string fields
struct HashStr : public SwHash
{
    OUString aSetStr;
    HashStr( const OUString& rName, const OUString& rText, HashStr* );
};

struct SwCalcFieldType : public SwHash
{
    const SwFieldType* pFieldType;

    SwCalcFieldType( const OUString& rStr, const SwFieldType* pFieldTyp )
        : SwHash( rStr ), pFieldType( pFieldTyp )
    {}
};

// search for the string that was saved under rName in the hash table
OUString LookString( SwHashTable<HashStr> const & rTable, const OUString& rName );

const int GETFLD_ALL        = 3;        // combine flags via OR
const int GETFLD_CALC       = 1;
const int GETFLD_EXPAND     = 2;

class SwDocUpdateField
{
    std::unique_ptr<SetGetExpFields> pFieldSortLst;    // current field list for calculation
    SwHashTable<SwCalcFieldType> aFieldTypeTable;

    sal_uLong nNodes;               // if the node count is different
    sal_uInt8 nFieldLstGetMode;
    SwDoc* pDocument;

    bool bInUpdateFields : 1;     // currently there is an UpdateFields
    bool bFieldsDirty : 1;        // some fields are invalid

    void MakeFieldList_( SwDoc& pDoc, int eGetMode );
    void GetBodyNode( const SwTextField& , SwFieldIds nFieldWhich );
    void GetBodyNode( const SwSectionNode&);

public:
    SwDocUpdateField(SwDoc* pDocument);
    ~SwDocUpdateField();

    const SetGetExpFields* GetSortLst() const { return pFieldSortLst.get(); }

    void MakeFieldList( SwDoc& rDoc, bool bAll, int eGetMode );

    void InsDelFieldInFieldLst( bool bIns, const SwTextField& rField );

    void InsertFieldType( const SwFieldType& rType );
    void RemoveFieldType( const SwFieldType& rType );

    bool IsInUpdateFields() const         { return bInUpdateFields; }
    void SetInUpdateFields( bool b )      { bInUpdateFields = b; }

    bool IsFieldsDirty() const          { return bFieldsDirty; }
    void SetFieldsDirty( bool b )
    {
        bFieldsDirty = b;

        if (b)
        {
            pDocument->getIDocumentTimerAccess().StartIdling();
        }
    }

    SwHashTable<SwCalcFieldType> const & GetFieldTypeTable() const { return aFieldTypeTable; }
};

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */