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