Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/include/editeng/brushitem.hxx
Line
Count
Source (jump to first uncovered line)
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 <tools/color.hxx>
22
#include <svl/poolitem.hxx>
23
#include <editeng/editengdllapi.h>
24
#include <memory>
25
#include <docmodel/color/ComplexColor.hxx>
26
27
class Graphic;
28
class GraphicObject;
29
30
constexpr sal_uInt16 BRUSH_GRAPHIC_VERSION = 0x0001;
31
32
enum SvxGraphicPosition
33
{
34
    GPOS_NONE,
35
    GPOS_LT, GPOS_MT, GPOS_RT,
36
    GPOS_LM, GPOS_MM, GPOS_RM,
37
    GPOS_LB, GPOS_MB, GPOS_RB,
38
    GPOS_AREA, GPOS_TILED
39
};
40
41
class EDITENG_DLLPUBLIC SvxBrushItem final : public SfxPoolItem
42
{
43
    Color               aColor;
44
    model::ComplexColor maComplexColor;
45
    Color               aFilterColor;
46
    sal_Int32           nShadingValue;
47
    mutable std::unique_ptr<GraphicObject> xGraphicObject;
48
    sal_Int8            nGraphicTransparency; //contains a percentage value which is
49
                                              //copied to the GraphicObject when necessary
50
    OUString            maStrLink;
51
    OUString            maStrFilter;
52
    SvxGraphicPosition  eGraphicPos;
53
    mutable bool        bLoadAgain;
54
55
    void        ApplyGraphicTransparency_Impl();
56
57
protected:
58
    virtual ItemInstanceManager* getItemInstanceManager() const override;
59
60
public:
61
    static SfxPoolItem* CreateDefault();
62
63
    DECLARE_ITEM_TYPE_FUNCTION(SvxBrushItem)
64
    explicit SvxBrushItem( sal_uInt16 nWhich );
65
    SvxBrushItem(Color const& rColor, sal_uInt16 nWhich);
66
    SvxBrushItem(Color const& rColor, model::ComplexColor const& rComplexColor, sal_uInt16 nWhich);
67
68
    SvxBrushItem( const Graphic& rGraphic,
69
                  SvxGraphicPosition ePos, sal_uInt16 nWhich );
70
    SvxBrushItem( const GraphicObject& rGraphicObj,
71
                  SvxGraphicPosition ePos, sal_uInt16 nWhich );
72
    SvxBrushItem( OUString  rLink, OUString aFilter,
73
                  SvxGraphicPosition ePos, sal_uInt16 nWhich );
74
    SvxBrushItem( const SvxBrushItem& );
75
    SvxBrushItem(SvxBrushItem&&);
76
77
    virtual ~SvxBrushItem() override;
78
79
public:
80
    // check if it's used
81
    bool isUsed() const;
82
83
    virtual bool GetPresentation( SfxItemPresentation ePres,
84
                                  MapUnit eCoreMetric,
85
                                  MapUnit ePresMetric,
86
                                  OUString &rText, const IntlWrapper& ) const override;
87
88
    virtual bool             operator==( const SfxPoolItem& ) const override;
89
0
    virtual bool             supportsHashCode() const override { return true; }
90
    virtual size_t           hashCode() const override;
91
    virtual bool             QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override;
92
    virtual bool             PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override;
93
94
    virtual SvxBrushItem*    Clone( SfxItemPool *pPool = nullptr ) const override;
95
96
2.14M
    const Color&    GetColor() const                { return aColor; }
97
73
    Color&          GetColor()                      { return aColor; }
98
    void            SetColor( const Color& rCol)
99
195k
    {
100
195k
        ASSERT_CHANGE_REFCOUNTED_ITEM;
101
195k
        aColor = rCol;
102
195k
    }
103
104
    const model::ComplexColor& getComplexColor() const
105
32.5k
    {
106
32.5k
        auto pUnConst = const_cast<SvxBrushItem*>(this);
107
32.5k
        pUnConst->maComplexColor.setFinalColor(GetColor());
108
32.5k
        return maComplexColor;
109
32.5k
    }
110
111
    void setComplexColor(model::ComplexColor const& rComplexColor)
112
18.0k
    {
113
18.0k
        ASSERT_CHANGE_REFCOUNTED_ITEM;
114
18.0k
        maComplexColor = rComplexColor;
115
18.0k
    }
116
117
0
    const Color&    GetFiltColor() const             { return aFilterColor; }
118
    void            SetFiltColor( const Color& rCol)
119
27.7k
    {
120
27.7k
        ASSERT_CHANGE_REFCOUNTED_ITEM;
121
27.7k
        aFilterColor = rCol;
122
27.7k
    }
123
124
2.42M
    SvxGraphicPosition  GetGraphicPos() const       { return eGraphicPos; }
125
126
0
    sal_Int32               GetShadingValue() const     { return nShadingValue; }
127
    const Graphic*          GetGraphic(OUString const & referer = OUString()/*TODO*/) const;
128
    const GraphicObject*    GetGraphicObject(OUString const & referer = OUString()/*TODO*/) const;
129
1.14k
    const OUString&         GetGraphicLink() const      { return maStrLink; }
130
0
    const OUString&         GetGraphicFilter() const    { return maStrFilter; }
131
132
    // get graphic transparency in percent
133
1.49k
    sal_Int8 getGraphicTransparency() const { return nGraphicTransparency; }
134
    void setGraphicTransparency(sal_Int8 nNew);
135
136
    void                SetGraphicPos( SvxGraphicPosition eNew );
137
    void                SetGraphic( const Graphic& rNew );
138
    void                SetGraphicObject( const GraphicObject& rNewObj );
139
    void                SetGraphicLink( const OUString& rNew );
140
    void                SetGraphicFilter( const OUString& rNew );
141
142
    static sal_Int8             TransparencyToPercent(sal_Int32 nTrans);
143
144
    void dumpAsXml(xmlTextWriterPtr pWriter) const override;
145
};
146
147
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */