summaryrefslogtreecommitdiff
path: root/chart2/source/controller/chartapiwrapper/DataSeriesPointWrapper.cxx
diff options
context:
space:
mode:
authorBjörn Milcke <bm@openoffice.org>2003-12-18 12:50:56 +0000
committerBjörn Milcke <bm@openoffice.org>2003-12-18 12:50:56 +0000
commit77a0557b67340195176d6b51571ad1a9f9ff9f26 (patch)
tree6fc7543d35ff53a4f2b4b3a67120fbd022950f05 /chart2/source/controller/chartapiwrapper/DataSeriesPointWrapper.cxx
parent1c3ad7b9ebdc7a3560257bc32dcff08793dc759c (diff)
moved from model/oldapi
Diffstat (limited to 'chart2/source/controller/chartapiwrapper/DataSeriesPointWrapper.cxx')
-rw-r--r--chart2/source/controller/chartapiwrapper/DataSeriesPointWrapper.cxx479
1 files changed, 479 insertions, 0 deletions
diff --git a/chart2/source/controller/chartapiwrapper/DataSeriesPointWrapper.cxx b/chart2/source/controller/chartapiwrapper/DataSeriesPointWrapper.cxx
new file mode 100644
index 000000000000..a5e01a9ba934
--- /dev/null
+++ b/chart2/source/controller/chartapiwrapper/DataSeriesPointWrapper.cxx
@@ -0,0 +1,479 @@
+/*************************************************************************
+ *
+ * $RCSfile: DataSeriesPointWrapper.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: bm $ $Date: 2003-12-18 13:49:36 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2003 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#include "DataSeriesPointWrapper.hxx"
+#include "macros.hxx"
+#include "InlineContainer.hxx"
+#include "algohelper.hxx"
+
+#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+#endif
+#ifndef _COM_SUN_STAR_CHART_CHARTAXISASSIGN_HPP_
+#include <com/sun/star/chart/ChartAxisAssign.hpp>
+#endif
+#ifndef _COM_SUN_STAR_CHART_CHARTDATACAPTION_HPP_
+#include <com/sun/star/chart/ChartDataCaption.hpp>
+#endif
+#ifndef _DRAFTS_COM_SUN_STAR_CHART2_DATAPOINTLABEL_HPP_
+#include <drafts/com/sun/star/chart2/DataPointLabel.hpp>
+#endif
+#ifndef _DRAFTS_COM_SUN_STAR_CHART2_TRANSPARENCYSTYLE_HPP_
+#include <drafts/com/sun/star/chart2/TransparencyStyle.hpp>
+#endif
+
+#include "LineProperties.hxx"
+#include "FillProperties.hxx"
+#include "CharacterProperties.hxx"
+#include "UserDefinedProperties.hxx"
+
+#include <algorithm>
+
+#ifndef _RTL_USTRBUF_HXX_
+#include <rtl/ustrbuf.hxx>
+#endif
+
+using namespace ::com::sun::star;
+using namespace ::drafts::com::sun::star;
+using ::com::sun::star::beans::Property;
+using ::osl::MutexGuard;
+using ::property::OPropertySet;
+
+namespace
+{
+static const ::rtl::OUString lcl_aServiceName(
+ RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.DataSeries" ));
+
+enum
+{
+ PROP_SERIES_ATTACHED_AXIS,
+ PROP_SERIES_DATA_CAPTION
+};
+
+typedef ::std::map< sal_Int32, ::rtl::OUString > lcl_PropertyMapType;
+typedef ::comphelper::MakeMap< sal_Int32, ::rtl::OUString > lcl_MakePropertyMapType;
+
+lcl_PropertyMapType & lcl_GetPropertyMapLine()
+{
+ static lcl_PropertyMapType aMap(
+ lcl_MakePropertyMapType
+ ( ::chart::LineProperties::PROP_LINE_TRANSPARENCE, C2U( "Transparency" ))
+ ( ::chart::LineProperties::PROP_LINE_COLOR, C2U( "Color" ))
+ ( ::chart::LineProperties::PROP_LINE_STYLE, C2U( "LineStyle" ))
+ );
+
+ return aMap;
+};
+
+lcl_PropertyMapType & lcl_GetPropertyMapFilled()
+{
+ static lcl_PropertyMapType aMap(
+ lcl_MakePropertyMapType
+ // Note: FillStyle has same name but must be mapped (ids differ)
+ ( ::chart::FillProperties::PROP_FILL_STYLE, C2U( "FillStyle" ))
+ ( ::chart::FillProperties::PROP_FILL_COLOR, C2U( "Color" ) )
+ ( ::chart::FillProperties::PROP_FILL_TRANSPARENCE, C2U( "Transparency" ))
+ ( ::chart::FillProperties::PROP_FILL_GRADIENT, C2U( "Gradient" ))
+ ( ::chart::FillProperties::PROP_FILL_HATCH, C2U( "Hatch" ))
+
+ ( ::chart::LineProperties::PROP_LINE_STYLE, C2U( "BorderStyle" ))
+ ( ::chart::LineProperties::PROP_LINE_COLOR, C2U( "BorderColor" ))
+ ( ::chart::LineProperties::PROP_LINE_WIDTH, C2U( "BorderWidth" ))
+ );
+
+ return aMap;
+};
+
+void lcl_AddPropertiesToVector(
+ ::std::vector< Property > & rOutProperties )
+{
+ rOutProperties.push_back(
+ Property( C2U( "Axis" ),
+ PROP_SERIES_ATTACHED_AXIS,
+ ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
+ beans::PropertyAttribute::BOUND
+ | beans::PropertyAttribute::MAYBEDEFAULT ));
+
+ rOutProperties.push_back(
+ Property( C2U( "DataCaption" ),
+ PROP_SERIES_DATA_CAPTION,
+ ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
+ beans::PropertyAttribute::BOUND
+ | beans::PropertyAttribute::MAYBEDEFAULT ));
+}
+
+void lcl_AddDefaultsToMap(
+ ::chart::helper::tPropertyValueMap & rOutMap )
+{
+ OSL_ASSERT( rOutMap.end() == rOutMap.find( PROP_SERIES_ATTACHED_AXIS ));
+ rOutMap[ PROP_SERIES_ATTACHED_AXIS ] =
+ uno::makeAny( sal_Int32( ::com::sun::star::chart::ChartAxisAssign::PRIMARY_Y ) );
+ OSL_ASSERT( rOutMap.end() == rOutMap.find( PROP_SERIES_DATA_CAPTION ));
+ rOutMap[ PROP_SERIES_DATA_CAPTION ] =
+ uno::makeAny( sal_Int32( ::com::sun::star::chart::ChartDataCaption::NONE ) );
+}
+
+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 );
+ ::chart::LineProperties::AddPropertiesToVector(
+ aProperties, /* bIncludeStyleProperties = */ false );
+ ::chart::FillProperties::AddPropertiesToVector(
+ aProperties, /* bIncludeStyleProperties = */ false );
+ ::chart::CharacterProperties::AddPropertiesToVector(
+ aProperties, /* bIncludeStyleProperties = */ false );
+ ::chart::UserDefinedProperties::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
+{
+namespace wrapper
+{
+
+DataSeriesPointWrapper::DataSeriesPointWrapper(
+ eParentType eType,
+ const uno::Reference< beans::XPropertySet > & xParentProperties,
+ const uno::Reference< uno::XComponentContext > & xContext,
+ ::osl::Mutex & _rMutex ) :
+ OPropertySet( _rMutex ),
+ m_rMutex( _rMutex ),
+ m_xContext( xContext ),
+ m_aEventListenerContainer( _rMutex ),
+ m_eParentType( eType ),
+ m_xParentProperties( xParentProperties ),
+ m_xParentFastProperties( xParentProperties, uno::UNO_QUERY )
+{}
+
+DataSeriesPointWrapper::~DataSeriesPointWrapper()
+{}
+
+::osl::Mutex & DataSeriesPointWrapper::GetMutex() const
+{
+ return m_rMutex;
+}
+
+// ____ XComponent ____
+void SAL_CALL DataSeriesPointWrapper::dispose()
+ throw (uno::RuntimeException)
+{
+ m_aEventListenerContainer.disposeAndClear( lang::EventObject( *this ) );
+
+ // /--
+ MutexGuard aGuard( GetMutex());
+ m_xParentProperties = NULL;
+ m_xParentFastProperties = NULL;
+ // \--
+}
+
+void SAL_CALL DataSeriesPointWrapper::addEventListener(
+ const uno::Reference< lang::XEventListener >& xListener )
+ throw (uno::RuntimeException)
+{
+ m_aEventListenerContainer.addInterface( xListener );
+}
+
+void SAL_CALL DataSeriesPointWrapper::removeEventListener(
+ const uno::Reference< lang::XEventListener >& aListener )
+ throw (uno::RuntimeException)
+{
+ m_aEventListenerContainer.removeInterface( aListener );
+}
+
+// ____ XEventListener ____
+void SAL_CALL DataSeriesPointWrapper::disposing( const lang::EventObject& Source )
+ throw (uno::RuntimeException)
+{
+}
+
+
+sal_Bool SAL_CALL DataSeriesPointWrapper::convertFastPropertyValue
+ ( uno::Any & rConvertedValue,
+ uno::Any & rOldValue,
+ sal_Int32 nHandle,
+ const uno::Any& rValue )
+ throw (lang::IllegalArgumentException)
+{
+ getFastPropertyValue( rOldValue, nHandle );
+
+ switch( nHandle )
+ {
+ case PROP_SERIES_DATA_CAPTION:
+ {
+ sal_Int32 nCaptionStyle;
+ if( rValue >>= nCaptionStyle )
+ {
+ chart2::DataPointLabel aConvertedLabel;
+
+ if( nCaptionStyle & ::com::sun::star::chart::ChartDataCaption::VALUE )
+ aConvertedLabel.ShowNumber = true;
+ if( nCaptionStyle & ::com::sun::star::chart::ChartDataCaption::PERCENT )
+ aConvertedLabel.ShowNumberInPercent = true;
+ if( nCaptionStyle & ::com::sun::star::chart::ChartDataCaption::TEXT )
+ aConvertedLabel.ShowCategoryName = true;
+ if( nCaptionStyle & ::com::sun::star::chart::ChartDataCaption::SYMBOL )
+ aConvertedLabel.ShowLegendSymbol = true;
+
+ rConvertedValue <<= aConvertedLabel;
+ }
+ else
+ return sal_False;
+ }
+ break;
+
+ default:
+ rConvertedValue = rValue;
+ break;
+ }
+
+ return sal_True;
+}
+
+void SAL_CALL DataSeriesPointWrapper::getFastPropertyValue
+ ( uno::Any& rValue,
+ sal_Int32 nHandle ) const
+{
+ // /--
+ MutexGuard aGuard( GetMutex());
+ if( ! m_xParentProperties.is())
+ return;
+
+ lcl_PropertyMapType & rMap( lcl_GetPropertyMapFilled());
+ lcl_PropertyMapType::const_iterator aIt( rMap.find( nHandle ));
+ if( aIt == rMap.end())
+ {
+ OPropertySet::getFastPropertyValue( rValue, nHandle );
+ }
+ else
+ {
+ rValue = m_xParentProperties->getPropertyValue( (*aIt).second );
+ }
+ // \--
+}
+
+void SAL_CALL DataSeriesPointWrapper::setFastPropertyValue_NoBroadcast(
+ sal_Int32 nHandle, const uno::Any& rValue )
+ throw (uno::Exception)
+{
+ if( m_xParentProperties.is())
+ {
+ // /--
+ MutexGuard aGuard( GetMutex());
+
+ lcl_PropertyMapType & rMap( lcl_GetPropertyMapFilled());
+ lcl_PropertyMapType::const_iterator aIt( rMap.find( nHandle ));
+
+ if( aIt != rMap.end())
+ {
+ // found in map
+ m_xParentProperties->setPropertyValue( (*aIt).second, rValue );
+ }
+ else
+ {
+ // try same handle for FastPropertySet. Caution! Works for global
+ // properties like FillProperties, LineProperties and
+ // CharacterProperties
+ if( m_xParentFastProperties.is() && nHandle > FAST_PROPERTY_ID_START )
+ m_xParentFastProperties->setFastPropertyValue( nHandle, rValue );
+ else
+ {
+ // get name for property handle
+ try
+ {
+ ::rtl::OUString aPropName;
+ getInfoHelper().fillPropertyMembersByHandle( & aPropName, NULL, nHandle );
+ m_xParentProperties->setPropertyValue( aPropName, rValue );
+ }
+ catch( beans::UnknownPropertyException ex )
+ {
+ OPropertySet::setFastPropertyValue_NoBroadcast( nHandle, rValue );
+ }
+ }
+
+ if( nHandle == FillProperties::PROP_FILL_TRANSPARENCE )
+ {
+ m_xParentProperties->setPropertyValue(
+ C2U( "TransparencyStyle" ),
+ uno::makeAny( chart2::TransparencyStyle_LINEAR ));
+ }
+ }
+ // \--
+ }
+ else
+ OPropertySet::setFastPropertyValue_NoBroadcast( nHandle, rValue );
+}
+
+// --------------------------------------------------------------------------------
+
+// ____ OPropertySet ____
+uno::Any DataSeriesPointWrapper::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 );
+ LineProperties::AddDefaultsToMap(
+ aStaticDefaults,
+ /* bIncludeStyleProperties = */ false );
+ FillProperties::AddDefaultsToMap(
+ aStaticDefaults,
+ /* bIncludeStyleProperties = */ false );
+ CharacterProperties::AddDefaultsToMap(
+ aStaticDefaults,
+ /* bIncludeStyleProperties = */ false );
+ }
+
+ helper::tPropertyValueMap::const_iterator aFound(
+ aStaticDefaults.find( nHandle ));
+
+ if( aFound == aStaticDefaults.end())
+ return uno::Any();
+
+ return (*aFound).second;
+ // \--
+}
+
+::cppu::IPropertyArrayHelper & SAL_CALL DataSeriesPointWrapper::getInfoHelper()
+{
+ return lcl_getInfoHelper();
+}
+
+
+// ____ XPropertySet ____
+uno::Reference< beans::XPropertySetInfo > SAL_CALL
+ DataSeriesPointWrapper::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 > DataSeriesPointWrapper::getSupportedServiceNames_Static()
+{
+ uno::Sequence< ::rtl::OUString > aServices( 7 );
+ aServices[ 0 ] = C2U( "com.sun.star.chart.ChartDataRowProperties" );
+ aServices[ 1 ] = C2U( "com.sun.star.chart.ChartDataPointProperties" );
+ aServices[ 2 ] = C2U( "com.sun.star.xml.UserDefinedAttributeSupplier" );
+ aServices[ 3 ] = C2U( "com.sun.star.beans.PropertySet" );
+ aServices[ 4 ] = C2U( "com.sun.star.drawing.FillProperties" );
+ aServices[ 5 ] = C2U( "com.sun.star.drawing.LineProperties" );
+ aServices[ 6 ] = C2U( "com.sun.star.drawing.CharacterProperties" );
+
+ return aServices;
+}
+
+// ================================================================================
+
+// implement XServiceInfo methods basing upon getSupportedServiceNames_Static
+APPHELPER_XSERVICEINFO_IMPL( DataSeriesPointWrapper, lcl_aServiceName );
+
+// needed by MSC compiler
+using impl::DataSeriesPointWrapper_Base;
+
+IMPLEMENT_FORWARD_XINTERFACE2( DataSeriesPointWrapper, DataSeriesPointWrapper_Base, OPropertySet )
+IMPLEMENT_FORWARD_XTYPEPROVIDER2( DataSeriesPointWrapper, DataSeriesPointWrapper_Base, OPropertySet )
+
+} // namespace wrapper
+} // namespace chart