1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WrappedNumberFormatProperty.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "WrappedNumberFormatProperty.hxx"
37 // header for define DBG_ERROR
38 #include <tools/debug.hxx>
40 using namespace ::com::sun::star
;
41 using ::com::sun::star::uno::Reference
;
42 using ::com::sun::star::uno::Any
;
43 using ::rtl::OUString
;
45 //.............................................................................
50 //.............................................................................
52 WrappedNumberFormatProperty::WrappedNumberFormatProperty( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
53 : WrappedDirectStateProperty( C2U("NumberFormat"), C2U("NumberFormat") )
54 , m_spChart2ModelContact(spChart2ModelContact
)
56 m_aOuterValue
= getPropertyDefault( 0 );
59 WrappedNumberFormatProperty::~WrappedNumberFormatProperty()
61 if( m_pWrappedLinkNumberFormatProperty
)
63 if( m_pWrappedLinkNumberFormatProperty
->m_pWrappedNumberFormatProperty
== this )
64 m_pWrappedLinkNumberFormatProperty
->m_pWrappedNumberFormatProperty
= 0;
68 void WrappedNumberFormatProperty::setPropertyValue( const Any
& rOuterValue
, const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
69 throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
71 sal_Int32 nFormat
= 0;
72 if( ! (rOuterValue
>>= nFormat
) )
73 throw lang::IllegalArgumentException( C2U("Property 'NumberFormat' requires value of type sal_Int32"), 0, 0 );
75 m_aOuterValue
= rOuterValue
;
76 if(xInnerPropertySet
.is())
78 bool bUseSourceFormat
= !xInnerPropertySet
->getPropertyValue( C2U("NumberFormat" )).hasValue();
79 if( bUseSourceFormat
)
81 uno::Reference
< chart2::XChartDocument
> xChartDoc( m_spChart2ModelContact
->getChart2Document() );
82 if( xChartDoc
.is() && xChartDoc
->hasInternalDataProvider() )
83 bUseSourceFormat
= false;
85 if( !bUseSourceFormat
)
86 xInnerPropertySet
->setPropertyValue( m_aInnerName
, this->convertOuterToInnerValue( rOuterValue
) );
90 Any
WrappedNumberFormatProperty::getPropertyValue( const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
91 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
93 if( !xInnerPropertySet
.is() )
95 DBG_ERROR("missing xInnerPropertySet in WrappedNumberFormatProperty::getPropertyValue");
98 Any
aRet( xInnerPropertySet
->getPropertyValue( m_aInnerName
));
99 if( !aRet
.hasValue() )
102 Reference
< chart2::XDataSeries
> xSeries( xInnerPropertySet
, uno::UNO_QUERY
);
104 nKey
= m_spChart2ModelContact
->getExplicitNumberFormatKeyForSeries( xSeries
);
107 Reference
< chart2::XAxis
> xAxis( xInnerPropertySet
, uno::UNO_QUERY
);
108 nKey
= m_spChart2ModelContact
->getExplicitNumberFormatKeyForAxis( xAxis
);
115 Any
WrappedNumberFormatProperty::getPropertyDefault( const Reference
< beans::XPropertyState
>& /*xInnerPropertyState*/ ) const
116 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
118 return uno::makeAny( sal_Int32( 0 ) );
121 //-----------------------------------------------------------------------------
122 //-----------------------------------------------------------------------------
123 //-----------------------------------------------------------------------------
125 WrappedLinkNumberFormatProperty::WrappedLinkNumberFormatProperty( WrappedNumberFormatProperty
* pWrappedNumberFormatProperty
)
126 : WrappedProperty( C2U("LinkNumberFormatToSource"), C2U("") )
127 , m_pWrappedNumberFormatProperty( pWrappedNumberFormatProperty
)
129 if( m_pWrappedNumberFormatProperty
)
131 m_pWrappedNumberFormatProperty
->m_pWrappedLinkNumberFormatProperty
= this;
135 WrappedLinkNumberFormatProperty::~WrappedLinkNumberFormatProperty()
137 if( m_pWrappedNumberFormatProperty
)
139 if( m_pWrappedNumberFormatProperty
->m_pWrappedLinkNumberFormatProperty
== this )
140 m_pWrappedNumberFormatProperty
->m_pWrappedLinkNumberFormatProperty
= 0;
144 void WrappedLinkNumberFormatProperty::setPropertyValue( const Any
& rOuterValue
, const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
145 throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
147 if( !xInnerPropertySet
.is() )
149 DBG_ERROR("missing xInnerPropertySet in WrappedNumberFormatProperty::setPropertyValue");
153 bool bLinkFormat
= false;
154 if( rOuterValue
>>= bLinkFormat
)
159 if( m_pWrappedNumberFormatProperty
)
161 uno::Reference
< chart2::XChartDocument
> xChartDoc( m_pWrappedNumberFormatProperty
->m_spChart2ModelContact
->getChart2Document() );
162 if( xChartDoc
.is() && xChartDoc
->hasInternalDataProvider() )
168 if( m_pWrappedNumberFormatProperty
)
170 aValue
= m_pWrappedNumberFormatProperty
->getPropertyValue( xInnerPropertySet
);
173 aValue
<<= sal_Int32( 0 );
176 xInnerPropertySet
->setPropertyValue( C2U("NumberFormat"), aValue
);
180 Any
WrappedLinkNumberFormatProperty::getPropertyValue( const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
181 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
183 if( !xInnerPropertySet
.is() )
185 DBG_ERROR("missing xInnerPropertySet in WrappedNumberFormatProperty::getPropertyValue");
186 return getPropertyDefault(0);
188 bool bLink
= ! xInnerPropertySet
->getPropertyValue( C2U("NumberFormat" )).hasValue();
189 return uno::makeAny( bLink
);
192 Any
WrappedLinkNumberFormatProperty::getPropertyDefault( const Reference
< beans::XPropertyState
>& /*xInnerPropertyState*/ ) const
193 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
196 return uno::makeAny( bLink
);
199 //.............................................................................
200 } //namespace wrapper
202 //.............................................................................