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