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 CHART2_INTERNALDATAPROVIDER_HXX 28 #define CHART2_INTERNALDATAPROVIDER_HXX 29 30 #include "InternalData.hxx" 31 32 #include <com/sun/star/lang/XServiceInfo.hpp> 33 #include <com/sun/star/chart/XDateCategories.hpp> 34 #include <com/sun/star/chart2/XAnyDescriptionAccess.hpp> 35 #include <com/sun/star/chart2/data/XDataProvider.hpp> 36 #include <com/sun/star/chart2/XInternalDataProvider.hpp> 37 #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp> 38 #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp> 39 #include <com/sun/star/chart2/XChartDocument.hpp> 40 #include <com/sun/star/lang/XInitialization.hpp> 41 #include <com/sun/star/util/XCloneable.hpp> 42 #include <cppuhelper/implbase7.hxx> 43 #include "ServiceMacros.hxx" 44 45 #include "CachedDataSequence.hxx" 46 47 #include <map> 48 #include <memory> 49 50 namespace chart 51 { 52 53 namespace impl 54 { 55 56 typedef ::cppu::WeakImplHelper7< 57 ::com::sun::star::chart2::XInternalDataProvider, 58 ::com::sun::star::chart2::data::XRangeXMLConversion, 59 ::com::sun::star::chart2::XAnyDescriptionAccess, 60 ::com::sun::star::chart::XDateCategories, 61 ::com::sun::star::util::XCloneable, 62 ::com::sun::star::lang::XInitialization, 63 ::com::sun::star::lang::XServiceInfo > 64 InternalDataProvider_Base; 65 } 66 67 /** Data provider that handles data internally. This is used for charts with 68 their own data. 69 70 <p>The format for single ranges is "categories|label n|n" where n is a 71 non-negative number. Meaning return all categories, the label of sequence n, 72 or the data of sequence n.</p> 73 74 <p>The format for a complete range is "all". (Do we need more than 75 that?)</p> 76 */ 77 class InternalDataProvider : 78 public impl::InternalDataProvider_Base 79 { 80 public: 81 explicit InternalDataProvider(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > & _xContext); 82 explicit InternalDataProvider( const ::com::sun::star::uno::Reference< 83 ::com::sun::star::chart2::XChartDocument > & xChartDoc, bool bConnectToModel ); 84 explicit InternalDataProvider( const InternalDataProvider & rOther ); 85 virtual ~InternalDataProvider(); 86 87 void createDefaultData(); 88 89 /// declare XServiceInfo methods 90 APPHELPER_XSERVICEINFO_DECL() 91 APPHELPER_SERVICE_FACTORY_HELPER(InternalDataProvider) 92 93 // ____ XInternalDataProvider ____ 94 virtual ::sal_Bool SAL_CALL hasDataByRangeRepresentation( const ::rtl::OUString& aRange ) 95 throw (::com::sun::star::uno::RuntimeException); 96 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > SAL_CALL 97 getDataByRangeRepresentation( const ::rtl::OUString& aRange ) 98 throw (::com::sun::star::uno::RuntimeException); 99 virtual void SAL_CALL setDataByRangeRepresentation( 100 const ::rtl::OUString& aRange, 101 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aNewData ) 102 throw (::com::sun::star::uno::RuntimeException); 103 virtual void SAL_CALL insertSequence( ::sal_Int32 nAfterIndex ) 104 throw (::com::sun::star::uno::RuntimeException); 105 virtual void SAL_CALL deleteSequence( ::sal_Int32 nAtIndex ) 106 throw (::com::sun::star::uno::RuntimeException); 107 virtual void SAL_CALL appendSequence() 108 throw (::com::sun::star::uno::RuntimeException); 109 virtual void SAL_CALL insertComplexCategoryLevel( ::sal_Int32 nLevel ) 110 throw (::com::sun::star::uno::RuntimeException); 111 virtual void SAL_CALL deleteComplexCategoryLevel( ::sal_Int32 nLevel ) 112 throw (::com::sun::star::uno::RuntimeException); 113 virtual void SAL_CALL insertDataPointForAllSequences( ::sal_Int32 nAfterIndex ) 114 throw (::com::sun::star::uno::RuntimeException); 115 virtual void SAL_CALL deleteDataPointForAllSequences( ::sal_Int32 nAtIndex ) 116 throw (::com::sun::star::uno::RuntimeException); 117 virtual void SAL_CALL swapDataPointWithNextOneForAllSequences( ::sal_Int32 nAtIndex ) 118 throw (::com::sun::star::uno::RuntimeException); 119 virtual void SAL_CALL registerDataSequenceForChanges( 120 const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSequence >& xSeq ) 121 throw (::com::sun::star::uno::RuntimeException); 122 123 // ____ XDataProvider (base of XInternalDataProvider) ____ 124 virtual ::sal_Bool SAL_CALL createDataSourcePossible( 125 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments ) 126 throw (::com::sun::star::uno::RuntimeException); 127 virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource > SAL_CALL createDataSource( 128 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments ) 129 throw (::com::sun::star::lang::IllegalArgumentException, 130 ::com::sun::star::uno::RuntimeException); 131 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL detectArguments( 132 const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >& xDataSource ) 133 throw (::com::sun::star::uno::RuntimeException); 134 virtual ::sal_Bool SAL_CALL createDataSequenceByRangeRepresentationPossible( 135 const ::rtl::OUString& aRangeRepresentation ) 136 throw (::com::sun::star::uno::RuntimeException); 137 virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSequence > SAL_CALL createDataSequenceByRangeRepresentation( 138 const ::rtl::OUString& aRangeRepresentation ) 139 throw (::com::sun::star::lang::IllegalArgumentException, 140 ::com::sun::star::uno::RuntimeException); 141 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XRangeSelection > SAL_CALL getRangeSelection() 142 throw (::com::sun::star::uno::RuntimeException); 143 144 // ____ XRangeXMLConversion ____ 145 virtual ::rtl::OUString SAL_CALL convertRangeToXML( 146 const ::rtl::OUString& aRangeRepresentation ) 147 throw (::com::sun::star::lang::IllegalArgumentException, 148 ::com::sun::star::uno::RuntimeException); 149 virtual ::rtl::OUString SAL_CALL convertRangeFromXML( 150 const ::rtl::OUString& aXMLRange ) 151 throw (::com::sun::star::lang::IllegalArgumentException, 152 ::com::sun::star::uno::RuntimeException); 153 154 // ____ XDateCategories ____ 155 virtual ::com::sun::star::uno::Sequence< double > SAL_CALL getDateCategories() throw (::com::sun::star::uno::RuntimeException); 156 virtual void SAL_CALL setDateCategories( const ::com::sun::star::uno::Sequence< double >& rDates ) throw (::com::sun::star::uno::RuntimeException); 157 158 // ____ XAnyDescriptionAccess ____ 159 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > > SAL_CALL 160 getAnyRowDescriptions() throw (::com::sun::star::uno::RuntimeException); 161 virtual void SAL_CALL setAnyRowDescriptions( 162 const ::com::sun::star::uno::Sequence< 163 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& aRowDescriptions ) 164 throw (::com::sun::star::uno::RuntimeException); 165 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > > SAL_CALL 166 getAnyColumnDescriptions() throw (::com::sun::star::uno::RuntimeException); 167 virtual void SAL_CALL setAnyColumnDescriptions( 168 const ::com::sun::star::uno::Sequence< 169 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& aColumnDescriptions ) 170 throw (::com::sun::star::uno::RuntimeException); 171 172 // ____ XComplexDescriptionAccess (base of XAnyDescriptionAccess) ____ 173 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > SAL_CALL 174 getComplexRowDescriptions() throw (::com::sun::star::uno::RuntimeException); 175 virtual void SAL_CALL setComplexRowDescriptions( 176 const ::com::sun::star::uno::Sequence< 177 ::com::sun::star::uno::Sequence< ::rtl::OUString > >& aRowDescriptions ) 178 throw (::com::sun::star::uno::RuntimeException); 179 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > SAL_CALL 180 getComplexColumnDescriptions() throw (::com::sun::star::uno::RuntimeException); 181 virtual void SAL_CALL setComplexColumnDescriptions( 182 const ::com::sun::star::uno::Sequence< 183 ::com::sun::star::uno::Sequence< ::rtl::OUString > >& aColumnDescriptions ) 184 throw (::com::sun::star::uno::RuntimeException); 185 186 // ____ XChartDataArray (base of XComplexDescriptionAccess) ____ 187 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > > SAL_CALL getData() 188 throw (::com::sun::star::uno::RuntimeException); 189 virtual void SAL_CALL setData( 190 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >& aData ) 191 throw (::com::sun::star::uno::RuntimeException); 192 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getRowDescriptions() 193 throw (::com::sun::star::uno::RuntimeException); 194 virtual void SAL_CALL setRowDescriptions( 195 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aRowDescriptions ) 196 throw (::com::sun::star::uno::RuntimeException); 197 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getColumnDescriptions() 198 throw (::com::sun::star::uno::RuntimeException); 199 virtual void SAL_CALL setColumnDescriptions( 200 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aColumnDescriptions ) 201 throw (::com::sun::star::uno::RuntimeException); 202 203 // ____ XChartData (base of XChartDataArray) ____ 204 virtual void SAL_CALL addChartDataChangeEventListener( 205 const ::com::sun::star::uno::Reference< ::com::sun::star::chart::XChartDataChangeEventListener >& aListener ) 206 throw (::com::sun::star::uno::RuntimeException); 207 virtual void SAL_CALL removeChartDataChangeEventListener( 208 const ::com::sun::star::uno::Reference< ::com::sun::star::chart::XChartDataChangeEventListener >& aListener ) 209 throw (::com::sun::star::uno::RuntimeException); 210 virtual double SAL_CALL getNotANumber() 211 throw (::com::sun::star::uno::RuntimeException); 212 virtual ::sal_Bool SAL_CALL isNotANumber( 213 double nNumber ) 214 throw (::com::sun::star::uno::RuntimeException); 215 216 // ____ XCloneable ____ 217 virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone() 218 throw (::com::sun::star::uno::RuntimeException); 219 // ::com::sun::star::lang::XInitialization: 220 virtual void SAL_CALL initialize(const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > & aArguments) 221 throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::uno::Exception); 222 223 private: 224 void lcl_addDataSequenceToMap( 225 const ::rtl::OUString & rRangeRepresentation, 226 const ::com::sun::star::uno::Reference< 227 ::com::sun::star::chart2::data::XDataSequence > & xSequence ); 228 229 ::com::sun::star::uno::Reference< 230 ::com::sun::star::chart2::data::XDataSequence > 231 lcl_createDataSequenceAndAddToMap( const ::rtl::OUString & rRangeRepresentation, 232 const ::rtl::OUString & rRole ); 233 ::com::sun::star::uno::Reference< 234 ::com::sun::star::chart2::data::XDataSequence > 235 lcl_createDataSequenceAndAddToMap( const ::rtl::OUString & rRangeRepresentation ); 236 237 void lcl_deleteMapReferences( const ::rtl::OUString & rRangeRepresentation ); 238 239 void lcl_adaptMapReferences( 240 const ::rtl::OUString & rOldRangeRepresentation, 241 const ::rtl::OUString & rNewRangeRepresentation ); 242 243 void lcl_increaseMapReferences( sal_Int32 nBegin, sal_Int32 nEnd ); 244 void lcl_decreaseMapReferences( sal_Int32 nBegin, sal_Int32 nEnd ); 245 246 typedef ::std::multimap< ::rtl::OUString, 247 ::com::sun::star::uno::WeakReference< ::com::sun::star::chart2::data::XDataSequence > > 248 tSequenceMap; 249 typedef ::std::pair< tSequenceMap::iterator, tSequenceMap::iterator > tSequenceMapRange; 250 typedef ::std::pair< tSequenceMap::const_iterator, tSequenceMap::const_iterator > tConstSequenceMapRange; 251 252 /** cache for all sequences that have been returned. 253 254 If the range-representation of a sequence changes and it is still 255 referred to by some component (weak reference is valid), the range will 256 be adapted. 257 */ 258 tSequenceMap m_aSequenceMap; 259 InternalData m_aInternalData; 260 bool m_bDataInColumns; 261 }; 262 263 } // namespace chart 264 265 // CHART2_INTERNALDATAPROVIDER_HXX 266 #endif 267