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 "LabeledDataSequence.hxx"
21 : #include "ModifyListenerHelper.hxx"
22 : #include "macros.hxx"
23 : #include <cppuhelper/supportsservice.hxx>
24 :
25 : using namespace ::com::sun::star;
26 :
27 : using ::com::sun::star::uno::Reference;
28 : using ::com::sun::star::uno::Sequence;
29 :
30 : namespace chart
31 : {
32 :
33 3463 : LabeledDataSequence::LabeledDataSequence( const Reference< uno::XComponentContext > & xContext ) :
34 : m_xContext( xContext ),
35 3463 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
36 3463 : {}
37 :
38 12789 : LabeledDataSequence::LabeledDataSequence(
39 : const uno::Reference< chart2::data::XDataSequence > & rValues ) :
40 : m_xData( rValues ),
41 12789 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
42 : {
43 12789 : ModifyListenerHelper::addListener( m_xData, m_xModifyEventForwarder );
44 12789 : }
45 :
46 105 : LabeledDataSequence::LabeledDataSequence(
47 : const uno::Reference< chart2::data::XDataSequence > & rValues,
48 : const uno::Reference< chart2::data::XDataSequence > & rLabel ) :
49 : m_xData( rValues ),
50 : m_xLabel( rLabel ),
51 105 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
52 : {
53 105 : ModifyListenerHelper::addListener( m_xData, m_xModifyEventForwarder );
54 105 : ModifyListenerHelper::addListener( m_xLabel, m_xModifyEventForwarder );
55 105 : }
56 :
57 48879 : LabeledDataSequence::~LabeledDataSequence()
58 : {
59 16293 : if( m_xModifyEventForwarder.is())
60 : {
61 16293 : if( m_xData.is())
62 16291 : ModifyListenerHelper::removeListener( m_xData, m_xModifyEventForwarder );
63 16293 : if( m_xLabel.is())
64 1527 : ModifyListenerHelper::removeListener( m_xLabel, m_xModifyEventForwarder );
65 : }
66 32586 : }
67 :
68 : // ____ XLabeledDataSequence ____
69 332768 : uno::Reference< chart2::data::XDataSequence > SAL_CALL LabeledDataSequence::getValues()
70 : throw (uno::RuntimeException, std::exception)
71 : {
72 332768 : return m_xData;
73 : }
74 :
75 3461 : void SAL_CALL LabeledDataSequence::setValues(
76 : const uno::Reference< chart2::data::XDataSequence >& xSequence )
77 : throw (uno::RuntimeException, std::exception)
78 : {
79 3461 : if( m_xData != xSequence )
80 : {
81 3461 : ModifyListenerHelper::removeListener( m_xData, m_xModifyEventForwarder );
82 3461 : m_xData = xSequence;
83 3461 : ModifyListenerHelper::addListener( m_xData, m_xModifyEventForwarder );
84 : }
85 3461 : }
86 :
87 34006 : uno::Reference< chart2::data::XDataSequence > SAL_CALL LabeledDataSequence::getLabel()
88 : throw (uno::RuntimeException, std::exception)
89 : {
90 34006 : return m_xLabel;
91 : }
92 :
93 1638 : void SAL_CALL LabeledDataSequence::setLabel(
94 : const uno::Reference< chart2::data::XDataSequence >& xSequence )
95 : throw (uno::RuntimeException, std::exception)
96 : {
97 1638 : if( m_xLabel != xSequence )
98 : {
99 1470 : ModifyListenerHelper::removeListener( m_xLabel, m_xModifyEventForwarder );
100 1470 : m_xLabel = xSequence;
101 1470 : ModifyListenerHelper::addListener( m_xLabel, m_xModifyEventForwarder );
102 : }
103 1638 : }
104 :
105 : // ____ XCloneable ____
106 28 : uno::Reference< util::XCloneable > SAL_CALL LabeledDataSequence::createClone()
107 : throw (uno::RuntimeException, std::exception)
108 : {
109 28 : uno::Reference< chart2::data::XDataSequence > xNewValues( m_xData );
110 56 : uno::Reference< chart2::data::XDataSequence > xNewLabel( m_xLabel );
111 :
112 56 : uno::Reference< util::XCloneable > xLabelCloneable( m_xLabel, uno::UNO_QUERY );
113 28 : if( xLabelCloneable.is())
114 28 : xNewLabel.set( xLabelCloneable->createClone(), uno::UNO_QUERY );
115 :
116 56 : uno::Reference< util::XCloneable > xValuesCloneable( m_xData, uno::UNO_QUERY );
117 28 : if( xValuesCloneable.is())
118 28 : xNewValues.set( xValuesCloneable->createClone(), uno::UNO_QUERY );
119 :
120 : return uno::Reference< util::XCloneable >(
121 56 : new LabeledDataSequence( xNewValues, xNewLabel ) );
122 : }
123 :
124 : // ____ XModifyBroadcaster ____
125 1246 : void SAL_CALL LabeledDataSequence::addModifyListener( const Reference< util::XModifyListener >& aListener )
126 : throw (uno::RuntimeException, std::exception)
127 : {
128 : try
129 : {
130 1246 : Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
131 1246 : xBroadcaster->addModifyListener( aListener );
132 : }
133 0 : catch( const uno::Exception & ex )
134 : {
135 : ASSERT_EXCEPTION( ex );
136 : }
137 1246 : }
138 :
139 1170 : void SAL_CALL LabeledDataSequence::removeModifyListener( const Reference< util::XModifyListener >& aListener )
140 : throw (uno::RuntimeException, std::exception)
141 : {
142 : try
143 : {
144 1170 : Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
145 1170 : xBroadcaster->removeModifyListener( aListener );
146 : }
147 0 : catch( const uno::Exception & ex )
148 : {
149 : ASSERT_EXCEPTION( ex );
150 : }
151 1170 : }
152 :
153 1 : Sequence< OUString > LabeledDataSequence::getSupportedServiceNames_Static()
154 : {
155 1 : Sequence< OUString > aServices( 1 );
156 1 : aServices[ 0 ] = "com.sun.star.chart2.data.LabeledDataSequence";
157 1 : return aServices;
158 : }
159 :
160 : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
161 1 : OUString SAL_CALL LabeledDataSequence::getImplementationName()
162 : throw( css::uno::RuntimeException, std::exception )
163 : {
164 1 : return getImplementationName_Static();
165 : }
166 :
167 1 : OUString LabeledDataSequence::getImplementationName_Static()
168 : {
169 1 : return OUString("com.sun.star.comp.chart2.LabeledDataSequence");
170 : }
171 :
172 0 : sal_Bool SAL_CALL LabeledDataSequence::supportsService( const OUString& rServiceName )
173 : throw( css::uno::RuntimeException, std::exception )
174 : {
175 0 : return cppu::supportsService(this, rServiceName);
176 : }
177 :
178 1 : css::uno::Sequence< OUString > SAL_CALL LabeledDataSequence::getSupportedServiceNames()
179 : throw( css::uno::RuntimeException, std::exception )
180 : {
181 1 : return getSupportedServiceNames_Static();
182 : }
183 :
184 : } // namespace chart
185 :
186 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
187 3463 : com_sun_star_comp_chart2_LabeledDataSequence_get_implementation(css::uno::XComponentContext *context,
188 : css::uno::Sequence<css::uno::Any> const &)
189 : {
190 3463 : return cppu::acquire(new ::chart::LabeledDataSequence(context));
191 : }
192 :
193 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|