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
;
33 using ::com::sun::star::uno::RuntimeException
;
37 class lcl_ColorPropertySetInfo
: public ::cppu::WeakImplHelper
<
41 explicit lcl_ColorPropertySetInfo( bool bFillColor
);
44 // ____ XPropertySetInfo ____
45 virtual Sequence
< Property
> SAL_CALL
getProperties() override
;
46 virtual Property SAL_CALL
getPropertyByName( const OUString
& aName
) override
;
47 virtual sal_Bool SAL_CALL
hasPropertyByName( const OUString
& Name
) override
;
50 OUString
const m_aColorPropName
;
51 Property m_aColorProp
;
54 lcl_ColorPropertySetInfo::lcl_ColorPropertySetInfo( bool bFillColor
) :
55 // note: length of FillColor and LineColor is 9
56 m_aColorPropName( (bFillColor
? "FillColor" : "LineColor"), 9, RTL_TEXTENCODING_ASCII_US
),
57 m_aColorProp( m_aColorPropName
, -1,
58 cppu::UnoType
<sal_Int32
>::get(), 0)
61 Sequence
< Property
> SAL_CALL
lcl_ColorPropertySetInfo::getProperties()
64 return Sequence
< Property
>( & m_aColorProp
, 1 );
67 Property SAL_CALL
lcl_ColorPropertySetInfo::getPropertyByName( const OUString
& aName
)
69 if( aName
== m_aColorPropName
)
71 throw UnknownPropertyException( m_aColorPropName
, static_cast< uno::XWeak
* >( this ));
74 sal_Bool SAL_CALL
lcl_ColorPropertySetInfo::hasPropertyByName( const OUString
& Name
)
76 return Name
== m_aColorPropName
;
79 } // anonymous namespace
86 ColorPropertySet::ColorPropertySet( ::Color nColor
, bool bFillColor
/* = true */ ) :
87 // note: length of FillColor and LineColor is 9
88 m_aColorPropName( (bFillColor
? "FillColor" : "LineColor"), 9, RTL_TEXTENCODING_ASCII_US
),
90 m_bIsFillColor( bFillColor
),
91 m_nDefaultColor( 0x0099ccff ) // blue 8
94 ColorPropertySet::~ColorPropertySet()
97 // ____ XPropertySet ____
99 Reference
< XPropertySetInfo
> SAL_CALL
ColorPropertySet::getPropertySetInfo()
102 m_xInfo
.set( new lcl_ColorPropertySetInfo( m_bIsFillColor
));
107 void SAL_CALL
ColorPropertySet::setPropertyValue( const OUString
& rPropertyName
, const uno::Any
& aValue
)
109 if (rPropertyName
!= m_aColorPropName
)
111 // trying to catch these cases in the next crash testing
119 uno::Any SAL_CALL
ColorPropertySet::getPropertyValue( const OUString
& aPropertyName
)
121 if( aPropertyName
== "FillStyle" && m_bIsFillColor
)
123 return uno::makeAny(css::drawing::FillStyle_SOLID
);
125 else if (aPropertyName
== m_aColorPropName
)
126 return uno::makeAny( m_nColor
);
128 throw UnknownPropertyException(aPropertyName
);
131 void SAL_CALL
ColorPropertySet::addPropertyChangeListener( const OUString
& /* aPropertyName */, const Reference
< XPropertyChangeListener
>& /* xListener */ )
133 OSL_FAIL( "Not Implemented" );
136 void SAL_CALL
ColorPropertySet::removePropertyChangeListener( const OUString
& /* aPropertyName */, const Reference
< XPropertyChangeListener
>& /* aListener */ )
138 OSL_FAIL( "Not Implemented" );
141 void SAL_CALL
ColorPropertySet::addVetoableChangeListener( const OUString
& /* PropertyName */, const Reference
< XVetoableChangeListener
>& /* aListener */ )
143 OSL_FAIL( "Not Implemented" );
146 void SAL_CALL
ColorPropertySet::removeVetoableChangeListener( const OUString
& /* PropertyName */, const Reference
< XVetoableChangeListener
>& /* aListener */ )
148 OSL_FAIL( "Not Implemented" );
151 // ____ XPropertyState ____
153 PropertyState SAL_CALL
ColorPropertySet::getPropertyState( const OUString
& /* PropertyName */ )
155 return PropertyState_DIRECT_VALUE
;
158 Sequence
< PropertyState
> SAL_CALL
ColorPropertySet::getPropertyStates( const Sequence
< OUString
>& /* aPropertyName */ )
160 PropertyState aState
= PropertyState_DIRECT_VALUE
;
161 // coverity[overrun-buffer-arg : FALSE] - coverity has difficulty with css::uno::Sequence
162 return Sequence
<PropertyState
>(&aState
, 1);
165 void SAL_CALL
ColorPropertySet::setPropertyToDefault( const OUString
& PropertyName
)
167 if( PropertyName
== m_aColorPropName
)
168 m_nColor
= m_nDefaultColor
;
171 uno::Any SAL_CALL
ColorPropertySet::getPropertyDefault( const OUString
& aPropertyName
)
173 if( aPropertyName
== m_aColorPropName
)
174 return uno::makeAny( m_nDefaultColor
);
180 } // namespace xmloff
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */