Branch libreoffice-5-0-4
[LibreOffice.git] / oox / source / export / ColorPropertySet.cxx
blobaa32446cfc84c980d6574086b76a669bcadb0149
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/implbase1.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::WeakImplHelper1<
38 XPropertySetInfo >
40 public:
41 explicit lcl_ColorPropertySetInfo( bool bFillColor );
43 protected:
44 // ____ XPropertySetInfo ____
45 virtual Sequence< Property > SAL_CALL getProperties() throw (RuntimeException, std::exception) SAL_OVERRIDE;
46 virtual Property SAL_CALL getPropertyByName( const OUString& aName ) throw (UnknownPropertyException, RuntimeException, std::exception) SAL_OVERRIDE;
47 virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) throw (RuntimeException, std::exception) SAL_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()
62 throw (RuntimeException, std::exception)
65 return Sequence< Property >( & m_aColorProp, 1 );
68 Property SAL_CALL lcl_ColorPropertySetInfo::getPropertyByName( const OUString& aName )
69 throw (UnknownPropertyException, RuntimeException, std::exception)
71 if( aName.equals( m_aColorPropName ))
72 return m_aColorProp;
73 throw UnknownPropertyException( m_aColorPropName, static_cast< uno::XWeak * >( this ));
76 sal_Bool SAL_CALL lcl_ColorPropertySetInfo::hasPropertyByName( const OUString& Name )
77 throw (RuntimeException, std::exception)
79 return Name.equals( m_aColorPropName );
82 } // anonymous namespace
84 namespace oox
86 namespace drawingml
89 ColorPropertySet::ColorPropertySet( sal_Int32 nColor, bool bFillColor /* = true */ ) :
90 // note: length of FillColor and LineColor is 9
91 m_aColorPropName( (bFillColor ? "FillColor" : "LineColor"), 9, RTL_TEXTENCODING_ASCII_US ),
92 m_nColor( nColor ),
93 m_bIsFillColor( bFillColor ),
94 m_nDefaultColor( 0x0099ccff ) // blue 8
97 ColorPropertySet::~ColorPropertySet()
100 // ____ XPropertySet ____
102 Reference< XPropertySetInfo > SAL_CALL ColorPropertySet::getPropertySetInfo()
103 throw (uno::RuntimeException, std::exception)
105 if( ! m_xInfo.is())
106 m_xInfo.set( new lcl_ColorPropertySetInfo( m_bIsFillColor ));
108 return m_xInfo;
111 void SAL_CALL ColorPropertySet::setPropertyValue( const OUString& /* aPropertyName */, const uno::Any& aValue )
112 throw (UnknownPropertyException,
113 PropertyVetoException,
114 lang::IllegalArgumentException,
115 lang::WrappedTargetException,
116 uno::RuntimeException, std::exception)
118 aValue >>= m_nColor;
121 uno::Any SAL_CALL ColorPropertySet::getPropertyValue( const OUString& aPropertyName )
122 throw (UnknownPropertyException,
123 lang::WrappedTargetException,
124 uno::RuntimeException, std::exception)
126 if( aPropertyName == "FillStyle" && m_bIsFillColor )
128 ::com::sun::star::drawing::FillStyle aFillStyle = ::com::sun::star::drawing::FillStyle_SOLID;
129 return uno::makeAny(aFillStyle);
131 return uno::makeAny( m_nColor );
134 void SAL_CALL ColorPropertySet::addPropertyChangeListener( const OUString& /* aPropertyName */, const Reference< XPropertyChangeListener >& /* xListener */ )
135 throw (UnknownPropertyException,
136 lang::WrappedTargetException,
137 uno::RuntimeException, std::exception)
139 OSL_FAIL( "Not Implemented" );
140 return;
143 void SAL_CALL ColorPropertySet::removePropertyChangeListener( const OUString& /* aPropertyName */, const Reference< XPropertyChangeListener >& /* aListener */ )
144 throw (UnknownPropertyException,
145 lang::WrappedTargetException,
146 uno::RuntimeException, std::exception)
148 OSL_FAIL( "Not Implemented" );
149 return;
152 void SAL_CALL ColorPropertySet::addVetoableChangeListener( const OUString& /* PropertyName */, const Reference< XVetoableChangeListener >& /* aListener */ )
153 throw (UnknownPropertyException,
154 lang::WrappedTargetException,
155 uno::RuntimeException, std::exception)
157 OSL_FAIL( "Not Implemented" );
158 return;
161 void SAL_CALL ColorPropertySet::removeVetoableChangeListener( const OUString& /* PropertyName */, const Reference< XVetoableChangeListener >& /* aListener */ )
162 throw (UnknownPropertyException,
163 lang::WrappedTargetException,
164 uno::RuntimeException, std::exception)
166 OSL_FAIL( "Not Implemented" );
167 return;
170 // ____ XPropertyState ____
172 PropertyState SAL_CALL ColorPropertySet::getPropertyState( const OUString& /* PropertyName */ )
173 throw (UnknownPropertyException,
174 uno::RuntimeException, std::exception)
176 return PropertyState_DIRECT_VALUE;
179 Sequence< PropertyState > SAL_CALL ColorPropertySet::getPropertyStates( const Sequence< OUString >& /* aPropertyName */ )
180 throw (UnknownPropertyException,
181 uno::RuntimeException, std::exception)
183 PropertyState aState = PropertyState_DIRECT_VALUE;
184 return Sequence< PropertyState >( & aState, 1 );
187 void SAL_CALL ColorPropertySet::setPropertyToDefault( const OUString& PropertyName )
188 throw (UnknownPropertyException,
189 uno::RuntimeException, std::exception)
191 if( PropertyName.equals( m_aColorPropName ))
192 m_nColor = m_nDefaultColor;
195 uno::Any SAL_CALL ColorPropertySet::getPropertyDefault( const OUString& aPropertyName )
196 throw (UnknownPropertyException,
197 lang::WrappedTargetException,
198 uno::RuntimeException, std::exception)
200 if( aPropertyName.equals( m_aColorPropName ))
201 return uno::makeAny( m_nDefaultColor );
202 return uno::Any();
205 } // namespace chart
206 } // namespace xmloff
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */