merge the formfield patch from ooo-build
[ooovba.git] / chart2 / source / model / main / GridProperties.cxx
blob34d58bdb911251614dd3fdffc8f367d9915877bb
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: GridProperties.cxx,v $
10 * $Revision: 1.7 $
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"
34 #include "GridProperties.hxx"
35 #include "LineProperties.hxx"
36 #include "UserDefinedProperties.hxx"
37 #include "PropertyHelper.hxx"
38 #include "macros.hxx"
39 #include "ContainerHelper.hxx"
40 #include <com/sun/star/style/XStyle.hpp>
41 #include <com/sun/star/beans/PropertyAttribute.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/uno/Sequence.hxx>
45 using namespace ::com::sun::star;
47 using ::com::sun::star::uno::Reference;
48 using ::com::sun::star::uno::Sequence;
49 using ::com::sun::star::beans::Property;
50 using ::osl::MutexGuard;
51 using ::rtl::OUString;
53 // ____________________________________________________________
55 namespace
58 static const ::rtl::OUString lcl_aServiceName(
59 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.GridProperties" ));
61 enum
63 PROP_GRID_SHOW
66 void lcl_AddPropertiesToVector(
67 ::std::vector< Property > & rOutProperties )
69 rOutProperties.push_back(
70 Property( C2U( "Show" ),
71 PROP_GRID_SHOW,
72 ::getBooleanCppuType(),
73 beans::PropertyAttribute::BOUND
74 | beans::PropertyAttribute::MAYBEDEFAULT ));
77 void lcl_addDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
79 ::chart::LineProperties::AddDefaultsToMap( rOutMap );
81 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_GRID_SHOW, false );
83 // override other defaults
84 ::chart::PropertyHelper::setPropertyValue< sal_Int32 >(
85 rOutMap, ::chart::LineProperties::PROP_LINE_COLOR, 0xb3b3b3 ); // gray30
88 const Sequence< Property > & lcl_getPropertySequence()
90 static Sequence< Property > aPropSeq;
92 // /--
93 MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
94 if( 0 == aPropSeq.getLength() )
96 // get properties
97 ::std::vector< Property > aProperties;
98 lcl_AddPropertiesToVector( aProperties );
99 ::chart::LineProperties::AddPropertiesToVector( aProperties );
100 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
102 // and sort them for access via bsearch
103 ::std::sort( aProperties.begin(), aProperties.end(),
104 ::chart::PropertyNameLess() );
106 // transfer result to static Sequence
107 aPropSeq = ::chart::ContainerHelper::ContainerToSequence( aProperties );
110 return aPropSeq;
113 ::cppu::IPropertyArrayHelper & lcl_getInfoHelper()
115 static ::cppu::OPropertyArrayHelper aArrayHelper(
116 lcl_getPropertySequence(),
117 /* bSorted = */ sal_True );
119 return aArrayHelper;
122 } // anonymous namespace
124 // ____________________________________________________________
126 namespace chart
129 GridProperties::GridProperties( Reference< uno::XComponentContext > const & /* xContext */ ) :
130 ::property::OPropertySet( m_aMutex ),
131 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
135 GridProperties::GridProperties() :
136 ::property::OPropertySet( m_aMutex ),
137 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
140 GridProperties::GridProperties( const GridProperties & rOther ) :
141 MutexContainer(),
142 impl::GridProperties_Base(),
143 ::property::OPropertySet( rOther, m_aMutex ),
144 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
148 GridProperties::~GridProperties()
151 // ____ OPropertySet ____
152 uno::Any GridProperties::GetDefaultValue( sal_Int32 nHandle ) const
153 throw(beans::UnknownPropertyException)
155 static tPropertyValueMap aStaticDefaults;
157 // /--
158 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
159 if( 0 == aStaticDefaults.size() )
160 lcl_addDefaultsToMap( aStaticDefaults );
162 tPropertyValueMap::const_iterator aFound(
163 aStaticDefaults.find( nHandle ));
165 if( aFound == aStaticDefaults.end())
166 return uno::Any();
168 return (*aFound).second;
169 // \--
172 ::cppu::IPropertyArrayHelper & SAL_CALL GridProperties::getInfoHelper()
174 return lcl_getInfoHelper();
177 // ____ XPropertySet ____
178 Reference< beans::XPropertySetInfo > SAL_CALL
179 GridProperties::getPropertySetInfo()
180 throw (uno::RuntimeException)
182 static Reference< beans::XPropertySetInfo > xInfo;
184 // /--
185 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
186 if( !xInfo.is())
188 xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo(
189 lcl_getInfoHelper());
192 return xInfo;
193 // \--
196 // ____ XCloneable ____
197 uno::Reference< util::XCloneable > SAL_CALL GridProperties::createClone()
198 throw (uno::RuntimeException)
200 return uno::Reference< util::XCloneable >( new GridProperties( *this ));
203 // ____ XModifyBroadcaster ____
204 void SAL_CALL GridProperties::addModifyListener( const Reference< util::XModifyListener >& aListener )
205 throw (uno::RuntimeException)
209 Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
210 xBroadcaster->addModifyListener( aListener );
212 catch( const uno::Exception & ex )
214 ASSERT_EXCEPTION( ex );
218 void SAL_CALL GridProperties::removeModifyListener( const Reference< util::XModifyListener >& aListener )
219 throw (uno::RuntimeException)
223 Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
224 xBroadcaster->removeModifyListener( aListener );
226 catch( const uno::Exception & ex )
228 ASSERT_EXCEPTION( ex );
232 // ____ XModifyListener ____
233 void SAL_CALL GridProperties::modified( const lang::EventObject& aEvent )
234 throw (uno::RuntimeException)
236 m_xModifyEventForwarder->modified( aEvent );
239 // ____ XEventListener (base of XModifyListener) ____
240 void SAL_CALL GridProperties::disposing( const lang::EventObject& /* Source */ )
241 throw (uno::RuntimeException)
243 // nothing
246 // ____ OPropertySet ____
247 void GridProperties::firePropertyChangeEvent()
249 fireModifyEvent();
252 void GridProperties::fireModifyEvent()
254 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
257 // ================================================================================
259 Sequence< OUString > GridProperties::getSupportedServiceNames_Static()
261 Sequence< OUString > aServices( 2 );
262 aServices[ 0 ] = C2U( "com.sun.star.chart2.GridProperties" );
263 aServices[ 1 ] = C2U( "com.sun.star.beans.PropertySet" );
264 return aServices;
267 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
268 APPHELPER_XSERVICEINFO_IMPL( GridProperties, lcl_aServiceName );
270 // needed by MSC compiler
271 using impl::GridProperties_Base;
273 IMPLEMENT_FORWARD_XINTERFACE2( GridProperties, GridProperties_Base, ::property::OPropertySet )
274 IMPLEMENT_FORWARD_XTYPEPROVIDER2( GridProperties, GridProperties_Base, ::property::OPropertySet )
276 } // namespace chart