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