diff options
Diffstat (limited to 'chart2/source/model/template/BarChartTypeTemplate.cxx')
-rw-r--r-- | chart2/source/model/template/BarChartTypeTemplate.cxx | 176 |
1 files changed, 170 insertions, 6 deletions
diff --git a/chart2/source/model/template/BarChartTypeTemplate.cxx b/chart2/source/model/template/BarChartTypeTemplate.cxx index 91f988602939..387ba68402a8 100644 --- a/chart2/source/model/template/BarChartTypeTemplate.cxx +++ b/chart2/source/model/template/BarChartTypeTemplate.cxx @@ -2,9 +2,9 @@ * * $RCSfile: BarChartTypeTemplate.cxx,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: bm $ $Date: 2003-10-06 09:58:31 $ + * last change: $Author: bm $ $Date: 2003-11-04 12:37:31 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -60,21 +60,115 @@ ************************************************************************/ #include "BarChartTypeTemplate.hxx" #include "BarChartType.hxx" +#include "ColumnChartType.hxx" +#include "algohelper.hxx" +#include "macros.hxx" + +#ifndef CHART_PROPERTYHELPER_HXX +#include "PropertyHelper.hxx" +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif +#ifndef _COM_SUN_STAR_CHART_CHARTSOLIDTYPE_HPP_ +#include <com/sun/star/chart/ChartSolidType.hpp> +#endif + +#include <algorithm> using namespace ::com::sun::star; using namespace ::drafts::com::sun::star; +using ::com::sun::star::beans::Property; +using ::osl::MutexGuard; + +namespace +{ + +static const ::rtl::OUString lcl_aServiceName( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.BarChartTypeTemplate" )); + +enum +{ + PROP_BAR_TEMPLATE_DIMENSION, + PROP_BAR_TEMPLATE_SOLID_TYPE +}; + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + rOutProperties.push_back( + Property( C2U( "Dimension" ), + PROP_BAR_TEMPLATE_DIMENSION, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "SolidType" ), + PROP_BAR_TEMPLATE_SOLID_TYPE, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); +} + +void lcl_AddDefaultsToMap( + ::chart::helper::tPropertyValueMap & rOutMap ) +{ + OSL_ASSERT( rOutMap.end() == rOutMap.find( PROP_BAR_TEMPLATE_DIMENSION )); + rOutMap[ PROP_BAR_TEMPLATE_DIMENSION ] = + uno::makeAny( sal_Int32( 2 ) ); + OSL_ASSERT( rOutMap.end() == rOutMap.find( PROP_BAR_TEMPLATE_SOLID_TYPE )); + rOutMap[ PROP_BAR_TEMPLATE_SOLID_TYPE ] = + uno::makeAny( ::com::sun::star::chart::ChartSolidType::RECTANGULAR_SOLID ); +} + +const uno::Sequence< Property > & lcl_GetPropertySequence() +{ + static uno::Sequence< Property > aPropSeq; + + // /-- + MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( 0 == aPropSeq.getLength() ) + { + // get properties + ::std::vector< ::com::sun::star::beans::Property > aProperties; + lcl_AddPropertiesToVector( aProperties ); + + // and sort them for access via bsearch + ::std::sort( aProperties.begin(), aProperties.end(), + ::chart::helper::PropertyNameLess() ); + + // transfer result to static Sequence + aPropSeq = ::chart::helper::VectorToSequence( aProperties ); + } + + return aPropSeq; +} + +::cppu::IPropertyArrayHelper & lcl_getInfoHelper() +{ + static ::cppu::OPropertyArrayHelper aArrayHelper( + lcl_GetPropertySequence(), + /* bSorted = */ sal_True ); + + return aArrayHelper; +} + +} // anonymous namespace + namespace chart { BarChartTypeTemplate::BarChartTypeTemplate( uno::Reference< uno::XComponentContext > const & xContext, + const ::rtl::OUString & rServiceName, chart2::StackMode eStackMode, BarDirection eDirection, sal_Int32 nDim /* = 2 */, ThreeDMode eThreeDMode /* = THREE_D_FLAT */ ) : - ChartTypeTemplate( xContext ), + ChartTypeTemplate( xContext, rServiceName ), + ::property::OPropertySet( m_aMutex ), m_eStackMode( eStackMode ), m_eBarDirection( eDirection ), m_nDim( nDim ), @@ -94,11 +188,81 @@ chart2::StackMode BarChartTypeTemplate::getStackMode() const return m_eStackMode; } -// ____ XChartTypeTemplate ____ -uno::Reference< chart2::XChartType > SAL_CALL BarChartTypeTemplate::getChartTypeForAdditionalSeries() +uno::Reference< chart2::XChartType > BarChartTypeTemplate::getDefaultChartType() throw (uno::RuntimeException) { - return new BarChartType( m_nDim ); + uno::Reference< chart2::XChartType > xResult; + if( m_eBarDirection == HORIZONTAL ) + xResult.set( new BarChartType( m_nDim )); + else + xResult.set( new ColumnChartType( m_nDim )); + + return xResult; } +// ____ OPropertySet ____ +uno::Any BarChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const + throw(beans::UnknownPropertyException) +{ + static helper::tPropertyValueMap aStaticDefaults; + + // /-- + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( 0 == aStaticDefaults.size() ) + { + // initialize defaults + lcl_AddDefaultsToMap( aStaticDefaults ); + } + + helper::tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + return uno::Any(); + + return (*aFound).second; + // \-- +} + +::cppu::IPropertyArrayHelper & SAL_CALL BarChartTypeTemplate::getInfoHelper() +{ + return lcl_getInfoHelper(); +} + + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + BarChartTypeTemplate::getPropertySetInfo() + throw (uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo; + + // /-- + MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !xInfo.is()) + { + xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo( + getInfoHelper()); + } + + return xInfo; + // \-- +} + +// ---------------------------------------- + +uno::Sequence< ::rtl::OUString > BarChartTypeTemplate::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString > aServices( 2 ); + aServices[ 0 ] = lcl_aServiceName; + aServices[ 1 ] = C2U( "drafts.com.sun.star.chart2.ChartTypeTemplate" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( BarChartTypeTemplate, lcl_aServiceName ); + +IMPLEMENT_FORWARD_XINTERFACE2( BarChartTypeTemplate, ChartTypeTemplate, OPropertySet ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( BarChartTypeTemplate, ChartTypeTemplate, OPropertySet ) + } // namespace chart |