Branch data 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 "FormattedString.hxx"
21 : : #include "ContainerHelper.hxx"
22 : :
23 : : #include "CharacterProperties.hxx"
24 : : #include "PropertyHelper.hxx"
25 : : #include "macros.hxx"
26 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
27 : :
28 : : using namespace ::com::sun::star;
29 : :
30 : : using ::rtl::OUString;
31 : : using ::com::sun::star::beans::Property;
32 : : using ::com::sun::star::uno::Sequence;
33 : : using ::com::sun::star::uno::Reference;
34 : : using ::com::sun::star::uno::Any;
35 : : using ::osl::MutexGuard;
36 : :
37 : : namespace
38 : : {
39 : :
40 : : struct StaticFormattedStringDefaults_Initializer
41 : : {
42 : 12 : ::chart::tPropertyValueMap* operator()()
43 : : {
44 [ + - ][ + - ]: 12 : static ::chart::tPropertyValueMap aStaticDefaults;
[ + - ][ # # ]
45 : 12 : lcl_AddDefaultsToMap( aStaticDefaults );
46 : 12 : return &aStaticDefaults;
47 : : }
48 : : private:
49 : 12 : void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
50 : : {
51 : 12 : ::chart::CharacterProperties::AddDefaultsToMap( rOutMap );
52 : 12 : }
53 : : };
54 : :
55 : : struct StaticFormattedStringDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticFormattedStringDefaults_Initializer >
56 : : {
57 : : };
58 : :
59 : : struct StaticFormattedStringInfoHelper_Initializer
60 : : {
61 : 12 : ::cppu::OPropertyArrayHelper* operator()()
62 : : {
63 [ + - ][ + - ]: 12 : static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
[ + - ][ + - ]
[ + - ][ # # ]
64 : 12 : return &aPropHelper;
65 : : }
66 : :
67 : : private:
68 : 12 : Sequence< Property > lcl_GetPropertySequence()
69 : : {
70 [ + - ]: 12 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
71 [ + - ]: 12 : ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
72 : :
73 : : ::std::sort( aProperties.begin(), aProperties.end(),
74 [ + - ]: 12 : ::chart::PropertyNameLess() );
75 : :
76 [ + - ]: 12 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
77 : : }
78 : :
79 : : };
80 : :
81 : : struct StaticFormattedStringInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticFormattedStringInfoHelper_Initializer >
82 : : {
83 : : };
84 : :
85 : : struct StaticFormattedStringInfo_Initializer
86 : : {
87 : 12 : uno::Reference< beans::XPropertySetInfo >* operator()()
88 : : {
89 : : static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
90 [ + - ][ + - ]: 12 : ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticFormattedStringInfoHelper::get() ) );
[ + - ][ + - ]
[ # # ]
91 : 12 : return &xPropertySetInfo;
92 : : }
93 : : };
94 : :
95 : : struct StaticFormattedStringInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticFormattedStringInfo_Initializer >
96 : : {
97 : : };
98 : :
99 : : } // anonymous namespace
100 : :
101 : : namespace chart
102 : : {
103 : :
104 : 3243 : FormattedString::FormattedString(
105 : : uno::Reference< uno::XComponentContext > const & /* xContext */ ) :
106 : : ::property::OPropertySet( m_aMutex ),
107 : : m_aString(),
108 [ + - ][ + - ]: 3243 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
[ + - ]
109 : 3243 : {}
110 : :
111 : 0 : FormattedString::FormattedString( const FormattedString & rOther ) :
112 : : MutexContainer(),
113 : : impl::FormattedString_Base(),
114 : : ::property::OPropertySet( rOther, m_aMutex ),
115 : : m_aString( rOther.m_aString ),
116 [ # # ][ # # ]: 0 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
[ # # ]
117 : 0 : {}
118 : :
119 [ + - ][ + - ]: 3243 : FormattedString::~FormattedString()
120 [ - + ]: 6486 : {}
121 : :
122 : : // ____ XCloneable ____
123 : 0 : uno::Reference< util::XCloneable > SAL_CALL FormattedString::createClone()
124 : : throw (uno::RuntimeException)
125 : : {
126 [ # # ][ # # ]: 0 : return uno::Reference< util::XCloneable >( new FormattedString( *this ));
127 : : }
128 : :
129 : : // ____ XFormattedString ____
130 : 5127 : ::rtl::OUString SAL_CALL FormattedString::getString()
131 : : throw (uno::RuntimeException)
132 : : {
133 [ + - ][ + - ]: 5127 : MutexGuard aGuard( GetMutex());
134 [ + - ]: 5127 : return m_aString;
135 : : }
136 : :
137 : 3257 : void SAL_CALL FormattedString::setString( const ::rtl::OUString& String )
138 : : throw (uno::RuntimeException)
139 : : {
140 : : {
141 [ + - ][ + - ]: 3257 : MutexGuard aGuard( GetMutex());
142 [ + - ]: 3257 : m_aString = String;
143 : : }
144 : : //don't keep the mutex locked while calling out
145 : 3257 : fireModifyEvent();
146 : :
147 : 3257 : }
148 : :
149 : : // ____ XModifyBroadcaster ____
150 : 52 : void SAL_CALL FormattedString::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
151 : : throw (uno::RuntimeException)
152 : : {
153 : : try
154 : : {
155 [ + - ]: 52 : uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
156 [ + - ][ + - ]: 52 : xBroadcaster->addModifyListener( aListener );
[ # # ]
157 : : }
158 : 0 : catch( const uno::Exception & ex )
159 : : {
160 : : ASSERT_EXCEPTION( ex );
161 : : }
162 : 52 : }
163 : :
164 : 52 : void SAL_CALL FormattedString::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
165 : : throw (uno::RuntimeException)
166 : : {
167 : : try
168 : : {
169 [ + - ]: 52 : uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
170 [ + - ][ + - ]: 52 : xBroadcaster->removeModifyListener( aListener );
[ # # ]
171 : : }
172 : 0 : catch( const uno::Exception & ex )
173 : : {
174 : : ASSERT_EXCEPTION( ex );
175 : : }
176 : 52 : }
177 : :
178 : : // ____ XModifyListener ____
179 : 0 : void SAL_CALL FormattedString::modified( const lang::EventObject& aEvent )
180 : : throw (uno::RuntimeException)
181 : : {
182 : 0 : m_xModifyEventForwarder->modified( aEvent );
183 : 0 : }
184 : :
185 : : // ____ XEventListener (base of XModifyListener) ____
186 : 0 : void SAL_CALL FormattedString::disposing( const lang::EventObject& /* Source */ )
187 : : throw (uno::RuntimeException)
188 : : {
189 : : // nothing
190 : 0 : }
191 : :
192 : : // ____ OPropertySet ____
193 : 147944 : void FormattedString::firePropertyChangeEvent()
194 : : {
195 : 147944 : fireModifyEvent();
196 : 147944 : }
197 : :
198 : 151201 : void FormattedString::fireModifyEvent()
199 : : {
200 [ + - ][ + - ]: 151201 : m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
[ + - ]
201 : 151201 : }
202 : :
203 : :
204 : : // ----------------------------------------
205 : :
206 : 12 : Sequence< OUString > FormattedString::getSupportedServiceNames_Static()
207 : : {
208 : 12 : Sequence< OUString > aServices( 2 );
209 : :
210 [ + - ][ + - ]: 12 : aServices[ 0 ] = C2U( "com.sun.star.chart2.FormattedString" );
211 [ + - ][ + - ]: 12 : aServices[ 1 ] = C2U( "com.sun.star.beans.PropertySet" );
212 : 12 : return aServices;
213 : : }
214 : :
215 : : // ____ OPropertySet ____
216 : 190512 : uno::Any FormattedString::GetDefaultValue( sal_Int32 nHandle ) const
217 : : throw(beans::UnknownPropertyException)
218 : : {
219 [ + - ]: 190512 : const tPropertyValueMap& rStaticDefaults = *StaticFormattedStringDefaults::get();
220 [ + - ]: 190512 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
221 [ + + ]: 190512 : if( aFound == rStaticDefaults.end() )
222 : 6414 : return uno::Any();
223 : 190512 : return (*aFound).second;
224 : : }
225 : :
226 : : // ____ OPropertySet ____
227 : 389131 : ::cppu::IPropertyArrayHelper & SAL_CALL FormattedString::getInfoHelper()
228 : : {
229 : 389131 : return *StaticFormattedStringInfoHelper::get();
230 : : }
231 : :
232 : :
233 : : // ____ XPropertySet ____
234 : 3205 : uno::Reference< beans::XPropertySetInfo > SAL_CALL FormattedString::getPropertySetInfo()
235 : : throw (uno::RuntimeException)
236 : : {
237 : 3205 : return *StaticFormattedStringInfo::get();
238 : : }
239 : :
240 : : // ================================================================================
241 : :
242 : : using impl::FormattedString_Base;
243 : :
244 [ + + ][ + - ]: 749211 : IMPLEMENT_FORWARD_XINTERFACE2( FormattedString, FormattedString_Base, ::property::OPropertySet )
245 [ # # ][ # # ]: 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( FormattedString, FormattedString_Base, ::property::OPropertySet )
[ # # ]
246 : :
247 : : // do this in derived classes!
248 : :
249 : : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
250 [ # # ][ # # ]: 173 : APPHELPER_XSERVICEINFO_IMPL( FormattedString,
[ # # ][ # # ]
[ # # ]
251 : : C2U( "com.sun.star.comp.chart.FormattedString" ));
252 : :
253 : : } // namespace chart
254 : :
255 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|