1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
31 #include "StockBar.hxx"
32 #include "LineProperties.hxx"
33 #include "FillProperties.hxx"
34 #include "UserDefinedProperties.hxx"
35 #include "PropertyHelper.hxx"
37 #include "ContainerHelper.hxx"
38 #include "ModifyListenerHelper.hxx"
39 #include <com/sun/star/beans/PropertyAttribute.hpp>
40 #include <com/sun/star/style/XStyle.hpp>
41 #include <com/sun/star/beans/XPropertySet.hpp>
42 #include <com/sun/star/uno/Sequence.hxx>
46 using namespace ::com::sun::star
;
48 using ::com::sun::star::uno::Reference
;
49 using ::com::sun::star::beans::Property
;
50 using ::osl::MutexGuard
;
52 // ____________________________________________________________
57 static const ::rtl::OUString
lcl_aServiceName(
58 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.StockBar" ));
60 const uno::Sequence
< Property
> & lcl_GetPropertySequence()
62 static uno::Sequence
< Property
> aPropSeq
;
65 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
66 if( 0 == aPropSeq
.getLength() )
69 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
70 ::chart::LineProperties::AddPropertiesToVector( aProperties
);
71 ::chart::FillProperties::AddPropertiesToVector( aProperties
);
72 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
74 // and sort them for access via bsearch
75 ::std::sort( aProperties
.begin(), aProperties
.end(),
76 ::chart::PropertyNameLess() );
78 // transfer result to static Sequence
79 aPropSeq
= ::chart::ContainerHelper::ContainerToSequence( aProperties
);
85 void lcl_AddDefaultsToMap(
86 ::chart::tPropertyValueMap
& rOutMap
)
88 // override other defaults
89 ::chart::PropertyHelper::setPropertyValue
< sal_Int32
>( rOutMap
, ::chart::FillProperties::PROP_FILL_COLOR
, 0xffffff ); // white
92 ::cppu::IPropertyArrayHelper
& lcl_getInfoHelper()
94 static ::cppu::OPropertyArrayHelper
aArrayHelper(
95 lcl_GetPropertySequence(),
96 /* bSorted = */ sal_True
);
101 } // anonymous namespace
103 // ____________________________________________________________
108 StockBar::StockBar( bool bRisingCourse
) :
109 ::property::OPropertySet( m_aMutex
),
110 m_bRisingCourse( bRisingCourse
),
111 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
113 if( ! m_bRisingCourse
)
115 setFastPropertyValue_NoBroadcast(
116 ::chart::FillProperties::PROP_FILL_COLOR
,
117 uno::makeAny( sal_Int32( 0x000000 ))); // black
118 setFastPropertyValue_NoBroadcast(
119 ::chart::LineProperties::PROP_LINE_COLOR
,
120 uno::makeAny( sal_Int32( 0xb3b3b3 ))); // gray30
124 StockBar::StockBar( const StockBar
& rOther
) :
126 impl::StockBar_Base(),
127 ::property::OPropertySet( rOther
, m_aMutex
),
128 m_bRisingCourse( rOther
.m_bRisingCourse
),
129 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
132 StockBar::~StockBar()
136 // ____ XCloneable ____
137 uno::Reference
< util::XCloneable
> SAL_CALL
StockBar::createClone()
138 throw (uno::RuntimeException
)
140 return uno::Reference
< util::XCloneable
>( new StockBar( *this ));
143 // ____ OPropertySet ____
144 uno::Any
StockBar::GetDefaultValue( sal_Int32 nHandle
) const
145 throw(beans::UnknownPropertyException
)
147 static tPropertyValueMap aStaticDefaults
;
150 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
151 if( 0 == aStaticDefaults
.size() )
153 // initialize defaults
154 LineProperties::AddDefaultsToMap( aStaticDefaults
);
155 FillProperties::AddDefaultsToMap( aStaticDefaults
);
157 // overrides a line property
158 lcl_AddDefaultsToMap( aStaticDefaults
);
161 tPropertyValueMap::const_iterator
aFound(
162 aStaticDefaults
.find( nHandle
));
164 if( aFound
== aStaticDefaults
.end())
167 return (*aFound
).second
;
171 ::cppu::IPropertyArrayHelper
& SAL_CALL
StockBar::getInfoHelper()
173 return lcl_getInfoHelper();
176 // ____ XPropertySet ____
177 Reference
< beans::XPropertySetInfo
> SAL_CALL
178 StockBar::getPropertySetInfo()
179 throw (uno::RuntimeException
)
181 static Reference
< beans::XPropertySetInfo
> xInfo
;
184 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
187 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
188 lcl_getInfoHelper());
196 // ____ XModifyBroadcaster ____
197 void SAL_CALL
StockBar::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
198 throw (uno::RuntimeException
)
202 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
203 xBroadcaster
->addModifyListener( aListener
);
205 catch( const uno::Exception
& ex
)
207 ASSERT_EXCEPTION( ex
);
211 void SAL_CALL
StockBar::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
212 throw (uno::RuntimeException
)
216 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
217 xBroadcaster
->removeModifyListener( aListener
);
219 catch( const uno::Exception
& ex
)
221 ASSERT_EXCEPTION( ex
);
225 // ____ XModifyListener ____
226 void SAL_CALL
StockBar::modified( const lang::EventObject
& aEvent
)
227 throw (uno::RuntimeException
)
229 m_xModifyEventForwarder
->modified( aEvent
);
232 // ____ XEventListener (base of XModifyListener) ____
233 void SAL_CALL
StockBar::disposing( const lang::EventObject
& /* Source */ )
234 throw (uno::RuntimeException
)
239 // ____ OPropertySet ____
240 void StockBar::firePropertyChangeEvent()
245 void StockBar::fireModifyEvent()
247 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
250 // ================================================================================
252 uno::Sequence
< ::rtl::OUString
> StockBar::getSupportedServiceNames_Static()
254 uno::Sequence
< ::rtl::OUString
> aServices( 2 );
255 aServices
[ 0 ] = C2U( "com.sun.star.chart2.StockBar" );
256 aServices
[ 1 ] = C2U( "com.sun.star.beans.PropertySet" );
260 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
261 APPHELPER_XSERVICEINFO_IMPL( StockBar
, lcl_aServiceName
);
263 using impl::StockBar_Base
;
265 IMPLEMENT_FORWARD_XINTERFACE2( StockBar
, StockBar_Base
, ::property::OPropertySet
)