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