1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 
27 #include "GridProperties.hxx"
28 #include "LineProperties.hxx"
29 #include "UserDefinedProperties.hxx"
30 #include "PropertyHelper.hxx"
31 #include "macros.hxx"
32 #include "ContainerHelper.hxx"
33 #include <com/sun/star/style/XStyle.hpp>
34 #include <com/sun/star/beans/PropertyAttribute.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/uno/Sequence.hxx>
37 
38 using namespace ::com::sun::star;
39 
40 using ::com::sun::star::uno::Reference;
41 using ::com::sun::star::uno::Sequence;
42 using ::com::sun::star::beans::Property;
43 using ::osl::MutexGuard;
44 using ::rtl::OUString;
45 
46 // ____________________________________________________________
47 
48 namespace
49 {
50 
51 static const ::rtl::OUString lcl_aServiceName(
52     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.GridProperties" ));
53 
54 enum
55 {
56     PROP_GRID_SHOW
57 };
58 
lcl_AddPropertiesToVector(::std::vector<Property> & rOutProperties)59 void lcl_AddPropertiesToVector(
60     ::std::vector< Property > & rOutProperties )
61 {
62     rOutProperties.push_back(
63         Property( C2U( "Show" ),
64                   PROP_GRID_SHOW,
65                   ::getBooleanCppuType(),
66                   beans::PropertyAttribute::BOUND
67                   | beans::PropertyAttribute::MAYBEDEFAULT ));
68 }
69 
70 struct StaticGridDefaults_Initializer
71 {
operator ()__anon3aa5f2110111::StaticGridDefaults_Initializer72     ::chart::tPropertyValueMap* operator()()
73     {
74         static ::chart::tPropertyValueMap aStaticDefaults;
75         lcl_AddDefaultsToMap( aStaticDefaults );
76         return &aStaticDefaults;
77     }
78 private:
lcl_AddDefaultsToMap__anon3aa5f2110111::StaticGridDefaults_Initializer79     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
80     {
81         ::chart::LineProperties::AddDefaultsToMap( rOutMap );
82 
83         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_GRID_SHOW, false );
84 
85         // override other defaults
86         ::chart::PropertyHelper::setPropertyValue< sal_Int32 >(
87             rOutMap, ::chart::LineProperties::PROP_LINE_COLOR, 0xb3b3b3 );  // gray30
88     }
89 };
90 
91 struct StaticGridDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticGridDefaults_Initializer >
92 {
93 };
94 
95 struct StaticGridInfoHelper_Initializer
96 {
operator ()__anon3aa5f2110111::StaticGridInfoHelper_Initializer97     ::cppu::OPropertyArrayHelper* operator()()
98     {
99         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
100         return &aPropHelper;
101     }
102 
103 private:
lcl_GetPropertySequence__anon3aa5f2110111::StaticGridInfoHelper_Initializer104     Sequence< Property > lcl_GetPropertySequence()
105     {
106         ::std::vector< Property > aProperties;
107         lcl_AddPropertiesToVector( aProperties );
108         ::chart::LineProperties::AddPropertiesToVector( aProperties );
109         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
110 
111         ::std::sort( aProperties.begin(), aProperties.end(),
112                      ::chart::PropertyNameLess() );
113 
114         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
115     }
116 
117 
118 };
119 
120 struct StaticGridInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticGridInfoHelper_Initializer >
121 {
122 };
123 
124 struct StaticGridInfo_Initializer
125 {
operator ()__anon3aa5f2110111::StaticGridInfo_Initializer126     uno::Reference< beans::XPropertySetInfo >* operator()()
127     {
128         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
129             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticGridInfoHelper::get() ) );
130         return &xPropertySetInfo;
131     }
132 };
133 
134 struct StaticGridInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticGridInfo_Initializer >
135 {
136 };
137 
138 } // anonymous namespace
139 
140 // ____________________________________________________________
141 
142 namespace chart
143 {
144 
GridProperties(Reference<uno::XComponentContext> const &)145 GridProperties::GridProperties( Reference< uno::XComponentContext > const & /* xContext */ ) :
146         ::property::OPropertySet( m_aMutex ),
147     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
148 {
149 }
150 
GridProperties()151 GridProperties::GridProperties() :
152         ::property::OPropertySet( m_aMutex ),
153     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
154 {}
155 
GridProperties(const GridProperties & rOther)156 GridProperties::GridProperties( const GridProperties & rOther ) :
157         MutexContainer(),
158         impl::GridProperties_Base(),
159         ::property::OPropertySet( rOther, m_aMutex ),
160     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
161 {
162 }
163 
~GridProperties()164 GridProperties::~GridProperties()
165 {}
166 
167 // ____ OPropertySet ____
GetDefaultValue(sal_Int32 nHandle) const168 uno::Any GridProperties::GetDefaultValue( sal_Int32 nHandle ) const
169     throw(beans::UnknownPropertyException)
170 {
171     const tPropertyValueMap& rStaticDefaults = *StaticGridDefaults::get();
172     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
173     if( aFound == rStaticDefaults.end() )
174         return uno::Any();
175     return (*aFound).second;
176 }
177 
getInfoHelper()178 ::cppu::IPropertyArrayHelper & SAL_CALL GridProperties::getInfoHelper()
179 {
180     return *StaticGridInfoHelper::get();
181 }
182 
183 // ____ XPropertySet ____
getPropertySetInfo()184 Reference< beans::XPropertySetInfo > SAL_CALL GridProperties::getPropertySetInfo()
185     throw (uno::RuntimeException)
186 {
187     return *StaticGridInfo::get();
188 }
189 
190 // ____ XCloneable ____
createClone()191 uno::Reference< util::XCloneable > SAL_CALL GridProperties::createClone()
192     throw (uno::RuntimeException)
193 {
194     return uno::Reference< util::XCloneable >( new GridProperties( *this ));
195 }
196 
197 // ____ XModifyBroadcaster ____
addModifyListener(const Reference<util::XModifyListener> & aListener)198 void SAL_CALL GridProperties::addModifyListener( const Reference< util::XModifyListener >& aListener )
199     throw (uno::RuntimeException)
200 {
201     try
202     {
203         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
204         xBroadcaster->addModifyListener( aListener );
205     }
206     catch( const uno::Exception & ex )
207     {
208         ASSERT_EXCEPTION( ex );
209     }
210 }
211 
removeModifyListener(const Reference<util::XModifyListener> & aListener)212 void SAL_CALL GridProperties::removeModifyListener( const Reference< util::XModifyListener >& aListener )
213     throw (uno::RuntimeException)
214 {
215     try
216     {
217         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
218         xBroadcaster->removeModifyListener( aListener );
219     }
220     catch( const uno::Exception & ex )
221     {
222         ASSERT_EXCEPTION( ex );
223     }
224 }
225 
226 // ____ XModifyListener ____
modified(const lang::EventObject & aEvent)227 void SAL_CALL GridProperties::modified( const lang::EventObject& aEvent )
228     throw (uno::RuntimeException)
229 {
230     m_xModifyEventForwarder->modified( aEvent );
231 }
232 
233 // ____ XEventListener (base of XModifyListener) ____
disposing(const lang::EventObject &)234 void SAL_CALL GridProperties::disposing( const lang::EventObject& /* Source */ )
235     throw (uno::RuntimeException)
236 {
237     // nothing
238 }
239 
240 // ____ OPropertySet ____
firePropertyChangeEvent()241 void GridProperties::firePropertyChangeEvent()
242 {
243     fireModifyEvent();
244 }
245 
fireModifyEvent()246 void GridProperties::fireModifyEvent()
247 {
248     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
249 }
250 
251 // ================================================================================
252 
getSupportedServiceNames_Static()253 Sequence< OUString > GridProperties::getSupportedServiceNames_Static()
254 {
255     Sequence< OUString > aServices( 2 );
256     aServices[ 0 ] = C2U( "com.sun.star.chart2.GridProperties" );
257     aServices[ 1 ] = C2U( "com.sun.star.beans.PropertySet" );
258     return aServices;
259 }
260 
261 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
262 APPHELPER_XSERVICEINFO_IMPL( GridProperties, lcl_aServiceName );
263 
264 // needed by MSC compiler
265 using impl::GridProperties_Base;
266 
267 IMPLEMENT_FORWARD_XINTERFACE2( GridProperties, GridProperties_Base, ::property::OPropertySet )
268 IMPLEMENT_FORWARD_XTYPEPROVIDER2( GridProperties, GridProperties_Base, ::property::OPropertySet )
269 
270 } //  namespace chart
271