Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/inc/unoxstyle.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
#pragma once
20
21
#include <rtl/ref.hxx>
22
#include <svl/listener.hxx>
23
#include <svl/style.hxx>
24
#include <com/sun/star/awt/FontSlant.hpp>
25
#include <com/sun/star/style/XStyle.hpp>
26
#include <com/sun/star/beans/XPropertySet.hpp>
27
#include <com/sun/star/beans/XPropertyState.hpp>
28
#include <com/sun/star/beans/XMultiPropertySet.hpp>
29
#include <com/sun/star/beans/XMultiPropertyStates.hpp>
30
#include <com/sun/star/lang/XServiceInfo.hpp>
31
#include <com/sun/star/lang/XUnoTunnel.hpp>
32
#include <cppuhelper/implbase.hxx>
33
#include <osl/diagnose.h>
34
#include "swdllapi.h"
35
#include "coreframestyle.hxx"
36
#include "unobasestyle.hxx"
37
#include "names.hxx"
38
#include <span>
39
40
class StyleFamilyEntry;
41
class SwStyleBase_Impl;
42
class SwStyleProperties_Impl;
43
class SvxSetItem;
44
struct SfxItemPropertyMapEntry;
45
class SwDoc;
46
class SfxItemPropertySet;
47
class SwDocShell;
48
class SwXNumberingRules;
49
class SwDocStyleSheet;
50
51
/** The names of built-in styles at the API are ProgNames which are not subject
52
    to i18n and must never change - these are written into ODF files.
53
54
    The names of built-in styles in the core document model are UINames which
55
    are subject to i18n and may change in different versions.
56
57
    Take care to use SwStyleNameMapper::GetProgName() or
58
    SwStyleNameMapper::GetUIName() to convert here in the UNO service.
59
  */
60
class SAL_DLLPUBLIC_RTTI SwXStyle
61
    : public cppu::ImplInheritanceHelper<
62
          SwXBaseStyle, css::beans::XMultiPropertySet, css::lang::XServiceInfo,
63
          css::lang::XUnoTunnel, css::beans::XPropertyState, css::beans::XMultiPropertyStates>,
64
      public SfxListener,
65
      public SvtListener
66
{
67
    SwDoc* m_pDoc;
68
    UIName m_sStyleUIName; ///< UIName, needs conversion to ProgName
69
    const StyleFamilyEntry& m_rEntry;
70
    bool m_bIsDescriptor;
71
    bool m_bIsConditional;
72
    UIName m_sParentStyleUIName; ///< UIName, needs conversion to ProgName
73
    // cache UNO stylesheets
74
    std::unordered_map<SfxStyleSheetBase*, rtl::Reference<SwDocStyleSheet>> maUnoStyleSheets;
75
76
protected:
77
    SfxStyleSheetBasePool* m_pBasePool;
78
    std::unique_ptr<SwStyleProperties_Impl> m_pPropertiesImpl;
79
    css::uno::Reference<css::container::XNameAccess> m_xStyleFamily;
80
    css::uno::Reference<css::beans::XPropertySet> m_xStyleData;
81
82
    template <sal_uInt16>
83
    void SetPropertyValue(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&,
84
                          const css::uno::Any&, SwStyleBase_Impl&);
85
    void SetPropertyValues_Impl(std::span<const OUString> aPropertyNames,
86
                                std::span<const css::uno::Any> aValues, bool bIgnoreUnknown);
87
    SfxStyleSheetBase* GetStyleSheetBase();
88
    void PrepareStyleBase(SwStyleBase_Impl& rBase);
89
    template <sal_uInt16>
90
    css::uno::Any GetStyleProperty(const SfxItemPropertyMapEntry& rEntry,
91
                                   const SfxItemPropertySet& rPropSet, SwStyleBase_Impl& rBase);
92
    css::uno::Any GetStyleProperty_Impl(const SfxItemPropertyMapEntry& rEntry,
93
                                        const SfxItemPropertySet& rPropSet,
94
                                        SwStyleBase_Impl& rBase);
95
    css::uno::Any GetPropertyValue_Impl(const SfxItemPropertySet* pPropSet, SwStyleBase_Impl& rBase,
96
                                        const OUString& rPropertyName);
97
98
public:
99
    SwXStyle(SwDoc* pDoc, SfxStyleFamily eFam, bool bConditional = false);
100
    SwXStyle(SfxStyleSheetBasePool* pPool, SfxStyleFamily eFamily, SwDoc* pDoc,
101
             const UIName& rStyleName);
102
    virtual ~SwXStyle() override;
103
104
    static const css::uno::Sequence<sal_Int8>& getUnoTunnelId();
105
106
    //XUnoTunnel
107
    virtual sal_Int64 SAL_CALL
108
    getSomething(const css::uno::Sequence<sal_Int8>& aIdentifier) override;
109
110
    //XNamed
111
    virtual OUString SAL_CALL getName() override;
112
    virtual void SAL_CALL setName(const OUString& Name_) override;
113
114
    //XStyle
115
    virtual sal_Bool SAL_CALL isUserDefined() override;
116
    virtual sal_Bool SAL_CALL isInUse() override;
117
    virtual OUString SAL_CALL getParentStyle() override;
118
    virtual void SAL_CALL setParentStyle(const OUString& aParentStyle) override;
119
120
    //XPropertySet
121
    SW_DLLPUBLIC virtual css::uno::Reference<css::beans::XPropertySetInfo>
122
        SAL_CALL getPropertySetInfo() override;
123
    virtual void SAL_CALL setPropertyValue(const OUString& aPropertyName,
124
                                           const css::uno::Any& aValue) override;
125
    virtual css::uno::Any SAL_CALL getPropertyValue(const OUString& PropertyName) override;
126
    virtual void SAL_CALL addPropertyChangeListener(
127
        const OUString&, const css::uno::Reference<css::beans::XPropertyChangeListener>&) override
128
0
    {
129
0
        OSL_FAIL("not implemented");
130
0
    };
131
    virtual void SAL_CALL removePropertyChangeListener(
132
        const OUString&, const css::uno::Reference<css::beans::XPropertyChangeListener>&) override
133
0
    {
134
0
        OSL_FAIL("not implemented");
135
0
    };
136
    virtual void SAL_CALL addVetoableChangeListener(
137
        const OUString&, const css::uno::Reference<css::beans::XVetoableChangeListener>&) override
138
0
    {
139
0
        OSL_FAIL("not implemented");
140
0
    };
141
    virtual void SAL_CALL removeVetoableChangeListener(
142
        const OUString&, const css::uno::Reference<css::beans::XVetoableChangeListener>&) override
143
0
    {
144
0
        OSL_FAIL("not implemented");
145
0
    };
146
147
    //XMultiPropertySet
148
    virtual void SAL_CALL
149
    setPropertyValues(const css::uno::Sequence<OUString>& aPropertyNames,
150
                      const css::uno::Sequence<css::uno::Any>& aValues) override;
151
    virtual css::uno::Sequence<css::uno::Any>
152
        SAL_CALL getPropertyValues(const css::uno::Sequence<OUString>& aPropertyNames) override;
153
    virtual void SAL_CALL addPropertiesChangeListener(
154
        const css::uno::Sequence<OUString>&,
155
0
        const css::uno::Reference<css::beans::XPropertiesChangeListener>&) override{};
156
    virtual void SAL_CALL removePropertiesChangeListener(
157
0
        const css::uno::Reference<css::beans::XPropertiesChangeListener>&) override{};
158
    virtual void SAL_CALL firePropertiesChangeEvent(
159
        const css::uno::Sequence<OUString>&,
160
0
        const css::uno::Reference<css::beans::XPropertiesChangeListener>&) override{};
161
162
    //XPropertyState
163
    virtual css::beans::PropertyState SAL_CALL
164
    getPropertyState(const OUString& PropertyName) override;
165
    virtual css::uno::Sequence<css::beans::PropertyState>
166
        SAL_CALL getPropertyStates(const css::uno::Sequence<OUString>& aPropertyName) override;
167
    virtual void SAL_CALL setPropertyToDefault(const OUString& PropertyName) override;
168
    virtual css::uno::Any SAL_CALL getPropertyDefault(const OUString& aPropertyName) override;
169
170
    //XMultiPropertyStates
171
    virtual void SAL_CALL setAllPropertiesToDefault() override;
172
    virtual void SAL_CALL
173
    setPropertiesToDefault(const css::uno::Sequence<OUString>& aPropertyNames) override;
174
    virtual css::uno::Sequence<css::uno::Any>
175
        SAL_CALL getPropertyDefaults(const css::uno::Sequence<OUString>& aPropertyNames) override;
176
177
    //XServiceInfo
178
    virtual OUString SAL_CALL getImplementationName() override;
179
    virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override;
180
    virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
181
182
    //SfxListener
183
    virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
184
    //SvtListener
185
    virtual void Notify(const SfxHint&) override;
186
    //SfxListener
187
    /// Used to avoid cost of dynamic_cast in SwXStyleFamily::FindStyle
188
676k
    virtual bool IsSwXStyle() const override final { return true; }
189
190
    SW_DLLPUBLIC rtl::Reference<SwXNumberingRules> getNumberingRules();
191
192
817k
    const UIName& GetStyleUIName() const { return m_sStyleUIName; }
193
    SfxStyleFamily GetFamily() const;
194
195
65.9k
    bool IsDescriptor() const { return m_bIsDescriptor; }
196
23.5k
    bool IsConditional() const { return m_bIsConditional; }
197
65.9k
    const UIName& GetParentStyleUIName() const { return m_sParentStyleUIName; }
198
    void SetDoc(SwDoc* pDc, SfxStyleSheetBasePool* pPool)
199
65.9k
    {
200
65.9k
        if (m_pBasePool)
201
0
            SfxListener::EndListening(*m_pBasePool);
202
203
65.9k
        m_bIsDescriptor = false;
204
65.9k
        m_pDoc = pDc;
205
65.9k
        m_pBasePool = pPool;
206
65.9k
        SfxListener::StartListening(*m_pBasePool);
207
65.9k
    }
208
1.18M
    SwDoc* GetDoc() const { return m_pDoc; }
209
    void Invalidate();
210
    void ApplyDescriptorProperties();
211
65.9k
    void SetStyleUIName(const UIName& rSet) { m_sStyleUIName = rSet; }
212
    /// @throws beans::PropertyVetoException
213
    /// @throws lang::IllegalArgumentException
214
    /// @throws lang::WrappedTargetException
215
    /// @throws uno::RuntimeException
216
    void SetStyleProperty(const SfxItemPropertyMapEntry& rEntry, const SfxItemPropertySet& rPropSet,
217
                          const css::uno::Any& rValue, SwStyleBase_Impl& rBase);
218
    void PutItemToSet(const SvxSetItem* pSetItem, const SfxItemPropertySet& rPropSet,
219
                      const SfxItemPropertyMapEntry& rEntry, const css::uno::Any& rVal,
220
                      SwStyleBase_Impl& rBaseImpl);
221
    SW_DLLPUBLIC void getToggleAttributes(
222
        float& rfCharStyleBold, float& rfCharStyleBoldComplex,
223
        css::awt::FontSlant& reCharStylePosture, css::awt::FontSlant& reCharStylePostureComplex,
224
        sal_Int16& rnCharStyleCaseMap, sal_Int16& rnCharStyleRelief, bool& rbCharStyleContoured,
225
        bool& rbCharStyleShadowed, sal_Int16& rnCharStyleStrikeThrough, bool& rbCharStyleHidden);
226
    // Set without throwing exceptions for unknown props, which is faster than throwing and then
227
    // ignoring.
228
    SW_DLLPUBLIC void setPropertyValueIgnoreUnknown(const OUString& aPropertyName,
229
                                                    const css::uno::Any& aValue);
230
    void SetPropertyValues(std::span<const OUString> aPropertyNames,
231
                           std::span<const css::uno::Any> aValues);
232
};
233
234
typedef cppu::ImplInheritanceHelper<SwXStyle, css::document::XEventsSupplier> SwXFrameStyle_Base;
235
class SwXFrameStyle final : public SwXFrameStyle_Base, public sw::ICoreFrameStyle
236
{
237
public:
238
    SwXFrameStyle(SfxStyleSheetBasePool& rPool, SwDoc* pDoc, const UIName& rStyleName)
239
80.2k
        : SwXFrameStyle_Base(&rPool, SfxStyleFamily::Frame, pDoc, rStyleName)
240
80.2k
    {
241
80.2k
    }
242
    explicit SwXFrameStyle(SwDoc* pDoc);
243
244
    virtual css::uno::Reference<css::container::XNameReplace> SAL_CALL getEvents() override;
245
246
    //ICoreStyle
247
    virtual void SetItem(sal_uInt16 eAtr, const SfxPoolItem& rItem) override;
248
    virtual const SfxPoolItem* GetItem(sal_uInt16 eAtr) override;
249
0
    virtual css::document::XEventsSupplier& GetEventsSupplier() override { return *this; };
250
};
251
252
class SW_DLLPUBLIC SwXPageStyle final : public SwXStyle
253
{
254
protected:
255
    void SetPropertyValues_Impl(const css::uno::Sequence<OUString>& aPropertyNames,
256
                                const css::uno::Sequence<css::uno::Any>& aValues);
257
    css::uno::Sequence<css::uno::Any>
258
    GetPropertyValues_Impl(const css::uno::Sequence<OUString>& aPropertyNames);
259
260
public:
261
    SwXPageStyle(SfxStyleSheetBasePool& rPool, SwDocShell* pDocSh, const UIName& rStyleName);
262
    explicit SwXPageStyle(SwDocShell* pDocSh);
263
264
    virtual void SAL_CALL setPropertyValue(const OUString& aPropertyName,
265
                                           const css::uno::Any& aValue) override;
266
    virtual css::uno::Any SAL_CALL getPropertyValue(const OUString& PropertyName) override;
267
268
    virtual void SAL_CALL
269
    setPropertyValues(const css::uno::Sequence<OUString>& aPropertyNames,
270
                      const css::uno::Sequence<css::uno::Any>& aValues) override;
271
    virtual css::uno::Sequence<css::uno::Any>
272
        SAL_CALL getPropertyValues(const css::uno::Sequence<OUString>& aPropertyNames) override;
273
};
274
275
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */