1*38d50f7bSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*38d50f7bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*38d50f7bSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*38d50f7bSAndrew Rist * distributed with this work for additional information 6*38d50f7bSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*38d50f7bSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*38d50f7bSAndrew Rist * "License"); you may not use this file except in compliance 9*38d50f7bSAndrew Rist * with the License. You may obtain a copy of the License at 10*38d50f7bSAndrew Rist * 11*38d50f7bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*38d50f7bSAndrew Rist * 13*38d50f7bSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*38d50f7bSAndrew Rist * software distributed under the License is distributed on an 15*38d50f7bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*38d50f7bSAndrew Rist * KIND, either express or implied. See the License for the 17*38d50f7bSAndrew Rist * specific language governing permissions and limitations 18*38d50f7bSAndrew Rist * under the License. 19*38d50f7bSAndrew Rist * 20*38d50f7bSAndrew Rist *************************************************************/ 21*38d50f7bSAndrew Rist 22*38d50f7bSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SC_DPOBJECT_HXX 25cdf0e10cSrcweir #define SC_DPOBJECT_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "scdllapi.h" 28cdf0e10cSrcweir #include "global.hxx" 29cdf0e10cSrcweir #include "address.hxx" 30cdf0e10cSrcweir #include "collect.hxx" 31cdf0e10cSrcweir #include "dpoutput.hxx" 32cdf0e10cSrcweir #include "pivot.hxx" 33cdf0e10cSrcweir #include <com/sun/star/sheet/XDimensionsSupplier.hpp> 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include <boost/shared_ptr.hpp> 36cdf0e10cSrcweir 37cdf0e10cSrcweir //------------------------------------------------------------------ 38cdf0e10cSrcweir 39cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace sheet { 40cdf0e10cSrcweir 41cdf0e10cSrcweir struct DataPilotTablePositionData; 42cdf0e10cSrcweir struct DataPilotTableHeaderData; 43cdf0e10cSrcweir 44cdf0e10cSrcweir }}}} 45cdf0e10cSrcweir 46cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace sheet { 47cdf0e10cSrcweir struct DataPilotFieldFilter; 48cdf0e10cSrcweir }}}} 49cdf0e10cSrcweir 50cdf0e10cSrcweir class Rectangle; 51cdf0e10cSrcweir class SvStream; 52cdf0e10cSrcweir class ScDPSaveData; 53cdf0e10cSrcweir class ScDPOutput; 54cdf0e10cSrcweir class ScPivot; 55cdf0e10cSrcweir class ScPivotCollection; 56cdf0e10cSrcweir struct ScPivotParam; 57cdf0e10cSrcweir struct ScImportSourceDesc; 58cdf0e10cSrcweir struct ScSheetSourceDesc; 59cdf0e10cSrcweir class ScStrCollection; 60cdf0e10cSrcweir class TypedScStrCollection; 61cdf0e10cSrcweir struct PivotField; 62cdf0e10cSrcweir class ScDPCacheTable; 63cdf0e10cSrcweir class ScDPTableData; 64cdf0e10cSrcweir 65cdf0e10cSrcweir struct ScDPServiceDesc 66cdf0e10cSrcweir { 67cdf0e10cSrcweir String aServiceName; 68cdf0e10cSrcweir String aParSource; 69cdf0e10cSrcweir String aParName; 70cdf0e10cSrcweir String aParUser; 71cdf0e10cSrcweir String aParPass; 72cdf0e10cSrcweir ScDPServiceDescScDPServiceDesc73cdf0e10cSrcweir ScDPServiceDesc( const String& rServ, const String& rSrc, const String& rNam, 74cdf0e10cSrcweir const String& rUser, const String& rPass ) : 75cdf0e10cSrcweir aServiceName( rServ ), aParSource( rSrc ), aParName( rNam ), 76cdf0e10cSrcweir aParUser( rUser ), aParPass( rPass ) { } 77cdf0e10cSrcweir operator ==ScDPServiceDesc78cdf0e10cSrcweir sal_Bool operator== ( const ScDPServiceDesc& rOther ) const 79cdf0e10cSrcweir { return aServiceName == rOther.aServiceName && 80cdf0e10cSrcweir aParSource == rOther.aParSource && 81cdf0e10cSrcweir aParName == rOther.aParName && 82cdf0e10cSrcweir aParUser == rOther.aParUser && 83cdf0e10cSrcweir aParPass == rOther.aParPass; } 84cdf0e10cSrcweir }; 85cdf0e10cSrcweir 86cdf0e10cSrcweir 87cdf0e10cSrcweir class SC_DLLPUBLIC ScDPObject : public ScDataObject 88cdf0e10cSrcweir { 89cdf0e10cSrcweir private: 90cdf0e10cSrcweir ScDocument* pDoc; 91cdf0e10cSrcweir // settings 92cdf0e10cSrcweir ScDPSaveData* pSaveData; 93cdf0e10cSrcweir String aTableName; 94cdf0e10cSrcweir String aTableTag; 95cdf0e10cSrcweir ScRange aOutRange; 96cdf0e10cSrcweir ScSheetSourceDesc* pSheetDesc; // for sheet data 97cdf0e10cSrcweir ScImportSourceDesc* pImpDesc; // for database data 98cdf0e10cSrcweir ScDPServiceDesc* pServDesc; // for external service 99cdf0e10cSrcweir ::boost::shared_ptr<ScDPTableData> mpTableData; 100cdf0e10cSrcweir // cached data 101cdf0e10cSrcweir com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier> xSource; 102cdf0e10cSrcweir ScDPOutput* pOutput; 103cdf0e10cSrcweir sal_Bool bSettingsChanged; 104cdf0e10cSrcweir sal_Bool bAlive; // sal_False if only used to hold settings 105cdf0e10cSrcweir sal_Bool bAllowMove; 106cdf0e10cSrcweir long nHeaderRows; // page fields plus filter button 107cdf0e10cSrcweir bool mbHeaderLayout; // sal_True : grid, sal_False : standard 108cdf0e10cSrcweir 109cdf0e10cSrcweir 110cdf0e10cSrcweir SC_DLLPRIVATE ScDPTableData* GetTableData(); 111cdf0e10cSrcweir SC_DLLPRIVATE void CreateObjects(); 112cdf0e10cSrcweir SC_DLLPRIVATE void CreateOutput(); 113cdf0e10cSrcweir sal_Bool bRefresh; 114cdf0e10cSrcweir long mnCacheId; 115cdf0e10cSrcweir bool mbCreatingTableData; 116cdf0e10cSrcweir 117cdf0e10cSrcweir public: 118cdf0e10cSrcweir // Wang Xu Ming -- 2009-8-17 119cdf0e10cSrcweir // DataPilot Migration - Cache&&Performance SetRefresh()120cdf0e10cSrcweir inline void SetRefresh() { bRefresh = sal_True; } 121cdf0e10cSrcweir const ScDPTableDataCache* GetCache() const; 122cdf0e10cSrcweir long GetCacheId() const; 123cdf0e10cSrcweir void SetCacheId( long nCacheId ); 124cdf0e10cSrcweir sal_uLong RefreshCache(); 125cdf0e10cSrcweir // End Comments 126cdf0e10cSrcweir ScDPObject( ScDocument* pD ); 127cdf0e10cSrcweir ScDPObject(const ScDPObject& r); 128cdf0e10cSrcweir virtual ~ScDPObject(); 129cdf0e10cSrcweir 130cdf0e10cSrcweir virtual ScDataObject* Clone() const; 131cdf0e10cSrcweir 132cdf0e10cSrcweir void SetAlive(sal_Bool bSet); 133cdf0e10cSrcweir void SetAllowMove(sal_Bool bSet); 134cdf0e10cSrcweir 135cdf0e10cSrcweir void InvalidateData(); 136cdf0e10cSrcweir void InvalidateSource(); 137cdf0e10cSrcweir 138cdf0e10cSrcweir 139cdf0e10cSrcweir void Output( const ScAddress& rPos ); 140cdf0e10cSrcweir ScRange GetNewOutputRange( sal_Bool& rOverflow ); 141cdf0e10cSrcweir const ScRange GetOutputRangeByType( sal_Int32 nType ); 142cdf0e10cSrcweir 143cdf0e10cSrcweir void SetSaveData(const ScDPSaveData& rData); GetSaveData() const144cdf0e10cSrcweir ScDPSaveData* GetSaveData() const { return pSaveData; } 145cdf0e10cSrcweir 146cdf0e10cSrcweir void SetOutRange(const ScRange& rRange); GetOutRange() const147cdf0e10cSrcweir const ScRange& GetOutRange() const { return aOutRange; } 148cdf0e10cSrcweir 149cdf0e10cSrcweir void SetHeaderLayout(bool bUseGrid); 150cdf0e10cSrcweir bool GetHeaderLayout() const; 151cdf0e10cSrcweir 152cdf0e10cSrcweir void SetSheetDesc(const ScSheetSourceDesc& rDesc, bool bFromRefUpdate = false); 153cdf0e10cSrcweir void SetImportDesc(const ScImportSourceDesc& rDesc); 154cdf0e10cSrcweir void SetServiceData(const ScDPServiceDesc& rDesc); 155cdf0e10cSrcweir 156cdf0e10cSrcweir void WriteSourceDataTo( ScDPObject& rDest ) const; 157cdf0e10cSrcweir void WriteTempDataTo( ScDPObject& rDest ) const; 158cdf0e10cSrcweir GetSheetDesc() const159cdf0e10cSrcweir const ScSheetSourceDesc* GetSheetDesc() const { return pSheetDesc; } GetImportSourceDesc() const160cdf0e10cSrcweir const ScImportSourceDesc* GetImportSourceDesc() const { return pImpDesc; } GetDPServiceDesc() const161cdf0e10cSrcweir const ScDPServiceDesc* GetDPServiceDesc() const { return pServDesc; } 162cdf0e10cSrcweir 163cdf0e10cSrcweir com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier> GetSource(); 164cdf0e10cSrcweir 165cdf0e10cSrcweir sal_Bool IsSheetData() const; IsImportData() const166cdf0e10cSrcweir sal_Bool IsImportData() const { return(pImpDesc != NULL); } IsServiceData() const167cdf0e10cSrcweir sal_Bool IsServiceData() const { return(pServDesc != NULL); } 168cdf0e10cSrcweir 169cdf0e10cSrcweir void SetName(const String& rNew); GetName() const170cdf0e10cSrcweir const String& GetName() const { return aTableName; } 171cdf0e10cSrcweir void SetTag(const String& rNew); GetTag() const172cdf0e10cSrcweir const String& GetTag() const { return aTableTag; } 173cdf0e10cSrcweir 174cdf0e10cSrcweir /** 175cdf0e10cSrcweir * Data description cell displays the description of a data dimension if 176cdf0e10cSrcweir * and only if there is only one data dimension. It's usually located at 177cdf0e10cSrcweir * the upper-left corner of the table output. 178cdf0e10cSrcweir */ 179cdf0e10cSrcweir bool IsDataDescriptionCell(const ScAddress& rPos); 180cdf0e10cSrcweir 181cdf0e10cSrcweir bool IsDimNameInUse(const ::rtl::OUString& rName) const; 182cdf0e10cSrcweir String GetDimName( long nDim, sal_Bool& rIsDataLayout, sal_Int32* pFlags = NULL ); 183cdf0e10cSrcweir sal_Bool IsDuplicated( long nDim ); 184cdf0e10cSrcweir long GetDimCount(); 185cdf0e10cSrcweir void GetHeaderPositionData(const ScAddress& rPos, ::com::sun::star::sheet::DataPilotTableHeaderData& rData); 186cdf0e10cSrcweir long GetHeaderDim( const ScAddress& rPos, sal_uInt16& rOrient ); 187cdf0e10cSrcweir sal_Bool GetHeaderDrag( const ScAddress& rPos, sal_Bool bMouseLeft, sal_Bool bMouseTop, 188cdf0e10cSrcweir long nDragDim, 189cdf0e10cSrcweir Rectangle& rPosRect, sal_uInt16& rOrient, long& rDimPos ); 190cdf0e10cSrcweir sal_Bool IsFilterButton( const ScAddress& rPos ); 191cdf0e10cSrcweir 192cdf0e10cSrcweir sal_Bool GetPivotData( ScDPGetPivotDataField& rTarget, /* returns result */ 193cdf0e10cSrcweir const std::vector< ScDPGetPivotDataField >& rFilters ); 194cdf0e10cSrcweir sal_Bool ParseFilters( ScDPGetPivotDataField& rTarget, 195cdf0e10cSrcweir std::vector< ScDPGetPivotDataField >& rFilters, 196cdf0e10cSrcweir const String& rFilterList ); 197cdf0e10cSrcweir 198cdf0e10cSrcweir void GetMemberResultNames( ScStrCollection& rNames, long nDimension ); 199cdf0e10cSrcweir 200cdf0e10cSrcweir void FillPageList( TypedScStrCollection& rStrings, long nField ); 201cdf0e10cSrcweir 202cdf0e10cSrcweir void ToggleDetails(const ::com::sun::star::sheet::DataPilotTableHeaderData& rElemDesc, ScDPObject* pDestObj); 203cdf0e10cSrcweir 204cdf0e10cSrcweir sal_Bool FillOldParam(ScPivotParam& rParam) const; 205cdf0e10cSrcweir sal_Bool FillLabelData(ScPivotParam& rParam); 206cdf0e10cSrcweir void InitFromOldPivot(const ScPivot& rOld, ScDocument* pDoc, sal_Bool bSetSource); 207cdf0e10cSrcweir 208cdf0e10cSrcweir sal_Bool GetHierarchiesNA( sal_Int32 nDim, com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& xHiers ); 209cdf0e10cSrcweir sal_Bool GetHierarchies( sal_Int32 nDim, com::sun::star::uno::Sequence< rtl::OUString >& rHiers ); 210cdf0e10cSrcweir 211cdf0e10cSrcweir sal_Int32 GetUsedHierarchy( sal_Int32 nDim ); 212cdf0e10cSrcweir 213cdf0e10cSrcweir sal_Bool GetMembersNA( sal_Int32 nDim, com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& xMembers ); 214cdf0e10cSrcweir sal_Bool GetMembersNA( sal_Int32 nDim, sal_Int32 nHier, com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& xMembers ); 215cdf0e10cSrcweir 216cdf0e10cSrcweir bool GetMemberNames( sal_Int32 nDim, ::com::sun::star::uno::Sequence< ::rtl::OUString >& rNames ); 217cdf0e10cSrcweir bool GetMembers( sal_Int32 nDim, sal_Int32 nHier, ::std::vector<ScDPLabelData::Member>& rMembers ); 218cdf0e10cSrcweir 219cdf0e10cSrcweir void UpdateReference( UpdateRefMode eUpdateRefMode, 220cdf0e10cSrcweir const ScRange& r, SCsCOL nDx, SCsROW nDy, SCsTAB nDz ); 221cdf0e10cSrcweir sal_Bool RefsEqual( const ScDPObject& r ) const; 222cdf0e10cSrcweir void WriteRefsTo( ScDPObject& r ) const; 223cdf0e10cSrcweir 224cdf0e10cSrcweir void GetPositionData(const ScAddress& rPos, ::com::sun::star::sheet::DataPilotTablePositionData& rPosData); 225cdf0e10cSrcweir 226cdf0e10cSrcweir bool GetDataFieldPositionData(const ScAddress& rPos, 227cdf0e10cSrcweir ::com::sun::star::uno::Sequence< 228cdf0e10cSrcweir ::com::sun::star::sheet::DataPilotFieldFilter >& rFilters); 229cdf0e10cSrcweir 230cdf0e10cSrcweir void GetDrillDownData(const ScAddress& rPos, 231cdf0e10cSrcweir ::com::sun::star::uno::Sequence< 232cdf0e10cSrcweir ::com::sun::star::uno::Sequence< 233cdf0e10cSrcweir ::com::sun::star::uno::Any > >& rTableData); 234cdf0e10cSrcweir 235cdf0e10cSrcweir // apply drop-down attribute, initialize nHeaderRows, without accessing the source 236cdf0e10cSrcweir // (button attribute must be present) 237cdf0e10cSrcweir void RefreshAfterLoad(); 238cdf0e10cSrcweir 239cdf0e10cSrcweir void BuildAllDimensionMembers(); 240cdf0e10cSrcweir 241cdf0e10cSrcweir static sal_Bool HasRegisteredSources(); 242cdf0e10cSrcweir static com::sun::star::uno::Sequence<rtl::OUString> GetRegisteredSources(); 243cdf0e10cSrcweir static com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier> 244cdf0e10cSrcweir CreateSource( const ScDPServiceDesc& rDesc ); 245cdf0e10cSrcweir 246cdf0e10cSrcweir static void ConvertOrientation( ScDPSaveData& rSaveData, 247cdf0e10cSrcweir const ScPivotFieldVector& rFields, sal_uInt16 nOrient, 248cdf0e10cSrcweir ScDocument* pDoc, SCROW nRow, SCTAB nTab, 249cdf0e10cSrcweir const com::sun::star::uno::Reference< 250cdf0e10cSrcweir com::sun::star::sheet::XDimensionsSupplier>& xSource, 251cdf0e10cSrcweir bool bOldDefaults, 252cdf0e10cSrcweir const ScPivotFieldVector* pRefColFields = 0, 253cdf0e10cSrcweir const ScPivotFieldVector* pRefRowFields = 0, 254cdf0e10cSrcweir const ScPivotFieldVector* pRefPageFields = 0 ); 255cdf0e10cSrcweir 256cdf0e10cSrcweir static bool IsOrientationAllowed( sal_uInt16 nOrient, sal_Int32 nDimFlags ); 257cdf0e10cSrcweir }; 258cdf0e10cSrcweir 259cdf0e10cSrcweir 260cdf0e10cSrcweir // ============================================================================ 261cdf0e10cSrcweir 262cdf0e10cSrcweir class ScDPCollection : public ScCollection 263cdf0e10cSrcweir { 264cdf0e10cSrcweir private: 265cdf0e10cSrcweir ScDocument* pDoc; 266cdf0e10cSrcweir public: 267cdf0e10cSrcweir ScDPCollection(ScDocument* pDocument); 268cdf0e10cSrcweir ScDPCollection(const ScDPCollection& r); 269cdf0e10cSrcweir virtual ~ScDPCollection(); 270cdf0e10cSrcweir 271cdf0e10cSrcweir virtual ScDataObject* Clone() const; 272cdf0e10cSrcweir operator [](sal_uInt16 nIndex) const273cdf0e10cSrcweir ScDPObject* operator[](sal_uInt16 nIndex) const {return (ScDPObject*)At(nIndex);} 274cdf0e10cSrcweir ScDPObject* GetByName(const String& rName) const; 275cdf0e10cSrcweir 276cdf0e10cSrcweir void DeleteOnTab( SCTAB nTab ); 277cdf0e10cSrcweir void UpdateReference( UpdateRefMode eUpdateRefMode, 278cdf0e10cSrcweir const ScRange& r, SCsCOL nDx, SCsROW nDy, SCsTAB nDz ); 279cdf0e10cSrcweir 280cdf0e10cSrcweir sal_Bool RefsEqual( const ScDPCollection& r ) const; 281cdf0e10cSrcweir void WriteRefsTo( ScDPCollection& r ) const; 282cdf0e10cSrcweir 283cdf0e10cSrcweir String CreateNewName( sal_uInt16 nMin = 1 ) const; 284cdf0e10cSrcweir 285cdf0e10cSrcweir void FreeTable(ScDPObject* pDPObj); 286cdf0e10cSrcweir SC_DLLPUBLIC bool InsertNewTable(ScDPObject* pDPObj); 287cdf0e10cSrcweir 288cdf0e10cSrcweir bool HasDPTable(SCCOL nCol, SCROW nRow, SCTAB nTab) const; 289cdf0e10cSrcweir }; 290cdf0e10cSrcweir 291cdf0e10cSrcweir 292cdf0e10cSrcweir #endif 293cdf0e10cSrcweir 294