Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/inc/unoparagraph.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_UNOPARAGRAPH_HXX
21
#define INCLUDED_SW_INC_UNOPARAGRAPH_HXX
22
23
#include <memory>
24
#include <optional>
25
26
#include <com/sun/star/lang/XServiceInfo.hpp>
27
#include <com/sun/star/beans/XPropertySet.hpp>
28
#include <com/sun/star/beans/XPropertyState.hpp>
29
#include <com/sun/star/beans/XMultiPropertySet.hpp>
30
#include <com/sun/star/beans/XTolerantMultiPropertySet.hpp>
31
#include <com/sun/star/container/XEnumerationAccess.hpp>
32
#include <com/sun/star/container/XContentEnumerationAccess.hpp>
33
#include <com/sun/star/text/XTextContent.hpp>
34
#include <com/sun/star/text/XTextRange.hpp>
35
36
#include <comphelper/interfacecontainer4.hxx>
37
#include <cppuhelper/implbase.hxx>
38
39
#include <sfx2/Metadatable.hxx>
40
#include <svl/listener.hxx>
41
42
#include "unobaseclass.hxx"
43
44
class SfxItemPropertySet;
45
class SfxItemSet;
46
struct SfxItemPropertyMapEntry;
47
class SwPaM;
48
class SwUnoCursor;
49
class SwTextNode;
50
class SwTableBox;
51
class SwXText;
52
class SwXTextPortionEnumeration;
53
54
typedef ::cppu::ImplInheritanceHelper
55
<   ::sfx2::MetadatableMixin
56
,   css::lang::XServiceInfo
57
,   css::beans::XPropertySet
58
,   css::beans::XPropertyState
59
,   css::beans::XMultiPropertySet
60
,   css::beans::XTolerantMultiPropertySet
61
,   css::container::XEnumerationAccess
62
,   css::container::XContentEnumerationAccess
63
,   css::text::XTextContent
64
,   css::text::XTextRange
65
> SwXParagraph_Base;
66
67
class SwXParagraph final
68
    : public SwXParagraph_Base
69
{
70
71
private:
72
73
    virtual ~SwXParagraph() override;
74
75
    SwXParagraph(css::uno::Reference< SwXText > const & xParent,
76
            SwTextNode & rTextNode,
77
            const sal_Int32 nSelStart, const sal_Int32 nSelEnd);
78
79
    /// descriptor
80
    SwXParagraph();
81
82
    /// @throws beans::UnknownPropertyException
83
    /// @throws beans::PropertyVetoException
84
    /// @throws lang::IllegalArgumentException
85
    /// @throws lang::WrappedTargetException
86
    /// @throws uno::RuntimeException
87
    void SetPropertyValues_Impl(
88
        const css::uno::Sequence< OUString >& rPropertyNames,
89
        const css::uno::Sequence< css::uno::Any >& rValues );
90
    /// @throws beans::UnknownPropertyException
91
    /// @throws lang::WrappedTargetException
92
    /// @throws uno::RuntimeException
93
    css::uno::Sequence< css::uno::Any > GetPropertyValues_Impl(
94
            const css::uno::Sequence< OUString >& rPropertyNames);
95
    SwTextNode& GetTextNodeOrThrow();
96
    /// @throws uno::RuntimeException
97
    static void GetSinglePropertyValue_Impl(
98
        const SfxItemPropertyMapEntry& rEntry,
99
        const SfxItemSet& rSet,
100
        css::uno::Any& rAny );
101
    /// @throws uno::RuntimeException
102
    css::uno::Sequence< css::beans::GetDirectPropertyTolerantResult >
103
        GetPropertyValuesTolerant_Impl(
104
            const css::uno::Sequence< OUString >& rPropertyNames,
105
            bool bDirectValuesOnly);
106
107
public:
108
109
    static rtl::Reference<SwXParagraph>
110
        CreateXParagraph(SwDoc & rDoc, SwTextNode * pTextNode,
111
            css::uno::Reference<SwXText> const& xParentText,
112
            const sal_Int32 nSelStart = -1, const sal_Int32 nSelEnd = - 1);
113
114
9.48k
    const SwTextNode * GetTextNode() const { return m_pTextNode; }
115
0
    bool            IsDescriptor() const { return m_bIsDescriptor; }
116
    /// make rPaM select the paragraph
117
    bool SelectPaM(SwPaM & rPaM);
118
    /// for SwXText
119
    void attachToText(SwXText & rParent, SwTextNode & rTextNode);
120
121
    // MetadatableMixin
122
    virtual ::sfx2::Metadatable* GetCoreObject() override;
123
    virtual css::uno::Reference< css::frame::XModel >
124
        GetModel() override;
125
126
    // XServiceInfo
127
    virtual OUString SAL_CALL getImplementationName() override;
128
    virtual sal_Bool SAL_CALL supportsService(
129
            const OUString& rServiceName) override;
130
    virtual css::uno::Sequence< OUString > SAL_CALL
131
        getSupportedServiceNames() override;
132
133
    // XComponent
134
    virtual void SAL_CALL dispose() override;
135
    virtual void SAL_CALL addEventListener(
136
            const css::uno::Reference< css::lang::XEventListener > & xListener) override;
137
    virtual void SAL_CALL removeEventListener(
138
            const css::uno::Reference< css::lang::XEventListener > & xListener) override;
139
140
    // XPropertySet
141
    virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
142
        getPropertySetInfo() override;
143
    virtual void SAL_CALL setPropertyValue(
144
            const OUString& rPropertyName,
145
            const css::uno::Any& rValue) override;
146
    virtual css::uno::Any SAL_CALL getPropertyValue(
147
            const OUString& rPropertyName) override;
148
    virtual void SAL_CALL addPropertyChangeListener(
149
            const OUString& rPropertyName,
150
            const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener) override;
151
    virtual void SAL_CALL removePropertyChangeListener(
152
            const OUString& rPropertyName,
153
            const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener) override;
154
    virtual void SAL_CALL addVetoableChangeListener(
155
            const OUString& rPropertyName,
156
            const css::uno::Reference< css::beans::XVetoableChangeListener >& xListener) override;
157
    virtual void SAL_CALL removeVetoableChangeListener(
158
            const OUString& rPropertyName,
159
            const css::uno::Reference< css::beans::XVetoableChangeListener >& xListener) override;
160
161
    // XPropertyState
162
    virtual css::beans::PropertyState SAL_CALL
163
        getPropertyState(const OUString& rPropertyName) override;
164
    virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL
165
        getPropertyStates(
166
            const css::uno::Sequence< OUString >& rPropertyNames) override;
167
    virtual void SAL_CALL setPropertyToDefault(
168
            const OUString& rPropertyName) override;
169
    virtual css::uno::Any SAL_CALL getPropertyDefault(
170
            const OUString& rPropertyName) override;
171
172
    // XMultiPropertySet
173
    virtual void SAL_CALL setPropertyValues(
174
            const css::uno::Sequence< OUString >&      rPropertyNames,
175
            const css::uno::Sequence< css::uno::Any >& rValues) override;
176
    virtual css::uno::Sequence< css::uno::Any >
177
        SAL_CALL getPropertyValues(
178
            const css::uno::Sequence< OUString >&  rPropertyNames) override;
179
    virtual void SAL_CALL addPropertiesChangeListener(
180
            const css::uno::Sequence< OUString >&         rPropertyNames,
181
            const css::uno::Reference< css::beans::XPropertiesChangeListener >& xListener) override;
182
    virtual void SAL_CALL removePropertiesChangeListener(
183
            const css::uno::Reference< css::beans::XPropertiesChangeListener >& xListener) override;
184
    virtual void SAL_CALL firePropertiesChangeEvent(
185
            const css::uno::Sequence< OUString >&        rPropertyNames,
186
            const css::uno::Reference< css::beans::XPropertiesChangeListener >& xListener) override;
187
188
    // XTolerantMultiPropertySet
189
    virtual css::uno::Sequence< css::beans::SetPropertyTolerantFailed > SAL_CALL
190
        setPropertyValuesTolerant(
191
            const css::uno::Sequence< OUString >&      rPropertyNames,
192
            const css::uno::Sequence< css::uno::Any >& rValues) override;
193
    virtual css::uno::Sequence< css::beans::GetPropertyTolerantResult > SAL_CALL
194
        getPropertyValuesTolerant(
195
            const css::uno::Sequence< OUString >& rPropertyNames) override;
196
    virtual css::uno::Sequence<
197
            css::beans::GetDirectPropertyTolerantResult > SAL_CALL
198
        getDirectPropertyValuesTolerant(
199
            const css::uno::Sequence< OUString >& rPropertyNames) override;
200
201
    // XElementAccess
202
    virtual css::uno::Type SAL_CALL getElementType() override;
203
    virtual sal_Bool SAL_CALL hasElements() override;
204
205
    // XEnumerationAccess
206
    virtual css::uno::Reference< css::container::XEnumeration >  SAL_CALL
207
        createEnumeration() override;
208
209
    // XContentEnumerationAccess
210
    virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
211
        createContentEnumeration(const OUString& rServiceName) override;
212
    virtual css::uno::Sequence< OUString > SAL_CALL
213
        getAvailableServiceNames() override;
214
215
    // XTextContent
216
    virtual void SAL_CALL attach(
217
            const css::uno::Reference< css::text::XTextRange > & xTextRange) override;
218
    virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getAnchor() override;
219
220
    // XTextRange
221
    virtual css::uno::Reference< css::text::XText >
222
        SAL_CALL getText() override;
223
    virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override;
224
    virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override;
225
    virtual OUString SAL_CALL getString() override;
226
    virtual void SAL_CALL setString(const OUString& rString) override;
227
228
    /// tries to return less data, but may return more than just text fields
229
    rtl::Reference<SwXTextPortionEnumeration> createTextFieldsEnumeration();
230
231
private:
232
    std::mutex m_Mutex; // just for OInterfaceContainerHelper4
233
    ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> m_EventListeners;
234
    SfxItemPropertySet const& m_rPropSet;
235
    bool m_bIsDescriptor;
236
    bool m_bDeleteWithoutCorrection = false;
237
    sal_Int32 m_nSelectionStartPos;
238
    sal_Int32 m_nSelectionEndPos;
239
    OUString m_sText;
240
    css::uno::Reference<SwXText> m_xParentText;
241
    SwTextNode* m_pTextNode;
242
    struct MySvtListener : public SvtListener
243
    {
244
        SwXParagraph& m_rThis;
245
176k
        MySvtListener(SwXParagraph& rThis) : m_rThis(rThis) {}
246
        virtual void Notify(const SfxHint& rHint) override;
247
    };
248
    std::optional<MySvtListener> moSvtListener;
249
};
250
251
252
struct SwXParagraphEnumeration
253
    : public SwSimpleEnumeration_Base
254
{
255
    static rtl::Reference<SwXParagraphEnumeration> Create(
256
        css::uno::Reference< css::text::XText > const & xParent,
257
        const std::shared_ptr<SwUnoCursor>& pCursor,
258
        const CursorType eType,
259
        /// only for CursorType::TableText
260
        SwTableBox const*const pTableBox = nullptr);
261
};
262
263
#endif // INCLUDED_SW_INC_UNOPARAGRAPH_HXX
264
265
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */