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
27 #include "LabeledDataSequence.hxx"
28 #include "ModifyListenerHelper.hxx"
29 #include "macros.hxx"
30
31 using namespace ::com::sun::star;
32
33 using ::com::sun::star::uno::Reference;
34 using ::com::sun::star::uno::Sequence;
35 using ::rtl::OUString;
36
37 namespace chart
38 {
39
LabeledDataSequence(const Reference<uno::XComponentContext> & xContext)40 LabeledDataSequence::LabeledDataSequence( const Reference< uno::XComponentContext > & xContext ) :
41 m_xContext( xContext ),
42 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
43 {}
44
LabeledDataSequence(const uno::Reference<chart2::data::XDataSequence> & rValues)45 LabeledDataSequence::LabeledDataSequence(
46 const uno::Reference< chart2::data::XDataSequence > & rValues ) :
47 m_xData( rValues ),
48 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
49 {
50 ModifyListenerHelper::addListener( m_xData, m_xModifyEventForwarder );
51 }
52
LabeledDataSequence(const uno::Reference<chart2::data::XDataSequence> & rValues,const uno::Reference<chart2::data::XDataSequence> & rLabel)53 LabeledDataSequence::LabeledDataSequence(
54 const uno::Reference< chart2::data::XDataSequence > & rValues,
55 const uno::Reference< chart2::data::XDataSequence > & rLabel ) :
56 m_xData( rValues ),
57 m_xLabel( rLabel ),
58 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
59 {
60 ModifyListenerHelper::addListener( m_xData, m_xModifyEventForwarder );
61 ModifyListenerHelper::addListener( m_xLabel, m_xModifyEventForwarder );
62 }
63
~LabeledDataSequence()64 LabeledDataSequence::~LabeledDataSequence()
65 {
66 if( m_xModifyEventForwarder.is())
67 {
68 if( m_xData.is())
69 ModifyListenerHelper::removeListener( m_xData, m_xModifyEventForwarder );
70 if( m_xLabel.is())
71 ModifyListenerHelper::removeListener( m_xLabel, m_xModifyEventForwarder );
72 }
73 }
74
75 // ____ XLabeledDataSequence ____
getValues()76 uno::Reference< chart2::data::XDataSequence > SAL_CALL LabeledDataSequence::getValues()
77 throw (uno::RuntimeException)
78 {
79 return m_xData;
80 }
81
setValues(const uno::Reference<chart2::data::XDataSequence> & xSequence)82 void SAL_CALL LabeledDataSequence::setValues(
83 const uno::Reference< chart2::data::XDataSequence >& xSequence )
84 throw (uno::RuntimeException)
85 {
86 if( m_xData != xSequence )
87 {
88 ModifyListenerHelper::removeListener( m_xData, m_xModifyEventForwarder );
89 m_xData = xSequence;
90 ModifyListenerHelper::addListener( m_xData, m_xModifyEventForwarder );
91 }
92 }
93
getLabel()94 uno::Reference< chart2::data::XDataSequence > SAL_CALL LabeledDataSequence::getLabel()
95 throw (uno::RuntimeException)
96 {
97 return m_xLabel;
98 }
99
setLabel(const uno::Reference<chart2::data::XDataSequence> & xSequence)100 void SAL_CALL LabeledDataSequence::setLabel(
101 const uno::Reference< chart2::data::XDataSequence >& xSequence )
102 throw (uno::RuntimeException)
103 {
104 if( m_xLabel != xSequence )
105 {
106 ModifyListenerHelper::removeListener( m_xLabel, m_xModifyEventForwarder );
107 m_xLabel = xSequence;
108 ModifyListenerHelper::addListener( m_xLabel, m_xModifyEventForwarder );
109 }
110 }
111
112 // ____ XCloneable ____
createClone()113 uno::Reference< util::XCloneable > SAL_CALL LabeledDataSequence::createClone()
114 throw (uno::RuntimeException)
115 {
116 uno::Reference< chart2::data::XDataSequence > xNewValues( m_xData );
117 uno::Reference< chart2::data::XDataSequence > xNewLabel( m_xLabel );
118
119 uno::Reference< util::XCloneable > xLabelCloneable( m_xLabel, uno::UNO_QUERY );
120 if( xLabelCloneable.is())
121 xNewLabel.set( xLabelCloneable->createClone(), uno::UNO_QUERY );
122
123 uno::Reference< util::XCloneable > xValuesCloneable( m_xData, uno::UNO_QUERY );
124 if( xValuesCloneable.is())
125 xNewValues.set( xValuesCloneable->createClone(), uno::UNO_QUERY );
126
127 return uno::Reference< util::XCloneable >(
128 new LabeledDataSequence( xNewValues, xNewLabel ) );
129 }
130
131 // ____ XModifyBroadcaster ____
addModifyListener(const Reference<util::XModifyListener> & aListener)132 void SAL_CALL LabeledDataSequence::addModifyListener( const Reference< util::XModifyListener >& aListener )
133 throw (uno::RuntimeException)
134 {
135 try
136 {
137 Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
138 xBroadcaster->addModifyListener( aListener );
139 }
140 catch( const uno::Exception & ex )
141 {
142 ASSERT_EXCEPTION( ex );
143 }
144 }
145
removeModifyListener(const Reference<util::XModifyListener> & aListener)146 void SAL_CALL LabeledDataSequence::removeModifyListener( const Reference< util::XModifyListener >& aListener )
147 throw (uno::RuntimeException)
148 {
149 try
150 {
151 Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
152 xBroadcaster->removeModifyListener( aListener );
153 }
154 catch( const uno::Exception & ex )
155 {
156 ASSERT_EXCEPTION( ex );
157 }
158 }
159
160 // ================================================================================
161
getSupportedServiceNames_Static()162 Sequence< OUString > LabeledDataSequence::getSupportedServiceNames_Static()
163 {
164 Sequence< OUString > aServices( 1 );
165 aServices[ 0 ] = C2U( "com.sun.star.chart2.data.LabeledDataSequence" );
166 return aServices;
167 }
168
169 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
170 APPHELPER_XSERVICEINFO_IMPL( LabeledDataSequence,
171 C2U( "com.sun.star.comp.chart2.LabeledDataSequence" ))
172
173 // ================================================================================
174
175 } // namespace chart
176