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: StockBar.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 "StockBar.hxx"
35 #include "LineProperties.hxx"
36 #include "FillProperties.hxx"
37 #include "UserDefinedProperties.hxx"
38 #include "PropertyHelper.hxx"
40 #include "ContainerHelper.hxx"
41 #include "ModifyListenerHelper.hxx"
42 #include <com/sun/star/beans/PropertyAttribute.hpp>
43 #include <com/sun/star/style/XStyle.hpp>
44 #include <com/sun/star/beans/XPropertySet.hpp>
45 #include <com/sun/star/uno/Sequence.hxx>
49 using namespace ::com::sun::star
;
51 using ::com::sun::star::uno::Reference
;
52 using ::com::sun::star::beans::Property
;
53 using ::osl::MutexGuard
;
55 // ____________________________________________________________
60 static const ::rtl::OUString
lcl_aServiceName(
61 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.StockBar" ));
63 const uno::Sequence
< Property
> & lcl_GetPropertySequence()
65 static uno::Sequence
< Property
> aPropSeq
;
68 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
69 if( 0 == aPropSeq
.getLength() )
72 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
73 ::chart::LineProperties::AddPropertiesToVector( aProperties
);
74 ::chart::FillProperties::AddPropertiesToVector( aProperties
);
75 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
77 // and sort them for access via bsearch
78 ::std::sort( aProperties
.begin(), aProperties
.end(),
79 ::chart::PropertyNameLess() );
81 // transfer result to static Sequence
82 aPropSeq
= ::chart::ContainerHelper::ContainerToSequence( aProperties
);
88 void lcl_AddDefaultsToMap(
89 ::chart::tPropertyValueMap
& rOutMap
)
91 // override other defaults
92 ::chart::PropertyHelper::setPropertyValue
< sal_Int32
>( rOutMap
, ::chart::FillProperties::PROP_FILL_COLOR
, 0xffffff ); // white
95 ::cppu::IPropertyArrayHelper
& lcl_getInfoHelper()
97 static ::cppu::OPropertyArrayHelper
aArrayHelper(
98 lcl_GetPropertySequence(),
99 /* bSorted = */ sal_True
);
104 } // anonymous namespace
106 // ____________________________________________________________
111 StockBar::StockBar( bool bRisingCourse
) :
112 ::property::OPropertySet( m_aMutex
),
113 m_bRisingCourse( bRisingCourse
),
114 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
116 if( ! m_bRisingCourse
)
118 setFastPropertyValue_NoBroadcast(
119 ::chart::FillProperties::PROP_FILL_COLOR
,
120 uno::makeAny( sal_Int32( 0x000000 ))); // black
121 setFastPropertyValue_NoBroadcast(
122 ::chart::LineProperties::PROP_LINE_COLOR
,
123 uno::makeAny( sal_Int32( 0xb3b3b3 ))); // gray30
127 StockBar::StockBar( const StockBar
& rOther
) :
129 impl::StockBar_Base(),
130 ::property::OPropertySet( rOther
, m_aMutex
),
131 m_bRisingCourse( rOther
.m_bRisingCourse
),
132 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
135 StockBar::~StockBar()
139 // ____ XCloneable ____
140 uno::Reference
< util::XCloneable
> SAL_CALL
StockBar::createClone()
141 throw (uno::RuntimeException
)
143 return uno::Reference
< util::XCloneable
>( new StockBar( *this ));
146 // ____ OPropertySet ____
147 uno::Any
StockBar::GetDefaultValue( sal_Int32 nHandle
) const
148 throw(beans::UnknownPropertyException
)
150 static tPropertyValueMap aStaticDefaults
;
153 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
154 if( 0 == aStaticDefaults
.size() )
156 // initialize defaults
157 LineProperties::AddDefaultsToMap( aStaticDefaults
);
158 FillProperties::AddDefaultsToMap( aStaticDefaults
);
160 // overrides a line property
161 lcl_AddDefaultsToMap( aStaticDefaults
);
164 tPropertyValueMap::const_iterator
aFound(
165 aStaticDefaults
.find( nHandle
));
167 if( aFound
== aStaticDefaults
.end())
170 return (*aFound
).second
;
174 ::cppu::IPropertyArrayHelper
& SAL_CALL
StockBar::getInfoHelper()
176 return lcl_getInfoHelper();
179 // ____ XPropertySet ____
180 Reference
< beans::XPropertySetInfo
> SAL_CALL
181 StockBar::getPropertySetInfo()
182 throw (uno::RuntimeException
)
184 static Reference
< beans::XPropertySetInfo
> xInfo
;
187 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
190 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
191 lcl_getInfoHelper());
199 // ____ XModifyBroadcaster ____
200 void SAL_CALL
StockBar::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
201 throw (uno::RuntimeException
)
205 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
206 xBroadcaster
->addModifyListener( aListener
);
208 catch( const uno::Exception
& ex
)
210 ASSERT_EXCEPTION( ex
);
214 void SAL_CALL
StockBar::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
215 throw (uno::RuntimeException
)
219 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
220 xBroadcaster
->removeModifyListener( aListener
);
222 catch( const uno::Exception
& ex
)
224 ASSERT_EXCEPTION( ex
);
228 // ____ XModifyListener ____
229 void SAL_CALL
StockBar::modified( const lang::EventObject
& aEvent
)
230 throw (uno::RuntimeException
)
232 m_xModifyEventForwarder
->modified( aEvent
);
235 // ____ XEventListener (base of XModifyListener) ____
236 void SAL_CALL
StockBar::disposing( const lang::EventObject
& /* Source */ )
237 throw (uno::RuntimeException
)
242 // ____ OPropertySet ____
243 void StockBar::firePropertyChangeEvent()
248 void StockBar::fireModifyEvent()
250 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
253 // ================================================================================
255 uno::Sequence
< ::rtl::OUString
> StockBar::getSupportedServiceNames_Static()
257 uno::Sequence
< ::rtl::OUString
> aServices( 2 );
258 aServices
[ 0 ] = C2U( "com.sun.star.chart2.StockBar" );
259 aServices
[ 1 ] = C2U( "com.sun.star.beans.PropertySet" );
263 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
264 APPHELPER_XSERVICEINFO_IMPL( StockBar
, lcl_aServiceName
);
266 using impl::StockBar_Base
;
268 IMPLEMENT_FORWARD_XINTERFACE2( StockBar
, StockBar_Base
, ::property::OPropertySet
)