1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 // FIXME? This file is nearly identical to xmloff/source/chart/ColorPropertySet.cxx
22 #include "ColorPropertySet.hxx"
24 #include <cppuhelper/implbase.hxx>
25 #include <osl/diagnose.h>
26 #include <com/sun/star/drawing/FillStyle.hpp>
28 using namespace ::com::sun::star
;
29 using namespace ::com::sun::star::beans
;
31 using ::com::sun::star::uno::Reference
;
32 using ::com::sun::star::uno::Sequence
;
36 class lcl_ColorPropertySetInfo
: public ::cppu::WeakImplHelper
<
40 explicit lcl_ColorPropertySetInfo( bool bFillColor
);
43 // ____ XPropertySetInfo ____
44 virtual Sequence
< Property
> SAL_CALL
getProperties() override
;
45 virtual Property SAL_CALL
getPropertyByName( const OUString
& aName
) override
;
46 virtual sal_Bool SAL_CALL
hasPropertyByName( const OUString
& Name
) override
;
49 OUString m_aColorPropName
;
50 Property m_aColorProp
;
53 lcl_ColorPropertySetInfo::lcl_ColorPropertySetInfo( bool bFillColor
) :
54 // note: length of FillColor and LineColor is 9
55 m_aColorPropName( (bFillColor
? "FillColor" : "LineColor"), 9, RTL_TEXTENCODING_ASCII_US
),
56 m_aColorProp( m_aColorPropName
, -1,
57 cppu::UnoType
<sal_Int32
>::get(), 0)
60 Sequence
< Property
> SAL_CALL
lcl_ColorPropertySetInfo::getProperties()
63 return Sequence
< Property
>( & m_aColorProp
, 1 );
66 Property SAL_CALL
lcl_ColorPropertySetInfo::getPropertyByName( const OUString
& aName
)
68 if( aName
== m_aColorPropName
)
70 throw UnknownPropertyException( m_aColorPropName
, getXWeak());
73 sal_Bool SAL_CALL
lcl_ColorPropertySetInfo::hasPropertyByName( const OUString
& Name
)
75 return Name
== m_aColorPropName
;
78 } // anonymous namespace
80 namespace oox::drawingml
83 ColorPropertySet::ColorPropertySet( ::Color nColor
, bool bFillColor
/* = true */ ) :
84 // note: length of FillColor and LineColor is 9
85 m_aColorPropName( (bFillColor
? "FillColor" : "LineColor"), 9, RTL_TEXTENCODING_ASCII_US
),
87 m_bIsFillColor( bFillColor
),
88 m_nDefaultColor( 0x0099ccff ) // blue 8
91 ColorPropertySet::~ColorPropertySet()
94 // ____ XPropertySet ____
96 Reference
< XPropertySetInfo
> SAL_CALL
ColorPropertySet::getPropertySetInfo()
99 m_xInfo
.set( new lcl_ColorPropertySetInfo( m_bIsFillColor
));
104 void SAL_CALL
ColorPropertySet::setPropertyValue( const OUString
& rPropertyName
, const uno::Any
& aValue
)
106 if (rPropertyName
!= m_aColorPropName
)
108 // trying to catch these cases in the next crash testing
116 uno::Any SAL_CALL
ColorPropertySet::getPropertyValue( const OUString
& aPropertyName
)
118 if( aPropertyName
== "FillStyle" && m_bIsFillColor
)
120 return uno::Any(css::drawing::FillStyle_SOLID
);
122 else if (aPropertyName
== m_aColorPropName
)
123 return uno::Any( m_nColor
);
125 throw UnknownPropertyException(aPropertyName
);
128 void SAL_CALL
ColorPropertySet::addPropertyChangeListener( const OUString
& /* aPropertyName */, const Reference
< XPropertyChangeListener
>& /* xListener */ )
130 OSL_FAIL( "Not Implemented" );
133 void SAL_CALL
ColorPropertySet::removePropertyChangeListener( const OUString
& /* aPropertyName */, const Reference
< XPropertyChangeListener
>& /* aListener */ )
135 OSL_FAIL( "Not Implemented" );
138 void SAL_CALL
ColorPropertySet::addVetoableChangeListener( const OUString
& /* PropertyName */, const Reference
< XVetoableChangeListener
>& /* aListener */ )
140 OSL_FAIL( "Not Implemented" );
143 void SAL_CALL
ColorPropertySet::removeVetoableChangeListener( const OUString
& /* PropertyName */, const Reference
< XVetoableChangeListener
>& /* aListener */ )
145 OSL_FAIL( "Not Implemented" );
148 // ____ XPropertyState ____
150 PropertyState SAL_CALL
ColorPropertySet::getPropertyState( const OUString
& /* PropertyName */ )
152 return PropertyState_DIRECT_VALUE
;
155 Sequence
< PropertyState
> SAL_CALL
ColorPropertySet::getPropertyStates( const Sequence
< OUString
>& /* aPropertyName */ )
157 PropertyState aState
= PropertyState_DIRECT_VALUE
;
158 // coverity[overrun-buffer-arg : FALSE] - coverity has difficulty with css::uno::Sequence
159 return Sequence
<PropertyState
>(&aState
, 1);
162 void SAL_CALL
ColorPropertySet::setPropertyToDefault( const OUString
& PropertyName
)
164 if( PropertyName
== m_aColorPropName
)
165 m_nColor
= m_nDefaultColor
;
168 uno::Any SAL_CALL
ColorPropertySet::getPropertyDefault( const OUString
& aPropertyName
)
170 if( aPropertyName
== m_aColorPropName
)
171 return uno::Any( m_nDefaultColor
);
176 } // namespace oox::drawingml
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */