Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / oox / source / export / ColorPropertySet.cxx
blob4c1d9d842d2ee759a466ce445be7321b03016d8e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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;
35 namespace
37 class lcl_ColorPropertySetInfo : public ::cppu::WeakImplHelper<
38 XPropertySetInfo >
40 public:
41 explicit lcl_ColorPropertySetInfo( bool bFillColor );
43 protected:
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;
49 private:
50 OUString 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.equals( m_aColorPropName ))
70 return m_aColorProp;
71 throw UnknownPropertyException( m_aColorPropName, static_cast< uno::XWeak * >( this ));
74 sal_Bool SAL_CALL lcl_ColorPropertySetInfo::hasPropertyByName( const OUString& Name )
76 return Name.equals( m_aColorPropName );
79 } // anonymous namespace
81 namespace oox
83 namespace drawingml
86 ColorPropertySet::ColorPropertySet( sal_Int32 nColor, bool bFillColor /* = true */ ) :
87 // note: length of FillColor and LineColor is 9
88 m_aColorPropName( (bFillColor ? "FillColor" : "LineColor"), 9, RTL_TEXTENCODING_ASCII_US ),
89 m_nColor( nColor ),
90 m_bIsFillColor( bFillColor ),
91 m_nDefaultColor( 0x0099ccff ) // blue 8
94 ColorPropertySet::~ColorPropertySet()
97 // ____ XPropertySet ____
99 Reference< XPropertySetInfo > SAL_CALL ColorPropertySet::getPropertySetInfo()
101 if( ! m_xInfo.is())
102 m_xInfo.set( new lcl_ColorPropertySetInfo( m_bIsFillColor ));
104 return m_xInfo;
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
112 assert(false);
113 return;
116 aValue >>= m_nColor;
119 uno::Any SAL_CALL ColorPropertySet::getPropertyValue( const OUString& aPropertyName )
121 if( aPropertyName == "FillStyle" && m_bIsFillColor )
123 css::drawing::FillStyle aFillStyle = css::drawing::FillStyle_SOLID;
124 return uno::makeAny(aFillStyle);
126 else if (aPropertyName == m_aColorPropName)
127 return uno::makeAny( m_nColor );
129 throw UnknownPropertyException();
132 void SAL_CALL ColorPropertySet::addPropertyChangeListener( const OUString& /* aPropertyName */, const Reference< XPropertyChangeListener >& /* xListener */ )
134 OSL_FAIL( "Not Implemented" );
135 return;
138 void SAL_CALL ColorPropertySet::removePropertyChangeListener( const OUString& /* aPropertyName */, const Reference< XPropertyChangeListener >& /* aListener */ )
140 OSL_FAIL( "Not Implemented" );
141 return;
144 void SAL_CALL ColorPropertySet::addVetoableChangeListener( const OUString& /* PropertyName */, const Reference< XVetoableChangeListener >& /* aListener */ )
146 OSL_FAIL( "Not Implemented" );
147 return;
150 void SAL_CALL ColorPropertySet::removeVetoableChangeListener( const OUString& /* PropertyName */, const Reference< XVetoableChangeListener >& /* aListener */ )
152 OSL_FAIL( "Not Implemented" );
153 return;
156 // ____ XPropertyState ____
158 PropertyState SAL_CALL ColorPropertySet::getPropertyState( const OUString& /* PropertyName */ )
160 return PropertyState_DIRECT_VALUE;
163 Sequence< PropertyState > SAL_CALL ColorPropertySet::getPropertyStates( const Sequence< OUString >& /* aPropertyName */ )
165 PropertyState aState = PropertyState_DIRECT_VALUE;
166 return Sequence< PropertyState >( & aState, 1 );
169 void SAL_CALL ColorPropertySet::setPropertyToDefault( const OUString& PropertyName )
171 if( PropertyName.equals( m_aColorPropName ))
172 m_nColor = m_nDefaultColor;
175 uno::Any SAL_CALL ColorPropertySet::getPropertyDefault( const OUString& aPropertyName )
177 if( aPropertyName.equals( m_aColorPropName ))
178 return uno::makeAny( m_nDefaultColor );
180 return uno::Any();
183 } // namespace chart
184 } // namespace xmloff
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */