1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 
31 #include "LabeledDataSequence.hxx"
32 #include "ModifyListenerHelper.hxx"
33 #include "macros.hxx"
34 
35 using namespace ::com::sun::star;
36 
37 using ::com::sun::star::uno::Reference;
38 using ::com::sun::star::uno::Sequence;
39 using ::rtl::OUString;
40 
41 namespace chart
42 {
43 
44 LabeledDataSequence::LabeledDataSequence( const Reference< uno::XComponentContext > & xContext ) :
45         m_xContext( xContext ),
46         m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
47 {}
48 
49 LabeledDataSequence::LabeledDataSequence(
50     const uno::Reference< chart2::data::XDataSequence > & rValues ) :
51         m_xData( rValues ),
52         m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
53 {
54     ModifyListenerHelper::addListener( m_xData, m_xModifyEventForwarder );
55 }
56 
57 LabeledDataSequence::LabeledDataSequence(
58     const uno::Reference< chart2::data::XDataSequence > & rValues,
59     const uno::Reference< chart2::data::XDataSequence > & rLabel ) :
60         m_xData( rValues ),
61         m_xLabel( rLabel ),
62         m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
63 {
64     ModifyListenerHelper::addListener( m_xData, m_xModifyEventForwarder );
65     ModifyListenerHelper::addListener( m_xLabel, m_xModifyEventForwarder );
66 }
67 
68 LabeledDataSequence::~LabeledDataSequence()
69 {
70     if( m_xModifyEventForwarder.is())
71     {
72         if( m_xData.is())
73             ModifyListenerHelper::removeListener( m_xData, m_xModifyEventForwarder );
74         if( m_xLabel.is())
75             ModifyListenerHelper::removeListener( m_xLabel, m_xModifyEventForwarder );
76     }
77 }
78 
79 // ____ XLabeledDataSequence ____
80 uno::Reference< chart2::data::XDataSequence > SAL_CALL LabeledDataSequence::getValues()
81     throw (uno::RuntimeException)
82 {
83     return m_xData;
84 }
85 
86 void SAL_CALL LabeledDataSequence::setValues(
87     const uno::Reference< chart2::data::XDataSequence >& xSequence )
88     throw (uno::RuntimeException)
89 {
90     if( m_xData != xSequence )
91     {
92         ModifyListenerHelper::removeListener( m_xData, m_xModifyEventForwarder );
93         m_xData = xSequence;
94         ModifyListenerHelper::addListener( m_xData, m_xModifyEventForwarder );
95     }
96 }
97 
98 uno::Reference< chart2::data::XDataSequence > SAL_CALL LabeledDataSequence::getLabel()
99     throw (uno::RuntimeException)
100 {
101     return m_xLabel;
102 }
103 
104 void SAL_CALL LabeledDataSequence::setLabel(
105     const uno::Reference< chart2::data::XDataSequence >& xSequence )
106     throw (uno::RuntimeException)
107 {
108     if( m_xLabel != xSequence )
109     {
110         ModifyListenerHelper::removeListener( m_xLabel, m_xModifyEventForwarder );
111         m_xLabel = xSequence;
112         ModifyListenerHelper::addListener( m_xLabel, m_xModifyEventForwarder );
113     }
114 }
115 
116 // ____ XCloneable ____
117 uno::Reference< util::XCloneable > SAL_CALL LabeledDataSequence::createClone()
118     throw (uno::RuntimeException)
119 {
120     uno::Reference< chart2::data::XDataSequence > xNewValues( m_xData );
121     uno::Reference< chart2::data::XDataSequence > xNewLabel( m_xLabel );
122 
123     uno::Reference< util::XCloneable > xLabelCloneable( m_xLabel, uno::UNO_QUERY );
124     if( xLabelCloneable.is())
125         xNewLabel.set( xLabelCloneable->createClone(), uno::UNO_QUERY );
126 
127     uno::Reference< util::XCloneable > xValuesCloneable( m_xData, uno::UNO_QUERY );
128     if( xValuesCloneable.is())
129         xNewValues.set( xValuesCloneable->createClone(), uno::UNO_QUERY );
130 
131     return uno::Reference< util::XCloneable >(
132         new LabeledDataSequence( xNewValues, xNewLabel ) );
133 }
134 
135 // ____ XModifyBroadcaster ____
136 void SAL_CALL LabeledDataSequence::addModifyListener( const Reference< util::XModifyListener >& aListener )
137     throw (uno::RuntimeException)
138 {
139     try
140     {
141         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
142         xBroadcaster->addModifyListener( aListener );
143     }
144     catch( const uno::Exception & ex )
145     {
146         ASSERT_EXCEPTION( ex );
147     }
148 }
149 
150 void SAL_CALL LabeledDataSequence::removeModifyListener( const Reference< util::XModifyListener >& aListener )
151     throw (uno::RuntimeException)
152 {
153     try
154     {
155         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
156         xBroadcaster->removeModifyListener( aListener );
157     }
158     catch( const uno::Exception & ex )
159     {
160         ASSERT_EXCEPTION( ex );
161     }
162 }
163 
164 // ================================================================================
165 
166 Sequence< OUString > LabeledDataSequence::getSupportedServiceNames_Static()
167 {
168     Sequence< OUString > aServices( 1 );
169     aServices[ 0 ] = C2U( "com.sun.star.chart2.data.LabeledDataSequence" );
170     return aServices;
171 }
172 
173 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
174 APPHELPER_XSERVICEINFO_IMPL( LabeledDataSequence,
175                              C2U( "com.sun.star.comp.chart2.LabeledDataSequence" ))
176 
177 // ================================================================================
178 
179 } //  namespace chart
180