Update ooo320-m1
[ooovba.git] / chart2 / source / model / main / PageBackground.cxx
blob4a60e30f449aa1c045d37af73cc50b04fccc4e75
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PageBackground.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "PageBackground.hxx"
34 #include "macros.hxx"
35 #include "LineProperties.hxx"
36 #include "FillProperties.hxx"
37 #include "UserDefinedProperties.hxx"
38 #include "ContainerHelper.hxx"
39 #include "PropertyHelper.hxx"
41 #include <com/sun/star/drawing/LineStyle.hpp>
42 #include <rtl/uuid.h>
43 #include <cppuhelper/queryinterface.hxx>
45 #include <vector>
46 #include <algorithm>
48 using namespace ::com::sun::star;
50 using ::com::sun::star::beans::Property;
51 using ::osl::MutexGuard;
53 namespace
56 static const ::rtl::OUString lcl_aServiceName(
57 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.PageBackground" ));
59 void lcl_AddDefaultsToMap(
60 ::chart::tPropertyValueMap & rOutMap )
62 // override other defaults
63 ::chart::PropertyHelper::setPropertyValue< sal_Int32 >( rOutMap, ::chart::FillProperties::PROP_FILL_COLOR, 0xffffff );
64 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::LineProperties::PROP_LINE_STYLE, drawing::LineStyle_NONE );
67 const uno::Sequence< Property > & lcl_GetPropertySequence()
69 static uno::Sequence< Property > aPropSeq;
71 // /--
72 MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
73 if( 0 == aPropSeq.getLength() )
75 // get properties
76 ::std::vector< ::com::sun::star::beans::Property > aProperties;
77 ::chart::LineProperties::AddPropertiesToVector( aProperties );
78 ::chart::FillProperties::AddPropertiesToVector( aProperties );
79 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
81 // and sort them for access via bsearch
82 ::std::sort( aProperties.begin(), aProperties.end(),
83 ::chart::PropertyNameLess() );
85 // transfer result to static Sequence
86 aPropSeq = ::chart::ContainerHelper::ContainerToSequence( aProperties );
89 return aPropSeq;
92 ::cppu::IPropertyArrayHelper & lcl_getInfoHelper()
94 static ::cppu::OPropertyArrayHelper aArrayHelper(
95 lcl_GetPropertySequence(),
96 /* bSorted = */ sal_True );
98 return aArrayHelper;
101 } // anonymous namespace
103 // ================================================================================
105 namespace chart
108 PageBackground::PageBackground( const uno::Reference< uno::XComponentContext > & xContext ) :
109 ::property::OPropertySet( m_aMutex ),
110 m_xContext( xContext ),
111 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
114 PageBackground::PageBackground( const PageBackground & rOther ) :
115 MutexContainer(),
116 impl::PageBackground_Base(),
117 ::property::OPropertySet( rOther, m_aMutex ),
118 m_xContext( rOther.m_xContext ),
119 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
122 PageBackground::~PageBackground()
125 // ____ XCloneable ____
126 uno::Reference< util::XCloneable > SAL_CALL PageBackground::createClone()
127 throw (uno::RuntimeException)
129 return uno::Reference< util::XCloneable >( new PageBackground( *this ));
132 // ================================================================================
134 // ____ OPropertySet ____
135 uno::Any PageBackground::GetDefaultValue( sal_Int32 nHandle ) const
136 throw(beans::UnknownPropertyException)
138 static tPropertyValueMap aStaticDefaults;
140 // /--
141 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
142 if( 0 == aStaticDefaults.size() )
144 // initialize defaults
145 LineProperties::AddDefaultsToMap( aStaticDefaults );
146 FillProperties::AddDefaultsToMap( aStaticDefaults );
147 // overrides defaults of FillProperties
148 lcl_AddDefaultsToMap( aStaticDefaults );
151 tPropertyValueMap::const_iterator aFound(
152 aStaticDefaults.find( nHandle ));
154 if( aFound == aStaticDefaults.end())
155 return uno::Any();
157 return (*aFound).second;
158 // \--
161 ::cppu::IPropertyArrayHelper & SAL_CALL PageBackground::getInfoHelper()
163 return lcl_getInfoHelper();
167 // ____ XPropertySet ____
168 uno::Reference< beans::XPropertySetInfo > SAL_CALL
169 PageBackground::getPropertySetInfo()
170 throw (uno::RuntimeException)
172 static uno::Reference< beans::XPropertySetInfo > xInfo;
174 // /--
175 MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
176 if( !xInfo.is())
178 xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo(
179 getInfoHelper());
182 return xInfo;
183 // \--
187 // ____ XModifyBroadcaster ____
188 void SAL_CALL PageBackground::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
189 throw (uno::RuntimeException)
193 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
194 xBroadcaster->addModifyListener( aListener );
196 catch( const uno::Exception & ex )
198 ASSERT_EXCEPTION( ex );
202 void SAL_CALL PageBackground::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
203 throw (uno::RuntimeException)
207 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
208 xBroadcaster->removeModifyListener( aListener );
210 catch( const uno::Exception & ex )
212 ASSERT_EXCEPTION( ex );
216 // ____ XModifyListener ____
217 void SAL_CALL PageBackground::modified( const lang::EventObject& aEvent )
218 throw (uno::RuntimeException)
220 m_xModifyEventForwarder->modified( aEvent );
223 // ____ XEventListener (base of XModifyListener) ____
224 void SAL_CALL PageBackground::disposing( const lang::EventObject& /* Source */ )
225 throw (uno::RuntimeException)
227 // nothing
230 // ____ OPropertySet ____
231 void PageBackground::firePropertyChangeEvent()
233 fireModifyEvent();
236 void PageBackground::fireModifyEvent()
238 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
241 // ================================================================================
243 uno::Sequence< ::rtl::OUString > PageBackground::getSupportedServiceNames_Static()
245 uno::Sequence< ::rtl::OUString > aServices( 2 );
246 aServices[ 0 ] = C2U( "com.sun.star.chart2.PageBackground" );
247 aServices[ 1 ] = C2U( "com.sun.star.beans.PropertySet" );
248 return aServices;
251 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
252 APPHELPER_XSERVICEINFO_IMPL( PageBackground, lcl_aServiceName );
254 using impl::PageBackground_Base;
256 IMPLEMENT_FORWARD_XINTERFACE2( PageBackground, PageBackground_Base, ::property::OPropertySet )
258 } // namespace chart