Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/inc/section.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
20
#ifndef INCLUDED_SW_INC_SECTION_HXX
21
#define INCLUDED_SW_INC_SECTION_HXX
22
23
#include <com/sun/star/uno/Sequence.h>
24
#include <com/sun/star/text/XTextSection.hpp>
25
26
#include <tools/ref.hxx>
27
#include <svl/hint.hxx>
28
#include <svl/listener.hxx>
29
#include <sfx2/lnkbase.hxx>
30
#include <sfx2/Metadatable.hxx>
31
#include <unotools/weakref.hxx>
32
33
#include "frmfmt.hxx"
34
#include <vector>
35
36
class SwSectionFormat;
37
class SwDoc;
38
class SwSection;
39
class SwSectionNode;
40
class SwTOXBase;
41
class SwServerObject;
42
class SwXTextSection;
43
44
typedef std::vector<SwSection*> SwSections;
45
46
enum class SectionType { Content,
47
                    ToxHeader,
48
                    ToxContent,
49
                    DdeLink    = static_cast<int>(sfx2::SvBaseLinkObjectType::ClientDde),
50
                    FileLink   = static_cast<int>(sfx2::SvBaseLinkObjectType::ClientFile)
51
                    };
52
53
enum class LinkCreateType
54
{
55
    NONE,            // Do nothing.
56
    Connect,         // Connect created link.
57
    Update           // Connect created link and update it.
58
};
59
60
class SW_DLLPUBLIC SwSectionData
61
{
62
private:
63
    SectionType m_eType;
64
65
    UIName m_sSectionName;
66
    OUString m_sCondition; ///< Hide condition
67
    OUString m_sLinkFileName;
68
    OUString m_sLinkFilePassword; // Must be changed to Sequence.
69
    css::uno::Sequence <sal_Int8> m_Password;
70
    sal_uInt16 m_nPage; // loaded meta page count for page anchored flys in master document
71
72
    /// It seems this flag caches the current final "hidden" state.
73
    bool m_bHiddenFlag          : 1;
74
    /// Flags that correspond to attributes in the format:
75
    /// may have different value than format attribute:
76
    /// format attr has value for this section, while flag is
77
    /// effectively ORed with parent sections!
78
    bool m_bProtectFlag         : 1; ///< protect flag is no longer inherited
79
    // Edit in readonly sections.
80
    bool m_bEditInReadonlyFlag  : 1;
81
82
    bool m_bHidden              : 1; ///< Section is hidden, unless condition evaluates `false'
83
    bool m_bCondHiddenFlag      : 1; ///< Hide condition evaluated `true'
84
    bool m_bConnectFlag         : 1; // Connected to server?
85
86
public:
87
88
    SwSectionData(SectionType const eType, UIName aName);
89
    explicit SwSectionData(SwSection const&);
90
    SwSectionData(SwSectionData const&);
91
    SwSectionData & operator=(SwSectionData const&);
92
    bool operator==(SwSectionData const&) const;
93
94
3.03M
    const UIName& GetSectionName() const         { return m_sSectionName; }
95
6.04k
    void SetSectionName(UIName const& rName){ m_sSectionName = rName; }
96
530k
    SectionType GetType() const             { return m_eType; }
97
2.19k
    void SetType(SectionType const eNew)    { m_eType = eNew; }
98
99
15.3M
    bool IsHidden() const { return m_bHidden; }
100
5.20k
    void SetHidden(bool const bFlag) { m_bHidden = bFlag; }
101
102
61.8k
    bool IsHiddenFlag() const { return m_bHiddenFlag; }
103
    SAL_DLLPRIVATE void
104
11.3k
        SetHiddenFlag(bool const bFlag) { m_bHiddenFlag = bFlag; }
105
54.6k
    bool IsProtectFlag() const { return m_bProtectFlag; }
106
    SAL_DLLPRIVATE void
107
121k
        SetProtectFlag(bool const bFlag) { m_bProtectFlag = bFlag; }
108
141k
    bool IsEditInReadonlyFlag() const { return m_bEditInReadonlyFlag; }
109
    void SetEditInReadonlyFlag(bool const bFlag)
110
141k
        { m_bEditInReadonlyFlag = bFlag; }
111
112
0
    void SetCondHidden(bool const bFlag) { m_bCondHiddenFlag = bFlag; }
113
137k
    bool IsCondHidden() const { return m_bCondHiddenFlag; }
114
115
2.47k
    const OUString& GetCondition() const           { return m_sCondition; }
116
5.94k
    void SetCondition(OUString const& rNew) { m_sCondition = rNew; }
117
118
4.76k
    const OUString& GetLinkFileName() const        { return m_sLinkFileName; }
119
    void SetLinkFileName(OUString const& rNew)
120
7.95k
    {
121
7.95k
        m_sLinkFileName = rNew;
122
7.95k
    }
123
124
277
    const OUString& GetLinkFilePassword() const        { return m_sLinkFilePassword; }
125
0
    void SetLinkFilePassword(OUString const& rS){ m_sLinkFilePassword = rS; }
126
127
    css::uno::Sequence<sal_Int8> const& GetPassword() const
128
277
                                            { return m_Password; }
129
    void SetPassword(css::uno::Sequence<sal_Int8> const& rNew)
130
0
                                            { m_Password = rNew; }
131
    bool IsLinkType() const
132
53.7k
    { return (SectionType::DdeLink == m_eType) || (SectionType::FileLink == m_eType); }
133
134
277
    bool IsConnectFlag() const                  { return m_bConnectFlag; }
135
0
    void SetConnectFlag(bool const bFlag){ m_bConnectFlag = bFlag; }
136
137
277
    sal_uInt16 GetPageNum() const         { return m_nPage; }
138
0
    void SetPageNum(sal_uInt16 nPageNum){ m_nPage = nPageNum; }
139
140
    void dumpAsXml(xmlTextWriterPtr pWriter) const;
141
};
142
143
class SW_DLLPUBLIC SwSection
144
    : public SwClient
145
    , public SvtListener // needed for SwClientNotify to be called from SwSectionFormat
146
{
147
    // In order to correctly maintain the flag when creating/deleting frames.
148
    friend class SwSectionNode;
149
    // The "read CTOR" of SwSectionFrame have to change the Hiddenflag.
150
    friend class SwSectionFrame;
151
152
private:
153
    mutable SwSectionData m_Data;
154
155
    tools::SvRef<SwServerObject> m_RefObj; // Set if DataServer.
156
    tools::SvRef<sfx2::SvBaseLink> m_RefLink;
157
158
    SAL_DLLPRIVATE void ImplSetHiddenFlag(
159
            bool const bHidden, bool const bCondition);
160
161
protected:
162
    virtual void Notify(SfxHint const& rHint) override;
163
    virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
164
165
public:
166
167
    SwSection(SectionType const eType, UIName const& rName,
168
                SwSectionFormat & rFormat);
169
    virtual ~SwSection() override;
170
171
    bool DataEquals(SwSectionData const& rCmp) const;
172
173
    void SetSectionData(SwSectionData const& rData);
174
175
2.98M
    const UIName& GetSectionName() const         { return m_Data.GetSectionName(); }
176
6.04k
    void SetSectionName(UIName const& rName){ m_Data.SetSectionName(rName); }
177
347k
    SectionType GetType() const             { return m_Data.GetType(); }
178
2.19k
    void SetType(SectionType const eType)   { return m_Data.SetType(eType); }
179
180
    inline SwSectionFormat* GetFormat();
181
    inline SwSectionFormat const * GetFormat() const;
182
183
    // Set hidden/protected -> update the whole tree!
184
    // (Attributes/flags are set/get.)
185
15.1M
    bool IsHidden()  const { return m_Data.IsHidden(); }
186
    void SetHidden (bool const bFlag = true);
187
    bool IsProtect() const;
188
    void SetProtect(bool const bFlag = true);
189
    bool IsEditInReadonly() const;
190
    void SetEditInReadonly(bool const bFlag = true);
191
192
    // Get internal flags (state including parents, not what is
193
    // currently set at section!).
194
60.4k
    bool IsHiddenFlag()  const { return m_Data.IsHiddenFlag(); }
195
4.05k
    bool IsProtectFlag() const { return m_Data.IsProtectFlag(); }
196
38.0k
    bool IsEditInReadonlyFlag() const { return m_Data.IsEditInReadonlyFlag(); }
197
198
    void SetCondHidden(bool const bFlag);
199
33.7k
    bool IsCondHidden() const { return m_Data.IsCondHidden(); }
200
    // Query (also for parents) if this section is to be hidden.
201
    bool CalcHiddenFlag() const;
202
203
    inline SwSection* GetParent() const;
204
205
2.47k
    OUString const & GetCondition() const           { return m_Data.GetCondition(); }
206
2.19k
    void SetCondition(OUString const& rNew) { m_Data.SetCondition(rNew); }
207
208
    OUString const & GetLinkFileName() const;
209
    void SetLinkFileName(OUString const& rNew);
210
    // Password of linked file (only valid during runtime!)
211
    OUString const & GetLinkFilePassword() const
212
277
        { return m_Data.GetLinkFilePassword(); }
213
    void SetLinkFilePassword(OUString const& rS)
214
0
        { m_Data.SetLinkFilePassword(rS); }
215
216
    // Get / set password of this section
217
    css::uno::Sequence<sal_Int8> const& GetPassword() const
218
277
                                            { return m_Data.GetPassword(); }
219
220
    sal_uInt16 GetPageNum() const
221
277
        { return m_Data.GetPageNum(); }
222
    void SetPageNum(sal_uInt16 nPage)
223
0
        { m_Data.SetPageNum(nPage); }
224
225
    // Data server methods.
226
    void SetRefObject( SwServerObject* pObj );
227
0
    const SwServerObject* GetObject() const {  return m_RefObj.get(); }
228
0
          SwServerObject* GetObject()       {  return m_RefObj.get(); }
229
3.48k
    bool IsServer() const                   {  return m_RefObj.is(); }
230
231
    // Methods for linked ranges.
232
0
    SfxLinkUpdateMode GetUpdateType() const    { return m_RefLink->GetUpdateMode(); }
233
    void SetUpdateType(SfxLinkUpdateMode nType )
234
0
        { m_RefLink->SetUpdateMode(nType); }
235
236
0
    bool IsConnected() const        { return m_RefLink.is(); }
237
0
    void UpdateNow()                { m_RefLink->Update(); }
238
0
    void Disconnect()               { m_RefLink->Disconnect(); }
239
240
0
    const ::sfx2::SvBaseLink& GetBaseLink() const    { return *m_RefLink; }
241
0
          ::sfx2::SvBaseLink& GetBaseLink()          { return *m_RefLink; }
242
243
    void CreateLink( LinkCreateType eType );
244
245
    static void MakeChildLinksVisible( const SwSectionNode& rSectNd );
246
247
3.48k
    bool IsLinkType() const { return m_Data.IsLinkType(); }
248
249
    // Flags for UI. Did connection work?
250
277
    bool IsConnectFlag() const      { return m_Data.IsConnectFlag(); }
251
    void SetConnectFlag(bool const bFlag = true)
252
0
                                    { m_Data.SetConnectFlag(bFlag); }
253
254
    // Return the TOX base class if the section is a TOX section
255
    const SwTOXBase* GetTOXBase() const;
256
257
    void BreakLink();
258
259
    void dumpAsXml(xmlTextWriterPtr pWriter) const;
260
};
261
262
// #i117863#
263
class SwSectionFrameMoveAndDeleteHint final : public SfxHint
264
{
265
    public:
266
        SwSectionFrameMoveAndDeleteHint( const bool bSaveContent )
267
147k
            : SfxHint( SfxHintId::SwSectionFrameMoveAndDelete )
268
147k
            , mbSaveContent( bSaveContent )
269
147k
        {}
270
271
        bool IsSaveContent() const
272
0
        {
273
0
            return mbSaveContent;
274
0
        }
275
276
    private:
277
        const bool mbSaveContent;
278
};
279
280
enum class SectionSort { Not, Pos };
281
282
class SW_DLLPUBLIC SwSectionFormat final
283
    : public SwFrameFormat
284
    , public ::sfx2::Metadatable
285
{
286
    friend class SwDoc;
287
288
    /** Why does this exist in addition to the m_wXObject in SwFrameFormat?
289
        in case of an index, both a SwXDocumentIndex and a SwXTextSection
290
        register at this SwSectionFormat, so we need to have two refs.
291
     */
292
    unotools::WeakReference<SwXTextSection> m_wXTextSection;
293
294
    SAL_DLLPRIVATE void UpdateParent();      // Parent has been changed.
295
296
    SwSectionFormat( SwFrameFormat* pDrvdFrame, SwDoc& rDoc );
297
    virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
298
299
public:
300
    virtual ~SwSectionFormat() override;
301
302
    // Deletes all Frames in aDepend (Frames are recognized via dynamic_cast).
303
    virtual void DelFrames() override;
304
305
    // Creates views.
306
    virtual void MakeFrames() override;
307
308
    // Get information from Format.
309
    virtual bool GetInfo( SwFindNearestNode& ) const override;
310
311
    virtual bool IsVisible() const override;
312
313
    SwSection* GetSection() const;
314
    inline SwSectionFormat* GetParent() const;
315
    inline SwSection* GetParentSection() const;
316
317
    //  All sections that are derived from this one:
318
    //  - sorted according to name or position or unsorted
319
    //  - all of them or only those that are in the normal Nodes-array.
320
    void GetChildSections( SwSections& rArr,
321
                            SectionSort eSort = SectionSort::Not,
322
                            bool bAllSections = true ) const;
323
324
    // Query whether section is in Nodes-array or in UndoNodes-array.
325
    bool IsInNodesArr() const;
326
327
          SwSectionNode* GetSectionNode();
328
    const SwSectionNode* GetSectionNode() const
329
148
        { return const_cast<SwSectionFormat *>(this)
330
148
                ->GetSectionNode(); }
331
332
    // Is section a valid one for global document?
333
    const SwSection* GetGlobalDocSection() const;
334
335
    SAL_DLLPRIVATE unotools::WeakReference<SwXTextSection> const& GetXTextSection() const
336
0
            { return m_wXTextSection; }
337
    SAL_DLLPRIVATE void SetXTextSection(rtl::Reference<SwXTextSection> const& xTextSection);
338
339
    // sfx2::Metadatable
340
    virtual ::sfx2::IXmlIdRegistry& GetRegistry() override;
341
    virtual bool IsInClipboard() const override;
342
    virtual bool IsInUndo() const override;
343
    virtual bool IsInContent() const override;
344
    virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override;
345
    virtual bool supportsFullDrawingLayerFillAttributeSet() const override;
346
    void dumpAsXml(xmlTextWriterPtr pWriter) const override;
347
348
};
349
350
SwSectionFormat* SwSection::GetFormat()
351
385k
{
352
385k
    return static_cast<SwSectionFormat*>(GetRegisteredIn());
353
385k
}
354
355
SwSectionFormat const * SwSection::GetFormat() const
356
15.2M
{
357
15.2M
    return static_cast<SwSectionFormat const *>(GetRegisteredIn());
358
15.2M
}
359
360
inline SwSection* SwSection::GetParent() const
361
15.1M
{
362
15.1M
    SwSectionFormat const * pFormat = GetFormat();
363
15.1M
    SwSection* pRet = nullptr;
364
15.1M
    if( pFormat )
365
15.1M
        pRet = pFormat->GetParentSection();
366
15.1M
    return pRet;
367
15.1M
}
368
369
inline SwSectionFormat* SwSectionFormat::GetParent() const
370
15.1M
{
371
15.1M
    SwSectionFormat* pRet = nullptr;
372
15.1M
    if( GetRegisteredIn() )
373
15.1M
        pRet = const_cast<SwSectionFormat*>(dynamic_cast< const SwSectionFormat* >( GetRegisteredIn() ));
374
15.1M
    return pRet;
375
15.1M
}
376
377
inline SwSection* SwSectionFormat::GetParentSection() const
378
15.1M
{
379
15.1M
    SwSectionFormat* pParent = GetParent();
380
15.1M
    SwSection* pRet = nullptr;
381
15.1M
    if( pParent )
382
15.0M
    {
383
15.0M
        pRet = pParent->GetSection();
384
15.0M
    }
385
15.1M
    return pRet;
386
15.1M
}
387
388
#endif /* _ INCLUDED_SW_INC_SECTION_HXX */
389
390
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */