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 #ifndef _CHART_CACHEDDATASEQUENCE_HXX
24 #define _CHART_CACHEDDATASEQUENCE_HXX
25 
26 // helper classes
27 #include <cppuhelper/compbase7.hxx>
28 #include <comphelper/uno3.hxx>
29 #include <comphelper/broadcasthelper.hxx>
30 #include <comphelper/propertycontainer.hxx>
31 #include <comphelper/proparrhlp.hxx>
32 #include "ServiceMacros.hxx"
33 
34 // interfaces and types
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/lang/XInitialization.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #include <com/sun/star/uno/XComponentContext.hpp>
39 #include <com/sun/star/chart2/data/XDataSequence.hpp>
40 #include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
41 #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
42 #include <com/sun/star/util/XCloneable.hpp>
43 #include <com/sun/star/util/XModifyBroadcaster.hpp>
44 
45 #include <vector>
46 
47 // ____________________
48 namespace chart
49 {
50 
51 namespace impl
52 {
53 typedef ::cppu::WeakComponentImplHelper7<
54     ::com::sun::star::chart2::data::XDataSequence,
55     ::com::sun::star::chart2::data::XNumericalDataSequence,
56     ::com::sun::star::chart2::data::XTextualDataSequence,
57     ::com::sun::star::util::XCloneable,
58     ::com::sun::star::util::XModifyBroadcaster,
59     ::com::sun::star::lang::XInitialization,
60     ::com::sun::star::lang::XServiceInfo >
61     CachedDataSequence_Base;
62 }
63 
64 class CachedDataSequence :
65         public ::comphelper::OMutexAndBroadcastHelper,
66         public ::comphelper::OPropertyContainer,
67         public ::comphelper::OPropertyArrayUsageHelper< CachedDataSequence >,
68         public impl::CachedDataSequence_Base
69 {
70 public:
71     /** constructs an empty sequence
72      */
73     CachedDataSequence();
74 
75 	explicit CachedDataSequence(
76         const ::com::sun::star::uno::Reference<
77             ::com::sun::star::uno::XComponentContext > & xContext );
78 
79     /** creates a sequence and initializes it with the given string.  This is
80         especially useful for labels, which only have one element.
81      */
82 	explicit CachedDataSequence( const ::rtl::OUString & rSingleText );
83 
84     /// Copy CTOR
85     explicit CachedDataSequence( const CachedDataSequence & rSource );
86 
87 	virtual ~CachedDataSequence();
88 
89     /// establish methods for factory instatiation
90 	APPHELPER_SERVICE_FACTORY_HELPER( CachedDataSequence )
91     /// declare XServiceInfo methods
92     APPHELPER_XSERVICEINFO_DECL()
93 
94     /// merge XInterface implementations
95 	DECLARE_XINTERFACE()
96     /// merge XTypeProvider implementations
97 	DECLARE_XTYPEPROVIDER()
98 
99 protected:
100     // ____ XPropertySet ____
101     /// @see ::com::sun::star::beans::XPropertySet
102     virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo()
103         throw (::com::sun::star::uno::RuntimeException);
104     /// @see ::comphelper::OPropertySetHelper
105 	virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
106     /// @see ::comphelper::OPropertyArrayUsageHelper
107 	virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const;
108 
109     // ____ XDataSequence ____
110     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > SAL_CALL getData()
111         throw (::com::sun::star::uno::RuntimeException);
112     virtual ::rtl::OUString SAL_CALL getSourceRangeRepresentation()
113         throw (::com::sun::star::uno::RuntimeException);
114     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL generateLabel(
115         ::com::sun::star::chart2::data::LabelOrigin nLabelOrigin )
116         throw (::com::sun::star::uno::RuntimeException);
117     virtual ::sal_Int32 SAL_CALL getNumberFormatKeyByIndex( ::sal_Int32 nIndex )
118         throw (::com::sun::star::lang::IndexOutOfBoundsException,
119                ::com::sun::star::uno::RuntimeException);
120 
121     // ____ XNumericalDataSequence ____
122     /// @see ::com::sun::star::chart::data::XNumericalDataSequence
123     virtual ::com::sun::star::uno::Sequence< double > SAL_CALL getNumericalData() throw (::com::sun::star::uno::RuntimeException);
124 
125     // ____ XTextualDataSequence ____
126     /// @see ::com::sun::star::chart::data::XTextualDataSequence
127     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getTextualData() throw (::com::sun::star::uno::RuntimeException);
128 
129     // ____ XCloneable ____
130     virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone()
131         throw (::com::sun::star::uno::RuntimeException);
132 
133     // ____ XModifyBroadcaster ____
134     virtual void SAL_CALL addModifyListener(
135         const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener )
136         throw (::com::sun::star::uno::RuntimeException);
137     virtual void SAL_CALL removeModifyListener(
138         const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener )
139         throw (::com::sun::star::uno::RuntimeException);
140 
141     // ::com::sun::star::lang::XInitialization:
142     virtual void SAL_CALL initialize(const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > & aArguments)
143         throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::uno::Exception);
144 
145     // <properties>
146     sal_Int32                                       m_nNumberFormatKey;
147     ::rtl::OUString                                 m_sRole;
148     // </properties>
149 
150     enum DataType
151     {
152         NUMERICAL,
153         TEXTUAL,
154         MIXED
155     };
156 
157     /** This method registers all properties.  It should be called by all
158         constructors.
159      */
160     void registerProperties();
161 
162 private:
163     /** is used by interface method getNumericalData().
164      */
165     ::com::sun::star::uno::Sequence< double > Impl_getNumericalData() const;
166     /** is used by interface method getTextualData().
167      */
168     ::com::sun::star::uno::Sequence< ::rtl::OUString > Impl_getTextualData() const;
169     /** is used by interface method getData().
170      */
171     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > Impl_getMixedData() const;
172 
173 private:
174     enum DataType                                       m_eCurrentDataType;
175 
176     ::com::sun::star::uno::Sequence< double >           m_aNumericalSequence;
177     ::com::sun::star::uno::Sequence< ::rtl::OUString >  m_aTextualSequence;
178     ::com::sun::star::uno::Sequence<
179         ::com::sun::star::uno::Any >                    m_aMixedSequence;
180     ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >
181         m_xModifyEventForwarder;
182 };
183 
184 }  // namespace chart
185 
186 
187 // _CHART_CACHEDDATASEQUENCE_HXX
188 #endif
189