1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_xmloff.hxx" 30 31 #include "ColorPropertySet.hxx" 32 33 #include <cppuhelper/implbase1.hxx> 34 35 using namespace ::com::sun::star; 36 using namespace ::com::sun::star::beans; 37 38 using ::com::sun::star::uno::Reference; 39 using ::com::sun::star::uno::Sequence; 40 using ::rtl::OUString; 41 using ::com::sun::star::uno::RuntimeException; 42 43 // ================================================================================ 44 45 namespace 46 { 47 class lcl_ColorPropertySetInfo : public ::cppu::WeakImplHelper1< 48 XPropertySetInfo > 49 { 50 public: 51 lcl_ColorPropertySetInfo( bool bFillColor ); 52 53 protected: 54 // ____ XPropertySetInfo ____ 55 virtual Sequence< Property > SAL_CALL getProperties() throw (RuntimeException); 56 virtual Property SAL_CALL getPropertyByName( const OUString& aName ) throw (UnknownPropertyException, RuntimeException); 57 virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) throw (RuntimeException); 58 59 private: 60 bool m_bIsFillColor; 61 OUString m_aColorPropName; 62 Property m_aColorProp; 63 }; 64 65 lcl_ColorPropertySetInfo::lcl_ColorPropertySetInfo( bool bFillColor ) : 66 m_bIsFillColor( bFillColor ), 67 // note: length of FillColor and LineColor is 9 68 m_aColorPropName( (bFillColor ? "FillColor" : "LineColor"), 9, RTL_TEXTENCODING_ASCII_US ), 69 m_aColorProp( m_aColorPropName, -1, 70 ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), 0) 71 {} 72 73 Sequence< Property > SAL_CALL lcl_ColorPropertySetInfo::getProperties() 74 throw (RuntimeException) 75 { 76 77 return Sequence< Property >( & m_aColorProp, 1 ); 78 } 79 80 Property SAL_CALL lcl_ColorPropertySetInfo::getPropertyByName( const OUString& aName ) 81 throw (UnknownPropertyException, RuntimeException) 82 { 83 if( aName.equals( m_aColorPropName )) 84 return m_aColorProp; 85 throw UnknownPropertyException( m_aColorPropName, static_cast< uno::XWeak * >( this )); 86 } 87 88 sal_Bool SAL_CALL lcl_ColorPropertySetInfo::hasPropertyByName( const OUString& Name ) 89 throw (RuntimeException) 90 { 91 return Name.equals( m_aColorPropName ); 92 } 93 94 } // anonymous namespace 95 96 // ================================================================================ 97 98 namespace xmloff 99 { 100 namespace chart 101 { 102 103 ColorPropertySet::ColorPropertySet( sal_Int32 nColor, bool bFillColor /* = true */ ) : 104 // note: length of FillColor and LineColor is 9 105 m_aColorPropName( (bFillColor ? "FillColor" : "LineColor"), 9, RTL_TEXTENCODING_ASCII_US ), 106 m_nColor( nColor ), 107 m_bIsFillColor( bFillColor ), 108 m_nDefaultColor( 0x0099ccff ) // blue 8 109 {} 110 111 ColorPropertySet::~ColorPropertySet() 112 {} 113 114 void ColorPropertySet::setColor( sal_Int32 nColor ) 115 { 116 m_nColor = nColor; 117 } 118 119 sal_Int32 ColorPropertySet::getColor() 120 { 121 return m_nColor; 122 } 123 124 // ____ XPropertySet ____ 125 126 Reference< XPropertySetInfo > SAL_CALL ColorPropertySet::getPropertySetInfo() 127 throw (uno::RuntimeException) 128 { 129 if( ! m_xInfo.is()) 130 m_xInfo.set( new lcl_ColorPropertySetInfo( m_bIsFillColor )); 131 132 return m_xInfo; 133 } 134 135 void SAL_CALL ColorPropertySet::setPropertyValue( const OUString& /* aPropertyName */, const uno::Any& aValue ) 136 throw (UnknownPropertyException, 137 PropertyVetoException, 138 lang::IllegalArgumentException, 139 lang::WrappedTargetException, 140 uno::RuntimeException) 141 { 142 aValue >>= m_nColor; 143 } 144 145 uno::Any SAL_CALL ColorPropertySet::getPropertyValue( const OUString& /* PropertyName */ ) 146 throw (UnknownPropertyException, 147 lang::WrappedTargetException, 148 uno::RuntimeException) 149 { 150 return uno::makeAny( m_nColor ); 151 } 152 153 void SAL_CALL ColorPropertySet::addPropertyChangeListener( const OUString& /* aPropertyName */, const Reference< XPropertyChangeListener >& /* xListener */ ) 154 throw (UnknownPropertyException, 155 lang::WrappedTargetException, 156 uno::RuntimeException) 157 { 158 OSL_ENSURE( false, "Not Implemented" ); 159 return; 160 } 161 162 void SAL_CALL ColorPropertySet::removePropertyChangeListener( const OUString& /* aPropertyName */, const Reference< XPropertyChangeListener >& /* aListener */ ) 163 throw (UnknownPropertyException, 164 lang::WrappedTargetException, 165 uno::RuntimeException) 166 { 167 OSL_ENSURE( false, "Not Implemented" ); 168 return; 169 } 170 171 void SAL_CALL ColorPropertySet::addVetoableChangeListener( const OUString& /* PropertyName */, const Reference< XVetoableChangeListener >& /* aListener */ ) 172 throw (UnknownPropertyException, 173 lang::WrappedTargetException, 174 uno::RuntimeException) 175 { 176 OSL_ENSURE( false, "Not Implemented" ); 177 return; 178 } 179 180 void SAL_CALL ColorPropertySet::removeVetoableChangeListener( const OUString& /* PropertyName */, const Reference< XVetoableChangeListener >& /* aListener */ ) 181 throw (UnknownPropertyException, 182 lang::WrappedTargetException, 183 uno::RuntimeException) 184 { 185 OSL_ENSURE( false, "Not Implemented" ); 186 return; 187 } 188 189 // ____ XPropertyState ____ 190 191 PropertyState SAL_CALL ColorPropertySet::getPropertyState( const OUString& /* PropertyName */ ) 192 throw (UnknownPropertyException, 193 uno::RuntimeException) 194 { 195 return PropertyState_DIRECT_VALUE; 196 } 197 198 Sequence< PropertyState > SAL_CALL ColorPropertySet::getPropertyStates( const Sequence< OUString >& /* aPropertyName */ ) 199 throw (UnknownPropertyException, 200 uno::RuntimeException) 201 { 202 PropertyState aState = PropertyState_DIRECT_VALUE; 203 return Sequence< PropertyState >( & aState, 1 ); 204 } 205 206 void SAL_CALL ColorPropertySet::setPropertyToDefault( const OUString& PropertyName ) 207 throw (UnknownPropertyException, 208 uno::RuntimeException) 209 { 210 if( PropertyName.equals( m_aColorPropName )) 211 m_nColor = m_nDefaultColor; 212 } 213 214 uno::Any SAL_CALL ColorPropertySet::getPropertyDefault( const OUString& aPropertyName ) 215 throw (UnknownPropertyException, 216 lang::WrappedTargetException, 217 uno::RuntimeException) 218 { 219 if( aPropertyName.equals( m_aColorPropName )) 220 return uno::makeAny( m_nDefaultColor ); 221 return uno::Any(); 222 } 223 224 } // namespace chart 225 } // namespace xmloff 226