xref: /trunk/main/xmloff/source/chart/ColorPropertySet.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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();
52     virtual Property SAL_CALL getPropertyByName( const OUString& aName );
53     virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name );
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 {
71 
72     return Sequence< Property >( & m_aColorProp, 1 );
73 }
74 
getPropertyByName(const OUString & aName)75 Property SAL_CALL lcl_ColorPropertySetInfo::getPropertyByName( const OUString& aName )
76 {
77     if( aName.equals( m_aColorPropName ))
78         return m_aColorProp;
79     throw UnknownPropertyException( m_aColorPropName, static_cast< uno::XWeak * >( this ));
80 }
81 
hasPropertyByName(const OUString & Name)82 sal_Bool SAL_CALL lcl_ColorPropertySetInfo::hasPropertyByName( const OUString& Name )
83 {
84     return Name.equals( m_aColorPropName );
85 }
86 
87 } // anonymous namespace
88 
89 // ================================================================================
90 
91 namespace xmloff
92 {
93 namespace chart
94 {
95 
ColorPropertySet(sal_Int32 nColor,bool bFillColor)96 ColorPropertySet::ColorPropertySet( sal_Int32 nColor, bool bFillColor /* = true */ ) :
97         // note: length of FillColor and LineColor is 9
98         m_aColorPropName( (bFillColor ? "FillColor" : "LineColor"), 9, RTL_TEXTENCODING_ASCII_US ),
99         m_nColor( nColor ),
100         m_bIsFillColor( bFillColor ),
101         m_nDefaultColor( 0x0099ccff )  // blue 8
102 {}
103 
~ColorPropertySet()104 ColorPropertySet::~ColorPropertySet()
105 {}
106 
setColor(sal_Int32 nColor)107 void ColorPropertySet::setColor( sal_Int32 nColor )
108 {
109     m_nColor = nColor;
110 }
111 
getColor()112 sal_Int32 ColorPropertySet::getColor()
113 {
114     return m_nColor;
115 }
116 
117 // ____ XPropertySet ____
118 
getPropertySetInfo()119 Reference< XPropertySetInfo > SAL_CALL ColorPropertySet::getPropertySetInfo()
120 {
121     if( ! m_xInfo.is())
122         m_xInfo.set( new lcl_ColorPropertySetInfo( m_bIsFillColor ));
123 
124     return m_xInfo;
125 }
126 
setPropertyValue(const OUString &,const uno::Any & aValue)127 void SAL_CALL ColorPropertySet::setPropertyValue( const OUString& /* aPropertyName */, const uno::Any& aValue )
128 {
129     aValue >>= m_nColor;
130 }
131 
getPropertyValue(const OUString &)132 uno::Any SAL_CALL ColorPropertySet::getPropertyValue( const OUString& /* PropertyName */ )
133 {
134     return uno::makeAny( m_nColor );
135 }
136 
addPropertyChangeListener(const OUString &,const Reference<XPropertyChangeListener> &)137 void SAL_CALL ColorPropertySet::addPropertyChangeListener( const OUString& /* aPropertyName */, const Reference< XPropertyChangeListener >& /* xListener */ )
138 {
139     OSL_ENSURE( false, "Not Implemented" );
140     return;
141 }
142 
removePropertyChangeListener(const OUString &,const Reference<XPropertyChangeListener> &)143 void SAL_CALL ColorPropertySet::removePropertyChangeListener( const OUString& /* aPropertyName */, const Reference< XPropertyChangeListener >& /* aListener */ )
144 {
145     OSL_ENSURE( false, "Not Implemented" );
146     return;
147 }
148 
addVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)149 void SAL_CALL ColorPropertySet::addVetoableChangeListener( const OUString& /* PropertyName */, const Reference< XVetoableChangeListener >& /* aListener */ )
150 {
151     OSL_ENSURE( false, "Not Implemented" );
152     return;
153 }
154 
removeVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)155 void SAL_CALL ColorPropertySet::removeVetoableChangeListener( const OUString& /* PropertyName */, const Reference< XVetoableChangeListener >& /* aListener */ )
156 {
157     OSL_ENSURE( false, "Not Implemented" );
158     return;
159 }
160 
161 // ____ XPropertyState ____
162 
getPropertyState(const OUString &)163 PropertyState SAL_CALL ColorPropertySet::getPropertyState( const OUString& /* PropertyName */ )
164 {
165     return PropertyState_DIRECT_VALUE;
166 }
167 
getPropertyStates(const Sequence<OUString> &)168 Sequence< PropertyState > SAL_CALL ColorPropertySet::getPropertyStates( const Sequence< OUString >& /* aPropertyName */ )
169 {
170     PropertyState aState = PropertyState_DIRECT_VALUE;
171     return Sequence< PropertyState >( & aState, 1 );
172 }
173 
setPropertyToDefault(const OUString & PropertyName)174 void SAL_CALL ColorPropertySet::setPropertyToDefault( const OUString& PropertyName )
175 {
176     if( PropertyName.equals( m_aColorPropName ))
177         m_nColor = m_nDefaultColor;
178 }
179 
getPropertyDefault(const OUString & aPropertyName)180 uno::Any SAL_CALL ColorPropertySet::getPropertyDefault( const OUString& aPropertyName )
181 {
182     if( aPropertyName.equals( m_aColorPropName ))
183         return uno::makeAny( m_nDefaultColor );
184     return uno::Any();
185 }
186 
187 } //  namespace chart
188 } //  namespace xmloff
189