Coverage Report

Created: 2025-12-08 09:28

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