Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/inc/reffld.hxx
Line
Count
Source
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
#ifndef INCLUDED_SW_INC_REFFLD_HXX
20
#define INCLUDED_SW_INC_REFFLD_HXX
21
22
#include <tools/solar.h>
23
24
#include "fldbas.hxx"
25
#include "names.hxx"
26
#include "reffldsubtype.hxx"
27
28
class SwDoc;
29
class SwTextNode;
30
class SwTextField;
31
class SwRootFrame;
32
class SwFrame;
33
34
bool IsFrameBehind( const SwTextNode& rMyNd, sal_Int32 nMySttPos,
35
                    const SwTextNode& rBehindNd, sal_Int32 nSttPos );
36
37
#define REFFLDFLAG          0x4000
38
#define REFFLDFLAG_BOOKMARK 0x4800
39
#define REFFLDFLAG_FOOTNOTE 0x5000
40
#define REFFLDFLAG_ENDNOTE  0x6000
41
// #i83479#
42
#define REFFLDFLAG_HEADING  0x7100
43
#define REFFLDFLAG_NUMITEM  0x7200
44
45
#define REFFLDFLAG_STYLE    0xc000
46
/* we skip past 0x8000, 0x9000, 0xa000 and 0xb000 as when we bitwise 'and'
47
       with REFFLDFLAG they are false */
48
0
#define REFFLDFLAG_STYLE_FROM_BOTTOM           0xc100
49
0
#define REFFLDFLAG_STYLE_HIDE_NON_NUMERICAL    0xc200
50
51
enum class RefFieldFormat : sal_uInt16
52
{
53
    Begin,
54
    Page = Begin,      ///< "Page"
55
    Chapter,           ///< "Chapter"
56
    Content,           ///< "Reference"
57
    UpDown,            ///< "Above/Below"
58
    AsPageStyle,       ///< "As Page Style"
59
    CategoryAndNumber, ///< "Category and Number"
60
    CaptionText,       ///< "Caption Text"
61
    Numbering,         ///< "Numbering"
62
    // --> #i81002#
63
    /// new reference format types for referencing bookmarks and set references
64
    Number,            ///< "Number"
65
    NumberNoContext,   ///< "Number (no context)"
66
    NumberFullContext, ///< "Number (full context)"
67
};
68
69
/// Get reference.
70
71
class SAL_DLLPUBLIC_RTTI SwGetRefFieldType final : public SwFieldType
72
{
73
    SwDoc& m_rDoc;
74
75
    /// Overlay in order to update all ref-fields.
76
    virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
77
public:
78
    SwGetRefFieldType(SwDoc& rDoc );
79
    virtual std::unique_ptr<SwFieldType> Copy() const override;
80
3.28k
    virtual void UpdateFields() override {};
81
82
67
    SwDoc&                  GetDoc() const { return m_rDoc; }
83
84
    void MergeWithOtherDoc( SwDoc& rDestDoc );
85
86
    static SwTextNode* FindAnchor( SwDoc* pDoc, const SwMarkName& rRefMark,
87
                                        ReferencesSubtype nSubType, sal_uInt16 nSeqNo, sal_uInt16 nFlags,
88
                                        sal_Int32* pStart, sal_Int32* pEnd = nullptr,
89
                                        SwRootFrame const* pLayout = nullptr,
90
                                        const SwTextNode* pSelf = nullptr, SwFrame* pFrame = nullptr);
91
    void UpdateGetReferences();
92
    void UpdateStyleReferences();
93
94
private:
95
    static SwTextNode* FindAnchorRefStyle( SwDoc* pDoc, const SwMarkName& rRefMark,
96
                                        sal_uInt16 nFlags,
97
                                        sal_Int32* pStart, sal_Int32* pEnd,
98
                                        SwRootFrame const* pLayout,
99
                                        const SwTextNode* pSelf, SwFrame* pFrame);
100
    static SwTextNode* FindAnchorRefStyleMarginal( SwDoc* pDoc,
101
                                        sal_uInt16 nFlags,
102
                                        sal_Int32* pStart, sal_Int32* pEnd,
103
                                        const SwTextNode* pSelf, SwFrame* pFrame,
104
                                        const SwTextNode* pReference, std::u16string_view styleName);
105
    static SwTextNode* FindAnchorRefStyleOther( SwDoc* pDoc,
106
                                        sal_Int32* pStart, sal_Int32* pEnd,
107
                                        const SwTextNode* pSelf,
108
                                        const SwTextNode* pReference, std::u16string_view styleName);
109
};
110
111
/// A cross-reference field: refers to a property (page number, relative location, etc) of a
112
/// bookmark or reference mark. When referring to headings, the bookmark is created implicitly by
113
/// the UI.
114
///
115
/// Insert -> Field -> Cross-references on the UI.
116
class SAL_DLLPUBLIC_RTTI SwGetRefField final : public SwField
117
{
118
private:
119
    SwMarkName m_sSetRefName;
120
    OUString m_sSetReferenceLanguage;
121
    OUString m_sText;         ///< result
122
    OUString m_sTextRLHidden; ///< result for layout with redlines hidden
123
    ReferencesSubtype m_nSubType;
124
    /// reference to either a SwTextFootnote::m_nSeqNo or a SwSetExpField::mnSeqNo
125
    sal_uInt16 m_nSeqNo;
126
    sal_uInt16 m_nFlags;
127
    RefFieldFormat m_nFormat;
128
129
    virtual OUString    ExpandImpl(SwRootFrame const* pLayout) const override;
130
    virtual std::unique_ptr<SwField> Copy() const override;
131
public:
132
    SW_DLLPUBLIC SwGetRefField( SwGetRefFieldType*, SwMarkName aSetRef, OUString aReferenceLanguage,
133
                    ReferencesSubtype nSubType, sal_uInt16 nSeqNo, sal_uInt16 nFlags, RefFieldFormat nFormat );
134
135
    SW_DLLPUBLIC virtual ~SwGetRefField() override;
136
137
4.33k
    RefFieldFormat GetFormat() const { return m_nFormat; }
138
0
    void SetFormat(RefFieldFormat n) { m_nFormat = n; }
139
140
    virtual OUString GetFieldName() const override;
141
142
103
    const SwMarkName& GetSetRefName() const { return m_sSetRefName; }
143
144
    // #i81002#
145
    /** The <SwTextField> instance, which represents the text attribute for the
146
       <SwGetRefField> instance, has to be passed to the method.
147
       This <SwTextField> instance is needed for the reference format type REF_UPDOWN, REF_NUMBER
148
       and ReferencesSubtype::Style.
149
       Note: This instance may be NULL (field in Undo/Redo). This will cause
150
       no update for these reference format types. */
151
    void                UpdateField( const SwTextField* pFieldTextAttr, SwFrame* pFrame );
152
    void                UpdateField( const SwTextField* pFieldTextAttr, SwFrame* pFrame,
153
                                     const SwRootFrame* const pLayout, OUString& rText );
154
155
    void                SetExpand( const OUString& rStr );
156
157
    /// Get/set sub type.
158
    SW_DLLPUBLIC ReferencesSubtype GetSubType() const;
159
    SW_DLLPUBLIC void SetSubType( ReferencesSubtype n );
160
161
    // --> #i81002#
162
    SW_DLLPUBLIC bool IsRefToHeadingCrossRefBookmark() const;
163
    SW_DLLPUBLIC bool IsRefToNumItemCrossRefBookmark() const;
164
    SW_DLLPUBLIC const SwTextNode* GetReferencedTextNode() const;
165
    // #i85090#
166
    SW_DLLPUBLIC OUString GetExpandedTextOfReferencedTextNode(SwRootFrame const& rLayout) const;
167
168
    /// Get/set SequenceNo (of interest only for ReferencesSubtype::SequenceField).
169
0
    sal_uInt16              GetSeqNo() const        { return m_nSeqNo; }
170
0
    void                SetSeqNo( sal_uInt16 n )    { m_nSeqNo = n; }
171
172
    /// Get/set flags (currently only used for ReferencesSubtype::Style)
173
0
    sal_uInt16              GetFlags() const        { return m_nFlags; }
174
0
    void                SetFlags( sal_uInt16 n )    { m_nFlags = n; }
175
176
    // Name of reference.
177
    SW_DLLPUBLIC virtual OUString GetPar1() const override;
178
    virtual void        SetPar1(const OUString& rStr) override;
179
180
    SW_DLLPUBLIC virtual OUString GetPar2() const override;
181
    virtual bool        QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const override;
182
    virtual bool        PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId ) override;
183
184
    void                ConvertProgrammaticToUIName();
185
186
    virtual OUString    GetDescription() const override;
187
};
188
189
#endif /// INCLUDED_SW_INC_REFFLD_HXX
190
191
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */