1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26
27 #include "ColorPropertySet.hxx"
28
29 #include <cppuhelper/implbase1.hxx>
30
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::beans;
33
34 using ::com::sun::star::uno::Reference;
35 using ::com::sun::star::uno::Sequence;
36 using ::rtl::OUString;
37 using ::com::sun::star::uno::RuntimeException;
38
39 // ================================================================================
40
41 namespace
42 {
43 class lcl_ColorPropertySetInfo : public ::cppu::WeakImplHelper1<
44 XPropertySetInfo >
45 {
46 public:
47 lcl_ColorPropertySetInfo( bool bFillColor );
48
49 protected:
50 // ____ XPropertySetInfo ____
51 virtual Sequence< Property > SAL_CALL getProperties() throw (RuntimeException);
52 virtual Property SAL_CALL getPropertyByName( const OUString& aName ) throw (UnknownPropertyException, RuntimeException);
53 virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) throw (RuntimeException);
54
55 private:
56 bool m_bIsFillColor;
57 OUString m_aColorPropName;
58 Property m_aColorProp;
59 };
60
lcl_ColorPropertySetInfo(bool bFillColor)61 lcl_ColorPropertySetInfo::lcl_ColorPropertySetInfo( bool bFillColor ) :
62 m_bIsFillColor( bFillColor ),
63 // note: length of FillColor and LineColor is 9
64 m_aColorPropName( (bFillColor ? "FillColor" : "LineColor"), 9, RTL_TEXTENCODING_ASCII_US ),
65 m_aColorProp( m_aColorPropName, -1,
66 ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), 0)
67 {}
68
getProperties()69 Sequence< Property > SAL_CALL lcl_ColorPropertySetInfo::getProperties()
70 throw (RuntimeException)
71 {
72
73 return Sequence< Property >( & m_aColorProp, 1 );
74 }
75
getPropertyByName(const OUString & aName)76 Property SAL_CALL lcl_ColorPropertySetInfo::getPropertyByName( const OUString& aName )
77 throw (UnknownPropertyException, RuntimeException)
78 {
79 if( aName.equals( m_aColorPropName ))
80 return m_aColorProp;
81 throw UnknownPropertyException( m_aColorPropName, static_cast< uno::XWeak * >( this ));
82 }
83
hasPropertyByName(const OUString & Name)84 sal_Bool SAL_CALL lcl_ColorPropertySetInfo::hasPropertyByName( const OUString& Name )
85 throw (RuntimeException)
86 {
87 return Name.equals( m_aColorPropName );
88 }
89
90 } // anonymous namespace
91
92 // ================================================================================
93
94 namespace xmloff
95 {
96 namespace chart
97 {
98
ColorPropertySet(sal_Int32 nColor,bool bFillColor)99 ColorPropertySet::ColorPropertySet( sal_Int32 nColor, bool bFillColor /* = true */ ) :
100 // note: length of FillColor and LineColor is 9
101 m_aColorPropName( (bFillColor ? "FillColor" : "LineColor"), 9, RTL_TEXTENCODING_ASCII_US ),
102 m_nColor( nColor ),
103 m_bIsFillColor( bFillColor ),
104 m_nDefaultColor( 0x0099ccff ) // blue 8
105 {}
106
~ColorPropertySet()107 ColorPropertySet::~ColorPropertySet()
108 {}
109
setColor(sal_Int32 nColor)110 void ColorPropertySet::setColor( sal_Int32 nColor )
111 {
112 m_nColor = nColor;
113 }
114
getColor()115 sal_Int32 ColorPropertySet::getColor()
116 {
117 return m_nColor;
118 }
119
120 // ____ XPropertySet ____
121
getPropertySetInfo()122 Reference< XPropertySetInfo > SAL_CALL ColorPropertySet::getPropertySetInfo()
123 throw (uno::RuntimeException)
124 {
125 if( ! m_xInfo.is())
126 m_xInfo.set( new lcl_ColorPropertySetInfo( m_bIsFillColor ));
127
128 return m_xInfo;
129 }
130
setPropertyValue(const OUString &,const uno::Any & aValue)131 void SAL_CALL ColorPropertySet::setPropertyValue( const OUString& /* aPropertyName */, const uno::Any& aValue )
132 throw (UnknownPropertyException,
133 PropertyVetoException,
134 lang::IllegalArgumentException,
135 lang::WrappedTargetException,
136 uno::RuntimeException)
137 {
138 aValue >>= m_nColor;
139 }
140
getPropertyValue(const OUString &)141 uno::Any SAL_CALL ColorPropertySet::getPropertyValue( const OUString& /* PropertyName */ )
142 throw (UnknownPropertyException,
143 lang::WrappedTargetException,
144 uno::RuntimeException)
145 {
146 return uno::makeAny( m_nColor );
147 }
148
addPropertyChangeListener(const OUString &,const Reference<XPropertyChangeListener> &)149 void SAL_CALL ColorPropertySet::addPropertyChangeListener( const OUString& /* aPropertyName */, const Reference< XPropertyChangeListener >& /* xListener */ )
150 throw (UnknownPropertyException,
151 lang::WrappedTargetException,
152 uno::RuntimeException)
153 {
154 OSL_ENSURE( false, "Not Implemented" );
155 return;
156 }
157
removePropertyChangeListener(const OUString &,const Reference<XPropertyChangeListener> &)158 void SAL_CALL ColorPropertySet::removePropertyChangeListener( const OUString& /* aPropertyName */, const Reference< XPropertyChangeListener >& /* aListener */ )
159 throw (UnknownPropertyException,
160 lang::WrappedTargetException,
161 uno::RuntimeException)
162 {
163 OSL_ENSURE( false, "Not Implemented" );
164 return;
165 }
166
addVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)167 void SAL_CALL ColorPropertySet::addVetoableChangeListener( const OUString& /* PropertyName */, const Reference< XVetoableChangeListener >& /* aListener */ )
168 throw (UnknownPropertyException,
169 lang::WrappedTargetException,
170 uno::RuntimeException)
171 {
172 OSL_ENSURE( false, "Not Implemented" );
173 return;
174 }
175
removeVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)176 void SAL_CALL ColorPropertySet::removeVetoableChangeListener( const OUString& /* PropertyName */, const Reference< XVetoableChangeListener >& /* aListener */ )
177 throw (UnknownPropertyException,
178 lang::WrappedTargetException,
179 uno::RuntimeException)
180 {
181 OSL_ENSURE( false, "Not Implemented" );
182 return;
183 }
184
185 // ____ XPropertyState ____
186
getPropertyState(const OUString &)187 PropertyState SAL_CALL ColorPropertySet::getPropertyState( const OUString& /* PropertyName */ )
188 throw (UnknownPropertyException,
189 uno::RuntimeException)
190 {
191 return PropertyState_DIRECT_VALUE;
192 }
193
getPropertyStates(const Sequence<OUString> &)194 Sequence< PropertyState > SAL_CALL ColorPropertySet::getPropertyStates( const Sequence< OUString >& /* aPropertyName */ )
195 throw (UnknownPropertyException,
196 uno::RuntimeException)
197 {
198 PropertyState aState = PropertyState_DIRECT_VALUE;
199 return Sequence< PropertyState >( & aState, 1 );
200 }
201
setPropertyToDefault(const OUString & PropertyName)202 void SAL_CALL ColorPropertySet::setPropertyToDefault( const OUString& PropertyName )
203 throw (UnknownPropertyException,
204 uno::RuntimeException)
205 {
206 if( PropertyName.equals( m_aColorPropName ))
207 m_nColor = m_nDefaultColor;
208 }
209
getPropertyDefault(const OUString & aPropertyName)210 uno::Any SAL_CALL ColorPropertySet::getPropertyDefault( const OUString& aPropertyName )
211 throw (UnknownPropertyException,
212 lang::WrappedTargetException,
213 uno::RuntimeException)
214 {
215 if( aPropertyName.equals( m_aColorPropName ))
216 return uno::makeAny( m_nDefaultColor );
217 return uno::Any();
218 }
219
220 } // namespace chart
221 } // namespace xmloff
222