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_chart2.hxx" 30 31 #include "WrappedNumberFormatProperty.hxx" 32 #include "macros.hxx" 33 34 // header for define DBG_ERROR 35 #include <tools/debug.hxx> 36 37 using namespace ::com::sun::star; 38 using ::com::sun::star::uno::Reference; 39 using ::com::sun::star::uno::Any; 40 using ::rtl::OUString; 41 42 //............................................................................. 43 namespace chart 44 { 45 namespace wrapper 46 { 47 //............................................................................. 48 49 WrappedNumberFormatProperty::WrappedNumberFormatProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 50 : WrappedDirectStateProperty( C2U("NumberFormat"), C2U("NumberFormat") ) 51 , m_spChart2ModelContact(spChart2ModelContact) 52 { 53 m_aOuterValue = getPropertyDefault( 0 ); 54 } 55 56 WrappedNumberFormatProperty::~WrappedNumberFormatProperty() 57 { 58 if( m_pWrappedLinkNumberFormatProperty ) 59 { 60 if( m_pWrappedLinkNumberFormatProperty->m_pWrappedNumberFormatProperty == this ) 61 m_pWrappedLinkNumberFormatProperty->m_pWrappedNumberFormatProperty = 0; 62 } 63 } 64 65 void WrappedNumberFormatProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const 66 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException) 67 { 68 sal_Int32 nFormat = 0; 69 if( ! (rOuterValue >>= nFormat) ) 70 throw lang::IllegalArgumentException( C2U("Property 'NumberFormat' requires value of type sal_Int32"), 0, 0 ); 71 72 m_aOuterValue = rOuterValue; 73 if(xInnerPropertySet.is()) 74 { 75 bool bUseSourceFormat = !xInnerPropertySet->getPropertyValue( C2U("NumberFormat" )).hasValue(); 76 if( bUseSourceFormat ) 77 { 78 uno::Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() ); 79 if( xChartDoc.is() && xChartDoc->hasInternalDataProvider() ) 80 bUseSourceFormat = false; 81 } 82 if( !bUseSourceFormat ) 83 xInnerPropertySet->setPropertyValue( m_aInnerName, this->convertOuterToInnerValue( rOuterValue ) ); 84 } 85 } 86 87 Any WrappedNumberFormatProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const 88 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 89 { 90 if( !xInnerPropertySet.is() ) 91 { 92 DBG_ERROR("missing xInnerPropertySet in WrappedNumberFormatProperty::getPropertyValue"); 93 return Any(); 94 } 95 Any aRet( xInnerPropertySet->getPropertyValue( m_aInnerName )); 96 if( !aRet.hasValue() ) 97 { 98 sal_Int32 nKey = 0; 99 Reference< chart2::XDataSeries > xSeries( xInnerPropertySet, uno::UNO_QUERY ); 100 if( xSeries.is() ) 101 nKey = m_spChart2ModelContact->getExplicitNumberFormatKeyForSeries( xSeries ); 102 else 103 { 104 Reference< chart2::XAxis > xAxis( xInnerPropertySet, uno::UNO_QUERY ); 105 nKey = m_spChart2ModelContact->getExplicitNumberFormatKeyForAxis( xAxis ); 106 } 107 aRet <<= nKey; 108 } 109 return aRet; 110 } 111 112 Any WrappedNumberFormatProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const 113 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 114 { 115 return uno::makeAny( sal_Int32( 0 ) ); 116 } 117 118 //----------------------------------------------------------------------------- 119 //----------------------------------------------------------------------------- 120 //----------------------------------------------------------------------------- 121 122 WrappedLinkNumberFormatProperty::WrappedLinkNumberFormatProperty( WrappedNumberFormatProperty* pWrappedNumberFormatProperty ) 123 : WrappedProperty( C2U("LinkNumberFormatToSource"), C2U("") ) 124 , m_pWrappedNumberFormatProperty( pWrappedNumberFormatProperty ) 125 { 126 if( m_pWrappedNumberFormatProperty ) 127 { 128 m_pWrappedNumberFormatProperty->m_pWrappedLinkNumberFormatProperty = this; 129 } 130 } 131 132 WrappedLinkNumberFormatProperty::~WrappedLinkNumberFormatProperty() 133 { 134 if( m_pWrappedNumberFormatProperty ) 135 { 136 if( m_pWrappedNumberFormatProperty->m_pWrappedLinkNumberFormatProperty == this ) 137 m_pWrappedNumberFormatProperty->m_pWrappedLinkNumberFormatProperty = 0; 138 } 139 } 140 141 void WrappedLinkNumberFormatProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const 142 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException) 143 { 144 if( !xInnerPropertySet.is() ) 145 { 146 DBG_ERROR("missing xInnerPropertySet in WrappedNumberFormatProperty::setPropertyValue"); 147 return; 148 } 149 150 bool bLinkFormat = false; 151 if( rOuterValue >>= bLinkFormat ) 152 { 153 Any aValue; 154 if( bLinkFormat ) 155 { 156 if( m_pWrappedNumberFormatProperty ) 157 { 158 uno::Reference< chart2::XChartDocument > xChartDoc( m_pWrappedNumberFormatProperty->m_spChart2ModelContact->getChart2Document() ); 159 if( xChartDoc.is() && xChartDoc->hasInternalDataProvider() ) 160 return; 161 } 162 } 163 else 164 { 165 if( m_pWrappedNumberFormatProperty ) 166 { 167 aValue = m_pWrappedNumberFormatProperty->getPropertyValue( xInnerPropertySet ); 168 } 169 else 170 aValue <<= sal_Int32( 0 ); 171 } 172 173 xInnerPropertySet->setPropertyValue( C2U("NumberFormat"), aValue ); 174 } 175 } 176 177 Any WrappedLinkNumberFormatProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const 178 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 179 { 180 if( !xInnerPropertySet.is() ) 181 { 182 DBG_ERROR("missing xInnerPropertySet in WrappedNumberFormatProperty::getPropertyValue"); 183 return getPropertyDefault(0); 184 } 185 bool bLink = ! xInnerPropertySet->getPropertyValue( C2U("NumberFormat" )).hasValue(); 186 return uno::makeAny( bLink ); 187 } 188 189 Any WrappedLinkNumberFormatProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const 190 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 191 { 192 bool bLink = true; 193 return uno::makeAny( bLink ); 194 } 195 196 //............................................................................. 197 } //namespace wrapper 198 } //namespace chart 199 //............................................................................. 200