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 "GridProperties.hxx"
21 : #include "LinePropertiesHelper.hxx"
22 : #include "UserDefinedProperties.hxx"
23 : #include "PropertyHelper.hxx"
24 : #include "macros.hxx"
25 : #include "ContainerHelper.hxx"
26 : #include <com/sun/star/style/XStyle.hpp>
27 : #include <com/sun/star/beans/PropertyAttribute.hpp>
28 : #include <com/sun/star/beans/XPropertySet.hpp>
29 : #include <com/sun/star/uno/Sequence.hxx>
30 : #include <cppuhelper/supportsservice.hxx>
31 :
32 : using namespace ::com::sun::star;
33 :
34 : using ::com::sun::star::uno::Reference;
35 : using ::com::sun::star::uno::Sequence;
36 : using ::com::sun::star::beans::Property;
37 : using ::osl::MutexGuard;
38 :
39 : namespace
40 : {
41 :
42 : static const char lcl_aServiceName[] = "com.sun.star.comp.chart2.GridProperties";
43 :
44 : enum
45 : {
46 : PROP_GRID_SHOW
47 : };
48 :
49 17 : void lcl_AddPropertiesToVector(
50 : ::std::vector< Property > & rOutProperties )
51 : {
52 : rOutProperties.push_back(
53 : Property( "Show",
54 : PROP_GRID_SHOW,
55 17 : cppu::UnoType<bool>::get(),
56 : beans::PropertyAttribute::BOUND
57 34 : | beans::PropertyAttribute::MAYBEDEFAULT ));
58 17 : }
59 :
60 : struct StaticGridDefaults_Initializer
61 : {
62 17 : ::chart::tPropertyValueMap* operator()()
63 : {
64 17 : static ::chart::tPropertyValueMap aStaticDefaults;
65 17 : lcl_AddDefaultsToMap( aStaticDefaults );
66 17 : return &aStaticDefaults;
67 : }
68 : private:
69 17 : static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
70 : {
71 17 : ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap );
72 :
73 17 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_GRID_SHOW, false );
74 :
75 : // override other defaults
76 : ::chart::PropertyHelper::setPropertyValue< sal_Int32 >(
77 17 : rOutMap, ::chart::LinePropertiesHelper::PROP_LINE_COLOR, 0xb3b3b3 ); // gray30
78 17 : }
79 : };
80 :
81 : struct StaticGridDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticGridDefaults_Initializer >
82 : {
83 : };
84 :
85 : struct StaticGridInfoHelper_Initializer
86 : {
87 17 : ::cppu::OPropertyArrayHelper* operator()()
88 : {
89 17 : static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
90 17 : return &aPropHelper;
91 : }
92 :
93 : private:
94 17 : static Sequence< Property > lcl_GetPropertySequence()
95 : {
96 17 : ::std::vector< Property > aProperties;
97 17 : lcl_AddPropertiesToVector( aProperties );
98 17 : ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
99 17 : ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
100 :
101 : ::std::sort( aProperties.begin(), aProperties.end(),
102 17 : ::chart::PropertyNameLess() );
103 :
104 17 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
105 : }
106 :
107 : };
108 :
109 : struct StaticGridInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticGridInfoHelper_Initializer >
110 : {
111 : };
112 :
113 : struct StaticGridInfo_Initializer
114 : {
115 6 : uno::Reference< beans::XPropertySetInfo >* operator()()
116 : {
117 : static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
118 6 : ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticGridInfoHelper::get() ) );
119 6 : return &xPropertySetInfo;
120 : }
121 : };
122 :
123 : struct StaticGridInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticGridInfo_Initializer >
124 : {
125 : };
126 :
127 : } // anonymous namespace
128 :
129 : namespace chart
130 : {
131 :
132 1 : GridProperties::GridProperties( Reference< uno::XComponentContext > const & /* xContext */ ) :
133 : ::property::OPropertySet( m_aMutex ),
134 1 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
135 : {
136 1 : }
137 :
138 2450 : GridProperties::GridProperties() :
139 : ::property::OPropertySet( m_aMutex ),
140 2450 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
141 2450 : {}
142 :
143 0 : GridProperties::GridProperties( const GridProperties & rOther ) :
144 : MutexContainer(),
145 : impl::GridProperties_Base(),
146 : ::property::OPropertySet( rOther, m_aMutex ),
147 0 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
148 : {
149 0 : }
150 :
151 4774 : GridProperties::~GridProperties()
152 4774 : {}
153 :
154 : // ____ OPropertySet ____
155 27694 : uno::Any GridProperties::GetDefaultValue( sal_Int32 nHandle ) const
156 : throw(beans::UnknownPropertyException)
157 : {
158 27694 : const tPropertyValueMap& rStaticDefaults = *StaticGridDefaults::get();
159 27694 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
160 27694 : if( aFound == rStaticDefaults.end() )
161 892 : return uno::Any();
162 26802 : return (*aFound).second;
163 : }
164 :
165 67519 : ::cppu::IPropertyArrayHelper & SAL_CALL GridProperties::getInfoHelper()
166 : {
167 67519 : return *StaticGridInfoHelper::get();
168 : }
169 :
170 : // ____ XPropertySet ____
171 704 : Reference< beans::XPropertySetInfo > SAL_CALL GridProperties::getPropertySetInfo()
172 : throw (uno::RuntimeException, std::exception)
173 : {
174 704 : return *StaticGridInfo::get();
175 : }
176 :
177 : // ____ XCloneable ____
178 0 : uno::Reference< util::XCloneable > SAL_CALL GridProperties::createClone()
179 : throw (uno::RuntimeException, std::exception)
180 : {
181 0 : return uno::Reference< util::XCloneable >( new GridProperties( *this ));
182 : }
183 :
184 : // ____ XModifyBroadcaster ____
185 2450 : void SAL_CALL GridProperties::addModifyListener( const Reference< util::XModifyListener >& aListener )
186 : throw (uno::RuntimeException, std::exception)
187 : {
188 : try
189 : {
190 2450 : Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
191 2450 : xBroadcaster->addModifyListener( aListener );
192 : }
193 0 : catch( const uno::Exception & ex )
194 : {
195 : ASSERT_EXCEPTION( ex );
196 : }
197 2450 : }
198 :
199 2386 : void SAL_CALL GridProperties::removeModifyListener( const Reference< util::XModifyListener >& aListener )
200 : throw (uno::RuntimeException, std::exception)
201 : {
202 : try
203 : {
204 2386 : Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
205 2386 : xBroadcaster->removeModifyListener( aListener );
206 : }
207 0 : catch( const uno::Exception & ex )
208 : {
209 : ASSERT_EXCEPTION( ex );
210 : }
211 2386 : }
212 :
213 : // ____ XModifyListener ____
214 0 : void SAL_CALL GridProperties::modified( const lang::EventObject& aEvent )
215 : throw (uno::RuntimeException, std::exception)
216 : {
217 0 : m_xModifyEventForwarder->modified( aEvent );
218 0 : }
219 :
220 : // ____ XEventListener (base of XModifyListener) ____
221 0 : void SAL_CALL GridProperties::disposing( const lang::EventObject& /* Source */ )
222 : throw (uno::RuntimeException, std::exception)
223 : {
224 : // nothing
225 0 : }
226 :
227 : // ____ OPropertySet ____
228 2838 : void GridProperties::firePropertyChangeEvent()
229 : {
230 2838 : fireModifyEvent();
231 2838 : }
232 :
233 2838 : void GridProperties::fireModifyEvent()
234 : {
235 2838 : m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
236 2838 : }
237 :
238 1 : Sequence< OUString > GridProperties::getSupportedServiceNames_Static()
239 : {
240 1 : Sequence< OUString > aServices( 2 );
241 1 : aServices[ 0 ] = "com.sun.star.chart2.GridProperties";
242 1 : aServices[ 1 ] = "com.sun.star.beans.PropertySet";
243 1 : return aServices;
244 : }
245 :
246 : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
247 1 : OUString SAL_CALL GridProperties::getImplementationName()
248 : throw( css::uno::RuntimeException, std::exception )
249 : {
250 1 : return getImplementationName_Static();
251 : }
252 :
253 1 : OUString GridProperties::getImplementationName_Static()
254 : {
255 1 : return OUString(lcl_aServiceName);
256 : }
257 :
258 0 : sal_Bool SAL_CALL GridProperties::supportsService( const OUString& rServiceName )
259 : throw( css::uno::RuntimeException, std::exception )
260 : {
261 0 : return cppu::supportsService(this, rServiceName);
262 : }
263 :
264 1 : css::uno::Sequence< OUString > SAL_CALL GridProperties::getSupportedServiceNames()
265 : throw( css::uno::RuntimeException, std::exception )
266 : {
267 1 : return getSupportedServiceNames_Static();
268 : }
269 :
270 : // needed by MSC compiler
271 : using impl::GridProperties_Base;
272 :
273 174188 : IMPLEMENT_FORWARD_XINTERFACE2( GridProperties, GridProperties_Base, ::property::OPropertySet )
274 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( GridProperties, GridProperties_Base, ::property::OPropertySet )
275 :
276 : } // namespace chart
277 :
278 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
279 1 : com_sun_star_comp_chart2_GridProperties_get_implementation(css::uno::XComponentContext *context,
280 : css::uno::Sequence<css::uno::Any> const &)
281 : {
282 1 : return cppu::acquire(new ::chart::GridProperties(context));
283 : }
284 :
285 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|