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 #include "PageBackground.hxx"
27 #include "macros.hxx"
28 #include "LineProperties.hxx"
29 #include "FillProperties.hxx"
30 #include "UserDefinedProperties.hxx"
31 #include "ContainerHelper.hxx"
32 #include "PropertyHelper.hxx"
33
34 #include <com/sun/star/drawing/LineStyle.hpp>
35 #include <rtl/uuid.h>
36 #include <cppuhelper/queryinterface.hxx>
37
38 #include <vector>
39 #include <algorithm>
40
41 using namespace ::com::sun::star;
42
43 using ::com::sun::star::beans::Property;
44 using ::osl::MutexGuard;
45
46 namespace
47 {
48
49 static const ::rtl::OUString lcl_aServiceName(
50 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.PageBackground" ));
51
52 struct StaticPageBackgroundDefaults_Initializer
53 {
operator ()__anon7ee9d3840111::StaticPageBackgroundDefaults_Initializer54 ::chart::tPropertyValueMap* operator()()
55 {
56 static ::chart::tPropertyValueMap aStaticDefaults;
57 lcl_AddDefaultsToMap( aStaticDefaults );
58 return &aStaticDefaults;
59 }
60 private:
lcl_AddDefaultsToMap__anon7ee9d3840111::StaticPageBackgroundDefaults_Initializer61 void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
62 {
63 ::chart::LineProperties::AddDefaultsToMap( rOutMap );
64 ::chart::FillProperties::AddDefaultsToMap( rOutMap );
65
66 // override other defaults
67 ::chart::PropertyHelper::setPropertyValue< sal_Int32 >( rOutMap, ::chart::FillProperties::PROP_FILL_COLOR, 0xffffff );
68 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::LineProperties::PROP_LINE_STYLE, drawing::LineStyle_NONE );
69 }
70 };
71
72 struct StaticPageBackgroundDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticPageBackgroundDefaults_Initializer >
73 {
74 };
75
76 struct StaticPageBackgroundInfoHelper_Initializer
77 {
operator ()__anon7ee9d3840111::StaticPageBackgroundInfoHelper_Initializer78 ::cppu::OPropertyArrayHelper* operator()()
79 {
80 static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
81 return &aPropHelper;
82 }
83
84 private:
lcl_GetPropertySequence__anon7ee9d3840111::StaticPageBackgroundInfoHelper_Initializer85 uno::Sequence< Property > lcl_GetPropertySequence()
86 {
87 ::std::vector< ::com::sun::star::beans::Property > aProperties;
88 ::chart::LineProperties::AddPropertiesToVector( aProperties );
89 ::chart::FillProperties::AddPropertiesToVector( aProperties );
90 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
91
92 ::std::sort( aProperties.begin(), aProperties.end(),
93 ::chart::PropertyNameLess() );
94
95 return ::chart::ContainerHelper::ContainerToSequence( aProperties );
96 }
97
98 };
99
100 struct StaticPageBackgroundInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticPageBackgroundInfoHelper_Initializer >
101 {
102 };
103
104 struct StaticPageBackgroundInfo_Initializer
105 {
operator ()__anon7ee9d3840111::StaticPageBackgroundInfo_Initializer106 uno::Reference< beans::XPropertySetInfo >* operator()()
107 {
108 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
109 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticPageBackgroundInfoHelper::get() ) );
110 return &xPropertySetInfo;
111 }
112 };
113
114 struct StaticPageBackgroundInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticPageBackgroundInfo_Initializer >
115 {
116 };
117
118 } // anonymous namespace
119
120 // ================================================================================
121
122 namespace chart
123 {
124
PageBackground(const uno::Reference<uno::XComponentContext> & xContext)125 PageBackground::PageBackground( const uno::Reference< uno::XComponentContext > & xContext ) :
126 ::property::OPropertySet( m_aMutex ),
127 m_xContext( xContext ),
128 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
129 {}
130
PageBackground(const PageBackground & rOther)131 PageBackground::PageBackground( const PageBackground & rOther ) :
132 MutexContainer(),
133 impl::PageBackground_Base(),
134 ::property::OPropertySet( rOther, m_aMutex ),
135 m_xContext( rOther.m_xContext ),
136 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
137 {}
138
~PageBackground()139 PageBackground::~PageBackground()
140 {}
141
142 // ____ XCloneable ____
createClone()143 uno::Reference< util::XCloneable > SAL_CALL PageBackground::createClone()
144 throw (uno::RuntimeException)
145 {
146 return uno::Reference< util::XCloneable >( new PageBackground( *this ));
147 }
148
149 // ================================================================================
150
151 // ____ OPropertySet ____
GetDefaultValue(sal_Int32 nHandle) const152 uno::Any PageBackground::GetDefaultValue( sal_Int32 nHandle ) const
153 throw(beans::UnknownPropertyException)
154 {
155 const tPropertyValueMap& rStaticDefaults = *StaticPageBackgroundDefaults::get();
156 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
157 if( aFound == rStaticDefaults.end() )
158 return uno::Any();
159 return (*aFound).second;
160 }
161
getInfoHelper()162 ::cppu::IPropertyArrayHelper & SAL_CALL PageBackground::getInfoHelper()
163 {
164 return *StaticPageBackgroundInfoHelper::get();
165 }
166
167 // ____ XPropertySet ____
getPropertySetInfo()168 uno::Reference< beans::XPropertySetInfo > SAL_CALL PageBackground::getPropertySetInfo()
169 throw (uno::RuntimeException)
170 {
171 return *StaticPageBackgroundInfo::get();
172 }
173
174 // ____ XModifyBroadcaster ____
addModifyListener(const uno::Reference<util::XModifyListener> & aListener)175 void SAL_CALL PageBackground::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
176 throw (uno::RuntimeException)
177 {
178 try
179 {
180 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
181 xBroadcaster->addModifyListener( aListener );
182 }
183 catch( const uno::Exception & ex )
184 {
185 ASSERT_EXCEPTION( ex );
186 }
187 }
188
removeModifyListener(const uno::Reference<util::XModifyListener> & aListener)189 void SAL_CALL PageBackground::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
190 throw (uno::RuntimeException)
191 {
192 try
193 {
194 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
195 xBroadcaster->removeModifyListener( aListener );
196 }
197 catch( const uno::Exception & ex )
198 {
199 ASSERT_EXCEPTION( ex );
200 }
201 }
202
203 // ____ XModifyListener ____
modified(const lang::EventObject & aEvent)204 void SAL_CALL PageBackground::modified( const lang::EventObject& aEvent )
205 throw (uno::RuntimeException)
206 {
207 m_xModifyEventForwarder->modified( aEvent );
208 }
209
210 // ____ XEventListener (base of XModifyListener) ____
disposing(const lang::EventObject &)211 void SAL_CALL PageBackground::disposing( const lang::EventObject& /* Source */ )
212 throw (uno::RuntimeException)
213 {
214 // nothing
215 }
216
217 // ____ OPropertySet ____
firePropertyChangeEvent()218 void PageBackground::firePropertyChangeEvent()
219 {
220 fireModifyEvent();
221 }
222
fireModifyEvent()223 void PageBackground::fireModifyEvent()
224 {
225 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
226 }
227
228 // ================================================================================
229
getSupportedServiceNames_Static()230 uno::Sequence< ::rtl::OUString > PageBackground::getSupportedServiceNames_Static()
231 {
232 uno::Sequence< ::rtl::OUString > aServices( 2 );
233 aServices[ 0 ] = C2U( "com.sun.star.chart2.PageBackground" );
234 aServices[ 1 ] = C2U( "com.sun.star.beans.PropertySet" );
235 return aServices;
236 }
237
238 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
239 APPHELPER_XSERVICEINFO_IMPL( PageBackground, lcl_aServiceName );
240
241 using impl::PageBackground_Base;
242
243 IMPLEMENT_FORWARD_XINTERFACE2( PageBackground, PageBackground_Base, ::property::OPropertySet )
244
245 } // namespace chart
246