merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / model / main / PageBackground.cxx
blob0dbe1d82fcf337938f280369ff622d77883a3181
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"
30 #include "PageBackground.hxx"
31 #include "macros.hxx"
32 #include "LineProperties.hxx"
33 #include "FillProperties.hxx"
34 #include "UserDefinedProperties.hxx"
35 #include "ContainerHelper.hxx"
36 #include "PropertyHelper.hxx"
38 #include <com/sun/star/drawing/LineStyle.hpp>
39 #include <rtl/uuid.h>
40 #include <cppuhelper/queryinterface.hxx>
42 #include <vector>
43 #include <algorithm>
45 using namespace ::com::sun::star;
47 using ::com::sun::star::beans::Property;
48 using ::osl::MutexGuard;
50 namespace
53 static const ::rtl::OUString lcl_aServiceName(
54 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.PageBackground" ));
56 void lcl_AddDefaultsToMap(
57 ::chart::tPropertyValueMap & rOutMap )
59 // override other defaults
60 ::chart::PropertyHelper::setPropertyValue< sal_Int32 >( rOutMap, ::chart::FillProperties::PROP_FILL_COLOR, 0xffffff );
61 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::LineProperties::PROP_LINE_STYLE, drawing::LineStyle_NONE );
64 const uno::Sequence< Property > & lcl_GetPropertySequence()
66 static uno::Sequence< Property > aPropSeq;
68 // /--
69 MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
70 if( 0 == aPropSeq.getLength() )
72 // get properties
73 ::std::vector< ::com::sun::star::beans::Property > aProperties;
74 ::chart::LineProperties::AddPropertiesToVector( aProperties );
75 ::chart::FillProperties::AddPropertiesToVector( aProperties );
76 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
78 // and sort them for access via bsearch
79 ::std::sort( aProperties.begin(), aProperties.end(),
80 ::chart::PropertyNameLess() );
82 // transfer result to static Sequence
83 aPropSeq = ::chart::ContainerHelper::ContainerToSequence( aProperties );
86 return aPropSeq;
89 ::cppu::IPropertyArrayHelper & lcl_getInfoHelper()
91 static ::cppu::OPropertyArrayHelper aArrayHelper(
92 lcl_GetPropertySequence(),
93 /* bSorted = */ sal_True );
95 return aArrayHelper;
98 } // anonymous namespace
100 // ================================================================================
102 namespace chart
105 PageBackground::PageBackground( const uno::Reference< uno::XComponentContext > & xContext ) :
106 ::property::OPropertySet( m_aMutex ),
107 m_xContext( xContext ),
108 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
111 PageBackground::PageBackground( const PageBackground & rOther ) :
112 MutexContainer(),
113 impl::PageBackground_Base(),
114 ::property::OPropertySet( rOther, m_aMutex ),
115 m_xContext( rOther.m_xContext ),
116 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
119 PageBackground::~PageBackground()
122 // ____ XCloneable ____
123 uno::Reference< util::XCloneable > SAL_CALL PageBackground::createClone()
124 throw (uno::RuntimeException)
126 return uno::Reference< util::XCloneable >( new PageBackground( *this ));
129 // ================================================================================
131 // ____ OPropertySet ____
132 uno::Any PageBackground::GetDefaultValue( sal_Int32 nHandle ) const
133 throw(beans::UnknownPropertyException)
135 static tPropertyValueMap aStaticDefaults;
137 // /--
138 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
139 if( 0 == aStaticDefaults.size() )
141 // initialize defaults
142 LineProperties::AddDefaultsToMap( aStaticDefaults );
143 FillProperties::AddDefaultsToMap( aStaticDefaults );
144 // overrides defaults of FillProperties
145 lcl_AddDefaultsToMap( aStaticDefaults );
148 tPropertyValueMap::const_iterator aFound(
149 aStaticDefaults.find( nHandle ));
151 if( aFound == aStaticDefaults.end())
152 return uno::Any();
154 return (*aFound).second;
155 // \--
158 ::cppu::IPropertyArrayHelper & SAL_CALL PageBackground::getInfoHelper()
160 return lcl_getInfoHelper();
164 // ____ XPropertySet ____
165 uno::Reference< beans::XPropertySetInfo > SAL_CALL
166 PageBackground::getPropertySetInfo()
167 throw (uno::RuntimeException)
169 static uno::Reference< beans::XPropertySetInfo > xInfo;
171 // /--
172 MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
173 if( !xInfo.is())
175 xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo(
176 getInfoHelper());
179 return xInfo;
180 // \--
184 // ____ XModifyBroadcaster ____
185 void SAL_CALL PageBackground::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
186 throw (uno::RuntimeException)
190 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
191 xBroadcaster->addModifyListener( aListener );
193 catch( const uno::Exception & ex )
195 ASSERT_EXCEPTION( ex );
199 void SAL_CALL PageBackground::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
200 throw (uno::RuntimeException)
204 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
205 xBroadcaster->removeModifyListener( aListener );
207 catch( const uno::Exception & ex )
209 ASSERT_EXCEPTION( ex );
213 // ____ XModifyListener ____
214 void SAL_CALL PageBackground::modified( const lang::EventObject& aEvent )
215 throw (uno::RuntimeException)
217 m_xModifyEventForwarder->modified( aEvent );
220 // ____ XEventListener (base of XModifyListener) ____
221 void SAL_CALL PageBackground::disposing( const lang::EventObject& /* Source */ )
222 throw (uno::RuntimeException)
224 // nothing
227 // ____ OPropertySet ____
228 void PageBackground::firePropertyChangeEvent()
230 fireModifyEvent();
233 void PageBackground::fireModifyEvent()
235 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
238 // ================================================================================
240 uno::Sequence< ::rtl::OUString > PageBackground::getSupportedServiceNames_Static()
242 uno::Sequence< ::rtl::OUString > aServices( 2 );
243 aServices[ 0 ] = C2U( "com.sun.star.chart2.PageBackground" );
244 aServices[ 1 ] = C2U( "com.sun.star.beans.PropertySet" );
245 return aServices;
248 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
249 APPHELPER_XSERVICEINFO_IMPL( PageBackground, lcl_aServiceName );
251 using impl::PageBackground_Base;
253 IMPLEMENT_FORWARD_XINTERFACE2( PageBackground, PageBackground_Base, ::property::OPropertySet )
255 } // namespace chart