Line data Source code
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 :
20 : // FIXME? This file is nearly identical to xmloff/source/chart/ColorPropertySet.cxx
21 :
22 : #include "ColorPropertySet.hxx"
23 :
24 : #include <cppuhelper/implbase1.hxx>
25 : #include <com/sun/star/drawing/FillStyle.hpp>
26 :
27 : using namespace ::com::sun::star;
28 : using namespace ::com::sun::star::beans;
29 :
30 : using ::com::sun::star::uno::Reference;
31 : using ::com::sun::star::uno::Sequence;
32 : using ::com::sun::star::uno::RuntimeException;
33 :
34 : namespace
35 : {
36 0 : class lcl_ColorPropertySetInfo : public ::cppu::WeakImplHelper1<
37 : XPropertySetInfo >
38 : {
39 : public:
40 : lcl_ColorPropertySetInfo( bool bFillColor );
41 :
42 : protected:
43 : // ____ XPropertySetInfo ____
44 : virtual Sequence< Property > SAL_CALL getProperties() throw (RuntimeException, std::exception) SAL_OVERRIDE;
45 : virtual Property SAL_CALL getPropertyByName( const OUString& aName ) throw (UnknownPropertyException, RuntimeException, std::exception) SAL_OVERRIDE;
46 : virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
47 :
48 : private:
49 : OUString m_aColorPropName;
50 : Property m_aColorProp;
51 : };
52 :
53 0 : 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 0 : cppu::UnoType<sal_Int32>::get(), 0)
58 0 : {}
59 :
60 0 : Sequence< Property > SAL_CALL lcl_ColorPropertySetInfo::getProperties()
61 : throw (RuntimeException, std::exception)
62 : {
63 :
64 0 : return Sequence< Property >( & m_aColorProp, 1 );
65 : }
66 :
67 0 : Property SAL_CALL lcl_ColorPropertySetInfo::getPropertyByName( const OUString& aName )
68 : throw (UnknownPropertyException, RuntimeException, std::exception)
69 : {
70 0 : if( aName.equals( m_aColorPropName ))
71 0 : return m_aColorProp;
72 0 : throw UnknownPropertyException( m_aColorPropName, static_cast< uno::XWeak * >( this ));
73 : }
74 :
75 0 : sal_Bool SAL_CALL lcl_ColorPropertySetInfo::hasPropertyByName( const OUString& Name )
76 : throw (RuntimeException, std::exception)
77 : {
78 0 : return Name.equals( m_aColorPropName );
79 : }
80 :
81 : } // anonymous namespace
82 :
83 : namespace oox
84 : {
85 : namespace drawingml
86 : {
87 :
88 0 : ColorPropertySet::ColorPropertySet( sal_Int32 nColor, bool bFillColor /* = true */ ) :
89 : // note: length of FillColor and LineColor is 9
90 : m_aColorPropName( (bFillColor ? "FillColor" : "LineColor"), 9, RTL_TEXTENCODING_ASCII_US ),
91 : m_nColor( nColor ),
92 : m_bIsFillColor( bFillColor ),
93 0 : m_nDefaultColor( 0x0099ccff ) // blue 8
94 0 : {}
95 :
96 0 : ColorPropertySet::~ColorPropertySet()
97 0 : {}
98 :
99 : // ____ XPropertySet ____
100 :
101 0 : Reference< XPropertySetInfo > SAL_CALL ColorPropertySet::getPropertySetInfo()
102 : throw (uno::RuntimeException, std::exception)
103 : {
104 0 : if( ! m_xInfo.is())
105 0 : m_xInfo.set( new lcl_ColorPropertySetInfo( m_bIsFillColor ));
106 :
107 0 : return m_xInfo;
108 : }
109 :
110 0 : void SAL_CALL ColorPropertySet::setPropertyValue( const OUString& /* aPropertyName */, const uno::Any& aValue )
111 : throw (UnknownPropertyException,
112 : PropertyVetoException,
113 : lang::IllegalArgumentException,
114 : lang::WrappedTargetException,
115 : uno::RuntimeException, std::exception)
116 : {
117 0 : aValue >>= m_nColor;
118 0 : }
119 :
120 0 : uno::Any SAL_CALL ColorPropertySet::getPropertyValue( const OUString& aPropertyName )
121 : throw (UnknownPropertyException,
122 : lang::WrappedTargetException,
123 : uno::RuntimeException, std::exception)
124 : {
125 0 : if( aPropertyName == "FillStyle" && m_bIsFillColor )
126 : {
127 0 : ::com::sun::star::drawing::FillStyle aFillStyle = ::com::sun::star::drawing::FillStyle_SOLID;
128 0 : return uno::makeAny(aFillStyle);
129 : }
130 0 : return uno::makeAny( m_nColor );
131 : }
132 :
133 0 : void SAL_CALL ColorPropertySet::addPropertyChangeListener( const OUString& /* aPropertyName */, const Reference< XPropertyChangeListener >& /* xListener */ )
134 : throw (UnknownPropertyException,
135 : lang::WrappedTargetException,
136 : uno::RuntimeException, std::exception)
137 : {
138 : OSL_FAIL( "Not Implemented" );
139 0 : return;
140 : }
141 :
142 0 : void SAL_CALL ColorPropertySet::removePropertyChangeListener( const OUString& /* aPropertyName */, const Reference< XPropertyChangeListener >& /* aListener */ )
143 : throw (UnknownPropertyException,
144 : lang::WrappedTargetException,
145 : uno::RuntimeException, std::exception)
146 : {
147 : OSL_FAIL( "Not Implemented" );
148 0 : return;
149 : }
150 :
151 0 : void SAL_CALL ColorPropertySet::addVetoableChangeListener( const OUString& /* PropertyName */, const Reference< XVetoableChangeListener >& /* aListener */ )
152 : throw (UnknownPropertyException,
153 : lang::WrappedTargetException,
154 : uno::RuntimeException, std::exception)
155 : {
156 : OSL_FAIL( "Not Implemented" );
157 0 : return;
158 : }
159 :
160 0 : void SAL_CALL ColorPropertySet::removeVetoableChangeListener( const OUString& /* PropertyName */, const Reference< XVetoableChangeListener >& /* aListener */ )
161 : throw (UnknownPropertyException,
162 : lang::WrappedTargetException,
163 : uno::RuntimeException, std::exception)
164 : {
165 : OSL_FAIL( "Not Implemented" );
166 0 : return;
167 : }
168 :
169 : // ____ XPropertyState ____
170 :
171 0 : PropertyState SAL_CALL ColorPropertySet::getPropertyState( const OUString& /* PropertyName */ )
172 : throw (UnknownPropertyException,
173 : uno::RuntimeException, std::exception)
174 : {
175 0 : return PropertyState_DIRECT_VALUE;
176 : }
177 :
178 0 : Sequence< PropertyState > SAL_CALL ColorPropertySet::getPropertyStates( const Sequence< OUString >& /* aPropertyName */ )
179 : throw (UnknownPropertyException,
180 : uno::RuntimeException, std::exception)
181 : {
182 0 : PropertyState aState = PropertyState_DIRECT_VALUE;
183 0 : return Sequence< PropertyState >( & aState, 1 );
184 : }
185 :
186 0 : void SAL_CALL ColorPropertySet::setPropertyToDefault( const OUString& PropertyName )
187 : throw (UnknownPropertyException,
188 : uno::RuntimeException, std::exception)
189 : {
190 0 : if( PropertyName.equals( m_aColorPropName ))
191 0 : m_nColor = m_nDefaultColor;
192 0 : }
193 :
194 0 : uno::Any SAL_CALL ColorPropertySet::getPropertyDefault( const OUString& aPropertyName )
195 : throw (UnknownPropertyException,
196 : lang::WrappedTargetException,
197 : uno::RuntimeException, std::exception)
198 : {
199 0 : if( aPropertyName.equals( m_aColorPropName ))
200 0 : return uno::makeAny( m_nDefaultColor );
201 0 : return uno::Any();
202 : }
203 :
204 : } // namespace chart
205 : } // namespace xmloff
206 :
207 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|