Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "StockBar.hxx"
21 : #include "LinePropertiesHelper.hxx"
22 : #include "FillProperties.hxx"
23 : #include "UserDefinedProperties.hxx"
24 : #include "PropertyHelper.hxx"
25 : #include "macros.hxx"
26 : #include "ContainerHelper.hxx"
27 : #include "ModifyListenerHelper.hxx"
28 : #include <com/sun/star/beans/PropertyAttribute.hpp>
29 : #include <com/sun/star/style/XStyle.hpp>
30 : #include <com/sun/star/beans/XPropertySet.hpp>
31 : #include <com/sun/star/uno/Sequence.hxx>
32 :
33 : #include <algorithm>
34 :
35 : using namespace ::com::sun::star;
36 :
37 : using ::com::sun::star::uno::Reference;
38 : using ::com::sun::star::beans::Property;
39 : using ::osl::MutexGuard;
40 :
41 : namespace
42 : {
43 :
44 : struct StaticStockBarInfoHelper_Initializer
45 : {
46 2 : ::cppu::OPropertyArrayHelper* operator()()
47 : {
48 2 : static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
49 2 : return &aPropHelper;
50 : }
51 :
52 : private:
53 2 : static uno::Sequence< Property > lcl_GetPropertySequence()
54 : {
55 2 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
56 2 : ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
57 2 : ::chart::FillProperties::AddPropertiesToVector( aProperties );
58 2 : ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
59 :
60 : ::std::sort( aProperties.begin(), aProperties.end(),
61 2 : ::chart::PropertyNameLess() );
62 :
63 2 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
64 : }
65 :
66 : };
67 :
68 : struct StaticStockBarInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticStockBarInfoHelper_Initializer >
69 : {
70 : };
71 :
72 : struct StaticStockBarInfo_Initializer
73 : {
74 1 : uno::Reference< beans::XPropertySetInfo >* operator()()
75 : {
76 : static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
77 1 : ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticStockBarInfoHelper::get() ) );
78 1 : return &xPropertySetInfo;
79 : }
80 : };
81 :
82 : struct StaticStockBarInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticStockBarInfo_Initializer >
83 : {
84 : };
85 :
86 : struct StaticStockBarDefaults_Initializer
87 : {
88 3 : ::chart::tPropertyValueMap* operator()()
89 : {
90 3 : static ::chart::tPropertyValueMap aStaticDefaults;
91 3 : lcl_AddDefaultsToMap( aStaticDefaults );
92 3 : return &aStaticDefaults;
93 : }
94 : private:
95 3 : static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
96 : {
97 3 : ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap );
98 3 : ::chart::FillProperties::AddDefaultsToMap( rOutMap );
99 :
100 : // override other defaults
101 3 : ::chart::PropertyHelper::setPropertyValue< sal_Int32 >( rOutMap, ::chart::FillProperties::PROP_FILL_COLOR, 0xffffff ); // white
102 3 : }
103 : };
104 :
105 : struct StaticStockBarDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticStockBarDefaults_Initializer >
106 : {
107 : };
108 :
109 : } // anonymous namespace
110 :
111 : namespace chart
112 : {
113 :
114 42 : StockBar::StockBar( bool bRisingCourse ) :
115 : ::property::OPropertySet( m_aMutex ),
116 : m_bRisingCourse( bRisingCourse ),
117 42 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
118 : {
119 42 : if( ! m_bRisingCourse )
120 : {
121 : setFastPropertyValue_NoBroadcast(
122 : ::chart::FillProperties::PROP_FILL_COLOR,
123 21 : uno::makeAny( sal_Int32( 0x000000 ))); // black
124 : setFastPropertyValue_NoBroadcast(
125 : ::chart::LinePropertiesHelper::PROP_LINE_COLOR,
126 21 : uno::makeAny( sal_Int32( 0xb3b3b3 ))); // gray30
127 : }
128 42 : }
129 :
130 0 : StockBar::StockBar( const StockBar & rOther ) :
131 : MutexContainer(),
132 : impl::StockBar_Base(),
133 : ::property::OPropertySet( rOther, m_aMutex ),
134 : m_bRisingCourse( rOther.m_bRisingCourse ),
135 0 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
136 0 : {}
137 :
138 84 : StockBar::~StockBar()
139 84 : {}
140 :
141 : // ____ XCloneable ____
142 0 : uno::Reference< util::XCloneable > SAL_CALL StockBar::createClone()
143 : throw (uno::RuntimeException, std::exception)
144 : {
145 0 : return uno::Reference< util::XCloneable >( new StockBar( *this ));
146 : }
147 :
148 : // ____ OPropertySet ____
149 925 : uno::Any StockBar::GetDefaultValue( sal_Int32 nHandle ) const
150 : throw(beans::UnknownPropertyException)
151 : {
152 925 : const tPropertyValueMap& rStaticDefaults = *StaticStockBarDefaults::get();
153 925 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
154 925 : if( aFound == rStaticDefaults.end() )
155 264 : return uno::Any();
156 661 : return (*aFound).second;
157 : }
158 :
159 2026 : ::cppu::IPropertyArrayHelper & SAL_CALL StockBar::getInfoHelper()
160 : {
161 2026 : return *StaticStockBarInfoHelper::get();
162 : }
163 :
164 : // ____ XPropertySet ____
165 4 : Reference< beans::XPropertySetInfo > SAL_CALL StockBar::getPropertySetInfo()
166 : throw (uno::RuntimeException, std::exception)
167 : {
168 4 : return *StaticStockBarInfo::get();
169 : }
170 :
171 : // ____ XModifyBroadcaster ____
172 84 : void SAL_CALL StockBar::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
173 : throw (uno::RuntimeException, std::exception)
174 : {
175 : try
176 : {
177 84 : uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
178 84 : xBroadcaster->addModifyListener( aListener );
179 : }
180 0 : catch( const uno::Exception & ex )
181 : {
182 : ASSERT_EXCEPTION( ex );
183 : }
184 84 : }
185 :
186 42 : void SAL_CALL StockBar::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
187 : throw (uno::RuntimeException, std::exception)
188 : {
189 : try
190 : {
191 42 : uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
192 42 : xBroadcaster->removeModifyListener( aListener );
193 : }
194 0 : catch( const uno::Exception & ex )
195 : {
196 : ASSERT_EXCEPTION( ex );
197 : }
198 42 : }
199 :
200 : // ____ XModifyListener ____
201 0 : void SAL_CALL StockBar::modified( const lang::EventObject& aEvent )
202 : throw (uno::RuntimeException, std::exception)
203 : {
204 0 : m_xModifyEventForwarder->modified( aEvent );
205 0 : }
206 :
207 : // ____ XEventListener (base of XModifyListener) ____
208 0 : void SAL_CALL StockBar::disposing( const lang::EventObject& /* Source */ )
209 : throw (uno::RuntimeException, std::exception)
210 : {
211 : // nothing
212 0 : }
213 :
214 : // ____ OPropertySet ____
215 8 : void StockBar::firePropertyChangeEvent()
216 : {
217 8 : fireModifyEvent();
218 8 : }
219 :
220 8 : void StockBar::fireModifyEvent()
221 : {
222 8 : m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
223 8 : }
224 :
225 : using impl::StockBar_Base;
226 :
227 4174 : IMPLEMENT_FORWARD_XINTERFACE2( StockBar, StockBar_Base, ::property::OPropertySet )
228 :
229 : } // namespace chart
230 :
231 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|