1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 
31 #include "StockBar.hxx"
32 #include "LineProperties.hxx"
33 #include "FillProperties.hxx"
34 #include "UserDefinedProperties.hxx"
35 #include "PropertyHelper.hxx"
36 #include "macros.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>
43 
44 #include <algorithm>
45 
46 using namespace ::com::sun::star;
47 
48 using ::com::sun::star::uno::Reference;
49 using ::com::sun::star::beans::Property;
50 using ::osl::MutexGuard;
51 
52 // ____________________________________________________________
53 
54 namespace
55 {
56 
57 static const ::rtl::OUString lcl_aServiceName(
58     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.StockBar" ));
59 
60 struct StaticStockBarInfoHelper_Initializer
61 {
62     ::cppu::OPropertyArrayHelper* operator()()
63     {
64         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
65         return &aPropHelper;
66     }
67 
68 private:
69     uno::Sequence< Property > lcl_GetPropertySequence()
70     {
71         ::std::vector< ::com::sun::star::beans::Property > aProperties;
72         ::chart::LineProperties::AddPropertiesToVector( aProperties );
73         ::chart::FillProperties::AddPropertiesToVector( aProperties );
74         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
75 
76         ::std::sort( aProperties.begin(), aProperties.end(),
77                      ::chart::PropertyNameLess() );
78 
79         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
80     }
81 
82 };
83 
84 struct StaticStockBarInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticStockBarInfoHelper_Initializer >
85 {
86 };
87 
88 struct StaticStockBarInfo_Initializer
89 {
90     uno::Reference< beans::XPropertySetInfo >* operator()()
91     {
92         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
93             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticStockBarInfoHelper::get() ) );
94         return &xPropertySetInfo;
95     }
96 };
97 
98 struct StaticStockBarInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticStockBarInfo_Initializer >
99 {
100 };
101 
102 struct StaticStockBarDefaults_Initializer
103 {
104     ::chart::tPropertyValueMap* operator()()
105     {
106         static ::chart::tPropertyValueMap aStaticDefaults;
107         lcl_AddDefaultsToMap( aStaticDefaults );
108         return &aStaticDefaults;
109     }
110 private:
111     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
112     {
113         ::chart::LineProperties::AddDefaultsToMap( rOutMap );
114         ::chart::FillProperties::AddDefaultsToMap( rOutMap );
115 
116         // override other defaults
117         ::chart::PropertyHelper::setPropertyValue< sal_Int32 >( rOutMap, ::chart::FillProperties::PROP_FILL_COLOR, 0xffffff ); // white
118     }
119 };
120 
121 struct StaticStockBarDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticStockBarDefaults_Initializer >
122 {
123 };
124 
125 } // anonymous namespace
126 
127 // ____________________________________________________________
128 
129 namespace chart
130 {
131 
132 StockBar::StockBar( bool bRisingCourse ) :
133         ::property::OPropertySet( m_aMutex ),
134     m_bRisingCourse( bRisingCourse ),
135     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
136 {
137     if( ! m_bRisingCourse )
138     {
139         setFastPropertyValue_NoBroadcast(
140             ::chart::FillProperties::PROP_FILL_COLOR,
141             uno::makeAny( sal_Int32( 0x000000 ))); // black
142         setFastPropertyValue_NoBroadcast(
143             ::chart::LineProperties::PROP_LINE_COLOR,
144             uno::makeAny( sal_Int32( 0xb3b3b3 ))); // gray30
145     }
146 }
147 
148 StockBar::StockBar( const StockBar & rOther ) :
149         MutexContainer(),
150         impl::StockBar_Base(),
151         ::property::OPropertySet( rOther, m_aMutex ),
152     m_bRisingCourse( rOther.m_bRisingCourse ),
153     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
154 {}
155 
156 StockBar::~StockBar()
157 {}
158 
159 
160 // ____ XCloneable ____
161 uno::Reference< util::XCloneable > SAL_CALL StockBar::createClone()
162     throw (uno::RuntimeException)
163 {
164     return uno::Reference< util::XCloneable >( new StockBar( *this ));
165 }
166 
167 // ____ OPropertySet ____
168 uno::Any StockBar::GetDefaultValue( sal_Int32 nHandle ) const
169     throw(beans::UnknownPropertyException)
170 {
171     const tPropertyValueMap& rStaticDefaults = *StaticStockBarDefaults::get();
172     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
173     if( aFound == rStaticDefaults.end() )
174         return uno::Any();
175     return (*aFound).second;
176 }
177 
178 ::cppu::IPropertyArrayHelper & SAL_CALL StockBar::getInfoHelper()
179 {
180     return *StaticStockBarInfoHelper::get();
181 }
182 
183 // ____ XPropertySet ____
184 Reference< beans::XPropertySetInfo > SAL_CALL StockBar::getPropertySetInfo()
185     throw (uno::RuntimeException)
186 {
187     return *StaticStockBarInfo::get();
188 }
189 
190 // ____ XModifyBroadcaster ____
191 void SAL_CALL StockBar::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
192     throw (uno::RuntimeException)
193 {
194     try
195     {
196         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
197         xBroadcaster->addModifyListener( aListener );
198     }
199     catch( const uno::Exception & ex )
200     {
201         ASSERT_EXCEPTION( ex );
202     }
203 }
204 
205 void SAL_CALL StockBar::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
206     throw (uno::RuntimeException)
207 {
208     try
209     {
210         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
211         xBroadcaster->removeModifyListener( aListener );
212     }
213     catch( const uno::Exception & ex )
214     {
215         ASSERT_EXCEPTION( ex );
216     }
217 }
218 
219 // ____ XModifyListener ____
220 void SAL_CALL StockBar::modified( const lang::EventObject& aEvent )
221     throw (uno::RuntimeException)
222 {
223     m_xModifyEventForwarder->modified( aEvent );
224 }
225 
226 // ____ XEventListener (base of XModifyListener) ____
227 void SAL_CALL StockBar::disposing( const lang::EventObject& /* Source */ )
228     throw (uno::RuntimeException)
229 {
230     // nothing
231 }
232 
233 // ____ OPropertySet ____
234 void StockBar::firePropertyChangeEvent()
235 {
236     fireModifyEvent();
237 }
238 
239 void StockBar::fireModifyEvent()
240 {
241     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
242 }
243 
244 // ================================================================================
245 
246 uno::Sequence< ::rtl::OUString > StockBar::getSupportedServiceNames_Static()
247 {
248     uno::Sequence< ::rtl::OUString > aServices( 2 );
249     aServices[ 0 ] = C2U( "com.sun.star.chart2.StockBar" );
250     aServices[ 1 ] = C2U( "com.sun.star.beans.PropertySet" );
251     return aServices;
252 }
253 
254 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
255 APPHELPER_XSERVICEINFO_IMPL( StockBar, lcl_aServiceName );
256 
257 using impl::StockBar_Base;
258 
259 IMPLEMENT_FORWARD_XINTERFACE2( StockBar, StockBar_Base, ::property::OPropertySet )
260 
261 } //  namespace chart
262