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