1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <StockBar.hxx>
21 #include <LinePropertiesHelper.hxx>
22 #include <FillProperties.hxx>
23 #include <UserDefinedProperties.hxx>
24 #include <PropertyHelper.hxx>
25 #include <ModifyListenerHelper.hxx>
26 #include <com/sun/star/uno/Sequence.hxx>
27 #include <tools/diagnose_ex.h>
31 namespace com::sun::star::beans
{ class XPropertySetInfo
; }
33 using namespace ::com::sun::star
;
35 using ::com::sun::star::uno::Reference
;
36 using ::com::sun::star::beans::Property
;
41 struct StaticStockBarInfoHelper_Initializer
43 ::cppu::OPropertyArrayHelper
* operator()()
45 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
50 static uno::Sequence
< Property
> lcl_GetPropertySequence()
52 std::vector
< css::beans::Property
> aProperties
;
53 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties
);
54 ::chart::FillProperties::AddPropertiesToVector( aProperties
);
55 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
57 std::sort( aProperties
.begin(), aProperties
.end(),
58 ::chart::PropertyNameLess() );
60 return comphelper::containerToSequence( aProperties
);
65 struct StaticStockBarInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticStockBarInfoHelper_Initializer
>
69 struct StaticStockBarInfo_Initializer
71 uno::Reference
< beans::XPropertySetInfo
>* operator()()
73 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
74 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticStockBarInfoHelper::get() ) );
75 return &xPropertySetInfo
;
79 struct StaticStockBarInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticStockBarInfo_Initializer
>
83 struct StaticStockBarDefaults_Initializer
85 ::chart::tPropertyValueMap
* operator()()
87 static ::chart::tPropertyValueMap aStaticDefaults
;
88 lcl_AddDefaultsToMap( aStaticDefaults
);
89 return &aStaticDefaults
;
92 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap
& rOutMap
)
94 ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap
);
95 ::chart::FillProperties::AddDefaultsToMap( rOutMap
);
97 // override other defaults
98 ::chart::PropertyHelper::setPropertyValue
< sal_Int32
>( rOutMap
, ::chart::FillProperties::PROP_FILL_COLOR
, 0xffffff ); // white
102 struct StaticStockBarDefaults
: public rtl::StaticAggregate
< ::chart::tPropertyValueMap
, StaticStockBarDefaults_Initializer
>
106 } // anonymous namespace
111 StockBar::StockBar( bool bRisingCourse
) :
112 ::property::OPropertySet( m_aMutex
),
113 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
115 if( ! bRisingCourse
)
117 setFastPropertyValue_NoBroadcast(
118 ::chart::FillProperties::PROP_FILL_COLOR
,
119 uno::Any( sal_Int32( 0x000000 ))); // black
120 setFastPropertyValue_NoBroadcast(
121 ::chart::LinePropertiesHelper::PROP_LINE_COLOR
,
122 uno::Any( sal_Int32( 0xb3b3b3 ))); // gray30
126 StockBar::StockBar( const StockBar
& rOther
) :
127 impl::StockBar_Base(rOther
),
128 ::property::OPropertySet( rOther
, m_aMutex
),
129 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
132 StockBar::~StockBar()
135 // ____ XCloneable ____
136 uno::Reference
< util::XCloneable
> SAL_CALL
StockBar::createClone()
138 return uno::Reference
< util::XCloneable
>( new StockBar( *this ));
141 // ____ OPropertySet ____
142 uno::Any
StockBar::GetDefaultValue( sal_Int32 nHandle
) const
144 const tPropertyValueMap
& rStaticDefaults
= *StaticStockBarDefaults::get();
145 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
146 if( aFound
== rStaticDefaults
.end() )
148 return (*aFound
).second
;
151 ::cppu::IPropertyArrayHelper
& SAL_CALL
StockBar::getInfoHelper()
153 return *StaticStockBarInfoHelper::get();
156 // ____ XPropertySet ____
157 Reference
< beans::XPropertySetInfo
> SAL_CALL
StockBar::getPropertySetInfo()
159 return *StaticStockBarInfo::get();
162 // ____ XModifyBroadcaster ____
163 void SAL_CALL
StockBar::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
167 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
168 xBroadcaster
->addModifyListener( aListener
);
170 catch( const uno::Exception
& )
172 DBG_UNHANDLED_EXCEPTION("chart2");
176 void SAL_CALL
StockBar::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
180 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
181 xBroadcaster
->removeModifyListener( aListener
);
183 catch( const uno::Exception
& )
185 DBG_UNHANDLED_EXCEPTION("chart2");
189 // ____ XModifyListener ____
190 void SAL_CALL
StockBar::modified( const lang::EventObject
& aEvent
)
192 m_xModifyEventForwarder
->modified( aEvent
);
195 // ____ XEventListener (base of XModifyListener) ____
196 void SAL_CALL
StockBar::disposing( const lang::EventObject
& /* Source */ )
201 // ____ OPropertySet ____
202 void StockBar::firePropertyChangeEvent()
204 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
207 using impl::StockBar_Base
;
209 IMPLEMENT_FORWARD_XINTERFACE2( StockBar
, StockBar_Base
, ::property::OPropertySet
)
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */